[System] Process.WaitForExit now triggers event Exited.
[mono.git] / mono / mini / exceptions-s390x.c
1 /*------------------------------------------------------------------*/
2 /*                                                                  */
3 /* Name        - exceptions-s390.c                                  */
4 /*                                                                  */
5 /* Function    - Exception support for S/390.                       */
6 /*                                                                  */
7 /* Name        - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
8 /*                                                                  */
9 /* Date        - January, 2004                                      */
10 /*                                                                  */
11 /* Derivation  - From exceptions-x86 & exceptions-ppc               */
12 /*               Paolo Molaro (lupus@ximian.com)                    */
13 /*               Dietmar Maurer (dietmar@ximian.com)                */
14 /*                                                                  */
15 /* Copyright   - 2001 Ximian, Inc.                                  */
16 /*                                                                  */
17 /*------------------------------------------------------------------*/
18
19 /*------------------------------------------------------------------*/
20 /*                 D e f i n e s                                    */
21 /*------------------------------------------------------------------*/
22
23 #define S390_CALLFILTER_INTREGS         S390_MINIMAL_STACK_SIZE
24 #define S390_CALLFILTER_FLTREGS         (S390_CALLFILTER_INTREGS+(16*sizeof(gulong)))
25 #define S390_CALLFILTER_ACCREGS         (S390_CALLFILTER_FLTREGS+(16*sizeof(gdouble)))
26 #define S390_CALLFILTER_SIZE            (S390_CALLFILTER_ACCREGS+(16*sizeof(gint32)))
27
28 #define S390_THROWSTACK_ACCPRM          S390_MINIMAL_STACK_SIZE
29 #define S390_THROWSTACK_FPCPRM          (S390_THROWSTACK_ACCPRM+sizeof(gpointer))
30 #define S390_THROWSTACK_RETHROW         (S390_THROWSTACK_FPCPRM+sizeof(gulong))
31 #define S390_THROWSTACK_INTREGS         (S390_THROWSTACK_RETHROW+sizeof(gboolean))
32 #define S390_THROWSTACK_FLTREGS         (S390_THROWSTACK_INTREGS+(16*sizeof(gulong)))
33 #define S390_THROWSTACK_ACCREGS         (S390_THROWSTACK_FLTREGS+(16*sizeof(gdouble)))
34 #define S390_THROWSTACK_SIZE            (S390_THROWSTACK_ACCREGS+(16*sizeof(gint32)))
35
36 #define SZ_THROW        384
37
38 #define setup_context(ctx)
39
40 /*========================= End of Defines =========================*/
41
42 /*------------------------------------------------------------------*/
43 /*                 I n c l u d e s                                  */
44 /*------------------------------------------------------------------*/
45
46 #include <config.h>
47 #include <glib.h>
48 #include <signal.h>
49 #include <string.h>
50 #include <ucontext.h>
51
52 #include <mono/arch/s390x/s390x-codegen.h>
53 #include <mono/metadata/appdomain.h>
54 #include <mono/metadata/tabledefs.h>
55 #include <mono/metadata/threads.h>
56 #include <mono/metadata/debug-helpers.h>
57 #include <mono/metadata/exception.h>
58 #include <mono/metadata/mono-debug.h>
59
60 #include "mini.h"
61 #include "mini-s390x.h"
62
63 /*========================= End of Includes ========================*/
64
65 /*------------------------------------------------------------------*/
66 /*                   P r o t o t y p e s                            */
67 /*------------------------------------------------------------------*/
68
69 gboolean mono_arch_handle_exception (void     *ctx,
70                                      gpointer obj);
71
72 /*========================= End of Prototypes ======================*/
73
74 /*------------------------------------------------------------------*/
75 /*                 G l o b a l   V a r i a b l e s                  */
76 /*------------------------------------------------------------------*/
77
78 typedef enum {
79         by_none,
80         by_token
81 } throwType;
82
83 /*====================== End of Global Variables ===================*/
84
85 /*------------------------------------------------------------------*/
86 /*                                                                  */
87 /* Name         - mono_arch_get_call_filter                         */
88 /*                                                                  */
89 /* Function     - Return a pointer to a method which calls an       */
90 /*                exception filter. We also use this function to    */
91 /*                call finally handlers (we pass NULL as @exc       */
92 /*                object in this case).                             */
93 /*                                                                  */
94 /*------------------------------------------------------------------*/
95
96 gpointer
97 mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
98 {
99         static guint8 *start;
100         static int inited = 0;
101         guint8 *code;
102         int alloc_size, pos, i;
103         GSList *unwind_ops = NULL;
104         MonoJumpInfo *ji = NULL;
105
106         g_assert (!aot);
107
108         if (inited)
109                 return start;
110
111         inited = 1;
112         /* call_filter (MonoContext *ctx, unsigned long eip, gpointer exc) */
113         code = start = mono_global_codeman_reserve (512);
114
115         s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
116         s390_lgr  (code, s390_r14, STK_BASE);
117         alloc_size = S390_ALIGN(S390_CALLFILTER_SIZE, S390_STACK_ALIGNMENT);
118         s390_aghi (code, STK_BASE, -alloc_size);
119         s390_stg  (code, s390_r14, 0, STK_BASE, 0);
120
121         /*------------------------------------------------------*/
122         /* save general registers on stack                      */
123         /*------------------------------------------------------*/
124         s390_stmg (code, s390_r0, STK_BASE, STK_BASE, S390_CALLFILTER_INTREGS);
125
126         /*------------------------------------------------------*/
127         /* save floating point registers on stack               */
128         /*------------------------------------------------------*/
129         pos = S390_CALLFILTER_FLTREGS;
130         for (i = 0; i < 16; ++i) {
131                 s390_std (code, i, 0, STK_BASE, pos);
132                 pos += sizeof (gdouble);
133         }
134
135         /*------------------------------------------------------*/
136         /* save access registers on stack                       */
137         /*------------------------------------------------------*/
138         s390_stam (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
139
140         /*------------------------------------------------------*/
141         /* Get A(Context)                                       */
142         /*------------------------------------------------------*/
143         s390_lgr  (code, s390_r13, s390_r2);
144
145         /*------------------------------------------------------*/
146         /* Get A(Handler Entry Point)                           */
147         /*------------------------------------------------------*/
148         s390_lgr  (code, s390_r0, s390_r3);
149
150         /*------------------------------------------------------*/
151         /* Set parameter register with Exception                */
152         /*------------------------------------------------------*/
153         s390_lgr  (code, s390_r2, s390_r4);
154
155         /*------------------------------------------------------*/
156         /* Load all registers with values from the context      */
157         /*------------------------------------------------------*/
158         s390_lmg  (code, s390_r3, s390_r12, s390_r13, 
159                    G_STRUCT_OFFSET(MonoContext, uc_mcontext.gregs[3]));
160         pos = G_STRUCT_OFFSET(MonoContext, uc_mcontext.fpregs.fprs[0]);
161         for (i = 0; i < 16; ++i) {
162                 s390_ld  (code, i, 0, s390_r13, pos);
163                 pos += sizeof(gdouble);
164         }
165
166 #if 0
167         /*------------------------------------------------------*/
168         /* We need to preserve current SP before calling filter */
169         /* with SP from the context                             */
170         /*------------------------------------------------------*/
171         s390_lgr  (code, s390_r14, STK_BASE);
172         s390_lg   (code, STK_BASE, 0, s390_r13,
173                    G_STRUCT_OFFSET(MonoContext, uc_mcontext.gregs[15]));
174         s390_lgr  (code, s390_r13, s390_r14);
175 #endif
176
177         /*------------------------------------------------------*/
178         /* Go call filter                                       */
179         /*------------------------------------------------------*/
180         s390_lgr  (code, s390_r1, s390_r0);
181         s390_basr (code, s390_r14, s390_r1);
182
183         /*------------------------------------------------------*/
184         /* Save return value                                    */
185         /*------------------------------------------------------*/
186         s390_lgr  (code, s390_r14, s390_r2);
187
188 #if 0
189         /*------------------------------------------------------*/
190         /* Reload our stack register with value saved in context*/
191         /*------------------------------------------------------*/
192         s390_lgr  (code, STK_BASE, s390_r13);
193 #endif
194
195         /*------------------------------------------------------*/
196         /* Restore all the regs from the stack                  */
197         /*------------------------------------------------------*/
198         s390_lmg  (code, s390_r0, s390_r13, STK_BASE, S390_CALLFILTER_INTREGS);
199         pos = S390_CALLFILTER_FLTREGS;
200         for (i = 0; i < 16; ++i) {
201                 s390_ld (code, i, 0, STK_BASE, pos);
202                 pos += sizeof (gdouble);
203         }
204
205         s390_lgr  (code, s390_r2, s390_r14);
206         s390_lam  (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
207         s390_aghi (code, s390_r15, alloc_size);
208         s390_lmg  (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
209         s390_br   (code, s390_r14);
210
211         g_assert ((code - start) < SZ_THROW); 
212
213         if (info)
214                 *info = mono_tramp_info_create ("call_filter",
215                                                 start, code - start, ji,
216                                                 unwind_ops);
217
218         return start;
219 }
220
221 /*========================= End of Function ========================*/
222
223 /*------------------------------------------------------------------*/
224 /*                                                                  */
225 /* Name         - throw_exception.                                  */
226 /*                                                                  */
227 /* Function     - Raise an exception based on the parameters passed.*/
228 /*                                                                  */
229 /*------------------------------------------------------------------*/
230
231 static void
232 throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp, 
233                  gulong *int_regs, gdouble *fp_regs, gint32 *acc_regs, 
234                  guint fpc, gboolean rethrow)
235 {
236         MonoContext ctx;
237         int iReg;
238
239         memset(&ctx, 0, sizeof(ctx));
240
241         setup_context(&ctx);
242
243         /* adjust eip so that it point into the call instruction */
244         ip -= 2;
245
246         for (iReg = 0; iReg < 16; iReg++) {
247                 ctx.uc_mcontext.gregs[iReg]         = int_regs[iReg];
248                 ctx.uc_mcontext.fpregs.fprs[iReg].d = fp_regs[iReg];
249                 ctx.uc_mcontext.aregs[iReg]         = acc_regs[iReg];
250         }
251
252         ctx.uc_mcontext.fpregs.fpc = fpc;
253
254         MONO_CONTEXT_SET_BP (&ctx, sp);
255         MONO_CONTEXT_SET_IP (&ctx, ip);
256         
257         if (mono_object_isinst (exc, mono_defaults.exception_class)) {
258                 MonoException *mono_ex = (MonoException*)exc;
259                 if (!rethrow)
260                         mono_ex->stack_trace = NULL;
261         }
262 //      mono_arch_handle_exception (&ctx, exc, FALSE);
263         mono_handle_exception (&ctx, exc);
264         mono_restore_context(&ctx);
265
266         g_assert_not_reached ();
267 }
268
269 /*========================= End of Function ========================*/
270
271 /*------------------------------------------------------------------*/
272 /*                                                                  */
273 /* Name         - get_throw_exception_generic                       */
274 /*                                                                  */
275 /* Function     - Return a function pointer which can be used to    */
276 /*                raise exceptions. The returned function has the   */
277 /*                following signature:                              */
278 /*                void (*func) (MonoException *exc); or,            */
279 /*                void (*func) (char *exc_name);                    */
280 /*                                                                  */
281 /*------------------------------------------------------------------*/
282
283 static gpointer 
284 mono_arch_get_throw_exception_generic (int size, MonoTrampInfo **info, 
285                                 int corlib, gboolean rethrow, gboolean aot)
286 {
287         guint8 *code, *start;
288         int alloc_size, pos, i;
289         MonoJumpInfo *ji = NULL;
290         GSList *unwind_ops = NULL;
291
292         code = start = mono_global_codeman_reserve(size);
293
294         s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
295         alloc_size = S390_ALIGN(S390_THROWSTACK_SIZE, S390_STACK_ALIGNMENT);
296         s390_lgr  (code, s390_r14, STK_BASE);
297         s390_aghi (code, STK_BASE, -alloc_size);
298         s390_stg  (code, s390_r14, 0, STK_BASE, 0);
299         s390_lgr  (code, s390_r3, s390_r2);
300         if (corlib) {
301                 s390_basr (code, s390_r13, 0);
302                 s390_j    (code, 10);
303                 s390_llong(code, mono_defaults.exception_class->image);
304                 s390_llong(code, mono_exception_from_token);
305                 s390_lg   (code, s390_r2, 0, s390_r13, 4);
306                 s390_lg   (code, s390_r1, 0, s390_r13, 12);
307                 s390_basr (code, s390_r14, s390_r1);
308         }
309
310         /*------------------------------------------------------*/
311         /* save the general registers on the stack              */
312         /*------------------------------------------------------*/
313         s390_stmg (code, s390_r0, s390_r13, STK_BASE, S390_THROWSTACK_INTREGS);
314
315         s390_lgr  (code, s390_r1, STK_BASE);
316         s390_aghi (code, s390_r1, alloc_size);
317         /*------------------------------------------------------*/
318         /* save the return address in the parameter register    */
319         /*------------------------------------------------------*/
320         s390_lg   (code, s390_r3, 0, s390_r1, S390_RET_ADDR_OFFSET);
321
322         /*------------------------------------------------------*/
323         /* save the floating point registers                    */
324         /*------------------------------------------------------*/
325         pos = S390_THROWSTACK_FLTREGS;
326         for (i = 0; i < 16; ++i) {
327                 s390_std (code, i, 0, STK_BASE, pos);
328                 pos += sizeof (gdouble);
329         }
330         /*------------------------------------------------------*/
331         /* save the access registers                            */
332         /*------------------------------------------------------*/
333         s390_stam (code, s390_r0, s390_r15, STK_BASE, S390_THROWSTACK_ACCREGS);
334
335         /*------------------------------------------------------*/
336         /* call throw_exception (tkn, ip, sp, gr, fr, ar, re)   */
337         /* - r2 already contains *exc                           */
338         /*------------------------------------------------------*/
339         s390_lgr  (code, s390_r4, s390_r1);        /* caller sp */
340
341         /*------------------------------------------------------*/
342         /* pointer to the saved int regs                        */
343         /*------------------------------------------------------*/
344         s390_la   (code, s390_r5, 0, STK_BASE, S390_THROWSTACK_INTREGS);
345         s390_la   (code, s390_r6, 0, STK_BASE, S390_THROWSTACK_FLTREGS);
346         s390_la   (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_ACCREGS);
347         s390_stg  (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_ACCPRM);
348         s390_stfpc(code, STK_BASE, S390_THROWSTACK_FPCPRM+4);
349         s390_lghi (code, s390_r7, rethrow);
350         s390_stg  (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_RETHROW);
351         s390_basr (code, s390_r13, 0);
352         s390_j    (code, 6);
353         s390_llong(code, throw_exception);
354         s390_lg   (code, s390_r1, 0, s390_r13, 4);
355         s390_basr (code, s390_r14, s390_r1);
356         /* we should never reach this breakpoint */
357         s390_break (code);
358         g_assert ((code - start) < size);
359
360         if (info)
361                 *info = mono_tramp_info_create (corlib ? "throw_corlib_exception" 
362                                                       : (rethrow ? "rethrow_exception" 
363                                                       : "throw_exception"), 
364                                                 start, code - start, ji, unwind_ops);
365
366         return start;
367 }
368
369 /*========================= End of Function ========================*/
370
371 /*------------------------------------------------------------------*/
372 /*                                                                  */
373 /* Name         - arch_get_throw_exception                          */
374 /*                                                                  */
375 /* Function     - Return a function pointer which can be used to    */
376 /*                raise exceptions. The returned function has the   */
377 /*                following signature:                              */
378 /*                void (*func) (MonoException *exc);                */
379 /*                                                                  */
380 /*------------------------------------------------------------------*/
381
382 gpointer
383 mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
384 {
385
386         g_assert (!aot);
387         if (info)
388                 *info = NULL;
389
390         return (mono_arch_get_throw_exception_generic (SZ_THROW, info, FALSE, FALSE, aot));
391 }
392
393 /*========================= End of Function ========================*/
394
395 /*------------------------------------------------------------------*/
396 /*                                                                  */
397 /* Name         - arch_get_rethrow_exception                        */
398 /*                                                                  */
399 /* Function     - Return a function pointer which can be used to    */
400 /*                raise exceptions. The returned function has the   */
401 /*                following signature:                              */
402 /*                void (*func) (MonoException *exc);                */
403 /*                                                                  */
404 /*------------------------------------------------------------------*/
405
406 gpointer 
407 mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
408 {
409         g_assert (!aot);
410         if (info)
411                 *info = NULL;
412
413         return (mono_arch_get_throw_exception_generic (SZ_THROW, info, FALSE, FALSE, aot));
414 }
415
416 /*========================= End of Function ========================*/
417
418 /*------------------------------------------------------------------*/
419 /*                                                                  */
420 /* Name         - arch_get_corlib_exception                         */
421 /*                                                                  */
422 /* Function     - Return a function pointer which can be used to    */
423 /*                raise corlib exceptions. The return function has  */
424 /*                the following signature:                          */
425 /*                void (*func) (guint32 token, guint32 offset)      */
426 /*                                                                  */
427 /*------------------------------------------------------------------*/
428
429 gpointer
430 mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
431 {
432         g_assert (!aot);
433         if (info)
434                 *info = NULL;
435
436         return (mono_arch_get_throw_exception_generic (SZ_THROW, info, TRUE, FALSE, aot));
437 }       
438
439 /*========================= End of Function ========================*/
440
441 /*------------------------------------------------------------------*/
442 /*                                                                  */
443 /* Name         - mono_arch_find_jit_info                           */
444 /*                                                                  */
445 /* Function     - See exceptions-amd64.c for docs.                  */
446 /*                                                                  */
447 /*------------------------------------------------------------------*/
448
449 gboolean
450 mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, 
451                          MonoJitInfo *ji, MonoContext *ctx, 
452                          MonoContext *new_ctx, MonoLMF **lmf,
453                          mgreg_t **save_locations,
454                          StackFrameInfo *frame)
455 {
456         gpointer ip = (gpointer) MONO_CONTEXT_GET_IP (ctx);
457         MonoS390StackFrame *sframe;
458
459         memset (frame, 0, sizeof (StackFrameInfo));
460         frame->ji = ji;
461
462         *new_ctx = *ctx;
463
464         if (ji != NULL) {
465                 gint64 address;
466                 guint8 *cfa;
467                 guint32 unwind_info_len;
468                 guint8 *unwind_info;
469                 mgreg_t regs[16];
470
471                 frame->type = FRAME_TYPE_MANAGED;
472
473                 unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len);
474
475                 address = (char *)ip - (char *)ji->code_start;
476
477                 memcpy(&regs, &ctx->uc_mcontext.gregs, sizeof(regs));
478                 mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start,
479                                                    (guint8 *) ji->code_start + ji->code_size,
480                                                    ip, NULL, regs, 16, save_locations,
481                                                    MONO_MAX_IREGS, &cfa);
482                 memcpy (&new_ctx->uc_mcontext.gregs, &regs, sizeof(regs));
483                 MONO_CONTEXT_SET_IP(new_ctx, regs[14] - 2);
484                 MONO_CONTEXT_SET_BP(new_ctx, cfa);
485         
486                 return TRUE;
487         } else if (*lmf) {
488
489                 ji = mini_jit_info_table_find (domain, (gpointer)(*lmf)->eip, NULL);
490                 if (!ji) {
491                         if (!(*lmf)->method)
492                                 return FALSE;
493                 
494                         frame->method = (*lmf)->method;
495                 }
496
497                 frame->ji = ji;
498                 frame->type = FRAME_TYPE_MANAGED_TO_NATIVE;
499
500                 memcpy(new_ctx->uc_mcontext.gregs, (*lmf)->gregs, sizeof((*lmf)->gregs));
501                 memcpy(new_ctx->uc_mcontext.fpregs.fprs, (*lmf)->fregs, sizeof((*lmf)->fregs));
502                 MONO_CONTEXT_SET_BP (new_ctx, (*lmf)->ebp);
503                 MONO_CONTEXT_SET_IP (new_ctx, (*lmf)->eip - 2);
504                 *lmf = (*lmf)->previous_lmf;
505
506                 return TRUE;
507         }
508
509         return FALSE;
510 }
511
512 /*========================= End of Function ========================*/
513
514 /*------------------------------------------------------------------*/
515 /*                                                                  */
516 /* Name         - mono_arch_handle_exception                        */
517 /*                                                                  */
518 /* Function     - Handle an exception raised by the JIT code.       */
519 /*                                                                  */
520 /* Parameters   - ctx       - Saved processor state                 */
521 /*                obj       - The exception object                  */
522 /*                                                                  */
523 /*------------------------------------------------------------------*/
524
525 gboolean
526 mono_arch_handle_exception (void *uc, gpointer obj)
527 {
528         return mono_handle_exception (uc, obj);
529 }
530
531 /*========================= End of Function ========================*/
532
533 /*------------------------------------------------------------------*/
534 /*                                                                  */
535 /* Name         - mono_arch_ip_from_context                         */
536 /*                                                                  */
537 /* Function     - Return the instruction pointer from the context.  */
538 /*                                                                  */
539 /* Parameters   - sigctx    - Saved processor state                 */
540 /*                                                                  */
541 /*------------------------------------------------------------------*/
542
543 gpointer
544 mono_arch_ip_from_context (void *sigctx)
545 {
546         return ((gpointer) MONO_CONTEXT_GET_IP(((MonoContext *) sigctx)));
547 }
548
549
550 /*========================= End of Function ========================*/
551
552 /*------------------------------------------------------------------*/
553 /*                                                                  */
554 /* Name         - mono_arch_get_restore_context                    */
555 /*                                                                  */
556 /* Function     - Return the address of the routine that will rest- */
557 /*                ore the context.                                  */
558 /*                                                                  */
559 /*------------------------------------------------------------------*/
560
561 gpointer
562 mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
563 {
564         g_assert (!aot);
565         if (info)
566                 *info = NULL;
567
568         return setcontext;
569 }
570
571 /*========================= End of Function ========================*/
572
573 /*------------------------------------------------------------------*/
574 /*                                                                  */
575 /* Name         - mono_arch_is_int_overflow                         */
576 /*                                                                  */
577 /* Function     - Inspect the code that raised the SIGFPE signal    */
578 /*                to see if the DivideByZero or Arithmetic exception*/
579 /*                should be raised.                                 */
580 /*                                                                  */
581 /*------------------------------------------------------------------*/
582
583 gboolean
584 mono_arch_is_int_overflow (void *uc, void *info)
585 {
586         MonoContext *ctx;
587         guint8      *code;
588         guint64     *operand;
589         gboolean    arithExc = TRUE;
590         gint        regNo,
591                     idxNo,
592                     offset;
593
594         ctx  = (MonoContext *) uc;
595         code =  (guint8 *) ((siginfo_t *)info)->si_addr;
596         /*----------------------------------------------------------*/
597         /* Divide operations are the only ones that will give the   */
598         /* divide by zero exception so just check for these ops.    */
599         /*----------------------------------------------------------*/
600         switch (code[0]) {
601                 case 0x1d :             /* Divide Register          */
602                         regNo = code[1] & 0x0f; 
603                         if (ctx->uc_mcontext.gregs[regNo] == 0)
604                                 arithExc = FALSE;
605                 break;
606                 case 0x5d :             /* Divide                   */
607                         regNo   = (code[2] & 0xf0 >> 8);        
608                         idxNo   = (code[1] & 0x0f);
609                         offset  = *((guint16 *) code+2) & 0x0fff;
610                         operand = (guint64*)(ctx->uc_mcontext.gregs[regNo] + offset);
611                         if (idxNo != 0)
612                                 operand += ctx->uc_mcontext.gregs[idxNo];
613                         if (*operand == 0)
614                                 arithExc = FALSE; 
615                 break;
616                 case 0xb9 :             /* DL[GR] or DS[GR]         */
617                         if ((code[1] == 0x97) || (code[1] == 0x87) ||
618                             (code[1] == 0x0d) || (code[1] == 0x1d)) {
619                                 regNo = (code[3] & 0x0f);
620                                 if (ctx->uc_mcontext.gregs[regNo] == 0)
621                                         arithExc = FALSE;
622                         }
623                 break;
624                 case 0xe3 :             /* DL[G] | DS[G]            */
625                         if ((code[5] == 0x97) || (code[5] == 0x87) ||
626                             (code[5] == 0x0d) || (code[5] == 0x1d)) {
627                                 regNo   = (code[2] & 0xf0 >> 8);        
628                                 idxNo   = (code[1] & 0x0f);
629                                 offset  = (code[2] & 0x0f << 8) + 
630                                           code[3] + (code[4] << 12);
631                                 operand = (guint64*)(ctx->uc_mcontext.gregs[regNo] + offset);
632                                 if (idxNo != 0)
633                                         operand += ctx->uc_mcontext.gregs[idxNo];
634                                 if (*operand == 0)
635                                         arithExc = FALSE; 
636                         }
637                 break;
638                 default:
639                         arithExc = TRUE;
640         }
641         ctx->uc_mcontext.psw.addr = (guint64)code;
642         return (arithExc);
643 }
644
645 /*========================= End of Function ========================*/