Page 1 of 1

Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 2:06 am
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

Re: Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 2:17 am
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.

Re: Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 2:25 am
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.

Re: Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 2:38 am
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

Re: Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 2:43 am
by Polluticorn
Oh, sorry, can't believe I missed that section.

Thanks very much!

Re: Switch page directory for higher half kernel

Posted: Wed Jun 27, 2012 4:04 am
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.

Re: Switch page directory for higher half kernel

Posted: Thu Jun 28, 2012 11:09 pm
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

Re: Switch page directory for higher half kernel

Posted: Wed Jul 18, 2012 5:54 pm
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...