arch/m68k-all/include/gencall: Proper regcall stubs
[AROS.git] / arch / m68k-all / include / gencall.c
blob4b65ab09fc6239efe2c20b634d047113a2c2d3a9
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 /* This program generates the libcall.h macroset for gcc-4.5.1 m68k-elf
7 * WARNING: The header generated by this program is designed
8 * to work with GCC 4.5.1 m68k-elf ONLY, and even
9 * then it has only been very lightly tested with
10 * "-O2 -fomit-frame-pointer -ffixed-a6"
12 * If it breaks, you get to keep both pieces.
15 #include <stdio.h>
17 #define GENCALL_MAX (13 + 1) /* Max number of arguments */
19 /* NOTE: For all 'call' macros, ie AROS_LC5(), the
20 * 'bt' parameter is frequently garbled by
21 * callers who use '#define's like:
23 * #define UtilityBase mydata->utilitybase
25 * this makes a 'bt' parameter of 'struct UtilityBase *'
26 * turn into 'struct mydata->utilitybase *'.
28 * Unhappiness ensues. So, we must use 'void *'
29 * for all 'bt' arguments in the call macros.
31 void aros_ufp(int id, int is_static)
33 int i;
35 printf("#define AROS_UFP%d%s(t,n", id, is_static ? "S" : "");
36 for (i = 0; i < id; i++)
37 printf(",a%d", i + 1);
38 printf(") \\\n");
39 printf("\t%st n (void)\n", is_static ? "static " : "");
42 void aros_ufh(int id, int is_static)
44 int i;
46 printf("#define AROS_UFH%d%s(t,n", id, is_static ? "S" : "");
47 for (i = 0; i < id; i++)
48 printf(",a%d", i + 1);
49 printf(") \\\n");
50 printf("\t%st n (void) {%s\n", is_static ? "static " : "", (i==0) ? "" : " \\");
51 for (i = 0; i < id; i++)
52 printf("\tregister __AROS_UFPA(a%d) __AROS_UFTA(a%d) asm(__AROS_UFSA(a%d)); \\\n", i+1, i+1, i+1);
53 for (i = 0; i < id; i++)
54 printf("\t__AROS_UFPA(a%d) __attribute__((unused)) __AROS_UFCA(a%d) = __AROS_UFTA(a%d);%s\n", i+1, i+1, i+1, (i == (id-1)) ? "" : " \\");
57 static void aros_ufc(int id)
59 int i;
60 printf("#define AROS_UFC%d(t,n", id);
61 for (i = 0; i < id; i++)
62 printf(",a%d", i + 1);
63 printf(") \\\n");
64 printf("\t({ volatile register ULONG _ret asm(\"%%d0\"); \\\n");
65 for (i = 0; i < id; i++) {
66 printf("\t volatile register ULONG __AROS_LTA(a%d) asm(__AROS_LSA(a%d)) = (ULONG)__AROS_LCA(a%d); \\\n",
67 i + 1, i + 1, i + 1);
69 printf("\t asm volatile ( \\\n");
70 printf("\t\t\"pea.l ufc%d_%%c1\\n\" \\\n", id);
71 printf("\t\t\"move.l %%0, %%%%sp@-\\n\" \\\n");
72 printf("\t\t: : \\\n");
73 printf("\t\t \"g\" (n), \"i\" (__LINE__) \\\n");
74 for (i = 0; i < id; i++)
75 printf("\t\t, \"r\" (__AROS_LTA(a%d)) \\\n", i + 1);
76 printf("\t\t); \\\n");
77 printf("\t asm volatile (\"rts\\nufc%d_%%c0:\\n\" : : \"i\" (__LINE__) : ); \\\n", id);
78 printf("\t asm volatile (\"\" : \"=r\" (_ret) : : \"%%a0\", \"%%a1\", \"%%d1\", \"cc\", \"memory\"); \\\n");
79 printf("\t (t)_ret;})\n\n");
82 void aros_lc(int id)
84 int i;
85 printf("#define AROS_LC%d(t,n,", id);
86 for (i = 0; i < id; i++)
87 printf("a%d,", i + 1);
88 printf("bt,bn,o,s) \\\n");
89 printf("\t({ volatile register ULONG _ret asm(\"%%d0\"); \\\n");
90 for (i = 0; i < id; i++) {
91 printf("\t volatile register ULONG __AROS_LTA(a%d) asm(__AROS_LSA(a%d)) = (ULONG)__AROS_LCA(a%d); \\\n",
92 i + 1, i + 1, i + 1);
94 printf("\t volatile register ULONG _bn asm(\"%%a6\") = (ULONG)bn; \\\n");
95 printf("\t asm volatile ( \\\n");
96 printf("\t\t\"jsr %%c0(%%%%a6)\" \\\n");
97 printf("\t\t: : \\\n");
98 printf("\t\t \"i\" (-1 * (o) * LIB_VECTSIZE) \\\n");
99 for (i = 0; i < id; i++)
100 printf("\t\t, \"r\" (__AROS_LTA(a%d)) \\\n", i + 1);
101 printf("\t\t, \"r\" (_bn)); \\\n");
102 printf("\t asm volatile (\"\" : \"=r\" (_ret) : : \"%%a0\", \"%%a1\", \"%%d1\", \"cc\", \"memory\"); \\\n");
103 printf("\t (t)_ret;})\n\n");
106 void aros_lh(int id, int is_ignored)
108 int i;
110 printf("#define AROS_LH%d%s(t,n,", id, is_ignored ? "I" : "");
111 for (i = 0; i < id; i++)
112 printf("a%d,", i + 1);
113 printf("bt,bn,o,s) \\\n");
114 printf("\tt AROS_SLIB_ENTRY(n,s) (void) {");
115 for (i = 0; i < id; i++)
116 printf(" \\\n\t__AROS_LPA(a%d) __attribute__((unused)) __AROS_LCA(a%d) = ({register ULONG __r asm(__AROS_LSA(a%d));(__AROS_LPA(a%d))__r;});", i+1, i+1, i+1, i+1);
117 if (!is_ignored)
118 printf(" \\\n\tregister bt __attribute__((unused)) bn = ({register ULONG __r asm(\"%%a6\");(bt)__r;});");
119 printf("\n");
122 static void aros_lcnr(int id)
124 printf("#define AROS_LC%dNR AROS_LC%d\n", id, id);
127 static void aros_call(int id)
129 int i;
130 printf("#define AROS_CALL%d(t,n,", id);
131 for (i = 0; i < id; i++)
132 printf("a%d,", i + 1);
133 printf("bt,bn) \\\n");
134 printf("\tAROS_UFC%d(t,n", id + 1);
135 for (i = 0; i < id; i++) {
136 printf(",AROS_UFCA(a%d)", i + 1);
138 printf(",AROS_UFCA(bt,bn,A6))\n");
141 static void aros_callnr(int id)
143 printf("#define AROS_CALL%dNR AROS_CALL%d\n", id, id);
146 static void aros_lvo_call(int id)
148 int i;
149 printf("#define AROS_LVO_CALL%d(t,", id);
150 for (i = 0; i < id; i++)
151 printf("a%d,", i + 1);
152 printf("bt,bn,o,s) \\\n");
153 printf("\tAROS_CALL%d(t,__AROS_GETVECADDR(bn,o), \\\n", id);
154 for (i = 0; i < id; i++)
155 printf("\t\tAROS_LCA(a%d), \\\n", i + 1);
156 printf("\t\tbt,bn)\n");
159 static void aros_lvo_callnr(int id)
161 int i;
162 printf("#define AROS_LVO_CALL%dNR(t,", id);
163 for (i = 0; i < id; i++)
164 printf("a%d,", i + 1);
165 printf("bt,bn,o,s) \\\n");
166 printf("\tAROS_CALL%dNR(t,__AROS_GETVECADDR(bn,o), \\\n", id);
167 for (i = 0; i < id; i++)
168 printf("\t\tAROS_LCA(a%d), \\\n", i + 1);
169 printf("\t\tbt,bn)\n");
172 static void aros_ld(int id, int is_ignored)
174 int i;
176 printf("#define AROS_LD%d%s(t,n,", id, is_ignored ? "I" : "");
177 for (i = 0; i < id; i++)
178 printf("a%d,", i + 1);
179 printf("bt,bn,o,s) \\\n");
180 printf("\t__AROS_LD_PREFIX t AROS_SLIB_ENTRY(n,s) (void)\n");
183 int main(int argc, char **argv)
185 int i;
187 printf("/* AUTOGENERATED by arch/m68k-all/include/gencall.c */\n");
188 printf("/* If you can get this to work for anything other */\n");
189 printf("/* than gcc-4.5.1 m68k-elf, it would be surprising. */\n");
190 printf("\n");
191 printf("#ifndef AROS_M68K_LIBCALL_H\n");
192 printf("#define AROS_M68K_LIBCALL_H\n");
193 printf("\n");
194 printf("/* Call a libary function which requires the libbase */\n");
195 printf("\n");
196 printf("#define __AROS_CPU_SPECIFIC_ASMCALLS\n\n");
198 for (i = 0; i < GENCALL_MAX; i++)
199 aros_ufp(i, 0);
201 for (i = 0; i < GENCALL_MAX; i++)
202 aros_ufp(i, 1);
204 for (i = 0; i < GENCALL_MAX; i++)
205 aros_ufh(i, 0);
207 for (i = 0; i < GENCALL_MAX; i++)
208 aros_ufh(i, 1);
210 for (i = 0; i < GENCALL_MAX; i++)
211 aros_ufc(i);
213 printf("#define __AROS_CPU_SPECIFIC_LH\n\n");
215 for (i = 0; i < GENCALL_MAX; i++)
216 aros_lh(i, 0);
218 for (i = 0; i < GENCALL_MAX; i++)
219 aros_lh(i, 1);
221 printf("\n");
222 printf("#define __AROS_CPU_SPECIFIC_LC\n\n");
224 for (i = 0; i < GENCALL_MAX; i++)
225 aros_lc(i);
227 for (i = 0; i < GENCALL_MAX; i++)
228 aros_lcnr(i);
230 for (i = 0; i < GENCALL_MAX; i++)
231 aros_call(i);
233 for (i = 0; i < GENCALL_MAX; i++)
234 aros_callnr(i);
236 for (i = 0; i < GENCALL_MAX; i++)
237 aros_lvo_call(i);
239 for (i = 0; i < GENCALL_MAX; i++)
240 aros_lvo_callnr(i);
242 printf("\n");
243 printf("#define __AROS_CPU_SPECIFIC_LD\n\n");
245 for (i = 0; i < GENCALL_MAX; i++)
246 aros_ld(i, 0);
248 for (i = 0; i < GENCALL_MAX; i++)
249 aros_ld(i, 1);
251 printf("#endif /* AROS_M68K_LIBCALL_H */\n");
252 return 0;