Paging and higher half kernels

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kraks
Posts: 10
Joined: Fri May 08, 2009 10:56 am

Paging and higher half kernels

Post by kraks »

Hi,

I think that I do understand paging, but it leaves two questions to me:
1) The wiki-page about paging doesn't mention this: Does each process need it's own page directory? (I think so but I'm not sure)
2) Does the kernel need a page-directory, too? And how does this work? Everytime control is passed to the kernel (by SysCalls or Interrupts), do I need to load the kernel-pd?

Regarding the higher-half kernel: Why needs the kernel to be mapped to user-processes? Is this to prevent the loading of kernel's page-directory? And how is the kernel-memory then protected from the user-processes? By the "user-/supervisor"-bit in the pages?

Greets,
kraks
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Paging and higher half kernels

Post by quanganht »

I'm not sure but it seems like the kernel doesn't need even a page, not to mention a page directory.
"Programmers are tools for converting caffeine into code."
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Paging and higher half kernels

Post by neon »

kraks wrote:1) The wiki-page about paging doesn't mention this: Does each process need it's own page directory? (I think so but I'm not sure)
Yes.
kraks wrote:2) Does the kernel need a page-directory, too? And how does this work? Everytime control is passed to the kernel (by SysCalls or Interrupts), do I need to load the kernel-pd?
No. How can a user process call a SysCall or an interrupt if there is nothing there (the kernel) in that same directory address space to catch it?

The important parts of the kernel (or the entire kernel binary) should be mapped to kernel space in a processes address pace. When a new address space is created, it should be mapped to the new address space as well.

Thus it does need a page table (or several), not an entire page directory.
kraks wrote:Regarding the higher-half kernel: Why needs the kernel to be mapped to user-processes? Is this to prevent the loading of kernel's page-directory? And how is the kernel-memory then protected from the user-processes? By the "user-/supervisor"-bit in the pages?
The kernel shouldnt use its own page directory. See above. The reason is the limitation of the architecture that only one page directory can be used at once. If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
blound
Member
Member
Posts: 70
Joined: Sat Dec 01, 2007 1:36 pm

Re: Paging and higher half kernels

Post by blound »

neon wrote: If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land
Are you referring to a full 4GB/4GB split of the address space? If so this is possible, osx does it.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Paging and higher half kernels

Post by Colonel Kernel »

blound wrote:
neon wrote: If you are in a user process address space, and the kernel is in another, there is no way to task switch or control that process at all because there would be no way to return back to kernel land
Are you referring to a full 4GB/4GB split of the address space? If so this is possible, osx does it.
Sort of... There still needs to be part of the kernel mapped in each address space for system calls and interrupts. I think of the OS X "kernel address space" as just a big process that runs in ring 0.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
kraks
Posts: 10
Joined: Fri May 08, 2009 10:56 am

Re: Paging and higher half kernels

Post by kraks »

Ok, thank you very much neon, I think I understand now :)
Post Reply