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