162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2013-2017 Linaro Ltd 462306a36Sopenharmony_ci * Authors: Roy Franz <roy.franz@linaro.org> 562306a36Sopenharmony_ci * Ard Biesheuvel <ard.biesheuvel@linaro.org> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/pe.h> 962306a36Sopenharmony_ci#include <linux/sizes.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci .macro __nop 1262306a36Sopenharmony_ci AR_CLASS( mov r0, r0 ) 1362306a36Sopenharmony_ci M_CLASS( nop.w ) 1462306a36Sopenharmony_ci .endm 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci .macro __initial_nops 1762306a36Sopenharmony_ci#ifdef CONFIG_EFI_STUB 1862306a36Sopenharmony_ci @ This is a two-instruction NOP, which happens to bear the 1962306a36Sopenharmony_ci @ PE/COFF signature "MZ" in the first two bytes, so the kernel 2062306a36Sopenharmony_ci @ is accepted as an EFI binary. Booting via the UEFI stub 2162306a36Sopenharmony_ci @ will not execute those instructions, but the ARM/Linux 2262306a36Sopenharmony_ci @ boot protocol does, so we need some NOPs here. 2362306a36Sopenharmony_ci .inst MZ_MAGIC | (0xe225 << 16) @ eor r5, r5, 0x4d000 2462306a36Sopenharmony_ci eor r5, r5, 0x4d000 @ undo previous insn 2562306a36Sopenharmony_ci#else 2662306a36Sopenharmony_ci __nop 2762306a36Sopenharmony_ci __nop 2862306a36Sopenharmony_ci#endif 2962306a36Sopenharmony_ci .endm 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci .macro __EFI_HEADER 3262306a36Sopenharmony_ci#ifdef CONFIG_EFI_STUB 3362306a36Sopenharmony_ci .set start_offset, __efi_start - start 3462306a36Sopenharmony_ci .org start + 0x3c 3562306a36Sopenharmony_ci @ 3662306a36Sopenharmony_ci @ The PE header can be anywhere in the file, but for 3762306a36Sopenharmony_ci @ simplicity we keep it together with the MSDOS header 3862306a36Sopenharmony_ci @ The offset to the PE/COFF header needs to be at offset 3962306a36Sopenharmony_ci @ 0x3C in the MSDOS header. 4062306a36Sopenharmony_ci @ The only 2 fields of the MSDOS header that are used are this 4162306a36Sopenharmony_ci @ PE/COFF offset, and the "MZ" bytes at offset 0x0. 4262306a36Sopenharmony_ci @ 4362306a36Sopenharmony_ci .long pe_header - start @ Offset to the PE header. 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cipe_header: 4662306a36Sopenharmony_ci .long PE_MAGIC 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cicoff_header: 4962306a36Sopenharmony_ci .short IMAGE_FILE_MACHINE_THUMB @ Machine 5062306a36Sopenharmony_ci .short section_count @ NumberOfSections 5162306a36Sopenharmony_ci .long 0 @ TimeDateStamp 5262306a36Sopenharmony_ci .long 0 @ PointerToSymbolTable 5362306a36Sopenharmony_ci .long 0 @ NumberOfSymbols 5462306a36Sopenharmony_ci .short section_table - optional_header @ SizeOfOptionalHeader 5562306a36Sopenharmony_ci .short IMAGE_FILE_32BIT_MACHINE | \ 5662306a36Sopenharmony_ci IMAGE_FILE_DEBUG_STRIPPED | \ 5762306a36Sopenharmony_ci IMAGE_FILE_EXECUTABLE_IMAGE | \ 5862306a36Sopenharmony_ci IMAGE_FILE_LINE_NUMS_STRIPPED @ Characteristics 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define __pecoff_code_size (__pecoff_data_start - __efi_start) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cioptional_header: 6362306a36Sopenharmony_ci .short PE_OPT_MAGIC_PE32 @ PE32 format 6462306a36Sopenharmony_ci .byte 0x02 @ MajorLinkerVersion 6562306a36Sopenharmony_ci .byte 0x14 @ MinorLinkerVersion 6662306a36Sopenharmony_ci .long __pecoff_code_size @ SizeOfCode 6762306a36Sopenharmony_ci .long __pecoff_data_size @ SizeOfInitializedData 6862306a36Sopenharmony_ci .long 0 @ SizeOfUninitializedData 6962306a36Sopenharmony_ci .long efi_pe_entry - start @ AddressOfEntryPoint 7062306a36Sopenharmony_ci .long start_offset @ BaseOfCode 7162306a36Sopenharmony_ci .long __pecoff_data_start - start @ BaseOfData 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciextra_header_fields: 7462306a36Sopenharmony_ci .long 0 @ ImageBase 7562306a36Sopenharmony_ci .long SZ_4K @ SectionAlignment 7662306a36Sopenharmony_ci .long SZ_512 @ FileAlignment 7762306a36Sopenharmony_ci .short 0 @ MajorOsVersion 7862306a36Sopenharmony_ci .short 0 @ MinorOsVersion 7962306a36Sopenharmony_ci .short LINUX_EFISTUB_MAJOR_VERSION @ MajorImageVersion 8062306a36Sopenharmony_ci .short LINUX_EFISTUB_MINOR_VERSION @ MinorImageVersion 8162306a36Sopenharmony_ci .short 0 @ MajorSubsystemVersion 8262306a36Sopenharmony_ci .short 0 @ MinorSubsystemVersion 8362306a36Sopenharmony_ci .long 0 @ Win32VersionValue 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci .long __pecoff_end - start @ SizeOfImage 8662306a36Sopenharmony_ci .long start_offset @ SizeOfHeaders 8762306a36Sopenharmony_ci .long 0 @ CheckSum 8862306a36Sopenharmony_ci .short IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem 8962306a36Sopenharmony_ci .short 0 @ DllCharacteristics 9062306a36Sopenharmony_ci .long 0 @ SizeOfStackReserve 9162306a36Sopenharmony_ci .long 0 @ SizeOfStackCommit 9262306a36Sopenharmony_ci .long 0 @ SizeOfHeapReserve 9362306a36Sopenharmony_ci .long 0 @ SizeOfHeapCommit 9462306a36Sopenharmony_ci .long 0 @ LoaderFlags 9562306a36Sopenharmony_ci .long (section_table - .) / 8 @ NumberOfRvaAndSizes 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci .quad 0 @ ExportTable 9862306a36Sopenharmony_ci .quad 0 @ ImportTable 9962306a36Sopenharmony_ci .quad 0 @ ResourceTable 10062306a36Sopenharmony_ci .quad 0 @ ExceptionTable 10162306a36Sopenharmony_ci .quad 0 @ CertificationTable 10262306a36Sopenharmony_ci .quad 0 @ BaseRelocationTable 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cisection_table: 10562306a36Sopenharmony_ci .ascii ".text\0\0\0" 10662306a36Sopenharmony_ci .long __pecoff_code_size @ VirtualSize 10762306a36Sopenharmony_ci .long __efi_start @ VirtualAddress 10862306a36Sopenharmony_ci .long __pecoff_code_size @ SizeOfRawData 10962306a36Sopenharmony_ci .long __efi_start @ PointerToRawData 11062306a36Sopenharmony_ci .long 0 @ PointerToRelocations 11162306a36Sopenharmony_ci .long 0 @ PointerToLineNumbers 11262306a36Sopenharmony_ci .short 0 @ NumberOfRelocations 11362306a36Sopenharmony_ci .short 0 @ NumberOfLineNumbers 11462306a36Sopenharmony_ci .long IMAGE_SCN_CNT_CODE | \ 11562306a36Sopenharmony_ci IMAGE_SCN_MEM_READ | \ 11662306a36Sopenharmony_ci IMAGE_SCN_MEM_EXECUTE @ Characteristics 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci .ascii ".data\0\0\0" 11962306a36Sopenharmony_ci .long __pecoff_data_size @ VirtualSize 12062306a36Sopenharmony_ci .long __pecoff_data_start - start @ VirtualAddress 12162306a36Sopenharmony_ci .long __pecoff_data_rawsize @ SizeOfRawData 12262306a36Sopenharmony_ci .long __pecoff_data_start - start @ PointerToRawData 12362306a36Sopenharmony_ci .long 0 @ PointerToRelocations 12462306a36Sopenharmony_ci .long 0 @ PointerToLineNumbers 12562306a36Sopenharmony_ci .short 0 @ NumberOfRelocations 12662306a36Sopenharmony_ci .short 0 @ NumberOfLineNumbers 12762306a36Sopenharmony_ci .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 12862306a36Sopenharmony_ci IMAGE_SCN_MEM_READ | \ 12962306a36Sopenharmony_ci IMAGE_SCN_MEM_WRITE @ Characteristics 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci .set section_count, (. - section_table) / 40 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci .align 12 13462306a36Sopenharmony_ci__efi_start: 13562306a36Sopenharmony_ci#endif 13662306a36Sopenharmony_ci .endm 137