Revert "riscv/swint: Give the full tcb to the context switch routine"

This reverts commit 040eb3c990.
This commit is contained in:
Masayuki Ishikawa 2023-06-19 22:47:29 +09:00
parent 2c6ad5c2bf
commit c5641b0252
5 changed files with 19 additions and 39 deletions

View File

@ -139,7 +139,7 @@ void up_exit(int status)
/* Then switch contexts */ /* Then switch contexts */
riscv_fullcontextrestore(tcb); riscv_fullcontextrestore(tcb->xcp.regs);
/* riscv_fullcontextrestore() should not return but could if the software /* riscv_fullcontextrestore() should not return but could if the software
* interrupts are disabled. * interrupts are disabled.

View File

@ -29,7 +29,6 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
# include <nuttx/compiler.h> # include <nuttx/compiler.h>
# include <nuttx/sched.h>
# include <sys/types.h> # include <sys/types.h>
# include <stdint.h> # include <stdint.h>
# include <syscall.h> # include <syscall.h>
@ -208,18 +207,6 @@ void riscv_fpuconfig(void);
# define riscv_fpuconfig() # define riscv_fpuconfig()
#endif #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 ********************************************************/ /* RISC-V PMP Config ********************************************************/
int riscv_config_pmp_region(uintptr_t region, uintptr_t attr, 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: /* SYS call 1:
* *
* void riscv_fullcontextrestore(struct tcb_s *next) noreturn_function; * void riscv_fullcontextrestore(uintptr_t *restoreregs) noreturn_function;
*/ */
#define riscv_fullcontextrestore(next) \ #define riscv_fullcontextrestore(restoreregs) \
sys_call1(SYS_restore_context, (uintptr_t)next) sys_call1(SYS_restore_context, (uintptr_t)restoreregs)
/* SYS call 2: /* 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) \ #define riscv_switchcontext(saveregs, restoreregs) \
sys_call2(SYS_switch_context, (uintptr_t)prev, (uintptr_t)next) sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
#ifdef CONFIG_BUILD_KERNEL #ifdef CONFIG_BUILD_KERNEL
/* SYS call 3: /* SYS call 3:

View File

@ -155,7 +155,5 @@ retry:
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
rtcb->irqcount--; rtcb->irqcount--;
#endif #endif
riscv_fullcontextrestore(regs);
rtcb->xcp.regs = regs;
riscv_fullcontextrestore(rtcb);
} }

View File

@ -135,12 +135,12 @@ int riscv_swint(int irq, void *context, void *arg)
/* A0=SYS_restore_context: This a restore context command: /* A0=SYS_restore_context: This a restore context command:
* *
* void * 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: * At this point, the following values are saved in context:
* *
* A0 = SYS_restore_context * A0 = SYS_restore_context
* A1 = next * A1 = restoreregs
* *
* In this case, we simply need to set CURRENT_REGS to restore register * In this case, we simply need to set CURRENT_REGS to restore register
* area referenced in the saved A1. context == CURRENT_REGS is the * 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: case SYS_restore_context:
{ {
struct tcb_s *next = (struct tcb_s *)regs[REG_A1];
DEBUGASSERT(regs[REG_A1] != 0); DEBUGASSERT(regs[REG_A1] != 0);
CURRENT_REGS = (uintptr_t *)next->xcp.regs; CURRENT_REGS = (uintptr_t *)regs[REG_A1];
} }
break; break;
/* A0=SYS_switch_context: This a switch context command: /* A0=SYS_switch_context: This a switch context command:
* *
* void * 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: * At this point, the following values are saved in context:
* *
* A0 = SYS_switch_context * A0 = SYS_switch_context
* A1 = prev * A1 = saveregs
* A2 = next * A2 = restoreregs
* *
* In this case, we save the context registers to the save register * In this case, we save the context registers to the save register
* area referenced by the saved contents of R5 and then set * 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: 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); DEBUGASSERT(regs[REG_A1] != 0 && regs[REG_A2] != 0);
prev->xcp.regs = (uintptr_t *)CURRENT_REGS; *(uintptr_t **)regs[REG_A1] = (uintptr_t *)regs;
CURRENT_REGS = (uintptr_t *)next->xcp.regs; CURRENT_REGS = (uintptr_t *)regs[REG_A2];
} }
break; break;

View File

@ -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. * Just copy the CURRENT_REGS into the OLD rtcb.
*/ */
riscv_savecontext(rtcb); riscv_savestate(rtcb->xcp.regs);
/* Update scheduler parameters */ /* 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. * 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 */ /* 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 */ /* 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 /* riscv_switchcontext forces a context switch to the task at the
* head of the ready-to-run list. It does not 'return' in the * head of the ready-to-run list. It does not 'return' in the