1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001-2024 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/>. */
20 #include "extract-store-integer.h"
23 #include "solib-svr4.h"
25 #include "mips-tdep.h"
28 #include "trad-frame.h"
29 #include "tramp-frame.h"
35 #include "target-descriptions.h"
37 #include "mips-linux-tdep.h"
38 #include "glibc-tdep.h"
39 #include "linux-tdep.h"
40 #include "xml-syscall.h"
41 #include "gdbsupport/gdb_signals.h"
44 #include "features/mips-linux.c"
45 #include "features/mips-dsp-linux.c"
46 #include "features/mips64-linux.c"
47 #include "features/mips64-dsp-linux.c"
49 static solib_ops mips_svr4_so_ops
;
51 /* This enum represents the signals' numbers on the MIPS
52 architecture. It just contains the signal definitions which are
53 different from the generic implementation.
55 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
56 from the Linux kernel tree. */
60 MIPS_LINUX_SIGEMT
= 7,
61 MIPS_LINUX_SIGBUS
= 10,
62 MIPS_LINUX_SIGSYS
= 12,
63 MIPS_LINUX_SIGUSR1
= 16,
64 MIPS_LINUX_SIGUSR2
= 17,
65 MIPS_LINUX_SIGCHLD
= 18,
66 MIPS_LINUX_SIGCLD
= MIPS_LINUX_SIGCHLD
,
67 MIPS_LINUX_SIGPWR
= 19,
68 MIPS_LINUX_SIGWINCH
= 20,
69 MIPS_LINUX_SIGURG
= 21,
70 MIPS_LINUX_SIGIO
= 22,
71 MIPS_LINUX_SIGPOLL
= MIPS_LINUX_SIGIO
,
72 MIPS_LINUX_SIGSTOP
= 23,
73 MIPS_LINUX_SIGTSTP
= 24,
74 MIPS_LINUX_SIGCONT
= 25,
75 MIPS_LINUX_SIGTTIN
= 26,
76 MIPS_LINUX_SIGTTOU
= 27,
77 MIPS_LINUX_SIGVTALRM
= 28,
78 MIPS_LINUX_SIGPROF
= 29,
79 MIPS_LINUX_SIGXCPU
= 30,
80 MIPS_LINUX_SIGXFSZ
= 31,
82 MIPS_LINUX_SIGRTMIN
= 32,
83 MIPS_LINUX_SIGRT64
= 64,
84 MIPS_LINUX_SIGRTMAX
= 127,
87 /* Figure out where the longjmp will land.
88 We expect the first arg to be a pointer to the jmp_buf structure
89 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
90 at. The pc is copied into PC. This routine returns 1 on
93 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
94 #define MIPS_LINUX_JB_PC 0
97 mips_linux_get_longjmp_target (const frame_info_ptr
&frame
, CORE_ADDR
*pc
)
100 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
101 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
102 gdb::byte_vector
buf (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
104 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
106 if (target_read_memory ((jb_addr
107 + MIPS_LINUX_JB_PC
* MIPS_LINUX_JB_ELEMENT_SIZE
),
109 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
112 *pc
= extract_unsigned_integer (buf
.data (),
113 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
119 /* Transform the bits comprising a 32-bit register to the right size
120 for regcache_raw_supply(). This is needed when mips_isa_regsize()
124 supply_32bit_reg (struct regcache
*regcache
, int regnum
, const void *addr
)
126 regcache
->raw_supply_integer (regnum
, (const gdb_byte
*) addr
, 4, true);
129 /* Unpack an elf_gregset_t into GDB's register cache. */
132 mips_supply_gregset (struct regcache
*regcache
,
133 const mips_elf_gregset_t
*gregsetp
)
136 const mips_elf_greg_t
*regp
= *gregsetp
;
137 struct gdbarch
*gdbarch
= regcache
->arch ();
139 for (regi
= EF_REG0
+ 1; regi
<= EF_REG31
; regi
++)
140 supply_32bit_reg (regcache
, regi
- EF_REG0
, regp
+ regi
);
142 if (mips_linux_restart_reg_p (gdbarch
))
143 supply_32bit_reg (regcache
, MIPS_RESTART_REGNUM
, regp
+ EF_REG0
);
145 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->lo
, regp
+ EF_LO
);
146 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->hi
, regp
+ EF_HI
);
148 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
150 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
151 regp
+ EF_CP0_BADVADDR
);
152 supply_32bit_reg (regcache
, MIPS_PS_REGNUM
, regp
+ EF_CP0_STATUS
);
153 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
154 regp
+ EF_CP0_CAUSE
);
156 /* Fill the inaccessible zero register with zero. */
157 regcache
->raw_supply_zeroed (MIPS_ZERO_REGNUM
);
161 mips_supply_gregset_wrapper (const struct regset
*regset
,
162 struct regcache
*regcache
,
163 int regnum
, const void *gregs
, size_t len
)
165 gdb_assert (len
>= sizeof (mips_elf_gregset_t
));
167 mips_supply_gregset (regcache
, (const mips_elf_gregset_t
*)gregs
);
170 /* Pack our registers (or one register) into an elf_gregset_t. */
173 mips_fill_gregset (const struct regcache
*regcache
,
174 mips_elf_gregset_t
*gregsetp
, int regno
)
176 struct gdbarch
*gdbarch
= regcache
->arch ();
178 mips_elf_greg_t
*regp
= *gregsetp
;
183 memset (regp
, 0, sizeof (mips_elf_gregset_t
));
184 for (regi
= 1; regi
< 32; regi
++)
185 mips_fill_gregset (regcache
, gregsetp
, regi
);
186 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
187 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
188 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
189 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->badvaddr
);
190 mips_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
191 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
192 mips_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
196 if (regno
> 0 && regno
< 32)
198 dst
= regp
+ regno
+ EF_REG0
;
199 regcache
->raw_collect (regno
, dst
);
203 if (regno
== mips_regnum (gdbarch
)->lo
)
205 else if (regno
== mips_regnum (gdbarch
)->hi
)
207 else if (regno
== mips_regnum (gdbarch
)->pc
)
208 regaddr
= EF_CP0_EPC
;
209 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
210 regaddr
= EF_CP0_BADVADDR
;
211 else if (regno
== MIPS_PS_REGNUM
)
212 regaddr
= EF_CP0_STATUS
;
213 else if (regno
== mips_regnum (gdbarch
)->cause
)
214 regaddr
= EF_CP0_CAUSE
;
215 else if (mips_linux_restart_reg_p (gdbarch
)
216 && regno
== MIPS_RESTART_REGNUM
)
223 dst
= regp
+ regaddr
;
224 regcache
->raw_collect (regno
, dst
);
229 mips_fill_gregset_wrapper (const struct regset
*regset
,
230 const struct regcache
*regcache
,
231 int regnum
, void *gregs
, size_t len
)
233 gdb_assert (len
>= sizeof (mips_elf_gregset_t
));
235 mips_fill_gregset (regcache
, (mips_elf_gregset_t
*)gregs
, regnum
);
238 /* Support for 64-bit ABIs. */
240 /* Figure out where the longjmp will land.
241 We expect the first arg to be a pointer to the jmp_buf structure
242 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
243 at. The pc is copied into PC. This routine returns 1 on
246 /* Details about jmp_buf. */
248 #define MIPS64_LINUX_JB_PC 0
251 mips64_linux_get_longjmp_target (const frame_info_ptr
&frame
, CORE_ADDR
*pc
)
254 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
255 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
257 = (gdb_byte
*) alloca (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
258 int element_size
= gdbarch_ptr_bit (gdbarch
) == 32 ? 4 : 8;
260 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
262 if (target_read_memory (jb_addr
+ MIPS64_LINUX_JB_PC
* element_size
,
264 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
267 *pc
= extract_unsigned_integer (buf
,
268 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
274 /* Register set support functions. These operate on standard 64-bit
275 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
276 target will still use the 64-bit format for PTRACE_GETREGS. */
278 /* Supply a 64-bit register. */
281 supply_64bit_reg (struct regcache
*regcache
, int regnum
,
284 struct gdbarch
*gdbarch
= regcache
->arch ();
285 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
286 && register_size (gdbarch
, regnum
) == 4)
287 regcache
->raw_supply (regnum
, buf
+ 4);
289 regcache
->raw_supply (regnum
, buf
);
292 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
295 mips64_supply_gregset (struct regcache
*regcache
,
296 const mips64_elf_gregset_t
*gregsetp
)
299 const mips64_elf_greg_t
*regp
= *gregsetp
;
300 struct gdbarch
*gdbarch
= regcache
->arch ();
302 for (regi
= MIPS64_EF_REG0
+ 1; regi
<= MIPS64_EF_REG31
; regi
++)
303 supply_64bit_reg (regcache
, regi
- MIPS64_EF_REG0
,
304 (const gdb_byte
*) (regp
+ regi
));
306 if (mips_linux_restart_reg_p (gdbarch
))
307 supply_64bit_reg (regcache
, MIPS_RESTART_REGNUM
,
308 (const gdb_byte
*) (regp
+ MIPS64_EF_REG0
));
310 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->lo
,
311 (const gdb_byte
*) (regp
+ MIPS64_EF_LO
));
312 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->hi
,
313 (const gdb_byte
*) (regp
+ MIPS64_EF_HI
));
315 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
316 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_EPC
));
317 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
318 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_BADVADDR
));
319 supply_64bit_reg (regcache
, MIPS_PS_REGNUM
,
320 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_STATUS
));
321 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
322 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_CAUSE
));
324 /* Fill the inaccessible zero register with zero. */
325 regcache
->raw_supply_zeroed (MIPS_ZERO_REGNUM
);
329 mips64_supply_gregset_wrapper (const struct regset
*regset
,
330 struct regcache
*regcache
,
331 int regnum
, const void *gregs
, size_t len
)
333 gdb_assert (len
>= sizeof (mips64_elf_gregset_t
));
335 mips64_supply_gregset (regcache
, (const mips64_elf_gregset_t
*)gregs
);
338 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
341 mips64_fill_gregset (const struct regcache
*regcache
,
342 mips64_elf_gregset_t
*gregsetp
, int regno
)
344 struct gdbarch
*gdbarch
= regcache
->arch ();
346 mips64_elf_greg_t
*regp
= *gregsetp
;
351 memset (regp
, 0, sizeof (mips64_elf_gregset_t
));
352 for (regi
= 1; regi
< 32; regi
++)
353 mips64_fill_gregset (regcache
, gregsetp
, regi
);
354 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
355 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
356 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
357 mips64_fill_gregset (regcache
, gregsetp
,
358 mips_regnum (gdbarch
)->badvaddr
);
359 mips64_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
360 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
361 mips64_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
365 if (regno
> 0 && regno
< 32)
366 regaddr
= regno
+ MIPS64_EF_REG0
;
367 else if (regno
== mips_regnum (gdbarch
)->lo
)
368 regaddr
= MIPS64_EF_LO
;
369 else if (regno
== mips_regnum (gdbarch
)->hi
)
370 regaddr
= MIPS64_EF_HI
;
371 else if (regno
== mips_regnum (gdbarch
)->pc
)
372 regaddr
= MIPS64_EF_CP0_EPC
;
373 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
374 regaddr
= MIPS64_EF_CP0_BADVADDR
;
375 else if (regno
== MIPS_PS_REGNUM
)
376 regaddr
= MIPS64_EF_CP0_STATUS
;
377 else if (regno
== mips_regnum (gdbarch
)->cause
)
378 regaddr
= MIPS64_EF_CP0_CAUSE
;
379 else if (mips_linux_restart_reg_p (gdbarch
)
380 && regno
== MIPS_RESTART_REGNUM
)
381 regaddr
= MIPS64_EF_REG0
;
387 dst
= regp
+ regaddr
;
388 regcache
->raw_collect_integer (regno
, (gdb_byte
*) dst
, 8, true);
393 mips64_fill_gregset_wrapper (const struct regset
*regset
,
394 const struct regcache
*regcache
,
395 int regnum
, void *gregs
, size_t len
)
397 gdb_assert (len
>= sizeof (mips64_elf_gregset_t
));
399 mips64_fill_gregset (regcache
, (mips64_elf_gregset_t
*)gregs
, regnum
);
402 /* Likewise, unpack an elf_fpregset_t. Linux only uses even-numbered
403 FPR slots in the Status.FR=0 mode, storing even-odd FPR pairs as the
404 SDC1 instruction would. When run on MIPS I architecture processors
405 all FPR slots used to be used, unusually, holding the respective FPRs
406 in the first 4 bytes, but that was corrected for consistency, with
407 `linux-mips.org' (LMO) commit 42533948caac ("Major pile of FP emulator
408 changes."), the fix corrected with LMO commit 849fa7a50dff ("R3k FPU
409 ptrace() handling fixes."), and then broken and fixed over and over
410 again, until last time fixed with commit 80cbfad79096 ("MIPS: Correct
411 MIPS I FP context layout"). */
414 mips64_supply_fpregset (struct regcache
*regcache
,
415 const mips64_elf_fpregset_t
*fpregsetp
)
417 struct gdbarch
*gdbarch
= regcache
->arch ();
420 if (register_size (gdbarch
, gdbarch_fp0_regnum (gdbarch
)) == 4)
421 for (regi
= 0; regi
< 32; regi
++)
423 const gdb_byte
*reg_ptr
424 = (const gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
425 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
427 regcache
->raw_supply (gdbarch_fp0_regnum (gdbarch
) + regi
, reg_ptr
);
430 for (regi
= 0; regi
< 32; regi
++)
431 regcache
->raw_supply (gdbarch_fp0_regnum (gdbarch
) + regi
,
432 (const char *) (*fpregsetp
+ regi
));
434 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->fp_control_status
,
435 (const gdb_byte
*) (*fpregsetp
+ 32));
437 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
438 include it - but the result of PTRACE_GETFPREGS does. The best we
439 can do is to assume that its value is present. */
440 supply_32bit_reg (regcache
,
441 mips_regnum (gdbarch
)->fp_implementation_revision
,
442 (const gdb_byte
*) (*fpregsetp
+ 32) + 4);
446 mips64_supply_fpregset_wrapper (const struct regset
*regset
,
447 struct regcache
*regcache
,
448 int regnum
, const void *gregs
, size_t len
)
450 gdb_assert (len
>= sizeof (mips64_elf_fpregset_t
));
452 mips64_supply_fpregset (regcache
, (const mips64_elf_fpregset_t
*)gregs
);
455 /* Likewise, pack one or all floating point registers into an
456 elf_fpregset_t. See `mips_supply_fpregset' for an explanation
460 mips64_fill_fpregset (const struct regcache
*regcache
,
461 mips64_elf_fpregset_t
*fpregsetp
, int regno
)
463 struct gdbarch
*gdbarch
= regcache
->arch ();
466 if ((regno
>= gdbarch_fp0_regnum (gdbarch
))
467 && (regno
< gdbarch_fp0_regnum (gdbarch
) + 32))
469 if (register_size (gdbarch
, regno
) == 4)
471 int regi
= regno
- gdbarch_fp0_regnum (gdbarch
);
473 to
= (gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
474 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
476 regcache
->raw_collect (regno
, to
);
480 to
= (gdb_byte
*) (*fpregsetp
+ regno
481 - gdbarch_fp0_regnum (gdbarch
));
482 regcache
->raw_collect (regno
, to
);
485 else if (regno
== mips_regnum (gdbarch
)->fp_control_status
)
487 to
= (gdb_byte
*) (*fpregsetp
+ 32);
488 regcache
->raw_collect_integer (regno
, to
, 4, true);
490 else if (regno
== mips_regnum (gdbarch
)->fp_implementation_revision
)
492 to
= (gdb_byte
*) (*fpregsetp
+ 32) + 4;
493 regcache
->raw_collect_integer (regno
, to
, 4, true);
495 else if (regno
== -1)
499 for (regi
= 0; regi
< 32; regi
++)
500 mips64_fill_fpregset (regcache
, fpregsetp
,
501 gdbarch_fp0_regnum (gdbarch
) + regi
);
502 mips64_fill_fpregset (regcache
, fpregsetp
,
503 mips_regnum (gdbarch
)->fp_control_status
);
504 mips64_fill_fpregset (regcache
, fpregsetp
,
505 mips_regnum (gdbarch
)->fp_implementation_revision
);
510 mips64_fill_fpregset_wrapper (const struct regset
*regset
,
511 const struct regcache
*regcache
,
512 int regnum
, void *gregs
, size_t len
)
514 gdb_assert (len
>= sizeof (mips64_elf_fpregset_t
));
516 mips64_fill_fpregset (regcache
, (mips64_elf_fpregset_t
*)gregs
, regnum
);
519 static const struct regset mips_linux_gregset
=
521 NULL
, mips_supply_gregset_wrapper
, mips_fill_gregset_wrapper
524 static const struct regset mips64_linux_gregset
=
526 NULL
, mips64_supply_gregset_wrapper
, mips64_fill_gregset_wrapper
529 static const struct regset mips64_linux_fpregset
=
531 NULL
, mips64_supply_fpregset_wrapper
, mips64_fill_fpregset_wrapper
535 mips_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
536 iterate_over_regset_sections_cb
*cb
,
538 const struct regcache
*regcache
)
540 if (register_size (gdbarch
, MIPS_ZERO_REGNUM
) == 4)
542 cb (".reg", sizeof (mips_elf_gregset_t
), sizeof (mips_elf_gregset_t
),
543 &mips_linux_gregset
, NULL
, cb_data
);
544 cb (".reg2", sizeof (mips64_elf_fpregset_t
),
545 sizeof (mips64_elf_fpregset_t
), &mips64_linux_fpregset
,
550 cb (".reg", sizeof (mips64_elf_gregset_t
), sizeof (mips64_elf_gregset_t
),
551 &mips64_linux_gregset
, NULL
, cb_data
);
552 cb (".reg2", sizeof (mips64_elf_fpregset_t
),
553 sizeof (mips64_elf_fpregset_t
), &mips64_linux_fpregset
,
558 static const struct target_desc
*
559 mips_linux_core_read_description (struct gdbarch
*gdbarch
,
560 struct target_ops
*target
,
563 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
567 switch (bfd_section_size (section
))
569 case sizeof (mips_elf_gregset_t
):
570 return mips_tdesc_gp32
;
572 case sizeof (mips64_elf_gregset_t
):
573 return mips_tdesc_gp64
;
581 /* Check the code at PC for a dynamic linker lazy resolution stub.
582 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
583 section uniformly since version 2.15. If the pc is in that section,
584 then we are in such a stub. Before that ".stub" was used in 32-bit
585 ELF binaries, however we do not bother checking for that since we
586 have never had and that case should be extremely rare these days.
587 Instead we pattern-match on the code generated by GNU ld. They look
595 (with the appropriate doubleword instructions for N64). As any lazy
596 resolution stubs in microMIPS binaries will always be in a
597 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
600 mips_linux_in_dynsym_stub (CORE_ADDR pc
)
602 gdb_byte buf
[28], *p
;
603 ULONGEST insn
, insn1
;
604 int n64
= (mips_abi (current_inferior ()->arch ()) == MIPS_ABI_N64
);
605 bfd_endian byte_order
= gdbarch_byte_order (current_inferior ()->arch ());
607 if (in_mips_stubs_section (pc
))
610 read_memory (pc
- 12, buf
, 28);
614 /* ld t9,0x8010(gp) */
619 /* lw t9,0x8010(gp) */
626 insn
= extract_unsigned_integer (p
, 4, byte_order
);
634 insn
= extract_unsigned_integer (p
+ 4, 4, byte_order
);
637 /* 'daddu t7,ra' or 'or t7, ra, zero'*/
638 if (insn
!= 0x03e0782d && insn
!= 0x03e07825)
643 /* 'addu t7,ra' or 'or t7, ra, zero'*/
644 if (insn
!= 0x03e07821 && insn
!= 0x03e07825)
648 insn
= extract_unsigned_integer (p
+ 8, 4, byte_order
);
650 if (insn
!= 0x0320f809)
653 insn
= extract_unsigned_integer (p
+ 12, 4, byte_order
);
656 /* daddiu t8,zero,0 */
657 if ((insn
& 0xffff0000) != 0x64180000)
662 /* addiu t8,zero,0 */
663 if ((insn
& 0xffff0000) != 0x24180000)
670 /* Return non-zero iff PC belongs to the dynamic linker resolution
671 code, a PLT entry, or a lazy binding stub. */
674 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
676 /* Check whether PC is in the dynamic linker. This also checks
677 whether it is in the .plt section, used by non-PIC executables. */
678 if (svr4_in_dynsym_resolve_code (pc
))
681 /* Likewise for the stubs. They live in the .MIPS.stubs section these
682 days, so we check if the PC is within, than fall back to a pattern
684 if (mips_linux_in_dynsym_stub (pc
))
690 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
691 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
692 implementation of this triggers at "fixup" from the same objfile as
693 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
694 "__dl_runtime_resolve" directly. An unresolved lazy binding
695 stub will point to _dl_runtime_resolve, which will first call
696 __dl_runtime_resolve, and then pass control to the resolved
700 mips_linux_skip_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
702 bound_minimal_symbol resolver
703 = lookup_minimal_symbol (current_program_space
, "__dl_runtime_resolve");
705 if (resolver
.minsym
&& resolver
.value_address () == pc
)
706 return frame_unwind_caller_pc (get_current_frame ());
708 return glibc_skip_solib_resolver (gdbarch
, pc
);
711 /* Signal trampoline support. There are four supported layouts for a
712 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
713 n64 rt_sigframe. We handle them all independently; not the most
714 efficient way, but simplest. First, declare all the unwinders. */
716 static void mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
717 const frame_info_ptr
&this_frame
,
718 struct trad_frame_cache
*this_cache
,
721 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
722 const frame_info_ptr
&this_frame
,
723 struct trad_frame_cache
*this_cache
,
726 static int mips_linux_sigframe_validate (const struct tramp_frame
*self
,
727 const frame_info_ptr
&this_frame
,
730 static int micromips_linux_sigframe_validate (const struct tramp_frame
*self
,
731 const frame_info_ptr
&this_frame
,
734 #define MIPS_NR_LINUX 4000
735 #define MIPS_NR_N64_LINUX 5000
736 #define MIPS_NR_N32_LINUX 6000
738 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
739 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
740 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
741 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
743 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
744 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
745 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
746 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
747 #define MIPS_INST_SYSCALL 0x0000000c
749 #define MICROMIPS_INST_LI_V0 0x3040
750 #define MICROMIPS_INST_POOL32A 0x0000
751 #define MICROMIPS_INST_SYSCALL 0x8b7c
753 static const struct tramp_frame mips_linux_o32_sigframe
= {
757 { MIPS_INST_LI_V0_SIGRETURN
, ULONGEST_MAX
},
758 { MIPS_INST_SYSCALL
, ULONGEST_MAX
},
759 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
761 mips_linux_o32_sigframe_init
,
762 mips_linux_sigframe_validate
765 static const struct tramp_frame mips_linux_o32_rt_sigframe
= {
769 { MIPS_INST_LI_V0_RT_SIGRETURN
, ULONGEST_MAX
},
770 { MIPS_INST_SYSCALL
, ULONGEST_MAX
},
771 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
} },
772 mips_linux_o32_sigframe_init
,
773 mips_linux_sigframe_validate
776 static const struct tramp_frame mips_linux_n32_rt_sigframe
= {
780 { MIPS_INST_LI_V0_N32_RT_SIGRETURN
, ULONGEST_MAX
},
781 { MIPS_INST_SYSCALL
, ULONGEST_MAX
},
782 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
784 mips_linux_n32n64_sigframe_init
,
785 mips_linux_sigframe_validate
788 static const struct tramp_frame mips_linux_n64_rt_sigframe
= {
792 { MIPS_INST_LI_V0_N64_RT_SIGRETURN
, ULONGEST_MAX
},
793 { MIPS_INST_SYSCALL
, ULONGEST_MAX
},
794 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
796 mips_linux_n32n64_sigframe_init
,
797 mips_linux_sigframe_validate
800 static const struct tramp_frame micromips_linux_o32_sigframe
= {
804 { MICROMIPS_INST_LI_V0
, ULONGEST_MAX
},
805 { MIPS_NR_sigreturn
, ULONGEST_MAX
},
806 { MICROMIPS_INST_POOL32A
, ULONGEST_MAX
},
807 { MICROMIPS_INST_SYSCALL
, ULONGEST_MAX
},
808 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
810 mips_linux_o32_sigframe_init
,
811 micromips_linux_sigframe_validate
814 static const struct tramp_frame micromips_linux_o32_rt_sigframe
= {
818 { MICROMIPS_INST_LI_V0
, ULONGEST_MAX
},
819 { MIPS_NR_rt_sigreturn
, ULONGEST_MAX
},
820 { MICROMIPS_INST_POOL32A
, ULONGEST_MAX
},
821 { MICROMIPS_INST_SYSCALL
, ULONGEST_MAX
},
822 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
824 mips_linux_o32_sigframe_init
,
825 micromips_linux_sigframe_validate
828 static const struct tramp_frame micromips_linux_n32_rt_sigframe
= {
832 { MICROMIPS_INST_LI_V0
, ULONGEST_MAX
},
833 { MIPS_NR_N32_rt_sigreturn
, ULONGEST_MAX
},
834 { MICROMIPS_INST_POOL32A
, ULONGEST_MAX
},
835 { MICROMIPS_INST_SYSCALL
, ULONGEST_MAX
},
836 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
838 mips_linux_n32n64_sigframe_init
,
839 micromips_linux_sigframe_validate
842 static const struct tramp_frame micromips_linux_n64_rt_sigframe
= {
846 { MICROMIPS_INST_LI_V0
, ULONGEST_MAX
},
847 { MIPS_NR_N64_rt_sigreturn
, ULONGEST_MAX
},
848 { MICROMIPS_INST_POOL32A
, ULONGEST_MAX
},
849 { MICROMIPS_INST_SYSCALL
, ULONGEST_MAX
},
850 { TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
852 mips_linux_n32n64_sigframe_init
,
853 micromips_linux_sigframe_validate
856 /* The unwinder for o32 signal frames. The legacy structures look
860 u32 sf_ass[4]; [argument save space for o32]
861 u32 sf_code[2]; [signal trampoline or fill]
862 struct sigcontext sf_sc;
866 Pre-2.6.12 sigcontext:
869 unsigned int sc_regmask; [Unused]
870 unsigned int sc_status;
871 unsigned long long sc_pc;
872 unsigned long long sc_regs[32];
873 unsigned long long sc_fpregs[32];
874 unsigned int sc_ownedfp;
875 unsigned int sc_fpc_csr;
876 unsigned int sc_fpc_eir; [Unused]
877 unsigned int sc_used_math;
878 unsigned int sc_ssflags; [Unused]
879 [Alignment hole of four bytes]
880 unsigned long long sc_mdhi;
881 unsigned long long sc_mdlo;
883 unsigned int sc_cause; [Unused]
884 unsigned int sc_badvaddr; [Unused]
886 unsigned long sc_sigset[4]; [kernel's sigset_t]
889 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
892 unsigned int sc_regmask; [Unused]
893 unsigned int sc_status; [Unused]
894 unsigned long long sc_pc;
895 unsigned long long sc_regs[32];
896 unsigned long long sc_fpregs[32];
898 unsigned int sc_fpc_csr;
899 unsigned int sc_fpc_eir; [Unused]
900 unsigned int sc_used_math;
902 [Alignment hole of four bytes]
903 unsigned long long sc_mdhi;
904 unsigned long long sc_mdlo;
905 unsigned long sc_hi1;
906 unsigned long sc_lo1;
907 unsigned long sc_hi2;
908 unsigned long sc_lo2;
909 unsigned long sc_hi3;
910 unsigned long sc_lo3;
913 The RT signal frames look like this:
916 u32 rs_ass[4]; [argument save space for o32]
917 u32 rs_code[2] [signal trampoline or fill]
918 struct siginfo rs_info;
919 struct ucontext rs_uc;
923 unsigned long uc_flags;
924 struct ucontext *uc_link;
926 [Alignment hole of four bytes]
927 struct sigcontext uc_mcontext;
931 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
933 #define RTSIGFRAME_SIGINFO_SIZE 128
934 #define STACK_T_SIZE (3 * 4)
935 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
936 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
937 + RTSIGFRAME_SIGINFO_SIZE \
938 + UCONTEXT_SIGCONTEXT_OFFSET)
940 #define SIGCONTEXT_PC (1 * 8)
941 #define SIGCONTEXT_REGS (2 * 8)
942 #define SIGCONTEXT_FPREGS (34 * 8)
943 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
944 #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
945 #define SIGCONTEXT_HI (69 * 8)
946 #define SIGCONTEXT_LO (70 * 8)
947 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
948 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
949 #define SIGCONTEXT_HI1 (71 * 8 + 0)
950 #define SIGCONTEXT_LO1 (71 * 8 + 4)
951 #define SIGCONTEXT_HI2 (72 * 8 + 0)
952 #define SIGCONTEXT_LO2 (72 * 8 + 4)
953 #define SIGCONTEXT_HI3 (73 * 8 + 0)
954 #define SIGCONTEXT_LO3 (73 * 8 + 4)
956 #define SIGCONTEXT_REG_SIZE 8
959 mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
960 const frame_info_ptr
&this_frame
,
961 struct trad_frame_cache
*this_cache
,
964 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
966 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
967 CORE_ADDR sigcontext_base
;
968 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
971 if (self
== &mips_linux_o32_sigframe
972 || self
== µmips_linux_o32_sigframe
)
973 sigcontext_base
= frame_sp
+ SIGFRAME_SIGCONTEXT_OFFSET
;
975 sigcontext_base
= frame_sp
+ RTSIGFRAME_SIGCONTEXT_OFFSET
;
977 /* I'm not proud of this hack. Eventually we will have the
978 infrastructure to indicate the size of saved registers on a
979 per-frame basis, but right now we don't; the kernel saves eight
980 bytes but we only want four. Use regs_base to access any
982 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
983 regs_base
= sigcontext_base
+ 4;
985 regs_base
= sigcontext_base
;
987 if (mips_linux_restart_reg_p (gdbarch
))
988 trad_frame_set_reg_addr (this_cache
,
990 + gdbarch_num_regs (gdbarch
)),
991 regs_base
+ SIGCONTEXT_REGS
);
993 for (ireg
= 1; ireg
< 32; ireg
++)
994 trad_frame_set_reg_addr (this_cache
,
995 (ireg
+ MIPS_ZERO_REGNUM
996 + gdbarch_num_regs (gdbarch
)),
997 (regs_base
+ SIGCONTEXT_REGS
998 + ireg
* SIGCONTEXT_REG_SIZE
));
1000 for (ireg
= 0; ireg
< 32; ireg
++)
1001 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (ireg
& 1))
1002 trad_frame_set_reg_addr (this_cache
,
1003 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1004 (sigcontext_base
+ SIGCONTEXT_FPREGS
+ 4
1005 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
));
1007 trad_frame_set_reg_addr (this_cache
,
1008 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1009 (sigcontext_base
+ SIGCONTEXT_FPREGS
1010 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
));
1012 trad_frame_set_reg_addr (this_cache
,
1013 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1014 regs_base
+ SIGCONTEXT_PC
);
1016 trad_frame_set_reg_addr (this_cache
,
1017 (regs
->fp_control_status
1018 + gdbarch_num_regs (gdbarch
)),
1019 sigcontext_base
+ SIGCONTEXT_FPCSR
);
1021 if (regs
->dspctl
!= -1)
1022 trad_frame_set_reg_addr (this_cache
,
1023 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1024 sigcontext_base
+ SIGCONTEXT_DSPCTL
);
1026 trad_frame_set_reg_addr (this_cache
,
1027 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1028 regs_base
+ SIGCONTEXT_HI
);
1029 trad_frame_set_reg_addr (this_cache
,
1030 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1031 regs_base
+ SIGCONTEXT_LO
);
1033 if (regs
->dspacc
!= -1)
1035 trad_frame_set_reg_addr (this_cache
,
1036 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1037 sigcontext_base
+ SIGCONTEXT_HI1
);
1038 trad_frame_set_reg_addr (this_cache
,
1039 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1040 sigcontext_base
+ SIGCONTEXT_LO1
);
1041 trad_frame_set_reg_addr (this_cache
,
1042 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1043 sigcontext_base
+ SIGCONTEXT_HI2
);
1044 trad_frame_set_reg_addr (this_cache
,
1045 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1046 sigcontext_base
+ SIGCONTEXT_LO2
);
1047 trad_frame_set_reg_addr (this_cache
,
1048 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1049 sigcontext_base
+ SIGCONTEXT_HI3
);
1050 trad_frame_set_reg_addr (this_cache
,
1051 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1052 sigcontext_base
+ SIGCONTEXT_LO3
);
1056 trad_frame_set_reg_addr (this_cache
,
1057 regs
->cause
+ gdbarch_num_regs (gdbarch
),
1058 sigcontext_base
+ SIGCONTEXT_CAUSE
);
1059 trad_frame_set_reg_addr (this_cache
,
1060 regs
->badvaddr
+ gdbarch_num_regs (gdbarch
),
1061 sigcontext_base
+ SIGCONTEXT_BADVADDR
);
1064 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1065 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1068 /* For N32/N64 things look different. There is no non-rt signal frame.
1070 struct rt_sigframe_n32 {
1071 u32 rs_ass[4]; [ argument save space for o32 ]
1072 u32 rs_code[2]; [ signal trampoline or fill ]
1073 struct siginfo rs_info;
1074 struct ucontextn32 rs_uc;
1077 struct ucontextn32 {
1081 struct sigcontext uc_mcontext;
1082 sigset_t uc_sigmask; [ mask last for extensibility ]
1085 struct rt_sigframe {
1086 u32 rs_ass[4]; [ argument save space for o32 ]
1087 u32 rs_code[2]; [ signal trampoline ]
1088 struct siginfo rs_info;
1089 struct ucontext rs_uc;
1093 unsigned long uc_flags;
1094 struct ucontext *uc_link;
1096 struct sigcontext uc_mcontext;
1097 sigset_t uc_sigmask; [ mask last for extensibility ]
1100 And the sigcontext is different (this is for both n32 and n64):
1103 unsigned long long sc_regs[32];
1104 unsigned long long sc_fpregs[32];
1105 unsigned long long sc_mdhi;
1106 unsigned long long sc_hi1;
1107 unsigned long long sc_hi2;
1108 unsigned long long sc_hi3;
1109 unsigned long long sc_mdlo;
1110 unsigned long long sc_lo1;
1111 unsigned long long sc_lo2;
1112 unsigned long long sc_lo3;
1113 unsigned long long sc_pc;
1114 unsigned int sc_fpc_csr;
1115 unsigned int sc_used_math;
1116 unsigned int sc_dsp;
1117 unsigned int sc_reserved;
1120 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1121 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1124 #define N32_STACK_T_SIZE STACK_T_SIZE
1125 #define N64_STACK_T_SIZE (2 * 8 + 4)
1126 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1127 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1128 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1129 + RTSIGFRAME_SIGINFO_SIZE \
1130 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1131 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1132 + RTSIGFRAME_SIGINFO_SIZE \
1133 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1135 #define N64_SIGCONTEXT_REGS (0 * 8)
1136 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1137 #define N64_SIGCONTEXT_HI (64 * 8)
1138 #define N64_SIGCONTEXT_HI1 (65 * 8)
1139 #define N64_SIGCONTEXT_HI2 (66 * 8)
1140 #define N64_SIGCONTEXT_HI3 (67 * 8)
1141 #define N64_SIGCONTEXT_LO (68 * 8)
1142 #define N64_SIGCONTEXT_LO1 (69 * 8)
1143 #define N64_SIGCONTEXT_LO2 (70 * 8)
1144 #define N64_SIGCONTEXT_LO3 (71 * 8)
1145 #define N64_SIGCONTEXT_PC (72 * 8)
1146 #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1147 #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1149 #define N64_SIGCONTEXT_REG_SIZE 8
1152 mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
1153 const frame_info_ptr
&this_frame
,
1154 struct trad_frame_cache
*this_cache
,
1157 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1159 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
1160 CORE_ADDR sigcontext_base
;
1161 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
1163 if (self
== &mips_linux_n32_rt_sigframe
1164 || self
== µmips_linux_n32_rt_sigframe
)
1165 sigcontext_base
= frame_sp
+ N32_SIGFRAME_SIGCONTEXT_OFFSET
;
1167 sigcontext_base
= frame_sp
+ N64_SIGFRAME_SIGCONTEXT_OFFSET
;
1169 if (mips_linux_restart_reg_p (gdbarch
))
1170 trad_frame_set_reg_addr (this_cache
,
1171 (MIPS_RESTART_REGNUM
1172 + gdbarch_num_regs (gdbarch
)),
1173 sigcontext_base
+ N64_SIGCONTEXT_REGS
);
1175 for (ireg
= 1; ireg
< 32; ireg
++)
1176 trad_frame_set_reg_addr (this_cache
,
1177 (ireg
+ MIPS_ZERO_REGNUM
1178 + gdbarch_num_regs (gdbarch
)),
1179 (sigcontext_base
+ N64_SIGCONTEXT_REGS
1180 + ireg
* N64_SIGCONTEXT_REG_SIZE
));
1182 for (ireg
= 0; ireg
< 32; ireg
++)
1183 trad_frame_set_reg_addr (this_cache
,
1184 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1185 (sigcontext_base
+ N64_SIGCONTEXT_FPREGS
1186 + ireg
* N64_SIGCONTEXT_REG_SIZE
));
1188 trad_frame_set_reg_addr (this_cache
,
1189 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1190 sigcontext_base
+ N64_SIGCONTEXT_PC
);
1192 trad_frame_set_reg_addr (this_cache
,
1193 (regs
->fp_control_status
1194 + gdbarch_num_regs (gdbarch
)),
1195 sigcontext_base
+ N64_SIGCONTEXT_FPCSR
);
1197 trad_frame_set_reg_addr (this_cache
,
1198 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1199 sigcontext_base
+ N64_SIGCONTEXT_HI
);
1200 trad_frame_set_reg_addr (this_cache
,
1201 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1202 sigcontext_base
+ N64_SIGCONTEXT_LO
);
1204 if (regs
->dspacc
!= -1)
1206 trad_frame_set_reg_addr (this_cache
,
1207 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1208 sigcontext_base
+ N64_SIGCONTEXT_HI1
);
1209 trad_frame_set_reg_addr (this_cache
,
1210 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1211 sigcontext_base
+ N64_SIGCONTEXT_LO1
);
1212 trad_frame_set_reg_addr (this_cache
,
1213 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1214 sigcontext_base
+ N64_SIGCONTEXT_HI2
);
1215 trad_frame_set_reg_addr (this_cache
,
1216 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1217 sigcontext_base
+ N64_SIGCONTEXT_LO2
);
1218 trad_frame_set_reg_addr (this_cache
,
1219 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1220 sigcontext_base
+ N64_SIGCONTEXT_HI3
);
1221 trad_frame_set_reg_addr (this_cache
,
1222 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1223 sigcontext_base
+ N64_SIGCONTEXT_LO3
);
1225 if (regs
->dspctl
!= -1)
1226 trad_frame_set_reg_addr (this_cache
,
1227 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1228 sigcontext_base
+ N64_SIGCONTEXT_DSPCTL
);
1230 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1231 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1234 /* Implement struct tramp_frame's "validate" method for standard MIPS code. */
1237 mips_linux_sigframe_validate (const struct tramp_frame
*self
,
1238 const frame_info_ptr
&this_frame
,
1241 return mips_pc_is_mips (*pc
);
1244 /* Implement struct tramp_frame's "validate" method for microMIPS code. */
1247 micromips_linux_sigframe_validate (const struct tramp_frame
*self
,
1248 const frame_info_ptr
&this_frame
,
1251 if (mips_pc_is_micromips (get_frame_arch (this_frame
), *pc
))
1253 *pc
= mips_unmake_compact_addr (*pc
);
1260 /* Implement the "write_pc" gdbarch method. */
1263 mips_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1265 struct gdbarch
*gdbarch
= regcache
->arch ();
1267 mips_write_pc (regcache
, pc
);
1269 /* Clear the syscall restart flag. */
1270 if (mips_linux_restart_reg_p (gdbarch
))
1271 regcache_cooked_write_unsigned (regcache
, MIPS_RESTART_REGNUM
, 0);
1274 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1277 mips_linux_restart_reg_p (struct gdbarch
*gdbarch
)
1279 /* If we do not have a target description with registers, then
1280 MIPS_RESTART_REGNUM will not be included in the register set. */
1281 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
1284 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1285 either be GPR-sized or missing. */
1286 return register_size (gdbarch
, MIPS_RESTART_REGNUM
) > 0;
1289 /* When FRAME is at a syscall instruction, return the PC of the next
1290 instruction to be executed. */
1293 mips_linux_syscall_next_pc (const frame_info_ptr
&frame
)
1295 CORE_ADDR pc
= get_frame_pc (frame
);
1296 ULONGEST v0
= get_frame_register_unsigned (frame
, MIPS_V0_REGNUM
);
1298 /* If we are about to make a sigreturn syscall, use the unwinder to
1299 decode the signal frame. */
1300 if (v0
== MIPS_NR_sigreturn
1301 || v0
== MIPS_NR_rt_sigreturn
1302 || v0
== MIPS_NR_N64_rt_sigreturn
1303 || v0
== MIPS_NR_N32_rt_sigreturn
)
1304 return frame_unwind_caller_pc (get_current_frame ());
1309 /* Return the current system call's number present in the
1310 v0 register. When the function fails, it returns -1. */
1313 mips_linux_get_syscall_number (struct gdbarch
*gdbarch
,
1314 thread_info
*thread
)
1316 struct regcache
*regcache
= get_thread_regcache (thread
);
1317 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
1318 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1319 int regsize
= register_size (gdbarch
, MIPS_V0_REGNUM
);
1320 /* The content of a register */
1325 /* Make sure we're in a known ABI */
1326 gdb_assert (tdep
->mips_abi
== MIPS_ABI_O32
1327 || tdep
->mips_abi
== MIPS_ABI_N32
1328 || tdep
->mips_abi
== MIPS_ABI_N64
);
1330 gdb_assert (regsize
<= sizeof (buf
));
1332 /* Getting the system call number from the register.
1333 syscall number is in v0 or $2. */
1334 regcache
->cooked_read (MIPS_V0_REGNUM
, buf
);
1336 ret
= extract_signed_integer (buf
, regsize
, byte_order
);
1341 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1345 mips_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1346 enum gdb_signal signal
)
1350 case GDB_SIGNAL_EMT
:
1351 return MIPS_LINUX_SIGEMT
;
1353 case GDB_SIGNAL_BUS
:
1354 return MIPS_LINUX_SIGBUS
;
1356 case GDB_SIGNAL_SYS
:
1357 return MIPS_LINUX_SIGSYS
;
1359 case GDB_SIGNAL_USR1
:
1360 return MIPS_LINUX_SIGUSR1
;
1362 case GDB_SIGNAL_USR2
:
1363 return MIPS_LINUX_SIGUSR2
;
1365 case GDB_SIGNAL_CHLD
:
1366 return MIPS_LINUX_SIGCHLD
;
1368 case GDB_SIGNAL_PWR
:
1369 return MIPS_LINUX_SIGPWR
;
1371 case GDB_SIGNAL_WINCH
:
1372 return MIPS_LINUX_SIGWINCH
;
1374 case GDB_SIGNAL_URG
:
1375 return MIPS_LINUX_SIGURG
;
1378 return MIPS_LINUX_SIGIO
;
1380 case GDB_SIGNAL_POLL
:
1381 return MIPS_LINUX_SIGPOLL
;
1383 case GDB_SIGNAL_STOP
:
1384 return MIPS_LINUX_SIGSTOP
;
1386 case GDB_SIGNAL_TSTP
:
1387 return MIPS_LINUX_SIGTSTP
;
1389 case GDB_SIGNAL_CONT
:
1390 return MIPS_LINUX_SIGCONT
;
1392 case GDB_SIGNAL_TTIN
:
1393 return MIPS_LINUX_SIGTTIN
;
1395 case GDB_SIGNAL_TTOU
:
1396 return MIPS_LINUX_SIGTTOU
;
1398 case GDB_SIGNAL_VTALRM
:
1399 return MIPS_LINUX_SIGVTALRM
;
1401 case GDB_SIGNAL_PROF
:
1402 return MIPS_LINUX_SIGPROF
;
1404 case GDB_SIGNAL_XCPU
:
1405 return MIPS_LINUX_SIGXCPU
;
1407 case GDB_SIGNAL_XFSZ
:
1408 return MIPS_LINUX_SIGXFSZ
;
1410 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1411 therefore we have to handle it here. */
1412 case GDB_SIGNAL_REALTIME_32
:
1413 return MIPS_LINUX_SIGRTMIN
;
1416 if (signal
>= GDB_SIGNAL_REALTIME_33
1417 && signal
<= GDB_SIGNAL_REALTIME_63
)
1419 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1421 return MIPS_LINUX_SIGRTMIN
+ 1 + offset
;
1423 else if (signal
>= GDB_SIGNAL_REALTIME_64
1424 && signal
<= GDB_SIGNAL_REALTIME_127
)
1426 int offset
= signal
- GDB_SIGNAL_REALTIME_64
;
1428 return MIPS_LINUX_SIGRT64
+ offset
;
1431 return linux_gdb_signal_to_target (gdbarch
, signal
);
1434 /* Translate signals based on MIPS signal values.
1435 Adapted from gdb/gdbsupport/signals.c. */
1437 static enum gdb_signal
1438 mips_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1442 case MIPS_LINUX_SIGEMT
:
1443 return GDB_SIGNAL_EMT
;
1445 case MIPS_LINUX_SIGBUS
:
1446 return GDB_SIGNAL_BUS
;
1448 case MIPS_LINUX_SIGSYS
:
1449 return GDB_SIGNAL_SYS
;
1451 case MIPS_LINUX_SIGUSR1
:
1452 return GDB_SIGNAL_USR1
;
1454 case MIPS_LINUX_SIGUSR2
:
1455 return GDB_SIGNAL_USR2
;
1457 case MIPS_LINUX_SIGCHLD
:
1458 return GDB_SIGNAL_CHLD
;
1460 case MIPS_LINUX_SIGPWR
:
1461 return GDB_SIGNAL_PWR
;
1463 case MIPS_LINUX_SIGWINCH
:
1464 return GDB_SIGNAL_WINCH
;
1466 case MIPS_LINUX_SIGURG
:
1467 return GDB_SIGNAL_URG
;
1469 /* No way to differentiate between SIGIO and SIGPOLL.
1470 Therefore, we just handle the first one. */
1471 case MIPS_LINUX_SIGIO
:
1472 return GDB_SIGNAL_IO
;
1474 case MIPS_LINUX_SIGSTOP
:
1475 return GDB_SIGNAL_STOP
;
1477 case MIPS_LINUX_SIGTSTP
:
1478 return GDB_SIGNAL_TSTP
;
1480 case MIPS_LINUX_SIGCONT
:
1481 return GDB_SIGNAL_CONT
;
1483 case MIPS_LINUX_SIGTTIN
:
1484 return GDB_SIGNAL_TTIN
;
1486 case MIPS_LINUX_SIGTTOU
:
1487 return GDB_SIGNAL_TTOU
;
1489 case MIPS_LINUX_SIGVTALRM
:
1490 return GDB_SIGNAL_VTALRM
;
1492 case MIPS_LINUX_SIGPROF
:
1493 return GDB_SIGNAL_PROF
;
1495 case MIPS_LINUX_SIGXCPU
:
1496 return GDB_SIGNAL_XCPU
;
1498 case MIPS_LINUX_SIGXFSZ
:
1499 return GDB_SIGNAL_XFSZ
;
1502 if (signal
>= MIPS_LINUX_SIGRTMIN
&& signal
<= MIPS_LINUX_SIGRTMAX
)
1504 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1505 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1506 int offset
= signal
- MIPS_LINUX_SIGRTMIN
;
1509 return GDB_SIGNAL_REALTIME_32
;
1510 else if (offset
< 32)
1511 return (enum gdb_signal
) (offset
- 1
1512 + (int) GDB_SIGNAL_REALTIME_33
);
1514 return (enum gdb_signal
) (offset
- 32
1515 + (int) GDB_SIGNAL_REALTIME_64
);
1518 return linux_gdb_signal_from_target (gdbarch
, signal
);
1521 /* Initialize one of the GNU/Linux OS ABIs. */
1524 mips_linux_init_abi (struct gdbarch_info info
,
1525 struct gdbarch
*gdbarch
)
1527 mips_gdbarch_tdep
*tdep
= gdbarch_tdep
<mips_gdbarch_tdep
> (gdbarch
);
1528 enum mips_abi abi
= mips_abi (gdbarch
);
1529 struct tdesc_arch_data
*tdesc_data
= info
.tdesc_data
;
1531 linux_init_abi (info
, gdbarch
, 0);
1533 /* Get the syscall number from the arch's register. */
1534 set_gdbarch_get_syscall_number (gdbarch
, mips_linux_get_syscall_number
);
1539 set_gdbarch_get_longjmp_target (gdbarch
,
1540 mips_linux_get_longjmp_target
);
1541 set_solib_svr4_fetch_link_map_offsets
1542 (gdbarch
, linux_ilp32_fetch_link_map_offsets
);
1543 tramp_frame_prepend_unwinder (gdbarch
, µmips_linux_o32_sigframe
);
1544 tramp_frame_prepend_unwinder (gdbarch
,
1545 µmips_linux_o32_rt_sigframe
);
1546 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_sigframe
);
1547 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_rt_sigframe
);
1548 set_xml_syscall_file_name (gdbarch
, "syscalls/mips-o32-linux.xml");
1551 set_gdbarch_get_longjmp_target (gdbarch
,
1552 mips_linux_get_longjmp_target
);
1553 set_solib_svr4_fetch_link_map_offsets
1554 (gdbarch
, linux_ilp32_fetch_link_map_offsets
);
1555 set_gdbarch_long_double_bit (gdbarch
, 128);
1556 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_quad
);
1557 tramp_frame_prepend_unwinder (gdbarch
,
1558 µmips_linux_n32_rt_sigframe
);
1559 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n32_rt_sigframe
);
1560 set_xml_syscall_file_name (gdbarch
, "syscalls/mips-n32-linux.xml");
1563 set_gdbarch_get_longjmp_target (gdbarch
,
1564 mips64_linux_get_longjmp_target
);
1565 set_solib_svr4_fetch_link_map_offsets
1566 (gdbarch
, linux_lp64_fetch_link_map_offsets
);
1567 set_gdbarch_long_double_bit (gdbarch
, 128);
1568 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_quad
);
1569 tramp_frame_prepend_unwinder (gdbarch
,
1570 µmips_linux_n64_rt_sigframe
);
1571 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n64_rt_sigframe
);
1572 set_xml_syscall_file_name (gdbarch
, "syscalls/mips-n64-linux.xml");
1578 set_gdbarch_skip_solib_resolver (gdbarch
, mips_linux_skip_resolver
);
1580 set_gdbarch_software_single_step (gdbarch
, mips_software_single_step
);
1582 /* Enable TLS support. */
1583 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1584 svr4_fetch_objfile_link_map
);
1586 /* Initialize this lazily, to avoid an initialization order
1587 dependency on solib-svr4.c's _initialize routine. */
1588 if (mips_svr4_so_ops
.in_dynsym_resolve_code
== NULL
)
1590 mips_svr4_so_ops
= svr4_so_ops
;
1591 mips_svr4_so_ops
.in_dynsym_resolve_code
1592 = mips_linux_in_dynsym_resolve_code
;
1594 set_gdbarch_so_ops (gdbarch
, &mips_svr4_so_ops
);
1596 set_gdbarch_write_pc (gdbarch
, mips_linux_write_pc
);
1598 set_gdbarch_core_read_description (gdbarch
,
1599 mips_linux_core_read_description
);
1601 set_gdbarch_iterate_over_regset_sections
1602 (gdbarch
, mips_linux_iterate_over_regset_sections
);
1604 set_gdbarch_gdb_signal_from_target (gdbarch
,
1605 mips_gdb_signal_from_target
);
1607 set_gdbarch_gdb_signal_to_target (gdbarch
,
1608 mips_gdb_signal_to_target
);
1610 tdep
->syscall_next_pc
= mips_linux_syscall_next_pc
;
1614 const struct tdesc_feature
*feature
;
1616 /* If we have target-described registers, then we can safely
1617 reserve a number for MIPS_RESTART_REGNUM (whether it is
1618 described or not). */
1619 gdb_assert (gdbarch_num_regs (gdbarch
) <= MIPS_RESTART_REGNUM
);
1620 set_gdbarch_num_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1621 set_gdbarch_num_pseudo_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1623 /* If it's present, then assign it to the reserved number. */
1624 feature
= tdesc_find_feature (info
.target_desc
,
1625 "org.gnu.gdb.mips.linux");
1626 if (feature
!= NULL
)
1627 tdesc_numbered_register (feature
, tdesc_data
, MIPS_RESTART_REGNUM
,
1632 void _initialize_mips_linux_tdep ();
1634 _initialize_mips_linux_tdep ()
1636 const struct bfd_arch_info
*arch_info
;
1638 for (arch_info
= bfd_lookup_arch (bfd_arch_mips
, 0);
1640 arch_info
= arch_info
->next
)
1642 gdbarch_register_osabi (bfd_arch_mips
, arch_info
->mach
,
1644 mips_linux_init_abi
);
1647 /* Initialize the standard target descriptions. */
1648 initialize_tdesc_mips_linux ();
1649 initialize_tdesc_mips_dsp_linux ();
1650 initialize_tdesc_mips64_linux ();
1651 initialize_tdesc_mips64_dsp_linux ();