File: data_xfer16.c

package info (click to toggle)
plex86 0.0.20011018-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,868 kB
  • ctags: 8,721
  • sloc: ansic: 46,915; cpp: 17,817; xml: 1,283; makefile: 1,130; sh: 451; asm: 360; csh: 18
file content (293 lines) | stat: -rw-r--r-- 6,159 bytes parent folder | download
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 *  plex86: run multiple x86 operating systems concurrently
 *  Copyright (C) 1999-2001 Kevin P. Lawton
 *
 *  data_xfer16.c:  emulation of 16-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_GwEw(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;
    Bit16u 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 = ReadReg16(vm, vm->i.rm);
      }
    else {
      /* pointer, segment address pair */
      read_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2);
      }
   
    if (condition) {
      WriteReg16(vm, vm->i.nnn, op2);
      }
    }
  else {
    monpanic(vm, "CMOV_GwEw:\n");
    UndefinedOpcode(vm);
    }
}


  void
MOVZX_GwEw(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);
    }
 
  /* normal move */
  WriteReg16(vm, vm->i.nnn, op2_16);
}

  void
MOVSX_GwEw(vm_t *vm)
{
  Bit16u op2;
 
  if (vm->i.mod == 0xc0) {
    op2 = ReadReg16(vm, vm->i.rm);
    }
  else {
    read_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2);
    }
 
  /* normal move */
  WriteReg16(vm, vm->i.nnn, op2);
}

  void
XCHG_EwGw(vm_t *vm)
{
  Bit16u op2, op1;
 
  op2 = ReadReg16(vm, vm->i.nnn);
 
  if (vm->i.mod == 0xc0) {
    op1 = ReadReg16(vm, vm->i.rm);
    WriteReg16(vm, vm->i.rm, op2);
    }
  else {
    read_RMW_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op1);
    write_RMW_virtual_word(vm, &op2);
    }
 
  WriteReg16(vm, vm->i.nnn, op1);
}

  void
XCHG_RXAX(vm_t *vm)
{
  Bit16u temp16;
  unsigned reg;
 
  reg = vm->i.b1 & 0x07;
 
  temp16 = G_AX(vm);
  G_AX(vm) = ReadReg16(vm, reg);
  WriteReg16(vm, reg, temp16);
}


  void
MOV_GwEw(vm_t *vm)
{
  Bit16u op2;

  if (vm->i.mod == 0xc0) {
    op2 = ReadReg16(vm, vm->i.rm);
    }
  else {
    read_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2);
    }

  WriteReg16(vm, vm->i.nnn, op2);
}

  void
MOV_EwSw(vm_t *vm)
{
  Bit16u val16;

  cache_selector(vm, vm->i.nnn);
  val16 = vm->guest_cpu.selector[vm->i.nnn].raw;

  if (vm->i.mod == 0xc0) {
    if ( vm->i.os_32 ) {
      WriteReg32(vm, vm->i.rm, val16);
      }
    else {
      WriteReg16(vm, vm->i.rm, val16);
      }
    }
  else {
    write_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &val16);
    }
}

  void
MOVZX_GwEb(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 word op1 */
  WriteReg16(vm, vm->i.nnn, (Bit16u) op2_8);
}

  void
MOV_EwGw(vm_t *vm)
{
  Bit16u op2;

  op2 = ReadReg16(vm, vm->i.nnn);

  if (vm->i.mod == 0xc0) {
    WriteReg16(vm, vm->i.rm, op2);
    }
  else {
    write_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2);
    }
}

  void
LEA_GwM(vm_t *vm)
{
  if (vm->i.mod == 0xc0) {
    monpanic(vm, "LEA_GvM: op2 is a register");
    UndefinedOpcode(vm);
    }

  WriteReg16(vm, vm->i.nnn, (Bit16u) vm->i.rm_addr);
}

  void
MOV_EwIw(vm_t *vm)
{
  Bit16u op2;

  op2 = vm->i.Iw;

  if (vm->i.mod == 0xc0) {
    WriteReg16(vm, vm->i.rm, op2);
    }
  else {
    write_virtual_word(vm, vm->i.seg, vm->i.rm_addr, &op2);
    }
}

  void
MOV_OwAX(vm_t *vm)
{
  Bit16u temp;
  Bit32u addr_32;

  addr_32 = vm->i.Id;

  temp = G_AX(vm);

  /* write to memory address */
  if (!NULL_SEG_REG(vm->i.seg)) {
    write_virtual_word(vm, vm->i.seg, addr_32, &temp);
    }
  else {
    write_virtual_word(vm, SRegDS, addr_32, &temp);
    }
}

  void
MOV_AXOw(vm_t *vm)
{
  Bit16u temp;
  Bit32u addr_32;
 
  addr_32 = vm->i.Id;
 
  if (!NULL_SEG_REG(vm->i.seg)) {
    read_virtual_word(vm, vm->i.seg, addr_32, &temp);
    }
  else {
    read_virtual_word(vm, SRegDS, addr_32, &temp);
    }
 
  G_AX(vm) = temp;
}

  void
MOVSX_GwEb(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 word op1 */
  WriteReg16(vm, vm->i.nnn, (Bit8s) op2_8);
}