Commit | Line | Data |
---|---|---|
386c036b MK |
1 | /* Target-dependent code for GNU/Linux SPARC. |
2 | ||
a33e488c | 3 | Copyright 2003, 2004, 2005 Free Software Foundation, Inc. |
386c036b MK |
4 | |
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "floatformat.h" | |
24 | #include "frame.h" | |
25 | #include "frame-unwind.h" | |
81f726ab | 26 | #include "tramp-frame.h" |
386c036b MK |
27 | #include "gdbarch.h" |
28 | #include "gdbcore.h" | |
29 | #include "osabi.h" | |
30 | #include "regcache.h" | |
31 | #include "solib-svr4.h" | |
32 | #include "symtab.h" | |
33 | #include "trad-frame.h" | |
34 | ||
386c036b MK |
35 | #include "sparc-tdep.h" |
36 | ||
81f726ab | 37 | /* Signal trampoline support. */ |
386c036b MK |
38 | |
39 | /* GNU/Linux has two flavors of signals. Normal signal handlers, and | |
40 | "realtime" (RT) signals. The RT signals can provide additional | |
41 | information to the signal handler if the SA_SIGINFO flag is set | |
42 | when establishing a signal handler using `sigaction'. It is not | |
43 | unlikely that future versions of GNU/Linux will support SA_SIGINFO | |
44 | for normal signals too. */ | |
45 | ||
46 | /* When the sparc Linux kernel calls a signal handler and the | |
47 | SA_RESTORER flag isn't set, the return address points to a bit of | |
48 | code on the stack. This function returns whether the PC appears to | |
49 | be within this bit of code. | |
50 | ||
51 | The instruction sequence for normal signals is | |
52 | mov __NR_sigreturn, %g1 ! hex: 0x821020d8 | |
53 | ta 0x10 ! hex: 0x91d02010 | |
54 | ||
55 | Checking for the code sequence should be somewhat reliable, because | |
56 | the effect is to call the system call sigreturn. This is unlikely | |
57 | to occur anywhere other than a signal trampoline. | |
58 | ||
59 | It kind of sucks that we have to read memory from the process in | |
60 | order to identify a signal trampoline, but there doesn't seem to be | |
61 | any other way. However, sparc32_linux_pc_in_sigtramp arranges to | |
62 | only call us if no function name could be identified, which should | |
63 | be the case since the code is on the stack. */ | |
64 | ||
65 | #define LINUX32_SIGTRAMP_INSN0 0x821020d8 /* mov __NR_sigreturn, %g1 */ | |
66 | #define LINUX32_SIGTRAMP_INSN1 0x91d02010 /* ta 0x10 */ | |
67 | ||
68 | /* The instruction sequence for RT signals is | |
69 | mov __NR_rt_sigreturn, %g1 ! hex: 0x82102065 | |
81f726ab | 70 | ta {0x10,0x6d} ! hex: 0x91d02010 |
386c036b | 71 | |
81f726ab | 72 | The effect is to call the system call rt_sigreturn. |
386c036b MK |
73 | Note that 64-bit binaries only use this RT signal return method. */ |
74 | ||
75 | #define LINUX32_RT_SIGTRAMP_INSN0 0x82102065 | |
76 | #define LINUX32_RT_SIGTRAMP_INSN1 0x91d02010 | |
77 | ||
81f726ab DM |
78 | static void sparc32_linux_sigframe_init (const struct tramp_frame *self, |
79 | struct frame_info *next_frame, | |
80 | struct trad_frame_cache *this_cache, | |
81 | CORE_ADDR func); | |
386c036b | 82 | |
81f726ab DM |
83 | static const struct tramp_frame sparc32_linux_sigframe = { |
84 | SIGTRAMP_FRAME, | |
85 | 4, | |
86 | { | |
87 | { LINUX32_SIGTRAMP_INSN0, -1 }, | |
88 | { LINUX32_SIGTRAMP_INSN1, -1 }, | |
89 | { TRAMP_SENTINEL_INSN, -1 } | |
90 | }, | |
91 | sparc32_linux_sigframe_init | |
92 | }; | |
386c036b | 93 | |
81f726ab DM |
94 | static const struct tramp_frame sparc32_linux_rt_sigframe = { |
95 | SIGTRAMP_FRAME, | |
96 | 4, | |
97 | { | |
98 | { LINUX32_RT_SIGTRAMP_INSN0, -1 }, | |
99 | { LINUX32_RT_SIGTRAMP_INSN1, -1 }, | |
100 | { TRAMP_SENTINEL_INSN, -1 } | |
101 | }, | |
102 | sparc32_linux_sigframe_init | |
103 | }; | |
386c036b | 104 | |
81f726ab DM |
105 | static void |
106 | sparc32_linux_sigframe_init (const struct tramp_frame *self, | |
107 | struct frame_info *next_frame, | |
108 | struct trad_frame_cache *this_cache, | |
109 | CORE_ADDR func) | |
386c036b | 110 | { |
81f726ab | 111 | CORE_ADDR base, addr; |
386c036b MK |
112 | int regnum; |
113 | ||
81f726ab DM |
114 | base = frame_unwind_register_unsigned (next_frame, SPARC_O1_REGNUM); |
115 | if (self == &sparc32_linux_rt_sigframe) | |
116 | base += 128; | |
386c036b | 117 | |
78a0fd57 DM |
118 | /* Offsets from <bits/sigcontext.h> */ |
119 | ||
81f726ab DM |
120 | trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0x00); |
121 | trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 0x04); | |
122 | trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 0x08); | |
123 | trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 0x0c); | |
386c036b MK |
124 | |
125 | /* Since %g0 is always zero, keep the identity encoding. */ | |
81f726ab DM |
126 | addr = base + 0x14; |
127 | for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++) | |
128 | { | |
129 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
130 | addr += 4; | |
131 | } | |
386c036b | 132 | |
81f726ab DM |
133 | base = addr = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM); |
134 | for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++) | |
135 | { | |
136 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
137 | addr += 4; | |
138 | } | |
139 | trad_frame_set_id (this_cache, frame_id_build (base, func)); | |
386c036b MK |
140 | } |
141 | ||
386c036b MK |
142 | \f |
143 | ||
386c036b MK |
144 | static void |
145 | sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
146 | { | |
a33e488c MK |
147 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
148 | ||
81f726ab DM |
149 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe); |
150 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe); | |
151 | ||
a33e488c MK |
152 | /* GNU/Linux has SVR4-style shared libraries... */ |
153 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); | |
154 | set_solib_svr4_fetch_link_map_offsets | |
155 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
386c036b | 156 | |
a33e488c MK |
157 | /* ...which means that we need some special handling when doing |
158 | prologue analysis. */ | |
159 | tdep->plt_entry_size = 12; | |
386c036b MK |
160 | |
161 | /* GNU/Linux doesn't support the 128-bit `long double' from the psABI. */ | |
162 | set_gdbarch_long_double_bit (gdbarch, 64); | |
163 | set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big); | |
164 | ||
b2756930 KB |
165 | /* Enable TLS support. */ |
166 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
167 | svr4_fetch_objfile_link_map); | |
386c036b MK |
168 | } |
169 | ||
170 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
171 | extern void _initialize_sparc_linux_tdep (void); | |
172 | ||
173 | void | |
174 | _initialize_sparc_linux_tdep (void) | |
175 | { | |
176 | gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX, | |
177 | sparc32_linux_init_abi); | |
178 | } |