1 /* Target-dependent code for HP PA-RISC BSD's.
2
3 Copyright 2004 Free Software Foundation, 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 "arch-utils.h"
24 #include "osabi.h"
25 #include "regcache.h"
26 #include "regset.h"
27
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
30
31 #include "hppa-tdep.h"
32 #include "solib-svr4.h"
33
34 /* Core file support. */
35
36 /* Sizeof `struct reg' in <machine/reg.h>. */
37 #define HPPABSD_SIZEOF_GREGS (46 * 4)
38
39 /* Sizeof `struct fpreg' in <machine/reg.h. */
40 #define HPPABSD_SIZEOF_FPREGS (32 * 8)
41
42 /* Supply register REGNUM from the buffer specified by GREGS and LEN
43 in the general-purpose register set REGSET to register cache
44 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
45
46 static void
hppabsd_supply_gregset(const struct regset * regset,struct regcache * regcache,int regnum,const void * gregs,size_t len)47 hppabsd_supply_gregset (const struct regset *regset, struct regcache *regcache,
48 int regnum, const void *gregs, size_t len)
49 {
50 const char *regs = gregs;
51 size_t offset;
52 int i;
53
54 gdb_assert (len >= HPPABSD_SIZEOF_GREGS);
55
56 for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4)
57 {
58 if (regnum == -1 || regnum == i)
59 regcache_raw_supply (regcache, i, regs + offset);
60 }
61
62 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
63 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
64 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
65 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
66 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
67 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
68 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
69 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
70 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
71 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
72 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
73 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
74 if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
75 regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
76 if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
77 regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
78 if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
79 regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
80 if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
81 regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
82 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
83 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
84 if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
85 regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
86 if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
87 regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
88 if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
89 regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
90 if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
91 regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
92 if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
93 regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
94 }
95
96 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
97 in the floating-point register set REGSET to register cache
98 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
99
100 static void
hppabsd_supply_fpregset(const struct regset * regset,struct regcache * regcache,int regnum,const void * fpregs,size_t len)101 hppabsd_supply_fpregset (const struct regset *regset,
102 struct regcache *regcache,
103 int regnum, const void *fpregs, size_t len)
104 {
105 const char *regs = fpregs;
106 int i;
107
108 gdb_assert (len >= HPPABSD_SIZEOF_FPREGS);
109
110 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32 * 2; i++)
111 {
112 if (regnum == i || regnum == -1)
113 regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4);
114 }
115 }
116
117 /* OpenBSD/hppa register sets. */
118
119 static struct regset hppabsd_gregset =
120 {
121 NULL,
122 hppabsd_supply_gregset
123 };
124
125 static struct regset hppabsd_fpregset =
126 {
127 NULL,
128 hppabsd_supply_fpregset
129 };
130
131 /* Return the appropriate register set for the core section identified
132 by SECT_NAME and SECT_SIZE. */
133
134 static const struct regset *
hppabsd_regset_from_core_section(struct gdbarch * gdbarch,const char * sect_name,size_t sect_size)135 hppabsd_regset_from_core_section (struct gdbarch *gdbarch,
136 const char *sect_name, size_t sect_size)
137 {
138 if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPABSD_SIZEOF_GREGS)
139 return &hppabsd_gregset;
140
141 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPABSD_SIZEOF_FPREGS)
142 return &hppabsd_fpregset;
143
144 return NULL;
145 }
146
147
148 static void
hppabsd_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)149 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
150 {
151 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
152
153 /* Core file support. */
154 set_gdbarch_regset_from_core_section
155 (gdbarch, hppabsd_regset_from_core_section);
156
157 /* OpenBSD and NetBSD use ELF. */
158 tdep->is_elf = 1;
159
160 /* OpenBSD and NetBSD uses SVR4-style shared libraries. */
161 set_gdbarch_in_solib_call_trampoline
162 (gdbarch, generic_in_solib_call_trampoline);
163 set_solib_svr4_fetch_link_map_offsets
164 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
165 }
166
167
168 /* OpenBSD uses uses the traditional NetBSD core file format, even for
169 ports that use ELF. */
170 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
171
172 static enum gdb_osabi
hppabsd_core_osabi_sniffer(bfd * abfd)173 hppabsd_core_osabi_sniffer (bfd *abfd)
174 {
175 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
176 return GDB_OSABI_NETBSD_CORE;
177
178 return GDB_OSABI_UNKNOWN;
179 }
180
181
182 /* Provide a prototype to silence -Wmissing-prototypes. */
183 void _initialize_hppabsd_tdep (void);
184
185 void
_initialize_hppabsd_tdep(void)186 _initialize_hppabsd_tdep (void)
187 {
188 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
189 gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour,
190 hppabsd_core_osabi_sniffer);
191
192 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_NETBSD_ELF,
193 hppabsd_init_abi);
194 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF,
195 hppabsd_init_abi);
196 }
197