interrupt.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         /* This is a safe place to exit exiting thread */
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 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6