Page 1 of 1

Triple Fault when changing the page directory

Posted: Fri Feb 06, 2009 1:35 am
by ChristianF
Hello Community,
I have a problem with paging and Multitasking.
With my process management class i can create processes. So this method creates a process with one thread and a page directory.

Everything works fine till the C-Style Function "schedule" have to switch to the third process.
After switching to this page directory within the third process the triple fault occurs (page fault) and I don't know why this page fault occurs...
The method which creates a page directory, allocate a page, set this page to 0 and copies the kernel page directory.
I hope someone could help me because I actually don't find the error...

This is what bochs prints out, and I found the place where it faults. It faults directly after activating the different page directory.
Bochs Output wrote: 00020958405d[CPU0 ] MOV_CdRd:CR3 = 01ef2000
00020958406d[CPU0 ] page walk for address 0x0000000000104565
00020958406d[CPU0 ] PDE: entry not present
00020958406d[CPU0 ] page fault for address 0000000000104565 @ 0000000000104565
00020958406d[CPU0 ] exception(0x0e): error_code=0000
00020958406d[CPU0 ] interrupt(): vector = 14, INT = 0, EXT = 1
00020958406d[CPU0 ] page walk for address 0x000000000010a7d0
00020958406d[CPU0 ] PDE: entry not present
00020958406d[CPU0 ] page fault for address 000000000010a7d0 @ 0000000000104565
00020958406d[CPU0 ] exception(0x0e): error_code=0000
00020958406d[CPU0 ] exception(0x08): error_code=0000
00020958406d[CPU0 ] interrupt(): vector = 8, INT = 0, EXT = 1
00020958406d[CPU0 ] page walk for address 0x000000000010a7a0
00020958406d[CPU0 ] PDE: entry not present
00020958406d[CPU0 ] page fault for address 000000000010a7a0 @ 0000000000104565
00020958406d[CPU0 ] exception(0x0e): error_code=0000
00020958406i[CPU0 ] CPU is in protected mode (active)
00020958406i[CPU0 ] CS.d_b = 32 bit
00020958406i[CPU0 ] SS.d_b = 32 bit
00020958406i[CPU0 ] EFER = 0x00000000
00020958406i[CPU0 ] | RAX=000000000010cfc8 RBX=0000000001ef2000
00020958406i[CPU0 ] | RCX=00000000000b8000 RDX=00000000000003d5
00020958406i[CPU0 ] | RSP=00000000d0002f78 RBP=00000000d0002fc4
00020958406i[CPU0 ] | RSI=0000000001ef2000 RDI=00000000c000221d
00020958406i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00020958406i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00020958406i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00020958406i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00020958406i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00020958406i[CPU0 ] | SEG selector base limit G D
00020958406i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00020958406i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00020958406i[CPU0 ] | MSR_FS_BASE:0000000000000000
00020958406i[CPU0 ] | MSR_GS_BASE:0000000000000000
00020958406i[CPU0 ] | RIP=0000000000104565 (0000000000104565)
00020958406i[CPU0 ] | CR0=0xe0000011 CR1=0x0 CR2=0x000000000010a7a0
00020958406i[CPU0 ] | CR3=0x01ef2000 CR4=0x00000000
00020958406i[CPU0 ] (instruction unavailable) page not present
00020958406d[CTRL ] searching for component 'cpu' in list 'bochs'
00020958406d[CTRL ] searching for component 'reset_on_triple_fault' in list 'cpu'
00020958406e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00020958406i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called

Here is the Sourcecode of my Kernel... I hope someone has time to look at it:
OS Source (*.zip)

Re: Triple Fault when changing the page directory

Posted: Fri Feb 06, 2009 6:21 am
by AndrewAPrice
I don't have time to look through your source at the moment, but these are a lot of common problems that cause this:
- You're writing virtual addresses, not the physical addresses, into CR3 or your page directory/table.
- The code you're currently executing exists does not exist at the same location in virtual memory after you write your new page directory.
- You're forgetting to set the present bit in your page directory/table entries.

In this case, the triple fault was an unhandled page fault. That means that your interrupt handling code also does not exist at the same virtual address as it was before you switched to the new page directory.