1 /* Target-dependent code for SPARC systems running NetBSD.
2 Copyright 2002 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 "sparcnbsd-tdep.h"
30 #include "nbsd-tdep.h"
32 #include "solib-svr4.h"
34 #define REG32_OFFSET_PSR (0 * 4)
35 #define REG32_OFFSET_PC (1 * 4)
36 #define REG32_OFFSET_NPC (2 * 4)
37 #define REG32_OFFSET_Y (3 * 4)
38 #define REG32_OFFSET_GLOBAL (4 * 4)
39 #define REG32_OFFSET_OUT (12 * 4)
41 #define REG64_OFFSET_TSTATE (0 * 8)
42 #define REG64_OFFSET_PC (1 * 8)
43 #define REG64_OFFSET_NPC (2 * 8)
44 #define REG64_OFFSET_Y (3 * 8)
45 #define REG64_OFFSET_GLOBAL (4 * 8)
46 #define REG64_OFFSET_OUT (12 * 8)
49 sparcnbsd_supply_reg32 (char *regs, int regno)
53 if (regno == PS_REGNUM || regno == -1)
54 supply_register (PS_REGNUM, regs + REG32_OFFSET_PSR);
56 if (regno == PC_REGNUM || regno == -1)
57 supply_register (PC_REGNUM, regs + REG32_OFFSET_PC);
59 if (regno == NPC_REGNUM || regno == -1)
60 supply_register (NPC_REGNUM, regs + REG32_OFFSET_NPC);
62 if (regno == Y_REGNUM || regno == -1)
63 supply_register (Y_REGNUM, regs + REG32_OFFSET_Y);
65 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
67 if (regno == G0_REGNUM || regno == -1)
68 supply_register (G0_REGNUM, NULL); /* %g0 is always zero */
69 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
71 if (regno == i || regno == -1)
72 supply_register (i, regs + REG32_OFFSET_GLOBAL +
73 ((i - G0_REGNUM) * 4));
77 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
79 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
81 if (regno == i || regno == -1)
82 supply_register (i, regs + REG32_OFFSET_OUT +
83 ((i - O0_REGNUM) * 4));
87 /* Inputs and Locals are stored onto the stack by by the kernel. */
88 if ((regno >= L0_REGNUM && regno <= I7_REGNUM) || regno == -1)
90 CORE_ADDR sp = read_register (SP_REGNUM);
93 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
95 if (regno == i || regno == -1)
97 target_read_memory (sp + ((i - L0_REGNUM) * 4),
99 supply_register (i, buf);
104 /* FIXME: If we don't set these valid, read_register_bytes() rereads
105 all the regs every time it is called! */
106 if (regno == WIM_REGNUM || regno == -1)
107 supply_register (WIM_REGNUM, NULL);
108 if (regno == TBR_REGNUM || regno == -1)
109 supply_register (TBR_REGNUM, NULL);
110 if (regno == CPS_REGNUM || regno == -1)
111 supply_register (CPS_REGNUM, NULL);
115 sparcnbsd_supply_reg64 (char *regs, int regno)
120 if (regno == TSTATE_REGNUM || regno == -1)
121 supply_register (PS_REGNUM, regs + REG64_OFFSET_TSTATE);
123 if (regno == PC_REGNUM || regno == -1)
124 supply_register (PC_REGNUM, regs + REG64_OFFSET_PC);
126 if (regno == NPC_REGNUM || regno == -1)
127 supply_register (NPC_REGNUM, regs + REG64_OFFSET_NPC);
129 if (regno == Y_REGNUM || regno == -1)
131 memset (buf, 0, sizeof (buf));
132 memcpy (&buf[4], regs + REG64_OFFSET_Y, 4);
133 supply_register (Y_REGNUM, buf);
136 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
138 if (regno == G0_REGNUM || regno == -1)
139 supply_register (G0_REGNUM, NULL); /* %g0 is always zero */
140 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
142 if (regno == i || regno == -1)
143 supply_register (i, regs + REG64_OFFSET_GLOBAL +
144 ((i - G0_REGNUM) * 8));
148 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
150 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
152 if (regno == i || regno == -1)
153 supply_register (i, regs + REG64_OFFSET_OUT +
154 ((i - O0_REGNUM) * 8));
158 /* Inputs and Locals are stored onto the stack by by the kernel. */
159 if ((regno >= L0_REGNUM && regno <= I7_REGNUM) || regno == -1)
161 CORE_ADDR sp = read_register (SP_REGNUM);
166 /* Registers are 64-bit. */
169 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
171 if (regno == i || regno == -1)
173 target_read_memory (sp + ((i - L0_REGNUM) * 8),
175 supply_register (i, buf);
181 /* Registers are 32-bit. Toss any sign-extension of the stack
182 pointer, clear out the top half of the temporary buffer, and
183 put the register value in the bottom half. */
186 memset (buf, 0, sizeof (buf));
187 for (i = L0_REGNUM; i <= I7_REGNUM; i++)
189 if (regno == i || regno == -1)
191 target_read_memory (sp + ((i - L0_REGNUM) * 4),
192 &buf[4], sizeof (buf));
193 supply_register (i, buf);
199 /* FIXME: If we don't set these valid, read_register_bytes() rereads
200 all the regs every time it is called! */
201 if (regno == WIM_REGNUM || regno == -1)
202 supply_register (WIM_REGNUM, NULL);
203 if (regno == TBR_REGNUM || regno == -1)
204 supply_register (TBR_REGNUM, NULL);
205 if (regno == CPS_REGNUM || regno == -1)
206 supply_register (CPS_REGNUM, NULL);
210 sparcnbsd_fill_reg32 (char *regs, int regno)
214 if (regno == PS_REGNUM || regno == -1)
215 regcache_collect (PS_REGNUM, regs + REG32_OFFSET_PSR);
217 if (regno == PC_REGNUM || regno == -1)
218 regcache_collect (PC_REGNUM, regs + REG32_OFFSET_PC);
220 if (regno == NPC_REGNUM || regno == -1)
221 regcache_collect (NPC_REGNUM, regs + REG32_OFFSET_NPC);
223 if (regno == Y_REGNUM || regno == -1)
224 regcache_collect (Y_REGNUM, regs + REG32_OFFSET_Y);
226 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
228 /* %g0 is always zero */
229 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
231 if (regno == i || regno == -1)
232 regcache_collect (i, regs + REG32_OFFSET_GLOBAL +
233 ((i - G0_REGNUM) * 4));
237 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
239 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
241 if (regno == i || regno == -1)
242 regcache_collect (i, regs + REG32_OFFSET_OUT +
243 ((i - O0_REGNUM) * 4));
247 /* Responsibility for the stack regs is pushed off onto the caller. */
251 sparcnbsd_fill_reg64 (char *regs, int regno)
255 if (regno == TSTATE_REGNUM || regno == -1)
256 regcache_collect (TSTATE_REGNUM, regs + REG64_OFFSET_TSTATE);
258 if (regno == PC_REGNUM || regno == -1)
259 regcache_collect (PC_REGNUM, regs + REG64_OFFSET_PC);
261 if (regno == NPC_REGNUM || regno == -1)
262 regcache_collect (NPC_REGNUM, regs + REG64_OFFSET_NPC);
264 if (regno == Y_REGNUM || regno == -1)
265 regcache_collect (Y_REGNUM, regs + REG64_OFFSET_Y);
267 if ((regno >= G0_REGNUM && regno <= G7_REGNUM) || regno == -1)
269 /* %g0 is always zero */
270 for (i = G1_REGNUM; i <= G7_REGNUM; i++)
272 if (regno == i || regno == -1)
273 regcache_collect (i, regs + REG64_OFFSET_GLOBAL +
274 ((i - G0_REGNUM) * 4));
278 if ((regno >= O0_REGNUM && regno <= O7_REGNUM) || regno == -1)
280 for (i = O0_REGNUM; i <= O7_REGNUM; i++)
282 if (regno == i || regno == -1)
283 regcache_collect (i, regs + REG64_OFFSET_OUT +
284 ((i - O0_REGNUM) * 4));
288 /* Responsibility for the stack regs is pushed off onto the caller. */
292 sparcnbsd_supply_fpreg32 (char *fpregs, int regno)
296 for (i = 0; i <= 31; i++)
298 if (regno == (FP0_REGNUM + i) || regno == -1)
299 supply_register (FP0_REGNUM + i, fpregs + (i * 4));
302 if (regno == FPS_REGNUM || regno == -1)
303 supply_register (FPS_REGNUM, fpregs + (32 * 4));
307 sparcnbsd_supply_fpreg64 (char *fpregs, int regno)
311 for (i = 0; i <= 31; i++)
313 if (regno == (FP0_REGNUM + i) || regno == -1)
314 supply_register (FP0_REGNUM + i, fpregs + (i * 4));
319 if (regno == (FP0_REGNUM + i) || regno == -1)
320 supply_register (FP0_REGNUM + i, fpregs + (32 * 4) + (i * 8));
323 if (regno == FPS_REGNUM || regno == -1)
324 supply_register (FPS_REGNUM, fpregs + (32 * 4) + (16 * 8));
330 sparcnbsd_fill_fpreg32 (char *fpregs, int regno)
334 for (i = 0; i <= 31; i++)
336 if (regno == (FP0_REGNUM + i) || regno == -1)
337 regcache_collect (FP0_REGNUM + i, fpregs + (i * 4));
340 if (regno == FPS_REGNUM || regno == -1)
341 regcache_collect (FPS_REGNUM, fpregs + (32 * 4));
345 sparcnbsd_fill_fpreg64 (char *fpregs, int regno)
349 for (i = 0; i <= 31; i++)
351 if (regno == (FP0_REGNUM + i) || regno == -1)
352 regcache_collect (FP0_REGNUM + i, fpregs + (i * 4));
357 if (regno == (FP0_REGNUM + i) || regno == -1)
358 regcache_collect (FP0_REGNUM + i, fpregs + (32 * 4) + (i * 8));
361 if (regno == FPS_REGNUM || regno == -1)
362 regcache_collect (FPS_REGNUM, fpregs + (32 * 4) + (16 * 8));
367 /* Unlike other NetBSD implementations, the SPARC port historically used
368 .reg and .reg2 (see bfd/netbsd-core.c), and as such, we can share one
369 routine for a.out and ELF core files. */
371 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
374 int reg_size, fpreg_size;
376 if (gdbarch_ptr_bit (current_gdbarch) == 32)
379 fpreg_size = (33 * 4);
384 fpreg_size = (64 * 4)
392 case 0: /* Integer registers */
393 if (core_reg_size != reg_size)
394 warning ("Wrong size register set in core file.");
395 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
396 sparcnbsd_supply_reg32 (core_reg_sect, -1);
398 sparcnbsd_supply_reg64 (core_reg_sect, -1);
401 case 2: /* Floating pointer registers */
402 if (core_reg_size != fpreg_size)
403 warning ("Wrong size FP register set in core file.");
404 else if (gdbarch_ptr_bit (current_gdbarch) == 32)
405 sparcnbsd_supply_fpreg32 (core_reg_sect, -1);
407 sparcnbsd_supply_fpreg64 (core_reg_sect, -1);
411 /* Don't know what kind of register request this is; just ignore it. */
416 static struct core_fns sparcnbsd_core_fns =
418 bfd_target_unknown_flavour, /* core_flavour */
419 default_check_format, /* check_format */
420 default_core_sniffer, /* core_sniffer */
421 fetch_core_registers, /* core_read_registers */
425 static struct core_fns sparcnbsd_elfcore_fns =
427 bfd_target_elf_flavour, /* core_flavour */
428 default_check_format, /* check_format */
429 default_core_sniffer, /* core_sniffer */
430 fetch_core_registers, /* core_read_registers */
434 /* FIXME: Need PC_IN_SIGTRAMP() support, but NetBSD/sparc signal trampolines
435 aren't easily identified. */
438 sparcnbsd_get_longjmp_target_32 (CORE_ADDR *pc)
443 jb_addr = read_register (O0_REGNUM);
445 if (target_read_memory (jb_addr + 12, buf, sizeof (buf)))
448 *pc = extract_address (buf, sizeof (buf));
454 sparcnbsd_get_longjmp_target_64 (CORE_ADDR *pc)
459 jb_addr = read_register (O0_REGNUM);
461 if (target_read_memory (jb_addr + 16, buf, sizeof (buf)))
464 *pc = extract_address (buf, sizeof (buf));
470 sparcnbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
472 if (strcmp (name, "_DYNAMIC") == 0)
479 sparcnbsd_init_abi_common (struct gdbarch_info info,
480 struct gdbarch *gdbarch)
482 set_gdbarch_get_longjmp_target (gdbarch, gdbarch_ptr_bit (gdbarch) == 32 ?
483 sparcnbsd_get_longjmp_target_32 :
484 sparcnbsd_get_longjmp_target_64);
488 sparcnbsd_init_abi_aout (struct gdbarch_info info,
489 struct gdbarch *gdbarch)
491 sparcnbsd_init_abi_common (info, gdbarch);
493 set_gdbarch_in_solib_call_trampoline (gdbarch,
494 sparcnbsd_aout_in_solib_call_trampoline);
498 sparcnbsd_init_abi_elf (struct gdbarch_info info,
499 struct gdbarch *gdbarch)
501 sparcnbsd_init_abi_common (info, gdbarch);
503 set_gdbarch_pc_in_sigtramp (gdbarch, nbsd_pc_in_sigtramp);
505 set_solib_svr4_fetch_link_map_offsets (gdbarch,
506 gdbarch_ptr_bit (gdbarch) == 32 ?
507 nbsd_ilp32_solib_svr4_fetch_link_map_offsets :
508 nbsd_lp64_solib_svr4_fetch_link_map_offsets);
511 static enum gdb_osabi
512 sparcnbsd_aout_osabi_sniffer (bfd *abfd)
514 if (strcmp (bfd_get_target (abfd), "a.out-sparc-netbsd") == 0)
515 return GDB_OSABI_NETBSD_AOUT;
517 return GDB_OSABI_UNKNOWN;
521 _initialize_sparnbsd_tdep (void)
523 gdbarch_register_osabi_sniffer (bfd_arch_sparc, bfd_target_aout_flavour,
524 sparcnbsd_aout_osabi_sniffer);
526 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_AOUT,
527 sparcnbsd_init_abi_aout);
528 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_ELF,
529 sparcnbsd_init_abi_elf);
531 add_core_fns (&sparcnbsd_core_fns);
532 add_core_fns (&sparcnbsd_elfcore_fns);