1/* 2 * crt0-efi-arm.S - PE/COFF header for ARM EFI applications 3 * 4 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 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 25ImageBase: 26 .ascii "MZ" 27 .skip 58 // 'MZ' + pad + offset == 64 28 .4byte pe_header - ImageBase // Offset to the PE header. 29pe_header: 30 .ascii "PE" 31 .2byte 0 32coff_header: 33 .2byte 0x1c2 // Mixed ARM/Thumb 34 .2byte 4 // nr_sections 35 .4byte 0 // TimeDateStamp 36 .4byte 0 // PointerToSymbolTable 37 .4byte 0 // NumberOfSymbols 38 .2byte section_table - optional_header // SizeOfOptionalHeader 39 .2byte 0x306 // Characteristics. 40 // IMAGE_FILE_32BIT_MACHINE | 41 // IMAGE_FILE_DEBUG_STRIPPED | 42 // IMAGE_FILE_EXECUTABLE_IMAGE | 43 // IMAGE_FILE_LINE_NUMS_STRIPPED 44optional_header: 45 .2byte 0x10b // PE32+ format 46 .byte 0x02 // MajorLinkerVersion 47 .byte 0x14 // MinorLinkerVersion 48 .4byte _etext - _start // SizeOfCode 49 .4byte _alldata_size - ImageBase // SizeOfInitializedData 50 .4byte 0 // SizeOfUninitializedData 51 .4byte _start - ImageBase // AddressOfEntryPoint 52 .4byte _start - ImageBase // BaseOfCode 53 .4byte _reloc - ImageBase // BaseOfData 54 55extra_header_fields: 56 .4byte 0 // ImageBase 57 .4byte 0x1000 // SectionAlignment 58 .4byte 0x1000 // FileAlignment 59 .2byte 0 // MajorOperatingSystemVersion 60 .2byte 0 // MinorOperatingSystemVersion 61 .2byte 0 // MajorImageVersion 62 .2byte 0 // MinorImageVersion 63 .2byte 0 // MajorSubsystemVersion 64 .2byte 0 // MinorSubsystemVersion 65 .4byte 0 // Win32VersionValue 66 67 .4byte _image_end - ImageBase // SizeOfImage 68 69 // Everything before the kernel image is considered part of the header 70 .4byte _start - ImageBase // SizeOfHeaders 71 .4byte 0 // CheckSum 72 .2byte EFI_SUBSYSTEM // Subsystem 73 .2byte 0 // DllCharacteristics 74 .4byte 0 // SizeOfStackReserve 75 .4byte 0 // SizeOfStackCommit 76 .4byte 0 // SizeOfHeapReserve 77 .4byte 0 // SizeOfHeapCommit 78 .4byte 0 // LoaderFlags 79 .4byte 0x10 // NumberOfRvaAndSizes 80 81 .8byte 0 // ExportTable 82 .8byte 0 // ImportTable 83 .8byte 0 // ResourceTable 84 .8byte 0 // ExceptionTable 85 .8byte 0 // CertificationTable 86 .4byte _reloc - ImageBase // BaseRelocationTable (VirtualAddress) 87 .4byte _reloc_vsize - ImageBase // BaseRelocationTable (Size) 88 .8byte 0 // Debug 89 .8byte 0 // Architecture 90 .8byte 0 // Global Ptr 91 .8byte 0 // TLS Table 92 .8byte 0 // Load Config Table 93 .8byte 0 // Bound Import 94 .8byte 0 // IAT 95 .8byte 0 // Delay Import Descriptor 96 .8byte 0 // CLR Runtime Header 97 .8byte 0 // Reserved, must be zero 98 99 // Section table 100section_table: 101 102 .ascii ".text\0\0\0" 103 .4byte _evtext - _start // VirtualSize 104 .4byte _start - ImageBase // VirtualAddress 105 .4byte _etext - _start // SizeOfRawData 106 .4byte _start - ImageBase // PointerToRawData 107 .4byte 0 // PointerToRelocations (0 for executables) 108 .4byte 0 // PointerToLineNumbers (0 for executables) 109 .2byte 0 // NumberOfRelocations (0 for executables) 110 .2byte 0 // NumberOfLineNumbers (0 for executables) 111 .4byte 0x60000020 // Characteristics (section flags) 112 113 /* 114 * The EFI application loader requires a relocation section 115 * because EFI applications must be relocatable. This is a 116 * dummy section as far as we are concerned. 117 */ 118 .ascii ".reloc\0\0" 119 .4byte _reloc_vsize - ImageBase // VirtualSize 120 .4byte _reloc - ImageBase // VirtualAddress 121 .4byte _reloc_size - ImageBase // SizeOfRawData 122 .4byte _reloc - ImageBase // PointerToRawData 123 .4byte 0 // PointerToRelocations 124 .4byte 0 // PointerToLineNumbers 125 .2byte 0 // NumberOfRelocations 126 .2byte 0 // NumberOfLineNumbers 127 .4byte 0x42000040 // Characteristics (section flags) 128 129 .ascii ".data\0\0\0" 130 .4byte _data_vsize - ImageBase // VirtualSize 131 .4byte _data - ImageBase // VirtualAddress 132 .4byte _data_size - ImageBase // SizeOfRawData 133 .4byte _data - ImageBase // PointerToRawData 134 .4byte 0 // PointerToRelocations 135 .4byte 0 // PointerToLineNumbers 136 .2byte 0 // NumberOfRelocations 137 .2byte 0 // NumberOfLineNumbers 138 .4byte 0xC0000040 // Characteristics (section flags) 139 140 .ascii ".rodata\0" 141 .4byte _rodata_vsize - ImageBase // VirtualSize 142 .4byte _rodata - ImageBase // VirtualAddress 143 .4byte _rodata_size - ImageBase // SizeOfRawData 144 .4byte _rodata - ImageBase // PointerToRawData 145 .4byte 0 // PointerToRelocations 146 .4byte 0 // PointerToLineNumbers 147 .2byte 0 // NumberOfRelocations 148 .2byte 0 // NumberOfLineNumbers 149 .4byte 0x40000040 // Characteristics (section flags) 150 151.balign 256 152.globl _start 153.type _start,%function 154_start: 155 stmfd sp!, {r0-r2, lr} 156 157 mov r2, r0 158 mov r3, r1 159 adr r1, .L_DYNAMIC 160 ldr r0, [r1] 161 add r1, r0, r1 162 adr r0, ImageBase 163 bl _relocate 164 teq r0, #0 165 bne 0f 166 167 ldmfd sp, {r0-r1} 168 bl _entry 169 1700: add sp, sp, #12 171 ldr pc, [sp], #4 172 173.L_DYNAMIC: 174 .4byte _DYNAMIC - . 175 176// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: 177 178 .data 179dummy: .4byte 0 180 181#define IMAGE_REL_ABSOLUTE 0 182 .section .areloc 183 .4byte dummy // Page RVA 184 .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits 185 .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 186 .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 187 188#if defined(__ELF__) && defined(__linux__) 189 .section .note.GNU-stack,"",%progbits 190#endif 191