From 2fe06ac083bcc99e42b85b528347b76578f6c1f6 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 14 Dec 2021 17:34:56 +0800 Subject: [PATCH] arch: xtensa: save current SP before overwrting Signed-off-by: chao.an --- arch/xtensa/src/common/xtensa_user_handler.S | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/xtensa/src/common/xtensa_user_handler.S b/arch/xtensa/src/common/xtensa_user_handler.S index 895f3e27b1..3574f66dc5 100644 --- a/arch/xtensa/src/common/xtensa_user_handler.S +++ b/arch/xtensa/src/common/xtensa_user_handler.S @@ -225,6 +225,12 @@ _xtensa_user_handler: mov a2, sp /* Address of state save on stack */ call0 _xtensa_context_save /* Save full register state */ + /* Save current SP before (possibly) overwriting it, + * it's the register save area. + */ + + mov a12, sp + /* Switch to an interrupt stack if we have one */ #if CONFIG_ARCH_INTERRUPTSTACK > 15 @@ -271,17 +277,18 @@ _xtensa_user_handler: #ifdef __XTENSA_CALL0_ABI__ rsr a2, EXCCAUSE /* Argument 1 (a2) = EXCCAUSE */ - mov a3, sp /* Argument 2 (a3) = pointer to register save area */ + mov a3, a12 /* Argument 2 (a3) = pointer to register save area */ calx0 xtensa_user /* Call xtensa_user */ #else rsr a6, EXCCAUSE /* Argument 1 (a6) = EXCCAUSE */ - mov a7, sp /* Argument 2 (a7) = pointer to register save area */ + mov a7, a12 /* Argument 2 (a7) = pointer to register save area */ call4 xtensa_user /* Call xtensa_user */ - mov a2, a6 + mov a12, a6 #endif /* Restore registers in preparation to return from interrupt */ + mov a2, a12 /* a2 = address of new state save area */ call0 _xtensa_context_restore /* (Preserves a2) */ /* Restore only level-specific regs (the rest were already restored) */