efi-header.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013-2017 Linaro Ltd
  4. * Authors: Roy Franz <[email protected]>
  5. * Ard Biesheuvel <[email protected]>
  6. */
  7. #include <linux/pe.h>
  8. #include <linux/sizes.h>
  9. .macro __nop
  10. AR_CLASS( mov r0, r0 )
  11. M_CLASS( nop.w )
  12. .endm
  13. .macro __initial_nops
  14. #ifdef CONFIG_EFI_STUB
  15. @ This is a two-instruction NOP, which happens to bear the
  16. @ PE/COFF signature "MZ" in the first two bytes, so the kernel
  17. @ is accepted as an EFI binary. Booting via the UEFI stub
  18. @ will not execute those instructions, but the ARM/Linux
  19. @ boot protocol does, so we need some NOPs here.
  20. .inst MZ_MAGIC | (0xe225 << 16) @ eor r5, r5, 0x4d000
  21. eor r5, r5, 0x4d000 @ undo previous insn
  22. #else
  23. __nop
  24. __nop
  25. #endif
  26. .endm
  27. .macro __EFI_HEADER
  28. #ifdef CONFIG_EFI_STUB
  29. .set start_offset, __efi_start - start
  30. .org start + 0x3c
  31. @
  32. @ The PE header can be anywhere in the file, but for
  33. @ simplicity we keep it together with the MSDOS header
  34. @ The offset to the PE/COFF header needs to be at offset
  35. @ 0x3C in the MSDOS header.
  36. @ The only 2 fields of the MSDOS header that are used are this
  37. @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
  38. @
  39. .long pe_header - start @ Offset to the PE header.
  40. pe_header:
  41. .long PE_MAGIC
  42. coff_header:
  43. .short IMAGE_FILE_MACHINE_THUMB @ Machine
  44. .short section_count @ NumberOfSections
  45. .long 0 @ TimeDateStamp
  46. .long 0 @ PointerToSymbolTable
  47. .long 0 @ NumberOfSymbols
  48. .short section_table - optional_header @ SizeOfOptionalHeader
  49. .short IMAGE_FILE_32BIT_MACHINE | \
  50. IMAGE_FILE_DEBUG_STRIPPED | \
  51. IMAGE_FILE_EXECUTABLE_IMAGE | \
  52. IMAGE_FILE_LINE_NUMS_STRIPPED @ Characteristics
  53. #define __pecoff_code_size (__pecoff_data_start - __efi_start)
  54. optional_header:
  55. .short PE_OPT_MAGIC_PE32 @ PE32 format
  56. .byte 0x02 @ MajorLinkerVersion
  57. .byte 0x14 @ MinorLinkerVersion
  58. .long __pecoff_code_size @ SizeOfCode
  59. .long __pecoff_data_size @ SizeOfInitializedData
  60. .long 0 @ SizeOfUninitializedData
  61. .long efi_pe_entry - start @ AddressOfEntryPoint
  62. .long start_offset @ BaseOfCode
  63. .long __pecoff_data_start - start @ BaseOfData
  64. extra_header_fields:
  65. .long 0 @ ImageBase
  66. .long SZ_4K @ SectionAlignment
  67. .long SZ_512 @ FileAlignment
  68. .short 0 @ MajorOsVersion
  69. .short 0 @ MinorOsVersion
  70. .short LINUX_EFISTUB_MAJOR_VERSION @ MajorImageVersion
  71. .short LINUX_EFISTUB_MINOR_VERSION @ MinorImageVersion
  72. .short 0 @ MajorSubsystemVersion
  73. .short 0 @ MinorSubsystemVersion
  74. .long 0 @ Win32VersionValue
  75. .long __pecoff_end - start @ SizeOfImage
  76. .long start_offset @ SizeOfHeaders
  77. .long 0 @ CheckSum
  78. .short IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem
  79. .short 0 @ DllCharacteristics
  80. .long 0 @ SizeOfStackReserve
  81. .long 0 @ SizeOfStackCommit
  82. .long 0 @ SizeOfHeapReserve
  83. .long 0 @ SizeOfHeapCommit
  84. .long 0 @ LoaderFlags
  85. .long (section_table - .) / 8 @ NumberOfRvaAndSizes
  86. .quad 0 @ ExportTable
  87. .quad 0 @ ImportTable
  88. .quad 0 @ ResourceTable
  89. .quad 0 @ ExceptionTable
  90. .quad 0 @ CertificationTable
  91. .quad 0 @ BaseRelocationTable
  92. section_table:
  93. .ascii ".text\0\0\0"
  94. .long __pecoff_code_size @ VirtualSize
  95. .long __efi_start @ VirtualAddress
  96. .long __pecoff_code_size @ SizeOfRawData
  97. .long __efi_start @ PointerToRawData
  98. .long 0 @ PointerToRelocations
  99. .long 0 @ PointerToLineNumbers
  100. .short 0 @ NumberOfRelocations
  101. .short 0 @ NumberOfLineNumbers
  102. .long IMAGE_SCN_CNT_CODE | \
  103. IMAGE_SCN_MEM_READ | \
  104. IMAGE_SCN_MEM_EXECUTE @ Characteristics
  105. .ascii ".data\0\0\0"
  106. .long __pecoff_data_size @ VirtualSize
  107. .long __pecoff_data_start - start @ VirtualAddress
  108. .long __pecoff_data_rawsize @ SizeOfRawData
  109. .long __pecoff_data_start - start @ PointerToRawData
  110. .long 0 @ PointerToRelocations
  111. .long 0 @ PointerToLineNumbers
  112. .short 0 @ NumberOfRelocations
  113. .short 0 @ NumberOfLineNumbers
  114. .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
  115. IMAGE_SCN_MEM_READ | \
  116. IMAGE_SCN_MEM_WRITE @ Characteristics
  117. .set section_count, (. - section_table) / 40
  118. .align 12
  119. __efi_start:
  120. #endif
  121. .endm