1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
/*
* plex86: run multiple x86 operating systems concurrently
* Copyright (C) 1999-2001 Kevin P. Lawton
*
* data_xfer32.c: emulation of 32-bit data transfer instructions
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "plex86.h"
#include "monitor.h"
void
CMOV_GdEd(vm_t *vm)
{
if (cpuid_info.featureFlags.fields.cmov) {
/* Note: CMOV accesses a memory source operand (read), regardless
* of whether condition is true or not. Thus, exceptions may
* occur even if the MOV does not take place.
*/
Boolean condition;
Bit32u op2;
switch (vm->i.b1) {
/* CMOV opcodes: */
case 0x140: condition = G_GetOF(vm); break;
case 0x141: condition = !G_GetOF(vm); break;
case 0x142: condition = G_GetCF(vm); break;
case 0x143: condition = !G_GetCF(vm); break;
case 0x144: condition = G_GetZF(vm); break;
case 0x145: condition = !G_GetZF(vm); break;
case 0x146: condition = G_GetCF(vm) || G_GetZF(vm); break;
case 0x147: condition = !G_GetCF(vm) && !G_GetZF(vm); break;
case 0x148: condition = G_GetSF(vm); break;
case 0x149: condition = !G_GetSF(vm); break;
case 0x14A: condition = G_GetPF(vm); break;
case 0x14B: condition = !G_GetPF(vm); break;
case 0x14C: condition = G_GetSF(vm) != G_GetOF(vm); break;
case 0x14D: condition = G_GetSF(vm) == G_GetOF(vm); break;
case 0x14E: condition = G_GetZF(vm) ||
(G_GetSF(vm) != G_GetOF(vm)); break;
case 0x14F: condition = !G_GetZF(vm) &&
(G_GetSF(vm) == G_GetOF(vm)); break;
default:
condition = 0;
monpanic(vm, "CMOV_GwEw: default case\n");
}
if (vm->i.mod == 0xc0) {
op2 = ReadReg32(vm, vm->i.rm);
}
else {
/* pointer, segment address pair */
read_virtual_dword(vm, vm->i.seg, vm->i.rm_addr, &op2);
}
if (condition) {
WriteReg32(vm, vm->i.nnn, op2);
}
}
else {
monpanic(vm, "CMOV_GdEd:\n");
UndefinedOpcode(vm);
}
}
void
MOVZX_GdEw(vm_t *vm)
{
Bit16u op2_16;
if (vm->i.mod == 0xc0) {
op2_16 = ReadReg16(vm, vm->i.rm);
}
else {
read_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2_16);
}
/* zero extend word op2 into dword op1 */
WriteReg32(vm, vm->i.nnn, (Bit32u) op2_16);
}
void
MOVSX_GdEw(vm_t *vm)
{
Bit16u op2_16;
if (vm->i.mod == 0xc0) {
op2_16 = ReadReg16(vm, vm->i.rm);
}
else {
read_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2_16);
}
/* sign extend word op2 into dword op1 */
WriteReg32(vm, vm->i.nnn, (Bit16s) op2_16);
}
void
XCHG_EdGd(vm_t *vm)
{
Bit32u op2, op1;
op2 = ReadReg32(vm, vm->i.nnn);
if (vm->i.mod == 0xc0) {
op1 = ReadReg32(vm, vm->i.rm);
WriteReg32(vm, vm->i.rm, op2);
}
else {
read_RMW_virtual_dword(vm, vm->i.seg, vm->i.rm_addr, &op1);
write_RMW_virtual_dword(vm, &op2);
}
WriteReg32(vm, vm->i.nnn, op1);
}
void
XCHG_ERXEAX(vm_t *vm)
{
Bit32u temp32;
unsigned reg;
reg = vm->i.b1 & 0x07;
temp32 = G_EAX(vm);
G_EAX(vm) = ReadReg32(vm, reg);
WriteReg32(vm, reg, temp32);
}
void
MOV_GdEd(vm_t *vm)
{
Bit32u op2_32;
if (vm->i.mod == 0xc0) {
op2_32 = ReadReg32(vm, vm->i.rm);
}
else {
read_virtual_dword(vm, vm->i.seg, vm->i.rm_addr, &op2_32);
}
WriteReg32(vm, vm->i.nnn, op2_32);
}
void
MOVZX_GdEb(vm_t *vm)
{
Bit8u op2_8;
if (vm->i.mod == 0xc0) {
op2_8 = ReadReg8(vm, vm->i.rm);
}
else {
read_virtual_byte(vm, vm->i.seg, vm->i.rm_addr, &op2_8);
}
/* zero extend byte op2 into dword op1 */
WriteReg32(vm, vm->i.nnn, (Bit32u) op2_8);
}
void
MOV_EdGd(vm_t *vm)
{
Bit32u op2_32;
op2_32 = ReadReg32(vm, vm->i.nnn);
if (vm->i.mod == 0xc0) {
WriteReg32(vm, vm->i.rm, op2_32);
}
else {
write_virtual_dword(vm, vm->i.seg, vm->i.rm_addr, &op2_32);
}
}
void
LEA_GdM(vm_t *vm)
{
if (vm->i.mod == 0xc0) {
monpanic(vm, "LEA_GvM: op2 is a register");
UndefinedOpcode(vm);
}
WriteReg32(vm, vm->i.nnn, vm->i.rm_addr);
}
void
MOV_EdId(vm_t *vm)
{
Bit32u op2_32;
op2_32 = vm->i.Id;
if (vm->i.mod == 0xc0) {
WriteReg32(vm, vm->i.rm, op2_32);
}
else {
write_virtual_dword(vm, vm->i.seg, vm->i.rm_addr, &op2_32);
}
}
void
MOV_OdEAX(vm_t *vm)
{
Bit32u temp_32;
Bit32u addr_32;
addr_32 = vm->i.Id;
temp_32 = G_EAX(vm);
if (!NULL_SEG_REG(vm->i.seg)) {
write_virtual_dword(vm, vm->i.seg, addr_32, &temp_32);
}
else {
write_virtual_dword(vm, SRegDS, addr_32, &temp_32);
}
}
void
MOV_EAXOd(vm_t *vm)
{
Bit32u temp_32;
Bit32u addr_32;
addr_32 = vm->i.Id;
if (!NULL_SEG_REG(vm->i.seg)) {
read_virtual_dword(vm, vm->i.seg, addr_32, &temp_32);
}
else {
read_virtual_dword(vm, SRegDS, addr_32, &temp_32);
}
G_EAX(vm) = temp_32;
}
void
MOVSX_GdEb(vm_t *vm)
{
Bit8u op2_8;
if (vm->i.mod == 0xc0) {
op2_8 = ReadReg8(vm, vm->i.rm);
}
else {
read_virtual_byte(vm, vm->i.seg, vm->i.rm_addr, &op2_8);
}
/* sign extend byte op2 into dword op1 */
WriteReg32(vm, vm->i.nnn, (Bit8s) op2_8);
}
|