2 * Copyright (C) 2013 - 2017 Linaro, Ltd.
3 * Copyright (C) 2013, 2014 Red Hat, Inc.
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.
11 #include <linux/sizes.h>
13 .macro __EFI_PE_HEADER
16 .short IMAGE_FILE_MACHINE_ARM64 // Machine
17 .short section_count // NumberOfSections
18 .long 0 // TimeDateStamp
19 .long 0 // PointerToSymbolTable
20 .long 0 // NumberOfSymbols
21 .short section_table - optional_header // SizeOfOptionalHeader
22 .short IMAGE_FILE_DEBUG_STRIPPED | \
23 IMAGE_FILE_EXECUTABLE_IMAGE | \
24 IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
27 .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
28 .byte 0x02 // MajorLinkerVersion
29 .byte 0x14 // MinorLinkerVersion
30 .long __initdata_begin - efi_header_end // SizeOfCode
31 .long __pecoff_data_size // SizeOfInitializedData
32 .long 0 // SizeOfUninitializedData
33 .long __efistub_entry - _head // AddressOfEntryPoint
34 .long efi_header_end - _head // BaseOfCode
38 .long SZ_4K // SectionAlignment
39 .long PECOFF_FILE_ALIGNMENT // FileAlignment
40 .short 0 // MajorOperatingSystemVersion
41 .short 0 // MinorOperatingSystemVersion
42 .short 0 // MajorImageVersion
43 .short 0 // MinorImageVersion
44 .short 0 // MajorSubsystemVersion
45 .short 0 // MinorSubsystemVersion
46 .long 0 // Win32VersionValue
48 .long _end - _head // SizeOfImage
50 // Everything before the kernel image is considered part of the header
51 .long efi_header_end - _head // SizeOfHeaders
53 .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
54 .short 0 // DllCharacteristics
55 .quad 0 // SizeOfStackReserve
56 .quad 0 // SizeOfStackCommit
57 .quad 0 // SizeOfHeapReserve
58 .quad 0 // SizeOfHeapCommit
59 .long 0 // LoaderFlags
60 .long (section_table - .) / 8 // NumberOfRvaAndSizes
62 .quad 0 // ExportTable
63 .quad 0 // ImportTable
64 .quad 0 // ResourceTable
65 .quad 0 // ExceptionTable
66 .quad 0 // CertificationTable
67 .quad 0 // BaseRelocationTable
69 #ifdef CONFIG_DEBUG_EFI
70 .long efi_debug_table - _head // DebugTable
71 .long efi_debug_table_size
77 .long __initdata_begin - efi_header_end // VirtualSize
78 .long efi_header_end - _head // VirtualAddress
79 .long __initdata_begin - efi_header_end // SizeOfRawData
80 .long efi_header_end - _head // PointerToRawData
82 .long 0 // PointerToRelocations
83 .long 0 // PointerToLineNumbers
84 .short 0 // NumberOfRelocations
85 .short 0 // NumberOfLineNumbers
86 .long IMAGE_SCN_CNT_CODE | \
87 IMAGE_SCN_MEM_READ | \
88 IMAGE_SCN_MEM_EXECUTE // Characteristics
91 .long __pecoff_data_size // VirtualSize
92 .long __initdata_begin - _head // VirtualAddress
93 .long __pecoff_data_rawsize // SizeOfRawData
94 .long __initdata_begin - _head // PointerToRawData
96 .long 0 // PointerToRelocations
97 .long 0 // PointerToLineNumbers
98 .short 0 // NumberOfRelocations
99 .short 0 // NumberOfLineNumbers
100 .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
101 IMAGE_SCN_MEM_READ | \
102 IMAGE_SCN_MEM_WRITE // Characteristics
104 .set section_count, (. - section_table) / 40
106 #ifdef CONFIG_DEBUG_EFI
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.
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.
121 // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
122 .long 0 // Characteristics
123 .long 0 // TimeDateStamp
124 .short 0 // MajorVersion
125 .short 0 // MinorVersion
126 .long IMAGE_DEBUG_TYPE_CODEVIEW // Type
127 .long efi_debug_entry_size // SizeOfData
129 .long efi_debug_entry - _head // FileOffset
131 .set efi_debug_table_size, . - efi_debug_table
135 // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
136 .ascii "NB10" // Signature
143 .set efi_debug_entry_size, . - efi_debug_entry
147 * EFI will load .text onwards at the 4k section alignment
148 * described in the PE/COFF header. To ensure that instruction
149 * sequences using an adrp and a :lo12: immediate will function
150 * correctly at this alignment, we must ensure that .text is
151 * placed at a 4k boundary in the Image to begin with.