comparison packages/kernel/current/src/common/except.cxx @ 2:443894e2e912 ecos-v1_2_1-release

Block commit of eCos version 1.2.1
author jlarmour
date Tue, 11 May 1999 12:24:34 +0000
parents 3111d98ba7b3
children c38311975d4f
comparison
equal deleted inserted replaced
1:72f549f0d891 2:443894e2e912
1 //========================================================================== 1 //==========================================================================
2 // 2 //
3 // common/except.cxx 3 // common/except.cxx
4 // 4 //
5 // Exception handling implementation 5 // Exception handling implementation
6 // 6 //
7 //========================================================================== 7 //==========================================================================
8 //####COPYRIGHTBEGIN#### 8 //####COPYRIGHTBEGIN####
9 // 9 //
10 // ------------------------------------------- 10 // -------------------------------------------
20 // 20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released 21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998. 22 // September 30, 1998.
23 // 23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created 24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved.
26 // ------------------------------------------- 26 // -------------------------------------------
27 // 27 //
28 //####COPYRIGHTEND#### 28 //####COPYRIGHTEND####
29 //========================================================================== 29 //==========================================================================
30 //#####DESCRIPTIONBEGIN#### 30 //#####DESCRIPTIONBEGIN####
31 // 31 //
32 // Author(s): nickg 32 // Author(s): nickg
33 // Contributors: nickg 33 // Contributors: nickg, jlarmour
34 // Date: 1998-04-09 34 // Date: 1999-02-16
35 // Purpose: Exception handling implementation 35 // Purpose: Exception handling implementation
36 // Description: This file contains the code that registers and delivers 36 // Description: This file contains the code that registers and delivers
37 // exceptions. 37 // exceptions.
38 // 38 //
39 //####DESCRIPTIONEND#### 39 //####DESCRIPTIONEND####
40 // 40 //
41 //========================================================================== 41 //==========================================================================
42 42
60 60
61 // ------------------------------------------------------------------------- 61 // -------------------------------------------------------------------------
62 // Null exception handler. This is used to capture exceptions that are 62 // Null exception handler. This is used to capture exceptions that are
63 // not caught by user supplied handlers. 63 // not caught by user supplied handlers.
64 64
65 void cyg_null_exception_handler( 65 void
66 cyg_null_exception_handler(
66 CYG_ADDRWORD data, // user supplied data 67 CYG_ADDRWORD data, // user supplied data
67 cyg_code exception_number, // exception being raised 68 cyg_code exception_number, // exception being raised
68 CYG_ADDRWORD exception_info // any exception specific info 69 CYG_ADDRWORD exception_info // any exception specific info
69 ) 70 )
70 { 71 {
72 CYG_REPORT_FUNCTION();
73 CYG_REPORT_FUNCARG3("data=%08x, exception=%d, info=%08x", data,
74 exception_number, exception_info);
71 CYG_TRACE1( 1, "Uncaught exception: %d", exception_number); 75 CYG_TRACE1( 1, "Uncaught exception: %d", exception_number);
76 CYG_REPORT_RETURN();
72 } 77 }
73 78
74 // ------------------------------------------------------------------------- 79 // -------------------------------------------------------------------------
75 // Exception Controller constructor. 80 // Exception Controller constructor.
76 81
77 Cyg_Exception_Control::Cyg_Exception_Control() 82 Cyg_Exception_Control::Cyg_Exception_Control()
78 { 83 {
79 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE 84 CYG_REPORT_FUNCTION();
80 85 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
81 for( int i = 0; i < CYG_EXCEPTION_COUNT ; i++ ) 86
87 for( int i = 0; i < CYGNUM_HAL_EXCEPTION_COUNT ; i++ )
82 exception_handler[i] = cyg_null_exception_handler, 88 exception_handler[i] = cyg_null_exception_handler,
83 exception_data[i] = 0; 89 exception_data[i] = 0;
84 #else 90 #else
85 91
86 exception_handler = cyg_null_exception_handler; 92 exception_handler = cyg_null_exception_handler;
87 exception_data = 0; 93 exception_data = 0;
88 94
89 #endif 95 #endif
90 96 CYG_REPORT_RETURN();
91 } 97 }
92 98
93 // ------------------------------------------------------------------------- 99 // -------------------------------------------------------------------------
94 // Exception registation. Stores the handler function and data to be used 100 // Exception registation. Stores the handler function and data to be used
95 // for handling the given exception number. Where exceptions are not decoded 101 // for handling the given exception number. Where exceptions are not decoded
96 // only a single handler may be registered for all exceptions. This function 102 // 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 103 // also returns the old values of the exception handler and data to allow
98 // chaining to be implemented. 104 // chaining to be implemented.
99 105
100 void Cyg_Exception_Control::register_exception( 106 void
107 Cyg_Exception_Control::register_exception(
101 cyg_code exception_number, // exception number 108 cyg_code exception_number, // exception number
102 cyg_exception_handler handler, // handler function 109 cyg_exception_handler handler, // handler function
103 CYG_ADDRWORD data, // data argument 110 CYG_ADDRWORD data, // data argument
104 cyg_exception_handler **old_handler, // handler function 111 cyg_exception_handler **old_handler, // handler function
105 CYG_ADDRWORD *old_data // data argument 112 CYG_ADDRWORD *old_data // data argument
106 ) 113 )
107 { 114 {
108 CYG_REPORT_FUNCTION(); 115 CYG_REPORT_FUNCTION();
109 116 CYG_REPORT_FUNCARG5("exception=%d, handler func=%08x, data=%08x, "
110 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, 117 "space for old handler=%08x,space for old data=%08x",
111 "Out of range exception number"); 118 exception_number, handler, data, old_handler,
112 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, 119 old_data);
120
121 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
122 "Out of range exception number");
123 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
113 "Out of range exception number"); 124 "Out of range exception number");
114 125
115 126
116 // Should we complain if there is already a registered 127 // Should we complain if there is already a registered
117 // handler, or should we just replace is silently? 128 // handler, or should we just replace is silently?
118 129
119 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE 130 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
120 131
121 if( old_handler != NULL ) 132 if( old_handler != NULL )
122 *old_handler = exception_handler[exception_number]; 133 *old_handler = exception_handler[exception_number -
134 CYGNUM_HAL_EXCEPTION_MIN];
123 if( old_data != NULL ) 135 if( old_data != NULL )
124 *old_data = exception_data[exception_number]; 136 *old_data = exception_data[exception_number -
125 exception_handler[exception_number] = handler; 137 CYGNUM_HAL_EXCEPTION_MIN];
126 exception_data[exception_number] = data; 138 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = handler;
139 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = data;
127 140
128 #else 141 #else
129 142
130 if( old_handler != NULL ) 143 if( old_handler != NULL )
131 *old_handler = exception_handler; 144 *old_handler = exception_handler;
133 *old_data = exception_data; 146 *old_data = exception_data;
134 exception_handler = handler; 147 exception_handler = handler;
135 exception_data = data; 148 exception_data = data;
136 149
137 #endif 150 #endif
138 151 CYG_REPORT_RETURN();
139 } 152 }
140 153
141 // ------------------------------------------------------------------------- 154 // -------------------------------------------------------------------------
142 // Exception deregistation. Revert the handler for the exception number 155 // Exception deregistation. Revert the handler for the exception number
143 // to the default. 156 // to the default.
144 157
145 void Cyg_Exception_Control::deregister_exception( 158 void
159 Cyg_Exception_Control::deregister_exception(
146 cyg_code exception_number // exception number 160 cyg_code exception_number // exception number
147 ) 161 )
148 { 162 {
149 CYG_REPORT_FUNCTION(); 163 CYG_REPORT_FUNCTION();
150 164 CYG_REPORT_FUNCARG1("exception number=%d", exception_number);
151 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, 165
152 "Out of range exception number"); 166 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
153 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, 167 "Out of range exception number");
154 "Out of range exception number"); 168 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
155 169 "Out of range exception number");
156 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE 170
157 171 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
158 exception_handler[exception_number] = cyg_null_exception_handler; 172
159 exception_data[exception_number] = 0; 173 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] =
174 cyg_null_exception_handler;
175 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = 0;
160 176
161 #else 177 #else
162 178
163 exception_handler = cyg_null_exception_handler; 179 exception_handler = cyg_null_exception_handler;
164 exception_data = 0; 180 exception_data = 0;
165 181
166 #endif 182 #endif
167 183
184 CYG_REPORT_RETURN();
168 } 185 }
169 186
170 // ------------------------------------------------------------------------- 187 // -------------------------------------------------------------------------
171 // Exception delivery. Call the appropriate exception handler. 188 // Exception delivery. Call the appropriate exception handler.
172 189
173 void Cyg_Exception_Control::deliver_exception( 190 void
191 Cyg_Exception_Control::deliver_exception(
174 cyg_code exception_number, // exception being raised 192 cyg_code exception_number, // exception being raised
175 CYG_ADDRWORD exception_info // exception specific info 193 CYG_ADDRWORD exception_info // exception specific info
176 ) 194 )
177 { 195 {
196 CYG_REPORT_FUNCTION();
197 CYG_REPORT_FUNCARG2("exception number=%d, exception info=%08x",
198 exception_number, exception_info);
199
178 cyg_exception_handler *handler = NULL; 200 cyg_exception_handler *handler = NULL;
179 CYG_ADDRWORD data = 0; 201 CYG_ADDRWORD data = 0;
180 202
181 CYG_ASSERT( exception_number <= CYG_EXCEPTION_MAX, 203 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
182 "Out of range exception number"); 204 "Out of range exception number");
183 CYG_ASSERT( exception_number >= CYG_EXCEPTION_MIN, 205 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
184 "Out of range exception number"); 206 "Out of range exception number");
185 207
186 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE 208 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
187 209
188 handler = exception_handler[exception_number]; 210 handler = exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN];
189 data = exception_data[exception_number]; 211 data = exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN];
190 212
191 #else 213 #else
192 214
193 handler = exception_handler; 215 handler = exception_handler;
194 data = exception_data; 216 data = exception_data;
198 // The handler will always be a callable function: either the user's 220 // 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 221 // registered function or the null handler. So it is always safe to
200 // just go ahead and call it. 222 // just go ahead and call it.
201 223
202 handler( data, exception_number, exception_info ); 224 handler( data, exception_number, exception_info );
203 225
226 CYG_REPORT_RETURN();
204 } 227 }
205 228
206 // ------------------------------------------------------------------------- 229 // -------------------------------------------------------------------------
207 // Exception delivery function called from the HAL as a result of a 230 // Exception delivery function called from the HAL as a result of a
208 // hardware exception being raised. 231 // hardware exception being raised.
209 232
210 externC void deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) 233 externC void
211 { 234 cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data )
212 Cyg_Thread::self()->deliver_exception( code, data ); 235 {
236 CYG_REPORT_FUNCTION();
237 Cyg_Thread::self()->deliver_exception( (cyg_code)code, data );
238 CYG_REPORT_RETURN();
213 } 239 }
214 240
215 // ------------------------------------------------------------------------- 241 // -------------------------------------------------------------------------
216 // Where exceptions are global, there is a single static instance of the 242 // Where exceptions are global, there is a single static instance of the
217 // exception control object. Define it here. 243 // exception control object. Define it here.
218 244
219 #ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL 245 #ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL
220 246
221 Cyg_Exception_Control Cyg_Thread::exception_control; 247 Cyg_Exception_Control Cyg_Thread::exception_control
222 248 CYG_INIT_PRIORITY(INTERRUPTS);
223 #endif 249
224 250 #endif
225 // ------------------------------------------------------------------------- 251
226 252 // -------------------------------------------------------------------------
227 #endif 253
254 #endif // ifdef CYGPKG_KERNEL_EXCEPTIONS
228 255
229 // ------------------------------------------------------------------------- 256 // -------------------------------------------------------------------------
230 // EOF common/except.cxx 257 // EOF common/except.cxx