Skip to contentSkip to conversation

Implement division by 0 trap on the Sparc target

PATCH New Aurelien Jarno 1 participant 1 message Mar 19, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement division by 0 trap on the Sparc target

Hi all,

A division by 0 currently does not generate a trap on the Sparc target, instead it crashes QEMU. The patch below fixes that.

Bye,
Aurelien

Index: target-sparc/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op.c,v
retrieving revision 1.24

op.c +10 -0
diff -u -d -p -r1.24 op.c
@@ -671,6 +671,11 @@ void OPPROTO op_udiv_T1_T0(void)
 
     x0 = T0 | ((uint64_t) (env->y) << 32);
     x1 = T1;
+
+    if (x1 == 0) {
+        raise_exception(TT_DIV_ZERO);
+    }
+
     x0 = x0 / x1;
     if (x0 > 0xffffffff) {
 	T0 = 0xffffffff;
@@ -689,6 +694,11 @@ void OPPROTO op_sdiv_T1_T0(void)
 
     x0 = T0 | ((int64_t) (env->y) << 32);
     x1 = T1;
+
+    if (x1 == 0) {
+        raise_exception(TT_DIV_ZERO);
+    }
+
     x0 = x0 / x1;
     if ((int32_t) x0 != x0) {
 	T0 = x0 < 0? 0x80000000: 0x7fffffff;
Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net