1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
26 #include "solib-svr4.h"
28 #include "mips-tdep.h"
29 #include "gdb_string.h"
30 #include "gdb_assert.h"
33 #include "trad-frame.h"
34 #include "tramp-frame.h"
38 #include "mips-linux-tdep.h"
40 /* Figure out where the longjmp will land.
41 We expect the first arg to be a pointer to the jmp_buf structure
42 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
43 at. The pc is copied into PC. This routine returns 1 on
46 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
47 #define MIPS_LINUX_JB_PC 0
50 mips_linux_get_longjmp_target (CORE_ADDR
*pc
)
53 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
55 jb_addr
= read_register (MIPS_A0_REGNUM
);
57 if (target_read_memory (jb_addr
58 + MIPS_LINUX_JB_PC
* MIPS_LINUX_JB_ELEMENT_SIZE
,
59 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
62 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
67 /* Transform the bits comprising a 32-bit register to the right size
68 for regcache_raw_supply(). This is needed when mips_isa_regsize()
72 supply_32bit_reg (int regnum
, const void *addr
)
74 gdb_byte buf
[MAX_REGISTER_SIZE
];
75 store_signed_integer (buf
, register_size (current_gdbarch
, regnum
),
76 extract_signed_integer (addr
, 4));
77 regcache_raw_supply (current_regcache
, regnum
, buf
);
80 /* Unpack an elf_gregset_t into GDB's register cache. */
83 mips_supply_gregset (mips_elf_gregset_t
*gregsetp
)
86 mips_elf_greg_t
*regp
= *gregsetp
;
87 char zerobuf
[MAX_REGISTER_SIZE
];
89 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
91 for (regi
= EF_REG0
; regi
<= EF_REG31
; regi
++)
92 supply_32bit_reg ((regi
- EF_REG0
), (char *)(regp
+ regi
));
94 supply_32bit_reg (mips_regnum (current_gdbarch
)->lo
,
95 (char *)(regp
+ EF_LO
));
96 supply_32bit_reg (mips_regnum (current_gdbarch
)->hi
,
97 (char *)(regp
+ EF_HI
));
99 supply_32bit_reg (mips_regnum (current_gdbarch
)->pc
,
100 (char *)(regp
+ EF_CP0_EPC
));
101 supply_32bit_reg (mips_regnum (current_gdbarch
)->badvaddr
,
102 (char *)(regp
+ EF_CP0_BADVADDR
));
103 supply_32bit_reg (MIPS_PS_REGNUM
, (char *)(regp
+ EF_CP0_STATUS
));
104 supply_32bit_reg (mips_regnum (current_gdbarch
)->cause
,
105 (char *)(regp
+ EF_CP0_CAUSE
));
107 /* Fill inaccessible registers with zero. */
108 regcache_raw_supply (current_regcache
, MIPS_UNUSED_REGNUM
, zerobuf
);
109 for (regi
= MIPS_FIRST_EMBED_REGNUM
;
110 regi
< MIPS_LAST_EMBED_REGNUM
;
112 regcache_raw_supply (current_regcache
, regi
, zerobuf
);
115 /* Pack our registers (or one register) into an elf_gregset_t. */
118 mips_fill_gregset (mips_elf_gregset_t
*gregsetp
, int regno
)
121 mips_elf_greg_t
*regp
= *gregsetp
;
126 memset (regp
, 0, sizeof (mips_elf_gregset_t
));
127 for (regi
= 0; regi
< 32; regi
++)
128 mips_fill_gregset (gregsetp
, regi
);
129 mips_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->lo
);
130 mips_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->hi
);
131 mips_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->pc
);
132 mips_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->badvaddr
);
133 mips_fill_gregset (gregsetp
, MIPS_PS_REGNUM
);
134 mips_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->cause
);
141 dst
= regp
+ regno
+ EF_REG0
;
142 regcache_raw_collect (current_regcache
, regno
, dst
);
146 if (regno
== mips_regnum (current_gdbarch
)->lo
)
148 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
150 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
151 regaddr
= EF_CP0_EPC
;
152 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
153 regaddr
= EF_CP0_BADVADDR
;
154 else if (regno
== MIPS_PS_REGNUM
)
155 regaddr
= EF_CP0_STATUS
;
156 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
157 regaddr
= EF_CP0_CAUSE
;
163 dst
= regp
+ regaddr
;
164 regcache_raw_collect (current_regcache
, regno
, dst
);
168 /* Likewise, unpack an elf_fpregset_t. */
171 mips_supply_fpregset (mips_elf_fpregset_t
*fpregsetp
)
174 char zerobuf
[MAX_REGISTER_SIZE
];
176 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
178 for (regi
= 0; regi
< 32; regi
++)
179 regcache_raw_supply (current_regcache
, FP0_REGNUM
+ regi
,
180 (char *)(*fpregsetp
+ regi
));
182 regcache_raw_supply (current_regcache
,
183 mips_regnum (current_gdbarch
)->fp_control_status
,
184 (char *)(*fpregsetp
+ 32));
186 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
187 regcache_raw_supply (current_regcache
,
188 mips_regnum (current_gdbarch
)->fp_implementation_revision
,
192 /* Likewise, pack one or all floating point registers into an
196 mips_fill_fpregset (mips_elf_fpregset_t
*fpregsetp
, int regno
)
200 if ((regno
>= FP0_REGNUM
) && (regno
< FP0_REGNUM
+ 32))
202 to
= (char *) (*fpregsetp
+ regno
- FP0_REGNUM
);
203 regcache_raw_collect (current_regcache
, regno
, to
);
205 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
207 to
= (char *) (*fpregsetp
+ 32);
208 regcache_raw_collect (current_regcache
, regno
, to
);
210 else if (regno
== -1)
214 for (regi
= 0; regi
< 32; regi
++)
215 mips_fill_fpregset (fpregsetp
, FP0_REGNUM
+ regi
);
216 mips_fill_fpregset (fpregsetp
,
217 mips_regnum (current_gdbarch
)->fp_control_status
);
221 /* Support for 64-bit ABIs. */
223 /* Figure out where the longjmp will land.
224 We expect the first arg to be a pointer to the jmp_buf structure
225 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
226 at. The pc is copied into PC. This routine returns 1 on
229 /* Details about jmp_buf. */
231 #define MIPS64_LINUX_JB_PC 0
234 mips64_linux_get_longjmp_target (CORE_ADDR
*pc
)
237 void *buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
238 int element_size
= TARGET_PTR_BIT
== 32 ? 4 : 8;
240 jb_addr
= read_register (MIPS_A0_REGNUM
);
242 if (target_read_memory (jb_addr
+ MIPS64_LINUX_JB_PC
* element_size
,
243 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
246 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
251 /* Register set support functions. These operate on standard 64-bit
252 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
253 target will still use the 64-bit format for PTRACE_GETREGS. */
255 /* Supply a 64-bit register. */
258 supply_64bit_reg (int regnum
, const gdb_byte
*buf
)
260 if (gdbarch_byte_order (current_gdbarch
) == BFD_ENDIAN_BIG
261 && register_size (current_gdbarch
, regnum
) == 4)
262 regcache_raw_supply (current_regcache
, regnum
, buf
+ 4);
264 regcache_raw_supply (current_regcache
, regnum
, buf
);
267 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
270 mips64_supply_gregset (mips64_elf_gregset_t
*gregsetp
)
273 mips64_elf_greg_t
*regp
= *gregsetp
;
274 gdb_byte zerobuf
[MAX_REGISTER_SIZE
];
276 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
278 for (regi
= MIPS64_EF_REG0
; regi
<= MIPS64_EF_REG31
; regi
++)
279 supply_64bit_reg (regi
- MIPS64_EF_REG0
, (gdb_byte
*)(regp
+ regi
));
281 supply_64bit_reg (mips_regnum (current_gdbarch
)->lo
,
282 (gdb_byte
*) (regp
+ MIPS64_EF_LO
));
283 supply_64bit_reg (mips_regnum (current_gdbarch
)->hi
,
284 (gdb_byte
*) (regp
+ MIPS64_EF_HI
));
286 supply_64bit_reg (mips_regnum (current_gdbarch
)->pc
,
287 (gdb_byte
*) (regp
+ MIPS64_EF_CP0_EPC
));
288 supply_64bit_reg (mips_regnum (current_gdbarch
)->badvaddr
,
289 (gdb_byte
*) (regp
+ MIPS64_EF_CP0_BADVADDR
));
290 supply_64bit_reg (MIPS_PS_REGNUM
,
291 (gdb_byte
*) (regp
+ MIPS64_EF_CP0_STATUS
));
292 supply_64bit_reg (mips_regnum (current_gdbarch
)->cause
,
293 (gdb_byte
*) (regp
+ MIPS64_EF_CP0_CAUSE
));
295 /* Fill inaccessible registers with zero. */
296 regcache_raw_supply (current_regcache
, MIPS_UNUSED_REGNUM
, zerobuf
);
297 for (regi
= MIPS_FIRST_EMBED_REGNUM
;
298 regi
< MIPS_LAST_EMBED_REGNUM
;
300 regcache_raw_supply (current_regcache
, regi
, zerobuf
);
303 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
306 mips64_fill_gregset (mips64_elf_gregset_t
*gregsetp
, int regno
)
309 mips64_elf_greg_t
*regp
= *gregsetp
;
314 memset (regp
, 0, sizeof (mips64_elf_gregset_t
));
315 for (regi
= 0; regi
< 32; regi
++)
316 mips64_fill_gregset (gregsetp
, regi
);
317 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->lo
);
318 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->hi
);
319 mips64_fill_gregset (gregsetp
, mips_regnum (current_gdbarch
)->pc
);
320 mips64_fill_gregset (gregsetp
,
321 mips_regnum (current_gdbarch
)->badvaddr
);
322 mips64_fill_gregset (gregsetp
, MIPS_PS_REGNUM
);
323 mips64_fill_gregset (gregsetp
,
324 mips_regnum (current_gdbarch
)->cause
);
330 regaddr
= regno
+ MIPS64_EF_REG0
;
331 else if (regno
== mips_regnum (current_gdbarch
)->lo
)
332 regaddr
= MIPS64_EF_LO
;
333 else if (regno
== mips_regnum (current_gdbarch
)->hi
)
334 regaddr
= MIPS64_EF_HI
;
335 else if (regno
== mips_regnum (current_gdbarch
)->pc
)
336 regaddr
= MIPS64_EF_CP0_EPC
;
337 else if (regno
== mips_regnum (current_gdbarch
)->badvaddr
)
338 regaddr
= MIPS64_EF_CP0_BADVADDR
;
339 else if (regno
== MIPS_PS_REGNUM
)
340 regaddr
= MIPS64_EF_CP0_STATUS
;
341 else if (regno
== mips_regnum (current_gdbarch
)->cause
)
342 regaddr
= MIPS64_EF_CP0_CAUSE
;
348 gdb_byte buf
[MAX_REGISTER_SIZE
];
351 regcache_raw_collect (current_regcache
, regno
, buf
);
352 val
= extract_signed_integer (buf
,
353 register_size (current_gdbarch
, regno
));
354 dst
= regp
+ regaddr
;
355 store_signed_integer (dst
, 8, val
);
359 /* Likewise, unpack an elf_fpregset_t. */
362 mips64_supply_fpregset (mips64_elf_fpregset_t
*fpregsetp
)
366 /* See mips_linux_o32_sigframe_init for a description of the
367 peculiar FP register layout. */
368 if (register_size (current_gdbarch
, FP0_REGNUM
) == 4)
369 for (regi
= 0; regi
< 32; regi
++)
371 gdb_byte
*reg_ptr
= (gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
372 if ((TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
) != (regi
& 1))
374 regcache_raw_supply (current_regcache
, FP0_REGNUM
+ regi
, reg_ptr
);
377 for (regi
= 0; regi
< 32; regi
++)
378 regcache_raw_supply (current_regcache
, FP0_REGNUM
+ regi
,
379 (char *)(*fpregsetp
+ regi
));
381 supply_32bit_reg (mips_regnum (current_gdbarch
)->fp_control_status
,
382 (gdb_byte
*)(*fpregsetp
+ 32));
384 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
385 include it - but the result of PTRACE_GETFPREGS does. The best we
386 can do is to assume that its value is present. */
387 supply_32bit_reg (mips_regnum (current_gdbarch
)->fp_implementation_revision
,
388 (gdb_byte
*)(*fpregsetp
+ 32) + 4);
391 /* Likewise, pack one or all floating point registers into an
395 mips64_fill_fpregset (mips64_elf_fpregset_t
*fpregsetp
, int regno
)
399 if ((regno
>= FP0_REGNUM
) && (regno
< FP0_REGNUM
+ 32))
401 /* See mips_linux_o32_sigframe_init for a description of the
402 peculiar FP register layout. */
403 if (register_size (current_gdbarch
, regno
) == 4)
405 int regi
= regno
- FP0_REGNUM
;
407 to
= (gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
408 if ((TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
) != (regi
& 1))
410 regcache_raw_collect (current_regcache
, regno
, to
);
414 to
= (gdb_byte
*) (*fpregsetp
+ regno
- FP0_REGNUM
);
415 regcache_raw_collect (current_regcache
, regno
, to
);
418 else if (regno
== mips_regnum (current_gdbarch
)->fp_control_status
)
420 gdb_byte buf
[MAX_REGISTER_SIZE
];
423 regcache_raw_collect (current_regcache
, regno
, buf
);
424 val
= extract_signed_integer (buf
,
425 register_size (current_gdbarch
, regno
));
426 to
= (gdb_byte
*) (*fpregsetp
+ 32);
427 store_signed_integer (to
, 4, val
);
429 else if (regno
== mips_regnum (current_gdbarch
)->fp_implementation_revision
)
431 gdb_byte buf
[MAX_REGISTER_SIZE
];
434 regcache_raw_collect (current_regcache
, regno
, buf
);
435 val
= extract_signed_integer (buf
,
436 register_size (current_gdbarch
, regno
));
437 to
= (gdb_byte
*) (*fpregsetp
+ 32) + 4;
438 store_signed_integer (to
, 4, val
);
440 else if (regno
== -1)
444 for (regi
= 0; regi
< 32; regi
++)
445 mips64_fill_fpregset (fpregsetp
, FP0_REGNUM
+ regi
);
446 mips64_fill_fpregset (fpregsetp
,
447 mips_regnum (current_gdbarch
)->fp_control_status
);
448 mips64_fill_fpregset (fpregsetp
, (mips_regnum (current_gdbarch
)
449 ->fp_implementation_revision
));
454 /* Use a local version of this function to get the correct types for
455 regsets, until multi-arch core support is ready. */
458 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
459 int which
, CORE_ADDR reg_addr
)
461 mips_elf_gregset_t gregset
;
462 mips_elf_fpregset_t fpregset
;
463 mips64_elf_gregset_t gregset64
;
464 mips64_elf_fpregset_t fpregset64
;
468 if (core_reg_size
== sizeof (gregset
))
470 memcpy ((char *) &gregset
, core_reg_sect
, sizeof (gregset
));
471 mips_supply_gregset (&gregset
);
473 else if (core_reg_size
== sizeof (gregset64
))
475 memcpy ((char *) &gregset64
, core_reg_sect
, sizeof (gregset64
));
476 mips64_supply_gregset (&gregset64
);
480 warning (_("wrong size gregset struct in core file"));
485 if (core_reg_size
== sizeof (fpregset
))
487 memcpy ((char *) &fpregset
, core_reg_sect
, sizeof (fpregset
));
488 mips_supply_fpregset (&fpregset
);
490 else if (core_reg_size
== sizeof (fpregset64
))
492 memcpy ((char *) &fpregset64
, core_reg_sect
,
493 sizeof (fpregset64
));
494 mips64_supply_fpregset (&fpregset64
);
498 warning (_("wrong size fpregset struct in core file"));
503 /* Register that we are able to handle ELF file formats using standard
504 procfs "regset" structures. */
506 static struct core_fns regset_core_fns
=
508 bfd_target_elf_flavour
, /* core_flavour */
509 default_check_format
, /* check_format */
510 default_core_sniffer
, /* core_sniffer */
511 fetch_core_registers
, /* core_read_registers */
516 /* Check the code at PC for a dynamic linker lazy resolution stub.
517 Because they aren't in the .plt section, we pattern-match on the
518 code generated by GNU ld. They look like this:
525 (with the appropriate doubleword instructions for N64). Also
526 return the dynamic symbol index used in the last instruction. */
529 mips_linux_in_dynsym_stub (CORE_ADDR pc
, char *name
)
531 unsigned char buf
[28], *p
;
532 ULONGEST insn
, insn1
;
533 int n64
= (mips_abi (current_gdbarch
) == MIPS_ABI_N64
);
535 read_memory (pc
- 12, buf
, 28);
539 /* ld t9,0x8010(gp) */
544 /* lw t9,0x8010(gp) */
551 insn
= extract_unsigned_integer (p
, 4);
559 insn
= extract_unsigned_integer (p
+ 4, 4);
563 if (insn
!= 0x03e0782d)
569 if (insn
!= 0x03e07821)
573 insn
= extract_unsigned_integer (p
+ 8, 4);
575 if (insn
!= 0x0320f809)
578 insn
= extract_unsigned_integer (p
+ 12, 4);
581 /* daddiu t8,zero,0 */
582 if ((insn
& 0xffff0000) != 0x64180000)
587 /* addiu t8,zero,0 */
588 if ((insn
& 0xffff0000) != 0x24180000)
592 return (insn
& 0xffff);
595 /* Return non-zero iff PC belongs to the dynamic linker resolution
596 code or to a stub. */
599 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
601 /* Check whether PC is in the dynamic linker. This also checks
602 whether it is in the .plt section, which MIPS does not use. */
603 if (in_solib_dynsym_resolve_code (pc
))
606 /* Pattern match for the stub. It would be nice if there were a
607 more efficient way to avoid this check. */
608 if (mips_linux_in_dynsym_stub (pc
, NULL
))
614 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
615 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
616 implementation of this triggers at "fixup" from the same objfile as
617 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
618 "__dl_runtime_resolve" directly. An unresolved PLT entry will
619 point to _dl_runtime_resolve, which will first call
620 __dl_runtime_resolve, and then pass control to the resolved
624 mips_linux_skip_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
626 struct minimal_symbol
*resolver
;
628 resolver
= lookup_minimal_symbol ("__dl_runtime_resolve", NULL
, NULL
);
630 if (resolver
&& SYMBOL_VALUE_ADDRESS (resolver
) == pc
)
631 return frame_pc_unwind (get_current_frame ());
636 /* Signal trampoline support. There are four supported layouts for a
637 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
638 n64 rt_sigframe. We handle them all independently; not the most
639 efficient way, but simplest. First, declare all the unwinders. */
641 static void mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
642 struct frame_info
*next_frame
,
643 struct trad_frame_cache
*this_cache
,
646 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
647 struct frame_info
*next_frame
,
648 struct trad_frame_cache
*this_cache
,
651 #define MIPS_NR_LINUX 4000
652 #define MIPS_NR_N64_LINUX 5000
653 #define MIPS_NR_N32_LINUX 6000
655 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
656 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
657 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
658 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
660 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
661 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
662 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
663 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
664 #define MIPS_INST_SYSCALL 0x0000000c
666 static const struct tramp_frame mips_linux_o32_sigframe
= {
670 { MIPS_INST_LI_V0_SIGRETURN
, -1 },
671 { MIPS_INST_SYSCALL
, -1 },
672 { TRAMP_SENTINEL_INSN
, -1 }
674 mips_linux_o32_sigframe_init
677 static const struct tramp_frame mips_linux_o32_rt_sigframe
= {
681 { MIPS_INST_LI_V0_RT_SIGRETURN
, -1 },
682 { MIPS_INST_SYSCALL
, -1 },
683 { TRAMP_SENTINEL_INSN
, -1 } },
684 mips_linux_o32_sigframe_init
687 static const struct tramp_frame mips_linux_n32_rt_sigframe
= {
691 { MIPS_INST_LI_V0_N32_RT_SIGRETURN
, -1 },
692 { MIPS_INST_SYSCALL
, -1 },
693 { TRAMP_SENTINEL_INSN
, -1 }
695 mips_linux_n32n64_sigframe_init
698 static const struct tramp_frame mips_linux_n64_rt_sigframe
= {
702 { MIPS_INST_LI_V0_N64_RT_SIGRETURN
, -1 },
703 { MIPS_INST_SYSCALL
, -1 },
704 { TRAMP_SENTINEL_INSN
, -1 }
706 mips_linux_n32n64_sigframe_init
710 /* The unwinder for o32 signal frames. The legacy structures look
714 u32 sf_ass[4]; [argument save space for o32]
715 u32 sf_code[2]; [signal trampoline]
716 struct sigcontext sf_sc;
721 unsigned int sc_regmask; [Unused]
722 unsigned int sc_status;
723 unsigned long long sc_pc;
724 unsigned long long sc_regs[32];
725 unsigned long long sc_fpregs[32];
726 unsigned int sc_ownedfp;
727 unsigned int sc_fpc_csr;
728 unsigned int sc_fpc_eir; [Unused]
729 unsigned int sc_used_math;
730 unsigned int sc_ssflags; [Unused]
731 [Alignment hole of four bytes]
732 unsigned long long sc_mdhi;
733 unsigned long long sc_mdlo;
735 unsigned int sc_cause; [Unused]
736 unsigned int sc_badvaddr; [Unused]
738 unsigned long sc_sigset[4]; [kernel's sigset_t]
741 The RT signal frames look like this:
744 u32 rs_ass[4]; [argument save space for o32]
745 u32 rs_code[2] [signal trampoline]
746 struct siginfo rs_info;
747 struct ucontext rs_uc;
751 unsigned long uc_flags;
752 struct ucontext *uc_link;
754 [Alignment hole of four bytes]
755 struct sigcontext uc_mcontext;
760 #define SIGFRAME_CODE_OFFSET (4 * 4)
761 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
763 #define RTSIGFRAME_SIGINFO_SIZE 128
764 #define STACK_T_SIZE (3 * 4)
765 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
766 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
767 + RTSIGFRAME_SIGINFO_SIZE \
768 + UCONTEXT_SIGCONTEXT_OFFSET)
770 #define SIGCONTEXT_PC (1 * 8)
771 #define SIGCONTEXT_REGS (2 * 8)
772 #define SIGCONTEXT_FPREGS (34 * 8)
773 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
774 #define SIGCONTEXT_HI (69 * 8)
775 #define SIGCONTEXT_LO (70 * 8)
776 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
777 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
779 #define SIGCONTEXT_REG_SIZE 8
782 mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
783 struct frame_info
*next_frame
,
784 struct trad_frame_cache
*this_cache
,
787 int ireg
, reg_position
;
788 CORE_ADDR sigcontext_base
= func
- SIGFRAME_CODE_OFFSET
;
789 const struct mips_regnum
*regs
= mips_regnum (current_gdbarch
);
792 if (self
== &mips_linux_o32_sigframe
)
793 sigcontext_base
+= SIGFRAME_SIGCONTEXT_OFFSET
;
795 sigcontext_base
+= RTSIGFRAME_SIGCONTEXT_OFFSET
;
797 /* I'm not proud of this hack. Eventually we will have the
798 infrastructure to indicate the size of saved registers on a
799 per-frame basis, but right now we don't; the kernel saves eight
800 bytes but we only want four. Use regs_base to access any
802 if (TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
)
803 regs_base
= sigcontext_base
+ 4;
805 regs_base
= sigcontext_base
;
808 trad_frame_set_reg_addr (this_cache
, ORIG_ZERO_REGNUM
+ NUM_REGS
,
809 regs_base
+ SIGCONTEXT_REGS
);
812 for (ireg
= 1; ireg
< 32; ireg
++)
813 trad_frame_set_reg_addr (this_cache
,
814 ireg
+ MIPS_ZERO_REGNUM
+ NUM_REGS
,
815 regs_base
+ SIGCONTEXT_REGS
816 + ireg
* SIGCONTEXT_REG_SIZE
);
818 /* The way that floating point registers are saved, unfortunately,
819 depends on the architecture the kernel is built for. For the r3000 and
820 tx39, four bytes of each register are at the beginning of each of the
821 32 eight byte slots. For everything else, the registers are saved
822 using double precision; only the even-numbered slots are initialized,
823 and the high bits are the odd-numbered register. Assume the latter
824 layout, since we can't tell, and it's much more common. Which bits are
825 the "high" bits depends on endianness. */
826 for (ireg
= 0; ireg
< 32; ireg
++)
827 if ((TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
) != (ireg
& 1))
828 trad_frame_set_reg_addr (this_cache
, ireg
+ regs
->fp0
+ NUM_REGS
,
829 sigcontext_base
+ SIGCONTEXT_FPREGS
+ 4
830 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
);
832 trad_frame_set_reg_addr (this_cache
, ireg
+ regs
->fp0
+ NUM_REGS
,
833 sigcontext_base
+ SIGCONTEXT_FPREGS
834 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
);
836 trad_frame_set_reg_addr (this_cache
, regs
->pc
+ NUM_REGS
,
837 regs_base
+ SIGCONTEXT_PC
);
839 trad_frame_set_reg_addr (this_cache
,
840 regs
->fp_control_status
+ NUM_REGS
,
841 sigcontext_base
+ SIGCONTEXT_FPCSR
);
842 trad_frame_set_reg_addr (this_cache
, regs
->hi
+ NUM_REGS
,
843 regs_base
+ SIGCONTEXT_HI
);
844 trad_frame_set_reg_addr (this_cache
, regs
->lo
+ NUM_REGS
,
845 regs_base
+ SIGCONTEXT_LO
);
846 trad_frame_set_reg_addr (this_cache
, regs
->cause
+ NUM_REGS
,
847 sigcontext_base
+ SIGCONTEXT_CAUSE
);
848 trad_frame_set_reg_addr (this_cache
, regs
->badvaddr
+ NUM_REGS
,
849 sigcontext_base
+ SIGCONTEXT_BADVADDR
);
851 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
852 trad_frame_set_id (this_cache
,
853 frame_id_build (func
- SIGFRAME_CODE_OFFSET
,
858 /* For N32/N64 things look different. There is no non-rt signal frame.
860 struct rt_sigframe_n32 {
861 u32 rs_ass[4]; [ argument save space for o32 ]
862 u32 rs_code[2]; [ signal trampoline ]
863 struct siginfo rs_info;
864 struct ucontextn32 rs_uc;
871 struct sigcontext uc_mcontext;
872 sigset_t uc_sigmask; [ mask last for extensibility ]
875 struct rt_sigframe_n32 {
876 u32 rs_ass[4]; [ argument save space for o32 ]
877 u32 rs_code[2]; [ signal trampoline ]
878 struct siginfo rs_info;
879 struct ucontext rs_uc;
883 unsigned long uc_flags;
884 struct ucontext *uc_link;
886 struct sigcontext uc_mcontext;
887 sigset_t uc_sigmask; [ mask last for extensibility ]
890 And the sigcontext is different (this is for both n32 and n64):
893 unsigned long long sc_regs[32];
894 unsigned long long sc_fpregs[32];
895 unsigned long long sc_mdhi;
896 unsigned long long sc_mdlo;
897 unsigned long long sc_pc;
898 unsigned int sc_status;
899 unsigned int sc_fpc_csr;
900 unsigned int sc_fpc_eir;
901 unsigned int sc_used_math;
902 unsigned int sc_cause;
903 unsigned int sc_badvaddr;
907 #define N32_STACK_T_SIZE STACK_T_SIZE
908 #define N64_STACK_T_SIZE (2 * 8 + 4)
909 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
910 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
911 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
912 + RTSIGFRAME_SIGINFO_SIZE \
913 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
914 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
915 + RTSIGFRAME_SIGINFO_SIZE \
916 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
918 #define N64_SIGCONTEXT_REGS (0 * 8)
919 #define N64_SIGCONTEXT_FPREGS (32 * 8)
920 #define N64_SIGCONTEXT_HI (64 * 8)
921 #define N64_SIGCONTEXT_LO (65 * 8)
922 #define N64_SIGCONTEXT_PC (66 * 8)
923 #define N64_SIGCONTEXT_FPCSR (67 * 8 + 1 * 4)
924 #define N64_SIGCONTEXT_FIR (67 * 8 + 2 * 4)
925 #define N64_SIGCONTEXT_CAUSE (67 * 8 + 4 * 4)
926 #define N64_SIGCONTEXT_BADVADDR (67 * 8 + 5 * 4)
928 #define N64_SIGCONTEXT_REG_SIZE 8
931 mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
932 struct frame_info
*next_frame
,
933 struct trad_frame_cache
*this_cache
,
936 int ireg
, reg_position
;
937 CORE_ADDR sigcontext_base
= func
- SIGFRAME_CODE_OFFSET
;
938 const struct mips_regnum
*regs
= mips_regnum (current_gdbarch
);
940 if (self
== &mips_linux_n32_rt_sigframe
)
941 sigcontext_base
+= N32_SIGFRAME_SIGCONTEXT_OFFSET
;
943 sigcontext_base
+= N64_SIGFRAME_SIGCONTEXT_OFFSET
;
946 trad_frame_set_reg_addr (this_cache
, ORIG_ZERO_REGNUM
+ NUM_REGS
,
947 sigcontext_base
+ N64_SIGCONTEXT_REGS
);
950 for (ireg
= 1; ireg
< 32; ireg
++)
951 trad_frame_set_reg_addr (this_cache
,
952 ireg
+ MIPS_ZERO_REGNUM
+ NUM_REGS
,
953 sigcontext_base
+ N64_SIGCONTEXT_REGS
954 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
956 for (ireg
= 0; ireg
< 32; ireg
++)
957 trad_frame_set_reg_addr (this_cache
, ireg
+ regs
->fp0
+ NUM_REGS
,
958 sigcontext_base
+ N64_SIGCONTEXT_FPREGS
959 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
961 trad_frame_set_reg_addr (this_cache
, regs
->pc
+ NUM_REGS
,
962 sigcontext_base
+ N64_SIGCONTEXT_PC
);
964 trad_frame_set_reg_addr (this_cache
,
965 regs
->fp_control_status
+ NUM_REGS
,
966 sigcontext_base
+ N64_SIGCONTEXT_FPCSR
);
967 trad_frame_set_reg_addr (this_cache
, regs
->hi
+ NUM_REGS
,
968 sigcontext_base
+ N64_SIGCONTEXT_HI
);
969 trad_frame_set_reg_addr (this_cache
, regs
->lo
+ NUM_REGS
,
970 sigcontext_base
+ N64_SIGCONTEXT_LO
);
971 trad_frame_set_reg_addr (this_cache
, regs
->cause
+ NUM_REGS
,
972 sigcontext_base
+ N64_SIGCONTEXT_CAUSE
);
973 trad_frame_set_reg_addr (this_cache
, regs
->badvaddr
+ NUM_REGS
,
974 sigcontext_base
+ N64_SIGCONTEXT_BADVADDR
);
976 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
977 trad_frame_set_id (this_cache
,
978 frame_id_build (func
- SIGFRAME_CODE_OFFSET
,
982 /* Wrapper functions. These are only used by libthread_db. */
985 supply_gregset (mips_elf_gregset_t
*gregsetp
)
987 if (mips_isa_regsize (current_gdbarch
) == 4)
988 mips_supply_gregset (gregsetp
);
990 mips64_supply_gregset ((void *) gregsetp
);
994 fill_gregset (mips_elf_gregset_t
*gregsetp
, int regno
)
996 if (mips_isa_regsize (current_gdbarch
) == 4)
997 mips_fill_gregset (gregsetp
, regno
);
999 mips64_fill_gregset ((void *) gregsetp
, regno
);
1002 /* Likewise, unpack an elf_fpregset_t. */
1005 supply_fpregset (mips_elf_fpregset_t
*fpregsetp
)
1007 if (mips_isa_regsize (current_gdbarch
) == 4)
1008 mips_supply_fpregset (fpregsetp
);
1010 mips64_supply_fpregset ((void *) fpregsetp
);
1013 /* Likewise, pack one or all floating point registers into an
1017 fill_fpregset (mips_elf_fpregset_t
*fpregsetp
, int regno
)
1019 if (mips_isa_regsize (current_gdbarch
) == 4)
1020 mips_fill_fpregset (fpregsetp
, regno
);
1022 mips64_fill_fpregset ((void *) fpregsetp
, regno
);
1025 /* Initialize one of the GNU/Linux OS ABIs. */
1028 mips_linux_init_abi (struct gdbarch_info info
,
1029 struct gdbarch
*gdbarch
)
1031 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1032 enum mips_abi abi
= mips_abi (gdbarch
);
1037 set_gdbarch_get_longjmp_target (gdbarch
,
1038 mips_linux_get_longjmp_target
);
1039 set_solib_svr4_fetch_link_map_offsets
1040 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1041 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_sigframe
);
1042 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_rt_sigframe
);
1045 set_gdbarch_get_longjmp_target (gdbarch
,
1046 mips_linux_get_longjmp_target
);
1047 set_solib_svr4_fetch_link_map_offsets
1048 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1049 set_gdbarch_long_double_bit (gdbarch
, 128);
1050 /* These floatformats should probably be renamed. MIPS uses
1051 the same 128-bit IEEE floating point format that IA-64 uses,
1052 except that the quiet/signalling NaN bit is reversed (GDB
1053 does not distinguish between quiet and signalling NaNs). */
1054 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1055 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n32_rt_sigframe
);
1058 set_gdbarch_get_longjmp_target (gdbarch
,
1059 mips64_linux_get_longjmp_target
);
1060 set_solib_svr4_fetch_link_map_offsets
1061 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1062 set_gdbarch_long_double_bit (gdbarch
, 128);
1063 /* These floatformats should probably be renamed. MIPS uses
1064 the same 128-bit IEEE floating point format that IA-64 uses,
1065 except that the quiet/signalling NaN bit is reversed (GDB
1066 does not distinguish between quiet and signalling NaNs). */
1067 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1068 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n64_rt_sigframe
);
1071 internal_error (__FILE__
, __LINE__
, _("can't handle ABI"));
1075 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1076 set_gdbarch_skip_solib_resolver (gdbarch
, mips_linux_skip_resolver
);
1078 set_gdbarch_software_single_step (gdbarch
, mips_software_single_step
);
1080 /* Enable TLS support. */
1081 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1082 svr4_fetch_objfile_link_map
);
1086 _initialize_mips_linux_tdep (void)
1088 const struct bfd_arch_info
*arch_info
;
1090 for (arch_info
= bfd_lookup_arch (bfd_arch_mips
, 0);
1092 arch_info
= arch_info
->next
)
1094 gdbarch_register_osabi (bfd_arch_mips
, arch_info
->mach
,
1096 mips_linux_init_abi
);
1099 deprecated_add_core_fns (®set_core_fns
);