2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: genmodule.h include file for arm-le systems
9 #ifndef AROS_ARM_GENMODULE_H
10 #define AROS_ARM_GENMODULE_H
12 #include <exec/execbase.h>
14 /* Macros for generating library stub functions and aliases for stack libcalls. */
16 /******************* Linklib Side Thunks ******************/
18 /* Macro: AROS_GM_LIBFUNCSTUB(functionname, libbasename, lvo)
19 This macro will generate code for a stub function for
20 the function 'functionname' of lirary with libbase
21 'libbasename' and 'lvo' number of the function in the
22 vector table. lvo has to be a constant value (not a variable)
24 #define __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
25 void __ ## fname ## _ ## libbasename ## _wrapper(void) \
28 ".weak " #fname "\n" \
29 ".type " #fname ", %%function\n" \
33 "\tldr r12, [r12]\n" \
34 /* Compute function address and jump */ \
35 "\tldr pc, [r12, #%c0]\n" \
37 "1: .word " #libbasename "\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(IPTR args) \
52 ".weak " #fname "\n" \
53 ".type " #fname ", %%function\n" \
55 /* return address is in lr register */ \
56 /* Up to four parameters are in r0 - r3 , the rest are on stack */ \
57 "\tpush {r0, r1, r2, r3, lr}\n" \
58 /* r0 = __aros_getoffsettable() */ \
59 "\tbl __aros_getoffsettable\n" \
63 "\tldr r12, [r0, r1]\n" \
64 /* Restore original arguments */ \
65 "\tpop {r0, r1, r2, r3, lr}\n" \
66 /* Compute function address and jump */ \
67 "\tldr pc, [r12, #%c0]\n" \
68 "1: .word __aros_rellib_offset_" #libbasename "\n" \
69 "2: .word __aros_getoffsettable\n" \
70 : : "i" ((-lvo*LIB_VECTSIZE)) \
73 #define AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
74 __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo)
76 /* Macro: AROS_GM_LIBFUNCALIAS(functionname, alias)
77 This macro will generate an alias 'alias' for function
80 #define __AROS_GM_LIBFUNCALIAS(fname, alias) \
81 asm(".weak " #alias "\n" \
82 "\t.set " #alias "," #fname \
84 #define AROS_GM_LIBFUNCALIAS(fname, alias) \
85 __AROS_GM_LIBFUNCALIAS(fname, alias)
87 /******************* Library Side Thunks ******************/
89 /* This macro relies upon the fact that the
90 * caller to a stack function will have passed in
91 * the base in %r12, since the caller will
92 * have used the AROS_LIBFUNCSTUB() macro.
94 #define __GM_STRINGIZE(x) #x
95 #define __AROS_GM_STACKCALL(fname, libbasename, libfuncname) \
96 void libfuncname(void); \
97 void __ ## fname ## _stackcall(void) \
100 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
101 /* Up to four parameters are in r0 - r3 , the rest are on stack */ \
102 "\tpush {r0, r1, r2, r3, lr}\n" \
104 "\tbl __aros_setoffsettable\n" \
105 "\tpop {r0, r1, r2, r3, lr}\n" \
110 #define AROS_GM_STACKCALL(fname, libbasename, lvo) \
111 __AROS_GM_STACKCALL(fname, libbasename, AROS_SLIB_ENTRY(fname, libbasename, lvo))
113 /* Macro: AROS_GM_STACKALIAS(functionname, libbasename, lvo)
114 This macro will generate an alias 'alias' for function
117 #define __AROS_GM_STACKALIAS(fname, alias) \
119 asm(".weak " __GM_STRINGIZE(alias) "\n" \
120 "\t.set " __GM_STRINGIZE(alias) "," #fname \
122 #define AROS_GM_STACKALIAS(fname, libbasename, lvo) \
123 __AROS_GM_STACKALIAS(fname, AROS_SLIB_ENTRY(fname, libbasename, lvo))
125 #endif /* AROS_ARM_GENMODULE_H */