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 
00041 #include <interrupt.h>
00042 #include <debug.h>
00043 #include <console/kconsole.h>
00044 #include <console/console.h>
00045 #include <console/chardev.h>
00046 #include <console/cmd.h>
00047 #include <panic.h>
00048 #include <print.h>
00049 #include <symtab.h>
00050 
00051 static struct {
00052         const char *name;
00053         iroutine f;
00054 } exc_table[IVT_ITEMS];
00055 
00056 SPINLOCK_INITIALIZE(exctbl_lock);
00057 
00064 iroutine exc_register(int n, const char *name, iroutine f)
00065 {
00066         ASSERT(n < IVT_ITEMS);
00067         
00068         iroutine old;
00069         
00070         spinlock_lock(&exctbl_lock);
00071 
00072         old = exc_table[n].f;
00073         exc_table[n].f = f;
00074         exc_table[n].name = name;
00075 
00076         spinlock_unlock(&exctbl_lock);  
00077 
00078         return old;
00079 }
00080 
00086 void exc_dispatch(int n, istate_t *istate)
00087 {
00088         ASSERT(n < IVT_ITEMS);
00089         
00090         exc_table[n].f(n + IVT_FIRST, istate);
00091         
00092         if (THREAD && THREAD->interrupted && istate_from_uspace(istate))
00093                 thread_exit();
00094 }
00095 
00097 static void exc_undef(int n, istate_t *istate)
00098 {
00099         fault_if_from_uspace(istate, "Unhandled exception %d.", n);
00100         panic("Unhandled exception %d.", n);
00101 }
00102 
00104 static int exc_print_cmd(cmd_arg_t *argv)
00105 {
00106         int i;
00107         char *symbol;
00108 
00109         spinlock_lock(&exctbl_lock);
00110         printf("Exc Description Handler\n");
00111         for (i=0; i < IVT_ITEMS; i++) {
00112                 symbol = get_symtab_entry((__native)exc_table[i].f);
00113                 if (!symbol)
00114                         symbol = "not found";
00115                 printf("%d %s %.*p(%s)\n", i + IVT_FIRST, exc_table[i].name,
00116                        sizeof(__address) * 2, exc_table[i].f,symbol);           
00117                 if (!((i+1) % 20)) {
00118                         printf("Press any key to continue.");
00119                         spinlock_unlock(&exctbl_lock);
00120                         getc(stdin);
00121                         spinlock_lock(&exctbl_lock);
00122                         printf("\n");
00123                 }
00124         }
00125         spinlock_unlock(&exctbl_lock);
00126         
00127         return 1;
00128 }
00129 
00130 static cmd_info_t exc_info = {
00131         .name = "exc",
00132         .description = "Print exception table.",
00133         .func = exc_print_cmd,
00134         .help = NULL,
00135         .argc = 0,
00136         .argv = NULL
00137 };
00138 
00140 void exc_init(void)
00141 {
00142         int i;
00143 
00144         for (i=0;i < IVT_ITEMS; i++)
00145                 exc_register(i, "undef", (iroutine) exc_undef);
00146 
00147         cmd_initialize(&exc_info);
00148         if (!cmd_register(&exc_info))
00149                 panic("could not register command %s\n", exc_info.name);
00150 }
00151 
00152