1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 4 * Copright (C) 2018 Alexander Graf <agraf@suse.de> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice and this list of conditions, without modification. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission. 13 * 14 * Alternatively, this software may be distributed under the terms of the 15 * GNU General Public License as published by the Free Software Foundation; 16 * either version 2 of the License, or (at your option) any later version. 17 */ 18 19#ifndef EFI_SUBSYSTEM 20#define EFI_SUBSYSTEM 10 21#endif 22 23 .section .text.head 24 25 /* 26 * Magic "MZ" signature for PE/COFF 27 */ 28 .globl ImageBase 29ImageBase: 30 .ascii "MZ" 31 .skip 58 // 'MZ' + pad + offset == 64 32 .long pe_header - ImageBase // Offset to the PE header. 33pe_header: 34 .ascii "PE" 35 .short 0 36coff_header: 37 .short 0x5064 // riscv64 38 .short 2 // nr_sections 39 .long 0 // TimeDateStamp 40 .long 0 // PointerToSymbolTable 41 .long 0 // NumberOfSymbols 42 .short section_table - optional_header // SizeOfOptionalHeader 43 .short 0x206 // Characteristics. 44 // IMAGE_FILE_DEBUG_STRIPPED | 45 // IMAGE_FILE_EXECUTABLE_IMAGE | 46 // IMAGE_FILE_LINE_NUMS_STRIPPED 47optional_header: 48 .short 0x20b // PE32+ format 49 .byte 0x02 // MajorLinkerVersion 50 .byte 0x14 // MinorLinkerVersion 51 .long _data - _start // SizeOfCode 52 .long _data_size // SizeOfInitializedData 53 .long 0 // SizeOfUninitializedData 54 .long _start - ImageBase // AddressOfEntryPoint 55 .long _start - ImageBase // BaseOfCode 56 57extra_header_fields: 58 .quad 0 // ImageBase 59 .long 0x1000 // SectionAlignment 60 .long 0x200 // FileAlignment 61 .short 0 // MajorOperatingSystemVersion 62 .short 0 // MinorOperatingSystemVersion 63 .short 0 // MajorImageVersion 64 .short 0 // MinorImageVersion 65 .short 0 // MajorSubsystemVersion 66 .short 0 // MinorSubsystemVersion 67 .long 0 // Win32VersionValue 68 69 .long _edata - ImageBase // SizeOfImage 70 71 // Everything before the kernel image is considered part of the header 72 .long _start - ImageBase // SizeOfHeaders 73 .long 0 // CheckSum 74 .short EFI_SUBSYSTEM // Subsystem 75 .short 0 // DllCharacteristics 76 .quad 0 // SizeOfStackReserve 77 .quad 0 // SizeOfStackCommit 78 .quad 0 // SizeOfHeapReserve 79 .quad 0 // SizeOfHeapCommit 80 .long 0 // LoaderFlags 81 .long 0x6 // NumberOfRvaAndSizes 82 83 .quad 0 // ExportTable 84 .quad 0 // ImportTable 85 .quad 0 // ResourceTable 86 .quad 0 // ExceptionTable 87 .quad 0 // CertificationTable 88 .quad 0 // BaseRelocationTable 89 90 // Section table 91section_table: 92 /* 93 * The EFI application loader requires a relocation section 94 * because EFI applications must be relocatable. This is a 95 * dummy section as far as we are concerned. 96 */ 97 .ascii ".reloc\0\0" 98 .long 0 99 .long 0 100 .long 0 // SizeOfRawData 101 .long 0 // PointerToRawData 102 .long 0 // PointerToRelocations 103 .long 0 // PointerToLineNumbers 104 .short 0 // NumberOfRelocations 105 .short 0 // NumberOfLineNumbers 106 .long 0x42100040 // Characteristics (section flags) 107 108 .ascii ".text\0\0\0" 109 .long _edata - _start // VirtualSize 110 .long _start - ImageBase // VirtualAddress 111 .long _edata - _start // SizeOfRawData 112 .long _start - ImageBase // PointerToRawData 113 114 .long 0 // PointerToRelocations (0 for executables) 115 .long 0 // PointerToLineNumbers (0 for executables) 116 .short 0 // NumberOfRelocations (0 for executables) 117 .short 0 // NumberOfLineNumbers (0 for executables) 118 .long 0xe0500020 // Characteristics (section flags) 119 120 .align 12 121 .globl _start 122_start: 123 addi sp, sp, -24 124 sd a0, 0(sp) 125 sd a1, 8(sp) 126 sd ra, 16(sp) 127 lla a0, ImageBase 128 lla a1, _DYNAMIC 129 call _relocate 130 bne a0, zero, 0f 131 ld a1, 8(sp) 132 ld a0, 0(sp) 133 call efi_main 134 ld ra, 16(sp) 1350: addi sp, sp, 24 136 ret 137 138#if defined(__ELF__) && defined(__linux__) 139 .section .note.GNU-stack,"",%progbits 140#endif 141