117aad0dfSpendry /*
2da274a0aSbostic  * Copyright (c) 1993
3da274a0aSbostic  *	The Regents of the University of California.  All rights reserved.
417aad0dfSpendry  * Copyright (c) 1993 Jan-Simon Pendry
517aad0dfSpendry  *
617aad0dfSpendry  * This code is derived from software contributed to Berkeley by
717aad0dfSpendry  * Jan-Simon Pendry.
817aad0dfSpendry  *
917aad0dfSpendry  * %sccs.include.redist.c%
1017aad0dfSpendry  *
11*e5452551Spendry  *	@(#)procfs_machdep.c	8.4 (Berkeley) 06/15/94
1217aad0dfSpendry  *
1317aad0dfSpendry  * From:
1417aad0dfSpendry  *	$Id: procfs_i386.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
1517aad0dfSpendry  */
1617aad0dfSpendry 
1717aad0dfSpendry /*
1817aad0dfSpendry  * Functions to be implemented here are:
1917aad0dfSpendry  *
2017aad0dfSpendry  * procfs_read_regs(proc, regs)
2117aad0dfSpendry  *	Get the current user-visible register set from the process
2217aad0dfSpendry  *	and copy it into the regs structure (<machine/reg.h>).
2317aad0dfSpendry  *	The process is stopped at the time read_regs is called.
2417aad0dfSpendry  *
2517aad0dfSpendry  * procfs_write_regs(proc, regs)
2617aad0dfSpendry  *	Update the current register set from the passed in regs
2717aad0dfSpendry  *	structure.  Take care to avoid clobbering special CPU
2817aad0dfSpendry  *	registers or privileged bits in the PSL.
2917aad0dfSpendry  *	The process is stopped at the time write_regs is called.
3017aad0dfSpendry  *
31809b6107Spendry  * procfs_read_fpregs, procfs_write_fpregs
32809b6107Spendry  *	deal with the floating point register set, otherwise as above.
33809b6107Spendry  *
3417aad0dfSpendry  * procfs_sstep(proc)
3517aad0dfSpendry  *	Arrange for the process to trap after executing a single instruction.
3617aad0dfSpendry  *
3717aad0dfSpendry  * procfs_fix_sstep(proc)
3817aad0dfSpendry  *	Cleanup process state after executing a single-step instruction.
3917aad0dfSpendry  */
4017aad0dfSpendry 
4117aad0dfSpendry #include <sys/param.h>
4217aad0dfSpendry #include <sys/systm.h>
4317aad0dfSpendry #include <sys/time.h>
4417aad0dfSpendry #include <sys/kernel.h>
4517aad0dfSpendry #include <sys/proc.h>
4617aad0dfSpendry #include <sys/user.h>
4717aad0dfSpendry #include <sys/vnode.h>
4817aad0dfSpendry #include <machine/psl.h>
4917aad0dfSpendry #include <machine/reg.h>
5017aad0dfSpendry /*#include <machine/frame.h>*/
5117aad0dfSpendry #include <miscfs/procfs/procfs.h>
5217aad0dfSpendry 
5317aad0dfSpendry int
procfs_read_regs(p,regs)5417aad0dfSpendry procfs_read_regs(p, regs)
5517aad0dfSpendry 	struct proc *p;
5617aad0dfSpendry 	struct reg *regs;
5717aad0dfSpendry {
5817aad0dfSpendry 	struct frame *f;
5917aad0dfSpendry 
6017aad0dfSpendry 	if ((p->p_flag & P_INMEM) == 0)
6117aad0dfSpendry 		return (EIO);
6217aad0dfSpendry 
6317aad0dfSpendry 	f = (struct frame *) p->p_md.md_regs;
6417aad0dfSpendry 	bcopy((void *) f->f_regs, (void *) regs->r_regs, sizeof(regs->r_regs));
6517aad0dfSpendry 	regs->r_pc = f->f_pc;
6617aad0dfSpendry 	regs->r_sr = f->f_sr;
6717aad0dfSpendry 
6817aad0dfSpendry 	return (0);
6917aad0dfSpendry }
7017aad0dfSpendry 
7117aad0dfSpendry /*
7217aad0dfSpendry  * Update the process's current register
7317aad0dfSpendry  * set.  Depending on the architecture this
7417aad0dfSpendry  * may have fix-up work to do, especially
7517aad0dfSpendry  * if the IAR or PCW are modified.
7617aad0dfSpendry  */
7717aad0dfSpendry int
procfs_write_regs(p,regs)7817aad0dfSpendry procfs_write_regs(p, regs)
7917aad0dfSpendry 	struct proc *p;
8017aad0dfSpendry 	struct reg *regs;
8117aad0dfSpendry {
8217aad0dfSpendry 	struct frame *f;
8317aad0dfSpendry 
8417aad0dfSpendry 	if ((p->p_flag & P_INMEM) == 0)
8517aad0dfSpendry 		return (EIO);
8617aad0dfSpendry 
8717aad0dfSpendry 	f = (struct frame *) p->p_md.md_regs;
8817aad0dfSpendry 	bcopy((void *) regs->r_regs, (void *) f->f_regs, sizeof(f->f_regs));
8917aad0dfSpendry 	f->f_pc = regs->r_pc;
9017aad0dfSpendry 	f->f_sr = regs->r_sr;
9117aad0dfSpendry 
9217aad0dfSpendry 	return (0);
9317aad0dfSpendry }
9417aad0dfSpendry 
9517aad0dfSpendry int
procfs_read_fpregs(p,fpregs)96809b6107Spendry procfs_read_fpregs(p, fpregs)
97809b6107Spendry 	struct proc *p;
98809b6107Spendry 	struct fpreg *fpregs;
99809b6107Spendry {
100809b6107Spendry 
101809b6107Spendry 	return (EOPNOTSUPP);
102809b6107Spendry }
103809b6107Spendry 
104809b6107Spendry int
procfs_write_fpregs(p,fpregs)105809b6107Spendry procfs_write_fpregs(p, fpregs)
106809b6107Spendry 	struct proc *p;
107809b6107Spendry 	struct fpreg *fpregs;
108809b6107Spendry {
109809b6107Spendry 
110809b6107Spendry 	return (EOPNOTSUPP);
111809b6107Spendry }
112809b6107Spendry 
113809b6107Spendry 
114809b6107Spendry int
procfs_sstep(p,sstep)115*e5452551Spendry procfs_sstep(p, sstep)
11617aad0dfSpendry 	struct proc *p;
117*e5452551Spendry 	int sstep;
11817aad0dfSpendry {
11917aad0dfSpendry 	int error;
12017aad0dfSpendry 	struct reg r;
12117aad0dfSpendry 
12217aad0dfSpendry 	error = procfs_read_regs(p, &r);
12317aad0dfSpendry 	if (error == 0) {
124*e5452551Spendry 		if (sstep)
125*e5452551Spendry 			r.r_sr |= PSL_T;
126*e5452551Spendry 		else
12717aad0dfSpendry 			r.r_sr |= PSL_T;
12817aad0dfSpendry 		error = procfs_write_regs(p, &r);
12917aad0dfSpendry 	}
13017aad0dfSpendry 
13117aad0dfSpendry 	return (error);
13217aad0dfSpendry }
13317aad0dfSpendry 
13417aad0dfSpendry void
procfs_fix_sstep(p)13517aad0dfSpendry procfs_fix_sstep(p)
13617aad0dfSpendry 	struct proc *p;
13717aad0dfSpendry {
13817aad0dfSpendry }
139