Indentation fix, cleanup.
[AROS.git] / arch / x86_64-all / include / aros / genmodule.h
blobaebf3b810026822f8ebb002a1af34c9eedc5c766
1 #ifndef AROS_X86_64_GENMODULE_H
2 #define AROS_X86_64_GENMODULE_H
4 /*
5 Copyright © 1995-2012, 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 "\tmovq " #libbasename "(%%rip), %%r11\n" \
33 "\tjmp *%c0(%%r11)\n" \
34 : : "i" ((-lvo)*LIB_VECTSIZE) \
35 ); \
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
42 the current libbase
44 #define __AROS_GM_RELLIBFUNCSTUB(fname, libbasename, lvo) \
45 void __ ## fname ## _ ## libbasename ## _relwrapper(void) \
46 { \
47 asm volatile( \
48 ".weak " #fname "\n" \
49 "\t" #fname " :\n" \
50 "\tpushq %%rax\n" \
51 "\tpushq %%rdi\n" \
52 "\tpushq %%rsi\n" \
53 "\tpushq %%rdx\n" \
54 "\tpushq %%rcx\n" \
55 "\tpushq %%r8\n" \
56 "\tpushq %%r9\n" \
57 "\tcall __aros_getoffsettable\n" \
58 "\taddq __aros_rellib_offset_" #libbasename "(%%rip), %%rax\n" \
59 "\tmovq (%%rax),%%r11\n" \
60 "\tpopq %%r9\n" \
61 "\tpopq %%r8\n" \
62 "\tpopq %%rcx\n" \
63 "\tpopq %%rdx\n" \
64 "\tpopq %%rsi\n" \
65 "\tpopq %%rdi\n" \
66 "\tpopq %%rax\n" \
67 "\tjmp *%c0(%%r11)\n" \
68 : : "i" ((-lvo)*LIB_VECTSIZE) \
69 ); \
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
76 'functionname'
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) \
97 { \
98 asm volatile( \
99 "\t" __GM_STRINGIZE(libfuncname) " :\n" \
100 "\tpushq %%rax\n" \
101 "\tpushq %%rdi\n" \
102 "\tpushq %%rsi\n" \
103 "\tpushq %%rdx\n" \
104 "\tpushq %%rcx\n" \
105 "\tpushq %%r8\n" \
106 "\tpushq %%r9\n" \
107 "\tmovq %%r11,%%rdi\n" \
108 "\tcall __aros_setoffsettable\n" \
109 "\tpopq %%r9\n" \
110 "\tpopq %%r8\n" \
111 "\tpopq %%rcx\n" \
112 "\tpopq %%rdx\n" \
113 "\tpopq %%rsi\n" \
114 "\tpopq %%rdi\n" \
115 "\tpopq %%rax\n" \
116 "\tjmp " #fname "\n" \
117 : : : \
118 ); \
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
126 'functionname'
128 #define __AROS_GM_STACKALIAS(fname, alias) \
129 void alias(void); \
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 */