Close interrupt during trapframe construction.

This commit is contained in:
TXuian 2024-04-28 18:34:45 +08:00
parent e5df6012af
commit 695dd91201
10 changed files with 22 additions and 8 deletions

View File

@ -51,6 +51,8 @@ Modification:
void dump_tf(struct trapframe* tf) 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("lr_svc: 0x%x\n", tf->lr_svc);
KPrintf(" spsr: 0x%x\n", tf->spsr); KPrintf(" spsr: 0x%x\n", tf->spsr);
KPrintf(" r0: 0x%x\n", tf->r0); KPrintf(" r0: 0x%x\n", tf->r0);

View File

@ -47,10 +47,13 @@ trap_return:
ldmfd r13!, {r14} ldmfd r13!, {r14}
ldmfd r13!, {r2} ldmfd r13!, {r2}
msr spsr_cxsf, 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: user_trap_swi_enter:
# save trapframe to swi stack # save trapframe to swi stack
cpsid i
stmfd sp!, {r0-r12, r14} // save context stmfd sp!, {r0-r12, r14} // save context
mrs r2, spsr // copy spsr to r2 mrs r2, spsr // copy spsr to r2
stmfd r13!, {r2} // save r2(spsr) to the stack stmfd r13!, {r2} // save r2(spsr) to the stack
@ -66,6 +69,7 @@ user_trap_swi_enter:
trap_irq_enter: trap_irq_enter:
# save it on the stack as r14 is banked # save it on the stack as r14 is banked
cpsid i
sub r14, r14, #4 // r14 (lr) contains the interrupted PC sub r14, r14, #4 // r14 (lr) contains the interrupted PC
stmfd r13!, {r0-r2, r14} // stmfd r13!, {r0-r2, r14} //
mrs r1, spsr // save spsr_irq mrs r1, spsr // save spsr_irq
@ -95,6 +99,7 @@ trap_irq_enter:
b trap_return b trap_return
trap_reset_enter: trap_reset_enter:
cpsid i
mov r14, #0 // lr: not defined on reset mov r14, #0 // lr: not defined on reset
stmfd r13!, {r0-r12, r14} stmfd r13!, {r0-r12, r14}
mrs r2, spsr // copy spsr to r2 mrs r2, spsr // copy spsr to r2
@ -108,6 +113,7 @@ trap_reset_enter:
bl _vector_jumper bl _vector_jumper
trap_dabort: trap_dabort:
cpsid i
sub r14, r14, #8 // lr: instruction causing the abort sub r14, r14, #8 // lr: instruction causing the abort
stmfd r13!, {r0-r12, r14} stmfd r13!, {r0-r12, r14}
mrs r2, spsr // copy spsr to r2 mrs r2, spsr // copy spsr to r2
@ -121,6 +127,7 @@ trap_dabort:
bl dabort_handler bl dabort_handler
trap_iabort: trap_iabort:
cpsid i
sub r14, r14, #4 // lr: instruction causing the abort sub r14, r14, #4 // lr: instruction causing the abort
stmfd r13!, {r0-r12, r14} stmfd r13!, {r0-r12, r14}
mrs r2, spsr // copy spsr to r2 mrs r2, spsr // copy spsr to r2
@ -134,6 +141,7 @@ trap_iabort:
bl iabort_handler bl iabort_handler
trap_undefined_instruction: trap_undefined_instruction:
cpsid i
stmfd r13!, {r0-r12, r14} stmfd r13!, {r0-r12, r14}
mrs r2, spsr // copy spsr to r2 mrs r2, spsr // copy spsr to r2
stmfd r13!, {r2} // save r2(spsr) to the stack stmfd r13!, {r2} // save r2(spsr) to the stack

View File

@ -34,7 +34,7 @@ Modification:
#define STACK_DEPTH 32 #define STACK_DEPTH 32
struct spinlock { // Mutex. 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) char name[28]; // The call stack (an array of program counters)
} __attribute__((aligned(32))); } __attribute__((aligned(32)));

View File

@ -56,7 +56,7 @@ Modification:
#define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) #define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT)
/* User memory layout */ /* User memory layout */
#define USER_STACK_SIZE PAGE_SIZE #define USER_STACK_SIZE MODE_STACK_SIZE
#define USER_MEM_BASE (0x00000000) #define USER_MEM_BASE (0x00000000)
#define USER_MEM_TOP DEV_VRTMEM_BASE #define USER_MEM_TOP DEV_VRTMEM_BASE
#define USER_IPC_SPACE_BASE (0x70000000) #define USER_IPC_SPACE_BASE (0x70000000)

View File

@ -56,7 +56,7 @@ Modification:
#define MAX_NR_FREE_PAGES ((PHY_USER_FREEMEM_BASE - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) #define MAX_NR_FREE_PAGES ((PHY_USER_FREEMEM_BASE - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT)
/* User memory layout */ /* User memory layout */
#define USER_STACK_SIZE PAGE_SIZE #define USER_STACK_SIZE MODE_STACK_SIZE
#define USER_MEM_BASE (0x00000000) #define USER_MEM_BASE (0x00000000)
#define USER_MEM_TOP DEV_VRTMEM_BASE #define USER_MEM_TOP DEV_VRTMEM_BASE
#define USER_IPC_SPACE_BASE (0x70000000) #define USER_IPC_SPACE_BASE (0x70000000)

View File

@ -89,7 +89,9 @@ int main()
mmap(ARM_PERIPHERAL_VIRT_BASE, ARM_PERIPHERAL_BASE, 0x2000, true); mmap(ARM_PERIPHERAL_VIRT_BASE, ARM_PERIPHERAL_BASE, 0x2000, true);
printf("%s: Sending soft interrupt\n", prog_name); 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); printf("%s: Soft interrupt send done\n", prog_name);
exit(); exit();
} }

View File

@ -159,6 +159,7 @@ void delay_session(void)
void ipc_server_loop(struct IpcNode* ipc_node) void ipc_server_loop(struct IpcNode* ipc_node)
{ {
struct Session session_list[NR_MAX_SESSION]; struct Session session_list[NR_MAX_SESSION];
memset(session_list, 0, sizeof(session_list));
for (;;) { for (;;) {
/* if connect sessions are greater than NR_MAX_SESSION, /* if connect sessions are greater than NR_MAX_SESSION,
a full round will require multiple polls. a full round will require multiple polls.

View File

@ -37,7 +37,7 @@ Modification:
#include "ipcargs.h" #include "ipcargs.h"
#include "session.h" #include "session.h"
#define NR_MAX_SESSION 16 #define NR_MAX_SESSION 32
#define IPC_MSG_MAGIC 0xABCDDCBA #define IPC_MSG_MAGIC 0xABCDDCBA
typedef struct { typedef struct {

View File

@ -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)) { 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)); 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); dabort_reason(r);
panic("data abort exception\n"); 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)) { 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)); 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); iabort_reason(r);
panic("kernel prefetch abort exception\n"); panic("kernel prefetch abort exception\n");
} }

View File

@ -114,5 +114,4 @@ bool xizi_try_enter_kernel()
void xizi_leave_kernel() void xizi_leave_kernel()
{ {
spinlock_unlock(&whole_kernel_lock); spinlock_unlock(&whole_kernel_lock);
p_intr_driver->cpu_irq_enable();
} }