Annotation of sys/arch/arm/arm/process_machdep.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: process_machdep.c,v 1.3 2005/12/16 21:36:31 miod Exp $ */
! 2: /* $NetBSD: process_machdep.c,v 1.11 2003/08/07 16:26:52 agc Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1993 The Regents of the University of California.
! 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. Neither the name of the University nor the names of its contributors
! 20: * may be used to endorse or promote products derived from this software
! 21: * without specific prior written permission.
! 22: *
! 23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 33: * SUCH DAMAGE.
! 34: *
! 35: * From:
! 36: * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
! 37: */
! 38:
! 39: /*
! 40: * Copyright (c) 1995 Frank Lancaster. All rights reserved.
! 41: * Copyright (c) 1995 Tools GmbH. All rights reserved.
! 42: * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
! 43: * Copyright (c) 1993 Jan-Simon Pendry
! 44: * All rights reserved.
! 45: *
! 46: * This code is derived from software contributed to Berkeley by
! 47: * Jan-Simon Pendry.
! 48: *
! 49: * Redistribution and use in source and binary forms, with or without
! 50: * modification, are permitted provided that the following conditions
! 51: * are met:
! 52: * 1. Redistributions of source code must retain the above copyright
! 53: * notice, this list of conditions and the following disclaimer.
! 54: * 2. Redistributions in binary form must reproduce the above copyright
! 55: * notice, this list of conditions and the following disclaimer in the
! 56: * documentation and/or other materials provided with the distribution.
! 57: * 3. All advertising materials mentioning features or use of this software
! 58: * must display the following acknowledgement:
! 59: * This product includes software developed by the University of
! 60: * California, Berkeley and its contributors.
! 61: * 4. Neither the name of the University nor the names of its contributors
! 62: * may be used to endorse or promote products derived from this software
! 63: * without specific prior written permission.
! 64: *
! 65: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 66: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 67: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 68: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 69: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 70: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 71: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 72: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 73: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 74: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 75: * SUCH DAMAGE.
! 76: *
! 77: * From:
! 78: * Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
! 79: */
! 80:
! 81: /*
! 82: * This file may seem a bit stylized, but that so that it's easier to port.
! 83: * Functions to be implemented here are:
! 84: *
! 85: * process_read_regs(proc, regs)
! 86: * Get the current user-visible register set from the process
! 87: * and copy it into the regs structure (<machine/reg.h>).
! 88: * The process is stopped at the time read_regs is called.
! 89: *
! 90: * process_write_regs(proc, regs)
! 91: * Update the current register set from the passed in regs
! 92: * structure. Take care to avoid clobbering special CPU
! 93: * registers or privileged bits in the PSL.
! 94: * The process is stopped at the time write_regs is called.
! 95: *
! 96: * process_sstep(proc, sstep)
! 97: * Arrange for the process to trap or not trap depending on sstep
! 98: * after executing a single instruction.
! 99: *
! 100: * process_set_pc(proc)
! 101: * Set the process's program counter.
! 102: */
! 103:
! 104: #include <sys/param.h>
! 105:
! 106: #include <sys/proc.h>
! 107: #include <sys/ptrace.h>
! 108: #include <sys/systm.h>
! 109: #include <sys/user.h>
! 110:
! 111: #include <machine/frame.h>
! 112: #include <machine/pcb.h>
! 113: #include <machine/reg.h>
! 114:
! 115: #include <arm/armreg.h>
! 116:
! 117: #ifdef ARMFPE
! 118: #include <arm/fpe-arm/armfpe.h>
! 119: #endif
! 120:
! 121: static __inline struct trapframe *
! 122: process_frame(struct proc *p)
! 123: {
! 124:
! 125: return p->p_addr->u_pcb.pcb_tf;
! 126: }
! 127:
! 128: int
! 129: process_read_regs(struct proc *p, struct reg *regs)
! 130: {
! 131: struct trapframe *tf = process_frame(p);
! 132:
! 133: KASSERT(tf != NULL);
! 134: bcopy((caddr_t)&tf->tf_r0, (caddr_t)regs->r, sizeof(regs->r));
! 135: regs->r_sp = tf->tf_usr_sp;
! 136: regs->r_lr = tf->tf_usr_lr;
! 137: regs->r_pc = tf->tf_pc;
! 138: regs->r_cpsr = tf->tf_spsr;
! 139:
! 140: #ifdef DIAGNOSTIC
! 141: if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
! 142: && tf->tf_spsr & I32_bit)
! 143: panic("process_read_regs: Interrupts blocked in user process");
! 144: #endif
! 145:
! 146: return(0);
! 147: }
! 148:
! 149: int
! 150: process_read_fpregs(struct proc *p, struct fpreg *regs)
! 151: {
! 152: #ifdef ARMFPE
! 153: arm_fpe_getcontext(p, regs);
! 154: return(0);
! 155: #else /* ARMFPE */
! 156: /* No hardware FP support */
! 157: memset(regs, 0, sizeof(struct fpreg));
! 158: return(0);
! 159: #endif /* ARMFPE */
! 160: }
! 161:
! 162: #ifdef PTRACE
! 163:
! 164: int
! 165: process_write_regs(struct proc *p, struct reg *regs)
! 166: {
! 167: struct trapframe *tf = process_frame(p);
! 168:
! 169: KASSERT(tf != NULL);
! 170: bcopy((caddr_t)regs->r, (caddr_t)&tf->tf_r0, sizeof(regs->r));
! 171: tf->tf_usr_sp = regs->r_sp;
! 172: tf->tf_usr_lr = regs->r_lr;
! 173: #ifdef __PROG32
! 174: tf->tf_pc = regs->r_pc;
! 175: tf->tf_spsr &= ~PSR_FLAGS;
! 176: tf->tf_spsr |= regs->r_cpsr & PSR_FLAGS;
! 177: #ifdef DIAGNOSTIC
! 178: if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
! 179: && tf->tf_spsr & I32_bit)
! 180: panic("process_write_regs: Interrupts blocked in user process");
! 181: #endif
! 182: #else /* __PROG26 */
! 183: if ((regs->r_pc & (R15_MODE | R15_IRQ_DISABLE | R15_FIQ_DISABLE)) != 0)
! 184: return EPERM;
! 185:
! 186: tf->tf_r15 = regs->r_pc;
! 187: #endif
! 188:
! 189: return(0);
! 190: }
! 191:
! 192: int
! 193: process_write_fpregs(struct proc *p, struct fpreg *regs)
! 194: {
! 195: #ifdef ARMFPE
! 196: arm_fpe_setcontext(p, regs);
! 197: return(0);
! 198: #else /* ARMFPE */
! 199: /* No hardware FP support */
! 200: return(0);
! 201: #endif /* ARMFPE */
! 202: }
! 203:
! 204: int
! 205: process_sstep(struct proc *p, int sstep)
! 206: {
! 207: if (sstep)
! 208: return (EINVAL);
! 209: return 0;
! 210: }
! 211:
! 212: int
! 213: process_set_pc(struct proc *p, caddr_t addr)
! 214: {
! 215: struct trapframe *tf = process_frame(p);
! 216:
! 217: KASSERT(tf != NULL);
! 218: #ifdef __PROG32
! 219: tf->tf_pc = (int)addr;
! 220: #else /* __PROG26 */
! 221: /* Only set the PC, not the PSR */
! 222: if (((register_t)addr & R15_PC) != (register_t)addr)
! 223: return EINVAL;
! 224: tf->tf_r15 = (tf->tf_r15 & ~R15_PC) | (register_t)addr;
! 225: #endif
! 226:
! 227: return (0);
! 228: }
! 229:
! 230: #endif /* PTRACE */
CVSweb