trap.c revision 1.51 1 /* $NetBSD: trap.c,v 1.51 2008/01/10 21:08:40 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matthew Fredette.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /* $OpenBSD: trap.c,v 1.30 2001/09/19 20:50:56 mickey Exp $ */
40
41 /*
42 * Copyright (c) 1998-2000 Michael Shalayeff
43 * All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by Michael Shalayeff.
56 * 4. The name of the author may not be used to endorse or promote products
57 * derived from this software without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.51 2008/01/10 21:08:40 skrll Exp $");
73
74 /* #define INTRDEBUG */
75 /* #define TRAPDEBUG */
76 /* #define USERTRACE */
77
78 #include "opt_kgdb.h"
79 #include "opt_ptrace.h"
80
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/kernel.h>
84 #include <sys/syscall.h>
85 #include <sys/mutex.h>
86 #include <sys/ktrace.h>
87 #include <sys/proc.h>
88 #include <sys/signalvar.h>
89 #include <sys/user.h>
90 #include <sys/acct.h>
91 #include <sys/signal.h>
92 #include <sys/device.h>
93 #include <sys/pool.h>
94 #include <sys/userret.h>
95
96 #include <net/netisr.h>
97
98 #ifdef KGDB
99 #include <sys/kgdb.h>
100 #endif
101
102 #include <uvm/uvm.h>
103
104 #include <machine/iomod.h>
105 #include <machine/cpufunc.h>
106 #include <machine/reg.h>
107 #include <machine/autoconf.h>
108
109 #include <machine/db_machdep.h>
110
111 #include <hppa/hppa/machdep.h>
112
113 #include <ddb/db_output.h>
114 #include <ddb/db_interface.h>
115
116 #ifdef PTRACE
117 void ss_clear_breakpoints(struct lwp *l);
118 int ss_put_value(struct lwp *, vaddr_t, u_int);
119 int ss_get_value(struct lwp *, vaddr_t, u_int *);
120 #endif
121
122 /* single-step breakpoint */
123 #define SSBREAKPOINT (HPPA_BREAK_KERNEL | (HPPA_BREAK_SS << 13))
124
125 #if defined(DEBUG) || defined(DIAGNOSTIC)
126 /*
127 * 0x6fc1000 is a stwm r1, d(sr0, sp), which is the last
128 * instruction in the function prologue that gcc -O0 uses.
129 * When we have this instruction we know the relationship
130 * between the stack pointer and the gcc -O0 frame pointer
131 * (in r3, loaded with the initial sp) for the body of a
132 * function.
133 *
134 * If the given instruction is a stwm r1, d(sr0, sp) where
135 * d > 0, we evaluate to d, else we evaluate to zero.
136 */
137 #define STWM_R1_D_SR0_SP(inst) \
138 (((inst) & 0xffffc001) == 0x6fc10000 ? (((inst) & 0x00003ff) >> 1) : 0)
139 #endif /* DEBUG || DIAGNOSTIC */
140
141 const char *trap_type[] = {
142 "invalid",
143 "HPMC",
144 "power failure",
145 "recovery counter",
146 "external interrupt",
147 "LPMC",
148 "ITLB miss fault",
149 "instruction protection",
150 "Illegal instruction",
151 "break instruction",
152 "privileged operation",
153 "privileged register",
154 "overflow",
155 "conditional",
156 "assist exception",
157 "DTLB miss",
158 "ITLB non-access miss",
159 "DTLB non-access miss",
160 "data protection/rights/alignment",
161 "data break",
162 "TLB dirty",
163 "page reference",
164 "assist emulation",
165 "higher-priv transfer",
166 "lower-priv transfer",
167 "taken branch",
168 "data access rights",
169 "data protection",
170 "unaligned data ref",
171 };
172 int trap_types = sizeof(trap_type)/sizeof(trap_type[0]);
173
174 uint8_t fpopmap[] = {
175 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
176 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 };
184
185 volatile int astpending;
186
187 void pmap_hptdump(void);
188 void syscall(struct trapframe *, int *);
189
190 #ifdef USERTRACE
191 /*
192 * USERTRACE is a crude facility that traces the PC of
193 * a single user process. This tracing is normally
194 * activated by the dispatching of a certain syscall
195 * with certain arguments - see the activation code in
196 * syscall().
197 */
198 u_int rctr_next_iioq;
199 #endif
200
201 static inline void
202 userret(struct lwp *l, register_t pc, u_quad_t oticks)
203 {
204 struct proc *p = l->l_proc;
205
206 if (curcpu()->ci_want_resched) {
207 preempt();
208 }
209
210 mi_userret(l);
211
212 /*
213 * If profiling, charge recent system time to the trapped pc.
214 */
215 if (p->p_stflag & PST_PROFIL) {
216 extern int psratio;
217
218 addupc_task(l, pc, (int)(p->p_sticks - oticks) * psratio);
219 }
220 }
221
222 /*
223 * This handles some messy kernel debugger details.
224 * It dispatches into either kgdb or DDB, and knows
225 * about some special things to do, like skipping over
226 * break instructions and how to really set up for
227 * a single-step.
228 */
229 #if defined(KGDB) || defined(DDB)
230 static int
231 trap_kdebug(int type, int code, struct trapframe *frame)
232 {
233 int handled;
234 u_int tf_iioq_head_old;
235 u_int tf_iioq_tail_old;
236
237 for(;;) {
238
239 /* This trap has not been handled. */
240 handled = 0;
241
242 /* Remember the instruction offset queue. */
243 tf_iioq_head_old = frame->tf_iioq_head;
244 tf_iioq_tail_old = frame->tf_iioq_tail;
245
246 #ifdef KGDB
247 /* Let KGDB handle it (if connected) */
248 if (!handled)
249 handled = kgdb_trap(type, frame);
250 #endif
251 #ifdef DDB
252 /* Let DDB handle it. */
253 if (!handled)
254 handled = kdb_trap(type, code, frame);
255 #endif
256
257 /* If this trap wasn't handled, return now. */
258 if (!handled)
259 return(0);
260
261 /*
262 * If the instruction offset queue head changed,
263 * but the offset queue tail didn't, assume that
264 * the user wants to jump to the head offset, and
265 * adjust the tail accordingly. This should fix
266 * the kgdb `jump' command, and can help DDB users
267 * who `set' the offset head but forget the tail.
268 */
269 if (frame->tf_iioq_head != tf_iioq_head_old &&
270 frame->tf_iioq_tail == tf_iioq_tail_old)
271 frame->tf_iioq_tail = frame->tf_iioq_head + 4;
272
273 /*
274 * This is some single-stepping support.
275 * If we're trying to step through a nullified
276 * instruction, just advance by hand and trap
277 * again. Otherwise, load the recovery counter
278 * with zero.
279 */
280 if (frame->tf_ipsw & PSW_R) {
281 #ifdef TRAPDEBUG
282 printf("(single stepping at head 0x%x tail 0x%x)\n",
283 frame->tf_iioq_head, frame->tf_iioq_tail);
284 #endif
285 if (frame->tf_ipsw & PSW_N) {
286 #ifdef TRAPDEBUG
287 printf("(single stepping past nullified)\n");
288 #endif
289
290 /* Advance the program counter. */
291 frame->tf_iioq_head = frame->tf_iioq_tail;
292 frame->tf_iioq_tail = frame->tf_iioq_head + 4;
293
294 /* Clear flags. */
295 frame->tf_ipsw &= ~(PSW_N|PSW_X|PSW_Y|PSW_Z|PSW_B|PSW_T|PSW_H|PSW_L);
296
297 /* Simulate another trap. */
298 type = T_RECOVERY;
299 continue;
300 }
301 frame->tf_rctr = 0;
302 }
303
304 /* We handled this trap. */
305 return (1);
306 }
307 /* NOTREACHED */
308 }
309 #else /* !KGDB && !DDB */
310 #define trap_kdebug(t, c, f) (0)
311 #endif /* !KGDB && !DDB */
312
313 #if defined(DEBUG) || defined(USERTRACE)
314 /*
315 * These functions give a crude usermode backtrace. They
316 * really only work when code has been compiled without
317 * optimization, as they assume a certain function prologue
318 * sets up a frame pointer and stores the return pointer
319 * and arguments in it.
320 */
321 static void user_backtrace_raw(u_int, u_int);
322 static void
323 user_backtrace_raw(u_int pc, u_int fp)
324 {
325 int frame_number;
326 int arg_number;
327
328 for (frame_number = 0;
329 frame_number < 100 && pc > HPPA_PC_PRIV_MASK && fp;
330 frame_number++) {
331
332 printf("%3d: pc=%08x%s fp=0x%08x", frame_number,
333 pc & ~HPPA_PC_PRIV_MASK, USERMODE(pc) ? " " : "**", fp);
334 for(arg_number = 0; arg_number < 4; arg_number++)
335 printf(" arg%d=0x%08x", arg_number,
336 (int) fuword(HPPA_FRAME_CARG(arg_number, fp)));
337 printf("\n");
338 pc = fuword(((register_t *) fp) - 5); /* fetch rp */
339 if (pc == -1) {
340 printf(" fuword for pc failed\n");
341 break;
342 }
343 fp = fuword(((register_t *) fp) + 0); /* fetch previous fp */
344 if (fp == -1) {
345 printf(" fuword for fp failed\n");
346 break;
347 }
348 }
349 printf(" backtrace stopped with pc %08x fp 0x%08x\n", pc, fp);
350 }
351
352 static void user_backtrace(struct trapframe *, struct lwp *, int);
353 static void
354 user_backtrace(struct trapframe *tf, struct lwp *l, int type)
355 {
356 struct proc *p = l->l_proc;
357 u_int pc, fp, inst;
358
359 /*
360 * Display any trap type that we have.
361 */
362 if (type >= 0)
363 printf("pid %d (%s) trap #%d\n",
364 p->p_pid, p->p_comm, type & ~T_USER);
365
366 /*
367 * Assuming that the frame pointer in r3 is valid,
368 * dump out a stack trace.
369 */
370 fp = tf->tf_r3;
371 printf("pid %d (%s) backtrace, starting with fp 0x%08x\n",
372 p->p_pid, p->p_comm, fp);
373 user_backtrace_raw(tf->tf_iioq_head, fp);
374
375 /*
376 * In case the frame pointer in r3 is not valid,
377 * assuming the stack pointer is valid and the
378 * faulting function is a non-leaf, if we can
379 * find its prologue we can recover its frame
380 * pointer.
381 */
382 pc = tf->tf_iioq_head;
383 fp = tf->tf_sp - HPPA_FRAME_SIZE;
384 printf("pid %d (%s) backtrace, starting with sp 0x%08x pc 0x%08x\n",
385 p->p_pid, p->p_comm, tf->tf_sp, pc);
386 for (pc &= ~HPPA_PC_PRIV_MASK; pc > 0; pc -= sizeof(inst)) {
387 inst = fuword((register_t *) pc);
388 if (inst == -1) {
389 printf(" fuword for inst at pc %08x failed\n", pc);
390 break;
391 }
392 /* Check for the prologue instruction that sets sp. */
393 if (STWM_R1_D_SR0_SP(inst)) {
394 fp = tf->tf_sp - STWM_R1_D_SR0_SP(inst);
395 printf(" sp from fp at pc %08x: %08x\n", pc, inst);
396 break;
397 }
398 }
399 user_backtrace_raw(tf->tf_iioq_head, fp);
400 }
401 #endif /* DEBUG || USERTRACE */
402
403 #ifdef DEBUG
404 /*
405 * This sanity-checks a trapframe. It is full of various
406 * assumptions about what a healthy CPU state should be,
407 * with some documented elsewhere, some not.
408 */
409 struct trapframe *sanity_frame;
410 struct lwp *sanity_lwp;
411 int sanity_checked = 0;
412 void frame_sanity_check(int, int, struct trapframe *, struct lwp *);
413 void
414 frame_sanity_check(int where, int type, struct trapframe *tf, struct lwp *l)
415 {
416 extern int kernel_text;
417 extern int etext;
418 extern register_t kpsw;
419 extern vaddr_t hpt_base;
420 extern vsize_t hpt_mask;
421 #define SANITY(e) \
422 do { \
423 if (sanity_frame == NULL && !(e)) { \
424 sanity_frame = tf; \
425 sanity_lwp = l; \
426 sanity_checked = __LINE__; \
427 } \
428 } while (/* CONSTCOND */ 0)
429
430 SANITY((tf->tf_ipsw & kpsw) == kpsw);
431 SANITY(tf->tf_hptm == hpt_mask && tf->tf_vtop == hpt_base);
432 SANITY((kpsw & PSW_I) == 0 || tf->tf_eiem != 0);
433 if (tf->tf_iisq_head == HPPA_SID_KERNEL) {
434 vaddr_t minsp, maxsp;
435
436 /*
437 * If the trap happened in the gateway
438 * page, we take the easy way out and
439 * assume that the trapframe is okay.
440 */
441 if ((tf->tf_iioq_head & ~PAGE_MASK) == SYSCALLGATE)
442 goto out;
443
444 SANITY(!USERMODE(tf->tf_iioq_head));
445 SANITY(!USERMODE(tf->tf_iioq_tail));
446
447 /*
448 * Don't check the instruction queues or stack on interrupts
449 * as we could be be in the sti code (outside normal kernel
450 * text) or switching LWPs (curlwp and sp are not in sync)
451 */
452 if ((type & ~T_USER) == T_INTERRUPT)
453 goto out;
454
455 SANITY(tf->tf_iioq_head >= (u_int) &kernel_text);
456 SANITY(tf->tf_iioq_head < (u_int) &etext);
457 SANITY(tf->tf_iioq_tail >= (u_int) &kernel_text);
458 SANITY(tf->tf_iioq_tail < (u_int) &etext);
459
460 #ifdef HPPA_REDZONE
461 maxsp = (u_int)(l->l_addr) + HPPA_REDZONE;
462 #else
463 maxsp = (u_int)(l->l_addr) + USPACE;
464 #endif
465 minsp = (u_int)(l->l_addr) + PAGE_SIZE;
466
467 SANITY(l != NULL || (tf->tf_sp >= minsp && tf->tf_sp < maxsp));
468 } else {
469 SANITY(USERMODE(tf->tf_iioq_head));
470 SANITY(USERMODE(tf->tf_iioq_tail));
471 SANITY(l != NULL && tf->tf_cr30 == kvtop((void *)l->l_addr));
472 }
473 #undef SANITY
474 out:
475 if (sanity_frame == tf) {
476 printf("insanity: where 0x%x type 0x%x tf %p lwp %p line %d "
477 "sp 0x%x pc 0x%x\n",
478 where, type, sanity_frame, sanity_lwp, sanity_checked,
479 tf->tf_sp, tf->tf_iioq_head);
480 (void) trap_kdebug(T_IBREAK, 0, tf);
481 sanity_frame = NULL;
482 sanity_lwp = NULL;
483 sanity_checked = 0;
484 }
485 }
486 #endif /* DEBUG */
487
488 void
489 trap(int type, struct trapframe *frame)
490 {
491 struct lwp *l;
492 struct proc *p;
493 struct pcb *pcbp;
494 vaddr_t va;
495 struct vm_map *map;
496 struct vmspace *vm;
497 vm_prot_t vftype;
498 pa_space_t space;
499 ksiginfo_t ksi;
500 u_int opcode, onfault;
501 int ret;
502 const char *tts;
503 int type_raw;
504 #ifdef DIAGNOSTIC
505 extern int emergency_stack_start, emergency_stack_end;
506 #endif
507
508 type_raw = type & ~T_USER;
509 opcode = frame->tf_iir;
510 if (type_raw == T_ITLBMISS || type_raw == T_ITLBMISSNA ||
511 type_raw == T_IBREAK || type_raw == T_TAKENBR) {
512 va = frame->tf_iioq_head;
513 space = frame->tf_iisq_head;
514 vftype = VM_PROT_EXECUTE;
515 } else {
516 va = frame->tf_ior;
517 space = frame->tf_isr;
518 vftype = inst_store(opcode) ? VM_PROT_WRITE : VM_PROT_READ;
519 }
520
521 l = curlwp;
522 p = l ? l->l_proc : NULL;
523 if ((type & T_USER) != 0)
524 LWP_CACHE_CREDS(l, p);
525
526 tts = (type & ~T_USER) > trap_types ? "reserved" :
527 trap_type[type & ~T_USER];
528
529 #ifdef DIAGNOSTIC
530 /*
531 * If we are on the emergency stack, then we either got
532 * a fault on the kernel stack, or we're just handling
533 * a trap for the machine check handler (which also
534 * runs on the emergency stack).
535 *
536 * We *very crudely* differentiate between the two cases
537 * by checking the faulting instruction: if it is the
538 * function prologue instruction that stores the old
539 * frame pointer and updates the stack pointer, we assume
540 * that we faulted on the kernel stack.
541 *
542 * In this case, not completing that instruction will
543 * probably confuse backtraces in kgdb/ddb. Completing
544 * it would be difficult, because we already faulted on
545 * that part of the stack, so instead we fix up the
546 * frame as if the function called has just returned.
547 * This has peculiar knowledge about what values are in
548 * what registers during the "normal gcc -g" prologue.
549 */
550 if (&type >= &emergency_stack_start &&
551 &type < &emergency_stack_end &&
552 type != T_IBREAK && STWM_R1_D_SR0_SP(opcode)) {
553 /* Restore the caller's frame pointer. */
554 frame->tf_r3 = frame->tf_r1;
555 /* Restore the caller's instruction offsets. */
556 frame->tf_iioq_head = frame->tf_rp;
557 frame->tf_iioq_tail = frame->tf_iioq_head + 4;
558 goto dead_end;
559 }
560 #endif /* DIAGNOSTIC */
561
562 #ifdef DEBUG
563 frame_sanity_check(0xdead01, type, frame, l);
564 #endif /* DEBUG */
565
566 /* If this is a trap, not an interrupt, reenable interrupts. */
567 if (type_raw != T_INTERRUPT)
568 mtctl(frame->tf_eiem, CR_EIEM);
569
570 if (frame->tf_flags & TFF_LAST)
571 l->l_md.md_regs = frame;
572
573 #ifdef TRAPDEBUG
574 if (type_raw != T_INTERRUPT && type_raw != T_IBREAK)
575 printf("trap: %d, %s for %x:%x at %x:%x, fp=%p, rp=%x\n",
576 type, tts, space, (u_int)va, frame->tf_iisq_head,
577 frame->tf_iioq_head, frame, frame->tf_rp);
578 else if (type_raw == T_IBREAK)
579 printf("trap: break instruction %x:%x at %x:%x, fp=%p\n",
580 break5(opcode), break13(opcode),
581 frame->tf_iisq_head, frame->tf_iioq_head, frame);
582
583 {
584 extern int etext;
585 if (frame < (struct trapframe *)&etext) {
586 printf("trap: bogus frame ptr %p\n", frame);
587 goto dead_end;
588 }
589 }
590 #endif
591 switch (type) {
592 case T_NONEXIST:
593 case T_NONEXIST|T_USER:
594 #if !defined(DDB) && !defined(KGDB)
595 /* we've got screwed up by the central scrutinizer */
596 panic ("trap: elvis has just left the building!");
597 break;
598 #else
599 goto dead_end;
600 #endif
601 case T_RECOVERY|T_USER:
602 #ifdef USERTRACE
603 for(;;) {
604 if (frame->tf_iioq_head != rctr_next_iioq)
605 printf("-%08x\nr %08x",
606 rctr_next_iioq - 4,
607 frame->tf_iioq_head);
608 rctr_next_iioq = frame->tf_iioq_head + 4;
609 if (frame->tf_ipsw & PSW_N) {
610 /* Advance the program counter. */
611 frame->tf_iioq_head = frame->tf_iioq_tail;
612 frame->tf_iioq_tail = frame->tf_iioq_head + 4;
613 /* Clear flags. */
614 frame->tf_ipsw &= ~(PSW_N|PSW_X|PSW_Y|PSW_Z|PSW_B|PSW_T|PSW_H|PSW_L);
615 /* Simulate another trap. */
616 continue;
617 }
618 break;
619 }
620 frame->tf_rctr = 0;
621 break;
622 #endif /* USERTRACE */
623 case T_RECOVERY:
624 #if !defined(DDB) && !defined(KGDB)
625 /* XXX will implement later */
626 printf ("trap: handicapped");
627 break;
628 #else
629 goto dead_end;
630 #endif
631
632 case T_EMULATION | T_USER:
633 #ifdef FPEMUL
634 hppa_fpu_emulate(frame, l, opcode);
635 #else /* !FPEMUL */
636 /*
637 * We don't have FPU emulation, so signal the
638 * process with a SIGFPE.
639 */
640
641 KSI_INIT_TRAP(&ksi);
642 ksi.ksi_signo = SIGFPE;
643 ksi.ksi_code = SI_NOINFO;
644 ksi.ksi_trap = type;
645 ksi.ksi_addr = (void *)frame->tf_iioq_head;
646 trapsignal(l, &ksi);
647 #endif /* !FPEMUL */
648 break;
649
650 case T_DATALIGN:
651 if (l->l_addr->u_pcb.pcb_onfault) {
652 do_onfault:
653 pcbp = &l->l_addr->u_pcb;
654 frame->tf_iioq_tail = 4 +
655 (frame->tf_iioq_head =
656 pcbp->pcb_onfault);
657 pcbp->pcb_onfault = 0;
658 break;
659 }
660 /*FALLTHROUGH*/
661
662 #ifdef DIAGNOSTIC
663 /* these just can't happen ever */
664 case T_PRIV_OP:
665 case T_PRIV_REG:
666 /* these just can't make it to the trap() ever */
667 case T_HPMC:
668 case T_HPMC | T_USER:
669 case T_EMULATION:
670 case T_EXCEPTION:
671 #endif
672 case T_IBREAK:
673 case T_DBREAK:
674 dead_end:
675 if (type & T_USER) {
676 #ifdef DEBUG
677 user_backtrace(frame, l, type);
678 #endif
679 KSI_INIT_TRAP(&ksi);
680 ksi.ksi_signo = SIGILL;
681 ksi.ksi_code = ILL_ILLTRP;
682 ksi.ksi_trap = type;
683 ksi.ksi_addr = (void *)frame->tf_iioq_head;
684 trapsignal(l, &ksi);
685 break;
686 }
687 if (trap_kdebug(type, va, frame))
688 return;
689 else if (type == T_DATALIGN)
690 panic ("trap: %s at 0x%x", tts, (u_int) va);
691 else
692 panic ("trap: no debugger for \"%s\" (%d)", tts, type);
693 break;
694
695 case T_IBREAK | T_USER:
696 case T_DBREAK | T_USER:
697 KSI_INIT_TRAP(&ksi);
698 ksi.ksi_signo = SIGTRAP;
699 ksi.ksi_code = TRAP_TRACE;
700 ksi.ksi_trap = type_raw;
701 ksi.ksi_addr = (void *)frame->tf_iioq_head;
702 #ifdef PTRACE
703 ss_clear_breakpoints(l);
704 if (opcode == SSBREAKPOINT)
705 ksi.ksi_code = TRAP_BRKPT;
706 #endif
707 /* pass to user debugger */
708 trapsignal(l, &ksi);
709
710 break;
711
712 #ifdef PTRACE
713 case T_TAKENBR | T_USER:
714 ss_clear_breakpoints(l);
715
716 KSI_INIT_TRAP(&ksi);
717 ksi.ksi_signo = SIGTRAP;
718 ksi.ksi_code = TRAP_TRACE;
719 ksi.ksi_trap = type_raw;
720 ksi.ksi_addr = (void *)frame->tf_iioq_head;
721
722 /* pass to user debugger */
723 trapsignal(l, &ksi);
724 break;
725 #endif
726
727 case T_EXCEPTION | T_USER: { /* co-proc assist trap */
728 uint64_t *fpp;
729 uint32_t *pex, ex, inst;
730 int i;
731
732 hppa_fpu_flush(l);
733 fpp = l->l_addr->u_pcb.pcb_fpregs;
734 pex = (uint32_t *)&fpp[1];
735 for (i = 1; i < 8 && !*pex; i++, pex++)
736 ;
737 KASSERT(i < 8);
738 ex = *pex;
739 *pex = 0;
740
741 /* reset the trap flag, as if there was none */
742 fpp[0] &= ~(((uint64_t)HPPA_FPU_T) << 32);
743
744 /* emulate the instruction */
745 inst = ((uint32_t)fpopmap[ex >> 26] << 26) | (ex & 0x03ffffff);
746 hppa_fpu_emulate(frame, l, inst);
747 }
748 break;
749
750 case T_OVERFLOW | T_USER:
751 KSI_INIT_TRAP(&ksi);
752 ksi.ksi_signo = SIGFPE;
753 ksi.ksi_code = SI_NOINFO;
754 ksi.ksi_trap = type;
755 ksi.ksi_addr = (void *)va;
756 trapsignal(l, &ksi);
757 break;
758
759 case T_CONDITION | T_USER:
760 KSI_INIT_TRAP(&ksi);
761 ksi.ksi_signo = SIGFPE;
762 ksi.ksi_code = FPE_INTDIV;
763 ksi.ksi_trap = type;
764 ksi.ksi_addr = (void *)va;
765 trapsignal(l, &ksi);
766 break;
767
768 case T_ILLEGAL | T_USER:
769 #ifdef DEBUG
770 user_backtrace(frame, l, type);
771 #endif
772 KSI_INIT_TRAP(&ksi);
773 ksi.ksi_signo = SIGILL;
774 ksi.ksi_code = ILL_ILLOPC;
775 ksi.ksi_trap = type;
776 ksi.ksi_addr = (void *)va;
777 trapsignal(l, &ksi);
778 break;
779
780 case T_PRIV_OP | T_USER:
781 #ifdef DEBUG
782 user_backtrace(frame, l, type);
783 #endif
784 KSI_INIT_TRAP(&ksi);
785 ksi.ksi_signo = SIGILL;
786 ksi.ksi_code = ILL_PRVOPC;
787 ksi.ksi_trap = type;
788 ksi.ksi_addr = (void *)va;
789 trapsignal(l, &ksi);
790 break;
791
792 case T_PRIV_REG | T_USER:
793 #ifdef DEBUG
794 user_backtrace(frame, l, type);
795 #endif
796 KSI_INIT_TRAP(&ksi);
797 ksi.ksi_signo = SIGILL;
798 ksi.ksi_code = ILL_PRVREG;
799 ksi.ksi_trap = type;
800 ksi.ksi_addr = (void *)va;
801 trapsignal(l, &ksi);
802 break;
803
804 /* these should never got here */
805 case T_HIGHERPL | T_USER:
806 case T_LOWERPL | T_USER:
807 KSI_INIT_TRAP(&ksi);
808 ksi.ksi_signo = SIGSEGV;
809 ksi.ksi_code = SEGV_ACCERR;
810 ksi.ksi_trap = type;
811 ksi.ksi_addr = (void *)va;
812 trapsignal(l, &ksi);
813 break;
814
815 case T_IPROT | T_USER:
816 case T_DPROT | T_USER:
817 KSI_INIT_TRAP(&ksi);
818 ksi.ksi_signo = SIGSEGV;
819 ksi.ksi_code = SEGV_ACCERR;
820 ksi.ksi_trap = type;
821 ksi.ksi_addr = (void *)va;
822 trapsignal(l, &ksi);
823 break;
824
825 case T_DATACC: case T_USER | T_DATACC:
826 case T_ITLBMISS: case T_USER | T_ITLBMISS:
827 case T_DTLBMISS: case T_USER | T_DTLBMISS:
828 case T_ITLBMISSNA: case T_USER | T_ITLBMISSNA:
829 case T_DTLBMISSNA: case T_USER | T_DTLBMISSNA:
830 case T_TLB_DIRTY: case T_USER | T_TLB_DIRTY:
831 vm = p->p_vmspace;
832
833 if (!vm) {
834 #ifdef TRAPDEBUG
835 printf("trap: no vm, p=%p\n", p);
836 #endif
837 goto dead_end;
838 }
839
840 /*
841 * it could be a kernel map for exec_map faults
842 */
843 if (!(type & T_USER) && space == HPPA_SID_KERNEL)
844 map = kernel_map;
845 else
846 map = &vm->vm_map;
847
848 va = trunc_page(va);
849
850 if (map->pmap->pmap_space != space) {
851 #ifdef TRAPDEBUG
852 printf("trap: space mismatch %d != %d\n",
853 space, map->pmap->pmap_space);
854 #endif
855 /* actually dump the user, crap the kernel */
856 goto dead_end;
857 }
858
859 /* Never call uvm_fault in interrupt context. */
860 KASSERT(hppa_intr_depth == 0);
861
862 onfault = l->l_addr->u_pcb.pcb_onfault;
863 l->l_addr->u_pcb.pcb_onfault = 0;
864 ret = uvm_fault(map, va, vftype);
865 l->l_addr->u_pcb.pcb_onfault = onfault;
866
867 #ifdef TRAPDEBUG
868 printf("uvm_fault(%p, %x, %d)=%d\n",
869 map, (u_int)va, vftype, ret);
870 #endif
871
872 /*
873 * If this was a stack access we keep track of the maximum
874 * accessed stack size. Also, if uvm_fault gets a protection
875 * failure it is due to accessing the stack region outside
876 * the current limit and we need to reflect that as an access
877 * error.
878 */
879 if (map != kernel_map && va >= (vaddr_t)vm->vm_minsaddr) {
880 if (ret == 0)
881 uvm_grow(l->l_proc, va);
882 else if (ret == EACCES)
883 ret = EFAULT;
884 }
885
886 if (ret != 0) {
887 if (type & T_USER) {
888 #ifdef DEBUG
889 user_backtrace(frame, l, type);
890 #endif
891 KSI_INIT_TRAP(&ksi);
892 ksi.ksi_signo = SIGSEGV;
893 ksi.ksi_code = (ret == EACCES ?
894 SEGV_ACCERR : SEGV_MAPERR);
895 ksi.ksi_trap = type;
896 ksi.ksi_addr = (void *)va;
897 trapsignal(l, &ksi);
898 } else {
899 if (l->l_addr->u_pcb.pcb_onfault) {
900 goto do_onfault;
901 }
902 panic("trap: uvm_fault(%p, %lx, %d): %d",
903 map, va, vftype, ret);
904 }
905 }
906 break;
907
908 case T_DATALIGN | T_USER:
909 #ifdef DEBUG
910 user_backtrace(frame, l, type);
911 #endif
912 KSI_INIT_TRAP(&ksi);
913 ksi.ksi_signo = SIGBUS;
914 ksi.ksi_code = BUS_ADRALN;
915 ksi.ksi_trap = type;
916 ksi.ksi_addr = (void *)va;
917 trapsignal(l, &ksi);
918 break;
919
920 case T_INTERRUPT:
921 case T_INTERRUPT|T_USER:
922 hppa_intr(frame);
923 mtctl(frame->tf_eiem, CR_EIEM);
924 break;
925
926 case T_LOWERPL:
927 case T_DPROT:
928 case T_IPROT:
929 case T_OVERFLOW:
930 case T_CONDITION:
931 case T_ILLEGAL:
932 case T_HIGHERPL:
933 case T_TAKENBR:
934 case T_POWERFAIL:
935 case T_LPMC:
936 case T_PAGEREF:
937 case T_DATAPID: case T_DATAPID | T_USER:
938 if (0 /* T-chip */) {
939 break;
940 }
941 /* FALLTHROUGH to unimplemented */
942 default:
943 panic ("trap: unimplemented \'%s\' (%d)", tts, type);
944 }
945
946 if (type & T_USER)
947 userret(l, l->l_md.md_regs->tf_iioq_head, 0);
948
949 #ifdef DEBUG
950 frame_sanity_check(0xdead02, type, frame, l);
951 if (frame->tf_flags & TFF_LAST && (curlwp->l_flag & LW_IDLE) == 0)
952 frame_sanity_check(0xdead03, type, curlwp->l_md.md_regs,
953 curlwp);
954 #endif /* DEBUG */
955 }
956
957 void
958 child_return(void *arg)
959 {
960 struct lwp *l = arg;
961
962 userret(l, l->l_md.md_regs->tf_iioq_head, 0);
963 ktrsysret(SYS_fork, 0, 0);
964 #ifdef DEBUG
965 frame_sanity_check(0xdead04, 0, l->l_md.md_regs, l);
966 #endif /* DEBUG */
967 }
968
969 #ifdef PTRACE
970
971 #include <sys/ptrace.h>
972
973 int
974 ss_get_value(struct lwp *l, vaddr_t addr, u_int *value)
975 {
976 struct uio uio;
977 struct iovec iov;
978
979 iov.iov_base = (void *)value;
980 iov.iov_len = sizeof(u_int);
981 uio.uio_iov = &iov;
982 uio.uio_iovcnt = 1;
983 uio.uio_offset = (off_t)addr;
984 uio.uio_resid = sizeof(u_int);
985 uio.uio_rw = UIO_READ;
986 UIO_SETUP_SYSSPACE(&uio);
987
988 return (process_domem(curlwp, l, &uio));
989 }
990
991 int
992 ss_put_value(struct lwp *l, vaddr_t addr, u_int value)
993 {
994 struct uio uio;
995 struct iovec iov;
996
997 iov.iov_base = (void *)&value;
998 iov.iov_len = sizeof(u_int);
999 uio.uio_iov = &iov;
1000 uio.uio_iovcnt = 1;
1001 uio.uio_offset = (off_t)addr;
1002 uio.uio_resid = sizeof(u_int);
1003 uio.uio_rw = UIO_WRITE;
1004 UIO_SETUP_SYSSPACE(&uio);
1005
1006 return (process_domem(curlwp, l, &uio));
1007 }
1008
1009 void
1010 ss_clear_breakpoints(struct lwp *l)
1011 {
1012 /* Restore origional instructions. */
1013 if (l->l_md.md_bpva != 0) {
1014 ss_put_value(l, l->l_md.md_bpva, l->l_md.md_bpsave[0]);
1015 ss_put_value(l, l->l_md.md_bpva + 4, l->l_md.md_bpsave[1]);
1016 l->l_md.md_bpva = 0;
1017 }
1018 }
1019
1020
1021 int
1022 process_sstep(struct lwp *l, int sstep)
1023 {
1024 struct trapframe *tf = l->l_md.md_regs;
1025 int error;
1026
1027 ss_clear_breakpoints(l);
1028
1029 /* We're continuing... */
1030 /* Don't touch the syscall gateway page. */
1031 /* XXX head */
1032 if (sstep == 0 ||
1033 (tf->tf_iioq_tail & ~PAGE_MASK) == SYSCALLGATE) {
1034 tf->tf_ipsw &= ~PSW_T;
1035 return 0;
1036 }
1037
1038 l->l_md.md_bpva = tf->tf_iioq_tail & ~HPPA_PC_PRIV_MASK;
1039
1040 /*
1041 * Insert two breakpoint instructions; the first one might be
1042 * nullified. Of course we need to save two instruction
1043 * first.
1044 */
1045
1046 error = ss_get_value(l, l->l_md.md_bpva, &l->l_md.md_bpsave[0]);
1047 if (error)
1048 return (error);
1049 error = ss_get_value(l, l->l_md.md_bpva + 4, &l->l_md.md_bpsave[1]);
1050 if (error)
1051 return (error);
1052
1053 error = ss_put_value(l, l->l_md.md_bpva, SSBREAKPOINT);
1054 if (error)
1055 return error;
1056 error = ss_put_value(l, l->l_md.md_bpva + 4, SSBREAKPOINT);
1057 if (error)
1058 return error;
1059
1060 tf->tf_ipsw |= PSW_T;
1061
1062 return 0;
1063 }
1064 #endif
1065
1066
1067 /*
1068 * call actual syscall routine
1069 * from the low-level syscall handler:
1070 * - all HPPA_FRAME_NARGS syscall's arguments supposed to be copied onto
1071 * our stack, this wins compared to copyin just needed amount anyway
1072 * - register args are copied onto stack too
1073 */
1074 void
1075 syscall(struct trapframe *frame, int *args)
1076 {
1077 struct lwp *l;
1078 struct proc *p;
1079 const struct sysent *callp;
1080 int nsys, code, argsize, error;
1081 int tmp;
1082 int rval[2];
1083
1084 uvmexp.syscalls++;
1085
1086 #ifdef DEBUG
1087 frame_sanity_check(0xdead04, 0, frame, curlwp);
1088 #endif /* DEBUG */
1089
1090 if (!USERMODE(frame->tf_iioq_head))
1091 panic("syscall");
1092
1093 l = curlwp;
1094 p = l->l_proc;
1095 l->l_md.md_regs = frame;
1096 nsys = p->p_emul->e_nsysent;
1097 callp = p->p_emul->e_sysent;
1098 code = frame->tf_t1;
1099 LWP_CACHE_CREDS(l, p);
1100
1101 /*
1102 * Restarting a system call is touchy on the HPPA,
1103 * because syscall arguments are passed in registers
1104 * and the program counter of the syscall "point"
1105 * isn't easily divined.
1106 *
1107 * We handle the first problem by assuming that we
1108 * will have to restart this system call, so we
1109 * stuff the first four words of the original arguments
1110 * back into the frame as arg0...arg3, which is where
1111 * we found them in the first place. Any further
1112 * arguments are (still) on the user's stack and the
1113 * syscall code will fetch them from there (again).
1114 *
1115 * The program counter problem is addressed below.
1116 */
1117 frame->tf_arg0 = args[0];
1118 frame->tf_arg1 = args[1];
1119 frame->tf_arg2 = args[2];
1120 frame->tf_arg3 = args[3];
1121
1122 /*
1123 * Some special handling for the syscall(2) and
1124 * __syscall(2) system calls.
1125 */
1126 switch (code) {
1127 case SYS_syscall:
1128 code = *args;
1129 args += 1;
1130 break;
1131 case SYS___syscall:
1132 if (callp != sysent)
1133 break;
1134 /*
1135 * NB: even though __syscall(2) takes a quad_t
1136 * containing the system call number, because
1137 * our argument copying word-swaps 64-bit arguments,
1138 * the least significant word of that quad_t
1139 * is the first word in the argument array.
1140 */
1141 code = *args;
1142 args += 2;
1143 }
1144
1145 /*
1146 * Stacks growing from lower addresses to higher
1147 * addresses are not really such a good idea, because
1148 * it makes it impossible to overlay a struct on top
1149 * of C stack arguments (the arguments appear in
1150 * reversed order).
1151 *
1152 * You can do the obvious thing (as locore.S does) and
1153 * copy argument words one by one, laying them out in
1154 * the "right" order in the destination buffer, but this
1155 * ends up word-swapping multi-word arguments (like off_t).
1156 *
1157 * To compensate, we have some automatically-generated
1158 * code that word-swaps these multi-word arguments.
1159 * Right now the script that generates this code is
1160 * in Perl, because I don't know awk.
1161 *
1162 * FIXME - this works only on native binaries and
1163 * will probably screw up any and all emulation.
1164 */
1165 switch (code) {
1166 /*
1167 * BEGIN automatically generated
1168 * by /home/fredette/project/hppa/makescargfix.pl
1169 * do not edit!
1170 */
1171 case SYS_pread:
1172 /*
1173 * syscallarg(int) fd;
1174 * syscallarg(void *) buf;
1175 * syscallarg(size_t) nbyte;
1176 * syscallarg(int) pad;
1177 * syscallarg(off_t) offset;
1178 */
1179 tmp = args[4];
1180 args[4] = args[4 + 1];
1181 args[4 + 1] = tmp;
1182 break;
1183 case SYS_pwrite:
1184 /*
1185 * syscallarg(int) fd;
1186 * syscallarg(const void *) buf;
1187 * syscallarg(size_t) nbyte;
1188 * syscallarg(int) pad;
1189 * syscallarg(off_t) offset;
1190 */
1191 tmp = args[4];
1192 args[4] = args[4 + 1];
1193 args[4 + 1] = tmp;
1194 break;
1195 case SYS_mmap:
1196 /*
1197 * syscallarg(void *) addr;
1198 * syscallarg(size_t) len;
1199 * syscallarg(int) prot;
1200 * syscallarg(int) flags;
1201 * syscallarg(int) fd;
1202 * syscallarg(long) pad;
1203 * syscallarg(off_t) pos;
1204 */
1205 tmp = args[6];
1206 args[6] = args[6 + 1];
1207 args[6 + 1] = tmp;
1208 break;
1209 case SYS_lseek:
1210 /*
1211 * syscallarg(int) fd;
1212 * syscallarg(int) pad;
1213 * syscallarg(off_t) offset;
1214 */
1215 tmp = args[2];
1216 args[2] = args[2 + 1];
1217 args[2 + 1] = tmp;
1218 break;
1219 case SYS_truncate:
1220 /*
1221 * syscallarg(const char *) path;
1222 * syscallarg(int) pad;
1223 * syscallarg(off_t) length;
1224 */
1225 tmp = args[2];
1226 args[2] = args[2 + 1];
1227 args[2 + 1] = tmp;
1228 break;
1229 case SYS_ftruncate:
1230 /*
1231 * syscallarg(int) fd;
1232 * syscallarg(int) pad;
1233 * syscallarg(off_t) length;
1234 */
1235 tmp = args[2];
1236 args[2] = args[2 + 1];
1237 args[2 + 1] = tmp;
1238 break;
1239 case SYS_preadv:
1240 /*
1241 * syscallarg(int) fd;
1242 * syscallarg(const struct iovec *) iovp;
1243 * syscallarg(int) iovcnt;
1244 * syscallarg(int) pad;
1245 * syscallarg(off_t) offset;
1246 */
1247 tmp = args[4];
1248 args[4] = args[4 + 1];
1249 args[4 + 1] = tmp;
1250 break;
1251 case SYS_pwritev:
1252 /*
1253 * syscallarg(int) fd;
1254 * syscallarg(const struct iovec *) iovp;
1255 * syscallarg(int) iovcnt;
1256 * syscallarg(int) pad;
1257 * syscallarg(off_t) offset;
1258 */
1259 tmp = args[4];
1260 args[4] = args[4 + 1];
1261 args[4 + 1] = tmp;
1262 break;
1263 default:
1264 break;
1265 /*
1266 * END automatically generated
1267 * by /home/fredette/project/hppa/makescargfix.pl
1268 * do not edit!
1269 */
1270 }
1271
1272 #ifdef USERTRACE
1273 if (0) {
1274 user_backtrace(frame, l, -1);
1275 frame->tf_ipsw |= PSW_R;
1276 frame->tf_rctr = 0;
1277 printf("r %08x", frame->tf_iioq_head);
1278 rctr_next_iioq = frame->tf_iioq_head + 4;
1279 }
1280 #endif
1281
1282 if (code < 0 || code >= nsys)
1283 callp += p->p_emul->e_nosys; /* bad syscall # */
1284 else
1285 callp += code;
1286 argsize = callp->sy_argsize;
1287
1288 if ((error = trace_enter(code, code, NULL, args)) != 0)
1289 goto out;
1290
1291 rval[0] = 0;
1292 rval[1] = 0;
1293 error = (*callp->sy_call)(l, args, rval);
1294 out:
1295 switch (error) {
1296 case 0:
1297 l = curlwp; /* changes on exec() */
1298 frame = l->l_md.md_regs;
1299 frame->tf_ret0 = rval[0];
1300 frame->tf_ret1 = rval[1];
1301 frame->tf_t1 = 0;
1302 break;
1303 case ERESTART:
1304 /*
1305 * Now we have to wind back the instruction
1306 * offset queue to the point where the system
1307 * call will be made again. This is inherently
1308 * tied to the SYSCALL macro.
1309 *
1310 * Currently, the part of the SYSCALL macro
1311 * that we want to rerun reads as:
1312 *
1313 * ldil L%SYSCALLGATE, r1
1314 * ble 4(sr7, r1)
1315 * ldi __CONCAT(SYS_,x), t1
1316 * ldw HPPA_FRAME_ERP(sr0,sp), rp
1317 *
1318 * And our offset queue head points to the
1319 * final ldw instruction. So we need to
1320 * subtract twelve to reach the ldil.
1321 */
1322 frame->tf_iioq_head -= 12;
1323 frame->tf_iioq_tail = frame->tf_iioq_head + 4;
1324 break;
1325 case EJUSTRETURN:
1326 p = curproc;
1327 break;
1328 default:
1329 if (p->p_emul->e_errno)
1330 error = p->p_emul->e_errno[error];
1331 frame->tf_t1 = error;
1332 break;
1333 }
1334
1335 trace_exit(code, args, rval, error);
1336
1337 userret(l, frame->tf_iioq_head, 0);
1338 #ifdef DEBUG
1339 frame_sanity_check(0xdead05, 0, frame, l);
1340 #endif /* DEBUG */
1341 }
1342
1343 /*
1344 * Start a new LWP
1345 */
1346 void
1347 startlwp(void *arg)
1348 {
1349 int err;
1350 ucontext_t *uc = arg;
1351 struct lwp *l = curlwp;
1352
1353 err = cpu_setmcontext(l, &uc->uc_mcontext, uc->uc_flags);
1354 #if DIAGNOSTIC
1355 if (err) {
1356 printf("Error %d from cpu_setmcontext.", err);
1357 }
1358 #endif
1359 pool_put(&lwp_uc_pool, uc);
1360
1361 userret(l, l->l_md.md_regs->tf_iioq_head, 0);
1362 }
1363