diff --git a/Makefile b/Makefile index e869980..b908f00 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ PROJECTS:=projects/hello \ projects/trapped \ - projects/ping-pong \ - projects/demonstrator + projects/ping-pong all: ${PROJECTS} diff --git a/kernel/inc/trap.h b/kernel/inc/trap.h index 3b3edb0..bcb391d 100644 --- a/kernel/inc/trap.h +++ b/kernel/inc/trap.h @@ -11,4 +11,5 @@ void trap_handle(void); void trap_entry(void) NORETURN; -void trap_exit(void) NORETURN; +void trap_resume(proc_t *proc) NORETURN; +void trap_return(proc_t *proc) NORETURN; diff --git a/kernel/src/head.S b/kernel/src/head.S index 4938b23..1f981e3 100644 --- a/kernel/src/head.S +++ b/kernel/src/head.S @@ -71,7 +71,7 @@ head_exit: la t0,trap_entry csrw mtvec,t0 csrw mscratch,0 - la ra,trap_exit + la ra,trap_resume tail sched __hang: diff --git a/kernel/src/trap.S b/kernel/src/trap.S index ce5f675..074bbf6 100644 --- a/kernel/src/trap.S +++ b/kernel/src/trap.S @@ -4,7 +4,8 @@ #include "csr.h" .globl trap_entry -.globl trap_exit +.globl trap_resume +.globl trap_return .type trap_entry, @function .type trap_exit, @function @@ -63,7 +64,7 @@ trap_entry: csrr a2,mtval call trap_handler -trap_exit: +trap_resume: ld s0,PROC_PMPADDR0(a0) ld s1,PROC_PMPADDR1(a0) ld s2,PROC_PMPADDR2(a0) @@ -72,7 +73,6 @@ trap_exit: ld s5,PROC_PMPADDR5(a0) ld s6,PROC_PMPADDR6(a0) ld s7,PROC_PMPADDR7(a0) - fence ld s8,PROC_PMPCFG0(a0) csrw pmpaddr0,s0 csrw pmpaddr1,s1 @@ -84,6 +84,7 @@ trap_exit: csrw pmpaddr7,s7 csrw pmpcfg0,s8 +trap_return: ld t0,PROC_PC(a0) ld t1,PROC_A0(a0) csrw mepc,t0 diff --git a/kernel/src/trap.c b/kernel/src/trap.c index eba4160..c4c18ef 100644 --- a/kernel/src/trap.c +++ b/kernel/src/trap.c @@ -8,14 +8,15 @@ proc_t *trap_handler(proc_t *proc, uint64_t mcause, uint64_t mtval) { if (mcause == 8) { proc_t *next = syscall_handler(proc); - if (next != proc) - proc_release(proc); + if (next == proc) + trap_return(proc); + proc_release(proc); if (next) return next; return sched(); } else if ((int64_t)mcause < 0) { return interrupt_handler(proc, mcause, mtval); } else { - return exception_handler(proc, mcause, mtval); + trap_return(exception_handler(proc, mcause, mtval)); } }