Page 1 of 1

Recursive Page Directory Help

Posted: Sat Oct 31, 2009 9:29 pm
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

Re: Recursive Page Directory Help

Posted: Sat Oct 31, 2009 9:44 pm
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.

Re: Recursive Page Directory Help

Posted: Sat Oct 31, 2009 10:14 pm
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.