]>
Commit | Line | Data |
---|---|---|
13a38d45 | 1 | /* Target-dependent code for SuperH running NetBSD, for GDB. |
4be87837 | 2 | Copyright 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 | |
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" | |
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. */ | |
36 | static 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 | ||
58 | void | |
20cb8cda | 59 | shnbsd_supply_reg (char *regs, int regno) |
13a38d45 | 60 | { |
20cb8cda | 61 | int i; |
13a38d45 | 62 | |
20cb8cda | 63 | if (regno == PC_REGNUM || regno == -1) |
13a38d45 | 64 | supply_register (PC_REGNUM, regs + (0 * 4)); |
20cb8cda JT |
65 | |
66 | if (regno == SR_REGNUM || regno == -1) | |
13a38d45 | 67 | supply_register (SR_REGNUM, regs + (1 * 4)); |
20cb8cda JT |
68 | |
69 | if (regno == PR_REGNUM || regno == -1) | |
13a38d45 | 70 | supply_register (PR_REGNUM, regs + (2 * 4)); |
13a38d45 | 71 | |
20cb8cda JT |
72 | if (regno == MACH_REGNUM || regno == -1) |
73 | supply_register (MACH_REGNUM, regs + (3 * 4)); | |
13a38d45 | 74 | |
20cb8cda JT |
75 | if (regno == MACL_REGNUM || regno == -1) |
76 | supply_register (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) | |
82 | supply_register (i, regs + regmap[i - R0_REGNUM]); | |
83 | } | |
13a38d45 JT |
84 | } |
85 | ||
86 | void | |
20cb8cda | 87 | shnbsd_fill_reg (char *regs, int regno) |
13a38d45 | 88 | { |
20cb8cda | 89 | int i; |
13a38d45 | 90 | |
20cb8cda | 91 | if (regno == PC_REGNUM || regno == -1) |
13a38d45 | 92 | regcache_collect (PC_REGNUM, regs + (0 * 4)); |
20cb8cda JT |
93 | |
94 | if (regno == SR_REGNUM || regno == -1) | |
13a38d45 | 95 | regcache_collect (SR_REGNUM, regs + (1 * 4)); |
20cb8cda JT |
96 | |
97 | if (regno == PR_REGNUM || regno == -1) | |
13a38d45 | 98 | regcache_collect (PR_REGNUM, regs + (2 * 4)); |
20cb8cda JT |
99 | |
100 | if (regno == MACH_REGNUM || regno == -1) | |
13a38d45 | 101 | regcache_collect (MACH_REGNUM, regs + (3 * 4)); |
20cb8cda JT |
102 | |
103 | if (regno == MACL_REGNUM || regno == -1) | |
13a38d45 | 104 | regcache_collect (MACL_REGNUM, regs + (4 * 4)); |
20cb8cda JT |
105 | |
106 | if ((regno >= R0_REGNUM && regno <= (R0_REGNUM + 15)) || regno == -1) | |
107 | { | |
108 | for (i = R0_REGNUM; i <= (R0_REGNUM + 15); i++) | |
109 | if (regno == i || regno == -1) | |
110 | regcache_collect (i, regs + regmap[i - R0_REGNUM]); | |
111 | } | |
13a38d45 JT |
112 | } |
113 | ||
13a38d45 JT |
114 | static void |
115 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, | |
116 | int which, CORE_ADDR ignore) | |
117 | { | |
118 | /* We get everything from the .reg section. */ | |
119 | if (which != 0) | |
120 | return; | |
121 | ||
122 | if (core_reg_size < SIZEOF_STRUCT_REG) | |
123 | { | |
124 | warning ("Wrong size register set in core file."); | |
125 | return; | |
126 | } | |
127 | ||
128 | /* Integer registers. */ | |
20cb8cda | 129 | shnbsd_supply_reg (core_reg_sect, -1); |
13a38d45 JT |
130 | } |
131 | ||
132 | static void | |
133 | fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, | |
134 | int which, CORE_ADDR ignore) | |
135 | { | |
136 | switch (which) | |
137 | { | |
138 | case 0: /* Integer registers. */ | |
139 | if (core_reg_size != SIZEOF_STRUCT_REG) | |
140 | warning ("Wrong size register set in core file."); | |
141 | else | |
20cb8cda | 142 | shnbsd_supply_reg (core_reg_sect, -1); |
13a38d45 JT |
143 | break; |
144 | ||
145 | default: | |
146 | /* Don't know what kind of register request this is; just ignore it. */ | |
147 | break; | |
148 | } | |
149 | } | |
150 | ||
20cb8cda | 151 | static struct core_fns shnbsd_core_fns = |
13a38d45 JT |
152 | { |
153 | bfd_target_unknown_flavour, /* core_flavour */ | |
154 | default_check_format, /* check_format */ | |
155 | default_core_sniffer, /* core_sniffer */ | |
156 | fetch_core_registers, /* core_read_registers */ | |
157 | NULL /* next */ | |
158 | }; | |
159 | ||
20cb8cda | 160 | static struct core_fns shnbsd_elfcore_fns = |
13a38d45 JT |
161 | { |
162 | bfd_target_elf_flavour, /* core_flavour */ | |
163 | default_check_format, /* check_format */ | |
164 | default_core_sniffer, /* core_sniffer */ | |
165 | fetch_elfcore_registers, /* core_read_registers */ | |
166 | NULL /* next */ | |
167 | }; | |
168 | ||
3d9b49b0 JT |
169 | static int |
170 | shnbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name) | |
171 | { | |
172 | /* FIXME: Need to add support for kernel-provided signal trampolines. */ | |
173 | return (nbsd_pc_in_sigtramp (pc, func_name)); | |
174 | } | |
175 | ||
13a38d45 | 176 | static void |
20cb8cda | 177 | shnbsd_init_abi (struct gdbarch_info info, |
13a38d45 JT |
178 | struct gdbarch *gdbarch) |
179 | { | |
f561f026 | 180 | set_gdbarch_deprecated_pc_in_sigtramp (gdbarch, shnbsd_pc_in_sigtramp); |
3d9b49b0 | 181 | |
13a38d45 | 182 | set_solib_svr4_fetch_link_map_offsets (gdbarch, |
ea5bc2a6 | 183 | nbsd_ilp32_solib_svr4_fetch_link_map_offsets); |
13a38d45 JT |
184 | } |
185 | ||
186 | void | |
20cb8cda | 187 | _initialize_shnbsd_tdep (void) |
13a38d45 | 188 | { |
20cb8cda JT |
189 | add_core_fns (&shnbsd_core_fns); |
190 | add_core_fns (&shnbsd_elfcore_fns); | |
13a38d45 | 191 | |
05816f70 MK |
192 | gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_NETBSD_ELF, |
193 | shnbsd_init_abi); | |
13a38d45 | 194 | } |