Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6502

64-bit kernel undefined behaviour with C calls

$
0
0

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?


Viewing all articles
Browse latest Browse all 6502

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>