1 /* Target-dependent code for NetBSD/sh.
3 Copyright (C) 2002, 2003, 2006, 2007, 2008 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 3 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, see <http://www.gnu.org/licenses/>. */
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
33 #include "shnbsd-tdep.h"
34 #include "solib-svr4.h"
36 /* Convert an r0-r15 register number into an offset into a ptrace
37 register structure. */
38 static const int regmap
[] =
58 /* Sizeof `struct reg' in <machine/reg.h>. */
59 #define SHNBSD_SIZEOF_GREGS (21 * 4)
61 /* Supply register REGNUM from the buffer specified by GREGS and LEN
62 in the general-purpose register set REGSET to register cache
63 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
66 shnbsd_supply_gregset (const struct regset
*regset
,
67 struct regcache
*regcache
,
68 int regnum
, const void *gregs
, size_t len
)
70 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
71 const gdb_byte
*regs
= gregs
;
74 gdb_assert (len
>= SHNBSD_SIZEOF_GREGS
);
76 if (regnum
== gdbarch_pc_regnum (gdbarch
) || regnum
== -1)
77 regcache_raw_supply (regcache
, gdbarch_pc_regnum (gdbarch
),
80 if (regnum
== SR_REGNUM
|| regnum
== -1)
81 regcache_raw_supply (regcache
, SR_REGNUM
, regs
+ (1 * 4));
83 if (regnum
== PR_REGNUM
|| regnum
== -1)
84 regcache_raw_supply (regcache
, PR_REGNUM
, regs
+ (2 * 4));
86 if (regnum
== MACH_REGNUM
|| regnum
== -1)
87 regcache_raw_supply (regcache
, MACH_REGNUM
, regs
+ (3 * 4));
89 if (regnum
== MACL_REGNUM
|| regnum
== -1)
90 regcache_raw_supply (regcache
, MACL_REGNUM
, regs
+ (4 * 4));
92 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
94 if (regnum
== i
|| regnum
== -1)
95 regcache_raw_supply (regcache
, i
, regs
+ regmap
[i
- R0_REGNUM
]);
99 /* Collect register REGNUM in the general-purpose register set
100 REGSET. from register cache REGCACHE into the buffer specified by
101 GREGS and LEN. If REGNUM is -1, do this for all registers in
105 shnbsd_collect_gregset (const struct regset
*regset
,
106 const struct regcache
*regcache
,
107 int regnum
, void *gregs
, size_t len
)
109 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
110 gdb_byte
*regs
= gregs
;
113 gdb_assert (len
>= SHNBSD_SIZEOF_GREGS
);
115 if (regnum
== gdbarch_pc_regnum (gdbarch
) || regnum
== -1)
116 regcache_raw_collect (regcache
, gdbarch_pc_regnum (gdbarch
),
119 if (regnum
== SR_REGNUM
|| regnum
== -1)
120 regcache_raw_collect (regcache
, SR_REGNUM
, regs
+ (1 * 4));
122 if (regnum
== PR_REGNUM
|| regnum
== -1)
123 regcache_raw_collect (regcache
, PR_REGNUM
, regs
+ (2 * 4));
125 if (regnum
== MACH_REGNUM
|| regnum
== -1)
126 regcache_raw_collect (regcache
, MACH_REGNUM
, regs
+ (3 * 4));
128 if (regnum
== MACL_REGNUM
|| regnum
== -1)
129 regcache_raw_collect (regcache
, MACL_REGNUM
, regs
+ (4 * 4));
131 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
133 if (regnum
== i
|| regnum
== -1)
134 regcache_raw_collect (regcache
, i
, regs
+ regmap
[i
- R0_REGNUM
]);
138 /* SH register sets. */
140 static struct regset shnbsd_gregset
=
143 shnbsd_supply_gregset
,
144 shnbsd_collect_gregset
147 /* Return the appropriate register set for the core section identified
148 by SECT_NAME and SECT_SIZE. */
150 const struct regset
*
151 shnbsd_regset_from_core_section (struct gdbarch
*gdbarch
,
152 const char *sect_name
, size_t sect_size
)
154 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= SHNBSD_SIZEOF_GREGS
)
155 return &shnbsd_gregset
;
161 shnbsd_supply_reg (struct regcache
*regcache
, const char *regs
, int regnum
)
163 shnbsd_supply_gregset (&shnbsd_gregset
, regcache
, regnum
,
164 regs
, SHNBSD_SIZEOF_GREGS
);
168 shnbsd_fill_reg (const struct regcache
*regcache
, char *regs
, int regnum
)
170 shnbsd_collect_gregset (&shnbsd_gregset
, regcache
, regnum
,
171 regs
, SHNBSD_SIZEOF_GREGS
);
176 shnbsd_init_abi (struct gdbarch_info info
,
177 struct gdbarch
*gdbarch
)
179 set_gdbarch_regset_from_core_section
180 (gdbarch
, shnbsd_regset_from_core_section
);
182 set_solib_svr4_fetch_link_map_offsets
183 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
187 /* OpenBSD uses uses the traditional NetBSD core file format, even for
188 ports that use ELF. */
189 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
191 static enum gdb_osabi
192 shnbsd_core_osabi_sniffer (bfd
*abfd
)
194 if (strcmp (bfd_get_target (abfd
), "netbsd-core") == 0)
195 return GDB_OSABI_NETBSD_CORE
;
197 return GDB_OSABI_UNKNOWN
;
201 _initialize_shnbsd_tdep (void)
203 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
204 gdbarch_register_osabi_sniffer (bfd_arch_sh
, bfd_target_unknown_flavour
,
205 shnbsd_core_osabi_sniffer
);
207 gdbarch_register_osabi (bfd_arch_sh
, 0, GDB_OSABI_NETBSD_ELF
,
209 gdbarch_register_osabi (bfd_arch_sh
, 0, GDB_OSABI_OPENBSD_ELF
,