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