crt0-efi-arm.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * crt0-efi-arm.S - PE/COFF header for ARM 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 0x1c2 // Mixed ARM/Thumb
  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 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. .short 0x10b // PE32+ format
  44. .byte 0x02 // MajorLinkerVersion
  45. .byte 0x14 // MinorLinkerVersion
  46. .long _edata - _start // SizeOfCode
  47. .long 0 // SizeOfInitializedData
  48. .long 0 // SizeOfUninitializedData
  49. .long _start - ImageBase // AddressOfEntryPoint
  50. .long _start - ImageBase // BaseOfCode
  51. .long 0 // BaseOfData
  52. extra_header_fields:
  53. .long 0 // ImageBase
  54. .long 0x20 // SectionAlignment
  55. .long 0x8 // FileAlignment
  56. .short 0 // MajorOperatingSystemVersion
  57. .short 0 // MinorOperatingSystemVersion
  58. .short 0 // MajorImageVersion
  59. .short 0 // MinorImageVersion
  60. .short 0 // MajorSubsystemVersion
  61. .short 0 // MinorSubsystemVersion
  62. .long 0 // Win32VersionValue
  63. .long _edata - ImageBase // SizeOfImage
  64. // Everything before the kernel image is considered part of the header
  65. .long _start - ImageBase // SizeOfHeaders
  66. .long 0 // CheckSum
  67. .short EFI_SUBSYSTEM // Subsystem
  68. .short 0 // DllCharacteristics
  69. .long 0 // SizeOfStackReserve
  70. .long 0 // SizeOfStackCommit
  71. .long 0 // SizeOfHeapReserve
  72. .long 0 // SizeOfHeapCommit
  73. .long 0 // LoaderFlags
  74. .long 0x6 // NumberOfRvaAndSizes
  75. .quad 0 // ExportTable
  76. .quad 0 // ImportTable
  77. .quad 0 // ResourceTable
  78. .quad 0 // ExceptionTable
  79. .quad 0 // CertificationTable
  80. .quad 0 // BaseRelocationTable
  81. // Section table
  82. section_table:
  83. /*
  84. * The EFI application loader requires a relocation section
  85. * because EFI applications must be relocatable. This is a
  86. * dummy section as far as we are concerned.
  87. */
  88. .ascii ".reloc"
  89. .byte 0
  90. .byte 0 // end of 0 padding of section name
  91. .long 0
  92. .long 0
  93. .long 0 // SizeOfRawData
  94. .long 0 // PointerToRawData
  95. .long 0 // PointerToRelocations
  96. .long 0 // PointerToLineNumbers
  97. .short 0 // NumberOfRelocations
  98. .short 0 // NumberOfLineNumbers
  99. .long 0x42100040 // Characteristics (section flags)
  100. .ascii ".text"
  101. .byte 0
  102. .byte 0
  103. .byte 0 // end of 0 padding of section name
  104. .long _edata - _start // VirtualSize
  105. .long _start - ImageBase // VirtualAddress
  106. .long _edata - _start // SizeOfRawData
  107. .long _start - ImageBase // PointerToRawData
  108. .long 0 // PointerToRelocations (0 for executables)
  109. .long 0 // PointerToLineNumbers (0 for executables)
  110. .short 0 // NumberOfRelocations (0 for executables)
  111. .short 0 // NumberOfLineNumbers (0 for executables)
  112. .long 0xe0500020 // Characteristics (section flags)
  113. _start:
  114. stmfd sp!, {r0-r2, lr}
  115. mov r2, r0
  116. mov r3, r1
  117. adr r1, .L_DYNAMIC
  118. ldr r0, [r1]
  119. add r1, r0, r1
  120. adr r0, ImageBase
  121. bl _relocate
  122. teq r0, #0
  123. bne 0f
  124. ldmfd sp, {r0-r1}
  125. bl efi_main
  126. 0: add sp, sp, #12
  127. ldr pc, [sp], #4
  128. .L_DYNAMIC:
  129. .word _DYNAMIC - .