Video memory access and postfix incrementation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
naccyde
Posts: 4
Joined: Thu Aug 27, 2015 5:58 am

Video memory access and postfix incrementation

Post by naccyde »

Hello !

I'm actually trying to create my own kernel, and I have got some problem with video memory access :/
I need to access to video memory at boot, thus, I create a pointer to 0xB8000 address and then, I increment the pointer to access next location.

Basically, the code would be :

Code: Select all

volatile char *p = (volatile char *)0xB8000;

for (int i = 0; i < 6; ++i)
    *(p++) = 'A';
This way, p point to the proper memory address, and after each access, it is incremented (I know, the there is 2 bytes for each character displayed, but it will be more simple without taking care of it). So, it should show, on top left of the screen 3 letters 'A', with 'A' = 0x41 attributes, so blue letter on red background.

But this doesn't work, no character displayed. It display nothing. But if I change incrementation position like this, it works, i can see the characters on the screen !

Code: Select all

volatile char *p = (volatile char *)0xB8000;

for (int i = 0; i < 5; ++i)
    *p = 'A';
    p++;
By the way, with a prefix incrementation, it works too. But with postif incrementation, I should set to pointer to the (first_video_memory_location - 1) to write on the good location :

Code: Select all

volatile char *p = (volatile char *)0xB7FFF;

for (int i = 0; i < 5; ++i)
    *(++p) = 'A';
So, I checked assembly code :

Code: Select all

; Postfix
mov ecx, DWORD PTR _p$[ebp]
mov BYTE PTR [ecx], 65       ; 'A' character
mov edx, DWORD PTR _p$[ebp]
add edx, 1
mov DWORD PTR _p$[ebp], edx

; Prefix
mov ecx, DWORD PTR _p$[ebp]
add ecx, 1
mov DWORD PTR _p$[ebp], ecx
mov edx, DWORD PTR _p$[ebp]
mov BYTE PTR [edx], 65       ; 'A' character
I can't spot the difference. By the way, I could use the prefix incrementation but, I would like to understand with does the postfix not work :/

The assembly code is from Visual C++ compiler, I don't have any GCC at work :/

I know the difference between prefix and postfix incrementation, and I see the difference between assembly code present here. But IMO, none of these differences leads to non printing characters on screen.

Thank you :)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Video memory access and postfix incrementation

Post by Combuster »

Sounds more like a case of using HLT in QEMU.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
naccyde
Posts: 4
Joined: Thu Aug 27, 2015 5:58 am

Re: Video memory access and postfix incrementation

Post by naccyde »

So, how could I bypass this ?
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Video memory access and postfix incrementation

Post by SpyderTL »

naccyde wrote:So, how could I bypass this ?
Put a while(true); immediately after this code.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply