luxos/Kernel/hal/crash.c~
Tiberiu Chibici 913e65b856 [GOOD] BUILD 0.1.0.450 DATE 8/29/2011 AT 10:30 AM
====================================================
+ Changed 'align 0x4' line above multiboot header in loader.asm to
'align 4'
+ Removed -e option for echo in build.sh
+ Modified build.sh for linux
+ Fixed triple fault when enabling paging
+ Fixed page faults at memory manager initialization
+ Fixed 'mem' console function
+ Added more info about page fault at crash screen
+ Added Panic() macro
+ Added verbose mode for memory manager

[ BAD] BUILD 0.1.0.390 DATE 8/27/2011 AT 10:54 PM
====================================================
+ Added stdlib routines, separated in different files
+ Rewritten physical memory manager
+ Added virtual mem manager
+ Added memory allocation/freeing
+ Added memory library
+ Added temporary allocation (at end of kernel), until paging is started
- Removed functionality from debug console function 'mem'
- Removed system.h, the one remaining function now in stdio.h
2021-09-14 18:48:57 +03:00

98 lines
3.2 KiB
C

/*
* crash.c
*
* Created on: Aug 19, 2011
* Author: Tiberiu
*/
#include <debugio.h>
string errorCodes[] =
{
"Division by zero", //0
"Debugger", //1
"Non maskable interrupt", //2
"Breakpoint", //3
"Overflow", //4
"Bounds", //5
"Invalid opcode", //6
"Coprocessor not available", //7
"Double fault", //8
"Coprocessor segment overrun",//9
"Invalid task state segment", //A
"Segment not present", //B
"Stack fault", //C
"General protection fault", //D
"Page fault", //E
"", //F
"Math fault", //10
"Alignment check", //11
"Machine check", //12
"SIMD floating-point exception" //13
};
void CrashMessage(_RegsStack32 *r)
{
ConsoleSetDefaultColor(ColorLightRed);
ConsoleWrite("\n"); uint32 i;
for (i = 0; i < 80; i++) ConsoleWrite("%c", 205);
ConsoleWrite("%#\t\t\t\tSomething went terribly wrong :(\n\n", ColorWhite);
ConsoleWrite("There was an unhandled exception: ");
if (r->int_no < 20)
ConsoleWrite("%#%s (INT%u)", ColorWhite, errorCodes[r->int_no], r->int_no);
else ConsoleWrite("%#INT%u", ColorWhite, r->int_no);
ConsoleWrite("\nTo protect your computer, it had to be halted.\n\n");
ConsoleWrite("Here, this might help find the problem:\n");
Point a = {4, -1}, b = {22, -1}, c = {40, -1}, d = {58, -1};
ConsoleSetDefaultColor(ColorWhite);
ConsoleCursorGoto(a); ConsoleWrite("eax=0x%x", r->eax);
ConsoleCursorGoto(b); ConsoleWrite("ebx=0x%x", r->ebx);
ConsoleCursorGoto(c); ConsoleWrite("ecx=0x%x", r->ecx);
ConsoleCursorGoto(d); ConsoleWrite("edx=0x%x\n", r->edx);
ConsoleCursorGoto(a); ConsoleWrite("edi=0x%x", r->edi);
ConsoleCursorGoto(b); ConsoleWrite("esi=0x%x", r->esi);
ConsoleCursorGoto(c); ConsoleWrite("ebp=0x%x", r->ebp);
ConsoleCursorGoto(d); ConsoleWrite("esp=0x%x\n", r->esp);
ConsoleCursorGoto(a); ConsoleWrite("gs=0x%x", r->gs);
ConsoleCursorGoto(b); ConsoleWrite("fs=0x%x", r->fs);
ConsoleCursorGoto(c); ConsoleWrite("es=0x%x", r->es);
ConsoleCursorGoto(d); ConsoleWrite("ds=0x%x\n", r->ds);
ConsoleCursorGoto(a); ConsoleWrite("eip=0x%x", r->eip);
ConsoleCursorGoto(b); ConsoleWrite("cs=0x%x", r->cs);
ConsoleCursorGoto(c); ConsoleWrite("eflags=0x%x", r->eflags);
ConsoleCursorGoto(d); ConsoleWrite("useresp=0x%x\n", r->useresp);
ConsoleCursorGoto(a); ConsoleWrite("gs=0x%x", r->ss);
ConsoleCursorGoto(b); ConsoleWrite("fs=0x%x", r->int_no);
ConsoleCursorGoto(c); ConsoleWrite("err_code=0x%x", r->err_code);
// Useful info about page fault
if (r->int_no == 0xE)
{
uint32 faulting_address;
asm volatile("mov %%cr2, %0" : "=r" (faulting_address));
ConsoleCursorGoto(d); ConsoleWrite("address=0x%x\n", faulting_address);
ConsoleCursorGoto(a); ConsoleWrite("reason: ");
if (!(r->err_code & 1)) ConsoleWrite("%#PAGE_NOT_PRESENT; ", ColorLightGray);
if (r->err_code & 2) ConsoleWrite("%#WRITE_OPERATION; ", ColorLightGray);
if (r->err_code & 4) ConsoleWrite("%#CPU_IN_USER_MODE; ", ColorLightGray);
if (r->err_code & 8) ConsoleWrite("%#CPU_RESERVED_PAGE_ENTRY_OVERWRITTEN; ", ColorLightGray);
if (r->err_code & 0x10) ConsoleWrite("%#INSTRUCTION_FETCH; ", ColorLightGray);
}
ConsoleSetDefaultColor(ColorLightRed);
ConsoleWrite("\n");
for (i = 0; i < 80; i++) ConsoleWrite("%c", 205);
}