]>
Commit | Line | Data |
---|---|---|
def18405 MK |
1 | /* Native-dependent code for NetBSD/powerpc. |
2 | ||
e2882c85 | 3 | Copyright (C) 2002-2018 Free Software Foundation, Inc. |
def18405 | 4 | |
485721b1 | 5 | Contributed by Wasabi Systems, Inc. |
e42180d7 C |
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 |
e42180d7 C |
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/>. */ |
e42180d7 | 21 | |
0baeab03 PA |
22 | #include "defs.h" |
23 | ||
e42180d7 C |
24 | #include <sys/types.h> |
25 | #include <sys/ptrace.h> | |
26 | #include <machine/reg.h> | |
69e9e646 NW |
27 | #include <machine/frame.h> |
28 | #include <machine/pcb.h> | |
e42180d7 | 29 | |
69e9e646 | 30 | #include "gdbcore.h" |
def18405 | 31 | #include "inferior.h" |
69e9e646 | 32 | #include "regcache.h" |
def18405 | 33 | |
485721b1 | 34 | #include "ppc-tdep.h" |
03b62bbb | 35 | #include "ppc-nbsd-tdep.h" |
def18405 | 36 | #include "bsd-kvm.h" |
5bf970f9 AC |
37 | #include "inf-ptrace.h" |
38 | ||
f6ac5f3d PA |
39 | struct ppc_nbsd_nat_target final : public inf_ptrace_target |
40 | { | |
41 | void fetch_registers (struct regcache *, int) override; | |
42 | void store_registers (struct regcache *, int) override; | |
43 | }; | |
44 | ||
45 | static ppc_nbsd_nat_target the_ppc_nbsd_nat_target; | |
46 | ||
485721b1 | 47 | /* Returns true if PT_GETREGS fetches this register. */ |
def18405 | 48 | |
485721b1 | 49 | static int |
206988c4 | 50 | getregs_supplies (struct gdbarch *gdbarch, int regnum) |
e42180d7 | 51 | { |
206988c4 | 52 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
485721b1 | 53 | |
def18405 MK |
54 | return ((regnum >= tdep->ppc_gp0_regnum |
55 | && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs) | |
56 | || regnum == tdep->ppc_lr_regnum | |
57 | || regnum == tdep->ppc_cr_regnum | |
58 | || regnum == tdep->ppc_xer_regnum | |
59 | || regnum == tdep->ppc_ctr_regnum | |
206988c4 | 60 | || regnum == gdbarch_pc_regnum (gdbarch)); |
e42180d7 C |
61 | } |
62 | ||
485721b1 | 63 | /* Like above, but for PT_GETFPREGS. */ |
def18405 | 64 | |
485721b1 | 65 | static int |
206988c4 | 66 | getfpregs_supplies (struct gdbarch *gdbarch, int regnum) |
e42180d7 | 67 | { |
206988c4 | 68 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e42180d7 | 69 | |
383f0f5b JB |
70 | /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating |
71 | point registers. Traditionally, GDB's register set has still | |
72 | listed the floating point registers for such machines, so this | |
73 | code is harmless. However, the new E500 port actually omits the | |
74 | floating point registers entirely from the register set --- they | |
75 | don't even have register numbers assigned to them. | |
76 | ||
77 | It's not clear to me how best to update this code, so this assert | |
78 | will alert the first person to encounter the NetBSD/E500 | |
79 | combination to the problem. */ | |
206988c4 | 80 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); |
383f0f5b | 81 | |
def18405 MK |
82 | return ((regnum >= tdep->ppc_fp0_regnum |
83 | && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) | |
84 | || regnum == tdep->ppc_fpscr_regnum); | |
485721b1 | 85 | } |
e42180d7 | 86 | |
f6ac5f3d PA |
87 | void |
88 | ppc_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum) | |
e42180d7 | 89 | { |
ac7936df | 90 | struct gdbarch *gdbarch = regcache->arch (); |
bcc0c096 | 91 | pid_t pid = ptid_get_pid (regcache_get_ptid (regcache)); |
206988c4 MD |
92 | |
93 | if (regnum == -1 || getregs_supplies (gdbarch, regnum)) | |
485721b1 JT |
94 | { |
95 | struct reg regs; | |
96 | ||
bcc0c096 | 97 | if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 98 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 99 | |
56be3814 | 100 | ppc_supply_gregset (&ppcnbsd_gregset, regcache, |
def18405 | 101 | regnum, ®s, sizeof regs); |
485721b1 JT |
102 | } |
103 | ||
206988c4 | 104 | if (regnum == -1 || getfpregs_supplies (gdbarch, regnum)) |
485721b1 JT |
105 | { |
106 | struct fpreg fpregs; | |
107 | ||
bcc0c096 | 108 | if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 109 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 110 | |
56be3814 | 111 | ppc_supply_fpregset (&ppcnbsd_fpregset, regcache, |
def18405 | 112 | regnum, &fpregs, sizeof fpregs); |
485721b1 | 113 | } |
e42180d7 C |
114 | } |
115 | ||
f6ac5f3d PA |
116 | void |
117 | ppc_nbsd_nat_target::store_registers (struct regcache *regcache, int regnum) | |
e42180d7 | 118 | { |
ac7936df | 119 | struct gdbarch *gdbarch = regcache->arch (); |
bcc0c096 | 120 | pid_t pid = ptid_get_pid (regcache_get_ptid (regcache)); |
206988c4 MD |
121 | |
122 | if (regnum == -1 || getregs_supplies (gdbarch, regnum)) | |
485721b1 JT |
123 | { |
124 | struct reg regs; | |
125 | ||
bcc0c096 | 126 | if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 127 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 128 | |
56be3814 | 129 | ppc_collect_gregset (&ppcnbsd_gregset, regcache, |
def18405 | 130 | regnum, ®s, sizeof regs); |
485721b1 | 131 | |
bcc0c096 | 132 | if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 133 | perror_with_name (_("Couldn't write registers")); |
485721b1 JT |
134 | } |
135 | ||
206988c4 | 136 | if (regnum == -1 || getfpregs_supplies (gdbarch, regnum)) |
485721b1 JT |
137 | { |
138 | struct fpreg fpregs; | |
139 | ||
bcc0c096 | 140 | if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 141 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 142 | |
56be3814 | 143 | ppc_collect_fpregset (&ppcnbsd_fpregset, regcache, |
def18405 MK |
144 | regnum, &fpregs, sizeof fpregs); |
145 | ||
bcc0c096 | 146 | if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 147 | perror_with_name (_("Couldn't set FP registers")); |
485721b1 | 148 | } |
e42180d7 | 149 | } |
69e9e646 NW |
150 | |
151 | static int | |
152 | ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
153 | { | |
154 | struct switchframe sf; | |
155 | struct callframe cf; | |
ac7936df | 156 | struct gdbarch *gdbarch = regcache->arch (); |
40a6adc1 | 157 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
69e9e646 NW |
158 | int i; |
159 | ||
160 | /* The stack pointer shouldn't be zero. */ | |
161 | if (pcb->pcb_sp == 0) | |
162 | return 0; | |
163 | ||
def18405 | 164 | read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf); |
69e9e646 NW |
165 | regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr); |
166 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2); | |
167 | for (i = 0 ; i < 19 ; i++) | |
168 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i, | |
169 | &sf.fixreg[i]); | |
170 | ||
def18405 | 171 | read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf)); |
69e9e646 NW |
172 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30); |
173 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31); | |
174 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp); | |
175 | ||
def18405 | 176 | read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf)); |
69e9e646 | 177 | regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr); |
40a6adc1 | 178 | regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr); |
69e9e646 NW |
179 | |
180 | return 1; | |
181 | } | |
182 | ||
69e9e646 NW |
183 | void |
184 | _initialize_ppcnbsd_nat (void) | |
185 | { | |
186 | /* Support debugging kernel virtual memory images. */ | |
187 | bsd_kvm_add_target (ppcnbsd_supply_pcb); | |
def18405 | 188 | |
f6ac5f3d | 189 | add_target (&the_ppc_nbsd_nat_target); |
69e9e646 | 190 | } |