comparison packages/kernel/current/tests/kexcept1.c @ 126:518f42066aba ecos-sw-2000-09-19

Merge from eCos master repository on 2000-09-19-06:25:26-BST
author jlarmour
date Tue, 19 Sep 2000 05:53:51 +0000
parents 59d97b6ba612
children ac086aa3217e
comparison
equal deleted inserted replaced
125:b4407dc7f59d 126:518f42066aba
96 #ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS 96 #ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
97 // The following function attempts to cause an exception in various 97 // The following function attempts to cause an exception in various
98 // hacky ways. It is machine dependent what exception is generated. 98 // hacky ways. It is machine dependent what exception is generated.
99 // It does reads rather than writes hoping not to corrupt anything 99 // It does reads rather than writes hoping not to corrupt anything
100 // important. 100 // important.
101 static int
102 cause_fpe(int num)
103 {
104 double a;
105
106 a = 1.0/num; // Depending on FPU emulation and/or
107 // the FPU architecture, this may
108 // cause an exception.
109 // (float division by zero)
110
111 return ((int)a)/num; // This may cause an exception if
112 // the architecture supports it.
113 // (integer division by zero).
114 } // cause_fpe()
115
101 void cause_exception(void) 116 void cause_exception(void)
102 { 117 {
103 int x; 118 int x;
104 unsigned int p=0; 119 unsigned int p=0;
105 120
121 // First try for an address exception (unaligned access exception
122 // or SEGV/BUS exceptions)
106 do { 123 do {
107 x=*(volatile int *)(p-1)/p; 124 x=*(volatile int *)(p-1);
108 p+=0x100000; 125 p+=0x100000;
109 } while(p != 0); 126 } while(p != 0);
127
128 // Next try an integer or floating point divide-by-zero exception.
129 cause_fpe(0);
110 } 130 }
111 #endif 131 #endif
112 132
113 static void entry0( CYG_ADDRWORD data ) 133 static void entry0( CYG_ADDRWORD data )
114 { 134 {
189 void except0_main( void ) 209 void except0_main( void )
190 { 210 {
191 // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT() 211 // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT()
192 CYG_TEST_GDBCMD("handle SIGBUS nostop"); 212 CYG_TEST_GDBCMD("handle SIGBUS nostop");
193 CYG_TEST_GDBCMD("handle SIGSEGV nostop"); 213 CYG_TEST_GDBCMD("handle SIGSEGV nostop");
214 CYG_TEST_GDBCMD("handle SIGFPE nostop");
194 215
195 CYG_TEST_INIT(); 216 CYG_TEST_INIT();
196 217
197 #ifdef HAL_VSR_SET_TO_ECOS_HANDLER 218 #ifdef HAL_VSR_SET_TO_ECOS_HANDLER
198 // Reclaim the VSR off CygMon possibly 219 // Reclaim the VSR off CygMon possibly
205 #ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS 226 #ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS
206 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL ); 227 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL );
207 #endif 228 #endif
208 #ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION 229 #ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION
209 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL ); 230 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL );
231 #endif
232 #ifdef CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO
233 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO, NULL );
234 #endif
235 #ifdef CYGNUM_HAL_EXCEPTION_FPU
236 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU, NULL );
237 #endif
238 #ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
239 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO, NULL );
210 #endif 240 #endif
211 #endif 241 #endif
212 242
213 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kexcept1", 243 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kexcept1",
214 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); 244 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);