* corelow.c (core_pid_to_str): Default to using normal_pid_to_str
[deliverable/binutils-gdb.git] / gdb / mips-linux-tdep.c
CommitLineData
75c9abc6 1/* Target-dependent code for GNU/Linux on MIPS processors.
a094c6fb 2
4c38e0a4 3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
76a9d10f 4 Free Software Foundation, Inc.
2aa830e4
DJ
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
2aa830e4
DJ
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/>. */
2aa830e4
DJ
20
21#include "defs.h"
22#include "gdbcore.h"
23#include "target.h"
24#include "solib-svr4.h"
19ed69dd 25#include "osabi.h"
96f026fc 26#include "mips-tdep.h"
19ed69dd 27#include "gdb_string.h"
96f026fc 28#include "gdb_assert.h"
6de918a6 29#include "frame.h"
2fdf551c 30#include "regcache.h"
5792a79b
DJ
31#include "trad-frame.h"
32#include "tramp-frame.h"
e6bb342a 33#include "gdbtypes.h"
5ea03926 34#include "solib.h"
7d522c90
DJ
35#include "solib-svr4.h"
36#include "solist.h"
982e9687 37#include "symtab.h"
822b6570 38#include "target-descriptions.h"
d37eb719 39#include "mips-linux-tdep.h"
db5f024e 40#include "glibc-tdep.h"
a5ee0f0c 41#include "linux-tdep.h"
2aa830e4 42
7d522c90
DJ
43static struct target_so_ops mips_svr4_so_ops;
44
2aa830e4 45/* Figure out where the longjmp will land.
295093a4
MS
46 We expect the first arg to be a pointer to the jmp_buf structure
47 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
48 at. The pc is copied into PC. This routine returns 1 on
49 success. */
2aa830e4 50
19ed69dd
KB
51#define MIPS_LINUX_JB_ELEMENT_SIZE 4
52#define MIPS_LINUX_JB_PC 0
53
54static int
60ade65d 55mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
2aa830e4
DJ
56{
57 CORE_ADDR jb_addr;
2eb4d78b 58 struct gdbarch *gdbarch = get_frame_arch (frame);
e17a4113 59 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2eb4d78b 60 char buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
2aa830e4 61
60ade65d 62 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
2aa830e4 63
bf072999 64 if (target_read_memory (jb_addr
819844ad 65 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE,
2eb4d78b 66 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
2aa830e4
DJ
67 return 0;
68
819844ad 69 *pc = extract_unsigned_integer (buf,
e17a4113
UW
70 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
71 byte_order);
2aa830e4
DJ
72
73 return 1;
74}
75
4246e332 76/* Transform the bits comprising a 32-bit register to the right size
23a6d369
AC
77 for regcache_raw_supply(). This is needed when mips_isa_regsize()
78 is 8. */
96f026fc
KB
79
80static void
28f5035f 81supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
96f026fc 82{
e17a4113
UW
83 struct gdbarch *gdbarch = get_regcache_arch (regcache);
84 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
d37eb719 85 gdb_byte buf[MAX_REGISTER_SIZE];
e17a4113
UW
86 store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
87 extract_signed_integer (addr, 4, byte_order));
28f5035f 88 regcache_raw_supply (regcache, regnum, buf);
96f026fc
KB
89}
90
2aa830e4
DJ
91/* Unpack an elf_gregset_t into GDB's register cache. */
92
d37eb719 93void
28f5035f
UW
94mips_supply_gregset (struct regcache *regcache,
95 const mips_elf_gregset_t *gregsetp)
2aa830e4
DJ
96{
97 int regi;
28f5035f 98 const mips_elf_greg_t *regp = *gregsetp;
d9d9c31f 99 char zerobuf[MAX_REGISTER_SIZE];
2eb4d78b 100 struct gdbarch *gdbarch = get_regcache_arch (regcache);
bf072999 101
d9d9c31f 102 memset (zerobuf, 0, MAX_REGISTER_SIZE);
2aa830e4 103
822b6570 104 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
28f5035f 105 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
2aa830e4 106
2eb4d78b 107 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
108 supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
109
2eb4d78b
UW
110 supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
111 supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
56cea623 112
2eb4d78b 113 supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
28f5035f 114 regp + EF_CP0_EPC);
2eb4d78b 115 supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
28f5035f
UW
116 regp + EF_CP0_BADVADDR);
117 supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
2eb4d78b 118 supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
28f5035f 119 regp + EF_CP0_CAUSE);
2aa830e4
DJ
120
121 /* Fill inaccessible registers with zero. */
822b6570 122 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
28f5035f 123 regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf);
295093a4 124 for (regi = MIPS_FIRST_EMBED_REGNUM;
822b6570 125 regi <= MIPS_LAST_EMBED_REGNUM;
295093a4 126 regi++)
28f5035f 127 regcache_raw_supply (regcache, regi, zerobuf);
2aa830e4
DJ
128}
129
130/* Pack our registers (or one register) into an elf_gregset_t. */
131
d37eb719 132void
28f5035f
UW
133mips_fill_gregset (const struct regcache *regcache,
134 mips_elf_gregset_t *gregsetp, int regno)
2aa830e4 135{
2eb4d78b 136 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2aa830e4 137 int regaddr, regi;
d37eb719 138 mips_elf_greg_t *regp = *gregsetp;
96f026fc 139 void *dst;
2aa830e4
DJ
140
141 if (regno == -1)
142 {
d37eb719 143 memset (regp, 0, sizeof (mips_elf_gregset_t));
822b6570 144 for (regi = 1; regi < 32; regi++)
28f5035f 145 mips_fill_gregset (regcache, gregsetp, regi);
2eb4d78b
UW
146 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
147 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
148 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
149 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
28f5035f 150 mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
2eb4d78b 151 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
822b6570 152 mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
2aa830e4
DJ
153 return;
154 }
155
822b6570 156 if (regno > 0 && regno < 32)
2aa830e4 157 {
2aa830e4 158 dst = regp + regno + EF_REG0;
28f5035f 159 regcache_raw_collect (regcache, regno, dst);
2aa830e4
DJ
160 return;
161 }
162
2eb4d78b
UW
163 if (regno == mips_regnum (gdbarch)->lo)
164 regaddr = EF_LO;
165 else if (regno == mips_regnum (gdbarch)->hi)
56cea623 166 regaddr = EF_HI;
2eb4d78b 167 else if (regno == mips_regnum (gdbarch)->pc)
56cea623 168 regaddr = EF_CP0_EPC;
2eb4d78b 169 else if (regno == mips_regnum (gdbarch)->badvaddr)
56cea623 170 regaddr = EF_CP0_BADVADDR;
24e05951 171 else if (regno == MIPS_PS_REGNUM)
56cea623 172 regaddr = EF_CP0_STATUS;
2eb4d78b 173 else if (regno == mips_regnum (gdbarch)->cause)
56cea623 174 regaddr = EF_CP0_CAUSE;
2eb4d78b 175 else if (mips_linux_restart_reg_p (gdbarch)
822b6570
DJ
176 && regno == MIPS_RESTART_REGNUM)
177 regaddr = EF_REG0;
56cea623
AC
178 else
179 regaddr = -1;
2aa830e4
DJ
180
181 if (regaddr != -1)
182 {
2aa830e4 183 dst = regp + regaddr;
28f5035f 184 regcache_raw_collect (regcache, regno, dst);
2aa830e4
DJ
185 }
186}
187
188/* Likewise, unpack an elf_fpregset_t. */
189
d37eb719 190void
28f5035f
UW
191mips_supply_fpregset (struct regcache *regcache,
192 const mips_elf_fpregset_t *fpregsetp)
2aa830e4 193{
2eb4d78b 194 struct gdbarch *gdbarch = get_regcache_arch (regcache);
52f0bd74 195 int regi;
d9d9c31f 196 char zerobuf[MAX_REGISTER_SIZE];
bf072999 197
d9d9c31f 198 memset (zerobuf, 0, MAX_REGISTER_SIZE);
2aa830e4
DJ
199
200 for (regi = 0; regi < 32; regi++)
3e8c568d 201 regcache_raw_supply (regcache,
2eb4d78b 202 gdbarch_fp0_regnum (gdbarch) + regi,
3e8c568d 203 *fpregsetp + regi);
2aa830e4 204
28f5035f 205 regcache_raw_supply (regcache,
2eb4d78b 206 mips_regnum (gdbarch)->fp_control_status,
28f5035f 207 *fpregsetp + 32);
2aa830e4 208
295093a4 209 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
28f5035f 210 regcache_raw_supply (regcache,
2eb4d78b 211 mips_regnum (gdbarch)->fp_implementation_revision,
23a6d369 212 zerobuf);
2aa830e4
DJ
213}
214
215/* Likewise, pack one or all floating point registers into an
216 elf_fpregset_t. */
217
d37eb719 218void
28f5035f
UW
219mips_fill_fpregset (const struct regcache *regcache,
220 mips_elf_fpregset_t *fpregsetp, int regno)
2aa830e4 221{
2eb4d78b 222 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2aa830e4
DJ
223 char *from, *to;
224
2eb4d78b
UW
225 if ((regno >= gdbarch_fp0_regnum (gdbarch))
226 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
2aa830e4 227 {
2eb4d78b 228 to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
28f5035f 229 regcache_raw_collect (regcache, regno, to);
2aa830e4 230 }
2eb4d78b 231 else if (regno == mips_regnum (gdbarch)->fp_control_status)
2aa830e4 232 {
2aa830e4 233 to = (char *) (*fpregsetp + 32);
28f5035f 234 regcache_raw_collect (regcache, regno, to);
2aa830e4
DJ
235 }
236 else if (regno == -1)
237 {
238 int regi;
239
240 for (regi = 0; regi < 32; regi++)
3e8c568d 241 mips_fill_fpregset (regcache, fpregsetp,
2eb4d78b 242 gdbarch_fp0_regnum (gdbarch) + regi);
28f5035f 243 mips_fill_fpregset (regcache, fpregsetp,
2eb4d78b 244 mips_regnum (gdbarch)->fp_control_status);
2aa830e4
DJ
245 }
246}
247
96f026fc
KB
248/* Support for 64-bit ABIs. */
249
96f026fc 250/* Figure out where the longjmp will land.
295093a4
MS
251 We expect the first arg to be a pointer to the jmp_buf structure
252 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
253 at. The pc is copied into PC. This routine returns 1 on
254 success. */
96f026fc
KB
255
256/* Details about jmp_buf. */
257
258#define MIPS64_LINUX_JB_PC 0
259
260static int
60ade65d 261mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
96f026fc
KB
262{
263 CORE_ADDR jb_addr;
2eb4d78b 264 struct gdbarch *gdbarch = get_frame_arch (frame);
e17a4113 265 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2eb4d78b
UW
266 void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
267 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
96f026fc 268
60ade65d 269 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
96f026fc
KB
270
271 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
819844ad 272 buf,
2eb4d78b 273 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
96f026fc
KB
274 return 0;
275
819844ad 276 *pc = extract_unsigned_integer (buf,
e17a4113
UW
277 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
278 byte_order);
96f026fc
KB
279
280 return 1;
281}
282
d37eb719
DJ
283/* Register set support functions. These operate on standard 64-bit
284 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
285 target will still use the 64-bit format for PTRACE_GETREGS. */
286
287/* Supply a 64-bit register. */
96f026fc 288
63807e1d 289static void
28f5035f
UW
290supply_64bit_reg (struct regcache *regcache, int regnum,
291 const gdb_byte *buf)
d37eb719 292{
2eb4d78b
UW
293 struct gdbarch *gdbarch = get_regcache_arch (regcache);
294 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
295 && register_size (gdbarch, regnum) == 4)
28f5035f 296 regcache_raw_supply (regcache, regnum, buf + 4);
d37eb719 297 else
28f5035f 298 regcache_raw_supply (regcache, regnum, buf);
d37eb719
DJ
299}
300
301/* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
302
303void
28f5035f
UW
304mips64_supply_gregset (struct regcache *regcache,
305 const mips64_elf_gregset_t *gregsetp)
96f026fc
KB
306{
307 int regi;
28f5035f 308 const mips64_elf_greg_t *regp = *gregsetp;
d37eb719 309 gdb_byte zerobuf[MAX_REGISTER_SIZE];
2eb4d78b 310 struct gdbarch *gdbarch = get_regcache_arch (regcache);
96f026fc 311
d9d9c31f 312 memset (zerobuf, 0, MAX_REGISTER_SIZE);
96f026fc 313
822b6570 314 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
28f5035f
UW
315 supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
316 (const gdb_byte *)(regp + regi));
317
2eb4d78b 318 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
319 supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
320 (const gdb_byte *)(regp + MIPS64_EF_REG0));
321
2eb4d78b 322 supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
28f5035f 323 (const gdb_byte *) (regp + MIPS64_EF_LO));
2eb4d78b 324 supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
28f5035f
UW
325 (const gdb_byte *) (regp + MIPS64_EF_HI));
326
2eb4d78b 327 supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
28f5035f 328 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
2eb4d78b 329 supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
28f5035f
UW
330 (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
331 supply_64bit_reg (regcache, MIPS_PS_REGNUM,
332 (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
2eb4d78b 333 supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
28f5035f 334 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
96f026fc
KB
335
336 /* Fill inaccessible registers with zero. */
822b6570 337 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
28f5035f 338 regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf);
295093a4 339 for (regi = MIPS_FIRST_EMBED_REGNUM;
822b6570 340 regi <= MIPS_LAST_EMBED_REGNUM;
295093a4 341 regi++)
28f5035f 342 regcache_raw_supply (regcache, regi, zerobuf);
96f026fc
KB
343}
344
d37eb719 345/* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
96f026fc 346
d37eb719 347void
28f5035f
UW
348mips64_fill_gregset (const struct regcache *regcache,
349 mips64_elf_gregset_t *gregsetp, int regno)
96f026fc 350{
2eb4d78b 351 struct gdbarch *gdbarch = get_regcache_arch (regcache);
e17a4113 352 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
96f026fc
KB
353 int regaddr, regi;
354 mips64_elf_greg_t *regp = *gregsetp;
2ba93934 355 void *dst;
96f026fc
KB
356
357 if (regno == -1)
358 {
359 memset (regp, 0, sizeof (mips64_elf_gregset_t));
822b6570 360 for (regi = 1; regi < 32; regi++)
28f5035f 361 mips64_fill_gregset (regcache, gregsetp, regi);
2eb4d78b
UW
362 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
363 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
364 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
365 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
28f5035f 366 mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
2eb4d78b 367 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
822b6570 368 mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
96f026fc
KB
369 return;
370 }
371
822b6570 372 if (regno > 0 && regno < 32)
d37eb719 373 regaddr = regno + MIPS64_EF_REG0;
2eb4d78b 374 else if (regno == mips_regnum (gdbarch)->lo)
56cea623 375 regaddr = MIPS64_EF_LO;
2eb4d78b 376 else if (regno == mips_regnum (gdbarch)->hi)
56cea623 377 regaddr = MIPS64_EF_HI;
2eb4d78b 378 else if (regno == mips_regnum (gdbarch)->pc)
56cea623 379 regaddr = MIPS64_EF_CP0_EPC;
2eb4d78b 380 else if (regno == mips_regnum (gdbarch)->badvaddr)
56cea623 381 regaddr = MIPS64_EF_CP0_BADVADDR;
24e05951 382 else if (regno == MIPS_PS_REGNUM)
56cea623 383 regaddr = MIPS64_EF_CP0_STATUS;
2eb4d78b 384 else if (regno == mips_regnum (gdbarch)->cause)
56cea623 385 regaddr = MIPS64_EF_CP0_CAUSE;
2eb4d78b 386 else if (mips_linux_restart_reg_p (gdbarch)
822b6570
DJ
387 && regno == MIPS_RESTART_REGNUM)
388 regaddr = MIPS64_EF_REG0;
56cea623
AC
389 else
390 regaddr = -1;
96f026fc
KB
391
392 if (regaddr != -1)
393 {
d37eb719
DJ
394 gdb_byte buf[MAX_REGISTER_SIZE];
395 LONGEST val;
396
28f5035f 397 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
398 val = extract_signed_integer (buf, register_size (gdbarch, regno),
399 byte_order);
96f026fc 400 dst = regp + regaddr;
e17a4113 401 store_signed_integer (dst, 8, byte_order, val);
96f026fc
KB
402 }
403}
404
405/* Likewise, unpack an elf_fpregset_t. */
406
d37eb719 407void
28f5035f
UW
408mips64_supply_fpregset (struct regcache *regcache,
409 const mips64_elf_fpregset_t *fpregsetp)
96f026fc 410{
2eb4d78b 411 struct gdbarch *gdbarch = get_regcache_arch (regcache);
52f0bd74 412 int regi;
96f026fc 413
d37eb719
DJ
414 /* See mips_linux_o32_sigframe_init for a description of the
415 peculiar FP register layout. */
2eb4d78b 416 if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
d37eb719
DJ
417 for (regi = 0; regi < 32; regi++)
418 {
28f5035f 419 const gdb_byte *reg_ptr = (const gdb_byte *)(*fpregsetp + (regi & ~1));
2eb4d78b 420 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
d37eb719 421 reg_ptr += 4;
3e8c568d 422 regcache_raw_supply (regcache,
2eb4d78b 423 gdbarch_fp0_regnum (gdbarch) + regi,
3e8c568d 424 reg_ptr);
d37eb719
DJ
425 }
426 else
427 for (regi = 0; regi < 32; regi++)
3e8c568d 428 regcache_raw_supply (regcache,
2eb4d78b 429 gdbarch_fp0_regnum (gdbarch) + regi,
28f5035f 430 (const char *)(*fpregsetp + regi));
d37eb719 431
2eb4d78b 432 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
28f5035f 433 (const gdb_byte *)(*fpregsetp + 32));
d37eb719
DJ
434
435 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
436 include it - but the result of PTRACE_GETFPREGS does. The best we
437 can do is to assume that its value is present. */
28f5035f 438 supply_32bit_reg (regcache,
2eb4d78b 439 mips_regnum (gdbarch)->fp_implementation_revision,
28f5035f 440 (const gdb_byte *)(*fpregsetp + 32) + 4);
96f026fc
KB
441}
442
443/* Likewise, pack one or all floating point registers into an
444 elf_fpregset_t. */
445
d37eb719 446void
28f5035f
UW
447mips64_fill_fpregset (const struct regcache *regcache,
448 mips64_elf_fpregset_t *fpregsetp, int regno)
96f026fc 449{
2eb4d78b 450 struct gdbarch *gdbarch = get_regcache_arch (regcache);
e17a4113 451 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
d37eb719 452 gdb_byte *to;
96f026fc 453
2eb4d78b
UW
454 if ((regno >= gdbarch_fp0_regnum (gdbarch))
455 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
96f026fc 456 {
d37eb719
DJ
457 /* See mips_linux_o32_sigframe_init for a description of the
458 peculiar FP register layout. */
2eb4d78b 459 if (register_size (gdbarch, regno) == 4)
d37eb719 460 {
2eb4d78b 461 int regi = regno - gdbarch_fp0_regnum (gdbarch);
d37eb719
DJ
462
463 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
2eb4d78b 464 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
d37eb719 465 to += 4;
28f5035f 466 regcache_raw_collect (regcache, regno, to);
d37eb719
DJ
467 }
468 else
469 {
2eb4d78b 470 to = (gdb_byte *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
28f5035f 471 regcache_raw_collect (regcache, regno, to);
d37eb719 472 }
96f026fc 473 }
2eb4d78b 474 else if (regno == mips_regnum (gdbarch)->fp_control_status)
96f026fc 475 {
d37eb719
DJ
476 gdb_byte buf[MAX_REGISTER_SIZE];
477 LONGEST val;
478
28f5035f 479 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
480 val = extract_signed_integer (buf, register_size (gdbarch, regno),
481 byte_order);
d37eb719 482 to = (gdb_byte *) (*fpregsetp + 32);
e17a4113 483 store_signed_integer (to, 4, byte_order, val);
d37eb719 484 }
2eb4d78b 485 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
d37eb719
DJ
486 {
487 gdb_byte buf[MAX_REGISTER_SIZE];
488 LONGEST val;
489
28f5035f 490 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
491 val = extract_signed_integer (buf, register_size (gdbarch, regno),
492 byte_order);
d37eb719 493 to = (gdb_byte *) (*fpregsetp + 32) + 4;
e17a4113 494 store_signed_integer (to, 4, byte_order, val);
96f026fc
KB
495 }
496 else if (regno == -1)
497 {
498 int regi;
499
500 for (regi = 0; regi < 32; regi++)
3e8c568d 501 mips64_fill_fpregset (regcache, fpregsetp,
2eb4d78b 502 gdbarch_fp0_regnum (gdbarch) + regi);
28f5035f 503 mips64_fill_fpregset (regcache, fpregsetp,
2eb4d78b 504 mips_regnum (gdbarch)->fp_control_status);
28f5035f 505 mips64_fill_fpregset (regcache, fpregsetp,
2eb4d78b
UW
506 (mips_regnum (gdbarch)
507 ->fp_implementation_revision));
96f026fc
KB
508 }
509}
510
511
2aa830e4
DJ
512/* Use a local version of this function to get the correct types for
513 regsets, until multi-arch core support is ready. */
514
515static void
9eefc95f
UW
516fetch_core_registers (struct regcache *regcache,
517 char *core_reg_sect, unsigned core_reg_size,
2aa830e4
DJ
518 int which, CORE_ADDR reg_addr)
519{
d37eb719
DJ
520 mips_elf_gregset_t gregset;
521 mips_elf_fpregset_t fpregset;
96f026fc
KB
522 mips64_elf_gregset_t gregset64;
523 mips64_elf_fpregset_t fpregset64;
2aa830e4
DJ
524
525 if (which == 0)
526 {
96f026fc 527 if (core_reg_size == sizeof (gregset))
2aa830e4 528 {
96f026fc 529 memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset));
9eefc95f 530 mips_supply_gregset (regcache,
28f5035f 531 (const mips_elf_gregset_t *) &gregset);
96f026fc
KB
532 }
533 else if (core_reg_size == sizeof (gregset64))
534 {
535 memcpy ((char *) &gregset64, core_reg_sect, sizeof (gregset64));
9eefc95f 536 mips64_supply_gregset (regcache,
28f5035f 537 (const mips64_elf_gregset_t *) &gregset64);
2aa830e4
DJ
538 }
539 else
540 {
8a3fe4f8 541 warning (_("wrong size gregset struct in core file"));
2aa830e4
DJ
542 }
543 }
544 else if (which == 2)
545 {
96f026fc 546 if (core_reg_size == sizeof (fpregset))
2aa830e4 547 {
96f026fc 548 memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset));
9eefc95f 549 mips_supply_fpregset (regcache,
28f5035f 550 (const mips_elf_fpregset_t *) &fpregset);
96f026fc
KB
551 }
552 else if (core_reg_size == sizeof (fpregset64))
553 {
295093a4
MS
554 memcpy ((char *) &fpregset64, core_reg_sect,
555 sizeof (fpregset64));
9eefc95f 556 mips64_supply_fpregset (regcache,
28f5035f 557 (const mips64_elf_fpregset_t *) &fpregset64);
2aa830e4
DJ
558 }
559 else
560 {
8a3fe4f8 561 warning (_("wrong size fpregset struct in core file"));
2aa830e4
DJ
562 }
563 }
564}
565
566/* Register that we are able to handle ELF file formats using standard
567 procfs "regset" structures. */
568
569static struct core_fns regset_core_fns =
570{
571 bfd_target_elf_flavour, /* core_flavour */
572 default_check_format, /* check_format */
573 default_core_sniffer, /* core_sniffer */
574 fetch_core_registers, /* core_read_registers */
575 NULL /* next */
576};
577
4eb0ad19
DJ
578static const struct target_desc *
579mips_linux_core_read_description (struct gdbarch *gdbarch,
580 struct target_ops *target,
581 bfd *abfd)
582{
583 asection *section = bfd_get_section_by_name (abfd, ".reg");
584 if (! section)
585 return NULL;
586
587 switch (bfd_section_size (abfd, section))
588 {
589 case sizeof (mips_elf_gregset_t):
590 return mips_tdesc_gp32;
591
592 case sizeof (mips64_elf_gregset_t):
593 return mips_tdesc_gp64;
594
595 default:
596 return NULL;
597 }
598}
599
96f026fc 600
295093a4
MS
601/* Check the code at PC for a dynamic linker lazy resolution stub.
602 Because they aren't in the .plt section, we pattern-match on the
603 code generated by GNU ld. They look like this:
6de918a6
DJ
604
605 lw t9,0x8010(gp)
606 addu t7,ra
607 jalr t9,ra
608 addiu t8,zero,INDEX
609
295093a4
MS
610 (with the appropriate doubleword instructions for N64). Also
611 return the dynamic symbol index used in the last instruction. */
6de918a6
DJ
612
613static int
614mips_linux_in_dynsym_stub (CORE_ADDR pc, char *name)
615{
616 unsigned char buf[28], *p;
617 ULONGEST insn, insn1;
1cf3db46 618 int n64 = (mips_abi (target_gdbarch) == MIPS_ABI_N64);
e17a4113 619 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
6de918a6
DJ
620
621 read_memory (pc - 12, buf, 28);
622
623 if (n64)
624 {
625 /* ld t9,0x8010(gp) */
626 insn1 = 0xdf998010;
627 }
628 else
629 {
630 /* lw t9,0x8010(gp) */
631 insn1 = 0x8f998010;
632 }
633
634 p = buf + 12;
635 while (p >= buf)
636 {
e17a4113 637 insn = extract_unsigned_integer (p, 4, byte_order);
6de918a6
DJ
638 if (insn == insn1)
639 break;
640 p -= 4;
641 }
642 if (p < buf)
643 return 0;
644
e17a4113 645 insn = extract_unsigned_integer (p + 4, 4, byte_order);
6de918a6
DJ
646 if (n64)
647 {
648 /* daddu t7,ra */
649 if (insn != 0x03e0782d)
650 return 0;
651 }
652 else
653 {
654 /* addu t7,ra */
655 if (insn != 0x03e07821)
656 return 0;
657 }
295093a4 658
e17a4113 659 insn = extract_unsigned_integer (p + 8, 4, byte_order);
6de918a6
DJ
660 /* jalr t9,ra */
661 if (insn != 0x0320f809)
662 return 0;
663
e17a4113 664 insn = extract_unsigned_integer (p + 12, 4, byte_order);
6de918a6
DJ
665 if (n64)
666 {
667 /* daddiu t8,zero,0 */
668 if ((insn & 0xffff0000) != 0x64180000)
669 return 0;
670 }
671 else
672 {
673 /* addiu t8,zero,0 */
674 if ((insn & 0xffff0000) != 0x24180000)
675 return 0;
676 }
677
678 return (insn & 0xffff);
679}
680
295093a4 681/* Return non-zero iff PC belongs to the dynamic linker resolution
db5f024e 682 code, a PLT entry, or a lazy binding stub. */
6de918a6 683
7d522c90 684static int
6de918a6
DJ
685mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
686{
295093a4 687 /* Check whether PC is in the dynamic linker. This also checks
db5f024e 688 whether it is in the .plt section, used by non-PIC executables. */
7d522c90 689 if (svr4_in_dynsym_resolve_code (pc))
6de918a6
DJ
690 return 1;
691
295093a4
MS
692 /* Pattern match for the stub. It would be nice if there were a
693 more efficient way to avoid this check. */
6de918a6
DJ
694 if (mips_linux_in_dynsym_stub (pc, NULL))
695 return 1;
696
697 return 0;
698}
699
700/* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
701 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
702 implementation of this triggers at "fixup" from the same objfile as
c4c5b7ba 703 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
db5f024e
DJ
704 "__dl_runtime_resolve" directly. An unresolved lazy binding
705 stub will point to _dl_runtime_resolve, which will first call
c4c5b7ba
AC
706 __dl_runtime_resolve, and then pass control to the resolved
707 function. */
6de918a6
DJ
708
709static CORE_ADDR
710mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
711{
712 struct minimal_symbol *resolver;
713
714 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
715
716 if (resolver && SYMBOL_VALUE_ADDRESS (resolver) == pc)
c7ce8faa 717 return frame_unwind_caller_pc (get_current_frame ());
6de918a6 718
db5f024e 719 return glibc_skip_solib_resolver (gdbarch, pc);
295093a4 720}
6de918a6 721
5792a79b
DJ
722/* Signal trampoline support. There are four supported layouts for a
723 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
724 n64 rt_sigframe. We handle them all independently; not the most
725 efficient way, but simplest. First, declare all the unwinders. */
726
727static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
b8a22b94 728 struct frame_info *this_frame,
5792a79b
DJ
729 struct trad_frame_cache *this_cache,
730 CORE_ADDR func);
731
732static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
b8a22b94 733 struct frame_info *this_frame,
5792a79b
DJ
734 struct trad_frame_cache *this_cache,
735 CORE_ADDR func);
736
737#define MIPS_NR_LINUX 4000
738#define MIPS_NR_N64_LINUX 5000
739#define MIPS_NR_N32_LINUX 6000
740
741#define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
742#define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
743#define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
744#define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
745
746#define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
747#define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
748#define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
749#define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
750#define MIPS_INST_SYSCALL 0x0000000c
751
2cd8546d
AC
752static const struct tramp_frame mips_linux_o32_sigframe = {
753 SIGTRAMP_FRAME,
5792a79b 754 4,
2cd8546d
AC
755 {
756 { MIPS_INST_LI_V0_SIGRETURN, -1 },
757 { MIPS_INST_SYSCALL, -1 },
758 { TRAMP_SENTINEL_INSN, -1 }
759 },
5792a79b
DJ
760 mips_linux_o32_sigframe_init
761};
762
2cd8546d
AC
763static const struct tramp_frame mips_linux_o32_rt_sigframe = {
764 SIGTRAMP_FRAME,
5792a79b 765 4,
2cd8546d
AC
766 {
767 { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
768 { MIPS_INST_SYSCALL, -1 },
769 { TRAMP_SENTINEL_INSN, -1 } },
5792a79b
DJ
770 mips_linux_o32_sigframe_init
771};
772
2cd8546d
AC
773static const struct tramp_frame mips_linux_n32_rt_sigframe = {
774 SIGTRAMP_FRAME,
5792a79b 775 4,
2cd8546d
AC
776 {
777 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
778 { MIPS_INST_SYSCALL, -1 },
779 { TRAMP_SENTINEL_INSN, -1 }
780 },
5792a79b
DJ
781 mips_linux_n32n64_sigframe_init
782};
783
2cd8546d
AC
784static const struct tramp_frame mips_linux_n64_rt_sigframe = {
785 SIGTRAMP_FRAME,
5792a79b 786 4,
fcbd8a5c
TS
787 {
788 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
789 { MIPS_INST_SYSCALL, -1 },
790 { TRAMP_SENTINEL_INSN, -1 }
791 },
5792a79b
DJ
792 mips_linux_n32n64_sigframe_init
793};
794
795/* *INDENT-OFF* */
796/* The unwinder for o32 signal frames. The legacy structures look
797 like this:
798
799 struct sigframe {
800 u32 sf_ass[4]; [argument save space for o32]
eb195664 801 u32 sf_code[2]; [signal trampoline or fill]
5792a79b
DJ
802 struct sigcontext sf_sc;
803 sigset_t sf_mask;
804 };
805
806 struct sigcontext {
807 unsigned int sc_regmask; [Unused]
808 unsigned int sc_status;
809 unsigned long long sc_pc;
810 unsigned long long sc_regs[32];
811 unsigned long long sc_fpregs[32];
812 unsigned int sc_ownedfp;
813 unsigned int sc_fpc_csr;
814 unsigned int sc_fpc_eir; [Unused]
815 unsigned int sc_used_math;
816 unsigned int sc_ssflags; [Unused]
817 [Alignment hole of four bytes]
818 unsigned long long sc_mdhi;
819 unsigned long long sc_mdlo;
820
821 unsigned int sc_cause; [Unused]
822 unsigned int sc_badvaddr; [Unused]
823
824 unsigned long sc_sigset[4]; [kernel's sigset_t]
825 };
826
827 The RT signal frames look like this:
828
829 struct rt_sigframe {
830 u32 rs_ass[4]; [argument save space for o32]
eb195664 831 u32 rs_code[2] [signal trampoline or fill]
5792a79b
DJ
832 struct siginfo rs_info;
833 struct ucontext rs_uc;
834 };
835
836 struct ucontext {
837 unsigned long uc_flags;
838 struct ucontext *uc_link;
839 stack_t uc_stack;
840 [Alignment hole of four bytes]
841 struct sigcontext uc_mcontext;
842 sigset_t uc_sigmask;
843 }; */
844/* *INDENT-ON* */
845
5792a79b
DJ
846#define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
847
848#define RTSIGFRAME_SIGINFO_SIZE 128
849#define STACK_T_SIZE (3 * 4)
850#define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
851#define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
852 + RTSIGFRAME_SIGINFO_SIZE \
853 + UCONTEXT_SIGCONTEXT_OFFSET)
854
855#define SIGCONTEXT_PC (1 * 8)
856#define SIGCONTEXT_REGS (2 * 8)
857#define SIGCONTEXT_FPREGS (34 * 8)
858#define SIGCONTEXT_FPCSR (66 * 8 + 4)
859#define SIGCONTEXT_HI (69 * 8)
860#define SIGCONTEXT_LO (70 * 8)
861#define SIGCONTEXT_CAUSE (71 * 8 + 0)
862#define SIGCONTEXT_BADVADDR (71 * 8 + 4)
863
864#define SIGCONTEXT_REG_SIZE 8
865
866static void
867mips_linux_o32_sigframe_init (const struct tramp_frame *self,
b8a22b94 868 struct frame_info *this_frame,
5792a79b
DJ
869 struct trad_frame_cache *this_cache,
870 CORE_ADDR func)
871{
b8a22b94 872 struct gdbarch *gdbarch = get_frame_arch (this_frame);
5792a79b 873 int ireg, reg_position;
eb195664
DD
874 CORE_ADDR frame_sp = get_frame_sp (this_frame);
875 CORE_ADDR sigcontext_base;
2eb4d78b 876 const struct mips_regnum *regs = mips_regnum (gdbarch);
37c4d197 877 CORE_ADDR regs_base;
5792a79b
DJ
878
879 if (self == &mips_linux_o32_sigframe)
eb195664 880 sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
5792a79b 881 else
eb195664 882 sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
295093a4
MS
883
884 /* I'm not proud of this hack. Eventually we will have the
885 infrastructure to indicate the size of saved registers on a
886 per-frame basis, but right now we don't; the kernel saves eight
37c4d197
DJ
887 bytes but we only want four. Use regs_base to access any
888 64-bit fields. */
2eb4d78b 889 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
37c4d197
DJ
890 regs_base = sigcontext_base + 4;
891 else
892 regs_base = sigcontext_base;
5792a79b 893
2eb4d78b 894 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
895 trad_frame_set_reg_addr (this_cache,
896 (MIPS_RESTART_REGNUM
2eb4d78b 897 + gdbarch_num_regs (gdbarch)),
822b6570 898 regs_base + SIGCONTEXT_REGS);
5792a79b
DJ
899
900 for (ireg = 1; ireg < 32; ireg++)
295093a4 901 trad_frame_set_reg_addr (this_cache,
f57d151a 902 ireg + MIPS_ZERO_REGNUM
2eb4d78b 903 + gdbarch_num_regs (gdbarch),
37c4d197 904 regs_base + SIGCONTEXT_REGS
5792a79b
DJ
905 + ireg * SIGCONTEXT_REG_SIZE);
906
37c4d197
DJ
907 /* The way that floating point registers are saved, unfortunately,
908 depends on the architecture the kernel is built for. For the r3000 and
909 tx39, four bytes of each register are at the beginning of each of the
910 32 eight byte slots. For everything else, the registers are saved
911 using double precision; only the even-numbered slots are initialized,
912 and the high bits are the odd-numbered register. Assume the latter
913 layout, since we can't tell, and it's much more common. Which bits are
914 the "high" bits depends on endianness. */
5792a79b 915 for (ireg = 0; ireg < 32; ireg++)
2eb4d78b 916 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
f57d151a
UW
917 trad_frame_set_reg_addr (this_cache,
918 ireg + regs->fp0 +
2eb4d78b 919 gdbarch_num_regs (gdbarch),
37c4d197
DJ
920 sigcontext_base + SIGCONTEXT_FPREGS + 4
921 + (ireg & ~1) * SIGCONTEXT_REG_SIZE);
922 else
f57d151a
UW
923 trad_frame_set_reg_addr (this_cache,
924 ireg + regs->fp0
2eb4d78b 925 + gdbarch_num_regs (gdbarch),
37c4d197
DJ
926 sigcontext_base + SIGCONTEXT_FPREGS
927 + (ireg & ~1) * SIGCONTEXT_REG_SIZE);
5792a79b 928
f57d151a 929 trad_frame_set_reg_addr (this_cache,
2eb4d78b 930 regs->pc + gdbarch_num_regs (gdbarch),
37c4d197 931 regs_base + SIGCONTEXT_PC);
5792a79b 932
295093a4 933 trad_frame_set_reg_addr (this_cache,
f57d151a 934 regs->fp_control_status
2eb4d78b 935 + gdbarch_num_regs (gdbarch),
5792a79b 936 sigcontext_base + SIGCONTEXT_FPCSR);
f57d151a 937 trad_frame_set_reg_addr (this_cache,
2eb4d78b 938 regs->hi + gdbarch_num_regs (gdbarch),
37c4d197 939 regs_base + SIGCONTEXT_HI);
f57d151a 940 trad_frame_set_reg_addr (this_cache,
2eb4d78b 941 regs->lo + gdbarch_num_regs (gdbarch),
37c4d197 942 regs_base + SIGCONTEXT_LO);
f57d151a 943 trad_frame_set_reg_addr (this_cache,
2eb4d78b 944 regs->cause + gdbarch_num_regs (gdbarch),
5792a79b 945 sigcontext_base + SIGCONTEXT_CAUSE);
f57d151a 946 trad_frame_set_reg_addr (this_cache,
2eb4d78b 947 regs->badvaddr + gdbarch_num_regs (gdbarch),
5792a79b
DJ
948 sigcontext_base + SIGCONTEXT_BADVADDR);
949
950 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
eb195664 951 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
5792a79b
DJ
952}
953
954/* *INDENT-OFF* */
955/* For N32/N64 things look different. There is no non-rt signal frame.
956
957 struct rt_sigframe_n32 {
958 u32 rs_ass[4]; [ argument save space for o32 ]
eb195664 959 u32 rs_code[2]; [ signal trampoline or fill ]
5792a79b
DJ
960 struct siginfo rs_info;
961 struct ucontextn32 rs_uc;
962 };
963
964 struct ucontextn32 {
965 u32 uc_flags;
966 s32 uc_link;
967 stack32_t uc_stack;
968 struct sigcontext uc_mcontext;
969 sigset_t uc_sigmask; [ mask last for extensibility ]
970 };
295093a4 971
e741f4d4 972 struct rt_sigframe {
5792a79b
DJ
973 u32 rs_ass[4]; [ argument save space for o32 ]
974 u32 rs_code[2]; [ signal trampoline ]
975 struct siginfo rs_info;
976 struct ucontext rs_uc;
977 };
978
979 struct ucontext {
980 unsigned long uc_flags;
981 struct ucontext *uc_link;
982 stack_t uc_stack;
983 struct sigcontext uc_mcontext;
984 sigset_t uc_sigmask; [ mask last for extensibility ]
985 };
986
987 And the sigcontext is different (this is for both n32 and n64):
988
989 struct sigcontext {
990 unsigned long long sc_regs[32];
991 unsigned long long sc_fpregs[32];
992 unsigned long long sc_mdhi;
e741f4d4
DJ
993 unsigned long long sc_hi1;
994 unsigned long long sc_hi2;
995 unsigned long long sc_hi3;
5792a79b 996 unsigned long long sc_mdlo;
e741f4d4
DJ
997 unsigned long long sc_lo1;
998 unsigned long long sc_lo2;
999 unsigned long long sc_lo3;
5792a79b 1000 unsigned long long sc_pc;
5792a79b 1001 unsigned int sc_fpc_csr;
5792a79b 1002 unsigned int sc_used_math;
e741f4d4
DJ
1003 unsigned int sc_dsp;
1004 unsigned int sc_reserved;
1005 };
1006
1007 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1008 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1009 included too. */
5792a79b
DJ
1010/* *INDENT-ON* */
1011
1012#define N32_STACK_T_SIZE STACK_T_SIZE
1013#define N64_STACK_T_SIZE (2 * 8 + 4)
1014#define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1015#define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1016#define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1017 + RTSIGFRAME_SIGINFO_SIZE \
1018 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1019#define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1020 + RTSIGFRAME_SIGINFO_SIZE \
1021 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1022
1023#define N64_SIGCONTEXT_REGS (0 * 8)
1024#define N64_SIGCONTEXT_FPREGS (32 * 8)
1025#define N64_SIGCONTEXT_HI (64 * 8)
e741f4d4
DJ
1026#define N64_SIGCONTEXT_LO (68 * 8)
1027#define N64_SIGCONTEXT_PC (72 * 8)
1028#define N64_SIGCONTEXT_FPCSR (73 * 8)
5792a79b
DJ
1029
1030#define N64_SIGCONTEXT_REG_SIZE 8
295093a4 1031
5792a79b
DJ
1032static void
1033mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
b8a22b94 1034 struct frame_info *this_frame,
5792a79b
DJ
1035 struct trad_frame_cache *this_cache,
1036 CORE_ADDR func)
1037{
b8a22b94 1038 struct gdbarch *gdbarch = get_frame_arch (this_frame);
5792a79b 1039 int ireg, reg_position;
eb195664
DD
1040 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1041 CORE_ADDR sigcontext_base;
2eb4d78b 1042 const struct mips_regnum *regs = mips_regnum (gdbarch);
5792a79b
DJ
1043
1044 if (self == &mips_linux_n32_rt_sigframe)
eb195664 1045 sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
5792a79b 1046 else
eb195664 1047 sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
295093a4 1048
2eb4d78b 1049 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
1050 trad_frame_set_reg_addr (this_cache,
1051 (MIPS_RESTART_REGNUM
2eb4d78b 1052 + gdbarch_num_regs (gdbarch)),
822b6570 1053 sigcontext_base + N64_SIGCONTEXT_REGS);
5792a79b
DJ
1054
1055 for (ireg = 1; ireg < 32; ireg++)
295093a4 1056 trad_frame_set_reg_addr (this_cache,
f57d151a 1057 ireg + MIPS_ZERO_REGNUM
2eb4d78b 1058 + gdbarch_num_regs (gdbarch),
5792a79b
DJ
1059 sigcontext_base + N64_SIGCONTEXT_REGS
1060 + ireg * N64_SIGCONTEXT_REG_SIZE);
1061
1062 for (ireg = 0; ireg < 32; ireg++)
f57d151a
UW
1063 trad_frame_set_reg_addr (this_cache,
1064 ireg + regs->fp0
2eb4d78b 1065 + gdbarch_num_regs (gdbarch),
5792a79b
DJ
1066 sigcontext_base + N64_SIGCONTEXT_FPREGS
1067 + ireg * N64_SIGCONTEXT_REG_SIZE);
1068
f57d151a 1069 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1070 regs->pc + gdbarch_num_regs (gdbarch),
5792a79b
DJ
1071 sigcontext_base + N64_SIGCONTEXT_PC);
1072
295093a4 1073 trad_frame_set_reg_addr (this_cache,
f57d151a 1074 regs->fp_control_status
2eb4d78b 1075 + gdbarch_num_regs (gdbarch),
5792a79b 1076 sigcontext_base + N64_SIGCONTEXT_FPCSR);
f57d151a 1077 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1078 regs->hi + gdbarch_num_regs (gdbarch),
5792a79b 1079 sigcontext_base + N64_SIGCONTEXT_HI);
f57d151a 1080 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1081 regs->lo + gdbarch_num_regs (gdbarch),
5792a79b 1082 sigcontext_base + N64_SIGCONTEXT_LO);
5792a79b
DJ
1083
1084 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
eb195664 1085 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
5792a79b
DJ
1086}
1087
822b6570 1088static void
61a1198a 1089mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
822b6570 1090{
2eb4d78b
UW
1091 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1092 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
822b6570
DJ
1093
1094 /* Clear the syscall restart flag. */
2eb4d78b 1095 if (mips_linux_restart_reg_p (gdbarch))
61a1198a 1096 regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
822b6570
DJ
1097}
1098
1099/* Return 1 if MIPS_RESTART_REGNUM is usable. */
1100
1101int
1102mips_linux_restart_reg_p (struct gdbarch *gdbarch)
1103{
1104 /* If we do not have a target description with registers, then
1105 MIPS_RESTART_REGNUM will not be included in the register set. */
1106 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1107 return 0;
1108
1109 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1110 either be GPR-sized or missing. */
1111 return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
1112}
9f62d0e2 1113
e38d4e1a
DJ
1114/* When FRAME is at a syscall instruction, return the PC of the next
1115 instruction to be executed. */
1116
63807e1d 1117static CORE_ADDR
e38d4e1a
DJ
1118mips_linux_syscall_next_pc (struct frame_info *frame)
1119{
1120 CORE_ADDR pc = get_frame_pc (frame);
1121 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1122
1123 /* If we are about to make a sigreturn syscall, use the unwinder to
1124 decode the signal frame. */
1125 if (v0 == MIPS_NR_sigreturn
1126 || v0 == MIPS_NR_rt_sigreturn
1127 || v0 == MIPS_NR_N64_rt_sigreturn
1128 || v0 == MIPS_NR_N32_rt_sigreturn)
c7ce8faa 1129 return frame_unwind_caller_pc (get_current_frame ());
e38d4e1a
DJ
1130
1131 return pc + 4;
1132}
1133
5792a79b
DJ
1134/* Initialize one of the GNU/Linux OS ABIs. */
1135
19ed69dd 1136static void
295093a4
MS
1137mips_linux_init_abi (struct gdbarch_info info,
1138 struct gdbarch *gdbarch)
19ed69dd 1139{
96f026fc
KB
1140 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1141 enum mips_abi abi = mips_abi (gdbarch);
822b6570 1142 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
96f026fc 1143
a5ee0f0c
PA
1144 linux_init_abi (info, gdbarch);
1145
96f026fc
KB
1146 switch (abi)
1147 {
1148 case MIPS_ABI_O32:
1149 set_gdbarch_get_longjmp_target (gdbarch,
1150 mips_linux_get_longjmp_target);
1151 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1152 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
fb2be677
AC
1153 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
1154 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
96f026fc
KB
1155 break;
1156 case MIPS_ABI_N32:
1157 set_gdbarch_get_longjmp_target (gdbarch,
1158 mips_linux_get_longjmp_target);
1159 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1160 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
d05f6826
DJ
1161 set_gdbarch_long_double_bit (gdbarch, 128);
1162 /* These floatformats should probably be renamed. MIPS uses
1163 the same 128-bit IEEE floating point format that IA-64 uses,
1164 except that the quiet/signalling NaN bit is reversed (GDB
1165 does not distinguish between quiet and signalling NaNs). */
8da61cc4 1166 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
fb2be677 1167 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
96f026fc
KB
1168 break;
1169 case MIPS_ABI_N64:
1170 set_gdbarch_get_longjmp_target (gdbarch,
1171 mips64_linux_get_longjmp_target);
1172 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1173 (gdbarch, svr4_lp64_fetch_link_map_offsets);
d05f6826
DJ
1174 set_gdbarch_long_double_bit (gdbarch, 128);
1175 /* These floatformats should probably be renamed. MIPS uses
1176 the same 128-bit IEEE floating point format that IA-64 uses,
1177 except that the quiet/signalling NaN bit is reversed (GDB
1178 does not distinguish between quiet and signalling NaNs). */
8da61cc4 1179 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
fb2be677 1180 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
96f026fc
KB
1181 break;
1182 default:
96f026fc
KB
1183 break;
1184 }
6de918a6
DJ
1185
1186 set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
1187
0d0266c6 1188 set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
b2756930
KB
1189
1190 /* Enable TLS support. */
1191 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1192 svr4_fetch_objfile_link_map);
7d522c90
DJ
1193
1194 /* Initialize this lazily, to avoid an initialization order
1195 dependency on solib-svr4.c's _initialize routine. */
1196 if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
1197 {
1198 mips_svr4_so_ops = svr4_so_ops;
1199 mips_svr4_so_ops.in_dynsym_resolve_code
1200 = mips_linux_in_dynsym_resolve_code;
1201 }
1202 set_solib_ops (gdbarch, &mips_svr4_so_ops);
822b6570
DJ
1203
1204 set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
1205
4eb0ad19
DJ
1206 set_gdbarch_core_read_description (gdbarch,
1207 mips_linux_core_read_description);
1208
e38d4e1a
DJ
1209 tdep->syscall_next_pc = mips_linux_syscall_next_pc;
1210
822b6570
DJ
1211 if (tdesc_data)
1212 {
1213 const struct tdesc_feature *feature;
1214
1215 /* If we have target-described registers, then we can safely
1216 reserve a number for MIPS_RESTART_REGNUM (whether it is
1217 described or not). */
1218 gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
1219 set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1220
1221 /* If it's present, then assign it to the reserved number. */
1222 feature = tdesc_find_feature (info.target_desc,
1223 "org.gnu.gdb.mips.linux");
1224 if (feature != NULL)
1225 tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
1226 "restart");
1227 }
19ed69dd
KB
1228}
1229
63807e1d
PA
1230/* Provide a prototype to silence -Wmissing-prototypes. */
1231extern initialize_file_ftype _initialize_mips_linux_tdep;
1232
2aa830e4 1233void
d1bacddc 1234_initialize_mips_linux_tdep (void)
2aa830e4 1235{
96f026fc
KB
1236 const struct bfd_arch_info *arch_info;
1237
96f026fc
KB
1238 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1239 arch_info != NULL;
1240 arch_info = arch_info->next)
1241 {
295093a4
MS
1242 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1243 GDB_OSABI_LINUX,
96f026fc
KB
1244 mips_linux_init_abi);
1245 }
1246
00e32a35 1247 deprecated_add_core_fns (&regset_core_fns);
2aa830e4 1248}
This page took 1.120015 seconds and 4 git commands to generate.