]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/sun4v/sun4v/trap.c
MFC r362623:
[FreeBSD/stable/8.git] / sys / sun4v / sun4v / trap.c
1 /*-
2  * Copyright (c) 2001, Jake Burkholder
3  * Copyright (C) 1994, David Greenman
4  * Copyright (c) 1990, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the University of Utah, and William Jolitz.
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  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *      from: @(#)trap.c        7.4 (Berkeley) 5/13/91
35  *      from: FreeBSD: src/sys/i386/i386/trap.c,v 1.197 2001/07/19
36  * $FreeBSD$
37  */
38
39 #include "opt_ddb.h"
40 #include "opt_ktr.h"
41 #include "opt_ktrace.h"
42
43 #include <sys/param.h>
44 #include <sys/kdb.h>
45 #include <sys/kernel.h>
46 #include <sys/bus.h>
47 #include <sys/interrupt.h>
48 #include <sys/ktr.h>
49 #include <sys/lock.h>
50 #include <sys/mutex.h>
51 #include <sys/systm.h>
52 #include <sys/pioctl.h>
53 #include <sys/ptrace.h>
54 #include <sys/proc.h>
55 #include <sys/smp.h>
56 #include <sys/signalvar.h>
57 #include <sys/syscall.h>
58 #include <sys/sysctl.h>
59 #include <sys/sysent.h>
60 #include <sys/vmmeter.h>
61 #ifdef KTRACE
62 #include <sys/uio.h>
63 #include <sys/ktrace.h>
64 #endif
65
66 #include <dev/ofw/openfirm.h>
67
68 #include <vm/vm.h>
69 #include <vm/pmap.h>
70 #include <vm/vm_extern.h>
71 #include <vm/vm_param.h>
72 #include <vm/vm_kern.h>
73 #include <vm/vm_map.h>
74 #include <vm/vm_page.h>
75
76 #include <machine/clock.h>
77 #include <machine/cpu.h>
78 #include <machine/frame.h>
79 #include <machine/intr_machdep.h>
80 #include <machine/pcb.h>
81 #include <machine/smp.h>
82 #include <machine/trap.h>
83 #include <machine/tstate.h>
84 #include <machine/tte.h>
85 #include <machine/tlb.h>
86 #include <machine/tsb.h>
87 #include <machine/watch.h>
88 #include <machine/wstate.h>
89
90 #include <machine/md_var.h>
91 #include <machine/hypervisorvar.h>
92
93 #include <security/audit/audit.h>
94
95 void trap(struct trapframe *tf, int64_t type, uint64_t data);
96 void syscall(struct trapframe *tf);
97
98 extern vm_paddr_t mmu_fault_status_area;
99
100 static int trap_pfault(struct thread *td, struct trapframe *tf, int64_t type, uint64_t data);
101
102 extern char copy_fault[];
103 extern char copy_nofault_begin[];
104 extern char copy_nofault_end[];
105
106 extern char fs_fault[];
107 extern char fs_nofault_begin[];
108 extern char fs_nofault_end[];
109 extern char fs_nofault_intr_begin[];
110 extern char fs_nofault_intr_end[];
111
112 extern char fas_fault[];
113 extern char fas_nofault_begin[];
114 extern char fas_nofault_end[];
115
116 const char *const trap_msg[] = {
117         "reserved",
118         "instruction access exception",
119         "instruction access error",
120         "instruction access protection",
121         "illtrap instruction",
122         "illegal instruction",
123         "privileged opcode",
124         "floating point disabled",
125         "floating point exception ieee 754",
126         "floating point exception other",
127         "tag overflow",
128         "division by zero",
129         "data access exception",
130         "data access error",
131         "data access protection",
132         "memory address not aligned",
133         "privileged action",
134         "async data error",
135         "trap instruction 16",
136         "trap instruction 17",
137         "trap instruction 18",
138         "trap instruction 19",
139         "trap instruction 20",
140         "trap instruction 21",
141         "trap instruction 22",
142         "trap instruction 23",
143         "trap instruction 24",
144         "trap instruction 25",
145         "trap instruction 26",
146         "trap instruction 27",
147         "trap instruction 28",
148         "trap instruction 29",
149         "trap instruction 30",
150         "trap instruction 31",
151         "fast instruction access mmu miss",
152         "fast data access mmu miss",
153         "interrupt",
154         "physical address watchpoint",
155         "virtual address watchpoint",
156         "corrected ecc error",
157         "spill",
158         "fill",
159         "fill",
160         "breakpoint",
161         "clean window",
162         "range check",
163         "fix alignment",
164         "integer overflow",
165         "syscall",
166         "restore physical watchpoint",
167         "restore virtual watchpoint",
168         "kernel stack fault",
169         "resumable error",
170         "nonresumable error"
171 };
172
173 const int trap_sig[] = {
174         SIGILL,                 /* reserved */
175         SIGILL,                 /* instruction access exception */
176         SIGILL,                 /* instruction access error */
177         SIGILL,                 /* instruction access protection */
178         SIGILL,                 /* illtrap instruction */
179         SIGILL,                 /* illegal instruction */
180         SIGBUS,                 /* privileged opcode */
181         SIGFPE,                 /* floating point disabled */
182         SIGFPE,                 /* floating point exception ieee 754 */
183         SIGFPE,                 /* floating point exception other */
184         SIGEMT,                 /* tag overflow */
185         SIGFPE,                 /* division by zero */
186         SIGILL,                 /* data access exception */
187         SIGILL,                 /* data access error */
188         SIGBUS,                 /* data access protection */
189         SIGBUS,                 /* memory address not aligned */
190         SIGBUS,                 /* privileged action */
191         SIGBUS,                 /* async data error */
192         SIGILL,                 /* trap instruction 16 */
193         SIGILL,                 /* trap instruction 17 */
194         SIGILL,                 /* trap instruction 18 */
195         SIGILL,                 /* trap instruction 19 */
196         SIGILL,                 /* trap instruction 20 */
197         SIGILL,                 /* trap instruction 21 */
198         SIGILL,                 /* trap instruction 22 */
199         SIGILL,                 /* trap instruction 23 */
200         SIGILL,                 /* trap instruction 24 */
201         SIGILL,                 /* trap instruction 25 */
202         SIGILL,                 /* trap instruction 26 */
203         SIGILL,                 /* trap instruction 27 */
204         SIGILL,                 /* trap instruction 28 */
205         SIGILL,                 /* trap instruction 29 */
206         SIGILL,                 /* trap instruction 30 */
207         SIGILL,                 /* trap instruction 31 */
208         SIGFPE,                 /* floating point error */
209         SIGSEGV,                /* fast data access mmu miss */
210         -1,                     /* interrupt */
211         -1,                     /* physical address watchpoint */
212         -1,                     /* virtual address watchpoint */
213         -1,                     /* corrected ecc error */
214         SIGILL,                 /* spill */
215         SIGILL,                 /* fill */
216         SIGILL,                 /* fill */
217         SIGTRAP,                /* breakpoint */
218         SIGILL,                 /* clean window */
219         SIGILL,                 /* range check */
220         SIGILL,                 /* fix alignment */
221         SIGILL,                 /* integer overflow */
222         SIGSYS,                 /* syscall */
223         -1,                     /* restore physical watchpoint */
224         -1,                     /* restore virtual watchpoint */
225         -1,                     /* kernel stack fault */
226 };
227
228 CTASSERT(sizeof(struct trapframe) == 256);
229
230 int debugger_on_signal = 0;
231 #ifdef DEBUG
232 SYSCTL_INT(_debug, OID_AUTO, debugger_on_signal, CTLFLAG_RW,
233     &debugger_on_signal, 0, "");
234 #endif
235
236 /*
237  * This interface allows the client to safely take over the %tba by
238  * the prom's service. The prom will take care of the quiescence of
239  * interrupts and handle any pending soft interrupts.
240  * This call also sets the MMU fault status area for the CPU.
241  */
242 void
243 set_mmfsa_traptable(void *tba_addr, uint64_t mmfsa_ra)
244 {
245         static struct {
246         cell_t name;
247                 cell_t nargs;
248                 cell_t nreturns;
249                 cell_t tba_addr;
250                 cell_t mmfsa_ra;
251         } args = {
252                 (cell_t)"SUNW,set-trap-table",
253                 2,
254         };
255
256         args.tba_addr = (cell_t)tba_addr;
257         args.mmfsa_ra = mmfsa_ra;
258         ofw_entry(&args);
259 }
260
261 void 
262 trap_init(void)
263 {
264         vm_paddr_t mmfsa;
265
266         mmfsa = mmu_fault_status_area + (MMFSA_SIZE*curcpu);
267
268         set_wstate(WSTATE_KERN);
269         set_mmfsa_scratchpad(mmfsa);
270
271         init_mondo_queue();
272         set_mmfsa_traptable(&tl0_base, mmfsa);
273 }
274
275 void
276 trap(struct trapframe *tf, int64_t type, uint64_t data)
277 {
278         struct thread *td;
279         struct proc *p;
280         int error, sig, ctx;
281         uint64_t trapno;
282         register_t addr;
283         ksiginfo_t ksi;
284
285         td = curthread;
286
287         CTR4(KTR_TRAP, "trap: %p type=%s (%s) pil=%#lx", td,
288             trap_msg[trapno],
289             (TRAPF_USERMODE(tf) ? "user" : "kernel"), rdpr(pil));
290
291         PCPU_INC(cnt.v_trap);
292
293         trapno = (type & TRAP_MASK);
294         ctx = (type >> TRAP_CTX_SHIFT);
295
296         if (((tf->tf_tstate & TSTATE_PRIV) == 0) || (ctx != 0)) {
297                 KASSERT(td != NULL, ("trap: curthread NULL"));
298                 KASSERT(td->td_proc != NULL, ("trap: curproc NULL"));
299
300                 p = td->td_proc;
301                 td->td_pticks = 0;
302                 td->td_frame = tf;
303                 addr = tf->tf_tpc;
304                 if (td->td_ucred != p->p_ucred)
305                         cred_update_thread(td);
306
307                 switch (trapno) {
308                 case T_DATA_MISS:
309                 case T_DATA_PROTECTION:
310                         addr = TLB_TAR_VA(data);
311                 case T_INSTRUCTION_MISS:
312                         sig = trap_pfault(td, tf, trapno, data);
313                         break;
314                 case T_FILL:
315                         sig = rwindow_load(td, tf, 2);
316                         break;
317                 case T_FILL_RET:
318                         sig = rwindow_load(td, tf, 1);
319                         break;
320                 case T_SPILL:
321                         sig = rwindow_save(td);
322                         break;
323                 case T_DATA_EXCEPTION:
324                 case T_DATA_ERROR:
325                 case T_MEM_ADDRESS_NOT_ALIGNED:
326                         printf("bad trap trapno=%ld data=0x%lx pc=0x%lx\n",
327                                trapno, data, tf->tf_tpc);
328                         if (tf->tf_tpc >= (u_long)copy_nofault_begin &&
329                             tf->tf_tpc <= (u_long)copy_nofault_end) {
330                                 tf->tf_tpc = (u_long)copy_fault;
331                                 tf->tf_tnpc = tf->tf_tpc + 4;
332                                 sig = 0;
333                                 break;
334                         }
335                         if (tf->tf_tpc >= (u_long)fs_nofault_begin &&
336                             tf->tf_tpc <= (u_long)fs_nofault_end) {
337                                 tf->tf_tpc = (u_long)fs_fault;
338                                 tf->tf_tnpc = tf->tf_tpc + 4;
339                                 sig = 0;
340                                 break;
341                         }
342
343                         addr = data;
344                         sig = trap_sig[trapno];
345                         break;
346
347                 default:
348                         if (trapno < 0 || trapno >= T_MAX ||
349                             trap_sig[trapno] == -1)
350                                 panic("trap: bad trap type");
351                         sig = trap_sig[trapno];
352                         break;
353                 }
354
355                 if (sig != 0) {
356                         /* Translate fault for emulators. */
357                         if (p->p_sysent->sv_transtrap != NULL) {
358                                 sig = p->p_sysent->sv_transtrap(sig,
359                                     trapno);
360                         }
361                         if (debugger_on_signal &&
362                             (sig == 4 || sig == 10 || sig == 11))
363                                 kdb_enter(KDB_WHY_TRAPSIG, "trapsig");
364 #ifdef VERBOSE
365                         if (sig == 4 || sig == 10 || sig == 11)
366                                 printf("trap: %ld:%s: 0x%lx at 0x%lx on cpu=%d sig=%d proc=%s\n", 
367                                        trapno, trap_msg[trapno], data, tf->tf_tpc, curcpu, sig, curthread->td_name);
368 #endif
369                         /* XXX I've renumbered the traps to largely reflect what the hardware uses
370                          * so this will need to be re-visited
371                          */
372                         ksiginfo_init_trap(&ksi);
373                         ksi.ksi_signo = sig;
374                         ksi.ksi_code = (int)trapno; /* XXX not POSIX */
375                         ksi.ksi_addr = (void *)addr;
376                         ksi.ksi_trapno = (int)trapno;
377                         trapsignal(td, &ksi);
378                 }
379
380                 userret(td, tf);
381                 mtx_assert(&Giant, MA_NOTOWNED);
382         } else {
383                 KASSERT((type & T_KERNEL) != 0,
384                     ("trap: kernel trap isn't - trap: %ld:%s: 0x%lx at 0x%lx on cpu=%d\n", 
385                      trapno, trap_msg[trapno], data, tf->tf_tpc, curcpu));
386
387                 if (kdb_active) {
388                         kdb_reenter();
389                         return;
390                 }
391
392                 switch (trapno) {
393                 case T_BREAKPOINT:
394                 case T_KSTACK_FAULT:
395                         error = (kdb_trap(trapno, 0, tf) == 0);
396                         TF_DONE(tf);
397                         break;
398                 case T_DATA_MISS:
399                 case T_DATA_PROTECTION:
400                 case T_INSTRUCTION_MISS:
401                         error = trap_pfault(td, tf, trapno, data);
402                         break;
403                 case T_DATA_EXCEPTION:
404                         printf("data exception on 0x%lx at 0x%lx\n", data, tf->tf_tpc);
405                         printf("trap: %ld=%s: 0x%lx at 0x%lx:0x%lx\n", trapno, 
406                                trap_msg[trapno], data, tf->tf_tpc, tf->tf_tnpc);
407                case T_ILLEGAL_INSTRUCTION:
408                        if (tf->tf_tpc > KERNBASE) {
409                                printf("illinstr: 0x%lx\n", tf->tf_tpc);
410                                printf("illinstr: 0x%x\n", *((uint32_t *)tf->tf_tpc));
411                        }
412                 case T_DATA_ERROR:
413                 case T_ALIGNMENT:
414                         if (tf->tf_asi == ASI_AIUS) {
415                                 if (tf->tf_tpc >= (u_long)copy_nofault_begin &&
416                                     tf->tf_tpc <= (u_long)copy_nofault_end) {
417                                         tf->tf_tpc = (u_long)copy_fault;
418                                         tf->tf_tnpc = tf->tf_tpc + 4;
419                                         error = 0;
420                                         break;
421                                 }
422                                 
423                                 printf("ASI_AIUS but bad tpc\n");
424                         } 
425                         if (tf->tf_tpc >= (u_long)fs_nofault_begin &&
426                             tf->tf_tpc <= (u_long)fs_nofault_end) {
427                                 tf->tf_tpc = (u_long)fs_fault;
428                                 tf->tf_tnpc = tf->tf_tpc + 4;
429                                 error = 0;
430                                         break;
431                         }
432                         printf("asi=0x%lx\n", tf->tf_asi);
433                         error = 1;      
434                         break;
435                 default:
436                         printf("unchecked trap 0x%lx asi=0x%lx\n", trapno, tf->tf_asi);
437                         error = 1;
438                         break;
439                 }
440
441                 if (error != 0)
442                         panic("trap: %ld=%s: 0x%lx at 0x%lx:0x%lx error=%d asi=0x%lx", 
443                               trapno, trap_msg[trapno], data, tf->tf_tpc, 
444                               tf->tf_tnpc, error, tf->tf_asi);
445         }
446         CTR1(KTR_TRAP, "trap: td=%p return", td);
447 }
448
449 static int
450 trap_pfault(struct thread *td, struct trapframe *tf, int64_t type, uint64_t data)
451 {
452         struct vmspace *vm;
453         struct proc *p;
454         vm_offset_t va;
455         vm_prot_t prot;
456         u_long ctx;
457         int flags;
458         int rv;
459
460         if (td == NULL)
461                 return (-1);
462
463         p = td->td_proc;
464
465         rv = KERN_SUCCESS;
466         ctx = TLB_TAR_CTX(data);
467         type = type & ~T_KERNEL;
468         va = TLB_TAR_VA(data);
469
470
471         if (data > VM_MIN_DIRECT_ADDRESS)
472                 printf("trap_pfault(type=%ld, data=0x%lx, tpc=0x%lx, ctx=0x%lx)\n", 
473                        type, data, tf->tf_tpc, ctx);
474
475 #if 0
476         CTR4(KTR_TRAP, "trap_pfault: td=%p pm_ctx=%#lx va=%#lx ctx=%#lx",
477             td, p->p_vmspace->vm_pmap.pm_context, va, ctx);
478 #endif
479         KASSERT(td->td_pcb != NULL, ("trap_pfault: pcb NULL"));
480         KASSERT(td->td_proc != NULL, ("trap_pfault: curproc NULL"));
481         KASSERT(td->td_proc->p_vmspace != NULL, ("trap_pfault: vmspace NULL"));
482
483
484         if (type == T_DATA_PROTECTION) {
485                 prot = VM_PROT_WRITE;
486                 flags = VM_FAULT_DIRTY;
487         } else {
488                 if (type == T_DATA_MISS)
489                         prot = VM_PROT_READ;
490                 else
491                         prot = VM_PROT_READ | VM_PROT_EXECUTE;
492                 flags = VM_FAULT_NORMAL;
493         }
494
495         if (ctx != TLB_CTX_KERNEL) {
496                 if ((tf->tf_tstate & TSTATE_PRIV) != 0 &&
497                     (tf->tf_tpc >= (u_long)fs_nofault_intr_begin &&
498                      tf->tf_tpc <= (u_long)fs_nofault_intr_end)) {
499                         tf->tf_tpc = (u_long)fs_fault;
500                         tf->tf_tnpc = tf->tf_tpc + 4;
501                         return (0);
502                 }
503
504                 /*
505                  * This is a fault on non-kernel virtual memory.
506                  */
507                 vm = p->p_vmspace;
508
509                 /*
510                  * Keep swapout from messing with us during this
511                  * critical time.
512                  */
513                 PROC_LOCK(p);
514                 ++p->p_lock;
515                 PROC_UNLOCK(p);
516
517                 /* Fault in the user page. */
518                 rv = vm_fault(&vm->vm_map, va, prot, flags);
519
520                 /*
521                  * Now the process can be swapped again.
522                  */
523                 PROC_LOCK(p);
524                 --p->p_lock;
525                 PROC_UNLOCK(p);
526         } else {
527                 /*
528                  * This is a fault on kernel virtual memory.  Attempts to
529                  * access kernel memory from user mode cause privileged
530                  * action traps, not page fault.
531                  */
532                 KASSERT(tf->tf_tstate & TSTATE_PRIV,
533                     ("trap_pfault: fault on nucleus context from user mode"));
534
535                 /*
536                  * Don't have to worry about process locking or stacks in the
537                  * kernel.
538                  */
539                 rv = vm_fault(kernel_map, va, prot, VM_FAULT_NORMAL);
540         }
541
542         CTR3(KTR_TRAP, "trap_pfault: return td=%p va=%#lx rv=%d",
543             td, va, rv);
544         if (rv == KERN_SUCCESS)
545                 return (0);
546         if (ctx != TLB_CTX_KERNEL && (tf->tf_tstate & TSTATE_PRIV) != 0) {
547                 if (tf->tf_tpc >= (u_long)fs_nofault_begin &&
548                     tf->tf_tpc <= (u_long)fs_nofault_end) {
549                         tf->tf_tpc = (u_long)fs_fault;
550                         tf->tf_tnpc = tf->tf_tpc + 4;
551                         return (0);
552                 }
553                 if (tf->tf_tpc >= (u_long)copy_nofault_begin &&
554                     tf->tf_tpc <= (u_long)copy_nofault_end) {
555                         tf->tf_tpc = (u_long)copy_fault;
556                         tf->tf_tnpc = tf->tf_tpc + 4;
557                         return (0);
558                 }
559         }
560         return ((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
561 }
562
563 /* Maximum number of arguments that can be passed via the out registers. */
564 #define REG_MAXARGS     6
565
566 int
567 cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
568 {
569         struct trapframe *tf;
570         struct proc *p;
571         register_t *argp;
572         int reg;
573         int regcnt;
574         int error;
575
576         p = td->td_proc;
577         tf = td->td_frame;
578         reg = 0;
579         regcnt = REG_MAXARGS;
580
581         sa->code = tf->tf_global[1];
582
583         if (sa->code == SYS_syscall || sa->code == SYS___syscall) {
584                 sa->code = tf->tf_out[reg++];
585                 regcnt--;
586         }
587
588         if (p->p_sysent->sv_mask)
589                 sa->code &= p->p_sysent->sv_mask;
590         if (sa->code >= p->p_sysent->sv_size)
591                 sa->callp = &p->p_sysent->sv_table[0];
592         else
593                 sa->callp = &p->p_sysent->sv_table[sa->code];
594
595         sa->narg = sa->callp->sy_narg;
596         KASSERT(sa->narg <= sizeof(sa->args) / sizeof(sa->args[0]),
597             ("Too many syscall arguments!"));
598         error = 0;
599         argp = sa->args;
600         bcopy(&tf->tf_out[reg], sa->args, sizeof(sa->args[0]) * regcnt);
601         if (sa->narg > regcnt)
602                 error = copyin((void *)(tf->tf_out[6] + SPOFF +
603                     offsetof(struct frame, fr_pad[6])), &sa->args[regcnt],
604                     (sa->narg - regcnt) * sizeof(sa->args[0]));
605         if (error == 0) {
606                 td->td_retval[0] = 0;
607                 td->td_retval[1] = 0;
608         }
609
610         return (error);
611 }
612
613 #include "../../kern/subr_syscall.c"
614
615 /*
616  * Syscall handler. The arguments to the syscall are passed in the o registers
617  * by the caller, and are saved in the trap frame. The syscall number is passed
618  * in %g1 (and also saved in the trap frame).
619  */
620 void
621 syscall(struct trapframe *tf)
622 {
623         struct thread *td;
624         struct syscall_args sa;
625         int error;
626
627         td = curthread;
628         td->td_frame = tf;
629
630         KASSERT(td != NULL, ("trap: curthread NULL"));
631         KASSERT(td->td_proc != NULL, ("trap: curproc NULL"));
632
633         /*
634          * For syscalls, we don't want to retry the faulting instruction
635          * (usually), instead we need to advance one instruction.
636          */
637         td->td_pcb->pcb_tpc = tf->tf_tpc;
638         TF_DONE(tf);
639
640         error = syscallenter(td, &sa);
641         syscallret(td, error, &sa);
642 }
643