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 .long pe_header - ImageBase // Offset to the PE header. 29pe_header: 30 .ascii "PE" 31 .short 0 32coff_header: 33 .short 0x1c2 // Mixed ARM/Thumb 34 .short 2 // 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 44optional_header: 45 .short 0x10b // PE32+ format 46 .byte 0x02 // MajorLinkerVersion 47 .byte 0x14 // MinorLinkerVersion 48 .long _edata - _start // SizeOfCode 49 .long 0 // SizeOfInitializedData 50 .long 0 // SizeOfUninitializedData 51 .long _start - ImageBase // AddressOfEntryPoint 52 .long _start - ImageBase // BaseOfCode 53 .long 0 // BaseOfData 54 55extra_header_fields: 56 .long 0 // ImageBase 57 .long 0x20 // SectionAlignment 58 .long 0x8 // 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 _edata - 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 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 .long 0 100 .long 0 101 .long 0 // SizeOfRawData 102 .long 0 // PointerToRawData 103 .long 0 // PointerToRelocations 104 .long 0 // PointerToLineNumbers 105 .short 0 // NumberOfRelocations 106 .short 0 // NumberOfLineNumbers 107 .long 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 .long _edata - _start // VirtualSize 115 .long _start - ImageBase // VirtualAddress 116 .long _edata - _start // SizeOfRawData 117 .long _start - ImageBase // PointerToRawData 118 119 .long 0 // PointerToRelocations (0 for executables) 120 .long 0 // PointerToLineNumbers (0 for executables) 121 .short 0 // NumberOfRelocations (0 for executables) 122 .short 0 // NumberOfLineNumbers (0 for executables) 123 .long 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 efi_main 140 1410: add sp, sp, #12 142 ldr pc, [sp], #4 143 144.L_DYNAMIC: 145 .word _DYNAMIC - . 146