crt0-efi-arm.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * crt0-efi-arm.S - PE/COFF header for ARM EFI applications
  3. *
  4. * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  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. .4byte pe_header - ImageBase // Offset to the PE header.
  27. pe_header:
  28. .ascii "PE"
  29. .2byte 0
  30. coff_header:
  31. .2byte 0x1c2 // Mixed ARM/Thumb
  32. .2byte 2 // nr_sections
  33. .4byte 0 // TimeDateStamp
  34. .4byte 0 // PointerToSymbolTable
  35. .4byte 0 // NumberOfSymbols
  36. .2byte section_table - optional_header // SizeOfOptionalHeader
  37. .2byte 0x306 // Characteristics.
  38. // IMAGE_FILE_32BIT_MACHINE |
  39. // IMAGE_FILE_DEBUG_STRIPPED |
  40. // IMAGE_FILE_EXECUTABLE_IMAGE |
  41. // IMAGE_FILE_LINE_NUMS_STRIPPED
  42. optional_header:
  43. .2byte 0x10b // PE32+ format
  44. .byte 0x02 // MajorLinkerVersion
  45. .byte 0x14 // MinorLinkerVersion
  46. .4byte _edata - _start // SizeOfCode
  47. .4byte 0 // SizeOfInitializedData
  48. .4byte 0 // SizeOfUninitializedData
  49. .4byte _start - ImageBase // AddressOfEntryPoint
  50. .4byte _start - ImageBase // BaseOfCode
  51. .4byte 0 // BaseOfData
  52. extra_header_fields:
  53. .4byte 0 // ImageBase
  54. .4byte 0x20 // SectionAlignment
  55. .4byte 0x8 // FileAlignment
  56. .2byte 0 // MajorOperatingSystemVersion
  57. .2byte 0 // MinorOperatingSystemVersion
  58. .2byte 0 // MajorImageVersion
  59. .2byte 0 // MinorImageVersion
  60. .2byte 0 // MajorSubsystemVersion
  61. .2byte 0 // MinorSubsystemVersion
  62. .4byte 0 // Win32VersionValue
  63. .4byte _edata - ImageBase // SizeOfImage
  64. // Everything before the kernel image is considered part of the header
  65. .4byte _start - ImageBase // SizeOfHeaders
  66. .4byte 0 // CheckSum
  67. .2byte EFI_SUBSYSTEM // Subsystem
  68. .2byte 0 // DllCharacteristics
  69. .4byte 0 // SizeOfStackReserve
  70. .4byte 0 // SizeOfStackCommit
  71. .4byte 0 // SizeOfHeapReserve
  72. .4byte 0 // SizeOfHeapCommit
  73. .4byte 0 // LoaderFlags
  74. .4byte 0x10 // NumberOfRvaAndSizes
  75. .8byte 0 // ExportTable
  76. .8byte 0 // ImportTable
  77. .8byte 0 // ResourceTable
  78. .8byte 0 // ExceptionTable
  79. .8byte 0 // CertificationTable
  80. .8byte 0 // BaseRelocationTable
  81. .8byte 0 // Debug
  82. .8byte 0 // Architecture
  83. .8byte 0 // Global Ptr
  84. .8byte 0 // TLS Table
  85. .8byte 0 // Load Config Table
  86. .8byte 0 // Bound Import
  87. .8byte 0 // IAT
  88. .8byte 0 // Delay Import Descriptor
  89. .8byte 0 // CLR Runtime Header
  90. .8byte 0 // Reserved, must be zero
  91. // Section table
  92. section_table:
  93. /*
  94. * The EFI application loader requires a relocation section
  95. * because EFI applications must be relocatable. This is a
  96. * dummy section as far as we are concerned.
  97. */
  98. .ascii ".reloc"
  99. .byte 0
  100. .byte 0 // end of 0 padding of section name
  101. .4byte 0
  102. .4byte 0
  103. .4byte 0 // SizeOfRawData
  104. .4byte 0 // PointerToRawData
  105. .4byte 0 // PointerToRelocations
  106. .4byte 0 // PointerToLineNumbers
  107. .2byte 0 // NumberOfRelocations
  108. .2byte 0 // NumberOfLineNumbers
  109. .4byte 0x42100040 // Characteristics (section flags)
  110. .ascii ".text"
  111. .byte 0
  112. .byte 0
  113. .byte 0 // end of 0 padding of section name
  114. .4byte _edata - _start // VirtualSize
  115. .4byte _start - ImageBase // VirtualAddress
  116. .4byte _edata - _start // SizeOfRawData
  117. .4byte _start - ImageBase // PointerToRawData
  118. .4byte 0 // PointerToRelocations (0 for executables)
  119. .4byte 0 // PointerToLineNumbers (0 for executables)
  120. .2byte 0 // NumberOfRelocations (0 for executables)
  121. .2byte 0 // NumberOfLineNumbers (0 for executables)
  122. .4byte 0xe0500020 // Characteristics (section flags)
  123. .globl _start
  124. .type _start,%function
  125. _start:
  126. stmfd sp!, {r0-r2, lr}
  127. mov r2, r0
  128. mov r3, r1
  129. adr r1, .L_DYNAMIC
  130. ldr r0, [r1]
  131. add r1, r0, r1
  132. adr r0, ImageBase
  133. bl _relocate
  134. teq r0, #0
  135. bne 0f
  136. ldmfd sp, {r0-r1}
  137. bl _entry
  138. 0: add sp, sp, #12
  139. ldr pc, [sp], #4
  140. .L_DYNAMIC:
  141. .4byte _DYNAMIC - .
  142. #if defined(__ELF__) && defined(__linux__)
  143. .section .note.GNU-stack,"",%progbits
  144. #endif