|
0
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // common/except.cxx |
|
|
4 // |
|
|
5 // Exception handling implementation |
|
|
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 |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg |
|
|
34 // Date: 1998-04-09 |
|
|
35 // Purpose: Exception handling implementation |
|
|
36 // Description: This file contains the code that registers and delivers |
|
|
37 // exceptions. |
|
|
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 |
|
|
65 void cyg_null_exception_handler( |
|
|
66 CYG_ADDRWORD data, // user supplied data |
|
|
67 cyg_code exception_number, // exception being raised |
|
|
68 CYG_ADDRWORD exception_info // any exception specific info |
|
|
69 ) |
|
|
70 { |
|
|
71 CYG_TRACE1( 1, "Uncaught exception: %d", exception_number); |
|
|
72 } |
|
|
73 |
|
|
74 // ------------------------------------------------------------------------- |
|
|
75 // Exception Controller constructor. |
|
|
76 |
|
|
77 Cyg_Exception_Control::Cyg_Exception_Control() |
|
|
78 { |
|
|
79 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
80 |
|
|
81 for( int i = 0; i < CYG_EXCEPTION_COUNT ; i++ ) |
|
|
82 exception_handler[i] = cyg_null_exception_handler, |
|
|
83 exception_data[i] = 0; |
|
|
84 #else |
|
|
85 |
|
|
86 exception_handler = cyg_null_exception_handler; |
|
|
87 exception_data = 0; |
|
|
88 |
|
|
89 #endif |
|
|
90 |
|
|
91 } |
|
|
92 |
|
|
93 // ------------------------------------------------------------------------- |
|
|
94 // Exception registation. Stores the handler function and data to be used |
|
|
95 // for handling the given exception number. Where exceptions are not decoded |
|
|
96 // only a single handler may be registered for all exceptions. This function |
|
|
97 // also returns the old values of the exception handler and data to allow |
|
|
98 // chaining to be implemented. |
|
|
99 |
|
|
100 void Cyg_Exception_Control::register_exception( |
|
|
101 cyg_code exception_number, // exception number |
|
|
102 cyg_exception_handler handler, // handler function |
|
|
103 CYG_ADDRWORD data, // data argument |
|
|
104 cyg_exception_handler **old_handler, // handler function |
|
|
105 CYG_ADDRWORD *old_data // data argument |
|
|
106 ) |
|
|
107 { |
|
|
108 CYG_REPORT_FUNCTION(); |
|
|
109 |
|
|
110 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, |
|
|
111 "Out of range exception number"); |
|
|
112 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, |
|
|
113 "Out of range exception number"); |
|
|
114 |
|
|
115 |
|
|
116 // Should we complain if there is already a registered |
|
|
117 // handler, or should we just replace is silently? |
|
|
118 |
|
|
119 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
120 |
|
|
121 if( old_handler != NULL ) |
|
|
122 *old_handler = exception_handler[exception_number]; |
|
|
123 if( old_data != NULL ) |
|
|
124 *old_data = exception_data[exception_number]; |
|
|
125 exception_handler[exception_number] = handler; |
|
|
126 exception_data[exception_number] = data; |
|
|
127 |
|
|
128 #else |
|
|
129 |
|
|
130 if( old_handler != NULL ) |
|
|
131 *old_handler = exception_handler; |
|
|
132 if( old_data != NULL ) |
|
|
133 *old_data = exception_data; |
|
|
134 exception_handler = handler; |
|
|
135 exception_data = data; |
|
|
136 |
|
|
137 #endif |
|
|
138 |
|
|
139 } |
|
|
140 |
|
|
141 // ------------------------------------------------------------------------- |
|
|
142 // Exception deregistation. Revert the handler for the exception number |
|
|
143 // to the default. |
|
|
144 |
|
|
145 void Cyg_Exception_Control::deregister_exception( |
|
|
146 cyg_code exception_number // exception number |
|
|
147 ) |
|
|
148 { |
|
|
149 CYG_REPORT_FUNCTION(); |
|
|
150 |
|
|
151 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, |
|
|
152 "Out of range exception number"); |
|
|
153 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, |
|
|
154 "Out of range exception number"); |
|
|
155 |
|
|
156 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
157 |
|
|
158 exception_handler[exception_number] = cyg_null_exception_handler; |
|
|
159 exception_data[exception_number] = 0; |
|
|
160 |
|
|
161 #else |
|
|
162 |
|
|
163 exception_handler = cyg_null_exception_handler; |
|
|
164 exception_data = 0; |
|
|
165 |
|
|
166 #endif |
|
|
167 |
|
|
168 } |
|
|
169 |
|
|
170 // ------------------------------------------------------------------------- |
|
|
171 // Exception delivery. Call the appropriate exception handler. |
|
|
172 |
|
|
173 void Cyg_Exception_Control::deliver_exception( |
|
|
174 cyg_code exception_number, // exception being raised |
|
|
175 CYG_ADDRWORD exception_info // exception specific info |
|
|
176 ) |
|
|
177 { |
|
|
178 cyg_exception_handler *handler = NULL; |
|
|
179 CYG_ADDRWORD data = 0; |
|
|
180 |
|
|
181 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, |
|
|
182 "Out of range exception number"); |
|
|
183 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, |
|
|
184 "Out of range exception number"); |
|
|
185 |
|
|
186 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
|
|
187 |
|
|
188 handler = exception_handler[exception_number]; |
|
|
189 data = exception_data[exception_number]; |
|
|
190 |
|
|
191 #else |
|
|
192 |
|
|
193 handler = exception_handler; |
|
|
194 data = exception_data; |
|
|
195 |
|
|
196 #endif |
|
|
197 |
|
|
198 // The handler will always be a callable function: either the user's |
|
|
199 // registered function or the null handler. So it is always safe to |
|
|
200 // just go ahead and call it. |
|
|
201 |
|
|
202 handler( data, exception_number, exception_info ); |
|
|
203 |
|
|
204 } |
|
|
205 |
|
|
206 // ------------------------------------------------------------------------- |
|
|
207 // Exception delivery function called from the HAL as a result of a |
|
|
208 // hardware exception being raised. |
|
|
209 |
|
|
210 externC void deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) |
|
|
211 { |
|
|
212 Cyg_Thread::self()->deliver_exception( code, data ); |
|
|
213 } |
|
|
214 |
|
|
215 // ------------------------------------------------------------------------- |
|
|
216 // Where exceptions are global, there is a single static instance of the |
|
|
217 // exception control object. Define it here. |
|
|
218 |
|
|
219 #ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL |
|
|
220 |
|
|
221 Cyg_Exception_Control Cyg_Thread::exception_control; |
|
|
222 |
|
|
223 #endif |
|
|
224 |
|
|
225 // ------------------------------------------------------------------------- |
|
|
226 |
|
|
227 #endif |
|
|
228 |
|
|
229 // ------------------------------------------------------------------------- |
|
|
230 // EOF common/except.cxx |