Commit | Line | Data |
---|---|---|
bd372731 MK |
1 | /* Native-dependent code for NetBSD/sh. |
2 | ||
42a4f53d | 3 | Copyright (C) 2002-2019 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" |
bd372731 | 30 | #include "inf-ptrace.h" |
4e3269e3 UW |
31 | #include "regcache.h" |
32 | ||
f6ac5f3d PA |
33 | struct sh_nbsd_nat_target final : public inf_ptrace_target |
34 | { | |
35 | void fetch_registers (struct regcache *, int) override; | |
36 | void store_registers (struct regcache *, int) override; | |
37 | }; | |
38 | ||
39 | static sh_nbsd_nat_target the_sh_nbsd_nat_target; | |
13a38d45 | 40 | |
c378eb4e | 41 | /* Determine if PT_GETREGS fetches this register. */ |
40a6adc1 | 42 | #define GETREGS_SUPPLIES(gdbarch, regno) \ |
13a38d45 | 43 | (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \ |
40a6adc1 | 44 | || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \ |
13a38d45 JT |
45 | || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \ |
46 | || (regno) == SR_REGNUM) | |
47 | ||
c9ac0a72 AS |
48 | /* Sizeof `struct reg' in <machine/reg.h>. */ |
49 | #define SHNBSD_SIZEOF_GREGS (21 * 4) | |
50 | ||
f6ac5f3d PA |
51 | void |
52 | sh_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno) | |
13a38d45 | 53 | { |
e99b03dc | 54 | pid_t pid = regcache->ptid ().pid (); |
bcc0c096 | 55 | |
ac7936df | 56 | if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno)) |
13a38d45 JT |
57 | { |
58 | struct reg inferior_registers; | |
59 | ||
bcc0c096 | 60 | if (ptrace (PT_GETREGS, pid, |
dfeafa2f | 61 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 62 | perror_with_name (_("Couldn't get registers")); |
13a38d45 | 63 | |
c9ac0a72 AS |
64 | sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno, |
65 | (char *) &inferior_registers, | |
66 | SHNBSD_SIZEOF_GREGS); | |
13a38d45 JT |
67 | |
68 | if (regno != -1) | |
69 | return; | |
70 | } | |
71 | } | |
72 | ||
f6ac5f3d PA |
73 | void |
74 | sh_nbsd_nat_target::store_registers (struct regcache *regcache, int regno) | |
13a38d45 | 75 | { |
e99b03dc | 76 | pid_t pid = regcache->ptid ().pid (); |
bcc0c096 | 77 | |
ac7936df | 78 | if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno)) |
13a38d45 JT |
79 | { |
80 | struct reg inferior_registers; | |
81 | ||
bcc0c096 | 82 | if (ptrace (PT_GETREGS, pid, |
dfeafa2f | 83 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 84 | perror_with_name (_("Couldn't get registers")); |
13a38d45 | 85 | |
c9ac0a72 AS |
86 | sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno, |
87 | (char *) &inferior_registers, | |
88 | SHNBSD_SIZEOF_GREGS); | |
13a38d45 | 89 | |
bcc0c096 | 90 | if (ptrace (PT_SETREGS, pid, |
dfeafa2f | 91 | (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) |
e2e0b3e5 | 92 | perror_with_name (_("Couldn't set registers")); |
13a38d45 JT |
93 | |
94 | if (regno != -1) | |
95 | return; | |
96 | } | |
97 | } | |
bd372731 | 98 | |
bd372731 MK |
99 | void |
100 | _initialize_shnbsd_nat (void) | |
101 | { | |
d9f719f1 | 102 | add_inf_child_target (&the_sh_nbsd_nat_target); |
bd372731 | 103 | } |