1 /* $NetBSD: process_machdep.c,v 1.7 1999/12/29 15:21:27 pk Exp $ */ 2 3 /* 4 * Copyright (c) 1993 The Regents of the University of California. 5 * Copyright (c) 1993 Jan-Simon Pendry 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * from: Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel 40 */ 41 42 /* 43 * This file may seem a bit stylized, but that so that it's easier to port. 44 * Functions to be implemented here are: 45 * 46 * process_read_regs(proc, regs) 47 * Get the current user-visible register set from the process 48 * and copy it into the regs structure (<machine/reg.h>). 49 * The process is stopped at the time read_regs is called. 50 * 51 * process_write_regs(proc, regs) 52 * Update the current register set from the passed in regs 53 * structure. Take care to avoid clobbering special CPU 54 * registers or privileged bits in the PSL. 55 * The process is stopped at the time write_regs is called. 56 * 57 * process_sstep(proc) 58 * Arrange for the process to trap after executing a single instruction. 59 * 60 * process_set_pc(proc) 61 * Set the process's program counter. 62 */ 63 64 #include <sys/param.h> 65 #include <sys/systm.h> 66 #include <sys/time.h> 67 #include <sys/kernel.h> 68 #include <sys/proc.h> 69 #include <sys/user.h> 70 #include <sys/vnode.h> 71 #include <machine/psl.h> 72 #include <machine/reg.h> 73 #include <machine/frame.h> 74 #include <sys/ptrace.h> 75 76 int 77 process_read_regs(p, regs) 78 struct proc *p; 79 struct reg *regs; 80 { 81 /* NOTE: struct reg == struct trapframe */ 82 bcopy(p->p_md.md_tf, (caddr_t)regs, sizeof(struct reg)); 83 return (0); 84 } 85 86 int 87 process_write_regs(p, regs) 88 struct proc *p; 89 struct reg *regs; 90 { 91 int psr = p->p_md.md_tf->tf_psr & ~PSR_ICC; 92 bcopy((caddr_t)regs, p->p_md.md_tf, sizeof(struct reg)); 93 p->p_md.md_tf->tf_psr = psr | (regs->r_psr & PSR_ICC); 94 return (0); 95 } 96 97 int 98 process_sstep(p, sstep) 99 struct proc *p; 100 int sstep; 101 { 102 if (sstep) 103 return (EINVAL); 104 return (0); 105 } 106 107 int 108 process_set_pc(p, addr) 109 struct proc *p; 110 caddr_t addr; 111 { 112 p->p_md.md_tf->tf_pc = (u_int)addr; 113 p->p_md.md_tf->tf_npc = (u_int)addr + 4; 114 return (0); 115 } 116 117 int 118 process_read_fpregs(p, regs) 119 struct proc *p; 120 struct fpreg *regs; 121 { 122 extern struct fpstate initfpstate; 123 struct fpstate *statep = &initfpstate; 124 125 /* NOTE: struct fpreg == prefix of struct fpstate */ 126 if (p->p_md.md_fpstate) 127 statep = p->p_md.md_fpstate; 128 bcopy(statep, regs, sizeof(struct fpreg)); 129 return (0); 130 } 131 132 int 133 process_write_fpregs(p, regs) 134 struct proc *p; 135 struct fpreg *regs; 136 { 137 if (p->p_md.md_fpstate == NULL) 138 return (EINVAL); 139 140 /* Write new values to the FP registers */ 141 bcopy(regs, p->p_md.md_fpstate, sizeof(struct fpreg)); 142 143 /* Reset FP queue in this process `fpstate' */ 144 p->p_md.md_fpstate->fs_qsize = 0; 145 146 return (0); 147 } 148