Subversion Repositories HelenOS-historic

Rev

Rev 575 | Rev 579 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 575 Rev 578
Line 26... Line 26...
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include <interrupt.h>
29
#include <interrupt.h>
30
#include <debug.h>
30
#include <debug.h>
-
 
31
#include <console/kconsole.h>
-
 
32
#include <console/console.h>
-
 
33
#include <console/chardev.h>
-
 
34
#include <panic.h>
-
 
35
#include <print.h>
-
 
36
#include <symtab.h>
31
 
37
 
32
static struct {
38
static struct {
33
    char *name;
39
    const char *name;
34
    iroutine f;
40
    iroutine f;
35
} ivt[IVT_ITEMS];
41
} exc_table[IVT_ITEMS];
36
 
42
 
-
 
43
static spinlock_t exctbl_lock;
-
 
44
 
-
 
45
/** Register exception handler
-
 
46
 *
-
 
47
 * @param n Exception number
-
 
48
 * @param name Description
-
 
49
 * @param f Exception handler
-
 
50
 */
37
iroutine exc_register(int n, char *name, iroutine f)
51
iroutine exc_register(int n, const char *name, iroutine f)
38
{
52
{
39
    ASSERT(n < IVT_ITEMS);
53
    ASSERT(n < IVT_ITEMS);
40
   
54
   
41
    iroutine old;
55
    iroutine old;
42
   
56
   
-
 
57
    spinlock_lock(&exctbl_lock);
-
 
58
 
43
    old = ivt[n].f;
59
    old = exc_table[n].f;
44
    ivt[n].f = f;
60
    exc_table[n].f = f;
45
    ivt[n].name = name;
61
    exc_table[n].name = name;
-
 
62
 
-
 
63
    spinlock_unlock(&exctbl_lock); 
46
   
64
 
47
    return old;
65
    return old;
48
}
66
}
49
 
67
 
-
 
68
/** Dispatch exception according to exception table
50
/*
69
 *
51
 * Called directly from the assembler code.
70
 * Called directly from the assembler code.
52
 * CPU is interrupts_disable()'d.
71
 * CPU is interrupts_disable()'d.
53
 */
72
 */
54
void exc_dispatch(int n, void *stack)
73
void exc_dispatch(int n, void *stack)
55
{
74
{
56
    ASSERT(n < IVT_ITEMS);
75
    ASSERT(n < IVT_ITEMS);
57
   
76
   
58
    ivt[n].f(n, stack);
77
    exc_table[n].f(n, stack);
-
 
78
}
-
 
79
 
-
 
80
/** Default 'null' exception handler */
-
 
81
static void exc_undef(int n, void *stack)
-
 
82
{
-
 
83
    panic("Unhandled exception %d.", n);
-
 
84
}
-
 
85
 
-
 
86
/** KConsole cmd - print all exceptions */
-
 
87
static int exc_print_cmd(cmd_arg_t *argv)
-
 
88
{
-
 
89
    int i;
-
 
90
    char *symbol;
-
 
91
 
-
 
92
    spinlock_lock(&exctbl_lock);
-
 
93
    printf("Exc Handler    Description\n");
-
 
94
    for (i=0; i < IVT_ITEMS; i++) {
-
 
95
        symbol = get_symtab_entry((__native)exc_table[i].f);
-
 
96
        if (!symbol)
-
 
97
            symbol = "not found";
-
 
98
        printf("%d %s 0x%p(%s)\n",i,exc_table[i].name,
-
 
99
               exc_table[i].f,symbol);     
-
 
100
        if (!((i+1) % 20)) {
-
 
101
            printf("Press any key to continue.");
-
 
102
            getc(stdin);
-
 
103
            printf("\n");
-
 
104
        }
-
 
105
    }
-
 
106
    spinlock_unlock(&exctbl_lock);
-
 
107
   
-
 
108
    return 1;
59
}
109
}
-
 
110
 
-
 
111
static cmd_info_t exc_info = {
-
 
112
    .name = "exc_print",
-
 
113
    .description = "Print exception table",
-
 
114
    .func = exc_print_cmd,
-
 
115
    .help = NULL,
-
 
116
    .argc = 0,
-
 
117
    .argv = NULL
-
 
118
};
-
 
119
 
-
 
120
/** Initialize generic exception handling support */
-
 
121
void exc_init(void)
-
 
122
{
-
 
123
    int i;
-
 
124
 
-
 
125
    spinlock_initialize(&exctbl_lock, "exctbl_lock");
-
 
126
 
-
 
127
    for (i=0;i < IVT_ITEMS; i++)
-
 
128
        exc_register(i, "undef", exc_undef);
-
 
129
 
-
 
130
    spinlock_initialize(&exc_info.lock, "kconsole_excinfo");
-
 
131
    link_initialize(&exc_info.link);
-
 
132
    if (!cmd_register(&exc_info))
-
 
133
        panic("could not register command %s\n", exc_info.name);
-
 
134
}
-
 
135