Rev 1224 | Rev 1595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1224 | Rev 1264 | ||
---|---|---|---|
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 | /** |
|
- | 30 | * @file interrupt.c |
|
- | 31 | * @brief Interrupt redirector. |
|
- | 32 | * |
|
- | 33 | * This file provides means of registering interrupt handlers |
|
- | 34 | * by kernel functions and calling the handlers when interrupts |
|
- | 35 | * occur. |
|
- | 36 | */ |
|
- | 37 | ||
29 | #include <interrupt.h> |
38 | #include <interrupt.h> |
30 | #include <debug.h> |
39 | #include <debug.h> |
31 | #include <console/kconsole.h> |
40 | #include <console/kconsole.h> |
32 | #include <console/console.h> |
41 | #include <console/console.h> |
33 | #include <console/chardev.h> |
42 | #include <console/chardev.h> |
34 | #include <console/cmd.h> |
43 | #include <console/cmd.h> |
35 | #include <panic.h> |
44 | #include <panic.h> |
36 | #include <print.h> |
45 | #include <print.h> |
37 | #include <symtab.h> |
46 | #include <symtab.h> |
38 | 47 | ||
39 | static struct { |
48 | static struct { |
40 | const char *name; |
49 | const char *name; |
41 | iroutine f; |
50 | iroutine f; |
42 | } exc_table[IVT_ITEMS]; |
51 | } exc_table[IVT_ITEMS]; |
43 | 52 | ||
44 | SPINLOCK_INITIALIZE(exctbl_lock); |
53 | SPINLOCK_INITIALIZE(exctbl_lock); |
45 | 54 | ||
46 | /** Register exception handler |
55 | /** Register exception handler |
47 | * |
56 | * |
48 | * @param n Exception number |
57 | * @param n Exception number |
49 | * @param name Description |
58 | * @param name Description |
50 | * @param f Exception handler |
59 | * @param f Exception handler |
51 | */ |
60 | */ |
52 | iroutine exc_register(int n, const char *name, iroutine f) |
61 | iroutine exc_register(int n, const char *name, iroutine f) |
53 | { |
62 | { |
54 | ASSERT(n < IVT_ITEMS); |
63 | ASSERT(n < IVT_ITEMS); |
55 | 64 | ||
56 | iroutine old; |
65 | iroutine old; |
57 | 66 | ||
58 | spinlock_lock(&exctbl_lock); |
67 | spinlock_lock(&exctbl_lock); |
59 | 68 | ||
60 | old = exc_table[n].f; |
69 | old = exc_table[n].f; |
61 | exc_table[n].f = f; |
70 | exc_table[n].f = f; |
62 | exc_table[n].name = name; |
71 | exc_table[n].name = name; |
63 | 72 | ||
64 | spinlock_unlock(&exctbl_lock); |
73 | spinlock_unlock(&exctbl_lock); |
65 | 74 | ||
66 | return old; |
75 | return old; |
67 | } |
76 | } |
68 | 77 | ||
69 | /** Dispatch exception according to exception table |
78 | /** Dispatch exception according to exception table |
70 | * |
79 | * |
71 | * Called directly from the assembler code. |
80 | * Called directly from the assembler code. |
72 | * CPU is interrupts_disable()'d. |
81 | * CPU is interrupts_disable()'d. |
73 | */ |
82 | */ |
74 | void exc_dispatch(int n, istate_t *istate) |
83 | void exc_dispatch(int n, istate_t *istate) |
75 | { |
84 | { |
76 | ASSERT(n < IVT_ITEMS); |
85 | ASSERT(n < IVT_ITEMS); |
77 | 86 | ||
78 | exc_table[n].f(n + IVT_FIRST, istate); |
87 | exc_table[n].f(n + IVT_FIRST, istate); |
79 | } |
88 | } |
80 | 89 | ||
81 | /** Default 'null' exception handler */ |
90 | /** Default 'null' exception handler */ |
82 | static void exc_undef(int n, istate_t *istate) |
91 | static void exc_undef(int n, istate_t *istate) |
83 | { |
92 | { |
84 | panic("Unhandled exception %d.", n); |
93 | panic("Unhandled exception %d.", n); |
85 | } |
94 | } |
86 | 95 | ||
87 | /** kconsole cmd - print all exceptions */ |
96 | /** kconsole cmd - print all exceptions */ |
88 | static int exc_print_cmd(cmd_arg_t *argv) |
97 | static int exc_print_cmd(cmd_arg_t *argv) |
89 | { |
98 | { |
90 | int i; |
99 | int i; |
91 | char *symbol; |
100 | char *symbol; |
92 | 101 | ||
93 | spinlock_lock(&exctbl_lock); |
102 | spinlock_lock(&exctbl_lock); |
94 | printf("Exc Description Handler\n"); |
103 | printf("Exc Description Handler\n"); |
95 | for (i=0; i < IVT_ITEMS; i++) { |
104 | for (i=0; i < IVT_ITEMS; i++) { |
96 | symbol = get_symtab_entry((__native)exc_table[i].f); |
105 | symbol = get_symtab_entry((__native)exc_table[i].f); |
97 | if (!symbol) |
106 | if (!symbol) |
98 | symbol = "not found"; |
107 | symbol = "not found"; |
99 | printf("%d %s %.*p(%s)\n", i + IVT_FIRST, exc_table[i].name, |
108 | printf("%d %s %.*p(%s)\n", i + IVT_FIRST, exc_table[i].name, |
100 | sizeof(__address) * 2, exc_table[i].f,symbol); |
109 | sizeof(__address) * 2, exc_table[i].f,symbol); |
101 | if (!((i+1) % 20)) { |
110 | if (!((i+1) % 20)) { |
102 | printf("Press any key to continue."); |
111 | printf("Press any key to continue."); |
103 | spinlock_unlock(&exctbl_lock); |
112 | spinlock_unlock(&exctbl_lock); |
104 | getc(stdin); |
113 | getc(stdin); |
105 | spinlock_lock(&exctbl_lock); |
114 | spinlock_lock(&exctbl_lock); |
106 | printf("\n"); |
115 | printf("\n"); |
107 | } |
116 | } |
108 | } |
117 | } |
109 | spinlock_unlock(&exctbl_lock); |
118 | spinlock_unlock(&exctbl_lock); |
110 | 119 | ||
111 | return 1; |
120 | return 1; |
112 | } |
121 | } |
113 | 122 | ||
114 | static cmd_info_t exc_info = { |
123 | static cmd_info_t exc_info = { |
115 | .name = "exc", |
124 | .name = "exc", |
116 | .description = "Print exception table.", |
125 | .description = "Print exception table.", |
117 | .func = exc_print_cmd, |
126 | .func = exc_print_cmd, |
118 | .help = NULL, |
127 | .help = NULL, |
119 | .argc = 0, |
128 | .argc = 0, |
120 | .argv = NULL |
129 | .argv = NULL |
121 | }; |
130 | }; |
122 | 131 | ||
123 | /** Initialize generic exception handling support */ |
132 | /** Initialize generic exception handling support */ |
124 | void exc_init(void) |
133 | void exc_init(void) |
125 | { |
134 | { |
126 | int i; |
135 | int i; |
127 | 136 | ||
128 | for (i=0;i < IVT_ITEMS; i++) |
137 | for (i=0;i < IVT_ITEMS; i++) |
129 | exc_register(i, "undef", (iroutine) exc_undef); |
138 | exc_register(i, "undef", (iroutine) exc_undef); |
130 | 139 | ||
131 | cmd_initialize(&exc_info); |
140 | cmd_initialize(&exc_info); |
132 | if (!cmd_register(&exc_info)) |
141 | if (!cmd_register(&exc_info)) |
133 | panic("could not register command %s\n", exc_info.name); |
142 | panic("could not register command %s\n", exc_info.name); |
134 | } |
143 | } |
135 | 144 | ||
136 | 145 |