From 14c2dd95a6a4ef9f68741def34d3bef139498fba Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Mon, 30 Aug 2021 20:11:07 +0200 Subject: [PATCH] ecall module now kills processes which trigger an exception --- kinclude/ecall.c | 11 ++++++++--- kinclude/sched.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kinclude/ecall.c b/kinclude/ecall.c index e54d478..02abaa2 100644 --- a/kinclude/ecall.c +++ b/kinclude/ecall.c @@ -202,7 +202,12 @@ void init_ecall_table() void handle_exception(int ecode, int mtval) { - //TODO: handle exceptions well - dbgln("exception encountered!", 17); - __asm__ ("ebreak"); + // kill off offending process + ProcessControlBlock* pcb = get_current_process(); + pcb->status = PROC_DEAD; + pcb->exit_code = -99; + destroy_process(pcb); + + // run the next process + scheduler_run_next(); } diff --git a/kinclude/sched.c b/kinclude/sched.c index 5335282..f01ddbe 100644 --- a/kinclude/sched.c +++ b/kinclude/sched.c @@ -96,7 +96,7 @@ ProcessControlBlock* scheduler_select_free() pcb->waiting_for_process->status == PROC_DEAD) { // the requested process exited, so we can set the status code and pcb->regs[REG_A0] = pcb->waiting_for_process->exit_code; - pcb->regs[REG_A0+1] = 0; + pcb->regs[REG_A0 + 1] = 0; pcb->status = PROC_RDY; return pcb; }