Rev 582 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 582 | Rev 586 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Ondrej Palkovsky |
2 | * Copyright (C) 2005 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
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> |
31 | #include <console/kconsole.h> |
32 | #include <console/console.h> |
32 | #include <console/console.h> |
33 | #include <console/chardev.h> |
33 | #include <console/chardev.h> |
34 | #include <panic.h> |
34 | #include <panic.h> |
35 | #include <print.h> |
35 | #include <print.h> |
36 | #include <symtab.h> |
36 | #include <symtab.h> |
37 | 37 | ||
38 | static struct { |
38 | static struct { |
39 | const char *name; |
39 | const char *name; |
40 | iroutine f; |
40 | iroutine f; |
41 | } exc_table[IVT_ITEMS]; |
41 | } exc_table[IVT_ITEMS]; |
42 | 42 | ||
43 | static spinlock_t exctbl_lock; |
43 | static spinlock_t exctbl_lock; |
44 | 44 | ||
45 | /** Register exception handler |
45 | /** Register exception handler |
46 | * |
46 | * |
47 | * @param n Exception number |
47 | * @param n Exception number |
48 | * @param name Description |
48 | * @param name Description |
49 | * @param f Exception handler |
49 | * @param f Exception handler |
50 | */ |
50 | */ |
51 | iroutine exc_register(int n, const char *name, iroutine f) |
51 | iroutine exc_register(int n, const char *name, iroutine f) |
52 | { |
52 | { |
53 | ASSERT(n < IVT_ITEMS); |
53 | ASSERT(n < IVT_ITEMS); |
54 | 54 | ||
55 | iroutine old; |
55 | iroutine old; |
56 | 56 | ||
57 | spinlock_lock(&exctbl_lock); |
57 | spinlock_lock(&exctbl_lock); |
58 | 58 | ||
59 | old = exc_table[n].f; |
59 | old = exc_table[n].f; |
60 | exc_table[n].f = f; |
60 | exc_table[n].f = f; |
61 | exc_table[n].name = name; |
61 | exc_table[n].name = name; |
62 | 62 | ||
63 | spinlock_unlock(&exctbl_lock); |
63 | spinlock_unlock(&exctbl_lock); |
64 | 64 | ||
65 | return old; |
65 | return old; |
66 | } |
66 | } |
67 | 67 | ||
68 | /** Dispatch exception according to exception table |
68 | /** Dispatch exception according to exception table |
69 | * |
69 | * |
70 | * Called directly from the assembler code. |
70 | * Called directly from the assembler code. |
71 | * CPU is interrupts_disable()'d. |
71 | * CPU is interrupts_disable()'d. |
72 | */ |
72 | */ |
73 | void exc_dispatch(int n, void *stack) |
73 | void exc_dispatch(int n, void *stack) |
74 | { |
74 | { |
75 | ASSERT(n < IVT_ITEMS); |
75 | ASSERT(n < IVT_ITEMS); |
76 | 76 | ||
77 | exc_table[n].f(n, stack); |
77 | exc_table[n].f(n, stack); |
78 | } |
78 | } |
79 | 79 | ||
80 | /** Default 'null' exception handler */ |
80 | /** Default 'null' exception handler */ |
81 | static void exc_undef(int n, void *stack) |
81 | static void exc_undef(int n, void *stack) |
82 | { |
82 | { |
83 | panic("Unhandled exception %d.", n); |
83 | panic("Unhandled exception %d.", n); |
84 | } |
84 | } |
85 | 85 | ||
86 | /** KConsole cmd - print all exceptions */ |
86 | /** KConsole cmd - print all exceptions */ |
87 | static int exc_print_cmd(cmd_arg_t *argv) |
87 | static int exc_print_cmd(cmd_arg_t *argv) |
88 | { |
88 | { |
89 | int i; |
89 | int i; |
90 | char *symbol; |
90 | char *symbol; |
91 | 91 | ||
92 | spinlock_lock(&exctbl_lock); |
92 | spinlock_lock(&exctbl_lock); |
93 | printf("Exc Description Handler\n"); |
93 | printf("Exc Description Handler\n"); |
94 | for (i=0; i < IVT_ITEMS; i++) { |
94 | for (i=0; i < IVT_ITEMS; i++) { |
95 | symbol = get_symtab_entry((__native)exc_table[i].f); |
95 | symbol = get_symtab_entry((__native)exc_table[i].f); |
96 | if (!symbol) |
96 | if (!symbol) |
97 | symbol = "not found"; |
97 | symbol = "not found"; |
98 | printf("%d %s 0x%p(%s)\n",i,exc_table[i].name, |
98 | printf("%d %s 0x%p(%s)\n",i,exc_table[i].name, |
99 | exc_table[i].f,symbol); |
99 | exc_table[i].f,symbol); |
100 | if (!((i+1) % 20)) { |
100 | if (!((i+1) % 20)) { |
101 | printf("Press any key to continue."); |
101 | printf("Press any key to continue."); |
102 | spinlock_unlock(&exctbl_lock); |
102 | spinlock_unlock(&exctbl_lock); |
103 | getc(stdin); |
103 | getc(stdin); |
104 | spinlock_lock(&exctbl_lock); |
104 | spinlock_lock(&exctbl_lock); |
105 | printf("\n"); |
105 | printf("\n"); |
106 | } |
106 | } |
107 | } |
107 | } |
108 | spinlock_unlock(&exctbl_lock); |
108 | spinlock_unlock(&exctbl_lock); |
109 | 109 | ||
110 | return 1; |
110 | return 1; |
111 | } |
111 | } |
112 | 112 | ||
113 | static cmd_info_t exc_info = { |
113 | static cmd_info_t exc_info = { |
114 | .name = "pexc", |
114 | .name = "pexc", |
115 | .description = "Print exception table", |
115 | .description = "Print exception table.", |
116 | .func = exc_print_cmd, |
116 | .func = exc_print_cmd, |
117 | .help = NULL, |
117 | .help = NULL, |
118 | .argc = 0, |
118 | .argc = 0, |
119 | .argv = NULL |
119 | .argv = NULL |
120 | }; |
120 | }; |
121 | 121 | ||
122 | /** Initialize generic exception handling support */ |
122 | /** Initialize generic exception handling support */ |
123 | void exc_init(void) |
123 | void exc_init(void) |
124 | { |
124 | { |
125 | int i; |
125 | int i; |
126 | 126 | ||
127 | spinlock_initialize(&exctbl_lock, "exctbl_lock"); |
127 | spinlock_initialize(&exctbl_lock, "exctbl_lock"); |
128 | 128 | ||
129 | for (i=0;i < IVT_ITEMS; i++) |
129 | for (i=0;i < IVT_ITEMS; i++) |
130 | exc_register(i, "undef", exc_undef); |
130 | exc_register(i, "undef", exc_undef); |
131 | 131 | ||
132 | spinlock_initialize(&exc_info.lock, "kconsole_excinfo"); |
132 | spinlock_initialize(&exc_info.lock, "kconsole_excinfo"); |
133 | link_initialize(&exc_info.link); |
133 | link_initialize(&exc_info.link); |
134 | if (!cmd_register(&exc_info)) |
134 | if (!cmd_register(&exc_info)) |
135 | panic("could not register command %s\n", exc_info.name); |
135 | panic("could not register command %s\n", exc_info.name); |
136 | } |
136 | } |
137 | 137 | ||
138 | 138 |