Commit | Line | Data |
---|---|---|
def18405 MK |
1 | /* Native-dependent code for NetBSD/powerpc. |
2 | ||
3 | Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. | |
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 | |
11 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
20 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 | Boston, MA 02110-1301, USA. */ | |
e42180d7 C |
23 | |
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 C |
29 | |
30 | #include "defs.h" | |
69e9e646 | 31 | #include "gdbcore.h" |
def18405 | 32 | #include "inferior.h" |
69e9e646 | 33 | #include "regcache.h" |
def18405 MK |
34 | |
35 | #include "gdb_assert.h" | |
e42180d7 | 36 | |
485721b1 JT |
37 | #include "ppc-tdep.h" |
38 | #include "ppcnbsd-tdep.h" | |
def18405 | 39 | #include "bsd-kvm.h" |
5bf970f9 AC |
40 | #include "inf-ptrace.h" |
41 | ||
485721b1 | 42 | /* Returns true if PT_GETREGS fetches this register. */ |
def18405 | 43 | |
485721b1 | 44 | static int |
def18405 | 45 | getregs_supplies (int regnum) |
e42180d7 | 46 | { |
485721b1 JT |
47 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
48 | ||
def18405 MK |
49 | return ((regnum >= tdep->ppc_gp0_regnum |
50 | && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs) | |
51 | || regnum == tdep->ppc_lr_regnum | |
52 | || regnum == tdep->ppc_cr_regnum | |
53 | || regnum == tdep->ppc_xer_regnum | |
54 | || regnum == tdep->ppc_ctr_regnum | |
55 | || regnum == PC_REGNUM); | |
e42180d7 C |
56 | } |
57 | ||
485721b1 | 58 | /* Like above, but for PT_GETFPREGS. */ |
def18405 | 59 | |
485721b1 | 60 | static int |
def18405 | 61 | getfpregs_supplies (int regnum) |
e42180d7 | 62 | { |
485721b1 | 63 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
e42180d7 | 64 | |
383f0f5b JB |
65 | /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating |
66 | point registers. Traditionally, GDB's register set has still | |
67 | listed the floating point registers for such machines, so this | |
68 | code is harmless. However, the new E500 port actually omits the | |
69 | floating point registers entirely from the register set --- they | |
70 | don't even have register numbers assigned to them. | |
71 | ||
72 | It's not clear to me how best to update this code, so this assert | |
73 | will alert the first person to encounter the NetBSD/E500 | |
74 | combination to the problem. */ | |
75 | gdb_assert (ppc_floating_point_unit_p (current_gdbarch)); | |
76 | ||
def18405 MK |
77 | return ((regnum >= tdep->ppc_fp0_regnum |
78 | && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) | |
79 | || regnum == tdep->ppc_fpscr_regnum); | |
485721b1 | 80 | } |
e42180d7 | 81 | |
5bf970f9 | 82 | static void |
def18405 | 83 | ppcnbsd_fetch_inferior_registers (int regnum) |
e42180d7 | 84 | { |
def18405 | 85 | if (regnum == -1 || getregs_supplies (regnum)) |
485721b1 JT |
86 | { |
87 | struct reg regs; | |
88 | ||
89 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 90 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 91 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 92 | |
def18405 MK |
93 | ppc_supply_gregset (&ppcnbsd_gregset, current_regcache, |
94 | regnum, ®s, sizeof regs); | |
485721b1 JT |
95 | } |
96 | ||
def18405 | 97 | if (regnum == -1 || getfpregs_supplies (regnum)) |
485721b1 JT |
98 | { |
99 | struct fpreg fpregs; | |
100 | ||
101 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 102 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 103 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 104 | |
def18405 MK |
105 | ppc_supply_fpregset (&ppcnbsd_fpregset, current_regcache, |
106 | regnum, &fpregs, sizeof fpregs); | |
485721b1 | 107 | } |
e42180d7 C |
108 | } |
109 | ||
5bf970f9 | 110 | static void |
def18405 | 111 | ppcnbsd_store_inferior_registers (int regnum) |
e42180d7 | 112 | { |
def18405 | 113 | if (regnum == -1 || getregs_supplies (regnum)) |
485721b1 JT |
114 | { |
115 | struct reg regs; | |
116 | ||
117 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 118 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 119 | perror_with_name (_("Couldn't get registers")); |
485721b1 | 120 | |
def18405 MK |
121 | ppc_collect_gregset (&ppcnbsd_gregset, current_regcache, |
122 | regnum, ®s, sizeof regs); | |
485721b1 JT |
123 | |
124 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 125 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 126 | perror_with_name (_("Couldn't write registers")); |
485721b1 JT |
127 | } |
128 | ||
def18405 | 129 | if (regnum == -1 || getfpregs_supplies (regnum)) |
485721b1 JT |
130 | { |
131 | struct fpreg fpregs; | |
132 | ||
133 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 134 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 135 | perror_with_name (_("Couldn't get FP registers")); |
485721b1 | 136 | |
def18405 MK |
137 | ppc_collect_fpregset (&ppcnbsd_fpregset, current_regcache, |
138 | regnum, &fpregs, sizeof fpregs); | |
139 | ||
485721b1 | 140 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), |
9f8e0089 | 141 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
e2e0b3e5 | 142 | perror_with_name (_("Couldn't set FP registers")); |
485721b1 | 143 | } |
e42180d7 | 144 | } |
69e9e646 NW |
145 | |
146 | static int | |
147 | ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
148 | { | |
149 | struct switchframe sf; | |
150 | struct callframe cf; | |
151 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
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 NW |
171 | regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr); |
172 | regcache_raw_supply (regcache, PC_REGNUM, &cf.lr); | |
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 | } |