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' */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 21 | .skip 58 /* 'MZ' + pad + offset == 64 */ |
| 22 | .long pe_header - ImageBase /* Offset to the PE header */ |
| 23 | pe_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 24 | .long IMAGE_NT_SIGNATURE /* 'PE' */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 25 | coff_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 26 | .short IMAGE_FILE_MACHINE_ARM64 /* AArch64 */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 27 | .short 2 /* nr_sections */ |
| 28 | .long 0 /* TimeDateStamp */ |
| 29 | .long 0 /* PointerToSymbolTable */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 30 | .long 0 /* NumberOfSymbols */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 31 | .short section_table - optional_header /* SizeOfOptionalHeader */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 32 | /* Characteristics */ |
| 33 | .short (IMAGE_FILE_EXECUTABLE_IMAGE | \ |
| 34 | IMAGE_FILE_LINE_NUMS_STRIPPED | \ |
| 35 | IMAGE_FILE_LOCAL_SYMS_STRIPPED | \ |
| 36 | IMAGE_FILE_DEBUG_STRIPPED) |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 37 | optional_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 38 | .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 39 | .byte 0x02 /* MajorLinkerVersion */ |
| 40 | .byte 0x14 /* MinorLinkerVersion */ |
| 41 | .long _edata - _start /* SizeOfCode */ |
| 42 | .long 0 /* SizeOfInitializedData */ |
| 43 | .long 0 /* SizeOfUninitializedData */ |
| 44 | .long _start - ImageBase /* AddressOfEntryPoint */ |
| 45 | .long _start - ImageBase /* BaseOfCode */ |
| 46 | |
| 47 | extra_header_fields: |
| 48 | .quad 0 /* ImageBase */ |
| 49 | .long 0x20 /* SectionAlignment */ |
| 50 | .long 0x8 /* FileAlignment */ |
| 51 | .short 0 /* MajorOperatingSystemVersion */ |
| 52 | .short 0 /* MinorOperatingSystemVersion */ |
| 53 | .short 0 /* MajorImageVersion */ |
| 54 | .short 0 /* MinorImageVersion */ |
| 55 | .short 0 /* MajorSubsystemVersion */ |
| 56 | .short 0 /* MinorSubsystemVersion */ |
| 57 | .long 0 /* Win32VersionValue */ |
| 58 | |
| 59 | .long _edata - ImageBase /* SizeOfImage */ |
| 60 | |
| 61 | /* |
| 62 | * Everything before the kernel image is considered part of the header |
| 63 | */ |
| 64 | .long _start - ImageBase /* SizeOfHeaders */ |
| 65 | .long 0 /* CheckSum */ |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 66 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 67 | .short 0 /* DllCharacteristics */ |
| 68 | .quad 0 /* SizeOfStackReserve */ |
| 69 | .quad 0 /* SizeOfStackCommit */ |
| 70 | .quad 0 /* SizeOfHeapReserve */ |
| 71 | .quad 0 /* SizeOfHeapCommit */ |
| 72 | .long 0 /* LoaderFlags */ |
| 73 | .long 0x6 /* 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 | |
| 85 | /* |
| 86 | * The EFI application loader requires a relocation section |
| 87 | * because EFI applications must be relocatable. This is a |
| 88 | * dummy section as far as we are concerned. |
| 89 | */ |
| 90 | .ascii ".reloc" |
| 91 | .byte 0 |
| 92 | .byte 0 /* end of 0 padding of section name */ |
| 93 | .long 0 |
| 94 | .long 0 |
| 95 | .long 0 /* SizeOfRawData */ |
| 96 | .long 0 /* PointerToRawData */ |
| 97 | .long 0 /* PointerToRelocations */ |
| 98 | .long 0 /* PointerToLineNumbers */ |
| 99 | .short 0 /* NumberOfRelocations */ |
| 100 | .short 0 /* NumberOfLineNumbers */ |
| 101 | .long 0x42100040 /* Characteristics (section flags) */ |
| 102 | |
| 103 | |
| 104 | .ascii ".text" |
| 105 | .byte 0 |
| 106 | .byte 0 |
| 107 | .byte 0 /* end of 0 padding of section name */ |
| 108 | .long _edata - _start /* VirtualSize */ |
| 109 | .long _start - ImageBase /* VirtualAddress */ |
| 110 | .long _edata - _start /* SizeOfRawData */ |
| 111 | .long _start - ImageBase /* PointerToRawData */ |
| 112 | |
| 113 | .long 0 /* PointerToRelocations (0 for executables) */ |
| 114 | .long 0 /* PointerToLineNumbers (0 for executables) */ |
| 115 | .short 0 /* NumberOfRelocations (0 for executables) */ |
| 116 | .short 0 /* NumberOfLineNumbers (0 for executables) */ |
| 117 | .long 0xe0500020 /* Characteristics (section flags) */ |
| 118 | |
| 119 | _start: |
| 120 | stp x29, x30, [sp, #-32]! |
| 121 | mov x29, sp |
| 122 | |
| 123 | stp x0, x1, [sp, #16] |
Simon Glass | 61378fd | 2016-11-07 08:47:11 -0700 | [diff] [blame] | 124 | adr x0, ImageBase |
| 125 | adrp x1, _DYNAMIC |
| 126 | add x1, x1, #:lo12:_DYNAMIC |
| 127 | bl _relocate |
| 128 | cbnz x0, 0f |
| 129 | |
| 130 | ldp x0, x1, [sp, #16] |
| 131 | bl efi_main |
| 132 | |
| 133 | 0: ldp x29, x30, [sp], #32 |
| 134 | ret |