You will first have to enter the protected mode, and to set 5 segments:
- The null segment
- A kernel code segment
- A kernel data segment
- A userland code segment
- A userland data segment
- A TSS to be able to switch from userland to kernelland.
The creation of the userland segment may be postponed to the binary loading. In fact, you cannot determine the size of the code segment without looking at the binary.
- Set up your own GDT
- You will need a kernel allocator for some libc functions, a dummy one will suffice, but don’t forget that kernel data should not appear in the rom address space.
- When setting up your GDT, you will face tons of reboot. It often means that your GDT is not set correctly.
Some memory areas are already busy, you should take care of this when creating
the user data and code segment. You can use the
given by GRUB to find those areas:
- the kernel code
- the user program
- I/O mappings (video framebuffer)
- Intel manual Vol. 3A chapter 3.4 (LOGICAL AND LINEAR ADDRESSES)