Final version
This commit is contained in:
		@@ -1,97 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user