1293b5c22SAndrew Turner /* $NetBSD: fault.c,v 1.45 2003/11/20 14:44:36 scw Exp $ */
2293b5c22SAndrew Turner
3293b5c22SAndrew Turner /*-
4293b5c22SAndrew Turner * Copyright 2004 Olivier Houchard
5293b5c22SAndrew Turner * Copyright 2003 Wasabi Systems, Inc.
6293b5c22SAndrew Turner * All rights reserved.
7293b5c22SAndrew Turner *
8293b5c22SAndrew Turner * Written by Steve C. Woodford for Wasabi Systems, Inc.
9293b5c22SAndrew Turner *
10293b5c22SAndrew Turner * Redistribution and use in source and binary forms, with or without
11293b5c22SAndrew Turner * modification, are permitted provided that the following conditions
12293b5c22SAndrew Turner * are met:
13293b5c22SAndrew Turner * 1. Redistributions of source code must retain the above copyright
14293b5c22SAndrew Turner * notice, this list of conditions and the following disclaimer.
15293b5c22SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright
16293b5c22SAndrew Turner * notice, this list of conditions and the following disclaimer in the
17293b5c22SAndrew Turner * documentation and/or other materials provided with the distribution.
18293b5c22SAndrew Turner * 3. All advertising materials mentioning features or use of this software
19293b5c22SAndrew Turner * must display the following acknowledgement:
20293b5c22SAndrew Turner * This product includes software developed for the NetBSD Project by
21293b5c22SAndrew Turner * Wasabi Systems, Inc.
22293b5c22SAndrew Turner * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23293b5c22SAndrew Turner * or promote products derived from this software without specific prior
24293b5c22SAndrew Turner * written permission.
25293b5c22SAndrew Turner *
26293b5c22SAndrew Turner * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27293b5c22SAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28293b5c22SAndrew Turner * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29293b5c22SAndrew Turner * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30293b5c22SAndrew Turner * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31293b5c22SAndrew Turner * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32293b5c22SAndrew Turner * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33293b5c22SAndrew Turner * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34293b5c22SAndrew Turner * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35293b5c22SAndrew Turner * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36293b5c22SAndrew Turner * POSSIBILITY OF SUCH DAMAGE.
37293b5c22SAndrew Turner */
38293b5c22SAndrew Turner /*-
39293b5c22SAndrew Turner * Copyright (c) 1994-1997 Mark Brinicombe.
40293b5c22SAndrew Turner * Copyright (c) 1994 Brini.
41293b5c22SAndrew Turner * All rights reserved.
42293b5c22SAndrew Turner *
43293b5c22SAndrew Turner * This code is derived from software written for Brini by Mark Brinicombe
44293b5c22SAndrew Turner *
45293b5c22SAndrew Turner * Redistribution and use in source and binary forms, with or without
46293b5c22SAndrew Turner * modification, are permitted provided that the following conditions
47293b5c22SAndrew Turner * are met:
48293b5c22SAndrew Turner * 1. Redistributions of source code must retain the above copyright
49293b5c22SAndrew Turner * notice, this list of conditions and the following disclaimer.
50293b5c22SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright
51293b5c22SAndrew Turner * notice, this list of conditions and the following disclaimer in the
52293b5c22SAndrew Turner * documentation and/or other materials provided with the distribution.
53293b5c22SAndrew Turner * 3. All advertising materials mentioning features or use of this software
54293b5c22SAndrew Turner * must display the following acknowledgement:
55293b5c22SAndrew Turner * This product includes software developed by Brini.
56293b5c22SAndrew Turner * 4. The name of the company nor the name of the author may be used to
57293b5c22SAndrew Turner * endorse or promote products derived from this software without specific
58293b5c22SAndrew Turner * prior written permission.
59293b5c22SAndrew Turner *
60293b5c22SAndrew Turner * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
61293b5c22SAndrew Turner * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62293b5c22SAndrew Turner * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63293b5c22SAndrew Turner * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64293b5c22SAndrew Turner * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65293b5c22SAndrew Turner * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66293b5c22SAndrew Turner * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67293b5c22SAndrew Turner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68293b5c22SAndrew Turner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69293b5c22SAndrew Turner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70293b5c22SAndrew Turner * SUCH DAMAGE.
71293b5c22SAndrew Turner *
72293b5c22SAndrew Turner * RiscBSD kernel project
73293b5c22SAndrew Turner *
74293b5c22SAndrew Turner * fault.c
75293b5c22SAndrew Turner *
76293b5c22SAndrew Turner * Fault handlers
77293b5c22SAndrew Turner *
78293b5c22SAndrew Turner * Created : 28/11/94
79293b5c22SAndrew Turner */
80293b5c22SAndrew Turner
81293b5c22SAndrew Turner #include <sys/param.h>
82293b5c22SAndrew Turner #include <sys/systm.h>
8395d7f8aaSAndrew Turner #include <sys/kernel.h>
84293b5c22SAndrew Turner #include <sys/proc.h>
85293b5c22SAndrew Turner #include <sys/lock.h>
86293b5c22SAndrew Turner #include <sys/mutex.h>
87293b5c22SAndrew Turner #include <sys/syscall.h>
88293b5c22SAndrew Turner #include <sys/sysent.h>
89293b5c22SAndrew Turner #include <sys/signalvar.h>
90293b5c22SAndrew Turner #include <sys/ptrace.h>
91293b5c22SAndrew Turner
92293b5c22SAndrew Turner #include <machine/frame.h>
93293b5c22SAndrew Turner
94293b5c22SAndrew Turner void swi_handler(struct trapframe *);
95293b5c22SAndrew Turner
96293b5c22SAndrew Turner int
cpu_fetch_syscall_args(struct thread * td)972d88da2fSKonstantin Belousov cpu_fetch_syscall_args(struct thread *td)
98293b5c22SAndrew Turner {
99293b5c22SAndrew Turner struct proc *p;
100b1ad6a90SBrooks Davis syscallarg_t *ap;
1012d88da2fSKonstantin Belousov struct syscall_args *sa;
1026998d5b1SEdward Tomasz Napierala u_int nap;
103293b5c22SAndrew Turner int error;
104293b5c22SAndrew Turner
1056998d5b1SEdward Tomasz Napierala nap = 4;
1062d88da2fSKonstantin Belousov sa = &td->td_sa;
107293b5c22SAndrew Turner sa->code = td->td_frame->tf_r7;
108cf98bc28SDavid Chisnall sa->original_code = sa->code;
109293b5c22SAndrew Turner ap = &td->td_frame->tf_r0;
110293b5c22SAndrew Turner if (sa->code == SYS_syscall) {
111293b5c22SAndrew Turner sa->code = *ap++;
1126998d5b1SEdward Tomasz Napierala nap--;
113293b5c22SAndrew Turner } else if (sa->code == SYS___syscall) {
114293b5c22SAndrew Turner sa->code = ap[_QUAD_LOWWORD];
1156998d5b1SEdward Tomasz Napierala nap -= 2;
116293b5c22SAndrew Turner ap += 2;
117293b5c22SAndrew Turner }
118293b5c22SAndrew Turner p = td->td_proc;
119293b5c22SAndrew Turner if (sa->code >= p->p_sysent->sv_size)
120*39024a89SKonstantin Belousov sa->callp = &nosys_sysent;
121293b5c22SAndrew Turner else
122293b5c22SAndrew Turner sa->callp = &p->p_sysent->sv_table[sa->code];
123293b5c22SAndrew Turner error = 0;
124b1ad6a90SBrooks Davis memcpy(sa->args, ap, nap * sizeof(*sa->args));
1256998d5b1SEdward Tomasz Napierala if (sa->callp->sy_narg > nap) {
126293b5c22SAndrew Turner error = copyin((void *)td->td_frame->tf_usr_sp, sa->args +
127b1ad6a90SBrooks Davis nap, (sa->callp->sy_narg - nap) * sizeof(*sa->args));
128293b5c22SAndrew Turner }
129293b5c22SAndrew Turner if (error == 0) {
130293b5c22SAndrew Turner td->td_retval[0] = 0;
131293b5c22SAndrew Turner td->td_retval[1] = 0;
132293b5c22SAndrew Turner }
133293b5c22SAndrew Turner return (error);
134293b5c22SAndrew Turner }
135293b5c22SAndrew Turner
136293b5c22SAndrew Turner #include "../../kern/subr_syscall.c"
137293b5c22SAndrew Turner
138293b5c22SAndrew Turner static void
syscall(struct thread * td,struct trapframe * frame)139293b5c22SAndrew Turner syscall(struct thread *td, struct trapframe *frame)
140293b5c22SAndrew Turner {
141293b5c22SAndrew Turner
142c18ca749SJohn Baldwin syscallenter(td);
143c18ca749SJohn Baldwin syscallret(td);
144293b5c22SAndrew Turner }
145293b5c22SAndrew Turner
146293b5c22SAndrew Turner void
swi_handler(struct trapframe * frame)147293b5c22SAndrew Turner swi_handler(struct trapframe *frame)
148293b5c22SAndrew Turner {
149293b5c22SAndrew Turner struct thread *td = curthread;
150293b5c22SAndrew Turner
151293b5c22SAndrew Turner td->td_frame = frame;
152293b5c22SAndrew Turner
153293b5c22SAndrew Turner td->td_pticks = 0;
154ae4fa222SAndrew Turner
155293b5c22SAndrew Turner /*
156293b5c22SAndrew Turner * Enable interrupts if they were enabled before the exception.
157293b5c22SAndrew Turner * Since all syscalls *should* come from user mode it will always
158293b5c22SAndrew Turner * be safe to enable them, but check anyway.
159293b5c22SAndrew Turner */
160293b5c22SAndrew Turner if (td->td_md.md_spinlock_count == 0) {
161293b5c22SAndrew Turner if (__predict_true(frame->tf_spsr & PSR_I) == 0)
162293b5c22SAndrew Turner enable_interrupts(PSR_I);
163293b5c22SAndrew Turner }
164293b5c22SAndrew Turner
165293b5c22SAndrew Turner syscall(td, frame);
166293b5c22SAndrew Turner }
167