-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patharm8.ops
220 lines (206 loc) · 9.99 KB
/
arm8.ops
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
#!perl
sub upperc {
local($_) = pop(@_);
tr/[a-z]/[A-Z]/;
return $_;
}
&output_header;
&arith_insn("add", "i u ul l p", "arm8_dproc", "ADD", "0");
&arith_insn("sub", "i u ul l p", "arm8_dproc", "SUB", "0");
&arith_insn("mul", "u ul", "arm8_mul", "1", "0");
&arith_insn("mul", "i l", "arm8_mul", "0", "0");
&arith_insn("div", "u ul", "arm8_div", "1", 0);
&arith_insn("div", "i l", "arm8_div", "0", 0);
&arith_insn("mod", "u", "arm8_mod", "0x0/*umod*/", 0); #"FORM3(2,0x0,dest,src1,src2)",
&arith_insn("mod", "ul", "arm8_mod", "0x0/*umod*/", 1); #"FORM3(2,0x0,dest,src1,src2)",
&arith_insn("mod", "i", "arm8_mod", "0x1/*smod*/", 0); #"FORM3(2,0x0,dest,src1,src2)",
&arith_insn("mod", "l", "arm8_mod", "0x1/*smod*/", 1); #"FORM3(2,0x0,dest,src1,src2)",
&arith_insn("and", "i u ul l", "arm8_dproc", "AND", "0");
&arith_insn("or", "i u ul l", "arm8_dproc", "ORR", "0");
&arith_insn("xor", "i u ul l", "arm8_dproc", "EOR", "0");
&arith2_insn("com", "i u ul l", "(arith_op2)arm8_dproc2", "MVN", "2");
&arith2_insn("neg", "i u ul l", "(arith_op2)arm8_dproc2", "RSB", "2");
&arith2_insn("not", "i u ul l", "(arith_op2)arm8_dproc2", "CMN", "0");
&arith_insn("lsh", "i u ul l", "arm8_dproc", "MOV", LLshift);
&arith_insn("rsh", "i l", "arm8_dproc", "MOV", ARshift);
&arith_insn("rsh", "u ul", "arm8_dproc", "MOV", LRshift);
&arith_insn("add", "f", "arm8_fproc", "0x6", "0x0");
&arith_insn("add", "d", "arm8_fproc", "0x6", "0x1");
&arith_insn("sub", "f", "arm8_fproc", "0x7", "0x0");
&arith_insn("sub", "d", "arm8_fproc", "0x7", "0x1");
&arith_insn("mul", "f", "arm8_fproc", "0x4", "0x0");
&arith_insn("mul", "d", "arm8_fproc", "0x4", "0x1");
&arith_insn("div", "f", "arm8_fproc", "0x8", "0x0");
&arith_insn("div", "d", "arm8_fproc", "0x8", "0x1");
&arith2_insn("neg", "f", "arm8_negf", "0x1", "0x0");
&arith2_insn("neg", "d", "arm8_negf", "0x1", "0x1");
&arith2_insn("bswap", "s us i u ul l f d", "arm8_bswap", "T", "0");
&arithi_insn("add", "i u ul l p", "arm8_dproci", "ADD", "0");
&arithi_insn("sub", "i u ul l p", "arm8_dproci", "SUB", "0");
&arithi_insn("mul", "u ul", "arm8_muli", "1", "0");
&arithi_insn("mul", "i l", "arm8_muli", "0", "0");
&arithi_insn("div", "u ul", "arm8_divi", "1", "0");
&arithi_insn("div", "i l", "arm8_divi", "0", "0");
&arithi_insn("mod", "u ul", "arm8_modi", "0", "0");
&arithi_insn("mod", "i l", "arm8_modi", "1", "0");
&arithi_insn("and", "i u ul l", "arm8_dproci", "AND", "0");
&arithi_insn("or", "i u ul l", "arm8_dproci", "ORR", "0");
&arithi_insn("xor", "i u ul l", "arm8_dproci", "EOR", "0");
&arithi_insn("lsh", "i l u ul", "arm8_dproci", "MOV", "LLshift");
&arithi_insn("rsh", "i l", "arm8_dproci", "MOV", "ARshift");
&arithi_insn("rsh", "u ul", "arm8_dproci", "MOV", "LRshift");
&branch_insn( "eq ge gt le lt ne", "c uc s us i u ul l p d f", "arm8_branch");
&branchi_insn( "eq ge gt le lt ne", "c uc s us i u ul l p", "arm8_branchi");
&compare_insn( "eq ge gt le lt ne", "c uc s us i u ul l p d f", "arm8_compare");
&comparei_insn( "eq ge gt le lt ne", "c uc s us i u ul l p", "arm8_comparei");
print COUT "DECLARE_JUMP_TABLE(${mach});\n";
print COUT "static void gen_arm8_jump_table()\n";
print COUT "{\n";
print COUT "\t FILL_JUMP_STRUCTURE($mach);\n";
print COUT $jmp_a3_assigns;
print COUT $jmp_a3i_assigns;
print COUT $jmp_a2_assigns;
print COUT $jmp_b_assigns;
print COUT $jmp_c_assigns;
print COUT "\t ${mach}_jump_table->proc_start = (dill_mach_proc_start) arm8_proc_start;\n";
print COUT "\t ${mach}_jump_table->end = arm8_end;\n";
print COUT "\t ${mach}_jump_table->package_end = arm8_package_end;\n";
print COUT "\t ${mach}_jump_table->clone_code = arm8_clone_code;\n";
print COUT "\t ${mach}_jump_table->type_align = arm8_type_align;\n";
print COUT "\t ${mach}_jump_table->type_size = arm8_type_size;\n";
print COUT "\t ${mach}_jump_table->clone_code = arm8_clone_code;\n";
print COUT "\t ${mach}_jump_table->ret = arm8_ret;\n";
print COUT "\t ${mach}_jump_table->reti = arm8_reti;\n";
print COUT "\t ${mach}_jump_table->retf = (ret_opf)arm8_retf;\n";
print COUT "\t ${mach}_jump_table->load = arm8_pload;\n";
print COUT "\t ${mach}_jump_table->bsload = arm8_pbsload;\n";
print COUT "\t ${mach}_jump_table->loadi = arm8_ploadi;\n";
print COUT "\t ${mach}_jump_table->bsloadi = arm8_pbsloadi;\n";
print COUT "\t ${mach}_jump_table->loadi = arm8_ploadi;\n";
print COUT "\t ${mach}_jump_table->store = arm8_pstore;\n";
print COUT "\t ${mach}_jump_table->storei = arm8_pstorei;\n";
print COUT "\t ${mach}_jump_table->convert = arm8_convert;\n";
print COUT "\t ${mach}_jump_table->mov = arm8_mov;\n";
print COUT "\t ${mach}_jump_table->set = arm8_pset;\n";
print COUT "\t ${mach}_jump_table->setf = arm8_setf;\n";
print COUT "\t ${mach}_jump_table->jv = arm8_jump_to_label;\n";
print COUT "\t ${mach}_jump_table->jp = arm8_jump_to_reg;\n";
print COUT "\t ${mach}_jump_table->jpi = arm8_jump_to_imm;\n";
print COUT "\t ${mach}_jump_table->jal = arm8_jal;\n";
print COUT "\t ${mach}_jump_table->push = arm8_push;\n";
print COUT "\t ${mach}_jump_table->pushi = arm8_pushi;\n";
print COUT "\t ${mach}_jump_table->pushfi = arm8_pushfi;\n";
print COUT "\t ${mach}_jump_table->pushpi = arm8_pushpi;\n";
print COUT "\t ${mach}_jump_table->calli = arm8_calli;\n";
print COUT "\t ${mach}_jump_table->callr = arm8_callr;\n";
print COUT "\t ${mach}_jump_table->local = arm8_local_op;\n";
print COUT "\t ${mach}_jump_table->setp = arm8_setp;\n";
print COUT "\t ${mach}_jump_table->save_restore = arm8_save_restore_op;\n";
#print COUT "\t ${mach}_jump_table->lea = arm8_lea;\n";
print COUT "\t ${mach}_jump_table->init_disassembly = arm8_init_disassembly_info;\n";
print COUT "\t ${mach}_jump_table->print_insn = arm8_print_insn;\n";
print COUT "\t ${mach}_jump_table->print_reg = arm8_print_reg;\n";
print COUT "\t ${mach}_jump_table->count_insn = arm8_count_insn;\n";
print COUT "\t ${mach}_jump_table->do_reverse_push = 0;\n";
print COUT "\t ${mach}_jump_table->target_byte_order = 2; /* Format_Integer_littleendian */\n";
print COUT "\t ${mach}_jump_table->target_float_format = 3; /* Format_IEEE_754_mixedendian */ \n";
print COUT "}\n\n";
print COUT "extern void dill_arm8_init(dill_stream s)\n{\n";
print COUT "\tgen_arm8_jump_table();\n";
print COUT "\ts->j = ${mach}_jump_table;\n";
print COUT "\ts->dill_local_pointer = _fp;\n";
print COUT "\ts->dill_param_reg_pointer = _fp;\n";
print COUT "\ts->p->mach_info = (void*)gen_arm8_mach_info(s,/*v9*/ 0);\n";
print COUT "\ts->p->machine_strr_tmp_reg = _v1;\n";
print COUT "\treturn;\n";
print COUT "}\n";
print COUT "extern void dill_armv9_init(dill_stream s)\n{\n";
print COUT "\tgen_arm8_jump_table();\n";
print COUT "\ts->j = ${mach}_jump_table;\n";
print COUT "\ts->dill_local_pointer = _fp;\n";
print COUT "\ts->dill_param_reg_pointer = _fp;\n";
print COUT "\ts->p->mach_info = (void*)gen_arm8_mach_info(s,/*v9*/ 1);\n";
print COUT "\ts->p->machine_strr_tmp_reg = _v1;\n";
print COUT "\treturn;\n";
print COUT "}\n";
sub arith_insn {
local ($op, $type_list, $subr, $code1, $code2) = @_;
foreach(split(' ', $type_list)) {
$jmp_a3_assigns = $jmp_a3_assigns . "\t ${mach}_jump_table->jmp_a3[dill_jmp_${op}${_}] = $subr;\n";
$jmp_a3_assigns = $jmp_a3_assigns . "\t ${mach}_jump_table->a3_data[dill_jmp_${op}${_}].data1 = $code1;\n";
$jmp_a3_assigns = $jmp_a3_assigns . "\t ${mach}_jump_table->a3_data[dill_jmp_${op}${_}].data2 = $code2;\n";
}
}
sub arith2_insn {
local ($op, $type_list, $subr, $code1, $code2) = @_;
local $pcode1 = $code1;
if ($code1 eq "T") {
$pcode1 = "DILL_". &upperc(${_});
}
foreach(split(' ', $type_list)) {
if ($code1 eq "T") {
$pcode1 = "DILL_". &upperc(${_});
}
$jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->jmp_a2[dill_jmp_${op}${_}] = $subr;\n";
$jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->a2_data[dill_jmp_${op}${_}].data1 = $pcode1;\n";
$jmp_a2_assigns = $jmp_a2_assigns . "\t ${mach}_jump_table->a2_data[dill_jmp_${op}${_}].data2 = $code2;\n";
}
}
sub arithi_insn {
local ($op, $type_list, $subr, $code1, $code2) = @_;
foreach(split(' ', $type_list)) {
$jmp_a3i_assigns = $jmp_a3i_assigns . "\t ${mach}_jump_table->jmp_a3i[dill_jmp_${op}${_}] = $subr;\n";
$jmp_a3i_assigns = $jmp_a3i_assigns . "\t ${mach}_jump_table->a3i_data[dill_jmp_${op}${_}].data1 = $code1;\n";
$jmp_a3i_assigns = $jmp_a3i_assigns . "\t ${mach}_jump_table->a3i_data[dill_jmp_${op}${_}].data2 = $code2;\n";
}
}
sub branch_insn {
local($ops, $types, $subr) = @_;
foreach (split(' ', $ops)) {
$op = $_;
foreach (split(' ', $types)) {
$jmp_b_assigns = $jmp_b_assigns . "\t ${mach}_jump_table->jmp_b[dill_jmp_b${op}${_}] = $subr;\n";
$jmp_b_assigns = $jmp_b_assigns . "\t ${mach}_jump_table->b_data[dill_jmp_b${op}${_}].data1 = dill_${op}_code;\n";
$jmp_b_assigns = $jmp_b_assigns . "\t ${mach}_jump_table->b_data[dill_jmp_b${op}${_}].data2 = DILL_". &upperc(${_}). ";\n";
}
}
}
sub branchi_insn {
local($ops, $types, $subr) = @_;
foreach (split(' ', $ops)) {
$op = $_;
foreach (split(' ', $types)) {
$jmp_b_assigns = $jmp_b_assigns . "\t ${mach}_jump_table->jmp_bi[dill_jmp_b${op}${_}] = $subr;\n";
}
}
}
sub compare_insn {
local($ops, $types, $subr) = @_;
foreach (split(' ', $ops)) {
$op = $_;
foreach (split(' ', $types)) {
$jmp_c_assigns = $jmp_c_assigns . "\t ${mach}_jump_table->jmp_c[dill_jmp_c${op}${_}] = $subr;\n";
$jmp_c_assigns = $jmp_c_assigns . "\t ${mach}_jump_table->c_data[dill_jmp_c${op}${_}].data1 = dill_${op}_code;\n";
$jmp_c_assigns = $jmp_c_assigns . "\t ${mach}_jump_table->c_data[dill_jmp_c${op}${_}].data2 = DILL_". &upperc(${_}). ";\n";
}
}
}
sub comparei_insn {
local($ops, $types, $subr) = @_;
foreach (split(' ', $ops)) {
$op = $_;
foreach (split(' ', $types)) {
$jmp_c_assigns = $jmp_c_assigns . "\t ${mach}_jump_table->jmp_ci[dill_jmp_c${op}${_}] = $subr;\n";
}
}
}
sub output_header {
$mach = arm8;
open(COUT, ">dill_${mach}.c") || die "Can't open header output";
print COUT<<EOF;
/* This file is generated from arm8.ops. Do not edit directly. */
#include "dill.h"
#include "dill_internal.h"
#include "arm8.h"
EOF
}