| 1 |
/* |
| 2 |
* crt0-efi-arm.S - PE/COFF header for ARM EFI applications |
| 3 |
* |
| 4 |
* Copright (C) 2014 Linaro Ltd. <[email protected]> |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
* notice and this list of conditions, without modification. |
| 11 |
* 2. The name of the author may not be used to endorse or promote products |
| 12 |
* derived from this software without specific prior written permission. |
| 13 |
* |
| 14 |
* Alternatively, this software may be distributed under the terms of the |
| 15 |
* GNU General Public License as published by the Free Software Foundation; |
| 16 |
* either version 2 of the License, or (at your option) any later version. |
| 17 |
*/ |
| 18 |
|
| 19 |
.section .text.head |
| 20 |
|
| 21 |
/* |
| 22 |
* Magic "MZ" signature for PE/COFF |
| 23 |
*/ |
| 24 |
.globl ImageBase |
| 25 |
ImageBase: |
| 26 |
.ascii "MZ" |
| 27 |
.skip 58 // 'MZ' + pad + offset == 64 |
| 28 |
.long pe_header - ImageBase // Offset to the PE header. |
| 29 |
pe_header: |
| 30 |
.ascii "PE" |
| 31 |
.short 0 |
| 32 |
coff_header: |
| 33 |
.short 0x1c2 // Mixed ARM/Thumb |
| 34 |
.short 4 // nr_sections |
| 35 |
.long 0 // TimeDateStamp |
| 36 |
.long 0 // PointerToSymbolTable |
| 37 |
.long 1 // NumberOfSymbols |
| 38 |
.short section_table - optional_header // SizeOfOptionalHeader |
| 39 |
.short 0x306 // Characteristics. |
| 40 |
// IMAGE_FILE_32BIT_MACHINE | |
| 41 |
// IMAGE_FILE_DEBUG_STRIPPED | |
| 42 |
// IMAGE_FILE_EXECUTABLE_IMAGE | |
| 43 |
// IMAGE_FILE_LINE_NUMS_STRIPPED |
| 44 |
optional_header: |
| 45 |
.short 0x10b // PE32+ format |
| 46 |
.byte 0x02 // MajorLinkerVersion |
| 47 |
.byte 0x14 // MinorLinkerVersion |
| 48 |
.long _text_size // SizeOfCode |
| 49 |
.long _alldata_size // SizeOfInitializedData |
| 50 |
.long 0 // SizeOfUninitializedData |
| 51 |
.long _start - ImageBase // AddressOfEntryPoint |
| 52 |
.long _start - ImageBase // BaseOfCode |
| 53 |
.long _data - ImageBase // BaseOfData |
| 54 |
|
| 55 |
extra_header_fields: |
| 56 |
.long 0 // ImageBase |
| 57 |
.long 0x800 // SectionAlignment |
| 58 |
.long 0x200 // FileAlignment |
| 59 |
.short 0 // MajorOperatingSystemVersion |
| 60 |
.short 0 // MinorOperatingSystemVersion |
| 61 |
.short 0 // MajorImageVersion |
| 62 |
.short 0 // MinorImageVersion |
| 63 |
.short 0 // MajorSubsystemVersion |
| 64 |
.short 0 // MinorSubsystemVersion |
| 65 |
.long 0 // Win32VersionValue |
| 66 |
|
| 67 |
.long _erodata - ImageBase // SizeOfImage |
| 68 |
|
| 69 |
// Everything before the kernel image is considered part of the header |
| 70 |
.long _start - ImageBase // SizeOfHeaders |
| 71 |
.long 0 // CheckSum |
| 72 |
.short EFI_SUBSYSTEM // Subsystem |
| 73 |
.short 0 // DllCharacteristics |
| 74 |
.long 0 // SizeOfStackReserve |
| 75 |
.long 0 // SizeOfStackCommit |
| 76 |
.long 0 // SizeOfHeapReserve |
| 77 |
.long 0 // SizeOfHeapCommit |
| 78 |
.long 0 // LoaderFlags |
| 79 |
.long 0x6 // NumberOfRvaAndSizes |
| 80 |
|
| 81 |
.quad 0 // ExportTable |
| 82 |
.quad 0 // ImportTable |
| 83 |
.quad 0 // ResourceTable |
| 84 |
.quad 0 // ExceptionTable |
| 85 |
.quad 0 // CertificationTable |
| 86 |
.quad 0 // BaseRelocationTable |
| 87 |
|
| 88 |
// Section table |
| 89 |
section_table: |
| 90 |
|
| 91 |
#if 0 |
| 92 |
/* |
| 93 |
* The EFI application loader requires a relocation section |
| 94 |
* because EFI applications must be relocatable. This is a |
| 95 |
* dummy section as far as we are concerned. |
| 96 |
*/ |
| 97 |
.ascii ".reloc" |
| 98 |
.byte 0 |
| 99 |
.byte 0 // end of 0 padding of section name |
| 100 |
.long 0 |
| 101 |
.long 0 |
| 102 |
.long 0 // SizeOfRawData |
| 103 |
.long 0 // PointerToRawData |
| 104 |
.long 0 // PointerToRelocations |
| 105 |
.long 0 // PointerToLineNumbers |
| 106 |
.short 0 // NumberOfRelocations |
| 107 |
.short 0 // NumberOfLineNumbers |
| 108 |
.long 0x42100040 // Characteristics (section flags) |
| 109 |
#endif |
| 110 |
|
| 111 |
.ascii ".text\0\0\0" |
| 112 |
.long _evtext - _start // VirtualSize |
| 113 |
.long _start - ImageBase // VirtualAddress |
| 114 |
.long _etext - _start // SizeOfRawData |
| 115 |
.long _start - ImageBase // PointerToRawData |
| 116 |
|
| 117 |
.long 0 // PointerToRelocations (0 for executables) |
| 118 |
.long 0 // PointerToLineNumbers (0 for executables) |
| 119 |
.short 0 // NumberOfRelocations (0 for executables) |
| 120 |
.short 0 // NumberOfLineNumbers (0 for executables) |
| 121 |
/* |
| 122 |
* EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_MEM_EXECUTE | EFI_IMAGE_SCN_CNT_CODE |
| 123 |
*/ |
| 124 |
.long 0x60000020 // Characteristics (section flags) |
| 125 |
|
| 126 |
.ascii ".data\0\0\0" |
| 127 |
.long _data_vsize // VirtualSize |
| 128 |
.long _data - ImageBase // VirtualAddress |
| 129 |
.long _data_size // SizeOfRawData |
| 130 |
.long _data - ImageBase // PointerToRawData |
| 131 |
|
| 132 |
.long 0 // PointerToRelocations (0 for executables) |
| 133 |
.long 0 // PointerToLineNumbers (0 for executables) |
| 134 |
.short 0 // NumberOfRelocations (0 for executables) |
| 135 |
.short 0 // NumberOfLineNumbers (0 for executables) |
| 136 |
/* |
| 137 |
* EFI_IMAGE_SCN_MEM_WRITE | EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
| 138 |
*/ |
| 139 |
.long 0xc0000040 // Characteristics (section flags) |
| 140 |
|
| 141 |
.ascii ".sbat\0\0\0" |
| 142 |
.long _sbat_vsize // VirtualSize |
| 143 |
.long _sbat - ImageBase // VirtualAddress |
| 144 |
.long _sbat_size // SizeOfRawData |
| 145 |
.long _sbat - ImageBase // PointerToRawData |
| 146 |
|
| 147 |
.long 0 // PointerToRelocations (0 for executables) |
| 148 |
.long 0 // PointerToLineNumbers (0 for executables) |
| 149 |
.short 0 // NumberOfRelocations (0 for executables) |
| 150 |
.short 0 // NumberOfLineNumbers (0 for executables) |
| 151 |
/* |
| 152 |
* EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_ALIGN_8BYTES | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
| 153 |
*/ |
| 154 |
.long 0x40400040 // Characteristics (section flags) |
| 155 |
|
| 156 |
.ascii ".rodata\0" |
| 157 |
.long _rodata_vsize // VirtualSize |
| 158 |
.long _rodata - ImageBase // VirtualAddress |
| 159 |
.long _rodata_size // SizeOfRawData |
| 160 |
.long _rodata - ImageBase // PointerToRawData |
| 161 |
|
| 162 |
.long 0 // PointerToRelocations (0 for executables) |
| 163 |
.long 0 // PointerToLineNumbers (0 for executables) |
| 164 |
.short 0 // NumberOfRelocations (0 for executables) |
| 165 |
.short 0 // NumberOfLineNumbers (0 for executables) |
| 166 |
/* |
| 167 |
* EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_ALIGN_8BYTES | EFI_IMAGE_SCN_CNT_INITIALIZED_DATA |
| 168 |
*/ |
| 169 |
.long 0x40400040 // Characteristics (section flags) |
| 170 |
|
| 171 |
|
| 172 |
.align 11 |
| 173 |
_start: |
| 174 |
stmfd sp!, {r0-r2, lr} |
| 175 |
|
| 176 |
mov r2, r0 |
| 177 |
mov r3, r1 |
| 178 |
adr r1, .L_DYNAMIC |
| 179 |
ldr r0, [r1] |
| 180 |
add r1, r0, r1 |
| 181 |
adr r0, ImageBase |
| 182 |
bl _relocate |
| 183 |
teq r0, #0 |
| 184 |
bne 0f |
| 185 |
|
| 186 |
ldmfd sp, {r0-r1} |
| 187 |
bl efi_main |
| 188 |
|
| 189 |
0: add sp, sp, #12 |
| 190 |
ldr pc, [sp], #4 |
| 191 |
|
| 192 |
.L_DYNAMIC: |
| 193 |
.word _DYNAMIC - . |
| 194 |
.section .note.GNU-stack,"a" |