* m32c/gdb-if.c (m32c_signal_to_host): Rename to
[gdb/SamB.git] / gdb / vaxobsd-tdep.c
blob76b1bf7fa48a2f7ba0aae16bba53d0ce324d361f
1 /* Target-dependent code for OpenBSD/vax.
3 Copyright (C) 2005, 2007, 2008, 2009 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 "arch-utils.h"
22 #include "frame.h"
23 #include "frame-unwind.h"
24 #include "osabi.h"
25 #include "symtab.h"
26 #include "trad-frame.h"
28 #include "vax-tdep.h"
30 #include "gdb_string.h"
32 /* Signal trampolines. */
34 /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
35 in virtual memory. The randomness makes it somewhat tricky to
36 detect it, but fortunately we can rely on the fact that the start
37 of the sigtramp routine is page-aligned. We recognize the
38 trampoline by looking for the code that invokes the sigreturn
39 system call. The offset where we can find that code varies from
40 release to release.
42 By the way, the mapping mentioned above is read-only, so you cannot
43 place a breakpoint in the signal trampoline. */
45 /* Default page size. */
46 static const int vaxobsd_page_size = 4096;
48 /* Offset for sigreturn(2). */
49 static const int vaxobsd_sigreturn_offset = 0x11;
51 /* Instruction sequence for sigreturn(2). VAX doesn't have
52 fixed-length instructions so we include the ensuing exit(2) to
53 reduce the chance of spurious matches. */
54 static const gdb_byte vaxobsd_sigreturn[] = {
55 0xbc, 0x8f, 0x67, 0x00, /* chmk $SYS_sigreturn */
56 0xbc, 0x01 /* chmk $SYS_exit */
59 static int
60 vaxobsd_sigtramp_sniffer (const struct frame_unwind *self,
61 struct frame_info *this_frame,
62 void **this_cache)
64 CORE_ADDR pc = get_frame_pc (this_frame);
65 CORE_ADDR start_pc = (pc & ~(vaxobsd_page_size - 1));
66 CORE_ADDR sigreturn_addr = start_pc + vaxobsd_sigreturn_offset;
67 gdb_byte *buf;
68 char *name;
70 find_pc_partial_function (pc, &name, NULL, NULL);
71 if (name)
72 return 0;
74 buf = alloca(sizeof vaxobsd_sigreturn);
75 if (!safe_frame_unwind_memory (this_frame, sigreturn_addr,
76 buf, sizeof vaxobsd_sigreturn))
77 return 0;
79 if (memcmp(buf, vaxobsd_sigreturn, sizeof vaxobsd_sigreturn) == 0)
80 return 1;
82 return 0;
85 static struct trad_frame_cache *
86 vaxobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
88 struct trad_frame_cache *cache;
89 CORE_ADDR addr, base, func;
91 if (*this_cache)
92 return *this_cache;
94 cache = trad_frame_cache_zalloc (this_frame);
95 *this_cache = cache;
97 func = get_frame_pc (this_frame);
98 func &= ~(vaxobsd_page_size - 1);
100 base = get_frame_register_unsigned (this_frame, VAX_SP_REGNUM);
101 addr = get_frame_memory_unsigned (this_frame, base - 4, 4);
103 trad_frame_set_reg_addr (cache, VAX_SP_REGNUM, addr + 8);
104 trad_frame_set_reg_addr (cache, VAX_FP_REGNUM, addr + 12);
105 trad_frame_set_reg_addr (cache, VAX_AP_REGNUM, addr + 16);
106 trad_frame_set_reg_addr (cache, VAX_PC_REGNUM, addr + 20);
107 trad_frame_set_reg_addr (cache, VAX_PS_REGNUM, addr + 24);
109 /* Construct the frame ID using the function start. */
110 trad_frame_set_id (cache, frame_id_build (base, func));
112 return cache;
115 static void
116 vaxobsd_sigtramp_frame_this_id (struct frame_info *this_frame,
117 void **this_cache, struct frame_id *this_id)
119 struct trad_frame_cache *cache =
120 vaxobsd_sigtramp_frame_cache (this_frame, this_cache);
122 trad_frame_get_id (cache, this_id);
125 static struct value *
126 vaxobsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
127 void **this_cache, int regnum)
129 struct trad_frame_cache *cache =
130 vaxobsd_sigtramp_frame_cache (this_frame, this_cache);
132 return trad_frame_get_register (cache, this_frame, regnum);
135 static const struct frame_unwind vaxobsd_sigtramp_frame_unwind = {
136 SIGTRAMP_FRAME,
137 vaxobsd_sigtramp_frame_this_id,
138 vaxobsd_sigtramp_frame_prev_register,
139 NULL,
140 vaxobsd_sigtramp_sniffer
144 /* OpenBSD a.out. */
146 static void
147 vaxobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
149 frame_unwind_append_unwinder (gdbarch, &vaxobsd_sigtramp_frame_unwind);
152 /* FIXME: kettenis/20050821: Since OpenBSD/vax binaries are
153 indistingushable from NetBSD/vax a.out binaries, building a GDB
154 that should support both these targets will probably not work as
155 expected. */
156 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
158 static enum gdb_osabi
159 vaxobsd_aout_osabi_sniffer (bfd *abfd)
161 if (strcmp (bfd_get_target (abfd), "a.out-vax-netbsd") == 0)
162 return GDB_OSABI_OPENBSD_AOUT;
164 return GDB_OSABI_UNKNOWN;
168 /* Provide a prototype to silence -Wmissing-prototypes. */
169 void _initialize_vaxobsd_tdep (void);
171 void
172 _initialize_vaxobsd_tdep (void)
174 gdbarch_register_osabi_sniffer (bfd_arch_vax, bfd_target_aout_flavour,
175 vaxobsd_aout_osabi_sniffer);
177 gdbarch_register_osabi (bfd_arch_vax, 0, GDB_OSABI_OPENBSD_AOUT,
178 vaxobsd_init_abi);