Recursive Page Directory Help

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
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Recursive Page Directory Help

Post by Firestryke31 »

So, it's been a while since I've last needed help with anything, but now I'm stuck. I'm trying to use the recursive page directory mapping technique and am a little confused with how it works. Here's the basic code I'm using right now (u32 is typedef'ed to unsigned int for now):

Code: Select all

MAPPING = ((u32*)(0xFFC00000));
tableIndex = 0xFFC00 + addr >> 22;
pageIndex = addr >> 10;
tableIndex and pageIndex are used like MAPPING[index].

How wrong am I?

I am a terrible coder since I couldn't for the life of me explain why I am using those values. I didn't even get them from a tutorial. I think I just kind of guessed at something that feels about right based on other code, which is probably why it's broken.

It's about 10:30 P.M. here, so if it ends up being something obvious or easily figured out my excuse is being tired. Thank you for your time and help!

Edit: Fixed tableIndex to use proper value
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Recursive Page Directory Help

Post by gravaera »

Hi;

AJ gave a pretty good discourse on the subject over here (http://forum.osdev.org/viewtopic.php?f= ... 66&start=0).

--All the best
gravaera.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Recursive Page Directory Help

Post by Firestryke31 »

I had a /facepalm moment. It turns out that the biggest problem I had was that I forgot to set the present bit on the page table I was trying to write pages to. There were a couple of other problems, but they're all fixed now. Damn that present bit!

Here's the code I'm currently using (the names could probably be better, but hey):

Code: Select all

#define DIRECTORY ((u32*)(0xFFC00000))
#define tableIndex(addr) (((ptr_t)(addr)>>22)+0xFFC00)
#define pageIndex(addr) ((ptr_t)(addr)>>12)
u32 == unsigned int;
ptr_t == integer where sizeof(type) == sizeof(void*);

Usage:
set a page table: DIRECTORY[tableIndex(virtualAddr)] = physicalAddr | flags;
set a page: DIRECTORY[pageIndex(virtualAddr)] = physicalAddr | flags;

So, it turns out I was very close. At least I now know why I used those values.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Post Reply