Update
[gdb.git] / gdb / shnbsd-nat.c
blob9b52194a3af1ac0d05c581fe768780cd4659fdb6
1 /* Native-dependent code for NetBSD/sh.
3 Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 Contributed by Wasabi Systems, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "defs.h"
24 #include "inferior.h"
26 #include <sys/types.h>
27 #include <sys/ptrace.h>
28 #include <machine/reg.h>
30 #include "sh-tdep.h"
31 #include "shnbsd-tdep.h"
32 #include "inf-ptrace.h"
33 #include "regcache.h"
36 /* Determine if PT_GETREGS fetches this register. */
37 #define GETREGS_SUPPLIES(gdbarch, regno) \
38 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
39 || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
40 || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
41 || (regno) == SR_REGNUM)
43 static void
44 shnbsd_fetch_inferior_registers (struct regcache *regcache, int regno)
46 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
48 struct reg inferior_registers;
50 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
51 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
52 perror_with_name (_("Couldn't get registers"));
54 shnbsd_supply_reg (regcache, (char *) &inferior_registers, regno);
56 if (regno != -1)
57 return;
61 static void
62 shnbsd_store_inferior_registers (struct regcache *regcache, int regno)
64 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
66 struct reg inferior_registers;
68 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
69 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
70 perror_with_name (_("Couldn't get registers"));
72 shnbsd_fill_reg (regcache, (char *) &inferior_registers, regno);
74 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
75 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
76 perror_with_name (_("Couldn't set registers"));
78 if (regno != -1)
79 return;
83 /* Provide a prototype to silence -Wmissing-prototypes. */
84 void _initialize_shnbsd_nat (void);
86 void
87 _initialize_shnbsd_nat (void)
89 struct target_ops *t;
91 t = inf_ptrace_target ();
92 t->to_fetch_registers = shnbsd_fetch_inferior_registers;
93 t->to_store_registers = shnbsd_store_inferior_registers;
94 add_target (t);