]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/shnbsd-nat.c
* target.h (struct regcache): Add forward declaration.
[thirdparty/binutils-gdb.git] / gdb / shnbsd-nat.c
CommitLineData
bd372731
MK
1/* Native-dependent code for NetBSD/sh.
2
6aba47ca 3 Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
9f8e0089 4
13a38d45
JT
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
197e01b6
EZ
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
13a38d45 23
bd372731
MK
24#include "defs.h"
25#include "inferior.h"
26
13a38d45
JT
27#include <sys/types.h>
28#include <sys/ptrace.h>
29#include <machine/reg.h>
30
97a5b208 31#include "sh-tdep.h"
4015edd1 32#include "shnbsd-tdep.h"
bd372731 33#include "inf-ptrace.h"
4e3269e3
UW
34#include "regcache.h"
35
13a38d45
JT
36
37/* Determine if PT_GETREGS fetches this register. */
38#define GETREGS_SUPPLIES(regno) \
39 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
40|| (regno) == PC_REGNUM || (regno) == PR_REGNUM \
41|| (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
42|| (regno) == SR_REGNUM)
43
bd372731 44static void
56be3814 45shnbsd_fetch_inferior_registers (struct regcache *regcache, int regno)
13a38d45
JT
46{
47 if (regno == -1 || GETREGS_SUPPLIES (regno))
48 {
49 struct reg inferior_registers;
50
51 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
dfeafa2f 52 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 53 perror_with_name (_("Couldn't get registers"));
13a38d45 54
56be3814 55 shnbsd_supply_reg (regcache, (char *) &inferior_registers, regno);
13a38d45
JT
56
57 if (regno != -1)
58 return;
59 }
60}
61
bd372731 62static void
56be3814 63shnbsd_store_inferior_registers (struct regcache *regcache, int regno)
13a38d45
JT
64{
65 if (regno == -1 || GETREGS_SUPPLIES (regno))
66 {
67 struct reg inferior_registers;
68
69 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
dfeafa2f 70 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 71 perror_with_name (_("Couldn't get registers"));
13a38d45 72
56be3814 73 shnbsd_fill_reg (regcache, (char *) &inferior_registers, regno);
13a38d45
JT
74
75 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
dfeafa2f 76 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 77 perror_with_name (_("Couldn't set registers"));
13a38d45
JT
78
79 if (regno != -1)
80 return;
81 }
82}
bd372731
MK
83
84/* Provide a prototype to silence -Wmissing-prototypes. */
85void _initialize_shnbsd_nat (void);
86
87void
88_initialize_shnbsd_nat (void)
89{
90 struct target_ops *t;
91
92 t = inf_ptrace_target ();
93 t->to_fetch_registers = shnbsd_fetch_inferior_registers;
94 t->to_store_registers = shnbsd_store_inferior_registers;
95 add_target (t);
96}