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 | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 2 | /* |
| 3 | * crt0-efi-arm.S - PE/COFF header for ARM EFI applications |
| 4 | * |
| 5 | * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> |
| 6 | * |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 7 | * This file is taken and modified from the gnu-efi project. |
| 8 | */ |
| 9 | |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 10 | #include <asm-generic/pe.h> |
| 11 | |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 12 | .section .text.head |
| 13 | |
| 14 | /* |
| 15 | * Magic "MZ" signature for PE/COFF |
| 16 | */ |
| 17 | .globl image_base |
| 18 | image_base: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 19 | .short IMAGE_DOS_SIGNATURE /* 'MZ' */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 20 | .skip 58 /* 'MZ' + pad + offset == 64 */ |
| 21 | .long pe_header - image_base /* Offset to the PE header */ |
| 22 | pe_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 23 | .long IMAGE_NT_SIGNATURE /* 'PE' */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 24 | coff_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 25 | .short IMAGE_FILE_MACHINE_THUMB /* Mixed ARM/Thumb */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 26 | .short 2 /* nr_sections */ |
| 27 | .long 0 /* TimeDateStamp */ |
| 28 | .long 0 /* PointerToSymbolTable */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 29 | .long 0 /* NumberOfSymbols */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 30 | .short section_table - optional_header /* SizeOfOptionalHeader */ |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 31 | /* Characteristics */ |
| 32 | .short (IMAGE_FILE_EXECUTABLE_IMAGE | \ |
| 33 | IMAGE_FILE_LINE_NUMS_STRIPPED | \ |
| 34 | IMAGE_FILE_LOCAL_SYMS_STRIPPED | \ |
| 35 | IMAGE_FILE_32BIT_MACHINE | \ |
| 36 | IMAGE_FILE_DEBUG_STRIPPED) |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 37 | optional_header: |
Heinrich Schuchardt | d680e9a | 2019-07-11 06:39:32 +0200 | [diff] [blame] | 38 | .short IMAGE_NT_OPTIONAL_HDR32_MAGIC /* PE32 format */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -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 - image_base /* AddressOfEntryPoint */ |
| 45 | .long _start - image_base /* BaseOfCode */ |
| 46 | .long 0 /* BaseOfData */ |
| 47 | |
| 48 | extra_header_fields: |
| 49 | .long 0 /* image_base */ |
Heinrich Schuchardt | f263479 | 2022-01-14 21:40:15 +0100 | [diff] [blame] | 50 | .long 0x200 /* SectionAlignment */ |
| 51 | .long 0x200 /* FileAlignment */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -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 - image_base /* SizeOfImage */ |
| 61 | |
| 62 | /* |
| 63 | * Everything before the kernel image is considered part of the header |
| 64 | */ |
| 65 | .long _start - image_base /* SizeOfHeaders */ |
| 66 | .long 0 /* CheckSum */ |
Heinrich Schuchardt | 467fd7a | 2018-01-31 18:45:35 +0000 | [diff] [blame] | 67 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ |
Heinrich Schuchardt | 299425d | 2024-02-14 21:43:21 +0100 | [diff] [blame] | 68 | #if CONFIG_VENDOR_EFI |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 69 | .short 0 /* DllCharacteristics */ |
Heinrich Schuchardt | 299425d | 2024-02-14 21:43:21 +0100 | [diff] [blame] | 70 | #else |
| 71 | .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT |
| 72 | #endif |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 73 | .long 0 /* SizeOfStackReserve */ |
| 74 | .long 0 /* SizeOfStackCommit */ |
| 75 | .long 0 /* SizeOfHeapReserve */ |
| 76 | .long 0 /* SizeOfHeapCommit */ |
| 77 | .long 0 /* LoaderFlags */ |
| 78 | .long 0x6 /* NumberOfRvaAndSizes */ |
| 79 | |
| 80 | .quad 0 /* ExportTable */ |
| 81 | .quad 0 /* ImportTable */ |
| 82 | .quad 0 /* ResourceTable */ |
| 83 | .quad 0 /* ExceptionTable */ |
| 84 | .quad 0 /* CertificationTable */ |
| 85 | .quad 0 /* BaseRelocationTable */ |
| 86 | |
| 87 | section_table: |
| 88 | |
| 89 | /* |
| 90 | * The EFI application loader requires a relocation section |
| 91 | * because EFI applications must be relocatable. This is a |
| 92 | * dummy section as far as we are concerned. |
| 93 | */ |
| 94 | .ascii ".reloc" |
| 95 | .byte 0 |
| 96 | .byte 0 /* end of 0 padding of section name */ |
| 97 | .long 0 |
| 98 | .long 0 |
| 99 | .long 0 /* SizeOfRawData */ |
| 100 | .long 0 /* PointerToRawData */ |
| 101 | .long 0 /* PointerToRelocations */ |
| 102 | .long 0 /* PointerToLineNumbers */ |
| 103 | .short 0 /* NumberOfRelocations */ |
| 104 | .short 0 /* NumberOfLineNumbers */ |
| 105 | .long 0x42100040 /* Characteristics (section flags) */ |
| 106 | |
| 107 | .ascii ".text" |
| 108 | .byte 0 |
| 109 | .byte 0 |
| 110 | .byte 0 /* end of 0 padding of section name */ |
| 111 | .long _edata - _start /* VirtualSize */ |
| 112 | .long _start - image_base /* VirtualAddress */ |
| 113 | .long _edata - _start /* SizeOfRawData */ |
| 114 | .long _start - image_base /* PointerToRawData */ |
| 115 | |
| 116 | .long 0 /* PointerToRelocations (0 for executables) */ |
| 117 | .long 0 /* PointerToLineNumbers (0 for executables) */ |
| 118 | .short 0 /* NumberOfRelocations (0 for executables) */ |
| 119 | .short 0 /* NumberOfLineNumbers (0 for executables) */ |
| 120 | .long 0xe0500020 /* Characteristics (section flags) */ |
| 121 | |
Heinrich Schuchardt | 0902863 | 2024-02-26 22:24:07 +0100 | [diff] [blame^] | 122 | .align 12 |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 123 | _start: |
| 124 | stmfd sp!, {r0-r2, lr} |
| 125 | |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 126 | adr r1, .L_DYNAMIC |
| 127 | ldr r0, [r1] |
| 128 | add r1, r0, r1 |
Heinrich Schuchardt | 0902863 | 2024-02-26 22:24:07 +0100 | [diff] [blame^] | 129 | adrl r0, image_base |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 130 | bl _relocate |
| 131 | teq r0, #0 |
| 132 | bne 0f |
| 133 | |
| 134 | ldmfd sp, {r0-r1} |
| 135 | bl efi_main |
| 136 | |
| 137 | 0: add sp, sp, #12 |
| 138 | ldr pc, [sp], #4 |
| 139 | |
| 140 | .L_DYNAMIC: |
| 141 | .word _DYNAMIC - . |