arch/sim: Change up_interrupt_context to inline function like arm

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-12-17 03:58:54 +08:00 committed by Petro Karashchenko
parent b6f1be8e03
commit 1905a02ddf
3 changed files with 38 additions and 47 deletions

View File

@ -30,6 +30,7 @@
****************************************************************************/ ****************************************************************************/
#include <arch/setjmp.h> #include <arch/setjmp.h>
#include <sys/types.h>
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
# include <stdbool.h> # include <stdbool.h>
#endif #endif
@ -53,13 +54,6 @@ struct xcptcontext
void *sigdeliver; /* Actual type is sig_deliver_t */ void *sigdeliver; /* Actual type is sig_deliver_t */
jmp_buf regs; jmp_buf regs;
}; };
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef __cplusplus #ifdef __cplusplus
#define EXTERN extern "C" #define EXTERN extern "C"
@ -70,21 +64,25 @@ extern "C"
#endif #endif
/**************************************************************************** /****************************************************************************
* Inline functions * Public Data
****************************************************************************/ ****************************************************************************/
/* Return the current value of the stack pointer */ /* g_current_regs[] holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to g_current_regs[] must be through the macro
* CURRENT_REGS for portability.
*/
static inline uintptr_t up_getsp(void) /* For the case of architectures with multiple CPUs, then there must be one
{ * such value for each processor that can receive an interrupt.
#ifdef _MSC_VER */
uintptr_t regval;
__asm mov regval, esp; EXTERN volatile void *g_current_regs[CONFIG_SMP_NCPUS];
return regval; #define CURRENT_REGS (g_current_regs[up_cpu_index()])
#else
return (uintptr_t)__builtin_frame_address(0); /****************************************************************************
#endif * Public Function Prototypes
} ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_cpu_index * Name: up_cpu_index
@ -120,6 +118,23 @@ int up_cpu_index(void);
irqstate_t up_irq_save(void); irqstate_t up_irq_save(void);
void up_irq_restore(irqstate_t flags); void up_irq_restore(irqstate_t flags);
/****************************************************************************
* Inline functions
****************************************************************************/
/* Return the current value of the stack pointer */
static inline uintptr_t up_getsp(void)
{
#ifdef _MSC_VER
uintptr_t regval;
__asm mov regval, esp;
return regval;
#else
return (uintptr_t)__builtin_frame_address(0);
#endif
}
/**************************************************************************** /****************************************************************************
* Name: up_interrupt_context * Name: up_interrupt_context
* *
@ -129,7 +144,10 @@ void up_irq_restore(irqstate_t flags);
* *
****************************************************************************/ ****************************************************************************/
bool up_interrupt_context(void); static inline bool up_interrupt_context(void)
{
return CURRENT_REGS != NULL;
}
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -120,19 +120,6 @@ struct i2c_master_s;
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
/* g_current_regs[] holds a references to the current interrupt level
* register storage structure. If is non-NULL only during interrupt
* processing. Access to g_current_regs[] must be through the macro
* CURRENT_REGS for portability.
*/
/* For the case of architectures with multiple CPUs, then there must be one
* such value for each processor that can receive an interrupt.
*/
extern volatile void *g_current_regs[CONFIG_SMP_NCPUS];
#define CURRENT_REGS (g_current_regs[up_cpu_index()])
/* The command line arguments passed to simulator */ /* The command line arguments passed to simulator */
extern int g_argc; extern int g_argc;

View File

@ -33,20 +33,6 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: up_interrupt_context
*
* Description:
* Return true is we are currently executing in the interrupt handler
* context.
*
****************************************************************************/
bool up_interrupt_context(void)
{
return CURRENT_REGS != NULL;
}
/**************************************************************************** /****************************************************************************
* Name: sim_doirq * Name: sim_doirq
****************************************************************************/ ****************************************************************************/