Disabling paging for copying physical frame
Posted: Sun May 20, 2012 10:32 am
Hey osdevers,
I've been a little lost with this for a while so I thought I would post here for some help.
I have been vaguely following along JamesM's tutorials for developing my OS. I am at the stage in my kernel where I have enabled paging, mapped the first 4MB of physical memory to a higher address (0xc0000000, using the gdt trick) and moved my kernel stack to a different address (0xe0000000). This moving of the stack is done after cloning the kernel directory so that when I clone a page directory, it gets copied rather than linked. This is all fine.
Now in order to create a new task, I clone the page directory. In order to do the cloning of the physical frame, I have to disable paging. When this happens, esp and ebp are no longer valid so in my copy_frame_physical assembly stub, I change my gdt to the trickgdt. The problem is that the stack is no longer the same physical location (since I moved it to a page that is mapped to a different physical address). To fix this I pass the offset to the physical address of esp as a parameter to copy_frame_physical. I then subtract this offset from esp and ebp to get the right physical address. However, this is still failing and causing a triple fault.
My question is, what is the normal way to do this copying of frames when you have a higher half kernel? Is there a cleaner approach?
Note: I haven't provided code as it's on a different machine and I can't get it. I will update the thread with my code tomorrow. In the meantime, if any of you have already done this, I would really appreciate the help (and if possible some code!)
Thanks and best regards!
Manohar
I've been a little lost with this for a while so I thought I would post here for some help.
I have been vaguely following along JamesM's tutorials for developing my OS. I am at the stage in my kernel where I have enabled paging, mapped the first 4MB of physical memory to a higher address (0xc0000000, using the gdt trick) and moved my kernel stack to a different address (0xe0000000). This moving of the stack is done after cloning the kernel directory so that when I clone a page directory, it gets copied rather than linked. This is all fine.
Now in order to create a new task, I clone the page directory. In order to do the cloning of the physical frame, I have to disable paging. When this happens, esp and ebp are no longer valid so in my copy_frame_physical assembly stub, I change my gdt to the trickgdt. The problem is that the stack is no longer the same physical location (since I moved it to a page that is mapped to a different physical address). To fix this I pass the offset to the physical address of esp as a parameter to copy_frame_physical. I then subtract this offset from esp and ebp to get the right physical address. However, this is still failing and causing a triple fault.
My question is, what is the normal way to do this copying of frames when you have a higher half kernel? Is there a cleaner approach?
Note: I haven't provided code as it's on a different machine and I can't get it. I will update the thread with my code tomorrow. In the meantime, if any of you have already done this, I would really appreciate the help (and if possible some code!)
Thanks and best regards!
Manohar