1

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

Mustafa
  • 9,075
  • 7
  • 62
  • 109

1 Answers1

1

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

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

video[pos++] = 'A';
video[pos++] = 0x7;
DmitryK
  • 5,302
  • 1
  • 17
  • 32
  • This made me aware that I was using the color & character wrong, the order should be reverse, first color then character! Thanks – Mustafa Sep 08 '13 at 15:29
  • First (low) byte - ASCII character, second (high) byte - attributes (colour, blinking etc) – DmitryK Sep 08 '13 at 15:31
  • Oh, I used this: `char* video = (char*)0xB8000;video[2 * pos] = c; video[2 * pos + 1] = color;`but the last character is always wrong attribute, what is wrong? – Mustafa Sep 08 '13 at 15:34
  • It seems like it is fixed when I made it offset by 1, it all suddenly work! – Mustafa Sep 08 '13 at 15:36