Rev 2465 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2465 | Rev 4669 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Michal Kebrt, Petr Stepan |
2 | * Copyright (c) 2007 Michal Kebrt, Petr Stepan |
3 | * |
3 | * |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup arm32 |
30 | /** @addtogroup arm32 |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** @file |
33 | /** @file |
34 | * @brief Exception declarations. |
34 | * @brief Exception declarations. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #ifndef KERN_arm32_EXCEPTION_H_ |
37 | #ifndef KERN_arm32_EXCEPTION_H_ |
38 | #define KERN_arm32_EXCEPTION_H_ |
38 | #define KERN_arm32_EXCEPTION_H_ |
39 | 39 | ||
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <arch/regutils.h> |
41 | #include <arch/regutils.h> |
42 | 42 | ||
43 | /** If defined, forces using of high exception vectors. */ |
43 | /** If defined, forces using of high exception vectors. */ |
44 | #define HIGH_EXCEPTION_VECTORS |
44 | #define HIGH_EXCEPTION_VECTORS |
45 | 45 | ||
46 | #ifdef HIGH_EXCEPTION_VECTORS |
46 | #ifdef HIGH_EXCEPTION_VECTORS |
47 | #define EXC_BASE_ADDRESS 0xffff0000 |
47 | #define EXC_BASE_ADDRESS 0xffff0000 |
48 | #else |
48 | #else |
49 | #define EXC_BASE_ADDRESS 0x0 |
49 | #define EXC_BASE_ADDRESS 0x0 |
50 | #endif |
50 | #endif |
51 | 51 | ||
52 | /* Exception Vectors */ |
52 | /* Exception Vectors */ |
53 | #define EXC_RESET_VEC (EXC_BASE_ADDRESS + 0x0) |
53 | #define EXC_RESET_VEC (EXC_BASE_ADDRESS + 0x0) |
54 | #define EXC_UNDEF_INSTR_VEC (EXC_BASE_ADDRESS + 0x4) |
54 | #define EXC_UNDEF_INSTR_VEC (EXC_BASE_ADDRESS + 0x4) |
55 | #define EXC_SWI_VEC (EXC_BASE_ADDRESS + 0x8) |
55 | #define EXC_SWI_VEC (EXC_BASE_ADDRESS + 0x8) |
56 | #define EXC_PREFETCH_ABORT_VEC (EXC_BASE_ADDRESS + 0xc) |
56 | #define EXC_PREFETCH_ABORT_VEC (EXC_BASE_ADDRESS + 0xc) |
57 | #define EXC_DATA_ABORT_VEC (EXC_BASE_ADDRESS + 0x10) |
57 | #define EXC_DATA_ABORT_VEC (EXC_BASE_ADDRESS + 0x10) |
58 | #define EXC_IRQ_VEC (EXC_BASE_ADDRESS + 0x18) |
58 | #define EXC_IRQ_VEC (EXC_BASE_ADDRESS + 0x18) |
59 | #define EXC_FIQ_VEC (EXC_BASE_ADDRESS + 0x1c) |
59 | #define EXC_FIQ_VEC (EXC_BASE_ADDRESS + 0x1c) |
60 | 60 | ||
61 | /* Exception numbers */ |
61 | /* Exception numbers */ |
62 | #define EXC_RESET 0 |
62 | #define EXC_RESET 0 |
63 | #define EXC_UNDEF_INSTR 1 |
63 | #define EXC_UNDEF_INSTR 1 |
64 | #define EXC_SWI 2 |
64 | #define EXC_SWI 2 |
65 | #define EXC_PREFETCH_ABORT 3 |
65 | #define EXC_PREFETCH_ABORT 3 |
66 | #define EXC_DATA_ABORT 4 |
66 | #define EXC_DATA_ABORT 4 |
67 | #define EXC_IRQ 5 |
67 | #define EXC_IRQ 5 |
68 | #define EXC_FIQ 6 |
68 | #define EXC_FIQ 6 |
69 | 69 | ||
70 | 70 | ||
71 | /** Kernel stack pointer. |
71 | /** Kernel stack pointer. |
72 | * |
72 | * |
73 | * It is set when thread switches to user mode, |
73 | * It is set when thread switches to user mode, |
74 | * and then used for exception handling. |
74 | * and then used for exception handling. |
75 | */ |
75 | */ |
76 | extern uintptr_t supervisor_sp; |
76 | extern uintptr_t supervisor_sp; |
77 | 77 | ||
78 | 78 | ||
79 | /** Temporary exception stack pointer. |
79 | /** Temporary exception stack pointer. |
80 | * |
80 | * |
81 | * Temporary stack is used in exceptions handling routines |
81 | * Temporary stack is used in exceptions handling routines |
82 | * before switching to thread's kernel stack. |
82 | * before switching to thread's kernel stack. |
83 | */ |
83 | */ |
84 | extern uintptr_t exc_stack; |
84 | extern uintptr_t exc_stack; |
85 | 85 | ||
86 | 86 | ||
87 | /** Struct representing CPU state saved when an exception occurs. */ |
87 | /** Struct representing CPU state saved when an exception occurs. */ |
88 | typedef struct { |
88 | typedef struct { |
89 | uint32_t spsr; |
89 | uint32_t spsr; |
90 | uint32_t sp; |
90 | uint32_t sp; |
91 | uint32_t lr; |
91 | uint32_t lr; |
92 | 92 | ||
93 | uint32_t r0; |
93 | uint32_t r0; |
94 | uint32_t r1; |
94 | uint32_t r1; |
95 | uint32_t r2; |
95 | uint32_t r2; |
96 | uint32_t r3; |
96 | uint32_t r3; |
97 | uint32_t r4; |
97 | uint32_t r4; |
98 | uint32_t r5; |
98 | uint32_t r5; |
99 | uint32_t r6; |
99 | uint32_t r6; |
100 | uint32_t r7; |
100 | uint32_t r7; |
101 | uint32_t r8; |
101 | uint32_t r8; |
102 | uint32_t r9; |
102 | uint32_t r9; |
103 | uint32_t r10; |
103 | uint32_t r10; |
104 | uint32_t r11; |
104 | uint32_t r11; |
105 | uint32_t r12; |
105 | uint32_t r12; |
106 | 106 | ||
107 | uint32_t pc; |
107 | uint32_t pc; |
108 | } istate_t; |
108 | } istate_t; |
109 | 109 | ||
110 | 110 | ||
111 | /** Sets Program Counter member of given istate structure. |
111 | /** Sets Program Counter member of given istate structure. |
112 | * |
112 | * |
113 | * @param istate istate structure |
113 | * @param istate istate structure |
114 | * @param retaddr new value of istate's PC member |
114 | * @param retaddr new value of istate's PC member |
115 | */ |
115 | */ |
116 | static inline void istate_set_retaddr(istate_t *istate, uintptr_t retaddr) |
116 | static inline void istate_set_retaddr(istate_t *istate, uintptr_t retaddr) |
117 | { |
117 | { |
118 | istate->pc = retaddr; |
118 | istate->pc = retaddr; |
119 | } |
119 | } |
120 | 120 | ||
121 | 121 | ||
122 | /** Returns true if exception happened while in userspace. */ |
122 | /** Returns true if exception happened while in userspace. */ |
123 | static inline int istate_from_uspace(istate_t *istate) |
123 | static inline int istate_from_uspace(istate_t *istate) |
124 | { |
124 | { |
125 | return (istate->spsr & STATUS_REG_MODE_MASK) == USER_MODE; |
125 | return (istate->spsr & STATUS_REG_MODE_MASK) == USER_MODE; |
126 | } |
126 | } |
127 | 127 | ||
128 | 128 | ||
129 | /** Returns Program Counter member of given istate structure. */ |
129 | /** Returns Program Counter member of given istate structure. */ |
130 | static inline unative_t istate_get_pc(istate_t *istate) |
130 | static inline unative_t istate_get_pc(istate_t *istate) |
131 | { |
131 | { |
132 | return istate->pc; |
132 | return istate->pc; |
133 | } |
133 | } |
134 | 134 | ||
135 | 135 | ||
136 | extern void install_exception_handlers(void); |
136 | extern void install_exception_handlers(void); |
137 | extern void exception_init(void); |
137 | extern void exception_init(void); |
138 | extern void print_istate(istate_t *istate); |
138 | extern void print_istate(istate_t *istate); |
- | 139 | extern void reset_exception_entry(void); |
|
- | 140 | extern void irq_exception_entry(void); |
|
- | 141 | extern void fiq_exception_entry(void); |
|
- | 142 | extern void undef_instr_exception_entry(void); |
|
- | 143 | extern void prefetch_abort_exception_entry(void); |
|
- | 144 | extern void data_abort_exception_entry(void); |
|
- | 145 | extern void swi_exception_entry(void); |
|
139 | 146 | ||
140 | 147 | ||
141 | #endif |
148 | #endif |
142 | 149 | ||
143 | /** @} |
150 | /** @} |
144 | */ |
151 | */ |
145 | 152 |