crt0-efi-riscv64.S 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  4. * Copright (C) 2018 Alexander Graf <agraf@suse.de>
  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. #ifndef EFI_SUBSYSTEM
  19. #define EFI_SUBSYSTEM 10
  20. #endif
  21. .section .text.head
  22. /*
  23. * Magic "MZ" signature for PE/COFF
  24. */
  25. .globl ImageBase
  26. ImageBase:
  27. .ascii "MZ"
  28. .skip 58 // 'MZ' + pad + offset == 64
  29. .4byte pe_header - ImageBase // Offset to the PE header.
  30. pe_header:
  31. .ascii "PE"
  32. .2byte 0
  33. coff_header:
  34. .2byte 0x5064 // riscv64
  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
  44. optional_header:
  45. .2byte 0x20b // PE32+ format
  46. .byte 0x02 // MajorLinkerVersion
  47. .byte 0x14 // MinorLinkerVersion
  48. .4byte _data - _start // SizeOfCode
  49. .4byte _edata - _data // SizeOfInitializedData
  50. .4byte 0 // SizeOfUninitializedData
  51. .4byte _start - ImageBase // AddressOfEntryPoint
  52. .4byte _start - ImageBase // BaseOfCode
  53. extra_header_fields:
  54. .8byte 0 // ImageBase
  55. .4byte 0x1000 // SectionAlignment
  56. .4byte 0x200 // FileAlignment
  57. .2byte 0 // MajorOperatingSystemVersion
  58. .2byte 0 // MinorOperatingSystemVersion
  59. .2byte 0 // MajorImageVersion
  60. .2byte 0 // MinorImageVersion
  61. .2byte 0 // MajorSubsystemVersion
  62. .2byte 0 // MinorSubsystemVersion
  63. .4byte 0 // Win32VersionValue
  64. .4byte _edata - ImageBase // SizeOfImage
  65. // Everything before the kernel image is considered part of the header
  66. .4byte _start - ImageBase // SizeOfHeaders
  67. .4byte 0 // CheckSum
  68. .2byte EFI_SUBSYSTEM // Subsystem
  69. .2byte 0 // DllCharacteristics
  70. .8byte 0 // SizeOfStackReserve
  71. .8byte 0 // SizeOfStackCommit
  72. .8byte 0 // SizeOfHeapReserve
  73. .8byte 0 // SizeOfHeapCommit
  74. .4byte 0 // LoaderFlags
  75. .4byte 0x10 // NumberOfRvaAndSizes
  76. .8byte 0 // ExportTable
  77. .8byte 0 // ImportTable
  78. .8byte 0 // ResourceTable
  79. .8byte 0 // ExceptionTable
  80. .8byte 0 // CertificationTable
  81. .8byte 0 // BaseRelocationTable
  82. .8byte 0 // Debug
  83. .8byte 0 // Architecture
  84. .8byte 0 // Global Ptr
  85. .8byte 0 // TLS Table
  86. .8byte 0 // Load Config Table
  87. .8byte 0 // Bound Import
  88. .8byte 0 // IAT
  89. .8byte 0 // Delay Import Descriptor
  90. .8byte 0 // CLR Runtime Header
  91. .8byte 0 // Reserved, must be zero
  92. // Section table
  93. section_table:
  94. /*
  95. * The EFI application loader requires a relocation section
  96. * because EFI applications must be relocatable. This is a
  97. * dummy section as far as we are concerned.
  98. */
  99. .ascii ".reloc\0\0"
  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\0\0\0"
  110. .4byte _edata - _start // VirtualSize
  111. .4byte _start - ImageBase // VirtualAddress
  112. .4byte _edata - _start // SizeOfRawData
  113. .4byte _start - ImageBase // PointerToRawData
  114. .4byte 0 // PointerToRelocations (0 for executables)
  115. .4byte 0 // PointerToLineNumbers (0 for executables)
  116. .2byte 0 // NumberOfRelocations (0 for executables)
  117. .2byte 0 // NumberOfLineNumbers (0 for executables)
  118. .4byte 0xe0500020 // Characteristics (section flags)
  119. .align 12
  120. .globl _start
  121. .type _start,%function
  122. _start:
  123. addi sp, sp, -24
  124. sd a0, 0(sp)
  125. sd a1, 8(sp)
  126. sd ra, 16(sp)
  127. lla a0, ImageBase
  128. lla a1, _DYNAMIC
  129. call _relocate
  130. bne a0, zero, 0f
  131. ld a1, 8(sp)
  132. ld a0, 0(sp)
  133. call _entry
  134. ld ra, 16(sp)
  135. 0: addi sp, sp, 24
  136. ret
  137. #if defined(__ELF__) && defined(__linux__)
  138. .section .note.GNU-stack,"",%progbits
  139. #endif