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