- compare disk size with the size calculated from geometry to avoid image
[bochs-mirror.git] / cpu / logical32.cc
blob7476fbad12e1478850870cf11b2497047d25c69b
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: logical32.cc,v 1.27 2007/04/17 21:38:51 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
28 #define NEED_CPU_REG_SHORTCUTS 1
29 #include "bochs.h"
30 #include "cpu.h"
31 #define LOG_THIS BX_CPU_THIS_PTR
33 #if BX_SUPPORT_X86_64==0
34 // Make life easier for merging cpu64 and cpu32 code.
35 #define RAX EAX
36 #endif
38 void BX_CPU_C::XOR_EdGd(bxInstruction_c *i)
40 Bit32u op2_32, op1_32, result_32;
42 op2_32 = BX_READ_32BIT_REG(i->nnn());
44 if (i->modC0()) {
45 op1_32 = BX_READ_32BIT_REG(i->rm());
46 result_32 = op1_32 ^ op2_32;
47 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
49 else {
50 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
51 result_32 = op1_32 ^ op2_32;
52 write_RMW_virtual_dword(result_32);
55 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
58 void BX_CPU_C::XOR_GdEd(bxInstruction_c *i)
60 Bit32u op1_32, op2_32, result_32;
61 unsigned nnn = i->nnn();
63 op1_32 = BX_READ_32BIT_REG(nnn);
65 if (i->modC0()) {
66 op2_32 = BX_READ_32BIT_REG(i->rm());
68 else {
69 read_virtual_dword(i->seg(), RMAddr(i), &op2_32);
72 result_32 = op1_32 ^ op2_32;
74 BX_WRITE_32BIT_REGZ(nnn, result_32);
76 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
79 void BX_CPU_C::XOR_EAXId(bxInstruction_c *i)
81 Bit32u op1_32, op2_32, result_32;
83 op1_32 = EAX;
84 op2_32 = i->Id();
86 result_32 = op1_32 ^ op2_32;
87 RAX = result_32;
89 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
92 void BX_CPU_C::XOR_EdId(bxInstruction_c *i)
94 Bit32u op2_32, op1_32, result_32;
96 op2_32 = i->Id();
98 if (i->modC0()) {
99 op1_32 = BX_READ_32BIT_REG(i->rm());
100 result_32 = op1_32 ^ op2_32;
101 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
103 else {
104 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
105 result_32 = op1_32 ^ op2_32;
106 write_RMW_virtual_dword(result_32);
109 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
112 void BX_CPU_C::OR_EdId(bxInstruction_c *i)
114 Bit32u op2_32, op1_32, result_32;
116 op2_32 = i->Id();
118 if (i->modC0()) {
119 op1_32 = BX_READ_32BIT_REG(i->rm());
120 result_32 = op1_32 | op2_32;
121 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
123 else {
124 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
125 result_32 = op1_32 | op2_32;
126 write_RMW_virtual_dword(result_32);
129 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
132 void BX_CPU_C::NOT_Ed(bxInstruction_c *i)
134 Bit32u op1_32, result_32;
136 if (i->modC0()) {
137 op1_32 = BX_READ_32BIT_REG(i->rm());
138 result_32 = ~op1_32;
139 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
141 else {
142 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
143 result_32 = ~op1_32;
144 write_RMW_virtual_dword(result_32);
148 void BX_CPU_C::OR_EdGd(bxInstruction_c *i)
150 Bit32u op2_32, op1_32, result_32;
152 op2_32 = BX_READ_32BIT_REG(i->nnn());
154 if (i->modC0()) {
155 op1_32 = BX_READ_32BIT_REG(i->rm());
156 result_32 = op1_32 | op2_32;
157 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
159 else {
160 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
161 result_32 = op1_32 | op2_32;
162 write_RMW_virtual_dword(result_32);
165 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
168 void BX_CPU_C::OR_GdEd(bxInstruction_c *i)
170 Bit32u op1_32, op2_32, result_32;
172 op1_32 = BX_READ_32BIT_REG(i->nnn());
174 if (i->modC0()) {
175 op2_32 = BX_READ_32BIT_REG(i->rm());
177 else {
178 read_virtual_dword(i->seg(), RMAddr(i), &op2_32);
181 #if defined(BX_HostAsm_Or32)
182 Bit32u flags32;
183 asmOr32(result_32, op1_32, op2_32, flags32);
184 setEFlagsOSZAPC(flags32);
185 #else
186 result_32 = op1_32 | op2_32;
187 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
188 #endif
190 BX_WRITE_32BIT_REGZ(i->nnn(), result_32);
193 void BX_CPU_C::OR_EAXId(bxInstruction_c *i)
195 Bit32u op1_32, op2_32, result_32;
197 op1_32 = EAX;
198 op2_32 = i->Id();
199 result_32 = op1_32 | op2_32;
201 RAX = result_32;
203 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
206 void BX_CPU_C::AND_EdGd(bxInstruction_c *i)
208 Bit32u op2_32, op1_32, result_32;
210 op2_32 = BX_READ_32BIT_REG(i->nnn());
212 if (i->modC0()) {
213 op1_32 = BX_READ_32BIT_REG(i->rm());
215 #if defined(BX_HostAsm_And32)
216 Bit32u flags32;
217 asmAnd32(result_32, op1_32, op2_32, flags32);
218 setEFlagsOSZAPC(flags32);
219 #else
220 result_32 = op1_32 & op2_32;
221 #endif
223 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
225 else {
226 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
228 #if defined(BX_HostAsm_And32)
229 Bit32u flags32;
230 asmAnd32(result_32, op1_32, op2_32, flags32);
231 setEFlagsOSZAPC(flags32);
232 #else
233 result_32 = op1_32 & op2_32;
234 #endif
236 write_RMW_virtual_dword(result_32);
239 #if !defined(BX_HostAsm_And32)
240 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
241 #endif
244 void BX_CPU_C::AND_GdEd(bxInstruction_c *i)
246 Bit32u op1_32, op2_32, result_32;
248 op1_32 = BX_READ_32BIT_REG(i->nnn());
250 if (i->modC0()) {
251 op2_32 = BX_READ_32BIT_REG(i->rm());
253 else {
254 read_virtual_dword(i->seg(), RMAddr(i), &op2_32);
257 #if defined(BX_HostAsm_And32)
258 Bit32u flags32;
259 asmAnd32(result_32, op1_32, op2_32, flags32);
260 setEFlagsOSZAPC(flags32);
261 #else
262 result_32 = op1_32 & op2_32;
263 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
264 #endif
266 BX_WRITE_32BIT_REGZ(i->nnn(), result_32);
269 void BX_CPU_C::AND_EAXId(bxInstruction_c *i)
271 Bit32u op1_32, op2_32, result_32;
273 op1_32 = EAX;
274 op2_32 = i->Id();
276 #if defined(BX_HostAsm_And32)
277 Bit32u flags32;
278 asmAnd32(result_32, op1_32, op2_32, flags32);
279 setEFlagsOSZAPC(flags32);
280 #else
281 result_32 = op1_32 & op2_32;
282 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
283 #endif
285 RAX = result_32;
288 void BX_CPU_C::AND_EdId(bxInstruction_c *i)
290 Bit32u op2_32, op1_32, result_32;
292 op2_32 = i->Id();
294 if (i->modC0()) {
295 op1_32 = BX_READ_32BIT_REG(i->rm());
297 #if defined(BX_HostAsm_And32)
298 Bit32u flags32;
299 asmAnd32(result_32, op1_32, op2_32, flags32);
300 setEFlagsOSZAPC(flags32);
301 #else
302 result_32 = op1_32 & op2_32;
303 #endif
305 BX_WRITE_32BIT_REGZ(i->rm(), result_32);
307 else {
308 read_RMW_virtual_dword(i->seg(), RMAddr(i), &op1_32);
310 #if defined(BX_HostAsm_And32)
311 Bit32u flags32;
312 asmAnd32(result_32, op1_32, op2_32, flags32);
313 setEFlagsOSZAPC(flags32);
314 #else
315 result_32 = op1_32 & op2_32;
316 #endif
318 write_RMW_virtual_dword(result_32);
321 #if !defined(BX_HostAsm_And32)
322 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
323 #endif
326 void BX_CPU_C::TEST_EdGd(bxInstruction_c *i)
328 Bit32u op2_32, op1_32;
330 op2_32 = BX_READ_32BIT_REG(i->nnn());
332 if (i->modC0()) {
333 op1_32 = BX_READ_32BIT_REG(i->rm());
335 else {
336 read_virtual_dword(i->seg(), RMAddr(i), &op1_32);
339 #if defined(BX_HostAsm_Test32)
340 Bit32u flags32;
341 asmTest32(op1_32, op2_32, flags32);
342 setEFlagsOSZAPC(flags32);
343 #else
344 Bit32u result_32 = op1_32 & op2_32;
345 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
346 #endif
349 void BX_CPU_C::TEST_EAXId(bxInstruction_c *i)
351 Bit32u op2_32, op1_32;
353 op1_32 = EAX;
354 op2_32 = i->Id();
356 #if defined(BX_HostAsm_Test32)
357 Bit32u flags32;
358 asmTest32(op1_32, op2_32, flags32);
359 setEFlagsOSZAPC(flags32);
360 #else
361 Bit32u result_32 = op1_32 & op2_32;
362 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
363 #endif
366 void BX_CPU_C::TEST_EdId(bxInstruction_c *i)
368 Bit32u op2_32, op1_32;
370 op2_32 = i->Id();
372 if (i->modC0()) {
373 op1_32 = BX_READ_32BIT_REG(i->rm());
375 else {
376 read_virtual_dword(i->seg(), RMAddr(i), &op1_32);
379 #if defined(BX_HostAsm_Test32)
380 Bit32u flags32;
381 asmTest32(op1_32, op2_32, flags32);
382 setEFlagsOSZAPC(flags32);
383 #else
384 Bit32u result_32 = op1_32 & op2_32;
385 SET_FLAGS_OSZAPC_RESULT_32(result_32, BX_INSTR_LOGIC32);
386 #endif