Re: [GXemul-devel] Patch: don't crash on MIPS divide overflow
Status: Alpha
Brought to you by:
gavare
From: Anders G. <ga...@gm...> - 2018-08-19 08:23:26
|
> > When emulating the MIPS DIV and DDIV instructions, check for divide > overflow instead of performing the overflowing divide on the host and > crashing the emulator. This is needed to run recent versions of the > NetBSD test suite on an emulated MIPS system. > > --- gxemul.old/work/gxemul-0.6.0.1/src/cpus/cpu_mips_instr.cc > 2018-08-08 17:27:19.146417631 +0300 > +++ gxemul/work/gxemul-0.6.0.1/src/cpus/cpu_mips_instr.cc > 2018-08-08 17:27:27.944250037 +0300 > @@ -1262,6 +1262,8 @@ > int32_t res, rem; > if (b == 0) > res = 0, rem = a; > + else if (a == (int32_t)0x80000000U && b == -1) > + res = 0, rem = 0; > else > res = a / b, rem = a - b*res; > cpu->cd.mips.lo = (int32_t)res; > @@ -1284,6 +1286,8 @@ > int64_t res, rem; > if (b == 0) > res = 0; > + else if (a == (int64_t)0x8000000000000000ULL && b == -1) > + res = 0; > else > res = a / b; > rem = a - b*res; > Thanks Andreas. The fix is now in trunk. A snapshot can be found here for testing: http://gavare.se/gxemul/news.html Anders |