After some time trying to write an x86 bootloader and asking my way on here in the process I think I need to take a step back and clear up some misconceptions i have about what I'm actually trying to achieve:
I understand that at the beginning of the boot process, the BIOS reads the first 512 byte from the boot medium and loads them into memory at address 0x7C00 below that from 0x500 downward and above that from 0x80000 upward (give or take) there is BIOS/video specific stuff loaded into memory that a bootloader should not touch.
But I'm not sure how the situation changes when the bootloader switches into protected mode. Say I do not relocate the bootloader code before doing this, I just disable interrupts, enable A20 and then directly jump into protected mode code with a GDT that is as simple as possible, i.e. one code and one data segment, both covering the whole 4GiB address space.
After I have done that, I assume my bootloader code is still located at 0x7C00. Can I then just move it anywhere I want before loading my kernel into memory? I.e. at 0x0? What about my stack, do I just let it start at 0xFFFFFFFF? Of course later I would want to set up paging but I'm not sure how to lay out my memory before I get to that point. Or is my approach suboptimal anyways and I should set up my GDT differently from the start? If so, what would be a "typical" way to do this, separate code and data segments together encompassing all memory addresses? Or even a separate stack segment?
User contributions licensed under CC BY-SA 3.0