00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <arch/exception.h>
00036 #include <arch/interrupt.h>
00037 #include <panic.h>
00038 #include <arch/cp0.h>
00039 #include <arch/types.h>
00040 #include <arch.h>
00041 #include <debug.h>
00042 #include <proc/thread.h>
00043 #include <symtab.h>
00044 #include <print.h>
00045 #include <interrupt.h>
00046 #include <func.h>
00047 #include <console/kconsole.h>
00048 #include <arch/debugger.h>
00049
00050 static char * exctable[] = {
00051 "Interrupt","TLB Modified","TLB Invalid","TLB Invalid Store",
00052 "Address Error - load/instr. fetch",
00053 "Address Error - store",
00054 "Bus Error - fetch instruction",
00055 "Bus Error - data reference",
00056 "Syscall",
00057 "BreakPoint",
00058 "Reserved Instruction",
00059 "Coprocessor Unusable",
00060 "Arithmetic Overflow",
00061 "Trap",
00062 "Virtual Coherency - instruction",
00063 "Floating Point",
00064 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00065 "WatchHi/WatchLo",
00066 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00067 "Virtual Coherency - data",
00068 };
00069
00070 static void print_regdump(istate_t *istate)
00071 {
00072 char *pcsymbol = "";
00073 char *rasymbol = "";
00074
00075 char *s = get_symtab_entry(istate->epc);
00076 if (s)
00077 pcsymbol = s;
00078 s = get_symtab_entry(istate->ra);
00079 if (s)
00080 rasymbol = s;
00081
00082 printf("PC: %#x(%s) RA: %#x(%s), SP(%p)\n", istate->epc, pcsymbol, istate->ra, rasymbol, istate->sp);
00083 }
00084
00085 static void unhandled_exception(int n, istate_t *istate)
00086 {
00087 fault_if_from_uspace(istate, "unhandled exception %s", exctable[n]);
00088
00089 print_regdump(istate);
00090 panic("unhandled exception %s\n", exctable[n]);
00091 }
00092
00093 static void reserved_instr_exception(int n, istate_t *istate)
00094 {
00095 if (*((__u32 *)istate->epc) == 0x7c03e83b) {
00096 ASSERT(THREAD);
00097 istate->epc += 4;
00098 istate->v1 = istate->k1;
00099 } else
00100 unhandled_exception(n, istate);
00101 }
00102
00103 static void breakpoint_exception(int n, istate_t *istate)
00104 {
00105 #ifdef CONFIG_DEBUG
00106 debugger_bpoint(istate);
00107 #else
00108
00109
00110
00111 istate->epc += 4;
00112 #endif
00113 }
00114
00115 static void tlbmod_exception(int n, istate_t *istate)
00116 {
00117 tlb_modified(istate);
00118 }
00119
00120 static void tlbinv_exception(int n, istate_t *istate)
00121 {
00122 tlb_invalid(istate);
00123 }
00124
00125 #ifdef CONFIG_FPU_LAZY
00126 static void cpuns_exception(int n, istate_t *istate)
00127 {
00128 if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id)
00129 scheduler_fpu_lazy_request();
00130 else {
00131 fault_if_from_uspace(istate, "unhandled Coprocessor Unusable Exception");
00132 panic("unhandled Coprocessor Unusable Exception\n");
00133 }
00134 }
00135 #endif
00136
00137 static void interrupt_exception(int n, istate_t *istate)
00138 {
00139 __u32 cause;
00140 int i;
00141
00142
00143 cause = (cp0_cause_read() >> 8) &0xff;
00144
00145 for (i = 0; i < 8; i++)
00146 if (cause & (1 << i))
00147 exc_dispatch(i+INT_OFFSET, istate);
00148 }
00149
00151 static void syscall_exception(int n, istate_t *istate)
00152 {
00153 panic("Syscall is handled through shortcut");
00154 }
00155
00156 void exception_init(void)
00157 {
00158 int i;
00159
00160
00161 for (i=0;i < IVT_ITEMS; i++)
00162 exc_register(i, "undef", (iroutine) unhandled_exception);
00163 exc_register(EXC_Bp, "bkpoint", (iroutine) breakpoint_exception);
00164 exc_register(EXC_RI, "resinstr", (iroutine) reserved_instr_exception);
00165 exc_register(EXC_Mod, "tlb_mod", (iroutine) tlbmod_exception);
00166 exc_register(EXC_TLBL, "tlbinvl", (iroutine) tlbinv_exception);
00167 exc_register(EXC_TLBS, "tlbinvl", (iroutine) tlbinv_exception);
00168 exc_register(EXC_Int, "interrupt", (iroutine) interrupt_exception);
00169 #ifdef CONFIG_FPU_LAZY
00170 exc_register(EXC_CpU, "cpunus", (iroutine) cpuns_exception);
00171 #endif
00172 exc_register(EXC_Sys, "syscall", (iroutine) syscall_exception);
00173 }
00174