Triple fault when enabling 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.
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault when enabling paging

Post by neon »

pgtbl[0] = 0x00000003 is correct however pgdir[0] = 0x0009B803 is not. Assuming the page table is at 0x00137000, pgdir[0] should be 0x137003. Without farther information, I cannot confirm where that 0x0009B803 is coming from - it points to a nonexistent page table at 0x9b000.

In fact, pgtbl[0] = 0x00000003, pgtbl[1] should be 0x00001003, pgtbl[2] should be 0x00002003 ... and pgtbl[1023] should be 0x003ff003. This maps frames 0 - 0x3ff, or addresses 0 - 0x400000 inclusive. If you got these as well, then we can focus on why the page directory is wrong.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

iansjack wrote:I'm puzzled. In your initial post you said the problem happened when you turned on paging. Now you are saying that it isn't in your code.

If it's crashing before you can do any debugging then from where are you getting the values that you tell us your page table entries have?
No, no. You misunderstanded me. The paging problem is in my code, my message about "not my code" is about Bochs crash on GRUB menu, not about paging.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

neon wrote:pgtbl[0] = 0x00000003 is correct however pgdir[0] = 0x0009B803 is not. Assuming the page table is at 0x00137000, pgdir[0] should be 0x137003. Without farther information, I cannot confirm where that 0x0009B803 is coming from - it points to a nonexistent page table at 0x9b000.

In fact, pgtbl[0] = 0x00000003, pgtbl[1] should be 0x00001003, pgtbl[2] should be 0x00002003 ... and pgtbl[1023] should be 0x003ff003. This maps frames 0 - 0x3ff, or addresses 0 - 0x400000 inclusive. If you got these as well, then we can focus on why the page directory is wrong.
I don't know why, but pgtbl is increases by 0x800, not by 0x1000.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

0x00000003, 0x00000803, 0x00001003, ...
User avatar
iansjack
Member
Member
Posts: 4814
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Triple fault when enabling paging

Post by iansjack »

Your definition of Page Table entries is wrong. You're missing the PWT bit. And the address field should be 20 bits, not 21
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

iansjack wrote:Your definition of Page Table entries is wrong. You're missing the PWT bit. And the address field should be 20 bits, not 21
Thanks, fixed. Now pgtbl is increasing by 0x1000. What next, @neon?
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault when enabling paging

Post by neon »

Make sure that you made the same update to your page directory structure (it follows the same structure as the page table; the address field should also be 20 bits.) What is (uint32_t)pgdir[0] and the address of page directory now?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

pgdir[0] is changed, now it's 0x00137003. Address is the same - 0x00138000. My page directory structure is:

Code: Select all

struct page_directory_t
{
    unsigned int present       : 1;
    unsigned int rw_flag       : 1;
    unsigned int access_lvl    : 1; //0 is for only ring0. 1 is for anybody.
    unsigned int write_through : 1;
    unsigned int cache_off     : 1;
    unsigned int accessed      : 1;
    unsigned int zero          : 1;
    unsigned int page_size     : 1;
    unsigned int unused        : 4; //Now it's 4, because of 1 ignored bit (G in wiki article)
    unsigned int tbl_addr      : 20;
};
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault when enabling paging

Post by neon »

Before you told us that the page table was at 0x00137000 not 0x00138000. Please double check which one is correct. pgdir[0] = 0x00137003 is only valid if the page table is at 0x00137000.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

Yes, that's a my typo :) The real address of pgdir is 0x00138000 and address of pgtbl is 0x00137000.
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault when enabling paging

Post by neon »

Okay, great - this means pgdir[0] is now correct and so is your page table. Now, post the value of the cr3 register. It should be 0x00138000.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

CR3==0x00138000
YAAAY!
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Triple fault when enabling paging

Post by neon »

Does it work without error or still triple fault?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

neon wrote:Does it work without error or still triple fault?
Works, I'll go and map the 32 MB of memory. Paging is enabling now, but I inserted the cli; hlt after it, so it cannot access non-accessible yet VBE framebuffer.
User avatar
abcdef4bfd
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am

Re: Triple fault when enabling paging

Post by abcdef4bfd »

Thank you, neon and iansjack!
Post Reply