revert between 56095 -> 55830 in arch
[AROS.git] / arch / x86_64-all / include / aros / genmodule.h
blob60ccfd7a947dc868f6d7fc480918b9525b29c82c
1 #ifndef AROS_X86_64_GENMODULE_H
2 #define AROS_X86_64_GENMODULE_H
4 /*
5 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: genmodule specific definitions for x86_64
9 Lang: english
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
24 to the asm statement
26 #define __AROS_GM_LIBFUNCSTUB(fname, libbasename, lvo) \
27 void __ ## fname ## _ ## libbasename ## _wrapper(void) \
28 { \
29 asm volatile( \
30 ".weak " #fname "\n" \
31 #fname " :\n" \
32 "\tmovabsq $" #libbasename ", %%r11\n" \
33 "\tmovq (%%r11),%%r11\n" \
34 "\tjmp *%c0(%%r11)\n" \
35 : : "i" ((-lvo)*LIB_VECTSIZE) \
36 ); \
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
43 the current libbase
45 #define __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
46 void __ ## fname ## _ ## libbasename ## _relwrapper(void) \
47 { \
48 asm volatile( \
49 ".weak " #fname "\n" \
50 "\t" #fname " :\n" \
51 "\tpushq %%rax\n" \
52 "\tpushq %%rdi\n" \
53 "\tpushq %%rsi\n" \
54 "\tpushq %%rdx\n" \
55 "\tpushq %%rcx\n" \
56 "\tpushq %%r8\n" \
57 "\tpushq %%r9\n" \
58 "\tmovabsq $__aros_getoffsettable,%%r11\n" \
59 "\tcall *%%r11\n" \
60 "\taddq __aros_rellib_offset_" #libbasename "(%%rip), %%rax\n" \
61 "\tmovq (%%rax),%%r11\n" \
62 "\tpopq %%r9\n" \
63 "\tpopq %%r8\n" \
64 "\tpopq %%rcx\n" \
65 "\tpopq %%rdx\n" \
66 "\tpopq %%rsi\n" \
67 "\tpopq %%rdi\n" \
68 "\tpopq %%rax\n" \
69 "\tjmp *%c0(%%r11)\n" \
70 : : "i" ((-lvo)*LIB_VECTSIZE) \
71 ); \
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
78 'functionname'
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) \
99 { \
100 asm volatile( \
101 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
102 "\tpushq %%rax\n" \
103 "\tpushq %%rdi\n" \
104 "\tpushq %%rsi\n" \
105 "\tpushq %%rdx\n" \
106 "\tpushq %%rcx\n" \
107 "\tpushq %%r8\n" \
108 "\tpushq %%r9\n" \
109 "\tmovq %%r11,%%rdi\n" \
110 "\tmovabsq $__aros_setoffsettable,%%r11\n" \
111 "\tcall *%%r11\n" \
112 "\tpopq %%r9\n" \
113 "\tpopq %%r8\n" \
114 "\tpopq %%rcx\n" \
115 "\tpopq %%rdx\n" \
116 "\tpopq %%rsi\n" \
117 "\tpopq %%rdi\n" \
118 "\tpopq %%rax\n" \
119 "\tmovabsq $" #fname ",%%r11\n" \
120 "\tjmp *%%r11\n" \
121 : : : \
122 ); \
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
130 'functionname'
132 #define __AROS_GM_STACKALIAS(fname, alias) \
133 void alias(void); \
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 */