- update sector count before calling write completion function (SF patch #2144692)
[bochs-mirror.git] / cpu / mult8.cc
blobb385328a4f0cf5606e62e793baa1c40c61a8a37d
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: mult8.cc,v 1.31 2008/08/11 20:34:05 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /////////////////////////////////////////////////////////////////////////
28 #define NEED_CPU_REG_SHORTCUTS 1
29 #include "bochs.h"
30 #include "cpu.h"
31 #define LOG_THIS BX_CPU_THIS_PTR
33 void BX_CPP_AttrRegparmN(1) BX_CPU_C::MUL_ALEbR(bxInstruction_c *i)
35 Bit8u op1 = AL;
36 Bit8u op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
38 Bit32u product_16 = ((Bit16u) op1) * ((Bit16u) op2);
40 Bit8u product_8l = (product_16 & 0xFF);
41 Bit8u product_8h = product_16 >> 8;
43 /* now write product back to destination */
44 AX = product_16;
46 /* set EFLAGS */
47 SET_FLAGS_OSZAPC_LOGIC_8(product_8l);
48 if(product_8h != 0)
50 ASSERT_FLAGS_OxxxxC();
54 void BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_ALEbR(bxInstruction_c *i)
56 Bit8s op1 = AL;
57 Bit8s op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
59 Bit16s product_16 = op1 * op2;
60 Bit8u product_8 = (product_16 & 0xFF);
62 /* now write product back to destination */
63 AX = product_16;
65 /* set EFLAGS:
66 * IMUL r/m8: condition for clearing CF & OF:
67 * AX = sign-extend of AL to 16 bits
70 SET_FLAGS_OSZAPC_LOGIC_8(product_8);
71 if(product_16 != (Bit8s) product_16)
73 ASSERT_FLAGS_OxxxxC();
77 void BX_CPP_AttrRegparmN(1) BX_CPU_C::DIV_ALEbR(bxInstruction_c *i)
79 Bit8u op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
80 if (op2 == 0) {
81 exception(BX_DE_EXCEPTION, 0, 0);
84 Bit16u op1 = AX;
86 Bit16u quotient_16 = op1 / op2;
87 Bit8u remainder_8 = op1 % op2;
88 Bit8u quotient_8l = quotient_16 & 0xFF;
90 if (quotient_16 != quotient_8l)
92 exception(BX_DE_EXCEPTION, 0, 0);
95 /* now write quotient back to destination */
96 AL = quotient_8l;
97 AH = remainder_8;
100 void BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_ALEbR(bxInstruction_c *i)
102 Bit16s op1 = AX;
104 /* check MIN_INT case */
105 if (op1 == ((Bit16s)0x8000))
106 exception(BX_DE_EXCEPTION, 0, 0);
108 Bit8s op2 = BX_READ_8BIT_REGx(i->rm(), i->extend8bitL());
110 if (op2 == 0)
111 exception(BX_DE_EXCEPTION, 0, 0);
113 Bit16s quotient_16 = op1 / op2;
114 Bit8s remainder_8 = op1 % op2;
115 Bit8s quotient_8l = quotient_16 & 0xFF;
117 if (quotient_16 != quotient_8l)
118 exception(BX_DE_EXCEPTION, 0, 0);
120 /* now write quotient back to destination */
121 AL = quotient_8l;
122 AH = remainder_8;