1/* 2 * crt0-efi-mips64el.S - PE/COFF header for MIPS64 EFI applications 3 * 4 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 5 * Copright (C) 2017 Heiher <r@hev.cc> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice and this list of conditions, without modification. 12 * 2. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * Alternatively, this software may be distributed under the terms of the 16 * GNU General Public License as published by the Free Software Foundation; 17 * either version 2 of the License, or (at your option) any later version. 18 */ 19 20 .section .text.head 21 22 /* 23 * Magic "MZ" signature for PE/COFF 24 */ 25 .globl ImageBase 26ImageBase: 27 .ascii "MZ" 28 .skip 58 // 'MZ' + pad + offset == 64 29 .4byte pe_header - ImageBase // Offset to the PE header. 30pe_header: 31 .ascii "PE" 32 .2byte 0 33coff_header: 34 .2byte 0x166 // MIPS little endian 35 .2byte 2 // nr_sections 36 .4byte 0 // TimeDateStamp 37 .4byte 0 // PointerToSymbolTable 38 .4byte 0 // NumberOfSymbols 39 .2byte section_table - optional_header // SizeOfOptionalHeader 40 .2byte 0x206 // Characteristics. 41 // IMAGE_FILE_DEBUG_STRIPPED | 42 // IMAGE_FILE_EXECUTABLE_IMAGE | 43 // IMAGE_FILE_LINE_NUMS_STRIPPED 44optional_header: 45 .2byte 0x20b // 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 54extra_header_fields: 55 .8byte 0 // ImageBase 56 .4byte 0x20 // SectionAlignment 57 .4byte 0x8 // FileAlignment 58 .2byte 0 // MajorOperatingSystemVersion 59 .2byte 0 // MinorOperatingSystemVersion 60 .2byte 0 // MajorImageVersion 61 .2byte 0 // MinorImageVersion 62 .2byte 0 // MajorSubsystemVersion 63 .2byte 0 // MinorSubsystemVersion 64 .4byte 0 // Win32VersionValue 65 66 .4byte _edata - ImageBase // SizeOfImage 67 68 // Everything before the kernel image is considered part of the header 69 .4byte _start - ImageBase // SizeOfHeaders 70 .4byte 0 // CheckSum 71 .2byte EFI_SUBSYSTEM // Subsystem 72 .2byte 0 // DllCharacteristics 73 .8byte 0 // SizeOfStackReserve 74 .8byte 0 // SizeOfStackCommit 75 .8byte 0 // SizeOfHeapReserve 76 .8byte 0 // SizeOfHeapCommit 77 .4byte 0 // LoaderFlags 78 .4byte 0x6 // NumberOfRvaAndSizes 79 80 .8byte 0 // ExportTable 81 .8byte 0 // ImportTable 82 .8byte 0 // ResourceTable 83 .8byte 0 // ExceptionTable 84 .8byte 0 // CertificationTable 85 .8byte 0 // BaseRelocationTable 86 87 // Section table 88section_table: 89 90 /* 91 * The EFI application loader requires a relocation section 92 * because EFI applications must be relocatable. This is a 93 * dummy section as far as we are concerned. 94 */ 95 .ascii ".reloc" 96 .byte 0 97 .byte 0 // end of 0 padding of section name 98 .4byte 0 99 .4byte 0 100 .4byte 0 // SizeOfRawData 101 .4byte 0 // PointerToRawData 102 .4byte 0 // PointerToRelocations 103 .4byte 0 // PointerToLineNumbers 104 .2byte 0 // NumberOfRelocations 105 .2byte 0 // NumberOfLineNumbers 106 .4byte 0x42100040 // Characteristics (section flags) 107 108 109 .ascii ".text" 110 .byte 0 111 .byte 0 112 .byte 0 // end of 0 padding of section name 113 .4byte _edata - _start // VirtualSize 114 .4byte _start - ImageBase // VirtualAddress 115 .4byte _edata - _start // SizeOfRawData 116 .4byte _start - ImageBase // PointerToRawData 117 118 .4byte 0 // PointerToRelocations (0 for executables) 119 .4byte 0 // PointerToLineNumbers (0 for executables) 120 .2byte 0 // NumberOfRelocations (0 for executables) 121 .2byte 0 // NumberOfLineNumbers (0 for executables) 122 .4byte 0xe0500020 // Characteristics (section flags) 123 124 .set push 125 .set noreorder 126 .align 4 127 128 .globl _start 129 .ent _start 130 .type _start, @function 131_start: 132 daddiu $sp, -32 133 sd $ra, ($sp) 134 135 // Get pc & gp 136 .align 3 137 bal 1f 138 sd $gp, 8($sp) 139_pc: 140 .dword _gp 141 .dword _DYNAMIC 142 .dword _relocate 1431: 144 // pc in ra 145 ld $gp, ($ra) 146 dli $t0, _pc 147 dsubu $gp, $t0 148 daddu $gp, $ra 149 150 sd $a0, 16($sp) 151 sd $a1, 24($sp) 152 153 // a2: ImageHandle 154 move $a2, $a0 155 // a3: SystemTable 156 move $a3, $a1 157 // a0: ImageBase 158 dli $t1, ImageBase - _pc 159 daddu $a0, $ra, $t1 160 // a1: DynamicSection 161 ld $t1, 8($ra) 162 dsubu $t1, $t0 163 daddu $a1, $ra, $t1 164 // call _relocate 165 ld $t1, 16($ra) 166 dsubu $t1, $t0 167 daddu $t9, $ra, $t1 168 jalr $t9 169 nop 170 bnez $v0, 1b 171 nop 172 173 // a0: ImageHandle 174 ld $a0, 16($sp) 175 // call _start 176 dla $t9, _entry 177 jalr $t9 178 // a1: SystemTable 179 ld $a1, 24($sp) 180 1811: 182 ld $gp, 8($sp) 183 ld $ra, ($sp) 184 jr $ra 185 daddiu $sp, 32 186 .end _start 187 188 .set pop 189 190#if defined(__ELF__) && defined(__linux__) 191 .section .note.GNU-stack,"",%progbits 192#endif 193