1a0509109SArd Biesheuvel/* SPDX-License-Identifier: GPL-2.0 */ 2a0509109SArd Biesheuvel 3a0509109SArd Biesheuvel#include <linux/pe.h> 4a0509109SArd Biesheuvel 5a0509109SArd Biesheuvel#ifdef CONFIG_64BIT 6a0509109SArd Biesheuvel .set .Lextra_characteristics, 0x0 7a0509109SArd Biesheuvel .set .Lpe_opt_magic, PE_OPT_MAGIC_PE32PLUS 8a0509109SArd Biesheuvel#else 9a0509109SArd Biesheuvel .set .Lextra_characteristics, IMAGE_FILE_32BIT_MACHINE 10a0509109SArd Biesheuvel .set .Lpe_opt_magic, PE_OPT_MAGIC_PE32 11a0509109SArd Biesheuvel#endif 12a0509109SArd Biesheuvel 13a0509109SArd Biesheuvel .section ".head", "a" 14a0509109SArd Biesheuvel .globl __efistub_efi_zboot_header 15a0509109SArd Biesheuvel__efistub_efi_zboot_header: 16a0509109SArd Biesheuvel.Ldoshdr: 17a0509109SArd Biesheuvel .long MZ_MAGIC 18a0509109SArd Biesheuvel .ascii "zimg" // image type 19a0509109SArd Biesheuvel .long __efistub__gzdata_start - .Ldoshdr // payload offset 20bca2f3a9SArd Biesheuvel .long __efistub__gzdata_size - ZBOOT_SIZE_LEN // payload size 21a0509109SArd Biesheuvel .long 0, 0 // reserved 22a0509109SArd Biesheuvel .asciz COMP_TYPE // compression type 2329636a5cSArd Biesheuvel .org .Ldoshdr + 0x38 2429636a5cSArd Biesheuvel .long LINUX_PE_MAGIC 25a0509109SArd Biesheuvel .long .Lpehdr - .Ldoshdr // PE header offset 26a0509109SArd Biesheuvel 27a0509109SArd Biesheuvel.Lpehdr: 28a0509109SArd Biesheuvel .long PE_MAGIC 29a0509109SArd Biesheuvel .short MACHINE_TYPE 30a0509109SArd Biesheuvel .short .Lsection_count 31a0509109SArd Biesheuvel .long 0 32a0509109SArd Biesheuvel .long 0 33a0509109SArd Biesheuvel .long 0 34a0509109SArd Biesheuvel .short .Lsection_table - .Loptional_header 35a0509109SArd Biesheuvel .short IMAGE_FILE_DEBUG_STRIPPED | \ 36a0509109SArd Biesheuvel IMAGE_FILE_EXECUTABLE_IMAGE | \ 37a0509109SArd Biesheuvel IMAGE_FILE_LINE_NUMS_STRIPPED |\ 38a0509109SArd Biesheuvel .Lextra_characteristics 39a0509109SArd Biesheuvel 40a0509109SArd Biesheuvel.Loptional_header: 41a0509109SArd Biesheuvel .short .Lpe_opt_magic 42a0509109SArd Biesheuvel .byte 0, 0 43a0509109SArd Biesheuvel .long _etext - .Lefi_header_end 44a0509109SArd Biesheuvel .long __data_size 45a0509109SArd Biesheuvel .long 0 46a0509109SArd Biesheuvel .long __efistub_efi_zboot_entry - .Ldoshdr 47a0509109SArd Biesheuvel .long .Lefi_header_end - .Ldoshdr 48a0509109SArd Biesheuvel 49a0509109SArd Biesheuvel#ifdef CONFIG_64BIT 50a0509109SArd Biesheuvel .quad 0 51a0509109SArd Biesheuvel#else 52a0509109SArd Biesheuvel .long _etext - .Ldoshdr, 0x0 53a0509109SArd Biesheuvel#endif 54a0509109SArd Biesheuvel .long 4096 55a0509109SArd Biesheuvel .long 512 56a0509109SArd Biesheuvel .short 0, 0 57a0509109SArd Biesheuvel .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion 58a0509109SArd Biesheuvel .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion 59a0509109SArd Biesheuvel .short 0, 0 60a0509109SArd Biesheuvel .long 0 61a0509109SArd Biesheuvel .long _end - .Ldoshdr 62a0509109SArd Biesheuvel 63a0509109SArd Biesheuvel .long .Lefi_header_end - .Ldoshdr 64a0509109SArd Biesheuvel .long 0 65a0509109SArd Biesheuvel .short IMAGE_SUBSYSTEM_EFI_APPLICATION 66c7d9e628SArd Biesheuvel .short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 67a0509109SArd Biesheuvel#ifdef CONFIG_64BIT 68a0509109SArd Biesheuvel .quad 0, 0, 0, 0 69a0509109SArd Biesheuvel#else 70a0509109SArd Biesheuvel .long 0, 0, 0, 0 71a0509109SArd Biesheuvel#endif 72a0509109SArd Biesheuvel .long 0 73a0509109SArd Biesheuvel .long (.Lsection_table - .) / 8 74a0509109SArd Biesheuvel 75a0509109SArd Biesheuvel .quad 0 // ExportTable 76a0509109SArd Biesheuvel .quad 0 // ImportTable 77a0509109SArd Biesheuvel .quad 0 // ResourceTable 78a0509109SArd Biesheuvel .quad 0 // ExceptionTable 79a0509109SArd Biesheuvel .quad 0 // CertificationTable 80a0509109SArd Biesheuvel .quad 0 // BaseRelocationTable 81*538bc0f4SArd Biesheuvel#if defined(PE_DLL_CHAR_EX) || defined(CONFIG_DEBUG_EFI) 82a0509109SArd Biesheuvel .long .Lefi_debug_table - .Ldoshdr // DebugTable 83a0509109SArd Biesheuvel .long .Lefi_debug_table_size 84*538bc0f4SArd Biesheuvel 85*538bc0f4SArd Biesheuvel .section ".rodata", "a" 86*538bc0f4SArd Biesheuvel .p2align 2 87*538bc0f4SArd Biesheuvel.Lefi_debug_table: 88*538bc0f4SArd Biesheuvel // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY[] 89*538bc0f4SArd Biesheuvel#ifdef PE_DLL_CHAR_EX 90*538bc0f4SArd Biesheuvel .long 0 // Characteristics 91*538bc0f4SArd Biesheuvel .long 0 // TimeDateStamp 92*538bc0f4SArd Biesheuvel .short 0 // MajorVersion 93*538bc0f4SArd Biesheuvel .short 0 // MinorVersion 94*538bc0f4SArd Biesheuvel .long IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS // Type 95*538bc0f4SArd Biesheuvel .long 4 // SizeOfData 96*538bc0f4SArd Biesheuvel .long 0 // RVA 97*538bc0f4SArd Biesheuvel .long .Lefi_dll_characteristics_ex - .Ldoshdr // FileOffset 98*538bc0f4SArd Biesheuvel#endif 99*538bc0f4SArd Biesheuvel#ifdef CONFIG_DEBUG_EFI 100*538bc0f4SArd Biesheuvel .long 0 // Characteristics 101*538bc0f4SArd Biesheuvel .long 0 // TimeDateStamp 102*538bc0f4SArd Biesheuvel .short 0 // MajorVersion 103*538bc0f4SArd Biesheuvel .short 0 // MinorVersion 104*538bc0f4SArd Biesheuvel .long IMAGE_DEBUG_TYPE_CODEVIEW // Type 105*538bc0f4SArd Biesheuvel .long .Lefi_debug_entry_size // SizeOfData 106*538bc0f4SArd Biesheuvel .long 0 // RVA 107*538bc0f4SArd Biesheuvel .long .Lefi_debug_entry - .Ldoshdr // FileOffset 108*538bc0f4SArd Biesheuvel#endif 109*538bc0f4SArd Biesheuvel .set .Lefi_debug_table_size, . - .Lefi_debug_table 110*538bc0f4SArd Biesheuvel .previous 111a0509109SArd Biesheuvel#endif 112a0509109SArd Biesheuvel 113a0509109SArd Biesheuvel.Lsection_table: 114a0509109SArd Biesheuvel .ascii ".text\0\0\0" 115a0509109SArd Biesheuvel .long _etext - .Lefi_header_end 116a0509109SArd Biesheuvel .long .Lefi_header_end - .Ldoshdr 117a0509109SArd Biesheuvel .long _etext - .Lefi_header_end 118a0509109SArd Biesheuvel .long .Lefi_header_end - .Ldoshdr 119a0509109SArd Biesheuvel 120a0509109SArd Biesheuvel .long 0, 0 121a0509109SArd Biesheuvel .short 0, 0 122a0509109SArd Biesheuvel .long IMAGE_SCN_CNT_CODE | \ 123a0509109SArd Biesheuvel IMAGE_SCN_MEM_READ | \ 124a0509109SArd Biesheuvel IMAGE_SCN_MEM_EXECUTE 125a0509109SArd Biesheuvel 126a0509109SArd Biesheuvel .ascii ".data\0\0\0" 127a0509109SArd Biesheuvel .long __data_size 128a0509109SArd Biesheuvel .long _etext - .Ldoshdr 129a0509109SArd Biesheuvel .long __data_rawsize 130a0509109SArd Biesheuvel .long _etext - .Ldoshdr 131a0509109SArd Biesheuvel 132a0509109SArd Biesheuvel .long 0, 0 133a0509109SArd Biesheuvel .short 0, 0 134a0509109SArd Biesheuvel .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 135a0509109SArd Biesheuvel IMAGE_SCN_MEM_READ | \ 136a0509109SArd Biesheuvel IMAGE_SCN_MEM_WRITE 137a0509109SArd Biesheuvel 138a0509109SArd Biesheuvel .set .Lsection_count, (. - .Lsection_table) / 40 139a0509109SArd Biesheuvel 140*538bc0f4SArd Biesheuvel#ifdef PE_DLL_CHAR_EX 141*538bc0f4SArd Biesheuvel.Lefi_dll_characteristics_ex: 142*538bc0f4SArd Biesheuvel .long PE_DLL_CHAR_EX 143*538bc0f4SArd Biesheuvel#endif 144a0509109SArd Biesheuvel#ifdef CONFIG_DEBUG_EFI 145a0509109SArd Biesheuvel.Lefi_debug_entry: 146a0509109SArd Biesheuvel // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY 147a0509109SArd Biesheuvel .ascii "NB10" // Signature 148a0509109SArd Biesheuvel .long 0 // Unknown 149a0509109SArd Biesheuvel .long 0 // Unknown2 150a0509109SArd Biesheuvel .long 0 // Unknown3 151a0509109SArd Biesheuvel 152a0509109SArd Biesheuvel .asciz ZBOOT_EFI_PATH 153a0509109SArd Biesheuvel 154a0509109SArd Biesheuvel .set .Lefi_debug_entry_size, . - .Lefi_debug_entry 155a0509109SArd Biesheuvel#endif 156a0509109SArd Biesheuvel 157a0509109SArd Biesheuvel .p2align 12 158a0509109SArd Biesheuvel.Lefi_header_end: 159a0509109SArd Biesheuvel 160