1 /* $NetBSD: process_machdep.c,v 1.39 2017/12/29 09:27:01 maya Exp $ */
2
3 /*
4 * Copyright (c) 1993 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Jan-Simon Pendry.
9 *
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.
21 *
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.
33 *
34 * From:
35 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
36 */
37
38 /*
39 * Copyright (c) 1994 Adam Glass
40 * Copyright (c) 1993 Jan-Simon Pendry
41 * All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * Jan-Simon Pendry.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 *
74 * From:
75 * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
76 */
77
78 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
79 __KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.39 2017/12/29 09:27:01 maya Exp $");
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)
97 * Arrange for the process to trap after executing a single instruction.
98 *
99 * process_set_pc(proc)
100 * Set the process's program counter.
101 */
102
103 #include <sys/param.h>
104 #include <sys/systm.h>
105 #include <sys/proc.h>
106 #include <sys/ptrace.h>
107
108 #include <mips/pcb.h>
109 #include <mips/regnum.h> /* symbolic register indices */
110 #include <mips/locore.h>
111
112 int
process_read_regs(struct lwp * l,struct reg * regs)113 process_read_regs(struct lwp *l, struct reg *regs)
114 {
115
116 *regs = l->l_md.md_utf->tf_registers;
117 return 0;
118 }
119
120 int
process_write_regs(struct lwp * l,const struct reg * regs)121 process_write_regs(struct lwp *l, const struct reg *regs)
122 {
123 struct trapframe * const tf = l->l_md.md_utf;
124 mips_reg_t sr;
125
126 sr = tf->tf_regs[_R_SR];
127 tf->tf_registers = *regs;
128 tf->tf_regs[_R_SR] = sr;
129 return 0;
130 }
131
132 #if defined(__mips_n32) || defined(__mips_n64)
133 CTASSERT(sizeof(struct fpreg_oabi) <= sizeof(struct fpreg));
134 #endif
135
136 int
process_read_fpregs(struct lwp * l,struct fpreg * regs,size_t * regslen_p)137 process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *regslen_p)
138 {
139 struct pcb * const pcb = lwp_getpcb(l);
140 KASSERT(*regslen_p == sizeof(struct fpreg));
141
142 #if defined(__mips_n32) || defined(__mips_n64)
143 if (!_MIPS_SIM_NEWABI_P(l->l_proc->p_md.md_abi))
144 *regslen_p = sizeof(struct fpreg_oabi);
145 #endif
146
147 fpu_save(l);
148 memcpy(regs, &pcb->pcb_fpregs, sizeof(*regs));
149 return 0;
150 }
151
152 int
process_write_fpregs(struct lwp * l,const struct fpreg * regs,size_t regslen)153 process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t regslen)
154 {
155 struct pcb * const pcb = lwp_getpcb(l);
156
157 #ifndef NOFPU
158 /* to load FPA contents next time when FP insn is executed */
159 fpu_discard(l);
160 #endif /* !NOFPU */
161
162 if (_MIPS_SIM_NEWABI_P(l->l_proc->p_md.md_abi))
163 KASSERT(regslen == sizeof(struct fpreg));
164 else
165 KASSERT(regslen == sizeof(struct fpreg_oabi));
166
167 memcpy(&pcb->pcb_fpregs, regs, regslen);
168 return 0;
169 }
170
171 int
process_sstep(struct lwp * l,int sstep)172 process_sstep(struct lwp *l, int sstep)
173 {
174
175 /* XXX what are the correct semantics: sstep once, or forevermore? */
176 if (sstep)
177 mips_singlestep(l);
178 return 0;
179 }
180
181 int
process_set_pc(struct lwp * l,void * addr)182 process_set_pc(struct lwp *l, void *addr)
183 {
184
185 l->l_md.md_utf->tf_regs[_R_PC] = (intptr_t)addr;
186 return 0;
187 }
188