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