|
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 |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm |
|
|
34 // Date: 1998-06-15 |
|
|
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 |
|
|
79 CYG_TEST_CHECK(number == CYG_EXCEPTION_MAX, "handler given wrong number"); |
|
|
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( |
|
|
113 CYG_EXCEPTION_MAX, |
|
|
114 &handler1, |
|
|
115 (CYG_ADDRWORD)&d0, |
|
|
116 &old_handler, |
|
|
117 &old_data); |
|
|
118 |
|
|
119 p->register_exception( |
|
|
120 CYG_EXCEPTION_MAX, |
|
|
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 |
|
|
131 p->deliver_exception(CYG_EXCEPTION_MAX, (CYG_ADDRWORD)99); |
|
|
132 |
|
|
133 CYG_TEST_INFO("handler 1 returned"); |
|
|
134 |
|
|
135 p->deregister_exception(CYG_EXCEPTION_MAX); |
|
|
136 p->deregister_exception(CYG_EXCEPTION_MAX); |
|
|
137 |
|
|
138 for(n = CYG_EXCEPTION_MIN; n <= CYG_EXCEPTION_MAX; n++) { |
|
|
139 p->register_exception( |
|
|
140 n, |
|
|
141 handler0, |
|
|
142 (CYG_ADDRWORD)123, |
|
|
143 &old_handler1, |
|
|
144 &old_data1); |
|
|
145 } |
|
|
146 |
|
|
147 CYG_TEST_INFO("Attempting to provoke exception"); |
|
|
148 |
|
|
149 cause_exception(); |
|
|
150 |
|
|
151 CYG_TEST_FAIL_FINISH("Couldn't cause exception"); |
|
|
152 } |
|
|
153 |
|
|
154 #ifdef CYG_HAL_TX39_JMR3904 |
|
|
155 |
|
|
156 externC cyg_VSR __default_exception_vsr; |
|
|
157 cyg_VSR *old_vsr; |
|
|
158 |
|
|
159 #endif |
|
|
160 |
|
|
161 void except0_main( void ) |
|
|
162 { |
|
|
163 CYG_TEST_INIT(); |
|
|
164 |
|
|
165 #ifdef CYG_HAL_TX39_JMR3904 |
|
|
166 |
|
|
167 HAL_VSR_SET( CYG_VECTOR_LOAD_ADDRESS, __default_exception_vsr, &old_vsr ); |
|
|
168 |
|
|
169 #endif |
|
|
170 |
|
|
171 new_thread(entry0, 0); |
|
|
172 |
|
|
173 Cyg_Scheduler::start(); |
|
|
174 |
|
|
175 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
176 } |
|
|
177 externC void |
|
|
178 cyg_start( void ) |
|
|
179 { |
|
|
180 except0_main(); |
|
|
181 } |
|
|
182 #else // def CYGPKG_KERNEL_EXCEPTIONS |
|
|
183 externC void |
|
|
184 cyg_start( void ) |
|
|
185 { |
|
|
186 CYG_TEST_INIT(); |
|
|
187 CYG_TEST_PASS_FINISH("NA: Exceptions disabled"); |
|
|
188 } |
|
|
189 #endif // def CYGPKG_KERNEL_EXCEPTIONS |
|
|
190 |
|
|
191 // EOF except1.cxx |