Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / efi / pe32.h
blobc3efa9b3d906c64ec603f6d420b77a9bbc30ced4
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_EFI_PE32_HEADER
20 #define GRUB_EFI_PE32_HEADER 1
22 #include <grub/types.h>
24 /* The MSDOS compatibility stub. This was copied from the output of
25 objcopy, and it is not necessary to care about what this means. */
26 #define GRUB_PE32_MSDOS_STUB \
27 { \
28 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, \
29 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, \
30 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
31 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
35 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, \
36 0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd, \
37 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68, \
38 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, \
39 0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, \
40 0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e, \
41 0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, \
42 0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a, \
43 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \
46 #define GRUB_PE32_MSDOS_STUB_SIZE 0x80
48 /* According to the spec, the minimal alignment is 512 bytes...
49 But some examples (such as EFI drivers in the Intel
50 Sample Implementation) use 32 bytes (0x20) instead, and it seems
51 to be working. For now, GRUB uses 512 bytes for safety. */
52 #define GRUB_PE32_SECTION_ALIGNMENT 0x200
53 #define GRUB_PE32_FILE_ALIGNMENT GRUB_PE32_SECTION_ALIGNMENT
55 struct grub_pe32_coff_header
57 grub_uint16_t machine;
58 grub_uint16_t num_sections;
59 grub_uint32_t time;
60 grub_uint32_t symtab_offset;
61 grub_uint32_t num_symbols;
62 grub_uint16_t optional_header_size;
63 grub_uint16_t characteristics;
66 #define GRUB_PE32_MACHINE_I386 0x14c
67 #define GRUB_PE32_MACHINE_IA64 0x200
68 #define GRUB_PE32_MACHINE_X86_64 0x8664
70 #define GRUB_PE32_RELOCS_STRIPPED 0x0001
71 #define GRUB_PE32_EXECUTABLE_IMAGE 0x0002
72 #define GRUB_PE32_LINE_NUMS_STRIPPED 0x0004
73 #define GRUB_PE32_LOCAL_SYMS_STRIPPED 0x0008
74 #define GRUB_PE32_AGGRESSIVE_WS_TRIM 0x0010
75 #define GRUB_PE32_LARGE_ADDRESS_AWARE 0x0020
76 #define GRUB_PE32_16BIT_MACHINE 0x0040
77 #define GRUB_PE32_BYTES_REVERSED_LO 0x0080
78 #define GRUB_PE32_32BIT_MACHINE 0x0100
79 #define GRUB_PE32_DEBUG_STRIPPED 0x0200
80 #define GRUB_PE32_REMOVABLE_RUN_FROM_SWAP 0x0400
81 #define GRUB_PE32_SYSTEM 0x1000
82 #define GRUB_PE32_DLL 0x2000
83 #define GRUB_PE32_UP_SYSTEM_ONLY 0x4000
84 #define GRUB_PE32_BYTES_REVERSED_HI 0x8000
86 struct grub_pe32_data_directory
88 grub_uint32_t rva;
89 grub_uint32_t size;
92 struct grub_pe32_optional_header
94 grub_uint16_t magic;
95 grub_uint8_t major_linker_version;
96 grub_uint8_t minor_linker_version;
97 grub_uint32_t code_size;
98 grub_uint32_t data_size;
99 grub_uint32_t bss_size;
100 grub_uint32_t entry_addr;
101 grub_uint32_t code_base;
103 grub_uint32_t data_base;
104 grub_uint32_t image_base;
106 grub_uint32_t section_alignment;
107 grub_uint32_t file_alignment;
108 grub_uint16_t major_os_version;
109 grub_uint16_t minor_os_version;
110 grub_uint16_t major_image_version;
111 grub_uint16_t minor_image_version;
112 grub_uint16_t major_subsystem_version;
113 grub_uint16_t minor_subsystem_version;
114 grub_uint32_t reserved;
115 grub_uint32_t image_size;
116 grub_uint32_t header_size;
117 grub_uint32_t checksum;
118 grub_uint16_t subsystem;
119 grub_uint16_t dll_characteristics;
121 grub_uint32_t stack_reserve_size;
122 grub_uint32_t stack_commit_size;
123 grub_uint32_t heap_reserve_size;
124 grub_uint32_t heap_commit_size;
126 grub_uint32_t loader_flags;
127 grub_uint32_t num_data_directories;
129 /* Data directories. */
130 struct grub_pe32_data_directory export_table;
131 struct grub_pe32_data_directory import_table;
132 struct grub_pe32_data_directory resource_table;
133 struct grub_pe32_data_directory exception_table;
134 struct grub_pe32_data_directory certificate_table;
135 struct grub_pe32_data_directory base_relocation_table;
136 struct grub_pe32_data_directory debug;
137 struct grub_pe32_data_directory architecture;
138 struct grub_pe32_data_directory global_ptr;
139 struct grub_pe32_data_directory tls_table;
140 struct grub_pe32_data_directory load_config_table;
141 struct grub_pe32_data_directory bound_import;
142 struct grub_pe32_data_directory iat;
143 struct grub_pe32_data_directory delay_import_descriptor;
144 struct grub_pe32_data_directory com_runtime_header;
145 struct grub_pe32_data_directory reserved_entry;
148 struct grub_pe64_optional_header
150 grub_uint16_t magic;
151 grub_uint8_t major_linker_version;
152 grub_uint8_t minor_linker_version;
153 grub_uint32_t code_size;
154 grub_uint32_t data_size;
155 grub_uint32_t bss_size;
156 grub_uint32_t entry_addr;
157 grub_uint32_t code_base;
159 grub_uint64_t image_base;
161 grub_uint32_t section_alignment;
162 grub_uint32_t file_alignment;
163 grub_uint16_t major_os_version;
164 grub_uint16_t minor_os_version;
165 grub_uint16_t major_image_version;
166 grub_uint16_t minor_image_version;
167 grub_uint16_t major_subsystem_version;
168 grub_uint16_t minor_subsystem_version;
169 grub_uint32_t reserved;
170 grub_uint32_t image_size;
171 grub_uint32_t header_size;
172 grub_uint32_t checksum;
173 grub_uint16_t subsystem;
174 grub_uint16_t dll_characteristics;
176 grub_uint64_t stack_reserve_size;
177 grub_uint64_t stack_commit_size;
178 grub_uint64_t heap_reserve_size;
179 grub_uint64_t heap_commit_size;
181 grub_uint32_t loader_flags;
182 grub_uint32_t num_data_directories;
184 /* Data directories. */
185 struct grub_pe32_data_directory export_table;
186 struct grub_pe32_data_directory import_table;
187 struct grub_pe32_data_directory resource_table;
188 struct grub_pe32_data_directory exception_table;
189 struct grub_pe32_data_directory certificate_table;
190 struct grub_pe32_data_directory base_relocation_table;
191 struct grub_pe32_data_directory debug;
192 struct grub_pe32_data_directory architecture;
193 struct grub_pe32_data_directory global_ptr;
194 struct grub_pe32_data_directory tls_table;
195 struct grub_pe32_data_directory load_config_table;
196 struct grub_pe32_data_directory bound_import;
197 struct grub_pe32_data_directory iat;
198 struct grub_pe32_data_directory delay_import_descriptor;
199 struct grub_pe32_data_directory com_runtime_header;
200 struct grub_pe32_data_directory reserved_entry;
203 #define GRUB_PE32_PE32_MAGIC 0x10b
204 #define GRUB_PE32_PE64_MAGIC 0x20b
206 #define GRUB_PE32_SUBSYSTEM_EFI_APPLICATION 10
208 #define GRUB_PE32_NUM_DATA_DIRECTORIES 16
210 struct grub_pe32_section_table
212 char name[8];
213 grub_uint32_t virtual_size;
214 grub_uint32_t virtual_address;
215 grub_uint32_t raw_data_size;
216 grub_uint32_t raw_data_offset;
217 grub_uint32_t relocations_offset;
218 grub_uint32_t line_numbers_offset;
219 grub_uint16_t num_relocations;
220 grub_uint16_t num_line_numbers;
221 grub_uint32_t characteristics;
224 #define GRUB_PE32_SCN_CNT_CODE 0x00000020
225 #define GRUB_PE32_SCN_CNT_INITIALIZED_DATA 0x00000040
226 #define GRUB_PE32_SCN_MEM_DISCARDABLE 0x02000000
227 #define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000
228 #define GRUB_PE32_SCN_MEM_READ 0x40000000
229 #define GRUB_PE32_SCN_MEM_WRITE 0x80000000
231 #define GRUB_PE32_SCN_ALIGN_1BYTES 0x00100000
232 #define GRUB_PE32_SCN_ALIGN_2BYTES 0x00200000
233 #define GRUB_PE32_SCN_ALIGN_4BYTES 0x00300000
234 #define GRUB_PE32_SCN_ALIGN_8BYTES 0x00400000
235 #define GRUB_PE32_SCN_ALIGN_16BYTES 0x00500000
236 #define GRUB_PE32_SCN_ALIGN_32BYTES 0x00600000
237 #define GRUB_PE32_SCN_ALIGN_64BYTES 0x00700000
239 #define GRUB_PE32_SCN_ALIGN_SHIFT 20
240 #define GRUB_PE32_SCN_ALIGN_MASK 7
242 #define GRUB_PE32_SIGNATURE_SIZE 4
244 struct grub_pe32_header
246 /* This should be filled in with GRUB_PE32_MSDOS_STUB. */
247 grub_uint8_t msdos_stub[GRUB_PE32_MSDOS_STUB_SIZE];
249 /* This is always PE\0\0. */
250 char signature[GRUB_PE32_SIGNATURE_SIZE];
252 /* The COFF file header. */
253 struct grub_pe32_coff_header coff_header;
255 #if GRUB_TARGET_SIZEOF_VOID_P == 8
256 /* The Optional header. */
257 struct grub_pe64_optional_header optional_header;
258 #else
259 /* The Optional header. */
260 struct grub_pe32_optional_header optional_header;
261 #endif
264 struct grub_pe32_fixup_block
266 grub_uint32_t page_rva;
267 grub_uint32_t block_size;
268 grub_uint16_t entries[0];
271 #define GRUB_PE32_FIXUP_ENTRY(type, offset) (((type) << 12) | (offset))
273 #define GRUB_PE32_REL_BASED_ABSOLUTE 0
274 #define GRUB_PE32_REL_BASED_HIGH 1
275 #define GRUB_PE32_REL_BASED_LOW 2
276 #define GRUB_PE32_REL_BASED_HIGHLOW 3
277 #define GRUB_PE32_REL_BASED_HIGHADJ 4
278 #define GRUB_PE32_REL_BASED_MIPS_JMPADDR 5
279 #define GRUB_PE32_REL_BASED_SECTION 6
280 #define GRUB_PE32_REL_BASED_REL 7
281 #define GRUB_PE32_REL_BASED_IA64_IMM64 9
282 #define GRUB_PE32_REL_BASED_DIR64 10
283 #define GRUB_PE32_REL_BASED_HIGH3ADJ 11
285 struct grub_pe32_symbol
287 union
289 char short_name[8];
290 grub_uint32_t long_name[2];
293 grub_uint32_t value;
294 grub_uint16_t section;
295 grub_uint16_t type;
296 grub_uint8_t storage_class;
297 grub_uint8_t num_aux;
298 } __attribute__ ((packed));
300 #define GRUB_PE32_SYM_CLASS_EXTERNAL 2
301 #define GRUB_PE32_SYM_CLASS_STATIC 3
302 #define GRUB_PE32_SYM_CLASS_FILE 0x67
304 #define GRUB_PE32_DT_FUNCTION 0x20
306 struct grub_pe32_reloc
308 grub_uint32_t offset;
309 grub_uint32_t symtab_index;
310 grub_uint16_t type;
311 } __attribute__ ((packed));
313 #define GRUB_PE32_REL_I386_DIR32 0x6
314 #define GRUB_PE32_REL_I386_REL32 0x14
316 #endif /* ! GRUB_EFI_PE32_HEADER */