generate_ppc_loadstore.c Source File

Back to the index.

generate_ppc_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 <string.h>
30 
31 
32 char *sizechar[4] = { "b", "h", "w", "d" };
33 char *modes[2] = { "", "32" };
34 
35 
36 void do_it(int mode)
37 {
38  int n, load, size, zero, ignoreofs, update;
39 
40  n = 0;
41  for (update=0; update<=1; update++)
42  for (ignoreofs=0; ignoreofs<=1; ignoreofs++)
43  for (load=0; load<=1; load++)
44  for (zero=0; zero<=1; zero++)
45  for (size=0; size<4; size++) {
46  if (!zero && !load)
47  continue;
48  if (load && !zero && size == 3)
49  continue;
50 
51  switch (size) {
52  case 0: printf("#define LS_B\n"); break;
53  case 1: printf("#define LS_H\n"); break;
54  case 2: printf("#define LS_W\n"); break;
55  case 3: printf("#define LS_D\n"); break;
56  }
57  printf("#define LS_SIZE %i\n", 1 << size);
58  if (zero)
59  printf("#define LS_ZERO\n");
60  if (load)
61  printf("#define LS_LOAD\n");
62  if (ignoreofs)
63  printf("#define LS_IGNOREOFS\n");
64  if (update)
65  printf("#define LS_UPDATE\n");
66 
67  printf("#define LS_GENERIC_N ppc%s_generic_",
68  modes[mode]);
69  if (load)
70  printf("l");
71  else
72  printf("st");
73  printf("%s", sizechar[size]);
74  if (load) {
75  if (zero)
76  printf("z");
77  else
78  printf("a");
79  }
80  if (update)
81  printf("u");
82  printf("\n");
83 
84  printf("#define LS_N ppc%s_instr_", modes[mode]);
85  if (load)
86  printf("l");
87  else
88  printf("st");
89  printf("%s", sizechar[size]);
90  if (load && size < 3) {
91  if (zero)
92  printf("z");
93  else
94  printf("a");
95  }
96  if (update)
97  printf("u");
98  if (ignoreofs)
99  printf("_0");
100  printf("\n");
101 
102  printf("#include \"cpu_ppc_instr_loadstore.cc\"\n");
103 
104  printf("#undef LS_N\n");
105  printf("#undef LS_GENERIC_N\n");
106  switch (size) {
107  case 0: printf("#undef LS_B\n"); break;
108  case 1: printf("#undef LS_H\n"); break;
109  case 2: printf("#undef LS_W\n"); break;
110  case 3: printf("#undef LS_D\n"); break;
111  }
112  printf("#undef LS_SIZE\n");
113  if (load)
114  printf("#undef LS_LOAD\n");
115  if (update)
116  printf("#undef LS_UPDATE\n");
117  if (zero)
118  printf("#undef LS_ZERO\n");
119  if (ignoreofs)
120  printf("#undef LS_IGNOREOFS\n");
121  }
122 
123  /* Indexed loads/stores: */
124  printf("#define LS_INDEXED\n");
125  for (update=0; update<=1; update++)
126  for (load=0; load<=1; load++)
127  for (zero=0; zero<=1; zero++)
128  for (size=0; size<4; size++) {
129  if (!zero && !load)
130  continue;
131  if (load && !zero && size == 3)
132  continue;
133 
134  switch (size) {
135  case 0: printf("#define LS_B\n"); break;
136  case 1: printf("#define LS_H\n"); break;
137  case 2: printf("#define LS_W\n"); break;
138  case 3: printf("#define LS_D\n"); break;
139  }
140  printf("#define LS_SIZE %i\n", 1 << size);
141  if (zero)
142  printf("#define LS_ZERO\n");
143  if (load)
144  printf("#define LS_LOAD\n");
145  if (update)
146  printf("#define LS_UPDATE\n");
147 
148  printf("#define LS_GENERIC_N ppc%s_generic_",
149  modes[mode]);
150  if (load)
151  printf("l");
152  else
153  printf("st");
154  printf("%s", sizechar[size]);
155  if (load) {
156  if (zero)
157  printf("z");
158  else
159  printf("a");
160  }
161  if (update)
162  printf("u");
163  printf("x");
164  printf("\n");
165 
166  printf("#define LS_N ppc%s_instr_", modes[mode]);
167  if (load)
168  printf("l");
169  else
170  printf("st");
171  printf("%s", sizechar[size]);
172  if (load && size < 3) {
173  if (zero)
174  printf("z");
175  else
176  printf("a");
177  }
178  if (update)
179  printf("u");
180  printf("x");
181  printf("\n");
182 
183  printf("#include \"cpu_ppc_instr_loadstore.cc\"\n");
184 
185  printf("#undef LS_N\n");
186  printf("#undef LS_GENERIC_N\n");
187  switch (size) {
188  case 0: printf("#undef LS_B\n"); break;
189  case 1: printf("#undef LS_H\n"); break;
190  case 2: printf("#undef LS_W\n"); break;
191  case 3: printf("#undef LS_D\n"); break;
192  }
193  printf("#undef LS_SIZE\n");
194  if (load)
195  printf("#undef LS_LOAD\n");
196  if (update)
197  printf("#undef LS_UPDATE\n");
198  if (zero)
199  printf("#undef LS_ZERO\n");
200  }
201 
202  printf("#undef LS_INDEXED\n");
203 
204 
205  /* Lookup tables for loads/stores: */
206  printf("\n\nvoid (*ppc%s_loadstore[64])(struct cpu *, struct "
207  "ppc_instr_call *) = {\n", modes[mode]);
208  n = 0;
209  for (update=0; update<=1; update++)
210  for (ignoreofs=0; ignoreofs<=1; ignoreofs++)
211  for (load=0; load<=1; load++)
212  for (zero=0; zero<=1; zero++)
213  for (size=0; size<4; size++) {
214  printf("\tppc%s_instr_", modes[mode]);
215 
216  if (load && !zero && size == 3) {
217  printf("invalid");
218  goto cont;
219  }
220 
221  if (load)
222  printf("l");
223  else
224  printf("st");
225  printf("%s", sizechar[size]);
226  if (load && size < 3) {
227  if (zero)
228  printf("z");
229  else
230  printf("a");
231  }
232  if (update)
233  printf("u");
234  if (ignoreofs)
235  printf("_0");
236 cont:
237  if (++n < 64)
238  printf(",");
239  printf("\n");
240  }
241 
242  printf("};\n\n");
243 
244  printf("\n\nvoid (*ppc%s_loadstore_indexed[32])(struct cpu *, struct "
245  "ppc_instr_call *) = {\n", modes[mode]);
246  n = 0;
247  for (update=0; update<=1; update++)
248  for (load=0; load<=1; load++)
249  for (zero=0; zero<=1; zero++)
250  for (size=0; size<4; size++) {
251  printf("\tppc%s_instr_", modes[mode]);
252 
253  if (load && !zero && size == 3) {
254  printf("invalid");
255  goto cont_x;
256  }
257 
258  if (load)
259  printf("l");
260  else
261  printf("st");
262  printf("%s", sizechar[size]);
263  if (load && size < 3) {
264  if (zero)
265  printf("z");
266  else
267  printf("a");
268  }
269  if (update)
270  printf("u");
271  printf("x");
272 cont_x:
273  if (++n < 32)
274  printf(",");
275  printf("\n");
276  }
277 
278  printf("};\n\n");
279 
280  /* Non-standard loads/stores: */
281  printf("#define LS_BYTEREVERSE\n"
282  "#define LS_INDEXED\n"
283 
284  "#define LS_SIZE 2\n"
285  "#define LS_H\n"
286  "#define LS_GENERIC_N ppc%s_generic_lhbrx\n"
287  "#define LS_N ppc%s_instr_lhbrx\n"
288  "#define LS_LOAD\n"
289  "#include \"cpu_ppc_instr_loadstore.cc\"\n"
290  "#undef LS_LOAD\n"
291  "#undef LS_N\n"
292  "#undef LS_GENERIC_N\n"
293  "#define LS_GENERIC_N ppc%s_generic_sthbrx\n"
294  "#define LS_N ppc%s_instr_sthbrx\n"
295  "#include \"cpu_ppc_instr_loadstore.cc\"\n"
296  "#undef LS_N\n"
297  "#undef LS_GENERIC_N\n"
298  "#undef LS_H\n"
299  "#undef LS_SIZE\n"
300 
301  "#define LS_SIZE 4\n"
302  "#define LS_W\n"
303  "#define LS_GENERIC_N ppc%s_generic_lwbrx\n"
304  "#define LS_N ppc%s_instr_lwbrx\n"
305  "#define LS_LOAD\n"
306  "#include \"cpu_ppc_instr_loadstore.cc\"\n"
307  "#undef LS_LOAD\n"
308  "#undef LS_N\n"
309  "#undef LS_GENERIC_N\n"
310  "#define LS_GENERIC_N ppc%s_generic_stwbrx\n"
311  "#define LS_N ppc%s_instr_stwbrx\n"
312  "#include \"cpu_ppc_instr_loadstore.cc\"\n"
313  "#undef LS_N\n"
314  "#undef LS_GENERIC_N\n"
315  "#undef LS_W\n"
316  "#undef LS_SIZE\n"
317 
318  "#undef LS_INDEXED\n"
319  "#undef LS_BYTEREVERSE\n",
320  modes[mode], modes[mode], modes[mode], modes[mode],
321  modes[mode], modes[mode], modes[mode], modes[mode]);
322 }
323 
324 int main(int argc, char *argv[])
325 {
326  int mode;
327 
328  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
329 
330  for (mode = 0; mode <= 1; mode ++) {
331  if (mode == 0)
332  printf("#ifndef MODE32\n");
333  else
334  printf("#ifdef MODE32\n");
335 
336  do_it(mode);
337 
338  printf("#endif\n");
339  }
340 
341  return 0;
342 }
343 
void do_it(int mode)
void load(FILE *fh, unsigned char *ptr, unsigned long sz)
char * sizechar[4]
char * modes[2]
int main(int argc, char *argv[])

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13