Page 1 of 1

Triple Fault while paging

Posted: Fri May 09, 2008 2:40 am
by asdfgh
#include<paging.h>
#include<io.h>
#include<textmode.h>
#include<types.h>
unsigned long *page_directory = (unsigned long *) 0xAA0000;
unsigned long *page_table = (unsigned long *) 0xAB0000; // the page table comes right after the page directory
void paging_install()
{
unsigned long address=0; // holds the physical address of where a page is
unsigned int i,j,d;

kprint("Installing PAGING \n");
for(i=0;i<1024;i++)
{
for(j=0;j<1024;j++)
{
page_table[1024*i+j] = address | 3; // attribute set to: supervisor level, read/write, present(011 in binary)
address = address + 4096; // 4096 = 4kb
}
if(i==0)
{
page_directory[0] = cast_ulong(page_table);
page_directory[0] = page_directory[0] | 3;
}
if(i==1)
{
page_directory[1] = page_directory[1] | 2;
}
else
{
page_directory = cast_ulong(page_table[1024*i]);
page_directory = page_directory | 3;
}
replace_int((1024*i+j)*4);
}
kprint(" Kilo Bytes.");

// write_cr3, read_cr3, write_cr0, and read_cr0 all come from the assembly functions
write_cr3(cast_ulong(page_directory)); // put that page directory address into CR3

write_cr0(read_cr0() | 0x80000000); // set the paging bit in CR0 to 1
kprint(" DONE\n");
}


bochs just quit when paging is installed?/

Posted: Fri May 09, 2008 3:00 am
by JamesM
Hi,

(1) Use [ code] tags, not quote tags, so your indentation is kept.
(2) Why the if (i==0), if (i==1) special cases?
(3) in the if(i==1) special case, page_directory[1] is undefined.
(4) Where's your bochs dump?

Cheers,

James

Posted: Fri May 09, 2008 3:07 am
by asdfgh
just set that the first entry is not used...
and others are set..

instead of using pagetable[1]
can we use pagetable+=1

Posted: Fri May 09, 2008 5:08 am
by JamesM
asdfgh wrote:just set that the first entry is not used...
and others are set..

instead of using pagetable[1]
can we use pagetable+=1
This post is illegible and I can't understand it.

(5) "page_directory = cast_ulong(page_table[1024*i]);" <-- There should be an '&' before the 'page_table'.