Im working on my knowledge in lower level languages, and therefore decided to try out writing a insanely minimal kernel in x86_64. Just having some problems with optimization.
My bootloader (run from GRUB) looks like this.
.global start.section .textstart: mov $stack_top, %esp call kernel_main hlt.size start, . - start.section .bss.align 16stack_bottom: .space 16384stack_top:My 'kernel' does the following things.
void kernel_main(void) { terminal_buffer = (uint16_t*) 0xB8000; uint16_t vga_char = ((VGA_BLACK << 4 | VGA_MAGENTA) << 8) | 'Y';}My problem is that using no optimization, the kernel_main doesn't even get called (or atleast, the behaviour within doesn't behave correctly). Im also having random off-by-one errors with the printed character, depending on what optimization i use.
I believe this could be because the processor still is in real/protected mode (GRUB ensures this), but i run C compiled with a x86_64-elf compiler. Is there a valid way to write C code for real/protected mode (i.e. 32-bit code) in a x86_64-elf compiler, so that i can write central bootup (checking long mode compat, switching to long mode, etc.). Or would i have to build another compiler? Or is this totally unreasonable, and "has" (and really should) to be done in assembly?