Question

I have written a very simple kernel that loads inside QEMU with the help of GRUB. I probably have a problem in pointer calculation, but cannot really figure out what is wrong.

The following code works as expected, it prints the given character.

char* video = 0xb8000 + 0;
char* color = 'A';

*video++ = c;
*video++ = color;

However when I change the video pointer calculation to this it does not work, nothing appears on screen:

int pos = 0;
char* video = 0xb8000 + pos;

But when I make the pos variable unsigned int, it works uncorrectly, but when I make it 1, it works as the first one, but why it needs to be 1?

unsigned int pos = 1;
char* video = 0xb8000 + pos;

My C flags: CFLAGS = -std=c99 -pedantic -Wall -nostdlib -ffreestanding -g

Was it helpful?

Solution

Perhaps try prefixing it like this: (char*)0xB8000

char* video = (char*)0xB8000;
int pos = 0;

video[pos++] = 'A';
video[pos++] = 0x7;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top