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 2 // 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 _edata - _start // SizeOfCode 49 .4byte 0 // SizeOfInitializedData 50 .4byte 0 // SizeOfUninitializedData 51 .4byte _start - ImageBase // AddressOfEntryPoint 52 .4byte _start - ImageBase // BaseOfCode 53 .4byte 0 // BaseOfData 54 55extra_header_fields: 56 .4byte 0 // ImageBase 57 .4byte 0x20 // SectionAlignment 58 .4byte 0x8 // 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 _edata - 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 .8byte 0 // BaseRelocationTable 87 .8byte 0 // Debug 88 .8byte 0 // Architecture 89 .8byte 0 // Global Ptr 90 .8byte 0 // TLS Table 91 .8byte 0 // Load Config Table 92 .8byte 0 // Bound Import 93 .8byte 0 // IAT 94 .8byte 0 // Delay Import Descriptor 95 .8byte 0 // CLR Runtime Header 96 .8byte 0 // Reserved, must be zero 97 98 // Section table 99section_table: 100 101 /* 102 * The EFI application loader requires a relocation section 103 * because EFI applications must be relocatable. This is a 104 * dummy section as far as we are concerned. 105 */ 106 .ascii ".reloc" 107 .byte 0 108 .byte 0 // end of 0 padding of section name 109 .4byte 0 110 .4byte 0 111 .4byte 0 // SizeOfRawData 112 .4byte 0 // PointerToRawData 113 .4byte 0 // PointerToRelocations 114 .4byte 0 // PointerToLineNumbers 115 .2byte 0 // NumberOfRelocations 116 .2byte 0 // NumberOfLineNumbers 117 .4byte 0x42100040 // Characteristics (section flags) 118 119 120 .ascii ".text" 121 .byte 0 122 .byte 0 123 .byte 0 // end of 0 padding of section name 124 .4byte _edata - _start // VirtualSize 125 .4byte _start - ImageBase // VirtualAddress 126 .4byte _edata - _start // SizeOfRawData 127 .4byte _start - ImageBase // PointerToRawData 128 129 .4byte 0 // PointerToRelocations (0 for executables) 130 .4byte 0 // PointerToLineNumbers (0 for executables) 131 .2byte 0 // NumberOfRelocations (0 for executables) 132 .2byte 0 // NumberOfLineNumbers (0 for executables) 133 .4byte 0xe0500020 // Characteristics (section flags) 134 135.globl _start 136_start: 137 stmfd sp!, {r0-r2, lr} 138 139 mov r2, r0 140 mov r3, r1 141 adr r1, .L_DYNAMIC 142 ldr r0, [r1] 143 add r1, r0, r1 144 adr r0, ImageBase 145 bl _relocate 146 teq r0, #0 147 bne 0f 148 149 ldmfd sp, {r0-r1} 150 bl _entry 151 1520: add sp, sp, #12 153 ldr pc, [sp], #4 154 155.L_DYNAMIC: 156 .4byte _DYNAMIC - . 157 158#if defined(__ELF__) && defined(__linux__) 159 .section .note.GNU-stack,"",%progbits 160#endif 161