Switch page directory for higher half kernel

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
Polluticorn
Posts: 4
Joined: Wed Jun 27, 2012 1:14 am

Switch page directory for higher half kernel

Post by Polluticorn »

I recently got back into os development and am this time trying to implement a higher half kernel, something I haven't done before.
So far I have an asm loader to setup a temporary page directory and enable paging, and it works to call my main.c at 0xc0000000. At this point, though, I'm not sure how to switch to a new page directory.

From what I understand the cr3 register takes a pointer to the physical address of the page directory entries? I think before I was just storing the physical addr in the page directory struct, but this wouldn't work with paging already enabled. It doesn't look like any sort of disabling paging is feasible for this?

I've heard a little about pointing one page table back to the directory, but I'm still pretty unclear about how this would work. Is it as simple as it sounds, in which case you would access the address using a member of

Code: Select all

&directory->tables[x]
or something like that? Is there a preferred page table to use for this?

Thanks,
-friendly neighborhood polluticorn
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Switch page directory for higher half kernel

Post by Nessphoro »

http://www.jamesmolloy.co.uk/tutorial_h ... aging.html

EDIT: It says the other way it wastes 256MB of addressable memory. Actually it's four megabytes - one table. Silly James.
Polluticorn
Posts: 4
Joined: Wed Jun 27, 2012 1:14 am

Re: Switch page directory for higher half kernel

Post by Polluticorn »

One solution to this problem is to never access your page tables directly, but to map one page table to point back to the page directory, so that by accessing memory at a certain address you can see all your page tables as if they were pages, and all your page table entries as if they were normal integers. The diagram on the right should help to explain. This method is a little counter-intuitive in my opinion and it also wastes 256MB of addressable space, so I prefer another method.
Yes, this is what I was talking about, but unless I'm missing something, there isn't any further explanation on the site, and without having paging enabled yet, he's using a pointer to the physical address. I'm just looking for a slightly more detailed explanation of the technique, if anyone is willing to provide it.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Switch page directory for higher half kernel

Post by Nessphoro »

Ah, okay. I thought you were looking for an alternative.
In that case, there is an example on the wiki Paging under manipulation
Polluticorn
Posts: 4
Joined: Wed Jun 27, 2012 1:14 am

Re: Switch page directory for higher half kernel

Post by Polluticorn »

Oh, sorry, can't believe I missed that section.

Thanks very much!
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Switch page directory for higher half kernel

Post by JamesM »

Nessphoro wrote:http://www.jamesmolloy.co.uk/tutorial_h ... aging.html

EDIT: It says the other way it wastes 256MB of addressable memory. Actually it's four megabytes - one table. Silly James.
Indeed. Silly me (5 years ago :) )
Yes, this is what I was talking about, but unless I'm missing something, there isn't any further explanation on the site, and without having paging enabled yet, he's using a pointer to the physical address. I'm just looking for a slightly more detailed explanation of the technique, if anyone is willing to provide it.
Give this a crack: https://code.google.com/p/jamesm-tutori ... /src/vmm.c
https://code.google.com/p/jamesm-tutori ... gement.txt

Not fully complete, but should give you some ideas.
Polluticorn
Posts: 4
Joined: Wed Jun 27, 2012 1:14 am

Re: Switch page directory for higher half kernel

Post by Polluticorn »

Hi James, thanks for the reply.

I just wanted to say those links have been very helpful so far and have cleared up the subject a lot more for me.

So thanks :D
Dominator
Member
Member
Posts: 25
Joined: Fri Jul 06, 2012 10:52 am

Re: Switch page directory for higher half kernel

Post by Dominator »

Polluticorn wrote:Hi James, thanks for the reply.

I just wanted to say those links have been very helpful so far and have cleared up the subject a lot more for me.

So thanks :D
So have you successfully re-enabled paging with your own directory? I'm trying the same, but I get page not present right after updating cr3...
Post Reply