sim: set timer irq as real timer

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-12-13 21:39:22 +08:00 committed by Masayuki Ishikawa
parent 64a54d2dfd
commit 5744c62443
7 changed files with 62 additions and 17 deletions

View File

@ -115,6 +115,7 @@ int up_cpu_index(void);
* leave_critical section(), are probably what you really want.
*/
irqstate_t up_irq_flags(void);
irqstate_t up_irq_save(void);
void up_irq_restore(irqstate_t flags);

View File

@ -37,7 +37,7 @@
#if defined(CONFIG_HOST_X86_64) && !defined(CONFIG_SIM_M32)
/* Storage order: %rbx, %rsp, %rbp, %r12, %r13, %r14, %r15, %rip */
# define XCPTCONTEXT_REGS 8
# define XCPTCONTEXT_REGS 9
# define XCPTCONTEXT_SIZE (8 * XCPTCONTEXT_REGS)
# ifdef __ASSEMBLY__
@ -50,6 +50,7 @@
# define JB_R14 (5*8)
# define JB_R15 (6*8)
# define JB_RSI (7*8)
# define JB_FLAG (8*8)
# else
@ -61,6 +62,7 @@
# define JB_R14 (5)
# define JB_R15 (6)
# define JB_RSI (7)
# define JB_FLAG (8)
# endif /* __ASSEMBLY__ */
@ -73,7 +75,7 @@
#elif defined(CONFIG_HOST_X86) || defined(CONFIG_SIM_M32)
/* Storage order: %ebx, %esi, %edi, %ebp, sp, and return PC */
# define XCPTCONTEXT_REGS 6
# define XCPTCONTEXT_REGS (8)
# define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
# ifdef __ASSEMBLY__
@ -84,6 +86,8 @@
# define JB_EBP (3*4)
# define JB_SP (4*4)
# define JB_PC (5*4)
# define JB_FLAG (6*4)
# define JB_FLAG1 (7*4)
# else
@ -93,6 +97,8 @@
# define JB_EBP (3)
# define JB_SP (4)
# define JB_PC (5)
# define JB_FLAG (6)
# define JB_FLAG1 (7)
# endif /* __ASSEMBLY__ */
@ -102,16 +108,18 @@
#elif defined(CONFIG_HOST_ARM)
# define XCPTCONTEXT_REGS 16
# define XCPTCONTEXT_REGS 18
# define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
# define JB_FP 7
# define JB_SP 8
# define JB_PC 9
# define JB_FLAG 16
# define JB_FLAG1 17
#elif defined(CONFIG_HOST_ARM64)
# define XCPTCONTEXT_REGS 32
# define XCPTCONTEXT_REGS 33
# define XCPTCONTEXT_SIZE (8 * XCPTCONTEXT_REGS)
# ifdef __ASSEMBLY__
@ -134,6 +142,7 @@
# define JB_PC (11)
# define JB_FP (12)
# define JB_SP (13)
# define JB_FLAG (32)
# endif /* __ASSEMBLY__ */

View File

@ -62,6 +62,23 @@ static void up_handle_irq(int irq, siginfo_t *info, void *context)
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_irq_flags
*
* Description:
* Get the current irq flags
*
****************************************************************************/
uint64_t up_irq_flags(void)
{
union sigset_u omask;
pthread_sigmask(SIG_SETMASK, NULL, &omask.sigset);
return omask.flags;
}
/****************************************************************************
* Name: up_irq_save
*

View File

@ -48,11 +48,8 @@ void *sim_doirq(int irq, void *context)
* CURRENT_REGS is also used to manage interrupt level context switches.
*/
#ifdef CONFIG_SMP
if (setjmp(regs) == 0)
if (sim_saveusercontext(regs) == 0)
{
#endif
CURRENT_REGS = regs;
/* Deliver the IRQ */
@ -74,12 +71,10 @@ void *sim_doirq(int irq, void *context)
CURRENT_REGS = NULL;
#ifdef CONFIG_SMP
/* Then switch contexts */
longjmp(regs, 1);
sim_fullcontextrestore(regs);
}
#endif
return regs;
}

View File

@ -31,6 +31,7 @@
#include "task/task.h"
#include "sched/sched.h"
#include "sim_internal.h"
/****************************************************************************
* Public Functions
@ -82,7 +83,7 @@ void up_exit(int status)
/* Then switch contexts */
longjmp(tcb->xcp.regs, 1);
sim_fullcontextrestore(tcb->xcp.regs);
/* The function does not return */

View File

@ -85,6 +85,29 @@
#define sim_savestate(regs) sim_copyfullstate(regs, (xcpt_reg_t *)CURRENT_REGS)
#define sim_restorestate(regs) (CURRENT_REGS = regs)
#define sim_saveusercontext(saveregs) \
({ \
irqstate_t flags = up_irq_flags(); \
uint32_t *env = (uint32_t *)saveregs + JB_FLAG; \
int ret; \
\
env[0] = flags & UINT32_MAX; \
env[1] = (flags >> 32) & UINT32_MAX; \
\
ret = setjmp(saveregs); \
ret; \
})
#define sim_fullcontextrestore(restoreregs) \
do \
{ \
xcpt_reg_t *env = restoreregs; \
uint32_t *flags = (uint32_t *)&env[JB_FLAG]; \
\
up_irq_restore(((uint64_t)flags[1] << 32) | flags[0]); \
longjmp(env, 1); \
} \
while (0)
/* File System Definitions **************************************************/
/* These definitions characterize the compressed filesystem image */

View File

@ -31,7 +31,6 @@
#include <nuttx/sched.h>
#include "clock/clock.h"
#include "sched/sched.h"
#include "sim_internal.h"
/****************************************************************************
@ -84,11 +83,11 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
}
/* Copy the exception context into the TCB of the task that was
* previously active. if setjmp returns a non-zero value, then
* this is really the previously running task restarting!
* previously active. if sim_saveusercontext returns a non-zero value,
* then this is really the previously running task restarting!
*/
else if (!setjmp(rtcb->xcp.regs))
else if (!sim_saveusercontext(rtcb->xcp.regs))
{
sinfo("New Active Task TCB=%p\n", tcb);
@ -102,7 +101,7 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
/* Then switch contexts */
longjmp(tcb->xcp.regs, 1);
sim_fullcontextrestore(tcb->xcp.regs);
}
else
{