| 1 | /* SPDX-License-Identifier: GPL-2.0-only */
|
| 2 | /*
|
| 3 | * Copyright (C) 2020 Western Digital Corporation or its affiliates.
|
| 4 | * Adapted from arch/arm64/kernel/efi-header.S
|
| 5 | */
|
| 6 |
|
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | .macro __EFI_PE_HEADER
|
| 12 | .long IMAGE_NT_SIGNATURE
|
| 13 | coff_header:
|
| 14 | |
| 15 | .short IMAGE_FILE_MACHINE_RISCV64 // Machine
|
| 16 | |
| 17 | .short IMAGE_FILE_MACHINE_RISCV32 // Machine
|
| 18 | |
| 19 | .short section_count // NumberOfSections
|
| 20 | .long 0 // TimeDateStamp
|
| 21 | .long 0 // PointerToSymbolTable
|
| 22 | .long 0 // NumberOfSymbols
|
| 23 | .short section_table - optional_header // SizeOfOptionalHeader
|
| 24 | .short IMAGE_FILE_DEBUG_STRIPPED | \
|
| 25 | IMAGE_FILE_EXECUTABLE_IMAGE | \
|
| 26 | IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
|
| 27 |
|
| 28 | optional_header:
|
| 29 | |
| 30 | .short IMAGE_NT_OPTIONAL_HDR64_MAGIC // PE32+ format
|
| 31 | |
| 32 | .short IMAGE_NT_OPTIONAL_HDR32_MAGIC // PE32 format
|
| 33 | |
| 34 | .byte 0x02 // MajorLinkerVersion
|
| 35 | .byte 0x14 // MinorLinkerVersion
|
| 36 | .long __pecoff_text_end - efi_header_end // SizeOfCode
|
| 37 | |
| 38 | .long __pecoff_data_virt_size // SizeOfInitializedData
|
| 39 | |
| 40 | .long __pecoff_data_virt_end - __pecoff_text_end // SizeOfInitializedData
|
| 41 | |
| 42 | .long 0 // SizeOfUninitializedData
|
| 43 | .long __efistub_efi_pe_entry - _start // AddressOfEntryPoint
|
| 44 | .long efi_header_end - _start // BaseOfCode
|
| 45 | |
| 46 | .long __pecoff_text_end - _start // BaseOfData
|
| 47 | |
| 48 |
|
| 49 | extra_header_fields:
|
| 50 | .quad 0 // ImageBase
|
| 51 | .long PECOFF_SECTION_ALIGNMENT // SectionAlignment
|
| 52 | .long PECOFF_FILE_ALIGNMENT // FileAlignment
|
| 53 | .short 0 // MajorOperatingSystemVersion
|
| 54 | .short 0 // MinorOperatingSystemVersion
|
| 55 | .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion
|
| 56 | .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion
|
| 57 | .short 0 // MajorSubsystemVersion
|
| 58 | .short 0 // MinorSubsystemVersion
|
| 59 | .long 0 // Win32VersionValue
|
| 60 |
|
| 61 | .long _end - _start // SizeOfImage
|
| 62 |
|
| 63 | // Everything before the kernel image is considered part of the header
|
| 64 | .long efi_header_end - _start // SizeOfHeaders
|
| 65 | .long 0 // CheckSum
|
| 66 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
|
| 67 | .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT // DllCharacteristics
|
| 68 | .quad 0 // SizeOfStackReserve
|
| 69 | .quad 0 // SizeOfStackCommit
|
| 70 | .quad 0 // SizeOfHeapReserve
|
| 71 | .quad 0 // SizeOfHeapCommit
|
| 72 | .long 0 // LoaderFlags
|
| 73 | .long (section_table - .) / 8 // NumberOfRvaAndSizes
|
| 74 |
|
| 75 | .quad 0 // ExportTable
|
| 76 | .quad 0 // ImportTable
|
| 77 | .quad 0 // ResourceTable
|
| 78 | .quad 0 // ExceptionTable
|
| 79 | .quad 0 // CertificationTable
|
| 80 | .quad 0 // BaseRelocationTable
|
| 81 |
|
| 82 | // Section table
|
| 83 | section_table:
|
| 84 | .ascii ".text\0\0\0"
|
| 85 | .long __pecoff_text_end - efi_header_end // VirtualSize
|
| 86 | .long efi_header_end - _start // VirtualAddress
|
| 87 | .long __pecoff_text_end - efi_header_end // SizeOfRawData
|
| 88 | .long efi_header_end - _start // PointerToRawData
|
| 89 |
|
| 90 | .long 0 // PointerToRelocations
|
| 91 | .long 0 // PointerToLineNumbers
|
| 92 | .short 0 // NumberOfRelocations
|
| 93 | .short 0 // NumberOfLineNumbers
|
| 94 | .long IMAGE_SCN_CNT_CODE | \
|
| 95 | IMAGE_SCN_MEM_READ | \
|
| 96 | IMAGE_SCN_MEM_EXECUTE // Characteristics
|
| 97 |
|
| 98 | .ascii ".data\0\0\0"
|
| 99 | |
| 100 | .long __pecoff_data_virt_size // VirtualSize
|
| 101 | |
| 102 | .long __pecoff_data_virt_end - __pecoff_text_end // VirtualSize
|
| 103 | |
| 104 | .long __pecoff_text_end - _start // VirtualAddress
|
| 105 | |
| 106 | .long __pecoff_data_raw_size // SizeOfRawData
|
| 107 | |
| 108 | .long __pecoff_data_raw_end - __pecoff_text_end // SizeOfRawData
|
| 109 | |
| 110 | .long __pecoff_text_end - _start // PointerToRawData
|
| 111 |
|
| 112 | .long 0 // PointerToRelocations
|
| 113 | .long 0 // PointerToLineNumbers
|
| 114 | .short 0 // NumberOfRelocations
|
| 115 | .short 0 // NumberOfLineNumbers
|
| 116 | .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
|
| 117 | IMAGE_SCN_MEM_READ | \
|
| 118 | IMAGE_SCN_MEM_WRITE // Characteristics
|
| 119 |
|
| 120 | .set section_count, (. - section_table) / 40
|
| 121 |
|
| 122 | .balign 0x1000
|
| 123 | efi_header_end:
|
| 124 | .endm
|