1 /* Target-dependent code for NetBSD/sh.
3 Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
5 Contributed by Wasabi Systems, Inc.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
30 #include "solib-svr4.h"
32 #include "nbsd-tdep.h"
34 #include "shnbsd-tdep.h"
36 /* Convert an r0-r15 register number into an offset into a ptrace
37 register structure. */
38 static const int regmap
[] =
58 #define SIZEOF_STRUCT_REG (21 * 4)
61 shnbsd_supply_reg (char *regs
, int regno
)
65 if (regno
== PC_REGNUM
|| regno
== -1)
66 regcache_raw_supply (current_regcache
, PC_REGNUM
, regs
+ (0 * 4));
68 if (regno
== SR_REGNUM
|| regno
== -1)
69 regcache_raw_supply (current_regcache
, SR_REGNUM
, regs
+ (1 * 4));
71 if (regno
== PR_REGNUM
|| regno
== -1)
72 regcache_raw_supply (current_regcache
, PR_REGNUM
, regs
+ (2 * 4));
74 if (regno
== MACH_REGNUM
|| regno
== -1)
75 regcache_raw_supply (current_regcache
, MACH_REGNUM
, regs
+ (3 * 4));
77 if (regno
== MACL_REGNUM
|| regno
== -1)
78 regcache_raw_supply (current_regcache
, MACL_REGNUM
, regs
+ (4 * 4));
80 if ((regno
>= R0_REGNUM
&& regno
<= (R0_REGNUM
+ 15)) || regno
== -1)
82 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
83 if (regno
== i
|| regno
== -1)
84 regcache_raw_supply (current_regcache
, i
,
85 regs
+ regmap
[i
- R0_REGNUM
]);
90 shnbsd_fill_reg (char *regs
, int regno
)
94 if (regno
== PC_REGNUM
|| regno
== -1)
95 regcache_raw_collect (current_regcache
, PC_REGNUM
, regs
+ (0 * 4));
97 if (regno
== SR_REGNUM
|| regno
== -1)
98 regcache_raw_collect (current_regcache
, SR_REGNUM
, regs
+ (1 * 4));
100 if (regno
== PR_REGNUM
|| regno
== -1)
101 regcache_raw_collect (current_regcache
, PR_REGNUM
, regs
+ (2 * 4));
103 if (regno
== MACH_REGNUM
|| regno
== -1)
104 regcache_raw_collect (current_regcache
, MACH_REGNUM
, regs
+ (3 * 4));
106 if (regno
== MACL_REGNUM
|| regno
== -1)
107 regcache_raw_collect (current_regcache
, MACL_REGNUM
, regs
+ (4 * 4));
109 if ((regno
>= R0_REGNUM
&& regno
<= (R0_REGNUM
+ 15)) || regno
== -1)
111 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
112 if (regno
== i
|| regno
== -1)
113 regcache_raw_collect (current_regcache
, i
,
114 regs
+ regmap
[i
- R0_REGNUM
]);
119 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
120 int which
, CORE_ADDR ignore
)
122 /* We get everything from the .reg section. */
126 if (core_reg_size
< SIZEOF_STRUCT_REG
)
128 warning (_("Wrong size register set in core file."));
132 /* Integer registers. */
133 shnbsd_supply_reg (core_reg_sect
, -1);
137 fetch_elfcore_registers (char *core_reg_sect
, unsigned core_reg_size
,
138 int which
, CORE_ADDR ignore
)
142 case 0: /* Integer registers. */
143 if (core_reg_size
!= SIZEOF_STRUCT_REG
)
144 warning (_("Wrong size register set in core file."));
146 shnbsd_supply_reg (core_reg_sect
, -1);
150 /* Don't know what kind of register request this is; just ignore it. */
155 static struct core_fns shnbsd_core_fns
=
157 bfd_target_unknown_flavour
, /* core_flavour */
158 default_check_format
, /* check_format */
159 default_core_sniffer
, /* core_sniffer */
160 fetch_core_registers
, /* core_read_registers */
164 static struct core_fns shnbsd_elfcore_fns
=
166 bfd_target_elf_flavour
, /* core_flavour */
167 default_check_format
, /* check_format */
168 default_core_sniffer
, /* core_sniffer */
169 fetch_elfcore_registers
, /* core_read_registers */
174 shnbsd_init_abi (struct gdbarch_info info
,
175 struct gdbarch
*gdbarch
)
177 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
178 nbsd_ilp32_solib_svr4_fetch_link_map_offsets
);
182 _initialize_shnbsd_tdep (void)
184 deprecated_add_core_fns (&shnbsd_core_fns
);
185 deprecated_add_core_fns (&shnbsd_elfcore_fns
);
187 gdbarch_register_osabi (bfd_arch_sh
, 0, GDB_OSABI_NETBSD_ELF
,
189 gdbarch_register_osabi (bfd_arch_sh
, 0, GDB_OSABI_OPENBSD_ELF
,