1 /* Target-dependent code for SuperH running NetBSD, for GDB.
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. */
26 #include "solib-svr4.h"
28 #include "shnbsd-tdep.h"
30 /* Convert an r0-r15 register number into an offset into a ptrace
31 register structure. */
32 static const int regmap
[] =
52 #define SIZEOF_STRUCT_REG (21 * 4)
55 shnbsd_supply_reg (char *regs
, int regno
)
59 if (regno
== PC_REGNUM
|| regno
== -1)
60 supply_register (PC_REGNUM
, regs
+ (0 * 4));
62 if (regno
== SR_REGNUM
|| regno
== -1)
63 supply_register (SR_REGNUM
, regs
+ (1 * 4));
65 if (regno
== PR_REGNUM
|| regno
== -1)
66 supply_register (PR_REGNUM
, regs
+ (2 * 4));
68 if (regno
== MACH_REGNUM
|| regno
== -1)
69 supply_register (MACH_REGNUM
, regs
+ (3 * 4));
71 if (regno
== MACL_REGNUM
|| regno
== -1)
72 supply_register (MACL_REGNUM
, regs
+ (4 * 4));
74 if ((regno
>= R0_REGNUM
&& regno
<= (R0_REGNUM
+ 15)) || regno
== -1)
76 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
77 if (regno
== i
|| regno
== -1)
78 supply_register (i
, regs
+ regmap
[i
- R0_REGNUM
]);
83 shnbsd_fill_reg (char *regs
, int regno
)
87 if (regno
== PC_REGNUM
|| regno
== -1)
88 regcache_collect (PC_REGNUM
, regs
+ (0 * 4));
90 if (regno
== SR_REGNUM
|| regno
== -1)
91 regcache_collect (SR_REGNUM
, regs
+ (1 * 4));
93 if (regno
== PR_REGNUM
|| regno
== -1)
94 regcache_collect (PR_REGNUM
, regs
+ (2 * 4));
96 if (regno
== MACH_REGNUM
|| regno
== -1)
97 regcache_collect (MACH_REGNUM
, regs
+ (3 * 4));
99 if (regno
== MACL_REGNUM
|| regno
== -1)
100 regcache_collect (MACL_REGNUM
, regs
+ (4 * 4));
102 if ((regno
>= R0_REGNUM
&& regno
<= (R0_REGNUM
+ 15)) || regno
== -1)
104 for (i
= R0_REGNUM
; i
<= (R0_REGNUM
+ 15); i
++)
105 if (regno
== i
|| regno
== -1)
106 regcache_collect (i
, regs
+ regmap
[i
- R0_REGNUM
]);
110 /* Fetch (and possibly build) an appropriate link_map_offsets
111 structure for NetBSD/sh targets using the struct offsets
112 defined in <link.h> (but without actual reference to that file).
114 This makes it possible to access NetBSD/sh shared libraries
115 from a GDB that was not built on a NetBSD/sh host (for cross
118 static struct link_map_offsets
*
119 shnbsd_solib_svr4_fetch_link_map_offsets (void)
121 static struct link_map_offsets lmo
;
122 static struct link_map_offsets
*lmp
= NULL
;
128 lmo
.r_debug_size
= 16;
130 lmo
.r_map_offset
= 4;
133 lmo
.link_map_size
= 20;
135 lmo
.l_addr_offset
= 0;
138 lmo
.l_name_offset
= 4;
141 lmo
.l_next_offset
= 12;
144 lmo
.l_prev_offset
= 16;
152 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
153 int which
, CORE_ADDR ignore
)
155 /* We get everything from the .reg section. */
159 if (core_reg_size
< SIZEOF_STRUCT_REG
)
161 warning ("Wrong size register set in core file.");
165 /* Integer registers. */
166 shnbsd_supply_reg (core_reg_sect
, -1);
170 fetch_elfcore_registers (char *core_reg_sect
, unsigned core_reg_size
,
171 int which
, CORE_ADDR ignore
)
175 case 0: /* Integer registers. */
176 if (core_reg_size
!= SIZEOF_STRUCT_REG
)
177 warning ("Wrong size register set in core file.");
179 shnbsd_supply_reg (core_reg_sect
, -1);
183 /* Don't know what kind of register request this is; just ignore it. */
188 static struct core_fns shnbsd_core_fns
=
190 bfd_target_unknown_flavour
, /* core_flavour */
191 default_check_format
, /* check_format */
192 default_core_sniffer
, /* core_sniffer */
193 fetch_core_registers
, /* core_read_registers */
197 static struct core_fns shnbsd_elfcore_fns
=
199 bfd_target_elf_flavour
, /* core_flavour */
200 default_check_format
, /* check_format */
201 default_core_sniffer
, /* core_sniffer */
202 fetch_elfcore_registers
, /* core_read_registers */
207 shnbsd_init_abi (struct gdbarch_info info
,
208 struct gdbarch
*gdbarch
)
210 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
211 shnbsd_solib_svr4_fetch_link_map_offsets
);
215 _initialize_shnbsd_tdep (void)
217 add_core_fns (&shnbsd_core_fns
);
218 add_core_fns (&shnbsd_elfcore_fns
);
220 sh_gdbarch_register_os_abi (SH_OSABI_NETBSD_ELF
, shnbsd_init_abi
);