crt0_aarch64_efi.S 3.7 KB

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