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