00001
00002
00003 #ifndef _CORE_COMMON_ERROR_HPP
00004 #define _CORE_COMMON_ERROR_HPP
00005
00010 #define STACK_TRACE_DUMP_ARGS 0
00011
00012
00021
00022 void panic() __attribute__ ((noreturn));
00023
00024
00025
00026
00027
00028
00029 const uint32 PORT_E9 = 0xe9;
00030
00031
00034 void init_dbg_val_map();
00035 uint32 get_dbg_val(uint32 key);
00036 bool set_dbg_val(uint32 key, uint32 val);
00037
00038 struct eip_ebp {
00039 uint32 eip;
00040 uint32 ebp;
00041 };
00042
00043
00044 #include "src/tty/teletype.hpp"
00045
00046 void debug_dump_call_trace(uint32 eip, uint32 addr);
00047 void debug_dump_call_trace();
00048 #define save_eip_ebp(x) do { asm volatile("x: movl $x, %0\nmovl %%ebp, %1":"=g"((x).eip),"=g"((x).ebp)); } while(0)
00049
00050
00051 void put_bochs(char ch);
00052 void write_bochs(const char *text);
00053 void write_bochs(int i);
00054 void write_bochs_num(uint32 n, uint32 radix, uint32 n_pos, char first_letter);
00055 inline void alert(const char *text)
00056 {
00057 write_bochs(text);
00058 cout(const_cast<char*>(text));
00059 }
00060
00061 inline void alert(int i)
00062 {
00063 write_bochs(i);
00064 cout(i);
00065 }
00066 inline void alert2(uint32 i)
00067 {
00068 write_bochs_num(i,10,1000000000,0);
00069 coutDec(i);
00070 }
00071
00072 #define complain(text) do {\
00073 alert((char*)__FILE__);\
00074 alert(": line ");\
00075 alert2(__LINE__);\
00076 alert(": "); \
00077 alert(text); \
00078 alert("\n"); \
00079 } while (0)
00080
00081 #define assert(val) do { if (!(val)) {complain("assertion fail"); for(;;);} } while (0)
00082 #define assertmsg(val,msg) do { if (!(val)) {complain(msg); for(;;);} } while (0)
00083 #define testif(val) do { if (!(val)) {complain("tesif fail"); } } while(0)
00084 #define testifmsg(val,msg) do { if (!(val)) {complain(msg); } } while (0)
00085 #define testifdbg(val) do { if (!(val)) {complain("tesifdbg fail"); } } while(0)
00086 #define testifdbgmsg(val,msg) do { if (!(val)) {complain(msg); } } while (0)
00087
00088 #define lnDbg do { alert("<< ");alert(__func__);alert(" : "); coutDec(__LINE__);write_bochs_num(__LINE__,10,10000,0); alert(">> \n");} while(0)
00089
00090 #define lnDb1 do { alert("<< ");alert(__func__);alert(" : "); coutDec(__LINE__);write_bochs_num(__LINE__,10,10000,0); alert(">> \n");} while(0)
00091
00092 #define lnDb2 do { alert("<< ");alert(__func__);alert(" : "); coutDec(__LINE__); write_bochs_num(__LINE__,10,10000,0); alert(">> \n");} while(0)
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #define say(...) do {\
00104 cout((char*)__FILE__);\
00105 cout(": ");\
00106 cout((char*)__func__);\
00107 cout(": "); \
00108 kprintf_alert(__VA_ARGS__);\
00109 cout("\n");\
00110 } while (0)
00111
00112 extern uint32 sysfail_dbg;
00113 #define sbg do {sysfail_dbg=__LINE__;} while(0)
00114 #define sysfail(reason) do {\
00115 alert("\n");\
00116 complain(reason);\
00117 if (sysfail_dbg) complain(sysfail_dbg); \
00118 panic();\
00119 } while(0)
00120
00121
00122 #define notimpl(ret) do { sysfail("not implemented"); return ret; } while(0)
00123
00124 #endif