From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sigma.offblast.org ([199.191.58.44]) by ttr; Fri Jan 31 04:45:20 EST 2014 Received: from iota.offblast.org ([66.109.99.211]) by sigma; Fri Jan 31 04:45:14 EST 2014 Date: Fri, 31 Jan 2014 01:45:09 -0800 From: Nick Owens To: 9front@9front.org Subject: realemu: implementing IDIV Message-ID: <20140131094509.GB27169@iota.offblast.org> List-ID: <9front.9front.org> X-Glyph: ➈ X-Bullshit: scale-out object-oriented XML rich-client general-purpose property-oriented method MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) currently aux/realemu does not have the IDIV instruction, which is used by newer versions of vga bioses included with qemu (1.7 here on debian 8). please review this patch which implements IDIV (signed integer division). it should account correctly for sign extension and overflow. see p858-860 of the intel manual. this patch also includes a fix for writing to 0xEXXXX, which is written to by the newer vga bios. writes to this range were previously trapped and considered errors. also included is a fix for overflow in the DIV instruction. on overflow, a division by zero trap should occur. "Overflow is indicated with the #DE (divide error) exception rather than with the CF flag." see p706 of the intel manual. http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf diff -r 20c2c6fccfee sys/src/cmd/aux/realemu/main.c --- a/sys/src/cmd/aux/realemu/main.c Sat Jan 11 16:07:35 2014 +0100 +++ b/sys/src/cmd/aux/realemu/main.c Thu Jan 30 01:29:46 2014 -0800 @@ -286,7 +286,7 @@ /* B */ nil, rrealmem, wrealmem, /* RAM: VGA framebuffer */ /* C */ memory, rmem, wmem, /* ROM: VGA BIOS */ /* D */ nil, rbad, wbad, - /* E */ memory, rmem, wbad, /* ROM: BIOS */ + /* E */ memory, rmem, wmem, /* ROM: BIOS */ /* F */ memory, rmem, wbad, /* ROM: BIOS */ }; diff -r 20c2c6fccfee sys/src/cmd/aux/realemu/xec.c --- a/sys/src/cmd/aux/realemu/xec.c Sat Jan 11 16:07:35 2014 +0100 +++ b/sys/src/cmd/aux/realemu/xec.c Thu Jan 30 01:29:46 2014 -0800 @@ -769,12 +769,59 @@ 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 m, r, d; + int s; + + s = i->a1->len*8; + m = mask(s); + 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 +1296,7 @@ [OMUL] = opmul, [OIMUL] = opimul, [ODIV] = opdiv, + [OIDIV] = opidiv, [OLEA] = oplea, [OMOV] = opmov,