crt0_aarch64_efi.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * crt0-efi-aarch64.S - PE/COFF header for aarch64 EFI applications
  4. *
  5. * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  6. *
  7. *
  8. * This file is taken and modified from the gnu-efi project.
  9. */
  10. #include <asm-generic/pe.h>
  11. .section .text.head
  12. /*
  13. * Magic "MZ" signature for PE/COFF
  14. */
  15. .globl ImageBase
  16. ImageBase:
  17. .ascii "MZ"
  18. .skip 58 /* 'MZ' + pad + offset == 64 */
  19. .long pe_header - ImageBase /* Offset to the PE header */
  20. pe_header:
  21. .ascii "PE"
  22. .short 0
  23. coff_header:
  24. .short 0xaa64 /* AArch64 */
  25. .short 2 /* nr_sections */
  26. .long 0 /* TimeDateStamp */
  27. .long 0 /* PointerToSymbolTable */
  28. .long 1 /* NumberOfSymbols */
  29. .short section_table - optional_header /* SizeOfOptionalHeader */
  30. /*
  31. * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
  32. * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
  33. */
  34. .short 0x206
  35. optional_header:
  36. .short 0x20b /* PE32+ format */
  37. .byte 0x02 /* MajorLinkerVersion */
  38. .byte 0x14 /* MinorLinkerVersion */
  39. .long _edata - _start /* SizeOfCode */
  40. .long 0 /* SizeOfInitializedData */
  41. .long 0 /* SizeOfUninitializedData */
  42. .long _start - ImageBase /* AddressOfEntryPoint */
  43. .long _start - ImageBase /* BaseOfCode */
  44. extra_header_fields:
  45. .quad 0 /* ImageBase */
  46. .long 0x20 /* SectionAlignment */
  47. .long 0x8 /* FileAlignment */
  48. .short 0 /* MajorOperatingSystemVersion */
  49. .short 0 /* MinorOperatingSystemVersion */
  50. .short 0 /* MajorImageVersion */
  51. .short 0 /* MinorImageVersion */
  52. .short 0 /* MajorSubsystemVersion */
  53. .short 0 /* MinorSubsystemVersion */
  54. .long 0 /* Win32VersionValue */
  55. .long _edata - ImageBase /* SizeOfImage */
  56. /*
  57. * Everything before the kernel image is considered part of the header
  58. */
  59. .long _start - ImageBase /* SizeOfHeaders */
  60. .long 0 /* CheckSum */
  61. .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
  62. .short 0 /* DllCharacteristics */
  63. .quad 0 /* SizeOfStackReserve */
  64. .quad 0 /* SizeOfStackCommit */
  65. .quad 0 /* SizeOfHeapReserve */
  66. .quad 0 /* SizeOfHeapCommit */
  67. .long 0 /* LoaderFlags */
  68. .long 0x6 /* NumberOfRvaAndSizes */
  69. .quad 0 /* ExportTable */
  70. .quad 0 /* ImportTable */
  71. .quad 0 /* ResourceTable */
  72. .quad 0 /* ExceptionTable */
  73. .quad 0 /* CertificationTable */
  74. .quad 0 /* BaseRelocationTable */
  75. /* Section table */
  76. section_table:
  77. /*
  78. * The EFI application loader requires a relocation section
  79. * because EFI applications must be relocatable. This is a
  80. * dummy section as far as we are concerned.
  81. */
  82. .ascii ".reloc"
  83. .byte 0
  84. .byte 0 /* end of 0 padding of section name */
  85. .long 0
  86. .long 0
  87. .long 0 /* SizeOfRawData */
  88. .long 0 /* PointerToRawData */
  89. .long 0 /* PointerToRelocations */
  90. .long 0 /* PointerToLineNumbers */
  91. .short 0 /* NumberOfRelocations */
  92. .short 0 /* NumberOfLineNumbers */
  93. .long 0x42100040 /* Characteristics (section flags) */
  94. .ascii ".text"
  95. .byte 0
  96. .byte 0
  97. .byte 0 /* end of 0 padding of section name */
  98. .long _edata - _start /* VirtualSize */
  99. .long _start - ImageBase /* VirtualAddress */
  100. .long _edata - _start /* SizeOfRawData */
  101. .long _start - ImageBase /* PointerToRawData */
  102. .long 0 /* PointerToRelocations (0 for executables) */
  103. .long 0 /* PointerToLineNumbers (0 for executables) */
  104. .short 0 /* NumberOfRelocations (0 for executables) */
  105. .short 0 /* NumberOfLineNumbers (0 for executables) */
  106. .long 0xe0500020 /* Characteristics (section flags) */
  107. _start:
  108. stp x29, x30, [sp, #-32]!
  109. mov x29, sp
  110. stp x0, x1, [sp, #16]
  111. mov x2, x0
  112. mov x3, x1
  113. adr x0, ImageBase
  114. adrp x1, _DYNAMIC
  115. add x1, x1, #:lo12:_DYNAMIC
  116. bl _relocate
  117. cbnz x0, 0f
  118. ldp x0, x1, [sp, #16]
  119. bl efi_main
  120. 0: ldp x29, x30, [sp], #32
  121. ret