efi-header.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 - 2017 Linaro, Ltd.
  4. * Copyright (C) 2013, 2014 Red Hat, Inc.
  5. */
  6. #include <linux/pe.h>
  7. #include <linux/sizes.h>
  8. .macro efi_signature_nop
  9. #ifdef CONFIG_EFI
  10. .L_head:
  11. /*
  12. * This ccmp instruction has no meaningful effect except that
  13. * its opcode forms the magic "MZ" signature required by UEFI.
  14. */
  15. ccmp x18, #0, #0xd, pl
  16. #else
  17. /*
  18. * Bootloaders may inspect the opcode at the start of the kernel
  19. * image to decide if the kernel is capable of booting via UEFI.
  20. * So put an ordinary NOP here, not the "MZ.." pseudo-nop above.
  21. */
  22. nop
  23. #endif
  24. .endm
  25. .macro __EFI_PE_HEADER
  26. #ifdef CONFIG_EFI
  27. .set .Lpe_header_offset, . - .L_head
  28. .long PE_MAGIC
  29. .short IMAGE_FILE_MACHINE_ARM64 // Machine
  30. .short .Lsection_count // NumberOfSections
  31. .long 0 // TimeDateStamp
  32. .long 0 // PointerToSymbolTable
  33. .long 0 // NumberOfSymbols
  34. .short .Lsection_table - .Loptional_header // SizeOfOptionalHeader
  35. .short IMAGE_FILE_DEBUG_STRIPPED | \
  36. IMAGE_FILE_EXECUTABLE_IMAGE | \
  37. IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
  38. .Loptional_header:
  39. .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
  40. .byte 0x02 // MajorLinkerVersion
  41. .byte 0x14 // MinorLinkerVersion
  42. .long __initdata_begin - .Lefi_header_end // SizeOfCode
  43. .long __pecoff_data_size // SizeOfInitializedData
  44. .long 0 // SizeOfUninitializedData
  45. .long __efistub_efi_pe_entry - .L_head // AddressOfEntryPoint
  46. .long .Lefi_header_end - .L_head // BaseOfCode
  47. .quad 0 // ImageBase
  48. .long SEGMENT_ALIGN // SectionAlignment
  49. .long PECOFF_FILE_ALIGNMENT // FileAlignment
  50. .short 0 // MajorOperatingSystemVersion
  51. .short 0 // MinorOperatingSystemVersion
  52. .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion
  53. .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion
  54. .short 0 // MajorSubsystemVersion
  55. .short 0 // MinorSubsystemVersion
  56. .long 0 // Win32VersionValue
  57. .long _end - .L_head // SizeOfImage
  58. // Everything before the kernel image is considered part of the header
  59. .long .Lefi_header_end - .L_head // SizeOfHeaders
  60. .long 0 // CheckSum
  61. .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
  62. .short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT // DllCharacteristics
  63. .quad 0 // SizeOfStackReserve
  64. .quad 0 // SizeOfStackCommit
  65. .quad 0 // SizeOfHeapReserve
  66. .quad 0 // SizeOfHeapCommit
  67. .long 0 // LoaderFlags
  68. .long (.Lsection_table - .) / 8 // NumberOfRvaAndSizes
  69. .quad 0 // ExportTable
  70. .quad 0 // ImportTable
  71. .quad 0 // ResourceTable
  72. .quad 0 // ExceptionTable
  73. .quad 0 // CertificationTable
  74. .quad 0 // BaseRelocationTable
  75. #ifdef CONFIG_DEBUG_EFI
  76. .long .Lefi_debug_table - .L_head // DebugTable
  77. .long .Lefi_debug_table_size
  78. #endif
  79. // Section table
  80. .Lsection_table:
  81. .ascii ".text\0\0\0"
  82. .long __initdata_begin - .Lefi_header_end // VirtualSize
  83. .long .Lefi_header_end - .L_head // VirtualAddress
  84. .long __initdata_begin - .Lefi_header_end // SizeOfRawData
  85. .long .Lefi_header_end - .L_head // PointerToRawData
  86. .long 0 // PointerToRelocations
  87. .long 0 // PointerToLineNumbers
  88. .short 0 // NumberOfRelocations
  89. .short 0 // NumberOfLineNumbers
  90. .long IMAGE_SCN_CNT_CODE | \
  91. IMAGE_SCN_MEM_READ | \
  92. IMAGE_SCN_MEM_EXECUTE // Characteristics
  93. .ascii ".data\0\0\0"
  94. .long __pecoff_data_size // VirtualSize
  95. .long __initdata_begin - .L_head // VirtualAddress
  96. .long __pecoff_data_rawsize // SizeOfRawData
  97. .long __initdata_begin - .L_head // PointerToRawData
  98. .long 0 // PointerToRelocations
  99. .long 0 // PointerToLineNumbers
  100. .short 0 // NumberOfRelocations
  101. .short 0 // NumberOfLineNumbers
  102. .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
  103. IMAGE_SCN_MEM_READ | \
  104. IMAGE_SCN_MEM_WRITE // Characteristics
  105. .set .Lsection_count, (. - .Lsection_table) / 40
  106. #ifdef CONFIG_DEBUG_EFI
  107. /*
  108. * The debug table is referenced via its Relative Virtual Address (RVA),
  109. * which is only defined for those parts of the image that are covered
  110. * by a section declaration. Since this header is not covered by any
  111. * section, the debug table must be emitted elsewhere. So stick it in
  112. * the .init.rodata section instead.
  113. *
  114. * Note that the EFI debug entry itself may legally have a zero RVA,
  115. * which means we can simply put it right after the section headers.
  116. */
  117. __INITRODATA
  118. .align 2
  119. .Lefi_debug_table:
  120. // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
  121. .long 0 // Characteristics
  122. .long 0 // TimeDateStamp
  123. .short 0 // MajorVersion
  124. .short 0 // MinorVersion
  125. .long IMAGE_DEBUG_TYPE_CODEVIEW // Type
  126. .long .Lefi_debug_entry_size // SizeOfData
  127. .long 0 // RVA
  128. .long .Lefi_debug_entry - .L_head // FileOffset
  129. .set .Lefi_debug_table_size, . - .Lefi_debug_table
  130. .previous
  131. .Lefi_debug_entry:
  132. // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
  133. .ascii "NB10" // Signature
  134. .long 0 // Unknown
  135. .long 0 // Unknown2
  136. .long 0 // Unknown3
  137. .asciz VMLINUX_PATH
  138. .set .Lefi_debug_entry_size, . - .Lefi_debug_entry
  139. #endif
  140. .balign SEGMENT_ALIGN
  141. .Lefi_header_end:
  142. #else
  143. .set .Lpe_header_offset, 0x0
  144. #endif
  145. .endm