45275f9e458b7eb260c9efac3d54071544a70293
[lunaix-os.git] / lunaix-os / arch / x86 / includes / sys / boot / bstage.h
1 #ifndef __LUNAIX_BSTAGE_H
2 #define __LUNAIX_BSTAGE_H
3 #include <lunaix/types.h>
4 #include <lunaix/boot_generic.h>
5
6 extern ptr_t __multiboot_addr;
7
8 extern u8_t __kboot_start[];
9 extern u8_t __kboot_end[];
10
11 #define boot_text __attribute__((section(".boot.text")))
12 #define boot_data __attribute__((section(".boot.data")))
13 #define boot_bss  __attribute__((section(".boot.bss")))
14
15 /*
16     Bridge the far symbol to the vicinity.
17
18     Which is a workaround for relocation 
19     issue where symbol define in kernel 
20     code is too far away from the boot code.
21 */
22 #ifdef CONFIG_ARCH_X86_64
23 #define __bridge_farsym(far_sym)        \
24     asm(                                \
25         ".section .boot.data\n"         \
26         ".align 8\n"                    \
27         ".globl __lc_" #far_sym "\n"    \
28         "__lc_" #far_sym ":\n"          \
29         ".8byte " #far_sym "\n"         \
30         ".previous\n"                   \
31     );                                  \
32     extern unsigned long __lc_##far_sym[];
33 #define bridge_farsym(far_sym)  __bridge_farsym(far_sym)
34
35 #define ___far(far_sym)  (__lc_##far_sym[0])
36 #define __far(far_sym)  ___far(far_sym)
37
38 #else
39 #define __bridge_farsym(far_sym)    extern unsigned long far_sym[]
40 #define ___far(far_sym)             ((ptr_t)far_sym)
41 #define bridge_farsym(far_sym)      __bridge_farsym(far_sym);
42 #define __far(far_sym)              ___far(far_sym)
43
44 #endif
45
46 ptr_t 
47 remap_kernel();
48
49 #endif /* __LUNAIX_BSTAGE_H */