1 #ifndef AROS_X86_64_GENMODULE_H
2 #define AROS_X86_64_GENMODULE_H
5 Copyright © 1995-2017, 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 "\tmovabsq $" #libbasename ", %%r11\n" \
33 "\tmovq (%%r11),%%r11\n" \
34 "\tjmp *%c0(%%r11)\n" \
35 : : "i" ((-lvo)*LIB_VECTSIZE) \
38 #define AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
39 __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo)
41 /* Macro: AROS_GM_RELLIBFUNCSTUB(functionname, libbasename, lvo)
42 Same as AROS_GM_LIBFUNCSTUB but finds libbase at an offset in
45 #define __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
46 void __ ## fname ## _ ## libbasename ## _relwrapper(void) \
49 ".weak " #fname "\n" \
58 "\tmovabsq $__aros_getoffsettable,%%r11\n" \
60 "\taddq __aros_rellib_offset_" #libbasename "(%%rip), %%rax\n" \
61 "\tmovq (%%rax),%%r11\n" \
69 "\tjmp *%c0(%%r11)\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 %r11, since the caller will
92 * have used the AROS_LIBFUNCSTUB() macro.
95 #define __GM_STRINGIZE(x) #x
96 #define __AROS_GM_STACKCALL(fname, libbasename, libfuncname) \
97 void libfuncname(void); \
98 void __ ## fname ## _stackcall(void) \
101 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
109 "\tmovq %%r11,%%rdi\n" \
110 "\tmovabsq $__aros_setoffsettable,%%r11\n" \
119 "\tmovabsq $" #fname ",%%r11\n" \
125 #define AROS_GM_STACKCALL(fname, libbasename, lvo) \
126 __AROS_GM_STACKCALL(fname, libbasename, AROS_SLIB_ENTRY(fname, libbasename, lvo))
128 /* Macro: AROS_GM_STACKALIAS(functionname, libbasename, lvo)
129 This macro will generate an alias 'alias' for function
132 #define __AROS_GM_STACKALIAS(fname, alias) \
134 asm(".weak " __GM_STRINGIZE(alias) "\n" \
135 "\t.set " __GM_STRINGIZE(alias) "," #fname \
137 #define AROS_GM_STACKALIAS(fname, libbasename, lvo) \
138 __AROS_GM_STACKALIAS(fname, AROS_SLIB_ENTRY(fname, libbasename, lvo))
141 #endif /* AROS_X86_64_GENMODULE_H */