Page 1 of 1

Video memory access and postfix incrementation

Posted: Thu Aug 27, 2015 6:10 am
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 :)

Re: Video memory access and postfix incrementation

Posted: Thu Aug 27, 2015 6:50 am
by Combuster
Sounds more like a case of using HLT in QEMU.

Re: Video memory access and postfix incrementation

Posted: Thu Aug 27, 2015 6:56 am
by naccyde
So, how could I bypass this ?

Re: Video memory access and postfix incrementation

Posted: Fri Aug 28, 2015 7:52 pm
by SpyderTL
naccyde wrote:So, how could I bypass this ?
Put a while(true); immediately after this code.