1 /* Target-dependent code for OpenBSD/hppa
3 Copyright (C) 2004-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "hppa-tdep.h"
26 #include "hppabsd-tdep.h"
28 /* Core file support. */
30 /* Sizeof `struct reg' in <machine/reg.h>. */
31 #define HPPAOBSD_SIZEOF_GREGS (34 * 4) /* OpenBSD 5.1 and earlier. */
32 #define HPPANBSD_SIZEOF_GREGS (46 * 4) /* NetBSD and OpenBSD 5.2 and later. */
34 /* Sizeof `struct fpreg' in <machine/reg.h>. */
35 #define HPPAOBSD_SIZEOF_FPREGS (32 * 8)
37 /* Supply register REGNUM from the buffer specified by GREGS and LEN
38 in the general-purpose register set REGSET to register cache
39 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
42 hppaobsd_supply_gregset (const struct regset *regset,
43 struct regcache *regcache,
44 int regnum, const void *gregs, size_t len)
46 gdb_byte zero[4] = { 0 };
47 const gdb_byte *regs = gregs;
51 gdb_assert (len >= HPPAOBSD_SIZEOF_GREGS);
53 if (regnum == -1 || regnum == HPPA_R0_REGNUM)
54 regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero);
55 for (i = HPPA_R1_REGNUM, offset = 4; i <= HPPA_R31_REGNUM; i++, offset += 4)
57 if (regnum == -1 || regnum == i)
58 regcache_raw_supply (regcache, i, regs + offset);
61 if (len >= HPPANBSD_SIZEOF_GREGS)
63 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
64 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
65 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
66 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
67 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
68 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
69 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
70 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
71 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
72 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
73 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
74 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
75 if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
76 regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
77 if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
78 regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
79 if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
80 regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
81 if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
82 regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
83 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
84 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
85 if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
86 regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
87 if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
88 regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
89 if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
90 regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
91 if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
92 regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
93 if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
94 regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
98 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
99 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
100 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
101 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
102 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
103 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
107 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
108 in the floating-point register set REGSET to register cache
109 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
112 hppaobsd_supply_fpregset (const struct regset *regset,
113 struct regcache *regcache,
114 int regnum, const void *fpregs, size_t len)
116 struct gdbarch *gdbarch = get_regcache_arch (regcache);
117 const gdb_byte *regs = fpregs;
120 gdb_assert (len >= HPPAOBSD_SIZEOF_FPREGS);
122 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i++)
124 if (regnum == i || regnum == -1)
125 regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4);
129 /* OpenBSD/hppa register sets. */
131 static const struct regset hppaobsd_gregset =
134 hppaobsd_supply_gregset
137 static const struct regset hppaobsd_fpregset =
140 hppaobsd_supply_fpregset
143 /* Return the appropriate register set for the core section identified
144 by SECT_NAME and SECT_SIZE. */
146 static const struct regset *
147 hppaobsd_regset_from_core_section (struct gdbarch *gdbarch,
148 const char *sect_name, size_t sect_size)
150 if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPAOBSD_SIZEOF_GREGS)
151 return &hppaobsd_gregset;
153 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPAOBSD_SIZEOF_FPREGS)
154 return &hppaobsd_fpregset;
161 hppaobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
163 /* Obviously OpenBSD is BSD-based. */
164 hppabsd_init_abi (info, gdbarch);
166 /* Core file support. */
167 set_gdbarch_regset_from_core_section
168 (gdbarch, hppaobsd_regset_from_core_section);
172 /* OpenBSD uses uses the traditional NetBSD core file format, even for
173 ports that use ELF. */
174 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
176 static enum gdb_osabi
177 hppaobsd_core_osabi_sniffer (bfd *abfd)
179 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
180 return GDB_OSABI_NETBSD_CORE;
182 return GDB_OSABI_UNKNOWN;
186 /* Provide a prototype to silence -Wmissing-prototypes. */
187 void _initialize_hppabsd_tdep (void);
190 _initialize_hppabsd_tdep (void)
192 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
193 gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour,
194 hppaobsd_core_osabi_sniffer);
196 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF,