/[gxemul]/upstream/0.3.6/src/cpus/generate_arm_loadstore.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.3.6/src/cpus/generate_arm_loadstore.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations)
Mon Oct 8 16:18:56 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 10156 byte(s)
0.3.6
1 /*
2 * Copyright (C) 2005 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 * $Id: generate_arm_loadstore.c,v 1.1 2005/08/29 14:36:41 debug Exp $
29 */
30
31 #include <stdio.h>
32
33 char *cond[16] = {
34 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
35 "hi", "ls", "ge", "lt", "gt", "le", "", "" };
36
37 int main(int argc, char *argv[])
38 {
39 int l, b, w, h, s, u, p, reg, c, n;
40
41 printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
42 printf("#include <stdio.h>\n#include <stdlib.h>\n"
43 "#include \"cpu.h\"\n"
44 "#include \"memory.h\"\n"
45 "#include \"misc.h\"\n"
46 "#define reg(x) (*((uint32_t *)(x)))\n");
47 printf("extern void arm_instr_nop(struct cpu *, "
48 "struct arm_instr_call *);\n");
49 printf("extern void arm_instr_invalid(struct cpu *, "
50 "struct arm_instr_call *);\n");
51 printf("extern uint32_t R(struct cpu *, struct arm_instr_call *,"
52 " uint32_t, int);\n");
53 printf("extern void arm_pc_to_pointers(struct cpu *);\n");
54
55 for (reg=0; reg<=1; reg++)
56 for (p=0; p<=1; p++)
57 for (u=0; u<=1; u++)
58 for (b=0; b<=1; b++)
59 for (w=0; w<=1; w++)
60 for (l=0; l<=1; l++) {
61 printf("#define A__NAME__general arm_instr_%s_"
62 "%s_%s_%s_%s_%s__general\n",
63 l?"load":"store", w? "w1" : "w0",
64 b? "byte" : "word", u? "u1" : "u0",
65 p? "p1" : "p0", reg? "reg" : "imm");
66
67 printf("#define A__NAME arm_instr_%s_%s_%s_%s_%s_%s\n",
68 l? "load" : "store", w? "w1" : "w0",
69 b? "byte" : "word", u? "u1" : "u0",
70 p? "p1" : "p0", reg? "reg" : "imm");
71 for (c=0; c<14; c++)
72 printf("#define A__NAME__%s arm_instr_%s_"
73 "%s_%s_%s_%s_%s__%s\n",
74 cond[c], l?"load":"store", w? "w1" : "w0",
75 b? "byte" : "word", u? "u1" : "u0",
76 p? "p1" : "p0", reg? "reg" : "imm",cond[c]);
77
78 printf("#define A__NAME_PC arm_instr_%s_%s_%s_%s_"
79 "%s_%s_pc\n", 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_PC__%s arm_instr_%s_"
84 "%s_%s_%s_%s_%s_pc__%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 if (l) printf("#define A__L\n");
90 if (w) printf("#define A__W\n");
91 if (b) printf("#define A__B\n");
92 if (u) printf("#define A__U\n");
93 if (p) printf("#define A__P\n");
94 if (reg)printf("#define A__REG\n");
95 printf("#include \"cpu_arm_instr_loadstore.c\"\n");
96 if (l) printf("#undef A__L\n");
97 if (w) printf("#undef A__W\n");
98 if (b) printf("#undef A__B\n");
99 if (u) printf("#undef A__U\n");
100 if (p) printf("#undef A__P\n");
101 if (reg)printf("#undef A__REG\n");
102 for (c=0; c<14; c++)
103 printf("#undef A__NAME__%s\n", cond[c]);
104 for (c=0; c<14; c++)
105 printf("#undef A__NAME_PC__%s\n", cond[c]);
106 printf("#undef A__NAME__general\n");
107 printf("#undef A__NAME_PC\n");
108 printf("#undef A__NAME\n");
109 }
110
111 printf("\n\tvoid (*arm_load_store_instr[1024])(struct cpu *,\n"
112 "\t\tstruct arm_instr_call *) = {\n");
113 n = 0;
114 for (reg=0; reg<=1; reg++)
115 for (p=0; p<=1; p++)
116 for (u=0; u<=1; u++)
117 for (b=0; b<=1; b++)
118 for (w=0; w<=1; w++)
119 for (l=0; l<=1; l++)
120 for (c=0; c<16; c++) {
121 if (c == 15)
122 printf("\tarm_instr_nop");
123 else
124 printf("\tarm_instr_%s_%s_%s_%s_%s_%s%s%s",
125 l? "load" : "store",
126 w? "w1" : "w0",
127 b? "byte" : "word",
128 u? "u1" : "u0",
129 p? "p1" : "p0",
130 reg? "reg" : "imm",
131 c!=14? "__" : "", cond[c]);
132 n++;
133 if (n!=2*2*2*2*2*2*16)
134 printf(",");
135 printf("\n");
136 }
137
138 printf("};\n\n");
139
140 /* Load/store with the pc register: */
141 printf("\n\tvoid (*arm_load_store_instr_pc[1024])(struct cpu *,\n"
142 "\t\tstruct arm_instr_call *) = {\n");
143 n = 0;
144 for (reg=0; reg<=1; reg++)
145 for (p=0; p<=1; p++)
146 for (u=0; u<=1; u++)
147 for (b=0; b<=1; b++)
148 for (w=0; w<=1; w++)
149 for (l=0; l<=1; l++)
150 for (c=0; c<16; c++) {
151 if (c == 15)
152 printf("\tarm_instr_nop");
153 else
154 printf("\tarm_instr_%s_%s_%s_%s_%s_%s_pc%s%s",
155 l? "load" : "store",
156 w? "w1" : "w0",
157 b? "byte" : "word",
158 u? "u1" : "u0",
159 p? "p1" : "p0",
160 reg? "reg" : "imm",
161 c!=14? "__" : "", cond[c]);
162 n++;
163 if (n!=2*2*2*2*2*2*16)
164 printf(",");
165 printf("\n");
166 }
167
168 printf("};\n\n");
169
170
171
172 /* "Addressing mode 3": */
173
174 for (reg=0; reg<=1; reg++)
175 for (p=0; p<=1; p++)
176 for (u=0; u<=1; u++)
177 for (h=0; h<=1; h++)
178 for (w=0; w<=1; w++)
179 for (s=0; s<=1; s++)
180 for (l=0; l<=1; l++) {
181 if (s==0 && h==0)
182 continue;
183 if (s==1 && l==0)
184 continue;
185
186 printf("#define A__NAME__general arm_instr_%s_"
187 "%s_%s_%s_%s_%s_%s__general\n",
188 l?"load":"store", w? "w1" : "w0",
189 s? "signed" : "unsigned",
190 h? "halfword" : "byte", u? "u1" : "u0",
191 p? "p1" : "p0", reg? "reg" : "imm");
192
193 printf("#define A__NAME arm_instr_%s_%s_%s_%s_"
194 "%s_%s_%s\n", l? "load" : "store", w? "w1" : "w0",
195 s? "signed" : "unsigned",
196 h? "halfword" : "byte", u? "u1" : "u0",
197 p? "p1" : "p0", reg? "reg" : "imm");
198 for (c=0; c<14; c++)
199 printf("#define A__NAME__%s arm_instr_%s_"
200 "%s_%s_%s_%s_%s_%s__%s\n",
201 cond[c], l?"load":"store", w? "w1" : "w0",
202 s? "signed" : "unsigned",
203 h? "halfword" : "byte", u? "u1" : "u0",
204 p? "p1" : "p0", reg? "reg" : "imm",cond[c]);
205
206 printf("#define A__NAME_PC arm_instr_%s_%s_%s_%s_%s_"
207 "%s_%s_pc\n", l? "load" : "store", w? "w1" : "w0",
208 s? "signed" : "unsigned",
209 h? "halfword" : "byte", u? "u1" : "u0",
210 p? "p1" : "p0", reg? "reg" : "imm");
211 for (c=0; c<14; c++)
212 printf("#define A__NAME_PC__%s arm_instr_%s_"
213 "%s_%s_%s_%s_%s_%s_pc__%s\n",
214 cond[c], l?"load":"store", w? "w1" : "w0",
215 s? "signed" : "unsigned",
216 h? "halfword" : "byte", u? "u1" : "u0",
217 p? "p1" : "p0", reg? "reg" : "imm",cond[c]);
218
219 if (s) printf("#define A__SIGNED\n");
220 if (l) printf("#define A__L\n");
221 if (w) printf("#define A__W\n");
222 if (h) printf("#define A__H\n");
223 else printf("#define A__B\n");
224 if (u) printf("#define A__U\n");
225 if (p) printf("#define A__P\n");
226 if (reg)printf("#define A__REG\n");
227 printf("#include \"cpu_arm_instr_loadstore.c\"\n");
228 if (s) printf("#undef A__SIGNED\n");
229 if (l) printf("#undef A__L\n");
230 if (w) printf("#undef A__W\n");
231 if (h) printf("#undef A__H\n");
232 else printf("#undef A__B\n");
233 if (u) printf("#undef A__U\n");
234 if (p) printf("#undef A__P\n");
235 if (reg)printf("#undef A__REG\n");
236 for (c=0; c<14; c++)
237 printf("#undef A__NAME__%s\n", cond[c]);
238 for (c=0; c<14; c++)
239 printf("#undef A__NAME_PC__%s\n", cond[c]);
240 printf("#undef A__NAME__general\n");
241 printf("#undef A__NAME_PC\n");
242 printf("#undef A__NAME\n");
243 }
244
245 printf("\n\tvoid (*arm_load_store_instr_3[2048])(struct cpu *,\n"
246 "\t\tstruct arm_instr_call *) = {\n");
247 n = 0;
248 for (reg=0; reg<=1; reg++)
249 for (p=0; p<=1; p++)
250 for (u=0; u<=1; u++)
251 for (h=0; h<=1; h++)
252 for (w=0; w<=1; w++)
253 for (s=0; s<=1; s++)
254 for (l=0; l<=1; l++)
255 for (c=0; c<16; c++) {
256 if (c == 15)
257 printf("\tarm_instr_nop");
258 else if (s==0 && h==0)
259 printf("\tarm_instr_invalid");
260 else if (s==1 && l==0)
261 printf("\tarm_instr_invalid");
262 else
263 printf("\tarm_instr_%s_%s_%s_%s_%s_%s_%s%s%s",
264 l? "load" : "store",
265 w? "w1" : "w0",
266 s? "signed" : "unsigned",
267 h? "halfword" : "byte",
268 u? "u1" : "u0", p? "p1" : "p0",
269 reg? "reg" : "imm",
270 c!=14? "__" : "", cond[c]);
271 n++;
272 if (n!=2*2*2*2*2*2*2*16)
273 printf(",");
274 printf("\n");
275 }
276
277 printf("};\n\n");
278
279 /* Load/store with the pc register: */
280 printf("\n\tvoid (*arm_load_store_instr_3_pc[2048])(struct cpu *,\n"
281 "\t\tstruct arm_instr_call *) = {\n");
282 n = 0;
283 for (reg=0; reg<=1; reg++)
284 for (p=0; p<=1; p++)
285 for (u=0; u<=1; u++)
286 for (h=0; h<=1; h++)
287 for (w=0; w<=1; w++)
288 for (s=0; s<=1; s++)
289 for (l=0; l<=1; l++)
290 for (c=0; c<16; c++) {
291 if (c == 15)
292 printf("\tarm_instr_nop");
293 else if (s==0 && h==0)
294 printf("\tarm_instr_invalid");
295 else if (s==1 && l==0)
296 printf("\tarm_instr_invalid");
297 else
298 printf("\tarm_instr_%s_%s_%s_%s_%s_%s_"
299 "%s_pc%s%s", l? "load" : "store",
300 w? "w1" : "w0",
301 s? "signed" : "unsigned",
302 h? "halfword" : "byte",
303 u? "u1" : "u0", p? "p1" : "p0",
304 reg? "reg" : "imm",
305 c!=14? "__" : "", cond[c]);
306 n++;
307 if (n!=2*2*2*2*2*2*2*16)
308 printf(",");
309 printf("\n");
310 }
311
312 printf("};\n\n");
313
314
315 return 0;
316 }
317

  ViewVC Help
Powered by ViewVC 1.1.26