Commit | Line | Data |
---|---|---|
def18405 MK |
1 | /* Native-dependent code for NetBSD/powerpc. |
2 | ||
9b254dd1 DJ |
3 | Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 |
4 | Free Software Foundation, Inc. | |
def18405 | 5 | |
485721b1 | 6 | Contributed by Wasabi Systems, Inc. |
e42180d7 C |
7 | |
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
e42180d7 C |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
e42180d7 C |
22 | |
23 | #include <sys/types.h> | |
24 | #include <sys/ptrace.h> | |
25 | #include <machine/reg.h> | |
69e9e646 NW |
26 | #include <machine/frame.h> |
27 | #include <machine/pcb.h> | |
e42180d7 C |
28 | |
29 | #include "defs.h" | |
69e9e646 | 30 | #include "gdbcore.h" |
def18405 | 31 | #include "inferior.h" |
69e9e646 | 32 | #include "regcache.h" |
def18405 MK |
33 | |
34 | #include "gdb_assert.h" | |
e42180d7 | 35 | |
485721b1 JT |
36 | #include "ppc-tdep.h" |
37 | #include "ppcnbsd-tdep.h" | |
def18405 | 38 | #include "bsd-kvm.h" |
5bf970f9 AC |
39 | #include "inf-ptrace.h" |
40 | ||
485721b1 | 41 | /* Returns true if PT_GETREGS fetches this register. */ |
def18405 | 42 | |
485721b1 | 43 | static int |
def18405 | 44 | getregs_supplies (int regnum) |
e42180d7 | 45 | { |
485721b1 JT |
46 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
47 | ||
def18405 MK |
48 | return ((regnum >= tdep->ppc_gp0_regnum |
49 | && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs) | |
50 | || regnum == tdep->ppc_lr_regnum | |
51 | || regnum == tdep->ppc_cr_regnum | |
52 | || regnum == tdep->ppc_xer_regnum | |
53 | || regnum == tdep->ppc_ctr_regnum | |
3e8c568d | 54 | || regnum == gdbarch_pc_regnum (current_gdbarch)); |
e42180d7 C |
55 | } |
56 | ||
485721b1 | 57 | /* Like above, but for PT_GETFPREGS. */ |
def18405 | 58 | |
485721b1 | 59 | static int |
def18405 | 60 | getfpregs_supplies (int regnum) |
e42180d7 | 61 | { |
485721b1 | 62 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
e42180d7 | 63 | |
383f0f5b JB |
64 | /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating |
65 | point registers. Traditionally, GDB's register set has still | |
66 | listed the floating point registers for such machines, so this | |
67 | code is harmless. However, the new E500 port actually omits the | |
68 | floating point registers entirely from the register set --- they | |
69 | don't even have register numbers assigned to them. | |
70 | ||
71 | It's not clear to me how best to update this code, so this assert | |
72 | will alert the first person to encounter the NetBSD/E500 | |
73 | combination to the problem. */ | |
74 | gdb_assert (ppc_floating_point_unit_p (current_gdbarch)); | |
75 | ||
def18405 MK |
76 | return ((regnum >= tdep->ppc_fp0_regnum |
77 | && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) | |
78 | || regnum == tdep->ppc_fpscr_regnum); | |
485721b1 | 79 | } |
e42180d7 | 80 | |
5bf970f9 | 81 | static void |
56be3814 | 82 | ppcnbsd_fetch_inferior_registers (struct regcache *regcache, int regnum) |
e42180d7 | 83 | { |
def18405 | 84 | if (regnum == -1 || getregs_supplies (regnum)) |
485721b1 JT |
85 | { |
86 | struct reg regs; | |
87 | ||
88 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 89 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 90 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 91 | |
56be3814 | 92 | ppc_supply_gregset (&ppcnbsd_gregset, regcache, |
def18405 | 93 | regnum, ®s, sizeof regs); |
485721b1 JT |
94 | } |
95 | ||
def18405 | 96 | if (regnum == -1 || getfpregs_supplies (regnum)) |
485721b1 JT |
97 | { |
98 | struct fpreg fpregs; | |
99 | ||
100 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 101 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 102 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 103 | |
56be3814 | 104 | ppc_supply_fpregset (&ppcnbsd_fpregset, regcache, |
def18405 | 105 | regnum, &fpregs, sizeof fpregs); |
485721b1 | 106 | } |
e42180d7 C |
107 | } |
108 | ||
5bf970f9 | 109 | static void |
56be3814 | 110 | ppcnbsd_store_inferior_registers (struct regcache *regcache, int regnum) |
e42180d7 | 111 | { |
def18405 | 112 | if (regnum == -1 || getregs_supplies (regnum)) |
485721b1 JT |
113 | { |
114 | struct reg regs; | |
115 | ||
116 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 117 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 118 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 119 | |
56be3814 | 120 | ppc_collect_gregset (&ppcnbsd_gregset, regcache, |
def18405 | 121 | regnum, ®s, sizeof regs); |
485721b1 JT |
122 | |
123 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 124 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 125 | perror_with_name (_("Couldn't write registers")); |
485721b1 JT |
126 | } |
127 | ||
def18405 | 128 | if (regnum == -1 || getfpregs_supplies (regnum)) |
485721b1 JT |
129 | { |
130 | struct fpreg fpregs; | |
131 | ||
132 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 133 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 134 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 135 | |
56be3814 | 136 | ppc_collect_fpregset (&ppcnbsd_fpregset, regcache, |
def18405 MK |
137 | regnum, &fpregs, sizeof fpregs); |
138 | ||
485721b1 | 139 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), |
9f8e0089 | 140 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 141 | perror_with_name (_("Couldn't set FP registers")); |
485721b1 | 142 | } |
e42180d7 | 143 | } |
69e9e646 NW |
144 | |
145 | static int | |
146 | ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
147 | { | |
148 | struct switchframe sf; | |
149 | struct callframe cf; | |
40a6adc1 MD |
150 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
151 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
69e9e646 NW |
152 | int i; |
153 | ||
154 | /* The stack pointer shouldn't be zero. */ | |
155 | if (pcb->pcb_sp == 0) | |
156 | return 0; | |
157 | ||
def18405 | 158 | read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf); |
69e9e646 NW |
159 | regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr); |
160 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2); | |
161 | for (i = 0 ; i < 19 ; i++) | |
162 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i, | |
163 | &sf.fixreg[i]); | |
164 | ||
def18405 | 165 | read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf)); |
69e9e646 NW |
166 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30); |
167 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31); | |
168 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp); | |
169 | ||
def18405 | 170 | read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf)); |
69e9e646 | 171 | regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr); |
40a6adc1 | 172 | regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr); |
69e9e646 NW |
173 | |
174 | return 1; | |
175 | } | |
176 | ||
177 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
178 | void _initialize_ppcnbsd_nat (void); | |
179 | ||
180 | void | |
181 | _initialize_ppcnbsd_nat (void) | |
182 | { | |
5bf970f9 | 183 | struct target_ops *t; |
def18405 | 184 | |
69e9e646 NW |
185 | /* Support debugging kernel virtual memory images. */ |
186 | bsd_kvm_add_target (ppcnbsd_supply_pcb); | |
def18405 | 187 | |
5bf970f9 AC |
188 | /* Add in local overrides. */ |
189 | t = inf_ptrace_target (); | |
190 | t->to_fetch_registers = ppcnbsd_fetch_inferior_registers; | |
191 | t->to_store_registers = ppcnbsd_store_inferior_registers; | |
192 | add_target (t); | |
69e9e646 | 193 | } |