1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "solib-svr4.h"
25 #include "mips-tdep.h"
28 #include "trad-frame.h"
29 #include "tramp-frame.h"
35 #include "target-descriptions.h"
37 #include "mips-linux-tdep.h"
38 #include "glibc-tdep.h"
39 #include "linux-tdep.h"
40 #include "xml-syscall.h"
41 #include "gdb_signals.h"
43 static struct target_so_ops mips_svr4_so_ops;
45 /* This enum represents the signals' numbers on the MIPS
46 architecture. It just contains the signal definitions which are
47 different from the generic implementation.
49 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
50 from the Linux kernel tree. */
54 MIPS_LINUX_SIGEMT = 7,
55 MIPS_LINUX_SIGBUS = 10,
56 MIPS_LINUX_SIGSYS = 12,
57 MIPS_LINUX_SIGUSR1 = 16,
58 MIPS_LINUX_SIGUSR2 = 17,
59 MIPS_LINUX_SIGCHLD = 18,
60 MIPS_LINUX_SIGCLD = MIPS_LINUX_SIGCHLD,
61 MIPS_LINUX_SIGPWR = 19,
62 MIPS_LINUX_SIGWINCH = 20,
63 MIPS_LINUX_SIGURG = 21,
64 MIPS_LINUX_SIGIO = 22,
65 MIPS_LINUX_SIGPOLL = MIPS_LINUX_SIGIO,
66 MIPS_LINUX_SIGSTOP = 23,
67 MIPS_LINUX_SIGTSTP = 24,
68 MIPS_LINUX_SIGCONT = 25,
69 MIPS_LINUX_SIGTTIN = 26,
70 MIPS_LINUX_SIGTTOU = 27,
71 MIPS_LINUX_SIGVTALRM = 28,
72 MIPS_LINUX_SIGPROF = 29,
73 MIPS_LINUX_SIGXCPU = 30,
74 MIPS_LINUX_SIGXFSZ = 31,
76 MIPS_LINUX_SIGRTMIN = 32,
77 MIPS_LINUX_SIGRT64 = 64,
78 MIPS_LINUX_SIGRTMAX = 127,
81 /* Figure out where the longjmp will land.
82 We expect the first arg to be a pointer to the jmp_buf structure
83 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
84 at. The pc is copied into PC. This routine returns 1 on
87 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
88 #define MIPS_LINUX_JB_PC 0
91 mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
94 struct gdbarch *gdbarch = get_frame_arch (frame);
95 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
96 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
98 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
100 if (target_read_memory ((jb_addr
101 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
102 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
105 *pc = extract_unsigned_integer (buf,
106 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
112 /* Transform the bits comprising a 32-bit register to the right size
113 for regcache_raw_supply(). This is needed when mips_isa_regsize()
117 supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
119 struct gdbarch *gdbarch = get_regcache_arch (regcache);
120 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
121 gdb_byte buf[MAX_REGISTER_SIZE];
122 store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
123 extract_signed_integer ((const gdb_byte *) addr, 4,
125 regcache_raw_supply (regcache, regnum, buf);
128 /* Unpack an elf_gregset_t into GDB's register cache. */
131 mips_supply_gregset (struct regcache *regcache,
132 const mips_elf_gregset_t *gregsetp)
135 const mips_elf_greg_t *regp = *gregsetp;
136 struct gdbarch *gdbarch = get_regcache_arch (regcache);
138 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
139 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
141 if (mips_linux_restart_reg_p (gdbarch))
142 supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
144 supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
145 supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
147 supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
149 supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
150 regp + EF_CP0_BADVADDR);
151 supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
152 supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
153 regp + EF_CP0_CAUSE);
155 /* Fill the inaccessible zero register with zero. */
156 regcache->raw_supply_zeroed (MIPS_ZERO_REGNUM);
160 mips_supply_gregset_wrapper (const struct regset *regset,
161 struct regcache *regcache,
162 int regnum, const void *gregs, size_t len)
164 gdb_assert (len >= sizeof (mips_elf_gregset_t));
166 mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
169 /* Pack our registers (or one register) into an elf_gregset_t. */
172 mips_fill_gregset (const struct regcache *regcache,
173 mips_elf_gregset_t *gregsetp, int regno)
175 struct gdbarch *gdbarch = get_regcache_arch (regcache);
177 mips_elf_greg_t *regp = *gregsetp;
182 memset (regp, 0, sizeof (mips_elf_gregset_t));
183 for (regi = 1; regi < 32; regi++)
184 mips_fill_gregset (regcache, gregsetp, regi);
185 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
186 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
187 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
188 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
189 mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
190 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
191 mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
195 if (regno > 0 && regno < 32)
197 dst = regp + regno + EF_REG0;
198 regcache_raw_collect (regcache, regno, dst);
202 if (regno == mips_regnum (gdbarch)->lo)
204 else if (regno == mips_regnum (gdbarch)->hi)
206 else if (regno == mips_regnum (gdbarch)->pc)
207 regaddr = EF_CP0_EPC;
208 else if (regno == mips_regnum (gdbarch)->badvaddr)
209 regaddr = EF_CP0_BADVADDR;
210 else if (regno == MIPS_PS_REGNUM)
211 regaddr = EF_CP0_STATUS;
212 else if (regno == mips_regnum (gdbarch)->cause)
213 regaddr = EF_CP0_CAUSE;
214 else if (mips_linux_restart_reg_p (gdbarch)
215 && regno == MIPS_RESTART_REGNUM)
222 dst = regp + regaddr;
223 regcache_raw_collect (regcache, regno, dst);
228 mips_fill_gregset_wrapper (const struct regset *regset,
229 const struct regcache *regcache,
230 int regnum, void *gregs, size_t len)
232 gdb_assert (len >= sizeof (mips_elf_gregset_t));
234 mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
237 /* Likewise, unpack an elf_fpregset_t. */
240 mips_supply_fpregset (struct regcache *regcache,
241 const mips_elf_fpregset_t *fpregsetp)
243 struct gdbarch *gdbarch = get_regcache_arch (regcache);
246 for (regi = 0; regi < 32; regi++)
247 regcache_raw_supply (regcache,
248 gdbarch_fp0_regnum (gdbarch) + regi,
251 regcache_raw_supply (regcache,
252 mips_regnum (gdbarch)->fp_control_status,
255 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
256 regcache->raw_supply_zeroed
257 (mips_regnum (gdbarch)->fp_implementation_revision);
261 mips_supply_fpregset_wrapper (const struct regset *regset,
262 struct regcache *regcache,
263 int regnum, const void *gregs, size_t len)
265 gdb_assert (len >= sizeof (mips_elf_fpregset_t));
267 mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *)gregs);
270 /* Likewise, pack one or all floating point registers into an
274 mips_fill_fpregset (const struct regcache *regcache,
275 mips_elf_fpregset_t *fpregsetp, int regno)
277 struct gdbarch *gdbarch = get_regcache_arch (regcache);
280 if ((regno >= gdbarch_fp0_regnum (gdbarch))
281 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
283 to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
284 regcache_raw_collect (regcache, regno, to);
286 else if (regno == mips_regnum (gdbarch)->fp_control_status)
288 to = (char *) (*fpregsetp + 32);
289 regcache_raw_collect (regcache, regno, to);
291 else if (regno == -1)
295 for (regi = 0; regi < 32; regi++)
296 mips_fill_fpregset (regcache, fpregsetp,
297 gdbarch_fp0_regnum (gdbarch) + regi);
298 mips_fill_fpregset (regcache, fpregsetp,
299 mips_regnum (gdbarch)->fp_control_status);
304 mips_fill_fpregset_wrapper (const struct regset *regset,
305 const struct regcache *regcache,
306 int regnum, void *gregs, size_t len)
308 gdb_assert (len >= sizeof (mips_elf_fpregset_t));
310 mips_fill_fpregset (regcache, (mips_elf_fpregset_t *)gregs, regnum);
313 /* Support for 64-bit ABIs. */
315 /* Figure out where the longjmp will land.
316 We expect the first arg to be a pointer to the jmp_buf structure
317 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
318 at. The pc is copied into PC. This routine returns 1 on
321 /* Details about jmp_buf. */
323 #define MIPS64_LINUX_JB_PC 0
326 mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
329 struct gdbarch *gdbarch = get_frame_arch (frame);
330 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
332 = (gdb_byte *) alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
333 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
335 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
337 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
339 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
342 *pc = extract_unsigned_integer (buf,
343 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
349 /* Register set support functions. These operate on standard 64-bit
350 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
351 target will still use the 64-bit format for PTRACE_GETREGS. */
353 /* Supply a 64-bit register. */
356 supply_64bit_reg (struct regcache *regcache, int regnum,
359 struct gdbarch *gdbarch = get_regcache_arch (regcache);
360 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
361 && register_size (gdbarch, regnum) == 4)
362 regcache_raw_supply (regcache, regnum, buf + 4);
364 regcache_raw_supply (regcache, regnum, buf);
367 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
370 mips64_supply_gregset (struct regcache *regcache,
371 const mips64_elf_gregset_t *gregsetp)
374 const mips64_elf_greg_t *regp = *gregsetp;
375 struct gdbarch *gdbarch = get_regcache_arch (regcache);
377 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
378 supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
379 (const gdb_byte *) (regp + regi));
381 if (mips_linux_restart_reg_p (gdbarch))
382 supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
383 (const gdb_byte *) (regp + MIPS64_EF_REG0));
385 supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
386 (const gdb_byte *) (regp + MIPS64_EF_LO));
387 supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
388 (const gdb_byte *) (regp + MIPS64_EF_HI));
390 supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
391 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
392 supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
393 (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
394 supply_64bit_reg (regcache, MIPS_PS_REGNUM,
395 (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
396 supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
397 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
399 /* Fill the inaccessible zero register with zero. */
400 regcache->raw_supply_zeroed (MIPS_ZERO_REGNUM);
404 mips64_supply_gregset_wrapper (const struct regset *regset,
405 struct regcache *regcache,
406 int regnum, const void *gregs, size_t len)
408 gdb_assert (len >= sizeof (mips64_elf_gregset_t));
410 mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
413 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
416 mips64_fill_gregset (const struct regcache *regcache,
417 mips64_elf_gregset_t *gregsetp, int regno)
419 struct gdbarch *gdbarch = get_regcache_arch (regcache);
420 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
422 mips64_elf_greg_t *regp = *gregsetp;
427 memset (regp, 0, sizeof (mips64_elf_gregset_t));
428 for (regi = 1; regi < 32; regi++)
429 mips64_fill_gregset (regcache, gregsetp, regi);
430 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
431 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
432 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
433 mips64_fill_gregset (regcache, gregsetp,
434 mips_regnum (gdbarch)->badvaddr);
435 mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
436 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
437 mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
441 if (regno > 0 && regno < 32)
442 regaddr = regno + MIPS64_EF_REG0;
443 else if (regno == mips_regnum (gdbarch)->lo)
444 regaddr = MIPS64_EF_LO;
445 else if (regno == mips_regnum (gdbarch)->hi)
446 regaddr = MIPS64_EF_HI;
447 else if (regno == mips_regnum (gdbarch)->pc)
448 regaddr = MIPS64_EF_CP0_EPC;
449 else if (regno == mips_regnum (gdbarch)->badvaddr)
450 regaddr = MIPS64_EF_CP0_BADVADDR;
451 else if (regno == MIPS_PS_REGNUM)
452 regaddr = MIPS64_EF_CP0_STATUS;
453 else if (regno == mips_regnum (gdbarch)->cause)
454 regaddr = MIPS64_EF_CP0_CAUSE;
455 else if (mips_linux_restart_reg_p (gdbarch)
456 && regno == MIPS_RESTART_REGNUM)
457 regaddr = MIPS64_EF_REG0;
463 gdb_byte buf[MAX_REGISTER_SIZE];
466 regcache_raw_collect (regcache, regno, buf);
467 val = extract_signed_integer (buf, register_size (gdbarch, regno),
469 dst = regp + regaddr;
470 store_signed_integer ((gdb_byte *) dst, 8, byte_order, val);
475 mips64_fill_gregset_wrapper (const struct regset *regset,
476 const struct regcache *regcache,
477 int regnum, void *gregs, size_t len)
479 gdb_assert (len >= sizeof (mips64_elf_gregset_t));
481 mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
484 /* Likewise, unpack an elf_fpregset_t. */
487 mips64_supply_fpregset (struct regcache *regcache,
488 const mips64_elf_fpregset_t *fpregsetp)
490 struct gdbarch *gdbarch = get_regcache_arch (regcache);
493 /* See mips_linux_o32_sigframe_init for a description of the
494 peculiar FP register layout. */
495 if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
496 for (regi = 0; regi < 32; regi++)
498 const gdb_byte *reg_ptr
499 = (const gdb_byte *) (*fpregsetp + (regi & ~1));
500 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
502 regcache_raw_supply (regcache,
503 gdbarch_fp0_regnum (gdbarch) + regi,
507 for (regi = 0; regi < 32; regi++)
508 regcache_raw_supply (regcache,
509 gdbarch_fp0_regnum (gdbarch) + regi,
510 (const char *) (*fpregsetp + regi));
512 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
513 (const gdb_byte *) (*fpregsetp + 32));
515 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
516 include it - but the result of PTRACE_GETFPREGS does. The best we
517 can do is to assume that its value is present. */
518 supply_32bit_reg (regcache,
519 mips_regnum (gdbarch)->fp_implementation_revision,
520 (const gdb_byte *) (*fpregsetp + 32) + 4);
524 mips64_supply_fpregset_wrapper (const struct regset *regset,
525 struct regcache *regcache,
526 int regnum, const void *gregs, size_t len)
528 gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
530 mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
533 /* Likewise, pack one or all floating point registers into an
537 mips64_fill_fpregset (const struct regcache *regcache,
538 mips64_elf_fpregset_t *fpregsetp, int regno)
540 struct gdbarch *gdbarch = get_regcache_arch (regcache);
541 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
544 if ((regno >= gdbarch_fp0_regnum (gdbarch))
545 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
547 /* See mips_linux_o32_sigframe_init for a description of the
548 peculiar FP register layout. */
549 if (register_size (gdbarch, regno) == 4)
551 int regi = regno - gdbarch_fp0_regnum (gdbarch);
553 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
554 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
556 regcache_raw_collect (regcache, regno, to);
560 to = (gdb_byte *) (*fpregsetp + regno
561 - gdbarch_fp0_regnum (gdbarch));
562 regcache_raw_collect (regcache, regno, to);
565 else if (regno == mips_regnum (gdbarch)->fp_control_status)
567 gdb_byte buf[MAX_REGISTER_SIZE];
570 regcache_raw_collect (regcache, regno, buf);
571 val = extract_signed_integer (buf, register_size (gdbarch, regno),
573 to = (gdb_byte *) (*fpregsetp + 32);
574 store_signed_integer (to, 4, byte_order, val);
576 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
578 gdb_byte buf[MAX_REGISTER_SIZE];
581 regcache_raw_collect (regcache, regno, buf);
582 val = extract_signed_integer (buf, register_size (gdbarch, regno),
584 to = (gdb_byte *) (*fpregsetp + 32) + 4;
585 store_signed_integer (to, 4, byte_order, val);
587 else if (regno == -1)
591 for (regi = 0; regi < 32; regi++)
592 mips64_fill_fpregset (regcache, fpregsetp,
593 gdbarch_fp0_regnum (gdbarch) + regi);
594 mips64_fill_fpregset (regcache, fpregsetp,
595 mips_regnum (gdbarch)->fp_control_status);
596 mips64_fill_fpregset (regcache, fpregsetp,
597 mips_regnum (gdbarch)->fp_implementation_revision);
602 mips64_fill_fpregset_wrapper (const struct regset *regset,
603 const struct regcache *regcache,
604 int regnum, void *gregs, size_t len)
606 gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
608 mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
611 static const struct regset mips_linux_gregset =
613 NULL, mips_supply_gregset_wrapper, mips_fill_gregset_wrapper
616 static const struct regset mips64_linux_gregset =
618 NULL, mips64_supply_gregset_wrapper, mips64_fill_gregset_wrapper
621 static const struct regset mips_linux_fpregset =
623 NULL, mips_supply_fpregset_wrapper, mips_fill_fpregset_wrapper
626 static const struct regset mips64_linux_fpregset =
628 NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
632 mips_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
633 iterate_over_regset_sections_cb *cb,
635 const struct regcache *regcache)
637 if (register_size (gdbarch, MIPS_ZERO_REGNUM) == 4)
639 cb (".reg", sizeof (mips_elf_gregset_t), &mips_linux_gregset,
641 cb (".reg2", sizeof (mips_elf_fpregset_t), &mips_linux_fpregset,
646 cb (".reg", sizeof (mips64_elf_gregset_t), &mips64_linux_gregset,
648 cb (".reg2", sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
653 static const struct target_desc *
654 mips_linux_core_read_description (struct gdbarch *gdbarch,
655 struct target_ops *target,
658 asection *section = bfd_get_section_by_name (abfd, ".reg");
662 switch (bfd_section_size (abfd, section))
664 case sizeof (mips_elf_gregset_t):
665 return mips_tdesc_gp32;
667 case sizeof (mips64_elf_gregset_t):
668 return mips_tdesc_gp64;
676 /* Check the code at PC for a dynamic linker lazy resolution stub.
677 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
678 section uniformly since version 2.15. If the pc is in that section,
679 then we are in such a stub. Before that ".stub" was used in 32-bit
680 ELF binaries, however we do not bother checking for that since we
681 have never had and that case should be extremely rare these days.
682 Instead we pattern-match on the code generated by GNU ld. They look
690 (with the appropriate doubleword instructions for N64). As any lazy
691 resolution stubs in microMIPS binaries will always be in a
692 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
695 mips_linux_in_dynsym_stub (CORE_ADDR pc)
697 gdb_byte buf[28], *p;
698 ULONGEST insn, insn1;
699 int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
700 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
702 if (in_mips_stubs_section (pc))
705 read_memory (pc - 12, buf, 28);
709 /* ld t9,0x8010(gp) */
714 /* lw t9,0x8010(gp) */
721 insn = extract_unsigned_integer (p, 4, byte_order);
729 insn = extract_unsigned_integer (p + 4, 4, byte_order);
732 /* 'daddu t7,ra' or 'or t7, ra, zero'*/
733 if (insn != 0x03e0782d || insn != 0x03e07825)
739 /* 'addu t7,ra' or 'or t7, ra, zero'*/
740 if (insn != 0x03e07821 || insn != 0x03e07825)
745 insn = extract_unsigned_integer (p + 8, 4, byte_order);
747 if (insn != 0x0320f809)
750 insn = extract_unsigned_integer (p + 12, 4, byte_order);
753 /* daddiu t8,zero,0 */
754 if ((insn & 0xffff0000) != 0x64180000)
759 /* addiu t8,zero,0 */
760 if ((insn & 0xffff0000) != 0x24180000)
767 /* Return non-zero iff PC belongs to the dynamic linker resolution
768 code, a PLT entry, or a lazy binding stub. */
771 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
773 /* Check whether PC is in the dynamic linker. This also checks
774 whether it is in the .plt section, used by non-PIC executables. */
775 if (svr4_in_dynsym_resolve_code (pc))
778 /* Likewise for the stubs. They live in the .MIPS.stubs section these
779 days, so we check if the PC is within, than fall back to a pattern
781 if (mips_linux_in_dynsym_stub (pc))
787 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
788 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
789 implementation of this triggers at "fixup" from the same objfile as
790 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
791 "__dl_runtime_resolve" directly. An unresolved lazy binding
792 stub will point to _dl_runtime_resolve, which will first call
793 __dl_runtime_resolve, and then pass control to the resolved
797 mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
799 struct bound_minimal_symbol resolver;
801 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
803 if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
804 return frame_unwind_caller_pc (get_current_frame ());
806 return glibc_skip_solib_resolver (gdbarch, pc);
809 /* Signal trampoline support. There are four supported layouts for a
810 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
811 n64 rt_sigframe. We handle them all independently; not the most
812 efficient way, but simplest. First, declare all the unwinders. */
814 static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
815 struct frame_info *this_frame,
816 struct trad_frame_cache *this_cache,
819 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
820 struct frame_info *this_frame,
821 struct trad_frame_cache *this_cache,
824 static int mips_linux_sigframe_validate (const struct tramp_frame *self,
825 struct frame_info *this_frame,
828 static int micromips_linux_sigframe_validate (const struct tramp_frame *self,
829 struct frame_info *this_frame,
832 #define MIPS_NR_LINUX 4000
833 #define MIPS_NR_N64_LINUX 5000
834 #define MIPS_NR_N32_LINUX 6000
836 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
837 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
838 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
839 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
841 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
842 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
843 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
844 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
845 #define MIPS_INST_SYSCALL 0x0000000c
847 #define MICROMIPS_INST_LI_V0 0x3040
848 #define MICROMIPS_INST_POOL32A 0x0000
849 #define MICROMIPS_INST_SYSCALL 0x8b7c
851 static const struct tramp_frame mips_linux_o32_sigframe = {
855 { MIPS_INST_LI_V0_SIGRETURN, -1 },
856 { MIPS_INST_SYSCALL, -1 },
857 { TRAMP_SENTINEL_INSN, -1 }
859 mips_linux_o32_sigframe_init,
860 mips_linux_sigframe_validate
863 static const struct tramp_frame mips_linux_o32_rt_sigframe = {
867 { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
868 { MIPS_INST_SYSCALL, -1 },
869 { TRAMP_SENTINEL_INSN, -1 } },
870 mips_linux_o32_sigframe_init,
871 mips_linux_sigframe_validate
874 static const struct tramp_frame mips_linux_n32_rt_sigframe = {
878 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
879 { MIPS_INST_SYSCALL, -1 },
880 { TRAMP_SENTINEL_INSN, -1 }
882 mips_linux_n32n64_sigframe_init,
883 mips_linux_sigframe_validate
886 static const struct tramp_frame mips_linux_n64_rt_sigframe = {
890 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
891 { MIPS_INST_SYSCALL, -1 },
892 { TRAMP_SENTINEL_INSN, -1 }
894 mips_linux_n32n64_sigframe_init,
895 mips_linux_sigframe_validate
898 static const struct tramp_frame micromips_linux_o32_sigframe = {
902 { MICROMIPS_INST_LI_V0, -1 },
903 { MIPS_NR_sigreturn, -1 },
904 { MICROMIPS_INST_POOL32A, -1 },
905 { MICROMIPS_INST_SYSCALL, -1 },
906 { TRAMP_SENTINEL_INSN, -1 }
908 mips_linux_o32_sigframe_init,
909 micromips_linux_sigframe_validate
912 static const struct tramp_frame micromips_linux_o32_rt_sigframe = {
916 { MICROMIPS_INST_LI_V0, -1 },
917 { MIPS_NR_rt_sigreturn, -1 },
918 { MICROMIPS_INST_POOL32A, -1 },
919 { MICROMIPS_INST_SYSCALL, -1 },
920 { TRAMP_SENTINEL_INSN, -1 }
922 mips_linux_o32_sigframe_init,
923 micromips_linux_sigframe_validate
926 static const struct tramp_frame micromips_linux_n32_rt_sigframe = {
930 { MICROMIPS_INST_LI_V0, -1 },
931 { MIPS_NR_N32_rt_sigreturn, -1 },
932 { MICROMIPS_INST_POOL32A, -1 },
933 { MICROMIPS_INST_SYSCALL, -1 },
934 { TRAMP_SENTINEL_INSN, -1 }
936 mips_linux_n32n64_sigframe_init,
937 micromips_linux_sigframe_validate
940 static const struct tramp_frame micromips_linux_n64_rt_sigframe = {
944 { MICROMIPS_INST_LI_V0, -1 },
945 { MIPS_NR_N64_rt_sigreturn, -1 },
946 { MICROMIPS_INST_POOL32A, -1 },
947 { MICROMIPS_INST_SYSCALL, -1 },
948 { TRAMP_SENTINEL_INSN, -1 }
950 mips_linux_n32n64_sigframe_init,
951 micromips_linux_sigframe_validate
955 /* The unwinder for o32 signal frames. The legacy structures look
959 u32 sf_ass[4]; [argument save space for o32]
960 u32 sf_code[2]; [signal trampoline or fill]
961 struct sigcontext sf_sc;
965 Pre-2.6.12 sigcontext:
968 unsigned int sc_regmask; [Unused]
969 unsigned int sc_status;
970 unsigned long long sc_pc;
971 unsigned long long sc_regs[32];
972 unsigned long long sc_fpregs[32];
973 unsigned int sc_ownedfp;
974 unsigned int sc_fpc_csr;
975 unsigned int sc_fpc_eir; [Unused]
976 unsigned int sc_used_math;
977 unsigned int sc_ssflags; [Unused]
978 [Alignment hole of four bytes]
979 unsigned long long sc_mdhi;
980 unsigned long long sc_mdlo;
982 unsigned int sc_cause; [Unused]
983 unsigned int sc_badvaddr; [Unused]
985 unsigned long sc_sigset[4]; [kernel's sigset_t]
988 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
991 unsigned int sc_regmask; [Unused]
992 unsigned int sc_status; [Unused]
993 unsigned long long sc_pc;
994 unsigned long long sc_regs[32];
995 unsigned long long sc_fpregs[32];
997 unsigned int sc_fpc_csr;
998 unsigned int sc_fpc_eir; [Unused]
999 unsigned int sc_used_math;
1000 unsigned int sc_dsp;
1001 [Alignment hole of four bytes]
1002 unsigned long long sc_mdhi;
1003 unsigned long long sc_mdlo;
1004 unsigned long sc_hi1;
1005 unsigned long sc_lo1;
1006 unsigned long sc_hi2;
1007 unsigned long sc_lo2;
1008 unsigned long sc_hi3;
1009 unsigned long sc_lo3;
1012 The RT signal frames look like this:
1014 struct rt_sigframe {
1015 u32 rs_ass[4]; [argument save space for o32]
1016 u32 rs_code[2] [signal trampoline or fill]
1017 struct siginfo rs_info;
1018 struct ucontext rs_uc;
1022 unsigned long uc_flags;
1023 struct ucontext *uc_link;
1025 [Alignment hole of four bytes]
1026 struct sigcontext uc_mcontext;
1027 sigset_t uc_sigmask;
1031 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
1033 #define RTSIGFRAME_SIGINFO_SIZE 128
1034 #define STACK_T_SIZE (3 * 4)
1035 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
1036 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1037 + RTSIGFRAME_SIGINFO_SIZE \
1038 + UCONTEXT_SIGCONTEXT_OFFSET)
1040 #define SIGCONTEXT_PC (1 * 8)
1041 #define SIGCONTEXT_REGS (2 * 8)
1042 #define SIGCONTEXT_FPREGS (34 * 8)
1043 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
1044 #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
1045 #define SIGCONTEXT_HI (69 * 8)
1046 #define SIGCONTEXT_LO (70 * 8)
1047 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
1048 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
1049 #define SIGCONTEXT_HI1 (71 * 8 + 0)
1050 #define SIGCONTEXT_LO1 (71 * 8 + 4)
1051 #define SIGCONTEXT_HI2 (72 * 8 + 0)
1052 #define SIGCONTEXT_LO2 (72 * 8 + 4)
1053 #define SIGCONTEXT_HI3 (73 * 8 + 0)
1054 #define SIGCONTEXT_LO3 (73 * 8 + 4)
1056 #define SIGCONTEXT_REG_SIZE 8
1059 mips_linux_o32_sigframe_init (const struct tramp_frame *self,
1060 struct frame_info *this_frame,
1061 struct trad_frame_cache *this_cache,
1064 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1066 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1067 CORE_ADDR sigcontext_base;
1068 const struct mips_regnum *regs = mips_regnum (gdbarch);
1069 CORE_ADDR regs_base;
1071 if (self == &mips_linux_o32_sigframe
1072 || self == µmips_linux_o32_sigframe)
1073 sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
1075 sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
1077 /* I'm not proud of this hack. Eventually we will have the
1078 infrastructure to indicate the size of saved registers on a
1079 per-frame basis, but right now we don't; the kernel saves eight
1080 bytes but we only want four. Use regs_base to access any
1082 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1083 regs_base = sigcontext_base + 4;
1085 regs_base = sigcontext_base;
1087 if (mips_linux_restart_reg_p (gdbarch))
1088 trad_frame_set_reg_addr (this_cache,
1089 (MIPS_RESTART_REGNUM
1090 + gdbarch_num_regs (gdbarch)),
1091 regs_base + SIGCONTEXT_REGS);
1093 for (ireg = 1; ireg < 32; ireg++)
1094 trad_frame_set_reg_addr (this_cache,
1095 (ireg + MIPS_ZERO_REGNUM
1096 + gdbarch_num_regs (gdbarch)),
1097 (regs_base + SIGCONTEXT_REGS
1098 + ireg * SIGCONTEXT_REG_SIZE));
1100 /* The way that floating point registers are saved, unfortunately,
1101 depends on the architecture the kernel is built for. For the r3000 and
1102 tx39, four bytes of each register are at the beginning of each of the
1103 32 eight byte slots. For everything else, the registers are saved
1104 using double precision; only the even-numbered slots are initialized,
1105 and the high bits are the odd-numbered register. Assume the latter
1106 layout, since we can't tell, and it's much more common. Which bits are
1107 the "high" bits depends on endianness. */
1108 for (ireg = 0; ireg < 32; ireg++)
1109 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
1110 trad_frame_set_reg_addr (this_cache,
1111 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1112 (sigcontext_base + SIGCONTEXT_FPREGS + 4
1113 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1115 trad_frame_set_reg_addr (this_cache,
1116 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1117 (sigcontext_base + SIGCONTEXT_FPREGS
1118 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1120 trad_frame_set_reg_addr (this_cache,
1121 regs->pc + gdbarch_num_regs (gdbarch),
1122 regs_base + SIGCONTEXT_PC);
1124 trad_frame_set_reg_addr (this_cache,
1125 (regs->fp_control_status
1126 + gdbarch_num_regs (gdbarch)),
1127 sigcontext_base + SIGCONTEXT_FPCSR);
1129 if (regs->dspctl != -1)
1130 trad_frame_set_reg_addr (this_cache,
1131 regs->dspctl + gdbarch_num_regs (gdbarch),
1132 sigcontext_base + SIGCONTEXT_DSPCTL);
1134 trad_frame_set_reg_addr (this_cache,
1135 regs->hi + gdbarch_num_regs (gdbarch),
1136 regs_base + SIGCONTEXT_HI);
1137 trad_frame_set_reg_addr (this_cache,
1138 regs->lo + gdbarch_num_regs (gdbarch),
1139 regs_base + SIGCONTEXT_LO);
1141 if (regs->dspacc != -1)
1143 trad_frame_set_reg_addr (this_cache,
1144 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1145 sigcontext_base + SIGCONTEXT_HI1);
1146 trad_frame_set_reg_addr (this_cache,
1147 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1148 sigcontext_base + SIGCONTEXT_LO1);
1149 trad_frame_set_reg_addr (this_cache,
1150 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1151 sigcontext_base + SIGCONTEXT_HI2);
1152 trad_frame_set_reg_addr (this_cache,
1153 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1154 sigcontext_base + SIGCONTEXT_LO2);
1155 trad_frame_set_reg_addr (this_cache,
1156 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1157 sigcontext_base + SIGCONTEXT_HI3);
1158 trad_frame_set_reg_addr (this_cache,
1159 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1160 sigcontext_base + SIGCONTEXT_LO3);
1164 trad_frame_set_reg_addr (this_cache,
1165 regs->cause + gdbarch_num_regs (gdbarch),
1166 sigcontext_base + SIGCONTEXT_CAUSE);
1167 trad_frame_set_reg_addr (this_cache,
1168 regs->badvaddr + gdbarch_num_regs (gdbarch),
1169 sigcontext_base + SIGCONTEXT_BADVADDR);
1172 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1173 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1177 /* For N32/N64 things look different. There is no non-rt signal frame.
1179 struct rt_sigframe_n32 {
1180 u32 rs_ass[4]; [ argument save space for o32 ]
1181 u32 rs_code[2]; [ signal trampoline or fill ]
1182 struct siginfo rs_info;
1183 struct ucontextn32 rs_uc;
1186 struct ucontextn32 {
1190 struct sigcontext uc_mcontext;
1191 sigset_t uc_sigmask; [ mask last for extensibility ]
1194 struct rt_sigframe {
1195 u32 rs_ass[4]; [ argument save space for o32 ]
1196 u32 rs_code[2]; [ signal trampoline ]
1197 struct siginfo rs_info;
1198 struct ucontext rs_uc;
1202 unsigned long uc_flags;
1203 struct ucontext *uc_link;
1205 struct sigcontext uc_mcontext;
1206 sigset_t uc_sigmask; [ mask last for extensibility ]
1209 And the sigcontext is different (this is for both n32 and n64):
1212 unsigned long long sc_regs[32];
1213 unsigned long long sc_fpregs[32];
1214 unsigned long long sc_mdhi;
1215 unsigned long long sc_hi1;
1216 unsigned long long sc_hi2;
1217 unsigned long long sc_hi3;
1218 unsigned long long sc_mdlo;
1219 unsigned long long sc_lo1;
1220 unsigned long long sc_lo2;
1221 unsigned long long sc_lo3;
1222 unsigned long long sc_pc;
1223 unsigned int sc_fpc_csr;
1224 unsigned int sc_used_math;
1225 unsigned int sc_dsp;
1226 unsigned int sc_reserved;
1229 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1230 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1234 #define N32_STACK_T_SIZE STACK_T_SIZE
1235 #define N64_STACK_T_SIZE (2 * 8 + 4)
1236 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1237 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1238 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1239 + RTSIGFRAME_SIGINFO_SIZE \
1240 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1241 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1242 + RTSIGFRAME_SIGINFO_SIZE \
1243 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1245 #define N64_SIGCONTEXT_REGS (0 * 8)
1246 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1247 #define N64_SIGCONTEXT_HI (64 * 8)
1248 #define N64_SIGCONTEXT_HI1 (65 * 8)
1249 #define N64_SIGCONTEXT_HI2 (66 * 8)
1250 #define N64_SIGCONTEXT_HI3 (67 * 8)
1251 #define N64_SIGCONTEXT_LO (68 * 8)
1252 #define N64_SIGCONTEXT_LO1 (69 * 8)
1253 #define N64_SIGCONTEXT_LO2 (70 * 8)
1254 #define N64_SIGCONTEXT_LO3 (71 * 8)
1255 #define N64_SIGCONTEXT_PC (72 * 8)
1256 #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1257 #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1259 #define N64_SIGCONTEXT_REG_SIZE 8
1262 mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
1263 struct frame_info *this_frame,
1264 struct trad_frame_cache *this_cache,
1267 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1269 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1270 CORE_ADDR sigcontext_base;
1271 const struct mips_regnum *regs = mips_regnum (gdbarch);
1273 if (self == &mips_linux_n32_rt_sigframe
1274 || self == µmips_linux_n32_rt_sigframe)
1275 sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
1277 sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
1279 if (mips_linux_restart_reg_p (gdbarch))
1280 trad_frame_set_reg_addr (this_cache,
1281 (MIPS_RESTART_REGNUM
1282 + gdbarch_num_regs (gdbarch)),
1283 sigcontext_base + N64_SIGCONTEXT_REGS);
1285 for (ireg = 1; ireg < 32; ireg++)
1286 trad_frame_set_reg_addr (this_cache,
1287 (ireg + MIPS_ZERO_REGNUM
1288 + gdbarch_num_regs (gdbarch)),
1289 (sigcontext_base + N64_SIGCONTEXT_REGS
1290 + ireg * N64_SIGCONTEXT_REG_SIZE));
1292 for (ireg = 0; ireg < 32; ireg++)
1293 trad_frame_set_reg_addr (this_cache,
1294 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1295 (sigcontext_base + N64_SIGCONTEXT_FPREGS
1296 + ireg * N64_SIGCONTEXT_REG_SIZE));
1298 trad_frame_set_reg_addr (this_cache,
1299 regs->pc + gdbarch_num_regs (gdbarch),
1300 sigcontext_base + N64_SIGCONTEXT_PC);
1302 trad_frame_set_reg_addr (this_cache,
1303 (regs->fp_control_status
1304 + gdbarch_num_regs (gdbarch)),
1305 sigcontext_base + N64_SIGCONTEXT_FPCSR);
1307 trad_frame_set_reg_addr (this_cache,
1308 regs->hi + gdbarch_num_regs (gdbarch),
1309 sigcontext_base + N64_SIGCONTEXT_HI);
1310 trad_frame_set_reg_addr (this_cache,
1311 regs->lo + gdbarch_num_regs (gdbarch),
1312 sigcontext_base + N64_SIGCONTEXT_LO);
1314 if (regs->dspacc != -1)
1316 trad_frame_set_reg_addr (this_cache,
1317 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1318 sigcontext_base + N64_SIGCONTEXT_HI1);
1319 trad_frame_set_reg_addr (this_cache,
1320 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1321 sigcontext_base + N64_SIGCONTEXT_LO1);
1322 trad_frame_set_reg_addr (this_cache,
1323 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1324 sigcontext_base + N64_SIGCONTEXT_HI2);
1325 trad_frame_set_reg_addr (this_cache,
1326 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1327 sigcontext_base + N64_SIGCONTEXT_LO2);
1328 trad_frame_set_reg_addr (this_cache,
1329 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1330 sigcontext_base + N64_SIGCONTEXT_HI3);
1331 trad_frame_set_reg_addr (this_cache,
1332 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1333 sigcontext_base + N64_SIGCONTEXT_LO3);
1335 if (regs->dspctl != -1)
1336 trad_frame_set_reg_addr (this_cache,
1337 regs->dspctl + gdbarch_num_regs (gdbarch),
1338 sigcontext_base + N64_SIGCONTEXT_DSPCTL);
1340 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1341 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1344 /* Implement struct tramp_frame's "validate" method for standard MIPS code. */
1347 mips_linux_sigframe_validate (const struct tramp_frame *self,
1348 struct frame_info *this_frame,
1351 return mips_pc_is_mips (*pc);
1354 /* Implement struct tramp_frame's "validate" method for microMIPS code. */
1357 micromips_linux_sigframe_validate (const struct tramp_frame *self,
1358 struct frame_info *this_frame,
1361 if (mips_pc_is_micromips (get_frame_arch (this_frame), *pc))
1363 *pc = mips_unmake_compact_addr (*pc);
1370 /* Implement the "write_pc" gdbarch method. */
1373 mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1375 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1377 mips_write_pc (regcache, pc);
1379 /* Clear the syscall restart flag. */
1380 if (mips_linux_restart_reg_p (gdbarch))
1381 regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
1384 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1387 mips_linux_restart_reg_p (struct gdbarch *gdbarch)
1389 /* If we do not have a target description with registers, then
1390 MIPS_RESTART_REGNUM will not be included in the register set. */
1391 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1394 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1395 either be GPR-sized or missing. */
1396 return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
1399 /* When FRAME is at a syscall instruction, return the PC of the next
1400 instruction to be executed. */
1403 mips_linux_syscall_next_pc (struct frame_info *frame)
1405 CORE_ADDR pc = get_frame_pc (frame);
1406 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1408 /* If we are about to make a sigreturn syscall, use the unwinder to
1409 decode the signal frame. */
1410 if (v0 == MIPS_NR_sigreturn
1411 || v0 == MIPS_NR_rt_sigreturn
1412 || v0 == MIPS_NR_N64_rt_sigreturn
1413 || v0 == MIPS_NR_N32_rt_sigreturn)
1414 return frame_unwind_caller_pc (get_current_frame ());
1419 /* Return the current system call's number present in the
1420 v0 register. When the function fails, it returns -1. */
1423 mips_linux_get_syscall_number (struct gdbarch *gdbarch,
1426 struct regcache *regcache = get_thread_regcache (ptid);
1427 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1428 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1429 int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
1430 /* The content of a register */
1435 /* Make sure we're in a known ABI */
1436 gdb_assert (tdep->mips_abi == MIPS_ABI_O32
1437 || tdep->mips_abi == MIPS_ABI_N32
1438 || tdep->mips_abi == MIPS_ABI_N64);
1440 gdb_assert (regsize <= sizeof (buf));
1442 /* Getting the system call number from the register.
1443 syscall number is in v0 or $2. */
1444 regcache_cooked_read (regcache, MIPS_V0_REGNUM, buf);
1446 ret = extract_signed_integer (buf, regsize, byte_order);
1451 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1455 mips_gdb_signal_to_target (struct gdbarch *gdbarch,
1456 enum gdb_signal signal)
1460 case GDB_SIGNAL_EMT:
1461 return MIPS_LINUX_SIGEMT;
1463 case GDB_SIGNAL_BUS:
1464 return MIPS_LINUX_SIGBUS;
1466 case GDB_SIGNAL_SYS:
1467 return MIPS_LINUX_SIGSYS;
1469 case GDB_SIGNAL_USR1:
1470 return MIPS_LINUX_SIGUSR1;
1472 case GDB_SIGNAL_USR2:
1473 return MIPS_LINUX_SIGUSR2;
1475 case GDB_SIGNAL_CHLD:
1476 return MIPS_LINUX_SIGCHLD;
1478 case GDB_SIGNAL_PWR:
1479 return MIPS_LINUX_SIGPWR;
1481 case GDB_SIGNAL_WINCH:
1482 return MIPS_LINUX_SIGWINCH;
1484 case GDB_SIGNAL_URG:
1485 return MIPS_LINUX_SIGURG;
1488 return MIPS_LINUX_SIGIO;
1490 case GDB_SIGNAL_POLL:
1491 return MIPS_LINUX_SIGPOLL;
1493 case GDB_SIGNAL_STOP:
1494 return MIPS_LINUX_SIGSTOP;
1496 case GDB_SIGNAL_TSTP:
1497 return MIPS_LINUX_SIGTSTP;
1499 case GDB_SIGNAL_CONT:
1500 return MIPS_LINUX_SIGCONT;
1502 case GDB_SIGNAL_TTIN:
1503 return MIPS_LINUX_SIGTTIN;
1505 case GDB_SIGNAL_TTOU:
1506 return MIPS_LINUX_SIGTTOU;
1508 case GDB_SIGNAL_VTALRM:
1509 return MIPS_LINUX_SIGVTALRM;
1511 case GDB_SIGNAL_PROF:
1512 return MIPS_LINUX_SIGPROF;
1514 case GDB_SIGNAL_XCPU:
1515 return MIPS_LINUX_SIGXCPU;
1517 case GDB_SIGNAL_XFSZ:
1518 return MIPS_LINUX_SIGXFSZ;
1520 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1521 therefore we have to handle it here. */
1522 case GDB_SIGNAL_REALTIME_32:
1523 return MIPS_LINUX_SIGRTMIN;
1526 if (signal >= GDB_SIGNAL_REALTIME_33
1527 && signal <= GDB_SIGNAL_REALTIME_63)
1529 int offset = signal - GDB_SIGNAL_REALTIME_33;
1531 return MIPS_LINUX_SIGRTMIN + 1 + offset;
1533 else if (signal >= GDB_SIGNAL_REALTIME_64
1534 && signal <= GDB_SIGNAL_REALTIME_127)
1536 int offset = signal - GDB_SIGNAL_REALTIME_64;
1538 return MIPS_LINUX_SIGRT64 + offset;
1541 return linux_gdb_signal_to_target (gdbarch, signal);
1544 /* Translate signals based on MIPS signal values.
1545 Adapted from gdb/common/signals.c. */
1547 static enum gdb_signal
1548 mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
1552 case MIPS_LINUX_SIGEMT:
1553 return GDB_SIGNAL_EMT;
1555 case MIPS_LINUX_SIGBUS:
1556 return GDB_SIGNAL_BUS;
1558 case MIPS_LINUX_SIGSYS:
1559 return GDB_SIGNAL_SYS;
1561 case MIPS_LINUX_SIGUSR1:
1562 return GDB_SIGNAL_USR1;
1564 case MIPS_LINUX_SIGUSR2:
1565 return GDB_SIGNAL_USR2;
1567 case MIPS_LINUX_SIGCHLD:
1568 return GDB_SIGNAL_CHLD;
1570 case MIPS_LINUX_SIGPWR:
1571 return GDB_SIGNAL_PWR;
1573 case MIPS_LINUX_SIGWINCH:
1574 return GDB_SIGNAL_WINCH;
1576 case MIPS_LINUX_SIGURG:
1577 return GDB_SIGNAL_URG;
1579 /* No way to differentiate between SIGIO and SIGPOLL.
1580 Therefore, we just handle the first one. */
1581 case MIPS_LINUX_SIGIO:
1582 return GDB_SIGNAL_IO;
1584 case MIPS_LINUX_SIGSTOP:
1585 return GDB_SIGNAL_STOP;
1587 case MIPS_LINUX_SIGTSTP:
1588 return GDB_SIGNAL_TSTP;
1590 case MIPS_LINUX_SIGCONT:
1591 return GDB_SIGNAL_CONT;
1593 case MIPS_LINUX_SIGTTIN:
1594 return GDB_SIGNAL_TTIN;
1596 case MIPS_LINUX_SIGTTOU:
1597 return GDB_SIGNAL_TTOU;
1599 case MIPS_LINUX_SIGVTALRM:
1600 return GDB_SIGNAL_VTALRM;
1602 case MIPS_LINUX_SIGPROF:
1603 return GDB_SIGNAL_PROF;
1605 case MIPS_LINUX_SIGXCPU:
1606 return GDB_SIGNAL_XCPU;
1608 case MIPS_LINUX_SIGXFSZ:
1609 return GDB_SIGNAL_XFSZ;
1612 if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
1614 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1615 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1616 int offset = signal - MIPS_LINUX_SIGRTMIN;
1619 return GDB_SIGNAL_REALTIME_32;
1620 else if (offset < 32)
1621 return (enum gdb_signal) (offset - 1
1622 + (int) GDB_SIGNAL_REALTIME_33);
1624 return (enum gdb_signal) (offset - 32
1625 + (int) GDB_SIGNAL_REALTIME_64);
1628 return linux_gdb_signal_from_target (gdbarch, signal);
1631 /* Initialize one of the GNU/Linux OS ABIs. */
1634 mips_linux_init_abi (struct gdbarch_info info,
1635 struct gdbarch *gdbarch)
1637 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1638 enum mips_abi abi = mips_abi (gdbarch);
1639 struct tdesc_arch_data *tdesc_data
1640 = (struct tdesc_arch_data *) info.tdep_info;
1642 linux_init_abi (info, gdbarch);
1644 /* Get the syscall number from the arch's register. */
1645 set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);
1650 set_gdbarch_get_longjmp_target (gdbarch,
1651 mips_linux_get_longjmp_target);
1652 set_solib_svr4_fetch_link_map_offsets
1653 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1654 tramp_frame_prepend_unwinder (gdbarch, µmips_linux_o32_sigframe);
1655 tramp_frame_prepend_unwinder (gdbarch,
1656 µmips_linux_o32_rt_sigframe);
1657 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
1658 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
1659 set_xml_syscall_file_name (gdbarch, "syscalls/mips-o32-linux.xml");
1662 set_gdbarch_get_longjmp_target (gdbarch,
1663 mips_linux_get_longjmp_target);
1664 set_solib_svr4_fetch_link_map_offsets
1665 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1666 set_gdbarch_long_double_bit (gdbarch, 128);
1667 /* These floatformats should probably be renamed. MIPS uses
1668 the same 128-bit IEEE floating point format that IA-64 uses,
1669 except that the quiet/signalling NaN bit is reversed (GDB
1670 does not distinguish between quiet and signalling NaNs). */
1671 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1672 tramp_frame_prepend_unwinder (gdbarch,
1673 µmips_linux_n32_rt_sigframe);
1674 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
1675 set_xml_syscall_file_name (gdbarch, "syscalls/mips-n32-linux.xml");
1678 set_gdbarch_get_longjmp_target (gdbarch,
1679 mips64_linux_get_longjmp_target);
1680 set_solib_svr4_fetch_link_map_offsets
1681 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1682 set_gdbarch_long_double_bit (gdbarch, 128);
1683 /* These floatformats should probably be renamed. MIPS uses
1684 the same 128-bit IEEE floating point format that IA-64 uses,
1685 except that the quiet/signalling NaN bit is reversed (GDB
1686 does not distinguish between quiet and signalling NaNs). */
1687 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1688 tramp_frame_prepend_unwinder (gdbarch,
1689 µmips_linux_n64_rt_sigframe);
1690 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
1691 set_xml_syscall_file_name (gdbarch, "syscalls/mips-n64-linux.xml");
1697 set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
1699 set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
1701 /* Enable TLS support. */
1702 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1703 svr4_fetch_objfile_link_map);
1705 /* Initialize this lazily, to avoid an initialization order
1706 dependency on solib-svr4.c's _initialize routine. */
1707 if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
1709 mips_svr4_so_ops = svr4_so_ops;
1710 mips_svr4_so_ops.in_dynsym_resolve_code
1711 = mips_linux_in_dynsym_resolve_code;
1713 set_solib_ops (gdbarch, &mips_svr4_so_ops);
1715 set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
1717 set_gdbarch_core_read_description (gdbarch,
1718 mips_linux_core_read_description);
1720 set_gdbarch_iterate_over_regset_sections
1721 (gdbarch, mips_linux_iterate_over_regset_sections);
1723 set_gdbarch_gdb_signal_from_target (gdbarch,
1724 mips_gdb_signal_from_target);
1726 set_gdbarch_gdb_signal_to_target (gdbarch,
1727 mips_gdb_signal_to_target);
1729 tdep->syscall_next_pc = mips_linux_syscall_next_pc;
1733 const struct tdesc_feature *feature;
1735 /* If we have target-described registers, then we can safely
1736 reserve a number for MIPS_RESTART_REGNUM (whether it is
1737 described or not). */
1738 gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
1739 set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1740 set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1742 /* If it's present, then assign it to the reserved number. */
1743 feature = tdesc_find_feature (info.target_desc,
1744 "org.gnu.gdb.mips.linux");
1745 if (feature != NULL)
1746 tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
1751 /* Provide a prototype to silence -Wmissing-prototypes. */
1752 extern initialize_file_ftype _initialize_mips_linux_tdep;
1755 _initialize_mips_linux_tdep (void)
1757 const struct bfd_arch_info *arch_info;
1759 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1761 arch_info = arch_info->next)
1763 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1765 mips_linux_init_abi);