1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001-2014 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"
29 #include "trad-frame.h"
30 #include "tramp-frame.h"
36 #include "target-descriptions.h"
38 #include "mips-linux-tdep.h"
39 #include "glibc-tdep.h"
40 #include "linux-tdep.h"
41 #include "xml-syscall.h"
42 #include "gdb_signals.h"
44 static struct target_so_ops mips_svr4_so_ops;
46 /* This enum represents the signals' numbers on the MIPS
47 architecture. It just contains the signal definitions which are
48 different from the generic implementation.
50 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
51 from the Linux kernel tree. */
55 MIPS_LINUX_SIGEMT = 7,
56 MIPS_LINUX_SIGBUS = 10,
57 MIPS_LINUX_SIGSYS = 12,
58 MIPS_LINUX_SIGUSR1 = 16,
59 MIPS_LINUX_SIGUSR2 = 17,
60 MIPS_LINUX_SIGCHLD = 18,
61 MIPS_LINUX_SIGCLD = MIPS_LINUX_SIGCHLD,
62 MIPS_LINUX_SIGPWR = 19,
63 MIPS_LINUX_SIGWINCH = 20,
64 MIPS_LINUX_SIGURG = 21,
65 MIPS_LINUX_SIGIO = 22,
66 MIPS_LINUX_SIGPOLL = MIPS_LINUX_SIGIO,
67 MIPS_LINUX_SIGSTOP = 23,
68 MIPS_LINUX_SIGTSTP = 24,
69 MIPS_LINUX_SIGCONT = 25,
70 MIPS_LINUX_SIGTTIN = 26,
71 MIPS_LINUX_SIGTTOU = 27,
72 MIPS_LINUX_SIGVTALRM = 28,
73 MIPS_LINUX_SIGPROF = 29,
74 MIPS_LINUX_SIGXCPU = 30,
75 MIPS_LINUX_SIGXFSZ = 31,
77 MIPS_LINUX_SIGRTMIN = 32,
78 MIPS_LINUX_SIGRT64 = 64,
79 MIPS_LINUX_SIGRTMAX = 127,
82 /* Figure out where the longjmp will land.
83 We expect the first arg to be a pointer to the jmp_buf structure
84 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
85 at. The pc is copied into PC. This routine returns 1 on
88 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
89 #define MIPS_LINUX_JB_PC 0
92 mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
95 struct gdbarch *gdbarch = get_frame_arch (frame);
96 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
97 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
99 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
101 if (target_read_memory ((jb_addr
102 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
103 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
106 *pc = extract_unsigned_integer (buf,
107 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
113 /* Transform the bits comprising a 32-bit register to the right size
114 for regcache_raw_supply(). This is needed when mips_isa_regsize()
118 supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
120 struct gdbarch *gdbarch = get_regcache_arch (regcache);
121 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
122 gdb_byte buf[MAX_REGISTER_SIZE];
123 store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
124 extract_signed_integer (addr, 4, byte_order));
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 char zerobuf[MAX_REGISTER_SIZE];
137 struct gdbarch *gdbarch = get_regcache_arch (regcache);
139 memset (zerobuf, 0, MAX_REGISTER_SIZE);
141 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
142 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
144 if (mips_linux_restart_reg_p (gdbarch))
145 supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
147 supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
148 supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
150 supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
152 supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
153 regp + EF_CP0_BADVADDR);
154 supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
155 supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
156 regp + EF_CP0_CAUSE);
158 /* Fill the inaccessible zero register with zero. */
159 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
163 mips_supply_gregset_wrapper (const struct regset *regset,
164 struct regcache *regcache,
165 int regnum, const void *gregs, size_t len)
167 gdb_assert (len == sizeof (mips_elf_gregset_t));
169 mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
172 /* Pack our registers (or one register) into an elf_gregset_t. */
175 mips_fill_gregset (const struct regcache *regcache,
176 mips_elf_gregset_t *gregsetp, int regno)
178 struct gdbarch *gdbarch = get_regcache_arch (regcache);
180 mips_elf_greg_t *regp = *gregsetp;
185 memset (regp, 0, sizeof (mips_elf_gregset_t));
186 for (regi = 1; regi < 32; regi++)
187 mips_fill_gregset (regcache, gregsetp, regi);
188 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
189 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
190 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
191 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
192 mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
193 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
194 mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
198 if (regno > 0 && regno < 32)
200 dst = regp + regno + EF_REG0;
201 regcache_raw_collect (regcache, regno, dst);
205 if (regno == mips_regnum (gdbarch)->lo)
207 else if (regno == mips_regnum (gdbarch)->hi)
209 else if (regno == mips_regnum (gdbarch)->pc)
210 regaddr = EF_CP0_EPC;
211 else if (regno == mips_regnum (gdbarch)->badvaddr)
212 regaddr = EF_CP0_BADVADDR;
213 else if (regno == MIPS_PS_REGNUM)
214 regaddr = EF_CP0_STATUS;
215 else if (regno == mips_regnum (gdbarch)->cause)
216 regaddr = EF_CP0_CAUSE;
217 else if (mips_linux_restart_reg_p (gdbarch)
218 && regno == MIPS_RESTART_REGNUM)
225 dst = regp + regaddr;
226 regcache_raw_collect (regcache, regno, dst);
231 mips_fill_gregset_wrapper (const struct regset *regset,
232 const struct regcache *regcache,
233 int regnum, void *gregs, size_t len)
235 gdb_assert (len == sizeof (mips_elf_gregset_t));
237 mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
240 /* Likewise, unpack an elf_fpregset_t. */
243 mips_supply_fpregset (struct regcache *regcache,
244 const mips_elf_fpregset_t *fpregsetp)
246 struct gdbarch *gdbarch = get_regcache_arch (regcache);
248 char zerobuf[MAX_REGISTER_SIZE];
250 memset (zerobuf, 0, MAX_REGISTER_SIZE);
252 for (regi = 0; regi < 32; regi++)
253 regcache_raw_supply (regcache,
254 gdbarch_fp0_regnum (gdbarch) + regi,
257 regcache_raw_supply (regcache,
258 mips_regnum (gdbarch)->fp_control_status,
261 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
262 regcache_raw_supply (regcache,
263 mips_regnum (gdbarch)->fp_implementation_revision,
268 mips_supply_fpregset_wrapper (const struct regset *regset,
269 struct regcache *regcache,
270 int regnum, const void *gregs, size_t len)
272 gdb_assert (len == sizeof (mips_elf_fpregset_t));
274 mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *)gregs);
277 /* Likewise, pack one or all floating point registers into an
281 mips_fill_fpregset (const struct regcache *regcache,
282 mips_elf_fpregset_t *fpregsetp, int regno)
284 struct gdbarch *gdbarch = get_regcache_arch (regcache);
287 if ((regno >= gdbarch_fp0_regnum (gdbarch))
288 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
290 to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
291 regcache_raw_collect (regcache, regno, to);
293 else if (regno == mips_regnum (gdbarch)->fp_control_status)
295 to = (char *) (*fpregsetp + 32);
296 regcache_raw_collect (regcache, regno, to);
298 else if (regno == -1)
302 for (regi = 0; regi < 32; regi++)
303 mips_fill_fpregset (regcache, fpregsetp,
304 gdbarch_fp0_regnum (gdbarch) + regi);
305 mips_fill_fpregset (regcache, fpregsetp,
306 mips_regnum (gdbarch)->fp_control_status);
311 mips_fill_fpregset_wrapper (const struct regset *regset,
312 const struct regcache *regcache,
313 int regnum, void *gregs, size_t len)
315 gdb_assert (len == sizeof (mips_elf_fpregset_t));
317 mips_fill_fpregset (regcache, (mips_elf_fpregset_t *)gregs, regnum);
320 /* Support for 64-bit ABIs. */
322 /* Figure out where the longjmp will land.
323 We expect the first arg to be a pointer to the jmp_buf structure
324 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
325 at. The pc is copied into PC. This routine returns 1 on
328 /* Details about jmp_buf. */
330 #define MIPS64_LINUX_JB_PC 0
333 mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
336 struct gdbarch *gdbarch = get_frame_arch (frame);
337 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
338 void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
339 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
341 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
343 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
345 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
348 *pc = extract_unsigned_integer (buf,
349 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
355 /* Register set support functions. These operate on standard 64-bit
356 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
357 target will still use the 64-bit format for PTRACE_GETREGS. */
359 /* Supply a 64-bit register. */
362 supply_64bit_reg (struct regcache *regcache, int regnum,
365 struct gdbarch *gdbarch = get_regcache_arch (regcache);
366 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
367 && register_size (gdbarch, regnum) == 4)
368 regcache_raw_supply (regcache, regnum, buf + 4);
370 regcache_raw_supply (regcache, regnum, buf);
373 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
376 mips64_supply_gregset (struct regcache *regcache,
377 const mips64_elf_gregset_t *gregsetp)
380 const mips64_elf_greg_t *regp = *gregsetp;
381 gdb_byte zerobuf[MAX_REGISTER_SIZE];
382 struct gdbarch *gdbarch = get_regcache_arch (regcache);
384 memset (zerobuf, 0, MAX_REGISTER_SIZE);
386 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
387 supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
388 (const gdb_byte *) (regp + regi));
390 if (mips_linux_restart_reg_p (gdbarch))
391 supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
392 (const gdb_byte *) (regp + MIPS64_EF_REG0));
394 supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
395 (const gdb_byte *) (regp + MIPS64_EF_LO));
396 supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
397 (const gdb_byte *) (regp + MIPS64_EF_HI));
399 supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
400 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
401 supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
402 (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
403 supply_64bit_reg (regcache, MIPS_PS_REGNUM,
404 (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
405 supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
406 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
408 /* Fill the inaccessible zero register with zero. */
409 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
413 mips64_supply_gregset_wrapper (const struct regset *regset,
414 struct regcache *regcache,
415 int regnum, const void *gregs, size_t len)
417 gdb_assert (len == sizeof (mips64_elf_gregset_t));
419 mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
422 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
425 mips64_fill_gregset (const struct regcache *regcache,
426 mips64_elf_gregset_t *gregsetp, int regno)
428 struct gdbarch *gdbarch = get_regcache_arch (regcache);
429 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
431 mips64_elf_greg_t *regp = *gregsetp;
436 memset (regp, 0, sizeof (mips64_elf_gregset_t));
437 for (regi = 1; regi < 32; regi++)
438 mips64_fill_gregset (regcache, gregsetp, regi);
439 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
440 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
441 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
442 mips64_fill_gregset (regcache, gregsetp,
443 mips_regnum (gdbarch)->badvaddr);
444 mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
445 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
446 mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
450 if (regno > 0 && regno < 32)
451 regaddr = regno + MIPS64_EF_REG0;
452 else if (regno == mips_regnum (gdbarch)->lo)
453 regaddr = MIPS64_EF_LO;
454 else if (regno == mips_regnum (gdbarch)->hi)
455 regaddr = MIPS64_EF_HI;
456 else if (regno == mips_regnum (gdbarch)->pc)
457 regaddr = MIPS64_EF_CP0_EPC;
458 else if (regno == mips_regnum (gdbarch)->badvaddr)
459 regaddr = MIPS64_EF_CP0_BADVADDR;
460 else if (regno == MIPS_PS_REGNUM)
461 regaddr = MIPS64_EF_CP0_STATUS;
462 else if (regno == mips_regnum (gdbarch)->cause)
463 regaddr = MIPS64_EF_CP0_CAUSE;
464 else if (mips_linux_restart_reg_p (gdbarch)
465 && regno == MIPS_RESTART_REGNUM)
466 regaddr = MIPS64_EF_REG0;
472 gdb_byte buf[MAX_REGISTER_SIZE];
475 regcache_raw_collect (regcache, regno, buf);
476 val = extract_signed_integer (buf, register_size (gdbarch, regno),
478 dst = regp + regaddr;
479 store_signed_integer (dst, 8, byte_order, val);
484 mips64_fill_gregset_wrapper (const struct regset *regset,
485 const struct regcache *regcache,
486 int regnum, void *gregs, size_t len)
488 gdb_assert (len == sizeof (mips64_elf_gregset_t));
490 mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
493 /* Likewise, unpack an elf_fpregset_t. */
496 mips64_supply_fpregset (struct regcache *regcache,
497 const mips64_elf_fpregset_t *fpregsetp)
499 struct gdbarch *gdbarch = get_regcache_arch (regcache);
502 /* See mips_linux_o32_sigframe_init for a description of the
503 peculiar FP register layout. */
504 if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
505 for (regi = 0; regi < 32; regi++)
507 const gdb_byte *reg_ptr
508 = (const gdb_byte *) (*fpregsetp + (regi & ~1));
509 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
511 regcache_raw_supply (regcache,
512 gdbarch_fp0_regnum (gdbarch) + regi,
516 for (regi = 0; regi < 32; regi++)
517 regcache_raw_supply (regcache,
518 gdbarch_fp0_regnum (gdbarch) + regi,
519 (const char *) (*fpregsetp + regi));
521 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
522 (const gdb_byte *) (*fpregsetp + 32));
524 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
525 include it - but the result of PTRACE_GETFPREGS does. The best we
526 can do is to assume that its value is present. */
527 supply_32bit_reg (regcache,
528 mips_regnum (gdbarch)->fp_implementation_revision,
529 (const gdb_byte *) (*fpregsetp + 32) + 4);
533 mips64_supply_fpregset_wrapper (const struct regset *regset,
534 struct regcache *regcache,
535 int regnum, const void *gregs, size_t len)
537 gdb_assert (len == sizeof (mips64_elf_fpregset_t));
539 mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
542 /* Likewise, pack one or all floating point registers into an
546 mips64_fill_fpregset (const struct regcache *regcache,
547 mips64_elf_fpregset_t *fpregsetp, int regno)
549 struct gdbarch *gdbarch = get_regcache_arch (regcache);
550 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
553 if ((regno >= gdbarch_fp0_regnum (gdbarch))
554 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
556 /* See mips_linux_o32_sigframe_init for a description of the
557 peculiar FP register layout. */
558 if (register_size (gdbarch, regno) == 4)
560 int regi = regno - gdbarch_fp0_regnum (gdbarch);
562 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
563 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
565 regcache_raw_collect (regcache, regno, to);
569 to = (gdb_byte *) (*fpregsetp + regno
570 - gdbarch_fp0_regnum (gdbarch));
571 regcache_raw_collect (regcache, regno, to);
574 else if (regno == mips_regnum (gdbarch)->fp_control_status)
576 gdb_byte buf[MAX_REGISTER_SIZE];
579 regcache_raw_collect (regcache, regno, buf);
580 val = extract_signed_integer (buf, register_size (gdbarch, regno),
582 to = (gdb_byte *) (*fpregsetp + 32);
583 store_signed_integer (to, 4, byte_order, val);
585 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
587 gdb_byte buf[MAX_REGISTER_SIZE];
590 regcache_raw_collect (regcache, regno, buf);
591 val = extract_signed_integer (buf, register_size (gdbarch, regno),
593 to = (gdb_byte *) (*fpregsetp + 32) + 4;
594 store_signed_integer (to, 4, byte_order, val);
596 else if (regno == -1)
600 for (regi = 0; regi < 32; regi++)
601 mips64_fill_fpregset (regcache, fpregsetp,
602 gdbarch_fp0_regnum (gdbarch) + regi);
603 mips64_fill_fpregset (regcache, fpregsetp,
604 mips_regnum (gdbarch)->fp_control_status);
605 mips64_fill_fpregset (regcache, fpregsetp,
606 mips_regnum (gdbarch)->fp_implementation_revision);
611 mips64_fill_fpregset_wrapper (const struct regset *regset,
612 const struct regcache *regcache,
613 int regnum, void *gregs, size_t len)
615 gdb_assert (len == sizeof (mips64_elf_fpregset_t));
617 mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
620 static const struct regset mips_linux_gregset =
622 NULL, mips_supply_gregset_wrapper, mips_fill_gregset_wrapper
625 static const struct regset mips64_linux_gregset =
627 NULL, mips64_supply_gregset_wrapper, mips64_fill_gregset_wrapper
630 static const struct regset mips_linux_fpregset =
632 NULL, mips_supply_fpregset_wrapper, mips_fill_fpregset_wrapper
635 static const struct regset mips64_linux_fpregset =
637 NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
640 static const struct regset *
641 mips_linux_regset_from_core_section (struct gdbarch *gdbarch,
642 const char *sect_name, size_t sect_size)
644 mips_elf_gregset_t gregset;
645 mips_elf_fpregset_t fpregset;
646 mips64_elf_gregset_t gregset64;
647 mips64_elf_fpregset_t fpregset64;
649 if (strcmp (sect_name, ".reg") == 0)
651 if (sect_size == sizeof (gregset))
652 return &mips_linux_gregset;
653 else if (sect_size == sizeof (gregset64))
654 return &mips64_linux_gregset;
657 warning (_("wrong size gregset struct in core file"));
660 else if (strcmp (sect_name, ".reg2") == 0)
662 if (sect_size == sizeof (fpregset))
663 return &mips_linux_fpregset;
664 else if (sect_size == sizeof (fpregset64))
665 return &mips64_linux_fpregset;
668 warning (_("wrong size fpregset struct in core file"));
675 static const struct target_desc *
676 mips_linux_core_read_description (struct gdbarch *gdbarch,
677 struct target_ops *target,
680 asection *section = bfd_get_section_by_name (abfd, ".reg");
684 switch (bfd_section_size (abfd, section))
686 case sizeof (mips_elf_gregset_t):
687 return mips_tdesc_gp32;
689 case sizeof (mips64_elf_gregset_t):
690 return mips_tdesc_gp64;
698 /* Check the code at PC for a dynamic linker lazy resolution stub.
699 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
700 section uniformly since version 2.15. If the pc is in that section,
701 then we are in such a stub. Before that ".stub" was used in 32-bit
702 ELF binaries, however we do not bother checking for that since we
703 have never had and that case should be extremely rare these days.
704 Instead we pattern-match on the code generated by GNU ld. They look
712 (with the appropriate doubleword instructions for N64). As any lazy
713 resolution stubs in microMIPS binaries will always be in a
714 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
717 mips_linux_in_dynsym_stub (CORE_ADDR pc)
719 gdb_byte buf[28], *p;
720 ULONGEST insn, insn1;
721 int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
722 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
724 if (in_mips_stubs_section (pc))
727 read_memory (pc - 12, buf, 28);
731 /* ld t9,0x8010(gp) */
736 /* lw t9,0x8010(gp) */
743 insn = extract_unsigned_integer (p, 4, byte_order);
751 insn = extract_unsigned_integer (p + 4, 4, byte_order);
755 if (insn != 0x03e0782d)
761 if (insn != 0x03e07821)
765 insn = extract_unsigned_integer (p + 8, 4, byte_order);
767 if (insn != 0x0320f809)
770 insn = extract_unsigned_integer (p + 12, 4, byte_order);
773 /* daddiu t8,zero,0 */
774 if ((insn & 0xffff0000) != 0x64180000)
779 /* addiu t8,zero,0 */
780 if ((insn & 0xffff0000) != 0x24180000)
787 /* Return non-zero iff PC belongs to the dynamic linker resolution
788 code, a PLT entry, or a lazy binding stub. */
791 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
793 /* Check whether PC is in the dynamic linker. This also checks
794 whether it is in the .plt section, used by non-PIC executables. */
795 if (svr4_in_dynsym_resolve_code (pc))
798 /* Likewise for the stubs. They live in the .MIPS.stubs section these
799 days, so we check if the PC is within, than fall back to a pattern
801 if (mips_linux_in_dynsym_stub (pc))
807 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
808 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
809 implementation of this triggers at "fixup" from the same objfile as
810 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
811 "__dl_runtime_resolve" directly. An unresolved lazy binding
812 stub will point to _dl_runtime_resolve, which will first call
813 __dl_runtime_resolve, and then pass control to the resolved
817 mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
819 struct bound_minimal_symbol resolver;
821 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
823 if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
824 return frame_unwind_caller_pc (get_current_frame ());
826 return glibc_skip_solib_resolver (gdbarch, pc);
829 /* Signal trampoline support. There are four supported layouts for a
830 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
831 n64 rt_sigframe. We handle them all independently; not the most
832 efficient way, but simplest. First, declare all the unwinders. */
834 static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
835 struct frame_info *this_frame,
836 struct trad_frame_cache *this_cache,
839 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
840 struct frame_info *this_frame,
841 struct trad_frame_cache *this_cache,
844 #define MIPS_NR_LINUX 4000
845 #define MIPS_NR_N64_LINUX 5000
846 #define MIPS_NR_N32_LINUX 6000
848 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
849 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
850 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
851 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
853 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
854 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
855 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
856 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
857 #define MIPS_INST_SYSCALL 0x0000000c
859 static const struct tramp_frame mips_linux_o32_sigframe = {
863 { MIPS_INST_LI_V0_SIGRETURN, -1 },
864 { MIPS_INST_SYSCALL, -1 },
865 { TRAMP_SENTINEL_INSN, -1 }
867 mips_linux_o32_sigframe_init
870 static const struct tramp_frame mips_linux_o32_rt_sigframe = {
874 { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
875 { MIPS_INST_SYSCALL, -1 },
876 { TRAMP_SENTINEL_INSN, -1 } },
877 mips_linux_o32_sigframe_init
880 static const struct tramp_frame mips_linux_n32_rt_sigframe = {
884 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
885 { MIPS_INST_SYSCALL, -1 },
886 { TRAMP_SENTINEL_INSN, -1 }
888 mips_linux_n32n64_sigframe_init
891 static const struct tramp_frame mips_linux_n64_rt_sigframe = {
895 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
896 { MIPS_INST_SYSCALL, -1 },
897 { TRAMP_SENTINEL_INSN, -1 }
899 mips_linux_n32n64_sigframe_init
903 /* The unwinder for o32 signal frames. The legacy structures look
907 u32 sf_ass[4]; [argument save space for o32]
908 u32 sf_code[2]; [signal trampoline or fill]
909 struct sigcontext sf_sc;
913 Pre-2.6.12 sigcontext:
916 unsigned int sc_regmask; [Unused]
917 unsigned int sc_status;
918 unsigned long long sc_pc;
919 unsigned long long sc_regs[32];
920 unsigned long long sc_fpregs[32];
921 unsigned int sc_ownedfp;
922 unsigned int sc_fpc_csr;
923 unsigned int sc_fpc_eir; [Unused]
924 unsigned int sc_used_math;
925 unsigned int sc_ssflags; [Unused]
926 [Alignment hole of four bytes]
927 unsigned long long sc_mdhi;
928 unsigned long long sc_mdlo;
930 unsigned int sc_cause; [Unused]
931 unsigned int sc_badvaddr; [Unused]
933 unsigned long sc_sigset[4]; [kernel's sigset_t]
936 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
939 unsigned int sc_regmask; [Unused]
940 unsigned int sc_status; [Unused]
941 unsigned long long sc_pc;
942 unsigned long long sc_regs[32];
943 unsigned long long sc_fpregs[32];
945 unsigned int sc_fpc_csr;
946 unsigned int sc_fpc_eir; [Unused]
947 unsigned int sc_used_math;
949 [Alignment hole of four bytes]
950 unsigned long long sc_mdhi;
951 unsigned long long sc_mdlo;
952 unsigned long sc_hi1;
953 unsigned long sc_lo1;
954 unsigned long sc_hi2;
955 unsigned long sc_lo2;
956 unsigned long sc_hi3;
957 unsigned long sc_lo3;
960 The RT signal frames look like this:
963 u32 rs_ass[4]; [argument save space for o32]
964 u32 rs_code[2] [signal trampoline or fill]
965 struct siginfo rs_info;
966 struct ucontext rs_uc;
970 unsigned long uc_flags;
971 struct ucontext *uc_link;
973 [Alignment hole of four bytes]
974 struct sigcontext uc_mcontext;
979 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
981 #define RTSIGFRAME_SIGINFO_SIZE 128
982 #define STACK_T_SIZE (3 * 4)
983 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
984 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
985 + RTSIGFRAME_SIGINFO_SIZE \
986 + UCONTEXT_SIGCONTEXT_OFFSET)
988 #define SIGCONTEXT_PC (1 * 8)
989 #define SIGCONTEXT_REGS (2 * 8)
990 #define SIGCONTEXT_FPREGS (34 * 8)
991 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
992 #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
993 #define SIGCONTEXT_HI (69 * 8)
994 #define SIGCONTEXT_LO (70 * 8)
995 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
996 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
997 #define SIGCONTEXT_HI1 (71 * 8 + 0)
998 #define SIGCONTEXT_LO1 (71 * 8 + 4)
999 #define SIGCONTEXT_HI2 (72 * 8 + 0)
1000 #define SIGCONTEXT_LO2 (72 * 8 + 4)
1001 #define SIGCONTEXT_HI3 (73 * 8 + 0)
1002 #define SIGCONTEXT_LO3 (73 * 8 + 4)
1004 #define SIGCONTEXT_REG_SIZE 8
1007 mips_linux_o32_sigframe_init (const struct tramp_frame *self,
1008 struct frame_info *this_frame,
1009 struct trad_frame_cache *this_cache,
1012 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1014 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1015 CORE_ADDR sigcontext_base;
1016 const struct mips_regnum *regs = mips_regnum (gdbarch);
1017 CORE_ADDR regs_base;
1019 if (self == &mips_linux_o32_sigframe)
1020 sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
1022 sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
1024 /* I'm not proud of this hack. Eventually we will have the
1025 infrastructure to indicate the size of saved registers on a
1026 per-frame basis, but right now we don't; the kernel saves eight
1027 bytes but we only want four. Use regs_base to access any
1029 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1030 regs_base = sigcontext_base + 4;
1032 regs_base = sigcontext_base;
1034 if (mips_linux_restart_reg_p (gdbarch))
1035 trad_frame_set_reg_addr (this_cache,
1036 (MIPS_RESTART_REGNUM
1037 + gdbarch_num_regs (gdbarch)),
1038 regs_base + SIGCONTEXT_REGS);
1040 for (ireg = 1; ireg < 32; ireg++)
1041 trad_frame_set_reg_addr (this_cache,
1042 (ireg + MIPS_ZERO_REGNUM
1043 + gdbarch_num_regs (gdbarch)),
1044 (regs_base + SIGCONTEXT_REGS
1045 + ireg * SIGCONTEXT_REG_SIZE));
1047 /* The way that floating point registers are saved, unfortunately,
1048 depends on the architecture the kernel is built for. For the r3000 and
1049 tx39, four bytes of each register are at the beginning of each of the
1050 32 eight byte slots. For everything else, the registers are saved
1051 using double precision; only the even-numbered slots are initialized,
1052 and the high bits are the odd-numbered register. Assume the latter
1053 layout, since we can't tell, and it's much more common. Which bits are
1054 the "high" bits depends on endianness. */
1055 for (ireg = 0; ireg < 32; ireg++)
1056 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
1057 trad_frame_set_reg_addr (this_cache,
1058 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1059 (sigcontext_base + SIGCONTEXT_FPREGS + 4
1060 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1062 trad_frame_set_reg_addr (this_cache,
1063 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1064 (sigcontext_base + SIGCONTEXT_FPREGS
1065 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1067 trad_frame_set_reg_addr (this_cache,
1068 regs->pc + gdbarch_num_regs (gdbarch),
1069 regs_base + SIGCONTEXT_PC);
1071 trad_frame_set_reg_addr (this_cache,
1072 (regs->fp_control_status
1073 + gdbarch_num_regs (gdbarch)),
1074 sigcontext_base + SIGCONTEXT_FPCSR);
1076 if (regs->dspctl != -1)
1077 trad_frame_set_reg_addr (this_cache,
1078 regs->dspctl + gdbarch_num_regs (gdbarch),
1079 sigcontext_base + SIGCONTEXT_DSPCTL);
1081 trad_frame_set_reg_addr (this_cache,
1082 regs->hi + gdbarch_num_regs (gdbarch),
1083 regs_base + SIGCONTEXT_HI);
1084 trad_frame_set_reg_addr (this_cache,
1085 regs->lo + gdbarch_num_regs (gdbarch),
1086 regs_base + SIGCONTEXT_LO);
1088 if (regs->dspacc != -1)
1090 trad_frame_set_reg_addr (this_cache,
1091 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1092 sigcontext_base + SIGCONTEXT_HI1);
1093 trad_frame_set_reg_addr (this_cache,
1094 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1095 sigcontext_base + SIGCONTEXT_LO1);
1096 trad_frame_set_reg_addr (this_cache,
1097 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1098 sigcontext_base + SIGCONTEXT_HI2);
1099 trad_frame_set_reg_addr (this_cache,
1100 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1101 sigcontext_base + SIGCONTEXT_LO2);
1102 trad_frame_set_reg_addr (this_cache,
1103 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1104 sigcontext_base + SIGCONTEXT_HI3);
1105 trad_frame_set_reg_addr (this_cache,
1106 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1107 sigcontext_base + SIGCONTEXT_LO3);
1111 trad_frame_set_reg_addr (this_cache,
1112 regs->cause + gdbarch_num_regs (gdbarch),
1113 sigcontext_base + SIGCONTEXT_CAUSE);
1114 trad_frame_set_reg_addr (this_cache,
1115 regs->badvaddr + gdbarch_num_regs (gdbarch),
1116 sigcontext_base + SIGCONTEXT_BADVADDR);
1119 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1120 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1124 /* For N32/N64 things look different. There is no non-rt signal frame.
1126 struct rt_sigframe_n32 {
1127 u32 rs_ass[4]; [ argument save space for o32 ]
1128 u32 rs_code[2]; [ signal trampoline or fill ]
1129 struct siginfo rs_info;
1130 struct ucontextn32 rs_uc;
1133 struct ucontextn32 {
1137 struct sigcontext uc_mcontext;
1138 sigset_t uc_sigmask; [ mask last for extensibility ]
1141 struct rt_sigframe {
1142 u32 rs_ass[4]; [ argument save space for o32 ]
1143 u32 rs_code[2]; [ signal trampoline ]
1144 struct siginfo rs_info;
1145 struct ucontext rs_uc;
1149 unsigned long uc_flags;
1150 struct ucontext *uc_link;
1152 struct sigcontext uc_mcontext;
1153 sigset_t uc_sigmask; [ mask last for extensibility ]
1156 And the sigcontext is different (this is for both n32 and n64):
1159 unsigned long long sc_regs[32];
1160 unsigned long long sc_fpregs[32];
1161 unsigned long long sc_mdhi;
1162 unsigned long long sc_hi1;
1163 unsigned long long sc_hi2;
1164 unsigned long long sc_hi3;
1165 unsigned long long sc_mdlo;
1166 unsigned long long sc_lo1;
1167 unsigned long long sc_lo2;
1168 unsigned long long sc_lo3;
1169 unsigned long long sc_pc;
1170 unsigned int sc_fpc_csr;
1171 unsigned int sc_used_math;
1172 unsigned int sc_dsp;
1173 unsigned int sc_reserved;
1176 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1177 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1181 #define N32_STACK_T_SIZE STACK_T_SIZE
1182 #define N64_STACK_T_SIZE (2 * 8 + 4)
1183 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1184 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1185 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1186 + RTSIGFRAME_SIGINFO_SIZE \
1187 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1188 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1189 + RTSIGFRAME_SIGINFO_SIZE \
1190 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1192 #define N64_SIGCONTEXT_REGS (0 * 8)
1193 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1194 #define N64_SIGCONTEXT_HI (64 * 8)
1195 #define N64_SIGCONTEXT_HI1 (65 * 8)
1196 #define N64_SIGCONTEXT_HI2 (66 * 8)
1197 #define N64_SIGCONTEXT_HI3 (67 * 8)
1198 #define N64_SIGCONTEXT_LO (68 * 8)
1199 #define N64_SIGCONTEXT_LO1 (69 * 8)
1200 #define N64_SIGCONTEXT_LO2 (70 * 8)
1201 #define N64_SIGCONTEXT_LO3 (71 * 8)
1202 #define N64_SIGCONTEXT_PC (72 * 8)
1203 #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1204 #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1206 #define N64_SIGCONTEXT_REG_SIZE 8
1209 mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
1210 struct frame_info *this_frame,
1211 struct trad_frame_cache *this_cache,
1214 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1216 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1217 CORE_ADDR sigcontext_base;
1218 const struct mips_regnum *regs = mips_regnum (gdbarch);
1220 if (self == &mips_linux_n32_rt_sigframe)
1221 sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
1223 sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
1225 if (mips_linux_restart_reg_p (gdbarch))
1226 trad_frame_set_reg_addr (this_cache,
1227 (MIPS_RESTART_REGNUM
1228 + gdbarch_num_regs (gdbarch)),
1229 sigcontext_base + N64_SIGCONTEXT_REGS);
1231 for (ireg = 1; ireg < 32; ireg++)
1232 trad_frame_set_reg_addr (this_cache,
1233 (ireg + MIPS_ZERO_REGNUM
1234 + gdbarch_num_regs (gdbarch)),
1235 (sigcontext_base + N64_SIGCONTEXT_REGS
1236 + ireg * N64_SIGCONTEXT_REG_SIZE));
1238 for (ireg = 0; ireg < 32; ireg++)
1239 trad_frame_set_reg_addr (this_cache,
1240 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1241 (sigcontext_base + N64_SIGCONTEXT_FPREGS
1242 + ireg * N64_SIGCONTEXT_REG_SIZE));
1244 trad_frame_set_reg_addr (this_cache,
1245 regs->pc + gdbarch_num_regs (gdbarch),
1246 sigcontext_base + N64_SIGCONTEXT_PC);
1248 trad_frame_set_reg_addr (this_cache,
1249 (regs->fp_control_status
1250 + gdbarch_num_regs (gdbarch)),
1251 sigcontext_base + N64_SIGCONTEXT_FPCSR);
1253 trad_frame_set_reg_addr (this_cache,
1254 regs->hi + gdbarch_num_regs (gdbarch),
1255 sigcontext_base + N64_SIGCONTEXT_HI);
1256 trad_frame_set_reg_addr (this_cache,
1257 regs->lo + gdbarch_num_regs (gdbarch),
1258 sigcontext_base + N64_SIGCONTEXT_LO);
1260 if (regs->dspacc != -1)
1262 trad_frame_set_reg_addr (this_cache,
1263 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1264 sigcontext_base + N64_SIGCONTEXT_HI1);
1265 trad_frame_set_reg_addr (this_cache,
1266 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1267 sigcontext_base + N64_SIGCONTEXT_LO1);
1268 trad_frame_set_reg_addr (this_cache,
1269 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1270 sigcontext_base + N64_SIGCONTEXT_HI2);
1271 trad_frame_set_reg_addr (this_cache,
1272 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1273 sigcontext_base + N64_SIGCONTEXT_LO2);
1274 trad_frame_set_reg_addr (this_cache,
1275 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1276 sigcontext_base + N64_SIGCONTEXT_HI3);
1277 trad_frame_set_reg_addr (this_cache,
1278 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1279 sigcontext_base + N64_SIGCONTEXT_LO3);
1281 if (regs->dspctl != -1)
1282 trad_frame_set_reg_addr (this_cache,
1283 regs->dspctl + gdbarch_num_regs (gdbarch),
1284 sigcontext_base + N64_SIGCONTEXT_DSPCTL);
1286 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1287 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1290 /* Implement the "write_pc" gdbarch method. */
1293 mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1295 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1297 mips_write_pc (regcache, pc);
1299 /* Clear the syscall restart flag. */
1300 if (mips_linux_restart_reg_p (gdbarch))
1301 regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
1304 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1307 mips_linux_restart_reg_p (struct gdbarch *gdbarch)
1309 /* If we do not have a target description with registers, then
1310 MIPS_RESTART_REGNUM will not be included in the register set. */
1311 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1314 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1315 either be GPR-sized or missing. */
1316 return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
1319 /* When FRAME is at a syscall instruction, return the PC of the next
1320 instruction to be executed. */
1323 mips_linux_syscall_next_pc (struct frame_info *frame)
1325 CORE_ADDR pc = get_frame_pc (frame);
1326 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1328 /* If we are about to make a sigreturn syscall, use the unwinder to
1329 decode the signal frame. */
1330 if (v0 == MIPS_NR_sigreturn
1331 || v0 == MIPS_NR_rt_sigreturn
1332 || v0 == MIPS_NR_N64_rt_sigreturn
1333 || v0 == MIPS_NR_N32_rt_sigreturn)
1334 return frame_unwind_caller_pc (get_current_frame ());
1339 /* Return the current system call's number present in the
1340 v0 register. When the function fails, it returns -1. */
1343 mips_linux_get_syscall_number (struct gdbarch *gdbarch,
1346 struct regcache *regcache = get_thread_regcache (ptid);
1347 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1348 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1349 int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
1350 /* The content of a register */
1355 /* Make sure we're in a known ABI */
1356 gdb_assert (tdep->mips_abi == MIPS_ABI_O32
1357 || tdep->mips_abi == MIPS_ABI_N32
1358 || tdep->mips_abi == MIPS_ABI_N64);
1360 gdb_assert (regsize <= sizeof (buf));
1362 /* Getting the system call number from the register.
1363 syscall number is in v0 or $2. */
1364 regcache_cooked_read (regcache, MIPS_V0_REGNUM, buf);
1366 ret = extract_signed_integer (buf, regsize, byte_order);
1371 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1375 mips_gdb_signal_to_target (struct gdbarch *gdbarch,
1376 enum gdb_signal signal)
1380 case GDB_SIGNAL_EMT:
1381 return MIPS_LINUX_SIGEMT;
1383 case GDB_SIGNAL_BUS:
1384 return MIPS_LINUX_SIGBUS;
1386 case GDB_SIGNAL_SYS:
1387 return MIPS_LINUX_SIGSYS;
1389 case GDB_SIGNAL_USR1:
1390 return MIPS_LINUX_SIGUSR1;
1392 case GDB_SIGNAL_USR2:
1393 return MIPS_LINUX_SIGUSR2;
1395 case GDB_SIGNAL_CHLD:
1396 return MIPS_LINUX_SIGCHLD;
1398 case GDB_SIGNAL_PWR:
1399 return MIPS_LINUX_SIGPWR;
1401 case GDB_SIGNAL_WINCH:
1402 return MIPS_LINUX_SIGWINCH;
1404 case GDB_SIGNAL_URG:
1405 return MIPS_LINUX_SIGURG;
1408 return MIPS_LINUX_SIGIO;
1410 case GDB_SIGNAL_POLL:
1411 return MIPS_LINUX_SIGPOLL;
1413 case GDB_SIGNAL_STOP:
1414 return MIPS_LINUX_SIGSTOP;
1416 case GDB_SIGNAL_TSTP:
1417 return MIPS_LINUX_SIGTSTP;
1419 case GDB_SIGNAL_CONT:
1420 return MIPS_LINUX_SIGCONT;
1422 case GDB_SIGNAL_TTIN:
1423 return MIPS_LINUX_SIGTTIN;
1425 case GDB_SIGNAL_TTOU:
1426 return MIPS_LINUX_SIGTTOU;
1428 case GDB_SIGNAL_VTALRM:
1429 return MIPS_LINUX_SIGVTALRM;
1431 case GDB_SIGNAL_PROF:
1432 return MIPS_LINUX_SIGPROF;
1434 case GDB_SIGNAL_XCPU:
1435 return MIPS_LINUX_SIGXCPU;
1437 case GDB_SIGNAL_XFSZ:
1438 return MIPS_LINUX_SIGXFSZ;
1440 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1441 therefore we have to handle it here. */
1442 case GDB_SIGNAL_REALTIME_32:
1443 return MIPS_LINUX_SIGRTMIN;
1446 if (signal >= GDB_SIGNAL_REALTIME_33
1447 && signal <= GDB_SIGNAL_REALTIME_63)
1449 int offset = signal - GDB_SIGNAL_REALTIME_33;
1451 return MIPS_LINUX_SIGRTMIN + 1 + offset;
1453 else if (signal >= GDB_SIGNAL_REALTIME_64
1454 && signal <= GDB_SIGNAL_REALTIME_127)
1456 int offset = signal - GDB_SIGNAL_REALTIME_64;
1458 return MIPS_LINUX_SIGRT64 + offset;
1461 return linux_gdb_signal_to_target (gdbarch, signal);
1464 /* Translate signals based on MIPS signal values.
1465 Adapted from gdb/common/signals.c. */
1467 static enum gdb_signal
1468 mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
1472 case MIPS_LINUX_SIGEMT:
1473 return GDB_SIGNAL_EMT;
1475 case MIPS_LINUX_SIGBUS:
1476 return GDB_SIGNAL_BUS;
1478 case MIPS_LINUX_SIGSYS:
1479 return GDB_SIGNAL_SYS;
1481 case MIPS_LINUX_SIGUSR1:
1482 return GDB_SIGNAL_USR1;
1484 case MIPS_LINUX_SIGUSR2:
1485 return GDB_SIGNAL_USR2;
1487 case MIPS_LINUX_SIGCHLD:
1488 return GDB_SIGNAL_CHLD;
1490 case MIPS_LINUX_SIGPWR:
1491 return GDB_SIGNAL_PWR;
1493 case MIPS_LINUX_SIGWINCH:
1494 return GDB_SIGNAL_WINCH;
1496 case MIPS_LINUX_SIGURG:
1497 return GDB_SIGNAL_URG;
1499 /* No way to differentiate between SIGIO and SIGPOLL.
1500 Therefore, we just handle the first one. */
1501 case MIPS_LINUX_SIGIO:
1502 return GDB_SIGNAL_IO;
1504 case MIPS_LINUX_SIGSTOP:
1505 return GDB_SIGNAL_STOP;
1507 case MIPS_LINUX_SIGTSTP:
1508 return GDB_SIGNAL_TSTP;
1510 case MIPS_LINUX_SIGCONT:
1511 return GDB_SIGNAL_CONT;
1513 case MIPS_LINUX_SIGTTIN:
1514 return GDB_SIGNAL_TTIN;
1516 case MIPS_LINUX_SIGTTOU:
1517 return GDB_SIGNAL_TTOU;
1519 case MIPS_LINUX_SIGVTALRM:
1520 return GDB_SIGNAL_VTALRM;
1522 case MIPS_LINUX_SIGPROF:
1523 return GDB_SIGNAL_PROF;
1525 case MIPS_LINUX_SIGXCPU:
1526 return GDB_SIGNAL_XCPU;
1528 case MIPS_LINUX_SIGXFSZ:
1529 return GDB_SIGNAL_XFSZ;
1532 if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
1534 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1535 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1536 int offset = signal - MIPS_LINUX_SIGRTMIN;
1539 return GDB_SIGNAL_REALTIME_32;
1540 else if (offset < 32)
1541 return (enum gdb_signal) (offset - 1
1542 + (int) GDB_SIGNAL_REALTIME_33);
1544 return (enum gdb_signal) (offset - 32
1545 + (int) GDB_SIGNAL_REALTIME_64);
1548 return linux_gdb_signal_from_target (gdbarch, signal);
1551 /* Initialize one of the GNU/Linux OS ABIs. */
1554 mips_linux_init_abi (struct gdbarch_info info,
1555 struct gdbarch *gdbarch)
1557 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1558 enum mips_abi abi = mips_abi (gdbarch);
1559 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1561 linux_init_abi (info, gdbarch);
1563 /* Get the syscall number from the arch's register. */
1564 set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);
1569 set_gdbarch_get_longjmp_target (gdbarch,
1570 mips_linux_get_longjmp_target);
1571 set_solib_svr4_fetch_link_map_offsets
1572 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1573 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
1574 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
1575 set_xml_syscall_file_name ("syscalls/mips-o32-linux.xml");
1578 set_gdbarch_get_longjmp_target (gdbarch,
1579 mips_linux_get_longjmp_target);
1580 set_solib_svr4_fetch_link_map_offsets
1581 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1582 set_gdbarch_long_double_bit (gdbarch, 128);
1583 /* These floatformats should probably be renamed. MIPS uses
1584 the same 128-bit IEEE floating point format that IA-64 uses,
1585 except that the quiet/signalling NaN bit is reversed (GDB
1586 does not distinguish between quiet and signalling NaNs). */
1587 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1588 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
1589 set_xml_syscall_file_name ("syscalls/mips-n32-linux.xml");
1592 set_gdbarch_get_longjmp_target (gdbarch,
1593 mips64_linux_get_longjmp_target);
1594 set_solib_svr4_fetch_link_map_offsets
1595 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1596 set_gdbarch_long_double_bit (gdbarch, 128);
1597 /* These floatformats should probably be renamed. MIPS uses
1598 the same 128-bit IEEE floating point format that IA-64 uses,
1599 except that the quiet/signalling NaN bit is reversed (GDB
1600 does not distinguish between quiet and signalling NaNs). */
1601 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1602 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
1603 set_xml_syscall_file_name ("syscalls/mips-n64-linux.xml");
1609 set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
1611 set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
1613 /* Enable TLS support. */
1614 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1615 svr4_fetch_objfile_link_map);
1617 /* Initialize this lazily, to avoid an initialization order
1618 dependency on solib-svr4.c's _initialize routine. */
1619 if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
1621 mips_svr4_so_ops = svr4_so_ops;
1622 mips_svr4_so_ops.in_dynsym_resolve_code
1623 = mips_linux_in_dynsym_resolve_code;
1625 set_solib_ops (gdbarch, &mips_svr4_so_ops);
1627 set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
1629 set_gdbarch_core_read_description (gdbarch,
1630 mips_linux_core_read_description);
1632 set_gdbarch_regset_from_core_section (gdbarch,
1633 mips_linux_regset_from_core_section);
1635 set_gdbarch_gdb_signal_from_target (gdbarch,
1636 mips_gdb_signal_from_target);
1638 set_gdbarch_gdb_signal_to_target (gdbarch,
1639 mips_gdb_signal_to_target);
1641 tdep->syscall_next_pc = mips_linux_syscall_next_pc;
1645 const struct tdesc_feature *feature;
1647 /* If we have target-described registers, then we can safely
1648 reserve a number for MIPS_RESTART_REGNUM (whether it is
1649 described or not). */
1650 gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
1651 set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1652 set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1654 /* If it's present, then assign it to the reserved number. */
1655 feature = tdesc_find_feature (info.target_desc,
1656 "org.gnu.gdb.mips.linux");
1657 if (feature != NULL)
1658 tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
1663 /* Provide a prototype to silence -Wmissing-prototypes. */
1664 extern initialize_file_ftype _initialize_mips_linux_tdep;
1667 _initialize_mips_linux_tdep (void)
1669 const struct bfd_arch_info *arch_info;
1671 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1673 arch_info = arch_info->next)
1675 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1677 mips_linux_init_abi);