Triple Fault after adding declarations to kernel

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
ajmoritz
Posts: 1
Joined: Wed Jul 09, 2025 11:35 pm

Triple Fault after adding declarations to kernel

Post by ajmoritz »

Hello all,

While writing some of my kernel, after just creating another function in the code, without even executing the function, I started triple faulting. Using qemu, having it dump interupts (although my idt doesn't have the chance to get initialized when I TF), I get this

Code: Select all

check_exception old: 0xffffffff new 0xe
     0: v=0e e=0000 i=0 cpl=0 IP=0010:c01044ca pc=c01044ca SP=0018:c010eab8 CR2=c010f570
EAX=c010f570 EBX=0010f570 ECX=c010ea30 EDX=000000a1
ESI=0010f000 EDI=0010943c EBP=c010eae0 ESP=c010eab8
EIP=c01044ca EFL=00200082 [--S----] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0010 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000010b0 00000020
IDT=     00000000 00000000
CR0=80000011 CR2=c010f570 CR3=00108000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000010 CCD=c010eaa8 CCO=ADDL
EFER=0000000000000000
check_exception old: 0xe new 0xd
     1: v=08 e=0000 i=0 cpl=0 IP=0010:c01044ca pc=c01044ca SP=0018:c010eab8 env->regs[R_EAX]=c010f570
EAX=c010f570 EBX=0010f570 ECX=c010ea30 EDX=000000a1
ESI=0010f000 EDI=0010943c EBP=c010eae0 ESP=c010eab8
EIP=c01044ca EFL=00200082 [--S----] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0010 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0018 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000010b0 00000020
IDT=     00000000 00000000
CR0=80000011 CR2=c010f570 CR3=00108000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000010 CCD=c010eaa8 CCO=ADDL
EFER=0000000000000000
check_exception old: 0x8 new 0xd
Now so far what I've found is this happens for all extra declarations such as global variables. I also realize this is a page fault as cr2 has that address in it, and looking through the page table I can see my kernel only maps through 0xc010e000. Now the part which I am confused on is my kernel WILL map past 0xc010f570 as long as I don't go over the "allotted" symbol amount. Another thing I've noticed is if I comment out a few lines of my code, it will work fine. It doesn't really matter what lines.

I've been able to trace this to just calling the function pg_init in my code, but it never gets the chance to execute any code.
Looking at the instruction, it is just

Code: Select all

mov %eax, (%eax)
, which is why the value is eax is the same as cr0.

The only reason I can see is my kernel being too big, and the code going over the 4mb initial paging, although checking the size of the kernel when a triple fault happens (I logged by stopping the page fault by using an inline infinite loop) and when one doesn't yields the same size of 0xeaf0. I have tried increasing and decreasing the stack size, but that has made no noticeable effect.

Any ideas of what this could be? Or are my suspicions correct and I need to somehow increase the available memory to load in my kernel (Not super sure on how I'd do this yet).

This is a 32-bit kernel and my first attempt, so things are not optimal.
Github link: https://github.com/ajmoritz2/wordOS
(Hopefully my code is readable enough, I apologize for any troubles)
Post Reply