From 695dd912019e817688acd926c4f15338ccd0c498 Mon Sep 17 00:00:00 2001 From: TXuian <1163589503@qq.com> Date: Sun, 28 Apr 2024 18:34:45 +0800 Subject: [PATCH] Close interrupt during trapframe construction. --- .../intr/arm/armv7-a/cortex-a9/error_debug.c | 2 ++ .../hardkernel/intr/arm/armv7-a/cortex-a9/trampoline.S | 10 +++++++++- Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.h | 2 +- .../arm/armv7-a/cortex-a9/imx6q-sabrelite/memlayout.h | 2 +- .../arm/armv7-a/cortex-a9/zynq7000-zc702/memlayout.h | 2 +- .../services/boards/imx6q-sabrelite/test_irq_sender.c | 4 +++- Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c | 1 + Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h | 2 +- Ubiquitous/XiZi_AIoT/softkernel/trap/abort_handler.c | 2 ++ .../XiZi_AIoT/softkernel/trap/default_irq_handler.c | 3 +-- 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c index fc1fe18d7..af072ff91 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c @@ -51,6 +51,8 @@ Modification: void dump_tf(struct trapframe* tf) { + KPrintf("sp_usr: 0x%x\n", tf->sp_usr); + KPrintf("lr_usr: 0x%x\n", tf->lr_usr); KPrintf("lr_svc: 0x%x\n", tf->lr_svc); KPrintf(" spsr: 0x%x\n", tf->spsr); KPrintf(" r0: 0x%x\n", tf->r0); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/trampoline.S b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/trampoline.S index 6d9dcb009..3dadefdc5 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/trampoline.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/trampoline.S @@ -47,10 +47,13 @@ trap_return: ldmfd r13!, {r14} ldmfd r13!, {r2} msr spsr_cxsf, r2 - ldmfd r13!, {r0-r12, pc}^ // restore context and return + ldmfd r13!, {r0-r12} // restore context and return + cpsie i + ldmfd r13!, {pc}^ // restore context and return user_trap_swi_enter: # save trapframe to swi stack + cpsid i stmfd sp!, {r0-r12, r14} // save context mrs r2, spsr // copy spsr to r2 stmfd r13!, {r2} // save r2(spsr) to the stack @@ -66,6 +69,7 @@ user_trap_swi_enter: trap_irq_enter: # save it on the stack as r14 is banked + cpsid i sub r14, r14, #4 // r14 (lr) contains the interrupted PC stmfd r13!, {r0-r2, r14} // mrs r1, spsr // save spsr_irq @@ -95,6 +99,7 @@ trap_irq_enter: b trap_return trap_reset_enter: + cpsid i mov r14, #0 // lr: not defined on reset stmfd r13!, {r0-r12, r14} mrs r2, spsr // copy spsr to r2 @@ -108,6 +113,7 @@ trap_reset_enter: bl _vector_jumper trap_dabort: + cpsid i sub r14, r14, #8 // lr: instruction causing the abort stmfd r13!, {r0-r12, r14} mrs r2, spsr // copy spsr to r2 @@ -121,6 +127,7 @@ trap_dabort: bl dabort_handler trap_iabort: + cpsid i sub r14, r14, #4 // lr: instruction causing the abort stmfd r13!, {r0-r12, r14} mrs r2, spsr // copy spsr to r2 @@ -134,6 +141,7 @@ trap_iabort: bl iabort_handler trap_undefined_instruction: + cpsid i stmfd r13!, {r0-r12, r14} mrs r2, spsr // copy spsr to r2 stmfd r13!, {r2} // save r2(spsr) to the stack diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.h b/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.h index 660db5c19..d082cc67f 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.h @@ -34,7 +34,7 @@ Modification: #define STACK_DEPTH 32 struct spinlock { // Mutex. - uint32_t owner_cpu; // 1 for locked, 0 for unlocked + volatile uint32_t owner_cpu; // 1 for locked, 0 for unlocked char name[28]; // The call stack (an array of program counters) } __attribute__((aligned(32))); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/imx6q-sabrelite/memlayout.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/imx6q-sabrelite/memlayout.h index b6ed98e68..26957c7bb 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/imx6q-sabrelite/memlayout.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/imx6q-sabrelite/memlayout.h @@ -56,7 +56,7 @@ Modification: #define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) /* User memory layout */ -#define USER_STACK_SIZE PAGE_SIZE +#define USER_STACK_SIZE MODE_STACK_SIZE #define USER_MEM_BASE (0x00000000) #define USER_MEM_TOP DEV_VRTMEM_BASE #define USER_IPC_SPACE_BASE (0x70000000) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/zynq7000-zc702/memlayout.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/zynq7000-zc702/memlayout.h index 855d27835..cf480c399 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/zynq7000-zc702/memlayout.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv7-a/cortex-a9/zynq7000-zc702/memlayout.h @@ -56,7 +56,7 @@ Modification: #define MAX_NR_FREE_PAGES ((PHY_USER_FREEMEM_BASE - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) /* User memory layout */ -#define USER_STACK_SIZE PAGE_SIZE +#define USER_STACK_SIZE MODE_STACK_SIZE #define USER_MEM_BASE (0x00000000) #define USER_MEM_TOP DEV_VRTMEM_BASE #define USER_IPC_SPACE_BASE (0x70000000) diff --git a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/test_irq_sender.c b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/test_irq_sender.c index a43189c7a..d89dba927 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/test_irq_sender.c +++ b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/test_irq_sender.c @@ -89,7 +89,9 @@ int main() mmap(ARM_PERIPHERAL_VIRT_BASE, ARM_PERIPHERAL_BASE, 0x2000, true); printf("%s: Sending soft interrupt\n", prog_name); - gic_send_sgi(SW_INTERRUPT_3, 0xF, kGicSgiFilter_UseTargetList); + while (1) { + gic_send_sgi(SW_INTERRUPT_3, 0xF, kGicSgiFilter_UseTargetList); + } printf("%s: Soft interrupt send done\n", prog_name); exit(); } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c index 788008706..7286146c6 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c @@ -159,6 +159,7 @@ void delay_session(void) void ipc_server_loop(struct IpcNode* ipc_node) { struct Session session_list[NR_MAX_SESSION]; + memset(session_list, 0, sizeof(session_list)); for (;;) { /* if connect sessions are greater than NR_MAX_SESSION, a full round will require multiple polls. diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h index 86148a9a6..c7e399f05 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h @@ -37,7 +37,7 @@ Modification: #include "ipcargs.h" #include "session.h" -#define NR_MAX_SESSION 16 +#define NR_MAX_SESSION 32 #define IPC_MSG_MAGIC 0xABCDDCBA typedef struct { diff --git a/Ubiquitous/XiZi_AIoT/softkernel/trap/abort_handler.c b/Ubiquitous/XiZi_AIoT/softkernel/trap/abort_handler.c index 1a8d9b37a..8e13e7d86 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/trap/abort_handler.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/trap/abort_handler.c @@ -53,6 +53,7 @@ void dabort_handler(struct trapframe* r) { if (r->pc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) { assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock)); + ERROR("dabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name); dabort_reason(r); panic("data abort exception\n"); } @@ -72,6 +73,7 @@ void iabort_handler(struct trapframe* r) { if (r->pc >= DEV_VRTMEM_BASE && is_spinlock_hold_by_current_cpu(&whole_kernel_lock)) { assert(is_spinlock_hold_by_current_cpu(&whole_kernel_lock)); + ERROR("iabort in kernel, current task: %s\n", cur_cpu()->task == NULL ? "NULL" : cur_cpu()->task->name); iabort_reason(r); panic("kernel prefetch abort exception\n"); } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c b/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c index 9d2d36543..d3fceb839 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c @@ -114,5 +114,4 @@ bool xizi_try_enter_kernel() void xizi_leave_kernel() { spinlock_unlock(&whole_kernel_lock); - p_intr_driver->cpu_irq_enable(); -} \ No newline at end of file +}