Tom Rini | 8b0c8a1 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 2 | /* |
| 3 | * crt0-efi-aarch64.S - PE/COFF header for aarch64 EFI applications |
| 4 | * |
| 5 | * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> |
| 6 | * |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 7 | * |
| 8 | * This file is taken and modified from the gnu-efi project. |
| 9 | */ |
| 10 | |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 11 | #include <asm-generic/pe.h> |
| 12 | |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 13 | .section .text.head |
| 14 | |
| 15 | /* |
| 16 | * Magic "MZ" signature for PE/COFF |
| 17 | */ |
| 18 | .globl ImageBase |
| 19 | ImageBase: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 20 | .short IMAGE_DOS_SIGNATURE /* 'MZ' */ |
Heinrich Schuchardt | d6bc9ec | 2021-01-29 12:35:51 +0100 | [diff] [blame] | 21 | .skip 54 /* 'MZ' + pad + offset == 64 */ |
| 22 | .long LINUX_ARM64_MAGIC /* For GRUB's linux command */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 23 | .long pe_header - ImageBase /* Offset to the PE header */ |
| 24 | pe_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 25 | .long IMAGE_NT_SIGNATURE /* 'PE' */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 26 | coff_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 27 | .short IMAGE_FILE_MACHINE_ARM64 /* AArch64 */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 28 | .short 2 /* nr_sections */ |
| 29 | .long 0 /* TimeDateStamp */ |
| 30 | .long 0 /* PointerToSymbolTable */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 31 | .long 0 /* NumberOfSymbols */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 32 | .short section_table - optional_header /* SizeOfOptionalHeader */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 33 | /* Characteristics */ |
| 34 | .short (IMAGE_FILE_EXECUTABLE_IMAGE | \ |
| 35 | IMAGE_FILE_LINE_NUMS_STRIPPED | \ |
| 36 | IMAGE_FILE_LOCAL_SYMS_STRIPPED | \ |
Heinrich Schuchardt | e84ab96 | 2022-12-23 02:16:03 +0100 | [diff] [blame^] | 37 | IMAGE_FILE_LARGE_ADDRESS_AWARE | \ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 38 | IMAGE_FILE_DEBUG_STRIPPED) |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 39 | optional_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 40 | .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 41 | .byte 0x02 /* MajorLinkerVersion */ |
| 42 | .byte 0x14 /* MinorLinkerVersion */ |
| 43 | .long _edata - _start /* SizeOfCode */ |
| 44 | .long 0 /* SizeOfInitializedData */ |
| 45 | .long 0 /* SizeOfUninitializedData */ |
| 46 | .long _start - ImageBase /* AddressOfEntryPoint */ |
| 47 | .long _start - ImageBase /* BaseOfCode */ |
| 48 | |
| 49 | extra_header_fields: |
| 50 | .quad 0 /* ImageBase */ |
Heinrich Schuchardt | f263479 | 2022-01-14 21:40:15 +0100 | [diff] [blame] | 51 | .long 0x200 /* SectionAlignment */ |
| 52 | .long 0x200 /* FileAlignment */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 53 | .short 0 /* MajorOperatingSystemVersion */ |
| 54 | .short 0 /* MinorOperatingSystemVersion */ |
| 55 | .short 0 /* MajorImageVersion */ |
| 56 | .short 0 /* MinorImageVersion */ |
| 57 | .short 0 /* MajorSubsystemVersion */ |
| 58 | .short 0 /* MinorSubsystemVersion */ |
| 59 | .long 0 /* Win32VersionValue */ |
| 60 | |
| 61 | .long _edata - ImageBase /* SizeOfImage */ |
| 62 | |
| 63 | /* |
| 64 | * Everything before the kernel image is considered part of the header |
| 65 | */ |
| 66 | .long _start - ImageBase /* SizeOfHeaders */ |
| 67 | .long 0 /* CheckSum */ |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 68 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 69 | .short 0 /* DllCharacteristics */ |
| 70 | .quad 0 /* SizeOfStackReserve */ |
| 71 | .quad 0 /* SizeOfStackCommit */ |
| 72 | .quad 0 /* SizeOfHeapReserve */ |
| 73 | .quad 0 /* SizeOfHeapCommit */ |
| 74 | .long 0 /* LoaderFlags */ |
| 75 | .long 0x6 /* NumberOfRvaAndSizes */ |
| 76 | |
| 77 | .quad 0 /* ExportTable */ |
| 78 | .quad 0 /* ImportTable */ |
| 79 | .quad 0 /* ResourceTable */ |
| 80 | .quad 0 /* ExceptionTable */ |
| 81 | .quad 0 /* CertificationTable */ |
| 82 | .quad 0 /* BaseRelocationTable */ |
| 83 | |
| 84 | /* Section table */ |
| 85 | section_table: |
| 86 | |
| 87 | /* |
| 88 | * The EFI application loader requires a relocation section |
| 89 | * because EFI applications must be relocatable. This is a |
| 90 | * dummy section as far as we are concerned. |
| 91 | */ |
| 92 | .ascii ".reloc" |
| 93 | .byte 0 |
| 94 | .byte 0 /* end of 0 padding of section name */ |
| 95 | .long 0 |
| 96 | .long 0 |
| 97 | .long 0 /* SizeOfRawData */ |
| 98 | .long 0 /* PointerToRawData */ |
| 99 | .long 0 /* PointerToRelocations */ |
| 100 | .long 0 /* PointerToLineNumbers */ |
| 101 | .short 0 /* NumberOfRelocations */ |
| 102 | .short 0 /* NumberOfLineNumbers */ |
| 103 | .long 0x42100040 /* Characteristics (section flags) */ |
| 104 | |
| 105 | |
| 106 | .ascii ".text" |
| 107 | .byte 0 |
| 108 | .byte 0 |
| 109 | .byte 0 /* end of 0 padding of section name */ |
| 110 | .long _edata - _start /* VirtualSize */ |
| 111 | .long _start - ImageBase /* VirtualAddress */ |
| 112 | .long _edata - _start /* SizeOfRawData */ |
| 113 | .long _start - ImageBase /* PointerToRawData */ |
| 114 | |
| 115 | .long 0 /* PointerToRelocations (0 for executables) */ |
| 116 | .long 0 /* PointerToLineNumbers (0 for executables) */ |
| 117 | .short 0 /* NumberOfRelocations (0 for executables) */ |
| 118 | .short 0 /* NumberOfLineNumbers (0 for executables) */ |
| 119 | .long 0xe0500020 /* Characteristics (section flags) */ |
| 120 | |
Heinrich Schuchardt | f263479 | 2022-01-14 21:40:15 +0100 | [diff] [blame] | 121 | .align 9 |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 122 | _start: |
| 123 | stp x29, x30, [sp, #-32]! |
| 124 | mov x29, sp |
| 125 | |
| 126 | stp x0, x1, [sp, #16] |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 127 | adr x0, ImageBase |
| 128 | adrp x1, _DYNAMIC |
| 129 | add x1, x1, #:lo12:_DYNAMIC |
| 130 | bl _relocate |
| 131 | cbnz x0, 0f |
| 132 | |
| 133 | ldp x0, x1, [sp, #16] |
| 134 | bl efi_main |
| 135 | |
| 136 | 0: ldp x29, x30, [sp], #32 |
| 137 | ret |