OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:25 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Example Higher Half x86_64 kernel @ -2GB
PostPosted: Thu Apr 20, 2017 11:22 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 153
Location: Ogre, Latvia, EU
I was also tinkering with same thing (move kernel to -2 GiB addresses) lately.

It causes interesting consequences if you're using Recursive mapping. The last 512 GiB of address space is reserved for paging tables. Better not try to sneak a kernel code in there, you have to move paging structures somewhere else first.

Fortunately, there is no technical restrictions on which entry of PML4T can be used for recursive mapping. We are using last one because it is convenient (PML4T is located @ -4KiB, PDPTs @ -2 MiB, PDs @ -1GiB and PTs @ -512GiB). Any entry will do, but table offset calculations get... complicated.

Here's a simplified model of recursive paging tables with only 4 entries per table and 3 levels, demonstrating how things move around:
Attachment:
ptables.png
ptables.png [ 3.06 KiB | Viewed 857 times ]

I was at complete loss :oops: until I drew this. Sharing, just in case someone finds it useful.

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
 Post subject: Re: Example Higher Half x86_64 kernel @ -2GB
PostPosted: Thu Apr 20, 2017 12:05 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 19, 2005 12:00 am
Posts: 106
Velko wrote:
I was also tinkering with same thing (move kernel to -2 GiB addresses) lately.

It causes interesting consequences if you're using Recursive mapping. The last 512 GiB of address space is reserved for paging tables. Better not try to sneak a kernel code in there, you have to move paging structures somewhere else first.

Fortunately, there is no technical restrictions on which entry of PML4T can be used for recursive mapping. We are using last one because it is convenient (PML4T is located @ -4KiB, PDPTs @ -2 MiB, PDs @ -1GiB and PTs @ -512GiB). Any entry will do, but table offset calculations get... complicated.


Right, the way that I've chosen to view it, is that the recursive mapping can go into one of 512 "slots", each occupying 512GB of address space. For my -2GB mapped kernel, I just put the recursive mapping in the second to last slot :-). Easy once you look at it that way (at least for me)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group