1 /*
2  * Copyright (c) 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1993 Jan-Simon Pendry
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Jan-Simon Pendry.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)procfs_machdep.c	8.4 (Berkeley) 06/15/94
12  *
13  * From:
14  *	$Id: procfs_i386.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
15  */
16 
17 /*
18  * Functions to be implemented here are:
19  *
20  * procfs_read_regs(proc, regs)
21  *	Get the current user-visible register set from the process
22  *	and copy it into the regs structure (<machine/reg.h>).
23  *	The process is stopped at the time read_regs is called.
24  *
25  * procfs_write_regs(proc, regs)
26  *	Update the current register set from the passed in regs
27  *	structure.  Take care to avoid clobbering special CPU
28  *	registers or privileged bits in the PSL.
29  *	The process is stopped at the time write_regs is called.
30  *
31  * procfs_read_fpregs, procfs_write_fpregs
32  *	deal with the floating point register set, otherwise as above.
33  *
34  * procfs_sstep(proc)
35  *	Arrange for the process to trap after executing a single instruction.
36  *
37  * procfs_fix_sstep(proc)
38  *	Cleanup process state after executing a single-step instruction.
39  */
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/time.h>
44 #include <sys/kernel.h>
45 #include <sys/proc.h>
46 #include <sys/user.h>
47 #include <sys/vnode.h>
48 #include <machine/psl.h>
49 #include <machine/reg.h>
50 /*#include <machine/frame.h>*/
51 #include <miscfs/procfs/procfs.h>
52 
53 int
54 procfs_read_regs(p, regs)
55 	struct proc *p;
56 	struct reg *regs;
57 {
58 	struct frame *f;
59 
60 	if ((p->p_flag & P_INMEM) == 0)
61 		return (EIO);
62 
63 	f = (struct frame *) p->p_md.md_regs;
64 	bcopy((void *) f->f_regs, (void *) regs->r_regs, sizeof(regs->r_regs));
65 	regs->r_pc = f->f_pc;
66 	regs->r_sr = f->f_sr;
67 
68 	return (0);
69 }
70 
71 /*
72  * Update the process's current register
73  * set.  Depending on the architecture this
74  * may have fix-up work to do, especially
75  * if the IAR or PCW are modified.
76  */
77 int
78 procfs_write_regs(p, regs)
79 	struct proc *p;
80 	struct reg *regs;
81 {
82 	struct frame *f;
83 
84 	if ((p->p_flag & P_INMEM) == 0)
85 		return (EIO);
86 
87 	f = (struct frame *) p->p_md.md_regs;
88 	bcopy((void *) regs->r_regs, (void *) f->f_regs, sizeof(f->f_regs));
89 	f->f_pc = regs->r_pc;
90 	f->f_sr = regs->r_sr;
91 
92 	return (0);
93 }
94 
95 int
96 procfs_read_fpregs(p, fpregs)
97 	struct proc *p;
98 	struct fpreg *fpregs;
99 {
100 
101 	return (EOPNOTSUPP);
102 }
103 
104 int
105 procfs_write_fpregs(p, fpregs)
106 	struct proc *p;
107 	struct fpreg *fpregs;
108 {
109 
110 	return (EOPNOTSUPP);
111 }
112 
113 
114 int
115 procfs_sstep(p, sstep)
116 	struct proc *p;
117 	int sstep;
118 {
119 	int error;
120 	struct reg r;
121 
122 	error = procfs_read_regs(p, &r);
123 	if (error == 0) {
124 		if (sstep)
125 			r.r_sr |= PSL_T;
126 		else
127 			r.r_sr |= PSL_T;
128 		error = procfs_write_regs(p, &r);
129 	}
130 
131 	return (error);
132 }
133 
134 void
135 procfs_fix_sstep(p)
136 	struct proc *p;
137 {
138 }
139