trap: explicitly handle certain exceptions
This commit is contained in:
parent
fba82790a9
commit
4a997cec35
4 changed files with 29 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
genrw(rsp);
|
||||
genrw(rbp);
|
||||
genrw(cr2);
|
||||
genrw(cr3);
|
||||
genrw(ds);
|
||||
|
||||
|
|
|
|||
8
include/kernel/trap.h
Normal file
8
include/kernel/trap.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _TRAP_H_
|
||||
#define _TRAP_H_
|
||||
|
||||
void exception(int vector, int error);
|
||||
void exception_init();
|
||||
|
||||
#endif
|
||||
19
init/trap.c
19
init/trap.c
|
|
@ -3,6 +3,9 @@
|
|||
#include <kernel/slab.h>
|
||||
#include <kernel/proc.h>
|
||||
|
||||
/* explicit handle list */
|
||||
void (*exception_handlers[32])(int error) = { NULL };
|
||||
|
||||
static const char *exception_names[] = {
|
||||
"Divide-by-zero Error",
|
||||
"Debug",
|
||||
|
|
@ -37,6 +40,13 @@ static const char *exception_names[] = {
|
|||
"Triple Fault",
|
||||
};
|
||||
|
||||
static void exception_page_fault(int err)
|
||||
{
|
||||
uint64_t cr2 = cr2_read();
|
||||
|
||||
kprintf(LOG_ERROR "Page fault at %xh, error code %xh\n", cr2, err);
|
||||
}
|
||||
|
||||
void exception(int vector, int error)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
|
|
@ -49,8 +59,17 @@ void exception(int vector, int error)
|
|||
} else {
|
||||
proc_term(pid);
|
||||
kprintf("Process %d terminated: %s(%xh)\n", pid, exception_names[vector], error);
|
||||
|
||||
if (exception_handlers[vector])
|
||||
exception_handlers[vector](error);
|
||||
|
||||
proc_set_current(0);
|
||||
|
||||
schedule();
|
||||
}
|
||||
}
|
||||
|
||||
void exception_init()
|
||||
{
|
||||
exception_handlers[0x0E] = exception_page_fault;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ reg##_write: \
|
|||
|
||||
genrw(rsp)
|
||||
genrw(rbp)
|
||||
genrw(cr2)
|
||||
genrw(cr3)
|
||||
genrww(ds)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue