aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorChristopher Celio <celio@eecs.berkeley.edu>2012-09-10 17:51:35 -0700
committerChristopher Celio <celio@eecs.berkeley.edu>2012-09-10 17:51:35 -0700
commit79e238eff793adf04017519e10b30cc212f4c4bb (patch)
treed4f5b584e68c321a2ca6e56ff5724fbc9b480e0b /pk
parentdd32a44bc07fe36d8c777e745b0b509ce2e55a2c (diff)
downloadpk-79e238eff793adf04017519e10b30cc212f4c4bb.zip
pk-79e238eff793adf04017519e10b30cc212f4c4bb.tar.gz
pk-79e238eff793adf04017519e10b30cc212f4c4bb.tar.bz2
div/rem bug fixes.
Diffstat (limited to 'pk')
-rw-r--r--pk/int.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/pk/int.c b/pk/int.c
index 1424e73..d7ced91 100644
--- a/pk/int.c
+++ b/pk/int.c
@@ -31,7 +31,26 @@ int emulate_int(trapframe_t* tf)
{
if(noisy)
printk("emulating div\n");
- XRD = softint_divu(xrs1, xrs2);
+
+ int num_negative = 0;
+
+ if ((signed long) xrs1 < 0)
+ {
+ xrs1 = -xrs1;
+ num_negative++;
+ }
+
+ if ((signed long) xrs2 < 0)
+ {
+ xrs2 = -xrs2;
+ num_negative++;
+ }
+
+ unsigned long res = softint_divu(xrs1, xrs2);
+ if (num_negative == 1)
+ XRD = -res;
+ else
+ XRD = res;
}
else if(IS_INSN(DIVU))
{
@@ -49,6 +68,10 @@ int emulate_int(trapframe_t* tf)
{
if(noisy)
printk("emulating rem\n");
+
+ if ((signed long) xrs1 < 0) {xrs1 = -xrs1;}
+ if ((signed long) xrs2 < 0) {xrs2 = -xrs2;}
+
XRD = softint_remu(xrs1, xrs2);
}
else if(IS_INSN(REMU))