1*65523Spendry /*
2*65523Spendry  * Copyright (c) 1993 The Regents of the University of California.
3*65523Spendry  * Copyright (c) 1993 Jan-Simon Pendry
4*65523Spendry  * All rights reserved.
5*65523Spendry  *
6*65523Spendry  * This code is derived from software contributed to Berkeley by
7*65523Spendry  * Jan-Simon Pendry.
8*65523Spendry  *
9*65523Spendry  * %sccs.include.redist.c%
10*65523Spendry  *
11*65523Spendry  *	@(#)procfs_regs.c	8.1 (Berkeley) 01/05/94
12*65523Spendry  *
13*65523Spendry  * From:
14*65523Spendry  *	$Id: procfs_regs.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
15*65523Spendry  */
16*65523Spendry 
17*65523Spendry #include <sys/param.h>
18*65523Spendry #include <sys/systm.h>
19*65523Spendry #include <sys/time.h>
20*65523Spendry #include <sys/kernel.h>
21*65523Spendry #include <sys/proc.h>
22*65523Spendry #include <sys/vnode.h>
23*65523Spendry #include <machine/reg.h>
24*65523Spendry #include <miscfs/procfs/procfs.h>
25*65523Spendry 
26*65523Spendry int
27*65523Spendry procfs_doregs(curp, p, pfs, uio)
28*65523Spendry 	struct proc *curp;
29*65523Spendry 	struct proc *p;
30*65523Spendry 	struct pfsnode *pfs;
31*65523Spendry 	struct uio *uio;
32*65523Spendry {
33*65523Spendry 	int error;
34*65523Spendry 	struct reg r;
35*65523Spendry 	char *kv;
36*65523Spendry 	int kl;
37*65523Spendry 
38*65523Spendry 	kl = sizeof(r);
39*65523Spendry 	kv = (char *) &r;
40*65523Spendry 
41*65523Spendry 	kv += uio->uio_offset;
42*65523Spendry 	kl -= uio->uio_offset;
43*65523Spendry 	if (kl > uio->uio_resid)
44*65523Spendry 		kl = uio->uio_resid;
45*65523Spendry 
46*65523Spendry 	if (kl < 0)
47*65523Spendry 		error = EINVAL;
48*65523Spendry 	else
49*65523Spendry 		error = procfs_read_regs(p, &r);
50*65523Spendry 	if (error == 0)
51*65523Spendry 		error = uiomove(kv, kl, uio);
52*65523Spendry 	if (error == 0 && uio->uio_rw == UIO_WRITE) {
53*65523Spendry 		if (p->p_stat != SSTOP)
54*65523Spendry 			error = EBUSY;
55*65523Spendry 		else
56*65523Spendry 			error = procfs_write_regs(p, &r);
57*65523Spendry 	}
58*65523Spendry 
59*65523Spendry 	uio->uio_offset = 0;
60*65523Spendry 	return (error);
61*65523Spendry }
62