Code: Select all
// page directories and tables
ulong_t* pagedir = ( ulong_t* ) 0x9C000;
ulong_t* pagetab = ( ulong_t* ) 0x9D000;
ulong_t* pagetab2 = ( ulong_t* ) 0x9E000;
// initializes paging
void InitPaging()
{
// necessary variables
ulong_t address = 0;
uint_t i;
// map the first 4 MB, first 4K not available
pagetab[0] = address | 2; // not present
address += 4096;
for( i = 1; i < 1024; i++ )
{
//kprintf( "Setting up entry at address 0x%8x to point to %d\n", (unsigned int) &pagetab[i], address );
pagetab[i] = address | 3; // supervisor, r/w, present
address += 4096; // 4 KB
}
// fill first entry of the page directory
pagedir[0] = (unsigned int) pagetab;
pagedir[0] = pagedir[0] | 3; // supervisor, r/w, present
// now map the second one
for( i = 0; i < 1024; i++ )
{
pagetab2[i] = address | 3;
address += 4096;
}
// fill second entry of page dir
pagedir[1] = (unsigned int) pagetab2;
pagedir[1] = pagetab[1] | 3;
// null out the rest
for( i = 2; i < 1024; i++ )
pagedir[i] = 0 | 2; // not present
// fill CR3 and CR0
write_cr3( (unsigned int) pagedir ); // put page directory address into cr3
write_cr0( read_cr0() | 0x80000000 ); // set paging bit to 1
}
Edit: Oops. Works now.
Code: Select all
// fill second entry of page dir
pagedir[1] = (unsigned int) pagetab2;
pagedir[1] = pagetab[1] | 3; <===== Should be pagedir[1]!
I've looked around in the wiki, tried Googling, and still nothing! I'm really confused now .