
I'm currently in the following situation. My kernel is running in the higher half, starting at 0xC0000000. In my initial paging directory I created the tables at index 0 and 768-1022 as kernel-tables (to ensure that any change to the kernel space happens in all processes) and entry 1023 mapped to the directory itself. So far so good - now the time has come to implement preemptive multitasking. My problem is the following: I am now inside of the setup function of my kernel. Now I want to kick off the first process. To do so, I have to create a copy of the page directory (copying only the kernel tables), so entries 1-767 can be used as user space.
Now, I ask my physical page allocator for a new page to create a directory for this new process. But, as currently the initial page directory is enabled, I have no access to the physical pages. The same problem occurs with the kernel stack - I need to put the initial register values on it, to allow my interrupt stub to pop them off the stack initially. And when I finally want to load a binary image to that space, I again have that problem.. How do you solve this?
I figured out these two methods:
a) Temporarily map the pages of the directory, the kernel stack and so on to the current (process-creating) directory, and unmap them after creating the process? (this seems dirty to me..)
b) Fetch the current page directory, temporarily switch to the newly created directory, and after creation switch back? (this seems even dirtier, also I am still forced to map at least the new page directory temporarily to copy the values)
Also, my physical page allocator does not give back zeroed pages, for the same reason as above, and I also cannot 0 all pages when pushing them into the allocator, that would be really slow. So that is another place where I temporarily have to map..
Is there an elegant solution for all of this?
Thanks a lot!
Greets, Max