mips/msim/fault.c

57 lines
1.1 KiB
C
Raw Permalink Normal View History

2024-09-30 22:52:25 +00:00
#include "fault.h"
#include "sim.h"
#include <signal.h>
#include <time.h>
static struct simulator *sim;
static void sigsegv_handler(int sig, siginfo_t *info, void *ucontext)
{
(void) sig;
(void) ucontext;
const char *inner = "";
switch (info->si_code) {
case SEGV_MAPERR:
inner = ": address not mapped to object";
break;
case SEGV_ACCERR:
inner = ": invalid premissions for mapped object";
break;
case SEGV_BNDERR:
inner = ": failed address bound checks";
break;
case SEGV_PKUERR:
inner = ": access was denied by memory protection";
break;
}
sim_dump(sim, "page fault at %p%s", info->si_addr, inner);
}
static void sigfpe_handler(int sig, siginfo_t *info, void *ucontext)
{
(void) sig;
(void) info;
(void) ucontext;
sim_dump(sim, "floating point exception");
}
void init_handlers(struct simulator *s)
{
struct sigaction act = {0};
sim = s;
/* sigsegv */
act.sa_sigaction = sigsegv_handler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &act, NULL);
/* sigfpe */
act.sa_sigaction = sigfpe_handler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGFPE, &act, NULL);
}