Skip to content

Commit 4ffdbe3

Browse files
author
Ard Biesheuvel
committed
arm64: move early boot code to the .init segment
Apart from the arm64/linux and EFI header data structures, there is nothing in the .head.text section that must reside at the beginning of the Image. So let's move it to the .init section where it belongs. Note that this involves some minor tweaking of the EFI header, primarily because the address of 'stext' no longer coincides with the start of the .text section. It also requires a couple of relocated symbol references to be slightly rewritten or their definition moved to the linker script. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit 546c8c44f092b2f23291fe499c221efc8cabbb67) Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
1 parent 4099b5a commit 4ffdbe3

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

arch/arm64/kernel/efi-entry.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ENTRY(entry)
6161
*/
6262
mov x20, x0 // DTB address
6363
ldr x0, [sp, #16] // relocated _text address
64-
movz x21, #:abs_g0:stext_offset
64+
ldr w21, =stext_offset
6565
add x21, x0, x21
6666

6767
/*

arch/arm64/kernel/head.S

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ _head:
100100
#endif
101101

102102
#ifdef CONFIG_EFI
103-
.globl __efistub_stext_offset
104-
.set __efistub_stext_offset, stext - _head
105103
.align 3
106104
pe_header:
107105
.ascii "PE"
@@ -121,11 +119,11 @@ optional_header:
121119
.short 0x20b // PE32+ format
122120
.byte 0x02 // MajorLinkerVersion
123121
.byte 0x14 // MinorLinkerVersion
124-
.long _end - stext // SizeOfCode
122+
.long _end - efi_header_end // SizeOfCode
125123
.long 0 // SizeOfInitializedData
126124
.long 0 // SizeOfUninitializedData
127125
.long __efistub_entry - _head // AddressOfEntryPoint
128-
.long __efistub_stext_offset // BaseOfCode
126+
.long efi_header_end - _head // BaseOfCode
129127

130128
extra_header_fields:
131129
.quad 0 // ImageBase
@@ -142,7 +140,7 @@ extra_header_fields:
142140
.long _end - _head // SizeOfImage
143141

144142
// Everything before the kernel image is considered part of the header
145-
.long __efistub_stext_offset // SizeOfHeaders
143+
.long efi_header_end - _head // SizeOfHeaders
146144
.long 0 // CheckSum
147145
.short 0xa // Subsystem (EFI application)
148146
.short 0 // DllCharacteristics
@@ -186,10 +184,10 @@ section_table:
186184
.byte 0
187185
.byte 0
188186
.byte 0 // end of 0 padding of section name
189-
.long _end - stext // VirtualSize
190-
.long __efistub_stext_offset // VirtualAddress
191-
.long _edata - stext // SizeOfRawData
192-
.long __efistub_stext_offset // PointerToRawData
187+
.long _end - efi_header_end // VirtualSize
188+
.long efi_header_end - _head // VirtualAddress
189+
.long _edata - efi_header_end // SizeOfRawData
190+
.long efi_header_end - _head // PointerToRawData
193191

194192
.long 0 // PointerToRelocations (0 for executables)
195193
.long 0 // PointerToLineNumbers (0 for executables)
@@ -198,15 +196,18 @@ section_table:
198196
.long 0xe0500020 // Characteristics (section flags)
199197

200198
/*
201-
* EFI will load stext onwards at the 4k section alignment
199+
* EFI will load .text onwards at the 4k section alignment
202200
* described in the PE/COFF header. To ensure that instruction
203201
* sequences using an adrp and a :lo12: immediate will function
204-
* correctly at this alignment, we must ensure that stext is
202+
* correctly at this alignment, we must ensure that .text is
205203
* placed at a 4k boundary in the Image to begin with.
206204
*/
207205
.align 12
206+
efi_header_end:
208207
#endif
209208

209+
__INIT
210+
210211
ENTRY(stext)
211212
bl preserve_boot_args
212213
bl el2_setup // Drop to EL1, w20=cpu_boot_mode
@@ -221,12 +222,12 @@ ENTRY(stext)
221222
* the TCR will have been set.
222223
*/
223224
ldr x27, 0f // address to jump to after
224-
// MMU has been enabled
225+
neg x27, x27 // MMU has been enabled
225226
adr_l lr, __enable_mmu // return (PIC) address
226227
b __cpu_setup // initialise processor
227228
ENDPROC(stext)
228229
.align 3
229-
0: .quad __mmap_switched - (_head - TEXT_OFFSET) + KIMAGE_VADDR
230+
0: .quad (_text - TEXT_OFFSET) - __mmap_switched - KIMAGE_VADDR
230231

231232
/*
232233
* Preserve the arguments passed by the bootloader in x0 .. x3
@@ -395,7 +396,7 @@ __create_page_tables:
395396
ldr x5, =KIMAGE_VADDR
396397
add x5, x5, x23 // add KASLR displacement
397398
create_pgd_entry x0, x5, x3, x6
398-
ldr w6, kernel_img_size
399+
ldr w6, =kernel_img_size
399400
add x6, x6, x5
400401
mov x3, x24 // phys offset
401402
create_block_map x0, x7, x3, x5, x6
@@ -412,9 +413,6 @@ __create_page_tables:
412413

413414
ret x28
414415
ENDPROC(__create_page_tables)
415-
416-
kernel_img_size:
417-
.long _end - (_head - TEXT_OFFSET)
418416
.ltorg
419417

420418
/*

arch/arm64/kernel/image.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@
7171
DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET); \
7272
DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
7373

74+
kernel_img_size = _end - (_text - TEXT_OFFSET);
75+
7476
#ifdef CONFIG_EFI
7577

78+
__efistub_stext_offset = stext - _text;
79+
7680
/*
7781
* Prevent the symbol aliases below from being emitted into the kallsyms
7882
* table, by forcing them to be absolute symbols (which are conveniently

0 commit comments

Comments
 (0)