Page 1 of 1
VGA Memory Byte Order
Posted: Mon Jun 02, 2014 11:43 am
by songziming
I just managed to link asm and c together, and I want to print a char from C
Code: Select all
void kmain(void) {
unsigned char *video = (unsigned char *)0xb8000;
video[0] = 'K';
video[1] = 0x07;
}
But what I got is
Can any one tell me why?
EDIT:
if I do
I can get the right result, But afaik the higher byte holds the attribute and the lower byte holds the char, why I got opposite after entering C.
Re: write video ram from C
Posted: Mon Jun 02, 2014 11:45 am
by Combuster
My crystal ball says you missed the
Posting Checklist, and especially the gcc/ld part.
Re: write video ram from C
Posted: Mon Jun 02, 2014 11:58 am
by sortie
This is probably because how little endian works. I'll admit, this does seem the opposite of what I would expect, too. If changing the order works, just do that instead, though.
Re: write video ram from C
Posted: Mon Jun 02, 2014 11:59 am
by songziming
Combuster wrote:My crystal ball says you missed the
Posting Checklist, and especially the gcc/ld part.
I use clang as the compiler
Re: VGA Memory Byte Order
Posted: Mon Jun 02, 2014 12:14 pm
by Combuster
I use clang as the compiler
That implies a number of things:
1) You did not use a tutorial (the shady and worse ones use gcc, the better ones a cross-compiler, but none that I know use clang)
2) Therefore, you have to have invented your own command line invocations
3) All the things regarding improper gcc use can equally apply to clang.
Point is, the shifting of bytes is a signature indication of running code of a different architecture - 64 bit code run in 32-bit mode gives a lot of off-by-one errors due to encoding differences.
Re: VGA Memory Byte Order
Posted: Mon Jun 02, 2014 9:42 pm
by alexfru
If the data segment's base address is off by 1 in the GDT, you may see such behavior.
Re: VGA Memory Byte Order
Posted: Mon Jun 02, 2014 9:43 pm
by songziming
It seems to be the problem of x86-64. If I pass the -m32 option to the compiler, it would get the correct result.