1 /* Target-dependent code for HP PA-RISC BSD's.
3 Copyright (C) 2004, 2005, 2006, 2007, 2008 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/>. */
21 #include "arch-utils.h"
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
34 #include "elf/common.h"
36 #include "hppa-tdep.h"
37 #include "solib-svr4.h"
39 /* Core file support. */
41 /* Sizeof `struct reg' in <machine/reg.h>. */
42 #define HPPABSD_SIZEOF_GREGS (34 * 4)
44 /* Supply register REGNUM from the buffer specified by GREGS and LEN
45 in the general-purpose register set REGSET to register cache
46 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
49 hppabsd_supply_gregset (const struct regset
*regset
, struct regcache
*regcache
,
50 int regnum
, const void *gregs
, size_t len
)
52 const gdb_byte
*regs
= gregs
;
56 gdb_assert (len
>= HPPABSD_SIZEOF_GREGS
);
58 for (i
= HPPA_R1_REGNUM
, offset
= 4; i
<= HPPA_R31_REGNUM
; i
++, offset
+= 4)
60 if (regnum
== -1 || regnum
== i
)
61 regcache_raw_supply (regcache
, i
, regs
+ offset
);
64 if (regnum
== -1 || regnum
== HPPA_SAR_REGNUM
)
65 regcache_raw_supply (regcache
, HPPA_SAR_REGNUM
, regs
);
66 if (regnum
== -1 || regnum
== HPPA_PCOQ_HEAD_REGNUM
)
67 regcache_raw_supply (regcache
, HPPA_PCOQ_HEAD_REGNUM
, regs
+ 32 * 4);
68 if (regnum
== -1 || regnum
== HPPA_PCOQ_TAIL_REGNUM
)
69 regcache_raw_supply (regcache
, HPPA_PCOQ_TAIL_REGNUM
, regs
+ 33 * 4);
72 /* OpenBSD/hppa register set. */
74 static struct regset hppabsd_gregset
=
77 hppabsd_supply_gregset
80 /* Return the appropriate register set for the core section identified
81 by SECT_NAME and SECT_SIZE. */
83 static const struct regset
*
84 hppabsd_regset_from_core_section (struct gdbarch
*gdbarch
,
85 const char *sect_name
, size_t sect_size
)
87 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= HPPABSD_SIZEOF_GREGS
)
88 return &hppabsd_gregset
;
95 hppabsd_find_global_pointer (struct value
*function
)
97 CORE_ADDR faddr
= value_as_address (function
);
98 struct obj_section
*faddr_sec
;
101 /* Is this a plabel? If so, dereference it to get the Global Pointer
105 if (target_read_memory ((faddr
& ~3) + 4, buf
, sizeof buf
) == 0)
106 return extract_unsigned_integer (buf
, sizeof buf
);
109 /* If the address is in the .plt section, then the real function
110 hasn't yet been fixed up by the linker so we cannot determine the
111 Global Pointer for that function. */
112 if (in_plt_section (faddr
, NULL
))
115 faddr_sec
= find_pc_section (faddr
);
116 if (faddr_sec
!= NULL
)
118 struct obj_section
*sec
;
120 ALL_OBJFILE_OSECTIONS (faddr_sec
->objfile
, sec
)
122 if (strcmp (sec
->the_bfd_section
->name
, ".dynamic") == 0)
126 if (sec
< faddr_sec
->objfile
->sections_end
)
128 CORE_ADDR addr
= sec
->addr
;
130 while (addr
< sec
->endaddr
)
135 if (target_read_memory (addr
, buf
, sizeof buf
) != 0)
138 tag
= extract_signed_integer (buf
, sizeof buf
);
139 if (tag
== DT_PLTGOT
)
143 if (target_read_memory (addr
+ 4, buf
, sizeof buf
) != 0)
146 /* The OpenBSD ld.so doesn't relocate DT_PLTGOT, so
147 we have to do it ourselves. */
148 pltgot
= extract_unsigned_integer (buf
, sizeof buf
);
149 pltgot
+= ANOFFSET (sec
->objfile
->section_offsets
,
150 SECT_OFF_TEXT (sec
->objfile
));
167 hppabsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
169 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
171 /* OpenBSD and NetBSD have a 64-bit 'long double'. */
172 set_gdbarch_long_double_bit (gdbarch
, 64);
173 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
175 /* Core file support. */
176 set_gdbarch_regset_from_core_section
177 (gdbarch
, hppabsd_regset_from_core_section
);
179 /* OpenBSD and NetBSD use ELF. */
181 tdep
->find_global_pointer
= hppabsd_find_global_pointer
;
182 tdep
->in_solib_call_trampoline
= hppa_in_solib_call_trampoline
;
183 set_gdbarch_skip_trampoline_code (gdbarch
, hppa_skip_trampoline_code
);
185 /* OpenBSD and NetBSD use SVR4-style shared libraries. */
186 set_solib_svr4_fetch_link_map_offsets
187 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
191 /* OpenBSD uses uses the traditional NetBSD core file format, even for
192 ports that use ELF. */
193 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
195 static enum gdb_osabi
196 hppabsd_core_osabi_sniffer (bfd
*abfd
)
198 if (strcmp (bfd_get_target (abfd
), "netbsd-core") == 0)
199 return GDB_OSABI_NETBSD_CORE
;
201 return GDB_OSABI_UNKNOWN
;
205 /* Provide a prototype to silence -Wmissing-prototypes. */
206 void _initialize_hppabsd_tdep (void);
209 _initialize_hppabsd_tdep (void)
211 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
212 gdbarch_register_osabi_sniffer (bfd_arch_hppa
, bfd_target_unknown_flavour
,
213 hppabsd_core_osabi_sniffer
);
215 gdbarch_register_osabi (bfd_arch_hppa
, 0, GDB_OSABI_NETBSD_ELF
,
217 gdbarch_register_osabi (bfd_arch_hppa
, 0, GDB_OSABI_OPENBSD_ELF
,