efi-header.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 2013 - 2017 Linaro, Ltd.
  3. * Copyright (C) 2013, 2014 Red Hat, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/pe.h>
  10. #include <linux/sizes.h>
  11. .macro __EFI_PE_HEADER
  12. .long PE_MAGIC
  13. coff_header:
  14. .short IMAGE_FILE_MACHINE_ARM64 // Machine
  15. .short section_count // NumberOfSections
  16. .long 0 // TimeDateStamp
  17. .long 0 // PointerToSymbolTable
  18. .long 0 // NumberOfSymbols
  19. .short section_table - optional_header // SizeOfOptionalHeader
  20. .short IMAGE_FILE_DEBUG_STRIPPED | \
  21. IMAGE_FILE_EXECUTABLE_IMAGE | \
  22. IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
  23. optional_header:
  24. .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
  25. .byte 0x02 // MajorLinkerVersion
  26. .byte 0x14 // MinorLinkerVersion
  27. .long __initdata_begin - efi_header_end // SizeOfCode
  28. .long __pecoff_data_size // SizeOfInitializedData
  29. .long 0 // SizeOfUninitializedData
  30. .long __efistub_entry - _head // AddressOfEntryPoint
  31. .long efi_header_end - _head // BaseOfCode
  32. extra_header_fields:
  33. .quad 0 // ImageBase
  34. .long SZ_4K // SectionAlignment
  35. .long PECOFF_FILE_ALIGNMENT // FileAlignment
  36. .short 0 // MajorOperatingSystemVersion
  37. .short 0 // MinorOperatingSystemVersion
  38. .short 0 // MajorImageVersion
  39. .short 0 // MinorImageVersion
  40. .short 0 // MajorSubsystemVersion
  41. .short 0 // MinorSubsystemVersion
  42. .long 0 // Win32VersionValue
  43. .long _end - _head // SizeOfImage
  44. // Everything before the kernel image is considered part of the header
  45. .long efi_header_end - _head // SizeOfHeaders
  46. .long 0 // CheckSum
  47. .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
  48. .short 0 // DllCharacteristics
  49. .quad 0 // SizeOfStackReserve
  50. .quad 0 // SizeOfStackCommit
  51. .quad 0 // SizeOfHeapReserve
  52. .quad 0 // SizeOfHeapCommit
  53. .long 0 // LoaderFlags
  54. .long (section_table - .) / 8 // NumberOfRvaAndSizes
  55. .quad 0 // ExportTable
  56. .quad 0 // ImportTable
  57. .quad 0 // ResourceTable
  58. .quad 0 // ExceptionTable
  59. .quad 0 // CertificationTable
  60. .quad 0 // BaseRelocationTable
  61. #ifdef CONFIG_DEBUG_EFI
  62. .long efi_debug_table - _head // DebugTable
  63. .long efi_debug_table_size
  64. #endif
  65. // Section table
  66. section_table:
  67. .ascii ".text\0\0\0"
  68. .long __initdata_begin - efi_header_end // VirtualSize
  69. .long efi_header_end - _head // VirtualAddress
  70. .long __initdata_begin - efi_header_end // SizeOfRawData
  71. .long efi_header_end - _head // PointerToRawData
  72. .long 0 // PointerToRelocations
  73. .long 0 // PointerToLineNumbers
  74. .short 0 // NumberOfRelocations
  75. .short 0 // NumberOfLineNumbers
  76. .long IMAGE_SCN_CNT_CODE | \
  77. IMAGE_SCN_MEM_READ | \
  78. IMAGE_SCN_MEM_EXECUTE // Characteristics
  79. .ascii ".data\0\0\0"
  80. .long __pecoff_data_size // VirtualSize
  81. .long __initdata_begin - _head // VirtualAddress
  82. .long __pecoff_data_rawsize // SizeOfRawData
  83. .long __initdata_begin - _head // PointerToRawData
  84. .long 0 // PointerToRelocations
  85. .long 0 // PointerToLineNumbers
  86. .short 0 // NumberOfRelocations
  87. .short 0 // NumberOfLineNumbers
  88. .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
  89. IMAGE_SCN_MEM_READ | \
  90. IMAGE_SCN_MEM_WRITE // Characteristics
  91. .set section_count, (. - section_table) / 40
  92. #ifdef CONFIG_DEBUG_EFI
  93. /*
  94. * The debug table is referenced via its Relative Virtual Address (RVA),
  95. * which is only defined for those parts of the image that are covered
  96. * by a section declaration. Since this header is not covered by any
  97. * section, the debug table must be emitted elsewhere. So stick it in
  98. * the .init.rodata section instead.
  99. *
  100. * Note that the EFI debug entry itself may legally have a zero RVA,
  101. * which means we can simply put it right after the section headers.
  102. */
  103. __INITRODATA
  104. .align 2
  105. efi_debug_table:
  106. // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
  107. .long 0 // Characteristics
  108. .long 0 // TimeDateStamp
  109. .short 0 // MajorVersion
  110. .short 0 // MinorVersion
  111. .long IMAGE_DEBUG_TYPE_CODEVIEW // Type
  112. .long efi_debug_entry_size // SizeOfData
  113. .long 0 // RVA
  114. .long efi_debug_entry - _head // FileOffset
  115. .set efi_debug_table_size, . - efi_debug_table
  116. .previous
  117. efi_debug_entry:
  118. // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
  119. .ascii "NB10" // Signature
  120. .long 0 // Unknown
  121. .long 0 // Unknown2
  122. .long 0 // Unknown3
  123. .asciz VMLINUX_PATH
  124. .set efi_debug_entry_size, . - efi_debug_entry
  125. #endif
  126. /*
  127. * EFI will load .text onwards at the 4k section alignment
  128. * described in the PE/COFF header. To ensure that instruction
  129. * sequences using an adrp and a :lo12: immediate will function
  130. * correctly at this alignment, we must ensure that .text is
  131. * placed at a 4k boundary in the Image to begin with.
  132. */
  133. .align 12
  134. efi_header_end:
  135. .endm