]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/shnbsd-tdep.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / shnbsd-tdep.c
1 /* Target-dependent code for NetBSD/sh.
2
3 Copyright (C) 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
4
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
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
23
24 #include "defs.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
27 #include "value.h"
28 #include "osabi.h"
29
30 #include "solib-svr4.h"
31
32 #include "nbsd-tdep.h"
33 #include "sh-tdep.h"
34 #include "shnbsd-tdep.h"
35
36 /* Convert an r0-r15 register number into an offset into a ptrace
37 register structure. */
38 static 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
60 void
61 shnbsd_supply_reg (char *regs, int regno)
62 {
63 int i;
64
65 if (regno == PC_REGNUM || regno == -1)
66 regcache_raw_supply (current_regcache, PC_REGNUM, regs + (0 * 4));
67
68 if (regno == SR_REGNUM || regno == -1)
69 regcache_raw_supply (current_regcache, SR_REGNUM, regs + (1 * 4));
70
71 if (regno == PR_REGNUM || regno == -1)
72 regcache_raw_supply (current_regcache, PR_REGNUM, regs + (2 * 4));
73
74 if (regno == MACH_REGNUM || regno == -1)
75 regcache_raw_supply (current_regcache, MACH_REGNUM, regs + (3 * 4));
76
77 if (regno == MACL_REGNUM || regno == -1)
78 regcache_raw_supply (current_regcache, MACL_REGNUM, regs + (4 * 4));
79
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)
84 regcache_raw_supply (current_regcache, i,
85 regs + regmap[i - R0_REGNUM]);
86 }
87 }
88
89 void
90 shnbsd_fill_reg (char *regs, int regno)
91 {
92 int i;
93
94 if (regno == PC_REGNUM || regno == -1)
95 regcache_raw_collect (current_regcache, PC_REGNUM, regs + (0 * 4));
96
97 if (regno == SR_REGNUM || regno == -1)
98 regcache_raw_collect (current_regcache, SR_REGNUM, regs + (1 * 4));
99
100 if (regno == PR_REGNUM || regno == -1)
101 regcache_raw_collect (current_regcache, PR_REGNUM, regs + (2 * 4));
102
103 if (regno == MACH_REGNUM || regno == -1)
104 regcache_raw_collect (current_regcache, MACH_REGNUM, regs + (3 * 4));
105
106 if (regno == MACL_REGNUM || regno == -1)
107 regcache_raw_collect (current_regcache, MACL_REGNUM, regs + (4 * 4));
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)
113 regcache_raw_collect (current_regcache, i,
114 regs + regmap[i - R0_REGNUM]);
115 }
116 }
117
118 static void
119 fetch_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 {
128 warning (_("Wrong size register set in core file."));
129 return;
130 }
131
132 /* Integer registers. */
133 shnbsd_supply_reg (core_reg_sect, -1);
134 }
135
136 static void
137 fetch_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)
144 warning (_("Wrong size register set in core file."));
145 else
146 shnbsd_supply_reg (core_reg_sect, -1);
147 break;
148
149 default:
150 /* Don't know what kind of register request this is; just ignore it. */
151 break;
152 }
153 }
154
155 static struct core_fns shnbsd_core_fns =
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
164 static struct core_fns shnbsd_elfcore_fns =
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
173 static void
174 shnbsd_init_abi (struct gdbarch_info info,
175 struct gdbarch *gdbarch)
176 {
177 set_solib_svr4_fetch_link_map_offsets (gdbarch,
178 nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
179 }
180
181 void
182 _initialize_shnbsd_tdep (void)
183 {
184 deprecated_add_core_fns (&shnbsd_core_fns);
185 deprecated_add_core_fns (&shnbsd_elfcore_fns);
186
187 gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_NETBSD_ELF,
188 shnbsd_init_abi);
189 gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_OPENBSD_ELF,
190 shnbsd_init_abi);
191 }