Commit | Line | Data |
---|---|---|
af5ca30d NH |
1 | /* Target-dependent code for OpenBSD/hppa |
2 | ||
28e7fd62 | 3 | Copyright (C) 2004-2013 Free Software Foundation, Inc. |
af5ca30d NH |
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 | |
5b1ba0e5 | 9 | the Free Software Foundation; either version 3 of the License, or |
af5ca30d NH |
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 | |
5b1ba0e5 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
af5ca30d NH |
19 | |
20 | #include "defs.h" | |
21 | #include "osabi.h" | |
22 | #include "regcache.h" | |
23 | #include "regset.h" | |
24 | ||
25 | #include "gdb_assert.h" | |
26 | #include "gdb_string.h" | |
27 | ||
28 | #include "hppa-tdep.h" | |
63807e1d | 29 | #include "hppabsd-tdep.h" |
af5ca30d NH |
30 | |
31 | /* Core file support. */ | |
32 | ||
33 | /* Sizeof `struct reg' in <machine/reg.h>. */ | |
cbb6aada MK |
34 | #define HPPAOBSD_SIZEOF_GREGS (34 * 4) /* OpenBSD 5.1 and earlier. */ |
35 | #define HPPANBSD_SIZEOF_GREGS (46 * 4) /* NetBSD and OpenBSD 5.2 and later. */ | |
7c54a108 MK |
36 | |
37 | /* Sizeof `struct fpreg' in <machine/reg.h>. */ | |
38 | #define HPPAOBSD_SIZEOF_FPREGS (32 * 8) | |
af5ca30d NH |
39 | |
40 | /* Supply register REGNUM from the buffer specified by GREGS and LEN | |
41 | in the general-purpose register set REGSET to register cache | |
42 | REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ | |
43 | ||
44 | static void | |
7c54a108 MK |
45 | hppaobsd_supply_gregset (const struct regset *regset, |
46 | struct regcache *regcache, | |
47 | int regnum, const void *gregs, size_t len) | |
af5ca30d | 48 | { |
cbb6aada | 49 | gdb_byte zero[4] = { 0 }; |
af5ca30d NH |
50 | const gdb_byte *regs = gregs; |
51 | size_t offset; | |
52 | int i; | |
53 | ||
7c54a108 | 54 | gdb_assert (len >= HPPAOBSD_SIZEOF_GREGS); |
af5ca30d | 55 | |
cbb6aada MK |
56 | if (regnum == -1 || regnum == HPPA_R0_REGNUM) |
57 | regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero); | |
af5ca30d NH |
58 | for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4) |
59 | { | |
60 | if (regnum == -1 || regnum == i) | |
61 | regcache_raw_supply (regcache, i, regs + offset); | |
62 | } | |
63 | ||
cbb6aada MK |
64 | if (len >= HPPANBSD_SIZEOF_GREGS) |
65 | { | |
66 | if (regnum == -1 || regnum == HPPA_IPSW_REGNUM) | |
67 | regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs); | |
68 | if (regnum == -1 || regnum == HPPA_SAR_REGNUM) | |
69 | regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4); | |
70 | if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM) | |
71 | regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4); | |
72 | if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM) | |
73 | regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4); | |
74 | if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) | |
75 | regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4); | |
76 | if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) | |
77 | regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4); | |
78 | if (regnum == -1 || regnum == HPPA_SR0_REGNUM) | |
79 | regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4); | |
80 | if (regnum == -1 || regnum == HPPA_SR1_REGNUM) | |
81 | regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4); | |
82 | if (regnum == -1 || regnum == HPPA_SR2_REGNUM) | |
83 | regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4); | |
84 | if (regnum == -1 || regnum == HPPA_SR3_REGNUM) | |
85 | regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4); | |
86 | if (regnum == -1 || regnum == HPPA_SR4_REGNUM) | |
87 | regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4); | |
88 | if (regnum == -1 || regnum == HPPA_SR5_REGNUM) | |
89 | regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4); | |
90 | if (regnum == -1 || regnum == HPPA_SR6_REGNUM) | |
91 | regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4); | |
92 | if (regnum == -1 || regnum == HPPA_SR7_REGNUM) | |
93 | regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4); | |
94 | if (regnum == -1 || regnum == HPPA_CR26_REGNUM) | |
95 | regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4); | |
96 | if (regnum == -1 || regnum == HPPA_CR27_REGNUM) | |
97 | regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4); | |
98 | } | |
99 | else | |
100 | { | |
101 | if (regnum == -1 || regnum == HPPA_SAR_REGNUM) | |
102 | regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs); | |
103 | if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) | |
104 | regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); | |
105 | if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) | |
106 | regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); | |
107 | } | |
af5ca30d NH |
108 | } |
109 | ||
7c54a108 MK |
110 | /* Supply register REGNUM from the buffer specified by FPREGS and LEN |
111 | in the floating-point register set REGSET to register cache | |
112 | REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ | |
113 | ||
114 | static void | |
115 | hppaobsd_supply_fpregset (const struct regset *regset, | |
116 | struct regcache *regcache, | |
117 | int regnum, const void *fpregs, size_t len) | |
118 | { | |
119 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
120 | const gdb_byte *regs = fpregs; | |
121 | int i; | |
122 | ||
123 | gdb_assert (len >= HPPAOBSD_SIZEOF_FPREGS); | |
124 | ||
125 | for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i++) | |
126 | { | |
127 | if (regnum == i || regnum == -1) | |
128 | regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4); | |
129 | } | |
130 | } | |
131 | ||
132 | /* OpenBSD/hppa register sets. */ | |
af5ca30d | 133 | |
7c54a108 | 134 | static struct regset hppaobsd_gregset = |
af5ca30d NH |
135 | { |
136 | NULL, | |
7c54a108 MK |
137 | hppaobsd_supply_gregset |
138 | }; | |
139 | ||
140 | static struct regset hppaobsd_fpregset = | |
141 | { | |
142 | NULL, | |
143 | hppaobsd_supply_fpregset | |
af5ca30d NH |
144 | }; |
145 | ||
146 | /* Return the appropriate register set for the core section identified | |
147 | by SECT_NAME and SECT_SIZE. */ | |
148 | ||
149 | static const struct regset * | |
150 | hppaobsd_regset_from_core_section (struct gdbarch *gdbarch, | |
151 | const char *sect_name, size_t sect_size) | |
152 | { | |
7c54a108 MK |
153 | if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPAOBSD_SIZEOF_GREGS) |
154 | return &hppaobsd_gregset; | |
155 | ||
156 | if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPAOBSD_SIZEOF_FPREGS) | |
157 | return &hppaobsd_fpregset; | |
af5ca30d NH |
158 | |
159 | return NULL; | |
160 | } | |
161 | \f | |
162 | ||
63807e1d | 163 | static void |
af5ca30d NH |
164 | hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
165 | { | |
166 | /* Obviously OpenBSD is BSD-based. */ | |
167 | hppabsd_init_abi (info, gdbarch); | |
168 | ||
169 | /* Core file support. */ | |
170 | set_gdbarch_regset_from_core_section | |
171 | (gdbarch, hppaobsd_regset_from_core_section); | |
af5ca30d NH |
172 | } |
173 | \f | |
174 | ||
175 | /* OpenBSD uses uses the traditional NetBSD core file format, even for | |
176 | ports that use ELF. */ | |
177 | #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF | |
178 | ||
179 | static enum gdb_osabi | |
180 | hppaobsd_core_osabi_sniffer (bfd *abfd) | |
181 | { | |
182 | if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0) | |
183 | return GDB_OSABI_NETBSD_CORE; | |
184 | ||
185 | return GDB_OSABI_UNKNOWN; | |
186 | } | |
187 | \f | |
188 | ||
189 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
190 | void _initialize_hppabsd_tdep (void); | |
191 | ||
192 | void | |
193 | _initialize_hppabsd_tdep (void) | |
194 | { | |
195 | /* BFD doesn't set a flavour for NetBSD style a.out core files. */ | |
196 | gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour, | |
197 | hppaobsd_core_osabi_sniffer); | |
198 | ||
199 | gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF, | |
200 | hppaobsd_init_abi); | |
201 | } |