Commit 0eb8088b authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/64: Rearrange 64-bit _switch to prepare for 32/64 merge

More some 64-bit specifics out from the function epilogue and rearrange
this to be a bit neater, use 32-bit mem ops for CR save/restore, and
change some register numbers.

This is preparation to consolidate 32-bit and 64-bit switch code.
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230606132447.315714-3-npiggin@gmail.com
parent d6b87c3e
...@@ -190,12 +190,13 @@ _GLOBAL(_switch) ...@@ -190,12 +190,13 @@ _GLOBAL(_switch)
mflr r0 mflr r0
std r0,16(r1) std r0,16(r1)
stdu r1,-SWITCH_FRAME_SIZE(r1) stdu r1,-SWITCH_FRAME_SIZE(r1)
std r1,KSP(r3) /* Set old stack pointer */
/* r3-r13 are caller saved -- Cort */ /* r3-r13 are caller saved -- Cort */
SAVE_NVGPRS(r1) SAVE_NVGPRS(r1)
std r0,_NIP(r1) /* Return to switch caller */ std r0,_NIP(r1) /* Return to switch caller */
mfcr r23 mfcr r0
std r23,_CCR(r1) stw r0,_CCR(r1)
std r1,KSP(r3) /* Set old stack pointer */ ld r8,KSP(r4) /* Load new stack pointer */
kuap_check_amr r9, r10 kuap_check_amr r9, r10
...@@ -232,14 +233,20 @@ _GLOBAL(_switch) ...@@ -232,14 +233,20 @@ _GLOBAL(_switch)
DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r6) DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r6)
#endif #endif
addi r6,r4,-THREAD /* Convert THREAD to 'current' */ addi r3,r3,-THREAD /* old thread -> task_struct for return value */
std r6,PACACURRENT(r13) /* Set new 'current' */ addi r6,r4,-THREAD /* new thread -> task_struct */
std r6,PACACURRENT(r13) /* Set new task_struct to 'current' */
#if defined(CONFIG_STACKPROTECTOR) #if defined(CONFIG_STACKPROTECTOR)
ld r6, TASK_CANARY(r6) ld r6, TASK_CANARY(r6)
std r6, PACA_CANARY(r13) std r6, PACA_CANARY(r13)
#endif #endif
/* Set the new PACAKSAVE */
ld r8,KSP(r4) /* new stack pointer */ clrrdi r7, r8, THREAD_SHIFT /* base of new stack */
/* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
because we don't need to leave the 288-byte ABI gap at the
top of the kernel stack. */
addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
std r7,PACAKSAVE(r13)
#ifdef CONFIG_PPC_64S_HASH_MMU #ifdef CONFIG_PPC_64S_HASH_MMU
BEGIN_MMU_FTR_SECTION BEGIN_MMU_FTR_SECTION
...@@ -247,12 +254,6 @@ BEGIN_MMU_FTR_SECTION ...@@ -247,12 +254,6 @@ BEGIN_MMU_FTR_SECTION
END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
#endif #endif
clrrdi r7, r8, THREAD_SHIFT /* base of new stack */
/* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
because we don't need to leave the 288-byte ABI gap at the
top of the kernel stack. */
addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
/* /*
* PMU interrupts in radix may come in here. They will use r1, not * PMU interrupts in radix may come in here. They will use r1, not
* PACAKSAVE, so this stack switch will not cause a problem. They * PACAKSAVE, so this stack switch will not cause a problem. They
...@@ -262,18 +263,15 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) ...@@ -262,18 +263,15 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
* active on the new CPU, will order those stores. * active on the new CPU, will order those stores.
*/ */
mr r1,r8 /* start using new stack pointer */ mr r1,r8 /* start using new stack pointer */
std r7,PACAKSAVE(r13)
ld r6,_CCR(r1) lwz r0,_CCR(r1)
mtcrf 0xFF,r6 mtcrf 0xFF,r0
/* r3-r13 are destroyed -- Cort */ /* r3-r13 are destroyed -- Cort */
REST_NVGPRS(r1) REST_NVGPRS(r1)
/* convert old thread to its task_struct for return value */ ld r0,_NIP(r1) /* Return to _switch caller in new task */
addi r3,r3,-THREAD mtlr r0
ld r7,_NIP(r1) /* Return to _switch caller in new task */
mtlr r7
addi r1,r1,SWITCH_FRAME_SIZE addi r1,r1,SWITCH_FRAME_SIZE
blr blr
......
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