crt0-efi-mips64el.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. .section .text.head
  20. /*
  21. * Magic "MZ" signature for PE/COFF
  22. */
  23. .globl ImageBase
  24. ImageBase:
  25. .ascii "MZ"
  26. .skip 58 // 'MZ' + pad + offset == 64
  27. .4byte pe_header - ImageBase // Offset to the PE header.
  28. pe_header:
  29. .ascii "PE"
  30. .2byte 0
  31. coff_header:
  32. .2byte 0x166 // MIPS little endian
  33. .2byte 2 // nr_sections
  34. .4byte 0 // TimeDateStamp
  35. .4byte 0 // PointerToSymbolTable
  36. .4byte 0 // NumberOfSymbols
  37. .2byte section_table - optional_header // SizeOfOptionalHeader
  38. .2byte 0x206 // Characteristics.
  39. // IMAGE_FILE_DEBUG_STRIPPED |
  40. // IMAGE_FILE_EXECUTABLE_IMAGE |
  41. // IMAGE_FILE_LINE_NUMS_STRIPPED
  42. optional_header:
  43. .2byte 0x20b // PE32+ format
  44. .byte 0x02 // MajorLinkerVersion
  45. .byte 0x14 // MinorLinkerVersion
  46. .4byte _edata - _start // SizeOfCode
  47. .4byte 0 // SizeOfInitializedData
  48. .4byte 0 // SizeOfUninitializedData
  49. .4byte _start - ImageBase // AddressOfEntryPoint
  50. .4byte _start - ImageBase // BaseOfCode
  51. extra_header_fields:
  52. .8byte 0 // ImageBase
  53. .4byte 0x20 // SectionAlignment
  54. .4byte 0x8 // FileAlignment
  55. .2byte 0 // MajorOperatingSystemVersion
  56. .2byte 0 // MinorOperatingSystemVersion
  57. .2byte 0 // MajorImageVersion
  58. .2byte 0 // MinorImageVersion
  59. .2byte 0 // MajorSubsystemVersion
  60. .2byte 0 // MinorSubsystemVersion
  61. .4byte 0 // Win32VersionValue
  62. .4byte _edata - ImageBase // SizeOfImage
  63. // Everything before the kernel image is considered part of the header
  64. .4byte _start - ImageBase // SizeOfHeaders
  65. .4byte 0 // CheckSum
  66. .2byte EFI_SUBSYSTEM // Subsystem
  67. .2byte 0 // DllCharacteristics
  68. .8byte 0 // SizeOfStackReserve
  69. .8byte 0 // SizeOfStackCommit
  70. .8byte 0 // SizeOfHeapReserve
  71. .8byte 0 // SizeOfHeapCommit
  72. .4byte 0 // LoaderFlags
  73. .4byte 0x10 // NumberOfRvaAndSizes
  74. .8byte 0 // ExportTable
  75. .8byte 0 // ImportTable
  76. .8byte 0 // ResourceTable
  77. .8byte 0 // ExceptionTable
  78. .8byte 0 // CertificationTable
  79. .8byte 0 // BaseRelocationTable
  80. .8byte 0 // Debug
  81. .8byte 0 // Architecture
  82. .8byte 0 // Global Ptr
  83. .8byte 0 // TLS Table
  84. .8byte 0 // Load Config Table
  85. .8byte 0 // Bound Import
  86. .8byte 0 // IAT
  87. .8byte 0 // Delay Import Descriptor
  88. .8byte 0 // CLR Runtime Header
  89. .8byte 0 // Reserved, must be zero
  90. // Section table
  91. section_table:
  92. /*
  93. * The EFI application loader requires a relocation section
  94. * because EFI applications must be relocatable. This is a
  95. * dummy section as far as we are concerned.
  96. */
  97. .ascii ".reloc"
  98. .byte 0
  99. .byte 0 // end of 0 padding of section name
  100. .4byte 0
  101. .4byte 0
  102. .4byte 0 // SizeOfRawData
  103. .4byte 0 // PointerToRawData
  104. .4byte 0 // PointerToRelocations
  105. .4byte 0 // PointerToLineNumbers
  106. .2byte 0 // NumberOfRelocations
  107. .2byte 0 // NumberOfLineNumbers
  108. .4byte 0x42100040 // Characteristics (section flags)
  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. .4byte 0 // PointerToRelocations (0 for executables)
  118. .4byte 0 // PointerToLineNumbers (0 for executables)
  119. .2byte 0 // NumberOfRelocations (0 for executables)
  120. .2byte 0 // NumberOfLineNumbers (0 for executables)
  121. .4byte 0xe0500020 // Characteristics (section flags)
  122. .set push
  123. .set noreorder
  124. .align 4
  125. .globl _start
  126. .ent _start
  127. .type _start, @function
  128. _start:
  129. daddiu $sp, -32
  130. sd $ra, ($sp)
  131. // Get pc & gp
  132. .align 3
  133. bal 1f
  134. sd $gp, 8($sp)
  135. _pc:
  136. .dword _gp
  137. .dword _DYNAMIC
  138. .dword _relocate
  139. 1:
  140. // pc in ra
  141. ld $gp, ($ra)
  142. dli $t0, _pc
  143. dsubu $gp, $t0
  144. daddu $gp, $ra
  145. sd $a0, 16($sp)
  146. sd $a1, 24($sp)
  147. // a2: ImageHandle
  148. move $a2, $a0
  149. // a3: SystemTable
  150. move $a3, $a1
  151. // a0: ImageBase
  152. dli $t1, ImageBase - _pc
  153. daddu $a0, $ra, $t1
  154. // a1: DynamicSection
  155. ld $t1, 8($ra)
  156. dsubu $t1, $t0
  157. daddu $a1, $ra, $t1
  158. // call _relocate
  159. ld $t1, 16($ra)
  160. dsubu $t1, $t0
  161. daddu $t9, $ra, $t1
  162. jalr $t9
  163. nop
  164. bnez $v0, 1b
  165. nop
  166. // a0: ImageHandle
  167. ld $a0, 16($sp)
  168. // call _start
  169. dla $t9, _entry
  170. jalr $t9
  171. // a1: SystemTable
  172. ld $a1, 24($sp)
  173. 1:
  174. ld $gp, 8($sp)
  175. ld $ra, ($sp)
  176. jr $ra
  177. daddiu $sp, 32
  178. .end _start
  179. .set pop
  180. #if defined(__ELF__) && defined(__linux__)
  181. .section .note.GNU-stack,"",%progbits
  182. #endif