Add generated source files and fix thinko in aarch64-asm.c
[binutils-gdb.git] / gdb / mips-sde-tdep.c
blobe54440e20b5d0146047d36a99b10a1c24e72a50b
1 /* Target-dependent code for SDE on MIPS processors.
3 Copyright (C) 2014-2024 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 "osabi.h"
22 #include "elf-bfd.h"
23 #include "symtab.h"
25 #include "frame.h"
26 #include "frame-unwind.h"
27 #include "frame-base.h"
28 #include "trad-frame.h"
30 #include "mips-tdep.h"
32 /* Fill in the register cache *THIS_CACHE for THIS_FRAME for use
33 in the SDE frame unwinder. */
35 static struct trad_frame_cache *
36 mips_sde_frame_cache (frame_info_ptr this_frame, void **this_cache)
38 struct gdbarch *gdbarch = get_frame_arch (this_frame);
39 const struct mips_regnum *regs = mips_regnum (gdbarch);
40 const int sizeof_reg_t = mips_abi_regsize (gdbarch);
41 enum mips_abi abi = mips_abi (gdbarch);
42 struct trad_frame_cache *cache;
43 CORE_ADDR xcpt_frame;
44 CORE_ADDR start_addr;
45 CORE_ADDR stack_addr;
46 CORE_ADDR pc;
47 int i;
49 if (*this_cache != NULL)
50 return (struct trad_frame_cache *) *this_cache;
51 cache = trad_frame_cache_zalloc (this_frame);
52 *this_cache = cache;
54 /* The previous registers are held in struct xcptcontext
55 which is at $sp+offs
57 struct xcptcontext {
58 reg_t sr; CP0 Status
59 reg_t cr; CP0 Cause
60 reg_t epc; CP0 EPC
61 reg_t vaddr; CP0 BadVAddr
62 reg_t regs[32]; General registers
63 reg_t mdlo; LO
64 reg_t mdhi; HI
65 reg_t mdex; ACX
66 ...
70 stack_addr = get_frame_register_signed (this_frame,
71 gdbarch_sp_regnum (gdbarch));
72 switch (abi)
74 case MIPS_ABI_O32:
75 /* 40: XCPTCONTEXT
76 24: xcpt_gen() argspace (16 bytes)
77 16: _xcptcall() saved ra, rounded up ( 8 bytes)
78 00: _xcptcall() argspace (16 bytes) */
79 xcpt_frame = stack_addr + 40;
80 break;
81 case MIPS_ABI_N32:
82 case MIPS_ABI_N64:
83 default: /* Wild guess. */
84 /* 16: XCPTCONTEXT
85 16: xcpt_gen() argspace ( 0 bytes)
86 00: _xcptcall() saved ra, rounded up (16 bytes) */
87 xcpt_frame = stack_addr + 16;
88 break;
91 trad_frame_set_reg_addr (cache,
92 MIPS_PS_REGNUM + gdbarch_num_regs (gdbarch),
93 xcpt_frame + 0 * sizeof_reg_t);
94 trad_frame_set_reg_addr (cache,
95 regs->cause + gdbarch_num_regs (gdbarch),
96 xcpt_frame + 1 * sizeof_reg_t);
97 trad_frame_set_reg_addr (cache,
98 regs->pc + gdbarch_num_regs (gdbarch),
99 xcpt_frame + 2 * sizeof_reg_t);
100 trad_frame_set_reg_addr (cache,
101 regs->badvaddr + gdbarch_num_regs (gdbarch),
102 xcpt_frame + 3 * sizeof_reg_t);
103 for (i = 0; i < MIPS_NUMREGS; i++)
104 trad_frame_set_reg_addr (cache,
105 i + MIPS_ZERO_REGNUM + gdbarch_num_regs (gdbarch),
106 xcpt_frame + (4 + i) * sizeof_reg_t);
107 trad_frame_set_reg_addr (cache,
108 regs->lo + gdbarch_num_regs (gdbarch),
109 xcpt_frame + 36 * sizeof_reg_t);
110 trad_frame_set_reg_addr (cache,
111 regs->hi + gdbarch_num_regs (gdbarch),
112 xcpt_frame + 37 * sizeof_reg_t);
114 pc = get_frame_pc (this_frame);
115 find_pc_partial_function (pc, NULL, &start_addr, NULL);
116 trad_frame_set_id (cache, frame_id_build (start_addr, stack_addr));
118 return cache;
121 /* Implement the this_id function for the SDE frame unwinder. */
123 static void
124 mips_sde_frame_this_id (frame_info_ptr this_frame, void **this_cache,
125 struct frame_id *this_id)
127 struct trad_frame_cache *this_trad_cache
128 = mips_sde_frame_cache (this_frame, this_cache);
130 trad_frame_get_id (this_trad_cache, this_id);
133 /* Implement the prev_register function for the SDE frame unwinder. */
135 static struct value *
136 mips_sde_frame_prev_register (frame_info_ptr this_frame,
137 void **this_cache,
138 int prev_regnum)
140 struct trad_frame_cache *trad_cache
141 = mips_sde_frame_cache (this_frame, this_cache);
143 return trad_frame_get_register (trad_cache, this_frame, prev_regnum);
146 /* Implement the sniffer function for the SDE frame unwinder. */
148 static int
149 mips_sde_frame_sniffer (const struct frame_unwind *self,
150 frame_info_ptr this_frame,
151 void **this_cache)
153 CORE_ADDR pc = get_frame_pc (this_frame);
154 const char *name;
156 find_pc_partial_function (pc, &name, NULL, NULL);
157 return (name
158 && (strcmp (name, "_xcptcall") == 0
159 || strcmp (name, "_sigtramp") == 0));
162 /* Data structure for the SDE frame unwinder. */
164 static const struct frame_unwind mips_sde_frame_unwind =
166 "mips sde sigtramp",
167 SIGTRAMP_FRAME,
168 default_frame_unwind_stop_reason,
169 mips_sde_frame_this_id,
170 mips_sde_frame_prev_register,
171 NULL,
172 mips_sde_frame_sniffer
175 /* Implement the this_base, this_locals, and this_args hooks
176 for the normal unwinder. */
178 static CORE_ADDR
179 mips_sde_frame_base_address (frame_info_ptr this_frame, void **this_cache)
181 struct trad_frame_cache *this_trad_cache
182 = mips_sde_frame_cache (this_frame, this_cache);
184 return trad_frame_get_this_base (this_trad_cache);
187 static const struct frame_base mips_sde_frame_base =
189 &mips_sde_frame_unwind,
190 mips_sde_frame_base_address,
191 mips_sde_frame_base_address,
192 mips_sde_frame_base_address
195 static const struct frame_base *
196 mips_sde_frame_base_sniffer (frame_info_ptr this_frame)
198 if (mips_sde_frame_sniffer (&mips_sde_frame_unwind, this_frame, NULL))
199 return &mips_sde_frame_base;
200 else
201 return NULL;
204 static void
205 mips_sde_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
206 void *obj)
208 enum gdb_osabi *os_ident_ptr = (enum gdb_osabi *) obj;
209 const char *name;
211 name = bfd_section_name (sect);
213 /* The presence of a section with a ".sde" prefix is indicative
214 of an SDE binary. */
215 if (startswith (name, ".sde"))
216 *os_ident_ptr = GDB_OSABI_SDE;
219 /* OSABI sniffer for MIPS SDE. */
221 static enum gdb_osabi
222 mips_sde_elf_osabi_sniffer (bfd *abfd)
224 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
225 unsigned int elfosabi;
227 /* If the generic sniffer gets a hit, return and let other sniffers
228 get a crack at it. */
229 for (asection *sect : gdb_bfd_sections (abfd))
230 generic_elf_osabi_sniff_abi_tag_sections (abfd, sect, &osabi);
231 if (osabi != GDB_OSABI_UNKNOWN)
232 return GDB_OSABI_UNKNOWN;
234 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
236 if (elfosabi == ELFOSABI_NONE)
238 /* When elfosabi is ELFOSABI_NONE (0), then the ELF structures in the
239 file are conforming to the base specification for that machine
240 (there are no OS-specific extensions). In order to determine the
241 real OS in use we must look for OS notes that have been added.
243 For SDE, we simply look for sections named with .sde as prefixes. */
244 bfd_map_over_sections (abfd,
245 mips_sde_elf_osabi_sniff_abi_tag_sections,
246 &osabi);
248 return osabi;
251 static void
252 mips_sde_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
254 frame_unwind_append_unwinder (gdbarch, &mips_sde_frame_unwind);
255 frame_base_append_sniffer (gdbarch, mips_sde_frame_base_sniffer);
258 void _initialize_mips_sde_tdep ();
259 void
260 _initialize_mips_sde_tdep ()
262 gdbarch_register_osabi_sniffer (bfd_arch_mips,
263 bfd_target_elf_flavour,
264 mips_sde_elf_osabi_sniffer);
266 gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_SDE, mips_sde_init_abi);