]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/shnbsd-tdep.c
* ppcnbsd-tdep.c: Fix typo in comment.
[thirdparty/binutils-gdb.git] / gdb / shnbsd-tdep.c
CommitLineData
13a38d45 1/* Target-dependent code for SuperH running NetBSD, for GDB.
197e01b6 2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
13a38d45
JT
3 Contributed by Wasabi Systems, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
13a38d45
JT
21
22#include "defs.h"
23#include "gdbcore.h"
24#include "regcache.h"
25#include "value.h"
4be87837 26#include "osabi.h"
13a38d45 27
9964235a
JT
28#include "solib-svr4.h"
29
ea5bc2a6 30#include "nbsd-tdep.h"
ab3b8126 31#include "sh-tdep.h"
4015edd1 32#include "shnbsd-tdep.h"
13a38d45
JT
33
34/* Convert an r0-r15 register number into an offset into a ptrace
35 register structure. */
36static const int regmap[] =
37{
38 (20 * 4), /* r0 */
39 (19 * 4), /* r1 */
40 (18 * 4), /* r2 */
41 (17 * 4), /* r3 */
42 (16 * 4), /* r4 */
43 (15 * 4), /* r5 */
44 (14 * 4), /* r6 */
45 (13 * 4), /* r7 */
46 (12 * 4), /* r8 */
47 (11 * 4), /* r9 */
48 (10 * 4), /* r10 */
49 ( 9 * 4), /* r11 */
50 ( 8 * 4), /* r12 */
51 ( 7 * 4), /* r13 */
52 ( 6 * 4), /* r14 */
53 ( 5 * 4), /* r15 */
54};
55
56#define SIZEOF_STRUCT_REG (21 * 4)
57
58void
20cb8cda 59shnbsd_supply_reg (char *regs, int regno)
13a38d45 60{
20cb8cda 61 int i;
13a38d45 62
20cb8cda 63 if (regno == PC_REGNUM || regno == -1)
23a6d369 64 regcache_raw_supply (current_regcache, PC_REGNUM, regs + (0 * 4));
20cb8cda
JT
65
66 if (regno == SR_REGNUM || regno == -1)
23a6d369 67 regcache_raw_supply (current_regcache, SR_REGNUM, regs + (1 * 4));
20cb8cda
JT
68
69 if (regno == PR_REGNUM || regno == -1)
23a6d369 70 regcache_raw_supply (current_regcache, PR_REGNUM, regs + (2 * 4));
13a38d45 71
20cb8cda 72 if (regno == MACH_REGNUM || regno == -1)
23a6d369 73 regcache_raw_supply (current_regcache, MACH_REGNUM, regs + (3 * 4));
13a38d45 74
20cb8cda 75 if (regno == MACL_REGNUM || regno == -1)
23a6d369 76 regcache_raw_supply (current_regcache, MACL_REGNUM, regs + (4 * 4));
13a38d45 77
20cb8cda
JT
78 if ((regno >= R0_REGNUM && regno <= (R0_REGNUM + 15)) || regno == -1)
79 {
80 for (i = R0_REGNUM; i <= (R0_REGNUM + 15); i++)
81 if (regno == i || regno == -1)
23a6d369
AC
82 regcache_raw_supply (current_regcache, i,
83 regs + regmap[i - R0_REGNUM]);
20cb8cda 84 }
13a38d45
JT
85}
86
87void
20cb8cda 88shnbsd_fill_reg (char *regs, int regno)
13a38d45 89{
20cb8cda 90 int i;
13a38d45 91
20cb8cda 92 if (regno == PC_REGNUM || regno == -1)
822c9732 93 regcache_raw_collect (current_regcache, PC_REGNUM, regs + (0 * 4));
20cb8cda
JT
94
95 if (regno == SR_REGNUM || regno == -1)
822c9732 96 regcache_raw_collect (current_regcache, SR_REGNUM, regs + (1 * 4));
20cb8cda
JT
97
98 if (regno == PR_REGNUM || regno == -1)
822c9732 99 regcache_raw_collect (current_regcache, PR_REGNUM, regs + (2 * 4));
20cb8cda
JT
100
101 if (regno == MACH_REGNUM || regno == -1)
822c9732 102 regcache_raw_collect (current_regcache, MACH_REGNUM, regs + (3 * 4));
20cb8cda
JT
103
104 if (regno == MACL_REGNUM || regno == -1)
822c9732 105 regcache_raw_collect (current_regcache, MACL_REGNUM, regs + (4 * 4));
20cb8cda
JT
106
107 if ((regno >= R0_REGNUM && regno <= (R0_REGNUM + 15)) || regno == -1)
108 {
109 for (i = R0_REGNUM; i <= (R0_REGNUM + 15); i++)
110 if (regno == i || regno == -1)
822c9732
AC
111 regcache_raw_collect (current_regcache, i,
112 regs + regmap[i - R0_REGNUM]);
20cb8cda 113 }
13a38d45
JT
114}
115
13a38d45
JT
116static void
117fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
118 int which, CORE_ADDR ignore)
119{
120 /* We get everything from the .reg section. */
121 if (which != 0)
122 return;
123
124 if (core_reg_size < SIZEOF_STRUCT_REG)
125 {
8a3fe4f8 126 warning (_("Wrong size register set in core file."));
13a38d45
JT
127 return;
128 }
129
130 /* Integer registers. */
20cb8cda 131 shnbsd_supply_reg (core_reg_sect, -1);
13a38d45
JT
132}
133
134static void
135fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size,
136 int which, CORE_ADDR ignore)
137{
138 switch (which)
139 {
140 case 0: /* Integer registers. */
141 if (core_reg_size != SIZEOF_STRUCT_REG)
8a3fe4f8 142 warning (_("Wrong size register set in core file."));
13a38d45 143 else
20cb8cda 144 shnbsd_supply_reg (core_reg_sect, -1);
13a38d45
JT
145 break;
146
147 default:
148 /* Don't know what kind of register request this is; just ignore it. */
149 break;
150 }
151}
152
20cb8cda 153static struct core_fns shnbsd_core_fns =
13a38d45
JT
154{
155 bfd_target_unknown_flavour, /* core_flavour */
156 default_check_format, /* check_format */
157 default_core_sniffer, /* core_sniffer */
158 fetch_core_registers, /* core_read_registers */
159 NULL /* next */
160};
161
20cb8cda 162static struct core_fns shnbsd_elfcore_fns =
13a38d45
JT
163{
164 bfd_target_elf_flavour, /* core_flavour */
165 default_check_format, /* check_format */
166 default_core_sniffer, /* core_sniffer */
167 fetch_elfcore_registers, /* core_read_registers */
168 NULL /* next */
169};
170
171static void
20cb8cda 172shnbsd_init_abi (struct gdbarch_info info,
13a38d45
JT
173 struct gdbarch *gdbarch)
174{
175 set_solib_svr4_fetch_link_map_offsets (gdbarch,
ea5bc2a6 176 nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
13a38d45
JT
177}
178
179void
20cb8cda 180_initialize_shnbsd_tdep (void)
13a38d45 181{
00e32a35
AC
182 deprecated_add_core_fns (&shnbsd_core_fns);
183 deprecated_add_core_fns (&shnbsd_elfcore_fns);
13a38d45 184
05816f70
MK
185 gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_NETBSD_ELF,
186 shnbsd_init_abi);
13a38d45 187}