page fault when switching to cloned kernel directory

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
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

page fault when switching to cloned kernel directory

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: page fault when switching to cloned kernel directory

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: page fault when switching to cloned kernel directory

Post by Combuster »

tried bochs' debugger?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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.
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: page fault when switching to cloned kernel directory

Post 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
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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?
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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?
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: page fault when switching to cloned kernel directory

Post 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
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: page fault when switching to cloned kernel directory

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: page fault when switching to cloned kernel directory

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: page fault when switching to cloned kernel directory

Post 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.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: page fault when switching to cloned kernel directory

Post by Owen »

Page directories must be page aligned, IIRC. And even if they don't have to be, theyre probably better off aligned
Post Reply