generate_m88k_loadstore.c Source File

Back to the index.

generate_m88k_loadstore.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-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  * Automatic generation of M88K loads and stores:
29  *
30  * 2 bits size (0=byte, 1=halfword, 2=word, 3=doubleword)
31  * 1 bit load/store
32  * 1 bit signedness (for byte and halfword loads only!)
33  * 1 bit endianness
34  * 1 bit scaledness (for halfword, word, and doublewords only,
35  * and only when using register offset)
36  * 1 bit ".usr" (only when using register offset)
37  * 1 bit registeroffset
38  */
39 
40 #include <stdio.h>
41 #include <string.h>
42 
43 
44 #define M88K_LOADSTORE_STORE 4
45 #define M88K_LOADSTORE_SIGNEDNESS 8
46 #define M88K_LOADSTORE_ENDIANNESS 16
47 #define M88K_LOADSTORE_SCALEDNESS 32
48 #define M88K_LOADSTORE_USR 64
49 #define M88K_LOADSTORE_REGISTEROFFSET 128
50 
51 
53 
54 
55 void print_function_name(int size, int store, int signedness,
56  int endianness, int scaledness, int usr, int registeroffset)
57 {
58  if (store)
59  printf("st");
60  else {
61  printf("ld");
62  if (!signedness)
63  printf("_u");
64  }
65  printf("_%i", 1 << size);
66 
67  if (endianness >= 0) {
68  /* Special case so that Byte loads/stores are only
69  included ones (for little endian): */
70  if (size == 0 && endianness)
71  printf("_le");
72  else
73  printf(endianness? "_be" : "_le");
74  }
75 
76  if (scaledness && size > 0)
77  printf("_scaled");
78 
79  if (usr)
80  printf("_usr");
81 
82  if (registeroffset)
83  printf("_regofs");
84 }
85 
86 
87 void loadstore(int size, int store, int signedness,
88  int endianness, int scaledness, int usr, int registeroffset)
89 {
90  if (store && signedness)
91  return;
92 
93  if (size == 0 && endianness)
94  return;
95 
96  if (size == 0 && scaledness)
97  return;
98 
99  if (!registeroffset && usr)
100  return;
101 
102  if (!registeroffset && scaledness)
103  return;
104 
105  if (store)
106  printf("#define LS_STORE\n");
107  else
108  printf("#define LS_LOAD\n");
109 
110  printf("#define LS_N m88k_instr_");
111  print_function_name(size, store, signedness, endianness,
112  scaledness, usr, registeroffset);
113  printf("\n");
114 
115  printf("#define LS_GENERIC_N m88k_generic_");
116  print_function_name(size, store, signedness, -1,
117  scaledness, usr, registeroffset);
118  printf("\n");
119 
120  printf("#define LS_%i\n", 1 << size);
121  printf("#define LS_SIZE %i\n", 1 << size);
122 
123  if (signedness && !store)
124  printf("#define LS_SIGNED\n");
125 
126  if (endianness)
127  printf("#define LS_BE\n");
128  else
129  printf("#define LS_LE\n");
130 
131  if (endianness == 0)
132  printf("#define LS_INCLUDE_GENERIC\n");
133 
134  if (scaledness)
135  printf("#define LS_SCALED\n");
136 
137  if (usr)
138  printf("#define LS_USR\n");
139 
140  if (registeroffset)
141  printf("#define LS_REGOFS\n");
142 
143  printf("#include \"cpu_m88k_instr_loadstore.cc\"\n");
145 
146  if (registeroffset)
147  printf("#undef LS_REGOFS\n");
148 
149  if (usr)
150  printf("#undef LS_USR\n");
151 
152  if (scaledness)
153  printf("#undef LS_SCALED\n");
154 
155  if (endianness == 0)
156  printf("#undef LS_INCLUDE_GENERIC\n");
157 
158  if (endianness)
159  printf("#undef LS_BE\n");
160  else
161  printf("#undef LS_LE\n");
162 
163  if (signedness && !store)
164  printf("#undef LS_SIGNED\n");
165 
166  printf("#undef LS_SIZE\n");
167  printf("#undef LS_%i\n", 1 << size);
168 
169  printf("#undef LS_GENERIC_N\n");
170  printf("#undef LS_N\n");
171 
172  if (store)
173  printf("#undef LS_STORE\n");
174  else
175  printf("#undef LS_LOAD\n");
176 }
177 
178 
179 int main(int argc, char *argv[])
180 {
181  int size, store, signedness, endianness, scaledness, usr,
182  registeroffset;
183 
184  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
185 
186  for (registeroffset=0; registeroffset<=M88K_LOADSTORE_REGISTEROFFSET;
187  registeroffset+=M88K_LOADSTORE_REGISTEROFFSET)
188  for (usr=0; usr<=M88K_LOADSTORE_USR; usr+=M88K_LOADSTORE_USR)
189  for (scaledness=0; scaledness<=M88K_LOADSTORE_SCALEDNESS;
190  scaledness+=M88K_LOADSTORE_SCALEDNESS)
191  for (endianness=0; endianness<=M88K_LOADSTORE_ENDIANNESS;
192  endianness+=M88K_LOADSTORE_ENDIANNESS)
193  for (signedness=0; signedness<=M88K_LOADSTORE_SIGNEDNESS;
194  signedness+=M88K_LOADSTORE_SIGNEDNESS)
195  for (store=0; store<=M88K_LOADSTORE_STORE;
196  store+=M88K_LOADSTORE_STORE)
197  for (size=0; size<=3; size++)
198  loadstore(size, store, signedness,
199  endianness, scaledness, usr, registeroffset);
200 
201  /* Array of pointers to fast load/store functions: */
202  printf("\n\nvoid (*m88k_loadstore[256])(struct cpu *, struct "
203  "m88k_instr_call *) = {\n");
204  for (registeroffset=0; registeroffset<=M88K_LOADSTORE_REGISTEROFFSET;
205  registeroffset+=M88K_LOADSTORE_REGISTEROFFSET)
206  for (usr=0; usr<=M88K_LOADSTORE_USR; usr+=M88K_LOADSTORE_USR)
207  for (scaledness=0; scaledness<=M88K_LOADSTORE_SCALEDNESS;
208  scaledness+=M88K_LOADSTORE_SCALEDNESS)
209  for (endianness=0; endianness<=M88K_LOADSTORE_ENDIANNESS;
210  endianness+=M88K_LOADSTORE_ENDIANNESS)
211  for (signedness=0; signedness<=M88K_LOADSTORE_SIGNEDNESS;
212  signedness+=M88K_LOADSTORE_SIGNEDNESS)
213  for (store=0; store<=M88K_LOADSTORE_STORE;
214  store+=M88K_LOADSTORE_STORE)
215  for (size=0; size<=3; size++) {
216  if (store || size || signedness || endianness
217  || scaledness || usr || registeroffset)
218  printf(",\n");
219 
220  if (store && signedness) {
221  printf("\tNULL");
222  continue;
223  }
224 
225  if (!registeroffset && usr) {
226  printf("\tNULL");
227  continue;
228  }
229 
230  if (!registeroffset && scaledness) {
231  printf("\tNULL");
232  continue;
233  }
234 
235  if (size == 0 && scaledness) {
236  printf("\tNULL");
237  continue;
238  }
239 
240  printf("\tm88k_instr_");
241  print_function_name(size, store, signedness,
242  endianness, scaledness, usr, registeroffset);
243  }
244  printf(" };\n");
245 
246  fprintf(stderr, "%s: generated_functions = %i\n",
247  argv[0], generated_functions);
248 
249  return 0;
250 }
251 
generated_functions
int generated_functions
Definition: generate_m88k_loadstore.c:52
loadstore
void loadstore(int size, int store, int signedness, int endianness, int scaledness, int usr, int registeroffset)
Definition: generate_m88k_loadstore.c:87
M88K_LOADSTORE_ENDIANNESS
#define M88K_LOADSTORE_ENDIANNESS
Definition: generate_m88k_loadstore.c:46
M88K_LOADSTORE_STORE
#define M88K_LOADSTORE_STORE
Definition: generate_m88k_loadstore.c:44
print_function_name
void print_function_name(int size, int store, int signedness, int endianness, int scaledness, int usr, int registeroffset)
Definition: generate_m88k_loadstore.c:55
M88K_LOADSTORE_SIGNEDNESS
#define M88K_LOADSTORE_SIGNEDNESS
Definition: generate_m88k_loadstore.c:45
M88K_LOADSTORE_REGISTEROFFSET
#define M88K_LOADSTORE_REGISTEROFFSET
Definition: generate_m88k_loadstore.c:49
M88K_LOADSTORE_SCALEDNESS
#define M88K_LOADSTORE_SCALEDNESS
Definition: generate_m88k_loadstore.c:47
main
int main(int argc, char *argv[])
Definition: generate_m88k_loadstore.c:179
M88K_LOADSTORE_USR
#define M88K_LOADSTORE_USR
Definition: generate_m88k_loadstore.c:48

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18