crt0_arm_efi.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. .short IMAGE_DOS_SIGNATURE /* 'MZ' */
  17. .skip 58 /* 'MZ' + pad + offset == 64 */
  18. .long pe_header - image_base /* Offset to the PE header */
  19. pe_header:
  20. .long IMAGE_NT_SIGNATURE /* 'PE' */
  21. coff_header:
  22. .short IMAGE_FILE_MACHINE_THUMB /* Mixed ARM/Thumb */
  23. .short 2 /* nr_sections */
  24. .long 0 /* TimeDateStamp */
  25. .long 0 /* PointerToSymbolTable */
  26. .long 0 /* NumberOfSymbols */
  27. .short section_table - optional_header /* SizeOfOptionalHeader */
  28. /* Characteristics */
  29. .short (IMAGE_FILE_EXECUTABLE_IMAGE | \
  30. IMAGE_FILE_LINE_NUMS_STRIPPED | \
  31. IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
  32. IMAGE_FILE_32BIT_MACHINE | \
  33. IMAGE_FILE_DEBUG_STRIPPED)
  34. optional_header:
  35. .short IMAGE_NT_OPTIONAL_HDR32_MAGIC /* 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 - image_base /* AddressOfEntryPoint */
  42. .long _start - image_base /* BaseOfCode */
  43. .long 0 /* BaseOfData */
  44. extra_header_fields:
  45. .long 0 /* image_base */
  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 - image_base /* SizeOfImage */
  56. /*
  57. * Everything before the kernel image is considered part of the header
  58. */
  59. .long _start - image_base /* SizeOfHeaders */
  60. .long 0 /* CheckSum */
  61. .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
  62. .short 0 /* DllCharacteristics */
  63. .long 0 /* SizeOfStackReserve */
  64. .long 0 /* SizeOfStackCommit */
  65. .long 0 /* SizeOfHeapReserve */
  66. .long 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. /*
  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 - image_base /* VirtualAddress */
  99. .long _edata - _start /* SizeOfRawData */
  100. .long _start - image_base /* 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. stmfd sp!, {r0-r2, lr}
  108. adr r1, .L_DYNAMIC
  109. ldr r0, [r1]
  110. add r1, r0, r1
  111. adr r0, image_base
  112. bl _relocate
  113. teq r0, #0
  114. bne 0f
  115. ldmfd sp, {r0-r1}
  116. bl efi_main
  117. 0: add sp, sp, #12
  118. ldr pc, [sp], #4
  119. .L_DYNAMIC:
  120. .word _DYNAMIC - .