Skip to content

Commit

Permalink
Improves exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Oct 21, 2024
1 parent 843dfdd commit 0b875fa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

PROJECTS:=projects/hello \
projects/trapped \
projects/ping-pong \
projects/demonstrator
projects/ping-pong

all: ${PROJECTS}

Expand Down
3 changes: 2 additions & 1 deletion kernel/inc/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion kernel/src/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions kernel/src/trap.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions kernel/src/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 0b875fa

Please sign in to comment.