Page 1 of 2

page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 2:07 pm
by xDDunce
hiya,

i havent had this much trouble in a long time!

basicly, i am still following JamesM's tutorial and i have reached the multitasking section. but having implemented the code from this section, i am running into an old error: receiving a page fault when switching page directory.

it is not like it was before though. it runs fine until i have cloned the kernel directory and load the physical address into CR3. but the most annoying thing is it does not get handled, it just throws a triple fault and exits. here is the bochslog:

Code: Select all

00164721852i[CPU0 ] CPU is in protected mode (active)
00164721852i[CPU0 ] CS.d_b = 32 bit
00164721852i[CPU0 ] SS.d_b = 32 bit
00164721852i[CPU0 ] EFER   = 0x00000000
00164721852i[CPU0 ] | RAX=00000000c0082000  RBX=0000000000106ff8
00164721852i[CPU0 ] | RCX=0000000000000300  RDX=00000000c0082000
00164721852i[CPU0 ] | RSP=0000000000106f58  RBP=0000000000106f68
00164721852i[CPU0 ] | RSI=000000000002d73a  RDI=000000000002d73b
00164721852i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00164721852i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00164721852i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00164721852i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00164721852i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf af pf cf
00164721852i[CPU0 ] | SEG selector     base    limit G D
00164721852i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00164721852i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00164721852i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00164721852i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00164721852i[CPU0 ] | RIP=0000000000101b7f (0000000000101b7f)
00164721852i[CPU0 ] | CR0=0xe0000011 CR1=0x0 CR2=0x0000000000108130
00164721852i[CPU0 ] | CR3=0xc0082000 CR4=0x00000000
00164721852i[CPU0 ] >> cld  : FC
00164721852p[CPU0 ] >>PANIC<< exception(): 3rd (14) exception with no resolution
but i know i have interrupts setup, i have a PageFault handler registered BUT i don't think that CR3's value is at all plausable as the code in the tutorial allocates some memory nearby, from what i understand. do i have this wrong? or could this be the problem?

Thanks in advance!

James.

Re: page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 2:13 pm
by Combuster
From the looks, the crash is caused by an external interrupt (cld can't cause an exception, and the IP doesn't match the fault address)

Could you doublecheck your IDT and GDT after reloading CR3

Re: page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 2:20 pm
by xDDunce
Thanks for the hasty reply :D

And, How would i go about doing that? would i just reload them, or is there any particular way of verifying their existence?

Thanks again!

James.

Re: page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 2:21 pm
by Combuster
tried bochs' debugger?

Re: page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 2:34 pm
by xDDunce
i have tried, but to no success. i have only ever used the bochslog file to fix errors, so bochs debugger is kinda new. i have tried it out, but never managed to do anything with the results to be honest.

but i'll give it another go.

Thanks.

Re: page fault when switching to cloned kernel directory

Posted: Mon Dec 15, 2008 4:03 pm
by tantrikwizard
http://bochs.sourceforge.net/doc/docboo ... ugger.html
type 'help' in the debugger for a list of commands. type 'help <command>' to get additional help on commands. type 'info idt' and 'info gdt' to view the IDT and GDT respectively

Re: page fault when switching to cloned kernel directory

Posted: Tue Dec 16, 2008 11:27 am
by xDDunce
thanks for the guidance, and in comparison to an ancient version of xD-OS, i have discovered the IDT and GDT are now empty.

so to fix it, should i just reload the GDT and IDT? or is there an error in my code somehwere?

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 9:08 am
by xDDunce
sorry guys, but i am really stuck now. no matter what i edit, i still get the same result. i have tried flushing the gdt and idt and anything i think may have a similar effect, but am i doomed for all eternity? or is it a simple fix which i'm just too stupid to see?

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 9:44 am
by jal
johnsy2008 wrote:sorry guys, but i am really stuck now. no matter what i edit, i still get the same result. i have tried flushing the gdt and idt and anything i think may have a similar effect, but am i doomed for all eternity? or is it a simple fix which i'm just too stupid to see?
It's difficult to say with this information, but you say your IDT and GDT are 'empty'. What do you mean by this? Is it the registers, or the actual tables? In the latter case, it seems obvious that you are mapping them out.


JAL

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 10:18 am
by xDDunce
well, upon running 'info gdt' and 'info idt' i find that each entry conatins the same data:

gdt:

Code: Select all

base = 0x00000000001080b0 limit = 23
gdt[0x00] = ??? descriptor hi = 0x00000000 lo = 0x00000000
gdt[0x01] = ??? descriptor hi = 0x00000000 lo - 0x00000000
etc...
idt:

Code: Select all

base = 0x00000000001080f0 limit = 2047
idt[0x00] = ??? descriptor hi = 0x00000000 lo = 0x00000000
idt[0x01] = ??? descriptor hi = 0x00000000 lo = 0x00000000
etc...
and this stays the same even if i flush them.

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 11:14 am
by Combuster
you can use the
info tab
command to get the state of paging.

The page mappings for the GDT and IDT seem to be no longer present, so either you're in higherhalf and you didn't tell the CPU to use the right address, or your page tables are off.

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 3:53 pm
by xDDunce
thanks combuster, but when i ran 'info tab' it over ran the screen so couldnt get all the info i needed. is there anyway around this?

Re: page fault when switching to cloned kernel directory

Posted: Thu Dec 18, 2008 5:16 pm
by Combuster
have bochs log to a file rather than the console.
But I think you can see from the last set of entries whether they are correct or not. (I expect CR3 to be pointing to garbage)

Re: page fault when switching to cloned kernel directory

Posted: Sat Dec 20, 2008 1:08 pm
by xDDunce
ok, so now info tab returns "CR3: 0x107ff8" and info IDT/GDT both return invalid pointers to memory addresses, which of course will be caused by the invalid CR3 value, but i know for a fact that my IDT (or atleast the page tables) is at physical address 0x107ff8, or does this have to be page aligned?

i know that info tab returns the value of CR3 because there are no pages in the page directory. and then because of this the IDT and GDT are false. but as far as i am aware, EVERY page is being copied.

Re: page fault when switching to cloned kernel directory

Posted: Sat Dec 20, 2008 6:07 pm
by Owen
Page directories must be page aligned, IIRC. And even if they don't have to be, theyre probably better off aligned