1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 - 2017 Linaro, Ltd.
4 * Copyright (C) 2013, 2014 Red Hat, Inc.
8 #include <linux/sizes.h>
10 .macro __EFI_PE_HEADER
13 .short IMAGE_FILE_MACHINE_ARM64 // Machine
14 .short section_count // NumberOfSections
15 .long 0 // TimeDateStamp
16 .long 0 // PointerToSymbolTable
17 .long 0 // NumberOfSymbols
18 .short section_table - optional_header // SizeOfOptionalHeader
19 .short IMAGE_FILE_DEBUG_STRIPPED | \
20 IMAGE_FILE_EXECUTABLE_IMAGE | \
21 IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
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
35 .long SZ_4K // SectionAlignment
36 .long PECOFF_FILE_ALIGNMENT // FileAlignment
37 .short 0 // MajorOperatingSystemVersion
38 .short 0 // MinorOperatingSystemVersion
39 .short 0 // MajorImageVersion
40 .short 0 // MinorImageVersion
41 .short 0 // MajorSubsystemVersion
42 .short 0 // MinorSubsystemVersion
43 .long 0 // Win32VersionValue
45 .long _end - _head // SizeOfImage
47 // Everything before the kernel image is considered part of the header
48 .long efi_header_end - _head // SizeOfHeaders
50 .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
51 .short 0 // DllCharacteristics
52 .quad 0 // SizeOfStackReserve
53 .quad 0 // SizeOfStackCommit
54 .quad 0 // SizeOfHeapReserve
55 .quad 0 // SizeOfHeapCommit
56 .long 0 // LoaderFlags
57 .long (section_table - .) / 8 // NumberOfRvaAndSizes
59 .quad 0 // ExportTable
60 .quad 0 // ImportTable
61 .quad 0 // ResourceTable
62 .quad 0 // ExceptionTable
63 .quad 0 // CertificationTable
64 .quad 0 // BaseRelocationTable
66 #ifdef CONFIG_DEBUG_EFI
67 .long efi_debug_table - _head // DebugTable
68 .long efi_debug_table_size
74 .long __initdata_begin - efi_header_end // VirtualSize
75 .long efi_header_end - _head // VirtualAddress
76 .long __initdata_begin - efi_header_end // SizeOfRawData
77 .long efi_header_end - _head // PointerToRawData
79 .long 0 // PointerToRelocations
80 .long 0 // PointerToLineNumbers
81 .short 0 // NumberOfRelocations
82 .short 0 // NumberOfLineNumbers
83 .long IMAGE_SCN_CNT_CODE | \
84 IMAGE_SCN_MEM_READ | \
85 IMAGE_SCN_MEM_EXECUTE // Characteristics
88 .long __pecoff_data_size // VirtualSize
89 .long __initdata_begin - _head // VirtualAddress
90 .long __pecoff_data_rawsize // SizeOfRawData
91 .long __initdata_begin - _head // PointerToRawData
93 .long 0 // PointerToRelocations
94 .long 0 // PointerToLineNumbers
95 .short 0 // NumberOfRelocations
96 .short 0 // NumberOfLineNumbers
97 .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
98 IMAGE_SCN_MEM_READ | \
99 IMAGE_SCN_MEM_WRITE // Characteristics
101 .set section_count, (. - section_table) / 40
103 #ifdef CONFIG_DEBUG_EFI
105 * The debug table is referenced via its Relative Virtual Address (RVA),
106 * which is only defined for those parts of the image that are covered
107 * by a section declaration. Since this header is not covered by any
108 * section, the debug table must be emitted elsewhere. So stick it in
109 * the .init.rodata section instead.
111 * Note that the EFI debug entry itself may legally have a zero RVA,
112 * which means we can simply put it right after the section headers.
118 // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
119 .long 0 // Characteristics
120 .long 0 // TimeDateStamp
121 .short 0 // MajorVersion
122 .short 0 // MinorVersion
123 .long IMAGE_DEBUG_TYPE_CODEVIEW // Type
124 .long efi_debug_entry_size // SizeOfData
126 .long efi_debug_entry - _head // FileOffset
128 .set efi_debug_table_size, . - efi_debug_table
132 // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
133 .ascii "NB10" // Signature
140 .set efi_debug_entry_size, . - efi_debug_entry
144 * EFI will load .text onwards at the 4k section alignment
145 * described in the PE/COFF header. To ensure that instruction
146 * sequences using an adrp and a :lo12: immediate will function
147 * correctly at this alignment, we must ensure that .text is
148 * placed at a 4k boundary in the Image to begin with.