1 #ifndef AROS_X86_64_GENMODULE_H
2 #define AROS_X86_64_GENMODULE_H
5 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
8 Desc: genmodule specific definitions for x86_64
12 #include <exec/execbase.h>
14 /* Macros for generating library stub functions and aliases for stack libcalls. */
16 /* Macro: AROS_LIBFUNCSTUB(functionname, libbasename, lvo)
17 This macro will generate code for a stub function for
18 the function 'functionname' of library with libbase
19 'libbasename' and 'lvo' number of the function in the
20 vector table. lvo has to be a constant value (not a variable)
22 Internals: a dummy function is used that will generate some
23 unused junk code but otherwise we can't pass input arguments
26 #define __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
27 void __ ## fname ## _ ## libbasename ## _wrapper(void) \
30 ".weak " #fname "\n" \
32 "\tmovq " #libbasename "(%%rip), %%r11\n" \
33 "\tjmp *%c0(%%r11)\n" \
34 : : "i" ((-lvo)*LIB_VECTSIZE) \
37 #define AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
38 __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo)
40 /* Macro: AROS_GM_RELLIBFUNCSTUB(functionname, libbasename, lvo)
41 Same as AROS_GM_LIBFUNCSTUB but finds libbase at an offset in
44 #define __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
45 void __ ## fname ## _ ## libbasename ## _relwrapper(void) \
48 ".weak " #fname "\n" \
57 "\tcall __aros_getoffsettable\n" \
58 "\taddq __aros_rellib_offset_" #libbasename "(%%rip), %%rax\n" \
59 "\tmovq (%%rax),%%r11\n" \
67 "\tjmp *%c0(%%r11)\n" \
68 : : "i" ((-lvo)*LIB_VECTSIZE) \
71 #define AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
72 __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo)
74 /* Macro: AROS_GM_LIBFUNCALIAS(functionname, alias)
75 This macro will generate an alias 'alias' for function
78 #define __AROS_GM_LIBFUNCALIAS(fname, alias) \
79 asm(".weak " #alias "\n" \
80 "\t.set " #alias "," #fname \
82 #define AROS_GM_LIBFUNCALIAS(fname, alias) \
83 __AROS_GM_LIBFUNCALIAS(fname, alias)
85 /******************* Library Side Thunks ******************/
87 /* This macro relies upon the fact that the
88 * caller to a stack function will have passed in
89 * the base in %r11, since the caller will
90 * have used the AROS_LIBFUNCSTUB() macro.
93 #define __GM_STRINGIZE(x) #x
94 #define __AROS_GM_STACKCALL(fname, libbasename, libfuncname) \
95 void libfuncname(void); \
96 void __ ## fname ## _stackcall(void) \
99 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
107 "\tmovq %%r11,%%rdi\n" \
108 "\tcall __aros_setoffsettable\n" \
116 "\tjmp " #fname "\n" \
121 #define AROS_GM_STACKCALL(fname, libbasename, lvo) \
122 __AROS_GM_STACKCALL(fname, libbasename, AROS_SLIB_ENTRY(fname, libbasename, lvo))
124 /* Macro: AROS_GM_STACKALIAS(functionname, libbasename, lvo)
125 This macro will generate an alias 'alias' for function
128 #define __AROS_GM_STACKALIAS(fname, alias) \
130 asm(".weak " __GM_STRINGIZE(alias) "\n" \
131 "\t.set " __GM_STRINGIZE(alias) "," #fname \
133 #define AROS_GM_STACKALIAS(fname, libbasename, lvo) \
134 __AROS_GM_STACKALIAS(fname, AROS_SLIB_ENTRY(fname, libbasename, lvo))
137 #endif /* AROS_X86_64_GENMODULE_H */