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