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