1 /* Native-dependent code for NetBSD/sparc64.
3 Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "sparc64-tdep.h"
27 #include "sparc-nat.h"
29 /* NetBSD is different from the other OSes that support both SPARC and
30 UltraSPARC in that the result of ptrace(2) depends on whether the
31 traced process is 32-bit or 64-bit. */
34 sparc64nbsd_supply_gregset (const struct sparc_gregset *gregset,
35 struct regcache *regcache,
36 int regnum, const void *gregs)
38 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
41 sparc32_supply_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
43 sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
47 sparc64nbsd_collect_gregset (const struct sparc_gregset *gregset,
48 const struct regcache *regcache,
49 int regnum, void *gregs)
51 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
54 sparc32_collect_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
56 sparc64_collect_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
60 sparc64nbsd_supply_fpregset (struct regcache *regcache,
61 int regnum, const void *fpregs)
63 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
66 sparc32_supply_fpregset (regcache, regnum, fpregs);
68 sparc64_supply_fpregset (regcache, regnum, fpregs);
72 sparc64nbsd_collect_fpregset (const struct regcache *regcache,
73 int regnum, void *fpregs)
75 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
78 sparc32_collect_fpregset (regcache, regnum, fpregs);
80 sparc64_collect_fpregset (regcache, regnum, fpregs);
83 /* Determine whether `gregset_t' contains register REGNUM. */
86 sparc64nbsd_gregset_supplies_p (struct gdbarch *gdbarch, int regnum)
88 if (gdbarch_ptr_bit (gdbarch) == 32)
89 return sparc32_gregset_supplies_p (gdbarch, regnum);
91 /* Integer registers. */
92 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM)
93 || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
94 || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
95 || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
98 /* Control registers. */
99 if (regnum == SPARC64_PC_REGNUM
100 || regnum == SPARC64_NPC_REGNUM
101 || regnum == SPARC64_STATE_REGNUM
102 || regnum == SPARC64_Y_REGNUM)
108 /* Determine whether `fpregset_t' contains register REGNUM. */
111 sparc64nbsd_fpregset_supplies_p (struct gdbarch *gdbarch, int regnum)
113 if (gdbarch_ptr_bit (gdbarch) == 32)
114 return sparc32_fpregset_supplies_p (gdbarch, regnum);
116 /* Floating-point registers. */
117 if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
118 || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
121 /* Control registers. */
122 if (regnum == SPARC64_FSR_REGNUM)
129 /* Support for debugging kernel virtual memory images. */
131 #include <sys/types.h>
132 #include <machine/pcb.h>
137 sparc64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
142 /* The following is true for NetBSD 1.6.2:
144 The pcb contains %sp and %pc, %pstate and %cwp. From this
145 information we reconstruct the register state as it would look
146 when we just returned from cpu_switch(). */
148 /* The stack pointer shouldn't be zero. */
149 if (pcb->pcb_sp == 0)
152 /* If the program counter is zero, this is probably a core dump, and
153 we can get %pc from the stack. */
154 if (pcb->pcb_pc == 0)
155 read_memory(pcb->pcb_sp + BIAS - 176 + (11 * 8),
156 (gdb_byte *)&pcb->pcb_pc, sizeof pcb->pcb_pc);
158 regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
159 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);
161 state = pcb->pcb_pstate << 8 | pcb->pcb_cwp;
162 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM, &state);
164 sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
170 /* Provide a prototype to silence -Wmissing-prototypes. */
171 void _initialize_sparc64nbsd_nat (void);
174 _initialize_sparc64nbsd_nat (void)
176 sparc_supply_gregset = sparc64nbsd_supply_gregset;
177 sparc_collect_gregset = sparc64nbsd_collect_gregset;
178 sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
179 sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
180 sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
181 sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
183 /* We've got nothing to add to the generic SPARC target. */
184 add_target (sparc_target ());
186 /* Support debugging kernel virtual memory images. */
187 bsd_kvm_add_target (sparc64nbsd_supply_pcb);