Triple Fault while paging

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
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

Triple Fault while paging

Post 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?/
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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'.
Post Reply