Mercurial > flash_v2
annotate packages/kernel/current/tests/kexcept1.c @ 10:d3fbcdfa1b2f ecos-sw-1999-05-29
Merge from eCos master repository on 1999-05-29-00:13:11-BST
| author | jlarmour |
|---|---|
| date | Fri, 28 May 1999 16:43:09 +0000 |
| parents | 1d7f19c9e4d1 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 /*================================================================= |
| 2 // | |
| 3 // kexcept1.cxx | |
| 4 // | |
| 5 // Kernel C API Exception test 1 | |
| 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 // | |
| 32 // Author(s): dsm | |
| 2 | 33 // Contributors: dsm, jlarmour |
| 34 // Date: 1999-02-16 | |
| 0 | 35 // Description: Test basic exception functionality |
| 36 //####DESCRIPTIONEND#### | |
| 37 */ | |
| 38 | |
| 2 | 39 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 40 | |
| 0 | 41 #include <cyg/kernel/kapi.h> |
| 42 | |
| 43 #include <cyg/infra/testcase.h> | |
| 44 | |
| 45 #ifdef CYGPKG_KERNEL_EXCEPTIONS | |
| 46 | |
| 47 #ifdef CYGFUN_KERNEL_API_C | |
| 48 | |
| 49 #include <cyg/hal/hal_intr.h> // exception ranges | |
| 50 | |
| 51 #include "testaux.h" | |
| 52 | |
| 53 #define NTHREADS 1 | |
| 2 | 54 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 0 | 55 |
| 56 static cyg_handle_t thread[NTHREADS]; | |
| 57 | |
| 58 static cyg_thread thread_obj[NTHREADS]; | |
| 59 static char stack[NTHREADS][STACKSIZE]; | |
| 60 | |
| 61 | |
| 62 static cyg_exception_handler_t handler0; | |
| 63 static int d0; | |
| 64 | |
| 65 static void handler0(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info) | |
| 66 { | |
| 67 CYG_TEST_INFO("handler 0 called"); | |
| 68 | |
| 69 CYG_TEST_CHECK((cyg_addrword_t)123 == data, "handler given wrong data"); | |
| 70 | |
| 71 // ignore machine specific stuff | |
| 72 CYG_UNUSED_PARAM(cyg_code_t, number); | |
| 73 CYG_UNUSED_PARAM(cyg_addrword_t, info); | |
| 74 | |
| 75 CYG_TEST_PASS_FINISH("Except 1 OK"); | |
| 76 } | |
| 77 | |
| 78 static void handler1(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info) | |
| 79 { | |
| 80 CYG_TEST_INFO("handler 1 called"); | |
| 81 | |
| 82 CYG_TEST_CHECK((cyg_addrword_t)&d0 == data, "handler given wrong data"); | |
| 83 | |
| 84 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE | |
| 2 | 85 CYG_TEST_CHECK(number == CYGNUM_HAL_EXCEPTION_MAX, "handler given wrong number"); |
| 0 | 86 #else |
| 87 CYG_UNUSED_PARAM(cyg_code_t, number); | |
| 88 #endif | |
| 89 | |
| 90 CYG_TEST_CHECK((cyg_addrword_t)99 == info, "handler given wrong info"); | |
| 91 } | |
| 92 | |
| 93 | |
| 94 // The following function attempts to cause an exception in various | |
| 95 // hacky ways. It is machine dependent what exception is generated. | |
| 96 // It does reads rather than writes hoping not to corrupt anything | |
| 97 // important. | |
| 98 void cause_exception(void) | |
| 99 { | |
| 100 int x; | |
| 101 unsigned int p=0; | |
| 102 | |
| 103 do { | |
| 104 x=*(volatile int *)(p-1)/p; | |
| 105 p+=0x100000; | |
| 106 } while(p != 0); | |
| 107 } | |
| 108 | |
| 109 static void entry0( CYG_ADDRWORD data ) | |
| 110 { | |
| 111 cyg_code_t n; | |
| 112 cyg_exception_handler_t *old_handler, *old_handler1; | |
| 113 cyg_addrword_t old_data, old_data1; | |
| 114 | |
| 115 CYG_UNUSED_PARAM(CYG_ADDRESS, data); | |
| 116 | |
| 117 cyg_exception_set_handler( | |
| 2 | 118 CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 119 &handler1, |
| 120 (cyg_addrword_t)&d0, | |
| 121 &old_handler, | |
| 122 &old_data); | |
| 123 | |
| 124 cyg_exception_set_handler( | |
| 2 | 125 CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 126 &handler1, |
| 127 (cyg_addrword_t)&d0, | |
| 128 &old_handler1, | |
| 129 &old_data1); | |
| 130 | |
| 131 CYG_TEST_CHECK(old_handler1 == &handler1, | |
| 132 "register exception: old_handler not the one previously registered"); | |
| 133 CYG_TEST_CHECK(old_data1 == (cyg_addrword_t)&d0, | |
| 134 "register exception: old_data not those previously registered"); | |
| 135 | |
| 136 cyg_exception_call_handler( | |
| 137 cyg_thread_self(), | |
| 2 | 138 CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 139 (cyg_addrword_t)99); |
| 140 | |
| 141 CYG_TEST_INFO("handler 1 returned"); | |
| 142 | |
| 2 | 143 cyg_exception_clear_handler(CYGNUM_HAL_EXCEPTION_MAX); |
| 144 cyg_exception_clear_handler(CYGNUM_HAL_EXCEPTION_MAX); | |
| 0 | 145 |
|
4
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
146 #if 0 |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
147 #elif defined(CYGPKG_HAL_POWERPC_SIM) |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
148 // The exception generated by the SIM is not recognized by GDB. |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
149 // PR 19945 workaround. |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
150 CYG_TEST_NA("Not applicable to PowerPC SIM"); |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
151 #elif defined(CYGPKG_HAL_I386_LINUX) |
| 2 | 152 // We can't catch segmentation violation exceptions on Linux. |
|
4
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
153 CYG_TEST_NA("Not applicable to synthetic target"); |
| 2 | 154 #endif |
| 155 | |
| 156 for(n = CYGNUM_HAL_EXCEPTION_MIN; n <= CYGNUM_HAL_EXCEPTION_MAX; n++) { | |
| 0 | 157 cyg_exception_set_handler( |
| 158 n, | |
| 159 handler0, | |
| 160 (cyg_addrword_t)123, | |
| 161 &old_handler1, | |
| 162 &old_data1); | |
| 163 } | |
| 164 | |
| 2 | 165 CYG_TEST_PASS("Attempting to provoke exception"); |
| 0 | 166 |
| 167 cause_exception(); | |
| 168 | |
| 169 CYG_TEST_FAIL_FINISH("Couldn't cause exception"); | |
| 170 } | |
| 171 | |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
4
diff
changeset
|
172 #ifdef CYG_HAL_MIPS_TX39_JMR3904 |
| 0 | 173 |
| 174 extern void __default_exception_vsr(void); | |
| 175 | |
| 176 #endif | |
| 177 | |
| 178 void except0_main( void ) | |
| 179 { | |
| 2 | 180 // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT() |
| 181 CYG_TEST_GDBCMD("handle SIGBUS nostop"); | |
| 182 CYG_TEST_GDBCMD("handle SIGSEGV nostop"); | |
| 183 | |
| 0 | 184 CYG_TEST_INIT(); |
| 185 | |
| 2 | 186 #ifdef HAL_VSR_SET_TO_ECOS_HANDLER |
| 187 // Reclaim the VSR off CygMon possibly | |
| 188 #ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS | |
| 189 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL ); | |
| 190 #endif | |
| 191 #ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS | |
| 192 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL ); | |
| 193 #endif | |
| 194 #ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION | |
| 195 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL ); | |
| 196 #endif | |
| 197 #endif | |
| 0 | 198 |
| 199 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kexcept1", | |
| 2 | 200 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
| 0 | 201 cyg_thread_resume(thread[0]); |
| 202 | |
| 203 cyg_scheduler_start(); | |
| 204 | |
| 205 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 206 } | |
| 207 | |
| 208 externC void | |
| 209 cyg_start( void ) | |
| 210 { | |
| 211 except0_main(); | |
| 212 } | |
| 213 | |
| 214 #else // def CYGFUN_KERNEL_API_C | |
| 215 #define N_A_MSG "Kernel C API layer disabled" | |
| 216 #endif // def CYGFUN_KERNEL_API_C | |
| 217 #else // def CYGPKG_KERNEL_EXCEPTIONS | |
| 218 #define N_A_MSG "Exceptions disabled" | |
| 219 #endif // def CYGPKG_KERNEL_EXCEPTIONS | |
| 220 | |
| 221 #ifdef N_A_MSG | |
| 222 externC void | |
| 223 cyg_start( void ) | |
| 224 { | |
| 225 CYG_TEST_INIT(); | |
| 2 | 226 CYG_TEST_NA( N_A_MSG); |
| 0 | 227 } |
| 228 #endif // N_A_MSG | |
| 229 | |
| 230 /* EOF kexcept1.c */ |
