generate_arm_loadstore.c Source File
Back to the index.
src
cpus
generate_arm_loadstore.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2005-2009 Anders Gavare. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* 3. The name of the author may not be used to endorse or promote products
13
* derived from this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*/
27
28
#include <stdio.h>
29
#include <stdlib.h>
30
31
32
char
*
cond
[16] = {
33
"eq"
,
"ne"
,
"cs"
,
"cc"
,
"mi"
,
"pl"
,
"vs"
,
"vc"
,
34
"hi"
,
"ls"
,
"ge"
,
"lt"
,
"gt"
,
"le"
,
""
,
""
};
35
36
int
main
(
int
argc,
char
*argv[])
37
{
38
int
l, b, w=0, h, s, u=0, p=0,
reg
, c, n;
39
int
only_array = 0;
40
41
if
(argc == 1) {
42
only_array = 1;
43
}
else
{
44
if
(argc != 4) {
45
fprintf(stderr,
"puw missing?\n"
);
46
exit(1);
47
}
48
p = atoi(argv[1]);
49
u = atoi(argv[2]);
50
w = atoi(argv[3]);
51
}
52
53
printf(
"\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n"
);
54
printf(
"#include <stdio.h>\n#include <stdlib.h>\n"
55
"#include \"cpu.h\"\n"
56
"#include \"machine.h\"\n"
57
"#include \"memory.h\"\n"
58
"#include \"misc.h\"\n"
59
"#define DYNTRANS_PC_TO_POINTERS arm_pc_to_pointers\n"
60
"#include \"quick_pc_to_pointers.h\"\n"
61
"#define reg(x) (*((uint32_t *)(x)))\n"
);
62
printf(
"extern void arm_instr_nop(struct cpu *, "
63
"struct arm_instr_call *);\n"
);
64
printf(
"extern void arm_instr_invalid(struct cpu *, "
65
"struct arm_instr_call *);\n"
);
66
printf(
"extern void arm_pc_to_pointers(struct cpu *);\n"
);
67
68
if
(!only_array)
69
for
(
reg
=0;
reg
<=1;
reg
++)
70
for
(b=0; b<=1; b++)
71
for
(l=0; l<=1; l++) {
72
printf(
"#define A__NAME__general arm_instr_%s_"
73
"%s_%s_%s_%s_%s__general\n"
,
74
l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
75
b?
"byte"
:
"word"
, u?
"u1"
:
"u0"
,
76
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
77
78
printf(
"#define A__NAME arm_instr_%s_%s_%s_%s_%s_%s\n"
,
79
l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
80
b?
"byte"
:
"word"
, u?
"u1"
:
"u0"
,
81
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
82
for
(c=0; c<14; c++)
83
printf(
"#define A__NAME__%s arm_instr_%s_"
84
"%s_%s_%s_%s_%s__%s\n"
,
85
cond
[c], l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
86
b?
"byte"
:
"word"
, u?
"u1"
:
"u0"
,
87
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
,
cond
[c]);
88
89
printf(
"#define A__NAME_PC arm_instr_%s_%s_%s_%s_"
90
"%s_%s_pc\n"
, l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
91
b?
"byte"
:
"word"
, u?
"u1"
:
"u0"
,
92
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
93
for
(c=0; c<14; c++)
94
printf(
"#define A__NAME_PC__%s arm_instr_%s_"
95
"%s_%s_%s_%s_%s_pc__%s\n"
,
96
cond
[c], l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
97
b?
"byte"
:
"word"
, u?
"u1"
:
"u0"
,
98
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
,
cond
[c]);
99
100
if
(l) printf(
"#define A__L\n"
);
101
if
(w) printf(
"#define A__W\n"
);
102
if
(b) printf(
"#define A__B\n"
);
103
if
(u) printf(
"#define A__U\n"
);
104
if
(p) printf(
"#define A__P\n"
);
105
if
(
reg
)printf(
"#define A__REG\n"
);
106
printf(
"#include \"cpu_arm_instr_loadstore.cc\"\n"
);
107
if
(l) printf(
"#undef A__L\n"
);
108
if
(w) printf(
"#undef A__W\n"
);
109
if
(b) printf(
"#undef A__B\n"
);
110
if
(u) printf(
"#undef A__U\n"
);
111
if
(p) printf(
"#undef A__P\n"
);
112
if
(
reg
)printf(
"#undef A__REG\n"
);
113
for
(c=0; c<14; c++)
114
printf(
"#undef A__NAME__%s\n"
,
cond
[c]);
115
for
(c=0; c<14; c++)
116
printf(
"#undef A__NAME_PC__%s\n"
,
cond
[c]);
117
printf(
"#undef A__NAME__general\n"
);
118
printf(
"#undef A__NAME_PC\n"
);
119
printf(
"#undef A__NAME\n"
);
120
}
121
122
if
(only_array) {
123
for
(
reg
=0;
reg
<=1;
reg
++)
124
for
(p=0; p<=1; p++)
125
for
(u=0; u<=1; u++)
126
for
(b=0; b<=1; b++)
127
for
(w=0; w<=1; w++)
128
for
(l=0; l<=1; l++)
129
for
(c=0; c<16; c++) {
130
if
(c == 15)
131
continue
;
132
133
printf(
"void arm_instr_%s_%s_%s"
134
"_%s_%s_%s%s%s(struct cpu *, struct "
135
"arm_instr_call *);"
,
136
l?
"load"
:
"store"
,
137
w?
"w1"
:
"w0"
,
138
b?
"byte"
:
"word"
,
139
u?
"u1"
:
"u0"
,
140
p?
"p1"
:
"p0"
,
141
reg
?
"reg"
:
"imm"
,
142
c!=14?
"__"
:
""
,
cond
[c]);
143
printf(
"void arm_instr_%s_%s_%s_%s_%s_%s_pc%s%s"
144
"(struct cpu *, struct "
145
"arm_instr_call *);\n"
,
146
l?
"load"
:
"store"
,
147
w?
"w1"
:
"w0"
,
148
b?
"byte"
:
"word"
,
149
u?
"u1"
:
"u0"
,
150
p?
"p1"
:
"p0"
,
151
reg
?
"reg"
:
"imm"
,
152
c!=14?
"__"
:
""
,
cond
[c]);
153
}
154
155
printf(
"\n\tvoid (*arm_load_store_instr[1024])(struct cpu *,\n"
156
"\t\tstruct arm_instr_call *) = {\n"
);
157
n = 0;
158
for
(
reg
=0;
reg
<=1;
reg
++)
159
for
(p=0; p<=1; p++)
160
for
(u=0; u<=1; u++)
161
for
(b=0; b<=1; b++)
162
for
(w=0; w<=1; w++)
163
for
(l=0; l<=1; l++)
164
for
(c=0; c<16; c++) {
165
if
(c == 15)
166
printf(
"\tarm_instr_nop"
);
167
else
168
printf(
"\tarm_instr_%s_%s_%s"
169
"_%s_%s_%s%s%s"
,
170
l?
"load"
:
"store"
,
171
w?
"w1"
:
"w0"
,
172
b?
"byte"
:
"word"
,
173
u?
"u1"
:
"u0"
,
174
p?
"p1"
:
"p0"
,
175
reg
?
"reg"
:
"imm"
,
176
c!=14?
"__"
:
""
,
cond
[c]);
177
n++;
178
if
(n!=2*2*2*2*2*2*16)
179
printf(
","
);
180
printf(
"\n"
);
181
}
182
183
printf(
"};\n\n"
);
184
185
/* Load/store with the pc register: */
186
printf(
"\n\tvoid (*arm_load_store_instr_pc[1024])"
187
"(struct cpu *,\n\t\tstruct arm_instr_call *) = {\n"
);
188
n = 0;
189
for
(
reg
=0;
reg
<=1;
reg
++)
190
for
(p=0; p<=1; p++)
191
for
(u=0; u<=1; u++)
192
for
(b=0; b<=1; b++)
193
for
(w=0; w<=1; w++)
194
for
(l=0; l<=1; l++)
195
for
(c=0; c<16; c++) {
196
if
(c == 15)
197
printf(
"\tarm_instr_nop"
);
198
else
199
printf(
"\tarm_instr_%s_%s_%s_"
200
"%s_%s_%s_pc%s%s"
,
201
l?
"load"
:
"store"
,
202
w?
"w1"
:
"w0"
,
203
b?
"byte"
:
"word"
,
204
u?
"u1"
:
"u0"
,
205
p?
"p1"
:
"p0"
,
206
reg
?
"reg"
:
"imm"
,
207
c!=14?
"__"
:
""
,
cond
[c]);
208
n++;
209
if
(n!=2*2*2*2*2*2*16)
210
printf(
","
);
211
printf(
"\n"
);
212
}
213
214
printf(
"};\n\n"
);
215
}
216
217
218
/* "Addressing mode 3": */
219
220
if
(!only_array)
221
for
(
reg
=0;
reg
<=1;
reg
++)
222
for
(h=0; h<=1; h++)
223
for
(s=0; s<=1; s++)
224
for
(l=0; l<=1; l++) {
225
if
(s==0 && h==0)
226
continue
;
227
/* l=0, s=1, h=0 means LDRD */
228
/* l=0, s=1, h=1 means STRD */
229
230
printf(
"#define A__NAME__general arm_instr_%s_"
231
"%s_%s_%s_%s_%s_%s__general\n"
,
232
l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
233
s?
"signed"
:
"unsigned"
,
234
h?
"halfword"
:
"byte"
, u?
"u1"
:
"u0"
,
235
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
236
237
printf(
"#define A__NAME arm_instr_%s_%s_%s_%s_"
238
"%s_%s_%s\n"
, l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
239
s?
"signed"
:
"unsigned"
,
240
h?
"halfword"
:
"byte"
, u?
"u1"
:
"u0"
,
241
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
242
for
(c=0; c<14; c++)
243
printf(
"#define A__NAME__%s arm_instr_%s_"
244
"%s_%s_%s_%s_%s_%s__%s\n"
,
245
cond
[c], l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
246
s?
"signed"
:
"unsigned"
,
247
h?
"halfword"
:
"byte"
, u?
"u1"
:
"u0"
,
248
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
,
cond
[c]);
249
250
printf(
"#define A__NAME_PC arm_instr_%s_%s_%s_%s_%s_"
251
"%s_%s_pc\n"
, l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
252
s?
"signed"
:
"unsigned"
,
253
h?
"halfword"
:
"byte"
, u?
"u1"
:
"u0"
,
254
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
);
255
for
(c=0; c<14; c++)
256
printf(
"#define A__NAME_PC__%s arm_instr_%s_"
257
"%s_%s_%s_%s_%s_%s_pc__%s\n"
,
258
cond
[c], l?
"load"
:
"store"
, w?
"w1"
:
"w0"
,
259
s?
"signed"
:
"unsigned"
,
260
h?
"halfword"
:
"byte"
, u?
"u1"
:
"u0"
,
261
p?
"p1"
:
"p0"
,
reg
?
"reg"
:
"imm"
,
cond
[c]);
262
263
if
(s) printf(
"#define A__SIGNED\n"
);
264
if
(l) printf(
"#define A__L\n"
);
265
if
(w) printf(
"#define A__W\n"
);
266
if
(h) printf(
"#define A__H\n"
);
267
else
printf(
"#define A__B\n"
);
268
if
(u) printf(
"#define A__U\n"
);
269
if
(p) printf(
"#define A__P\n"
);
270
if
(
reg
)printf(
"#define A__REG\n"
);
271
printf(
"#include \"cpu_arm_instr_loadstore.cc\"\n"
);
272
if
(s) printf(
"#undef A__SIGNED\n"
);
273
if
(l) printf(
"#undef A__L\n"
);
274
if
(w) printf(
"#undef A__W\n"
);
275
if
(h) printf(
"#undef A__H\n"
);
276
else
printf(
"#undef A__B\n"
);
277
if
(u) printf(
"#undef A__U\n"
);
278
if
(p) printf(
"#undef A__P\n"
);
279
if
(
reg
)printf(
"#undef A__REG\n"
);
280
for
(c=0; c<14; c++)
281
printf(
"#undef A__NAME__%s\n"
,
cond
[c]);
282
for
(c=0; c<14; c++)
283
printf(
"#undef A__NAME_PC__%s\n"
,
cond
[c]);
284
printf(
"#undef A__NAME__general\n"
);
285
printf(
"#undef A__NAME_PC\n"
);
286
printf(
"#undef A__NAME\n"
);
287
}
288
289
if
(only_array) {
290
for
(
reg
=0;
reg
<=1;
reg
++)
291
for
(p=0; p<=1; p++)
292
for
(u=0; u<=1; u++)
293
for
(h=0; h<=1; h++)
294
for
(w=0; w<=1; w++)
295
for
(s=0; s<=1; s++)
296
for
(l=0; l<=1; l++)
297
for
(c=0; c<16; c++) {
298
if
(c == 15)
299
continue
;
300
else
if
(s==0 && h==0)
301
continue
;
302
303
printf(
"void arm_instr_%s_%s_%s_%s_%s_%s_%s%s%s"
304
"(struct cpu *, struct arm_instr_call *);\n"
,
305
l?
"load"
:
"store"
,
306
w?
"w1"
:
"w0"
,
307
s?
"signed"
:
"unsigned"
,
308
h?
"halfword"
:
"byte"
,
309
u?
"u1"
:
"u0"
, p?
"p1"
:
"p0"
,
310
reg
?
"reg"
:
"imm"
,
311
c!=14?
"__"
:
""
,
cond
[c]);
312
printf(
"void arm_instr_%s_%s_%s_%s_%s_%s_"
313
"%s_pc%s%s(struct cpu *, struct "
314
"arm_instr_call *);\n"
,
315
l?
"load"
:
"store"
,
316
w?
"w1"
:
"w0"
,
317
s?
"signed"
:
"unsigned"
,
318
h?
"halfword"
:
"byte"
,
319
u?
"u1"
:
"u0"
, p?
"p1"
:
"p0"
,
320
reg
?
"reg"
:
"imm"
,
321
c!=14?
"__"
:
""
,
cond
[c]);
322
}
323
324
printf(
"\n\tvoid (*arm_load_store_instr_3[2048])"
325
"(struct cpu *,\n\t\tstruct arm_instr_call *) = {\n"
);
326
n = 0;
327
for
(
reg
=0;
reg
<=1;
reg
++)
328
for
(p=0; p<=1; p++)
329
for
(u=0; u<=1; u++)
330
for
(h=0; h<=1; h++)
331
for
(w=0; w<=1; w++)
332
for
(s=0; s<=1; s++)
333
for
(l=0; l<=1; l++)
334
for
(c=0; c<16; c++) {
335
if
(c == 15)
336
printf(
"\tarm_instr_nop"
);
337
else
if
(s==0 && h==0)
338
printf(
"\tarm_instr_invalid"
);
339
else
340
printf(
"\tarm_instr_%s_%s_%s_%s_"
341
"%s_%s_%s%s%s"
,
342
l?
"load"
:
"store"
,
343
w?
"w1"
:
"w0"
,
344
s?
"signed"
:
"unsigned"
,
345
h?
"halfword"
:
"byte"
,
346
u?
"u1"
:
"u0"
, p?
"p1"
:
"p0"
,
347
reg
?
"reg"
:
"imm"
,
348
c!=14?
"__"
:
""
,
cond
[c]);
349
n++;
350
if
(n!=2*2*2*2*2*2*2*16)
351
printf(
","
);
352
printf(
"\n"
);
353
}
354
355
printf(
"};\n\n"
);
356
357
/* Load/store with the pc register: */
358
printf(
"\n\tvoid (*arm_load_store_instr_3_pc[2048])"
359
"(struct cpu *,\n\t\tstruct arm_instr_call *) = {\n"
);
360
n = 0;
361
for
(
reg
=0;
reg
<=1;
reg
++)
362
for
(p=0; p<=1; p++)
363
for
(u=0; u<=1; u++)
364
for
(h=0; h<=1; h++)
365
for
(w=0; w<=1; w++)
366
for
(s=0; s<=1; s++)
367
for
(l=0; l<=1; l++)
368
for
(c=0; c<16; c++) {
369
if
(c == 15)
370
printf(
"\tarm_instr_nop"
);
371
else
if
(s==0 && h==0)
372
printf(
"\tarm_instr_invalid"
);
373
else
374
printf(
"\tarm_instr_%s_%s_%s_%s_%s_%s_"
375
"%s_pc%s%s"
, l?
"load"
:
"store"
,
376
w?
"w1"
:
"w0"
,
377
s?
"signed"
:
"unsigned"
,
378
h?
"halfword"
:
"byte"
,
379
u?
"u1"
:
"u0"
, p?
"p1"
:
"p0"
,
380
reg
?
"reg"
:
"imm"
,
381
c!=14?
"__"
:
""
,
cond
[c]);
382
n++;
383
if
(n!=2*2*2*2*2*2*2*16)
384
printf(
","
);
385
printf(
"\n"
);
386
}
387
388
printf(
"};\n\n"
);
389
}
390
391
return
0;
392
}
393
main
int main(int argc, char *argv[])
Definition:
generate_arm_loadstore.c:36
reg
#define reg(x)
Definition:
tmp_alpha_tail.cc:53
cond
char * cond[16]
Definition:
generate_arm_loadstore.c:32
Generated on Sun Sep 30 2018 16:05:18 for GXemul by
1.8.13