1/* SPDX-License-Identifier: BSD-3-Clause or GPL-2.0-or-later */ 2 3/* 4 * crt0-efi-aarch64.S - PE/COFF header for AArch64 EFI applications 5 * 6 * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice and this list of conditions, without modification. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * Alternatively, this software may be distributed under the terms of the 17 * GNU General Public License as published by the Free Software Foundation; 18 * either version 2 of the License, or (at your option) any later version. 19 */ 20 21 .section .text.head 22 23 /* 24 * Magic "MZ" signature for PE/COFF 25 */ 26 .globl ImageBase 27ImageBase: 28 .ascii "MZ" 29 .skip 58 // 'MZ' + pad + offset == 64 30 .long pe_header - ImageBase // Offset to the PE header. 31pe_header: 32 .ascii "PE" 33 .short 0 34coff_header: 35 .short 0xaa64 // AArch64 36 .short 2 // nr_sections 37 .long 0 // TimeDateStamp 38 .long 0 // PointerToSymbolTable 39 .long 1 // NumberOfSymbols 40 .short section_table - optional_header // SizeOfOptionalHeader 41 .short 0x206 // Characteristics. 42 // IMAGE_FILE_DEBUG_STRIPPED | 43 // IMAGE_FILE_EXECUTABLE_IMAGE | 44 // IMAGE_FILE_LINE_NUMS_STRIPPED 45optional_header: 46 .short 0x20b // PE32+ format 47 .byte 0x02 // MajorLinkerVersion 48 .byte 0x14 // MinorLinkerVersion 49 .long _data - _gnuefi_start // SizeOfCode 50 .long _data_size // SizeOfInitializedData 51 .long 0 // SizeOfUninitializedData 52 .long _gnuefi_start - ImageBase // AddressOfEntryPoint 53 .long _gnuefi_start - ImageBase // BaseOfCode 54 55extra_header_fields: 56 .quad 0 // ImageBase 57 .long 0x1000 // SectionAlignment 58 .long 0x200 // FileAlignment 59 .short 0 // MajorOperatingSystemVersion 60 .short 0 // MinorOperatingSystemVersion 61 .short 0 // MajorImageVersion 62 .short 0 // MinorImageVersion 63 .short 0 // MajorSubsystemVersion 64 .short 0 // MinorSubsystemVersion 65 .long 0 // Win32VersionValue 66 67 .long _edata - ImageBase // SizeOfImage 68 69 // Everything before the kernel image is considered part of the header 70 .long _gnuefi_start - ImageBase // SizeOfHeaders 71 .long 0 // CheckSum 72 .short EFI_SUBSYSTEM // Subsystem 73 .short 0 // DllCharacteristics 74 .quad 0 // SizeOfStackReserve 75 .quad 0 // SizeOfStackCommit 76 .quad 0 // SizeOfHeapReserve 77 .quad 0 // SizeOfHeapCommit 78 .long 0 // LoaderFlags 79 .long 0x6 // NumberOfRvaAndSizes 80 81 .quad 0 // ExportTable 82 .quad 0 // ImportTable 83 .quad 0 // ResourceTable 84 .quad 0 // ExceptionTable 85 .quad 0 // CertificationTable 86 .quad 0 // BaseRelocationTable 87 88 // Section table 89section_table: 90 .ascii ".text\0\0\0" 91 .long _data - _gnuefi_start // VirtualSize 92 .long _gnuefi_start - ImageBase // VirtualAddress 93 .long _data - _gnuefi_start // SizeOfRawData 94 .long _gnuefi_start - ImageBase // PointerToRawData 95 96 .long 0 // PointerToRelocations (0 for executables) 97 .long 0 // PointerToLineNumbers (0 for executables) 98 .short 0 // NumberOfRelocations (0 for executables) 99 .short 0 // NumberOfLineNumbers (0 for executables) 100 .long 0x60000020 // Characteristics (section flags) 101 102 .ascii ".data\0\0\0" 103 .long _data_size // VirtualSize 104 .long _data - ImageBase // VirtualAddress 105 .long _data_size // SizeOfRawData 106 .long _data - ImageBase // PointerToRawData 107 108 .long 0 // PointerToRelocations (0 for executables) 109 .long 0 // PointerToLineNumbers (0 for executables) 110 .short 0 // NumberOfRelocations (0 for executables) 111 .short 0 // NumberOfLineNumbers (0 for executables) 112 .long 0xc0000040 // Characteristics (section flags) 113 114 .align 12 115_gnuefi_start: 116 stp x29, x30, [sp, #-32]! 117 mov x29, sp 118 119 stp x0, x1, [sp, #16] 120 mov x2, x0 121 mov x3, x1 122 adr x0, ImageBase 123 adrp x1, _DYNAMIC 124 add x1, x1, #:lo12:_DYNAMIC 125 bl _relocate 126 cbnz x0, 0f 127 128 ldp x0, x1, [sp, #16] 129 bl efi_main 130 1310: ldp x29, x30, [sp], #32 132 ret 133