efi-header.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. W(mov) r0, r0
  20. #endif
  21. .endm
  22. .macro __EFI_HEADER
  23. #ifdef CONFIG_EFI_STUB
  24. .set start_offset, __efi_start - start
  25. .org start + 0x3c
  26. @
  27. @ The PE header can be anywhere in the file, but for
  28. @ simplicity we keep it together with the MSDOS header
  29. @ The offset to the PE/COFF header needs to be at offset
  30. @ 0x3C in the MSDOS header.
  31. @ The only 2 fields of the MSDOS header that are used are this
  32. @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
  33. @
  34. .long pe_header - start @ Offset to the PE header.
  35. pe_header:
  36. .ascii "PE\0\0"
  37. coff_header:
  38. .short 0x01c2 @ ARM or Thumb
  39. .short 2 @ nr_sections
  40. .long 0 @ TimeDateStamp
  41. .long 0 @ PointerToSymbolTable
  42. .long 1 @ NumberOfSymbols
  43. .short section_table - optional_header
  44. @ SizeOfOptionalHeader
  45. .short 0x306 @ Characteristics.
  46. @ IMAGE_FILE_32BIT_MACHINE |
  47. @ IMAGE_FILE_DEBUG_STRIPPED |
  48. @ IMAGE_FILE_EXECUTABLE_IMAGE |
  49. @ IMAGE_FILE_LINE_NUMS_STRIPPED
  50. optional_header:
  51. .short 0x10b @ PE32 format
  52. .byte 0x02 @ MajorLinkerVersion
  53. .byte 0x14 @ MinorLinkerVersion
  54. .long _end - __efi_start @ SizeOfCode
  55. .long 0 @ SizeOfInitializedData
  56. .long 0 @ SizeOfUninitializedData
  57. .long efi_stub_entry - start @ AddressOfEntryPoint
  58. .long start_offset @ BaseOfCode
  59. .long 0 @ data
  60. extra_header_fields:
  61. .long 0 @ ImageBase
  62. .long 0x200 @ SectionAlignment
  63. .long 0x200 @ FileAlignment
  64. .short 0 @ MajorOperatingSystemVersion
  65. .short 0 @ MinorOperatingSystemVersion
  66. .short 0 @ MajorImageVersion
  67. .short 0 @ MinorImageVersion
  68. .short 0 @ MajorSubsystemVersion
  69. .short 0 @ MinorSubsystemVersion
  70. .long 0 @ Win32VersionValue
  71. .long _end - start @ SizeOfImage
  72. .long start_offset @ SizeOfHeaders
  73. .long 0 @ CheckSum
  74. .short 0xa @ Subsystem (EFI application)
  75. .short 0 @ DllCharacteristics
  76. .long 0 @ SizeOfStackReserve
  77. .long 0 @ SizeOfStackCommit
  78. .long 0 @ SizeOfHeapReserve
  79. .long 0 @ SizeOfHeapCommit
  80. .long 0 @ LoaderFlags
  81. .long 0x6 @ NumberOfRvaAndSizes
  82. .quad 0 @ ExportTable
  83. .quad 0 @ ImportTable
  84. .quad 0 @ ResourceTable
  85. .quad 0 @ ExceptionTable
  86. .quad 0 @ CertificationTable
  87. .quad 0 @ BaseRelocationTable
  88. section_table:
  89. @
  90. @ The EFI application loader requires a relocation section
  91. @ because EFI applications must be relocatable. This is a
  92. @ dummy section as far as we are concerned.
  93. @
  94. .ascii ".reloc\0\0"
  95. .long 0 @ VirtualSize
  96. .long 0 @ VirtualAddress
  97. .long 0 @ SizeOfRawData
  98. .long 0 @ PointerToRawData
  99. .long 0 @ PointerToRelocations
  100. .long 0 @ PointerToLineNumbers
  101. .short 0 @ NumberOfRelocations
  102. .short 0 @ NumberOfLineNumbers
  103. .long 0x42100040 @ Characteristics
  104. .ascii ".text\0\0\0"
  105. .long _end - __efi_start @ VirtualSize
  106. .long __efi_start @ VirtualAddress
  107. .long _edata - __efi_start @ SizeOfRawData
  108. .long __efi_start @ PointerToRawData
  109. .long 0 @ PointerToRelocations
  110. .long 0 @ PointerToLineNumbers
  111. .short 0 @ NumberOfRelocations
  112. .short 0 @ NumberOfLineNumbers
  113. .long 0xe0500020 @ Characteristics
  114. .align 9
  115. __efi_start:
  116. #endif
  117. .endm