• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <stdio.h>
3 #include <signal.h>
4 #include <setjmp.h>
5 #include <string.h>
6 #include <assert.h>
7 
8 static jmp_buf env_sigtrap;
handler_sigtrap(int x)9 static void handler_sigtrap ( int x ) { longjmp(env_sigtrap,1); }
10 
try(char * who,void (* maybe_traps)(long,long),long arg1,long arg2)11 void try ( char* who, void(*maybe_traps)(long,long), long arg1, long arg2 )
12 {
13    struct sigaction tmp_act;
14    int r, trapped = 0;
15    memset(&tmp_act, 0, sizeof(tmp_act));
16    tmp_act.sa_handler = handler_sigtrap;
17    sigemptyset(&tmp_act.sa_mask);
18    tmp_act.sa_flags = SA_NODEFER;
19    r = sigaction(SIGTRAP, &tmp_act, NULL);
20    assert(r == 0);
21    if (setjmp(env_sigtrap)) {
22       trapped = 1;
23    } else {
24       maybe_traps(arg1, arg2);
25    }
26    signal(SIGTRAP, SIG_DFL);
27 
28    printf("%s(%4lld,%4lld) -> %s\n", who, (long long int)arg1,
29 	   (long long int)arg2,
30 	  trapped ? "TRAP" : "no trap" );
31 }
32 
tw_0(long n,long m)33 static void tw_0 ( long n, long m ) {
34   __asm__ __volatile__("tw 0, %0,%1"
35 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
36 }
tw_1(long n,long m)37 static void tw_1 ( long n, long m ) {
38   __asm__ __volatile__("tw 1, %0,%1"
39 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
40 }
tw_2(long n,long m)41 static void tw_2 ( long n, long m ) {
42   __asm__ __volatile__("tw 2, %0,%1"
43 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
44 }
tw_3(long n,long m)45 static void tw_3 ( long n, long m ) {
46   __asm__ __volatile__("tw 3, %0,%1"
47 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
48 }
tw_4(long n,long m)49 static void tw_4 ( long n, long m ) {
50   __asm__ __volatile__("tw 4, %0,%1"
51 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
52 }
tw_5(long n,long m)53 static void tw_5 ( long n, long m ) {
54   __asm__ __volatile__("tw 5, %0,%1"
55 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
56 }
tw_6(long n,long m)57 static void tw_6 ( long n, long m ) {
58   __asm__ __volatile__("tw 6, %0,%1"
59 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
60 }
tw_7(long n,long m)61 static void tw_7 ( long n, long m ) {
62   __asm__ __volatile__("tw 7, %0,%1"
63 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
64 }
tw_8(long n,long m)65 static void tw_8 ( long n, long m ) {
66   __asm__ __volatile__("tw 8, %0,%1"
67 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
68 }
tw_9(long n,long m)69 static void tw_9 ( long n, long m ) {
70   __asm__ __volatile__("tw 9, %0,%1"
71 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
72 }
tw_10(long n,long m)73 static void tw_10 ( long n, long m ) {
74   __asm__ __volatile__("tw 10, %0,%1"
75 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
76 }
tw_11(long n,long m)77 static void tw_11 ( long n, long m ) {
78   __asm__ __volatile__("tw 11, %0,%1"
79 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
80 }
tw_12(long n,long m)81 static void tw_12 ( long n, long m ) {
82   __asm__ __volatile__("tw 12, %0,%1"
83 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
84 }
tw_13(long n,long m)85 static void tw_13 ( long n, long m ) {
86   __asm__ __volatile__("tw 13, %0,%1"
87 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
88 }
tw_14(long n,long m)89 static void tw_14 ( long n, long m ) {
90   __asm__ __volatile__("tw 14, %0,%1"
91 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
92 }
tw_15(long n,long m)93 static void tw_15 ( long n, long m ) {
94   __asm__ __volatile__("tw 15, %0,%1"
95 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
96 }
tw_16(long n,long m)97 static void tw_16 ( long n, long m ) {
98   __asm__ __volatile__("tw 16, %0,%1"
99 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
100 }
tw_17(long n,long m)101 static void tw_17 ( long n, long m ) {
102   __asm__ __volatile__("tw 17, %0,%1"
103 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
104 }
tw_18(long n,long m)105 static void tw_18 ( long n, long m ) {
106   __asm__ __volatile__("tw 18, %0,%1"
107 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
108 }
tw_19(long n,long m)109 static void tw_19 ( long n, long m ) {
110   __asm__ __volatile__("tw 19, %0,%1"
111 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
112 }
tw_20(long n,long m)113 static void tw_20 ( long n, long m ) {
114   __asm__ __volatile__("tw 20, %0,%1"
115 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
116 }
tw_21(long n,long m)117 static void tw_21 ( long n, long m ) {
118   __asm__ __volatile__("tw 21, %0,%1"
119 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
120 }
tw_22(long n,long m)121 static void tw_22 ( long n, long m ) {
122   __asm__ __volatile__("tw 22, %0,%1"
123 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
124 }
tw_23(long n,long m)125 static void tw_23 ( long n, long m ) {
126   __asm__ __volatile__("tw 23, %0,%1"
127 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
128 }
tw_24(long n,long m)129 static void tw_24 ( long n, long m ) {
130   __asm__ __volatile__("tw 24, %0,%1"
131 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
132 }
tw_25(long n,long m)133 static void tw_25 ( long n, long m ) {
134   __asm__ __volatile__("tw 25, %0,%1"
135 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
136 }
tw_26(long n,long m)137 static void tw_26 ( long n, long m ) {
138   __asm__ __volatile__("tw 26, %0,%1"
139 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
140 }
tw_27(long n,long m)141 static void tw_27 ( long n, long m ) {
142   __asm__ __volatile__("tw 27, %0,%1"
143 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
144 }
tw_28(long n,long m)145 static void tw_28 ( long n, long m ) {
146   __asm__ __volatile__("tw 28, %0,%1"
147 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
148 }
tw_29(long n,long m)149 static void tw_29 ( long n, long m ) {
150   __asm__ __volatile__("tw 29, %0,%1"
151 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
152 }
tw_30(long n,long m)153 static void tw_30 ( long n, long m ) {
154   __asm__ __volatile__("tw 30, %0,%1"
155 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
156 }
tw_31(long n,long m)157 static void tw_31 ( long n, long m ) {
158   __asm__ __volatile__("tw 31, %0,%1"
159 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
160 }
161 
162 #if defined(__powerpc64__)
163 
td_0(long n,long m)164 static void td_0 ( long n, long m ) {
165   __asm__ __volatile__("td 0, %0,%1"
166 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
167 }
td_1(long n,long m)168 static void td_1 ( long n, long m ) {
169   __asm__ __volatile__("td 1, %0,%1"
170 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
171 }
td_2(long n,long m)172 static void td_2 ( long n, long m ) {
173   __asm__ __volatile__("td 2, %0,%1"
174 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
175 }
td_3(long n,long m)176 static void td_3 ( long n, long m ) {
177   __asm__ __volatile__("td 3, %0,%1"
178 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
179 }
td_4(long n,long m)180 static void td_4 ( long n, long m ) {
181   __asm__ __volatile__("td 4, %0,%1"
182 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
183 }
td_5(long n,long m)184 static void td_5 ( long n, long m ) {
185   __asm__ __volatile__("td 5, %0,%1"
186 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
187 }
td_6(long n,long m)188 static void td_6 ( long n, long m ) {
189   __asm__ __volatile__("td 6, %0,%1"
190 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
191 }
td_7(long n,long m)192 static void td_7 ( long n, long m ) {
193   __asm__ __volatile__("td 7, %0,%1"
194 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
195 }
td_8(long n,long m)196 static void td_8 ( long n, long m ) {
197   __asm__ __volatile__("td 8, %0,%1"
198 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
199 }
td_9(long n,long m)200 static void td_9 ( long n, long m ) {
201   __asm__ __volatile__("td 9, %0,%1"
202 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
203 }
td_10(long n,long m)204 static void td_10 ( long n, long m ) {
205   __asm__ __volatile__("td 10, %0,%1"
206 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
207 }
td_11(long n,long m)208 static void td_11 ( long n, long m ) {
209   __asm__ __volatile__("td 11, %0,%1"
210 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
211 }
td_12(long n,long m)212 static void td_12 ( long n, long m ) {
213   __asm__ __volatile__("td 12, %0,%1"
214 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
215 }
td_13(long n,long m)216 static void td_13 ( long n, long m ) {
217   __asm__ __volatile__("td 13, %0,%1"
218 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
219 }
td_14(long n,long m)220 static void td_14 ( long n, long m ) {
221   __asm__ __volatile__("td 14, %0,%1"
222 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
223 }
td_15(long n,long m)224 static void td_15 ( long n, long m ) {
225   __asm__ __volatile__("td 15, %0,%1"
226 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
227 }
td_16(long n,long m)228 static void td_16 ( long n, long m ) {
229   __asm__ __volatile__("td 16, %0,%1"
230 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
231 }
td_17(long n,long m)232 static void td_17 ( long n, long m ) {
233   __asm__ __volatile__("td 17, %0,%1"
234 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
235 }
td_18(long n,long m)236 static void td_18 ( long n, long m ) {
237   __asm__ __volatile__("td 18, %0,%1"
238 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
239 }
td_19(long n,long m)240 static void td_19 ( long n, long m ) {
241   __asm__ __volatile__("td 19, %0,%1"
242 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
243 }
td_20(long n,long m)244 static void td_20 ( long n, long m ) {
245   __asm__ __volatile__("td 20, %0,%1"
246 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
247 }
td_21(long n,long m)248 static void td_21 ( long n, long m ) {
249   __asm__ __volatile__("td 21, %0,%1"
250 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
251 }
td_22(long n,long m)252 static void td_22 ( long n, long m ) {
253   __asm__ __volatile__("td 22, %0,%1"
254 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
255 }
td_23(long n,long m)256 static void td_23 ( long n, long m ) {
257   __asm__ __volatile__("td 23, %0,%1"
258 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
259 }
td_24(long n,long m)260 static void td_24 ( long n, long m ) {
261   __asm__ __volatile__("td 24, %0,%1"
262 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
263 }
td_25(long n,long m)264 static void td_25 ( long n, long m ) {
265   __asm__ __volatile__("td 25, %0,%1"
266 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
267 }
td_26(long n,long m)268 static void td_26 ( long n, long m ) {
269   __asm__ __volatile__("td 26, %0,%1"
270 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
271 }
td_27(long n,long m)272 static void td_27 ( long n, long m ) {
273   __asm__ __volatile__("td 27, %0,%1"
274 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
275 }
td_28(long n,long m)276 static void td_28 ( long n, long m ) {
277   __asm__ __volatile__("td 28, %0,%1"
278 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
279 }
td_29(long n,long m)280 static void td_29 ( long n, long m ) {
281   __asm__ __volatile__("td 29, %0,%1"
282 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
283 }
td_30(long n,long m)284 static void td_30 ( long n, long m ) {
285   __asm__ __volatile__("td 30, %0,%1"
286 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
287 }
td_31(long n,long m)288 static void td_31 ( long n, long m ) {
289   __asm__ __volatile__("td 31, %0,%1"
290 		       : /*out*/ : /*in*/ "r" (n), "r" (m) );
291 }
292 
293 #endif
294 
295 
main(void)296 int main ( void )
297 {
298 #define TW_GROUP(cmp) \
299    try("tw_" #cmp "", tw_##cmp, -150, -100); \
300    try("tw_" #cmp "", tw_##cmp, -100, -100); \
301    try("tw_" #cmp "", tw_##cmp,  -50, -100);
302 
303    TW_GROUP(0);
304    TW_GROUP(1);
305    TW_GROUP(2);
306    TW_GROUP(3);
307    TW_GROUP(4);
308    TW_GROUP(5);
309    TW_GROUP(6);
310    TW_GROUP(7);
311    TW_GROUP(8);
312    TW_GROUP(9);
313    TW_GROUP(10);
314    TW_GROUP(11);
315    TW_GROUP(12);
316    TW_GROUP(13);
317    TW_GROUP(14);
318    TW_GROUP(15);
319    TW_GROUP(16);
320    TW_GROUP(17);
321    TW_GROUP(18);
322    TW_GROUP(19);
323    TW_GROUP(20);
324    TW_GROUP(21);
325    TW_GROUP(22);
326    TW_GROUP(23);
327    TW_GROUP(24);
328    TW_GROUP(25);
329    TW_GROUP(26);
330    TW_GROUP(27);
331    TW_GROUP(28);
332    TW_GROUP(29);
333    TW_GROUP(30);
334    TW_GROUP(31);
335 #if defined(__powerpc64__)
336 #define TD_GROUP(cmp) \
337    try("td_" #cmp "", td_##cmp, -150, -100); \
338    try("td_" #cmp "", td_##cmp, -100, -100); \
339    try("td_" #cmp "", td_##cmp,  -50, -100);
340 
341    TD_GROUP(0);
342    TD_GROUP(1);
343    TD_GROUP(2);
344    TD_GROUP(3);
345    TD_GROUP(4);
346    TD_GROUP(5);
347    TD_GROUP(6);
348    TD_GROUP(7);
349    TD_GROUP(8);
350    TD_GROUP(9);
351    TD_GROUP(10);
352    TD_GROUP(11);
353    TD_GROUP(12);
354    TD_GROUP(13);
355    TD_GROUP(14);
356    TD_GROUP(15);
357    TD_GROUP(16);
358    TD_GROUP(17);
359    TD_GROUP(18);
360    TD_GROUP(19);
361    TD_GROUP(20);
362    TD_GROUP(21);
363    TD_GROUP(22);
364    TD_GROUP(23);
365    TD_GROUP(24);
366    TD_GROUP(25);
367    TD_GROUP(26);
368    TD_GROUP(27);
369    TD_GROUP(28);
370    TD_GROUP(29);
371    TD_GROUP(30);
372    TD_GROUP(31);
373 #endif
374    return 0;
375 }
376