-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstructions_30.c
212 lines (199 loc) · 5.61 KB
/
instructions_30.c
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
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "instruction_defs.h"
#include "emulator_functions.h"
#include "modrm.h"
#include "io.h"
/*
* or rm8 r8: 2/3 bytes (or byte [eax], ah;)
* Logical exclusive OR between value of ModR/M and REG, storing result to destination.
* 1 byte: op (30)
* 1/2 byte: ModR/M
*/
void xor_rm8_r8(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint8_t rm8_val = get_rm8(emu, &modrm);
uint8_t r8_val = get_r8(emu, &modrm);
uint8_t result = rm8_val ^ r8_val;
set_rm8(emu, &modrm, result);
update_eflags_logical_ops_8bit(emu, result);
}
/*
* or rm32 r32: 2/3 bytes
* Logical exclusive OR between value of REG and ModR/M, storing result to destination.
* 1 byte: op (31)
* 1/2 byte: ModR/M
*/
void xor_rm32_r32(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t rm32_val = get_rm32(emu, &modrm);
uint32_t r32_val = get_r32(emu, &modrm);
uint32_t result = rm32_val ^ r32_val;
set_rm32(emu, &modrm, result);
update_eflags_logical_ops(emu, result);
}
/*
* or r8 rm8: 2/3 bytes
* Logical exclusive OR between value of ModR/M and r8, storing result of destination.
* 1 byte: op (32)
* 1/2 byte: ModR/M
*/
void xor_r8_rm8(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint8_t rm8_val = get_rm8(emu, &modrm);
uint8_t r8_val = get_r8(emu, &modrm);
uint8_t result = (uint8_t)r8_val ^ rm8_val;
set_r8(emu, &modrm, result);
update_eflags_logical_ops_8bit(emu, result);
}
/*
* or r32 rm32: 2/3 bytes
* Logical exclusive OR between value of ModR/M and r32, storing result of destination.
* 1 byte: op (33)
* 1/2 byte: ModR/M
*/
void xor_r32_rm32(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t r32_val = get_r32(emu, &modrm);
uint32_t rm32_val = get_rm32(emu, &modrm);
uint32_t result = r32_val ^ rm32_val;
set_r32(emu, &modrm, result);
update_eflags_logical_ops(emu, result);
}
/*
* or al imm8: 2 bytes
* Logical exclusive OR between imm8 and al, storing result to destination.
* 1 byte: op (34)
* 1 byte: imm8
*/
void xor_al_imm8(Emulator *emu)
{
uint8_t imm8_val = get_code8(emu, 1);
uint8_t al_val = get_register8(emu, AL);
uint8_t result = (uint8_t)al_val ^ (uint8_t)imm8_val;
set_register8(emu, AL, result);
update_eflags_logical_ops_8bit(emu, result);
emu->eip += 2;
}
/*
* or al imm32: 5 bytes
* Logical exclusive OR between imm32 to eax, storing result to destination.
* 1 byte: op (35)
* 4 byte: imm32
*/
void xor_eax_imm32(Emulator *emu)
{
uint32_t eax_val = get_register32(emu, EAX);
uint32_t imm32_val = get_code32(emu, 1);
uint32_t result = eax_val ^ imm32_val;
set_register32(emu, EAX, result);
update_eflags_logical_ops(emu, result);
emu->eip += 5;
}
/*
* cmp rm8 r8: 2|3 bytes
* Compares register ModR/M(8bit) value and register's 8-bit value by subtracting in order.
* 1 byte: op (38)
* 1|2 byte: ModR/M
*/
void cmp_rm8_r8(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint8_t rm8_val = get_rm8(emu, &modrm);
uint8_t r8_val = get_r8(emu, &modrm);
uint16_t result = (uint16_t)rm8_val - (uint16_t)r8_val;
update_eflags_sub_8bit(emu, rm8_val, r8_val, result);
}
/*
* cmp rm32 r32: 2|3 bytes
* Compares register ModR/M(32bit) value and register's 32-bit value by subtracting in order.
* 1 byte: op (39)
* 1|2 byte: ModR/M
*/
void cmp_rm32_r32(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t rm32_val = get_rm32(emu, &modrm);
uint32_t r32_val = get_r32(emu, &modrm);
uint64_t result = (uint64_t)rm32_val - (uint64_t)r32_val;
update_eflags_sub(emu, rm32_val, r32_val, result);
}
/*
* cmp r8 rm8: 2|3 bytes
* Compares register register's 8-bit value and ModR/M (8 bit) by subtracting in order.
* 1 byte: op (3A)
* 1|2 byte: ModR/M
*/
void cmp_r8_rm8(Emulator *emu)
{
emu->eip += 1;
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint8_t rm8_val = get_rm8(emu, &modrm);
uint8_t r8_val = get_r8(emu, &modrm);
uint16_t result = (uint16_t)r8_val - (uint16_t)rm8_val;
update_eflags_sub_8bit(emu, r8_val, rm8_val, result);
}
/*
* cmp r32 rm32: 2 bytes
* Compares register 32-bit value and RM32 value by subtracting in order.
* 1 byte: op (3B)
* 1 byte: ModR/M
*/
void cmp_r32_rm32(Emulator *emu)
{
emu->eip += 1; // op code
ModRM modrm = create_modrm();
parse_modrm(emu, &modrm);
uint32_t r32 = get_r32(emu, &modrm);
uint32_t rm32 = get_rm32(emu, &modrm);
uint64_t result = (uint64_t)r32 - (uint64_t)rm32;
update_eflags_sub(emu, r32, rm32, result);
}
/*
* cmp al imm8: 2 bytes
* Compares AL value and 8-bit imm value by subtracting in order.
* 1 byte: op (3C)
* 1 byte: 8-bit imm value
*/
void cmp_al_imm8(Emulator *emu)
{
uint8_t value = get_sign_code8(emu, 1);
uint8_t al = get_register8(emu, AL);
uint16_t result = (uint16_t)al - (uint16_t)value;
update_eflags_sub_8bit(emu, al, value, result);
emu->eip += 2;
}
/*
* cmp eax imm32: 5 bytes
* Compares EAX value and 32-bit imm value by subtracting in order.
* 1 byte: op (3D)
* 4 bytes: 32-bit imm value
*/
void cmp_eax_imm32(Emulator *emu)
{
uint32_t value = get_sign_code32(emu, 1);
uint32_t eax = get_register32(emu, EAX);
uint64_t result = (uint64_t)eax - (uint64_t)value;
update_eflags_sub(emu, eax, value, result);
emu->eip += 5;
}