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