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" | |
26 | #include "gdbarch.h" | |
27 | #include "gdbcore.h" | |
28 | #include "osabi.h" | |
29 | #include "regcache.h" | |
30 | #include "solib-svr4.h" | |
31 | #include "symtab.h" | |
32 | #include "trad-frame.h" | |
70f1dc74 | 33 | #include "tramp-frame.h" |
386c036b | 34 | |
386c036b MK |
35 | #include "sparc-tdep.h" |
36 | ||
81f726ab | 37 | /* Signal trampoline support. */ |
386c036b | 38 | |
70f1dc74 MK |
39 | static void sparc32_linux_sigframe_init (const struct tramp_frame *self, |
40 | struct frame_info *next_frame, | |
41 | struct trad_frame_cache *this_cache, | |
42 | CORE_ADDR func); | |
43 | ||
386c036b MK |
44 | /* GNU/Linux has two flavors of signals. Normal signal handlers, and |
45 | "realtime" (RT) signals. The RT signals can provide additional | |
46 | information to the signal handler if the SA_SIGINFO flag is set | |
47 | when establishing a signal handler using `sigaction'. It is not | |
48 | unlikely that future versions of GNU/Linux will support SA_SIGINFO | |
49 | for normal signals too. */ | |
50 | ||
51 | /* When the sparc Linux kernel calls a signal handler and the | |
52 | SA_RESTORER flag isn't set, the return address points to a bit of | |
70f1dc74 MK |
53 | code on the stack. This code checks whether the PC appears to be |
54 | within this bit of code. | |
386c036b | 55 | |
70f1dc74 | 56 | The instruction sequence for normal signals is encoded below. |
386c036b MK |
57 | Checking for the code sequence should be somewhat reliable, because |
58 | the effect is to call the system call sigreturn. This is unlikely | |
70f1dc74 | 59 | to occur anywhere other than a signal trampoline. */ |
386c036b | 60 | |
70f1dc74 MK |
61 | static const struct tramp_frame sparc32_linux_sigframe = |
62 | { | |
81f726ab DM |
63 | SIGTRAMP_FRAME, |
64 | 4, | |
65 | { | |
70f1dc74 MK |
66 | { 0x821020d8, -1 }, /* mov __NR_sugreturn, %g1 */ |
67 | { 0x91d02010, -1 }, /* ta 0x10 */ | |
81f726ab DM |
68 | { TRAMP_SENTINEL_INSN, -1 } |
69 | }, | |
70 | sparc32_linux_sigframe_init | |
71 | }; | |
386c036b | 72 | |
70f1dc74 MK |
73 | /* The instruction sequence for RT signals is slightly different. The |
74 | effect is to call the system call rt_sigreturn. */ | |
75 | ||
76 | static const struct tramp_frame sparc32_linux_rt_sigframe = | |
77 | { | |
81f726ab DM |
78 | SIGTRAMP_FRAME, |
79 | 4, | |
80 | { | |
70f1dc74 MK |
81 | { 0x82102065, -1 }, /* mov __NR_rt_sigreturn, %g1 */ |
82 | { 0x91d02010, -1 }, /* ta 0x10 */ | |
81f726ab DM |
83 | { TRAMP_SENTINEL_INSN, -1 } |
84 | }, | |
85 | sparc32_linux_sigframe_init | |
86 | }; | |
386c036b | 87 | |
81f726ab DM |
88 | static void |
89 | sparc32_linux_sigframe_init (const struct tramp_frame *self, | |
90 | struct frame_info *next_frame, | |
91 | struct trad_frame_cache *this_cache, | |
92 | CORE_ADDR func) | |
386c036b | 93 | { |
81f726ab | 94 | CORE_ADDR base, addr; |
386c036b MK |
95 | int regnum; |
96 | ||
81f726ab DM |
97 | base = frame_unwind_register_unsigned (next_frame, SPARC_O1_REGNUM); |
98 | if (self == &sparc32_linux_rt_sigframe) | |
99 | base += 128; | |
386c036b | 100 | |
70f1dc74 | 101 | /* Offsets from <bits/sigcontext.h>. */ |
78a0fd57 | 102 | |
70f1dc74 MK |
103 | trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0); |
104 | trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 4); | |
105 | trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 8); | |
106 | trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 12); | |
386c036b MK |
107 | |
108 | /* Since %g0 is always zero, keep the identity encoding. */ | |
70f1dc74 | 109 | addr = base + 20; |
81f726ab DM |
110 | for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++) |
111 | { | |
112 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
113 | addr += 4; | |
114 | } | |
386c036b | 115 | |
81f726ab DM |
116 | base = addr = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM); |
117 | for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++) | |
118 | { | |
119 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
120 | addr += 4; | |
121 | } | |
122 | trad_frame_set_id (this_cache, frame_id_build (base, func)); | |
386c036b | 123 | } |
386c036b MK |
124 | \f |
125 | ||
386c036b MK |
126 | static void |
127 | sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
128 | { | |
a33e488c MK |
129 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
130 | ||
81f726ab DM |
131 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe); |
132 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe); | |
133 | ||
a33e488c MK |
134 | /* GNU/Linux has SVR4-style shared libraries... */ |
135 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); | |
136 | set_solib_svr4_fetch_link_map_offsets | |
137 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
386c036b | 138 | |
a33e488c MK |
139 | /* ...which means that we need some special handling when doing |
140 | prologue analysis. */ | |
141 | tdep->plt_entry_size = 12; | |
386c036b MK |
142 | |
143 | /* GNU/Linux doesn't support the 128-bit `long double' from the psABI. */ | |
144 | set_gdbarch_long_double_bit (gdbarch, 64); | |
145 | set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big); | |
146 | ||
b2756930 KB |
147 | /* Enable TLS support. */ |
148 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
149 | svr4_fetch_objfile_link_map); | |
386c036b MK |
150 | } |
151 | ||
152 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
153 | extern void _initialize_sparc_linux_tdep (void); | |
154 | ||
155 | void | |
156 | _initialize_sparc_linux_tdep (void) | |
157 | { | |
158 | gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX, | |
159 | sparc32_linux_init_abi); | |
160 | } |