From 1fe36bf84947198199b0dcf895aedfd584521e84 Mon Sep 17 00:00:00 2001 From: mischief Date: Sat, 1 Feb 2014 12:27:07 -0800 Subject: [PATCH] realemu: implement IDIV, mark 0xE0000 writeable, fix DIV overfow trap --- sys/src/cmd/aux/realemu/xec.c | 51 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/aux/realemu/xec.c b/sys/src/cmd/aux/realemu/xec.c index 5a5f8a8cf..90c8bc1ec 100644 --- a/sys/src/cmd/aux/realemu/xec.c +++ b/sys/src/cmd/aux/realemu/xec.c @@ -769,12 +769,58 @@ opdiv(Cpu *cpu, Inst *i) n = (uvlong)ar(ra)< m) - trap(cpu, EGPF); + trap(cpu, EDIV0); r = n%d; aw(ra, r); aw(qa, q); } - + +static void +opidiv(Cpu *cpu, Inst *i) +{ + Iarg *qa, *ra; + vlong n, q, min, max; + long r, d; + int s; + + s = i->a1->len*8; + d = ars(i->a1); + if(d == 0) + trap(cpu, EDIV0); + if(s == 8){ + qa = areg(cpu, 1, RAX); + ra = adup(qa); + ra->tag |= TH; + } else { + qa = areg(cpu, i->olen, RAX); + ra = areg(cpu, i->olen, RDX); + } + n = (vlong)ars(ra)< max || q < min) + trap(cpu, EDIV0); + + aw(ra, r); + aw(qa, q); +} static int cctrue(Cpu *cpu, Inst *i) @@ -1249,6 +1295,7 @@ static void (*exctab[NUMOP])(Cpu *cpu, Inst*) = { [OMUL] = opmul, [OIMUL] = opimul, [ODIV] = opdiv, + [OIDIV] = opidiv, [OLEA] = oplea, [OMOV] = opmov,