Home | History | Annotate | Line # | Download | only in sparc
      1 /*	$NetBSD: process_machdep.c,v 1.21 2021/01/24 07:36:54 mrg 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.21 2021/01/24 07:36:54 mrg 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 <sys/ptrace.h>
    107 
    108 #include <machine/psl.h>
    109 #include <machine/reg.h>
    110 #include <machine/frame.h>
    111 #include <machine/trap.h>
    112 
    113 int
    114 process_read_regs(struct lwp *l, struct reg *regs)
    115 {
    116 
    117 	/* NOTE: struct reg == struct trapframe */
    118 	memcpy(regs, l->l_md.md_tf, sizeof(*regs));
    119 	return 0;
    120 }
    121 
    122 int
    123 process_write_regs(struct lwp *l, const struct reg *regs)
    124 {
    125 	int	psr = l->l_md.md_tf->tf_psr & ~PSR_ICC;
    126 
    127 	if (((regs->r_pc | regs->r_npc) & 0x03) != 0)
    128 		return EINVAL;
    129 
    130 	memcpy(l->l_md.md_tf, regs, sizeof(*regs));
    131 	l->l_md.md_tf->tf_psr = psr | (regs->r_psr & PSR_ICC);
    132 	return 0;
    133 }
    134 
    135 int
    136 process_sstep(struct lwp *l, int sstep)
    137 {
    138 
    139 	if (sstep)
    140 		return EINVAL;
    141 	return 0;
    142 }
    143 
    144 int
    145 process_set_pc(struct lwp *l, void *addr)
    146 {
    147 
    148 	if (((u_int)addr & 0x03) != 0)
    149 		return EINVAL;
    150 
    151 	l->l_md.md_tf->tf_pc = (u_int)addr;
    152 	l->l_md.md_tf->tf_npc = (u_int)addr + 4;
    153 	return 0;
    154 }
    155 
    156 int
    157 process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
    158 {
    159 	struct fpstate *fs;
    160 
    161 	if ((fs = l->l_md.md_fpstate) == NULL)
    162 		fs = &initfpstate;
    163 
    164 	*regs = fs->fs_reg;
    165 	return 0;
    166 }
    167 
    168 int
    169 process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t sz)
    170 {
    171 	struct fpstate *fs;
    172 
    173 	if ((fs = l->l_md.md_fpstate) == NULL) {
    174 		fs = kmem_zalloc(sizeof(*fs), KM_SLEEP);
    175 		l->l_md.md_fpstate = fs;
    176 	} else {
    177 		/* Reset FP queue in this process `fpstate' */
    178 		fs->fs_qsize = 0;
    179 	}
    180 
    181 	/* Write new values to the FP registers */
    182 	fs->fs_reg = *regs;
    183 
    184 	return 0;
    185 }
    186