crt0-efi-riscv64.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  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. .long pe_header - ImageBase // Offset to the PE header.
  30. pe_header:
  31. .ascii "PE"
  32. .short 0
  33. coff_header:
  34. .short 0x5064 // riscv64
  35. .short 2 // nr_sections
  36. .long 0 // TimeDateStamp
  37. .long 0 // PointerToSymbolTable
  38. .long 0 // NumberOfSymbols
  39. .short section_table - optional_header // SizeOfOptionalHeader
  40. .short 0x206 // Characteristics.
  41. // IMAGE_FILE_DEBUG_STRIPPED |
  42. // IMAGE_FILE_EXECUTABLE_IMAGE |
  43. // IMAGE_FILE_LINE_NUMS_STRIPPED
  44. optional_header:
  45. .short 0x20b // PE32+ format
  46. .byte 0x02 // MajorLinkerVersion
  47. .byte 0x14 // MinorLinkerVersion
  48. .long _data - _start // SizeOfCode
  49. .long _data_size // SizeOfInitializedData
  50. .long 0 // SizeOfUninitializedData
  51. .long _start - ImageBase // AddressOfEntryPoint
  52. .long _start - ImageBase // BaseOfCode
  53. extra_header_fields:
  54. .quad 0 // ImageBase
  55. .long 0x1000 // SectionAlignment
  56. .long 0x200 // FileAlignment
  57. .short 0 // MajorOperatingSystemVersion
  58. .short 0 // MinorOperatingSystemVersion
  59. .short 0 // MajorImageVersion
  60. .short 0 // MinorImageVersion
  61. .short 0 // MajorSubsystemVersion
  62. .short 0 // MinorSubsystemVersion
  63. .long 0 // Win32VersionValue
  64. .long _edata - ImageBase // SizeOfImage
  65. // Everything before the kernel image is considered part of the header
  66. .long _start - ImageBase // SizeOfHeaders
  67. .long 0 // CheckSum
  68. .short EFI_SUBSYSTEM // Subsystem
  69. .short 0 // DllCharacteristics
  70. .quad 0 // SizeOfStackReserve
  71. .quad 0 // SizeOfStackCommit
  72. .quad 0 // SizeOfHeapReserve
  73. .quad 0 // SizeOfHeapCommit
  74. .long 0 // LoaderFlags
  75. .long 0x6 // NumberOfRvaAndSizes
  76. .quad 0 // ExportTable
  77. .quad 0 // ImportTable
  78. .quad 0 // ResourceTable
  79. .quad 0 // ExceptionTable
  80. .quad 0 // CertificationTable
  81. .quad 0 // BaseRelocationTable
  82. // Section table
  83. section_table:
  84. /*
  85. * The EFI application loader requires a relocation section
  86. * because EFI applications must be relocatable. This is a
  87. * dummy section as far as we are concerned.
  88. */
  89. .ascii ".reloc\0\0"
  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\0\0\0"
  100. .long _edata - _start // VirtualSize
  101. .long _start - ImageBase // VirtualAddress
  102. .long _edata - _start // SizeOfRawData
  103. .long _start - ImageBase // PointerToRawData
  104. .long 0 // PointerToRelocations (0 for executables)
  105. .long 0 // PointerToLineNumbers (0 for executables)
  106. .short 0 // NumberOfRelocations (0 for executables)
  107. .short 0 // NumberOfLineNumbers (0 for executables)
  108. .long 0xe0500020 // Characteristics (section flags)
  109. .align 12
  110. .globl _start
  111. _start:
  112. addi sp, sp, -24
  113. sd a0, 0(sp)
  114. sd a1, 8(sp)
  115. sd ra, 16(sp)
  116. lla a0, ImageBase
  117. lla a1, _DYNAMIC
  118. call _relocate
  119. bne a0, zero, 0f
  120. ld a1, 8(sp)
  121. ld a0, 0(sp)
  122. call efi_main
  123. ld ra, 16(sp)
  124. 0: addi sp, sp, 24
  125. ret
  126. #if defined(__ELF__) && defined(__linux__)
  127. .section .note.GNU-stack,"",%progbits
  128. #endif