2 * Copyright (c) 2005 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "opt_ktrace.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/sysproto.h>
38 #include <sys/kernel.h>
42 #include <sys/mutex.h>
43 #include <sys/sched.h>
45 #include <sys/vmmeter.h>
46 #include <sys/sysent.h>
47 #include <sys/signalvar.h>
48 #include <sys/syscall.h>
49 #include <sys/pioctl.h>
50 #include <sys/ptrace.h>
51 #include <sys/sysctl.h>
53 #include <vm/vm_kern.h>
54 #include <vm/vm_page.h>
55 #include <vm/vm_map.h>
56 #include <vm/vm_extern.h>
57 #include <vm/vm_param.h>
58 #include <sys/ptrace.h>
59 #include <machine/cpu.h>
60 #include <machine/md_var.h>
61 #include <machine/reg.h>
62 #include <machine/pal.h>
63 #include <machine/fpu.h>
64 #include <machine/efi.h>
65 #include <machine/pcb.h>
67 #include <machine/smp.h>
72 #include <sys/ktrace.h>
75 #include <security/audit/audit.h>
77 #include <ia64/disasm/disasm.h>
79 static int print_usertrap = 0;
80 SYSCTL_INT(_machdep, OID_AUTO, print_usertrap,
81 CTLFLAG_RW, &print_usertrap, 0, "");
83 static void break_syscall(struct trapframe *tf);
86 * EFI-Provided FPSWA interface (Floating Point SoftWare Assist)
88 extern struct fpswa_iface *fpswa_iface;
90 extern char *syscallnames[];
92 static const char *ia64_vector_names[] = {
93 "VHPT Translation", /* 0 */
94 "Instruction TLB", /* 1 */
96 "Alternate Instruction TLB", /* 3 */
97 "Alternate Data TLB", /* 4 */
98 "Data Nested TLB", /* 5 */
99 "Instruction Key Miss", /* 6 */
100 "Data Key Miss", /* 7 */
102 "Instruction Access-Bit", /* 9 */
103 "Data Access-Bit", /* 10 */
104 "Break Instruction", /* 11 */
105 "External Interrupt", /* 12 */
106 "Reserved 13", /* 13 */
107 "Reserved 14", /* 14 */
108 "Reserved 15", /* 15 */
109 "Reserved 16", /* 16 */
110 "Reserved 17", /* 17 */
111 "Reserved 18", /* 18 */
112 "Reserved 19", /* 19 */
113 "Page Not Present", /* 20 */
114 "Key Permission", /* 21 */
115 "Instruction Access Rights", /* 22 */
116 "Data Access Rights", /* 23 */
117 "General Exception", /* 24 */
118 "Disabled FP-Register", /* 25 */
119 "NaT Consumption", /* 26 */
120 "Speculation", /* 27 */
121 "Reserved 28", /* 28 */
123 "Unaligned Reference", /* 30 */
124 "Unsupported Data Reference", /* 31 */
125 "Floating-point Fault", /* 32 */
126 "Floating-point Trap", /* 33 */
127 "Lower-Privilege Transfer Trap", /* 34 */
128 "Taken Branch Trap", /* 35 */
129 "Single Step Trap", /* 36 */
130 "Reserved 37", /* 37 */
131 "Reserved 38", /* 38 */
132 "Reserved 39", /* 39 */
133 "Reserved 40", /* 40 */
134 "Reserved 41", /* 41 */
135 "Reserved 42", /* 42 */
136 "Reserved 43", /* 43 */
137 "Reserved 44", /* 44 */
138 "IA-32 Exception", /* 45 */
139 "IA-32 Intercept", /* 46 */
140 "IA-32 Interrupt", /* 47 */
141 "Reserved 48", /* 48 */
142 "Reserved 49", /* 49 */
143 "Reserved 50", /* 50 */
144 "Reserved 51", /* 51 */
145 "Reserved 52", /* 52 */
146 "Reserved 53", /* 53 */
147 "Reserved 54", /* 54 */
148 "Reserved 55", /* 55 */
149 "Reserved 56", /* 56 */
150 "Reserved 57", /* 57 */
151 "Reserved 58", /* 58 */
152 "Reserved 59", /* 59 */
153 "Reserved 60", /* 60 */
154 "Reserved 61", /* 61 */
155 "Reserved 62", /* 62 */
156 "Reserved 63", /* 63 */
157 "Reserved 64", /* 64 */
158 "Reserved 65", /* 65 */
159 "Reserved 66", /* 66 */
160 "Reserved 67", /* 67 */
169 printbits(uint64_t mask, struct bitname *bn, int count)
174 for (i = 0; i < count; i++) {
176 * Handle fields wider than one bit.
178 bit = bn[i].mask & ~(bn[i].mask - 1);
179 if (bn[i].mask > bit) {
184 printf("%s=%ld", bn[i].name,
185 (mask & bn[i].mask) / bit);
186 } else if (mask & bit) {
191 printf("%s", bn[i].name);
196 struct bitname psr_bits[] = {
200 {IA64_PSR_MFL, "mfl"},
201 {IA64_PSR_MFH, "mfh"},
206 {IA64_PSR_DFL, "dfl"},
207 {IA64_PSR_DFH, "dfh"},
216 {IA64_PSR_CPL, "cpl"},
231 printpsr(uint64_t psr)
233 printbits(psr, psr_bits, sizeof(psr_bits)/sizeof(psr_bits[0]));
236 struct bitname isr_bits[] = {
237 {IA64_ISR_CODE, "code"},
238 {IA64_ISR_VECTOR, "vector"},
252 static void printisr(uint64_t isr)
254 printbits(isr, isr_bits, sizeof(isr_bits)/sizeof(isr_bits[0]));
258 printtrap(int vector, struct trapframe *tf, int isfatal, int user)
261 printf("%s %s trap (cpu %d):\n", isfatal? "fatal" : "handled",
262 user ? "user" : "kernel", PCPU_GET(cpuid));
264 printf(" trap vector = 0x%x (%s)\n",
265 vector, ia64_vector_names[vector]);
266 printf(" cr.iip = 0x%lx\n", tf->tf_special.iip);
267 printf(" cr.ipsr = 0x%lx (", tf->tf_special.psr);
268 printpsr(tf->tf_special.psr);
270 printf(" cr.isr = 0x%lx (", tf->tf_special.isr);
271 printisr(tf->tf_special.isr);
273 printf(" cr.ifa = 0x%lx\n", tf->tf_special.ifa);
274 if (tf->tf_special.psr & IA64_PSR_IS) {
275 printf(" ar.cflg = 0x%lx\n", ia64_get_cflg());
276 printf(" ar.csd = 0x%lx\n", ia64_get_csd());
277 printf(" ar.ssd = 0x%lx\n", ia64_get_ssd());
279 printf(" curthread = %p\n", curthread);
280 if (curthread != NULL)
281 printf(" pid = %d, comm = %s\n",
282 curthread->td_proc->p_pid, curthread->td_name);
287 * We got a trap caused by a break instruction and the immediate was 0.
288 * This indicates that we may have a break.b with some non-zero immediate.
289 * The break.b doesn't cause the immediate to be put in cr.iim. Hence,
290 * we need to disassemble the bundle and return the immediate found there.
291 * This may be a 0 value anyway. Return 0 for any error condition. This
292 * will result in a SIGILL, which is pretty much the best thing to do.
295 trap_decode_break(struct trapframe *tf)
297 struct asm_bundle bundle;
298 struct asm_inst *inst;
301 if (!asm_decode(tf->tf_special.iip, &bundle))
304 slot = ((tf->tf_special.psr & IA64_PSR_RI) == IA64_PSR_RI_0) ? 0 :
305 ((tf->tf_special.psr & IA64_PSR_RI) == IA64_PSR_RI_1) ? 1 : 2;
306 inst = bundle.b_inst + slot;
309 * Sanity checking: It must be a break instruction and the operand
310 * that has the break value must be an immediate.
312 if (inst->i_op != ASM_OP_BREAK ||
313 inst->i_oper[1].o_type != ASM_OPER_IMM)
316 return (inst->i_oper[1].o_value);
320 trap_panic(int vector, struct trapframe *tf)
323 printtrap(vector, tf, 1, TRAPF_USERMODE(tf));
325 kdb_trap(vector, 0, tf);
334 do_ast(struct trapframe *tf)
338 while (curthread->td_flags & (TDF_ASTPENDING|TDF_NEEDRESCHED)) {
344 * Keep interrupts disabled. We return r10 as a favor to the EPC
345 * syscall code so that it can quicky determine if the syscall
346 * needs to be restarted or not.
348 return (tf->tf_scratch.gr10);
352 * Trap is called from exception.s to handle most types of processor traps.
356 trap(int vector, struct trapframe *tf)
361 int error, sig, user;
364 user = TRAPF_USERMODE(tf) ? 1 : 0;
366 PCPU_INC(cnt.v_trap);
373 ia64_set_fpsr(IA64_FPSR_DEFAULT);
376 if (td->td_ucred != p->p_ucred)
377 cred_update_thread(td);
379 KASSERT(cold || td->td_ucred != NULL,
380 ("kernel trap doesn't have ucred"));
391 * This one is tricky. We should hardwire the VHPT, but
392 * don't at this time. I think we're mostly lucky that
393 * the VHPT is mapped.
395 trap_panic(vector, tf);
400 case IA64_VEC_EXT_INTR:
401 /* We never call trap() with these vectors. */
402 trap_panic(vector, tf);
405 case IA64_VEC_ALT_ITLB:
406 case IA64_VEC_ALT_DTLB:
408 * These should never happen, because regions 0-4 use the
409 * VHPT. If we get one of these it means we didn't program
410 * the region registers correctly.
412 trap_panic(vector, tf);
415 case IA64_VEC_NESTED_DTLB:
417 * When the nested TLB handler encounters an unexpected
418 * condition, it'll switch to the backup stack and transfer
419 * here. All we need to do is panic.
421 trap_panic(vector, tf);
424 case IA64_VEC_IKEY_MISS:
425 case IA64_VEC_DKEY_MISS:
426 case IA64_VEC_KEY_PERMISSION:
428 * We don't use protection keys, so we should never get
431 trap_panic(vector, tf);
434 case IA64_VEC_DIRTY_BIT:
435 case IA64_VEC_INST_ACCESS:
436 case IA64_VEC_DATA_ACCESS:
438 * We get here if we read or write to a page of which the
439 * PTE does not have the access bit or dirty bit set and
440 * we can not find the PTE in our datastructures. This
441 * either means we have a stale PTE in the TLB, or we lost
442 * the PTE in our datastructures.
444 trap_panic(vector, tf);
449 ucode = (int)tf->tf_special.ifa & 0x1FFFFF;
452 * A break.b doesn't cause the immediate to be
453 * stored in cr.iim (and saved in the TF in
454 * tf_special.ifa). We need to decode the
455 * instruction to find out what the immediate
456 * was. Note that if the break instruction
457 * didn't happen to be a break.b, but any
458 * other break with an immediate of 0, we
459 * will do unnecessary work to get the value
460 * we already had. Not an issue, because a
461 * break 0 is invalid.
463 ucode = trap_decode_break(tf);
465 if (ucode < 0x80000) {
466 /* Software interrupts. */
468 case 0: /* Unknown error. */
471 case 1: /* Integer divide by zero. */
475 case 2: /* Integer overflow. */
479 case 3: /* Range check/bounds check. */
483 case 6: /* Decimal overflow. */
484 case 7: /* Decimal divide by zero. */
485 case 8: /* Packed decimal error. */
486 case 9: /* Invalid ASCII digit. */
487 case 10: /* Invalid decimal digit. */
491 case 4: /* Null pointer dereference. */
492 case 5: /* Misaligned data. */
493 case 11: /* Paragraph stack overflow. */
500 } else if (ucode < 0x100000) {
501 /* Debugger breakpoint. */
502 tf->tf_special.psr &= ~IA64_PSR_SS;
504 } else if (ucode == 0x100000) {
506 return; /* do_ast() already called. */
507 } else if (ucode == 0x180000) {
510 error = copyin((void*)tf->tf_scratch.gr8,
513 set_mcontext(td, &mc);
514 return; /* Don't call do_ast()!!! */
517 ucode = tf->tf_scratch.gr8;
522 if (kdb_trap(vector, 0, tf))
526 trap_panic(vector, tf);
531 case IA64_VEC_PAGE_NOT_PRESENT:
532 case IA64_VEC_INST_ACCESS_RIGHTS:
533 case IA64_VEC_DATA_ACCESS_RIGHTS: {
541 va = trunc_page(tf->tf_special.ifa);
543 if (va >= VM_MAX_ADDRESS) {
545 * Don't allow user-mode faults for kernel virtual
546 * addresses, including the gateway page.
552 vm = (p != NULL) ? p->p_vmspace : NULL;
558 if (tf->tf_special.isr & IA64_ISR_X)
559 ftype = VM_PROT_EXECUTE;
560 else if (tf->tf_special.isr & IA64_ISR_W)
561 ftype = VM_PROT_WRITE;
563 ftype = VM_PROT_READ;
565 if (map != kernel_map) {
567 * Keep swapout from messing with us during this
574 /* Fault in the user page: */
575 rv = vm_fault(map, va, ftype, (ftype & VM_PROT_WRITE)
576 ? VM_FAULT_DIRTY : VM_FAULT_NORMAL);
583 * Don't have to worry about process locking or
584 * stacks in the kernel.
586 rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
589 if (rv == KERN_SUCCESS)
594 /* Check for copyin/copyout fault. */
595 if (td != NULL && td->td_pcb->pcb_onfault != 0) {
597 td->td_pcb->pcb_onfault;
598 tf->tf_special.psr &= ~IA64_PSR_RI;
599 td->td_pcb->pcb_onfault = 0;
602 trap_panic(vector, tf);
605 sig = (rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV;
609 case IA64_VEC_GENERAL_EXCEPTION: {
613 trap_panic(vector, tf);
615 code = tf->tf_special.isr & (IA64_ISR_CODE & 0xf0ull);
617 case 0x0: /* Illegal Operation Fault. */
618 sig = ia64_emulate(tf, td);
630 case IA64_VEC_SPECULATION:
632 * The branching behaviour of the chk instruction is not
633 * implemented by the processor. All we need to do is
634 * compute the target address of the branch and make sure
635 * that control is transfered to that address.
636 * We should do this in the IVT table and not by entring
639 tf->tf_special.iip += tf->tf_special.ifa << 4;
640 tf->tf_special.psr &= ~IA64_PSR_RI;
643 case IA64_VEC_NAT_CONSUMPTION:
644 case IA64_VEC_UNSUPP_DATA_REFERENCE:
649 trap_panic(vector, tf);
652 case IA64_VEC_DISABLED_FP: {
654 ia64_highfp_enable(td, tf);
656 trap_panic(vector, tf);
661 case IA64_VEC_SINGLE_STEP_TRAP:
662 tf->tf_special.psr &= ~IA64_PSR_SS;
665 if (kdb_trap(vector, 0, tf))
669 trap_panic(vector, tf);
675 case IA64_VEC_UNALIGNED_REFERENCE:
677 * If user-land, do whatever fixups, printing, and
678 * signalling is appropriate (based on system-wide
679 * and per-process unaligned-access-handling flags).
682 sig = unaligned_fixup(tf, td);
685 ucode = tf->tf_special.ifa; /* VA */
687 /* Check for copyin/copyout fault. */
688 if (td != NULL && td->td_pcb->pcb_onfault != 0) {
690 td->td_pcb->pcb_onfault;
691 tf->tf_special.psr &= ~IA64_PSR_RI;
692 td->td_pcb->pcb_onfault = 0;
695 trap_panic(vector, tf);
699 case IA64_VEC_FLOATING_POINT_FAULT:
700 case IA64_VEC_FLOATING_POINT_TRAP: {
701 struct fpswa_bundle bundle;
702 struct fpswa_fpctx fpctx;
703 struct fpswa_ret ret;
707 /* Always fatal in kernel. Should never happen. */
709 trap_panic(vector, tf);
711 if (fpswa_iface == NULL) {
717 ip = (char *)tf->tf_special.iip;
718 if (vector == IA64_VEC_FLOATING_POINT_TRAP &&
719 (tf->tf_special.psr & IA64_PSR_RI) == 0)
721 error = copyin(ip, &bundle, sizeof(bundle));
723 sig = SIGBUS; /* EFAULT, basically */
724 ucode = 0; /* exception summary */
728 /* f6-f15 are saved in exception_save */
729 fpctx.mask_low = 0xffc0; /* bits 6 - 15 */
731 fpctx.fp_low_preserved = NULL;
732 fpctx.fp_low_volatile = &tf->tf_scratch_fp.fr6;
733 fpctx.fp_high_preserved = NULL;
734 fpctx.fp_high_volatile = NULL;
736 fault = (vector == IA64_VEC_FLOATING_POINT_FAULT) ? 1 : 0;
739 * We have the high FP registers disabled while in the
740 * kernel. Enable them for the FPSWA handler only.
742 ia64_enable_highfp();
744 /* The docs are unclear. Is Fpswa reentrant? */
745 ret = fpswa_iface->if_fpswa(fault, &bundle,
746 &tf->tf_special.psr, &tf->tf_special.fpsr,
747 &tf->tf_special.isr, &tf->tf_special.pr,
748 &tf->tf_special.cfm, &fpctx);
750 ia64_disable_highfp();
753 * Update ipsr and iip to next instruction. We only
754 * have to do that for faults.
756 if (fault && (ret.status == 0 || (ret.status & 2))) {
759 ei = (tf->tf_special.isr >> 41) & 0x03;
760 if (ei == 0) { /* no template for this case */
761 tf->tf_special.psr &= ~IA64_ISR_EI;
762 tf->tf_special.psr |= IA64_ISR_EI_1;
763 } else if (ei == 1) { /* MFI or MFB */
764 tf->tf_special.psr &= ~IA64_ISR_EI;
765 tf->tf_special.psr |= IA64_ISR_EI_2;
766 } else if (ei == 2) { /* MMF */
767 tf->tf_special.psr &= ~IA64_ISR_EI;
768 tf->tf_special.iip += 0x10;
772 if (ret.status == 0) {
774 } else if (ret.status == -1) {
775 printf("FATAL: FPSWA err1 %lx, err2 %lx, err3 %lx\n",
776 ret.err1, ret.err2, ret.err3);
777 panic("fpswa fatal error on fp fault");
780 ucode = 0; /* XXX exception summary */
785 case IA64_VEC_LOWER_PRIVILEGE_TRANSFER:
787 * The lower-privilege transfer trap is used by the EPC
788 * syscall code to trigger re-entry into the kernel when the
789 * process should be single stepped. The problem is that
790 * there's no way to set single stepping directly without
791 * using the rfi instruction. So instead we enable the
792 * lower-privilege transfer trap and when we get here we
793 * know that the process is about to enter userland (and
794 * has already lowered its privilege).
795 * However, there's another gotcha. When the process has
796 * lowered it's privilege it's still running in the gateway
797 * page. If we enable single stepping, we'll be stepping
798 * the code in the gateway page. In and by itself this is
799 * not a problem, but it's an address debuggers won't know
800 * anything about. Hence, it can only cause confusion.
801 * We know that we need to branch to get out of the gateway
802 * page, so what we do here is enable the taken branch
803 * trap and just let the process continue. When we branch
804 * out of the gateway page we'll get back into the kernel
805 * and then we enable single stepping.
806 * Since this a rather round-about way of enabling single
807 * stepping, don't make things even more complicated by
808 * calling userret() and do_ast(). We do that later...
810 tf->tf_special.psr &= ~IA64_PSR_LP;
811 tf->tf_special.psr |= IA64_PSR_TB;
814 case IA64_VEC_TAKEN_BRANCH_TRAP:
816 * Don't assume there aren't any branches other than the
817 * branch that takes us out of the gateway page. Check the
818 * iip and enable single stepping only when it's an user
821 if (tf->tf_special.iip >= VM_MAX_ADDRESS)
823 tf->tf_special.psr &= ~IA64_PSR_TB;
824 tf->tf_special.psr |= IA64_PSR_SS;
827 case IA64_VEC_IA32_EXCEPTION:
828 case IA64_VEC_IA32_INTERCEPT:
829 case IA64_VEC_IA32_INTERRUPT:
831 ucode = tf->tf_special.iip;
835 /* Reserved vectors get here. Should never happen of course. */
836 trap_panic(vector, tf);
840 KASSERT(sig != 0, ("foo"));
843 printtrap(vector, tf, 1, user);
847 ksi.ksi_code = ucode;
848 trapsignal(td, &ksi);
853 mtx_assert(&Giant, MA_NOTOWNED);
860 * Handle break instruction based system calls.
863 break_syscall(struct trapframe *tf)
869 /* Save address of break instruction. */
870 iip = tf->tf_special.iip;
871 psr = tf->tf_special.psr;
873 /* Advance to the next instruction. */
874 tf->tf_special.psr += IA64_PSR_RI_1;
875 if ((tf->tf_special.psr & IA64_PSR_RI) > IA64_PSR_RI_2) {
876 tf->tf_special.iip += 16;
877 tf->tf_special.psr &= ~IA64_PSR_RI;
881 * Copy the arguments on the register stack into the trapframe
882 * to avoid having interleaved NaT collections.
884 tfp = &tf->tf_scratch.gr16;
885 nargs = tf->tf_special.cfm & 0x7f;
886 bsp = (uint64_t*)(curthread->td_kstack + tf->tf_special.ndirty +
887 (tf->tf_special.bspstore & 0x1ffUL));
888 bsp -= (((uintptr_t)bsp & 0x1ff) < (nargs << 3)) ? (nargs + 1): nargs;
891 if (((uintptr_t)bsp & 0x1ff) == 0x1f8)
895 if (error == ERESTART) {
896 tf->tf_special.iip = iip;
897 tf->tf_special.psr = psr;
904 * Process a system call.
906 * See syscall.s for details as to how we get here. In order to support
907 * the ERESTART case, we return the error to our caller. They deal with
911 syscall(struct trapframe *tf)
913 struct sysent *callp;
919 ia64_set_fpsr(IA64_FPSR_DEFAULT);
921 code = tf->tf_scratch.gr15;
922 args = &tf->tf_scratch.gr16;
924 PCPU_INC(cnt.v_syscall);
931 if (td->td_ucred != p->p_ucred)
932 cred_update_thread(td);
934 if (p->p_sysent->sv_prepsyscall) {
935 /* (*p->p_sysent->sv_prepsyscall)(tf, args, &code, ¶ms); */
936 panic("prepsyscall");
939 * syscall() and __syscall() are handled the same on
940 * the ia64, as everything is 64-bit aligned, anyway.
942 if (code == SYS_syscall || code == SYS___syscall) {
944 * Code is first argument, followed by actual args.
951 if (p->p_sysent->sv_mask)
952 code &= p->p_sysent->sv_mask;
954 if (code >= p->p_sysent->sv_size)
955 callp = &p->p_sysent->sv_table[0];
957 callp = &p->p_sysent->sv_table[code];
960 if (KTRPOINT(td, KTR_SYSCALL))
961 ktrsyscall(code, callp->sy_narg, args);
963 CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td,
964 td->td_proc->p_pid, td->td_name, code);
966 td->td_retval[0] = 0;
967 td->td_retval[1] = 0;
968 tf->tf_scratch.gr10 = EJUSTRETURN;
970 STOPEVENT(p, S_SCE, callp->sy_narg);
972 PTRACESTOP_SC(p, td, S_PT_SCE);
974 AUDIT_SYSCALL_ENTER(code, td);
975 error = (*callp->sy_call)(td, args);
976 AUDIT_SYSCALL_EXIT(error, td);
978 cpu_set_syscall_retval(td, error);
982 * Check for misbehavior.
984 WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning",
985 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???");
986 KASSERT(td->td_critnest == 0,
987 ("System call %s returning in a critical section",
988 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"));
989 KASSERT(td->td_locks == 0,
990 ("System call %s returning with %d locks held",
991 (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???",
995 * Handle reschedule and other end-of-syscall issues
999 CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td,
1000 td->td_proc->p_pid, td->td_name, code);
1002 if (KTRPOINT(td, KTR_SYSRET))
1003 ktrsysret(code, error, td->td_retval[0]);
1007 * This works because errno is findable through the
1008 * register set. If we ever support an emulation where this
1009 * is not the case, this code will need to be revisited.
1011 STOPEVENT(p, S_SCX, code);
1013 PTRACESTOP_SC(p, td, S_PT_SCX);