2 * Acess2 x86_64 Project
9 #define MAX_BACKTRACE 6
12 void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs);
13 void Error_Backtrace(Uint IP, Uint BP);
16 void Error_Handler(tRegs *Regs);
19 const char * const csaERROR_NAMES[] = {
20 "Divide By Zero", "Debug", "NMI Exception", "INT3",
21 "INTO", "Out of Bounds", "Invalid Opcode", "Coprocessor not avaliable",
22 "Double Fault", "Coprocessor Segment Overrun", "Bad TSS", "Segment Not Present",
23 "Stack Fault Exception", "GPF", "#PF", "Reserved",
24 "Floating Point Exception", "Alignment Check Exception", "Machine Check Exception", "Reserved",
25 "Reserved", "Reserved", "Reserved", "Reserved",
26 "Reserved", "Reserved", "Reserved", "Reserved",
27 "Reserved", "Reserved", "Reserved", "Reserved"
31 void Error_Handler(tRegs *Regs)
35 if( Regs->IntNum == 14 ) {
36 __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr));
37 MM_PageFault(cr, Regs->ErrorCode, Regs);
43 Log("CPU Error %x, Code: 0x%x", Regs->IntNum, Regs->ErrorCode);
44 // Log(" - %s", csaERROR_NAMES[Regs->IntNum]);
45 Log(" CS:RIP = 0x%04x:%016llx", Regs->CS, Regs->RIP);
46 Log(" SS:RSP = 0x%04x:%016llx", Regs->SS, Regs->RSP);
47 Log(" RFLAGS = 0x%016llx", Regs->RFlags);
49 Log(" RAX %016llx RCX %016llx RDX %016llx RBX %016llx",
50 Regs->RAX, Regs->RCX, Regs->RDX, Regs->RBX);
51 Log(" RSP %016llx RBP %016llx RSI %016llx RDI %016llx",
52 Regs->RSP, Regs->RBP, Regs->RSP, Regs->RDI);
53 Log(" R8 %016llx R9 %016llx R10 %016llx R11 %016llx",
54 Regs->R8, Regs->R9, Regs->R10, Regs->R11);
55 Log(" R12 %016llx R13 %016llx R14 %016llx R15 %016llx",
56 Regs->R12, Regs->R13, Regs->R14, Regs->R15);
57 Log(" FS %04x GS %04x", Regs->FS, Regs->GS);
61 __asm__ __volatile__ ("mov %%cr0, %0":"=r"(cr));
62 Warning(" CR0 0x%08x", cr);
63 __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr));
64 Warning(" CR2 0x%016llx", cr);
65 __asm__ __volatile__ ("mov %%cr3, %0":"=r"(cr));
66 Warning(" CR3 0x%016llx", cr);
67 __asm__ __volatile__ ("mov %%cr4, %0":"=r"(cr));
68 Warning(" CR4 0x%08x", cr);
70 switch( Regs->IntNum )
73 Warning(" Offending bytes: %02x %02x %02x %02x",
74 *(Uint8*)(Regs->RIP+0), *(Uint8*)(Regs->RIP+1),
75 *(Uint8*)(Regs->RIP+2), *(Uint8*)(Regs->RIP+3)
80 __asm__ __volatile__ ("cli");
82 __asm__ __volatile__ ("hlt");
86 * \fn void Error_Backtrace(Uint eip, Uint ebp)
87 * \brief Unrolls the stack to trace execution
88 * \param eip Current Instruction Pointer
89 * \param ebp Current Base Pointer (Stack Frame)
91 void Error_Backtrace(Uint IP, Uint BP)
95 //if(eip < 0xC0000000 && eip > 0x1000)
97 // LogF("Backtrace: User - 0x%x\n", eip);
102 && IP < MM_KERNEL_CODE
103 && (MM_MODULE_MIN > IP || IP > MM_MODULE_MAX)
106 LogF("Backtrace: Data Area - %p\n", IP);
110 //str = Debug_GetSymbol(eip, &delta);
112 LogF("Backtrace: %p", IP);
114 // LogF("Backtrace: %s+0x%x", str, delta);
115 if( !MM_GetPhysAddr(BP) )
117 LogF("\nBacktrace: Invalid BP, stopping\n");
122 while( MM_GetPhysAddr(BP) && i < MAX_BACKTRACE )
124 //str = Debug_GetSymbol(*(Uint*)(ebp+4), &delta);
126 LogF(" >> 0x%llx", ((Uint*)BP)[1]);
128 // LogF(" >> %s+0x%x", str, delta);