More work on error and interrupt handling (almost got it working)
[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         Log("CPU Error %x, Code: 0x%x", Regs->IntNum, Regs->ErrorCode);
31         Log(" - %s", csaERROR_NAMES[Regs->IntNum]);
32         Log(" CS:RIP = 0x%04x:%016x", Regs->CS, Regs->RIP);
33         Log(" SS:RSP = 0x%04x:%016x", Regs->SS, Regs->RSP);
34         Log(" RFLAGS = 0x%016x", Regs->RFlags);
35         
36         Log(" EAX %016x ECX %016x EDX %016x EBX %016x",
37                 Regs->RAX, Regs->RCX, Regs->RDX, Regs->RBX);
38         Log(" ESP %016x EBP %016x ESI %016x EDI %016x",
39                 Regs->RSP, Regs->RBP, Regs->RSP, Regs->RDI);
40         Log(" R8  %016x R9  %016x R10 %016x R11 %016x",
41                 Regs->R8, Regs->R9, Regs->R10, Regs->R11);
42         Log(" FS %04x GS %04x", Regs->FS, Regs->GS);
43         
44         
45         // Control Registers
46         __asm__ __volatile__ ("mov %%cr0, %0":"=r"(cr));
47         Warning(" CR0 0x%08x", cr);
48         __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr));
49         Warning(" CR2 0x%08x", cr);
50         __asm__ __volatile__ ("mov %%cr3, %0":"=r"(cr));
51         Warning(" CR3 0x%08x", cr);
52         __asm__ __volatile__ ("mov %%cr4, %0":"=r"(cr));
53         Warning(" CR4 0x%08x", cr);
54         
55         switch( Regs->IntNum )
56         {
57         case 6: // #UD
58                 Warning(" Offending bytes: %02x %02x %02x %02x",
59                         *(Uint8*)Regs->RIP+0, *(Uint8*)Regs->RIP+1,
60                         *(Uint8*)Regs->RIP+2, *(Uint8*)Regs->RIP+3);
61                 break;
62         }
63         
64         for(;;)
65                 __asm__ __volatile__ ("hlt");
66 }

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