GDB (xrefs)
Loading...
Searching...
No Matches
mips-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux on MIPS processors.
2
3 Copyright (C) 2001-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "target.h"
23#include "solib-svr4.h"
24#include "osabi.h"
25#include "mips-tdep.h"
26#include "frame.h"
27#include "regcache.h"
28#include "trad-frame.h"
29#include "tramp-frame.h"
30#include "gdbtypes.h"
31#include "objfiles.h"
32#include "solib.h"
33#include "solist.h"
34#include "symtab.h"
35#include "target-descriptions.h"
36#include "regset.h"
37#include "mips-linux-tdep.h"
38#include "glibc-tdep.h"
39#include "linux-tdep.h"
40#include "xml-syscall.h"
41#include "gdbsupport/gdb_signals.h"
42
43#include "features/mips-linux.c"
47
49
50/* This enum represents the signals' numbers on the MIPS
51 architecture. It just contains the signal definitions which are
52 different from the generic implementation.
53
54 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
55 from the Linux kernel tree. */
56
57enum
58 {
80
84 };
85
86/* Figure out where the longjmp will land.
87 We expect the first arg to be a pointer to the jmp_buf structure
88 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
89 at. The pc is copied into PC. This routine returns 1 on
90 success. */
91
92#define MIPS_LINUX_JB_ELEMENT_SIZE 4
93#define MIPS_LINUX_JB_PC 0
94
95static int
97{
98 CORE_ADDR jb_addr;
99 struct gdbarch *gdbarch = get_frame_arch (frame);
100 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
101 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
102
104
105 if (target_read_memory ((jb_addr
107 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
108 return 0;
109
110 *pc = extract_unsigned_integer (buf,
111 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
112 byte_order);
113
114 return 1;
115}
116
117/* Transform the bits comprising a 32-bit register to the right size
118 for regcache_raw_supply(). This is needed when mips_isa_regsize()
119 is 8. */
120
121static void
122supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
123{
124 regcache->raw_supply_integer (regnum, (const gdb_byte *) addr, 4, true);
125}
126
127/* Unpack an elf_gregset_t into GDB's register cache. */
128
129void
131 const mips_elf_gregset_t *gregsetp)
132{
133 int regi;
134 const mips_elf_greg_t *regp = *gregsetp;
135 struct gdbarch *gdbarch = regcache->arch ();
136
137 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
138 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
139
142
145
147 regp + EF_CP0_EPC);
149 regp + EF_CP0_BADVADDR);
152 regp + EF_CP0_CAUSE);
153
154 /* Fill the inaccessible zero register with zero. */
156}
157
158static void
160 struct regcache *regcache,
161 int regnum, const void *gregs, size_t len)
162{
163 gdb_assert (len >= sizeof (mips_elf_gregset_t));
164
166}
167
168/* Pack our registers (or one register) into an elf_gregset_t. */
169
170void
172 mips_elf_gregset_t *gregsetp, int regno)
173{
174 struct gdbarch *gdbarch = regcache->arch ();
175 int regaddr, regi;
176 mips_elf_greg_t *regp = *gregsetp;
177 void *dst;
178
179 if (regno == -1)
180 {
181 memset (regp, 0, sizeof (mips_elf_gregset_t));
182 for (regi = 1; regi < 32; regi++)
183 mips_fill_gregset (regcache, gregsetp, regi);
187 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
189 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
191 return;
192 }
193
194 if (regno > 0 && regno < 32)
195 {
196 dst = regp + regno + EF_REG0;
197 regcache->raw_collect (regno, dst);
198 return;
199 }
200
201 if (regno == mips_regnum (gdbarch)->lo)
202 regaddr = EF_LO;
203 else if (regno == mips_regnum (gdbarch)->hi)
204 regaddr = EF_HI;
205 else if (regno == mips_regnum (gdbarch)->pc)
206 regaddr = EF_CP0_EPC;
207 else if (regno == mips_regnum (gdbarch)->badvaddr)
208 regaddr = EF_CP0_BADVADDR;
209 else if (regno == MIPS_PS_REGNUM)
210 regaddr = EF_CP0_STATUS;
211 else if (regno == mips_regnum (gdbarch)->cause)
212 regaddr = EF_CP0_CAUSE;
214 && regno == MIPS_RESTART_REGNUM)
215 regaddr = EF_REG0;
216 else
217 regaddr = -1;
218
219 if (regaddr != -1)
220 {
221 dst = regp + regaddr;
222 regcache->raw_collect (regno, dst);
223 }
224}
225
226static void
228 const struct regcache *regcache,
229 int regnum, void *gregs, size_t len)
230{
231 gdb_assert (len >= sizeof (mips_elf_gregset_t));
232
234}
235
236/* Support for 64-bit ABIs. */
237
238/* Figure out where the longjmp will land.
239 We expect the first arg to be a pointer to the jmp_buf structure
240 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
241 at. The pc is copied into PC. This routine returns 1 on
242 success. */
243
244/* Details about jmp_buf. */
245
246#define MIPS64_LINUX_JB_PC 0
247
248static int
250{
251 CORE_ADDR jb_addr;
252 struct gdbarch *gdbarch = get_frame_arch (frame);
253 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
254 gdb_byte *buf
255 = (gdb_byte *) alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
256 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
257
259
260 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
261 buf,
262 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
263 return 0;
264
265 *pc = extract_unsigned_integer (buf,
266 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
267 byte_order);
268
269 return 1;
270}
271
272/* Register set support functions. These operate on standard 64-bit
273 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
274 target will still use the 64-bit format for PTRACE_GETREGS. */
275
276/* Supply a 64-bit register. */
277
278static void
280 const gdb_byte *buf)
281{
282 struct gdbarch *gdbarch = regcache->arch ();
283 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
284 && register_size (gdbarch, regnum) == 4)
285 regcache->raw_supply (regnum, buf + 4);
286 else
287 regcache->raw_supply (regnum, buf);
288}
289
290/* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
291
292void
294 const mips64_elf_gregset_t *gregsetp)
295{
296 int regi;
297 const mips64_elf_greg_t *regp = *gregsetp;
298 struct gdbarch *gdbarch = regcache->arch ();
299
300 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
302 (const gdb_byte *) (regp + regi));
303
306 (const gdb_byte *) (regp + MIPS64_EF_REG0));
307
309 (const gdb_byte *) (regp + MIPS64_EF_LO));
311 (const gdb_byte *) (regp + MIPS64_EF_HI));
312
314 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
316 (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
318 (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
320 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
321
322 /* Fill the inaccessible zero register with zero. */
324}
325
326static void
328 struct regcache *regcache,
329 int regnum, const void *gregs, size_t len)
330{
331 gdb_assert (len >= sizeof (mips64_elf_gregset_t));
332
334}
335
336/* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
337
338void
340 mips64_elf_gregset_t *gregsetp, int regno)
341{
342 struct gdbarch *gdbarch = regcache->arch ();
343 int regaddr, regi;
344 mips64_elf_greg_t *regp = *gregsetp;
345 void *dst;
346
347 if (regno == -1)
348 {
349 memset (regp, 0, sizeof (mips64_elf_gregset_t));
350 for (regi = 1; regi < 32; regi++)
351 mips64_fill_gregset (regcache, gregsetp, regi);
355 mips64_fill_gregset (regcache, gregsetp,
356 mips_regnum (gdbarch)->badvaddr);
358 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
360 return;
361 }
362
363 if (regno > 0 && regno < 32)
364 regaddr = regno + MIPS64_EF_REG0;
365 else if (regno == mips_regnum (gdbarch)->lo)
366 regaddr = MIPS64_EF_LO;
367 else if (regno == mips_regnum (gdbarch)->hi)
368 regaddr = MIPS64_EF_HI;
369 else if (regno == mips_regnum (gdbarch)->pc)
370 regaddr = MIPS64_EF_CP0_EPC;
371 else if (regno == mips_regnum (gdbarch)->badvaddr)
372 regaddr = MIPS64_EF_CP0_BADVADDR;
373 else if (regno == MIPS_PS_REGNUM)
374 regaddr = MIPS64_EF_CP0_STATUS;
375 else if (regno == mips_regnum (gdbarch)->cause)
376 regaddr = MIPS64_EF_CP0_CAUSE;
378 && regno == MIPS_RESTART_REGNUM)
379 regaddr = MIPS64_EF_REG0;
380 else
381 regaddr = -1;
382
383 if (regaddr != -1)
384 {
385 dst = regp + regaddr;
386 regcache->raw_collect_integer (regno, (gdb_byte *) dst, 8, true);
387 }
388}
389
390static void
392 const struct regcache *regcache,
393 int regnum, void *gregs, size_t len)
394{
395 gdb_assert (len >= sizeof (mips64_elf_gregset_t));
396
398}
399
400/* Likewise, unpack an elf_fpregset_t. Linux only uses even-numbered
401 FPR slots in the Status.FR=0 mode, storing even-odd FPR pairs as the
402 SDC1 instruction would. When run on MIPS I architecture processors
403 all FPR slots used to be used, unusually, holding the respective FPRs
404 in the first 4 bytes, but that was corrected for consistency, with
405 `linux-mips.org' (LMO) commit 42533948caac ("Major pile of FP emulator
406 changes."), the fix corrected with LMO commit 849fa7a50dff ("R3k FPU
407 ptrace() handling fixes."), and then broken and fixed over and over
408 again, until last time fixed with commit 80cbfad79096 ("MIPS: Correct
409 MIPS I FP context layout"). */
410
411void
413 const mips64_elf_fpregset_t *fpregsetp)
414{
415 struct gdbarch *gdbarch = regcache->arch ();
416 int regi;
417
419 for (regi = 0; regi < 32; regi++)
420 {
421 const gdb_byte *reg_ptr
422 = (const gdb_byte *) (*fpregsetp + (regi & ~1));
423 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
424 reg_ptr += 4;
425 regcache->raw_supply (gdbarch_fp0_regnum (gdbarch) + regi, reg_ptr);
426 }
427 else
428 for (regi = 0; regi < 32; regi++)
430 (const char *) (*fpregsetp + regi));
431
432 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
433 (const gdb_byte *) (*fpregsetp + 32));
434
435 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
436 include it - but the result of PTRACE_GETFPREGS does. The best we
437 can do is to assume that its value is present. */
439 mips_regnum (gdbarch)->fp_implementation_revision,
440 (const gdb_byte *) (*fpregsetp + 32) + 4);
441}
442
443static void
445 struct regcache *regcache,
446 int regnum, const void *gregs, size_t len)
447{
448 gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
449
451}
452
453/* Likewise, pack one or all floating point registers into an
454 elf_fpregset_t. See `mips_supply_fpregset' for an explanation
455 of the layout. */
456
457void
459 mips64_elf_fpregset_t *fpregsetp, int regno)
460{
461 struct gdbarch *gdbarch = regcache->arch ();
462 gdb_byte *to;
463
464 if ((regno >= gdbarch_fp0_regnum (gdbarch))
465 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
466 {
467 if (register_size (gdbarch, regno) == 4)
468 {
469 int regi = regno - gdbarch_fp0_regnum (gdbarch);
470
471 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
472 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
473 to += 4;
474 regcache->raw_collect (regno, to);
475 }
476 else
477 {
478 to = (gdb_byte *) (*fpregsetp + regno
480 regcache->raw_collect (regno, to);
481 }
482 }
483 else if (regno == mips_regnum (gdbarch)->fp_control_status)
484 {
485 to = (gdb_byte *) (*fpregsetp + 32);
486 regcache->raw_collect_integer (regno, to, 4, true);
487 }
489 {
490 to = (gdb_byte *) (*fpregsetp + 32) + 4;
491 regcache->raw_collect_integer (regno, to, 4, true);
492 }
493 else if (regno == -1)
494 {
495 int regi;
496
497 for (regi = 0; regi < 32; regi++)
498 mips64_fill_fpregset (regcache, fpregsetp,
499 gdbarch_fp0_regnum (gdbarch) + regi);
500 mips64_fill_fpregset (regcache, fpregsetp,
501 mips_regnum (gdbarch)->fp_control_status);
502 mips64_fill_fpregset (regcache, fpregsetp,
503 mips_regnum (gdbarch)->fp_implementation_revision);
504 }
505}
506
507static void
509 const struct regcache *regcache,
510 int regnum, void *gregs, size_t len)
511{
512 gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
513
515}
516
521
526
531
532static void
535 void *cb_data,
536 const struct regcache *regcache)
537{
539 {
540 cb (".reg", sizeof (mips_elf_gregset_t), sizeof (mips_elf_gregset_t),
541 &mips_linux_gregset, NULL, cb_data);
542 cb (".reg2", sizeof (mips64_elf_fpregset_t),
544 NULL, cb_data);
545 }
546 else
547 {
548 cb (".reg", sizeof (mips64_elf_gregset_t), sizeof (mips64_elf_gregset_t),
549 &mips64_linux_gregset, NULL, cb_data);
550 cb (".reg2", sizeof (mips64_elf_fpregset_t),
552 NULL, cb_data);
553 }
554}
555
556static const struct target_desc *
558 struct target_ops *target,
559 bfd *abfd)
560{
561 asection *section = bfd_get_section_by_name (abfd, ".reg");
562 if (! section)
563 return NULL;
564
565 switch (bfd_section_size (section))
566 {
567 case sizeof (mips_elf_gregset_t):
568 return mips_tdesc_gp32;
569
570 case sizeof (mips64_elf_gregset_t):
571 return mips_tdesc_gp64;
572
573 default:
574 return NULL;
575 }
576}
577
578
579/* Check the code at PC for a dynamic linker lazy resolution stub.
580 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
581 section uniformly since version 2.15. If the pc is in that section,
582 then we are in such a stub. Before that ".stub" was used in 32-bit
583 ELF binaries, however we do not bother checking for that since we
584 have never had and that case should be extremely rare these days.
585 Instead we pattern-match on the code generated by GNU ld. They look
586 like this:
587
588 lw t9,0x8010(gp)
589 addu t7,ra
590 jalr t9,ra
591 addiu t8,zero,INDEX
592
593 (with the appropriate doubleword instructions for N64). As any lazy
594 resolution stubs in microMIPS binaries will always be in a
595 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
596
597static int
599{
600 gdb_byte buf[28], *p;
601 ULONGEST insn, insn1;
602 int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
603 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
604
605 if (in_mips_stubs_section (pc))
606 return 1;
607
608 read_memory (pc - 12, buf, 28);
609
610 if (n64)
611 {
612 /* ld t9,0x8010(gp) */
613 insn1 = 0xdf998010;
614 }
615 else
616 {
617 /* lw t9,0x8010(gp) */
618 insn1 = 0x8f998010;
619 }
620
621 p = buf + 12;
622 while (p >= buf)
623 {
624 insn = extract_unsigned_integer (p, 4, byte_order);
625 if (insn == insn1)
626 break;
627 p -= 4;
628 }
629 if (p < buf)
630 return 0;
631
632 insn = extract_unsigned_integer (p + 4, 4, byte_order);
633 if (n64)
634 {
635 /* 'daddu t7,ra' or 'or t7, ra, zero'*/
636 if (insn != 0x03e0782d && insn != 0x03e07825)
637 return 0;
638 }
639 else
640 {
641 /* 'addu t7,ra' or 'or t7, ra, zero'*/
642 if (insn != 0x03e07821 && insn != 0x03e07825)
643 return 0;
644 }
645
646 insn = extract_unsigned_integer (p + 8, 4, byte_order);
647 /* jalr t9,ra */
648 if (insn != 0x0320f809)
649 return 0;
650
651 insn = extract_unsigned_integer (p + 12, 4, byte_order);
652 if (n64)
653 {
654 /* daddiu t8,zero,0 */
655 if ((insn & 0xffff0000) != 0x64180000)
656 return 0;
657 }
658 else
659 {
660 /* addiu t8,zero,0 */
661 if ((insn & 0xffff0000) != 0x24180000)
662 return 0;
663 }
664
665 return 1;
666}
667
668/* Return non-zero iff PC belongs to the dynamic linker resolution
669 code, a PLT entry, or a lazy binding stub. */
670
671static int
673{
674 /* Check whether PC is in the dynamic linker. This also checks
675 whether it is in the .plt section, used by non-PIC executables. */
677 return 1;
678
679 /* Likewise for the stubs. They live in the .MIPS.stubs section these
680 days, so we check if the PC is within, than fall back to a pattern
681 match. */
683 return 1;
684
685 return 0;
686}
687
688/* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
689 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
690 implementation of this triggers at "fixup" from the same objfile as
691 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
692 "__dl_runtime_resolve" directly. An unresolved lazy binding
693 stub will point to _dl_runtime_resolve, which will first call
694 __dl_runtime_resolve, and then pass control to the resolved
695 function. */
696
697static CORE_ADDR
699{
700 struct bound_minimal_symbol resolver;
701
702 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
703
704 if (resolver.minsym && resolver.value_address () == pc)
706
708}
709
710/* Signal trampoline support. There are four supported layouts for a
711 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
712 n64 rt_sigframe. We handle them all independently; not the most
713 efficient way, but simplest. First, declare all the unwinders. */
714
715static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
716 frame_info_ptr this_frame,
717 struct trad_frame_cache *this_cache,
718 CORE_ADDR func);
719
720static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
721 frame_info_ptr this_frame,
722 struct trad_frame_cache *this_cache,
723 CORE_ADDR func);
724
725static int mips_linux_sigframe_validate (const struct tramp_frame *self,
726 frame_info_ptr this_frame,
727 CORE_ADDR *pc);
728
729static int micromips_linux_sigframe_validate (const struct tramp_frame *self,
730 frame_info_ptr this_frame,
731 CORE_ADDR *pc);
732
733#define MIPS_NR_LINUX 4000
734#define MIPS_NR_N64_LINUX 5000
735#define MIPS_NR_N32_LINUX 6000
736
737#define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
738#define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
739#define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
740#define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
741
742#define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
743#define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
744#define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
745#define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
746#define MIPS_INST_SYSCALL 0x0000000c
747
748#define MICROMIPS_INST_LI_V0 0x3040
749#define MICROMIPS_INST_POOL32A 0x0000
750#define MICROMIPS_INST_SYSCALL 0x8b7c
751
754 4,
755 {
756 { MIPS_INST_LI_V0_SIGRETURN, ULONGEST_MAX },
757 { MIPS_INST_SYSCALL, ULONGEST_MAX },
758 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
759 },
762};
763
766 4,
767 {
768 { MIPS_INST_LI_V0_RT_SIGRETURN, ULONGEST_MAX },
769 { MIPS_INST_SYSCALL, ULONGEST_MAX },
770 { TRAMP_SENTINEL_INSN, ULONGEST_MAX } },
773};
774
777 4,
778 {
779 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, ULONGEST_MAX },
780 { MIPS_INST_SYSCALL, ULONGEST_MAX },
781 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
782 },
785};
786
789 4,
790 {
791 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, ULONGEST_MAX },
792 { MIPS_INST_SYSCALL, ULONGEST_MAX },
793 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
794 },
797};
798
801 2,
802 {
803 { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
804 { MIPS_NR_sigreturn, ULONGEST_MAX },
805 { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
806 { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
807 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
808 },
811};
812
815 2,
816 {
817 { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
818 { MIPS_NR_rt_sigreturn, ULONGEST_MAX },
819 { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
820 { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
821 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
822 },
825};
826
829 2,
830 {
831 { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
832 { MIPS_NR_N32_rt_sigreturn, ULONGEST_MAX },
833 { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
834 { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
835 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
836 },
839};
840
843 2,
844 {
845 { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
846 { MIPS_NR_N64_rt_sigreturn, ULONGEST_MAX },
847 { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
848 { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
849 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
850 },
853};
854
855/* The unwinder for o32 signal frames. The legacy structures look
856 like this:
857
858 struct sigframe {
859 u32 sf_ass[4]; [argument save space for o32]
860 u32 sf_code[2]; [signal trampoline or fill]
861 struct sigcontext sf_sc;
862 sigset_t sf_mask;
863 };
864
865 Pre-2.6.12 sigcontext:
866
867 struct sigcontext {
868 unsigned int sc_regmask; [Unused]
869 unsigned int sc_status;
870 unsigned long long sc_pc;
871 unsigned long long sc_regs[32];
872 unsigned long long sc_fpregs[32];
873 unsigned int sc_ownedfp;
874 unsigned int sc_fpc_csr;
875 unsigned int sc_fpc_eir; [Unused]
876 unsigned int sc_used_math;
877 unsigned int sc_ssflags; [Unused]
878 [Alignment hole of four bytes]
879 unsigned long long sc_mdhi;
880 unsigned long long sc_mdlo;
881
882 unsigned int sc_cause; [Unused]
883 unsigned int sc_badvaddr; [Unused]
884
885 unsigned long sc_sigset[4]; [kernel's sigset_t]
886 };
887
888 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
889
890 struct sigcontext {
891 unsigned int sc_regmask; [Unused]
892 unsigned int sc_status; [Unused]
893 unsigned long long sc_pc;
894 unsigned long long sc_regs[32];
895 unsigned long long sc_fpregs[32];
896 unsigned int sc_acx;
897 unsigned int sc_fpc_csr;
898 unsigned int sc_fpc_eir; [Unused]
899 unsigned int sc_used_math;
900 unsigned int sc_dsp;
901 [Alignment hole of four bytes]
902 unsigned long long sc_mdhi;
903 unsigned long long sc_mdlo;
904 unsigned long sc_hi1;
905 unsigned long sc_lo1;
906 unsigned long sc_hi2;
907 unsigned long sc_lo2;
908 unsigned long sc_hi3;
909 unsigned long sc_lo3;
910 };
911
912 The RT signal frames look like this:
913
914 struct rt_sigframe {
915 u32 rs_ass[4]; [argument save space for o32]
916 u32 rs_code[2] [signal trampoline or fill]
917 struct siginfo rs_info;
918 struct ucontext rs_uc;
919 };
920
921 struct ucontext {
922 unsigned long uc_flags;
923 struct ucontext *uc_link;
924 stack_t uc_stack;
925 [Alignment hole of four bytes]
926 struct sigcontext uc_mcontext;
927 sigset_t uc_sigmask;
928 }; */
929
930#define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
931
932#define RTSIGFRAME_SIGINFO_SIZE 128
933#define STACK_T_SIZE (3 * 4)
934#define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
935#define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
936 + RTSIGFRAME_SIGINFO_SIZE \
937 + UCONTEXT_SIGCONTEXT_OFFSET)
938
939#define SIGCONTEXT_PC (1 * 8)
940#define SIGCONTEXT_REGS (2 * 8)
941#define SIGCONTEXT_FPREGS (34 * 8)
942#define SIGCONTEXT_FPCSR (66 * 8 + 4)
943#define SIGCONTEXT_DSPCTL (68 * 8 + 0)
944#define SIGCONTEXT_HI (69 * 8)
945#define SIGCONTEXT_LO (70 * 8)
946#define SIGCONTEXT_CAUSE (71 * 8 + 0)
947#define SIGCONTEXT_BADVADDR (71 * 8 + 4)
948#define SIGCONTEXT_HI1 (71 * 8 + 0)
949#define SIGCONTEXT_LO1 (71 * 8 + 4)
950#define SIGCONTEXT_HI2 (72 * 8 + 0)
951#define SIGCONTEXT_LO2 (72 * 8 + 4)
952#define SIGCONTEXT_HI3 (73 * 8 + 0)
953#define SIGCONTEXT_LO3 (73 * 8 + 4)
954
955#define SIGCONTEXT_REG_SIZE 8
956
957static void
959 frame_info_ptr this_frame,
960 struct trad_frame_cache *this_cache,
961 CORE_ADDR func)
962{
963 struct gdbarch *gdbarch = get_frame_arch (this_frame);
964 int ireg;
965 CORE_ADDR frame_sp = get_frame_sp (this_frame);
966 CORE_ADDR sigcontext_base;
967 const struct mips_regnum *regs = mips_regnum (gdbarch);
968 CORE_ADDR regs_base;
969
970 if (self == &mips_linux_o32_sigframe
972 sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
973 else
974 sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
975
976 /* I'm not proud of this hack. Eventually we will have the
977 infrastructure to indicate the size of saved registers on a
978 per-frame basis, but right now we don't; the kernel saves eight
979 bytes but we only want four. Use regs_base to access any
980 64-bit fields. */
981 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
982 regs_base = sigcontext_base + 4;
983 else
984 regs_base = sigcontext_base;
985
987 trad_frame_set_reg_addr (this_cache,
990 regs_base + SIGCONTEXT_REGS);
991
992 for (ireg = 1; ireg < 32; ireg++)
993 trad_frame_set_reg_addr (this_cache,
994 (ireg + MIPS_ZERO_REGNUM
996 (regs_base + SIGCONTEXT_REGS
997 + ireg * SIGCONTEXT_REG_SIZE));
998
999 for (ireg = 0; ireg < 32; ireg++)
1000 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
1001 trad_frame_set_reg_addr (this_cache,
1002 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1003 (sigcontext_base + SIGCONTEXT_FPREGS + 4
1004 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1005 else
1006 trad_frame_set_reg_addr (this_cache,
1007 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1008 (sigcontext_base + SIGCONTEXT_FPREGS
1009 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
1010
1011 trad_frame_set_reg_addr (this_cache,
1012 regs->pc + gdbarch_num_regs (gdbarch),
1013 regs_base + SIGCONTEXT_PC);
1014
1015 trad_frame_set_reg_addr (this_cache,
1016 (regs->fp_control_status
1018 sigcontext_base + SIGCONTEXT_FPCSR);
1019
1020 if (regs->dspctl != -1)
1021 trad_frame_set_reg_addr (this_cache,
1023 sigcontext_base + SIGCONTEXT_DSPCTL);
1024
1025 trad_frame_set_reg_addr (this_cache,
1026 regs->hi + gdbarch_num_regs (gdbarch),
1027 regs_base + SIGCONTEXT_HI);
1028 trad_frame_set_reg_addr (this_cache,
1029 regs->lo + gdbarch_num_regs (gdbarch),
1030 regs_base + SIGCONTEXT_LO);
1031
1032 if (regs->dspacc != -1)
1033 {
1034 trad_frame_set_reg_addr (this_cache,
1035 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1036 sigcontext_base + SIGCONTEXT_HI1);
1037 trad_frame_set_reg_addr (this_cache,
1038 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1039 sigcontext_base + SIGCONTEXT_LO1);
1040 trad_frame_set_reg_addr (this_cache,
1041 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1042 sigcontext_base + SIGCONTEXT_HI2);
1043 trad_frame_set_reg_addr (this_cache,
1044 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1045 sigcontext_base + SIGCONTEXT_LO2);
1046 trad_frame_set_reg_addr (this_cache,
1047 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1048 sigcontext_base + SIGCONTEXT_HI3);
1049 trad_frame_set_reg_addr (this_cache,
1050 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1051 sigcontext_base + SIGCONTEXT_LO3);
1052 }
1053 else
1054 {
1055 trad_frame_set_reg_addr (this_cache,
1056 regs->cause + gdbarch_num_regs (gdbarch),
1057 sigcontext_base + SIGCONTEXT_CAUSE);
1058 trad_frame_set_reg_addr (this_cache,
1060 sigcontext_base + SIGCONTEXT_BADVADDR);
1061 }
1062
1063 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1064 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1065}
1066
1067/* For N32/N64 things look different. There is no non-rt signal frame.
1068
1069 struct rt_sigframe_n32 {
1070 u32 rs_ass[4]; [ argument save space for o32 ]
1071 u32 rs_code[2]; [ signal trampoline or fill ]
1072 struct siginfo rs_info;
1073 struct ucontextn32 rs_uc;
1074 };
1075
1076 struct ucontextn32 {
1077 u32 uc_flags;
1078 s32 uc_link;
1079 stack32_t uc_stack;
1080 struct sigcontext uc_mcontext;
1081 sigset_t uc_sigmask; [ mask last for extensibility ]
1082 };
1083
1084 struct rt_sigframe {
1085 u32 rs_ass[4]; [ argument save space for o32 ]
1086 u32 rs_code[2]; [ signal trampoline ]
1087 struct siginfo rs_info;
1088 struct ucontext rs_uc;
1089 };
1090
1091 struct ucontext {
1092 unsigned long uc_flags;
1093 struct ucontext *uc_link;
1094 stack_t uc_stack;
1095 struct sigcontext uc_mcontext;
1096 sigset_t uc_sigmask; [ mask last for extensibility ]
1097 };
1098
1099 And the sigcontext is different (this is for both n32 and n64):
1100
1101 struct sigcontext {
1102 unsigned long long sc_regs[32];
1103 unsigned long long sc_fpregs[32];
1104 unsigned long long sc_mdhi;
1105 unsigned long long sc_hi1;
1106 unsigned long long sc_hi2;
1107 unsigned long long sc_hi3;
1108 unsigned long long sc_mdlo;
1109 unsigned long long sc_lo1;
1110 unsigned long long sc_lo2;
1111 unsigned long long sc_lo3;
1112 unsigned long long sc_pc;
1113 unsigned int sc_fpc_csr;
1114 unsigned int sc_used_math;
1115 unsigned int sc_dsp;
1116 unsigned int sc_reserved;
1117 };
1118
1119 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1120 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1121 included too. */
1122
1123#define N32_STACK_T_SIZE STACK_T_SIZE
1124#define N64_STACK_T_SIZE (2 * 8 + 4)
1125#define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1126#define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1127#define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1128 + RTSIGFRAME_SIGINFO_SIZE \
1129 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1130#define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1131 + RTSIGFRAME_SIGINFO_SIZE \
1132 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1133
1134#define N64_SIGCONTEXT_REGS (0 * 8)
1135#define N64_SIGCONTEXT_FPREGS (32 * 8)
1136#define N64_SIGCONTEXT_HI (64 * 8)
1137#define N64_SIGCONTEXT_HI1 (65 * 8)
1138#define N64_SIGCONTEXT_HI2 (66 * 8)
1139#define N64_SIGCONTEXT_HI3 (67 * 8)
1140#define N64_SIGCONTEXT_LO (68 * 8)
1141#define N64_SIGCONTEXT_LO1 (69 * 8)
1142#define N64_SIGCONTEXT_LO2 (70 * 8)
1143#define N64_SIGCONTEXT_LO3 (71 * 8)
1144#define N64_SIGCONTEXT_PC (72 * 8)
1145#define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1146#define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1147
1148#define N64_SIGCONTEXT_REG_SIZE 8
1149
1150static void
1152 frame_info_ptr this_frame,
1153 struct trad_frame_cache *this_cache,
1154 CORE_ADDR func)
1155{
1156 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1157 int ireg;
1158 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1159 CORE_ADDR sigcontext_base;
1160 const struct mips_regnum *regs = mips_regnum (gdbarch);
1161
1162 if (self == &mips_linux_n32_rt_sigframe
1164 sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
1165 else
1166 sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
1167
1169 trad_frame_set_reg_addr (this_cache,
1172 sigcontext_base + N64_SIGCONTEXT_REGS);
1173
1174 for (ireg = 1; ireg < 32; ireg++)
1175 trad_frame_set_reg_addr (this_cache,
1176 (ireg + MIPS_ZERO_REGNUM
1178 (sigcontext_base + N64_SIGCONTEXT_REGS
1179 + ireg * N64_SIGCONTEXT_REG_SIZE));
1180
1181 for (ireg = 0; ireg < 32; ireg++)
1182 trad_frame_set_reg_addr (this_cache,
1183 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1184 (sigcontext_base + N64_SIGCONTEXT_FPREGS
1185 + ireg * N64_SIGCONTEXT_REG_SIZE));
1186
1187 trad_frame_set_reg_addr (this_cache,
1188 regs->pc + gdbarch_num_regs (gdbarch),
1189 sigcontext_base + N64_SIGCONTEXT_PC);
1190
1191 trad_frame_set_reg_addr (this_cache,
1192 (regs->fp_control_status
1194 sigcontext_base + N64_SIGCONTEXT_FPCSR);
1195
1196 trad_frame_set_reg_addr (this_cache,
1197 regs->hi + gdbarch_num_regs (gdbarch),
1198 sigcontext_base + N64_SIGCONTEXT_HI);
1199 trad_frame_set_reg_addr (this_cache,
1200 regs->lo + gdbarch_num_regs (gdbarch),
1201 sigcontext_base + N64_SIGCONTEXT_LO);
1202
1203 if (regs->dspacc != -1)
1204 {
1205 trad_frame_set_reg_addr (this_cache,
1206 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1207 sigcontext_base + N64_SIGCONTEXT_HI1);
1208 trad_frame_set_reg_addr (this_cache,
1209 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1210 sigcontext_base + N64_SIGCONTEXT_LO1);
1211 trad_frame_set_reg_addr (this_cache,
1212 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1213 sigcontext_base + N64_SIGCONTEXT_HI2);
1214 trad_frame_set_reg_addr (this_cache,
1215 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1216 sigcontext_base + N64_SIGCONTEXT_LO2);
1217 trad_frame_set_reg_addr (this_cache,
1218 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1219 sigcontext_base + N64_SIGCONTEXT_HI3);
1220 trad_frame_set_reg_addr (this_cache,
1221 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1222 sigcontext_base + N64_SIGCONTEXT_LO3);
1223 }
1224 if (regs->dspctl != -1)
1225 trad_frame_set_reg_addr (this_cache,
1227 sigcontext_base + N64_SIGCONTEXT_DSPCTL);
1228
1229 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1230 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
1231}
1232
1233/* Implement struct tramp_frame's "validate" method for standard MIPS code. */
1234
1235static int
1237 frame_info_ptr this_frame,
1238 CORE_ADDR *pc)
1239{
1240 return mips_pc_is_mips (*pc);
1241}
1242
1243/* Implement struct tramp_frame's "validate" method for microMIPS code. */
1244
1245static int
1247 frame_info_ptr this_frame,
1248 CORE_ADDR *pc)
1249{
1250 if (mips_pc_is_micromips (get_frame_arch (this_frame), *pc))
1251 {
1253 return 1;
1254 }
1255 else
1256 return 0;
1257}
1258
1259/* Implement the "write_pc" gdbarch method. */
1260
1261static void
1263{
1264 struct gdbarch *gdbarch = regcache->arch ();
1265
1266 mips_write_pc (regcache, pc);
1267
1268 /* Clear the syscall restart flag. */
1271}
1272
1273/* Return 1 if MIPS_RESTART_REGNUM is usable. */
1274
1275int
1277{
1278 /* If we do not have a target description with registers, then
1279 MIPS_RESTART_REGNUM will not be included in the register set. */
1281 return 0;
1282
1283 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1284 either be GPR-sized or missing. */
1286}
1287
1288/* When FRAME is at a syscall instruction, return the PC of the next
1289 instruction to be executed. */
1290
1291static CORE_ADDR
1293{
1294 CORE_ADDR pc = get_frame_pc (frame);
1295 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1296
1297 /* If we are about to make a sigreturn syscall, use the unwinder to
1298 decode the signal frame. */
1299 if (v0 == MIPS_NR_sigreturn
1300 || v0 == MIPS_NR_rt_sigreturn
1302 || v0 == MIPS_NR_N32_rt_sigreturn)
1304
1305 return pc + 4;
1306}
1307
1308/* Return the current system call's number present in the
1309 v0 register. When the function fails, it returns -1. */
1310
1311static LONGEST
1313 thread_info *thread)
1314{
1315 struct regcache *regcache = get_thread_regcache (thread);
1316 mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
1317 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1318 int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
1319 /* The content of a register */
1320 gdb_byte buf[8];
1321 /* The result */
1322 LONGEST ret;
1323
1324 /* Make sure we're in a known ABI */
1325 gdb_assert (tdep->mips_abi == MIPS_ABI_O32
1326 || tdep->mips_abi == MIPS_ABI_N32
1327 || tdep->mips_abi == MIPS_ABI_N64);
1328
1329 gdb_assert (regsize <= sizeof (buf));
1330
1331 /* Getting the system call number from the register.
1332 syscall number is in v0 or $2. */
1334
1335 ret = extract_signed_integer (buf, regsize, byte_order);
1336
1337 return ret;
1338}
1339
1340/* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1341 gdbarch.h. */
1342
1343static int
1345 enum gdb_signal signal)
1346{
1347 switch (signal)
1348 {
1349 case GDB_SIGNAL_EMT:
1350 return MIPS_LINUX_SIGEMT;
1351
1352 case GDB_SIGNAL_BUS:
1353 return MIPS_LINUX_SIGBUS;
1354
1355 case GDB_SIGNAL_SYS:
1356 return MIPS_LINUX_SIGSYS;
1357
1358 case GDB_SIGNAL_USR1:
1359 return MIPS_LINUX_SIGUSR1;
1360
1361 case GDB_SIGNAL_USR2:
1362 return MIPS_LINUX_SIGUSR2;
1363
1364 case GDB_SIGNAL_CHLD:
1365 return MIPS_LINUX_SIGCHLD;
1366
1367 case GDB_SIGNAL_PWR:
1368 return MIPS_LINUX_SIGPWR;
1369
1370 case GDB_SIGNAL_WINCH:
1371 return MIPS_LINUX_SIGWINCH;
1372
1373 case GDB_SIGNAL_URG:
1374 return MIPS_LINUX_SIGURG;
1375
1376 case GDB_SIGNAL_IO:
1377 return MIPS_LINUX_SIGIO;
1378
1379 case GDB_SIGNAL_POLL:
1380 return MIPS_LINUX_SIGPOLL;
1381
1382 case GDB_SIGNAL_STOP:
1383 return MIPS_LINUX_SIGSTOP;
1384
1385 case GDB_SIGNAL_TSTP:
1386 return MIPS_LINUX_SIGTSTP;
1387
1388 case GDB_SIGNAL_CONT:
1389 return MIPS_LINUX_SIGCONT;
1390
1391 case GDB_SIGNAL_TTIN:
1392 return MIPS_LINUX_SIGTTIN;
1393
1394 case GDB_SIGNAL_TTOU:
1395 return MIPS_LINUX_SIGTTOU;
1396
1397 case GDB_SIGNAL_VTALRM:
1398 return MIPS_LINUX_SIGVTALRM;
1399
1400 case GDB_SIGNAL_PROF:
1401 return MIPS_LINUX_SIGPROF;
1402
1403 case GDB_SIGNAL_XCPU:
1404 return MIPS_LINUX_SIGXCPU;
1405
1406 case GDB_SIGNAL_XFSZ:
1407 return MIPS_LINUX_SIGXFSZ;
1408
1409 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1410 therefore we have to handle it here. */
1411 case GDB_SIGNAL_REALTIME_32:
1412 return MIPS_LINUX_SIGRTMIN;
1413 }
1414
1415 if (signal >= GDB_SIGNAL_REALTIME_33
1416 && signal <= GDB_SIGNAL_REALTIME_63)
1417 {
1418 int offset = signal - GDB_SIGNAL_REALTIME_33;
1419
1420 return MIPS_LINUX_SIGRTMIN + 1 + offset;
1421 }
1422 else if (signal >= GDB_SIGNAL_REALTIME_64
1423 && signal <= GDB_SIGNAL_REALTIME_127)
1424 {
1425 int offset = signal - GDB_SIGNAL_REALTIME_64;
1426
1427 return MIPS_LINUX_SIGRT64 + offset;
1428 }
1429
1430 return linux_gdb_signal_to_target (gdbarch, signal);
1431}
1432
1433/* Translate signals based on MIPS signal values.
1434 Adapted from gdb/gdbsupport/signals.c. */
1435
1436static enum gdb_signal
1438{
1439 switch (signal)
1440 {
1441 case MIPS_LINUX_SIGEMT:
1442 return GDB_SIGNAL_EMT;
1443
1444 case MIPS_LINUX_SIGBUS:
1445 return GDB_SIGNAL_BUS;
1446
1447 case MIPS_LINUX_SIGSYS:
1448 return GDB_SIGNAL_SYS;
1449
1450 case MIPS_LINUX_SIGUSR1:
1451 return GDB_SIGNAL_USR1;
1452
1453 case MIPS_LINUX_SIGUSR2:
1454 return GDB_SIGNAL_USR2;
1455
1456 case MIPS_LINUX_SIGCHLD:
1457 return GDB_SIGNAL_CHLD;
1458
1459 case MIPS_LINUX_SIGPWR:
1460 return GDB_SIGNAL_PWR;
1461
1463 return GDB_SIGNAL_WINCH;
1464
1465 case MIPS_LINUX_SIGURG:
1466 return GDB_SIGNAL_URG;
1467
1468 /* No way to differentiate between SIGIO and SIGPOLL.
1469 Therefore, we just handle the first one. */
1470 case MIPS_LINUX_SIGIO:
1471 return GDB_SIGNAL_IO;
1472
1473 case MIPS_LINUX_SIGSTOP:
1474 return GDB_SIGNAL_STOP;
1475
1476 case MIPS_LINUX_SIGTSTP:
1477 return GDB_SIGNAL_TSTP;
1478
1479 case MIPS_LINUX_SIGCONT:
1480 return GDB_SIGNAL_CONT;
1481
1482 case MIPS_LINUX_SIGTTIN:
1483 return GDB_SIGNAL_TTIN;
1484
1485 case MIPS_LINUX_SIGTTOU:
1486 return GDB_SIGNAL_TTOU;
1487
1489 return GDB_SIGNAL_VTALRM;
1490
1491 case MIPS_LINUX_SIGPROF:
1492 return GDB_SIGNAL_PROF;
1493
1494 case MIPS_LINUX_SIGXCPU:
1495 return GDB_SIGNAL_XCPU;
1496
1497 case MIPS_LINUX_SIGXFSZ:
1498 return GDB_SIGNAL_XFSZ;
1499 }
1500
1501 if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
1502 {
1503 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1504 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1505 int offset = signal - MIPS_LINUX_SIGRTMIN;
1506
1507 if (offset == 0)
1508 return GDB_SIGNAL_REALTIME_32;
1509 else if (offset < 32)
1510 return (enum gdb_signal) (offset - 1
1511 + (int) GDB_SIGNAL_REALTIME_33);
1512 else
1513 return (enum gdb_signal) (offset - 32
1514 + (int) GDB_SIGNAL_REALTIME_64);
1515 }
1516
1517 return linux_gdb_signal_from_target (gdbarch, signal);
1518}
1519
1520/* Initialize one of the GNU/Linux OS ABIs. */
1521
1522static void
1524 struct gdbarch *gdbarch)
1525{
1526 mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
1527 enum mips_abi abi = mips_abi (gdbarch);
1528 struct tdesc_arch_data *tdesc_data = info.tdesc_data;
1529
1530 linux_init_abi (info, gdbarch, 0);
1531
1532 /* Get the syscall number from the arch's register. */
1534
1535 switch (abi)
1536 {
1537 case MIPS_ABI_O32:
1547 set_xml_syscall_file_name (gdbarch, "syscalls/mips-o32-linux.xml");
1548 break;
1549 case MIPS_ABI_N32:
1559 set_xml_syscall_file_name (gdbarch, "syscalls/mips-n32-linux.xml");
1560 break;
1561 case MIPS_ABI_N64:
1571 set_xml_syscall_file_name (gdbarch, "syscalls/mips-n64-linux.xml");
1572 break;
1573 default:
1574 break;
1575 }
1576
1578
1580
1581 /* Enable TLS support. */
1584
1585 /* Initialize this lazily, to avoid an initialization order
1586 dependency on solib-svr4.c's _initialize routine. */
1588 {
1592 }
1594
1596
1599
1602
1605
1608
1610
1611 if (tdesc_data)
1612 {
1613 const struct tdesc_feature *feature;
1614
1615 /* If we have target-described registers, then we can safely
1616 reserve a number for MIPS_RESTART_REGNUM (whether it is
1617 described or not). */
1621
1622 /* If it's present, then assign it to the reserved number. */
1623 feature = tdesc_find_feature (info.target_desc,
1624 "org.gnu.gdb.mips.linux");
1625 if (feature != NULL)
1627 "restart");
1628 }
1629}
1630
1632void
1634{
1635 const struct bfd_arch_info *arch_info;
1636
1637 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1638 arch_info != NULL;
1639 arch_info = arch_info->next)
1640 {
1641 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1644 }
1645
1646 /* Initialize the standard target descriptions. */
1651}
int regnum
struct gdbarch * target_gdbarch(void)
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
gdbarch * arch() const
Definition regcache.c:231
void raw_collect_integer(int regnum, gdb_byte *addr, int addr_len, bool is_signed) const
Definition regcache.c:1143
void raw_supply_integer(int regnum, const gdb_byte *addr, int addr_len, bool is_signed)
Definition regcache.c:1090
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
void raw_supply_zeroed(int regnum)
Definition regcache.c:1110
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:238
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:465
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR frame_unwind_caller_pc(frame_info_ptr this_frame)
Definition frame.c:1042
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
CORE_ADDR get_frame_sp(frame_info_ptr this_frame)
Definition frame.c:3115
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:736
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
frame_info_ptr get_current_frame(void)
Definition frame.c:1670
@ SIGTRAMP_FRAME
Definition frame.h:198
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype *software_single_step)
void set_gdbarch_core_read_description(struct gdbarch *gdbarch, gdbarch_core_read_description_ftype *core_read_description)
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype *write_pc)
void set_gdbarch_get_longjmp_target(struct gdbarch *gdbarch, gdbarch_get_longjmp_target_ftype *get_longjmp_target)
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number)
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition gdbarch.c:1930
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition gdbarch.c:1663
void set_gdbarch_gdb_signal_from_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_from_target_ftype *gdb_signal_from_target)
const struct target_desc * gdbarch_target_desc(struct gdbarch *gdbarch)
Definition gdbarch.c:1423
void set_gdbarch_num_pseudo_regs(struct gdbarch *gdbarch, int num_pseudo_regs)
Definition gdbarch.c:1958
void set_gdbarch_gdb_signal_to_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_to_target_ftype *gdb_signal_to_target)
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
int gdbarch_fp0_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2088
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition gdbarch.c:1941
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition gdbarch.c:1646
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1722
void set_gdbarch_so_ops(struct gdbarch *gdbarch, const struct target_so_ops *so_ops)
Definition gdbarch.c:3380
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
const struct floatformat * floatformats_ieee_quad[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:93
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition glibc-tdep.c:38
link_map_offsets * linux_lp64_fetch_link_map_offsets()
int linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
enum gdb_signal linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
link_map_offsets * linux_ilp32_fetch_link_map_offsets()
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
static void initialize_tdesc_mips_dsp_linux(void)
void mips_fill_gregset(const struct regcache *regcache, mips_elf_gregset_t *gregsetp, int regno)
#define MIPS64_LINUX_JB_PC
static const struct tramp_frame micromips_linux_o32_rt_sigframe
#define MIPS_NR_sigreturn
static void mips64_supply_gregset_wrapper(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static const struct tramp_frame mips_linux_o32_rt_sigframe
#define MIPS_NR_rt_sigreturn
#define MICROMIPS_INST_SYSCALL
static void mips64_fill_gregset_wrapper(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
#define SIGCONTEXT_HI2
static CORE_ADDR mips_linux_skip_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
static void supply_64bit_reg(struct regcache *regcache, int regnum, const gdb_byte *buf)
#define SIGCONTEXT_HI1
static const struct tramp_frame mips_linux_o32_sigframe
#define N32_SIGFRAME_SIGCONTEXT_OFFSET
static void mips_fill_gregset_wrapper(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
#define SIGCONTEXT_REGS
#define MIPS_INST_LI_V0_N32_RT_SIGRETURN
static int mips_linux_in_dynsym_stub(CORE_ADDR pc)
@ MIPS_LINUX_SIGPOLL
@ MIPS_LINUX_SIGSTOP
@ MIPS_LINUX_SIGRTMAX
@ MIPS_LINUX_SIGTTIN
@ MIPS_LINUX_SIGRT64
@ MIPS_LINUX_SIGVTALRM
@ MIPS_LINUX_SIGRTMIN
@ MIPS_LINUX_SIGURG
@ MIPS_LINUX_SIGXCPU
@ MIPS_LINUX_SIGEMT
@ MIPS_LINUX_SIGPWR
@ MIPS_LINUX_SIGWINCH
@ MIPS_LINUX_SIGCONT
@ MIPS_LINUX_SIGUSR2
@ MIPS_LINUX_SIGIO
@ MIPS_LINUX_SIGUSR1
@ MIPS_LINUX_SIGPROF
@ MIPS_LINUX_SIGTTOU
@ MIPS_LINUX_SIGXFSZ
@ MIPS_LINUX_SIGCLD
@ MIPS_LINUX_SIGTSTP
@ MIPS_LINUX_SIGSYS
@ MIPS_LINUX_SIGBUS
@ MIPS_LINUX_SIGCHLD
#define N64_SIGCONTEXT_LO
#define MIPS_INST_LI_V0_RT_SIGRETURN
#define SIGCONTEXT_BADVADDR
static enum gdb_signal mips_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
#define SIGCONTEXT_LO2
#define MIPS_LINUX_JB_ELEMENT_SIZE
static struct target_so_ops mips_svr4_so_ops
void mips_supply_gregset(struct regcache *regcache, const mips_elf_gregset_t *gregsetp)
static const struct tramp_frame micromips_linux_o32_sigframe
#define N64_SIGCONTEXT_FPCSR
static int mips_linux_in_dynsym_resolve_code(CORE_ADDR pc)
int mips_linux_restart_reg_p(struct gdbarch *gdbarch)
#define N64_SIGCONTEXT_HI
void mips64_fill_gregset(const struct regcache *regcache, mips64_elf_gregset_t *gregsetp, int regno)
#define N64_SIGCONTEXT_LO2
static void mips_supply_gregset_wrapper(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static const struct tramp_frame micromips_linux_n64_rt_sigframe
static void mips_linux_n32n64_sigframe_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
#define N64_SIGCONTEXT_REG_SIZE
static int mips_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
#define MIPS_INST_LI_V0_SIGRETURN
#define SIGCONTEXT_LO1
#define N64_SIGCONTEXT_LO1
static CORE_ADDR mips_linux_syscall_next_pc(frame_info_ptr frame)
#define N64_SIGCONTEXT_LO3
static void mips_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
#define N64_SIGFRAME_SIGCONTEXT_OFFSET
#define MICROMIPS_INST_LI_V0
static int micromips_linux_sigframe_validate(const struct tramp_frame *self, frame_info_ptr this_frame, CORE_ADDR *pc)
#define N64_SIGCONTEXT_REGS
#define N64_SIGCONTEXT_FPREGS
#define SIGCONTEXT_HI
static void mips64_fill_fpregset_wrapper(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
#define SIGCONTEXT_REG_SIZE
#define SIGCONTEXT_LO3
#define RTSIGFRAME_SIGCONTEXT_OFFSET
static void supply_32bit_reg(struct regcache *regcache, int regnum, const void *addr)
#define N64_SIGCONTEXT_HI3
#define MIPS_NR_N64_rt_sigreturn
static const struct tramp_frame mips_linux_n32_rt_sigframe
void mips64_fill_fpregset(const struct regcache *regcache, mips64_elf_fpregset_t *fpregsetp, int regno)
#define SIGCONTEXT_FPCSR
#define N64_SIGCONTEXT_DSPCTL
#define MIPS_INST_LI_V0_N64_RT_SIGRETURN
#define SIGCONTEXT_CAUSE
static void mips_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
#define MIPS_LINUX_JB_PC
static const struct tramp_frame mips_linux_n64_rt_sigframe
#define SIGCONTEXT_DSPCTL
void mips64_supply_fpregset(struct regcache *regcache, const mips64_elf_fpregset_t *fpregsetp)
#define SIGCONTEXT_HI3
#define SIGCONTEXT_PC
static void mips_linux_o32_sigframe_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
void _initialize_mips_linux_tdep()
static void mips_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
#define MICROMIPS_INST_POOL32A
static const struct regset mips64_linux_gregset
static int mips64_linux_get_longjmp_target(frame_info_ptr frame, CORE_ADDR *pc)
static const struct regset mips_linux_gregset
#define SIGFRAME_SIGCONTEXT_OFFSET
#define MIPS_INST_SYSCALL
void mips64_supply_gregset(struct regcache *regcache, const mips64_elf_gregset_t *gregsetp)
#define MIPS_NR_N32_rt_sigreturn
#define N64_SIGCONTEXT_HI1
static int mips_linux_sigframe_validate(const struct tramp_frame *self, frame_info_ptr this_frame, CORE_ADDR *pc)
static LONGEST mips_linux_get_syscall_number(struct gdbarch *gdbarch, thread_info *thread)
#define SIGCONTEXT_LO
static const struct target_desc * mips_linux_core_read_description(struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd)
static const struct regset mips64_linux_fpregset
static void mips64_supply_fpregset_wrapper(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
#define N64_SIGCONTEXT_PC
#define N64_SIGCONTEXT_HI2
#define SIGCONTEXT_FPREGS
static int mips_linux_get_longjmp_target(frame_info_ptr frame, CORE_ADDR *pc)
static const struct tramp_frame micromips_linux_n32_rt_sigframe
mips64_elf_greg_t mips64_elf_gregset_t[MIPS64_ELF_NGREG]
#define MIPS64_EF_CP0_BADVADDR
unsigned char mips_elf_greg_t[4]
#define EF_CP0_BADVADDR
#define EF_CP0_STATUS
#define MIPS64_EF_CP0_EPC
#define MIPS64_EF_REG31
mips_elf_greg_t mips_elf_gregset_t[ELF_NGREG]
#define EF_CP0_EPC
#define EF_REG0
#define MIPS64_EF_CP0_STATUS
#define EF_HI
#define MIPS64_EF_CP0_CAUSE
#define EF_CP0_CAUSE
unsigned char mips64_elf_greg_t[8]
#define EF_LO
#define MIPS64_EF_LO
#define MIPS64_EF_HI
@ MIPS_RESTART_REGNUM
mips64_elf_fpreg_t mips64_elf_fpregset_t[MIPS64_ELF_NFPREG]
#define EF_REG31
#define MIPS64_EF_REG0
static void initialize_tdesc_mips_linux(void)
Definition mips-linux.c:10
int mips_pc_is_mips(CORE_ADDR memaddr)
Definition mips-tdep.c:1208
struct target_desc * mips_tdesc_gp64
Definition mips-tdep.c:213
void mips_write_pc(struct regcache *regcache, CORE_ADDR pc)
Definition mips-tdep.c:1453
struct target_desc * mips_tdesc_gp32
Definition mips-tdep.c:212
std::vector< CORE_ADDR > mips_software_single_step(struct regcache *regcache)
Definition mips-tdep.c:4210
const struct mips_regnum * mips_regnum(struct gdbarch *gdbarch)
Definition mips-tdep.c:228
int mips_pc_is_micromips(struct gdbarch *gdbarch, CORE_ADDR memaddr)
Definition mips-tdep.c:1244
CORE_ADDR mips_unmake_compact_addr(CORE_ADDR addr)
Definition mips-tdep.c:403
@ MIPS_V0_REGNUM
Definition mips-tdep.h:137
@ MIPS_ZERO_REGNUM
Definition mips-tdep.h:135
@ MIPS_PS_REGNUM
Definition mips-tdep.h:144
@ MIPS_A0_REGNUM
Definition mips-tdep.h:138
mips_abi
Definition mips-tdep.h:30
@ MIPS_ABI_N32
Definition mips-tdep.h:32
@ MIPS_ABI_O32
Definition mips-tdep.h:33
@ MIPS_ABI_N64
Definition mips-tdep.h:34
static int in_mips_stubs_section(CORE_ADDR pc)
Definition mips-tdep.h:199
static void initialize_tdesc_mips64_dsp_linux(void)
static void initialize_tdesc_mips64_linux(void)
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition osabi.c:146
@ GDB_OSABI_LINUX
Definition osabi.h:32
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition regcache.c:825
void(* func)(remote_target *remote, char *)
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
const struct target_so_ops svr4_so_ops
int svr4_in_dynsym_resolve_code(CORE_ADDR pc)
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
CORE_ADDR(* syscall_next_pc)(frame_info_ptr frame)
Definition mips-tdep.h:128
int fp_implementation_revision
Definition mips-tdep.h:74
int fp_control_status
Definition mips-tdep.h:75
int(* in_dynsym_resolve_code)(CORE_ADDR pc)
Definition solist.h:121
const struct tdesc_feature * tdesc_find_feature(const struct target_desc *target_desc, const char *name)
int tdesc_numbered_register(const struct tdesc_feature *feature, struct tdesc_arch_data *data, int regno, const char *name)
static const registry< gdbarch >::key< tdesc_arch_data > tdesc_data
int tdesc_has_registers(const struct target_desc *target_desc)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition trad-frame.c:110
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition trad-frame.c:220
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
#define TRAMP_SENTINEL_INSN
Definition tramp-frame.h:44
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition xml-syscall.c:50