xref: /titanic_52/usr/src/grub/grub-0.97/netboot/i386_elf.h (revision 91d7f85e02991954d1e1bd44673df567ad8dcc87)
1 #ifndef I386_BITS_ELF_H
2 #define I386_BITS_ELF_H
3 
4 #include "cpu.h"
5 
6 #ifdef CONFIG_X86_64
7 /* ELF Defines for the 64bit version of the current architecture */
8 #define EM_CURRENT_64	EM_X86_64
9 #define EM_CURRENT_64_PRESENT ( \
10 	CPU_FEATURE_P(cpu_info.x86_capability, LM) && \
11 	CPU_FEATURE_P(cpu_info.x86_capability, PAE) && \
12 	CPU_FEATURE_P(cpu_info.x86_capability, PSE))
13 
14 #define ELF_CHECK_X86_64_ARCH(x) \
15 	(EM_CURRENT_64_PRESENT && ((x).e_machine == EM_X86_64))
16 #define __unused_i386
17 #else
18 #define ELF_CHECK_X86_64_ARCH(x) 0
19 #define __unused_i386 __unused
20 #endif
21 
22 
23 /* ELF Defines for the current architecture */
24 #define	EM_CURRENT	EM_386
25 #define ELFDATA_CURRENT	ELFDATA2LSB
26 
27 #define ELF_CHECK_I386_ARCH(x) \
28 	(((x).e_machine == EM_386) || ((x).e_machine == EM_486))
29 
30 #define ELF_CHECK_ARCH(x) \
31 	((ELF_CHECK_I386_ARCH(x) || ELF_CHECK_X86_64_ARCH(x)) && \
32 		((x).e_entry <= 0xffffffffUL))
33 
34 #ifdef  IMAGE_FREEBSD
35 /*
36  * FreeBSD has this rather strange "feature" of its design.
37  * At some point in its evolution, FreeBSD started to rely
38  * externally on private/static/debug internal symbol information.
39  * That is, some of the interfaces that software uses to access
40  * and work with the FreeBSD kernel are made available not
41  * via the shared library symbol information (the .DYNAMIC section)
42  * but rather the debug symbols.  This means that any symbol, not
43  * just publicly defined symbols can be (and are) used by system
44  * tools to make the system work.  (such as top, swapinfo, swapon,
45  * etc)
46  *
47  * Even worse, however, is the fact that standard ELF loaders do
48  * not know how to load the symbols since they are not within
49  * an ELF PT_LOAD section.  The kernel needs these symbols to
50  * operate so the following changes/additions to the boot
51  * loading of EtherBoot have been made to get the kernel to load.
52  * All of the changes are within IMAGE_FREEBSD such that the
53  * extra/changed code only compiles when FREEBSD support is
54  * enabled.
55  */
56 
57 /*
58  * Section header for FreeBSD (debug symbol kludge!) support
59  */
60 typedef struct {
61 	Elf32_Word	sh_name;	/* Section name (index into the
62 					   section header string table). */
63 	Elf32_Word	sh_type;	/* Section type. */
64 	Elf32_Word	sh_flags;	/* Section flags. */
65 	Elf32_Addr	sh_addr;	/* Address in memory image. */
66 	Elf32_Off	sh_offset;	/* Offset in file. */
67 	Elf32_Size	sh_size;	/* Size in bytes. */
68 	Elf32_Word	sh_link;	/* Index of a related section. */
69 	Elf32_Word	sh_info;	/* Depends on section type. */
70 	Elf32_Size	sh_addralign;	/* Alignment in bytes. */
71 	Elf32_Size	sh_entsize;	/* Size of each entry in section. */
72 } Elf32_Shdr;
73 
74 /* sh_type */
75 #define SHT_SYMTAB	2		/* symbol table section */
76 #define SHT_STRTAB	3		/* string table section */
77 
78 /*
79  * Module information subtypes (for the metadata that we need to build)
80  */
81 #define MODINFO_END		0x0000		/* End of list */
82 #define MODINFO_NAME		0x0001		/* Name of module (string) */
83 #define MODINFO_TYPE		0x0002		/* Type of module (string) */
84 #define MODINFO_METADATA	0x8000		/* Module-specfic */
85 
86 #define MODINFOMD_SSYM		0x0003		/* start of symbols */
87 #define MODINFOMD_ESYM		0x0004		/* end of symbols */
88 
89 #endif	/* IMAGE_FREEBSD */
90 
91 #endif /* I386_BITS_ELF_H */
92