efi-header.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2013-2017 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. #include <linux/pe.h>
  11. #include <linux/sizes.h>
  12. .macro __nop
  13. #ifdef CONFIG_EFI_STUB
  14. @ This is almost but not quite a NOP, since it does clobber the
  15. @ condition flags. But it is the best we can do for EFI, since
  16. @ PE/COFF expects the magic string "MZ" at offset 0, while the
  17. @ ARM/Linux boot protocol expects an executable instruction
  18. @ there.
  19. .inst MZ_MAGIC | (0x1310 << 16) @ tstne r0, #0x4d000
  20. #else
  21. AR_CLASS( mov r0, r0 )
  22. M_CLASS( nop.w )
  23. #endif
  24. .endm
  25. .macro __EFI_HEADER
  26. #ifdef CONFIG_EFI_STUB
  27. .set start_offset, __efi_start - start
  28. .org start + 0x3c
  29. @
  30. @ The PE header can be anywhere in the file, but for
  31. @ simplicity we keep it together with the MSDOS header
  32. @ The offset to the PE/COFF header needs to be at offset
  33. @ 0x3C in the MSDOS header.
  34. @ The only 2 fields of the MSDOS header that are used are this
  35. @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
  36. @
  37. .long pe_header - start @ Offset to the PE header.
  38. pe_header:
  39. .long PE_MAGIC
  40. coff_header:
  41. .short IMAGE_FILE_MACHINE_THUMB @ Machine
  42. .short section_count @ NumberOfSections
  43. .long 0 @ TimeDateStamp
  44. .long 0 @ PointerToSymbolTable
  45. .long 0 @ NumberOfSymbols
  46. .short section_table - optional_header @ SizeOfOptionalHeader
  47. .short IMAGE_FILE_32BIT_MACHINE | \
  48. IMAGE_FILE_DEBUG_STRIPPED | \
  49. IMAGE_FILE_EXECUTABLE_IMAGE | \
  50. IMAGE_FILE_LINE_NUMS_STRIPPED @ Characteristics
  51. #define __pecoff_code_size (__pecoff_data_start - __efi_start)
  52. optional_header:
  53. .short PE_OPT_MAGIC_PE32 @ PE32 format
  54. .byte 0x02 @ MajorLinkerVersion
  55. .byte 0x14 @ MinorLinkerVersion
  56. .long __pecoff_code_size @ SizeOfCode
  57. .long __pecoff_data_size @ SizeOfInitializedData
  58. .long 0 @ SizeOfUninitializedData
  59. .long efi_stub_entry - start @ AddressOfEntryPoint
  60. .long start_offset @ BaseOfCode
  61. .long __pecoff_data_start - start @ BaseOfData
  62. extra_header_fields:
  63. .long 0 @ ImageBase
  64. .long SZ_4K @ SectionAlignment
  65. .long SZ_512 @ FileAlignment
  66. .short 0 @ MajorOsVersion
  67. .short 0 @ MinorOsVersion
  68. .short 0 @ MajorImageVersion
  69. .short 0 @ MinorImageVersion
  70. .short 0 @ MajorSubsystemVersion
  71. .short 0 @ MinorSubsystemVersion
  72. .long 0 @ Win32VersionValue
  73. .long __pecoff_end - start @ SizeOfImage
  74. .long start_offset @ SizeOfHeaders
  75. .long 0 @ CheckSum
  76. .short IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem
  77. .short 0 @ DllCharacteristics
  78. .long 0 @ SizeOfStackReserve
  79. .long 0 @ SizeOfStackCommit
  80. .long 0 @ SizeOfHeapReserve
  81. .long 0 @ SizeOfHeapCommit
  82. .long 0 @ LoaderFlags
  83. .long (section_table - .) / 8 @ NumberOfRvaAndSizes
  84. .quad 0 @ ExportTable
  85. .quad 0 @ ImportTable
  86. .quad 0 @ ResourceTable
  87. .quad 0 @ ExceptionTable
  88. .quad 0 @ CertificationTable
  89. .quad 0 @ BaseRelocationTable
  90. section_table:
  91. .ascii ".text\0\0\0"
  92. .long __pecoff_code_size @ VirtualSize
  93. .long __efi_start @ VirtualAddress
  94. .long __pecoff_code_size @ SizeOfRawData
  95. .long __efi_start @ PointerToRawData
  96. .long 0 @ PointerToRelocations
  97. .long 0 @ PointerToLineNumbers
  98. .short 0 @ NumberOfRelocations
  99. .short 0 @ NumberOfLineNumbers
  100. .long IMAGE_SCN_CNT_CODE | \
  101. IMAGE_SCN_MEM_READ | \
  102. IMAGE_SCN_MEM_EXECUTE @ Characteristics
  103. .ascii ".data\0\0\0"
  104. .long __pecoff_data_size @ VirtualSize
  105. .long __pecoff_data_start - start @ VirtualAddress
  106. .long __pecoff_data_rawsize @ SizeOfRawData
  107. .long __pecoff_data_start - start @ PointerToRawData
  108. .long 0 @ PointerToRelocations
  109. .long 0 @ PointerToLineNumbers
  110. .short 0 @ NumberOfRelocations
  111. .short 0 @ NumberOfLineNumbers
  112. .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
  113. IMAGE_SCN_MEM_READ | \
  114. IMAGE_SCN_MEM_WRITE @ Characteristics
  115. .set section_count, (. - section_table) / 40
  116. .align 12
  117. __efi_start:
  118. #endif
  119. .endm