Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / dl.h
blob9562fa6634c298f17b25082a43e705c9b37418d3
1 /* dl.h - types and prototypes for loadable module support */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2002,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef GRUB_DL_H
21 #define GRUB_DL_H 1
23 #include <grub/symbol.h>
24 #ifndef ASM_FILE
25 #include <grub/err.h>
26 #include <grub/types.h>
27 #include <grub/elf.h>
28 #include <grub/list.h>
29 #include <grub/misc.h>
30 #endif
33 * Macros GRUB_MOD_INIT and GRUB_MOD_FINI are also used by build rules
34 * to collect module names, so we define them only when they are not
35 * defined already.
37 #ifndef ASM_FILE
39 #ifndef GRUB_MOD_INIT
41 #if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
43 #define GRUB_MOD_INIT(name) \
44 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
45 static void \
46 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
48 #define GRUB_MOD_FINI(name) \
49 static void grub_mod_fini (void) __attribute__ ((used)); \
50 static void \
51 grub_mod_fini (void)
53 #elif defined (GRUB_KERNEL)
55 #define GRUB_MOD_INIT(name) \
56 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
57 void \
58 grub_##name##_init (void) { grub_mod_init (0); } \
59 static void \
60 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
62 #define GRUB_MOD_FINI(name) \
63 static void grub_mod_fini (void) __attribute__ ((used)); \
64 void \
65 grub_##name##_fini (void) { grub_mod_fini (); } \
66 static void \
67 grub_mod_fini (void)
69 #else
71 #define GRUB_MOD_INIT(name) \
72 static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
73 void grub_##name##_init (void); \
74 void \
75 grub_##name##_init (void) { grub_mod_init (0); } \
76 static void \
77 grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
79 #define GRUB_MOD_FINI(name) \
80 static void grub_mod_fini (void) __attribute__ ((used)); \
81 void grub_##name##_fini (void); \
82 void \
83 grub_##name##_fini (void) { grub_mod_fini (); } \
84 static void \
85 grub_mod_fini (void)
87 #endif
89 #endif
91 #endif
93 #ifndef ASM_FILE
94 #ifdef __APPLE__
95 #define GRUB_MOD_SECTION(x) "_" #x ", _" #x ""
96 #else
97 #define GRUB_MOD_SECTION(x) "." #x
98 #endif
99 #else
100 #ifdef __APPLE__
101 #define GRUB_MOD_SECTION(x) _ ## x , _ ##x
102 #else
103 #define GRUB_MOD_SECTION(x) . ## x
104 #endif
105 #endif
107 /* Me, Vladimir Serbinenko, hereby I add this module check as per new
108 GNU module policy. Note that this license check is informative only.
109 Modules have to be licensed under GPLv3 or GPLv3+ (optionally
110 multi-licensed under other licences as well) independently of the
111 presence of this check and solely by linking (module loading in GRUB
112 constitutes linking) and GRUB core being licensed under GPLv3+.
113 Be sure to understand your license obligations.
115 #ifndef ASM_FILE
116 #if GNUC_PREREQ (3,2)
117 #define ATTRIBUTE_USED __used__
118 #else
119 #define ATTRIBUTE_USED __unused__
120 #endif
121 #define GRUB_MOD_LICENSE(license) \
122 static char grub_module_license[] __attribute__ ((section (GRUB_MOD_SECTION (module_license)), ATTRIBUTE_USED)) = "LICENSE=" license;
123 #define GRUB_MOD_DEP(name) \
124 static const char grub_module_depend_##name[] \
125 __attribute__((section(GRUB_MOD_SECTION(moddeps)), ATTRIBUTE_USED)) = #name
126 #define GRUB_MOD_NAME(name) \
127 static const char grub_module_name_##name[] \
128 __attribute__((section(GRUB_MOD_SECTION(modname)), __used__)) = #name
129 #else
130 #ifdef __APPLE__
131 .macro GRUB_MOD_LICENSE
132 .section GRUB_MOD_SECTION(module_license)
133 .ascii "LICENSE="
134 .ascii $0
135 .byte 0
136 .endm
137 #else
138 .macro GRUB_MOD_LICENSE license
139 .section GRUB_MOD_SECTION(module_license), "a"
140 .ascii "LICENSE="
141 .ascii "\license"
142 .byte 0
143 .endm
144 #endif
145 #endif
147 /* Under GPL license obligations you have to distribute your module
148 under GPLv3(+). However, you can also distribute the same code under
149 another license as long as GPLv3(+) version is provided.
151 #define GRUB_MOD_DUAL_LICENSE(x)
153 #ifndef ASM_FILE
155 struct grub_dl_segment
157 struct grub_dl_segment *next;
158 void *addr;
159 grub_size_t size;
160 unsigned section;
162 typedef struct grub_dl_segment *grub_dl_segment_t;
164 struct grub_dl;
166 struct grub_dl_dep
168 struct grub_dl_dep *next;
169 struct grub_dl *mod;
171 typedef struct grub_dl_dep *grub_dl_dep_t;
173 #ifndef GRUB_UTIL
174 struct grub_dl
176 char *name;
177 int ref_count;
178 grub_dl_dep_t dep;
179 grub_dl_segment_t segment;
180 Elf_Sym *symtab;
181 grub_size_t symsize;
182 void (*init) (struct grub_dl *mod);
183 void (*fini) (void);
184 #if !defined (__i386__) && !defined (__x86_64__)
185 void *got;
186 void *gotptr;
187 void *tramp;
188 void *trampptr;
189 #endif
190 #ifdef __mips__
191 grub_uint32_t *reginfo;
192 #endif
193 void *base;
194 grub_size_t sz;
195 struct grub_dl *next;
197 #endif
198 typedef struct grub_dl *grub_dl_t;
200 grub_dl_t grub_dl_load_file (const char *filename);
201 grub_dl_t EXPORT_FUNC(grub_dl_load) (const char *name);
202 grub_dl_t grub_dl_load_core (void *addr, grub_size_t size);
203 grub_dl_t EXPORT_FUNC(grub_dl_load_core_noinit) (void *addr, grub_size_t size);
204 int EXPORT_FUNC(grub_dl_unload) (grub_dl_t mod);
205 void grub_dl_unload_unneeded (void);
206 int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
207 int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
208 extern grub_dl_t EXPORT_VAR(grub_dl_head);
210 #ifndef GRUB_UTIL
212 #define FOR_DL_MODULES(var) FOR_LIST_ELEMENTS ((var), (grub_dl_head))
214 #ifdef GRUB_MACHINE_EMU
215 void *
216 grub_osdep_dl_memalign (grub_size_t align, grub_size_t size);
217 void
218 grub_dl_osdep_dl_free (void *ptr);
219 #endif
221 static inline void
222 grub_dl_init (grub_dl_t mod)
224 if (mod->init)
225 (mod->init) (mod);
227 mod->next = grub_dl_head;
228 grub_dl_head = mod;
231 static inline grub_dl_t
232 grub_dl_get (const char *name)
234 grub_dl_t l;
236 FOR_DL_MODULES(l)
237 if (grub_strcmp (name, l->name) == 0)
238 return l;
240 return 0;
243 #endif
245 grub_err_t grub_dl_register_symbol (const char *name, void *addr,
246 int isfunc, grub_dl_t mod);
248 grub_err_t grub_arch_dl_check_header (void *ehdr);
249 #ifndef GRUB_UTIL
250 grub_err_t
251 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
252 Elf_Shdr *s, grub_dl_segment_t seg);
253 #endif
255 #if defined (_mips)
256 #define GRUB_LINKER_HAVE_INIT 1
257 void grub_arch_dl_init_linker (void);
258 #endif
260 #define GRUB_IA64_DL_TRAMP_ALIGN 16
261 #define GRUB_IA64_DL_GOT_ALIGN 16
263 grub_err_t
264 grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
265 grub_size_t *got);
267 #if defined (__ia64__)
268 #define GRUB_ARCH_DL_TRAMP_ALIGN GRUB_IA64_DL_TRAMP_ALIGN
269 #define GRUB_ARCH_DL_GOT_ALIGN GRUB_IA64_DL_GOT_ALIGN
270 #define grub_arch_dl_get_tramp_got_size grub_ia64_dl_get_tramp_got_size
271 #else
272 grub_err_t
273 grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
274 grub_size_t *got);
275 #endif
277 #if defined (__powerpc__) || defined (__mips__) || defined (__arm__)
278 #define GRUB_ARCH_DL_TRAMP_ALIGN 4
279 #define GRUB_ARCH_DL_GOT_ALIGN 4
280 #endif
282 #if defined (__aarch64__) || defined (__sparc__)
283 #define GRUB_ARCH_DL_TRAMP_ALIGN 8
284 #define GRUB_ARCH_DL_GOT_ALIGN 8
285 #endif
287 #endif
289 #endif /* ! GRUB_DL_H */