1 /* $OpenBSD: process_machdep.c,v 1.4 2008/07/28 17:50:11 miod Exp $ */
2
3 /*
4 * Copyright (c) 1993 The Regents of the University of California.
5 * Copyright (c) 1993 Jan-Simon Pendry
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
36 */
37
38 /*
39 * This file may seem a bit stylized, but that so that it's easier to port.
40 * Functions to be implemented here are:
41 *
42 * process_read_regs(proc, regs)
43 * Get the current user-visible register set from the process
44 * and copy it into the regs structure (<machine/reg.h>).
45 * The process is stopped at the time read_regs is called.
46 *
47 * process_write_regs(proc, regs)
48 * Update the current register set from the passed in regs
49 * structure. Take care to avoid clobbering special CPU
50 * registers or privileged bits in the PSL.
51 * The process is stopped at the time write_regs is called.
52 *
53 * process_sstep(proc)
54 * Arrange for the process to trap after executing a single instruction.
55 *
56 * process_set_pc(proc)
57 * Set the process's program counter.
58 */
59
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/time.h>
63 #include <sys/kernel.h>
64 #include <sys/proc.h>
65 #include <sys/user.h>
66 #include <sys/vnode.h>
67 #include <machine/psl.h>
68 #include <machine/reg.h>
69 #include <machine/trap.h>
70 #include <sys/ptrace.h>
71
72 int
process_read_regs(p,regs)73 process_read_regs(p, regs)
74 struct proc *p;
75 struct reg *regs;
76 {
77 bcopy((caddr_t)USER_REGS(p), (caddr_t)regs, sizeof(struct reg));
78 return (0);
79 }
80
81 #ifdef PTRACE
82
83 int
process_write_regs(p,regs)84 process_write_regs(p, regs)
85 struct proc *p;
86 struct reg *regs;
87 {
88 struct reg *procregs = (struct reg *)USER_REGS(p);
89 unsigned int psr = procregs->epsr;
90
91 bcopy(regs, procregs, sizeof(struct reg));
92 procregs->epsr =
93 (psr & PSR_USERSTATIC) | (regs->epsr & ~PSR_USERSTATIC);
94
95 return (0);
96 }
97
98 /* process_sstep() is in trap.c */
99
100 int
process_set_pc(p,addr)101 process_set_pc(p, addr)
102 struct proc *p;
103 caddr_t addr;
104 {
105 struct reg *regs;
106
107 regs = USER_REGS(p);
108 regs->sxip = (u_int)addr;
109 regs->snip = (u_int)addr + 4;
110 return (0);
111 }
112
113 #endif /* PTRACE */
114