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