mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
arch: use up_current_regs/up_set_current_regs replace CURRENT_REGS
reason:
1 On different architectures, we can utilize more optimized strategies
to implement up_current_regs/up_set_current_regs.
eg. use interrupt registersor percpu registers.
code size
before
text data bss dec hex filename
262848 49985 63893 376726 5bf96 nuttx
after
text data bss dec hex filename
262844 49985 63893 376722 5bf92 nuttx
size change -4
Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
-mon chardev=con,mode=readline -kernel ./nuttx
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -52,7 +52,7 @@ uintptr_t up_getusrsp(FAR void *regs)
|
||||
|
||||
void up_dump_register(FAR void *dumpregs)
|
||||
{
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : g_current_regs;
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : up_current_regs();
|
||||
|
||||
#ifdef CONFIG_EZ80_Z80MODE
|
||||
_alert("AF: %04x I: %04x\n",
|
||||
|
||||
+26
-10
@@ -43,14 +43,14 @@
|
||||
|
||||
/* Initialize the IRQ state */
|
||||
|
||||
#define INIT_IRQCONTEXT() g_current_regs = NULL
|
||||
#define INIT_IRQCONTEXT() up_set_current_regs(NULL)
|
||||
|
||||
/* IN_INTERRUPT returns true if the system is currently operating in the
|
||||
* interrupt context. IN_INTERRUPT is the inline equivalent
|
||||
* of up_interrupt_context().
|
||||
*/
|
||||
|
||||
#define IN_INTERRUPT() (g_current_regs != NULL)
|
||||
#define IN_INTERRUPT() (up_current_regs() != NULL)
|
||||
|
||||
/* The following macro is used when the system enters interrupt
|
||||
* handling logic
|
||||
@@ -67,30 +67,32 @@
|
||||
FAR chipreg_t *savestate
|
||||
|
||||
#define IRQ_ENTER(irq, regs) \
|
||||
do { \
|
||||
savestate = (FAR chipreg_t *)g_current_regs; \
|
||||
g_current_regs = (regs); \
|
||||
} while (0)
|
||||
do \
|
||||
{ \
|
||||
savestate = up_current_regs(); \
|
||||
up_set_current_regs(regs); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* The following macro is used when the system exits interrupt
|
||||
* handling logic
|
||||
*/
|
||||
|
||||
#define IRQ_LEAVE(irq) g_current_regs = savestate
|
||||
#define IRQ_LEAVE(irq) up_set_current_regs(savestate)
|
||||
|
||||
/* The following macro is used to sample the interrupt state
|
||||
* (as a opaque handle)
|
||||
*/
|
||||
|
||||
#define IRQ_STATE() (g_current_regs)
|
||||
#define IRQ_STATE() up_current_regs()
|
||||
|
||||
/* Save the current IRQ context in the specified TCB */
|
||||
|
||||
#define SAVE_IRQCONTEXT(tcb) ez80_copystate((tcb)->xcp.regs, (FAR chipreg_t*)g_current_regs)
|
||||
#define SAVE_IRQCONTEXT(tcb) ez80_copystate((tcb)->xcp.regs, up_current_regs())
|
||||
|
||||
/* Set the current IRQ context to the state specified in the TCB */
|
||||
|
||||
#define SET_IRQCONTEXT(tcb) ez80_copystate((FAR chipreg_t*)g_current_regs, (tcb)->xcp.regs)
|
||||
#define SET_IRQCONTEXT(tcb) ez80_copystate(up_current_regs(), (tcb)->xcp.regs)
|
||||
|
||||
/* Save the user context in the specified TCB.
|
||||
* User context saves can be simpler because only those registers normally
|
||||
@@ -143,6 +145,20 @@ int up_saveusercontext(FAR chipreg_t *regs);
|
||||
|
||||
void ez80_restorecontext(FAR chipreg_t *regs);
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function chipreg_t *up_current_regs(void)
|
||||
{
|
||||
return (FAR chipreg_t *)g_current_regs;
|
||||
}
|
||||
|
||||
static inline_function void up_set_current_regs(FAR chipreg_t *regs)
|
||||
{
|
||||
g_current_regs = regs;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+25
-11
@@ -46,7 +46,7 @@
|
||||
/* Initialize the IRQ state */
|
||||
|
||||
#define INIT_IRQCONTEXT() \
|
||||
g_current_regs = NULL
|
||||
up_set_current_regs(NULL)
|
||||
|
||||
/* IN_INTERRUPT returns true if the system is currently operating
|
||||
* in the interrupt context. IN_INTERRUPT is the inline equivalent
|
||||
@@ -54,7 +54,7 @@
|
||||
*/
|
||||
|
||||
#define IN_INTERRUPT() \
|
||||
(g_current_regs != NULL)
|
||||
(up_current_regs() != NULL)
|
||||
|
||||
/* The following macro declares the variables need by IRQ_ENTER
|
||||
* and IRQ_LEAVE. These variables are used to support nested interrupts.
|
||||
@@ -83,10 +83,10 @@
|
||||
#define IRQ_ENTER(irq, regs) \
|
||||
do \
|
||||
{ \
|
||||
savestate = (FAR chipreg_t *)g_current_regs; \
|
||||
savecbr = current_cbr; \
|
||||
g_current_regs = (regs); \
|
||||
current_cbr = inp(Z180_MMU_CBR); \
|
||||
savestate = up_current_regs(); \
|
||||
savecbr = current_cbr; \
|
||||
up_set_current_regs(regs) \
|
||||
current_cbr = inp(Z180_MMU_CBR); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -100,8 +100,8 @@
|
||||
#define IRQ_LEAVE(irq) \
|
||||
do \
|
||||
{ \
|
||||
g_current_regs = savestate; \
|
||||
if (g_current_regs) \
|
||||
up_set_current_regs(savestate); \
|
||||
if (up_current_regs()) \
|
||||
{ \
|
||||
current_cbr = savecbr; \
|
||||
} \
|
||||
@@ -117,12 +117,12 @@
|
||||
*/
|
||||
|
||||
#define IRQ_STATE() \
|
||||
(g_current_regs)
|
||||
up_current_regs()
|
||||
|
||||
/* Save the current IRQ context in the specified TCB */
|
||||
|
||||
#define SAVE_IRQCONTEXT(tcb) \
|
||||
z180_copystate((tcb)->xcp.regs, (FAR chipreg_t*)g_current_regs)
|
||||
z180_copystate((tcb)->xcp.regs, up_current_regs())
|
||||
|
||||
/* Set the current IRQ context to the state specified in the TCB */
|
||||
|
||||
@@ -133,7 +133,7 @@
|
||||
{ \
|
||||
current_cbr = (tcb)->xcp.cbr->cbr; \
|
||||
} \
|
||||
z180_copystate((FAR chipreg_t*)g_current_regs, (tcb)->xcp.regs); \
|
||||
z180_copystate(up_current_regs(), (tcb)->xcp.regs); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -211,6 +211,20 @@ void z180_restoreusercontext(FAR chipreg_t *regs);
|
||||
void z180_sigsetup(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver,
|
||||
FAR chipreg_t *regs);
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function chipreg_t *up_current_regs(void)
|
||||
{
|
||||
return (FAR chipreg_t *)g_current_regs;
|
||||
}
|
||||
|
||||
static inline_function void up_set_current_regs(FAR chipreg_t *regs)
|
||||
{
|
||||
g_current_regs = regs;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,7 @@ uintptr_t up_getusrsp(FAR void *regs)
|
||||
|
||||
void up_dump_register(FAR void *dumpregs)
|
||||
{
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : g_current_regs;
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : up_current_regs();
|
||||
|
||||
_alert("AF: %04x I: %04x\n",
|
||||
regs[XCPT_AF], regs[XCPT_I]);
|
||||
|
||||
+26
-10
@@ -42,14 +42,14 @@
|
||||
|
||||
/* Initialize the IRQ state */
|
||||
|
||||
#define INIT_IRQCONTEXT() g_current_regs = NULL
|
||||
#define INIT_IRQCONTEXT() up_set_current_regs(NULL)
|
||||
|
||||
/* IN_INTERRUPT returns true if the system is currently operating in the
|
||||
* interrupt context.
|
||||
* IN_INTERRUPT is the inline equivalent of up_interrupt_context().
|
||||
*/
|
||||
|
||||
#define IN_INTERRUPT() (g_current_regs != NULL)
|
||||
#define IN_INTERRUPT() (up_current_regs() != NULL)
|
||||
|
||||
/* The following macro is used when the system enters interrupt
|
||||
* handling logic
|
||||
@@ -66,30 +66,32 @@
|
||||
FAR chipreg_t *savestate
|
||||
|
||||
#define IRQ_ENTER(irq, regs) \
|
||||
do { \
|
||||
savestate = (FAR chipreg_t *)g_current_regs; \
|
||||
g_current_regs = (regs); \
|
||||
} while (0)
|
||||
do \
|
||||
{ \
|
||||
savestate = up_current_regs(); \
|
||||
up_set_current_regs(regs); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* The following macro is used when the system exits
|
||||
* interrupt handling logic
|
||||
*/
|
||||
|
||||
#define IRQ_LEAVE(irq) g_current_regs = savestate
|
||||
#define IRQ_LEAVE(irq) up_set_current_regs(savestate)
|
||||
|
||||
/* The following macro is used to sample the interrupt state
|
||||
* (as a opaque handle)
|
||||
*/
|
||||
|
||||
#define IRQ_STATE() (g_current_regs)
|
||||
#define IRQ_STATE() up_current_regs()
|
||||
|
||||
/* Save the current IRQ context in the specified TCB */
|
||||
|
||||
#define SAVE_IRQCONTEXT(tcb) z80_copystate((tcb)->xcp.regs, (FAR chipreg_t*)g_current_regs)
|
||||
#define SAVE_IRQCONTEXT(tcb) z80_copystate((tcb)->xcp.regs, up_current_regs())
|
||||
|
||||
/* Set the current IRQ context to the state specified in the TCB */
|
||||
|
||||
#define SET_IRQCONTEXT(tcb) z80_copystate((FAR chipreg_t*)g_current_regs, (tcb)->xcp.regs)
|
||||
#define SET_IRQCONTEXT(tcb) z80_copystate(up_current_regs(), (tcb)->xcp.regs)
|
||||
|
||||
/* Save the user context in the specified TCB. User context saves
|
||||
* can be simpler because only those registers normally saved in a C called
|
||||
@@ -142,6 +144,20 @@ int up_saveusercontext(FAR chipreg_t *regs);
|
||||
|
||||
void z80_restoreusercontext(FAR chipreg_t *regs);
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
static inline_function chipreg_t *up_current_regs(void)
|
||||
{
|
||||
return (FAR chipreg_t *)g_current_regs;
|
||||
}
|
||||
|
||||
static inline_function void up_set_current_regs(FAR chipreg_t *regs)
|
||||
{
|
||||
g_current_regs = regs;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,7 @@ uintptr_t up_getusrsp(FAR void *regs)
|
||||
|
||||
void up_dump_register(FAR void *dumpregs)
|
||||
{
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : g_current_regs;
|
||||
FAR volatile chipreg_t *regs = dumpregs ? dumpregs : up_current_regs();
|
||||
|
||||
_alert("AF: %04x I: %04x\n",
|
||||
regs[XCPT_AF], regs[XCPT_I]);
|
||||
|
||||
Reference in New Issue
Block a user