Kernel/x86 - Cleaning up dead code
[tpg/acess2.git] / Kernel / arch / x86 / errors.c
index 22ad1a3..c1c3ae6 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include <acess.h>
 #include <proc.h>
+#include <mm_virt.h>
 
 // === CONSTANTS ===
 #define        MAX_BACKTRACE   8       //!< Maximum distance to trace the stack backwards
 // === IMPORTS ===
 extern void    MM_PageFault(Uint Addr, Uint ErrorCode, tRegs *Regs);
 extern void    VM8086_GPF(tRegs *Regs);
-extern void Threads_Dump(void);
+extern void    Threads_Dump(void);
 extern void    Threads_Fault(int Num);
 extern int     GetCPUNum(void);
+extern void    MM_DumpTables(tVAddr, tVAddr);
+extern void    Proc_EnableSSE(void);
+extern void    Proc_RestoreSSE(Uint32 Data);
 
 // === PROTOTYPES ===
 void   __stack_chk_fail(void);
 void   ErrorHandler(tRegs *Regs);
+void   Proc_PrintBacktrace(void);
 void   Error_Backtrace(Uint eip, Uint ebp);
 void   StartupPrint(char *Str);
 
 // === GLOBALS ===
 const char *csaERROR_NAMES[] = {
        "Divide By Zero", "Debug", "NMI Exception", "INT3",
-       "INTO", "Out of Bounds", "Invalid Opcode", "Coprocessor not avaliable",
+       "INTO Instr - Overflow", "BOUND Instr - Out of Bounds", "Invalid Opcode", "Coprocessor not avaliable",
        "Double Fault", "Coprocessor Segment Overrun", "Bad TSS", "Segment Not Present",
        "Stack Fault Exception", "GPF", "#PF", "Reserved",
        "Floating Point Exception", "Alignment Check Exception", "Machine Check Exception",     "Reserved",
@@ -75,10 +80,29 @@ void ErrorHandler(tRegs *Regs)
        // Page Fault
        if(Regs->int_num == 14)
        {
+               __asm__ __volatile__ ("sti");   // Should be OK, TODO: Test
                __asm__ __volatile__ ("mov %%cr2, %0":"=r"(cr));
                MM_PageFault( cr, Regs->err_code, Regs );
                return ;
        }
+
+       // #NM - Coprocessor unavaliable
+       if(Regs->int_num == 7)
+       {
+               tThread *thread = Proc_GetCurThread();
+               if(!thread->SavedState.bSSEModified)
+               {
+                       Proc_EnableSSE();
+                       if(!thread->SavedState.SSE)
+                               thread->SavedState.SSE = malloc(sizeof(tSSEState) + 0xF);
+                       else
+                               Proc_RestoreSSE( ((Uint)thread->SavedState.SSE + 0xF) & ~0xF );
+                       thread->SavedState.bSSEModified = 1;
+                       __asm__ __volatile__ ("sti");
+                       return ;
+               }
+               // oops, SSE enabled but a #NM, bad news
+       }
        
        // VM8086 GPF
        if(Regs->int_num == 13 && Regs->eflags & 0x20000)
@@ -93,6 +117,7 @@ void ErrorHandler(tRegs *Regs)
                        csaERROR_NAMES[Regs->int_num], Regs->err_code);
                Log_Warning("Arch", "at CS:EIP %04x:%08x",
                        Regs->cs, Regs->eip);
+               MM_DumpTables(0, KERNEL_BASE);
                switch( Regs->int_num )
                {
                // Division by Zero
@@ -157,6 +182,14 @@ void ErrorHandler(tRegs *Regs)
        
        for(;;) __asm__ __volatile__ ("hlt");
 }
+
+void Proc_PrintBacktrace(void)
+{
+       Uint32  ebp;
+       __asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp));
+       Error_Backtrace( *(Uint32*)(ebp+4), *(Uint32*)ebp );
+}
+
 /**
  * \fn void Error_Backtrace(Uint eip, Uint ebp)
  * \brief Unrolls the stack to trace execution
@@ -166,8 +199,8 @@ void ErrorHandler(tRegs *Regs)
 void Error_Backtrace(Uint eip, Uint ebp)
 {
         int    i = 0;
-       Uint    delta = 0;
-       char    *str = NULL;
+//     Uint    delta = 0;
+//     char    *str = NULL;
        
        //if(eip < 0xC0000000 && eip > 0x1000)
        //{
@@ -188,10 +221,10 @@ void Error_Backtrace(Uint eip, Uint ebp)
        }
        
        //str = Debug_GetSymbol(eip, &delta);
-       if(str == NULL)
+//     if(str == NULL)
                LogF("Backtrace: 0x%x", eip);
-       else
-               LogF("Backtrace: %s+0x%x", str, delta);
+//     else
+//             LogF("Backtrace: %s+0x%x", str, delta);
        if(!MM_GetPhysAddr(ebp))
        {
                LogF("\nBacktrace: Invalid EBP, stopping\n");
@@ -201,11 +234,12 @@ void Error_Backtrace(Uint eip, Uint ebp)
        
        while( MM_GetPhysAddr(ebp) && i < MAX_BACKTRACE )
        {
+               if( ebp >= MM_KERNEL_STACKS_END )       break;
                //str = Debug_GetSymbol(*(Uint*)(ebp+4), &delta);
-               if(str == NULL)
+//             if(str == NULL)
                        LogF(" >> 0x%x", *(Uint*)(ebp+4));
-               else
-                       LogF(" >> %s+0x%x", str, delta);
+//             else
+//                     LogF(" >> %s+0x%x", str, delta);
                ebp = *(Uint*)ebp;
                i++;
        }

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