1 /* $MirOS: src/gnu/usr.bin/binutils/gdb/sparcobsd-tdep.c,v 1.3 2005/07/07 16:23:00 tg Exp $ */
2
3 /* Target-dependent code for OpenBSD/sparc and MirOS BSD/sparc.
4
5 Copyright 2004, 2005
6 Free Software Foundation, Inc.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 #include "defs.h"
26 #include "floatformat.h"
27 #include "frame.h"
28 #include "frame-unwind.h"
29 #include "osabi.h"
30 #include "solib-svr4.h"
31 #include "symtab.h"
32 #include "trad-frame.h"
33
34 #include "gdb_assert.h"
35
36 #include "sparc-tdep.h"
37
38 /* Signal trampolines. */
39
40 /* The OpenBSD kernel maps the signal trampoline at some random
41 location in user space, which means that the traditional BSD way of
42 detecting it won't work.
43
44 The signal trampoline will be mapped at an address that is page
45 aligned. We recognize the signal trampoline by the looking for the
46 sigreturn system call. */
47
48 static const int sparc32obsd_page_size = 4096;
49
50 static int
sparc32obsd_pc_in_sigtramp(CORE_ADDR pc,char * name)51 sparc32obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
52 {
53 CORE_ADDR start_pc = (pc & ~(sparc32obsd_page_size - 1));
54 unsigned long insn;
55
56 if (name)
57 return 0;
58
59 /* Check for "restore %g0, SYS_sigreturn, %g1". */
60 insn = sparc_fetch_instruction (start_pc + 0xec);
61 if (insn != 0x83e82067)
62 return 0;
63
64 /* Check for "t ST_SYSCALL". */
65 insn = sparc_fetch_instruction (start_pc + 0xf4);
66 if (insn != 0x91d02000)
67 return 0;
68
69 return 1;
70 }
71
72 static struct sparc_frame_cache *
sparc32obsd_frame_cache(struct frame_info * next_frame,void ** this_cache)73 sparc32obsd_frame_cache (struct frame_info *next_frame, void **this_cache)
74 {
75 struct sparc_frame_cache *cache;
76 CORE_ADDR addr;
77
78 if (*this_cache)
79 return *this_cache;
80
81 cache = sparc_frame_cache (next_frame, this_cache);
82 gdb_assert (cache == *this_cache);
83
84 /* If we couldn't find the frame's function, we're probably dealing
85 with an on-stack signal trampoline. */
86 if (cache->pc == 0)
87 {
88 cache->pc = frame_pc_unwind (next_frame);
89 cache->pc &= ~(sparc32obsd_page_size - 1);
90
91 /* Since we couldn't find the frame's function, the cache was
92 initialized under the assumption that we're frameless. */
93 cache->frameless_p = 0;
94 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
95 cache->base = addr;
96 }
97
98 cache->saved_regs = sparc32nbsd_sigcontext_saved_regs (next_frame);
99
100 return cache;
101 }
102
103 static void
sparc32obsd_frame_this_id(struct frame_info * next_frame,void ** this_cache,struct frame_id * this_id)104 sparc32obsd_frame_this_id (struct frame_info *next_frame, void **this_cache,
105 struct frame_id *this_id)
106 {
107 struct sparc_frame_cache *cache =
108 sparc32obsd_frame_cache (next_frame, this_cache);
109
110 (*this_id) = frame_id_build (cache->base, cache->pc);
111 }
112
113 static void
sparc32obsd_frame_prev_register(struct frame_info * next_frame,void ** this_cache,int regnum,int * optimizedp,enum lval_type * lvalp,CORE_ADDR * addrp,int * realnump,gdb_byte * valuep)114 sparc32obsd_frame_prev_register (struct frame_info *next_frame,
115 void **this_cache,
116 int regnum, int *optimizedp,
117 enum lval_type *lvalp, CORE_ADDR *addrp,
118 int *realnump, gdb_byte *valuep)
119 {
120 struct sparc_frame_cache *cache =
121 sparc32obsd_frame_cache (next_frame, this_cache);
122
123 trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
124 optimizedp, lvalp, addrp, realnump, valuep);
125 }
126
127 static const struct frame_unwind sparc32obsd_frame_unwind =
128 {
129 SIGTRAMP_FRAME,
130 sparc32obsd_frame_this_id,
131 sparc32obsd_frame_prev_register
132 };
133
134 static const struct frame_unwind *
sparc32obsd_sigtramp_frame_sniffer(struct frame_info * next_frame)135 sparc32obsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
136 {
137 CORE_ADDR pc = frame_pc_unwind (next_frame);
138 char *name;
139
140 find_pc_partial_function (pc, &name, NULL, NULL);
141 if (sparc32obsd_pc_in_sigtramp (pc, name))
142 return &sparc32obsd_frame_unwind;
143
144 return NULL;
145 }
146
147
148 static void
sparc32obsd_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)149 sparc32obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
150 {
151 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
152
153 /* OpenBSD/sparc is very similar to NetBSD/sparc ELF. */
154 sparc32nbsd_elf_init_abi (info, gdbarch);
155
156 frame_unwind_append_sniffer (gdbarch, sparc32obsd_sigtramp_frame_sniffer);
157 }
158
159
160 /* Provide a prototype to silence -Wmissing-prototypes. */
161 void _initialize_sparc32obsd_tdep (void);
162
163 void
_initialize_sparc32obsd_tdep(void)164 _initialize_sparc32obsd_tdep (void)
165 {
166 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_OPENBSD_ELF,
167 sparc32obsd_init_abi);
168 }
169
170
171 /* MirOS BSD/sparc is virtually identical to OpenBSD/sparc. */
172
173 /* Provide a prototype to silence -Wmissing-prototypes. */
174 void _initialize_sparc32mbsd_tdep (void);
175
176 void
_initialize_sparc32mbsd_tdep(void)177 _initialize_sparc32mbsd_tdep (void)
178 {
179 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_MIRBSD,
180 sparc32obsd_init_abi);
181 }
182