First, an overview of my virtual memory manager. I simply renamed my old MMU_AllocPage to MMU_AllocPagePhys, and replaced it with a function that grabs a physical page, maps it into kernel dynamic data space, and returns the virtual address. Also, the kernel uses a permanent mapping of the upper 2GB of memory (2mb set aside) at physical 0x800000 or virtual 0xFFA00000.
Now, the hard part (as if that wasn't hard enough ). I've wondered long an hard as to how I should deal with the lower 2mb portion, and it isn't all that easy for me. I finally decided to map it into the Shared Data Space (from 0x80000000 to 0xBFFFFFFF) in a specific area. Heres this section of my documentation:
Also, note that the "Current Page Directories" section only contains 'task' specific data in the lower 2mb - the upper 2mb always contain the kernel mappings, which are the same throughout every task.0x80000000 - Shared data (messages are mapped here, certain drivers, paging directoris etc.){
0x80000000 to 0x8FFFFFFF - Shared/Mapped messages
0x90000000 to 0xAFFFFFFF - Shared libraries etc., such as drivers or graphic libs etc.
0xB0000000 to 0xBFFFFFFF{
0xB0000000 to 0xB03FFFFF - Current Page Directories (entire 4mb area, only portions may be mapped)
0xB0400000 to 0xB0400FFF - Current Page Table (for current Task)
0xB0401000 to 0xB0401FFF - Working Page Table (for when editing)
0xB0402000 to 0xBFFFFFFF - Reserved for future use
}
}
Anyways, when CR3 is switched for a task change, it (The page table pointed at by CR3) has this area of memory (0xB0000000 to 0xBFFFFFFF) changed by the 4k of page table entries. This is the only difference between task's upper 2GB memory. The lower area is cleared (the area that maps the lower 2GB of memory) and memory is not even allocated for the would-be page directories for it to point. Instead, it is left completly, and my virtual memory manager finds (when you try to map something) that the page directory is not already present for that section of memory, and allocates the memory for it.
So, when I create a task and set up its initial stack, I have to create the page table (with the area of the upper 2GB filled in with pointers into the permanent kernel page directories) and then start by creating maps for the code (from 0x00000000 - ....) and a 4k stack (which can grow downward via page-faults).
To be honest, I'm not really sure _how_ this is messing my head up, but it seems to anyways. So, in retrospect, I think my major question has changed. Does this make sense? I mean, should I really be doing it another way that is simpler? Is this simple as it is? Any problems I may run into? etc.