Page 1 of 1
C++ video memory access
Posted: Tue Jul 29, 2014 7:56 pm
by jpal
In my kernel I am trying to write to the screen.
Code: Select all
*((char*)0xB8000) = 72;
*((char*)0xB8001) = 15;
which compiles to
Code: Select all
movb $72, ($0xB8000)
movb $15, ($0xB8000)
displays an 'H', but
Code: Select all
char* ptr = (char*)0xB8000;
*ptr = 72;
*(ptr + 1) = 15;
which compiles to
Code: Select all
movl $0xB8000, -0x4(%ebp)
mov -0x4(%ebp), %eax
movb $72, (%eax)
mov -0x4(%ebp), %eax
add %eax, 1
movb $15, (%eax)
does not show any characters.
I do use a cross compiler so that is not the problem.
Please help! Thanks.
Re: C++ video memory access
Posted: Tue Jul 29, 2014 8:08 pm
by YaYo
maybe because you are using a char* pointer,
i.e. :
char* ptr = (char*)0xB8000;
*ptr = 72; // now ptr equals 0xB8000
*(ptr + 1) = 15; // but now is (0xB8000 + sizeof(char*)) equals 0xB8004
// try casting.
Re: C++ video memory access
Posted: Tue Jul 29, 2014 8:59 pm
by thepowersgang
@YaYo - Actually, that's not the problem.
@OP - Are you running on bochs/qemu and putting a cli;hlt loop soon afterwards? Iirc one (or both) of these will stop updating the screen when the CPU is halted in this manner.
The code looks correct to me (pretty obviously compiled with optimisaton off), so it's probably either the code not running, or something else hiding its effect.
Re: C++ video memory access
Posted: Tue Jul 29, 2014 9:24 pm
by YaYo
try to change this line
*(ptr + 1) = 15;
to this
*((char*)(((unsigned long)ptr) + 1)) = 15;.
Note: Bochs, Qemo, VBox,...etc have nothing to do with this problem.
Re: C++ video memory access
Posted: Tue Jul 29, 2014 9:52 pm
by thepowersgang
@YaYo - Please actually check what you're saying, and don't comment unless you have actually read and understood the post.
The generated assembly is correct (It's adding one to the address, not four). Which points to an error outside of the provided code, which is most likely bochs/qemu not updating the screen (this has caught almost everyone once, myself included)
Re: C++ video memory access
Posted: Wed Jul 30, 2014 12:32 am
by Combuster
jpal wrote:In my kernel I am trying to write to the screen.
Code: Select all
*((char*)0xB8000) = 72;
*((char*)0xB8001) = 15;
which compiles to
Code: Select all
movb $72, ($0xB8000)
movb $15, ($0xB8000)
That's obviously wrong. I get
0: c6 05 00 80 0b 00 48 movb $0x48,0xb8000
7: c6 05 01 80 0b 00 0f movb $0xf,0xb8001
What else did you not copy-paste properly?
Re: C++ video memory access
Posted: Wed Jul 30, 2014 3:01 am
by evoex
Combuster wrote:
What else did you not copy-paste properly?
I'd daresay this line:
Which ought to be: