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
|
|
|
*/
|
|
|
|
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#include "../../kernel.h"
|
2007-04-23 15:19:25 +02:00
|
|
|
#include "proto.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <signal.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <minix/sysutil.h>
|
Split of architecture-dependent and -independent functions for i386,
mainly in the kernel and headers. This split based on work by
Ingmar Alting <iaalting@cs.vu.nl> done for his Minix PowerPC architecture
port.
. kernel does not program the interrupt controller directly, do any
other architecture-dependent operations, or contain assembly any more,
but uses architecture-dependent functions in arch/$(ARCH)/.
. architecture-dependent constants and types defined in arch/$(ARCH)/include.
. <ibm/portio.h> moved to <minix/portio.h>, as they have become, for now,
architecture-independent functions.
. int86, sdevio, readbios, and iopenable are now i386-specific kernel calls
and live in arch/i386/do_* now.
. i386 arch now supports even less 86 code; e.g. mpx86.s and klib86.s have
gone, and 'machine.protected' is gone (and always taken to be 1 in i386).
If 86 support is to return, it should be a new architecture.
. prototypes for the architecture-dependent functions defined in
kernel/arch/$(ARCH)/*.c but used in kernel/ are in kernel/proto.h
. /etc/make.conf included in makefiles and shell scripts that need to
know the building architecture; it defines ARCH=<arch>, currently only
i386.
. some basic per-architecture build support outside of the kernel (lib)
. in clock.c, only dequeue a process if it was ready
. fixes for new include files
files deleted:
. mpx/klib.s - only for choosing between mpx/klib86 and -386
. klib86.s - only for 86
i386-specific files files moved (or arch-dependent stuff moved) to arch/i386/:
. mpx386.s (entry point)
. klib386.s
. sconst.h
. exception.c
. protect.c
. protect.h
. i8269.c
2006-12-22 16:22:27 +01:00
|
|
|
#include "../../proc.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
extern int vm_copy_in_progress;
|
|
|
|
extern struct proc *vm_copy_from, *vm_copy_to;
|
|
|
|
extern u32_t vm_copy_from_v, vm_copy_to_v;
|
|
|
|
extern u32_t vm_copy_from_p, vm_copy_to_p, vm_copy_cr3;
|
|
|
|
|
|
|
|
u32_t pagefault_cr2, pagefault_count = 0;
|
|
|
|
|
|
|
|
void pagefault(struct proc *pr, int trap_errno)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
vir_bytes ph;
|
|
|
|
u32_t pte;
|
|
|
|
|
|
|
|
if(pagefault_count != 1)
|
|
|
|
minix_panic("recursive pagefault", pagefault_count);
|
|
|
|
|
|
|
|
/* Don't schedule this process until pagefault is handled. */
|
|
|
|
if(RTS_ISSET(pr, PAGEFAULT))
|
|
|
|
minix_panic("PAGEFAULT set", pr->p_endpoint);
|
|
|
|
RTS_LOCK_SET(pr, PAGEFAULT);
|
|
|
|
|
2008-12-11 15:16:40 +01:00
|
|
|
if(pr->p_endpoint <= INIT_PROC_NR && !(pr->p_misc_flags & MF_FULLVM)) {
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Page fault we can't / don't want to
|
|
|
|
* handle.
|
|
|
|
*/
|
2009-05-12 13:35:01 +02:00
|
|
|
kprintf("pagefault for process %d ('%s'), pc = 0x%x, addr = 0x%x, flags = 0x%x\n",
|
|
|
|
pr->p_endpoint, pr->p_name, pr->p_reg.pc,
|
|
|
|
pagefault_cr2, trap_errno);
|
2008-11-19 13:26:10 +01:00
|
|
|
proc_stacktrace(pr);
|
|
|
|
minix_panic("page fault in system process", pr->p_endpoint);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save pagefault details, suspend process,
|
|
|
|
* add process to pagefault chain,
|
|
|
|
* and tell VM there is a pagefault to be
|
|
|
|
* handled.
|
|
|
|
*/
|
|
|
|
pr->p_pagefault.pf_virtual = pagefault_cr2;
|
|
|
|
pr->p_pagefault.pf_flags = trap_errno;
|
|
|
|
pr->p_nextpagefault = pagefaults;
|
|
|
|
pagefaults = pr;
|
|
|
|
lock_notify(HARDWARE, VM_PROC_NR);
|
|
|
|
|
|
|
|
pagefault_count = 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
kprintf("pagefault for process %d ('%s'), pc = 0x%x\n",
|
|
|
|
pr->p_endpoint, pr->p_name, pr->p_reg.pc);
|
|
|
|
proc_stacktrace(pr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-11 18:44:06 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* exception *
|
|
|
|
*===========================================================================*/
|
2007-04-23 15:19:25 +02:00
|
|
|
PUBLIC void exception(vec_nr, trap_errno, old_eip, old_cs, old_eflags)
|
|
|
|
unsigned vec_nr;
|
|
|
|
u32_t trap_errno;
|
|
|
|
u32_t old_eip;
|
|
|
|
U16_t old_cs;
|
|
|
|
u32_t old_eflags;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* An exception or unexpected interrupt has occurred. */
|
|
|
|
|
2009-05-12 13:35:01 +02:00
|
|
|
struct proc *t;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
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;
|
|
|
|
|
2009-05-12 13:35:01 +02:00
|
|
|
#if DEBUG_SCHED_CHECK
|
|
|
|
for (t = BEG_PROC_ADDR; t < END_PROC_ADDR; ++t) {
|
|
|
|
if(t->p_magic != PMAGIC)
|
|
|
|
kprintf("entry %d broken\n", t->p_nr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2009-05-12 13:35:01 +02:00
|
|
|
if(vec_nr == PAGE_FAULT_VECTOR) {
|
|
|
|
pagefault(saved_proc, trap_errno);
|
|
|
|
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
|
|
|
{
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2006-05-11 16:49:46 +02:00
|
|
|
kprintf(
|
2008-02-22 11:43:18 +01:00
|
|
|
"exception for process %d, endpoint %d ('%s'), pc = 0x%x:0x%x, sp = 0x%x:0x%x\n",
|
|
|
|
proc_nr(saved_proc), saved_proc->p_endpoint,
|
|
|
|
saved_proc->p_name,
|
2006-05-11 16:49:46 +02:00
|
|
|
saved_proc->p_reg.cs, saved_proc->p_reg.pc,
|
|
|
|
saved_proc->p_reg.ss, saved_proc->p_reg.sp);
|
2008-02-22 11:43:18 +01:00
|
|
|
kprintf(
|
|
|
|
"vec_nr= %d, trap_errno= 0x%lx, eip= 0x%lx, cs= 0x%x, eflags= 0x%lx\n",
|
|
|
|
vec_nr, (unsigned long)trap_errno,
|
|
|
|
(unsigned long)old_eip, old_cs,
|
|
|
|
(unsigned long)old_eflags);
|
2008-11-19 13:26:10 +01:00
|
|
|
proc_stacktrace(saved_proc);
|
2006-05-11 16:49:46 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
kprintf("kernel: cause_sig %d for %d\n",
|
|
|
|
ep->signum, saved_proc->p_endpoint);
|
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);
|
2008-11-19 13:26:10 +01:00
|
|
|
kprintf("pc = %u:0x%x\n", (unsigned) saved_proc->p_reg.cs,
|
|
|
|
(unsigned) saved_proc->p_reg.pc);
|
2007-04-23 15:19:25 +02:00
|
|
|
kprintf(
|
|
|
|
"vec_nr= %d, trap_errno= 0x%lx, eip= 0x%lx, cs= 0x%x, eflags= 0x%lx\n",
|
|
|
|
vec_nr, (unsigned long)trap_errno,
|
|
|
|
(unsigned long)old_eip, old_cs, (unsigned long)old_eflags);
|
2008-11-19 13:26:10 +01:00
|
|
|
proc_stacktrace(saved_proc);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
minix_panic("exception in a kernel task", saved_proc->p_endpoint);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2006-06-29 15:35:27 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* stacktrace *
|
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void proc_stacktrace(struct proc *proc)
|
2006-06-29 15:35:27 +02:00
|
|
|
{
|
|
|
|
reg_t bp, v_bp, v_pc, v_hbp;
|
|
|
|
|
|
|
|
v_bp = proc->p_reg.fp;
|
|
|
|
|
2009-01-27 13:54:33 +01:00
|
|
|
kprintf("%8.8s %6d 0x%lx ",
|
2008-12-11 15:16:40 +01:00
|
|
|
proc->p_name, proc->p_endpoint, proc->p_reg.pc);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2006-06-29 15:35:27 +02:00
|
|
|
while(v_bp) {
|
2008-11-19 13:26:10 +01:00
|
|
|
if(data_copy(proc->p_endpoint, v_bp,
|
|
|
|
SYSTEM, (vir_bytes) &v_hbp, sizeof(v_hbp)) != OK) {
|
|
|
|
kprintf("(v_bp 0x%lx ?)", v_bp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(data_copy(proc->p_endpoint, v_bp + sizeof(v_pc),
|
|
|
|
SYSTEM, (vir_bytes) &v_pc, sizeof(v_pc)) != OK) {
|
|
|
|
kprintf("(v_pc 0x%lx ?)", v_pc);
|
2006-06-29 15:35:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
kprintf("0x%lx ", (unsigned long) v_pc);
|
|
|
|
if(v_hbp != 0 && v_hbp <= v_bp) {
|
2008-11-19 13:26:10 +01:00
|
|
|
kprintf("(hbp %lx ?)", v_hbp);
|
2006-06-29 15:35:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
v_bp = v_hbp;
|
|
|
|
}
|
|
|
|
kprintf("\n");
|
|
|
|
}
|