* arch/x86/errors.c
* - CPU Error Handler
*/
-#include <common.h>
+#include <acess.h>
+#include <proc.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 Proc_DumpThreads();
+extern void Threads_Dump();
+
+// === PROTOTYPES ===
+void Error_Backtrace(Uint eip, Uint ebp);
// === CODE ===
+void __stack_chk_fail()
+{
+ Panic("FATAL ERROR: Stack Check Failed\n");
+ for(;;);
+}
+
/**
* \fn void ErrorHandler(tRegs *Regs)
* \brief General Error Handler
__asm__ __volatile__ ("mov %%cr3, %0":"=r"(cr));
Warning(" CR3: 0x%08x", cr);
+ // Print Stack Backtrace
+ Error_Backtrace(Regs->eip, Regs->ebp);
+
// Dump running threads
- Proc_DumpThreads();
+ Threads_Dump();
for(;;) __asm__ __volatile__ ("hlt");
}
+/**
+ * \fn void Error_Backtrace(Uint eip, Uint ebp)
+ * \brief Unrolls the stack to trace execution
+ */
+void Error_Backtrace(Uint eip, Uint ebp)
+{
+ int i = 0;
+ Uint delta = 0;
+ char *str = NULL;
+
+ //if(eip < 0xC0000000 && eip > 0x1000)
+ //{
+ // LogF("Backtrace: User - 0x%x\n", eip);
+ // return;
+ //}
+
+ if(eip > 0xE0000000)
+ {
+ LogF("Backtrace: Data Area - 0x%x\n", eip);
+ return;
+ }
+
+ if(eip > 0xC8000000)
+ {
+ LogF("Backtrace: Kernel Module - 0x%x\n", eip);
+ return;
+ }
+
+ //str = Debug_GetSymbol(eip, &delta);
+ if(str == NULL)
+ LogF("Backtrace: 0x%x", eip);
+ else
+ LogF("Backtrace: %s+0x%x", str, delta);
+ if(!MM_GetPhysAddr(ebp))
+ {
+ LogF("\nBacktrace: Invalid EBP, stopping\n");
+ return;
+ }
+
+
+ while( MM_GetPhysAddr(ebp) && i < MAX_BACKTRACE )
+ {
+ //str = Debug_GetSymbol(*(Uint*)(ebp+4), &delta);
+ if(str == NULL)
+ LogF(" >> 0x%x", *(Uint*)(ebp+4));
+ else
+ LogF(" >> %s+0x%x", str, delta);
+ ebp = *(Uint*)ebp;
+ i++;
+ }
+ LogF("\n");
+}
+
+/**
+ * \fn void StartupPrint(char *Str)
+ */
+void StartupPrint(char *Str)
+{
+ Uint16 *buf = (void*)0xC00B8000;
+ int i = 0;
+ static int line = 0;
+ while(*Str)
+ {
+ buf[line*80 + i++] = *Str | 0x0700;
+ Str ++;
+ }
+
+ while(i < 80) buf[line*80 + i++] = 0x0720;
+
+ line ++;
+ if(line == 25)
+ {
+ line --;
+ memcpy(buf, &buf[80], 80*24*2);
+ memset(&buf[80*24], 0, 80*2);
+ }
+}
+
+// === EXPORTS ===
+EXPORT(__stack_chk_fail);