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	(34 * 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
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_SAR_REGNUM)
63     regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
64   if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
65     regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
66   if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
67     regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
68 }
69 
70 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
71    in the floating-point register set REGSET to register cache
72    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
73 
74 static void
75 hppabsd_supply_fpregset (const struct regset *regset,
76 			 struct regcache *regcache,
77 			 int regnum, const void *fpregs, size_t len)
78 {
79   const char *regs = fpregs;
80   int i;
81 
82   gdb_assert (len >= HPPABSD_SIZEOF_FPREGS);
83 
84   for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32 * 2; i++)
85     {
86       if (regnum == i || regnum == -1)
87 	regcache_raw_supply (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4);
88     }
89 }
90 
91 /* OpenBSD/hppa register sets.  */
92 
93 static struct regset hppabsd_gregset =
94 {
95   NULL,
96   hppabsd_supply_gregset
97 };
98 
99 static struct regset hppabsd_fpregset =
100 {
101   NULL,
102   hppabsd_supply_fpregset
103 };
104 
105 /* Return the appropriate register set for the core section identified
106    by SECT_NAME and SECT_SIZE.  */
107 
108 static const struct regset *
109 hppabsd_regset_from_core_section (struct gdbarch *gdbarch,
110 				  const char *sect_name, size_t sect_size)
111 {
112   if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPABSD_SIZEOF_GREGS)
113     return &hppabsd_gregset;
114 
115   if (strcmp (sect_name, ".reg2") == 0 && sect_size >= HPPABSD_SIZEOF_FPREGS)
116     return &hppabsd_fpregset;
117 
118   return NULL;
119 }
120 
121 
122 static void
123 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
124 {
125   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
126 
127   /* Core file support.  */
128   set_gdbarch_regset_from_core_section
129     (gdbarch, hppabsd_regset_from_core_section);
130 
131   /* OpenBSD and NetBSD use ELF.  */
132   tdep->is_elf = 1;
133 
134   /* OpenBSD and NetBSD uses SVR4-style shared libraries.  */
135   set_gdbarch_in_solib_call_trampoline
136     (gdbarch, generic_in_solib_call_trampoline);
137   set_solib_svr4_fetch_link_map_offsets
138     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
139 }
140 
141 
142 /* OpenBSD uses uses the traditional NetBSD core file format, even for
143    ports that use ELF.  */
144 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
145 
146 static enum gdb_osabi
147 hppabsd_core_osabi_sniffer (bfd *abfd)
148 {
149   if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
150     return GDB_OSABI_NETBSD_CORE;
151 
152   return GDB_OSABI_UNKNOWN;
153 }
154 
155 
156 /* Provide a prototype to silence -Wmissing-prototypes.  */
157 void _initialize_hppabsd_tdep (void);
158 
159 void
160 _initialize_hppabsd_tdep (void)
161 {
162   /* BFD doesn't set a flavour for NetBSD style a.out core files.  */
163   gdbarch_register_osabi_sniffer (bfd_arch_hppa, bfd_target_unknown_flavour,
164 				  hppabsd_core_osabi_sniffer);
165 
166   gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_NETBSD_ELF,
167 			  hppabsd_init_abi);
168   gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_OPENBSD_ELF,
169 			  hppabsd_init_abi);
170 }
171