arch: save user context in assert common code

This is the work continue with #7875

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
zhangyuan21
2022-12-21 22:26:38 +08:00
committed by Xiang Xiao
parent cb958e5d69
commit 45394eb6dc
110 changed files with 654 additions and 1271 deletions
+4 -3
View File
@@ -95,10 +95,11 @@
#define REG_R33 (1) /* R33 */
#define REG_R34 (2) /* R34 */
#define REG_R35 (18) /* R35 */
#define REG_R36 (19) /* R36 */
#define REG_R35 (18) /* R35 */
#define REG_R36 (19) /* R36 */
#define XCPTCONTEXT_REGS (52)
#define XCPTCONTEXT_REGS (68)
#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS)
/* Alternate register names *************************************************/
/* %psr: processor status register */
+6 -1
View File
@@ -61,7 +61,12 @@
/* Context switching system calls *******************************************/
/* SYS call 0: (not used) */
/* SYS call 0:
*
* int up_saveusercontext(void *saveregs);
*/
#define SYS_save_context (0)
/* SYS call 1:
*
+6 -6
View File
@@ -20,12 +20,12 @@
# Common Sparc files (arch/sparc/src/common)
CMN_CSRCS += sparc_allocateheap.c sparc_assert.c
CMN_CSRCS += sparc_createstack.c sparc_exit.c sparc_idle.c sparc_initialize.c
CMN_CSRCS += sparc_lowputs.c sparc_mdelay.c
CMN_CSRCS += sparc_modifyreg8.c sparc_modifyreg16.c sparc_modifyreg32.c
CMN_CSRCS += sparc_nputs.c sparc_releasestack.c sparc_getintstack.c
CMN_CSRCS += sparc_stackframe.c sparc_udelay.c sparc_usestack.c
CMN_CSRCS += sparc_allocateheap.c sparc_createstack.c sparc_exit.c
CMN_CSRCS += sparc_getintstack.c sparc_idle.c sparc_initialize.c
CMN_CSRCS += sparc_lowputs.c sparc_mdelay.c sparc_modifyreg8.c
CMN_CSRCS += sparc_modifyreg16.c sparc_modifyreg32.c sparc_nputs.c
CMN_CSRCS += sparc_releasestack.c sparc_stackframe.c
CMN_CSRCS += sparc_udelay.c sparc_usestack.c
# Configuration-dependent common files
-4
View File
@@ -183,10 +183,6 @@ void sparc_copystate(uint32_t *dest, uint32_t *src);
void sparc_lowputs(const char *str);
/* Debug */
void sparc_registerdump(volatile uint32_t *regs);
/* Software interrupt 0 handler */
int sparc_swint0(int irq, void *context, void *arg);
+1 -1
View File
@@ -25,6 +25,6 @@ include common/Make.defs
CMN_ASRCS += sparc_v8_syscall.S
CMN_CSRCS += sparc_v8_copystate.c sparc_v8_doirq.c
CMN_CSRCS += sparc_v8_initialstate.c sparc_v8_irq.c
CMN_CSRCS += sparc_v8_schedulesigaction.c
CMN_CSRCS += sparc_v8_schedulesigaction.c sparc_v8_saveusercontext.c
CMN_CSRCS += sparc_v8_sigdeliver.c sparc_v8_swint1.c sparc_v8_systemreset.c
CMN_CSRCS += sparc_v8_switchcontext.c sparc_v8_registerdump.c
@@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void)
}
/****************************************************************************
* Name: sparc_registerdump
* Name: up_dump_register
****************************************************************************/
void sparc_registerdump(volatile uint32_t *regs)
void up_dump_register(void *dumpregs)
{
volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS;
/* Are user registers available from interrupt processing? */
if (regs)
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/sparc/src/common/sparc_assert.c
* arch/sparc/src/sparc_v8/sparc_v8_saveusercontext.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -24,17 +24,27 @@
#include <nuttx/config.h>
#include "sparc_internal.h"
#include <arch/syscall.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_assert
* Name: up_saveusercontext
*
* Description:
* Save the current thread context. Full prototype is:
*
* int up_saveusercontext(void *saveregs);
*
* Returned Value:
* 0: Normal return
* 1: Context switch return
*
****************************************************************************/
void up_assert(void)
int up_saveusercontext(void *saveregs)
{
sparc_registerdump(CURRENT_REGS);
return sys_call1(SYS_save_context, (uintptr_t)saveregs);
}
+22 -2
View File
@@ -82,13 +82,33 @@ int sparc_swint1(int irq, void *context, void *arg)
#ifdef CONFIG_DEBUG_SYSCALL_INFO
svcinfo("Entry: regs: %p cmd: %d\n", regs, regs[REG_I0]);
up_registerdump(regs);
up_dump_register(regs);
#endif
/* Handle the SWInt according to the command in $4 */
switch (regs[REG_I0])
{
/* A0=SYS_save_context: This is a save context command:
*
* int up_saveusercontext(void *saveregs);
*
* At this point, the following values are saved in context:
*
* A0 = SYS_save_context
* A1 = saveregs
*
* In this case, we simply need to copy the current registers to the
* save register space references in the saved R1 and return.
*/
case SYS_save_context:
{
DEBUGASSERT(regs[REG_I1] != 0);
trap_flush_task((uint32_t *)regs[REG_I1], regs);
}
break;
/* A0=SYS_restore_context: This a restore context command:
*
* void sparc_fullcontextrestore
@@ -217,7 +237,7 @@ int sparc_swint1(int irq, void *context, void *arg)
if (regs != CURRENT_REGS)
{
svcinfo("SWInt Return: Context switch!\n");
up_registerdump(CURRENT_REGS);
up_dump_register(CURRENT_REGS);
}
else
{