efi-header.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2013-2015 Linaro Ltd
  3. * Authors: Roy Franz <roy.franz@linaro.org>
  4. * Ard Biesheuvel <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. .macro __nop
  11. #ifdef CONFIG_EFI_STUB
  12. @ This is almost but not quite a NOP, since it does clobber the
  13. @ condition flags. But it is the best we can do for EFI, since
  14. @ PE/COFF expects the magic string "MZ" at offset 0, while the
  15. @ ARM/Linux boot protocol expects an executable instruction
  16. @ there.
  17. .inst 'M' | ('Z' << 8) | (0x1310 << 16) @ tstne r0, #0x4d000
  18. #else
  19. mov r0, r0
  20. #endif
  21. .endm
  22. .macro __EFI_HEADER
  23. #ifdef CONFIG_EFI_STUB
  24. b __efi_start
  25. .set start_offset, __efi_start - start
  26. .org start + 0x3c
  27. @
  28. @ The PE header can be anywhere in the file, but for
  29. @ simplicity we keep it together with the MSDOS header
  30. @ The offset to the PE/COFF header needs to be at offset
  31. @ 0x3C in the MSDOS header.
  32. @ The only 2 fields of the MSDOS header that are used are this
  33. @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
  34. @
  35. .long pe_header - start @ Offset to the PE header.
  36. pe_header:
  37. .ascii "PE\0\0"
  38. coff_header:
  39. .short 0x01c2 @ ARM or Thumb
  40. .short 2 @ nr_sections
  41. .long 0 @ TimeDateStamp
  42. .long 0 @ PointerToSymbolTable
  43. .long 1 @ NumberOfSymbols
  44. .short section_table - optional_header
  45. @ SizeOfOptionalHeader
  46. .short 0x306 @ Characteristics.
  47. @ IMAGE_FILE_32BIT_MACHINE |
  48. @ IMAGE_FILE_DEBUG_STRIPPED |
  49. @ IMAGE_FILE_EXECUTABLE_IMAGE |
  50. @ IMAGE_FILE_LINE_NUMS_STRIPPED
  51. optional_header:
  52. .short 0x10b @ PE32 format
  53. .byte 0x02 @ MajorLinkerVersion
  54. .byte 0x14 @ MinorLinkerVersion
  55. .long _end - __efi_start @ SizeOfCode
  56. .long 0 @ SizeOfInitializedData
  57. .long 0 @ SizeOfUninitializedData
  58. .long efi_stub_entry - start @ AddressOfEntryPoint
  59. .long start_offset @ BaseOfCode
  60. .long 0 @ data
  61. extra_header_fields:
  62. .long 0 @ ImageBase
  63. .long 0x200 @ SectionAlignment
  64. .long 0x200 @ FileAlignment
  65. .short 0 @ MajorOperatingSystemVersion
  66. .short 0 @ MinorOperatingSystemVersion
  67. .short 0 @ MajorImageVersion
  68. .short 0 @ MinorImageVersion
  69. .short 0 @ MajorSubsystemVersion
  70. .short 0 @ MinorSubsystemVersion
  71. .long 0 @ Win32VersionValue
  72. .long _end - start @ SizeOfImage
  73. .long start_offset @ SizeOfHeaders
  74. .long 0 @ CheckSum
  75. .short 0xa @ Subsystem (EFI application)
  76. .short 0 @ DllCharacteristics
  77. .long 0 @ SizeOfStackReserve
  78. .long 0 @ SizeOfStackCommit
  79. .long 0 @ SizeOfHeapReserve
  80. .long 0 @ SizeOfHeapCommit
  81. .long 0 @ LoaderFlags
  82. .long 0x6 @ NumberOfRvaAndSizes
  83. .quad 0 @ ExportTable
  84. .quad 0 @ ImportTable
  85. .quad 0 @ ResourceTable
  86. .quad 0 @ ExceptionTable
  87. .quad 0 @ CertificationTable
  88. .quad 0 @ BaseRelocationTable
  89. section_table:
  90. @
  91. @ The EFI application loader requires a relocation section
  92. @ because EFI applications must be relocatable. This is a
  93. @ dummy section as far as we are concerned.
  94. @
  95. .ascii ".reloc\0\0"
  96. .long 0 @ VirtualSize
  97. .long 0 @ VirtualAddress
  98. .long 0 @ SizeOfRawData
  99. .long 0 @ PointerToRawData
  100. .long 0 @ PointerToRelocations
  101. .long 0 @ PointerToLineNumbers
  102. .short 0 @ NumberOfRelocations
  103. .short 0 @ NumberOfLineNumbers
  104. .long 0x42100040 @ Characteristics
  105. .ascii ".text\0\0\0"
  106. .long _end - __efi_start @ VirtualSize
  107. .long __efi_start @ VirtualAddress
  108. .long _edata - __efi_start @ SizeOfRawData
  109. .long __efi_start @ PointerToRawData
  110. .long 0 @ PointerToRelocations
  111. .long 0 @ PointerToLineNumbers
  112. .short 0 @ NumberOfRelocations
  113. .short 0 @ NumberOfLineNumbers
  114. .long 0xe0500020 @ Characteristics
  115. .align 9
  116. __efi_start:
  117. #endif
  118. .endm