xref: /minix3/minix/kernel/arch/i386/exception.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* This file contains a simple exception handler.  Exceptions in user
2*433d6423SLionel Sambuc  * processes are converted to signals. Exceptions in a kernel task cause
3*433d6423SLionel Sambuc  * a panic.
4*433d6423SLionel Sambuc  */
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc #include "kernel/kernel.h"
7*433d6423SLionel Sambuc #include "arch_proto.h"
8*433d6423SLionel Sambuc #include <signal.h>
9*433d6423SLionel Sambuc #include <string.h>
10*433d6423SLionel Sambuc #include <assert.h>
11*433d6423SLionel Sambuc #include <machine/vm.h>
12*433d6423SLionel Sambuc 
13*433d6423SLionel Sambuc struct ex_s {
14*433d6423SLionel Sambuc 	char *msg;
15*433d6423SLionel Sambuc 	int signum;
16*433d6423SLionel Sambuc 	int minprocessor;
17*433d6423SLionel Sambuc };
18*433d6423SLionel Sambuc 
19*433d6423SLionel Sambuc static struct ex_s ex_data[] = {
20*433d6423SLionel Sambuc 	{ "Divide error", SIGFPE, 86 },
21*433d6423SLionel Sambuc 	{ "Debug exception", SIGTRAP, 86 },
22*433d6423SLionel Sambuc 	{ "Nonmaskable interrupt", SIGBUS, 86 },
23*433d6423SLionel Sambuc 	{ "Breakpoint", SIGEMT, 86 },
24*433d6423SLionel Sambuc 	{ "Overflow", SIGFPE, 86 },
25*433d6423SLionel Sambuc 	{ "Bounds check", SIGFPE, 186 },
26*433d6423SLionel Sambuc 	{ "Invalid opcode", SIGILL, 186 },
27*433d6423SLionel Sambuc 	{ "Coprocessor not available", SIGFPE, 186 },
28*433d6423SLionel Sambuc 	{ "Double fault", SIGBUS, 286 },
29*433d6423SLionel Sambuc 	{ "Coprocessor segment overrun", SIGSEGV, 286 },
30*433d6423SLionel Sambuc 	{ "Invalid TSS", SIGSEGV, 286 },
31*433d6423SLionel Sambuc 	{ "Segment not present", SIGSEGV, 286 },
32*433d6423SLionel Sambuc 	{ "Stack exception", SIGSEGV, 286 },	/* STACK_FAULT already used */
33*433d6423SLionel Sambuc 	{ "General protection", SIGSEGV, 286 },
34*433d6423SLionel Sambuc 	{ "Page fault", SIGSEGV, 386 },		/* not close */
35*433d6423SLionel Sambuc 	{ NULL, SIGILL, 0 },			/* probably software trap */
36*433d6423SLionel Sambuc 	{ "Coprocessor error", SIGFPE, 386 },
37*433d6423SLionel Sambuc 	{ "Alignment check", SIGBUS, 386 },
38*433d6423SLionel Sambuc 	{ "Machine check", SIGBUS, 386 },
39*433d6423SLionel Sambuc 	{ "SIMD exception", SIGFPE, 386 },
40*433d6423SLionel Sambuc };
41*433d6423SLionel Sambuc 
42*433d6423SLionel Sambuc static void inkernel_disaster(struct proc *saved_proc,
43*433d6423SLionel Sambuc 	struct exception_frame *frame, struct ex_s *ep, int is_nested);
44*433d6423SLionel Sambuc 
45*433d6423SLionel Sambuc extern int catch_pagefaults;
46*433d6423SLionel Sambuc 
47*433d6423SLionel Sambuc static void proc_stacktrace_execute(struct proc *whichproc, reg_t v_bp, reg_t pc);
48*433d6423SLionel Sambuc 
49*433d6423SLionel Sambuc static void pagefault( struct proc *pr,
50*433d6423SLionel Sambuc 			struct exception_frame * frame,
51*433d6423SLionel Sambuc 			int is_nested)
52*433d6423SLionel Sambuc {
53*433d6423SLionel Sambuc 	int in_physcopy = 0, in_memset = 0;
54*433d6423SLionel Sambuc 
55*433d6423SLionel Sambuc 	reg_t pagefaultcr2;
56*433d6423SLionel Sambuc 	message m_pagefault;
57*433d6423SLionel Sambuc 	int err;
58*433d6423SLionel Sambuc 
59*433d6423SLionel Sambuc 	pagefaultcr2 = read_cr2();
60*433d6423SLionel Sambuc 
61*433d6423SLionel Sambuc #if 0
62*433d6423SLionel Sambuc 	printf("kernel: pagefault in pr %d, addr 0x%lx, his cr3 0x%lx, actual cr3 0x%lx\n",
63*433d6423SLionel Sambuc 		pr->p_endpoint, pagefaultcr2, pr->p_seg.p_cr3, read_cr3());
64*433d6423SLionel Sambuc #endif
65*433d6423SLionel Sambuc 
66*433d6423SLionel Sambuc 	in_physcopy = (frame->eip > (vir_bytes) phys_copy) &&
67*433d6423SLionel Sambuc 	   (frame->eip < (vir_bytes) phys_copy_fault);
68*433d6423SLionel Sambuc 
69*433d6423SLionel Sambuc 	in_memset = (frame->eip > (vir_bytes) phys_memset) &&
70*433d6423SLionel Sambuc 	   (frame->eip < (vir_bytes) memset_fault);
71*433d6423SLionel Sambuc 
72*433d6423SLionel Sambuc 	if((is_nested || iskernelp(pr)) &&
73*433d6423SLionel Sambuc 		catch_pagefaults && (in_physcopy || in_memset)) {
74*433d6423SLionel Sambuc #if 0
75*433d6423SLionel Sambuc 		printf("pf caught! addr 0x%lx\n", pagefaultcr2);
76*433d6423SLionel Sambuc #endif
77*433d6423SLionel Sambuc 		if (is_nested) {
78*433d6423SLionel Sambuc 			if(in_physcopy) {
79*433d6423SLionel Sambuc 				assert(!in_memset);
80*433d6423SLionel Sambuc 				frame->eip = (reg_t) phys_copy_fault_in_kernel;
81*433d6423SLionel Sambuc 			} else {
82*433d6423SLionel Sambuc 				frame->eip = (reg_t) memset_fault_in_kernel;
83*433d6423SLionel Sambuc 			}
84*433d6423SLionel Sambuc 		}
85*433d6423SLionel Sambuc 		else {
86*433d6423SLionel Sambuc 			pr->p_reg.pc = (reg_t) phys_copy_fault;
87*433d6423SLionel Sambuc 			pr->p_reg.retreg = pagefaultcr2;
88*433d6423SLionel Sambuc 		}
89*433d6423SLionel Sambuc 
90*433d6423SLionel Sambuc 		return;
91*433d6423SLionel Sambuc 	}
92*433d6423SLionel Sambuc 
93*433d6423SLionel Sambuc 	if(is_nested) {
94*433d6423SLionel Sambuc 		printf("pagefault in kernel at pc 0x%lx address 0x%lx\n",
95*433d6423SLionel Sambuc 			frame->eip, pagefaultcr2);
96*433d6423SLionel Sambuc 		inkernel_disaster(pr, frame, NULL, is_nested);
97*433d6423SLionel Sambuc 	}
98*433d6423SLionel Sambuc 
99*433d6423SLionel Sambuc 	/* VM can't handle page faults. */
100*433d6423SLionel Sambuc 	if(pr->p_endpoint == VM_PROC_NR) {
101*433d6423SLionel Sambuc 		/* Page fault we can't / don't want to
102*433d6423SLionel Sambuc 		 * handle.
103*433d6423SLionel Sambuc 		 */
104*433d6423SLionel Sambuc 		printf("pagefault for VM on CPU %d, "
105*433d6423SLionel Sambuc 			"pc = 0x%x, addr = 0x%x, flags = 0x%x, is_nested %d\n",
106*433d6423SLionel Sambuc 			cpuid, pr->p_reg.pc, pagefaultcr2, frame->errcode,
107*433d6423SLionel Sambuc 			is_nested);
108*433d6423SLionel Sambuc 		proc_stacktrace(pr);
109*433d6423SLionel Sambuc 		printf("pc of pagefault: 0x%lx\n", frame->eip);
110*433d6423SLionel Sambuc 		panic("pagefault in VM");
111*433d6423SLionel Sambuc 
112*433d6423SLionel Sambuc 		return;
113*433d6423SLionel Sambuc 	}
114*433d6423SLionel Sambuc 
115*433d6423SLionel Sambuc 	/* Don't schedule this process until pagefault is handled. */
116*433d6423SLionel Sambuc 	RTS_SET(pr, RTS_PAGEFAULT);
117*433d6423SLionel Sambuc 
118*433d6423SLionel Sambuc 	/* tell Vm about the pagefault */
119*433d6423SLionel Sambuc 	m_pagefault.m_source = pr->p_endpoint;
120*433d6423SLionel Sambuc 	m_pagefault.m_type   = VM_PAGEFAULT;
121*433d6423SLionel Sambuc 	m_pagefault.VPF_ADDR = pagefaultcr2;
122*433d6423SLionel Sambuc 	m_pagefault.VPF_FLAGS = frame->errcode;
123*433d6423SLionel Sambuc 
124*433d6423SLionel Sambuc 	if ((err = mini_send(pr, VM_PROC_NR,
125*433d6423SLionel Sambuc 					&m_pagefault, FROM_KERNEL))) {
126*433d6423SLionel Sambuc 		panic("WARNING: pagefault: mini_send returned %d\n", err);
127*433d6423SLionel Sambuc 	}
128*433d6423SLionel Sambuc 
129*433d6423SLionel Sambuc 	return;
130*433d6423SLionel Sambuc }
131*433d6423SLionel Sambuc 
132*433d6423SLionel Sambuc static void inkernel_disaster(struct proc *saved_proc,
133*433d6423SLionel Sambuc 	struct exception_frame * frame, struct ex_s *ep,
134*433d6423SLionel Sambuc 	int is_nested)
135*433d6423SLionel Sambuc {
136*433d6423SLionel Sambuc #if USE_SYSDEBUG
137*433d6423SLionel Sambuc   if(ep) {
138*433d6423SLionel Sambuc 	if (ep->msg == NULL)
139*433d6423SLionel Sambuc 		printf("\nIntel-reserved exception %d\n", frame->vector);
140*433d6423SLionel Sambuc 	  else
141*433d6423SLionel Sambuc 		printf("\n%s\n", ep->msg);
142*433d6423SLionel Sambuc   }
143*433d6423SLionel Sambuc 
144*433d6423SLionel Sambuc   printf("cpu %d is_nested = %d ", cpuid, is_nested);
145*433d6423SLionel Sambuc 
146*433d6423SLionel Sambuc   printf("vec_nr= %d, trap_errno= 0x%x, eip= 0x%x, "
147*433d6423SLionel Sambuc 	"cs= 0x%x, eflags= 0x%x trap_esp 0x%08x\n",
148*433d6423SLionel Sambuc 	frame->vector, frame->errcode, frame->eip,
149*433d6423SLionel Sambuc 	frame->cs, frame->eflags, frame);
150*433d6423SLionel Sambuc   printf("KERNEL registers :\n");
151*433d6423SLionel Sambuc #define REG(n) (((u32_t *)frame)[-n])
152*433d6423SLionel Sambuc   printf(
153*433d6423SLionel Sambuc 		  "\t%%eax 0x%08x %%ebx 0x%08x %%ecx 0x%08x %%edx 0x%08x\n"
154*433d6423SLionel Sambuc 		  "\t%%esp 0x%08x %%ebp 0x%08x %%esi 0x%08x %%edi 0x%08x\n",
155*433d6423SLionel Sambuc 		  REG(1), REG(2), REG(3), REG(4),
156*433d6423SLionel Sambuc 		  REG(5), REG(6), REG(7), REG(8));
157*433d6423SLionel Sambuc 
158*433d6423SLionel Sambuc   {
159*433d6423SLionel Sambuc   	reg_t k_ebp = REG(6);
160*433d6423SLionel Sambuc   	printf("KERNEL stacktrace, starting with ebp = 0x%lx:\n", k_ebp);
161*433d6423SLionel Sambuc   	proc_stacktrace_execute(proc_addr(SYSTEM), k_ebp, frame->eip);
162*433d6423SLionel Sambuc   }
163*433d6423SLionel Sambuc 
164*433d6423SLionel Sambuc   if (saved_proc) {
165*433d6423SLionel Sambuc 	  printf("scheduled was: process %d (%s), ", saved_proc->p_endpoint, saved_proc->p_name);
166*433d6423SLionel Sambuc 	  printf("pc = 0x%x\n", (unsigned) saved_proc->p_reg.pc);
167*433d6423SLionel Sambuc 	  proc_stacktrace(saved_proc);
168*433d6423SLionel Sambuc 
169*433d6423SLionel Sambuc 	  panic("Unhandled kernel exception");
170*433d6423SLionel Sambuc   }
171*433d6423SLionel Sambuc 
172*433d6423SLionel Sambuc   /* in an early stage of boot process we don't have processes yet */
173*433d6423SLionel Sambuc   panic("exception in kernel while booting, no saved_proc yet");
174*433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
175*433d6423SLionel Sambuc }
176*433d6423SLionel Sambuc 
177*433d6423SLionel Sambuc /*===========================================================================*
178*433d6423SLionel Sambuc  *				exception				     *
179*433d6423SLionel Sambuc  *===========================================================================*/
180*433d6423SLionel Sambuc void exception_handler(int is_nested, struct exception_frame * frame)
181*433d6423SLionel Sambuc {
182*433d6423SLionel Sambuc /* An exception or unexpected interrupt has occurred. */
183*433d6423SLionel Sambuc   register struct ex_s *ep;
184*433d6423SLionel Sambuc   struct proc *saved_proc;
185*433d6423SLionel Sambuc 
186*433d6423SLionel Sambuc   /* Save proc_ptr, because it may be changed by debug statements. */
187*433d6423SLionel Sambuc   saved_proc = get_cpulocal_var(proc_ptr);
188*433d6423SLionel Sambuc 
189*433d6423SLionel Sambuc   ep = &ex_data[frame->vector];
190*433d6423SLionel Sambuc 
191*433d6423SLionel Sambuc   if (frame->vector == 2) {		/* spurious NMI on some machines */
192*433d6423SLionel Sambuc 	printf("got spurious NMI\n");
193*433d6423SLionel Sambuc 	return;
194*433d6423SLionel Sambuc   }
195*433d6423SLionel Sambuc 
196*433d6423SLionel Sambuc   /*
197*433d6423SLionel Sambuc    * handle special cases for nested problems as they might be tricky or filter
198*433d6423SLionel Sambuc    * them out quickly if the traps are not nested
199*433d6423SLionel Sambuc    */
200*433d6423SLionel Sambuc   if (is_nested) {
201*433d6423SLionel Sambuc 	/*
202*433d6423SLionel Sambuc 	 * if a problem occured while copying a message from userspace because
203*433d6423SLionel Sambuc 	 * of a wrong pointer supplied by userland, handle it the only way we
204*433d6423SLionel Sambuc 	 * can handle it ...
205*433d6423SLionel Sambuc 	 */
206*433d6423SLionel Sambuc 	if (((void*)frame->eip >= (void*)copy_msg_to_user &&
207*433d6423SLionel Sambuc 			(void*)frame->eip <= (void*)__copy_msg_to_user_end) ||
208*433d6423SLionel Sambuc 			((void*)frame->eip >= (void*)copy_msg_from_user &&
209*433d6423SLionel Sambuc 			(void*)frame->eip <= (void*)__copy_msg_from_user_end)) {
210*433d6423SLionel Sambuc 		switch(frame->vector) {
211*433d6423SLionel Sambuc 		/* these error are expected */
212*433d6423SLionel Sambuc 		case PAGE_FAULT_VECTOR:
213*433d6423SLionel Sambuc 		case PROTECTION_VECTOR:
214*433d6423SLionel Sambuc 			frame->eip = (reg_t) __user_copy_msg_pointer_failure;
215*433d6423SLionel Sambuc 			return;
216*433d6423SLionel Sambuc 		default:
217*433d6423SLionel Sambuc 			panic("Copy involving a user pointer failed unexpectedly!");
218*433d6423SLionel Sambuc 		}
219*433d6423SLionel Sambuc 	}
220*433d6423SLionel Sambuc 
221*433d6423SLionel Sambuc 	/* Pass any error resulting from restoring FPU state, as a FPU
222*433d6423SLionel Sambuc 	 * exception to the process.
223*433d6423SLionel Sambuc 	 */
224*433d6423SLionel Sambuc 	if (((void*)frame->eip >= (void*)fxrstor &&
225*433d6423SLionel Sambuc 			(void *)frame->eip <= (void*)__fxrstor_end) ||
226*433d6423SLionel Sambuc 			((void*)frame->eip >= (void*)frstor &&
227*433d6423SLionel Sambuc 			(void *)frame->eip <= (void*)__frstor_end)) {
228*433d6423SLionel Sambuc 		frame->eip = (reg_t) __frstor_failure;
229*433d6423SLionel Sambuc 		return;
230*433d6423SLionel Sambuc 	}
231*433d6423SLionel Sambuc 
232*433d6423SLionel Sambuc   	if(frame->vector == DEBUG_VECTOR
233*433d6423SLionel Sambuc 		&& (saved_proc->p_reg.psw & TRACEBIT)
234*433d6423SLionel Sambuc 		&& (saved_proc->p_seg.p_kern_trap_style == KTS_NONE)) {
235*433d6423SLionel Sambuc 		/* Getting a debug trap in the kernel is legitimate
236*433d6423SLionel Sambuc 		 * if a traced process entered the kernel using sysenter
237*433d6423SLionel Sambuc 		 * or syscall; the trap flag is not cleared then.
238*433d6423SLionel Sambuc 		 *
239*433d6423SLionel Sambuc 		 * It triggers on the first kernel entry so the trap
240*433d6423SLionel Sambuc 		 * style is still KTS_NONE.
241*433d6423SLionel Sambuc 		 */
242*433d6423SLionel Sambuc 
243*433d6423SLionel Sambuc 		frame->eflags &= ~TRACEBIT;
244*433d6423SLionel Sambuc 
245*433d6423SLionel Sambuc 		return;
246*433d6423SLionel Sambuc 
247*433d6423SLionel Sambuc 		/* If control passes, this case is not recognized as legitimate
248*433d6423SLionel Sambuc 		 * and we panic later on after all.
249*433d6423SLionel Sambuc 		 */
250*433d6423SLionel Sambuc 	}
251*433d6423SLionel Sambuc   }
252*433d6423SLionel Sambuc 
253*433d6423SLionel Sambuc   if(frame->vector == PAGE_FAULT_VECTOR) {
254*433d6423SLionel Sambuc 	pagefault(saved_proc, frame, is_nested);
255*433d6423SLionel Sambuc 	return;
256*433d6423SLionel Sambuc   }
257*433d6423SLionel Sambuc 
258*433d6423SLionel Sambuc   /* If an exception occurs while running a process, the is_nested variable
259*433d6423SLionel Sambuc    * will be zero. Exceptions in interrupt handlers or system traps will make
260*433d6423SLionel Sambuc    * is_nested non-zero.
261*433d6423SLionel Sambuc    */
262*433d6423SLionel Sambuc   if (is_nested == 0 && ! iskernelp(saved_proc)) {
263*433d6423SLionel Sambuc #if 0
264*433d6423SLionel Sambuc 	{
265*433d6423SLionel Sambuc 
266*433d6423SLionel Sambuc   		printf(
267*433d6423SLionel Sambuc   "vec_nr= %d, trap_errno= 0x%lx, eip= 0x%lx, cs= 0x%x, eflags= 0x%lx\n",
268*433d6423SLionel Sambuc 			frame->vector, (unsigned long)frame->errcode,
269*433d6423SLionel Sambuc 			(unsigned long)frame->eip, frame->cs,
270*433d6423SLionel Sambuc 			(unsigned long)frame->eflags);
271*433d6423SLionel Sambuc 		proc_stacktrace(saved_proc);
272*433d6423SLionel Sambuc 	}
273*433d6423SLionel Sambuc 
274*433d6423SLionel Sambuc #endif
275*433d6423SLionel Sambuc 	cause_sig(proc_nr(saved_proc), ep->signum);
276*433d6423SLionel Sambuc 	return;
277*433d6423SLionel Sambuc   }
278*433d6423SLionel Sambuc 
279*433d6423SLionel Sambuc   /* Exception in system code. This is not supposed to happen. */
280*433d6423SLionel Sambuc   inkernel_disaster(saved_proc, frame, ep, is_nested);
281*433d6423SLionel Sambuc 
282*433d6423SLionel Sambuc   panic("return from inkernel_disaster");
283*433d6423SLionel Sambuc }
284*433d6423SLionel Sambuc 
285*433d6423SLionel Sambuc #if USE_SYSDEBUG
286*433d6423SLionel Sambuc /*===========================================================================*
287*433d6423SLionel Sambuc  *				proc_stacktrace_execute			     *
288*433d6423SLionel Sambuc  *===========================================================================*/
289*433d6423SLionel Sambuc static void proc_stacktrace_execute(struct proc *whichproc, reg_t v_bp, reg_t pc)
290*433d6423SLionel Sambuc {
291*433d6423SLionel Sambuc 	reg_t v_hbp;
292*433d6423SLionel Sambuc 	int iskernel;
293*433d6423SLionel Sambuc 	int n = 0;
294*433d6423SLionel Sambuc 
295*433d6423SLionel Sambuc 	iskernel = iskernelp(whichproc);
296*433d6423SLionel Sambuc 
297*433d6423SLionel Sambuc 	printf("%-8.8s %6d 0x%lx ",
298*433d6423SLionel Sambuc 		whichproc->p_name, whichproc->p_endpoint, pc);
299*433d6423SLionel Sambuc 
300*433d6423SLionel Sambuc 	while(v_bp) {
301*433d6423SLionel Sambuc 		reg_t v_pc;
302*433d6423SLionel Sambuc 
303*433d6423SLionel Sambuc #define PRCOPY(pr, pv, v, n) \
304*433d6423SLionel Sambuc   (iskernel ? (memcpy((char *) v, (char *) pv, n), OK) : \
305*433d6423SLionel Sambuc      data_copy(pr->p_endpoint, pv, KERNEL, (vir_bytes) (v), n))
306*433d6423SLionel Sambuc 
307*433d6423SLionel Sambuc 	        if(PRCOPY(whichproc, v_bp, &v_hbp, sizeof(v_hbp)) != OK) {
308*433d6423SLionel Sambuc 			printf("(v_bp 0x%lx ?)", v_bp);
309*433d6423SLionel Sambuc 			break;
310*433d6423SLionel Sambuc 		}
311*433d6423SLionel Sambuc 		if(PRCOPY(whichproc, v_bp + sizeof(v_pc), &v_pc, sizeof(v_pc)) != OK) {
312*433d6423SLionel Sambuc 			printf("(v_pc 0x%lx ?)", v_bp + sizeof(v_pc));
313*433d6423SLionel Sambuc 			break;
314*433d6423SLionel Sambuc 		}
315*433d6423SLionel Sambuc 		printf("0x%lx ", (unsigned long) v_pc);
316*433d6423SLionel Sambuc 		if(v_hbp != 0 && v_hbp <= v_bp) {
317*433d6423SLionel Sambuc 			printf("(hbp %lx ?)", v_hbp);
318*433d6423SLionel Sambuc 			break;
319*433d6423SLionel Sambuc 		}
320*433d6423SLionel Sambuc 		v_bp = v_hbp;
321*433d6423SLionel Sambuc 		if(n++ > 50) {
322*433d6423SLionel Sambuc 			printf("(truncated after %d steps) ", n);
323*433d6423SLionel Sambuc 			break;
324*433d6423SLionel Sambuc 		}
325*433d6423SLionel Sambuc 	}
326*433d6423SLionel Sambuc 	printf("\n");
327*433d6423SLionel Sambuc }
328*433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
329*433d6423SLionel Sambuc 
330*433d6423SLionel Sambuc /*===========================================================================*
331*433d6423SLionel Sambuc  *				proc_stacktrace			     *
332*433d6423SLionel Sambuc  *===========================================================================*/
333*433d6423SLionel Sambuc void proc_stacktrace(struct proc *whichproc)
334*433d6423SLionel Sambuc {
335*433d6423SLionel Sambuc 	u32_t use_bp;
336*433d6423SLionel Sambuc 
337*433d6423SLionel Sambuc 	if(whichproc->p_seg.p_kern_trap_style == KTS_NONE) {
338*433d6423SLionel Sambuc 		printf("WARNING: stacktrace of running proecss\n");
339*433d6423SLionel Sambuc 	}
340*433d6423SLionel Sambuc 
341*433d6423SLionel Sambuc 	switch(whichproc->p_seg.p_kern_trap_style) {
342*433d6423SLionel Sambuc 		case KTS_SYSENTER:
343*433d6423SLionel Sambuc 		case KTS_SYSCALL:
344*433d6423SLionel Sambuc 		{
345*433d6423SLionel Sambuc 			u32_t sp = whichproc->p_reg.sp;
346*433d6423SLionel Sambuc 
347*433d6423SLionel Sambuc 			/* Full context is not available in the p_reg
348*433d6423SLionel Sambuc 			 * struct. Obtain it from the user's stack.
349*433d6423SLionel Sambuc 			 * The use stack pointer is always available.
350*433d6423SLionel Sambuc 			 * The fact that it's there, and the 16 byte offset,
351*433d6423SLionel Sambuc 			 * is a dependency on the trap code in
352*433d6423SLionel Sambuc 			 * kernel/arch/i386/usermapped_glo_ipc.S.
353*433d6423SLionel Sambuc 			 */
354*433d6423SLionel Sambuc 
355*433d6423SLionel Sambuc 			if(data_copy(whichproc->p_endpoint, sp+16,
356*433d6423SLionel Sambuc 			  KERNEL, (vir_bytes) &use_bp,
357*433d6423SLionel Sambuc 				sizeof(use_bp)) != OK) {
358*433d6423SLionel Sambuc 				printf("stacktrace: aborting, copy failed\n");
359*433d6423SLionel Sambuc 				return;
360*433d6423SLionel Sambuc 			}
361*433d6423SLionel Sambuc 
362*433d6423SLionel Sambuc 			break;
363*433d6423SLionel Sambuc 		}
364*433d6423SLionel Sambuc 		default:
365*433d6423SLionel Sambuc 			/* Full context is available; use the stored ebp */
366*433d6423SLionel Sambuc 			use_bp = whichproc->p_reg.fp;
367*433d6423SLionel Sambuc 			break;
368*433d6423SLionel Sambuc 	}
369*433d6423SLionel Sambuc 
370*433d6423SLionel Sambuc #if USE_SYSDEBUG
371*433d6423SLionel Sambuc 	proc_stacktrace_execute(whichproc, use_bp, whichproc->p_reg.pc);
372*433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
373*433d6423SLionel Sambuc }
374*433d6423SLionel Sambuc 
375*433d6423SLionel Sambuc void enable_fpu_exception(void)
376*433d6423SLionel Sambuc {
377*433d6423SLionel Sambuc 	u32_t cr0 = read_cr0();
378*433d6423SLionel Sambuc 	if(!(cr0 & I386_CR0_TS))
379*433d6423SLionel Sambuc 		write_cr0(cr0 | I386_CR0_TS);
380*433d6423SLionel Sambuc }
381*433d6423SLionel Sambuc 
382*433d6423SLionel Sambuc void disable_fpu_exception(void)
383*433d6423SLionel Sambuc {
384*433d6423SLionel Sambuc 	clts();
385*433d6423SLionel Sambuc }
386*433d6423SLionel Sambuc 
387