1 /* $OpenBSD: process_machdep.c,v 1.7 2021/03/25 04:12:00 jsg Exp $ */
2 /* $NetBSD: process_machdep.c,v 1.11 2003/08/07 16:26:52 agc Exp $ */
3
4 /*
5 * Copyright (c) 1993 The Regents of the University of California.
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:
36 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
37 */
38
39 /*
40 * Copyright (c) 1995 Frank Lancaster. All rights reserved.
41 * Copyright (c) 1995 Tools GmbH. All rights reserved.
42 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
43 * Copyright (c) 1993 Jan-Simon Pendry
44 * All rights reserved.
45 *
46 * This code is derived from software contributed to Berkeley by
47 * Jan-Simon Pendry.
48 *
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 * notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 * notice, this list of conditions and the following disclaimer in the
56 * documentation and/or other materials provided with the distribution.
57 * 3. All advertising materials mentioning features or use of this software
58 * must display the following acknowledgement:
59 * This product includes software developed by the University of
60 * California, Berkeley and its contributors.
61 * 4. Neither the name of the University nor the names of its contributors
62 * may be used to endorse or promote products derived from this software
63 * without specific prior written permission.
64 *
65 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 * SUCH DAMAGE.
76 *
77 * From:
78 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
79 */
80
81 /*
82 * This file may seem a bit stylized, but that so that it's easier to port.
83 * Functions to be implemented here are:
84 *
85 * process_read_regs(proc, regs)
86 * Get the current user-visible register set from the process
87 * and copy it into the regs structure (<machine/reg.h>).
88 * The process is stopped at the time read_regs is called.
89 *
90 * process_write_regs(proc, regs)
91 * Update the current register set from the passed in regs
92 * structure. Take care to avoid clobbering special CPU
93 * registers or privileged bits in the PSL.
94 * The process is stopped at the time write_regs is called.
95 *
96 * process_sstep(proc, sstep)
97 * Arrange for the process to trap or not trap depending on sstep
98 * after executing a single instruction.
99 *
100 * process_set_pc(proc)
101 * Set the process's program counter.
102 */
103
104 #include <sys/param.h>
105 #include <sys/proc.h>
106 #include <sys/ptrace.h>
107 #include <sys/systm.h>
108 #include <sys/user.h>
109
110 #include <arm/armreg.h>
111 #include <arm/vfp.h>
112
113 static __inline struct trapframe *
process_frame(struct proc * p)114 process_frame(struct proc *p)
115 {
116
117 return p->p_addr->u_pcb.pcb_tf;
118 }
119
120 int
process_read_regs(struct proc * p,struct reg * regs)121 process_read_regs(struct proc *p, struct reg *regs)
122 {
123 struct trapframe *tf = process_frame(p);
124
125 KASSERT(tf != NULL);
126 bcopy((caddr_t)&tf->tf_r0, (caddr_t)regs->r, sizeof(regs->r));
127 regs->r_sp = tf->tf_usr_sp;
128 regs->r_lr = tf->tf_usr_lr;
129 regs->r_pc = tf->tf_pc;
130 regs->r_cpsr = tf->tf_spsr;
131
132 #ifdef DIAGNOSTIC
133 if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
134 && tf->tf_spsr & PSR_I)
135 panic("process_read_regs: Interrupts blocked in user process");
136 #endif
137
138 return(0);
139 }
140
141 int
process_read_fpregs(struct proc * p,struct fpreg * regs)142 process_read_fpregs(struct proc *p, struct fpreg *regs)
143 {
144 if (p->p_addr->u_pcb.pcb_flags & PCB_FPU)
145 memcpy(regs, &p->p_addr->u_pcb.pcb_fpstate, sizeof(*regs));
146 else
147 memset(regs, 0, sizeof(*regs));
148
149 return(0);
150 }
151
152 #ifdef PTRACE
153
154 int
process_write_regs(struct proc * p,struct reg * regs)155 process_write_regs(struct proc *p, struct reg *regs)
156 {
157 struct trapframe *tf = process_frame(p);
158
159 KASSERT(tf != NULL);
160 bcopy((caddr_t)regs->r, (caddr_t)&tf->tf_r0, sizeof(regs->r));
161 tf->tf_usr_sp = regs->r_sp;
162 tf->tf_usr_lr = regs->r_lr;
163 tf->tf_pc = regs->r_pc;
164 tf->tf_spsr &= ~PSR_FLAGS;
165 tf->tf_spsr |= regs->r_cpsr & PSR_FLAGS;
166 #ifdef DIAGNOSTIC
167 if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
168 && tf->tf_spsr & PSR_I)
169 panic("process_write_regs: Interrupts blocked in user process");
170 #endif
171
172 return(0);
173 }
174
175 int
process_write_fpregs(struct proc * p,struct fpreg * regs)176 process_write_fpregs(struct proc *p, struct fpreg *regs)
177 {
178 if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
179 vfp_discard(p);
180
181 memcpy(&p->p_addr->u_pcb.pcb_fpstate, regs, sizeof(*regs));
182 p->p_addr->u_pcb.pcb_flags |= PCB_FPU;
183 return(0);
184 }
185
186 int
process_sstep(struct proc * p,int sstep)187 process_sstep(struct proc *p, int sstep)
188 {
189 if (sstep)
190 return (EINVAL);
191 return 0;
192 }
193
194 int
process_set_pc(struct proc * p,caddr_t addr)195 process_set_pc(struct proc *p, caddr_t addr)
196 {
197 struct trapframe *tf = process_frame(p);
198
199 KASSERT(tf != NULL);
200 tf->tf_pc = (int)addr;
201
202 return (0);
203 }
204
205 #endif /* PTRACE */
206