OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [mult32.cc] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: mult32.cc 11313 2012-08-05 13:52:40Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2012  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
20
/////////////////////////////////////////////////////////////////////////
21
 
22
#define NEED_CPU_REG_SHORTCUTS 1
23
#include "bochs.h"
24
#include "cpu.h"
25
#define LOG_THIS BX_CPU_THIS_PTR
26
 
27
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::MUL_EAXEdR(bxInstruction_c *i)
28
{
29
  Bit32u op1_32 = EAX;
30
  Bit32u op2_32 = BX_READ_32BIT_REG(i->src());
31
 
32
  Bit64u product_64  = ((Bit64u) op1_32) * ((Bit64u) op2_32);
33
  Bit32u product_32l = GET32L(product_64);
34
  Bit32u product_32h = GET32H(product_64);
35
 
36
  /* now write product back to destination */
37
  RAX = product_32l;
38
  RDX = product_32h;
39
 
40
  /* set EFLAGS */
41
  SET_FLAGS_OSZAPC_LOGIC_32(product_32l);
42
  if(product_32h != 0)
43
  {
44
    ASSERT_FLAGS_OxxxxC();
45
  }
46
 
47
  BX_NEXT_INSTR(i);
48
}
49
 
50
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_EAXEdR(bxInstruction_c *i)
51
{
52
  Bit32s op1_32 = EAX;
53
  Bit32s op2_32 = BX_READ_32BIT_REG(i->src());
54
 
55
  Bit64s product_64  = ((Bit64s) op1_32) * ((Bit64s) op2_32);
56
  Bit32u product_32l = GET32L(product_64);
57
  Bit32u product_32h = GET32H(product_64);
58
 
59
  /* now write product back to destination */
60
  RAX = product_32l;
61
  RDX = product_32h;
62
 
63
  /* set eflags:
64
   * IMUL r/m32: condition for clearing CF & OF:
65
   *   EDX:EAX = sign-extend of EAX
66
   */
67
  SET_FLAGS_OSZAPC_LOGIC_32(product_32l);
68
  if(product_64 != (Bit32s)product_64)
69
  {
70
    ASSERT_FLAGS_OxxxxC();
71
  }
72
 
73
  BX_NEXT_INSTR(i);
74
}
75
 
76
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::DIV_EAXEdR(bxInstruction_c *i)
77
{
78
  Bit32u op2_32 = BX_READ_32BIT_REG(i->src());
79
  if (op2_32 == 0) {
80
    exception(BX_DE_EXCEPTION, 0);
81
  }
82
 
83
  Bit64u op1_64 = (((Bit64u) EDX) << 32) + ((Bit64u) EAX);
84
 
85
  Bit64u quotient_64  = op1_64 / op2_32;
86
  Bit32u remainder_32 = (Bit32u) (op1_64 % op2_32);
87
  Bit32u quotient_32l = (Bit32u) (quotient_64 & 0xFFFFFFFF);
88
 
89
  if (quotient_64 != quotient_32l)
90
  {
91
    exception(BX_DE_EXCEPTION, 0);
92
  }
93
 
94
  /* set EFLAGS:
95
   * DIV affects the following flags: O,S,Z,A,P,C are undefined
96
   */
97
 
98
  /* now write quotient back to destination */
99
  RAX = quotient_32l;
100
  RDX = remainder_32;
101
 
102
  BX_NEXT_INSTR(i);
103
}
104
 
105
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_EAXEdR(bxInstruction_c *i)
106
{
107
  Bit64s op1_64 = (((Bit64u) EDX) << 32) | ((Bit64u) EAX);
108
 
109
  /* check MIN_INT case */
110
  if (op1_64 == ((Bit64s)BX_CONST64(0x8000000000000000)))
111
    exception(BX_DE_EXCEPTION, 0);
112
 
113
  Bit32s op2_32 = BX_READ_32BIT_REG(i->src());
114
 
115
  if (op2_32 == 0)
116
    exception(BX_DE_EXCEPTION, 0);
117
 
118
  Bit64s quotient_64  = op1_64 / op2_32;
119
  Bit32s remainder_32 = (Bit32s) (op1_64 % op2_32);
120
  Bit32s quotient_32l = (Bit32s) (quotient_64 & 0xFFFFFFFF);
121
 
122
  if (quotient_64 != quotient_32l)
123
  {
124
    exception(BX_DE_EXCEPTION, 0);
125
  }
126
 
127
  /* set EFLAGS:
128
   * IDIV affects the following flags: O,S,Z,A,P,C are undefined
129
   */
130
 
131
  /* now write quotient back to destination */
132
  RAX = (Bit32u) quotient_32l;
133
  RDX = (Bit32u) remainder_32;
134
 
135
  BX_NEXT_INSTR(i);
136
}
137
 
138
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_GdEdIdR(bxInstruction_c *i)
139
{
140
  Bit32s op2_32 = BX_READ_32BIT_REG(i->src());
141
  Bit32s op3_32 = i->Id();
142
 
143
  Bit64s product_64 = ((Bit64s) op2_32) * ((Bit64s) op3_32);
144
  Bit32u product_32 = (Bit32u)(product_64 & 0xFFFFFFFF);
145
 
146
  /* now write product back to destination */
147
  BX_WRITE_32BIT_REGZ(i->dst(), product_32);
148
 
149
  /* set eflags:
150
   * IMUL r32,r/m32,imm32: condition for clearing CF & OF:
151
   *   result exactly fits within r32
152
   */
153
  SET_FLAGS_OSZAPC_LOGIC_32(product_32);
154
  if(product_64 != (Bit32s) product_64)
155
  {
156
    ASSERT_FLAGS_OxxxxC();
157
  }
158
 
159
  BX_NEXT_INSTR(i);
160
}
161
 
162
BX_INSF_TYPE BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_GdEdR(bxInstruction_c *i)
163
{
164
  Bit32s op1_32 = BX_READ_32BIT_REG(i->dst());
165
  Bit32s op2_32 = BX_READ_32BIT_REG(i->src());
166
 
167
  Bit64s product_64 = ((Bit64s) op1_32) * ((Bit64s) op2_32);
168
  Bit32u product_32 = (Bit32u)(product_64 & 0xFFFFFFFF);
169
 
170
  /* now write product back to destination */
171
  BX_WRITE_32BIT_REGZ(i->dst(), product_32);
172
 
173
  /* set eflags:
174
   * IMUL r32,r/m32: condition for clearing CF & OF:
175
   *   result exactly fits within r32
176
   */
177
  SET_FLAGS_OSZAPC_LOGIC_32(product_32);
178
  if(product_64 != (Bit32s) product_64)
179
  {
180
    ASSERT_FLAGS_OxxxxC();
181
  }
182
 
183
  BX_NEXT_INSTR(i);
184
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.