-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjit_opcode.c
114 lines (98 loc) · 2.89 KB
/
jit_opcode.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
#include "jit_opcode.h"
#include "defs_6502.h"
#include "util.h"
#include "asm/asm_util.h"
#include <assert.h>
#include <stddef.h>
#include <string.h>
void
jit_opcode_find_replace1(struct jit_opcode_details* p_opcode,
int32_t find_uop,
int32_t uop1,
int32_t value1) {
int32_t index;
struct asm_uop* p_uop = jit_opcode_find_uop(p_opcode, &index, find_uop);
assert(p_uop != NULL);
asm_make_uop1(p_uop, uop1, value1);
}
void
jit_opcode_find_replace2(struct jit_opcode_details* p_opcode,
int32_t find_uop,
int32_t uop1,
int32_t value1,
int32_t uop2,
int32_t value2) {
int32_t index;
struct asm_uop* p_uop = jit_opcode_find_uop(p_opcode, &index, find_uop);
assert(p_uop != NULL);
if (p_opcode->num_uops == k_max_uops_per_opcode) {
util_bail("uops full");
}
asm_make_uop1(p_uop, uop1, value1);
p_uop = jit_opcode_insert_uop(p_opcode, (index + 1));
asm_make_uop1(p_uop, uop2, value2);
}
struct asm_uop*
jit_opcode_find_uop(struct jit_opcode_details* p_opcode,
int32_t* p_out_index,
int32_t uopcode) {
return asm_find_uop(p_out_index,
&p_opcode->uops[0],
p_opcode->num_uops,
uopcode);
}
void
jit_opcode_erase_uop(struct jit_opcode_details* p_opcode, int32_t uopcode) {
int32_t index;
struct asm_uop* p_uop = jit_opcode_find_uop(p_opcode, &index, uopcode);
assert(p_uop != NULL);
(void) memmove(p_uop,
(p_uop + 1),
((p_opcode->num_uops - index - 1) * sizeof(struct asm_uop)));
p_opcode->num_uops--;
}
struct asm_uop*
jit_opcode_insert_uop(struct jit_opcode_details* p_opcode, uint32_t index) {
struct asm_uop* p_ret;
uint32_t num_uops = p_opcode->num_uops;
if (num_uops == k_max_uops_per_opcode) {
util_bail("uops full");
}
p_ret = asm_insert_uop(&p_opcode->uops[0], num_uops, index);
p_opcode->num_uops++;
return p_ret;
}
void
jit_opcode_eliminate(struct jit_opcode_details* p_opcode) {
uint32_t i;
uint32_t num_uops = p_opcode->num_uops;
p_opcode->is_eliminated = 1;
for (i = 0; i < num_uops; ++i) {
struct asm_uop* p_uop;
if (i == 0) {
if (p_opcode->has_prefix_uop) {
continue;
}
} else if (i == (num_uops - 1)) {
if (p_opcode->has_postfix_uop) {
continue;
}
}
p_uop = &p_opcode->uops[i];
p_uop->is_eliminated = 1;
}
}
int
jit_opcode_can_write_to_addr(struct jit_opcode_details* p_opcode,
uint16_t addr) {
if (!(p_opcode->opmem_6502 & k_opmem_write_flag)) {
return 0;
}
if (p_opcode->is_dynamic_operand) {
return 1;
}
if ((addr >= p_opcode->min_6502_addr) && (addr <= p_opcode->max_6502_addr)) {
return 1;
}
return 0;
}