IBM zSystems: Add support for z16 as CPU name.
[binutils-gdb.git] / gdb / sparc-sol2-tdep.c
blob28eb6f67601d5d411e0f1c974720446580147ab1
1 /* Target-dependent code for Solaris SPARC.
3 Copyright (C) 2003-2022 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/>. */
20 #include "defs.h"
21 #include "frame.h"
22 #include "frame-unwind.h"
23 #include "gdbcore.h"
24 #include "symtab.h"
25 #include "objfiles.h"
26 #include "osabi.h"
27 #include "regcache.h"
28 #include "regset.h"
29 #include "target.h"
30 #include "trad-frame.h"
32 #include "sol2-tdep.h"
33 #include "sparc-tdep.h"
34 #include "solib-svr4.h"
36 /* From <sys/regset.h>. */
37 const struct sparc_gregmap sparc32_sol2_gregmap =
39 32 * 4, /* %psr */
40 33 * 4, /* %pc */
41 34 * 4, /* %npc */
42 35 * 4, /* %y */
43 36 * 4, /* %wim */
44 37 * 4, /* %tbr */
45 1 * 4, /* %g1 */
46 16 * 4, /* %l0 */
49 const struct sparc_fpregmap sparc32_sol2_fpregmap =
51 0 * 4, /* %f0 */
52 33 * 4, /* %fsr */
55 static void
56 sparc32_sol2_supply_core_gregset (const struct regset *regset,
57 struct regcache *regcache,
58 int regnum, const void *gregs, size_t len)
60 sparc32_supply_gregset (&sparc32_sol2_gregmap, regcache, regnum, gregs);
63 static void
64 sparc32_sol2_collect_core_gregset (const struct regset *regset,
65 const struct regcache *regcache,
66 int regnum, void *gregs, size_t len)
68 sparc32_collect_gregset (&sparc32_sol2_gregmap, regcache, regnum, gregs);
71 static void
72 sparc32_sol2_supply_core_fpregset (const struct regset *regset,
73 struct regcache *regcache,
74 int regnum, const void *fpregs, size_t len)
76 sparc32_supply_fpregset (&sparc32_sol2_fpregmap, regcache, regnum, fpregs);
79 static void
80 sparc32_sol2_collect_core_fpregset (const struct regset *regset,
81 const struct regcache *regcache,
82 int regnum, void *fpregs, size_t len)
84 sparc32_collect_fpregset (&sparc32_sol2_fpregmap, regcache, regnum, fpregs);
87 static const struct regset sparc32_sol2_gregset =
89 NULL,
90 sparc32_sol2_supply_core_gregset,
91 sparc32_sol2_collect_core_gregset
94 static const struct regset sparc32_sol2_fpregset =
96 NULL,
97 sparc32_sol2_supply_core_fpregset,
98 sparc32_sol2_collect_core_fpregset
102 static struct sparc_frame_cache *
103 sparc32_sol2_sigtramp_frame_cache (struct frame_info *this_frame,
104 void **this_cache)
106 struct sparc_frame_cache *cache;
107 CORE_ADDR mcontext_addr, addr;
108 int regnum;
110 if (*this_cache)
111 return (struct sparc_frame_cache *) *this_cache;
113 cache = sparc_frame_cache (this_frame, this_cache);
114 gdb_assert (cache == *this_cache);
116 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
118 /* The third argument is a pointer to an instance of `ucontext_t',
119 which has a member `uc_mcontext' that contains the saved
120 registers. */
121 regnum =
122 (cache->copied_regs_mask & 0x04) ? SPARC_I2_REGNUM : SPARC_O2_REGNUM;
123 mcontext_addr = get_frame_register_unsigned (this_frame, regnum) + 40;
125 cache->saved_regs[SPARC32_PSR_REGNUM].set_addr (mcontext_addr + 0 * 4);
126 cache->saved_regs[SPARC32_PC_REGNUM].set_addr (mcontext_addr + 1 * 4);
127 cache->saved_regs[SPARC32_NPC_REGNUM].set_addr (mcontext_addr + 2 * 4);
128 cache->saved_regs[SPARC32_Y_REGNUM].set_addr (mcontext_addr + 3 * 4);
130 /* Since %g0 is always zero, keep the identity encoding. */
131 for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 4 * 4;
132 regnum <= SPARC_O7_REGNUM; regnum++, addr += 4)
133 cache->saved_regs[regnum].set_addr (addr);
135 if (get_frame_memory_unsigned (this_frame, mcontext_addr + 19 * 4, 4))
137 /* The register windows haven't been flushed. */
138 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
139 cache->saved_regs[regnum].set_unknown ();
141 else
143 addr = cache->saved_regs[SPARC_SP_REGNUM].addr ();
144 addr = get_frame_memory_unsigned (this_frame, addr, 4);
145 for (regnum = SPARC_L0_REGNUM;
146 regnum <= SPARC_I7_REGNUM; regnum++, addr += 4)
147 cache->saved_regs[regnum].set_addr (addr);
150 return cache;
153 static void
154 sparc32_sol2_sigtramp_frame_this_id (struct frame_info *this_frame,
155 void **this_cache,
156 struct frame_id *this_id)
158 struct sparc_frame_cache *cache =
159 sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);
161 (*this_id) = frame_id_build (cache->base, cache->pc);
164 static struct value *
165 sparc32_sol2_sigtramp_frame_prev_register (struct frame_info *this_frame,
166 void **this_cache,
167 int regnum)
169 struct sparc_frame_cache *cache =
170 sparc32_sol2_sigtramp_frame_cache (this_frame, this_cache);
172 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
175 static int
176 sparc32_sol2_sigtramp_frame_sniffer (const struct frame_unwind *self,
177 struct frame_info *this_frame,
178 void **this_cache)
180 return sol2_sigtramp_p (this_frame);
183 static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
185 "sparc32 solaris sigtramp",
186 SIGTRAMP_FRAME,
187 default_frame_unwind_stop_reason,
188 sparc32_sol2_sigtramp_frame_this_id,
189 sparc32_sol2_sigtramp_frame_prev_register,
190 NULL,
191 sparc32_sol2_sigtramp_frame_sniffer
196 static void
197 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
199 sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
201 tdep->gregset = &sparc32_sol2_gregset;
202 tdep->sizeof_gregset = 152;
204 tdep->fpregset = &sparc32_sol2_fpregset;
205 tdep->sizeof_fpregset = 400;
207 sol2_init_abi (info, gdbarch);
209 /* Solaris has SVR4-style shared libraries... */
210 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
211 set_solib_svr4_fetch_link_map_offsets
212 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
214 /* ...which means that we need some special handling when doing
215 prologue analysis. */
216 tdep->plt_entry_size = 12;
218 /* Solaris has kernel-assisted single-stepping support. */
219 set_gdbarch_software_single_step (gdbarch, NULL);
221 frame_unwind_append_unwinder (gdbarch, &sparc32_sol2_sigtramp_frame_unwind);
224 void _initialize_sparc_sol2_tdep ();
225 void
226 _initialize_sparc_sol2_tdep ()
228 gdbarch_register_osabi (bfd_arch_sparc, 0,
229 GDB_OSABI_SOLARIS, sparc32_sol2_init_abi);