2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains a simple exception handler. Exceptions in user
|
2005-07-14 17:12:12 +02:00
|
|
|
* processes are converted to signals. Exceptions in a kernel task cause
|
|
|
|
* a panic.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
#include <signal.h>
|
|
|
|
#include "proc.h"
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* exception *
|
|
|
|
*===========================================================================*/
|
2005-04-21 16:53:53 +02:00
|
|
|
PUBLIC void exception(vec_nr)
|
|
|
|
unsigned vec_nr;
|
|
|
|
{
|
|
|
|
/* An exception or unexpected interrupt has occurred. */
|
|
|
|
|
|
|
|
struct ex_s {
|
|
|
|
char *msg;
|
|
|
|
int signum;
|
|
|
|
int minprocessor;
|
|
|
|
};
|
|
|
|
static struct ex_s ex_data[] = {
|
2005-06-21 12:47:46 +02:00
|
|
|
{ "Divide error", SIGFPE, 86 },
|
|
|
|
{ "Debug exception", SIGTRAP, 86 },
|
|
|
|
{ "Nonmaskable interrupt", SIGBUS, 86 },
|
|
|
|
{ "Breakpoint", SIGEMT, 86 },
|
|
|
|
{ "Overflow", SIGFPE, 86 },
|
|
|
|
{ "Bounds check", SIGFPE, 186 },
|
|
|
|
{ "Invalid opcode", SIGILL, 186 },
|
|
|
|
{ "Coprocessor not available", SIGFPE, 186 },
|
|
|
|
{ "Double fault", SIGBUS, 286 },
|
|
|
|
{ "Copressor segment overrun", SIGSEGV, 286 },
|
|
|
|
{ "Invalid TSS", SIGSEGV, 286 },
|
|
|
|
{ "Segment not present", SIGSEGV, 286 },
|
|
|
|
{ "Stack exception", SIGSEGV, 286 }, /* STACK_FAULT already used */
|
|
|
|
{ "General protection", SIGSEGV, 286 },
|
|
|
|
{ "Page fault", SIGSEGV, 386 }, /* not close */
|
|
|
|
{ NIL_PTR, SIGILL, 0 }, /* probably software trap */
|
|
|
|
{ "Coprocessor error", SIGFPE, 386 },
|
2005-04-21 16:53:53 +02:00
|
|
|
};
|
|
|
|
register struct ex_s *ep;
|
|
|
|
struct proc *saved_proc;
|
|
|
|
|
|
|
|
/* Save proc_ptr, because it may be changed by debug statements. */
|
|
|
|
saved_proc = proc_ptr;
|
|
|
|
|
|
|
|
ep = &ex_data[vec_nr];
|
|
|
|
|
|
|
|
if (vec_nr == 2) { /* spurious NMI on some machines */
|
2005-07-26 14:48:34 +02:00
|
|
|
kprintf("got spurious NMI\n");
|
2005-04-21 16:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-19 17:01:47 +02:00
|
|
|
/* If an exception occurs while running a process, the k_reenter variable
|
|
|
|
* will be zero. Exceptions in interrupt handlers or system traps will make
|
|
|
|
* k_reenter larger than zero.
|
|
|
|
*/
|
2005-06-24 18:24:40 +02:00
|
|
|
if (k_reenter == 0 && ! iskernelp(saved_proc)) {
|
2006-05-11 16:49:46 +02:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
kprintf(
|
|
|
|
"exception for process %d, pc = 0x%x:0x%x, sp = 0x%x:0x%x\n",
|
|
|
|
proc_nr(saved_proc),
|
|
|
|
saved_proc->p_reg.cs, saved_proc->p_reg.pc,
|
|
|
|
saved_proc->p_reg.ss, saved_proc->p_reg.sp);
|
|
|
|
kprintf("edi = 0x%x\n", saved_proc->p_reg.di);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-26 15:17:57 +02:00
|
|
|
cause_sig(proc_nr(saved_proc), ep->signum);
|
2005-04-21 16:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exception in system code. This is not supposed to happen. */
|
2005-04-29 17:36:43 +02:00
|
|
|
if (ep->msg == NIL_PTR || machine.processor < ep->minprocessor)
|
2005-04-21 16:53:53 +02:00
|
|
|
kprintf("\nIntel-reserved exception %d\n", vec_nr);
|
|
|
|
else
|
2005-07-20 17:25:38 +02:00
|
|
|
kprintf("\n%s\n", ep->msg);
|
|
|
|
kprintf("k_reenter = %d ", k_reenter);
|
2005-07-26 14:48:34 +02:00
|
|
|
kprintf("process %d (%s), ", proc_nr(saved_proc), saved_proc->p_name);
|
|
|
|
kprintf("pc = %u:0x%x", (unsigned) saved_proc->p_reg.cs,
|
2005-07-20 17:25:38 +02:00
|
|
|
(unsigned) saved_proc->p_reg.pc);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-06-17 11:09:54 +02:00
|
|
|
panic("exception in a kernel task", NO_NUM);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|