]>
Commit | Line | Data |
---|---|---|
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
13a38d45 JT |
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 | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
13a38d45 | 21 | |
bd372731 MK |
22 | #include "defs.h" |
23 | #include "inferior.h" | |
24 | ||
13a38d45 JT |
25 | #include <sys/types.h> |
26 | #include <sys/ptrace.h> | |
27 | #include <machine/reg.h> | |
28 | ||
97a5b208 | 29 | #include "sh-tdep.h" |
4015edd1 | 30 | #include "shnbsd-tdep.h" |
bd372731 | 31 | #include "inf-ptrace.h" |
4e3269e3 UW |
32 | #include "regcache.h" |
33 | ||
13a38d45 JT |
34 | |
35 | /* Determine if PT_GETREGS fetches this register. */ | |
36 | #define GETREGS_SUPPLIES(regno) \ | |
37 | (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \ | |
3e8c568d | 38 | || (regno) == gdbarch_pc_regnum (current_gdbarch) || (regno) == PR_REGNUM \ |
13a38d45 JT |
39 | || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \ |
40 | || (regno) == SR_REGNUM) | |
41 | ||
bd372731 | 42 | static void |
56be3814 | 43 | shnbsd_fetch_inferior_registers (struct regcache *regcache, int regno) |
13a38d45 JT |
44 | { |
45 | if (regno == -1 || GETREGS_SUPPLIES (regno)) | |
46 | { | |
47 | struct reg inferior_registers; | |
48 | ||
49 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
dfeafa2f | 50 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 51 | perror_with_name (_("Couldn't get registers")); |
13a38d45 | 52 | |
56be3814 | 53 | shnbsd_supply_reg (regcache, (char *) &inferior_registers, regno); |
13a38d45 JT |
54 | |
55 | if (regno != -1) | |
56 | return; | |
57 | } | |
58 | } | |
59 | ||
bd372731 | 60 | static void |
56be3814 | 61 | shnbsd_store_inferior_registers (struct regcache *regcache, int regno) |
13a38d45 JT |
62 | { |
63 | if (regno == -1 || GETREGS_SUPPLIES (regno)) | |
64 | { | |
65 | struct reg inferior_registers; | |
66 | ||
67 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
dfeafa2f | 68 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 69 | perror_with_name (_("Couldn't get registers")); |
13a38d45 | 70 | |
56be3814 | 71 | shnbsd_fill_reg (regcache, (char *) &inferior_registers, regno); |
13a38d45 JT |
72 | |
73 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
dfeafa2f | 74 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 75 | perror_with_name (_("Couldn't set registers")); |
13a38d45 JT |
76 | |
77 | if (regno != -1) | |
78 | return; | |
79 | } | |
80 | } | |
bd372731 MK |
81 | |
82 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
83 | void _initialize_shnbsd_nat (void); | |
84 | ||
85 | void | |
86 | _initialize_shnbsd_nat (void) | |
87 | { | |
88 | struct target_ops *t; | |
89 | ||
90 | t = inf_ptrace_target (); | |
91 | t->to_fetch_registers = shnbsd_fetch_inferior_registers; | |
92 | t->to_store_registers = shnbsd_store_inferior_registers; | |
93 | add_target (t); | |
94 | } |