1 #ifndef AROS_PPC_GENMODULE_H
2 #define AROS_PPC_GENMODULE_H
4 Copyright © 2012-2017, The AROS Development Team. All rights reserved.
7 NOTE: This file must compile *without* any other header !
9 Desc: genmodule.h include file for powerpc arch
13 #include <exec/execbase.h>
15 /* Macros for generating library stub functions and aliases for stack libcalls. */
17 /* Macro: AROS_LIBFUNCSTUB(functionname, libbasename, lvo)
18 This macro will generate code for a stub function for
19 the function 'functionname' of lirary with libbase
20 'libbasename' and 'lvo' number of the function in the
21 vector table. lvo has to be a constant value (not a variable)
23 Internals: a dummy function is used that will generate some
24 unused junk code but otherwise we can't pass input arguments
27 #define __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
28 void __ ## fname ## _ ## libbasename ## _wrapper(void) \
31 ".weak " #fname "\n" \
33 "\tlis %%r12," #libbasename "@ha\n" \
34 "\tlwz %%r12," #libbasename "@l(%%r12)\n" \
35 "\tlwz %%r11,%c0(%%r12)\n" \
38 : : "i" ((-lvo*LIB_VECTSIZE)) \
41 #define AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
42 __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo)
44 /* Macro: AROS_GM_RELLIBFUNCSTUB(functionname, libbasename, lvo)
45 Same as AROS_GM_LIBFUNCSTUB but finds libbase at an offset in
48 #define __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
49 void __ ## fname ## _ ## libbasename ## _relwrapper(void) \
52 ".weak " #fname "\n" \
54 "\tstwu %%r1,-48(%%r1)\n" /* Previous stack frame */\
56 "\tstw %%r12,52(%%r1)\n" /* LR */\
57 "\tstw %%r3,8(%%r1)\n" /* Arg 1 */\
58 "\tstw %%r4,12(%%r1)\n" /* Arg 2 */\
59 "\tstw %%r5,16(%%r1)\n" /* Arg 3 */\
60 "\tstw %%r6,20(%%r1)\n" /* Arg 4 */\
61 "\tstw %%r7,24(%%r1)\n" /* Arg 5 */\
62 "\tstw %%r8,28(%%r1)\n" /* Arg 6 */\
63 "\tstw %%r9,32(%%r1)\n" /* Arg 7 */\
64 "\tstw %%r10,36(%%r1)\n" /* Arg 8 */\
65 "\tbl __aros_getoffsettable\n" /* base is in r3 */\
66 "\tlis %%r12,__aros_rellib_offset_" #libbasename "@ha\n" \
67 "\tlwz %%r12,__aros_rellib_offset_" #libbasename "@l(%%r12)\n" \
68 "\tlwzx %%r12, %%r12, %%r3\n" /* Offset of library in base */\
69 "\taddis %%r11,%%r12,%c0@ha\n" \
70 "\tlwz %%r11,%c0@l(%%r11)\n" /* Get LVO offset */\
71 "\tlwz %%r3,52(%%r1)\n" /* LR (r3) */\
72 "\tmtlr %%r3\n" /* Restore LR from r3 */\
73 "\tlwz %%r3,8(%%r1)\n" /* Arg 1 */\
74 "\tlwz %%r4,12(%%r1)\n" /* Arg 2 */\
75 "\tlwz %%r5,16(%%r1)\n" /* Arg 3 */\
76 "\tlwz %%r6,20(%%r1)\n" /* Arg 4 */\
77 "\tlwz %%r7,24(%%r1)\n" /* Arg 5 */\
78 "\tlwz %%r8,28(%%r1)\n" /* Arg 6 */\
79 "\tlwz %%r9,32(%%r1)\n" /* Arg 7 */\
80 "\tlwz %%r10,36(%%r1)\n" /* Arg 8 */\
81 "\taddi %%r1,%%r1,48\n" /* Destroy stack frame */\
82 "\tmtctr %%r11\n" /* r12 = base, r11 = lvo */\
84 : : "i" (-(lvo*LIB_VECTSIZE)) \
87 #define AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
88 __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo)
90 /* Macro: AROS_GM_LIBFUNCALIAS(functionname, alias)
91 This macro will generate an alias 'alias' for function
94 #define __AROS_GM_LIBFUNCALIAS(fname, alias) \
95 asm(".weak " #alias "\n" \
96 "\t.set " #alias "," #fname \
98 #define AROS_GM_LIBFUNCALIAS(fname, alias) \
99 __AROS_GM_LIBFUNCALIAS(fname, alias)
101 /******************* Library Side Thunks ******************/
103 /* This macro relies upon the fact that the
104 * caller to a stack function will have passed in
105 * the base in %r12, since the caller
106 * will have used the AROS_GM_LIBFUNCSTUB() macro.
108 #define __GM_STRINGIZE(x) #x
109 #define __AROS_GM_STACKCALL(fname, libbasename, libfuncname) \
110 void libfuncname(void); \
111 void __ ## fname ## _stackcall(void) \
114 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
115 "\tstwu %%r1,-48(%%r1)\n" /* Previous stack frame */\
117 "\tstw %%r11,52(%%r1)\n" /* LR */\
118 "\tstw %%r3,8(%%r1)\n" /* Arg 1 */\
119 "\tstw %%r4,12(%%r1)\n" /* Arg 2 */\
120 "\tstw %%r5,16(%%r1)\n" /* Arg 3 */\
121 "\tstw %%r6,20(%%r1)\n" /* Arg 4 */\
122 "\tstw %%r7,24(%%r1)\n" /* Arg 5 */\
123 "\tstw %%r8,28(%%r1)\n" /* Arg 6 */\
124 "\tstw %%r9,32(%%r1)\n" /* Arg 7 */\
125 "\tstw %%r10,36(%%r1)\n" /* Arg 8 */\
126 "\tstw %%r12,44(%%r1)\n" /* current r12 */\
127 "\tmr %%r3,%%r12\n" \
128 "\tbl __aros_setoffsettable\n" /* base is in r3 */\
129 "\tlwz %%r3,52(%%r1)\n" /* LR (r3) */\
130 "\tmtlr %%r3\n" /* Restore LR from r3 */\
131 "\tlwz %%r3,8(%%r1)\n" /* Arg 1 */\
132 "\tlwz %%r4,12(%%r1)\n" /* Arg 2 */\
133 "\tlwz %%r5,16(%%r1)\n" /* Arg 3 */\
134 "\tlwz %%r6,20(%%r1)\n" /* Arg 4 */\
135 "\tlwz %%r7,24(%%r1)\n" /* Arg 5 */\
136 "\tlwz %%r8,28(%%r1)\n" /* Arg 6 */\
137 "\tlwz %%r9,32(%%r1)\n" /* Arg 7 */\
138 "\tlwz %%r10,36(%%r1)\n" /* Arg 8 */\
139 "\tlwz %%r12,40(%%r1)\n" /* Restore r12 */\
140 "\taddi %%r1,%%r1,48\n" /* Destroy stack frame */\
146 #define AROS_GM_STACKCALL(fname, libbasename, lvo) \
147 __AROS_GM_STACKCALL(fname, libbasename, AROS_SLIB_ENTRY(fname, libbasename, lvo))
149 /* Macro: AROS_GM_STACKALIAS(functionname, libbasename, lvo)
150 This macro will generate an alias 'alias' for function
153 #define __AROS_GM_STACKALIAS(fname, alias) \
155 asm(".weak " __GM_STRINGIZE(alias) "\n" \
156 "\t.set " __GM_STRINGIZE(alias) "," #fname \
158 #define AROS_GM_STACKALIAS(fname, libbasename, lvo) \
159 __AROS_GM_STACKALIAS(fname, AROS_SLIB_ENTRY(fname, libbasename, lvo))
162 #endif /* AROS_PPC_GENMODULE_H */