xref: /linux-6.15/include/linux/pe.h (revision 36e4fc57)
12b72c9e3SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
29c87e0f1SDavid Howells /*
39c87e0f1SDavid Howells  * Copyright 2011 Red Hat, Inc.
49c87e0f1SDavid Howells  * All rights reserved.
59c87e0f1SDavid Howells  *
69c87e0f1SDavid Howells  * Author(s): Peter Jones <[email protected]>
79c87e0f1SDavid Howells  */
89c87e0f1SDavid Howells #ifndef __LINUX_PE_H
99c87e0f1SDavid Howells #define __LINUX_PE_H
109c87e0f1SDavid Howells 
119c87e0f1SDavid Howells #include <linux/types.h>
129c87e0f1SDavid Howells 
13dc235d62SArd Biesheuvel /*
14*36e4fc57SAkihiro Suda  * Starting from version v3.0, the major version field should be interpreted as
15*36e4fc57SAkihiro Suda  * a bit mask of features supported by the kernel's EFI stub:
16*36e4fc57SAkihiro Suda  * - 0x1: initrd loading from the LINUX_EFI_INITRD_MEDIA_GUID device path,
17*36e4fc57SAkihiro Suda  * - 0x2: initrd loading using the initrd= command line option, where the file
18*36e4fc57SAkihiro Suda  *        may be specified using device path notation, and is not required to
19*36e4fc57SAkihiro Suda  *        reside on the same volume as the loaded kernel image.
20dc235d62SArd Biesheuvel  *
21dc235d62SArd Biesheuvel  * The recommended way of loading and starting v1.0 or later kernels is to use
22dc235d62SArd Biesheuvel  * the LoadImage() and StartImage() EFI boot services, and expose the initrd
23dc235d62SArd Biesheuvel  * via the LINUX_EFI_INITRD_MEDIA_GUID device path.
24dc235d62SArd Biesheuvel  *
25*36e4fc57SAkihiro Suda  * Versions older than v1.0 may support initrd loading via the image load
26*36e4fc57SAkihiro Suda  * options (using initrd=, limited to the volume from which the kernel itself
27*36e4fc57SAkihiro Suda  * was loaded), or only via arch specific means (bootparams, DT, etc).
28dc235d62SArd Biesheuvel  *
29*36e4fc57SAkihiro Suda  * The minor version field must remain 0x0.
30*36e4fc57SAkihiro Suda  * (https://lore.kernel.org/all/[email protected]/)
31dc235d62SArd Biesheuvel  */
32*36e4fc57SAkihiro Suda #define LINUX_EFISTUB_MAJOR_VERSION		0x3
33*36e4fc57SAkihiro Suda #define LINUX_EFISTUB_MINOR_VERSION		0x0
34148d3f71SArd Biesheuvel 
3529636a5cSArd Biesheuvel /*
3629636a5cSArd Biesheuvel  * LINUX_PE_MAGIC appears at offset 0x38 into the MS-DOS header of EFI bootable
3729636a5cSArd Biesheuvel  * Linux kernel images that target the architecture as specified by the PE/COFF
3829636a5cSArd Biesheuvel  * header machine type field.
3929636a5cSArd Biesheuvel  */
4029636a5cSArd Biesheuvel #define LINUX_PE_MAGIC	0x818223cd
4129636a5cSArd Biesheuvel 
429c87e0f1SDavid Howells #define MZ_MAGIC	0x5a4d	/* "MZ" */
439c87e0f1SDavid Howells 
449c87e0f1SDavid Howells #define PE_MAGIC		0x00004550	/* "PE\0\0" */
459c87e0f1SDavid Howells #define PE_OPT_MAGIC_PE32	0x010b
469c87e0f1SDavid Howells #define PE_OPT_MAGIC_PE32_ROM	0x0107
479c87e0f1SDavid Howells #define PE_OPT_MAGIC_PE32PLUS	0x020b
489c87e0f1SDavid Howells 
499c87e0f1SDavid Howells /* machine type */
509c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_UNKNOWN	0x0000
519c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_AM33		0x01d3
529c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_AMD64	0x8664
539c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_ARM		0x01c0
549c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_ARMV7	0x01c4
556f5541baSMark Rutland #define	IMAGE_FILE_MACHINE_ARM64	0xaa64
569c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_EBC		0x0ebc
579c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_I386		0x014c
589c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_IA64		0x0200
599c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_M32R		0x9041
609c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_MIPS16	0x0266
619c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_MIPSFPU	0x0366
629c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_MIPSFPU16	0x0466
639c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_POWERPC	0x01f0
649c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_POWERPCFP	0x01f1
659c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_R4000	0x0166
666d0fd536SAtish Patra #define	IMAGE_FILE_MACHINE_RISCV32	0x5032
676d0fd536SAtish Patra #define	IMAGE_FILE_MACHINE_RISCV64	0x5064
686d0fd536SAtish Patra #define	IMAGE_FILE_MACHINE_RISCV128	0x5128
699c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_SH3		0x01a2
709c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_SH3DSP	0x01a3
719c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_SH3E		0x01a4
729c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_SH4		0x01a6
739c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_SH5		0x01a8
749c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_THUMB	0x01c2
759c87e0f1SDavid Howells #define	IMAGE_FILE_MACHINE_WCEMIPSV2	0x0169
76ead384d9SHuacai Chen #define	IMAGE_FILE_MACHINE_LOONGARCH32	0x6232
77ead384d9SHuacai Chen #define	IMAGE_FILE_MACHINE_LOONGARCH64	0x6264
789c87e0f1SDavid Howells 
799c87e0f1SDavid Howells /* flags */
809c87e0f1SDavid Howells #define IMAGE_FILE_RELOCS_STRIPPED           0x0001
819c87e0f1SDavid Howells #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002
829c87e0f1SDavid Howells #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004
839c87e0f1SDavid Howells #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008
849c87e0f1SDavid Howells #define IMAGE_FILE_AGGRESSIVE_WS_TRIM        0x0010
859c87e0f1SDavid Howells #define IMAGE_FILE_LARGE_ADDRESS_AWARE       0x0020
869c87e0f1SDavid Howells #define IMAGE_FILE_16BIT_MACHINE             0x0040
879c87e0f1SDavid Howells #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080
889c87e0f1SDavid Howells #define IMAGE_FILE_32BIT_MACHINE             0x0100
899c87e0f1SDavid Howells #define IMAGE_FILE_DEBUG_STRIPPED            0x0200
909c87e0f1SDavid Howells #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400
919c87e0f1SDavid Howells #define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800
929c87e0f1SDavid Howells #define IMAGE_FILE_SYSTEM                    0x1000
939c87e0f1SDavid Howells #define IMAGE_FILE_DLL                       0x2000
949c87e0f1SDavid Howells #define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000
959c87e0f1SDavid Howells #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000
969c87e0f1SDavid Howells 
979c87e0f1SDavid Howells #define IMAGE_FILE_OPT_ROM_MAGIC	0x107
989c87e0f1SDavid Howells #define IMAGE_FILE_OPT_PE32_MAGIC	0x10b
999c87e0f1SDavid Howells #define IMAGE_FILE_OPT_PE32_PLUS_MAGIC	0x20b
1009c87e0f1SDavid Howells 
1019c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_UNKNOWN			 0
1029c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_NATIVE			 1
1039c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_WINDOWS_GUI		 2
1049c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_WINDOWS_CUI		 3
1059c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_POSIX_CUI		 7
1069c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI		 9
1079c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_EFI_APPLICATION		10
1089c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER	11
1099c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER	12
1109c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE		13
1119c87e0f1SDavid Howells #define IMAGE_SUBSYSTEM_XBOX			14
1129c87e0f1SDavid Howells 
1139c87e0f1SDavid Howells #define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE          0x0040
1149c87e0f1SDavid Howells #define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY       0x0080
1159c87e0f1SDavid Howells #define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT             0x0100
1169c87e0f1SDavid Howells #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION           0x0200
1179c87e0f1SDavid Howells #define IMAGE_DLLCHARACTERISTICS_NO_SEH                 0x0400
1189c87e0f1SDavid Howells #define IMAGE_DLLCHARACTERISTICS_NO_BIND                0x0800
1199c87e0f1SDavid Howells #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER             0x2000
1209c87e0f1SDavid Howells #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE  0x8000
1219c87e0f1SDavid Howells 
12203858557SArd Biesheuvel #define IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT		0x0001
12303858557SArd Biesheuvel #define IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT	0x0040
12403858557SArd Biesheuvel 
12565c2e69bSMark Rutland /* they actually defined 0x00000000 as well, but I think we'll skip that one. */
12665c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_0	0x00000001
12765c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_1	0x00000002
12865c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_2	0x00000004
12965c2e69bSMark Rutland #define IMAGE_SCN_TYPE_NO_PAD	0x00000008 /* don't pad - obsolete */
13065c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_3	0x00000010
13165c2e69bSMark Rutland #define IMAGE_SCN_CNT_CODE	0x00000020 /* .text */
13265c2e69bSMark Rutland #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* .data */
13365c2e69bSMark Rutland #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* .bss */
13465c2e69bSMark Rutland #define IMAGE_SCN_LNK_OTHER	0x00000100 /* reserved */
13565c2e69bSMark Rutland #define IMAGE_SCN_LNK_INFO	0x00000200 /* .drectve comments */
13665c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_4	0x00000400
13765c2e69bSMark Rutland #define IMAGE_SCN_LNK_REMOVE	0x00000800 /* .o only - scn to be rm'd*/
13865c2e69bSMark Rutland #define IMAGE_SCN_LNK_COMDAT	0x00001000 /* .o only - COMDAT data */
13965c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_5	0x00002000 /* spec omits this */
14065c2e69bSMark Rutland #define IMAGE_SCN_RESERVED_6	0x00004000 /* spec omits this */
14165c2e69bSMark Rutland #define IMAGE_SCN_GPREL		0x00008000 /* global pointer referenced data */
14265c2e69bSMark Rutland /* spec lists 0x20000 twice, I suspect they meant 0x10000 for one of them */
14365c2e69bSMark Rutland #define IMAGE_SCN_MEM_PURGEABLE	0x00010000 /* reserved for "future" use */
14465c2e69bSMark Rutland #define IMAGE_SCN_16BIT		0x00020000 /* reserved for "future" use */
14565c2e69bSMark Rutland #define IMAGE_SCN_LOCKED	0x00040000 /* reserved for "future" use */
14665c2e69bSMark Rutland #define IMAGE_SCN_PRELOAD	0x00080000 /* reserved for "future" use */
14765c2e69bSMark Rutland /* and here they just stuck a 1-byte integer in the middle of a bitfield */
14865c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_1BYTES	0x00100000 /* it does what it says on the box */
14965c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_2BYTES	0x00200000
15065c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_4BYTES	0x00300000
15165c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_8BYTES	0x00400000
15265c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_16BYTES	0x00500000
15365c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_32BYTES	0x00600000
15465c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_64BYTES	0x00700000
15565c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_128BYTES 0x00800000
15665c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_256BYTES 0x00900000
15765c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_512BYTES 0x00a00000
15865c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000
15965c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000
16065c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000
16165c2e69bSMark Rutland #define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000
16265c2e69bSMark Rutland #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* extended relocations */
16365c2e69bSMark Rutland #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* scn can be discarded */
16465c2e69bSMark Rutland #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* cannot be cached */
16565c2e69bSMark Rutland #define IMAGE_SCN_MEM_NOT_PAGED	0x08000000 /* not pageable */
16665c2e69bSMark Rutland #define IMAGE_SCN_MEM_SHARED	0x10000000 /* can be shared */
16765c2e69bSMark Rutland #define IMAGE_SCN_MEM_EXECUTE	0x20000000 /* can be executed as code */
16865c2e69bSMark Rutland #define IMAGE_SCN_MEM_READ	0x40000000 /* readable */
16965c2e69bSMark Rutland #define IMAGE_SCN_MEM_WRITE	0x80000000 /* writeable */
17065c2e69bSMark Rutland 
1716f5541baSMark Rutland #define IMAGE_DEBUG_TYPE_CODEVIEW	2
17203858557SArd Biesheuvel #define IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS	20
1736f5541baSMark Rutland 
17465c2e69bSMark Rutland #ifndef __ASSEMBLY__
17565c2e69bSMark Rutland 
17665c2e69bSMark Rutland struct mz_hdr {
17765c2e69bSMark Rutland 	uint16_t magic;		/* MZ_MAGIC */
17865c2e69bSMark Rutland 	uint16_t lbsize;	/* size of last used block */
17965c2e69bSMark Rutland 	uint16_t blocks;	/* pages in file, 0x3 */
18065c2e69bSMark Rutland 	uint16_t relocs;	/* relocations */
18165c2e69bSMark Rutland 	uint16_t hdrsize;	/* header size in "paragraphs" */
18265c2e69bSMark Rutland 	uint16_t min_extra_pps;	/* .bss */
18365c2e69bSMark Rutland 	uint16_t max_extra_pps;	/* runtime limit for the arena size */
18465c2e69bSMark Rutland 	uint16_t ss;		/* relative stack segment */
18565c2e69bSMark Rutland 	uint16_t sp;		/* initial %sp register */
18665c2e69bSMark Rutland 	uint16_t checksum;	/* word checksum */
18765c2e69bSMark Rutland 	uint16_t ip;		/* initial %ip register */
18865c2e69bSMark Rutland 	uint16_t cs;		/* initial %cs relative to load segment */
18965c2e69bSMark Rutland 	uint16_t reloc_table_offset;	/* offset of the first relocation */
19065c2e69bSMark Rutland 	uint16_t overlay_num;	/* overlay number.  set to 0. */
19165c2e69bSMark Rutland 	uint16_t reserved0[4];	/* reserved */
19265c2e69bSMark Rutland 	uint16_t oem_id;	/* oem identifier */
19365c2e69bSMark Rutland 	uint16_t oem_info;	/* oem specific */
19465c2e69bSMark Rutland 	uint16_t reserved1[10];	/* reserved */
19565c2e69bSMark Rutland 	uint32_t peaddr;	/* address of pe header */
196702ed5bbSAKASHI Takahiro 	char     message[];	/* message to print */
19765c2e69bSMark Rutland };
19865c2e69bSMark Rutland 
19965c2e69bSMark Rutland struct mz_reloc {
20065c2e69bSMark Rutland 	uint16_t offset;
20165c2e69bSMark Rutland 	uint16_t segment;
20265c2e69bSMark Rutland };
20365c2e69bSMark Rutland 
20465c2e69bSMark Rutland struct pe_hdr {
20565c2e69bSMark Rutland 	uint32_t magic;		/* PE magic */
20665c2e69bSMark Rutland 	uint16_t machine;	/* machine type */
20765c2e69bSMark Rutland 	uint16_t sections;	/* number of sections */
20865c2e69bSMark Rutland 	uint32_t timestamp;	/* time_t */
20965c2e69bSMark Rutland 	uint32_t symbol_table;	/* symbol table offset */
21065c2e69bSMark Rutland 	uint32_t symbols;	/* number of symbols */
21165c2e69bSMark Rutland 	uint16_t opt_hdr_size;	/* size of optional header */
21265c2e69bSMark Rutland 	uint16_t flags;		/* flags */
21365c2e69bSMark Rutland };
21465c2e69bSMark Rutland 
2159c87e0f1SDavid Howells /* the fact that pe32 isn't padded where pe32+ is 64-bit means union won't
2169c87e0f1SDavid Howells  * work right.  vomit. */
2179c87e0f1SDavid Howells struct pe32_opt_hdr {
2189c87e0f1SDavid Howells 	/* "standard" header */
2199c87e0f1SDavid Howells 	uint16_t magic;		/* file type */
2209c87e0f1SDavid Howells 	uint8_t  ld_major;	/* linker major version */
2219c87e0f1SDavid Howells 	uint8_t  ld_minor;	/* linker minor version */
2229c87e0f1SDavid Howells 	uint32_t text_size;	/* size of text section(s) */
2239c87e0f1SDavid Howells 	uint32_t data_size;	/* size of data section(s) */
2249c87e0f1SDavid Howells 	uint32_t bss_size;	/* size of bss section(s) */
2259c87e0f1SDavid Howells 	uint32_t entry_point;	/* file offset of entry point */
2269c87e0f1SDavid Howells 	uint32_t code_base;	/* relative code addr in ram */
2279c87e0f1SDavid Howells 	uint32_t data_base;	/* relative data addr in ram */
2289c87e0f1SDavid Howells 	/* "windows" header */
2299c87e0f1SDavid Howells 	uint32_t image_base;	/* preferred load address */
2309c87e0f1SDavid Howells 	uint32_t section_align;	/* alignment in bytes */
2319c87e0f1SDavid Howells 	uint32_t file_align;	/* file alignment in bytes */
2329c87e0f1SDavid Howells 	uint16_t os_major;	/* major OS version */
2339c87e0f1SDavid Howells 	uint16_t os_minor;	/* minor OS version */
2349c87e0f1SDavid Howells 	uint16_t image_major;	/* major image version */
2359c87e0f1SDavid Howells 	uint16_t image_minor;	/* minor image version */
2369c87e0f1SDavid Howells 	uint16_t subsys_major;	/* major subsystem version */
2379c87e0f1SDavid Howells 	uint16_t subsys_minor;	/* minor subsystem version */
2389c87e0f1SDavid Howells 	uint32_t win32_version;	/* reserved, must be 0 */
2399c87e0f1SDavid Howells 	uint32_t image_size;	/* image size */
2409c87e0f1SDavid Howells 	uint32_t header_size;	/* header size rounded up to
2419c87e0f1SDavid Howells 				   file_align */
2429c87e0f1SDavid Howells 	uint32_t csum;		/* checksum */
2439c87e0f1SDavid Howells 	uint16_t subsys;	/* subsystem */
2449c87e0f1SDavid Howells 	uint16_t dll_flags;	/* more flags! */
2459c87e0f1SDavid Howells 	uint32_t stack_size_req;/* amt of stack requested */
2469c87e0f1SDavid Howells 	uint32_t stack_size;	/* amt of stack required */
2479c87e0f1SDavid Howells 	uint32_t heap_size_req;	/* amt of heap requested */
2489c87e0f1SDavid Howells 	uint32_t heap_size;	/* amt of heap required */
2499c87e0f1SDavid Howells 	uint32_t loader_flags;	/* reserved, must be 0 */
2509c87e0f1SDavid Howells 	uint32_t data_dirs;	/* number of data dir entries */
2519c87e0f1SDavid Howells };
2529c87e0f1SDavid Howells 
2539c87e0f1SDavid Howells struct pe32plus_opt_hdr {
2549c87e0f1SDavid Howells 	uint16_t magic;		/* file type */
2559c87e0f1SDavid Howells 	uint8_t  ld_major;	/* linker major version */
2569c87e0f1SDavid Howells 	uint8_t  ld_minor;	/* linker minor version */
2579c87e0f1SDavid Howells 	uint32_t text_size;	/* size of text section(s) */
2589c87e0f1SDavid Howells 	uint32_t data_size;	/* size of data section(s) */
2599c87e0f1SDavid Howells 	uint32_t bss_size;	/* size of bss section(s) */
2609c87e0f1SDavid Howells 	uint32_t entry_point;	/* file offset of entry point */
2619c87e0f1SDavid Howells 	uint32_t code_base;	/* relative code addr in ram */
2629c87e0f1SDavid Howells 	/* "windows" header */
2639c87e0f1SDavid Howells 	uint64_t image_base;	/* preferred load address */
2649c87e0f1SDavid Howells 	uint32_t section_align;	/* alignment in bytes */
2659c87e0f1SDavid Howells 	uint32_t file_align;	/* file alignment in bytes */
2669c87e0f1SDavid Howells 	uint16_t os_major;	/* major OS version */
2679c87e0f1SDavid Howells 	uint16_t os_minor;	/* minor OS version */
2689c87e0f1SDavid Howells 	uint16_t image_major;	/* major image version */
2699c87e0f1SDavid Howells 	uint16_t image_minor;	/* minor image version */
2709c87e0f1SDavid Howells 	uint16_t subsys_major;	/* major subsystem version */
2719c87e0f1SDavid Howells 	uint16_t subsys_minor;	/* minor subsystem version */
2729c87e0f1SDavid Howells 	uint32_t win32_version;	/* reserved, must be 0 */
2739c87e0f1SDavid Howells 	uint32_t image_size;	/* image size */
2749c87e0f1SDavid Howells 	uint32_t header_size;	/* header size rounded up to
2759c87e0f1SDavid Howells 				   file_align */
2769c87e0f1SDavid Howells 	uint32_t csum;		/* checksum */
2779c87e0f1SDavid Howells 	uint16_t subsys;	/* subsystem */
2789c87e0f1SDavid Howells 	uint16_t dll_flags;	/* more flags! */
2799c87e0f1SDavid Howells 	uint64_t stack_size_req;/* amt of stack requested */
2809c87e0f1SDavid Howells 	uint64_t stack_size;	/* amt of stack required */
2819c87e0f1SDavid Howells 	uint64_t heap_size_req;	/* amt of heap requested */
2829c87e0f1SDavid Howells 	uint64_t heap_size;	/* amt of heap required */
2839c87e0f1SDavid Howells 	uint32_t loader_flags;	/* reserved, must be 0 */
2849c87e0f1SDavid Howells 	uint32_t data_dirs;	/* number of data dir entries */
2859c87e0f1SDavid Howells };
2869c87e0f1SDavid Howells 
2879c87e0f1SDavid Howells struct data_dirent {
2889c87e0f1SDavid Howells 	uint32_t virtual_address;	/* relative to load address */
2899c87e0f1SDavid Howells 	uint32_t size;
2909c87e0f1SDavid Howells };
2919c87e0f1SDavid Howells 
2929c87e0f1SDavid Howells struct data_directory {
2939c87e0f1SDavid Howells 	struct data_dirent exports;		/* .edata */
2949c87e0f1SDavid Howells 	struct data_dirent imports;		/* .idata */
2959c87e0f1SDavid Howells 	struct data_dirent resources;		/* .rsrc */
2969c87e0f1SDavid Howells 	struct data_dirent exceptions;		/* .pdata */
2979c87e0f1SDavid Howells 	struct data_dirent certs;		/* certs */
2989c87e0f1SDavid Howells 	struct data_dirent base_relocations;	/* .reloc */
2999c87e0f1SDavid Howells 	struct data_dirent debug;		/* .debug */
3009c87e0f1SDavid Howells 	struct data_dirent arch;		/* reservered */
3019c87e0f1SDavid Howells 	struct data_dirent global_ptr;		/* global pointer reg. Size=0 */
3029c87e0f1SDavid Howells 	struct data_dirent tls;			/* .tls */
3039c87e0f1SDavid Howells 	struct data_dirent load_config;		/* load configuration structure */
3049c87e0f1SDavid Howells 	struct data_dirent bound_imports;	/* no idea */
3059c87e0f1SDavid Howells 	struct data_dirent import_addrs;	/* import address table */
3069c87e0f1SDavid Howells 	struct data_dirent delay_imports;	/* delay-load import table */
3079c87e0f1SDavid Howells 	struct data_dirent clr_runtime_hdr;	/* .cor (object only) */
3089c87e0f1SDavid Howells 	struct data_dirent reserved;
3099c87e0f1SDavid Howells };
3109c87e0f1SDavid Howells 
3119c87e0f1SDavid Howells struct section_header {
3129c87e0f1SDavid Howells 	char name[8];			/* name or "/12\0" string tbl offset */
3139c87e0f1SDavid Howells 	uint32_t virtual_size;		/* size of loaded section in ram */
3149c87e0f1SDavid Howells 	uint32_t virtual_address;	/* relative virtual address */
3159c87e0f1SDavid Howells 	uint32_t raw_data_size;		/* size of the section */
3169c87e0f1SDavid Howells 	uint32_t data_addr;		/* file pointer to first page of sec */
3179c87e0f1SDavid Howells 	uint32_t relocs;		/* file pointer to relocation entries */
3189c87e0f1SDavid Howells 	uint32_t line_numbers;		/* line numbers! */
3199c87e0f1SDavid Howells 	uint16_t num_relocs;		/* number of relocations */
3209c87e0f1SDavid Howells 	uint16_t num_lin_numbers;	/* srsly. */
3219c87e0f1SDavid Howells 	uint32_t flags;
3229c87e0f1SDavid Howells };
3239c87e0f1SDavid Howells 
3249c87e0f1SDavid Howells enum x64_coff_reloc_type {
3259c87e0f1SDavid Howells 	IMAGE_REL_AMD64_ABSOLUTE = 0,
3269c87e0f1SDavid Howells 	IMAGE_REL_AMD64_ADDR64,
3279c87e0f1SDavid Howells 	IMAGE_REL_AMD64_ADDR32,
3289c87e0f1SDavid Howells 	IMAGE_REL_AMD64_ADDR32N,
3299c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32,
3309c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32_1,
3319c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32_2,
3329c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32_3,
3339c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32_4,
3349c87e0f1SDavid Howells 	IMAGE_REL_AMD64_REL32_5,
3359c87e0f1SDavid Howells 	IMAGE_REL_AMD64_SECTION,
3369c87e0f1SDavid Howells 	IMAGE_REL_AMD64_SECREL,
3379c87e0f1SDavid Howells 	IMAGE_REL_AMD64_SECREL7,
3389c87e0f1SDavid Howells 	IMAGE_REL_AMD64_TOKEN,
3399c87e0f1SDavid Howells 	IMAGE_REL_AMD64_SREL32,
3409c87e0f1SDavid Howells 	IMAGE_REL_AMD64_PAIR,
3419c87e0f1SDavid Howells 	IMAGE_REL_AMD64_SSPAN32,
3429c87e0f1SDavid Howells };
3439c87e0f1SDavid Howells 
3449c87e0f1SDavid Howells enum arm_coff_reloc_type {
3459c87e0f1SDavid Howells 	IMAGE_REL_ARM_ABSOLUTE,
3469c87e0f1SDavid Howells 	IMAGE_REL_ARM_ADDR32,
3479c87e0f1SDavid Howells 	IMAGE_REL_ARM_ADDR32N,
3489c87e0f1SDavid Howells 	IMAGE_REL_ARM_BRANCH2,
3499c87e0f1SDavid Howells 	IMAGE_REL_ARM_BRANCH1,
3509c87e0f1SDavid Howells 	IMAGE_REL_ARM_SECTION,
3519c87e0f1SDavid Howells 	IMAGE_REL_ARM_SECREL,
3529c87e0f1SDavid Howells };
3539c87e0f1SDavid Howells 
3549c87e0f1SDavid Howells enum sh_coff_reloc_type {
3559c87e0f1SDavid Howells 	IMAGE_REL_SH3_ABSOLUTE,
3569c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT16,
3579c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT32,
3589c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT8,
3599c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT8_WORD,
3609c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT8_LONG,
3619c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT4,
3629c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT4_WORD,
3639c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT4_LONG,
3649c87e0f1SDavid Howells 	IMAGE_REL_SH3_PCREL8_WORD,
3659c87e0f1SDavid Howells 	IMAGE_REL_SH3_PCREL8_LONG,
3669c87e0f1SDavid Howells 	IMAGE_REL_SH3_PCREL12_WORD,
3679c87e0f1SDavid Howells 	IMAGE_REL_SH3_STARTOF_SECTION,
3689c87e0f1SDavid Howells 	IMAGE_REL_SH3_SIZEOF_SECTION,
3699c87e0f1SDavid Howells 	IMAGE_REL_SH3_SECTION,
3709c87e0f1SDavid Howells 	IMAGE_REL_SH3_SECREL,
3719c87e0f1SDavid Howells 	IMAGE_REL_SH3_DIRECT32_NB,
3729c87e0f1SDavid Howells 	IMAGE_REL_SH3_GPREL4_LONG,
3739c87e0f1SDavid Howells 	IMAGE_REL_SH3_TOKEN,
3749c87e0f1SDavid Howells 	IMAGE_REL_SHM_PCRELPT,
3759c87e0f1SDavid Howells 	IMAGE_REL_SHM_REFLO,
3769c87e0f1SDavid Howells 	IMAGE_REL_SHM_REFHALF,
3779c87e0f1SDavid Howells 	IMAGE_REL_SHM_RELLO,
3789c87e0f1SDavid Howells 	IMAGE_REL_SHM_RELHALF,
3799c87e0f1SDavid Howells 	IMAGE_REL_SHM_PAIR,
3809c87e0f1SDavid Howells 	IMAGE_REL_SHM_NOMODE,
3819c87e0f1SDavid Howells };
3829c87e0f1SDavid Howells 
3839c87e0f1SDavid Howells enum ppc_coff_reloc_type {
3849c87e0f1SDavid Howells 	IMAGE_REL_PPC_ABSOLUTE,
3859c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR64,
3869c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR32,
3879c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR24,
3889c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR16,
3899c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR14,
3909c87e0f1SDavid Howells 	IMAGE_REL_PPC_REL24,
3919c87e0f1SDavid Howells 	IMAGE_REL_PPC_REL14,
3929c87e0f1SDavid Howells 	IMAGE_REL_PPC_ADDR32N,
3939c87e0f1SDavid Howells 	IMAGE_REL_PPC_SECREL,
3949c87e0f1SDavid Howells 	IMAGE_REL_PPC_SECTION,
3959c87e0f1SDavid Howells 	IMAGE_REL_PPC_SECREL16,
3969c87e0f1SDavid Howells 	IMAGE_REL_PPC_REFHI,
3979c87e0f1SDavid Howells 	IMAGE_REL_PPC_REFLO,
3989c87e0f1SDavid Howells 	IMAGE_REL_PPC_PAIR,
3999c87e0f1SDavid Howells 	IMAGE_REL_PPC_SECRELLO,
4009c87e0f1SDavid Howells 	IMAGE_REL_PPC_GPREL,
4019c87e0f1SDavid Howells 	IMAGE_REL_PPC_TOKEN,
4029c87e0f1SDavid Howells };
4039c87e0f1SDavid Howells 
4049c87e0f1SDavid Howells enum x86_coff_reloc_type {
4059c87e0f1SDavid Howells 	IMAGE_REL_I386_ABSOLUTE,
4069c87e0f1SDavid Howells 	IMAGE_REL_I386_DIR16,
4079c87e0f1SDavid Howells 	IMAGE_REL_I386_REL16,
4089c87e0f1SDavid Howells 	IMAGE_REL_I386_DIR32,
4099c87e0f1SDavid Howells 	IMAGE_REL_I386_DIR32NB,
4109c87e0f1SDavid Howells 	IMAGE_REL_I386_SEG12,
4119c87e0f1SDavid Howells 	IMAGE_REL_I386_SECTION,
4129c87e0f1SDavid Howells 	IMAGE_REL_I386_SECREL,
4139c87e0f1SDavid Howells 	IMAGE_REL_I386_TOKEN,
4149c87e0f1SDavid Howells 	IMAGE_REL_I386_SECREL7,
4159c87e0f1SDavid Howells 	IMAGE_REL_I386_REL32,
4169c87e0f1SDavid Howells };
4179c87e0f1SDavid Howells 
4189c87e0f1SDavid Howells enum ia64_coff_reloc_type {
4199c87e0f1SDavid Howells 	IMAGE_REL_IA64_ABSOLUTE,
4209c87e0f1SDavid Howells 	IMAGE_REL_IA64_IMM14,
4219c87e0f1SDavid Howells 	IMAGE_REL_IA64_IMM22,
4229c87e0f1SDavid Howells 	IMAGE_REL_IA64_IMM64,
4239c87e0f1SDavid Howells 	IMAGE_REL_IA64_DIR32,
4249c87e0f1SDavid Howells 	IMAGE_REL_IA64_DIR64,
4259c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL21B,
4269c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL21M,
4279c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL21F,
4289c87e0f1SDavid Howells 	IMAGE_REL_IA64_GPREL22,
4299c87e0f1SDavid Howells 	IMAGE_REL_IA64_LTOFF22,
4309c87e0f1SDavid Howells 	IMAGE_REL_IA64_SECTION,
4319c87e0f1SDavid Howells 	IMAGE_REL_IA64_SECREL22,
4329c87e0f1SDavid Howells 	IMAGE_REL_IA64_SECREL64I,
4339c87e0f1SDavid Howells 	IMAGE_REL_IA64_SECREL32,
4349c87e0f1SDavid Howells 	IMAGE_REL_IA64_DIR32NB,
4359c87e0f1SDavid Howells 	IMAGE_REL_IA64_SREL14,
4369c87e0f1SDavid Howells 	IMAGE_REL_IA64_SREL22,
4379c87e0f1SDavid Howells 	IMAGE_REL_IA64_SREL32,
4389c87e0f1SDavid Howells 	IMAGE_REL_IA64_UREL32,
4399c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL60X,
4409c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL60B,
4419c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL60F,
4429c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL60I,
4439c87e0f1SDavid Howells 	IMAGE_REL_IA64_PCREL60M,
4449c87e0f1SDavid Howells 	IMAGE_REL_IA64_IMMGPREL6,
4459c87e0f1SDavid Howells 	IMAGE_REL_IA64_TOKEN,
4469c87e0f1SDavid Howells 	IMAGE_REL_IA64_GPREL32,
4479c87e0f1SDavid Howells 	IMAGE_REL_IA64_ADDEND,
4489c87e0f1SDavid Howells };
4499c87e0f1SDavid Howells 
4509c87e0f1SDavid Howells struct coff_reloc {
4519c87e0f1SDavid Howells 	uint32_t virtual_address;
4529c87e0f1SDavid Howells 	uint32_t symbol_table_index;
4539c87e0f1SDavid Howells 	union {
4549c87e0f1SDavid Howells 		enum x64_coff_reloc_type  x64_type;
4559c87e0f1SDavid Howells 		enum arm_coff_reloc_type  arm_type;
4569c87e0f1SDavid Howells 		enum sh_coff_reloc_type   sh_type;
4579c87e0f1SDavid Howells 		enum ppc_coff_reloc_type  ppc_type;
4589c87e0f1SDavid Howells 		enum x86_coff_reloc_type  x86_type;
4599c87e0f1SDavid Howells 		enum ia64_coff_reloc_type ia64_type;
4609c87e0f1SDavid Howells 		uint16_t data;
4619c87e0f1SDavid Howells 	};
4629c87e0f1SDavid Howells };
4639c87e0f1SDavid Howells 
4649c87e0f1SDavid Howells /*
4659c87e0f1SDavid Howells  * Definitions for the contents of the certs data block
4669c87e0f1SDavid Howells  */
4679c87e0f1SDavid Howells #define WIN_CERT_TYPE_PKCS_SIGNED_DATA	0x0002
4689c87e0f1SDavid Howells #define WIN_CERT_TYPE_EFI_OKCS115	0x0EF0
4699c87e0f1SDavid Howells #define WIN_CERT_TYPE_EFI_GUID		0x0EF1
4709c87e0f1SDavid Howells 
4719c87e0f1SDavid Howells #define WIN_CERT_REVISION_1_0	0x0100
4729c87e0f1SDavid Howells #define WIN_CERT_REVISION_2_0	0x0200
4739c87e0f1SDavid Howells 
4749c87e0f1SDavid Howells struct win_certificate {
4759c87e0f1SDavid Howells 	uint32_t length;
4769c87e0f1SDavid Howells 	uint16_t revision;
4779c87e0f1SDavid Howells 	uint16_t cert_type;
4789c87e0f1SDavid Howells };
4799c87e0f1SDavid Howells 
48065c2e69bSMark Rutland #endif /* !__ASSEMBLY__ */
48165c2e69bSMark Rutland 
4829c87e0f1SDavid Howells #endif /* __LINUX_PE_H */
483