1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright 2001, 2002, 2004 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "solib-svr4.h"
27 #include "mips-tdep.h"
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
31 #include "trad-frame.h"
32 #include "tramp-frame.h"
34 /* Copied from <asm/elf.h>. */
38 typedef unsigned char elf_greg_t
[4];
39 typedef elf_greg_t elf_gregset_t
[ELF_NGREG
];
41 typedef unsigned char elf_fpreg_t
[8];
42 typedef elf_fpreg_t elf_fpregset_t
[ELF_NFPREG
];
44 /* 0 - 31 are integer registers, 32 - 63 are fp registers. */
59 #define EF_CP0_BADVADDR 41
60 #define EF_CP0_STATUS 42
61 #define EF_CP0_CAUSE 43
65 /* Figure out where the longjmp will land.
66 We expect the first arg to be a pointer to the jmp_buf structure from
67 which we extract the pc (MIPS_LINUX_JB_PC) that we will land at. The pc
68 is copied into PC. This routine returns 1 on success. */
70 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
71 #define MIPS_LINUX_JB_PC 0
74 mips_linux_get_longjmp_target (CORE_ADDR
*pc
)
77 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
79 jb_addr
= read_register (A0_REGNUM
);
81 if (target_read_memory (jb_addr
82 + MIPS_LINUX_JB_PC
* MIPS_LINUX_JB_ELEMENT_SIZE
,
83 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
86 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
91 /* Transform the bits comprising a 32-bit register to the right size
92 for supply_register(). This is needed when mips_regsize() is 8. */
95 supply_32bit_reg (int regnum
, const void *addr
)
97 char buf
[MAX_REGISTER_SIZE
];
98 store_signed_integer (buf
, DEPRECATED_REGISTER_RAW_SIZE (regnum
),
99 extract_signed_integer (addr
, 4));
100 supply_register (regnum
, buf
);
103 /* Unpack an elf_gregset_t into GDB's register cache. */
106 supply_gregset (elf_gregset_t
*gregsetp
)
109 elf_greg_t
*regp
= *gregsetp
;
110 char zerobuf
[MAX_REGISTER_SIZE
];
112 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
114 for (regi
= EF_REG0
; regi
<= EF_REG31
; regi
++)
115 supply_32bit_reg ((regi
- EF_REG0
), (char *)(regp
+ regi
));
117 supply_32bit_reg (mips_regnum (current_gdbarch
)->lo
,
118 (char *)(regp
+ EF_LO
));
119 supply_32bit_reg (mips_regnum (current_gdbarch
)->hi
,
120 (char *)(regp
+ EF_HI
));
122 supply_32bit_reg (mips_regnum (current_gdbarch
)->pc
,
123 (char *)(regp
+ EF_CP0_EPC
));
124 supply_32bit_reg (mips_regnum (current_gdbarch
)->badvaddr
,
125 (char *)(regp
+ EF_CP0_BADVADDR
));
126 supply_32bit_reg (PS_REGNUM
, (char *)(regp
+ EF_CP0_STATUS
));
127 supply_32bit_reg (mips_regnum (current_gdbarch
)->cause
,
128 (char *)(regp
+ EF_CP0_CAUSE
));
130 /* Fill inaccessible registers with zero. */
131 supply_register (UNUSED_REGNUM
, zerobuf
);
132 for (regi
= FIRST_EMBED_REGNUM
; regi
< LAST_EMBED_REGNUM
; regi
++)
133 supply_register (regi
, zerobuf
);
136 /* Pack our registers (or one register) into an elf_gregset_t. */
139 fill_gregset (elf_gregset_t
*gregsetp
, int regno
)
142 elf_greg_t
*regp
= *gregsetp
;
147 memset (regp
, 0, sizeof (elf_gregset_t
));
148 for (regi
= 0; regi
< 32; regi
++)
149 fill_gregset (gregsetp
, regi
);
150 fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->lo
);
151 fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->hi
);
152 fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->pc
);
153 fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->badvaddr
);
154 fill_gregset (gregsetp
, PS_REGNUM
);
155 fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->cause
);
162 dst
= regp
+ regno
+ EF_REG0
;
163 regcache_collect (regno
, dst
);
167 if (regno
== mips_regnum (current_gdbarch
)->lo
)
169 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
171 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
172 regaddr
= EF_CP0_EPC
;
173 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
174 regaddr
= EF_CP0_BADVADDR
;
175 else if (regno
== PS_REGNUM
)
176 regaddr
= EF_CP0_STATUS
;
177 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
178 regaddr
= EF_CP0_CAUSE
;
184 dst
= regp
+ regaddr
;
185 regcache_collect (regno
, dst
);
189 /* Likewise, unpack an elf_fpregset_t. */
192 supply_fpregset (elf_fpregset_t
*fpregsetp
)
195 char zerobuf
[MAX_REGISTER_SIZE
];
197 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
199 for (regi
= 0; regi
< 32; regi
++)
200 supply_register (FP0_REGNUM
+ regi
,
201 (char *)(*fpregsetp
+ regi
));
203 supply_register (mips_regnum (current_gdbarch
)->fp_control_status
,
204 (char *)(*fpregsetp
+ 32));
206 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
207 supply_register (mips_regnum (current_gdbarch
)->fp_implementation_revision
,
211 /* Likewise, pack one or all floating point registers into an
215 fill_fpregset (elf_fpregset_t
*fpregsetp
, int regno
)
219 if ((regno
>= FP0_REGNUM
) && (regno
< FP0_REGNUM
+ 32))
221 from
= (char *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
222 to
= (char *) (*fpregsetp
+ regno
- FP0_REGNUM
);
223 memcpy (to
, from
, DEPRECATED_REGISTER_RAW_SIZE (regno
- FP0_REGNUM
));
225 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
227 from
= (char *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
228 to
= (char *) (*fpregsetp
+ 32);
229 memcpy (to
, from
, DEPRECATED_REGISTER_RAW_SIZE (regno
));
231 else if (regno
== -1)
235 for (regi
= 0; regi
< 32; regi
++)
236 fill_fpregset (fpregsetp
, FP0_REGNUM
+ regi
);
237 fill_fpregset(fpregsetp
, mips_regnum (current_gdbarch
)->fp_control_status
);
241 /* Map gdb internal register number to ptrace ``address''.
242 These ``addresses'' are normally defined in <asm/ptrace.h>. */
245 mips_linux_register_addr (int regno
, CORE_ADDR blockend
)
249 if (regno
< 0 || regno
>= NUM_REGS
)
250 error ("Bogon register number %d.", regno
);
254 else if ((regno
>= mips_regnum (current_gdbarch
)->fp0
)
255 && (regno
< mips_regnum (current_gdbarch
)->fp0
+ 32))
256 regaddr
= FPR_BASE
+ (regno
- mips_regnum (current_gdbarch
)->fp0
);
257 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
259 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
261 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
263 else if (regno
== mips_regnum (current_gdbarch
)->lo
)
265 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
267 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
269 else if (regno
== mips_regnum (current_gdbarch
)->fp_implementation_revision
)
272 error ("Unknowable register number %d.", regno
);
278 /* Fetch (and possibly build) an appropriate link_map_offsets
279 structure for native GNU/Linux MIPS targets using the struct offsets
280 defined in link.h (but without actual reference to that file).
282 This makes it possible to access GNU/Linux MIPS shared libraries from a
283 GDB that was built on a different host platform (for cross debugging). */
285 static struct link_map_offsets
*
286 mips_linux_svr4_fetch_link_map_offsets (void)
288 static struct link_map_offsets lmo
;
289 static struct link_map_offsets
*lmp
= NULL
;
295 lmo
.r_debug_size
= 8; /* The actual size is 20 bytes, but
296 this is all we need. */
297 lmo
.r_map_offset
= 4;
300 lmo
.link_map_size
= 20;
302 lmo
.l_addr_offset
= 0;
305 lmo
.l_name_offset
= 4;
308 lmo
.l_next_offset
= 12;
311 lmo
.l_prev_offset
= 16;
318 /* Support for 64-bit ABIs. */
320 /* Copied from <asm/elf.h>. */
321 #define MIPS64_ELF_NGREG 45
322 #define MIPS64_ELF_NFPREG 33
324 typedef unsigned char mips64_elf_greg_t
[8];
325 typedef mips64_elf_greg_t mips64_elf_gregset_t
[MIPS64_ELF_NGREG
];
327 typedef unsigned char mips64_elf_fpreg_t
[8];
328 typedef mips64_elf_fpreg_t mips64_elf_fpregset_t
[MIPS64_ELF_NFPREG
];
330 /* 0 - 31 are integer registers, 32 - 63 are fp registers. */
331 #define MIPS64_FPR_BASE 32
333 #define MIPS64_CAUSE 65
334 #define MIPS64_BADVADDR 66
335 #define MIPS64_MMHI 67
336 #define MIPS64_MMLO 68
337 #define MIPS64_FPC_CSR 69
338 #define MIPS64_FPC_EIR 70
340 #define MIPS64_EF_REG0 0
341 #define MIPS64_EF_REG31 31
342 #define MIPS64_EF_LO 32
343 #define MIPS64_EF_HI 33
344 #define MIPS64_EF_CP0_EPC 34
345 #define MIPS64_EF_CP0_BADVADDR 35
346 #define MIPS64_EF_CP0_STATUS 36
347 #define MIPS64_EF_CP0_CAUSE 37
349 #define MIPS64_EF_SIZE 304
351 /* Figure out where the longjmp will land.
352 We expect the first arg to be a pointer to the jmp_buf structure from
353 which we extract the pc (MIPS_LINUX_JB_PC) that we will land at. The pc
354 is copied into PC. This routine returns 1 on success. */
356 /* Details about jmp_buf. */
358 #define MIPS64_LINUX_JB_PC 0
361 mips64_linux_get_longjmp_target (CORE_ADDR
*pc
)
364 void *buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
365 int element_size
= TARGET_PTR_BIT
== 32 ? 4 : 8;
367 jb_addr
= read_register (A0_REGNUM
);
369 if (target_read_memory (jb_addr
+ MIPS64_LINUX_JB_PC
* element_size
,
370 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
373 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
378 /* Unpack an elf_gregset_t into GDB's register cache. */
381 mips64_supply_gregset (mips64_elf_gregset_t
*gregsetp
)
384 mips64_elf_greg_t
*regp
= *gregsetp
;
385 char zerobuf
[MAX_REGISTER_SIZE
];
387 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
389 for (regi
= MIPS64_EF_REG0
; regi
<= MIPS64_EF_REG31
; regi
++)
390 supply_register ((regi
- MIPS64_EF_REG0
), (char *)(regp
+ regi
));
392 supply_register (mips_regnum (current_gdbarch
)->lo
,
393 (char *)(regp
+ MIPS64_EF_LO
));
394 supply_register (mips_regnum (current_gdbarch
)->hi
,
395 (char *)(regp
+ MIPS64_EF_HI
));
397 supply_register (mips_regnum (current_gdbarch
)->pc
,
398 (char *)(regp
+ MIPS64_EF_CP0_EPC
));
399 supply_register (mips_regnum (current_gdbarch
)->badvaddr
,
400 (char *)(regp
+ MIPS64_EF_CP0_BADVADDR
));
401 supply_register (PS_REGNUM
, (char *)(regp
+ MIPS64_EF_CP0_STATUS
));
402 supply_register (mips_regnum (current_gdbarch
)->cause
,
403 (char *)(regp
+ MIPS64_EF_CP0_CAUSE
));
405 /* Fill inaccessible registers with zero. */
406 supply_register (UNUSED_REGNUM
, zerobuf
);
407 for (regi
= FIRST_EMBED_REGNUM
; regi
< LAST_EMBED_REGNUM
; regi
++)
408 supply_register (regi
, zerobuf
);
411 /* Pack our registers (or one register) into an elf_gregset_t. */
414 mips64_fill_gregset (mips64_elf_gregset_t
*gregsetp
, int regno
)
417 mips64_elf_greg_t
*regp
= *gregsetp
;
422 memset (regp
, 0, sizeof (mips64_elf_gregset_t
));
423 for (regi
= 0; regi
< 32; regi
++)
424 mips64_fill_gregset (gregsetp
, regi
);
425 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->lo
);
426 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->hi
);
427 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->pc
);
428 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->badvaddr
);
429 mips64_fill_gregset (gregsetp
, PS_REGNUM
);
430 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->cause
);
437 dst
= regp
+ regno
+ MIPS64_EF_REG0
;
438 regcache_collect (regno
, dst
);
442 if (regno
== mips_regnum (current_gdbarch
)->lo
)
443 regaddr
= MIPS64_EF_LO
;
444 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
445 regaddr
= MIPS64_EF_HI
;
446 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
447 regaddr
= MIPS64_EF_CP0_EPC
;
448 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
449 regaddr
= MIPS64_EF_CP0_BADVADDR
;
450 else if (regno
== PS_REGNUM
)
451 regaddr
= MIPS64_EF_CP0_STATUS
;
452 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
453 regaddr
= MIPS64_EF_CP0_CAUSE
;
459 dst
= regp
+ regaddr
;
460 regcache_collect (regno
, dst
);
464 /* Likewise, unpack an elf_fpregset_t. */
467 mips64_supply_fpregset (mips64_elf_fpregset_t
*fpregsetp
)
470 char zerobuf
[MAX_REGISTER_SIZE
];
472 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
474 for (regi
= 0; regi
< 32; regi
++)
475 supply_register (FP0_REGNUM
+ regi
,
476 (char *)(*fpregsetp
+ regi
));
478 supply_register (mips_regnum (current_gdbarch
)->fp_control_status
,
479 (char *)(*fpregsetp
+ 32));
481 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
482 supply_register (mips_regnum (current_gdbarch
)->fp_implementation_revision
,
486 /* Likewise, pack one or all floating point registers into an
490 mips64_fill_fpregset (mips64_elf_fpregset_t
*fpregsetp
, int regno
)
494 if ((regno
>= FP0_REGNUM
) && (regno
< FP0_REGNUM
+ 32))
496 from
= (char *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
497 to
= (char *) (*fpregsetp
+ regno
- FP0_REGNUM
);
498 memcpy (to
, from
, DEPRECATED_REGISTER_RAW_SIZE (regno
- FP0_REGNUM
));
500 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
502 from
= (char *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
503 to
= (char *) (*fpregsetp
+ 32);
504 memcpy (to
, from
, DEPRECATED_REGISTER_RAW_SIZE (regno
));
506 else if (regno
== -1)
510 for (regi
= 0; regi
< 32; regi
++)
511 mips64_fill_fpregset (fpregsetp
, FP0_REGNUM
+ regi
);
512 mips64_fill_fpregset(fpregsetp
,
513 mips_regnum (current_gdbarch
)->fp_control_status
);
518 /* Map gdb internal register number to ptrace ``address''.
519 These ``addresses'' are normally defined in <asm/ptrace.h>. */
522 mips64_linux_register_addr (int regno
, CORE_ADDR blockend
)
526 if (regno
< 0 || regno
>= NUM_REGS
)
527 error ("Bogon register number %d.", regno
);
531 else if ((regno
>= mips_regnum (current_gdbarch
)->fp0
)
532 && (regno
< mips_regnum (current_gdbarch
)->fp0
+ 32))
533 regaddr
= MIPS64_FPR_BASE
+ (regno
- FP0_REGNUM
);
534 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
536 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
537 regaddr
= MIPS64_CAUSE
;
538 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
539 regaddr
= MIPS64_BADVADDR
;
540 else if (regno
== mips_regnum (current_gdbarch
)->lo
)
541 regaddr
= MIPS64_MMLO
;
542 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
543 regaddr
= MIPS64_MMHI
;
544 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
545 regaddr
= MIPS64_FPC_CSR
;
546 else if (regno
== mips_regnum (current_gdbarch
)->fp_implementation_revision
)
547 regaddr
= MIPS64_FPC_EIR
;
549 error ("Unknowable register number %d.", regno
);
554 /* Use a local version of this function to get the correct types for
555 regsets, until multi-arch core support is ready. */
558 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
559 int which
, CORE_ADDR reg_addr
)
561 elf_gregset_t gregset
;
562 elf_fpregset_t fpregset
;
563 mips64_elf_gregset_t gregset64
;
564 mips64_elf_fpregset_t fpregset64
;
568 if (core_reg_size
== sizeof (gregset
))
570 memcpy ((char *) &gregset
, core_reg_sect
, sizeof (gregset
));
571 supply_gregset (&gregset
);
573 else if (core_reg_size
== sizeof (gregset64
))
575 memcpy ((char *) &gregset64
, core_reg_sect
, sizeof (gregset64
));
576 mips64_supply_gregset (&gregset64
);
580 warning ("wrong size gregset struct in core file");
585 if (core_reg_size
== sizeof (fpregset
))
587 memcpy ((char *) &fpregset
, core_reg_sect
, sizeof (fpregset
));
588 supply_fpregset (&fpregset
);
590 else if (core_reg_size
== sizeof (fpregset64
))
592 memcpy ((char *) &fpregset64
, core_reg_sect
, sizeof (fpregset64
));
593 mips64_supply_fpregset (&fpregset64
);
597 warning ("wrong size fpregset struct in core file");
602 /* Register that we are able to handle ELF file formats using standard
603 procfs "regset" structures. */
605 static struct core_fns regset_core_fns
=
607 bfd_target_elf_flavour
, /* core_flavour */
608 default_check_format
, /* check_format */
609 default_core_sniffer
, /* core_sniffer */
610 fetch_core_registers
, /* core_read_registers */
614 /* Fetch (and possibly build) an appropriate link_map_offsets
615 structure for native GNU/Linux MIPS targets using the struct offsets
616 defined in link.h (but without actual reference to that file).
618 This makes it possible to access GNU/Linux MIPS shared libraries from a
619 GDB that was built on a different host platform (for cross debugging). */
621 static struct link_map_offsets
*
622 mips64_linux_svr4_fetch_link_map_offsets (void)
624 static struct link_map_offsets lmo
;
625 static struct link_map_offsets
*lmp
= NULL
;
631 lmo
.r_debug_size
= 16; /* The actual size is 40 bytes, but
632 this is all we need. */
633 lmo
.r_map_offset
= 8;
636 lmo
.link_map_size
= 40;
638 lmo
.l_addr_offset
= 0;
641 lmo
.l_name_offset
= 8;
644 lmo
.l_next_offset
= 24;
647 lmo
.l_prev_offset
= 32;
654 /* Handle for obtaining pointer to the current register_addr() function
655 for a given architecture. */
656 static struct gdbarch_data
*register_addr_data
;
659 register_addr (int regno
, CORE_ADDR blockend
)
661 CORE_ADDR (*register_addr_ptr
) (int, CORE_ADDR
) =
662 gdbarch_data (current_gdbarch
, register_addr_data
);
664 gdb_assert (register_addr_ptr
!= 0);
666 return register_addr_ptr (regno
, blockend
);
670 set_mips_linux_register_addr (struct gdbarch
*gdbarch
,
671 CORE_ADDR (*register_addr_ptr
) (int, CORE_ADDR
))
673 deprecated_set_gdbarch_data (gdbarch
, register_addr_data
, register_addr_ptr
);
677 init_register_addr_data (struct gdbarch
*gdbarch
)
682 /* Check the code at PC for a dynamic linker lazy resolution stub. Because
683 they aren't in the .plt section, we pattern-match on the code generated
684 by GNU ld. They look like this:
691 (with the appropriate doubleword instructions for N64). Also return the
692 dynamic symbol index used in the last instruction. */
695 mips_linux_in_dynsym_stub (CORE_ADDR pc
, char *name
)
697 unsigned char buf
[28], *p
;
698 ULONGEST insn
, insn1
;
699 int n64
= (mips_abi (current_gdbarch
) == MIPS_ABI_N64
);
701 read_memory (pc
- 12, buf
, 28);
705 /* ld t9,0x8010(gp) */
710 /* lw t9,0x8010(gp) */
717 insn
= extract_unsigned_integer (p
, 4);
725 insn
= extract_unsigned_integer (p
+ 4, 4);
729 if (insn
!= 0x03e0782d)
735 if (insn
!= 0x03e07821)
739 insn
= extract_unsigned_integer (p
+ 8, 4);
741 if (insn
!= 0x0320f809)
744 insn
= extract_unsigned_integer (p
+ 12, 4);
747 /* daddiu t8,zero,0 */
748 if ((insn
& 0xffff0000) != 0x64180000)
753 /* addiu t8,zero,0 */
754 if ((insn
& 0xffff0000) != 0x24180000)
758 return (insn
& 0xffff);
761 /* Return non-zero iff PC belongs to the dynamic linker resolution code
765 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
767 /* Check whether PC is in the dynamic linker. This also checks whether
768 it is in the .plt section, which MIPS does not use. */
769 if (in_solib_dynsym_resolve_code (pc
))
772 /* Pattern match for the stub. It would be nice if there were a more
773 efficient way to avoid this check. */
774 if (mips_linux_in_dynsym_stub (pc
, NULL
))
780 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
781 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
782 implementation of this triggers at "fixup" from the same objfile as
783 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
784 "__dl_runtime_resolve" directly. An unresolved PLT entry will
785 point to _dl_runtime_resolve, which will first call
786 __dl_runtime_resolve, and then pass control to the resolved
790 mips_linux_skip_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
792 struct minimal_symbol
*resolver
;
794 resolver
= lookup_minimal_symbol ("__dl_runtime_resolve", NULL
, NULL
);
796 if (resolver
&& SYMBOL_VALUE_ADDRESS (resolver
) == pc
)
797 return frame_pc_unwind (get_current_frame ());
802 /* Signal trampoline support. There are four supported layouts for a
803 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
804 n64 rt_sigframe. We handle them all independently; not the most
805 efficient way, but simplest. First, declare all the unwinders. */
807 static void mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
808 struct frame_info
*next_frame
,
809 struct trad_frame_cache
*this_cache
,
812 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
813 struct frame_info
*next_frame
,
814 struct trad_frame_cache
*this_cache
,
817 #define MIPS_NR_LINUX 4000
818 #define MIPS_NR_N64_LINUX 5000
819 #define MIPS_NR_N32_LINUX 6000
821 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
822 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
823 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
824 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
826 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
827 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
828 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
829 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
830 #define MIPS_INST_SYSCALL 0x0000000c
832 struct tramp_frame mips_linux_o32_sigframe
= {
834 { MIPS_INST_LI_V0_SIGRETURN
, MIPS_INST_SYSCALL
, TRAMP_SENTINEL_INSN
},
835 mips_linux_o32_sigframe_init
838 struct tramp_frame mips_linux_o32_rt_sigframe
= {
840 { MIPS_INST_LI_V0_RT_SIGRETURN
, MIPS_INST_SYSCALL
, TRAMP_SENTINEL_INSN
},
841 mips_linux_o32_sigframe_init
844 struct tramp_frame mips_linux_n32_rt_sigframe
= {
846 { MIPS_INST_LI_V0_N32_RT_SIGRETURN
, MIPS_INST_SYSCALL
, TRAMP_SENTINEL_INSN
},
847 mips_linux_n32n64_sigframe_init
850 struct tramp_frame mips_linux_n64_rt_sigframe
= {
852 { MIPS_INST_LI_V0_N64_RT_SIGRETURN
, MIPS_INST_SYSCALL
, TRAMP_SENTINEL_INSN
},
853 mips_linux_n32n64_sigframe_init
857 /* The unwinder for o32 signal frames. The legacy structures look
861 u32 sf_ass[4]; [argument save space for o32]
862 u32 sf_code[2]; [signal trampoline]
863 struct sigcontext sf_sc;
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;
882 unsigned int sc_cause; [Unused]
883 unsigned int sc_badvaddr; [Unused]
885 unsigned long sc_sigset[4]; [kernel's sigset_t]
888 The RT signal frames look like this:
891 u32 rs_ass[4]; [argument save space for o32]
892 u32 rs_code[2] [signal trampoline]
893 struct siginfo rs_info;
894 struct ucontext rs_uc;
898 unsigned long uc_flags;
899 struct ucontext *uc_link;
901 [Alignment hole of four bytes]
902 struct sigcontext uc_mcontext;
907 #define SIGFRAME_CODE_OFFSET (4 * 4)
908 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
910 #define RTSIGFRAME_SIGINFO_SIZE 128
911 #define STACK_T_SIZE (3 * 4)
912 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
913 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
914 + RTSIGFRAME_SIGINFO_SIZE \
915 + UCONTEXT_SIGCONTEXT_OFFSET)
917 #define SIGCONTEXT_PC (1 * 8)
918 #define SIGCONTEXT_REGS (2 * 8)
919 #define SIGCONTEXT_FPREGS (34 * 8)
920 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
921 #define SIGCONTEXT_HI (69 * 8)
922 #define SIGCONTEXT_LO (70 * 8)
923 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
924 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
926 #define SIGCONTEXT_REG_SIZE 8
929 mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
930 struct frame_info
*next_frame
,
931 struct trad_frame_cache
*this_cache
,
934 int ireg
, reg_position
;
935 CORE_ADDR sigcontext_base
= func
- SIGFRAME_CODE_OFFSET
;
936 const struct mips_regnum
*regs
= mips_regnum (current_gdbarch
);
938 if (self
== &mips_linux_o32_sigframe
)
939 sigcontext_base
+= SIGFRAME_SIGCONTEXT_OFFSET
;
941 sigcontext_base
+= RTSIGFRAME_SIGCONTEXT_OFFSET
;
943 /* I'm not proud of this hack. Eventually we will have the infrastructure
944 to indicate the size of saved registers on a per-frame basis, but
945 right now we don't; the kernel saves eight bytes but we only want
947 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
948 sigcontext_base
+= 4;
951 trad_frame_set_reg_addr (this_cache
, ORIG_ZERO_REGNUM
+ NUM_REGS
,
952 sigcontext_base
+ SIGCONTEXT_REGS
);
955 for (ireg
= 1; ireg
< 32; ireg
++)
956 trad_frame_set_reg_addr (this_cache
, ireg
+ ZERO_REGNUM
+ NUM_REGS
,
957 sigcontext_base
+ SIGCONTEXT_REGS
958 + ireg
* SIGCONTEXT_REG_SIZE
);
960 for (ireg
= 0; ireg
< 32; ireg
++)
961 trad_frame_set_reg_addr (this_cache
, ireg
+ regs
->fp0
+ NUM_REGS
,
962 sigcontext_base
+ SIGCONTEXT_FPREGS
963 + ireg
* SIGCONTEXT_REG_SIZE
);
965 trad_frame_set_reg_addr (this_cache
, regs
->pc
+ NUM_REGS
,
966 sigcontext_base
+ SIGCONTEXT_PC
);
968 trad_frame_set_reg_addr (this_cache
, regs
->fp_control_status
+ NUM_REGS
,
969 sigcontext_base
+ SIGCONTEXT_FPCSR
);
970 trad_frame_set_reg_addr (this_cache
, regs
->hi
+ NUM_REGS
,
971 sigcontext_base
+ SIGCONTEXT_HI
);
972 trad_frame_set_reg_addr (this_cache
, regs
->lo
+ NUM_REGS
,
973 sigcontext_base
+ SIGCONTEXT_LO
);
974 trad_frame_set_reg_addr (this_cache
, regs
->cause
+ NUM_REGS
,
975 sigcontext_base
+ SIGCONTEXT_CAUSE
);
976 trad_frame_set_reg_addr (this_cache
, regs
->badvaddr
+ NUM_REGS
,
977 sigcontext_base
+ SIGCONTEXT_BADVADDR
);
979 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
980 trad_frame_set_id (this_cache
,
981 frame_id_build (func
- SIGFRAME_CODE_OFFSET
, func
));
985 /* For N32/N64 things look different. There is no non-rt signal frame.
987 struct rt_sigframe_n32 {
988 u32 rs_ass[4]; [ argument save space for o32 ]
989 u32 rs_code[2]; [ signal trampoline ]
990 struct siginfo rs_info;
991 struct ucontextn32 rs_uc;
998 struct sigcontext uc_mcontext;
999 sigset_t uc_sigmask; [ mask last for extensibility ]
1002 struct rt_sigframe_n32 {
1003 u32 rs_ass[4]; [ argument save space for o32 ]
1004 u32 rs_code[2]; [ signal trampoline ]
1005 struct siginfo rs_info;
1006 struct ucontext rs_uc;
1010 unsigned long uc_flags;
1011 struct ucontext *uc_link;
1013 struct sigcontext uc_mcontext;
1014 sigset_t uc_sigmask; [ mask last for extensibility ]
1017 And the sigcontext is different (this is for both n32 and n64):
1020 unsigned long long sc_regs[32];
1021 unsigned long long sc_fpregs[32];
1022 unsigned long long sc_mdhi;
1023 unsigned long long sc_mdlo;
1024 unsigned long long sc_pc;
1025 unsigned int sc_status;
1026 unsigned int sc_fpc_csr;
1027 unsigned int sc_fpc_eir;
1028 unsigned int sc_used_math;
1029 unsigned int sc_cause;
1030 unsigned int sc_badvaddr;
1034 #define N32_STACK_T_SIZE STACK_T_SIZE
1035 #define N64_STACK_T_SIZE (2 * 8 + 4)
1036 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1037 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1038 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1039 + RTSIGFRAME_SIGINFO_SIZE \
1040 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1041 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1042 + RTSIGFRAME_SIGINFO_SIZE \
1043 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1045 #define N64_SIGCONTEXT_REGS (0 * 8)
1046 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1047 #define N64_SIGCONTEXT_HI (64 * 8)
1048 #define N64_SIGCONTEXT_LO (65 * 8)
1049 #define N64_SIGCONTEXT_PC (66 * 8)
1050 #define N64_SIGCONTEXT_FPCSR (67 * 8 + 1 * 4)
1051 #define N64_SIGCONTEXT_FIR (67 * 8 + 2 * 4)
1052 #define N64_SIGCONTEXT_CAUSE (67 * 8 + 4 * 4)
1053 #define N64_SIGCONTEXT_BADVADDR (67 * 8 + 5 * 4)
1055 #define N64_SIGCONTEXT_REG_SIZE 8
1058 mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
1059 struct frame_info
*next_frame
,
1060 struct trad_frame_cache
*this_cache
,
1063 int ireg
, reg_position
;
1064 CORE_ADDR sigcontext_base
= func
- SIGFRAME_CODE_OFFSET
;
1065 const struct mips_regnum
*regs
= mips_regnum (current_gdbarch
);
1067 if (self
== &mips_linux_n32_rt_sigframe
)
1068 sigcontext_base
+= N32_SIGFRAME_SIGCONTEXT_OFFSET
;
1070 sigcontext_base
+= N64_SIGFRAME_SIGCONTEXT_OFFSET
;
1073 trad_frame_set_reg_addr (this_cache
, ORIG_ZERO_REGNUM
+ NUM_REGS
,
1074 sigcontext_base
+ N64_SIGCONTEXT_REGS
);
1077 for (ireg
= 1; ireg
< 32; ireg
++)
1078 trad_frame_set_reg_addr (this_cache
, ireg
+ ZERO_REGNUM
+ NUM_REGS
,
1079 sigcontext_base
+ N64_SIGCONTEXT_REGS
1080 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
1082 for (ireg
= 0; ireg
< 32; ireg
++)
1083 trad_frame_set_reg_addr (this_cache
, ireg
+ regs
->fp0
+ NUM_REGS
,
1084 sigcontext_base
+ N64_SIGCONTEXT_FPREGS
1085 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
1087 trad_frame_set_reg_addr (this_cache
, regs
->pc
+ NUM_REGS
,
1088 sigcontext_base
+ N64_SIGCONTEXT_PC
);
1090 trad_frame_set_reg_addr (this_cache
, regs
->fp_control_status
+ NUM_REGS
,
1091 sigcontext_base
+ N64_SIGCONTEXT_FPCSR
);
1092 trad_frame_set_reg_addr (this_cache
, regs
->hi
+ NUM_REGS
,
1093 sigcontext_base
+ N64_SIGCONTEXT_HI
);
1094 trad_frame_set_reg_addr (this_cache
, regs
->lo
+ NUM_REGS
,
1095 sigcontext_base
+ N64_SIGCONTEXT_LO
);
1096 trad_frame_set_reg_addr (this_cache
, regs
->cause
+ NUM_REGS
,
1097 sigcontext_base
+ N64_SIGCONTEXT_CAUSE
);
1098 trad_frame_set_reg_addr (this_cache
, regs
->badvaddr
+ NUM_REGS
,
1099 sigcontext_base
+ N64_SIGCONTEXT_BADVADDR
);
1101 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1102 trad_frame_set_id (this_cache
,
1103 frame_id_build (func
- SIGFRAME_CODE_OFFSET
, func
));
1106 /* Initialize one of the GNU/Linux OS ABIs. */
1109 mips_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1111 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1112 enum mips_abi abi
= mips_abi (gdbarch
);
1117 set_gdbarch_get_longjmp_target (gdbarch
,
1118 mips_linux_get_longjmp_target
);
1119 set_solib_svr4_fetch_link_map_offsets
1120 (gdbarch
, mips_linux_svr4_fetch_link_map_offsets
);
1121 set_mips_linux_register_addr (gdbarch
, mips_linux_register_addr
);
1122 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_sigframe
);
1123 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_rt_sigframe
);
1126 set_gdbarch_get_longjmp_target (gdbarch
,
1127 mips_linux_get_longjmp_target
);
1128 set_solib_svr4_fetch_link_map_offsets
1129 (gdbarch
, mips_linux_svr4_fetch_link_map_offsets
);
1130 set_mips_linux_register_addr (gdbarch
, mips64_linux_register_addr
);
1131 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n32_rt_sigframe
);
1134 set_gdbarch_get_longjmp_target (gdbarch
,
1135 mips64_linux_get_longjmp_target
);
1136 set_solib_svr4_fetch_link_map_offsets
1137 (gdbarch
, mips64_linux_svr4_fetch_link_map_offsets
);
1138 set_mips_linux_register_addr (gdbarch
, mips64_linux_register_addr
);
1139 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n64_rt_sigframe
);
1142 internal_error (__FILE__
, __LINE__
, "can't handle ABI");
1146 set_gdbarch_skip_solib_resolver (gdbarch
, mips_linux_skip_resolver
);
1148 /* This overrides the MIPS16 stub support from mips-tdep. But no
1149 one uses MIPS16 on GNU/Linux yet, so this isn't much of a loss. */
1150 set_gdbarch_in_solib_call_trampoline (gdbarch
, mips_linux_in_dynsym_stub
);
1154 _initialize_mips_linux_tdep (void)
1156 const struct bfd_arch_info
*arch_info
;
1158 register_addr_data
=
1159 gdbarch_data_register_post_init (init_register_addr_data
);
1161 for (arch_info
= bfd_lookup_arch (bfd_arch_mips
, 0);
1163 arch_info
= arch_info
->next
)
1165 gdbarch_register_osabi (bfd_arch_mips
, arch_info
->mach
, GDB_OSABI_LINUX
,
1166 mips_linux_init_abi
);
1169 add_core_fns (®set_core_fns
);