blog_os icon indicating copy to clipboard operation
blog_os copied to clipboard

Steps to divide the address space in kernel space and user space

Open sauravdeshpande opened this issue 2 years ago • 2 comments

Great blog, I have followed all the articles so far from the blog os post, I was thinking about how to divide the address spaces. What modifications are needed to divide the virtual memory into kernel space and user space and how context switch can be done.

Thank you

sauravdeshpande avatar Feb 22 '22 11:02 sauravdeshpande

Here's an article about how to get to usermode (a.k.a Ring 3 on x86): https://wiki.osdev.org/Getting_to_Ring_3

  • Add two new GDT entries (at least) configured for ring 3.
  • Set up a barebones TSS with an ESP0 stack.
  • Set up an IDT entry for ring 3 system call interrupts (optional).

nullium21 avatar Mar 06 '22 10:03 nullium21

For moving the kernel to the higher half, it should be enough to instruct the linker to use a different base address. You can do this through a linker script or by passing an --image-base argument.

phil-opp avatar Mar 06 '22 12:03 phil-opp