.. | .. |
---|
15 | 15 | * hex while segment addresses are written as segment:offset. |
---|
16 | 16 | * |
---|
17 | 17 | */ |
---|
18 | | - |
---|
| 18 | +#include <linux/pe.h> |
---|
19 | 19 | #include <asm/segment.h> |
---|
20 | 20 | #include <asm/boot.h> |
---|
21 | 21 | #include <asm/page_types.h> |
---|
.. | .. |
---|
43 | 43 | bootsect_start: |
---|
44 | 44 | #ifdef CONFIG_EFI_STUB |
---|
45 | 45 | # "MZ", MS-DOS header |
---|
46 | | - .byte 0x4d |
---|
47 | | - .byte 0x5a |
---|
| 46 | + .word MZ_MAGIC |
---|
48 | 47 | #endif |
---|
49 | 48 | |
---|
50 | 49 | # Normalize the start address |
---|
.. | .. |
---|
97 | 96 | |
---|
98 | 97 | #ifdef CONFIG_EFI_STUB |
---|
99 | 98 | pe_header: |
---|
100 | | - .ascii "PE" |
---|
101 | | - .word 0 |
---|
| 99 | + .long PE_MAGIC |
---|
102 | 100 | |
---|
103 | 101 | coff_header: |
---|
104 | 102 | #ifdef CONFIG_X86_32 |
---|
105 | | - .word 0x14c # i386 |
---|
| 103 | + .set image_file_add_flags, IMAGE_FILE_32BIT_MACHINE |
---|
| 104 | + .set pe_opt_magic, PE_OPT_MAGIC_PE32 |
---|
| 105 | + .word IMAGE_FILE_MACHINE_I386 |
---|
106 | 106 | #else |
---|
107 | | - .word 0x8664 # x86-64 |
---|
| 107 | + .set image_file_add_flags, 0 |
---|
| 108 | + .set pe_opt_magic, PE_OPT_MAGIC_PE32PLUS |
---|
| 109 | + .word IMAGE_FILE_MACHINE_AMD64 |
---|
108 | 110 | #endif |
---|
109 | | - .word 4 # nr_sections |
---|
| 111 | + .word section_count # nr_sections |
---|
110 | 112 | .long 0 # TimeDateStamp |
---|
111 | 113 | .long 0 # PointerToSymbolTable |
---|
112 | 114 | .long 1 # NumberOfSymbols |
---|
113 | 115 | .word section_table - optional_header # SizeOfOptionalHeader |
---|
114 | | -#ifdef CONFIG_X86_32 |
---|
115 | | - .word 0x306 # Characteristics. |
---|
116 | | - # IMAGE_FILE_32BIT_MACHINE | |
---|
117 | | - # IMAGE_FILE_DEBUG_STRIPPED | |
---|
118 | | - # IMAGE_FILE_EXECUTABLE_IMAGE | |
---|
119 | | - # IMAGE_FILE_LINE_NUMS_STRIPPED |
---|
120 | | -#else |
---|
121 | | - .word 0x206 # Characteristics |
---|
122 | | - # IMAGE_FILE_DEBUG_STRIPPED | |
---|
123 | | - # IMAGE_FILE_EXECUTABLE_IMAGE | |
---|
124 | | - # IMAGE_FILE_LINE_NUMS_STRIPPED |
---|
125 | | -#endif |
---|
| 116 | + .word IMAGE_FILE_EXECUTABLE_IMAGE | \ |
---|
| 117 | + image_file_add_flags | \ |
---|
| 118 | + IMAGE_FILE_DEBUG_STRIPPED | \ |
---|
| 119 | + IMAGE_FILE_LINE_NUMS_STRIPPED # Characteristics |
---|
126 | 120 | |
---|
127 | 121 | optional_header: |
---|
128 | | -#ifdef CONFIG_X86_32 |
---|
129 | | - .word 0x10b # PE32 format |
---|
130 | | -#else |
---|
131 | | - .word 0x20b # PE32+ format |
---|
132 | | -#endif |
---|
| 122 | + .word pe_opt_magic |
---|
133 | 123 | .byte 0x02 # MajorLinkerVersion |
---|
134 | 124 | .byte 0x14 # MinorLinkerVersion |
---|
135 | 125 | |
---|
.. | .. |
---|
148 | 138 | #endif |
---|
149 | 139 | |
---|
150 | 140 | extra_header_fields: |
---|
| 141 | + # PE specification requires ImageBase to be 64k aligned |
---|
| 142 | + .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff |
---|
151 | 143 | #ifdef CONFIG_X86_32 |
---|
152 | | - .long 0 # ImageBase |
---|
| 144 | + .long image_base # ImageBase |
---|
153 | 145 | #else |
---|
154 | | - .quad 0 # ImageBase |
---|
| 146 | + .quad image_base # ImageBase |
---|
155 | 147 | #endif |
---|
156 | 148 | .long 0x20 # SectionAlignment |
---|
157 | 149 | .long 0x20 # FileAlignment |
---|
158 | 150 | .word 0 # MajorOperatingSystemVersion |
---|
159 | 151 | .word 0 # MinorOperatingSystemVersion |
---|
160 | | - .word 0 # MajorImageVersion |
---|
161 | | - .word 0 # MinorImageVersion |
---|
| 152 | + .word LINUX_EFISTUB_MAJOR_VERSION # MajorImageVersion |
---|
| 153 | + .word LINUX_EFISTUB_MINOR_VERSION # MinorImageVersion |
---|
162 | 154 | .word 0 # MajorSubsystemVersion |
---|
163 | 155 | .word 0 # MinorSubsystemVersion |
---|
164 | 156 | .long 0 # Win32VersionValue |
---|
.. | .. |
---|
170 | 162 | |
---|
171 | 163 | .long 0x200 # SizeOfHeaders |
---|
172 | 164 | .long 0 # CheckSum |
---|
173 | | - .word 0xa # Subsystem (EFI application) |
---|
| 165 | + .word IMAGE_SUBSYSTEM_EFI_APPLICATION # Subsystem (EFI application) |
---|
174 | 166 | .word 0 # DllCharacteristics |
---|
175 | 167 | #ifdef CONFIG_X86_32 |
---|
176 | 168 | .long 0 # SizeOfStackReserve |
---|
.. | .. |
---|
184 | 176 | .quad 0 # SizeOfHeapCommit |
---|
185 | 177 | #endif |
---|
186 | 178 | .long 0 # LoaderFlags |
---|
187 | | - .long 0x6 # NumberOfRvaAndSizes |
---|
| 179 | + .long (section_table - .) / 8 # NumberOfRvaAndSizes |
---|
188 | 180 | |
---|
189 | 181 | .quad 0 # ExportTable |
---|
190 | 182 | .quad 0 # ImportTable |
---|
.. | .. |
---|
210 | 202 | .long 0 # PointerToLineNumbers |
---|
211 | 203 | .word 0 # NumberOfRelocations |
---|
212 | 204 | .word 0 # NumberOfLineNumbers |
---|
213 | | - .long 0x60500020 # Characteristics (section flags) |
---|
| 205 | + .long IMAGE_SCN_CNT_CODE | \ |
---|
| 206 | + IMAGE_SCN_MEM_READ | \ |
---|
| 207 | + IMAGE_SCN_MEM_EXECUTE | \ |
---|
| 208 | + IMAGE_SCN_ALIGN_16BYTES # Characteristics |
---|
214 | 209 | |
---|
215 | 210 | # |
---|
216 | 211 | # The EFI application loader requires a relocation section |
---|
.. | .. |
---|
228 | 223 | .long 0 # PointerToLineNumbers |
---|
229 | 224 | .word 0 # NumberOfRelocations |
---|
230 | 225 | .word 0 # NumberOfLineNumbers |
---|
231 | | - .long 0x42100040 # Characteristics (section flags) |
---|
| 226 | + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ |
---|
| 227 | + IMAGE_SCN_MEM_READ | \ |
---|
| 228 | + IMAGE_SCN_MEM_DISCARDABLE | \ |
---|
| 229 | + IMAGE_SCN_ALIGN_1BYTES # Characteristics |
---|
| 230 | + |
---|
| 231 | +#ifdef CONFIG_EFI_MIXED |
---|
| 232 | + # |
---|
| 233 | + # The offset & size fields are filled in by build.c. |
---|
| 234 | + # |
---|
| 235 | + .asciz ".compat" |
---|
| 236 | + .long 0 |
---|
| 237 | + .long 0x0 |
---|
| 238 | + .long 0 # Size of initialized data |
---|
| 239 | + # on disk |
---|
| 240 | + .long 0x0 |
---|
| 241 | + .long 0 # PointerToRelocations |
---|
| 242 | + .long 0 # PointerToLineNumbers |
---|
| 243 | + .word 0 # NumberOfRelocations |
---|
| 244 | + .word 0 # NumberOfLineNumbers |
---|
| 245 | + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ |
---|
| 246 | + IMAGE_SCN_MEM_READ | \ |
---|
| 247 | + IMAGE_SCN_MEM_DISCARDABLE | \ |
---|
| 248 | + IMAGE_SCN_ALIGN_1BYTES # Characteristics |
---|
| 249 | +#endif |
---|
232 | 250 | |
---|
233 | 251 | # |
---|
234 | 252 | # The offset & size fields are filled in by build.c. |
---|
.. | .. |
---|
246 | 264 | .long 0 # PointerToLineNumbers |
---|
247 | 265 | .word 0 # NumberOfRelocations |
---|
248 | 266 | .word 0 # NumberOfLineNumbers |
---|
249 | | - .long 0x60500020 # Characteristics (section flags) |
---|
| 267 | + .long IMAGE_SCN_CNT_CODE | \ |
---|
| 268 | + IMAGE_SCN_MEM_READ | \ |
---|
| 269 | + IMAGE_SCN_MEM_EXECUTE | \ |
---|
| 270 | + IMAGE_SCN_ALIGN_16BYTES # Characteristics |
---|
250 | 271 | |
---|
251 | | - # |
---|
252 | | - # The offset & size fields are filled in by build.c. |
---|
253 | | - # |
---|
254 | | - .ascii ".bss" |
---|
255 | | - .byte 0 |
---|
256 | | - .byte 0 |
---|
257 | | - .byte 0 |
---|
258 | | - .byte 0 |
---|
259 | | - .long 0 |
---|
260 | | - .long 0x0 |
---|
261 | | - .long 0 # Size of initialized data |
---|
262 | | - # on disk |
---|
263 | | - .long 0x0 |
---|
264 | | - .long 0 # PointerToRelocations |
---|
265 | | - .long 0 # PointerToLineNumbers |
---|
266 | | - .word 0 # NumberOfRelocations |
---|
267 | | - .word 0 # NumberOfLineNumbers |
---|
268 | | - .long 0xc8000080 # Characteristics (section flags) |
---|
269 | | - |
---|
| 272 | + .set section_count, (. - section_table) / 40 |
---|
270 | 273 | #endif /* CONFIG_EFI_STUB */ |
---|
271 | 274 | |
---|
272 | 275 | # Kernel attributes; used by setup. This is part 1 of the |
---|
.. | .. |
---|
300 | 303 | # Part 2 of the header, from the old setup.S |
---|
301 | 304 | |
---|
302 | 305 | .ascii "HdrS" # header signature |
---|
303 | | - .word 0x020d # header version number (>= 0x0105) |
---|
| 306 | + .word 0x020f # header version number (>= 0x0105) |
---|
304 | 307 | # or else old loadlin-1.5 will fail) |
---|
305 | 308 | .globl realmode_swtch |
---|
306 | 309 | realmode_swtch: .word 0, 0 # default_switch, SETUPSEG |
---|
.. | .. |
---|
313 | 316 | |
---|
314 | 317 | type_of_loader: .byte 0 # 0 means ancient bootloader, newer |
---|
315 | 318 | # bootloaders know to change this. |
---|
316 | | - # See Documentation/x86/boot.txt for |
---|
| 319 | + # See Documentation/x86/boot.rst for |
---|
317 | 320 | # assigned ids |
---|
318 | 321 | |
---|
319 | 322 | # flags, unused bits must be zero (RFU) bit within loadflags |
---|
.. | .. |
---|
419 | 422 | # define XLF4 0 |
---|
420 | 423 | #endif |
---|
421 | 424 | |
---|
422 | | - .word XLF0 | XLF1 | XLF23 | XLF4 |
---|
| 425 | +#ifdef CONFIG_X86_64 |
---|
| 426 | +#ifdef CONFIG_X86_5LEVEL |
---|
| 427 | +#define XLF56 (XLF_5LEVEL|XLF_5LEVEL_ENABLED) |
---|
| 428 | +#else |
---|
| 429 | +#define XLF56 XLF_5LEVEL |
---|
| 430 | +#endif |
---|
| 431 | +#else |
---|
| 432 | +#define XLF56 0 |
---|
| 433 | +#endif |
---|
| 434 | + |
---|
| 435 | + .word XLF0 | XLF1 | XLF23 | XLF4 | XLF56 |
---|
423 | 436 | |
---|
424 | 437 | cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line, |
---|
425 | 438 | #added with boot protocol |
---|
.. | .. |
---|
526 | 539 | # the size-dependent part now grows so fast. |
---|
527 | 540 | # |
---|
528 | 541 | # extra_bytes = (uncompressed_size >> 8) + 65536 |
---|
| 542 | +# |
---|
| 543 | +# ZSTD compressed data grows by at most 3 bytes per 128K, and only has a 22 |
---|
| 544 | +# byte fixed overhead but has a maximum block size of 128K, so it needs a |
---|
| 545 | +# larger margin. |
---|
| 546 | +# |
---|
| 547 | +# extra_bytes = (uncompressed_size >> 8) + 131072 |
---|
529 | 548 | |
---|
530 | | -#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 65536) |
---|
| 549 | +#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 131072) |
---|
531 | 550 | #if ZO_z_output_len > ZO_z_input_len |
---|
532 | 551 | # define ZO_z_extract_offset (ZO_z_output_len + ZO_z_extra_bytes - \ |
---|
533 | 552 | ZO_z_input_len) |
---|
.. | .. |
---|
557 | 576 | |
---|
558 | 577 | init_size: .long INIT_SIZE # kernel initialization size |
---|
559 | 578 | handover_offset: .long 0 # Filled in by build.c |
---|
| 579 | +kernel_info_offset: .long 0 # Filled in by build.c |
---|
560 | 580 | |
---|
561 | 581 | # End of setup header ##################################################### |
---|
562 | 582 | |
---|