-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadwrite.c
More file actions
173 lines (159 loc) · 5.86 KB
/
readwrite.c
File metadata and controls
173 lines (159 loc) · 5.86 KB
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
/*
* functionality to split operands into read and written
*
* Copyright (C) 2009-2013 Juan Caballero <juan.caballero@imdea.org>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "readwrite.h"
#include "config.h"
#include "tfd.h"
#include "DECAF_main.h"
#include "DECAF_target.h"
#include "assert.h"
#include "xed-interface.h"
void get_new_access (
xed_operand_action_enum_t curr_access,
xed_operand_action_enum_t *old_access,
xed_operand_action_enum_t *new_access)
{
switch(curr_access) {
case XED_OPERAND_ACTION_RW: {
*old_access = XED_OPERAND_ACTION_R;
*new_access = XED_OPERAND_ACTION_W;
break;
}
case XED_OPERAND_ACTION_RCW: {
*old_access = XED_OPERAND_ACTION_R;
*new_access = XED_OPERAND_ACTION_CW;
break;
}
case XED_OPERAND_ACTION_CRW: {
*old_access = XED_OPERAND_ACTION_CR;
*new_access = XED_OPERAND_ACTION_W;
break;
}
default: {
*old_access = curr_access;
*new_access = curr_access;
break;
}
}
}
// Update all written operands with current value
void update_written_operands (CPUState* env, EntryHeader *eh) {
int i = 0, first_empty_idx = 0;
xed_operand_action_enum_t old_access, new_access;
// Find number of operands
while ((eh->operand[i].type != TNone) && (i < MAX_NUM_OPERANDS)) {
i++;
}
first_empty_idx = i;
// Modify operands
i = 0;
while ((eh->operand[i].type != TNone) && (i < MAX_NUM_OPERANDS)) {
switch(eh->operand[i].access) {
case XED_OPERAND_ACTION_W:
case XED_OPERAND_ACTION_CW: {
// Just update the operand value
if (eh->operand[i].type == TRegister) {
int regnum = REGNUM(REGOP_ADDR(eh->operand[i]));
REGOP_VAL(eh->operand[i]) = env->regs[regnum];
}
else if (eh->operand[i].type == TMemLoc) {
DECAF_read_mem(env, MEMOP_ADDR(eh->operand[i]),
(int)(eh->operand[i].length),
(uint8_t *)&(MEMOP_VAL(eh->operand[i])));
}
#ifndef TRACE_VERSION_50
else if (eh->operand[i].type == TMMXRegister) {
int regnum = eh->operand[i].addr.reg_addr;
eh->operand[i].value.val64 = MMXVAL(env,regnum);
}
else if (eh->operand[i].type == TFloatRegister) {
int regnum = eh->operand[i].addr.reg_addr;
eh->operand[i].value.float_val = FLOATVAL(env,regnum);
}
else if (eh->operand[i].type == TFloatControlRegister) {
if (eh->operand[i].addr.reg_addr == fpu_status_reg) {
eh->operand[i].value.val32 = (uint32_t) *(&env->fpus);
}
else if (eh->operand[i].addr.reg_addr == fpu_control_reg) {
eh->operand[i].value.val32 = (uint32_t) *(&env->fpuc);
}
}
else if (eh->operand[i].type == TXMMRegister) {
int regnum = eh->operand[i].addr.reg_addr;
eh->operand[i].value.xmm_val._q[0] = XMMVAL(env,regnum,0);
eh->operand[i].value.xmm_val._q[1] = XMMVAL(env,regnum,1);
}
#endif
break;
}
case XED_OPERAND_ACTION_RW:
case XED_OPERAND_ACTION_RCW:
case XED_OPERAND_ACTION_CRW: {
// Copy operand to empty slot
assert(first_empty_idx < MAX_NUM_OPERANDS);
assert(first_empty_idx != i);
memcpy((void *)&(eh->operand[first_empty_idx]),
(void *)&(eh->operand[i]),sizeof(OperandVal));
// Update the number of operands
eh->num_operands++;
// Update operand access for both operands
get_new_access(eh->operand[i].access,&old_access,&new_access);
eh->operand[i].access = old_access;
eh->operand[first_empty_idx].access = new_access;
// Update value for new operand
// Update value for new operand
if (eh->operand[i].type == TRegister) {
int regnum = REGNUM(REGOP_ADDR(eh->operand[i]));
REGOP_VAL(eh->operand[first_empty_idx]) = env->regs[regnum];
}
else if (eh->operand[i].type == TMemLoc) {
DECAF_read_mem(env, MEMOP_ADDR(eh->operand[i]),
(int)(eh->operand[i].length),
(uint8_t *)&(MEMOP_VAL(eh->operand[first_empty_idx])));
}
#ifndef TRACE_VERSION_50
else if (eh->operand[i].type == TMMXRegister) {
int regnum = eh->operand[i].addr.reg_addr;
eh->operand[first_empty_idx].value.val64 = MMXVAL(env,regnum);
}
else if (eh->operand[i].type == TFloatRegister) {
int regnum = eh->operand[i].addr.reg_addr;
eh->operand[first_empty_idx].value.float_val =
FLOATVAL(env,regnum);
}
else if (eh->operand[i].type == TFloatControlRegister) {
if (eh->operand[i].addr.reg_addr == fpu_status_reg) {
eh->operand[first_empty_idx].value.val32 =
(uint32_t) *(&env->fpus);
}
else if (eh->operand[i].addr.reg_addr == fpu_control_reg) {
eh->operand[first_empty_idx].value.val32 =
(uint32_t) *(&env->fpuc);
}
}
#endif
first_empty_idx++;
}
default: {
break;
}
}
i++;
}
}