1:1 Userland threading stage 2.11/4:
[dragonfly.git] / sys / platform / vkernel / i386 / procfs_machdep.c
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  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by the University of
20  *      California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      @(#)procfs_machdep.c    8.3 (Berkeley) 1/27/94
38  *
39  * From:
40  * $FreeBSD: src/sys/i386/i386/procfs_machdep.c,v 1.14 1999/10/11 14:50:03 peter Exp $
41  * $DragonFly: src/sys/platform/vkernel/i386/procfs_machdep.c,v 1.2 2007/02/03 17:05:58 corecode Exp $
42  */
43
44 /*
45  * Functions to be implemented here are:
46  *
47  * procfs_read_regs(proc, regs)
48  *      Get the current user-visible register set from the process
49  *      and copy it into the regs structure (<machine/reg.h>).
50  *      The process is stopped at the time read_regs is called.
51  *
52  * procfs_write_regs(proc, regs)
53  *      Update the current register set from the passed in regs
54  *      structure.  Take care to avoid clobbering special CPU
55  *      registers or privileged bits in the PSL.
56  *      Depending on the architecture this may have fix-up work to do,
57  *      especially if the IAR or PCW are modified.
58  *      The process is stopped at the time write_regs is called.
59  *
60  * procfs_read_fpregs, procfs_write_fpregs
61  *      deal with the floating point register set, otherwise as above.
62  *
63  * procfs_read_dbregs, procfs_write_dbregs
64  *      deal with the processor debug register set, otherwise as above.
65  *
66  * procfs_sstep(proc)
67  *      Arrange for the process to trap after executing a single instruction.
68  *
69  */
70
71 #include <sys/param.h>
72 #include <sys/proc.h>
73 #include <sys/ptrace.h>
74 #include <sys/vnode.h>
75 #include <sys/reg.h>
76 #include <machine/md_var.h>
77 #include <vfs/procfs/procfs.h>
78
79 #include <vm/vm.h>
80 #include <sys/lock.h>
81 #include <vm/pmap.h>
82 #include <vm/vm_map.h>
83
84 int
85 procfs_read_regs(struct proc *p, struct reg *regs)
86 {
87         struct lwp *lp;
88
89         if (p->p_flag & P_SWAPPEDOUT)
90                 return (EIO);
91         /* XXX lwp */
92         lp = FIRST_LWP_IN_PROC(p);
93         return (fill_regs(lp, regs));
94 }
95
96 int
97 procfs_write_regs(struct proc *p, struct reg *regs)
98 {
99         struct lwp *lp;
100
101         if (p->p_flag & P_SWAPPEDOUT)
102                 return (EIO);
103         /* XXX lwp */
104         lp = FIRST_LWP_IN_PROC(p);
105         return (set_regs(lp, regs));
106 }
107
108 int
109 procfs_read_dbregs(struct proc *p, struct dbreg *dbregs)
110 {
111         struct lwp *lp;
112
113         if (p->p_flag & P_SWAPPEDOUT)
114                 return (EIO);
115         /* XXX lwp */
116         lp = FIRST_LWP_IN_PROC(p);
117         return (fill_dbregs(lp, dbregs));
118 }
119
120 int
121 procfs_write_dbregs(struct proc *p, struct dbreg *dbregs)
122 {
123         struct lwp *lp;
124
125         if (p->p_flag & P_SWAPPEDOUT)
126                 return (EIO);
127         /* XXX lwp */
128         lp = FIRST_LWP_IN_PROC(p);
129         return (set_dbregs(lp, dbregs));
130 }
131
132 /*
133  * Ptrace doesn't support fpregs at all, and there are no security holes
134  * or translations for fpregs, so we can just copy them.
135  */
136
137 int
138 procfs_read_fpregs(struct proc *p, struct fpreg *fpregs)
139 {
140         struct lwp *lp;
141
142         if (p->p_flag & P_SWAPPEDOUT)
143                 return (EIO);
144         /* XXX lwp */
145         lp = FIRST_LWP_IN_PROC(p);
146         return (fill_fpregs(lp, fpregs));
147 }
148
149 int
150 procfs_write_fpregs(struct proc *p, struct fpreg *fpregs)
151 {
152         struct lwp *lp;
153
154         if (p->p_flag & P_SWAPPEDOUT)
155                 return (EIO);
156         /* XXX lwp */
157         lp = FIRST_LWP_IN_PROC(p);
158         return (set_fpregs(lp, fpregs));
159 }
160
161 int
162 procfs_sstep(struct proc *p)
163 {
164         struct lwp *lp;
165
166         if (p->p_flag & P_SWAPPEDOUT)
167                 return (EIO);
168         /* XXX lwp */
169         lp = FIRST_LWP_IN_PROC(p);
170         return (ptrace_single_step(lp));
171 }