Mercurial > ecos-v3_0-branch
annotate packages/kernel/current/src/common/except.cxx @ 2863:7d8c61e6225c default tip
* Added execute permissions to files missed in conversion from CVS
| author | alexs |
|---|---|
| date | Thu, 26 Mar 2009 20:39:18 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // common/except.cxx |
| 0 | 4 // |
| 2 | 5 // Exception handling implementation |
| 0 | 6 // |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 2 | 42 // Author(s): nickg |
| 43 // Contributors: nickg, jlarmour | |
| 44 // Date: 1999-02-16 | |
| 45 // Purpose: Exception handling implementation | |
| 46 // Description: This file contains the code that registers and delivers | |
| 47 // exceptions. | |
| 0 | 48 // |
| 49 //####DESCRIPTIONEND#### | |
| 50 // | |
| 51 //========================================================================== | |
| 52 | |
| 53 #include <pkgconf/kernel.h> | |
| 54 | |
| 55 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 56 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 57 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 58 #include <cyg/kernel/instrmnt.h> // instrumentation | |
| 59 | |
| 60 #include <cyg/kernel/except.hxx> // our header | |
| 61 | |
| 62 #include <cyg/hal/hal_arch.h> // architecture definitions | |
| 63 #include <cyg/hal/hal_intr.h> // vector definitions | |
| 64 | |
| 65 #include <cyg/kernel/thread.hxx> // thread interface | |
| 66 | |
| 67 #include <cyg/kernel/thread.inl> // thread inlines | |
| 68 | |
| 69 #ifdef CYGPKG_KERNEL_EXCEPTIONS | |
| 70 | |
| 71 // ------------------------------------------------------------------------- | |
| 72 // Null exception handler. This is used to capture exceptions that are | |
| 73 // not caught by user supplied handlers. | |
| 74 | |
| 2 | 75 void |
| 76 cyg_null_exception_handler( | |
| 0 | 77 CYG_ADDRWORD data, // user supplied data |
| 78 cyg_code exception_number, // exception being raised | |
| 79 CYG_ADDRWORD exception_info // any exception specific info | |
| 80 ) | |
| 81 { | |
| 2 | 82 CYG_REPORT_FUNCTION(); |
| 83 CYG_REPORT_FUNCARG3("data=%08x, exception=%d, info=%08x", data, | |
| 84 exception_number, exception_info); | |
| 0 | 85 CYG_TRACE1( 1, "Uncaught exception: %d", exception_number); |
| 2 | 86 CYG_REPORT_RETURN(); |
| 0 | 87 } |
| 88 | |
| 89 // ------------------------------------------------------------------------- | |
| 90 // Exception Controller constructor. | |
| 91 | |
| 92 Cyg_Exception_Control::Cyg_Exception_Control() | |
| 93 { | |
| 2 | 94 CYG_REPORT_FUNCTION(); |
| 0 | 95 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE |
| 96 | |
| 2 | 97 for( int i = 0; i < CYGNUM_HAL_EXCEPTION_COUNT ; i++ ) |
| 0 | 98 exception_handler[i] = cyg_null_exception_handler, |
| 99 exception_data[i] = 0; | |
| 100 #else | |
| 101 | |
| 102 exception_handler = cyg_null_exception_handler; | |
| 103 exception_data = 0; | |
| 104 | |
| 105 #endif | |
| 2 | 106 CYG_REPORT_RETURN(); |
| 0 | 107 } |
| 108 | |
| 109 // ------------------------------------------------------------------------- | |
| 110 // Exception registation. Stores the handler function and data to be used | |
| 111 // for handling the given exception number. Where exceptions are not decoded | |
| 112 // only a single handler may be registered for all exceptions. This function | |
| 113 // also returns the old values of the exception handler and data to allow | |
| 114 // chaining to be implemented. | |
| 115 | |
| 2 | 116 void |
| 117 Cyg_Exception_Control::register_exception( | |
| 0 | 118 cyg_code exception_number, // exception number |
| 119 cyg_exception_handler handler, // handler function | |
| 120 CYG_ADDRWORD data, // data argument | |
| 121 cyg_exception_handler **old_handler, // handler function | |
| 122 CYG_ADDRWORD *old_data // data argument | |
| 123 ) | |
| 124 { | |
| 125 CYG_REPORT_FUNCTION(); | |
| 2 | 126 CYG_REPORT_FUNCARG5("exception=%d, handler func=%08x, data=%08x, " |
| 127 "space for old handler=%08x,space for old data=%08x", | |
| 128 exception_number, handler, data, old_handler, | |
| 129 old_data); | |
| 0 | 130 |
| 2 | 131 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 132 "Out of range exception number"); |
| 2 | 133 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
| 0 | 134 "Out of range exception number"); |
| 135 | |
| 136 | |
| 137 // Should we complain if there is already a registered | |
| 138 // handler, or should we just replace is silently? | |
| 139 | |
| 140 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE | |
| 141 | |
| 142 if( old_handler != NULL ) | |
| 2 | 143 *old_handler = exception_handler[exception_number - |
| 144 CYGNUM_HAL_EXCEPTION_MIN]; | |
| 0 | 145 if( old_data != NULL ) |
| 2 | 146 *old_data = exception_data[exception_number - |
| 147 CYGNUM_HAL_EXCEPTION_MIN]; | |
| 148 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = handler; | |
| 149 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = data; | |
| 0 | 150 |
| 151 #else | |
| 152 | |
| 153 if( old_handler != NULL ) | |
| 154 *old_handler = exception_handler; | |
| 155 if( old_data != NULL ) | |
| 156 *old_data = exception_data; | |
| 157 exception_handler = handler; | |
| 158 exception_data = data; | |
| 159 | |
| 160 #endif | |
| 2 | 161 CYG_REPORT_RETURN(); |
| 0 | 162 } |
| 163 | |
| 164 // ------------------------------------------------------------------------- | |
| 165 // Exception deregistation. Revert the handler for the exception number | |
| 166 // to the default. | |
| 167 | |
| 2 | 168 void |
| 169 Cyg_Exception_Control::deregister_exception( | |
| 0 | 170 cyg_code exception_number // exception number |
| 171 ) | |
| 172 { | |
| 173 CYG_REPORT_FUNCTION(); | |
| 2 | 174 CYG_REPORT_FUNCARG1("exception number=%d", exception_number); |
| 0 | 175 |
| 2 | 176 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 177 "Out of range exception number"); |
| 2 | 178 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
| 0 | 179 "Out of range exception number"); |
| 180 | |
| 181 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE | |
| 182 | |
| 2 | 183 exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = |
| 184 cyg_null_exception_handler; | |
| 185 exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = 0; | |
| 0 | 186 |
| 187 #else | |
| 188 | |
| 189 exception_handler = cyg_null_exception_handler; | |
| 190 exception_data = 0; | |
| 191 | |
| 192 #endif | |
| 2 | 193 |
| 194 CYG_REPORT_RETURN(); | |
| 0 | 195 } |
| 196 | |
| 197 // ------------------------------------------------------------------------- | |
| 198 // Exception delivery. Call the appropriate exception handler. | |
| 199 | |
| 2 | 200 void |
| 201 Cyg_Exception_Control::deliver_exception( | |
| 0 | 202 cyg_code exception_number, // exception being raised |
| 203 CYG_ADDRWORD exception_info // exception specific info | |
| 204 ) | |
| 205 { | |
| 2 | 206 CYG_REPORT_FUNCTION(); |
| 207 CYG_REPORT_FUNCARG2("exception number=%d, exception info=%08x", | |
| 208 exception_number, exception_info); | |
| 209 | |
| 0 | 210 cyg_exception_handler *handler = NULL; |
| 211 CYG_ADDRWORD data = 0; | |
| 212 | |
| 2 | 213 CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 214 "Out of range exception number"); |
| 2 | 215 CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN, |
| 0 | 216 "Out of range exception number"); |
| 217 | |
| 218 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE | |
| 219 | |
| 2 | 220 handler = exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN]; |
| 221 data = exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN]; | |
| 0 | 222 |
| 223 #else | |
| 224 | |
| 225 handler = exception_handler; | |
| 226 data = exception_data; | |
| 227 | |
| 228 #endif | |
| 229 | |
| 230 // The handler will always be a callable function: either the user's | |
| 231 // registered function or the null handler. So it is always safe to | |
| 232 // just go ahead and call it. | |
| 233 | |
| 234 handler( data, exception_number, exception_info ); | |
| 2 | 235 |
| 236 CYG_REPORT_RETURN(); | |
| 0 | 237 } |
| 238 | |
| 239 // ------------------------------------------------------------------------- | |
| 240 // Exception delivery function called from the HAL as a result of a | |
| 241 // hardware exception being raised. | |
| 242 | |
| 2 | 243 externC void |
| 244 cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data ) | |
| 0 | 245 { |
| 2 | 246 CYG_REPORT_FUNCTION(); |
| 247 Cyg_Thread::self()->deliver_exception( (cyg_code)code, data ); | |
| 248 CYG_REPORT_RETURN(); | |
| 0 | 249 } |
| 250 | |
| 251 // ------------------------------------------------------------------------- | |
| 252 // Where exceptions are global, there is a single static instance of the | |
| 253 // exception control object. Define it here. | |
| 254 | |
| 255 #ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL | |
| 256 | |
| 2 | 257 Cyg_Exception_Control Cyg_Thread::exception_control |
| 258 CYG_INIT_PRIORITY(INTERRUPTS); | |
| 0 | 259 |
| 260 #endif | |
| 261 | |
| 262 // ------------------------------------------------------------------------- | |
| 263 | |
| 2 | 264 #endif // ifdef CYGPKG_KERNEL_EXCEPTIONS |
| 0 | 265 |
| 266 // ------------------------------------------------------------------------- | |
| 267 // EOF common/except.cxx |
