forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/arch/x86/boot/header.S
....@@ -15,7 +15,7 @@
1515 * hex while segment addresses are written as segment:offset.
1616 *
1717 */
18
-
18
+#include <linux/pe.h>
1919 #include <asm/segment.h>
2020 #include <asm/boot.h>
2121 #include <asm/page_types.h>
....@@ -43,8 +43,7 @@
4343 bootsect_start:
4444 #ifdef CONFIG_EFI_STUB
4545 # "MZ", MS-DOS header
46
- .byte 0x4d
47
- .byte 0x5a
46
+ .word MZ_MAGIC
4847 #endif
4948
5049 # Normalize the start address
....@@ -97,39 +96,30 @@
9796
9897 #ifdef CONFIG_EFI_STUB
9998 pe_header:
100
- .ascii "PE"
101
- .word 0
99
+ .long PE_MAGIC
102100
103101 coff_header:
104102 #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
106106 #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
108110 #endif
109
- .word 4 # nr_sections
111
+ .word section_count # nr_sections
110112 .long 0 # TimeDateStamp
111113 .long 0 # PointerToSymbolTable
112114 .long 1 # NumberOfSymbols
113115 .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
126120
127121 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
133123 .byte 0x02 # MajorLinkerVersion
134124 .byte 0x14 # MinorLinkerVersion
135125
....@@ -148,17 +138,19 @@
148138 #endif
149139
150140 extra_header_fields:
141
+ # PE specification requires ImageBase to be 64k aligned
142
+ .set image_base, (LOAD_PHYSICAL_ADDR + 0xffff) & ~0xffff
151143 #ifdef CONFIG_X86_32
152
- .long 0 # ImageBase
144
+ .long image_base # ImageBase
153145 #else
154
- .quad 0 # ImageBase
146
+ .quad image_base # ImageBase
155147 #endif
156148 .long 0x20 # SectionAlignment
157149 .long 0x20 # FileAlignment
158150 .word 0 # MajorOperatingSystemVersion
159151 .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
162154 .word 0 # MajorSubsystemVersion
163155 .word 0 # MinorSubsystemVersion
164156 .long 0 # Win32VersionValue
....@@ -170,7 +162,7 @@
170162
171163 .long 0x200 # SizeOfHeaders
172164 .long 0 # CheckSum
173
- .word 0xa # Subsystem (EFI application)
165
+ .word IMAGE_SUBSYSTEM_EFI_APPLICATION # Subsystem (EFI application)
174166 .word 0 # DllCharacteristics
175167 #ifdef CONFIG_X86_32
176168 .long 0 # SizeOfStackReserve
....@@ -184,7 +176,7 @@
184176 .quad 0 # SizeOfHeapCommit
185177 #endif
186178 .long 0 # LoaderFlags
187
- .long 0x6 # NumberOfRvaAndSizes
179
+ .long (section_table - .) / 8 # NumberOfRvaAndSizes
188180
189181 .quad 0 # ExportTable
190182 .quad 0 # ImportTable
....@@ -210,7 +202,10 @@
210202 .long 0 # PointerToLineNumbers
211203 .word 0 # NumberOfRelocations
212204 .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
214209
215210 #
216211 # The EFI application loader requires a relocation section
....@@ -228,7 +223,30 @@
228223 .long 0 # PointerToLineNumbers
229224 .word 0 # NumberOfRelocations
230225 .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
232250
233251 #
234252 # The offset & size fields are filled in by build.c.
....@@ -246,27 +264,12 @@
246264 .long 0 # PointerToLineNumbers
247265 .word 0 # NumberOfRelocations
248266 .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
250271
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
270273 #endif /* CONFIG_EFI_STUB */
271274
272275 # Kernel attributes; used by setup. This is part 1 of the
....@@ -300,7 +303,7 @@
300303 # Part 2 of the header, from the old setup.S
301304
302305 .ascii "HdrS" # header signature
303
- .word 0x020d # header version number (>= 0x0105)
306
+ .word 0x020f # header version number (>= 0x0105)
304307 # or else old loadlin-1.5 will fail)
305308 .globl realmode_swtch
306309 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
....@@ -313,7 +316,7 @@
313316
314317 type_of_loader: .byte 0 # 0 means ancient bootloader, newer
315318 # bootloaders know to change this.
316
- # See Documentation/x86/boot.txt for
319
+ # See Documentation/x86/boot.rst for
317320 # assigned ids
318321
319322 # flags, unused bits must be zero (RFU) bit within loadflags
....@@ -419,7 +422,17 @@
419422 # define XLF4 0
420423 #endif
421424
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
423436
424437 cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
425438 #added with boot protocol
....@@ -526,8 +539,14 @@
526539 # the size-dependent part now grows so fast.
527540 #
528541 # 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
529548
530
-#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 65536)
549
+#define ZO_z_extra_bytes ((ZO_z_output_len >> 8) + 131072)
531550 #if ZO_z_output_len > ZO_z_input_len
532551 # define ZO_z_extract_offset (ZO_z_output_len + ZO_z_extra_bytes - \
533552 ZO_z_input_len)
....@@ -557,6 +576,7 @@
557576
558577 init_size: .long INIT_SIZE # kernel initialization size
559578 handover_offset: .long 0 # Filled in by build.c
579
+kernel_info_offset: .long 0 # Filled in by build.c
560580
561581 # End of setup header #####################################################
562582