Mercurial > nand-ecoscentric
annotate packages/kernel/current/tests/except1.cxx @ 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 // except1.cxx | |
| 4 // | |
| 5 // 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 #include <pkgconf/kernel.h> | |
| 39 | |
| 40 #include <cyg/infra/testcase.h> | |
| 41 | |
| 42 #ifdef CYGPKG_KERNEL_EXCEPTIONS | |
| 43 | |
| 44 #include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start() | |
| 45 #include <cyg/kernel/thread.hxx> // Cyg_Thread | |
| 46 #include <cyg/kernel/intr.hxx> // cyg_VSR | |
| 47 | |
| 48 #include <cyg/hal/hal_intr.h> // exception ranges | |
| 49 | |
| 50 #include <cyg/kernel/sched.inl> | |
| 51 #include <cyg/kernel/thread.inl> | |
| 52 | |
| 53 #define NTHREADS 1 | |
| 54 #include "testaux.hxx" | |
| 55 | |
| 56 static cyg_exception_handler handler0; | |
| 57 static int d0; | |
| 58 | |
| 59 static void handler0(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info) | |
| 60 { | |
| 61 CYG_TEST_INFO("handler 0 called"); | |
| 62 | |
| 63 CYG_TEST_CHECK((CYG_ADDRWORD)123 == data, "handler given wrong data"); | |
| 64 | |
| 65 // ignore machine specific stuff | |
| 66 CYG_UNUSED_PARAM(cyg_code, number); | |
| 67 CYG_UNUSED_PARAM(CYG_ADDRWORD, info); | |
| 68 | |
| 69 CYG_TEST_PASS_FINISH("Except 1 OK"); | |
| 70 } | |
| 71 | |
| 72 static void handler1(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info) | |
| 73 { | |
| 74 CYG_TEST_INFO("handler 1 called"); | |
| 75 | |
| 76 CYG_TEST_CHECK((CYG_ADDRWORD)&d0 == data, "handler given wrong data"); | |
| 77 | |
| 78 #ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE | |
| 2 | 79 CYG_TEST_CHECK(number == CYGNUM_HAL_EXCEPTION_MAX, "handler given wrong number"); |
| 0 | 80 #else |
| 81 CYG_UNUSED_PARAM(cyg_code, number); | |
| 82 #endif | |
| 83 | |
| 84 CYG_TEST_CHECK((CYG_ADDRWORD)99 == info, "handler given wrong info"); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 // The following function attempts to cause an exception in various | |
| 89 // hacky ways. It is machine dependent what exception is generated. | |
| 90 // It does reads rather than writes hoping not to corrupt anything | |
| 91 // important. | |
| 92 void cause_exception(void) | |
| 93 { | |
| 94 int x; | |
| 95 unsigned int p=0; | |
| 96 | |
| 97 do { | |
| 98 x=*(volatile int *)(p-1)/p; | |
| 99 p+=0x100000; | |
| 100 } while(p != 0); | |
| 101 } | |
| 102 | |
| 103 static void entry0( CYG_ADDRWORD data ) | |
| 104 { | |
| 105 cyg_code n; | |
| 106 cyg_exception_handler *old_handler, *old_handler1; | |
| 107 CYG_ADDRWORD old_data, old_data1; | |
| 108 Cyg_Thread *p=Cyg_Thread::self(); | |
| 109 | |
| 110 CYG_UNUSED_PARAM(CYG_ADDRESS, data); | |
| 111 | |
| 112 p->register_exception( | |
| 2 | 113 CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 114 &handler1, |
| 115 (CYG_ADDRWORD)&d0, | |
| 116 &old_handler, | |
| 117 &old_data); | |
| 118 | |
| 119 p->register_exception( | |
| 2 | 120 CYGNUM_HAL_EXCEPTION_MAX, |
| 0 | 121 &handler1, |
| 122 (CYG_ADDRWORD)&d0, | |
| 123 &old_handler1, | |
| 124 &old_data1); | |
| 125 | |
| 126 CYG_TEST_CHECK(old_handler1 == &handler1, | |
| 127 "register exception: old_handler not the one previously registered"); | |
| 128 CYG_TEST_CHECK(old_data1 == (CYG_ADDRWORD)&d0, | |
| 129 "register exception: old_data not those previously registered"); | |
| 130 | |
| 2 | 131 p->deliver_exception(CYGNUM_HAL_EXCEPTION_MAX, (CYG_ADDRWORD)99); |
| 0 | 132 |
| 133 CYG_TEST_INFO("handler 1 returned"); | |
| 134 | |
| 2 | 135 p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX); |
| 136 p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX); | |
| 0 | 137 |
|
4
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
138 #if 0 |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
139 #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
|
140 // 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
|
141 // PR 19945 workaround. |
|
1d7f19c9e4d1
Merge from eCos master repository on 1999-05-11-21:11:10-BST
jlarmour
parents:
2
diff
changeset
|
142 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
|
143 #elif defined(CYGPKG_HAL_I386_LINUX) |
| 2 | 144 // 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
|
145 CYG_TEST_NA("Not applicable to synthetic target"); |
| 2 | 146 #endif |
| 147 | |
| 148 for(n = CYGNUM_HAL_EXCEPTION_MIN; n <= CYGNUM_HAL_EXCEPTION_MAX; n++) { | |
| 0 | 149 p->register_exception( |
| 150 n, | |
| 151 handler0, | |
| 152 (CYG_ADDRWORD)123, | |
| 153 &old_handler1, | |
| 154 &old_data1); | |
| 155 } | |
| 156 | |
| 2 | 157 CYG_TEST_PASS("Attempting to provoke exception"); |
| 0 | 158 |
| 159 cause_exception(); | |
| 160 | |
| 161 CYG_TEST_FAIL_FINISH("Couldn't cause exception"); | |
| 162 } | |
| 163 | |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
4
diff
changeset
|
164 #ifdef CYG_HAL_MIPS_TX39_JMR3904 |
| 0 | 165 |
| 166 externC cyg_VSR __default_exception_vsr; | |
| 167 cyg_VSR *old_vsr; | |
| 168 | |
| 169 #endif | |
| 170 | |
| 171 void except0_main( void ) | |
| 172 { | |
| 2 | 173 // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT() |
| 174 CYG_TEST_GDBCMD("handle SIGBUS nostop"); | |
| 175 CYG_TEST_GDBCMD("handle SIGSEGV nostop"); | |
| 176 | |
| 0 | 177 CYG_TEST_INIT(); |
| 178 | |
| 2 | 179 #ifdef HAL_VSR_SET_TO_ECOS_HANDLER |
| 180 // Reclaim the VSR off CygMon possibly | |
| 181 #ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS | |
| 182 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL ); | |
| 183 #endif | |
| 184 #ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS | |
| 185 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL ); | |
| 186 #endif | |
| 187 #ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION | |
| 188 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL ); | |
| 189 #endif | |
| 0 | 190 #endif |
| 191 | |
| 192 new_thread(entry0, 0); | |
| 193 | |
| 194 Cyg_Scheduler::start(); | |
| 195 | |
| 196 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 197 } | |
| 198 externC void | |
| 199 cyg_start( void ) | |
| 200 { | |
| 201 except0_main(); | |
| 202 } | |
| 203 #else // def CYGPKG_KERNEL_EXCEPTIONS | |
| 204 externC void | |
| 205 cyg_start( void ) | |
| 206 { | |
| 207 CYG_TEST_INIT(); | |
| 2 | 208 CYG_TEST_NA("Exceptions disabled"); |
| 0 | 209 } |
| 210 #endif // def CYGPKG_KERNEL_EXCEPTIONS | |
| 211 | |
| 212 // EOF except1.cxx |
