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 0x6 // 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 88 // Section table 89section_table: 90 91 /* 92 * The EFI application loader requires a relocation section 93 * because EFI applications must be relocatable. This is a 94 * dummy section as far as we are concerned. 95 */ 96 .ascii ".reloc" 97 .byte 0 98 .byte 0 // end of 0 padding of section name 99 .4byte 0 100 .4byte 0 101 .4byte 0 // SizeOfRawData 102 .4byte 0 // PointerToRawData 103 .4byte 0 // PointerToRelocations 104 .4byte 0 // PointerToLineNumbers 105 .2byte 0 // NumberOfRelocations 106 .2byte 0 // NumberOfLineNumbers 107 .4byte 0x42100040 // Characteristics (section flags) 108 109 110 .ascii ".text" 111 .byte 0 112 .byte 0 113 .byte 0 // end of 0 padding of section name 114 .4byte _edata - _start // VirtualSize 115 .4byte _start - ImageBase // VirtualAddress 116 .4byte _edata - _start // SizeOfRawData 117 .4byte _start - ImageBase // PointerToRawData 118 119 .4byte 0 // PointerToRelocations (0 for executables) 120 .4byte 0 // PointerToLineNumbers (0 for executables) 121 .2byte 0 // NumberOfRelocations (0 for executables) 122 .2byte 0 // NumberOfLineNumbers (0 for executables) 123 .4byte 0xe0500020 // Characteristics (section flags) 124 125_start: 126 stmfd sp!, {r0-r2, lr} 127 128 mov r2, r0 129 mov r3, r1 130 adr r1, .L_DYNAMIC 131 ldr r0, [r1] 132 add r1, r0, r1 133 adr r0, ImageBase 134 bl _relocate 135 teq r0, #0 136 bne 0f 137 138 ldmfd sp, {r0-r1} 139 bl _entry 140 1410: add sp, sp, #12 142 ldr pc, [sp], #4 143 144.L_DYNAMIC: 145 .2byte _DYNAMIC - . 146 147#if defined(__ELF__) && defined(__linux__) 148 .section .note.GNU-stack,"",%progbits 149#endif 150