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