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