crt0-efi-mips64el.S 4.8 KB

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