1 /* Target-dependent code for SPARC systems running NetBSD.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Wasabi Systems, 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
29 #include "gdb_string.h"
31 #include "sparc-tdep.h"
32 #include "sparcnbsd-tdep.h"
33 #include "nbsd-tdep.h"
35 #include "solib-svr4.h"
37 #define REG32_OFFSET_PSR (0 * 4)
38 #define REG32_OFFSET_PC (1 * 4)
39 #define REG32_OFFSET_NPC (2 * 4)
40 #define REG32_OFFSET_Y (3 * 4)
41 #define REG32_OFFSET_GLOBAL (4 * 4)
42 #define REG32_OFFSET_OUT (12 * 4)
44 #define REG64_OFFSET_TSTATE (0 * 8)
45 #define REG64_OFFSET_PC (1 * 8)
46 #define REG64_OFFSET_NPC (2 * 8)
47 #define REG64_OFFSET_Y (3 * 8)
48 #define REG64_OFFSET_GLOBAL (4 * 8)
49 #define REG64_OFFSET_OUT (12 * 8)
52 sparcnbsd_supply_reg32 (char *regs, int regno)
56 if (regno == PS_REGNUM || regno == -1)
57 supply_register (PS_REGNUM, regs + REG32_OFFSET_PSR);
59 if (regno == PC_REGNUM || regno == -1)
60 supply_register (PC_REGNUM, regs + REG32_OFFSET_PC);
62 if (regno == DEPRECATED_NPC_REGNUM || regno == -1)
63 supply_register (DEPRECATED_NPC_REGNUM, regs + REG32_OFFSET_NPC);
65 if (regno == Y_REGNUM || regno == -1)
66 supply_register (Y_REGNUM, regs + REG32_OFFSET_Y);
68 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
70 if (regno == G0_REGNUM || regno == -1)
71 supply_register (G0_REGNUM, NULL); /* %g0 is always zero */
72 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
74 if (regno == i || regno == -1)
75 supply_register (i, regs + REG32_OFFSET_GLOBAL +
76 ((i - G0_REGNUM) * 4));
80 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
82 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
84 if (regno == i || regno == -1)
85 supply_register (i, regs + REG32_OFFSET_OUT +
86 ((i - O0_REGNUM) * 4));
90 /* Inputs and Locals are stored onto the stack by by the kernel. */
91 if ((regno >= L0_REGNUM && regno <= I7_REGNUM) || regno == -1)
93 CORE_ADDR sp = read_register (SP_REGNUM);
96 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
98 if (regno == i || regno == -1)
100 target_read_memory (sp + ((i - L0_REGNUM) * 4),
102 supply_register (i, buf);
107 /* FIXME: If we don't set these valid, read_register_bytes() rereads
108 all the regs every time it is called! */
109 if (regno == WIM_REGNUM || regno == -1)
110 supply_register (WIM_REGNUM, NULL);
111 if (regno == TBR_REGNUM || regno == -1)
112 supply_register (TBR_REGNUM, NULL);
113 if (regno == CPS_REGNUM || regno == -1)
114 supply_register (CPS_REGNUM, NULL);
118 sparcnbsd_supply_reg64 (char *regs, int regno)
123 if (regno == TSTATE_REGNUM || regno == -1)
124 supply_register (PS_REGNUM, regs + REG64_OFFSET_TSTATE);
126 if (regno == PC_REGNUM || regno == -1)
127 supply_register (PC_REGNUM, regs + REG64_OFFSET_PC);
129 if (regno == DEPRECATED_NPC_REGNUM || regno == -1)
130 supply_register (DEPRECATED_NPC_REGNUM, regs + REG64_OFFSET_NPC);
132 if (regno == Y_REGNUM || regno == -1)
134 memset (buf, 0, sizeof (buf));
135 memcpy (&buf[4], regs + REG64_OFFSET_Y, 4);
136 supply_register (Y_REGNUM, buf);
139 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
141 if (regno == G0_REGNUM || regno == -1)
142 supply_register (G0_REGNUM, NULL); /* %g0 is always zero */
143 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
145 if (regno == i || regno == -1)
146 supply_register (i, regs + REG64_OFFSET_GLOBAL +
147 ((i - G0_REGNUM) * 8));
151 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
153 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
155 if (regno == i || regno == -1)
156 supply_register (i, regs + REG64_OFFSET_OUT +
157 ((i - O0_REGNUM) * 8));
161 /* Inputs and Locals are stored onto the stack by by the kernel. */
162 if ((regno >= L0_REGNUM && regno <= I7_REGNUM) || regno == -1)
164 CORE_ADDR sp = read_register (SP_REGNUM);
169 /* Registers are 64-bit. */
172 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
174 if (regno == i || regno == -1)
176 target_read_memory (sp + ((i - L0_REGNUM) * 8),
178 supply_register (i, buf);
184 /* Registers are 32-bit. Toss any sign-extension of the stack
185 pointer, clear out the top half of the temporary buffer, and
186 put the register value in the bottom half. */
189 memset (buf, 0, sizeof (buf));
190 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
192 if (regno == i || regno == -1)
194 target_read_memory (sp + ((i - L0_REGNUM) * 4),
195 &buf[4], sizeof (buf));
196 supply_register (i, buf);
202 /* FIXME: If we don't set these valid, read_register_bytes() rereads
203 all the regs every time it is called! */
204 if (regno == WIM_REGNUM || regno == -1)
205 supply_register (WIM_REGNUM, NULL);
206 if (regno == TBR_REGNUM || regno == -1)
207 supply_register (TBR_REGNUM, NULL);
208 if (regno == CPS_REGNUM || regno == -1)
209 supply_register (CPS_REGNUM, NULL);
213 sparcnbsd_fill_reg32 (char *regs, int regno)
217 if (regno == PS_REGNUM || regno == -1)
218 regcache_collect (PS_REGNUM, regs + REG32_OFFSET_PSR);
220 if (regno == PC_REGNUM || regno == -1)
221 regcache_collect (PC_REGNUM, regs + REG32_OFFSET_PC);
223 if (regno == DEPRECATED_NPC_REGNUM || regno == -1)
224 regcache_collect (DEPRECATED_NPC_REGNUM, regs + REG32_OFFSET_NPC);
226 if (regno == Y_REGNUM || regno == -1)
227 regcache_collect (Y_REGNUM, regs + REG32_OFFSET_Y);
229 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
231 /* %g0 is always zero */
232 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
234 if (regno == i || regno == -1)
235 regcache_collect (i, regs + REG32_OFFSET_GLOBAL +
236 ((i - G0_REGNUM) * 4));
240 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
242 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
244 if (regno == i || regno == -1)
245 regcache_collect (i, regs + REG32_OFFSET_OUT +
246 ((i - O0_REGNUM) * 4));
250 /* Responsibility for the stack regs is pushed off onto the caller. */
254 sparcnbsd_fill_reg64 (char *regs, int regno)
258 if (regno == TSTATE_REGNUM || regno == -1)
259 regcache_collect (TSTATE_REGNUM, regs + REG64_OFFSET_TSTATE);
261 if (regno == PC_REGNUM || regno == -1)
262 regcache_collect (PC_REGNUM, regs + REG64_OFFSET_PC);
264 if (regno == DEPRECATED_NPC_REGNUM || regno == -1)
265 regcache_collect (DEPRECATED_NPC_REGNUM, regs + REG64_OFFSET_NPC);
267 if (regno == Y_REGNUM || regno == -1)
268 regcache_collect (Y_REGNUM, regs + REG64_OFFSET_Y);
270 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
272 /* %g0 is always zero */
273 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
275 if (regno == i || regno == -1)
276 regcache_collect (i, regs + REG64_OFFSET_GLOBAL +
277 ((i - G0_REGNUM) * 4));
281 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
283 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
285 if (regno == i || regno == -1)
286 regcache_collect (i, regs + REG64_OFFSET_OUT +
287 ((i - O0_REGNUM) * 4));
291 /* Responsibility for the stack regs is pushed off onto the caller. */
295 sparcnbsd_supply_fpreg32 (char *fpregs, int regno)
299 for (i = 0; i <= 31; i++)
301 if (regno == (FP0_REGNUM + i) || regno == -1)
302 supply_register (FP0_REGNUM + i, fpregs + (i * 4));
305 if (regno == FPS_REGNUM || regno == -1)
306 supply_register (FPS_REGNUM, fpregs + (32 * 4));
310 sparcnbsd_supply_fpreg64 (char *fpregs, int regno)
314 for (i = 0; i <= 31; i++)
316 if (regno == (FP0_REGNUM + i) || regno == -1)
317 supply_register (FP0_REGNUM + i, fpregs + (i * 4));
322 if (regno == (FP0_REGNUM + i) || regno == -1)
323 supply_register (FP0_REGNUM + i, fpregs + (32 * 4) + (i * 8));
326 if (regno == FPS_REGNUM || regno == -1)
327 supply_register (FPS_REGNUM, fpregs + (32 * 4) + (16 * 8));
333 sparcnbsd_fill_fpreg32 (char *fpregs, int regno)
337 for (i = 0; i <= 31; i++)
339 if (regno == (FP0_REGNUM + i) || regno == -1)
340 regcache_collect (FP0_REGNUM + i, fpregs + (i * 4));
343 if (regno == FPS_REGNUM || regno == -1)
344 regcache_collect (FPS_REGNUM, fpregs + (32 * 4));
348 sparcnbsd_fill_fpreg64 (char *fpregs, int regno)
352 for (i = 0; i <= 31; i++)
354 if (regno == (FP0_REGNUM + i) || regno == -1)
355 regcache_collect (FP0_REGNUM + i, fpregs + (i * 4));
360 if (regno == (FP0_REGNUM + i) || regno == -1)
361 regcache_collect (FP0_REGNUM + i, fpregs + (32 * 4) + (i * 8));
364 if (regno == FPS_REGNUM || regno == -1)
365 regcache_collect (FPS_REGNUM, fpregs + (32 * 4) + (16 * 8));
370 /* Unlike other NetBSD implementations, the SPARC port historically used
371 .reg and .reg2 (see bfd/netbsd-core.c), and as such, we can share one
372 routine for a.out and ELF core files. */
374 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
377 int reg_size, fpreg_size;
379 if (gdbarch_ptr_bit (current_gdbarch) == 32)
382 fpreg_size = (33 * 4);
387 fpreg_size = (64 * 4)
395 case 0: /* Integer registers */
396 if (core_reg_size != reg_size)
397 warning ("Wrong size register set in core file.");
398 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
399 sparcnbsd_supply_reg32 (core_reg_sect, -1);
401 sparcnbsd_supply_reg64 (core_reg_sect, -1);
404 case 2: /* Floating pointer registers */
405 if (core_reg_size != fpreg_size)
406 warning ("Wrong size FP register set in core file.");
407 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
408 sparcnbsd_supply_fpreg32 (core_reg_sect, -1);
410 sparcnbsd_supply_fpreg64 (core_reg_sect, -1);
414 /* Don't know what kind of register request this is; just ignore it. */
419 static struct core_fns sparcnbsd_core_fns =
421 bfd_target_unknown_flavour, /* core_flavour */
422 default_check_format, /* check_format */
423 default_core_sniffer, /* core_sniffer */
424 fetch_core_registers, /* core_read_registers */
428 static struct core_fns sparcnbsd_elfcore_fns =
430 bfd_target_elf_flavour, /* core_flavour */
431 default_check_format, /* check_format */
432 default_core_sniffer, /* core_sniffer */
433 fetch_core_registers, /* core_read_registers */
437 /* FIXME: Need PC_IN_SIGTRAMP() support, but NetBSD/sparc signal trampolines
438 aren't easily identified. */
441 sparcnbsd_get_longjmp_target_32 (CORE_ADDR *pc)
446 jb_addr = read_register (O0_REGNUM);
448 if (target_read_memory (jb_addr + 12, buf, sizeof (buf)))
451 *pc = extract_unsigned_integer (buf, sizeof (buf));
457 sparcnbsd_get_longjmp_target_64 (CORE_ADDR *pc)
462 jb_addr = read_register (O0_REGNUM);
464 if (target_read_memory (jb_addr + 16, buf, sizeof (buf)))
467 *pc = extract_unsigned_integer (buf, sizeof (buf));
473 sparcnbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
475 if (strcmp (name, "_DYNAMIC") == 0)
482 sparcnbsd_init_abi_common (struct gdbarch_info info,
483 struct gdbarch *gdbarch)
485 set_gdbarch_get_longjmp_target (gdbarch, gdbarch_ptr_bit (gdbarch) == 32 ?
486 sparcnbsd_get_longjmp_target_32 :
487 sparcnbsd_get_longjmp_target_64);
491 sparcnbsd_init_abi_aout (struct gdbarch_info info,
492 struct gdbarch *gdbarch)
494 sparcnbsd_init_abi_common (info, gdbarch);
496 set_gdbarch_in_solib_call_trampoline (gdbarch,
497 sparcnbsd_aout_in_solib_call_trampoline);
501 sparcnbsd_init_abi_elf (struct gdbarch_info info,
502 struct gdbarch *gdbarch)
504 sparcnbsd_init_abi_common (info, gdbarch);
506 set_gdbarch_pc_in_sigtramp (gdbarch, nbsd_pc_in_sigtramp);
508 set_solib_svr4_fetch_link_map_offsets (gdbarch,
509 gdbarch_ptr_bit (gdbarch) == 32 ?
510 nbsd_ilp32_solib_svr4_fetch_link_map_offsets :
511 nbsd_lp64_solib_svr4_fetch_link_map_offsets);
514 static enum gdb_osabi
515 sparcnbsd_aout_osabi_sniffer (bfd *abfd)
517 if (strcmp (bfd_get_target (abfd), "a.out-sparc-netbsd") == 0)
518 return GDB_OSABI_NETBSD_AOUT;
520 return GDB_OSABI_UNKNOWN;
524 _initialize_sparnbsd_tdep (void)
526 gdbarch_register_osabi_sniffer (bfd_arch_sparc, bfd_target_aout_flavour,
527 sparcnbsd_aout_osabi_sniffer);
529 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_AOUT,
530 sparcnbsd_init_abi_aout);
531 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_ELF,
532 sparcnbsd_init_abi_elf);
534 add_core_fns (&sparcnbsd_core_fns);
535 add_core_fns (&sparcnbsd_elfcore_fns);