| 1 | /* Native-dependent code for SuperH running NetBSD, for GDB. |
| 2 | |
| 3 | Copyright 2002, 2003, 2004 Free Software Foundation, Inc. |
| 4 | Contributed by Wasabi Systems, Inc. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | Boston, MA 02111-1307, USA. */ |
| 22 | |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/ptrace.h> |
| 25 | #include <machine/reg.h> |
| 26 | |
| 27 | #include "defs.h" |
| 28 | #include "inferior.h" |
| 29 | |
| 30 | #include "sh-tdep.h" |
| 31 | #include "shnbsd-tdep.h" |
| 32 | |
| 33 | /* Determine if PT_GETREGS fetches this register. */ |
| 34 | #define GETREGS_SUPPLIES(regno) \ |
| 35 | (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \ |
| 36 | || (regno) == PC_REGNUM || (regno) == PR_REGNUM \ |
| 37 | || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \ |
| 38 | || (regno) == SR_REGNUM) |
| 39 | |
| 40 | void |
| 41 | fetch_inferior_registers (int regno) |
| 42 | { |
| 43 | if (regno == -1 || GETREGS_SUPPLIES (regno)) |
| 44 | { |
| 45 | struct reg inferior_registers; |
| 46 | |
| 47 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), |
| 48 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
| 49 | perror_with_name ("Couldn't get registers"); |
| 50 | |
| 51 | shnbsd_supply_reg ((char *) &inferior_registers, regno); |
| 52 | |
| 53 | if (regno != -1) |
| 54 | return; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | store_inferior_registers (int regno) |
| 60 | { |
| 61 | if (regno == -1 || GETREGS_SUPPLIES (regno)) |
| 62 | { |
| 63 | struct reg inferior_registers; |
| 64 | |
| 65 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), |
| 66 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
| 67 | perror_with_name ("Couldn't get registers"); |
| 68 | |
| 69 | shnbsd_fill_reg ((char *) &inferior_registers, regno); |
| 70 | |
| 71 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), |
| 72 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
| 73 | perror_with_name ("Couldn't set registers"); |
| 74 | |
| 75 | if (regno != -1) |
| 76 | return; |
| 77 | } |
| 78 | } |