xref: /minix3/minix/kernel/arch/i386/exception.c (revision d09f72c453f045009224111c765f7dd7d5f27dae)
1433d6423SLionel Sambuc /* This file contains a simple exception handler.  Exceptions in user
2433d6423SLionel Sambuc  * processes are converted to signals. Exceptions in a kernel task cause
3433d6423SLionel Sambuc  * a panic.
4433d6423SLionel Sambuc  */
5433d6423SLionel Sambuc 
6433d6423SLionel Sambuc #include "kernel/kernel.h"
7433d6423SLionel Sambuc #include "arch_proto.h"
8433d6423SLionel Sambuc #include <signal.h>
9433d6423SLionel Sambuc #include <string.h>
10433d6423SLionel Sambuc #include <assert.h>
11433d6423SLionel Sambuc #include <machine/vm.h>
12433d6423SLionel Sambuc 
13433d6423SLionel Sambuc struct ex_s {
14433d6423SLionel Sambuc 	char *msg;
15433d6423SLionel Sambuc 	int signum;
16433d6423SLionel Sambuc 	int minprocessor;
17433d6423SLionel Sambuc };
18433d6423SLionel Sambuc 
19433d6423SLionel Sambuc static struct ex_s ex_data[] = {
20433d6423SLionel Sambuc 	{ "Divide error", SIGFPE, 86 },
21433d6423SLionel Sambuc 	{ "Debug exception", SIGTRAP, 86 },
22433d6423SLionel Sambuc 	{ "Nonmaskable interrupt", SIGBUS, 86 },
23433d6423SLionel Sambuc 	{ "Breakpoint", SIGEMT, 86 },
24433d6423SLionel Sambuc 	{ "Overflow", SIGFPE, 86 },
25433d6423SLionel Sambuc 	{ "Bounds check", SIGFPE, 186 },
26433d6423SLionel Sambuc 	{ "Invalid opcode", SIGILL, 186 },
27433d6423SLionel Sambuc 	{ "Coprocessor not available", SIGFPE, 186 },
28433d6423SLionel Sambuc 	{ "Double fault", SIGBUS, 286 },
29433d6423SLionel Sambuc 	{ "Coprocessor segment overrun", SIGSEGV, 286 },
30433d6423SLionel Sambuc 	{ "Invalid TSS", SIGSEGV, 286 },
31433d6423SLionel Sambuc 	{ "Segment not present", SIGSEGV, 286 },
32433d6423SLionel Sambuc 	{ "Stack exception", SIGSEGV, 286 },	/* STACK_FAULT already used */
33433d6423SLionel Sambuc 	{ "General protection", SIGSEGV, 286 },
34433d6423SLionel Sambuc 	{ "Page fault", SIGSEGV, 386 },		/* not close */
35433d6423SLionel Sambuc 	{ NULL, SIGILL, 0 },			/* probably software trap */
36433d6423SLionel Sambuc 	{ "Coprocessor error", SIGFPE, 386 },
37433d6423SLionel Sambuc 	{ "Alignment check", SIGBUS, 386 },
38433d6423SLionel Sambuc 	{ "Machine check", SIGBUS, 386 },
39433d6423SLionel Sambuc 	{ "SIMD exception", SIGFPE, 386 },
40433d6423SLionel Sambuc };
41433d6423SLionel Sambuc 
42433d6423SLionel Sambuc static void inkernel_disaster(struct proc *saved_proc,
43433d6423SLionel Sambuc 	struct exception_frame *frame, struct ex_s *ep, int is_nested);
44433d6423SLionel Sambuc 
45433d6423SLionel Sambuc extern int catch_pagefaults;
46433d6423SLionel Sambuc 
47433d6423SLionel Sambuc static void proc_stacktrace_execute(struct proc *whichproc, reg_t v_bp, reg_t pc);
48433d6423SLionel Sambuc 
pagefault(struct proc * pr,struct exception_frame * frame,int is_nested)49433d6423SLionel Sambuc static void pagefault( struct proc *pr,
50433d6423SLionel Sambuc 			struct exception_frame * frame,
51433d6423SLionel Sambuc 			int is_nested)
52433d6423SLionel Sambuc {
53433d6423SLionel Sambuc 	int in_physcopy = 0, in_memset = 0;
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc 	reg_t pagefaultcr2;
56433d6423SLionel Sambuc 	message m_pagefault;
57433d6423SLionel Sambuc 	int err;
58433d6423SLionel Sambuc 
59433d6423SLionel Sambuc 	pagefaultcr2 = read_cr2();
60433d6423SLionel Sambuc 
61433d6423SLionel Sambuc #if 0
62433d6423SLionel Sambuc 	printf("kernel: pagefault in pr %d, addr 0x%lx, his cr3 0x%lx, actual cr3 0x%lx\n",
63433d6423SLionel Sambuc 		pr->p_endpoint, pagefaultcr2, pr->p_seg.p_cr3, read_cr3());
64433d6423SLionel Sambuc #endif
65433d6423SLionel Sambuc 
66433d6423SLionel Sambuc 	in_physcopy = (frame->eip > (vir_bytes) phys_copy) &&
67433d6423SLionel Sambuc 	   (frame->eip < (vir_bytes) phys_copy_fault);
68433d6423SLionel Sambuc 
69433d6423SLionel Sambuc 	in_memset = (frame->eip > (vir_bytes) phys_memset) &&
70433d6423SLionel Sambuc 	   (frame->eip < (vir_bytes) memset_fault);
71433d6423SLionel Sambuc 
72433d6423SLionel Sambuc 	if((is_nested || iskernelp(pr)) &&
73433d6423SLionel Sambuc 		catch_pagefaults && (in_physcopy || in_memset)) {
74433d6423SLionel Sambuc #if 0
75433d6423SLionel Sambuc 		printf("pf caught! addr 0x%lx\n", pagefaultcr2);
76433d6423SLionel Sambuc #endif
77433d6423SLionel Sambuc 		if (is_nested) {
78433d6423SLionel Sambuc 			if(in_physcopy) {
79433d6423SLionel Sambuc 				assert(!in_memset);
80433d6423SLionel Sambuc 				frame->eip = (reg_t) phys_copy_fault_in_kernel;
81433d6423SLionel Sambuc 			} else {
82433d6423SLionel Sambuc 				frame->eip = (reg_t) memset_fault_in_kernel;
83433d6423SLionel Sambuc 			}
84433d6423SLionel Sambuc 		}
85433d6423SLionel Sambuc 		else {
86433d6423SLionel Sambuc 			pr->p_reg.pc = (reg_t) phys_copy_fault;
87433d6423SLionel Sambuc 			pr->p_reg.retreg = pagefaultcr2;
88433d6423SLionel Sambuc 		}
89433d6423SLionel Sambuc 
90433d6423SLionel Sambuc 		return;
91433d6423SLionel Sambuc 	}
92433d6423SLionel Sambuc 
93433d6423SLionel Sambuc 	if(is_nested) {
94433d6423SLionel Sambuc 		printf("pagefault in kernel at pc 0x%lx address 0x%lx\n",
95433d6423SLionel Sambuc 			frame->eip, pagefaultcr2);
96433d6423SLionel Sambuc 		inkernel_disaster(pr, frame, NULL, is_nested);
97433d6423SLionel Sambuc 	}
98433d6423SLionel Sambuc 
99433d6423SLionel Sambuc 	/* VM can't handle page faults. */
100433d6423SLionel Sambuc 	if(pr->p_endpoint == VM_PROC_NR) {
101433d6423SLionel Sambuc 		/* Page fault we can't / don't want to
102433d6423SLionel Sambuc 		 * handle.
103433d6423SLionel Sambuc 		 */
104433d6423SLionel Sambuc 		printf("pagefault for VM on CPU %d, "
105433d6423SLionel Sambuc 			"pc = 0x%x, addr = 0x%x, flags = 0x%x, is_nested %d\n",
106433d6423SLionel Sambuc 			cpuid, pr->p_reg.pc, pagefaultcr2, frame->errcode,
107433d6423SLionel Sambuc 			is_nested);
108433d6423SLionel Sambuc 		proc_stacktrace(pr);
109433d6423SLionel Sambuc 		printf("pc of pagefault: 0x%lx\n", frame->eip);
110433d6423SLionel Sambuc 		panic("pagefault in VM");
111433d6423SLionel Sambuc 
112433d6423SLionel Sambuc 		return;
113433d6423SLionel Sambuc 	}
114433d6423SLionel Sambuc 
115433d6423SLionel Sambuc 	/* Don't schedule this process until pagefault is handled. */
116433d6423SLionel Sambuc 	RTS_SET(pr, RTS_PAGEFAULT);
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc 	/* tell Vm about the pagefault */
119433d6423SLionel Sambuc 	m_pagefault.m_source = pr->p_endpoint;
120433d6423SLionel Sambuc 	m_pagefault.m_type   = VM_PAGEFAULT;
121433d6423SLionel Sambuc 	m_pagefault.VPF_ADDR = pagefaultcr2;
122433d6423SLionel Sambuc 	m_pagefault.VPF_FLAGS = frame->errcode;
123433d6423SLionel Sambuc 
124433d6423SLionel Sambuc 	if ((err = mini_send(pr, VM_PROC_NR,
125433d6423SLionel Sambuc 					&m_pagefault, FROM_KERNEL))) {
126433d6423SLionel Sambuc 		panic("WARNING: pagefault: mini_send returned %d\n", err);
127433d6423SLionel Sambuc 	}
128433d6423SLionel Sambuc 
129433d6423SLionel Sambuc 	return;
130433d6423SLionel Sambuc }
131433d6423SLionel Sambuc 
inkernel_disaster(struct proc * saved_proc,struct exception_frame * frame,struct ex_s * ep,int is_nested)132433d6423SLionel Sambuc static void inkernel_disaster(struct proc *saved_proc,
133433d6423SLionel Sambuc 	struct exception_frame * frame, struct ex_s *ep,
134433d6423SLionel Sambuc 	int is_nested)
135433d6423SLionel Sambuc {
136433d6423SLionel Sambuc #if USE_SYSDEBUG
137433d6423SLionel Sambuc   if(ep) {
138433d6423SLionel Sambuc 	if (ep->msg == NULL)
139433d6423SLionel Sambuc 		printf("\nIntel-reserved exception %d\n", frame->vector);
140433d6423SLionel Sambuc 	  else
141433d6423SLionel Sambuc 		printf("\n%s\n", ep->msg);
142433d6423SLionel Sambuc   }
143433d6423SLionel Sambuc 
144433d6423SLionel Sambuc   printf("cpu %d is_nested = %d ", cpuid, is_nested);
145433d6423SLionel Sambuc 
146433d6423SLionel Sambuc   printf("vec_nr= %d, trap_errno= 0x%x, eip= 0x%x, "
147433d6423SLionel Sambuc 	"cs= 0x%x, eflags= 0x%x trap_esp 0x%08x\n",
148433d6423SLionel Sambuc 	frame->vector, frame->errcode, frame->eip,
149433d6423SLionel Sambuc 	frame->cs, frame->eflags, frame);
150433d6423SLionel Sambuc   printf("KERNEL registers :\n");
151433d6423SLionel Sambuc #define REG(n) (((u32_t *)frame)[-n])
152433d6423SLionel Sambuc   printf(
153433d6423SLionel Sambuc 		  "\t%%eax 0x%08x %%ebx 0x%08x %%ecx 0x%08x %%edx 0x%08x\n"
154433d6423SLionel Sambuc 		  "\t%%esp 0x%08x %%ebp 0x%08x %%esi 0x%08x %%edi 0x%08x\n",
155433d6423SLionel Sambuc 		  REG(1), REG(2), REG(3), REG(4),
156433d6423SLionel Sambuc 		  REG(5), REG(6), REG(7), REG(8));
157433d6423SLionel Sambuc 
158433d6423SLionel Sambuc   {
159433d6423SLionel Sambuc   	reg_t k_ebp = REG(6);
160433d6423SLionel Sambuc   	printf("KERNEL stacktrace, starting with ebp = 0x%lx:\n", k_ebp);
161433d6423SLionel Sambuc   	proc_stacktrace_execute(proc_addr(SYSTEM), k_ebp, frame->eip);
162433d6423SLionel Sambuc   }
163433d6423SLionel Sambuc 
164433d6423SLionel Sambuc   if (saved_proc) {
165433d6423SLionel Sambuc 	  printf("scheduled was: process %d (%s), ", saved_proc->p_endpoint, saved_proc->p_name);
166433d6423SLionel Sambuc 	  printf("pc = 0x%x\n", (unsigned) saved_proc->p_reg.pc);
167433d6423SLionel Sambuc 	  proc_stacktrace(saved_proc);
168433d6423SLionel Sambuc 
169433d6423SLionel Sambuc 	  panic("Unhandled kernel exception");
170433d6423SLionel Sambuc   }
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc   /* in an early stage of boot process we don't have processes yet */
173433d6423SLionel Sambuc   panic("exception in kernel while booting, no saved_proc yet");
174433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
175433d6423SLionel Sambuc }
176433d6423SLionel Sambuc 
177433d6423SLionel Sambuc /*===========================================================================*
178433d6423SLionel Sambuc  *				exception				     *
179433d6423SLionel Sambuc  *===========================================================================*/
exception_handler(int is_nested,struct exception_frame * frame)180433d6423SLionel Sambuc void exception_handler(int is_nested, struct exception_frame * frame)
181433d6423SLionel Sambuc {
182433d6423SLionel Sambuc /* An exception or unexpected interrupt has occurred. */
183433d6423SLionel Sambuc   register struct ex_s *ep;
184433d6423SLionel Sambuc   struct proc *saved_proc;
185433d6423SLionel Sambuc 
186433d6423SLionel Sambuc   /* Save proc_ptr, because it may be changed by debug statements. */
187433d6423SLionel Sambuc   saved_proc = get_cpulocal_var(proc_ptr);
188433d6423SLionel Sambuc 
189433d6423SLionel Sambuc   ep = &ex_data[frame->vector];
190433d6423SLionel Sambuc 
191433d6423SLionel Sambuc   if (frame->vector == 2) {		/* spurious NMI on some machines */
192433d6423SLionel Sambuc 	printf("got spurious NMI\n");
193433d6423SLionel Sambuc 	return;
194433d6423SLionel Sambuc   }
195433d6423SLionel Sambuc 
196433d6423SLionel Sambuc   /*
197433d6423SLionel Sambuc    * handle special cases for nested problems as they might be tricky or filter
198433d6423SLionel Sambuc    * them out quickly if the traps are not nested
199433d6423SLionel Sambuc    */
200433d6423SLionel Sambuc   if (is_nested) {
201433d6423SLionel Sambuc 	/*
202433d6423SLionel Sambuc 	 * if a problem occured while copying a message from userspace because
203433d6423SLionel Sambuc 	 * of a wrong pointer supplied by userland, handle it the only way we
204433d6423SLionel Sambuc 	 * can handle it ...
205433d6423SLionel Sambuc 	 */
206433d6423SLionel Sambuc 	if (((void*)frame->eip >= (void*)copy_msg_to_user &&
207433d6423SLionel Sambuc 			(void*)frame->eip <= (void*)__copy_msg_to_user_end) ||
208433d6423SLionel Sambuc 			((void*)frame->eip >= (void*)copy_msg_from_user &&
209433d6423SLionel Sambuc 			(void*)frame->eip <= (void*)__copy_msg_from_user_end)) {
210433d6423SLionel Sambuc 		switch(frame->vector) {
211433d6423SLionel Sambuc 		/* these error are expected */
212433d6423SLionel Sambuc 		case PAGE_FAULT_VECTOR:
213433d6423SLionel Sambuc 		case PROTECTION_VECTOR:
214433d6423SLionel Sambuc 			frame->eip = (reg_t) __user_copy_msg_pointer_failure;
215433d6423SLionel Sambuc 			return;
216433d6423SLionel Sambuc 		default:
217433d6423SLionel Sambuc 			panic("Copy involving a user pointer failed unexpectedly!");
218433d6423SLionel Sambuc 		}
219433d6423SLionel Sambuc 	}
220433d6423SLionel Sambuc 
221433d6423SLionel Sambuc 	/* Pass any error resulting from restoring FPU state, as a FPU
222433d6423SLionel Sambuc 	 * exception to the process.
223433d6423SLionel Sambuc 	 */
224433d6423SLionel Sambuc 	if (((void*)frame->eip >= (void*)fxrstor &&
225433d6423SLionel Sambuc 			(void *)frame->eip <= (void*)__fxrstor_end) ||
226433d6423SLionel Sambuc 			((void*)frame->eip >= (void*)frstor &&
227433d6423SLionel Sambuc 			(void *)frame->eip <= (void*)__frstor_end)) {
228433d6423SLionel Sambuc 		frame->eip = (reg_t) __frstor_failure;
229433d6423SLionel Sambuc 		return;
230433d6423SLionel Sambuc 	}
231433d6423SLionel Sambuc 
232433d6423SLionel Sambuc   	if(frame->vector == DEBUG_VECTOR
233433d6423SLionel Sambuc 		&& (saved_proc->p_reg.psw & TRACEBIT)
234433d6423SLionel Sambuc 		&& (saved_proc->p_seg.p_kern_trap_style == KTS_NONE)) {
235433d6423SLionel Sambuc 		/* Getting a debug trap in the kernel is legitimate
236433d6423SLionel Sambuc 		 * if a traced process entered the kernel using sysenter
237433d6423SLionel Sambuc 		 * or syscall; the trap flag is not cleared then.
238433d6423SLionel Sambuc 		 *
239433d6423SLionel Sambuc 		 * It triggers on the first kernel entry so the trap
240433d6423SLionel Sambuc 		 * style is still KTS_NONE.
241433d6423SLionel Sambuc 		 */
242433d6423SLionel Sambuc 
243433d6423SLionel Sambuc 		frame->eflags &= ~TRACEBIT;
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc 		return;
246433d6423SLionel Sambuc 
247433d6423SLionel Sambuc 		/* If control passes, this case is not recognized as legitimate
248433d6423SLionel Sambuc 		 * and we panic later on after all.
249433d6423SLionel Sambuc 		 */
250433d6423SLionel Sambuc 	}
251433d6423SLionel Sambuc   }
252433d6423SLionel Sambuc 
253433d6423SLionel Sambuc   if(frame->vector == PAGE_FAULT_VECTOR) {
254433d6423SLionel Sambuc 	pagefault(saved_proc, frame, is_nested);
255433d6423SLionel Sambuc 	return;
256433d6423SLionel Sambuc   }
257433d6423SLionel Sambuc 
258433d6423SLionel Sambuc   /* If an exception occurs while running a process, the is_nested variable
259433d6423SLionel Sambuc    * will be zero. Exceptions in interrupt handlers or system traps will make
260433d6423SLionel Sambuc    * is_nested non-zero.
261433d6423SLionel Sambuc    */
262433d6423SLionel Sambuc   if (is_nested == 0 && ! iskernelp(saved_proc)) {
263433d6423SLionel Sambuc #if 0
264433d6423SLionel Sambuc 	{
265433d6423SLionel Sambuc 
266433d6423SLionel Sambuc   		printf(
267433d6423SLionel Sambuc   "vec_nr= %d, trap_errno= 0x%lx, eip= 0x%lx, cs= 0x%x, eflags= 0x%lx\n",
268433d6423SLionel Sambuc 			frame->vector, (unsigned long)frame->errcode,
269433d6423SLionel Sambuc 			(unsigned long)frame->eip, frame->cs,
270433d6423SLionel Sambuc 			(unsigned long)frame->eflags);
271433d6423SLionel Sambuc 		proc_stacktrace(saved_proc);
272433d6423SLionel Sambuc 	}
273433d6423SLionel Sambuc 
274433d6423SLionel Sambuc #endif
275433d6423SLionel Sambuc 	cause_sig(proc_nr(saved_proc), ep->signum);
276433d6423SLionel Sambuc 	return;
277433d6423SLionel Sambuc   }
278433d6423SLionel Sambuc 
279433d6423SLionel Sambuc   /* Exception in system code. This is not supposed to happen. */
280433d6423SLionel Sambuc   inkernel_disaster(saved_proc, frame, ep, is_nested);
281433d6423SLionel Sambuc 
282433d6423SLionel Sambuc   panic("return from inkernel_disaster");
283433d6423SLionel Sambuc }
284433d6423SLionel Sambuc 
285433d6423SLionel Sambuc #if USE_SYSDEBUG
286433d6423SLionel Sambuc /*===========================================================================*
287433d6423SLionel Sambuc  *				proc_stacktrace_execute			     *
288433d6423SLionel Sambuc  *===========================================================================*/
proc_stacktrace_execute(struct proc * whichproc,reg_t v_bp,reg_t pc)289433d6423SLionel Sambuc static void proc_stacktrace_execute(struct proc *whichproc, reg_t v_bp, reg_t pc)
290433d6423SLionel Sambuc {
291433d6423SLionel Sambuc 	reg_t v_hbp;
292433d6423SLionel Sambuc 	int iskernel;
293433d6423SLionel Sambuc 	int n = 0;
294433d6423SLionel Sambuc 
295433d6423SLionel Sambuc 	iskernel = iskernelp(whichproc);
296433d6423SLionel Sambuc 
297433d6423SLionel Sambuc 	printf("%-8.8s %6d 0x%lx ",
298433d6423SLionel Sambuc 		whichproc->p_name, whichproc->p_endpoint, pc);
299433d6423SLionel Sambuc 
300433d6423SLionel Sambuc 	while(v_bp) {
301433d6423SLionel Sambuc 		reg_t v_pc;
302433d6423SLionel Sambuc 
303433d6423SLionel Sambuc #define PRCOPY(pr, pv, v, n) \
304433d6423SLionel Sambuc   (iskernel ? (memcpy((char *) v, (char *) pv, n), OK) : \
305433d6423SLionel Sambuc      data_copy(pr->p_endpoint, pv, KERNEL, (vir_bytes) (v), n))
306433d6423SLionel Sambuc 
307433d6423SLionel Sambuc 	        if(PRCOPY(whichproc, v_bp, &v_hbp, sizeof(v_hbp)) != OK) {
308433d6423SLionel Sambuc 			printf("(v_bp 0x%lx ?)", v_bp);
309433d6423SLionel Sambuc 			break;
310433d6423SLionel Sambuc 		}
311433d6423SLionel Sambuc 		if(PRCOPY(whichproc, v_bp + sizeof(v_pc), &v_pc, sizeof(v_pc)) != OK) {
312433d6423SLionel Sambuc 			printf("(v_pc 0x%lx ?)", v_bp + sizeof(v_pc));
313433d6423SLionel Sambuc 			break;
314433d6423SLionel Sambuc 		}
315433d6423SLionel Sambuc 		printf("0x%lx ", (unsigned long) v_pc);
316433d6423SLionel Sambuc 		if(v_hbp != 0 && v_hbp <= v_bp) {
317*d09f72c4SDavid van Moolenbroek 			printf("(hbp 0x%lx ?)", v_hbp);
318433d6423SLionel Sambuc 			break;
319433d6423SLionel Sambuc 		}
320433d6423SLionel Sambuc 		v_bp = v_hbp;
321433d6423SLionel Sambuc 		if(n++ > 50) {
322433d6423SLionel Sambuc 			printf("(truncated after %d steps) ", n);
323433d6423SLionel Sambuc 			break;
324433d6423SLionel Sambuc 		}
325433d6423SLionel Sambuc 	}
326433d6423SLionel Sambuc 	printf("\n");
327433d6423SLionel Sambuc }
328433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
329433d6423SLionel Sambuc 
330433d6423SLionel Sambuc /*===========================================================================*
331433d6423SLionel Sambuc  *				proc_stacktrace			     *
332433d6423SLionel Sambuc  *===========================================================================*/
proc_stacktrace(struct proc * whichproc)333433d6423SLionel Sambuc void proc_stacktrace(struct proc *whichproc)
334433d6423SLionel Sambuc {
335433d6423SLionel Sambuc 	u32_t use_bp;
336433d6423SLionel Sambuc 
337433d6423SLionel Sambuc 	if(whichproc->p_seg.p_kern_trap_style == KTS_NONE) {
338*d09f72c4SDavid van Moolenbroek 		printf("WARNING: stacktrace of running process\n");
339433d6423SLionel Sambuc 	}
340433d6423SLionel Sambuc 
341433d6423SLionel Sambuc 	switch(whichproc->p_seg.p_kern_trap_style) {
342433d6423SLionel Sambuc 		case KTS_SYSENTER:
343433d6423SLionel Sambuc 		case KTS_SYSCALL:
344433d6423SLionel Sambuc 		{
345433d6423SLionel Sambuc 			u32_t sp = whichproc->p_reg.sp;
346433d6423SLionel Sambuc 
347433d6423SLionel Sambuc 			/* Full context is not available in the p_reg
348433d6423SLionel Sambuc 			 * struct. Obtain it from the user's stack.
349433d6423SLionel Sambuc 			 * The use stack pointer is always available.
350433d6423SLionel Sambuc 			 * The fact that it's there, and the 16 byte offset,
351433d6423SLionel Sambuc 			 * is a dependency on the trap code in
352433d6423SLionel Sambuc 			 * kernel/arch/i386/usermapped_glo_ipc.S.
353433d6423SLionel Sambuc 			 */
354433d6423SLionel Sambuc 
355433d6423SLionel Sambuc 			if(data_copy(whichproc->p_endpoint, sp+16,
356433d6423SLionel Sambuc 			  KERNEL, (vir_bytes) &use_bp,
357433d6423SLionel Sambuc 				sizeof(use_bp)) != OK) {
358433d6423SLionel Sambuc 				printf("stacktrace: aborting, copy failed\n");
359433d6423SLionel Sambuc 				return;
360433d6423SLionel Sambuc 			}
361433d6423SLionel Sambuc 
362433d6423SLionel Sambuc 			break;
363433d6423SLionel Sambuc 		}
364433d6423SLionel Sambuc 		default:
365433d6423SLionel Sambuc 			/* Full context is available; use the stored ebp */
366433d6423SLionel Sambuc 			use_bp = whichproc->p_reg.fp;
367433d6423SLionel Sambuc 			break;
368433d6423SLionel Sambuc 	}
369433d6423SLionel Sambuc 
370433d6423SLionel Sambuc #if USE_SYSDEBUG
371433d6423SLionel Sambuc 	proc_stacktrace_execute(whichproc, use_bp, whichproc->p_reg.pc);
372433d6423SLionel Sambuc #endif /* USE_SYSDEBUG */
373433d6423SLionel Sambuc }
374433d6423SLionel Sambuc 
enable_fpu_exception(void)375433d6423SLionel Sambuc void enable_fpu_exception(void)
376433d6423SLionel Sambuc {
377433d6423SLionel Sambuc 	u32_t cr0 = read_cr0();
378433d6423SLionel Sambuc 	if(!(cr0 & I386_CR0_TS))
379433d6423SLionel Sambuc 		write_cr0(cr0 | I386_CR0_TS);
380433d6423SLionel Sambuc }
381433d6423SLionel Sambuc 
disable_fpu_exception(void)382433d6423SLionel Sambuc void disable_fpu_exception(void)
383433d6423SLionel Sambuc {
384433d6423SLionel Sambuc 	clts();
385433d6423SLionel Sambuc }
386433d6423SLionel Sambuc 
387