A good way for storing&accessing paging structure
Posted: Sun Dec 15, 2013 12:51 pm
Hello
During the summer summer I jumped from writing C programs to lower level and learnt many things about assembly and operating systems. Now I want to get back to it and I'm decided to write a microkernel.
I have used GRUB2 for loading my ELF file, which is planned to be a higher half kernel. Its entry point maps the whole kernel to the highest gigabyte of memory and tries to create more address spaces for other processes. Physical memory management code uses memory map provided by GRUB to fill a bitmap, which covers whole possible 4GBs of memory. My kernel uses page directory (set up by entry assembly) located after kernels code, data and uninitialized data, together with a single page table which has been enough so far.
Whenever I want to create a new page table or page directory, I need to allocate it somewhere. I can get address of first free physical page from the bitmap I have, but I need to access it somehow, as it's not paged. So, I can use a special address within my kernel´s page table to write PDEies pointing on page tables that are global (kernel) and then use it for different PDE, or I can identity-page its physical location. If I choose to do the first, I need to map every single page directory or page table I'm going to work with to my special page and execute invlpg each time I manipulate with it. The second option requires creating lots of page tables for only holding another page tables and directories for different address spaces to be accessible for the kernel every time its necessary, but it can save me some time. I would choose to create a special physical location that would be identity-paged in kernel´s space, but the problem is that I don't know how many page tables and directories am I going to have. And if I wanted to manage somthing like "blocks of paging entities", I would need to hold bitmap for each of them + have some array or list in kernel.
How can I hold page tables and page directories to be quickly accessible when system needs it, without limiting quantity of address spaces?
How do hobby operating systems usually solve this problem?
Thanks,
Filip.
During the summer summer I jumped from writing C programs to lower level and learnt many things about assembly and operating systems. Now I want to get back to it and I'm decided to write a microkernel.
I have used GRUB2 for loading my ELF file, which is planned to be a higher half kernel. Its entry point maps the whole kernel to the highest gigabyte of memory and tries to create more address spaces for other processes. Physical memory management code uses memory map provided by GRUB to fill a bitmap, which covers whole possible 4GBs of memory. My kernel uses page directory (set up by entry assembly) located after kernels code, data and uninitialized data, together with a single page table which has been enough so far.
Whenever I want to create a new page table or page directory, I need to allocate it somewhere. I can get address of first free physical page from the bitmap I have, but I need to access it somehow, as it's not paged. So, I can use a special address within my kernel´s page table to write PDEies pointing on page tables that are global (kernel) and then use it for different PDE, or I can identity-page its physical location. If I choose to do the first, I need to map every single page directory or page table I'm going to work with to my special page and execute invlpg each time I manipulate with it. The second option requires creating lots of page tables for only holding another page tables and directories for different address spaces to be accessible for the kernel every time its necessary, but it can save me some time. I would choose to create a special physical location that would be identity-paged in kernel´s space, but the problem is that I don't know how many page tables and directories am I going to have. And if I wanted to manage somthing like "blocks of paging entities", I would need to hold bitmap for each of them + have some array or list in kernel.
How can I hold page tables and page directories to be quickly accessible when system needs it, without limiting quantity of address spaces?
How do hobby operating systems usually solve this problem?
Thanks,
Filip.