Page 3 of 3
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 9:50 am
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 10:25 am
by osdever
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 10:34 am
by osdever
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 10:36 am
by osdever
0x00000003, 0x00000803, 0x00001003, ...
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 10:45 am
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
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 10:57 am
by osdever
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?
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:06 am
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?
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:17 am
by osdever
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;
};
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:23 am
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:28 am
by osdever
Yes, that's a my typo
The real address of pgdir is 0x00138000 and address of pgtbl is 0x00137000.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:29 am
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:36 am
by osdever
CR3==0x00138000
YAAAY!
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:36 am
by neon
Does it work without error or still triple fault?
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:38 am
by osdever
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.
Re: Triple fault when enabling paging
Posted: Sat Feb 20, 2016 11:50 am
by osdever
Thank you, neon and iansjack!