Enabling paging only in Ring 3

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
darkknight97
Posts: 1
Joined: Tue Jul 28, 2020 5:36 pm

Enabling paging only in Ring 3

Post by darkknight97 »

Hey guys.
I'm developing an OS for 80386 and am currently looking to implement paging. However I want logical addresses to be generated only in Userland (Ring 3) and all addresses in ring 0 to be physical. Is this possible and if yes, how can I do so?
I understand that paging gets enabled upon setting PG in CR0. If I set the bit right before my IRET, then the stack pointer address (esp) used by IRET for retrieving the CS, IP, EFLAGS, ESP, SS etc is also logical right? Any way to make sure logical addressing is used only after IRET completes?
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Enabling paging only in Ring 3

Post by Octocontrabass »

darkknight97 wrote:However I want logical addresses to be generated only in Userland (Ring 3) and all addresses in ring 0 to be physical.
Why?
darkknight97 wrote:Is this possible and if yes, how can I do so?
Sort of. You can use the hardware task switching mechanism to change CR3 when the privilege level changes, so you can have one set of page tables that identity map everything for ring 0, and another set of page tables that provide some other mapping for ring 3.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Enabling paging only in Ring 3

Post by iansjack »

The end result will be that every system call invalidates the TLB. This doesn't sound like the most efficient way of working.

You must use some really compelling reason for this.
Post Reply