Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / sys / arch / sh3 / sh3 / process_machdep.c
blobac975b61e132bed5632b7f018992ea18a9e84b41
1 /* $NetBSD: process_machdep.c,v 1.17 2009/10/21 21:12:02 rmind Exp $ */
3 /*
4 * Copyright (c) 1993 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Jan-Simon Pendry.
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. 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.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
34 * From:
35 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
39 * Copyright (c) 1995, 1996, 1997
40 * Charles M. Hannum. All rights reserved.
41 * Copyright (c) 1993 Jan-Simon Pendry
42 * All rights reserved.
44 * This code is derived from software contributed to Berkeley by
45 * Jan-Simon Pendry.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the University of
58 * California, Berkeley and its contributors.
59 * 4. Neither the name of the University nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * SUCH DAMAGE.
75 * From:
76 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.17 2009/10/21 21:12:02 rmind Exp $");
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/time.h>
85 #include <sys/kernel.h>
86 #include <sys/proc.h>
87 #include <sys/vnode.h>
88 #include <sys/ptrace.h>
90 #include <machine/psl.h>
91 #include <machine/reg.h>
93 #include "opt_compat_netbsd.h"
94 #include "opt_coredump.h"
95 #include "opt_ptrace.h"
97 #ifdef COMPAT_40
98 static int process_machdep_doregs40(struct lwp *, struct lwp *, struct uio *);
99 static int process_machdep_read_regs40(struct lwp *l, struct __reg40 *);
100 static int process_machdep_write_regs40(struct lwp *l, struct __reg40 *);
101 #endif /* COMPAT_40 */
104 #if defined(PTRACE) || defined(COREDUMP)
106 static inline struct trapframe *
107 process_frame(struct lwp *l)
110 return (l->l_md.md_regs);
114 process_read_regs(struct lwp *l, struct reg *regs)
116 struct trapframe *tf = process_frame(l);
118 regs->r_spc = tf->tf_spc;
119 regs->r_ssr = tf->tf_ssr;
120 regs->r_gbr = tf->tf_gbr;
121 regs->r_macl = tf->tf_macl;
122 regs->r_mach = tf->tf_mach;
123 regs->r_pr = tf->tf_pr;
124 regs->r_r14 = tf->tf_r14;
125 regs->r_r13 = tf->tf_r13;
126 regs->r_r12 = tf->tf_r12;
127 regs->r_r11 = tf->tf_r11;
128 regs->r_r10 = tf->tf_r10;
129 regs->r_r9 = tf->tf_r9;
130 regs->r_r8 = tf->tf_r8;
131 regs->r_r7 = tf->tf_r7;
132 regs->r_r6 = tf->tf_r6;
133 regs->r_r5 = tf->tf_r5;
134 regs->r_r4 = tf->tf_r4;
135 regs->r_r3 = tf->tf_r3;
136 regs->r_r2 = tf->tf_r2;
137 regs->r_r1 = tf->tf_r1;
138 regs->r_r0 = tf->tf_r0;
139 regs->r_r15 = tf->tf_r15;
141 return (0);
144 #endif /* PTRACE || COREDUMP */
147 #ifdef PTRACE
150 process_write_regs(struct lwp *l, const struct reg *regs)
152 struct trapframe *tf = process_frame(l);
155 * Check for security violations.
157 if (((regs->r_ssr ^ tf->tf_ssr) & PSL_USERSTATIC) != 0) {
158 return (EINVAL);
161 tf->tf_spc = regs->r_spc;
162 tf->tf_ssr = regs->r_ssr;
163 tf->tf_pr = regs->r_pr;
165 tf->tf_gbr = regs->r_gbr;
166 tf->tf_mach = regs->r_mach;
167 tf->tf_macl = regs->r_macl;
168 tf->tf_r14 = regs->r_r14;
169 tf->tf_r13 = regs->r_r13;
170 tf->tf_r12 = regs->r_r12;
171 tf->tf_r11 = regs->r_r11;
172 tf->tf_r10 = regs->r_r10;
173 tf->tf_r9 = regs->r_r9;
174 tf->tf_r8 = regs->r_r8;
175 tf->tf_r7 = regs->r_r7;
176 tf->tf_r6 = regs->r_r6;
177 tf->tf_r5 = regs->r_r5;
178 tf->tf_r4 = regs->r_r4;
179 tf->tf_r3 = regs->r_r3;
180 tf->tf_r2 = regs->r_r2;
181 tf->tf_r1 = regs->r_r1;
182 tf->tf_r0 = regs->r_r0;
183 tf->tf_r15 = regs->r_r15;
185 return (0);
189 #ifdef __HAVE_PTRACE_MACHDEP
192 ptrace_machdep_dorequest(struct lwp *l, struct lwp *lt,
193 int req, void *addr, int data)
195 struct uio uio;
196 struct iovec iov;
197 int write = 0;
199 switch (req) {
200 default:
201 return EINVAL;
203 #ifdef COMPAT_40
204 case PT___SETREGS40:
205 write = 1;
206 /* FALLTHROUGH*/
208 case PT___GETREGS40:
209 if (!process_validregs(lt))
210 return EINVAL;
211 iov.iov_base = addr;
212 iov.iov_len = sizeof(struct __reg40);
213 uio.uio_iov = &iov;
214 uio.uio_iovcnt = 1;
215 uio.uio_offset = 0;
216 uio.uio_resid = sizeof(struct __reg40);
217 uio.uio_rw = write ? UIO_WRITE : UIO_READ;
218 uio.uio_vmspace = l->l_proc->p_vmspace;
219 return process_machdep_doregs40(l, lt, &uio);
220 #endif /* COMPAT_40 */
225 #ifdef COMPAT_40
227 static int
228 process_machdep_doregs40(struct lwp *curl, struct lwp *l, struct uio *uio)
230 struct __reg40 r;
231 int error;
232 char *kv;
233 int kl;
235 kl = sizeof(r);
236 kv = (char *) &r;
238 kv += uio->uio_offset;
239 kl -= uio->uio_offset;
240 if (kl > uio->uio_resid)
241 kl = uio->uio_resid;
243 if (kl < 0)
244 error = EINVAL;
245 else
246 error = process_machdep_read_regs40(l, &r);
247 if (error == 0)
248 error = uiomove(kv, kl, uio);
249 if (error == 0 && uio->uio_rw == UIO_WRITE) {
250 if (l->l_proc->p_stat != SSTOP)
251 error = EBUSY;
252 else
253 error = process_machdep_write_regs40(l, &r);
256 uio->uio_offset = 0;
257 return error;
261 * Like process_read_regs() but for old struct reg w/out r_gbr.
263 static int
264 process_machdep_read_regs40(struct lwp *l, struct __reg40 *regs)
266 struct trapframe *tf = process_frame(l);
268 regs->r_spc = tf->tf_spc;
269 regs->r_ssr = tf->tf_ssr;
270 /* no r_gbr in struct __reg40 */
271 regs->r_macl = tf->tf_macl;
272 regs->r_mach = tf->tf_mach;
273 regs->r_pr = tf->tf_pr;
274 regs->r_r14 = tf->tf_r14;
275 regs->r_r13 = tf->tf_r13;
276 regs->r_r12 = tf->tf_r12;
277 regs->r_r11 = tf->tf_r11;
278 regs->r_r10 = tf->tf_r10;
279 regs->r_r9 = tf->tf_r9;
280 regs->r_r8 = tf->tf_r8;
281 regs->r_r7 = tf->tf_r7;
282 regs->r_r6 = tf->tf_r6;
283 regs->r_r5 = tf->tf_r5;
284 regs->r_r4 = tf->tf_r4;
285 regs->r_r3 = tf->tf_r3;
286 regs->r_r2 = tf->tf_r2;
287 regs->r_r1 = tf->tf_r1;
288 regs->r_r0 = tf->tf_r0;
289 regs->r_r15 = tf->tf_r15;
291 return 0;
295 * Like process_write_regs() but for old struct reg w/out r_gbr
297 static int
298 process_machdep_write_regs40(struct lwp *l, struct __reg40 *regs)
300 struct trapframe *tf = process_frame(l);
303 * Check for security violations.
305 if (((regs->r_ssr ^ tf->tf_ssr) & PSL_USERSTATIC) != 0) {
306 return EINVAL;
309 tf->tf_spc = regs->r_spc;
310 tf->tf_ssr = regs->r_ssr;
311 tf->tf_pr = regs->r_pr;
313 /* no r_gbr in struct __reg40 */
314 tf->tf_mach = regs->r_mach;
315 tf->tf_macl = regs->r_macl;
316 tf->tf_r14 = regs->r_r14;
317 tf->tf_r13 = regs->r_r13;
318 tf->tf_r12 = regs->r_r12;
319 tf->tf_r11 = regs->r_r11;
320 tf->tf_r10 = regs->r_r10;
321 tf->tf_r9 = regs->r_r9;
322 tf->tf_r8 = regs->r_r8;
323 tf->tf_r7 = regs->r_r7;
324 tf->tf_r6 = regs->r_r6;
325 tf->tf_r5 = regs->r_r5;
326 tf->tf_r4 = regs->r_r4;
327 tf->tf_r3 = regs->r_r3;
328 tf->tf_r2 = regs->r_r2;
329 tf->tf_r1 = regs->r_r1;
330 tf->tf_r0 = regs->r_r0;
331 tf->tf_r15 = regs->r_r15;
333 return 0;
336 #endif /* COMPAT_40 */
338 #endif /* __HAVE_PTRACE_MACHDEP */
342 process_sstep(struct lwp *l, int sstep)
345 if (sstep)
346 return (EINVAL);
348 return (0);
352 process_set_pc(struct lwp *l, void *addr)
354 struct trapframe *tf = process_frame(l);
356 tf->tf_spc = (int)addr;
358 return (0);
361 #endif /* PTRACE */