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.
10 .macro __EFI_PE_HEADER
14 .short 0xaa64 // AArch64
15 .short 2 // nr_sections
16 .long 0 // TimeDateStamp
17 .long 0 // PointerToSymbolTable
18 .long 1 // NumberOfSymbols
19 .short section_table - optional_header // SizeOfOptionalHeader
20 .short 0x206 // Characteristics.
21 // IMAGE_FILE_DEBUG_STRIPPED |
22 // IMAGE_FILE_EXECUTABLE_IMAGE |
23 // IMAGE_FILE_LINE_NUMS_STRIPPED
25 .short 0x20b // PE32+ format
26 .byte 0x02 // MajorLinkerVersion
27 .byte 0x14 // MinorLinkerVersion
28 .long _end - efi_header_end // SizeOfCode
29 .long 0 // SizeOfInitializedData
30 .long 0 // SizeOfUninitializedData
31 .long __efistub_entry - _head // AddressOfEntryPoint
32 .long efi_header_end - _head // BaseOfCode
36 .long 0x1000 // SectionAlignment
37 .long PECOFF_FILE_ALIGNMENT // FileAlignment
38 .short 0 // MajorOperatingSystemVersion
39 .short 0 // MinorOperatingSystemVersion
40 .short 0 // MajorImageVersion
41 .short 0 // MinorImageVersion
42 .short 0 // MajorSubsystemVersion
43 .short 0 // MinorSubsystemVersion
44 .long 0 // Win32VersionValue
46 .long _end - _head // SizeOfImage
48 // Everything before the kernel image is considered part of the header
49 .long efi_header_end - _head // SizeOfHeaders
51 .short 0xa // Subsystem (EFI application)
52 .short 0 // DllCharacteristics
53 .quad 0 // SizeOfStackReserve
54 .quad 0 // SizeOfStackCommit
55 .quad 0 // SizeOfHeapReserve
56 .quad 0 // SizeOfHeapCommit
57 .long 0 // LoaderFlags
58 .long (section_table - .) / 8 // NumberOfRvaAndSizes
60 .quad 0 // ExportTable
61 .quad 0 // ImportTable
62 .quad 0 // ResourceTable
63 .quad 0 // ExceptionTable
64 .quad 0 // CertificationTable
65 .quad 0 // BaseRelocationTable
67 #ifdef CONFIG_DEBUG_EFI
68 .long efi_debug_table - _head // DebugTable
69 .long efi_debug_table_size
76 * The EFI application loader requires a relocation section
77 * because EFI applications must be relocatable. This is a
78 * dummy section as far as we are concerned.
82 .byte 0 // end of 0 padding of section name
85 .long 0 // SizeOfRawData
86 .long 0 // PointerToRawData
87 .long 0 // PointerToRelocations
88 .long 0 // PointerToLineNumbers
89 .short 0 // NumberOfRelocations
90 .short 0 // NumberOfLineNumbers
91 .long 0x42100040 // Characteristics (section flags)
97 .byte 0 // end of 0 padding of section name
98 .long _end - efi_header_end // VirtualSize
99 .long efi_header_end - _head // VirtualAddress
100 .long _edata - efi_header_end // SizeOfRawData
101 .long efi_header_end - _head // PointerToRawData
103 .long 0 // PointerToRelocations
104 .long 0 // PointerToLineNumbers
105 .short 0 // NumberOfRelocations
106 .short 0 // NumberOfLineNumbers
107 .long 0xe0500020 // Characteristics
109 #ifdef CONFIG_DEBUG_EFI
111 * The debug table is referenced via its Relative Virtual Address (RVA),
112 * which is only defined for those parts of the image that are covered
113 * by a section declaration. Since this header is not covered by any
114 * section, the debug table must be emitted elsewhere. So stick it in
115 * the .init.rodata section instead.
117 * Note that the EFI debug entry itself may legally have a zero RVA,
118 * which means we can simply put it right after the section headers.
124 // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
125 .long 0 // Characteristics
126 .long 0 // TimeDateStamp
127 .short 0 // MajorVersion
128 .short 0 // MinorVersion
129 .long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW
130 .long efi_debug_entry_size // SizeOfData
132 .long efi_debug_entry - _head // FileOffset
134 .set efi_debug_table_size, . - efi_debug_table
138 // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
139 .ascii "NB10" // Signature
146 .set efi_debug_entry_size, . - efi_debug_entry
150 * EFI will load .text onwards at the 4k section alignment
151 * described in the PE/COFF header. To ensure that instruction
152 * sequences using an adrp and a :lo12: immediate will function
153 * correctly at this alignment, we must ensure that .text is
154 * placed at a 4k boundary in the Image to begin with.