-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.c
74 lines (65 loc) · 1.48 KB
/
test.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
#include "vm.h"
void v_test(v_register *v_reg)
{
DEBUG("test\n");
v_info *info = parse(v_reg, 2);
int PF;
int ZF;
int SF;
if (info[0].SIZE == 0) {
char result = *(char *)info[0].operand & *(char *)info[1].operand;
SF = (result & (1 << 7)) >> 7;
ZF = (result) ? 0 : 1;
for (int i = 0; i < 8; i++) {
PF ^= (result & (1 << i)) >> i;
}
}
else if (info[0].SIZE == 1) {
short result = *(short *)info[0].operand & *(short *)info[1].operand;
SF = (result & (1 << 15)) >> 15;
ZF = (result) ? 0 : 1;
for (int i = 0; i < 16; i++) {
PF ^= (result & (1 << i)) >> i;
}
}
else if (info[0].SIZE == 2) {
int result = *(int *)info[0].operand & *(int *)info[1].operand;
SF = (result & (1 << 31)) >> 31;
ZF = (result) ? 0 : 1;
for (int i = 0; i < 32; i++) {
PF ^= (result & (1 << i)) >> i;
}
}
else if (info[0].SIZE == 3) {
long long result = *(long long *)info[0].operand & *(long long *)info[1].operand;
SF = (result & (1LL << 63)) >> 63;
ZF = (result) ? 0 : 1;
for (int i = 0; i < 64; i++) {
PF ^= (result & (1 << i)) >> i;
}
}
// set CF and OF to 0
v_reg->v_eflags &= ~0x801;
// set PF
if (PF) {
v_reg->v_eflags |= 0x4;
}
else {
v_reg->v_eflags &= ~0x4;
}
// set ZF
if (ZF) {
v_reg->v_eflags |= 0x40;
}
else {
v_reg->v_eflags &= ~0x40;
}
// set SF
if (SF) {
v_reg->v_eflags |= 0x80;
}
else {
v_reg->v_eflags &= ~0x80;
}
free(info);
}