procfs_fpregs.c revision 77031
178266Snik/*
278266Snik * Copyright (c) 1993 Jan-Simon Pendry
378266Snik * Copyright (c) 1993
4174425Sdougb *	The Regents of the University of California.  All rights reserved.
5174425Sdougb *
6174425Sdougb * This code is derived from software contributed to Berkeley by
778266Snik * Jan-Simon Pendry.
878266Snik *
978266Snik * Redistribution and use in source and binary forms, with or without
1078266Snik * modification, are permitted provided that the following conditions
11256019Sglebius * are met:
12256019Sglebius * 1. Redistributions of source code must retain the above copyright
1378266Snik *    notice, this list of conditions and the following disclaimer.
14174425Sdougb * 2. Redistributions in binary form must reproduce the above copyright
15174425Sdougb *    notice, this list of conditions and the following disclaimer in the
16174425Sdougb *    documentation and/or other materials provided with the distribution.
1778266Snik * 3. All advertising materials mentioning features or use of this software
18174425Sdougb *    must display the following acknowledgement:
1978266Snik *	This product includes software developed by the University of
20174425Sdougb *	California, Berkeley and its contributors.
21174425Sdougb * 4. Neither the name of the University nor the names of its contributors
2278266Snik *    may be used to endorse or promote products derived from this software
23174425Sdougb *    without specific prior written permission.
24174425Sdougb *
2578266Snik * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26174425Sdougb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27174425Sdougb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28174425Sdougb * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2978266Snik * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30174425Sdougb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31174425Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32174425Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33174425Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34174425Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3578266Snik * SUCH DAMAGE.
36174425Sdougb *
37174425Sdougb *	@(#)procfs_fpregs.c	8.2 (Berkeley) 6/15/94
3878266Snik *
39174425Sdougb * From:
40174425Sdougb * $FreeBSD: head/sys/fs/procfs/procfs_fpregs.c 77031 2001-05-23 09:42:29Z ru $
4178266Snik */
42174425Sdougb
43241934Seadler#include <sys/param.h>
44174425Sdougb#include <sys/systm.h>
4578266Snik#include <sys/lock.h>
46174425Sdougb#include <sys/mutex.h>
47174425Sdougb#include <sys/proc.h>
4878266Snik#include <sys/vnode.h>
49174425Sdougb
50174425Sdougb#include <machine/reg.h>
51174425Sdougb
5278266Snik#include <fs/procfs/procfs.h>
5378266Snik
5478266Snik#include <vm/vm.h>
5578266Snik
5678266Snikint
57174425Sdougbprocfs_dofpregs(curp, p, pfs, uio)
58174425Sdougb	struct proc *curp;
59174425Sdougb	struct proc *p;
60174425Sdougb	struct pfsnode *pfs;
61174425Sdougb	struct uio *uio;
6278266Snik{
63174425Sdougb	int error;
6478266Snik	struct fpreg r;
65174425Sdougb	char *kv;
66174425Sdougb	int kl;
67174425Sdougb
6878266Snik	if (p_can(curp, p, P_CAN_DEBUG, NULL))
69174425Sdougb		return EPERM;
7078266Snik	kl = sizeof(r);
71174425Sdougb	kv = (char *) &r;
72174425Sdougb
7378266Snik	kv += uio->uio_offset;
74174425Sdougb	kl -= uio->uio_offset;
7578266Snik	if (kl > uio->uio_resid)
76235227Seadler		kl = uio->uio_resid;
77235209Seadler
78174425Sdougb	PHOLD(p);
7978266Snik
80174425Sdougb	if (kl < 0)
81174425Sdougb		error = EINVAL;
8278266Snik	else
83174425Sdougb		error = procfs_read_fpregs(p, &r);
84174425Sdougb	if (error == 0)
8578266Snik		error = uiomove(kv, kl, uio);
86174425Sdougb	if (error == 0 && uio->uio_rw == UIO_WRITE) {
87174425Sdougb		if (p->p_stat != SSTOP)
8878266Snik			error = EBUSY;
89174425Sdougb		else
90174425Sdougb			error = procfs_write_fpregs(p, &r);
91174425Sdougb	}
92174425Sdougb	PRELE(p);
93174425Sdougb
9478266Snik	uio->uio_offset = 0;
9578266Snik	return (error);
9678266Snik}
9778266Snik
9878266Snikint
99174425Sdougbprocfs_validfpregs(p)
100174425Sdougb	struct proc *p;
10178266Snik{
102174425Sdougb
103174425Sdougb	return ((p->p_flag & P_SYSTEM) == 0);
104174425Sdougb}
105174425Sdougb