|
0
|
1 //========================================================================== |
|
|
2 // |
|
2
|
3 // common/except.cxx |
|
0
|
4 // |
|
2
|
5 // Exception handling implementation |
|
0
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg, jlarmour |
|
|
34 // Date: 1999-02-16 |
|
|
35 // Purpose: Exception handling implementation |
|
|
36 // Description: This file contains the code that registers and delivers |
|
|
37 // exceptions. |
|
0
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 // |
|
|
41 //========================================================================== |
|
|
42 |
|
|
43 #include <pkgconf/kernel.h> |
|
|
44 |
|
|
45 #include <cyg/kernel/ktypes.h> // base kernel types |
|
|
46 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
47 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
48 #include <cyg/kernel/instrmnt.h> // instrumentation |
|
|
49 |
|
|
50 #include <cyg/kernel/except.hxx> // our header |
|
|
51 |
|
|
52 #include <cyg/hal/hal_arch.h> // architecture definitions |
|
|
53 #include <cyg/hal/hal_intr.h> // vector definitions |
|
|
54 |
|
|
55 #include <cyg/kernel/thread.hxx> // thread interface |
|
|
56 |
|
|
57 #include <cyg/kernel/thread.inl> // thread inlines |
|
|
58 |
|
|
59 #ifdef CYGPKG_KERNEL_EXCEPTIONS |
|
|
60 |
|
|
61 // ------------------------------------------------------------------------- |
|
|
62 // Null exception handler. This is used to capture exceptions that are |
|
|
63 // not caught by user supplied handlers. |
|
|
64 |
|
2
|
65 void |
|
|
66 cyg_null_exception_handler( |
|
0
|
67 CYG_ADDRWORD data, // user supplied data |
|
|
68 cyg_code exception_number, // exception being raised |
|
|
69 CYG_ADDRWORD exception_info // any exception specific info |
|
|
70 ) |
|
|
71 { |
|
2
|
72 CYG_REPORT_FUNCTION(); |
|
|
73 CYG_REPORT_FUNCARG3("data=%08x, exception=%d, info=%08x", data, |
|
|
74 exception_number, exception_info); |
|
0
|
75 CYG_TRACE1( 1, "Uncaught exception: %d", exception_number); |
|
2
|
76 CYG_REPORT_RETURN(); |
|
0
|
77 } |
|
|
78 |
|
|
79 // ------------------------------------------------------------------------- |
|
|
80 // Exception Controller constructor. |
|
|
81 |
|
|
82 Cyg_Exception_Control::Cyg_Exception_Control() |
|
|
83 { |
|
2
|
84 CYG_REPORT_FUNCTION(); |
|
0
|
85 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
86 |
|
2
|
87 for( int i = 0; i < CYGNUM_HAL_EXCEPTION_COUNT ; i++ ) |
|
0
|
88 exception_handler[i] = cyg_null_exception_handler, |
|
|
89 exception_data[i] = 0; |
|
|
90 #else |
|
|
91 |
|
|
92 exception_handler = cyg_null_exception_handler; |
|
|
93 exception_data = 0; |
|
|
94 |
|
|
95 #endif |
|
2
|
96 CYG_REPORT_RETURN(); |
|
0
|
97 } |
|
|
98 |
|
|
99 // ------------------------------------------------------------------------- |
|
|
100 // Exception registation. Stores the handler function and data to be used |
|
|
101 // for handling the given exception number. Where exceptions are not decoded |
|
|
102 // only a single handler may be registered for all exceptions. This function |
|
|
103 // also returns the old values of the exception handler and data to allow |
|
|
104 // chaining to be implemented. |
|
|
105 |
|
2
|
106 void |
|
|
107 Cyg_Exception_Control::register_exception( |
|
0
|
108 cyg_code exception_number, // exception number |
|
|
109 cyg_exception_handler handler, // handler function |
|
|
110 CYG_ADDRWORD data, // data argument |
|
|
111 cyg_exception_handler **old_handler, // handler function |
|
|
112 CYG_ADDRWORD *old_data // data argument |
|
|
113 ) |
|
|
114 { |
|
|
115 CYG_REPORT_FUNCTION(); |
|
2
|
116 CYG_REPORT_FUNCARG5("exception=%d, handler func=%08x, data=%08x, " |
|
|
117 "space for old handler=%08x,space for old data=%08x", |
|
|
118 exception_number, handler, data, old_handler, |
|
|
119 old_data); |
|
0
|
120 |
|
2
|
121 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
|
0
|
122 "Out of range exception number"); |
|
2
|
123 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
|
0
|
124 "Out of range exception number"); |
|
|
125 |
|
|
126 |
|
|
127 // Should we complain if there is already a registered |
|
|
128 // handler, or should we just replace is silently? |
|
|
129 |
|
|
130 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
131 |
|
|
132 if( old_handler != NULL ) |
|
2
|
133 *old_handler = exception_handler[exception_number - |
|
|
134 CYGNUM_HAL_EXCEPTION_MIN]; |
|
0
|
135 if( old_data != NULL ) |
|
2
|
136 *old_data = exception_data[exception_number - |
|
|
137 CYGNUM_HAL_EXCEPTION_MIN]; |
|
|
138 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = handler; |
|
|
139 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = data; |
|
0
|
140 |
|
|
141 #else |
|
|
142 |
|
|
143 if( old_handler != NULL ) |
|
|
144 *old_handler = exception_handler; |
|
|
145 if( old_data != NULL ) |
|
|
146 *old_data = exception_data; |
|
|
147 exception_handler = handler; |
|
|
148 exception_data = data; |
|
|
149 |
|
|
150 #endif |
|
2
|
151 CYG_REPORT_RETURN(); |
|
0
|
152 } |
|
|
153 |
|
|
154 // ------------------------------------------------------------------------- |
|
|
155 // Exception deregistation. Revert the handler for the exception number |
|
|
156 // to the default. |
|
|
157 |
|
2
|
158 void |
|
|
159 Cyg_Exception_Control::deregister_exception( |
|
0
|
160 cyg_code exception_number // exception number |
|
|
161 ) |
|
|
162 { |
|
|
163 CYG_REPORT_FUNCTION(); |
|
2
|
164 CYG_REPORT_FUNCARG1("exception number=%d", exception_number); |
|
0
|
165 |
|
2
|
166 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
|
0
|
167 "Out of range exception number"); |
|
2
|
168 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
|
0
|
169 "Out of range exception number"); |
|
|
170 |
|
|
171 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
172 |
|
2
|
173 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = |
|
|
174 cyg_null_exception_handler; |
|
|
175 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = 0; |
|
0
|
176 |
|
|
177 #else |
|
|
178 |
|
|
179 exception_handler = cyg_null_exception_handler; |
|
|
180 exception_data = 0; |
|
|
181 |
|
|
182 #endif |
|
2
|
183 |
|
|
184 CYG_REPORT_RETURN(); |
|
0
|
185 } |
|
|
186 |
|
|
187 // ------------------------------------------------------------------------- |
|
|
188 // Exception delivery. Call the appropriate exception handler. |
|
|
189 |
|
2
|
190 void |
|
|
191 Cyg_Exception_Control::deliver_exception( |
|
0
|
192 cyg_code exception_number, // exception being raised |
|
|
193 CYG_ADDRWORD exception_info // exception specific info |
|
|
194 ) |
|
|
195 { |
|
2
|
196 CYG_REPORT_FUNCTION(); |
|
|
197 CYG_REPORT_FUNCARG2("exception number=%d, exception info=%08x", |
|
|
198 exception_number, exception_info); |
|
|
199 |
|
0
|
200 cyg_exception_handler *handler = NULL; |
|
|
201 CYG_ADDRWORD data = 0; |
|
|
202 |
|
2
|
203 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
|
0
|
204 "Out of range exception number"); |
|
2
|
205 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
|
0
|
206 "Out of range exception number"); |
|
|
207 |
|
|
208 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
209 |
|
2
|
210 handler = exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN]; |
|
|
211 data = exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN]; |
|
0
|
212 |
|
|
213 #else |
|
|
214 |
|
|
215 handler = exception_handler; |
|
|
216 data = exception_data; |
|
|
217 |
|
|
218 #endif |
|
|
219 |
|
|
220 // The handler will always be a callable function: either the user's |
|
|
221 // registered function or the null handler. So it is always safe to |
|
|
222 // just go ahead and call it. |
|
|
223 |
|
|
224 handler( data, exception_number, exception_info ); |
|
2
|
225 |
|
|
226 CYG_REPORT_RETURN(); |
|
0
|
227 } |
|
|
228 |
|
|
229 // ------------------------------------------------------------------------- |
|
|
230 // Exception delivery function called from the HAL as a result of a |
|
|
231 // hardware exception being raised. |
|
|
232 |
|
2
|
233 externC void |
|
|
234 cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) |
|
0
|
235 { |
|
2
|
236 CYG_REPORT_FUNCTION(); |
|
|
237 Cyg_Thread::self()->deliver_exception( (cyg_code)code, data ); |
|
|
238 CYG_REPORT_RETURN(); |
|
0
|
239 } |
|
|
240 |
|
|
241 // ------------------------------------------------------------------------- |
|
|
242 // Where exceptions are global, there is a single static instance of the |
|
|
243 // exception control object. Define it here. |
|
|
244 |
|
|
245 #ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL |
|
|
246 |
|
2
|
247 Cyg_Exception_Control Cyg_Thread::exception_control |
|
|
248 CYG_INIT_PRIORITY(INTERRUPTS); |
|
0
|
249 |
|
|
250 #endif |
|
|
251 |
|
|
252 // ------------------------------------------------------------------------- |
|
|
253 |
|
2
|
254 #endif // ifdef CYGPKG_KERNEL_EXCEPTIONS |
|
0
|
255 |
|
|
256 // ------------------------------------------------------------------------- |
|
|
257 // EOF common/except.cxx |