crt0-efi-aarch64.S 4.0 KB

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