Craze Frog wrote:So basically I need to do some static setup of stuff.
If you're using a multiboot bootloader, it should pass how big the kernel is. Load the kernel. Using this you should be able to work out where you free memory begins. Place your free/used page bitmap here. Since you know how big the kernel is, and how much room the bitmap takes up, mark the pages these expand across as "used" in your bitmap. Your memory manager requires no more to setup. This bitmap is all you need to be able to find free pages. Then you can dynamically allocate a page for your page directories and page tables. The trick here is not to enable paging (or switch to your new page directory) until after you have constructed the page directory/tables.
How I do it in my kernel is:
- I link my kernel to be at 1GB+1MB.
- GRUB loads my kernel to 1MB.
- In my assembly stub code I have to place "- 0x40000000" next to every label until I map the top 1GB to the lower 1GB. (Use 4MB pages for this, it's easier).
- When my kernel switches to C++, I create a page bitmap and place it just after my kernel.
- Then using this bitmap I allocate the necessary page directories/tables.
- I set up the page tables to to cover the kernel, the bitmap, and the directories/tables.
- I then switch over to one of my new page directories.
- Now paging is set up and everything concerning memory management is functioning as normal.