|
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 |
|
2
|
138 #ifdef CYGPKG_HAL_I386_LINUX |
|
|
139 // We can't catch segmentation violation exceptions on Linux. |
|
|
140 CYG_TEST_PASS_FINISH("Except 1 OK"); |
|
|
141 #endif |
|
|
142 |
|
|
143 for(n = CYGNUM_HAL_EXCEPTION_MIN; n <= CYGNUM_HAL_EXCEPTION_MAX; n++) { |
|
0
|
144 p->register_exception( |
|
|
145 n, |
|
|
146 handler0, |
|
|
147 (CYG_ADDRWORD)123, |
|
|
148 &old_handler1, |
|
|
149 &old_data1); |
|
|
150 } |
|
|
151 |
|
2
|
152 CYG_TEST_PASS("Attempting to provoke exception"); |
|
0
|
153 |
|
|
154 cause_exception(); |
|
|
155 |
|
|
156 CYG_TEST_FAIL_FINISH("Couldn't cause exception"); |
|
|
157 } |
|
|
158 |
|
|
159 #ifdef CYG_HAL_TX39_JMR3904 |
|
|
160 |
|
|
161 externC cyg_VSR __default_exception_vsr; |
|
|
162 cyg_VSR *old_vsr; |
|
|
163 |
|
|
164 #endif |
|
|
165 |
|
|
166 void except0_main( void ) |
|
|
167 { |
|
2
|
168 // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT() |
|
|
169 CYG_TEST_GDBCMD("handle SIGBUS nostop"); |
|
|
170 CYG_TEST_GDBCMD("handle SIGSEGV nostop"); |
|
|
171 |
|
0
|
172 CYG_TEST_INIT(); |
|
|
173 |
|
2
|
174 #ifdef HAL_VSR_SET_TO_ECOS_HANDLER |
|
|
175 // Reclaim the VSR off CygMon possibly |
|
|
176 #ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS |
|
|
177 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL ); |
|
|
178 #endif |
|
|
179 #ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS |
|
|
180 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL ); |
|
|
181 #endif |
|
|
182 #ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION |
|
|
183 HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL ); |
|
|
184 #endif |
|
0
|
185 #endif |
|
|
186 |
|
|
187 new_thread(entry0, 0); |
|
|
188 |
|
|
189 Cyg_Scheduler::start(); |
|
|
190 |
|
|
191 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
192 } |
|
|
193 externC void |
|
|
194 cyg_start( void ) |
|
|
195 { |
|
|
196 except0_main(); |
|
|
197 } |
|
|
198 #else // def CYGPKG_KERNEL_EXCEPTIONS |
|
|
199 externC void |
|
|
200 cyg_start( void ) |
|
|
201 { |
|
|
202 CYG_TEST_INIT(); |
|
2
|
203 CYG_TEST_NA("Exceptions disabled"); |
|
0
|
204 } |
|
|
205 #endif // def CYGPKG_KERNEL_EXCEPTIONS |
|
|
206 |
|
|
207 // EOF except1.cxx |