Kernel memory layout and memory management
Posted: Wed Jun 02, 2021 3:50 am
Hi everyone, new member here. I've just recently started os development as a way to extend the little pratical knowledge given about operating systems at universities.
As this is my first time delving into os development, i have decided to make a 32 bit (without PAE) os targetting x86 architecture. To make things even simpler (since for now i'm interested to make an os and not a bootloader) i have decided to make my kernel bootable by a multiboot2 compliant bootloader.
I have started from the beginners tutorials on the wiki and completed succesfully all up until "meaty skeleton" and then moved on by taking only inspiration from it. I'm now at the point where i have succesfully grabbed the multiboot2 memory map and designing the physical memory manager. Before jumping into coding a few questions arised in my mind and i was wondering if someone could give me some pointers (no pun intended).
The first question i wanted to ask is about kernel memory placement, i would like to go with an higher half kernel to be placed starting at 0xC0000000. I wanted to ask which is the best way to do this? In my linker script i place the kernel at the conventional 1M and after enabling paging i would map the kernel memory region to start at 0xC0000000. I've seen that another approach is to link the kernel at the virtual address from the start and enable paging in the boot initialization before jumping to c code. In my case, since i'm loaded by a multiboot2 bootloader i find myself already in 32 bit protected mode and was thinking about doing all the setup from c code (GDT, IVT, paging). What's the best way to go about it and why? For now i'm using the gdt provided by multiboot and haven't setup interrupts yet.
As this is my first time delving into os development, i have decided to make a 32 bit (without PAE) os targetting x86 architecture. To make things even simpler (since for now i'm interested to make an os and not a bootloader) i have decided to make my kernel bootable by a multiboot2 compliant bootloader.
I have started from the beginners tutorials on the wiki and completed succesfully all up until "meaty skeleton" and then moved on by taking only inspiration from it. I'm now at the point where i have succesfully grabbed the multiboot2 memory map and designing the physical memory manager. Before jumping into coding a few questions arised in my mind and i was wondering if someone could give me some pointers (no pun intended).
The first question i wanted to ask is about kernel memory placement, i would like to go with an higher half kernel to be placed starting at 0xC0000000. I wanted to ask which is the best way to do this? In my linker script i place the kernel at the conventional 1M and after enabling paging i would map the kernel memory region to start at 0xC0000000. I've seen that another approach is to link the kernel at the virtual address from the start and enable paging in the boot initialization before jumping to c code. In my case, since i'm loaded by a multiboot2 bootloader i find myself already in 32 bit protected mode and was thinking about doing all the setup from c code (GDT, IVT, paging). What's the best way to go about it and why? For now i'm using the gdt provided by multiboot and haven't setup interrupts yet.