Commit 60699ba1 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Will Deacon

arm64: head.S: use ordinary stack frame for __primary_switched()

Instead of stashing the value of the link register in x28 before setting
up the stack and calling into C code, create an ordinary PCS compatible
stack frame so that we can push the return address onto the stack.

Since exception handlers require a stack as well, assign the stack pointer
register before installing the vector table.

Note that this accounts for the difference between THREAD_START_SP and
THREAD_SIZE, given that the stack pointer is always decremented before
calling into any C code.
Reviewed-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent b929fe32
...@@ -415,13 +415,18 @@ ENDPROC(__create_page_tables) ...@@ -415,13 +415,18 @@ ENDPROC(__create_page_tables)
* *
* x0 = __PHYS_OFFSET * x0 = __PHYS_OFFSET
*/ */
.set initial_sp, init_thread_union + THREAD_START_SP
__primary_switched: __primary_switched:
mov x28, lr // preserve LR adrp x4, init_thread_union
add sp, x4, #THREAD_SIZE
msr sp_el0, x4 // Save thread_info
adr_l x8, vectors // load VBAR_EL1 with virtual adr_l x8, vectors // load VBAR_EL1 with virtual
msr vbar_el1, x8 // vector table address msr vbar_el1, x8 // vector table address
isb isb
stp xzr, x30, [sp, #-16]!
mov x29, sp
str_l x21, __fdt_pointer, x5 // Save FDT pointer str_l x21, __fdt_pointer, x5 // Save FDT pointer
ldr_l x4, kimage_vaddr // Save the offset between ldr_l x4, kimage_vaddr // Save the offset between
...@@ -436,11 +441,6 @@ __primary_switched: ...@@ -436,11 +441,6 @@ __primary_switched:
bl __pi_memset bl __pi_memset
dsb ishst // Make zero page visible to PTW dsb ishst // Make zero page visible to PTW
adr_l sp, initial_sp, x4
mov x4, sp
and x4, x4, #~(THREAD_SIZE - 1)
msr sp_el0, x4 // Save thread_info
mov x29, #0
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
bl kasan_early_init bl kasan_early_init
#endif #endif
...@@ -452,8 +452,8 @@ __primary_switched: ...@@ -452,8 +452,8 @@ __primary_switched:
bl kaslr_early_init // parse FDT for KASLR options bl kaslr_early_init // parse FDT for KASLR options
cbz x0, 0f // KASLR disabled? just proceed cbz x0, 0f // KASLR disabled? just proceed
orr x23, x23, x0 // record KASLR offset orr x23, x23, x0 // record KASLR offset
ret x28 // we must enable KASLR, return ldp x29, x30, [sp], #16 // we must enable KASLR, return
// to __primary_switch() ret // to __primary_switch()
0: 0:
#endif #endif
b start_kernel b start_kernel
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment