GDB (API)
|
00001 /* Target-dependent code for GNU/Linux SPARC. 00002 00003 Copyright (C) 2003-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "dwarf2-frame.h" 00022 #include "frame.h" 00023 #include "frame-unwind.h" 00024 #include "gdbtypes.h" 00025 #include "regset.h" 00026 #include "gdbarch.h" 00027 #include "gdbcore.h" 00028 #include "osabi.h" 00029 #include "regcache.h" 00030 #include "solib-svr4.h" 00031 #include "symtab.h" 00032 #include "trad-frame.h" 00033 #include "tramp-frame.h" 00034 #include "xml-syscall.h" 00035 #include "linux-tdep.h" 00036 00037 /* The syscall's XML filename for sparc 32-bit. */ 00038 #define XML_SYSCALL_FILENAME_SPARC32 "syscalls/sparc-linux.xml" 00039 00040 #include "sparc-tdep.h" 00041 00042 /* Signal trampoline support. */ 00043 00044 static void sparc32_linux_sigframe_init (const struct tramp_frame *self, 00045 struct frame_info *this_frame, 00046 struct trad_frame_cache *this_cache, 00047 CORE_ADDR func); 00048 00049 /* GNU/Linux has two flavors of signals. Normal signal handlers, and 00050 "realtime" (RT) signals. The RT signals can provide additional 00051 information to the signal handler if the SA_SIGINFO flag is set 00052 when establishing a signal handler using `sigaction'. It is not 00053 unlikely that future versions of GNU/Linux will support SA_SIGINFO 00054 for normal signals too. */ 00055 00056 /* When the sparc Linux kernel calls a signal handler and the 00057 SA_RESTORER flag isn't set, the return address points to a bit of 00058 code on the stack. This code checks whether the PC appears to be 00059 within this bit of code. 00060 00061 The instruction sequence for normal signals is encoded below. 00062 Checking for the code sequence should be somewhat reliable, because 00063 the effect is to call the system call sigreturn. This is unlikely 00064 to occur anywhere other than a signal trampoline. */ 00065 00066 static const struct tramp_frame sparc32_linux_sigframe = 00067 { 00068 SIGTRAMP_FRAME, 00069 4, 00070 { 00071 { 0x821020d8, -1 }, /* mov __NR_sugreturn, %g1 */ 00072 { 0x91d02010, -1 }, /* ta 0x10 */ 00073 { TRAMP_SENTINEL_INSN, -1 } 00074 }, 00075 sparc32_linux_sigframe_init 00076 }; 00077 00078 /* The instruction sequence for RT signals is slightly different. The 00079 effect is to call the system call rt_sigreturn. */ 00080 00081 static const struct tramp_frame sparc32_linux_rt_sigframe = 00082 { 00083 SIGTRAMP_FRAME, 00084 4, 00085 { 00086 { 0x82102065, -1 }, /* mov __NR_rt_sigreturn, %g1 */ 00087 { 0x91d02010, -1 }, /* ta 0x10 */ 00088 { TRAMP_SENTINEL_INSN, -1 } 00089 }, 00090 sparc32_linux_sigframe_init 00091 }; 00092 00093 /* This enum represents the signals' numbers on the SPARC 00094 architecture. It just contains the signal definitions which are 00095 different from the generic implementation. 00096 00097 It is derived from the file <arch/sparc/include/uapi/asm/signal.h>, 00098 from the Linux kernel tree. */ 00099 00100 enum 00101 { 00102 SPARC_LINUX_SIGEMT = 7, 00103 SPARC_LINUX_SIGBUS = 10, 00104 SPARC_LINUX_SIGSYS = 12, 00105 SPARC_LINUX_SIGURG = 16, 00106 SPARC_LINUX_SIGSTOP = 17, 00107 SPARC_LINUX_SIGTSTP = 18, 00108 SPARC_LINUX_SIGCONT = 19, 00109 SPARC_LINUX_SIGCHLD = 20, 00110 SPARC_LINUX_SIGIO = 23, 00111 SPARC_LINUX_SIGPOLL = SPARC_LINUX_SIGIO, 00112 SPARC_LINUX_SIGLOST = 29, 00113 SPARC_LINUX_SIGPWR = SPARC_LINUX_SIGLOST, 00114 SPARC_LINUX_SIGUSR1 = 30, 00115 SPARC_LINUX_SIGUSR2 = 31, 00116 }; 00117 00118 static void 00119 sparc32_linux_sigframe_init (const struct tramp_frame *self, 00120 struct frame_info *this_frame, 00121 struct trad_frame_cache *this_cache, 00122 CORE_ADDR func) 00123 { 00124 CORE_ADDR base, addr, sp_addr; 00125 int regnum; 00126 00127 base = get_frame_register_unsigned (this_frame, SPARC_O1_REGNUM); 00128 if (self == &sparc32_linux_rt_sigframe) 00129 base += 128; 00130 00131 /* Offsets from <bits/sigcontext.h>. */ 00132 00133 trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0); 00134 trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 4); 00135 trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 8); 00136 trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 12); 00137 00138 /* Since %g0 is always zero, keep the identity encoding. */ 00139 addr = base + 20; 00140 sp_addr = base + 16 + ((SPARC_SP_REGNUM - SPARC_G0_REGNUM) * 4); 00141 for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++) 00142 { 00143 trad_frame_set_reg_addr (this_cache, regnum, addr); 00144 addr += 4; 00145 } 00146 00147 base = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM); 00148 addr = get_frame_memory_unsigned (this_frame, sp_addr, 4); 00149 00150 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++) 00151 { 00152 trad_frame_set_reg_addr (this_cache, regnum, addr); 00153 addr += 4; 00154 } 00155 trad_frame_set_id (this_cache, frame_id_build (base, func)); 00156 } 00157 00158 /* Return the address of a system call's alternative return 00159 address. */ 00160 00161 static CORE_ADDR 00162 sparc32_linux_step_trap (struct frame_info *frame, unsigned long insn) 00163 { 00164 if (insn == 0x91d02010) 00165 { 00166 ULONGEST sc_num = get_frame_register_unsigned (frame, SPARC_G1_REGNUM); 00167 00168 /* __NR_rt_sigreturn is 101 and __NR_sigreturn is 216. */ 00169 if (sc_num == 101 || sc_num == 216) 00170 { 00171 struct gdbarch *gdbarch = get_frame_arch (frame); 00172 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00173 00174 ULONGEST sp, pc_offset; 00175 00176 sp = get_frame_register_unsigned (frame, SPARC_SP_REGNUM); 00177 00178 /* The kernel puts the sigreturn registers on the stack, 00179 and this is where the signal unwinding state is take from 00180 when returning from a signal. 00181 00182 For __NR_sigreturn, this register area sits 96 bytes from 00183 the base of the stack. The saved PC sits 4 bytes into the 00184 sigreturn register save area. 00185 00186 For __NR_rt_sigreturn a siginfo_t, which is 128 bytes, sits 00187 right before the sigreturn register save area. */ 00188 00189 pc_offset = 96 + 4; 00190 if (sc_num == 101) 00191 pc_offset += 128; 00192 00193 return read_memory_unsigned_integer (sp + pc_offset, 4, byte_order); 00194 } 00195 } 00196 00197 return 0; 00198 } 00199 00200 00201 const struct sparc_gregset sparc32_linux_core_gregset = 00202 { 00203 32 * 4, /* %psr */ 00204 33 * 4, /* %pc */ 00205 34 * 4, /* %npc */ 00206 35 * 4, /* %y */ 00207 -1, /* %wim */ 00208 -1, /* %tbr */ 00209 1 * 4, /* %g1 */ 00210 16 * 4, /* %l0 */ 00211 4, /* y size */ 00212 }; 00213 00214 00215 static void 00216 sparc32_linux_supply_core_gregset (const struct regset *regset, 00217 struct regcache *regcache, 00218 int regnum, const void *gregs, size_t len) 00219 { 00220 sparc32_supply_gregset (&sparc32_linux_core_gregset, 00221 regcache, regnum, gregs); 00222 } 00223 00224 static void 00225 sparc32_linux_collect_core_gregset (const struct regset *regset, 00226 const struct regcache *regcache, 00227 int regnum, void *gregs, size_t len) 00228 { 00229 sparc32_collect_gregset (&sparc32_linux_core_gregset, 00230 regcache, regnum, gregs); 00231 } 00232 00233 static void 00234 sparc32_linux_supply_core_fpregset (const struct regset *regset, 00235 struct regcache *regcache, 00236 int regnum, const void *fpregs, size_t len) 00237 { 00238 sparc32_supply_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs); 00239 } 00240 00241 static void 00242 sparc32_linux_collect_core_fpregset (const struct regset *regset, 00243 const struct regcache *regcache, 00244 int regnum, void *fpregs, size_t len) 00245 { 00246 sparc32_collect_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs); 00247 } 00248 00249 /* Set the program counter for process PTID to PC. */ 00250 00251 #define PSR_SYSCALL 0x00004000 00252 00253 static void 00254 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) 00255 { 00256 struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache)); 00257 ULONGEST psr; 00258 00259 regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); 00260 regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4); 00261 00262 /* Clear the "in syscall" bit to prevent the kernel from 00263 messing with the PCs we just installed, if we happen to be 00264 within an interrupted system call that the kernel wants to 00265 restart. 00266 00267 Note that after we return from the dummy call, the PSR et al. 00268 registers will be automatically restored, and the kernel 00269 continues to restart the system call at this point. */ 00270 regcache_cooked_read_unsigned (regcache, SPARC32_PSR_REGNUM, &psr); 00271 psr &= ~PSR_SYSCALL; 00272 regcache_cooked_write_unsigned (regcache, SPARC32_PSR_REGNUM, psr); 00273 } 00274 00275 static LONGEST 00276 sparc32_linux_get_syscall_number (struct gdbarch *gdbarch, 00277 ptid_t ptid) 00278 { 00279 struct regcache *regcache = get_thread_regcache (ptid); 00280 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00281 /* The content of a register. */ 00282 gdb_byte buf[4]; 00283 /* The result. */ 00284 LONGEST ret; 00285 00286 /* Getting the system call number from the register. 00287 When dealing with the sparc architecture, this information 00288 is stored at the %g1 register. */ 00289 regcache_cooked_read (regcache, SPARC_G1_REGNUM, buf); 00290 00291 ret = extract_signed_integer (buf, 4, byte_order); 00292 00293 return ret; 00294 } 00295 00296 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in 00297 gdbarch.h. */ 00298 00299 static enum gdb_signal 00300 sparc32_linux_gdb_signal_from_target (struct gdbarch *gdbarch, 00301 int signal) 00302 { 00303 switch (signal) 00304 { 00305 case SPARC_LINUX_SIGEMT: 00306 return GDB_SIGNAL_EMT; 00307 00308 case SPARC_LINUX_SIGBUS: 00309 return GDB_SIGNAL_BUS; 00310 00311 case SPARC_LINUX_SIGSYS: 00312 return GDB_SIGNAL_SYS; 00313 00314 case SPARC_LINUX_SIGURG: 00315 return GDB_SIGNAL_URG; 00316 00317 case SPARC_LINUX_SIGSTOP: 00318 return GDB_SIGNAL_STOP; 00319 00320 case SPARC_LINUX_SIGTSTP: 00321 return GDB_SIGNAL_TSTP; 00322 00323 case SPARC_LINUX_SIGCONT: 00324 return GDB_SIGNAL_CONT; 00325 00326 case SPARC_LINUX_SIGCHLD: 00327 return GDB_SIGNAL_CHLD; 00328 00329 /* No way to differentiate between SIGIO and SIGPOLL. 00330 Therefore, we just handle the first one. */ 00331 case SPARC_LINUX_SIGIO: 00332 return GDB_SIGNAL_IO; 00333 00334 /* No way to differentiate between SIGLOST and SIGPWR. 00335 Therefore, we just handle the first one. */ 00336 case SPARC_LINUX_SIGLOST: 00337 return GDB_SIGNAL_LOST; 00338 00339 case SPARC_LINUX_SIGUSR1: 00340 return GDB_SIGNAL_USR1; 00341 00342 case SPARC_LINUX_SIGUSR2: 00343 return GDB_SIGNAL_USR2; 00344 } 00345 00346 return linux_gdb_signal_from_target (gdbarch, signal); 00347 } 00348 00349 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in 00350 gdbarch.h. */ 00351 00352 static int 00353 sparc32_linux_gdb_signal_to_target (struct gdbarch *gdbarch, 00354 enum gdb_signal signal) 00355 { 00356 switch (signal) 00357 { 00358 case GDB_SIGNAL_EMT: 00359 return SPARC_LINUX_SIGEMT; 00360 00361 case GDB_SIGNAL_BUS: 00362 return SPARC_LINUX_SIGBUS; 00363 00364 case GDB_SIGNAL_SYS: 00365 return SPARC_LINUX_SIGSYS; 00366 00367 case GDB_SIGNAL_URG: 00368 return SPARC_LINUX_SIGURG; 00369 00370 case GDB_SIGNAL_STOP: 00371 return SPARC_LINUX_SIGSTOP; 00372 00373 case GDB_SIGNAL_TSTP: 00374 return SPARC_LINUX_SIGTSTP; 00375 00376 case GDB_SIGNAL_CONT: 00377 return SPARC_LINUX_SIGCONT; 00378 00379 case GDB_SIGNAL_CHLD: 00380 return SPARC_LINUX_SIGCHLD; 00381 00382 case GDB_SIGNAL_IO: 00383 return SPARC_LINUX_SIGIO; 00384 00385 case GDB_SIGNAL_POLL: 00386 return SPARC_LINUX_SIGPOLL; 00387 00388 case GDB_SIGNAL_LOST: 00389 return SPARC_LINUX_SIGLOST; 00390 00391 case GDB_SIGNAL_PWR: 00392 return SPARC_LINUX_SIGPWR; 00393 00394 case GDB_SIGNAL_USR1: 00395 return SPARC_LINUX_SIGUSR1; 00396 00397 case GDB_SIGNAL_USR2: 00398 return SPARC_LINUX_SIGUSR2; 00399 } 00400 00401 return linux_gdb_signal_to_target (gdbarch, signal); 00402 } 00403 00404 00405 00406 static void 00407 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 00408 { 00409 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00410 00411 linux_init_abi (info, gdbarch); 00412 00413 tdep->gregset = regset_alloc (gdbarch, sparc32_linux_supply_core_gregset, 00414 sparc32_linux_collect_core_gregset); 00415 tdep->sizeof_gregset = 152; 00416 00417 tdep->fpregset = regset_alloc (gdbarch, sparc32_linux_supply_core_fpregset, 00418 sparc32_linux_collect_core_fpregset); 00419 tdep->sizeof_fpregset = 396; 00420 00421 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe); 00422 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe); 00423 00424 /* GNU/Linux has SVR4-style shared libraries... */ 00425 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); 00426 set_solib_svr4_fetch_link_map_offsets 00427 (gdbarch, svr4_ilp32_fetch_link_map_offsets); 00428 00429 /* ...which means that we need some special handling when doing 00430 prologue analysis. */ 00431 tdep->plt_entry_size = 12; 00432 00433 /* Enable TLS support. */ 00434 set_gdbarch_fetch_tls_load_module_address (gdbarch, 00435 svr4_fetch_objfile_link_map); 00436 00437 /* Make sure we can single-step over signal return system calls. */ 00438 tdep->step_trap = sparc32_linux_step_trap; 00439 00440 /* Hook in the DWARF CFI frame unwinder. */ 00441 dwarf2_append_unwinders (gdbarch); 00442 00443 set_gdbarch_write_pc (gdbarch, sparc_linux_write_pc); 00444 00445 /* Functions for 'catch syscall'. */ 00446 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_SPARC32); 00447 set_gdbarch_get_syscall_number (gdbarch, 00448 sparc32_linux_get_syscall_number); 00449 00450 set_gdbarch_gdb_signal_from_target (gdbarch, 00451 sparc32_linux_gdb_signal_from_target); 00452 set_gdbarch_gdb_signal_to_target (gdbarch, 00453 sparc32_linux_gdb_signal_to_target); 00454 } 00455 00456 /* Provide a prototype to silence -Wmissing-prototypes. */ 00457 extern void _initialize_sparc_linux_tdep (void); 00458 00459 void 00460 _initialize_sparc_linux_tdep (void) 00461 { 00462 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX, 00463 sparc32_linux_init_abi); 00464 }