1 /* Target-dependent code for SDE on MIPS processors.
3 Copyright (C) 2014-2015 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/>. */
27 #include "frame-unwind.h"
28 #include "frame-base.h"
29 #include "trad-frame.h"
31 #include "mips-tdep.h"
33 /* Fill in the register cache *THIS_CACHE for THIS_FRAME for use
34 in the SDE frame unwinder. */
36 static struct trad_frame_cache *
37 mips_sde_frame_cache (struct frame_info *this_frame, void **this_cache)
39 struct gdbarch *gdbarch = get_frame_arch (this_frame);
40 const struct mips_regnum *regs = mips_regnum (gdbarch);
41 const int sizeof_reg_t = mips_abi_regsize (gdbarch);
42 enum mips_abi abi = mips_abi (gdbarch);
43 struct trad_frame_cache *cache;
50 if (*this_cache != NULL)
52 cache = trad_frame_cache_zalloc (this_frame);
55 /* The previous registers are held in struct xcptcontext
62 reg_t vaddr; CP0 BadVAddr
63 reg_t regs[32]; General registers
71 stack_addr = get_frame_register_signed (this_frame,
72 gdbarch_sp_regnum (gdbarch));
77 24: xcpt_gen() argspace (16 bytes)
78 16: _xcptcall() saved ra, rounded up ( 8 bytes)
79 00: _xcptcall() argspace (16 bytes) */
80 xcpt_frame = stack_addr + 40;
84 default: /* Wild guess. */
86 16: xcpt_gen() argspace ( 0 bytes)
87 00: _xcptcall() saved ra, rounded up (16 bytes) */
88 xcpt_frame = stack_addr + 16;
92 trad_frame_set_reg_addr (cache,
93 MIPS_PS_REGNUM + gdbarch_num_regs (gdbarch),
94 xcpt_frame + 0 * sizeof_reg_t);
95 trad_frame_set_reg_addr (cache,
96 regs->cause + gdbarch_num_regs (gdbarch),
97 xcpt_frame + 1 * sizeof_reg_t);
98 trad_frame_set_reg_addr (cache,
99 regs->pc + gdbarch_num_regs (gdbarch),
100 xcpt_frame + 2 * sizeof_reg_t);
101 trad_frame_set_reg_addr (cache,
102 regs->badvaddr + gdbarch_num_regs (gdbarch),
103 xcpt_frame + 3 * sizeof_reg_t);
104 for (i = 0; i < MIPS_NUMREGS; i++)
105 trad_frame_set_reg_addr (cache,
106 i + MIPS_ZERO_REGNUM + gdbarch_num_regs (gdbarch),
107 xcpt_frame + (4 + i) * sizeof_reg_t);
108 trad_frame_set_reg_addr (cache,
109 regs->lo + gdbarch_num_regs (gdbarch),
110 xcpt_frame + 36 * sizeof_reg_t);
111 trad_frame_set_reg_addr (cache,
112 regs->hi + gdbarch_num_regs (gdbarch),
113 xcpt_frame + 37 * sizeof_reg_t);
115 pc = get_frame_pc (this_frame);
116 find_pc_partial_function (pc, NULL, &start_addr, NULL);
117 trad_frame_set_id (cache, frame_id_build (start_addr, stack_addr));
122 /* Implement the this_id function for the SDE frame unwinder. */
125 mips_sde_frame_this_id (struct frame_info *this_frame, void **this_cache,
126 struct frame_id *this_id)
128 struct trad_frame_cache *this_trad_cache
129 = mips_sde_frame_cache (this_frame, this_cache);
131 trad_frame_get_id (this_trad_cache, this_id);
134 /* Implement the prev_register function for the SDE frame unwinder. */
136 static struct value *
137 mips_sde_frame_prev_register (struct frame_info *this_frame,
141 struct trad_frame_cache *trad_cache
142 = mips_sde_frame_cache (this_frame, this_cache);
144 return trad_frame_get_register (trad_cache, this_frame, prev_regnum);
147 /* Implement the sniffer function for the SDE frame unwinder. */
150 mips_sde_frame_sniffer (const struct frame_unwind *self,
151 struct frame_info *this_frame,
154 CORE_ADDR pc = get_frame_pc (this_frame);
157 find_pc_partial_function (pc, &name, NULL, NULL);
159 && (strcmp (name, "_xcptcall") == 0
160 || strcmp (name, "_sigtramp") == 0));
163 /* Data structure for the SDE frame unwinder. */
165 static const struct frame_unwind mips_sde_frame_unwind =
168 default_frame_unwind_stop_reason,
169 mips_sde_frame_this_id,
170 mips_sde_frame_prev_register,
172 mips_sde_frame_sniffer
175 /* Implement the this_base, this_locals, and this_args hooks
176 for the normal unwinder. */
179 mips_sde_frame_base_address (struct frame_info *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 (struct frame_info *this_frame)
198 if (mips_sde_frame_sniffer (&mips_sde_frame_unwind, this_frame, NULL))
199 return &mips_sde_frame_base;
205 mips_sde_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
208 enum gdb_osabi *os_ident_ptr = obj;
211 name = bfd_get_section_name (abfd, sect);
213 /* The presence of a section with a ".sde" prefix is indicative
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 bfd_map_over_sections (abfd,
230 generic_elf_osabi_sniff_abi_tag_sections,
232 if (osabi != GDB_OSABI_UNKNOWN)
233 return GDB_OSABI_UNKNOWN;
235 elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
237 if (elfosabi == ELFOSABI_NONE)
239 /* When elfosabi is ELFOSABI_NONE (0), then the ELF structures in the
240 file are conforming to the base specification for that machine
241 (there are no OS-specific extensions). In order to determine the
242 real OS in use we must look for OS notes that have been added.
244 For SDE, we simply look for sections named with .sde as prefixes. */
245 bfd_map_over_sections (abfd,
246 mips_sde_elf_osabi_sniff_abi_tag_sections,
253 mips_sde_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
255 frame_unwind_append_unwinder (gdbarch, &mips_sde_frame_unwind);
256 frame_base_append_sniffer (gdbarch, mips_sde_frame_base_sniffer);
259 /* Provide a prototype to silence -Wmissing-prototypes. */
260 extern initialize_file_ftype _initialize_mips_sde_tdep;
263 _initialize_mips_sde_tdep (void)
265 gdbarch_register_osabi_sniffer (bfd_arch_mips,
266 bfd_target_elf_flavour,
267 mips_sde_elf_osabi_sniffer);
269 gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_SDE, mips_sde_init_abi);