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: |
| 19 | .ascii "MZ" |
| 20 | .skip 58 /* 'MZ' + pad + offset == 64 */ |
| 21 | .long pe_header - image_base /* Offset to the PE header */ |
| 22 | pe_header: |
| 23 | .ascii "PE" |
| 24 | .short 0 |
| 25 | coff_header: |
| 26 | .short 0x1c2 /* Mixed ARM/Thumb */ |
| 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 | fc03fb9 | 2016-11-07 08:47:10 -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_32BIT_MACHINE | \ |
| 37 | IMAGE_FILE_DEBUG_STRIPPED) |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 38 | optional_header: |
Bin Meng | a15de9e | 2018-10-02 07:39:33 -0700 | [diff] [blame] | 39 | .short 0x10b /* PE32 format */ |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -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 - image_base /* AddressOfEntryPoint */ |
| 46 | .long _start - image_base /* BaseOfCode */ |
| 47 | .long 0 /* BaseOfData */ |
| 48 | |
| 49 | extra_header_fields: |
| 50 | .long 0 /* image_base */ |
| 51 | .long 0x20 /* SectionAlignment */ |
| 52 | .long 0x8 /* FileAlignment */ |
| 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 - image_base /* SizeOfImage */ |
| 62 | |
| 63 | /* |
| 64 | * Everything before the kernel image is considered part of the header |
| 65 | */ |
| 66 | .long _start - image_base /* 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 | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 69 | .short 0 /* DllCharacteristics */ |
| 70 | .long 0 /* SizeOfStackReserve */ |
| 71 | .long 0 /* SizeOfStackCommit */ |
| 72 | .long 0 /* SizeOfHeapReserve */ |
| 73 | .long 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 | |
| 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 | .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 - image_base /* VirtualAddress */ |
| 110 | .long _edata - _start /* SizeOfRawData */ |
| 111 | .long _start - image_base /* 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 | stmfd sp!, {r0-r2, lr} |
| 121 | |
Simon Glass | fc03fb9 | 2016-11-07 08:47:10 -0700 | [diff] [blame] | 122 | adr r1, .L_DYNAMIC |
| 123 | ldr r0, [r1] |
| 124 | add r1, r0, r1 |
| 125 | adr r0, image_base |
| 126 | bl _relocate |
| 127 | teq r0, #0 |
| 128 | bne 0f |
| 129 | |
| 130 | ldmfd sp, {r0-r1} |
| 131 | bl efi_main |
| 132 | |
| 133 | 0: add sp, sp, #12 |
| 134 | ldr pc, [sp], #4 |
| 135 | |
| 136 | .L_DYNAMIC: |
| 137 | .word _DYNAMIC - . |