generate_mips_loadstore.c Source File

Back to the index.

generate_mips_loadstore.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-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 void print_function_name(int store, int size, int signedness, int endianness)
33 {
34  if (store)
35  printf("s");
36  else {
37  printf("l");
38  if (!signedness)
39  printf("u");
40  }
41  printf("%i", 1 << size);
42 
43  if (endianness >= 0) {
44  /* Special case so that Byte loads/stores are only
45  included ones (for little endian): */
46  if (size == 0 && endianness)
47  printf("_le");
48  else
49  printf(endianness? "_be" : "_le");
50  }
51 }
52 
53 
54 void loadstore(int mode32, int store, int size, int signedness, int endianness)
55 {
56  if (store && signedness)
57  return;
58 
59  if (size == 0 && endianness)
60  return;
61 
62  printf("#if%sdef MODE32\n", mode32? "" : "n");
63 
64  if (store)
65  printf("#define LS_STORE\n");
66  else
67  printf("#define LS_LOAD\n");
68 
69  printf("#define LS_N mips%s_instr_", mode32? "32" : "");
70  print_function_name(store, size, signedness, endianness);
71  printf("\n");
72 
73  printf("#define LS_GENERIC_N mips%s_generic_", mode32? "32" : "");
74  print_function_name(store, size, signedness, -1);
75  printf("\n");
76 
77  printf("#define LS_%i\n", 1 << size);
78  printf("#define LS_SIZE %i\n", 1 << size);
79 
80  if (signedness && !store)
81  printf("#define LS_SIGNED\n");
82 
83  if (endianness)
84  printf("#define LS_BE\n");
85  else
86  printf("#define LS_LE\n");
87 
88  if (endianness == 0)
89  printf("#define LS_INCLUDE_GENERIC\n");
90 
91  printf("#include \"cpu_mips_instr_loadstore.cc\"\n");
92 
93  if (endianness == 0)
94  printf("#undef LS_INCLUDE_GENERIC\n");
95 
96  if (endianness)
97  printf("#undef LS_BE\n");
98  else
99  printf("#undef LS_LE\n");
100 
101  if (signedness && !store)
102  printf("#undef LS_SIGNED\n");
103 
104  printf("#undef LS_SIZE\n");
105  printf("#undef LS_%i\n", 1 << size);
106 
107  printf("#undef LS_GENERIC_N\n");
108  printf("#undef LS_N\n");
109 
110  if (store)
111  printf("#undef LS_STORE\n");
112  else
113  printf("#undef LS_LOAD\n");
114 
115  printf("#endif\n");
116 }
117 
118 
119 int main(int argc, char *argv[])
120 {
121  int store, mode32, size, signedness, endianness;
122 
123  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
124 
125  for (mode32=0; mode32<=1; mode32++)
126  for (endianness=0; endianness<=1; endianness++)
127  for (store=0; store<=1; store++)
128  for (size=0; size<=3; size++)
129  for (signedness=0; signedness<=1; signedness++)
130  loadstore(mode32, store, size, signedness,
131  endianness);
132 
133  /* Array of pointers to fast load/store functions: */
134  for (mode32=0; mode32<=1; mode32++) {
135  printf("#if%sdef MODE32\n", mode32? "" : "n");
136  printf("\n\nvoid (*mips%s_loadstore[32])(struct cpu *, struct "
137  "mips_instr_call *) = {\n", mode32? "32" : "");
138  for (endianness=0; endianness<=1; endianness++)
139  for (store=0; store<=1; store++)
140  for (size=0; size<=3; size++)
141  for (signedness=0; signedness<=1; signedness++) {
142  if (store || size || signedness || endianness)
143  printf(",\n");
144 
145  if (store && signedness) {
146  printf("\tmips%s_instr_invalid",
147  mode32? "32" : "");
148  continue;
149  }
150 
151  printf("\tmips%s_instr_", mode32? "32" : "");
152  print_function_name(store, size, signedness,
153  endianness);
154  }
155  printf(" };\n");
156  printf("#endif\n");
157  }
158 
159  /* Array of pointers to the generic functions: */
160  for (mode32=0; mode32<=1; mode32++) {
161  printf("#if%sdef MODE32\n", mode32? "" : "n");
162  printf("\n\nvoid (*mips%s_loadstore_generic[16])("
163  "struct cpu *, struct mips_instr_call *) = {\n",
164  mode32? "32" : "");
165  for (store=0; store<=1; store++)
166  for (size=0; size<=3; size++)
167  for (signedness=0; signedness<=1; signedness++) {
168  if (store || size || signedness)
169  printf(",\n");
170 
171  if (store && signedness) {
172  printf("\tmips%s_instr_invalid",
173  mode32? "32" : "");
174  continue;
175  }
176 
177  printf("\tmips%s_generic_", mode32? "32" : "");
178  print_function_name(store, size, signedness,
179  -1);
180  }
181  printf(" };\n");
182  printf("#endif\n");
183  }
184 
185  return 0;
186 }
187 
loadstore
void loadstore(int mode32, int store, int size, int signedness, int endianness)
Definition: generate_mips_loadstore.c:54
print_function_name
void print_function_name(int store, int size, int signedness, int endianness)
Definition: generate_mips_loadstore.c:32
main
int main(int argc, char *argv[])
Definition: generate_mips_loadstore.c:119

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17