xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/mips64-obsd-tdep.c (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1699b0f92Schristos /* Target-dependent code for OpenBSD/mips64.
2699b0f92Schristos 
3*6881a400Schristos    Copyright (C) 2004-2023 Free Software Foundation, Inc.
4699b0f92Schristos 
5699b0f92Schristos    This file is part of GDB.
6699b0f92Schristos 
7699b0f92Schristos    This program is free software; you can redistribute it and/or modify
8699b0f92Schristos    it under the terms of the GNU General Public License as published by
9699b0f92Schristos    the Free Software Foundation; either version 3 of the License, or
10699b0f92Schristos    (at your option) any later version.
11699b0f92Schristos 
12699b0f92Schristos    This program is distributed in the hope that it will be useful,
13699b0f92Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14699b0f92Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15699b0f92Schristos    GNU General Public License for more details.
16699b0f92Schristos 
17699b0f92Schristos    You should have received a copy of the GNU General Public License
18699b0f92Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19699b0f92Schristos 
20699b0f92Schristos #include "defs.h"
21699b0f92Schristos #include "gdbtypes.h"
22699b0f92Schristos #include "osabi.h"
23699b0f92Schristos #include "regcache.h"
24699b0f92Schristos #include "regset.h"
25699b0f92Schristos #include "trad-frame.h"
26699b0f92Schristos #include "tramp-frame.h"
27699b0f92Schristos 
28699b0f92Schristos #include "obsd-tdep.h"
29699b0f92Schristos #include "mips-tdep.h"
30699b0f92Schristos #include "solib-svr4.h"
31699b0f92Schristos 
32699b0f92Schristos #define MIPS64OBSD_NUM_REGS 73
33699b0f92Schristos 
34699b0f92Schristos /* Core file support.  */
35699b0f92Schristos 
36699b0f92Schristos /* Supply register REGNUM from the buffer specified by GREGS and LEN
37699b0f92Schristos    in the general-purpose register set REGSET to register cache
38699b0f92Schristos    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
39699b0f92Schristos 
40699b0f92Schristos static void
41699b0f92Schristos mips64obsd_supply_gregset (const struct regset *regset,
42699b0f92Schristos 			   struct regcache *regcache, int regnum,
43699b0f92Schristos 			   const void *gregs, size_t len)
44699b0f92Schristos {
45699b0f92Schristos   const char *regs = (const char *) gregs;
46699b0f92Schristos   int i;
47699b0f92Schristos 
48699b0f92Schristos   for (i = 0; i < MIPS64OBSD_NUM_REGS; i++)
49699b0f92Schristos     {
50699b0f92Schristos       if (regnum == i || regnum == -1)
517f2ac410Schristos 	regcache->raw_supply (i, regs + i * 8);
52699b0f92Schristos     }
53699b0f92Schristos }
54699b0f92Schristos 
55699b0f92Schristos /* OpenBSD/mips64 register set.  */
56699b0f92Schristos 
57699b0f92Schristos static const struct regset mips64obsd_gregset =
58699b0f92Schristos {
59699b0f92Schristos   NULL,
60699b0f92Schristos   mips64obsd_supply_gregset
61699b0f92Schristos };
62699b0f92Schristos 
63699b0f92Schristos /* Iterate over core file register note sections.  */
64699b0f92Schristos 
65699b0f92Schristos static void
66699b0f92Schristos mips64obsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
67699b0f92Schristos 					 iterate_over_regset_sections_cb *cb,
68699b0f92Schristos 					 void *cb_data,
69699b0f92Schristos 					 const struct regcache *regcache)
70699b0f92Schristos {
717f2ac410Schristos   cb (".reg", MIPS64OBSD_NUM_REGS * 8, MIPS64OBSD_NUM_REGS * 8,
727f2ac410Schristos       &mips64obsd_gregset, NULL, cb_data);
73699b0f92Schristos }
74699b0f92Schristos 
75699b0f92Schristos 
76699b0f92Schristos /* Signal trampolines.  */
77699b0f92Schristos 
78699b0f92Schristos static void
79699b0f92Schristos mips64obsd_sigframe_init (const struct tramp_frame *self,
80*6881a400Schristos 			  frame_info_ptr this_frame,
81699b0f92Schristos 			  struct trad_frame_cache *cache,
82699b0f92Schristos 			  CORE_ADDR func)
83699b0f92Schristos {
84699b0f92Schristos   struct gdbarch *gdbarch = get_frame_arch (this_frame);
85699b0f92Schristos   CORE_ADDR sp, sigcontext_addr, addr;
86699b0f92Schristos   int regnum;
87699b0f92Schristos 
88699b0f92Schristos   /* We find the appropriate instance of `struct sigcontext' at a
89699b0f92Schristos      fixed offset in the signal frame.  */
90699b0f92Schristos   sp = get_frame_register_signed (this_frame,
91699b0f92Schristos 				  MIPS_SP_REGNUM + gdbarch_num_regs (gdbarch));
92699b0f92Schristos   sigcontext_addr = sp + 32;
93699b0f92Schristos 
94699b0f92Schristos   /* PC.  */
95699b0f92Schristos   regnum = mips_regnum (gdbarch)->pc;
96699b0f92Schristos   trad_frame_set_reg_addr (cache,
97699b0f92Schristos 			   regnum + gdbarch_num_regs (gdbarch),
98699b0f92Schristos 			    sigcontext_addr + 16);
99699b0f92Schristos 
100699b0f92Schristos   /* GPRs.  */
101699b0f92Schristos   for (regnum = MIPS_AT_REGNUM, addr = sigcontext_addr + 32;
102699b0f92Schristos        regnum <= MIPS_RA_REGNUM; regnum++, addr += 8)
103699b0f92Schristos     trad_frame_set_reg_addr (cache,
104699b0f92Schristos 			     regnum + gdbarch_num_regs (gdbarch),
105699b0f92Schristos 			     addr);
106699b0f92Schristos 
107699b0f92Schristos   /* HI and LO.  */
108699b0f92Schristos   regnum = mips_regnum (gdbarch)->lo;
109699b0f92Schristos   trad_frame_set_reg_addr (cache,
110699b0f92Schristos 			   regnum + gdbarch_num_regs (gdbarch),
111699b0f92Schristos 			   sigcontext_addr + 280);
112699b0f92Schristos   regnum = mips_regnum (gdbarch)->hi;
113699b0f92Schristos   trad_frame_set_reg_addr (cache,
114699b0f92Schristos 			   regnum + gdbarch_num_regs (gdbarch),
115699b0f92Schristos 			   sigcontext_addr + 288);
116699b0f92Schristos 
117699b0f92Schristos   /* TODO: Handle the floating-point registers.  */
118699b0f92Schristos 
119699b0f92Schristos   trad_frame_set_id (cache, frame_id_build (sp, func));
120699b0f92Schristos }
121699b0f92Schristos 
122699b0f92Schristos static const struct tramp_frame mips64obsd_sigframe =
123699b0f92Schristos {
124699b0f92Schristos   SIGTRAMP_FRAME,
125699b0f92Schristos   MIPS_INSN32_SIZE,
126699b0f92Schristos   {
1277f2ac410Schristos     { 0x67a40020, ULONGEST_MAX },		/* daddiu  a0,sp,32 */
1287f2ac410Schristos     { 0x24020067, ULONGEST_MAX },		/* li      v0,103 */
1297f2ac410Schristos     { 0x0000000c, ULONGEST_MAX },		/* syscall */
1307f2ac410Schristos     { 0x0000000d, ULONGEST_MAX },		/* break */
1317f2ac410Schristos     { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
132699b0f92Schristos   },
133699b0f92Schristos   mips64obsd_sigframe_init
134699b0f92Schristos };
135699b0f92Schristos 
136699b0f92Schristos 
137699b0f92Schristos static void
138699b0f92Schristos mips64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
139699b0f92Schristos {
140699b0f92Schristos   /* OpenBSD/mips64 only supports the n64 ABI, but the braindamaged
141699b0f92Schristos      way GDB works, forces us to pretend we can handle them all.  */
142699b0f92Schristos 
143699b0f92Schristos   set_gdbarch_iterate_over_regset_sections
144699b0f92Schristos     (gdbarch, mips64obsd_iterate_over_regset_sections);
145699b0f92Schristos 
146699b0f92Schristos   tramp_frame_prepend_unwinder (gdbarch, &mips64obsd_sigframe);
147699b0f92Schristos 
148699b0f92Schristos   set_gdbarch_long_double_bit (gdbarch, 128);
149*6881a400Schristos   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
150699b0f92Schristos 
151699b0f92Schristos   obsd_init_abi(info, gdbarch);
152699b0f92Schristos 
153699b0f92Schristos   /* OpenBSD/mips64 has SVR4-style shared libraries.  */
154699b0f92Schristos   set_solib_svr4_fetch_link_map_offsets
155699b0f92Schristos     (gdbarch, svr4_lp64_fetch_link_map_offsets);
156699b0f92Schristos }
157699b0f92Schristos 
1587d62b00eSchristos void _initialize_mips64obsd_tdep ();
159699b0f92Schristos void
1607d62b00eSchristos _initialize_mips64obsd_tdep ()
161699b0f92Schristos {
162699b0f92Schristos   gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_OPENBSD,
163699b0f92Schristos 			  mips64obsd_init_abi);
164699b0f92Schristos }
165