crt0_arm_efi.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * crt0-efi-arm.S - PE/COFF header for ARM EFI applications
  4. *
  5. * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  6. *
  7. * This file is taken and modified from the gnu-efi project.
  8. */
  9. #include <asm-generic/pe.h>
  10. .section .text.head
  11. /*
  12. * Magic "MZ" signature for PE/COFF
  13. */
  14. .globl image_base
  15. image_base:
  16. .ascii "MZ"
  17. .skip 58 /* 'MZ' + pad + offset == 64 */
  18. .long pe_header - image_base /* Offset to the PE header */
  19. pe_header:
  20. .ascii "PE"
  21. .short 0
  22. coff_header:
  23. .short 0x1c2 /* Mixed ARM/Thumb */
  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_32BIT_MACHINE |
  31. * IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
  32. * IMAGE_FILE_LINE_NUMS_STRIPPED
  33. */
  34. .short 0x306
  35. optional_header:
  36. .short 0x10b /* 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 - image_base /* AddressOfEntryPoint */
  43. .long _start - image_base /* BaseOfCode */
  44. .long 0 /* BaseOfData */
  45. extra_header_fields:
  46. .long 0 /* image_base */
  47. .long 0x20 /* SectionAlignment */
  48. .long 0x8 /* FileAlignment */
  49. .short 0 /* MajorOperatingSystemVersion */
  50. .short 0 /* MinorOperatingSystemVersion */
  51. .short 0 /* MajorImageVersion */
  52. .short 0 /* MinorImageVersion */
  53. .short 0 /* MajorSubsystemVersion */
  54. .short 0 /* MinorSubsystemVersion */
  55. .long 0 /* Win32VersionValue */
  56. .long _edata - image_base /* SizeOfImage */
  57. /*
  58. * Everything before the kernel image is considered part of the header
  59. */
  60. .long _start - image_base /* SizeOfHeaders */
  61. .long 0 /* CheckSum */
  62. .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
  63. .short 0 /* DllCharacteristics */
  64. .long 0 /* SizeOfStackReserve */
  65. .long 0 /* SizeOfStackCommit */
  66. .long 0 /* SizeOfHeapReserve */
  67. .long 0 /* SizeOfHeapCommit */
  68. .long 0 /* LoaderFlags */
  69. .long 0x6 /* NumberOfRvaAndSizes */
  70. .quad 0 /* ExportTable */
  71. .quad 0 /* ImportTable */
  72. .quad 0 /* ResourceTable */
  73. .quad 0 /* ExceptionTable */
  74. .quad 0 /* CertificationTable */
  75. .quad 0 /* BaseRelocationTable */
  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 - image_base /* VirtualAddress */
  100. .long _edata - _start /* SizeOfRawData */
  101. .long _start - image_base /* 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. stmfd sp!, {r0-r2, lr}
  109. mov r2, r0
  110. mov r3, r1
  111. adr r1, .L_DYNAMIC
  112. ldr r0, [r1]
  113. add r1, r0, r1
  114. adr r0, image_base
  115. bl _relocate
  116. teq r0, #0
  117. bne 0f
  118. ldmfd sp, {r0-r1}
  119. bl efi_main
  120. 0: add sp, sp, #12
  121. ldr pc, [sp], #4
  122. .L_DYNAMIC:
  123. .word _DYNAMIC - .