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 | \ |
| 37 | IMAGE_FILE_DEBUG_STRIPPED) |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 38 | optional_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 39 | .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 40 | .byte 0x02 /* MajorLinkerVersion */ |
| 41 | .byte 0x14 /* MinorLinkerVersion */ |
| 42 | .long _edata - _start /* SizeOfCode */ |
| 43 | .long 0 /* SizeOfInitializedData */ |
| 44 | .long 0 /* SizeOfUninitializedData */ |
| 45 | .long _start - ImageBase /* AddressOfEntryPoint */ |
| 46 | .long _start - ImageBase /* BaseOfCode */ |
| 47 | |
| 48 | extra_header_fields: |
| 49 | .quad 0 /* ImageBase */ |
Heinrich Schuchardt | f263479 | 2022-01-14 21:40:15 +0100 | [diff] [blame] | 50 | .long 0x200 /* SectionAlignment */ |
| 51 | .long 0x200 /* FileAlignment */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 52 | .short 0 /* MajorOperatingSystemVersion */ |
| 53 | .short 0 /* MinorOperatingSystemVersion */ |
| 54 | .short 0 /* MajorImageVersion */ |
| 55 | .short 0 /* MinorImageVersion */ |
| 56 | .short 0 /* MajorSubsystemVersion */ |
| 57 | .short 0 /* MinorSubsystemVersion */ |
| 58 | .long 0 /* Win32VersionValue */ |
| 59 | |
| 60 | .long _edata - ImageBase /* SizeOfImage */ |
| 61 | |
| 62 | /* |
| 63 | * Everything before the kernel image is considered part of the header |
| 64 | */ |
| 65 | .long _start - ImageBase /* SizeOfHeaders */ |
| 66 | .long 0 /* CheckSum */ |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 67 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 68 | .short 0 /* DllCharacteristics */ |
| 69 | .quad 0 /* SizeOfStackReserve */ |
| 70 | .quad 0 /* SizeOfStackCommit */ |
| 71 | .quad 0 /* SizeOfHeapReserve */ |
| 72 | .quad 0 /* SizeOfHeapCommit */ |
| 73 | .long 0 /* LoaderFlags */ |
| 74 | .long 0x6 /* NumberOfRvaAndSizes */ |
| 75 | |
| 76 | .quad 0 /* ExportTable */ |
| 77 | .quad 0 /* ImportTable */ |
| 78 | .quad 0 /* ResourceTable */ |
| 79 | .quad 0 /* ExceptionTable */ |
| 80 | .quad 0 /* CertificationTable */ |
| 81 | .quad 0 /* BaseRelocationTable */ |
| 82 | |
| 83 | /* Section table */ |
| 84 | section_table: |
| 85 | |
| 86 | /* |
| 87 | * The EFI application loader requires a relocation section |
| 88 | * because EFI applications must be relocatable. This is a |
| 89 | * dummy section as far as we are concerned. |
| 90 | */ |
| 91 | .ascii ".reloc" |
| 92 | .byte 0 |
| 93 | .byte 0 /* end of 0 padding of section name */ |
| 94 | .long 0 |
| 95 | .long 0 |
| 96 | .long 0 /* SizeOfRawData */ |
| 97 | .long 0 /* PointerToRawData */ |
| 98 | .long 0 /* PointerToRelocations */ |
| 99 | .long 0 /* PointerToLineNumbers */ |
| 100 | .short 0 /* NumberOfRelocations */ |
| 101 | .short 0 /* NumberOfLineNumbers */ |
| 102 | .long 0x42100040 /* Characteristics (section flags) */ |
| 103 | |
| 104 | |
| 105 | .ascii ".text" |
| 106 | .byte 0 |
| 107 | .byte 0 |
| 108 | .byte 0 /* end of 0 padding of section name */ |
| 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 | |
Heinrich Schuchardt | f263479 | 2022-01-14 21:40:15 +0100 | [diff] [blame] | 120 | .align 9 |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 121 | _start: |
| 122 | stp x29, x30, [sp, #-32]! |
| 123 | mov x29, sp |
| 124 | |
| 125 | stp x0, x1, [sp, #16] |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 126 | adr x0, ImageBase |
| 127 | adrp x1, _DYNAMIC |
| 128 | add x1, x1, #:lo12:_DYNAMIC |
| 129 | bl _relocate |
| 130 | cbnz x0, 0f |
| 131 | |
| 132 | ldp x0, x1, [sp, #16] |
| 133 | bl efi_main |
| 134 | |
| 135 | 0: ldp x29, x30, [sp], #32 |
| 136 | ret |