162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2020 Western Digital Corporation or its affiliates. 462306a36Sopenharmony_ci * Adapted from arch/arm64/kernel/efi-header.S 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/pe.h> 862306a36Sopenharmony_ci#include <linux/sizes.h> 962306a36Sopenharmony_ci#include <asm/set_memory.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci .macro __EFI_PE_HEADER 1262306a36Sopenharmony_ci .long PE_MAGIC 1362306a36Sopenharmony_cicoff_header: 1462306a36Sopenharmony_ci#ifdef CONFIG_64BIT 1562306a36Sopenharmony_ci .short IMAGE_FILE_MACHINE_RISCV64 // Machine 1662306a36Sopenharmony_ci#else 1762306a36Sopenharmony_ci .short IMAGE_FILE_MACHINE_RISCV32 // Machine 1862306a36Sopenharmony_ci#endif 1962306a36Sopenharmony_ci .short section_count // NumberOfSections 2062306a36Sopenharmony_ci .long 0 // TimeDateStamp 2162306a36Sopenharmony_ci .long 0 // PointerToSymbolTable 2262306a36Sopenharmony_ci .long 0 // NumberOfSymbols 2362306a36Sopenharmony_ci .short section_table - optional_header // SizeOfOptionalHeader 2462306a36Sopenharmony_ci .short IMAGE_FILE_DEBUG_STRIPPED | \ 2562306a36Sopenharmony_ci IMAGE_FILE_EXECUTABLE_IMAGE | \ 2662306a36Sopenharmony_ci IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cioptional_header: 2962306a36Sopenharmony_ci#ifdef CONFIG_64BIT 3062306a36Sopenharmony_ci .short PE_OPT_MAGIC_PE32PLUS // PE32+ format 3162306a36Sopenharmony_ci#else 3262306a36Sopenharmony_ci .short PE_OPT_MAGIC_PE32 // PE32 format 3362306a36Sopenharmony_ci#endif 3462306a36Sopenharmony_ci .byte 0x02 // MajorLinkerVersion 3562306a36Sopenharmony_ci .byte 0x14 // MinorLinkerVersion 3662306a36Sopenharmony_ci .long __pecoff_text_end - efi_header_end // SizeOfCode 3762306a36Sopenharmony_ci#ifdef __clang__ 3862306a36Sopenharmony_ci .long __pecoff_data_virt_size // SizeOfInitializedData 3962306a36Sopenharmony_ci#else 4062306a36Sopenharmony_ci .long __pecoff_data_virt_end - __pecoff_text_end // SizeOfInitializedData 4162306a36Sopenharmony_ci#endif 4262306a36Sopenharmony_ci .long 0 // SizeOfUninitializedData 4362306a36Sopenharmony_ci .long __efistub_efi_pe_entry - _start // AddressOfEntryPoint 4462306a36Sopenharmony_ci .long efi_header_end - _start // BaseOfCode 4562306a36Sopenharmony_ci#ifdef CONFIG_32BIT 4662306a36Sopenharmony_ci .long __pecoff_text_end - _start // BaseOfData 4762306a36Sopenharmony_ci#endif 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciextra_header_fields: 5062306a36Sopenharmony_ci .quad 0 // ImageBase 5162306a36Sopenharmony_ci .long PECOFF_SECTION_ALIGNMENT // SectionAlignment 5262306a36Sopenharmony_ci .long PECOFF_FILE_ALIGNMENT // FileAlignment 5362306a36Sopenharmony_ci .short 0 // MajorOperatingSystemVersion 5462306a36Sopenharmony_ci .short 0 // MinorOperatingSystemVersion 5562306a36Sopenharmony_ci .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion 5662306a36Sopenharmony_ci .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion 5762306a36Sopenharmony_ci .short 0 // MajorSubsystemVersion 5862306a36Sopenharmony_ci .short 0 // MinorSubsystemVersion 5962306a36Sopenharmony_ci .long 0 // Win32VersionValue 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci .long _end - _start // SizeOfImage 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci // Everything before the kernel image is considered part of the header 6462306a36Sopenharmony_ci .long efi_header_end - _start // SizeOfHeaders 6562306a36Sopenharmony_ci .long 0 // CheckSum 6662306a36Sopenharmony_ci .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem 6762306a36Sopenharmony_ci .short 0 // DllCharacteristics 6862306a36Sopenharmony_ci .quad 0 // SizeOfStackReserve 6962306a36Sopenharmony_ci .quad 0 // SizeOfStackCommit 7062306a36Sopenharmony_ci .quad 0 // SizeOfHeapReserve 7162306a36Sopenharmony_ci .quad 0 // SizeOfHeapCommit 7262306a36Sopenharmony_ci .long 0 // LoaderFlags 7362306a36Sopenharmony_ci .long (section_table - .) / 8 // NumberOfRvaAndSizes 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci .quad 0 // ExportTable 7662306a36Sopenharmony_ci .quad 0 // ImportTable 7762306a36Sopenharmony_ci .quad 0 // ResourceTable 7862306a36Sopenharmony_ci .quad 0 // ExceptionTable 7962306a36Sopenharmony_ci .quad 0 // CertificationTable 8062306a36Sopenharmony_ci .quad 0 // BaseRelocationTable 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci // Section table 8362306a36Sopenharmony_cisection_table: 8462306a36Sopenharmony_ci .ascii ".text\0\0\0" 8562306a36Sopenharmony_ci .long __pecoff_text_end - efi_header_end // VirtualSize 8662306a36Sopenharmony_ci .long efi_header_end - _start // VirtualAddress 8762306a36Sopenharmony_ci .long __pecoff_text_end - efi_header_end // SizeOfRawData 8862306a36Sopenharmony_ci .long efi_header_end - _start // PointerToRawData 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci .long 0 // PointerToRelocations 9162306a36Sopenharmony_ci .long 0 // PointerToLineNumbers 9262306a36Sopenharmony_ci .short 0 // NumberOfRelocations 9362306a36Sopenharmony_ci .short 0 // NumberOfLineNumbers 9462306a36Sopenharmony_ci .long IMAGE_SCN_CNT_CODE | \ 9562306a36Sopenharmony_ci IMAGE_SCN_MEM_READ | \ 9662306a36Sopenharmony_ci IMAGE_SCN_MEM_EXECUTE // Characteristics 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci .ascii ".data\0\0\0" 9962306a36Sopenharmony_ci#ifdef __clang__ 10062306a36Sopenharmony_ci .long __pecoff_data_virt_size // VirtualSize 10162306a36Sopenharmony_ci#else 10262306a36Sopenharmony_ci .long __pecoff_data_virt_end - __pecoff_text_end // VirtualSize 10362306a36Sopenharmony_ci#endif 10462306a36Sopenharmony_ci .long __pecoff_text_end - _start // VirtualAddress 10562306a36Sopenharmony_ci#ifdef __clang__ 10662306a36Sopenharmony_ci .long __pecoff_data_raw_size // SizeOfRawData 10762306a36Sopenharmony_ci#else 10862306a36Sopenharmony_ci .long __pecoff_data_raw_end - __pecoff_text_end // SizeOfRawData 10962306a36Sopenharmony_ci#endif 11062306a36Sopenharmony_ci .long __pecoff_text_end - _start // PointerToRawData 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci .long 0 // PointerToRelocations 11362306a36Sopenharmony_ci .long 0 // PointerToLineNumbers 11462306a36Sopenharmony_ci .short 0 // NumberOfRelocations 11562306a36Sopenharmony_ci .short 0 // NumberOfLineNumbers 11662306a36Sopenharmony_ci .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 11762306a36Sopenharmony_ci IMAGE_SCN_MEM_READ | \ 11862306a36Sopenharmony_ci IMAGE_SCN_MEM_WRITE // Characteristics 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci .set section_count, (. - section_table) / 40 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci .balign 0x1000 12362306a36Sopenharmony_ciefi_header_end: 12462306a36Sopenharmony_ci .endm 125