[BACK]Return to process_machdep.c CVS log [TXT][DIR] Up to [local] / sys / arch / sh / sh

Annotation of sys/arch/sh/sh/process_machdep.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: process_machdep.c,v 1.3 2007/03/02 06:11:54 miod Exp $        */
                      2: /*     $NetBSD: process_machdep.c,v 1.12 2006/01/21 04:12:22 uwe Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 2007 Miodrag Vallat.
                      6:  *
                      7:  * Permission to use, copy, modify, and distribute this software for any
                      8:  * purpose with or without fee is hereby granted, provided that the above
                      9:  * copyright notice, this permission notice, and the disclaimer below
                     10:  * appear in all copies.
                     11:  *
                     12:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     13:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     14:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     15:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     16:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     17:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     18:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     19:  */
                     20: /*
                     21:  * Copyright (c) 1993 The Regents of the University of California.
                     22:  * All rights reserved.
                     23:  *
                     24:  * This code is derived from software contributed to Berkeley by
                     25:  * Jan-Simon Pendry.
                     26:  *
                     27:  * Redistribution and use in source and binary forms, with or without
                     28:  * modification, are permitted provided that the following conditions
                     29:  * are met:
                     30:  * 1. Redistributions of source code must retain the above copyright
                     31:  *    notice, this list of conditions and the following disclaimer.
                     32:  * 2. Redistributions in binary form must reproduce the above copyright
                     33:  *    notice, this list of conditions and the following disclaimer in the
                     34:  *    documentation and/or other materials provided with the distribution.
                     35:  * 3. Neither the name of the University nor the names of its contributors
                     36:  *    may be used to endorse or promote products derived from this software
                     37:  *    without specific prior written permission.
                     38:  *
                     39:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     40:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     41:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     42:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     43:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     44:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     45:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     46:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     47:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     48:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     49:  * SUCH DAMAGE.
                     50:  *
                     51:  * From:
                     52:  *     Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
                     53:  */
                     54: /*
                     55:  * Copyright (c) 1995, 1996, 1997
                     56:  *     Charles M. Hannum.  All rights reserved.
                     57:  * Copyright (c) 1993 Jan-Simon Pendry
                     58:  * All rights reserved.
                     59:  *
                     60:  * This code is derived from software contributed to Berkeley by
                     61:  * Jan-Simon Pendry.
                     62:  *
                     63:  * Redistribution and use in source and binary forms, with or without
                     64:  * modification, are permitted provided that the following conditions
                     65:  * are met:
                     66:  * 1. Redistributions of source code must retain the above copyright
                     67:  *    notice, this list of conditions and the following disclaimer.
                     68:  * 2. Redistributions in binary form must reproduce the above copyright
                     69:  *    notice, this list of conditions and the following disclaimer in the
                     70:  *    documentation and/or other materials provided with the distribution.
                     71:  * 3. All advertising materials mentioning features or use of this software
                     72:  *    must display the following acknowledgement:
                     73:  *     This product includes software developed by the University of
                     74:  *     California, Berkeley and its contributors.
                     75:  * 4. Neither the name of the University nor the names of its contributors
                     76:  *    may be used to endorse or promote products derived from this software
                     77:  *    without specific prior written permission.
                     78:  *
                     79:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     80:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     81:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     82:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     83:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     84:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     85:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     86:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     87:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     88:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     89:  * SUCH DAMAGE.
                     90:  *
                     91:  * From:
                     92:  *     Id: procfs_i386.c,v 4.1 1993/12/17 10:47:45 jsp Rel
                     93:  */
                     94:
                     95: /*
                     96:  * This file may seem a bit stylized, but that so that it's easier to port.
                     97:  * Functions to be implemented here are:
                     98:  *
                     99:  * process_read_regs(proc, regs)
                    100:  *     Get the current user-visible register set from the process
                    101:  *     and copy it into the regs structure (<machine/reg.h>).
                    102:  *     The process is stopped at the time read_regs is called.
                    103:  *
                    104:  * process_read_fpregs(proc, fpregs)
                    105:  *     Same as the above, but for floating-point registers.
                    106:  *
                    107:  * process_write_regs(proc, regs)
                    108:  *     Update the current register set from the passed in regs
                    109:  *     structure.  Take care to avoid clobbering special CPU
                    110:  *     registers or privileged bits in the PSL.
                    111:  *     The process is stopped at the time write_regs is called.
                    112:  *
                    113:  * process_write_fpregs(proc, fpregs)
                    114:  *     Same as the above, but for floating-point registers.
                    115:  *
                    116:  * process_sstep(proc)
                    117:  *     Arrange for the process to trap after executing a single instruction.
                    118:  *
                    119:  * process_set_pc(proc)
                    120:  *     Set the process's program counter.
                    121:  */
                    122:
                    123: #include <sys/param.h>
                    124: #include <sys/systm.h>
                    125: #include <sys/time.h>
                    126: #include <sys/kernel.h>
                    127: #include <sys/proc.h>
                    128: #include <sys/user.h>
                    129: #include <sys/vnode.h>
                    130: #include <sys/ptrace.h>
                    131:
                    132: #include <machine/cpu.h>
                    133: #include <machine/psl.h>
                    134: #include <machine/reg.h>
                    135:
                    136: static inline struct trapframe *
                    137: process_frame(struct proc *p)
                    138: {
                    139:        return (p->p_md.md_regs);
                    140: }
                    141:
                    142: int
                    143: process_read_regs(struct proc *p, struct reg *regs)
                    144: {
                    145:        struct trapframe *tf = process_frame(p);
                    146:
                    147:        regs->r_spc = tf->tf_spc;
                    148:        regs->r_ssr = tf->tf_ssr;
                    149:        regs->r_macl = tf->tf_macl;
                    150:        regs->r_mach = tf->tf_mach;
                    151:        regs->r_pr = tf->tf_pr;
                    152:        regs->r_r14 = tf->tf_r14;
                    153:        regs->r_r13 = tf->tf_r13;
                    154:        regs->r_r12 = tf->tf_r12;
                    155:        regs->r_r11 = tf->tf_r11;
                    156:        regs->r_r10 = tf->tf_r10;
                    157:        regs->r_r9 = tf->tf_r9;
                    158:        regs->r_r8 = tf->tf_r8;
                    159:        regs->r_r7 = tf->tf_r7;
                    160:        regs->r_r6 = tf->tf_r6;
                    161:        regs->r_r5 = tf->tf_r5;
                    162:        regs->r_r4 = tf->tf_r4;
                    163:        regs->r_r3 = tf->tf_r3;
                    164:        regs->r_r2 = tf->tf_r2;
                    165:        regs->r_r1 = tf->tf_r1;
                    166:        regs->r_r0 = tf->tf_r0;
                    167:        regs->r_r15 = tf->tf_r15;
                    168:
                    169:        return (0);
                    170: }
                    171:
                    172: int
                    173: process_read_fpregs(struct proc *p, struct fpreg *fpregs)
                    174: {
                    175: #ifdef SH4
                    176:        if (CPU_IS_SH4) {
                    177:                struct pcb *pcb = p->p_md.md_pcb;
                    178:
                    179:                if (p == curproc)
                    180:                        fpu_save(&pcb->pcb_fp);
                    181:
                    182:                bcopy(&pcb->pcb_fp, fpregs, sizeof(*fpregs));
                    183:        }
                    184: #endif
                    185: #ifdef SH3
                    186:        if (CPU_IS_SH3)
                    187:                return (EINVAL);
                    188: #endif
                    189:        return (0);
                    190: }
                    191:
                    192: #ifdef PTRACE
                    193:
                    194: int
                    195: process_write_regs(struct proc *p, struct reg *regs)
                    196: {
                    197:        struct trapframe *tf = process_frame(p);
                    198:
                    199:        /*
                    200:         * Check for security violations.
                    201:         */
                    202:        if (((regs->r_ssr ^ tf->tf_ssr) & PSL_USERSTATIC) != 0)
                    203:                return (EINVAL);
                    204:
                    205:        tf->tf_spc = regs->r_spc;
                    206:        tf->tf_ssr = regs->r_ssr;
                    207:        tf->tf_pr = regs->r_pr;
                    208:
                    209:        tf->tf_mach = regs->r_mach;
                    210:        tf->tf_macl = regs->r_macl;
                    211:        tf->tf_r14 = regs->r_r14;
                    212:        tf->tf_r13 = regs->r_r13;
                    213:        tf->tf_r12 = regs->r_r12;
                    214:        tf->tf_r11 = regs->r_r11;
                    215:        tf->tf_r10 = regs->r_r10;
                    216:        tf->tf_r9 = regs->r_r9;
                    217:        tf->tf_r8 = regs->r_r8;
                    218:        tf->tf_r7 = regs->r_r7;
                    219:        tf->tf_r6 = regs->r_r6;
                    220:        tf->tf_r5 = regs->r_r5;
                    221:        tf->tf_r4 = regs->r_r4;
                    222:        tf->tf_r3 = regs->r_r3;
                    223:        tf->tf_r2 = regs->r_r2;
                    224:        tf->tf_r1 = regs->r_r1;
                    225:        tf->tf_r0 = regs->r_r0;
                    226:        tf->tf_r15 = regs->r_r15;
                    227:
                    228:        return (0);
                    229: }
                    230:
                    231: int
                    232: process_write_fpregs(struct proc *p, struct fpreg *fpregs)
                    233: {
                    234: #ifdef SH4
                    235:        if (CPU_IS_SH4) {
                    236:                struct pcb *pcb = p->p_md.md_pcb;
                    237:
                    238:                bcopy(fpregs, &pcb->pcb_fp, sizeof(*fpregs));
                    239:
                    240:                /* force update of live cpu registers */
                    241:                if (p == curproc)
                    242:                        fpu_restore(&pcb->pcb_fp);
                    243:        }
                    244: #endif
                    245: #ifdef SH3
                    246:        if (CPU_IS_SH3)
                    247:                return (EINVAL);
                    248: #endif
                    249:        return (0);
                    250: }
                    251:
                    252: int
                    253: process_sstep(struct proc *p, int sstep)
                    254: {
                    255:        if (sstep)
                    256:                p->p_md.md_flags |= MDP_STEP;
                    257:        else
                    258:                p->p_md.md_flags &= ~MDP_STEP;
                    259:
                    260:        return (0);
                    261: }
                    262:
                    263: int
                    264: process_set_pc(struct proc *p, caddr_t addr)
                    265: {
                    266:        struct trapframe *tf = process_frame(p);
                    267:
                    268:        tf->tf_spc = (int)addr;
                    269:
                    270:        return (0);
                    271: }
                    272:
                    273: #endif /* PTRACE */

CVSweb