[solved]Triple fault after pageing is enabled

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.
Post Reply
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

[solved]Triple fault after pageing is enabled

Post by dukedevon »

After enabling pageing I get a triple fault.
The pagetable looks like this:

Code: Select all

0x00000000-0x00109fff -> 0x00000000-0x00109fff
bochs issues the following assembler commands before crashing:

Code: Select all

mov cr0, eax      <<<---- After that I get the page table
leave                 <<<---- Here the triple fault happens
If I try to issue another command before the leave, it also crashes right after mov cr0, eax.
I am not really firm with pagetables, does mine look convenient?

Thanks in advance
dukedevon
Last edited by dukedevon on Sat Jul 24, 2010 6:39 am, edited 1 time in total.
FlExOS --- Stay tuned ;-)
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: Triple fault after pageing is enabled - Pagetable broken

Post by Combuster »

Is that pagingdump the same at the crashing instruction? What's the pagefault address?
"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
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

Re: Triple fault after pageing is enabled - Pagetable broken

Post by dukedevon »

Combuster wrote:Is that pagingdump the same at the crashing instruction? What's the pagefault address?
I changed my code a little. I followed http://www.osdever.net/tutorials/view/i ... sic-paging to make it easier for me to understand the whole thing.

Now the pagetable looks like this before the crash:

Code: Select all

0x00000000-0x003fffff -> 0x00000000-0x003fffff
After the crash, bochs dumps the following information:

Code: Select all

00022873145i[CPU0 ] CPU is in protected mode (active)
00022873145i[CPU0 ] CS.d_b = 32 bit
00022873145i[CPU0 ] SS.d_b = 32 bit
00022873145i[CPU0 ] EFER   = 0x00000000
00022873145i[CPU0 ] | RAX=00000000e0000011  RBX=0000000000103004
00022873145i[CPU0 ] | RCX=00000000000b0030  RDX=00000000000003d5
00022873145i[CPU0 ] | RSP=0000000001feff84  RBP=0000000001feff84
00022873145i[CPU0 ] | RSI=0000000000000000  RDI=0000000000000000
00022873145i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00022873145i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00022873145i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00022873145i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00022873145i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf SF zf af PF cf
00022873145i[CPU0 ] | SEG selector     base    limit G D
00022873145i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00022873145i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00022873145i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00022873145i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00022873145i[CPU0 ] | RIP=00000000001003a5 (00000000001003a5)
00022873145i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000001feff80
00022873145i[CPU0 ] | CR3=0x0009c000 CR4=0x00000000
00022873145e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
CR3 contains the address i assigned it to, so that looks fine.

I get 0x1feff80 as the faulting address. What do I do with that information?

Thanks in advance
dukedevon
FlExOS --- Stay tuned ;-)
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Triple fault after pageing is enabled - Pagetable broken

Post by xenos »

dukedevon wrote:

Code: Select all

0x00000000-0x003fffff -> 0x00000000-0x003fffff
So you identity-map the first 4 MB. Fine.
I get 0x1feff80 as the faulting address. What do I do with that information?
This is the virtual address that causes the page fault, i.e. some instruction tried to access memory at virtual address 0x1feff80. Obviously this must fail, because you did not map anything to that address. It's far beyond your 4 MB.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

Re: Triple fault after pageing is enabled - Pagetable broken

Post by dukedevon »

XenOS wrote: This is the virtual address that causes the page fault, i.e. some instruction tried to access memory at virtual address 0x1feff80. Obviously this must fail, because you did not map anything to that address. It's far beyond your 4 MB.
I can figure that out, but I don't know how to fix this.
The command that causes the crash is the last of the following

Code: Select all

mov cr0, eax   <<<------ This one works fine
pop ebp          <<<------ This one crashes
after the mov the regs look like this:

Code: Select all

CPU0:
rax: 0x00000000:e0000011 rcx: 0x00000000:000b0030
rdx: 0x00000000:000003d5 rbx: 0x00000000:00103004
rsp: 0x00000000:01feff84 rbp: 0x00000000:01feff84
rsi: 0x00000000:00000000 rdi: 0x00000000:00000000
r8 : 0x00000000:00000000 r9 : 0x00000000:00000000
r10: 0x00000000:00000000 r11: 0x00000000:00000000
r12: 0x00000000:00000000 r13: 0x00000000:00000000
r14: 0x00000000:00000000 r15: 0x00000000:00000000
rip: 0x00000000:001003a5
eflags 0x00000286: id vip vif ac vm rf nt IOPL=0 of df IF tf SF zf af PF cf
creg:

Code: Select all

CR0=0xe0000011: PG CD NW ac wp ne ET ts em mp PE
CR2=page fault laddr=0x0000000000000000
CR3=0x0019c000
    PCD=page-level cache disable=0
    PWT=page-level write-through=0
CR4=0x00000000: osxsave pcid smx vmx osxmmexcpt osfxsr pce pge mce pae pse de tsd pvi vme
EFER=0x00000000: ffxsr nxe lma lme sce
Is my stack broken?
What can I do to fix the issue?
Last edited by dukedevon on Wed May 25, 2011 11:34 am, edited 1 time in total.
FlExOS --- Stay tuned ;-)
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Triple fault after pageing is enabled - Pagetable broken

Post by gerryg400 »

Is my stack broken?
Modify your code so that the instruction after mov to cr0 doesn't touch the stack. Then you will know.
If a trainstation is where trains stop, what is a workstation ?
User avatar
dukedevon
Posts: 21
Joined: Thu Jul 08, 2010 10:02 am
Location: Karlsruhe, Germany
Contact:

Re: Triple fault after pageing is enabled - Pagetable broken

Post by dukedevon »

gerryg400 wrote:
Is my stack broken?
Modify your code so that the instruction after mov to cr0 doesn't touch the stack. Then you will know.
Thanks, that helped me a lot. Figured out I didn't even declare a sys_stack in my loader.s #-o
I wonder how I got this far...
Thanks a lot, I would be totally lost without this forum!!!
Thank you for being so tolerant towards my stupid newbie questions.
FlExOS --- Stay tuned ;-)
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: [solved]Triple fault after pageing is enabled

Post by Combuster »

Are you passing -i or -r to the linker? They stop it from emitting errors for missing symbols (as well as generating a wrong binary), yet some braindead tutorials (and occasionally other members) advocate its use.
"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 ]
Post Reply