xref: /netbsd/sys/arch/mips/mips/process_machdep.c (revision 6550d01e)
1 /*	$NetBSD: process_machdep.c,v 1.32 2011/01/14 02:06:28 rmind 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.32 2011/01/14 02:06:28 rmind 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 
111 CTASSERT(sizeof(struct reg) == sizeof(((struct frame *)0)->f_regs));
112 
113 int
114 process_read_regs(struct lwp *l, struct reg *regs)
115 {
116 
117 	memcpy(regs, l->l_md.md_regs->f_regs, sizeof(struct reg));
118 	return 0;
119 }
120 
121 int
122 process_write_regs(struct lwp *l, const struct reg *regs)
123 {
124 	struct frame *f = l->l_md.md_regs;
125 	mips_reg_t sr;
126 
127 	sr = f->f_regs[_R_SR];
128 	memcpy(l->l_md.md_regs, regs, sizeof(struct reg));
129 	f->f_regs[_R_SR] = sr;
130 	return 0;
131 }
132 
133 #if defined(__mips_n32) || defined(__mips_n64)
134 CTASSERT(sizeof(struct fpreg_oabi) <= sizeof(struct fpreg));
135 #endif
136 
137 int
138 process_read_xfpregs(struct lwp *l, struct fpreg *regs, size_t *regslen_p)
139 {
140 	struct pcb * const pcb = lwp_getpcb(l);
141 	KASSERT(*regslen_p == sizeof(struct fpreg));
142 
143 #if defined(__mips_n32) || defined(__mips_n64)
144 	if (!_MIPS_SIM_NEWABI_P(l->l_proc->p_md.md_abi))
145 		*regslen_p = sizeof(struct fpreg_oabi);
146 #endif
147 
148 	if ((l->l_md.md_flags & MDP_FPUSED) && l == fpcurlwp)
149 		savefpregs(l);
150 	memcpy(regs, &pcb->pcb_fpregs, sizeof(struct fpreg));
151 	return 0;
152 }
153 
154 int
155 process_write_xfpregs(struct lwp *l, const struct fpreg *regs, size_t regslen)
156 {
157 	struct pcb * const pcb = lwp_getpcb(l);
158 
159 	/* to load FPA contents next time when FP insn is executed */
160 	if ((l->l_md.md_flags & MDP_FPUSED) && l == fpcurlwp)
161 		fpcurlwp = &lwp0;
162 #if defined(__mips_n32) || defined(__mips_n64)
163 	KASSERT((_MIPS_SIM_NEWABI_P(l->l_proc->p_md.md_abi) ? sizeof(struct fpreg) : sizeof(struct fpreg_oabi)) == regslen);
164 #else
165 	KASSERT(regslen == sizeof(struct fpreg));
166 #endif
167 	memcpy(&pcb->pcb_fpregs, regs, regslen);
168 	return 0;
169 }
170 
171 int
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
182 process_set_pc(struct lwp *l, void *addr)
183 {
184 
185 	((struct frame *)l->l_md.md_regs)->f_regs[_R_PC] = (intptr_t)addr;
186 	return 0;
187 }
188