1 /* $NetBSD: fault.c,v 1.45 2003/11/20 14:44:36 scw Exp $ */
4 * Copyright 2004 Olivier Houchard
5 * Copyright 2003 Wasabi Systems, Inc.
8 * Written by Steve C. Woodford for Wasabi Systems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * 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 WASABI SYSTEMS, INC
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.
39 * Copyright (c) 1994-1997 Mark Brinicombe.
40 * Copyright (c) 1994 Brini.
41 * All rights reserved.
43 * This code is derived from software written for Brini by Mark Brinicombe
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
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 Brini.
56 * 4. The name of the company nor the name of the author may be used to
57 * endorse or promote products derived from this software without specific
58 * prior written permission.
60 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
61 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * RiscBSD kernel project
82 #include "opt_ktrace.h"
84 #include <sys/cdefs.h>
85 __FBSDID("$FreeBSD$");
87 #include <sys/param.h>
89 #include <sys/systm.h>
91 #include <sys/kernel.h>
93 #include <sys/mutex.h>
94 #include <sys/syscall.h>
95 #include <sys/sysent.h>
96 #include <sys/signalvar.h>
100 #include <sys/ktrace.h>
102 #include <sys/ptrace.h>
103 #include <sys/pioctl.h>
107 #include <vm/vm_kern.h>
108 #include <vm/vm_map.h>
109 #include <vm/vm_extern.h>
111 #include <machine/armreg.h>
112 #include <machine/cpuconf.h>
113 #include <machine/vmparam.h>
114 #include <machine/frame.h>
115 #include <machine/cpu.h>
116 #include <machine/intr.h>
117 #include <machine/pcb.h>
118 #include <machine/proc.h>
119 #include <machine/swi.h>
121 #include <security/audit/audit.h>
128 void swi_handler(struct trapframe *);
130 #include <machine/disassem.h>
131 #include <machine/machdep.h>
133 extern char fusubailout[];
136 int last_fault_code; /* For the benefit of pmap_fault_fixup() */
144 int (*func)(struct trapframe *, u_int, u_int, struct thread *,
149 static int dab_fatal(struct trapframe *, u_int, u_int, struct thread *,
151 static int dab_align(struct trapframe *, u_int, u_int, struct thread *,
153 static int dab_buserr(struct trapframe *, u_int, u_int, struct thread *,
156 static const struct data_abort data_aborts[] = {
157 {dab_fatal, "Vector Exception"},
158 {dab_align, "Alignment Fault 1"},
159 {dab_fatal, "Terminal Exception"},
160 {dab_align, "Alignment Fault 3"},
161 {dab_buserr, "External Linefetch Abort (S)"},
162 {NULL, "Translation Fault (S)"},
163 #if (ARM_MMU_V6 + ARM_MMU_V7) != 0
164 {NULL, "Translation Flag Fault"},
166 {dab_buserr, "External Linefetch Abort (P)"},
168 {NULL, "Translation Fault (P)"},
169 {dab_buserr, "External Non-Linefetch Abort (S)"},
170 {NULL, "Domain Fault (S)"},
171 {dab_buserr, "External Non-Linefetch Abort (P)"},
172 {NULL, "Domain Fault (P)"},
173 {dab_buserr, "External Translation Abort (L1)"},
174 {NULL, "Permission Fault (S)"},
175 {dab_buserr, "External Translation Abort (L2)"},
176 {NULL, "Permission Fault (P)"}
179 /* Determine if a fault came from user mode */
180 #define TRAP_USERMODE(tf) ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE)
182 /* Determine if 'x' is a permission fault */
183 #define IS_PERMISSION_FAULT(x) \
184 (((1 << ((x) & FAULT_TYPE_MASK)) & \
185 ((1 << FAULT_PERM_P) | (1 << FAULT_PERM_S))) != 0)
188 call_trapsignal(struct thread *td, int sig, u_long code)
192 ksiginfo_init_trap(&ksi);
194 ksi.ksi_code = (int)code;
195 trapsignal(td, &ksi);
199 data_abort_handler(struct trapframe *tf)
204 u_int user, far, fsr;
213 /* Grab FAR/FSR before enabling interrupts */
214 far = cpu_faultaddress();
215 fsr = cpu_faultstatus();
217 printf("data abort: fault address=%p (from pc=%p lr=%p)\n",
218 (void*)far, (void*)tf->tf_pc, (void*)tf->tf_svc_lr);
221 /* Update vmmeter statistics */
229 PCPU_INC(cnt.v_trap);
230 /* Data abort came from user mode? */
231 user = TRAP_USERMODE(tf);
236 if (td->td_ucred != td->td_proc->p_ucred)
237 cred_update_thread(td);
240 /* Grab the current pcb */
242 /* Re-enable interrupts if they were enabled previously */
243 if (td->td_md.md_spinlock_count == 0) {
244 if (__predict_true(tf->tf_spsr & PSR_I) == 0)
245 enable_interrupts(PSR_I);
246 if (__predict_true(tf->tf_spsr & PSR_F) == 0)
247 enable_interrupts(PSR_F);
251 /* Invoke the appropriate handler, if necessary */
252 if (__predict_false(data_aborts[fsr & FAULT_TYPE_MASK].func != NULL)) {
253 if ((data_aborts[fsr & FAULT_TYPE_MASK].func)(tf, fsr, far,
261 * At this point, we're dealing with one of the following data aborts:
263 * FAULT_TRANS_S - Translation -- Section
264 * FAULT_TRANS_P - Translation -- Page
265 * FAULT_DOMAIN_S - Domain -- Section
266 * FAULT_DOMAIN_P - Domain -- Page
267 * FAULT_PERM_S - Permission -- Section
268 * FAULT_PERM_P - Permission -- Page
270 * These are the main virtual memory-related faults signalled by
274 /* fusubailout is used by [fs]uswintr to avoid page faulting */
275 if (__predict_false(pcb->pcb_onfault == fusubailout)) {
277 tf->tf_pc = (register_t)(intptr_t) pcb->pcb_onfault;
282 * Make sure the Program Counter is sane. We could fall foul of
283 * someone executing Thumb code, in which case the PC might not
284 * be word-aligned. This would cause a kernel alignment fault
285 * further down if we have to decode the current instruction.
286 * XXX: It would be nice to be able to support Thumb at some point.
288 if (__predict_false((tf->tf_pc & 3) != 0)) {
291 * Give the user an illegal instruction signal.
293 /* Deliver a SIGILL to the process */
300 * The kernel never executes Thumb code.
302 printf("\ndata_abort_fault: Misaligned Kernel-mode "
303 "Program Counter\n");
304 dab_fatal(tf, fsr, far, td, &ksig);
307 va = trunc_page((vm_offset_t)far);
310 * It is only a kernel address space fault iff:
312 * 2. pcb_onfault not set or
313 * 3. pcb_onfault set and not LDRT/LDRBT/STRT/STRBT instruction.
315 if (user == 0 && (va >= VM_MIN_KERNEL_ADDRESS ||
316 (va < VM_MIN_ADDRESS && vector_page == ARM_VECTORS_LOW)) &&
317 __predict_true((pcb->pcb_onfault == NULL ||
318 (ReadWord(tf->tf_pc) & 0x05200000) != 0x04200000))) {
321 /* Was the fault due to the FPE/IPKDB ? */
322 if (__predict_false((tf->tf_spsr & PSR_MODE)==PSR_UND32_MODE)) {
325 * Force exit via userret()
326 * This is necessary as the FPE is an extension to
327 * userland that actually runs in a priveledged mode
328 * but uses USR mode permissions for its accesses.
331 ksig.signb = SIGSEGV;
336 map = &td->td_proc->p_vmspace->vm_map;
340 * We need to know whether the page should be mapped as R or R/W. On
341 * armv6 and later the fault status register indicates whether the
342 * access was a read or write. Prior to armv6, we know that a
343 * permission fault can only be the result of a write to a read-only
344 * location, so we can deal with those quickly. Otherwise we need to
345 * disassemble the faulting instruction to determine if it was a write.
347 #if ARM_ARCH_6 || ARM_ARCH_7A
348 ftype = (fsr & FAULT_WNR) ? VM_PROT_READ | VM_PROT_WRITE : VM_PROT_READ;
350 if (IS_PERMISSION_FAULT(fsr))
351 ftype = VM_PROT_WRITE;
353 u_int insn = ReadWord(tf->tf_pc);
355 if (((insn & 0x0c100000) == 0x04000000) || /* STR/STRB */
356 ((insn & 0x0e1000b0) == 0x000000b0) || /* STRH/STRD */
357 ((insn & 0x0a100000) == 0x08000000)) { /* STM/CDT */
358 ftype = VM_PROT_WRITE;
360 if ((insn & 0x0fb00ff0) == 0x01000090) /* SWP */
361 ftype = VM_PROT_READ | VM_PROT_WRITE;
363 ftype = VM_PROT_READ;
369 * See if the fault is as a result of ref/mod emulation,
370 * or domain mismatch.
373 last_fault_code = fsr;
375 if (pmap_fault_fixup(vmspace_pmap(td->td_proc->p_vmspace), va, ftype,
380 onfault = pcb->pcb_onfault;
381 pcb->pcb_onfault = NULL;
382 if (map != kernel_map) {
387 error = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
388 pcb->pcb_onfault = onfault;
390 if (map != kernel_map) {
395 if (__predict_true(error == 0))
398 if (pcb->pcb_onfault) {
400 tf->tf_pc = (register_t)(intptr_t) pcb->pcb_onfault;
404 printf("\nvm_fault(%p, %x, %x, 0) -> %x\n", map, va, ftype,
406 dab_fatal(tf, fsr, far, td, &ksig);
410 if (error == ENOMEM) {
411 printf("VM: pid %d (%s), uid %d killed: "
412 "out of swap\n", td->td_proc->p_pid, td->td_name,
413 (td->td_proc->p_ucred) ?
414 td->td_proc->p_ucred->cr_uid : -1);
415 ksig.signb = SIGKILL;
417 ksig.signb = SIGSEGV;
421 call_trapsignal(td, ksig.signb, ksig.code);
423 /* If returning to user mode, make sure to invoke userret() */
429 * dab_fatal() handles the following data aborts:
431 * FAULT_WRTBUF_0 - Vector Exception
432 * FAULT_WRTBUF_1 - Terminal Exception
434 * We should never see these on a properly functioning system.
436 * This function is also called by the other handlers if they
437 * detect a fatal problem.
439 * Note: If 'l' is NULL, we assume we're dealing with a prefetch abort.
442 dab_fatal(struct trapframe *tf, u_int fsr, u_int far, struct thread *td,
447 mode = TRAP_USERMODE(tf) ? "user" : "kernel";
449 disable_interrupts(PSR_I|PSR_F);
451 printf("Fatal %s mode data abort: '%s'\n", mode,
452 data_aborts[fsr & FAULT_TYPE_MASK].desc);
453 printf("trapframe: %p\nFSR=%08x, FAR=", tf, fsr);
454 if ((fsr & FAULT_IMPRECISE) == 0)
455 printf("%08x, ", far);
458 printf("spsr=%08x\n", tf->tf_spsr);
460 printf("Fatal %s mode prefetch abort at 0x%08x\n",
462 printf("trapframe: %p, spsr=%08x\n", tf, tf->tf_spsr);
465 printf("r0 =%08x, r1 =%08x, r2 =%08x, r3 =%08x\n",
466 tf->tf_r0, tf->tf_r1, tf->tf_r2, tf->tf_r3);
467 printf("r4 =%08x, r5 =%08x, r6 =%08x, r7 =%08x\n",
468 tf->tf_r4, tf->tf_r5, tf->tf_r6, tf->tf_r7);
469 printf("r8 =%08x, r9 =%08x, r10=%08x, r11=%08x\n",
470 tf->tf_r8, tf->tf_r9, tf->tf_r10, tf->tf_r11);
471 printf("r12=%08x, ", tf->tf_r12);
473 if (TRAP_USERMODE(tf))
474 printf("usp=%08x, ulr=%08x",
475 tf->tf_usr_sp, tf->tf_usr_lr);
477 printf("ssp=%08x, slr=%08x",
478 tf->tf_svc_sp, tf->tf_svc_lr);
479 printf(", pc =%08x\n\n", tf->tf_pc);
482 if (debugger_on_panic || kdb_active)
483 if (kdb_trap(fsr, 0, tf))
486 panic("Fatal abort");
491 * dab_align() handles the following data aborts:
493 * FAULT_ALIGN_0 - Alignment fault
494 * FAULT_ALIGN_1 - Alignment fault
496 * These faults are fatal if they happen in kernel mode. Otherwise, we
497 * deliver a bus error to the process.
500 dab_align(struct trapframe *tf, u_int fsr, u_int far, struct thread *td,
504 /* Alignment faults are always fatal if they occur in kernel mode */
505 if (!TRAP_USERMODE(tf)) {
506 if (!td || !td->td_pcb->pcb_onfault)
507 dab_fatal(tf, fsr, far, td, ksig);
509 tf->tf_pc = (int)td->td_pcb->pcb_onfault;
513 /* pcb_onfault *must* be NULL at this point */
515 /* Deliver a bus error signal to the process */
517 ksig->signb = SIGBUS;
524 * dab_buserr() handles the following data aborts:
526 * FAULT_BUSERR_0 - External Abort on Linefetch -- Section
527 * FAULT_BUSERR_1 - External Abort on Linefetch -- Page
528 * FAULT_BUSERR_2 - External Abort on Non-linefetch -- Section
529 * FAULT_BUSERR_3 - External Abort on Non-linefetch -- Page
530 * FAULT_BUSTRNL1 - External abort on Translation -- Level 1
531 * FAULT_BUSTRNL2 - External abort on Translation -- Level 2
533 * If pcb_onfault is set, flag the fault and return to the handler.
534 * If the fault occurred in user mode, give the process a SIGBUS.
536 * Note: On XScale, FAULT_BUSERR_0, FAULT_BUSERR_1, and FAULT_BUSERR_2
537 * can be flagged as imprecise in the FSR. This causes a real headache
538 * since some of the machine state is lost. In this case, tf->tf_pc
539 * may not actually point to the offending instruction. In fact, if
540 * we've taken a double abort fault, it generally points somewhere near
541 * the top of "data_abort_entry" in exception.S.
543 * In all other cases, these data aborts are considered fatal.
546 dab_buserr(struct trapframe *tf, u_int fsr, u_int far, struct thread *td,
549 struct pcb *pcb = td->td_pcb;
552 if ((fsr & FAULT_IMPRECISE) != 0 &&
553 (tf->tf_spsr & PSR_MODE) == PSR_ABT32_MODE) {
555 * Oops, an imprecise, double abort fault. We've lost the
556 * r14_abt/spsr_abt values corresponding to the original
557 * abort, and the spsr saved in the trapframe indicates
560 tf->tf_spsr &= ~PSR_MODE;
563 * We use a simple heuristic to determine if the double abort
564 * happened as a result of a kernel or user mode access.
565 * If the current trapframe is at the top of the kernel stack,
566 * the fault _must_ have come from user mode.
568 if (tf != ((struct trapframe *)pcb->un_32.pcb32_sp) - 1) {
570 * Kernel mode. We're either about to die a
571 * spectacular death, or pcb_onfault will come
572 * to our rescue. Either way, the current value
573 * of tf->tf_pc is irrelevant.
575 tf->tf_spsr |= PSR_SVC32_MODE;
576 if (pcb->pcb_onfault == NULL)
577 printf("\nKernel mode double abort!\n");
580 * User mode. We've lost the program counter at the
581 * time of the fault (not that it was accurate anyway;
582 * it's not called an imprecise fault for nothing).
583 * About all we can do is copy r14_usr to tf_pc and
584 * hope for the best. The process is about to get a
585 * SIGBUS, so it's probably history anyway.
587 tf->tf_spsr |= PSR_USR32_MODE;
588 tf->tf_pc = tf->tf_usr_lr;
592 /* FAR is invalid for imprecise exceptions */
593 if ((fsr & FAULT_IMPRECISE) != 0)
595 #endif /* __XSCALE__ */
597 if (pcb->pcb_onfault) {
599 tf->tf_pc = (register_t)(intptr_t) pcb->pcb_onfault;
604 * At this point, if the fault happened in kernel mode, we're toast
606 if (!TRAP_USERMODE(tf))
607 dab_fatal(tf, fsr, far, td, ksig);
609 /* Deliver a bus error signal to the process */
610 ksig->signb = SIGBUS;
618 * void prefetch_abort_handler(struct trapframe *tf)
620 * Abort handler called when instruction execution occurs at
621 * a non existent or restricted (access permissions) memory page.
622 * If the address is invalid and we were in SVC mode then panic as
623 * the kernel should never prefetch abort.
624 * If the address is invalid and the page is mapped then the user process
625 * does no have read permission so send it a signal.
626 * Otherwise fault the page in and try again.
629 prefetch_abort_handler(struct trapframe *tf)
634 vm_offset_t fault_pc, va;
640 /* Update vmmeter statistics */
644 printf("prefetch abort handler: %p %p\n", (void*)tf->tf_pc,
645 (void*)tf->tf_usr_lr);
650 PCPU_INC(cnt.v_trap);
652 if (TRAP_USERMODE(tf)) {
654 if (td->td_ucred != td->td_proc->p_ucred)
655 cred_update_thread(td);
657 fault_pc = tf->tf_pc;
658 if (td->td_md.md_spinlock_count == 0) {
659 if (__predict_true(tf->tf_spsr & PSR_I) == 0)
660 enable_interrupts(PSR_I);
661 if (__predict_true(tf->tf_spsr & PSR_F) == 0)
662 enable_interrupts(PSR_F);
665 /* Prefetch aborts cannot happen in kernel mode */
666 if (__predict_false(!TRAP_USERMODE(tf)))
667 dab_fatal(tf, 0, tf->tf_pc, NULL, &ksig);
671 /* Ok validate the address, can only execute in USER space */
672 if (__predict_false(fault_pc >= VM_MAXUSER_ADDRESS ||
673 (fault_pc < VM_MIN_ADDRESS && vector_page == ARM_VECTORS_LOW))) {
674 ksig.signb = SIGSEGV;
679 map = &td->td_proc->p_vmspace->vm_map;
680 va = trunc_page(fault_pc);
683 * See if the pmap can handle this fault on its own...
686 last_fault_code = -1;
688 if (pmap_fault_fixup(map->pmap, va, VM_PROT_READ, 1))
691 if (map != kernel_map) {
697 error = vm_fault(map, va, VM_PROT_READ | VM_PROT_EXECUTE,
699 if (map != kernel_map) {
705 if (__predict_true(error == 0))
708 if (error == ENOMEM) {
709 printf("VM: pid %d (%s), uid %d killed: "
710 "out of swap\n", td->td_proc->p_pid, td->td_name,
711 (td->td_proc->p_ucred) ?
712 td->td_proc->p_ucred->cr_uid : -1);
713 ksig.signb = SIGKILL;
715 ksig.signb = SIGSEGV;
720 call_trapsignal(td, ksig.signb, ksig.code);
727 extern int badaddr_read_1(const uint8_t *, uint8_t *);
728 extern int badaddr_read_2(const uint16_t *, uint16_t *);
729 extern int badaddr_read_4(const uint32_t *, uint32_t *);
731 * Tentatively read an 8, 16, or 32-bit value from 'addr'.
732 * If the read succeeds, the value is written to 'rptr' and zero is returned.
733 * Else, return EFAULT.
736 badaddr_read(void *addr, size_t size, void *rptr)
745 cpu_drain_writebuf();
747 /* Read from the test address. */
749 case sizeof(uint8_t):
750 rv = badaddr_read_1(addr, &u.v1);
752 *(uint8_t *) rptr = u.v1;
755 case sizeof(uint16_t):
756 rv = badaddr_read_2(addr, &u.v2);
758 *(uint16_t *) rptr = u.v2;
761 case sizeof(uint32_t):
762 rv = badaddr_read_4(addr, &u.v4);
764 *(uint32_t *) rptr = u.v4;
768 panic("badaddr: invalid size (%lu)", (u_long) size);
771 /* Return EFAULT if the address was invalid, else zero */
776 cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
783 sa->code = td->td_frame->tf_r7;
785 sa->code = sa->insn & 0x000fffff;
787 ap = &td->td_frame->tf_r0;
788 if (sa->code == SYS_syscall) {
791 } else if (sa->code == SYS___syscall) {
792 sa->code = ap[_QUAD_LOWWORD];
797 if (p->p_sysent->sv_mask)
798 sa->code &= p->p_sysent->sv_mask;
799 if (sa->code >= p->p_sysent->sv_size)
800 sa->callp = &p->p_sysent->sv_table[0];
802 sa->callp = &p->p_sysent->sv_table[sa->code];
803 sa->narg = sa->callp->sy_narg;
805 memcpy(sa->args, ap, sa->nap * sizeof(register_t));
806 if (sa->narg > sa->nap) {
807 error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
808 sa->nap, (sa->narg - sa->nap) * sizeof(register_t));
811 td->td_retval[0] = 0;
812 td->td_retval[1] = 0;
817 #include "../../kern/subr_syscall.c"
820 syscall(struct thread *td, struct trapframe *frame)
822 struct syscall_args sa;
826 sa.insn = *(uint32_t *)(frame->tf_pc - INSN_SIZE);
827 switch (sa.insn & SWI_OS_MASK) {
828 case 0: /* XXX: we need our own one. */
831 call_trapsignal(td, SIGILL, 0);
838 error = syscallenter(td, &sa);
839 KASSERT(error != 0 || td->td_ar == NULL,
840 ("returning from syscall with td_ar set!"));
841 syscallret(td, error, &sa);
845 swi_handler(struct trapframe *frame)
847 struct thread *td = curthread;
849 td->td_frame = frame;
853 * Make sure the program counter is correctly aligned so we
854 * don't take an alignment fault trying to read the opcode.
856 if (__predict_false(((frame->tf_pc - INSN_SIZE) & 3) != 0)) {
857 call_trapsignal(td, SIGILL, 0);
862 * Enable interrupts if they were enabled before the exception.
863 * Since all syscalls *should* come from user mode it will always
864 * be safe to enable them, but check anyway.
866 if (td->td_md.md_spinlock_count == 0) {
867 if (__predict_true(frame->tf_spsr & PSR_I) == 0)
868 enable_interrupts(PSR_I);
869 if (__predict_true(frame->tf_spsr & PSR_F) == 0)
870 enable_interrupts(PSR_F);