1 /* Target-dependent code for OpenBSD/sparc.
3 Copyright 2004 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "floatformat.h"
25 #include "frame-unwind.h"
27 #include "solib-svr4.h"
29 #include "trad-frame.h"
31 #include "gdb_assert.h"
33 #include "sparc-tdep.h"
35 /* Signal trampolines. */
37 /* The OpenBSD kernel maps the signal trampoline at some random
38 location in user space, which means that the traditional BSD way of
39 detecting it won't work.
41 The signal trampoline will be mapped at an address that is page
42 aligned. We recognize the signal trampoline by the looking for the
43 sigreturn system call. */
45 static const int sparc32obsd_page_size
= 4096;
48 sparc32obsd_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
50 CORE_ADDR start_pc
= (pc
& ~(sparc32obsd_page_size
- 1));
56 /* Check for "restore %g0, SYS_sigreturn, %g1". */
57 insn
= sparc_fetch_instruction (start_pc
+ 0xec);
58 if (insn
!= 0x83e82067)
61 /* Check for "t ST_SYSCALL". */
62 insn
= sparc_fetch_instruction (start_pc
+ 0xf4);
63 if (insn
!= 0x91d02000)
69 static struct sparc_frame_cache
*
70 sparc32obsd_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
72 struct sparc_frame_cache
*cache
;
78 cache
= sparc_frame_cache (next_frame
, this_cache
);
79 gdb_assert (cache
== *this_cache
);
81 /* If we couldn't find the frame's function, we're probably dealing
82 with an on-stack signal trampoline. */
85 cache
->pc
= frame_pc_unwind (next_frame
);
86 cache
->pc
&= ~(sparc32obsd_page_size
- 1);
88 /* Since we couldn't find the frame's function, the cache was
89 initialized under the assumption that we're frameless. */
90 cache
->frameless_p
= 0;
91 addr
= frame_unwind_register_unsigned (next_frame
, SPARC_FP_REGNUM
);
95 cache
->saved_regs
= sparc32nbsd_sigcontext_saved_regs (next_frame
);
101 sparc32obsd_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
102 struct frame_id
*this_id
)
104 struct sparc_frame_cache
*cache
=
105 sparc32obsd_frame_cache (next_frame
, this_cache
);
107 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
111 sparc32obsd_frame_prev_register (struct frame_info
*next_frame
,
113 int regnum
, int *optimizedp
,
114 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
115 int *realnump
, void *valuep
)
117 struct sparc_frame_cache
*cache
=
118 sparc32obsd_frame_cache (next_frame
, this_cache
);
120 trad_frame_get_prev_register (next_frame
, cache
->saved_regs
, regnum
,
121 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
124 static const struct frame_unwind sparc32obsd_frame_unwind
=
127 sparc32obsd_frame_this_id
,
128 sparc32obsd_frame_prev_register
131 static const struct frame_unwind
*
132 sparc32obsd_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
134 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
137 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
138 if (sparc32obsd_pc_in_sigtramp (pc
, name
))
139 return &sparc32obsd_frame_unwind
;
146 sparc32obsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
148 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
150 /* OpenBSD/sparc is very similar to NetBSD/sparc ELF. */
151 sparc32nbsd_elf_init_abi (info
, gdbarch
);
153 frame_unwind_append_sniffer (gdbarch
, sparc32obsd_sigtramp_frame_sniffer
);
157 /* Provide a prototype to silence -Wmissing-prototypes. */
158 void _initialize_sparc32obsd_tdep (void);
161 _initialize_sparc32obsd_tdep (void)
163 gdbarch_register_osabi (bfd_arch_sparc
, 0, GDB_OSABI_OPENBSD_ELF
,
164 sparc32obsd_init_abi
);