revert between 56095 -> 55830 in arch
[AROS.git] / arch / i386-all / include / gencall.c
blob629859b05ee208645528064a066a7f3c5ffa3bb1
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 /*
6 * This program generates the libcall.h macroset for gcc
7 */
9 #include <stdio.h>
10 #include <string.h>
12 #define GENCALL_MAX (13 + 1) /* Max number of arguments */
14 void aros_lc(int id, const char *suffix)
16 int i;
18 printf("#define AROS_LC%d%s(t,n,", id, suffix);
19 for (i = 0; i < id; i++)
20 printf("a%d,", i + 1);
21 printf("bt,bn,o,s) \\\n"
22 "({ \\\n"
23 " bt __bn = (bt)bn; \\\n"
24 " ((__attribute__((regparm(1))) t (*)(bt"
26 for (i = 0; i < id; i++)
28 printf(", __AROS_LDA(a%d)", i+1);
30 printf("))__AROS_GETVECADDR(__bn,o))(__bn");
31 for (i = 0; i < id; i++)
33 printf(", __AROS_LCA(a%d)", i+1);
35 printf("); \\\n"
36 "})\n"
40 void aros_call(int id, const char *suffix)
42 int i;
44 printf("#define AROS_CALL%d%s(t,n,", id, suffix);
45 for (i = 0; i < id; i++)
46 printf("a%d,", i + 1);
47 printf("bt,bn) \\\n"
48 "({ \\\n"
49 " bt __bn = (bt)bn; \\\n"
50 /* Need to first assign to variable otherwise gcc may miscompile */
51 " APTR __func = (APTR)n; \\\n"
52 " ((__attribute__((regparm(1))) t (*)(bt"
54 for (i = 0; i < id; i++)
56 printf(", __AROS_LDA(a%d)", i+1);
58 printf("))(APTR)__func)(__bn");
59 for (i = 0; i < id; i++)
61 printf(", __AROS_LCA(a%d)", i+1);
63 printf("); \\\n"
64 "})\n"
68 void aros_lh(int id, int is_ignored)
70 int i;
72 printf("#define AROS_LH%d%s(t,n,", id, is_ignored ? "I" : "");
73 for (i = 0; i < id; i++)
74 printf("a%d,", i + 1);
75 printf("bt,bn,o,s) \\\n");
77 if (!is_ignored)
79 printf(" __attribute__((regparm(1))) t AROS_SLIB_ENTRY(n,s,o) (bt bn");
80 for (i = 0; i < id; i++)
82 printf(", __AROS_LHA(a%d)", i + 1);
84 printf(") \\\n"
85 " {(void)bn;\n\n"
88 else
90 printf(" t AROS_SLIB_ENTRY(n,s,o) (");
91 if (i == 0)
92 printf("void");
93 for (i = 0; i < id; i++)
95 if (i > 0)
96 printf(", ");
97 printf("__AROS_LHA(a%d)", i + 1);
99 printf(") \\\n"
100 " {\n\n"
105 static void aros_ld(int id, int is_ignored)
107 int i;
109 printf("#define AROS_LD%d%s(t,n,", id, is_ignored ? "I" : "");
110 for (i = 0; i < id; i++)
111 printf("a%d,", i + 1);
112 printf("bt,bn,o,s) \\\n");
113 if (!is_ignored)
115 printf(" __attribute__((regparm(1))) t AROS_SLIB_ENTRY(n,s,o) (bt bn");
116 for (i = 0; i < id; i++)
118 printf(", __AROS_LDA(a%d)", i + 1);
121 else
123 printf(" t AROS_SLIB_ENTRY(n,s,o) (");
124 if (i == 0)
125 printf("void");
126 for (i = 0; i < id; i++)
128 if (i > 0)
129 printf(", ");
130 printf("__AROS_LDA(a%d)", i + 1);
133 printf(");\n");
136 const static char extra[] =
137 "\n"
138 "#define __AROS_QUADt(type,name,reg1,reg2) type\n"
139 "#define __AROS_QUADn(type,name,reg1,reg2) name\n"
140 "#define __AROS_QUADr(type,name,reg1,reg2) reg1##reg2\n"
141 "\n"
142 "#define AROS_LHQUAD1(t,n,a1,bt,bn,o,s) \\\n"
143 " AROS_LH1(t,n, \\\n"
144 " AROS_LHA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
145 " bt, bn, o, s \\\n"
146 " )\n"
147 "#define AROS_LHQUAD2(t,n,a1,a2,bt,bn,o,s) \\\n"
148 " AROS_LH2(t,n, \\\n"
149 " AROS_LHA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
150 " AROS_LHA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
151 " bt, bn, o, s \\\n"
152 " )\n"
153 "#define AROS_LH1QUAD1(t,n,a1,a2,bt,bn,o,s) \\\n"
154 " AROS_LH2(t,n, \\\n"
155 " AROS_LHA(a1), \\\n"
156 " AROS_LHA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
157 " bt, bn, o, s \\\n"
158 " )\n"
159 "#define AROS_LH2QUAD1(t,n,a1,a2,a3,bt,bn,o,s) \\\n"
160 " AROS_LH3(t,n, \\\n"
161 " AROS_LHA(a1), \\\n"
162 " AROS_LHA(a2), \\\n"
163 " AROS_LHA(__AROS_QUADt(a3), __AROS_QUADn(a3), __AROS_QUADr(a3)), \\\n"
164 " bt, bn, o, s \\\n"
165 " )\n"
166 "#define AROS_LH3QUAD1(t,n,a1,a2,a3,a4,bt,bn,o,s) \\\n"
167 " AROS_LH4(t,n, \\\n"
168 " AROS_LHA(a1), \\\n"
169 " AROS_LHA(a2), \\\n"
170 " AROS_LHA(a3), \\\n"
171 " AROS_LHA(__AROS_QUADt(a4), __AROS_QUADn(a4), __AROS_QUADr(a4)), \\\n"
172 " bt, bn, o, s \\\n"
173 " )\n"
174 "\n"
175 "\n"
176 "#define AROS_LCQUAD1(t,n,a1,bt,bn,o,s) \\\n"
177 " AROS_LC1(t,n, \\\n"
178 " AROS_LCA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
179 " bt, bn, o, s \\\n"
180 " )\n"
181 "#define AROS_LCQUAD2(t,n,a1,a2,bt,bn,o,s) \\\n"
182 " AROS_LC2(t,n, \\\n"
183 " AROS_LCA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
184 " AROS_LCA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
185 " bt, bn, o, s \\\n"
186 " )\n"
187 "#define AROS_LC1QUAD1(t,n,a1,a2,bt,bn,o,s) \\\n"
188 " AROS_LC2(t,n, \\\n"
189 " AROS_LCA(a1), \\\n"
190 " AROS_LCA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
191 " bt, bn, o, s \\\n"
192 " )\n"
193 "#define AROS_LC2QUAD1(t,n,a1,a2,a3,bt,bn,o,s) \\\n"
194 " AROS_LC3(t,n, \\\n"
195 " AROS_LCA(a1), \\\n"
196 " AROS_LCA(a2), \\\n"
197 " AROS_LCA(__AROS_QUADt(a3), __AROS_QUADn(a3), __AROS_QUADr(a3)), \\\n"
198 " bt, bn, o, s \\\n"
199 " )\n"
200 "#define AROS_LC3QUAD1(t,n,a1,a2,a3,a4,bt,bn,o,s) \\\n"
201 " AROS_LC4(t,n, \\\n"
202 " AROS_LCA(a1), \\\n"
203 " AROS_LCA(a2), \\\n"
204 " AROS_LCA(a3), \\\n"
205 " AROS_LCA(__AROS_QUADt(a4), __AROS_QUADn(a4), __AROS_QUADr(a4)), \\\n"
206 " bt, bn, o, s \\\n"
207 " )\n"
208 "\n"
209 "#define AROS_LDQUAD1(t,n,a1,bt,bn,o,s) \\\n"
210 " AROS_LD1(t,n, \\\n"
211 " AROS_LDA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
212 " bt, bn, o, s \\\n"
213 " )\n"
214 "#define AROS_LDQUAD2(t,n,a1,a2,bt,bn,o,s) \\\n"
215 " AROS_LD2(t,n, \\\n"
216 " AROS_LDA(__AROS_QUADt(a1), __AROS_QUADn(a1), __AROS_QUADr(a1)), \\\n"
217 " AROS_LDA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
218 " bt, bn, o, s \\\n"
219 " )\n"
220 "#define AROS_LD1QUAD1(t,n,a1,a2,bt,bn,o,s) \\\n"
221 " AROS_LD2(t,n, \\\n"
222 " AROS_LDA(a1), \\\n"
223 " AROS_LDA(__AROS_QUADt(a2), __AROS_QUADn(a2), __AROS_QUADr(a2)), \\\n"
224 " bt, bn, o, s \\\n"
225 " )\n"
226 "#define AROS_LD2QUAD1(t,n,a1,a2,a3,bt,bn,o,s) \\\n"
227 " AROS_LD3(t,n, \\\n"
228 " AROS_LDA(a1), \\\n"
229 " AROS_LDA(a2), \\\n"
230 " AROS_LDA(__AROS_QUADt(a3), __AROS_QUADn(a3), __AROS_QUADr(a3)), \\\n"
231 " bt, bn, o, s \\\n"
232 " )\n"
233 "#define AROS_LD3QUAD1(t,n,a1,a2,a3,a4,bt,bn,o,s) \\\n"
234 " AROS_LD4(t,n, \\\n"
235 " AROS_LDA(a1), \\\n"
236 " AROS_LDA(a2), \\\n"
237 " AROS_LDA(a3), \\\n"
238 " AROS_LDA(__AROS_QUADt(a4), __AROS_QUADn(a4), __AROS_QUADr(a4)), \\\n"
239 " bt, bn, o, s \\\n"
240 " )\n"
241 "\n";
243 int main(int argc, char **argv)
245 int i;
247 printf("/* AUTOGENERATED by arch/i386-all/include/gencall.c */\n");
248 printf("\n");
249 printf("#ifndef AROS_I386_LIBCALL_H\n");
250 printf("#define AROS_I386_LIBCALL_H\n");
251 printf("\n");
253 printf("#define __AROS_CPU_SPECIFIC_LH\n\n");
255 for (i = 0; i < GENCALL_MAX; i++)
256 aros_lh(i, 0);
258 for (i = 0; i < GENCALL_MAX; i++)
259 aros_lh(i, 1);
261 printf("\n");
262 printf("#define __AROS_CPU_SPECIFIC_LC\n\n");
264 for (i = 0; i < GENCALL_MAX; i++)
265 aros_lc(i, "");
267 for (i = 0; i < GENCALL_MAX; i++)
268 aros_lc(i, "NR");
270 for (i = 0; i < GENCALL_MAX; i++)
271 aros_call(i, "");
273 for (i = 0; i < GENCALL_MAX; i++)
274 aros_call(i, "NR");
276 printf("\n");
277 printf("#define __AROS_CPU_SPECIFIC_LD\n\n");
279 for (i = 0; i < GENCALL_MAX; i++)
280 aros_ld(i, 0);
282 for (i = 0; i < GENCALL_MAX; i++)
283 aros_ld(i, 1);
285 printf("%s\n", extra);
287 printf("#endif /* AROS_I386_LIBCALL_H */\n");
288 return 0;