Commit | Line | Data |
---|---|---|
8a112c90 MK |
1 | /* Target-dependent code for OpenBSD/alpha. |
2 | ||
7b6bb8da JB |
3 | Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 |
4 | Free Software Foundation, Inc. | |
8a112c90 MK |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
8a112c90 MK |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8a112c90 MK |
20 | |
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "gdbcore.h" | |
24 | #include "osabi.h" | |
25 | ||
6ea0ec3f | 26 | #include "obsd-tdep.h" |
8a112c90 MK |
27 | #include "alpha-tdep.h" |
28 | #include "alphabsd-tdep.h" | |
29 | #include "solib-svr4.h" | |
30 | ||
31 | /* Signal trampolines. */ | |
32 | ||
33 | /* The OpenBSD kernel maps the signal trampoline at some random | |
34 | location in user space, which means that the traditional BSD way of | |
35 | detecting it won't work. | |
36 | ||
37 | The signal trampoline will be mapped at an address that is page | |
38 | aligned. We recognize the signal trampoline by looking for the | |
39 | sigreturn system call. */ | |
40 | ||
41 | static const int alphaobsd_page_size = 8192; | |
42 | ||
43 | static LONGEST | |
e17a4113 | 44 | alphaobsd_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc) |
8a112c90 MK |
45 | { |
46 | return (pc & (alphaobsd_page_size - 1)); | |
47 | } | |
48 | ||
49 | static int | |
e17a4113 UW |
50 | alphaobsd_pc_in_sigtramp (struct gdbarch *gdbarch, |
51 | CORE_ADDR pc, char *name) | |
8a112c90 MK |
52 | { |
53 | CORE_ADDR start_pc = (pc & ~(alphaobsd_page_size - 1)); | |
54 | unsigned insn; | |
55 | ||
56 | if (name) | |
57 | return 0; | |
58 | ||
59 | /* Check for "". */ | |
e17a4113 | 60 | insn = alpha_read_insn (gdbarch, start_pc + 5 * ALPHA_INSN_SIZE); |
8a112c90 MK |
61 | if (insn != 0x201f0067) |
62 | return 0; | |
63 | ||
64 | /* Check for "". */ | |
e17a4113 | 65 | insn = alpha_read_insn (gdbarch, start_pc + 6 * ALPHA_INSN_SIZE); |
8a112c90 MK |
66 | if (insn != 0x00000083) |
67 | return 0; | |
68 | ||
69 | return 1; | |
70 | } | |
71 | ||
72 | static CORE_ADDR | |
94afd7a6 | 73 | alphaobsd_sigcontext_addr (struct frame_info *this_frame) |
8a112c90 | 74 | { |
e17a4113 | 75 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
94afd7a6 | 76 | CORE_ADDR pc = get_frame_pc (this_frame); |
8a112c90 | 77 | |
e17a4113 | 78 | if (alphaobsd_sigtramp_offset (gdbarch, pc) < 3 * ALPHA_INSN_SIZE) |
8a112c90 MK |
79 | { |
80 | /* On entry, a pointer the `struct sigcontext' is passed in %a2. */ | |
94afd7a6 | 81 | return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM + 2); |
8a112c90 | 82 | } |
e17a4113 | 83 | else if (alphaobsd_sigtramp_offset (gdbarch, pc) < 4 * ALPHA_INSN_SIZE) |
8a112c90 MK |
84 | { |
85 | /* It is stored on the stack Before calling the signal handler. */ | |
86 | CORE_ADDR sp; | |
94afd7a6 UW |
87 | sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM); |
88 | return get_frame_memory_unsigned (this_frame, sp, 8); | |
8a112c90 MK |
89 | } |
90 | else | |
91 | { | |
92 | /* It is reloaded into %a0 for the sigreturn(2) call. */ | |
94afd7a6 | 93 | return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM); |
8a112c90 MK |
94 | } |
95 | } | |
96 | \f | |
97 | ||
98 | static void | |
99 | alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch) | |
100 | { | |
101 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
102 | ||
103 | /* Hook into the DWARF CFI frame unwinder. */ | |
104 | alpha_dwarf2_init_abi (info, gdbarch); | |
105 | ||
106 | /* Hook into the MDEBUG frame unwinder. */ | |
107 | alpha_mdebug_init_abi (info, gdbarch); | |
108 | ||
109 | /* OpenBSD/alpha 3.0 and earlier does not provide single step | |
110 | support via ptrace(2); use software single-stepping for now. */ | |
111 | set_gdbarch_software_single_step (gdbarch, alpha_software_single_step); | |
112 | ||
113 | /* OpenBSD/alpha has SVR4-style shared libraries. */ | |
114 | set_solib_svr4_fetch_link_map_offsets | |
115 | (gdbarch, svr4_lp64_fetch_link_map_offsets); | |
6ea0ec3f | 116 | set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver); |
8a112c90 MK |
117 | |
118 | tdep->dynamic_sigtramp_offset = alphaobsd_sigtramp_offset; | |
119 | tdep->pc_in_sigtramp = alphaobsd_pc_in_sigtramp; | |
120 | tdep->sigcontext_addr = alphaobsd_sigcontext_addr; | |
121 | ||
122 | tdep->jb_pc = 2; | |
123 | tdep->jb_elt_size = 8; | |
124 | ||
125 | set_gdbarch_regset_from_core_section | |
126 | (gdbarch, alphanbsd_regset_from_core_section); | |
127 | } | |
128 | \f | |
129 | ||
130 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
131 | void _initialize_alphaobsd_tdep (void); | |
132 | ||
133 | void | |
134 | _initialize_alphaobsd_tdep (void) | |
135 | { | |
136 | gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_OPENBSD_ELF, | |
137 | alphaobsd_init_abi); | |
138 | } |