1*6881a400Schristos /* Native-dependent code for NetBSD/sh. 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 2002-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos Contributed by Wasabi Systems, Inc. 6*6881a400Schristos 7*6881a400Schristos This file is part of GDB. 8*6881a400Schristos 9*6881a400Schristos This program is free software; you can redistribute it and/or modify 10*6881a400Schristos it under the terms of the GNU General Public License as published by 11*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 12*6881a400Schristos (at your option) any later version. 13*6881a400Schristos 14*6881a400Schristos This program is distributed in the hope that it will be useful, 15*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 16*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*6881a400Schristos GNU General Public License for more details. 18*6881a400Schristos 19*6881a400Schristos You should have received a copy of the GNU General Public License 20*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21*6881a400Schristos 22*6881a400Schristos #include "defs.h" 23*6881a400Schristos #include "inferior.h" 24*6881a400Schristos 25*6881a400Schristos #include <sys/types.h> 26*6881a400Schristos #include <sys/ptrace.h> 27*6881a400Schristos #include <machine/reg.h> 28*6881a400Schristos 29*6881a400Schristos #include "sh-tdep.h" 30*6881a400Schristos #include "inf-ptrace.h" 31*6881a400Schristos #include "netbsd-nat.h" 32*6881a400Schristos #include "regcache.h" 33*6881a400Schristos 34*6881a400Schristos struct sh_nbsd_nat_target final : public nbsd_nat_target 35*6881a400Schristos { 36*6881a400Schristos void fetch_registers (struct regcache *, int) override; 37*6881a400Schristos void store_registers (struct regcache *, int) override; 38*6881a400Schristos }; 39*6881a400Schristos 40*6881a400Schristos static sh_nbsd_nat_target the_sh_nbsd_nat_target; 41*6881a400Schristos 42*6881a400Schristos /* Determine if PT_GETREGS fetches this register. */ 43*6881a400Schristos #define GETREGS_SUPPLIES(gdbarch, regno) \ 44*6881a400Schristos (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \ 45*6881a400Schristos || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \ 46*6881a400Schristos || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \ 47*6881a400Schristos || (regno) == SR_REGNUM || (regno) == GBR_REGNUM) 48*6881a400Schristos 49*6881a400Schristos /* Sizeof `struct reg' in <machine/reg.h>. */ 50*6881a400Schristos #define SHNBSD_SIZEOF_GREGS (22 * 4) 51*6881a400Schristos 52*6881a400Schristos void 53*6881a400Schristos sh_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno) 54*6881a400Schristos { 55*6881a400Schristos pid_t pid = regcache->ptid ().pid (); 56*6881a400Schristos int lwp = regcache->ptid ().lwp (); 57*6881a400Schristos 58*6881a400Schristos if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno)) 59*6881a400Schristos { 60*6881a400Schristos struct reg inferior_registers; 61*6881a400Schristos 62*6881a400Schristos if (ptrace (PT_GETREGS, pid, 63*6881a400Schristos (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1) 64*6881a400Schristos perror_with_name (_("Couldn't get registers")); 65*6881a400Schristos 66*6881a400Schristos sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno, 67*6881a400Schristos (char *) &inferior_registers, 68*6881a400Schristos SHNBSD_SIZEOF_GREGS); 69*6881a400Schristos 70*6881a400Schristos if (regno != -1) 71*6881a400Schristos return; 72*6881a400Schristos } 73*6881a400Schristos } 74*6881a400Schristos 75*6881a400Schristos void 76*6881a400Schristos sh_nbsd_nat_target::store_registers (struct regcache *regcache, int regno) 77*6881a400Schristos { 78*6881a400Schristos pid_t pid = regcache->ptid ().pid (); 79*6881a400Schristos int lwp = regcache->ptid ().lwp (); 80*6881a400Schristos 81*6881a400Schristos if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno)) 82*6881a400Schristos { 83*6881a400Schristos struct reg inferior_registers; 84*6881a400Schristos 85*6881a400Schristos if (ptrace (PT_GETREGS, pid, 86*6881a400Schristos (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1) 87*6881a400Schristos perror_with_name (_("Couldn't get registers")); 88*6881a400Schristos 89*6881a400Schristos sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno, 90*6881a400Schristos (char *) &inferior_registers, 91*6881a400Schristos SHNBSD_SIZEOF_GREGS); 92*6881a400Schristos 93*6881a400Schristos if (ptrace (PT_SETREGS, pid, 94*6881a400Schristos (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1) 95*6881a400Schristos perror_with_name (_("Couldn't set registers")); 96*6881a400Schristos 97*6881a400Schristos if (regno != -1) 98*6881a400Schristos return; 99*6881a400Schristos } 100*6881a400Schristos } 101*6881a400Schristos 102*6881a400Schristos void _initialize_shnbsd_nat (); 103*6881a400Schristos void 104*6881a400Schristos _initialize_shnbsd_nat () 105*6881a400Schristos { 106*6881a400Schristos add_inf_child_target (&the_sh_nbsd_nat_target); 107*6881a400Schristos } 108