Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright 2011 Red Hat, Inc.
4 * All rights reserved.
5 *
6 * Author(s): Peter Jones <pjones@redhat.com>
7 */
8#ifndef __LINUX_PE_H
9#define __LINUX_PE_H
10
11#include <linux/types.h>
12
13/*
14 * Starting from version v3.0, the major version field should be interpreted as
15 * a bit mask of features supported by the kernel's EFI stub:
16 * - 0x1: initrd loading from the LINUX_EFI_INITRD_MEDIA_GUID device path,
17 * - 0x2: initrd loading using the initrd= command line option, where the file
18 * may be specified using device path notation, and is not required to
19 * reside on the same volume as the loaded kernel image.
20 *
21 * The recommended way of loading and starting v1.0 or later kernels is to use
22 * the LoadImage() and StartImage() EFI boot services, and expose the initrd
23 * via the LINUX_EFI_INITRD_MEDIA_GUID device path.
24 *
25 * Versions older than v1.0 may support initrd loading via the image load
26 * options (using initrd=, limited to the volume from which the kernel itself
27 * was loaded), or only via arch specific means (bootparams, DT, etc).
28 *
29 * The minor version field must remain 0x0.
30 * (https://lore.kernel.org/all/efd6f2d4-547c-1378-1faa-53c044dbd297@gmail.com/)
31 */
32#define LINUX_EFISTUB_MAJOR_VERSION 0x3
33#define LINUX_EFISTUB_MINOR_VERSION 0x0
34
35/*
36 * LINUX_PE_MAGIC appears at offset 0x38 into the MS-DOS header of EFI bootable
37 * Linux kernel images that target the architecture as specified by the PE/COFF
38 * header machine type field.
39 */
40#define LINUX_PE_MAGIC 0x818223cd
41
42#define IMAGE_DOS_SIGNATURE 0x5a4d /* "MZ" */
43
44#define IMAGE_NT_SIGNATURE 0x00004550 /* "PE\0\0" */
45
46#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x0107 /* ROM image (for R3000/R4000/R10000/ALPHA), without MZ and PE\0\0 sign */
47#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x010b /* PE32 executable image */
48#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x020b /* PE32+ executable image */
49
50/* machine type */
51#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 /* Unknown architecture */
52#define IMAGE_FILE_MACHINE_TARGET_HOST 0x0001 /* Interacts with the host and not a WOW64 guest (not for file image) */
53#define IMAGE_FILE_MACHINE_ALPHA_OLD 0x0183 /* DEC Alpha AXP 32-bit (old images) */
54#define IMAGE_FILE_MACHINE_ALPHA 0x0184 /* DEC Alpha AXP 32-bit */
55#define IMAGE_FILE_MACHINE_ALPHA64 0x0284 /* DEC Alpha AXP 64-bit (with 8kB page size) */
56#define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
57#define IMAGE_FILE_MACHINE_AM33 0x01d3 /* Matsushita AM33, now Panasonic MN103 */
58#define IMAGE_FILE_MACHINE_AMD64 0x8664 /* AMD64 (x64) */
59#define IMAGE_FILE_MACHINE_ARM 0x01c0 /* ARM Little-Endian (ARMv4) */
60#define IMAGE_FILE_MACHINE_THUMB 0x01c2 /* ARM Thumb Little-Endian (ARMv4T) */
61#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 /* ARM Thumb-2 Little-Endian (ARMv7) */
62#define IMAGE_FILE_MACHINE_ARMV7 IMAGE_FILE_MACHINE_ARMNT
63#define IMAGE_FILE_MACHINE_ARM64 0xaa64 /* ARM64 Little-Endian (Classic ABI) */
64#define IMAGE_FILE_MACHINE_ARM64EC 0xa641 /* ARM64 Little-Endian (Emulation Compatible ABI for AMD64) */
65#define IMAGE_FILE_MACHINE_ARM64X 0xa64e /* ARM64 Little-Endian (fat binary with both Classic ABI and EC ABI code) */
66#define IMAGE_FILE_MACHINE_CEE 0xc0ee /* COM+ Execution Engine (CLR pure MSIL object files) */
67#define IMAGE_FILE_MACHINE_CEF 0x0cef /* Windows CE 3.0 Common Executable Format (CEF bytecode) */
68#define IMAGE_FILE_MACHINE_CHPE_X86 0x3a64 /* ARM64 Little-Endian (Compiled Hybrid PE ABI for I386) */
69#define IMAGE_FILE_MACHINE_HYBRID_X86 IMAGE_FILE_MACHINE_CHPE_X86
70#define IMAGE_FILE_MACHINE_EBC 0x0ebc /* EFI/UEFI Byte Code */
71#define IMAGE_FILE_MACHINE_I386 0x014c /* Intel 386 (x86) */
72#define IMAGE_FILE_MACHINE_I860 0x014d /* Intel 860 (N10) */
73#define IMAGE_FILE_MACHINE_IA64 0x0200 /* Intel IA-64 (with 8kB page size) */
74#define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232 /* LoongArch 32-bit processor family */
75#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 /* LoongArch 64-bit processor family */
76#define IMAGE_FILE_MACHINE_M32R 0x9041 /* Mitsubishi M32R 32-bit Little-Endian */
77#define IMAGE_FILE_MACHINE_M68K 0x0268 /* Motorola 68000 series */
78#define IMAGE_FILE_MACHINE_MIPS16 0x0266 /* MIPS III with MIPS16 ASE Little-Endian */
79#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 /* MIPS III with FPU Little-Endian */
80#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 /* MIPS III with MIPS16 ASE and FPU Little-Endian */
81#define IMAGE_FILE_MACHINE_MPPC_601 0x0601 /* PowerPC 32-bit Big-Endian */
82#define IMAGE_FILE_MACHINE_OMNI 0xace1 /* Microsoft OMNI VM (omniprox.dll) */
83#define IMAGE_FILE_MACHINE_PARISC 0x0290 /* HP PA-RISC */
84#define IMAGE_FILE_MACHINE_POWERPC 0x01f0 /* PowerPC 32-bit Little-Endian */
85#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 /* PowerPC 32-bit with FPU Little-Endian */
86#define IMAGE_FILE_MACHINE_POWERPCBE 0x01f2 /* PowerPC 64-bit Big-Endian */
87#define IMAGE_FILE_MACHINE_R3000 0x0162 /* MIPS I Little-Endian */
88#define IMAGE_FILE_MACHINE_R3000_BE 0x0160 /* MIPS I Big-Endian */
89#define IMAGE_FILE_MACHINE_R4000 0x0166 /* MIPS III Little-Endian (with 1kB or 4kB page size) */
90#define IMAGE_FILE_MACHINE_R10000 0x0168 /* MIPS IV Little-Endian */
91#define IMAGE_FILE_MACHINE_RISCV32 0x5032 /* RISC-V 32-bit address space */
92#define IMAGE_FILE_MACHINE_RISCV64 0x5064 /* RISC-V 64-bit address space */
93#define IMAGE_FILE_MACHINE_RISCV128 0x5128 /* RISC-V 128-bit address space */
94#define IMAGE_FILE_MACHINE_SH3 0x01a2 /* Hitachi SH-3 32-bit Little-Endian (with 1kB page size) */
95#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 /* Hitachi SH-3 DSP 32-bit (with 1kB page size) */
96#define IMAGE_FILE_MACHINE_SH3E 0x01a4 /* Hitachi SH-3E Little-Endian (with 1kB page size) */
97#define IMAGE_FILE_MACHINE_SH4 0x01a6 /* Hitachi SH-4 32-bit Little-Endian (with 1kB page size) */
98#define IMAGE_FILE_MACHINE_SH5 0x01a8 /* Hitachi SH-5 64-bit */
99#define IMAGE_FILE_MACHINE_TAHOE 0x07cc /* Intel EM machine */
100#define IMAGE_FILE_MACHINE_TRICORE 0x0520 /* Infineon AUDO 32-bit */
101#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 /* MIPS Windows CE v2 Little-Endian */
102
103/* flags */
104#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* Relocation info stripped from file */
105#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 /* File is executable (i.e. no unresolved external references) */
106#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 /* Line nunbers stripped from file */
107#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 /* Local symbols stripped from file */
108#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 /* Aggressively trim working set */
109#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 /* App can handle >2gb addresses (image can be loaded at address above 2GB) */
110#define IMAGE_FILE_16BIT_MACHINE 0x0040 /* 16 bit word machine */
111#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 /* Bytes of machine word are reversed (should be set together with IMAGE_FILE_BYTES_REVERSED_HI) */
112#define IMAGE_FILE_32BIT_MACHINE 0x0100 /* 32 bit word machine */
113#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 /* Debugging info stripped from file in .DBG file */
114#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 /* If Image is on removable media, copy and run from the swap file */
115#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 /* If Image is on Net, copy and run from the swap file */
116#define IMAGE_FILE_SYSTEM 0x1000 /* System kernel-mode file (can't be loaded in user-mode) */
117#define IMAGE_FILE_DLL 0x2000 /* File is a DLL */
118#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 /* File should only be run on a UP (uniprocessor) machine */
119#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 /* Bytes of machine word are reversed (should be set together with IMAGE_FILE_BYTES_REVERSED_LO) */
120
121/* subsys */
122#define IMAGE_SUBSYSTEM_UNKNOWN 0 /* Unknown subsystem */
123#define IMAGE_SUBSYSTEM_NATIVE 1 /* No subsystem required (NT device drivers and NT native system processes) */
124#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 /* Windows graphical user interface (GUI) subsystem */
125#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 /* Windows character-mode user interface (CUI) subsystem */
126#define IMAGE_SUBSYSTEM_WINDOWS_OLD_CE_GUI 4 /* Old Windows CE subsystem */
127#define IMAGE_SUBSYSTEM_OS2_CUI 5 /* OS/2 CUI subsystem */
128#define IMAGE_SUBSYSTEM_RESERVED_6 6
129#define IMAGE_SUBSYSTEM_POSIX_CUI 7 /* POSIX CUI subsystem */
130#define IMAGE_SUBSYSTEM_MMOSA 8 /* MMOSA/Native Win32E */
131#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 /* Windows CE subsystem */
132#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 /* Extensible Firmware Interface (EFI) application */
133#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 /* EFI driver with boot services */
134#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 /* EFI driver with run-time services */
135#define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE 13 /* EFI ROM image */
136#define IMAGE_SUBSYSTEM_XBOX 14 /* Xbox system */
137#define IMAGE_SUBSYSTEM_RESERVED_15 15
138#define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 /* Windows Boot application */
139#define IMAGE_SUBSYSTEM_XBOX_CODE_CATALOG 17 /* Xbox Code Catalog */
140
141/* dll_flags */
142#define IMAGE_LIBRARY_PROCESS_INIT 0x0001 /* DLL initialization function called just after process initialization */
143#define IMAGE_LIBRARY_PROCESS_TERM 0x0002 /* DLL initialization function called just before process termination */
144#define IMAGE_LIBRARY_THREAD_INIT 0x0004 /* DLL initialization function called just after thread initialization */
145#define IMAGE_LIBRARY_THREAD_TERM 0x0008 /* DLL initialization function called just before thread initialization */
146#define IMAGE_DLLCHARACTERISTICS_RESERVED_4 0x0010
147#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020 /* ASLR with 64 bit address space (image can be loaded at address above 4GB) */
148#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 /* The DLL can be relocated at load time */
149#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080 /* Code integrity checks are forced */
150#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 /* Image is compatible with data execution prevention */
151#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 /* Image is isolation aware, but should not be isolated (prevents loading of manifest file) */
152#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 /* Image does not use SEH, no SE handler may reside in this image */
153#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 /* Do not bind the image */
154#define IMAGE_DLLCHARACTERISTICS_X86_THUNK 0x1000 /* Image is a Wx86 Thunk DLL (for non-x86/risc DLL files) */
155#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000 /* Image should execute in an AppContainer (for EXE Metro Apps in Windows 8) */
156#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 /* A WDM driver */
157#define IMAGE_DLLCHARACTERISTICS_GUARD_CF 0x4000 /* Image supports Control Flow Guard */
158#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 /* The image is terminal server (Remote Desktop Services) aware */
159
160/* IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS flags */
161#define IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001 /* Image is Control-flow Enforcement Technology Shadow Stack compatible */
162#define IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT_STRICT_MODE 0x0002 /* CET is enforced in strict mode */
163#define IMAGE_DLLCHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODE 0x0004 /* Relaxed mode for Context IP Validation under CET is allowed */
164#define IMAGE_DLLCHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROC 0x0008 /* Use of dynamic APIs is restricted to processes only */
165#define IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1 0x0010
166#define IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2 0x0020
167#define IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040 /* All branch targets in all image code sections are annotated with forward-edge control flow integrity guard instructions */
168#define IMAGE_DLLCHARACTERISTICS_EX_HOTPATCH_COMPATIBLE 0x0080 /* Image can be modified while in use, hotpatch-compatible */
169
170/* section_header flags */
171#define IMAGE_SCN_SCALE_INDEX 0x00000001 /* address of tls index is scaled = multiplied by 4 (for .tls section on MIPS only) */
172#define IMAGE_SCN_TYPE_NO_LOAD 0x00000002 /* reserved */
173#define IMAGE_SCN_TYPE_GROUPED 0x00000004 /* obsolete (used for 16-bit offset code) */
174#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* .o only - don't pad - obsolete (same as IMAGE_SCN_ALIGN_1BYTES) */
175#define IMAGE_SCN_TYPE_COPY 0x00000010 /* reserved */
176#define IMAGE_SCN_CNT_CODE 0x00000020 /* .text */
177#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* .data */
178#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* .bss */
179#define IMAGE_SCN_LNK_OTHER 0x00000100 /* .o only - other type than code, data or info */
180#define IMAGE_SCN_LNK_INFO 0x00000200 /* .o only - .drectve comments */
181#define IMAGE_SCN_LNK_OVERLAY 0x00000400 /* section contains overlay */
182#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* .o only - scn to be rm'd*/
183#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* .o only - COMDAT data */
184#define IMAGE_SCN_RESERVED_13 0x00002000 /* spec omits this */
185#define IMAGE_SCN_MEM_PROTECTED 0x00004000 /* section is memory protected (for M68K) */
186#define IMAGE_SCN_NO_DEFER_SPEC_EXC 0x00004000 /* reset speculative exceptions handling bits in the TLB entries (for non-M68K) */
187#define IMAGE_SCN_MEM_FARDATA 0x00008000 /* section uses FAR_EXTERNAL relocations (for M68K) */
188#define IMAGE_SCN_GPREL 0x00008000 /* global pointer referenced data (for non-M68K) */
189#define IMAGE_SCN_MEM_SYSHEAP 0x00010000 /* use system heap (for M68K) */
190#define IMAGE_SCN_MEM_PURGEABLE 0x00020000 /* section can be released from RAM (for M68K) */
191#define IMAGE_SCN_MEM_16BIT 0x00020000 /* section is 16-bit (for non-M68K where it makes sense: I386, THUMB, MIPS16, MIPSFPU16, ...) */
192#define IMAGE_SCN_MEM_LOCKED 0x00040000 /* prevent the section from being moved (for M68K and .o I386) */
193#define IMAGE_SCN_MEM_PRELOAD 0x00080000 /* section is preload to RAM (for M68K and .o I386) */
194/* and here they just stuck a 1-byte integer in the middle of a bitfield */
195#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 /* .o only - it does what it says on the box */
196#define IMAGE_SCN_ALIGN_2BYTES 0x00200000
197#define IMAGE_SCN_ALIGN_4BYTES 0x00300000
198#define IMAGE_SCN_ALIGN_8BYTES 0x00400000
199#define IMAGE_SCN_ALIGN_16BYTES 0x00500000
200#define IMAGE_SCN_ALIGN_32BYTES 0x00600000
201#define IMAGE_SCN_ALIGN_64BYTES 0x00700000
202#define IMAGE_SCN_ALIGN_128BYTES 0x00800000
203#define IMAGE_SCN_ALIGN_256BYTES 0x00900000
204#define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
205#define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
206#define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
207#define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
208#define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
209#define IMAGE_SCN_ALIGN_RESERVED 0x00f00000
210#define IMAGE_SCN_ALIGN_MASK 0x00f00000
211#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* .o only - extended relocations */
212#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* scn can be discarded */
213#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* cannot be cached */
214#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* not pageable */
215#define IMAGE_SCN_MEM_SHARED 0x10000000 /* can be shared */
216#define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* can be executed as code */
217#define IMAGE_SCN_MEM_READ 0x40000000 /* readable */
218#define IMAGE_SCN_MEM_WRITE 0x80000000 /* writeable */
219
220#define IMAGE_DEBUG_TYPE_UNKNOWN 0 /* Unknown value, ignored by all tools */
221#define IMAGE_DEBUG_TYPE_COFF 1 /* COFF debugging information */
222#define IMAGE_DEBUG_TYPE_CODEVIEW 2 /* CodeView debugging information or Visual C++ Program Database debugging information */
223#define IMAGE_DEBUG_TYPE_FPO 3 /* Frame pointer omission (FPO) information */
224#define IMAGE_DEBUG_TYPE_MISC 4 /* Location of DBG file with CodeView debugging information */
225#define IMAGE_DEBUG_TYPE_EXCEPTION 5 /* Exception information, copy of .pdata section */
226#define IMAGE_DEBUG_TYPE_FIXUP 6 /* Fixup information */
227#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC 7 /* The mapping from an RVA in image to an RVA in source image */
228#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC 8 /* The mapping from an RVA in source image to an RVA in image */
229#define IMAGE_DEBUG_TYPE_BORLAND 9 /* Borland debugging information */
230#define IMAGE_DEBUG_TYPE_RESERVED10 10 /* Coldpath / Hotpatch debug information */
231#define IMAGE_DEBUG_TYPE_CLSID 11 /* CLSID */
232#define IMAGE_DEBUG_TYPE_VC_FEATURE 12 /* Visual C++ counts / statistics */
233#define IMAGE_DEBUG_TYPE_POGO 13 /* COFF group information, data for profile-guided optimization */
234#define IMAGE_DEBUG_TYPE_ILTCG 14 /* Incremental link-time code generation */
235#define IMAGE_DEBUG_TYPE_MPX 15 /* Intel Memory Protection Extensions */
236#define IMAGE_DEBUG_TYPE_REPRO 16 /* PE determinism or reproducibility */
237#define IMAGE_DEBUG_TYPE_EMBEDDED_PORTABLE_PDB 17 /* Embedded Portable PDB debugging information */
238#define IMAGE_DEBUG_TYPE_SPGO 18 /* Sample profile-guided optimization */
239#define IMAGE_DEBUG_TYPE_PDBCHECKSUM 19 /* PDB Checksum */
240#define IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20 /* Extended DLL characteristics bits */
241#define IMAGE_DEBUG_TYPE_PERFMAP 21 /* Location of associated Ready To Run PerfMap file */
242
243#ifndef __ASSEMBLY__
244
245struct mz_hdr {
246 uint16_t magic; /* MZ_MAGIC */
247 uint16_t lbsize; /* size of last used block */
248 uint16_t blocks; /* pages in file, 0x3 */
249 uint16_t relocs; /* relocations */
250 uint16_t hdrsize; /* header size in "paragraphs" */
251 uint16_t min_extra_pps; /* .bss */
252 uint16_t max_extra_pps; /* runtime limit for the arena size */
253 uint16_t ss; /* relative stack segment */
254 uint16_t sp; /* initial %sp register */
255 uint16_t checksum; /* word checksum */
256 uint16_t ip; /* initial %ip register */
257 uint16_t cs; /* initial %cs relative to load segment */
258 uint16_t reloc_table_offset; /* offset of the first relocation */
259 uint16_t overlay_num; /* overlay number. set to 0. */
260 uint16_t reserved0[4]; /* reserved */
261 uint16_t oem_id; /* oem identifier */
262 uint16_t oem_info; /* oem specific */
263 uint16_t reserved1[10]; /* reserved */
264 uint32_t peaddr; /* address of pe header */
265 char message[]; /* message to print */
266};
267
268struct mz_reloc {
269 uint16_t offset;
270 uint16_t segment;
271};
272
273struct pe_hdr {
274 uint32_t magic; /* PE magic */
275 uint16_t machine; /* machine type */
276 uint16_t sections; /* number of sections */
277 uint32_t timestamp; /* time_t */
278 uint32_t symbol_table; /* symbol table offset */
279 uint32_t symbols; /* number of symbols */
280 uint16_t opt_hdr_size; /* size of optional header */
281 uint16_t flags; /* flags */
282};
283
284/* the fact that pe32 isn't padded where pe32+ is 64-bit means union won't
285 * work right. vomit. */
286struct pe32_opt_hdr {
287 /* "standard" header */
288 uint16_t magic; /* file type */
289 uint8_t ld_major; /* linker major version */
290 uint8_t ld_minor; /* linker minor version */
291 uint32_t text_size; /* size of text section(s) */
292 uint32_t data_size; /* size of data section(s) */
293 uint32_t bss_size; /* size of bss section(s) */
294 uint32_t entry_point; /* file offset of entry point */
295 uint32_t code_base; /* relative code addr in ram */
296 uint32_t data_base; /* relative data addr in ram */
297 /* "windows" header */
298 uint32_t image_base; /* preferred load address */
299 uint32_t section_align; /* alignment in bytes */
300 uint32_t file_align; /* file alignment in bytes */
301 uint16_t os_major; /* major OS version */
302 uint16_t os_minor; /* minor OS version */
303 uint16_t image_major; /* major image version */
304 uint16_t image_minor; /* minor image version */
305 uint16_t subsys_major; /* major subsystem version */
306 uint16_t subsys_minor; /* minor subsystem version */
307 uint32_t win32_version; /* win32 version reported at runtime */
308 uint32_t image_size; /* image size */
309 uint32_t header_size; /* header size rounded up to
310 file_align */
311 uint32_t csum; /* checksum */
312 uint16_t subsys; /* subsystem */
313 uint16_t dll_flags; /* more flags! */
314 uint32_t stack_size_req;/* amt of stack requested */
315 uint32_t stack_size; /* amt of stack required */
316 uint32_t heap_size_req; /* amt of heap requested */
317 uint32_t heap_size; /* amt of heap required */
318 uint32_t loader_flags; /* loader flags */
319 uint32_t data_dirs; /* number of data dir entries */
320};
321
322struct pe32plus_opt_hdr {
323 uint16_t magic; /* file type */
324 uint8_t ld_major; /* linker major version */
325 uint8_t ld_minor; /* linker minor version */
326 uint32_t text_size; /* size of text section(s) */
327 uint32_t data_size; /* size of data section(s) */
328 uint32_t bss_size; /* size of bss section(s) */
329 uint32_t entry_point; /* file offset of entry point */
330 uint32_t code_base; /* relative code addr in ram */
331 /* "windows" header */
332 uint64_t image_base; /* preferred load address */
333 uint32_t section_align; /* alignment in bytes */
334 uint32_t file_align; /* file alignment in bytes */
335 uint16_t os_major; /* major OS version */
336 uint16_t os_minor; /* minor OS version */
337 uint16_t image_major; /* major image version */
338 uint16_t image_minor; /* minor image version */
339 uint16_t subsys_major; /* major subsystem version */
340 uint16_t subsys_minor; /* minor subsystem version */
341 uint32_t win32_version; /* win32 version reported at runtime */
342 uint32_t image_size; /* image size */
343 uint32_t header_size; /* header size rounded up to
344 file_align */
345 uint32_t csum; /* checksum */
346 uint16_t subsys; /* subsystem */
347 uint16_t dll_flags; /* more flags! */
348 uint64_t stack_size_req;/* amt of stack requested */
349 uint64_t stack_size; /* amt of stack required */
350 uint64_t heap_size_req; /* amt of heap requested */
351 uint64_t heap_size; /* amt of heap required */
352 uint32_t loader_flags; /* loader flags */
353 uint32_t data_dirs; /* number of data dir entries */
354};
355
356struct data_dirent {
357 uint32_t virtual_address; /* relative to load address */
358 uint32_t size;
359};
360
361struct data_directory {
362 struct data_dirent exports; /* .edata */
363 struct data_dirent imports; /* .idata */
364 struct data_dirent resources; /* .rsrc */
365 struct data_dirent exceptions; /* .pdata */
366 struct data_dirent certs; /* certs */
367 struct data_dirent base_relocations; /* .reloc */
368 struct data_dirent debug; /* .debug */
369 struct data_dirent arch; /* reservered */
370 struct data_dirent global_ptr; /* global pointer reg. Size=0 */
371 struct data_dirent tls; /* .tls */
372 struct data_dirent load_config; /* load configuration structure */
373 struct data_dirent bound_imports; /* bound import table */
374 struct data_dirent import_addrs; /* import address table */
375 struct data_dirent delay_imports; /* delay-load import table */
376 struct data_dirent clr_runtime_hdr; /* .cor (clr/.net executables) */
377 struct data_dirent reserved;
378};
379
380struct section_header {
381 char name[8]; /* name or "/12\0" string tbl offset */
382 uint32_t virtual_size; /* size of loaded section in ram */
383 uint32_t virtual_address; /* relative virtual address */
384 uint32_t raw_data_size; /* size of the section */
385 uint32_t data_addr; /* file pointer to first page of sec */
386 uint32_t relocs; /* file pointer to relocation entries */
387 uint32_t line_numbers; /* line numbers! */
388 uint16_t num_relocs; /* number of relocations */
389 uint16_t num_lin_numbers; /* srsly. */
390 uint32_t flags;
391};
392
393enum x64_coff_reloc_type {
394 IMAGE_REL_AMD64_ABSOLUTE = 0,
395 IMAGE_REL_AMD64_ADDR64,
396 IMAGE_REL_AMD64_ADDR32,
397 IMAGE_REL_AMD64_ADDR32N,
398 IMAGE_REL_AMD64_REL32,
399 IMAGE_REL_AMD64_REL32_1,
400 IMAGE_REL_AMD64_REL32_2,
401 IMAGE_REL_AMD64_REL32_3,
402 IMAGE_REL_AMD64_REL32_4,
403 IMAGE_REL_AMD64_REL32_5,
404 IMAGE_REL_AMD64_SECTION,
405 IMAGE_REL_AMD64_SECREL,
406 IMAGE_REL_AMD64_SECREL7,
407 IMAGE_REL_AMD64_TOKEN,
408 IMAGE_REL_AMD64_SREL32,
409 IMAGE_REL_AMD64_PAIR,
410 IMAGE_REL_AMD64_SSPAN32,
411};
412
413enum arm_coff_reloc_type {
414 IMAGE_REL_ARM_ABSOLUTE,
415 IMAGE_REL_ARM_ADDR32,
416 IMAGE_REL_ARM_ADDR32N,
417 IMAGE_REL_ARM_BRANCH2,
418 IMAGE_REL_ARM_BRANCH1,
419 IMAGE_REL_ARM_SECTION,
420 IMAGE_REL_ARM_SECREL,
421};
422
423enum sh_coff_reloc_type {
424 IMAGE_REL_SH3_ABSOLUTE,
425 IMAGE_REL_SH3_DIRECT16,
426 IMAGE_REL_SH3_DIRECT32,
427 IMAGE_REL_SH3_DIRECT8,
428 IMAGE_REL_SH3_DIRECT8_WORD,
429 IMAGE_REL_SH3_DIRECT8_LONG,
430 IMAGE_REL_SH3_DIRECT4,
431 IMAGE_REL_SH3_DIRECT4_WORD,
432 IMAGE_REL_SH3_DIRECT4_LONG,
433 IMAGE_REL_SH3_PCREL8_WORD,
434 IMAGE_REL_SH3_PCREL8_LONG,
435 IMAGE_REL_SH3_PCREL12_WORD,
436 IMAGE_REL_SH3_STARTOF_SECTION,
437 IMAGE_REL_SH3_SIZEOF_SECTION,
438 IMAGE_REL_SH3_SECTION,
439 IMAGE_REL_SH3_SECREL,
440 IMAGE_REL_SH3_DIRECT32_NB,
441 IMAGE_REL_SH3_GPREL4_LONG,
442 IMAGE_REL_SH3_TOKEN,
443 IMAGE_REL_SHM_PCRELPT,
444 IMAGE_REL_SHM_REFLO,
445 IMAGE_REL_SHM_REFHALF,
446 IMAGE_REL_SHM_RELLO,
447 IMAGE_REL_SHM_RELHALF,
448 IMAGE_REL_SHM_PAIR,
449 IMAGE_REL_SHM_NOMODE,
450};
451
452enum ppc_coff_reloc_type {
453 IMAGE_REL_PPC_ABSOLUTE,
454 IMAGE_REL_PPC_ADDR64,
455 IMAGE_REL_PPC_ADDR32,
456 IMAGE_REL_PPC_ADDR24,
457 IMAGE_REL_PPC_ADDR16,
458 IMAGE_REL_PPC_ADDR14,
459 IMAGE_REL_PPC_REL24,
460 IMAGE_REL_PPC_REL14,
461 IMAGE_REL_PPC_ADDR32N,
462 IMAGE_REL_PPC_SECREL,
463 IMAGE_REL_PPC_SECTION,
464 IMAGE_REL_PPC_SECREL16,
465 IMAGE_REL_PPC_REFHI,
466 IMAGE_REL_PPC_REFLO,
467 IMAGE_REL_PPC_PAIR,
468 IMAGE_REL_PPC_SECRELLO,
469 IMAGE_REL_PPC_GPREL,
470 IMAGE_REL_PPC_TOKEN,
471};
472
473enum x86_coff_reloc_type {
474 IMAGE_REL_I386_ABSOLUTE,
475 IMAGE_REL_I386_DIR16,
476 IMAGE_REL_I386_REL16,
477 IMAGE_REL_I386_DIR32,
478 IMAGE_REL_I386_DIR32NB,
479 IMAGE_REL_I386_SEG12,
480 IMAGE_REL_I386_SECTION,
481 IMAGE_REL_I386_SECREL,
482 IMAGE_REL_I386_TOKEN,
483 IMAGE_REL_I386_SECREL7,
484 IMAGE_REL_I386_REL32,
485};
486
487enum ia64_coff_reloc_type {
488 IMAGE_REL_IA64_ABSOLUTE,
489 IMAGE_REL_IA64_IMM14,
490 IMAGE_REL_IA64_IMM22,
491 IMAGE_REL_IA64_IMM64,
492 IMAGE_REL_IA64_DIR32,
493 IMAGE_REL_IA64_DIR64,
494 IMAGE_REL_IA64_PCREL21B,
495 IMAGE_REL_IA64_PCREL21M,
496 IMAGE_REL_IA64_PCREL21F,
497 IMAGE_REL_IA64_GPREL22,
498 IMAGE_REL_IA64_LTOFF22,
499 IMAGE_REL_IA64_SECTION,
500 IMAGE_REL_IA64_SECREL22,
501 IMAGE_REL_IA64_SECREL64I,
502 IMAGE_REL_IA64_SECREL32,
503 IMAGE_REL_IA64_DIR32NB,
504 IMAGE_REL_IA64_SREL14,
505 IMAGE_REL_IA64_SREL22,
506 IMAGE_REL_IA64_SREL32,
507 IMAGE_REL_IA64_UREL32,
508 IMAGE_REL_IA64_PCREL60X,
509 IMAGE_REL_IA64_PCREL60B,
510 IMAGE_REL_IA64_PCREL60F,
511 IMAGE_REL_IA64_PCREL60I,
512 IMAGE_REL_IA64_PCREL60M,
513 IMAGE_REL_IA64_IMMGPREL6,
514 IMAGE_REL_IA64_TOKEN,
515 IMAGE_REL_IA64_GPREL32,
516 IMAGE_REL_IA64_ADDEND,
517};
518
519struct coff_reloc {
520 uint32_t virtual_address;
521 uint32_t symbol_table_index;
522 union {
523 enum x64_coff_reloc_type x64_type;
524 enum arm_coff_reloc_type arm_type;
525 enum sh_coff_reloc_type sh_type;
526 enum ppc_coff_reloc_type ppc_type;
527 enum x86_coff_reloc_type x86_type;
528 enum ia64_coff_reloc_type ia64_type;
529 uint16_t data;
530 };
531};
532
533/*
534 * Definitions for the contents of the certs data block
535 */
536#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
537#define WIN_CERT_TYPE_EFI_OKCS115 0x0EF0
538#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
539
540#define WIN_CERT_REVISION_1_0 0x0100
541#define WIN_CERT_REVISION_2_0 0x0200
542
543struct win_certificate {
544 uint32_t length;
545 uint16_t revision;
546 uint16_t cert_type;
547};
548
549#endif /* !__ASSEMBLY__ */
550
551#endif /* __LINUX_PE_H */