diff options
author | Christopher Celio <celio@eecs.berkeley.edu> | 2012-09-10 17:51:35 -0700 |
---|---|---|
committer | Christopher Celio <celio@eecs.berkeley.edu> | 2012-09-10 17:51:35 -0700 |
commit | 79e238eff793adf04017519e10b30cc212f4c4bb (patch) | |
tree | d4f5b584e68c321a2ca6e56ff5724fbc9b480e0b /pk/int.c | |
parent | dd32a44bc07fe36d8c777e745b0b509ce2e55a2c (diff) | |
download | pk-79e238eff793adf04017519e10b30cc212f4c4bb.zip pk-79e238eff793adf04017519e10b30cc212f4c4bb.tar.gz pk-79e238eff793adf04017519e10b30cc212f4c4bb.tar.bz2 |
div/rem bug fixes.
Diffstat (limited to 'pk/int.c')
-rw-r--r-- | pk/int.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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)) |