Fix dw2-ifort-parameter.exp on PPC64
[binutils-gdb.git] / gdb / sparc64nbsd-nat.c
blobf8db7fae8770ab771c7d9cbaf32f2a8e482f912c
1 /* Native-dependent code for NetBSD/sparc64.
3 Copyright (C) 2003-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "regcache.h"
23 #include "target.h"
25 #include "sparc64-tdep.h"
26 #include "sparc-nat.h"
28 /* NetBSD is different from the other OSes that support both SPARC and
29 UltraSPARC in that the result of ptrace(2) depends on whether the
30 traced process is 32-bit or 64-bit. */
32 static void
33 sparc64nbsd_supply_gregset (const struct sparc_gregset *gregset,
34 struct regcache *regcache,
35 int regnum, const void *gregs)
37 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
39 if (sparc32)
40 sparc32_supply_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
41 else
42 sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
45 static void
46 sparc64nbsd_collect_gregset (const struct sparc_gregset *gregset,
47 const struct regcache *regcache,
48 int regnum, void *gregs)
50 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
52 if (sparc32)
53 sparc32_collect_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
54 else
55 sparc64_collect_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
58 static void
59 sparc64nbsd_supply_fpregset (const struct sparc_fpregset *fpregset,
60 struct regcache *regcache,
61 int regnum, const void *fpregs)
63 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
65 if (sparc32)
66 sparc32_supply_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs);
67 else
68 sparc64_supply_fpregset (&sparc64_bsd_fpregset, regcache, regnum, fpregs);
71 static void
72 sparc64nbsd_collect_fpregset (const struct sparc_fpregset *fpregset,
73 const struct regcache *regcache,
74 int regnum, void *fpregs)
76 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
78 if (sparc32)
79 sparc32_collect_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs);
80 else
81 sparc64_collect_fpregset (&sparc64_bsd_fpregset, regcache, regnum, fpregs);
84 /* Determine whether `gregset_t' contains register REGNUM. */
86 static int
87 sparc64nbsd_gregset_supplies_p (struct gdbarch *gdbarch, int regnum)
89 if (gdbarch_ptr_bit (gdbarch) == 32)
90 return sparc32_gregset_supplies_p (gdbarch, regnum);
92 /* Integer registers. */
93 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM)
94 || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
95 || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
96 || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
97 return 1;
99 /* Control registers. */
100 if (regnum == SPARC64_PC_REGNUM
101 || regnum == SPARC64_NPC_REGNUM
102 || regnum == SPARC64_STATE_REGNUM
103 || regnum == SPARC64_Y_REGNUM)
104 return 1;
106 return 0;
109 /* Determine whether `fpregset_t' contains register REGNUM. */
111 static int
112 sparc64nbsd_fpregset_supplies_p (struct gdbarch *gdbarch, int regnum)
114 if (gdbarch_ptr_bit (gdbarch) == 32)
115 return sparc32_fpregset_supplies_p (gdbarch, regnum);
117 /* Floating-point registers. */
118 if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
119 || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
120 return 1;
122 /* Control registers. */
123 if (regnum == SPARC64_FSR_REGNUM)
124 return 1;
126 return 0;
130 /* Support for debugging kernel virtual memory images. */
132 #include <sys/types.h>
133 #include <machine/pcb.h>
135 #include "bsd-kvm.h"
137 static int
138 sparc64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
140 u_int64_t state;
141 int regnum;
143 /* The following is true for NetBSD 1.6.2:
145 The pcb contains %sp and %pc, %pstate and %cwp. From this
146 information we reconstruct the register state as it would look
147 when we just returned from cpu_switch(). */
149 /* The stack pointer shouldn't be zero. */
150 if (pcb->pcb_sp == 0)
151 return 0;
153 /* If the program counter is zero, this is probably a core dump, and
154 we can get %pc from the stack. */
155 if (pcb->pcb_pc == 0)
156 read_memory(pcb->pcb_sp + BIAS - 176 + (11 * 8),
157 (gdb_byte *)&pcb->pcb_pc, sizeof pcb->pcb_pc);
159 regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
160 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);
162 state = pcb->pcb_pstate << 8 | pcb->pcb_cwp;
163 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM, &state);
165 sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
167 return 1;
171 /* Provide a prototype to silence -Wmissing-prototypes. */
172 void _initialize_sparc64nbsd_nat (void);
174 void
175 _initialize_sparc64nbsd_nat (void)
177 sparc_supply_gregset = sparc64nbsd_supply_gregset;
178 sparc_collect_gregset = sparc64nbsd_collect_gregset;
179 sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
180 sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
181 sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
182 sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
184 /* We've got nothing to add to the generic SPARC target. */
185 add_target (sparc_target ());
187 /* Support debugging kernel virtual memory images. */
188 bsd_kvm_add_target (sparc64nbsd_supply_pcb);