crt0-efi-arm.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * crt0-efi-arm.S - PE/COFF header for ARM EFI applications
  3. *
  4. * Copright (C) 2014 Linaro Ltd. <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. .section .text.head
  12. /*
  13. * Magic "MZ" signature for PE/COFF
  14. */
  15. .globl ImageBase
  16. ImageBase:
  17. .ascii "MZ"
  18. .skip 58 // 'MZ' + pad + offset == 64
  19. .long pe_header - ImageBase // Offset to the PE header.
  20. pe_header:
  21. .ascii "PE"
  22. .short 0
  23. coff_header:
  24. .short 0x1c2 // Mixed ARM/Thumb
  25. .short 2 // nr_sections
  26. .long 0 // TimeDateStamp
  27. .long 0 // PointerToSymbolTable
  28. .long 1 // NumberOfSymbols
  29. .short section_table - optional_header // SizeOfOptionalHeader
  30. .short 0x306 // Characteristics.
  31. // IMAGE_FILE_32BIT_MACHINE |
  32. // IMAGE_FILE_DEBUG_STRIPPED |
  33. // IMAGE_FILE_EXECUTABLE_IMAGE |
  34. // IMAGE_FILE_LINE_NUMS_STRIPPED
  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 - ImageBase // AddressOfEntryPoint
  43. .long _start - ImageBase // BaseOfCode
  44. .long 0 // BaseOfData
  45. extra_header_fields:
  46. .long 0 // ImageBase
  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 - ImageBase // SizeOfImage
  57. // Everything before the kernel image is considered part of the header
  58. .long _start - ImageBase // SizeOfHeaders
  59. .long 0 // CheckSum
  60. .short EFI_SUBSYSTEM // Subsystem
  61. .short 0 // DllCharacteristics
  62. .long 0 // SizeOfStackReserve
  63. .long 0 // SizeOfStackCommit
  64. .long 0 // SizeOfHeapReserve
  65. .long 0 // SizeOfHeapCommit
  66. .long 0 // LoaderFlags
  67. .long 0x6 // NumberOfRvaAndSizes
  68. .quad 0 // ExportTable
  69. .quad 0 // ImportTable
  70. .quad 0 // ResourceTable
  71. .quad 0 // ExceptionTable
  72. .quad 0 // CertificationTable
  73. .quad 0 // BaseRelocationTable
  74. // Section table
  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 - ImageBase // VirtualAddress
  99. .long _edata - _start // SizeOfRawData
  100. .long _start - ImageBase // 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. mov r2, r0
  109. mov r3, r1
  110. adr r1, .L_DYNAMIC
  111. ldr r0, [r1]
  112. add r1, r0, r1
  113. adr r0, ImageBase
  114. bl _relocate
  115. teq r0, #0
  116. bne 0f
  117. ldmfd sp, {r0-r1}
  118. bl efi_main
  119. 0: add sp, sp, #12
  120. ldr pc, [sp], #4
  121. .L_DYNAMIC:
  122. .word _DYNAMIC - .