More work on x86_64 build, error handling and IDT
[tpg/acess2.git] / Kernel / arch / x86_64 / errors.c
1 /*
2  * Acess2 x86_64 Project
3  * - Error Handling
4  */
5 #include <acess.h>
6 #include <proc.h>
7
8 // === PROTOTYPES ===
9 void    Error_Handler(tRegs *Regs);
10
11 // === GLOBALS ==
12 const char * const csaERROR_NAMES[] = {
13         "Divide By Zero", "Debug", "NMI Exception", "INT3",
14         "INTO", "Out of Bounds", "Invalid Opcode", "Coprocessor not avaliable",
15         "Double Fault", "Coprocessor Segment Overrun", "Bad TSS", "Segment Not Present",
16         "Stack Fault Exception", "GPF", "#PF", "Reserved",
17         "Floating Point Exception", "Alignment Check Exception", "Machine Check Exception",     "Reserved",
18         "Reserved", "Reserved", "Reserved", "Reserved",
19         "Reserved", "Reserved", "Reserved", "Reserved",
20         "Reserved", "Reserved", "Reserved", "Reserved"
21         };
22
23 // === CODE ===
24 void Error_Handler(tRegs *Regs)
25 {
26         Uint    cr;
27         
28         Debug_KernelPanic();
29         
30         Warning("CPU Error %i - %s, Code: 0x%x",
31                 Regs->IntNum, csaERROR_NAMES[Regs->IntNum], Regs->ErrorCode);
32         Warning(" CS:RIP = 0x%04x:%016x", Regs->CS, Regs->RIP);
33         Warning(" SS:RSP = 0x%04x:%016x", Regs->SS, Regs->RIP);
34         Warning(" RFLAGS = 0x%016x", Regs->RFlags);
35         Warning(" EAX %016x ECX %016x EDX %016x EBX %016x",
36                 Regs->RAX, Regs->RCX, Regs->RDX, Regs->RBX);
37         Warning(" ESP %016x EBP %016x ESI %016x EDI %016x",
38                 Regs->RSP, Regs->RBP, Regs->RSP, Regs->RDI);
39         
40         Warning(" FS %04x GS %04x", Regs->FS, Regs->GS);
41         
42         
43         // Control Registers
44         __asm__ __volatile__ ("mov %%cr0, %0":"=r"(cr));
45         Warning(" CR0 0x%08x", cr);
46         __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr));
47         Warning(" CR2 0x%08x", cr);
48         __asm__ __volatile__ ("mov %%cr3, %0":"=r"(cr));
49         Warning(" CR3 0x%08x", cr);
50         __asm__ __volatile__ ("mov %%cr4, %0":"=r"(cr));
51         Warning(" CR4 0x%08x", cr);
52         
53         switch( Regs->IntNum )
54         {
55         case 6: // #UD
56                 Warning(" Offending bytes: %02x %02x %02x %02x",
57                         *(Uint8*)Regs->RIP+0, *(Uint8*)Regs->RIP+1,
58                         *(Uint8*)Regs->RIP+2, *(Uint8*)Regs->RIP+3);
59                 break;
60         }
61         
62         for(;;)
63                 __asm__ __volatile__ ("hlt");
64 }

UCC git Repository :: git.ucc.asn.au