This is an automated email from the ASF dual-hosted git repository. masayuki pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c5641b0252941af433e95f1c738d6dbc59dd8b74 Author: Masayuki Ishikawa <[email protected]> AuthorDate: Mon Jun 19 22:47:29 2023 +0900 Revert "riscv/swint: Give the full tcb to the context switch routine" This reverts commit 040eb3c990adad935409cddd077976d7742ca043. --- arch/risc-v/src/common/riscv_exit.c | 2 +- arch/risc-v/src/common/riscv_internal.h | 25 ++++++------------------- arch/risc-v/src/common/riscv_sigdeliver.c | 4 +--- arch/risc-v/src/common/riscv_swint.c | 21 ++++++++------------- arch/risc-v/src/common/riscv_switchcontext.c | 6 +++--- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/arch/risc-v/src/common/riscv_exit.c b/arch/risc-v/src/common/riscv_exit.c index 143ffb438a..c6177f29b7 100644 --- a/arch/risc-v/src/common/riscv_exit.c +++ b/arch/risc-v/src/common/riscv_exit.c @@ -139,7 +139,7 @@ void up_exit(int status) /* Then switch contexts */ - riscv_fullcontextrestore(tcb); + riscv_fullcontextrestore(tcb->xcp.regs); /* riscv_fullcontextrestore() should not return but could if the software * interrupts are disabled. diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index 6b385818cb..f3a50d4c95 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -29,7 +29,6 @@ #ifndef __ASSEMBLY__ # include <nuttx/compiler.h> -# include <nuttx/sched.h> # include <sys/types.h> # include <stdint.h> # include <syscall.h> @@ -208,18 +207,6 @@ void riscv_fpuconfig(void); # define riscv_fpuconfig() #endif -/* Save / restore context of task */ - -static inline void riscv_savecontext(struct tcb_s *tcb) -{ - tcb->xcp.regs = (uintptr_t *)CURRENT_REGS; -} - -static inline void riscv_restorecontext(struct tcb_s *tcb) -{ - CURRENT_REGS = (uintptr_t *)tcb->xcp.regs; -} - /* RISC-V PMP Config ********************************************************/ int riscv_config_pmp_region(uintptr_t region, uintptr_t attr, @@ -317,19 +304,19 @@ void *riscv_perform_syscall(uintptr_t *regs); /* SYS call 1: * - * void riscv_fullcontextrestore(struct tcb_s *next) noreturn_function; + * void riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function; */ -#define riscv_fullcontextrestore(next) \ - sys_call1(SYS_restore_context, (uintptr_t)next) +#define riscv_fullcontextrestore(restoreregs) \ + sys_call1(SYS_restore_context, (uintptr_t)restoreregs) /* SYS call 2: * - * riscv_switchcontext(struct tcb_s *prev, struct tcb_s *next); + * void riscv_switchcontext(uintptr_t *saveregs, uintptr_t *restoreregs); */ -#define riscv_switchcontext(prev, next) \ - sys_call2(SYS_switch_context, (uintptr_t)prev, (uintptr_t)next) +#define riscv_switchcontext(saveregs, restoreregs) \ + sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs) #ifdef CONFIG_BUILD_KERNEL /* SYS call 3: diff --git a/arch/risc-v/src/common/riscv_sigdeliver.c b/arch/risc-v/src/common/riscv_sigdeliver.c index 0ff3261785..c5c61cd9ca 100644 --- a/arch/risc-v/src/common/riscv_sigdeliver.c +++ b/arch/risc-v/src/common/riscv_sigdeliver.c @@ -155,7 +155,5 @@ retry: #ifdef CONFIG_SMP rtcb->irqcount--; #endif - - rtcb->xcp.regs = regs; - riscv_fullcontextrestore(rtcb); + riscv_fullcontextrestore(regs); } diff --git a/arch/risc-v/src/common/riscv_swint.c b/arch/risc-v/src/common/riscv_swint.c index dc2c11f00e..8eae2db37c 100644 --- a/arch/risc-v/src/common/riscv_swint.c +++ b/arch/risc-v/src/common/riscv_swint.c @@ -135,12 +135,12 @@ int riscv_swint(int irq, void *context, void *arg) /* A0=SYS_restore_context: This a restore context command: * * void - * void riscv_fullcontextrestore(struct tcb_s *prev) noreturn_function; + * riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function; * * At this point, the following values are saved in context: * * A0 = SYS_restore_context - * A1 = next + * A1 = restoreregs * * In this case, we simply need to set CURRENT_REGS to restore register * area referenced in the saved A1. context == CURRENT_REGS is the @@ -150,23 +150,21 @@ int riscv_swint(int irq, void *context, void *arg) case SYS_restore_context: { - struct tcb_s *next = (struct tcb_s *)regs[REG_A1]; - DEBUGASSERT(regs[REG_A1] != 0); - CURRENT_REGS = (uintptr_t *)next->xcp.regs; + CURRENT_REGS = (uintptr_t *)regs[REG_A1]; } break; /* A0=SYS_switch_context: This a switch context command: * * void - * riscv_switchcontext(struct tcb_s *prev, struct tcb_s *next); + * riscv_switchcontext(uintptr_t *saveregs, uintptr_t *restoreregs); * * At this point, the following values are saved in context: * * A0 = SYS_switch_context - * A1 = prev - * A2 = next + * A1 = saveregs + * A2 = restoreregs * * In this case, we save the context registers to the save register * area referenced by the saved contents of R5 and then set @@ -176,12 +174,9 @@ int riscv_swint(int irq, void *context, void *arg) case SYS_switch_context: { - struct tcb_s *prev = (struct tcb_s *)regs[REG_A1]; - struct tcb_s *next = (struct tcb_s *)regs[REG_A2]; - DEBUGASSERT(regs[REG_A1] != 0 && regs[REG_A2] != 0); - prev->xcp.regs = (uintptr_t *)CURRENT_REGS; - CURRENT_REGS = (uintptr_t *)next->xcp.regs; + *(uintptr_t **)regs[REG_A1] = (uintptr_t *)regs; + CURRENT_REGS = (uintptr_t *)regs[REG_A2]; } break; diff --git a/arch/risc-v/src/common/riscv_switchcontext.c b/arch/risc-v/src/common/riscv_switchcontext.c index d39ad24b68..30ea84a00f 100644 --- a/arch/risc-v/src/common/riscv_switchcontext.c +++ b/arch/risc-v/src/common/riscv_switchcontext.c @@ -69,7 +69,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) * Just copy the CURRENT_REGS into the OLD rtcb. */ - riscv_savecontext(rtcb); + riscv_savestate(rtcb->xcp.regs); /* Update scheduler parameters */ @@ -79,7 +79,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) * changes will be made when the interrupt returns. */ - riscv_restorecontext(tcb); + riscv_restorestate(tcb->xcp.regs); } /* No, then we will need to perform the user context switch */ @@ -92,7 +92,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) /* Then switch contexts */ - riscv_switchcontext(rtcb, tcb); + riscv_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs); /* riscv_switchcontext forces a context switch to the task at the * head of the ready-to-run list. It does not 'return' in the
