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 "defs.h"
24 #include "inferior.h"
25
26 #include <sys/types.h>
27 #include <sys/ptrace.h>
28 #include <machine/reg.h>
29
30 #include "sh-tdep.h"
31 #include "shnbsd-tdep.h"
32 #include "inf-ptrace.h"
33
34 /* Determine if PT_GETREGS fetches this register. */
35 #define GETREGS_SUPPLIES(regno) \
36 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
37 || (regno) == PC_REGNUM || (regno) == PR_REGNUM \
38 || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
39 || (regno) == SR_REGNUM)
40
41 static void
shnbsd_fetch_inferior_registers(int regno)42 shnbsd_fetch_inferior_registers (int regno)
43 {
44 if (regno == -1 || GETREGS_SUPPLIES (regno))
45 {
46 struct reg inferior_registers;
47
48 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
49 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
50 perror_with_name ("Couldn't get registers");
51
52 shnbsd_supply_reg ((char *) &inferior_registers, regno);
53
54 if (regno != -1)
55 return;
56 }
57 }
58
59 static void
shnbsd_store_inferior_registers(int regno)60 shnbsd_store_inferior_registers (int regno)
61 {
62 if (regno == -1 || GETREGS_SUPPLIES (regno))
63 {
64 struct reg inferior_registers;
65
66 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
67 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
68 perror_with_name ("Couldn't get registers");
69
70 shnbsd_fill_reg ((char *) &inferior_registers, regno);
71
72 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
73 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
74 perror_with_name ("Couldn't set registers");
75
76 if (regno != -1)
77 return;
78 }
79 }
80
81 /* Provide a prototype to silence -Wmissing-prototypes. */
82 void _initialize_shnbsd_nat (void);
83
84 void
_initialize_shnbsd_nat(void)85 _initialize_shnbsd_nat (void)
86 {
87 struct target_ops *t;
88
89 t = inf_ptrace_target ();
90 t->to_fetch_registers = shnbsd_fetch_inferior_registers;
91 t->to_store_registers = shnbsd_store_inferior_registers;
92 add_target (t);
93 }
94