1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001-2002, 2004-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "solib-svr4.h"
25 #include "mips-tdep.h"
26 #include "gdb_string.h"
27 #include "gdb_assert.h"
30 #include "trad-frame.h"
31 #include "tramp-frame.h"
34 #include "solib-svr4.h"
37 #include "target-descriptions.h"
39 #include "mips-linux-tdep.h"
40 #include "glibc-tdep.h"
41 #include "linux-tdep.h"
42 #include "xml-syscall.h"
43 #include "gdb_signals.h"
45 static struct target_so_ops mips_svr4_so_ops
;
47 /* Figure out where the longjmp will land.
48 We expect the first arg to be a pointer to the jmp_buf structure
49 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
50 at. The pc is copied into PC. This routine returns 1 on
53 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
54 #define MIPS_LINUX_JB_PC 0
57 mips_linux_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
60 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
61 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
62 char buf
[gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
];
64 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
66 if (target_read_memory (jb_addr
67 + MIPS_LINUX_JB_PC
* MIPS_LINUX_JB_ELEMENT_SIZE
,
68 buf
, gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
71 *pc
= extract_unsigned_integer (buf
,
72 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
78 /* Transform the bits comprising a 32-bit register to the right size
79 for regcache_raw_supply(). This is needed when mips_isa_regsize()
83 supply_32bit_reg (struct regcache
*regcache
, int regnum
, const void *addr
)
85 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
86 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
87 gdb_byte buf
[MAX_REGISTER_SIZE
];
88 store_signed_integer (buf
, register_size (gdbarch
, regnum
), byte_order
,
89 extract_signed_integer (addr
, 4, byte_order
));
90 regcache_raw_supply (regcache
, regnum
, buf
);
93 /* Unpack an elf_gregset_t into GDB's register cache. */
96 mips_supply_gregset (struct regcache
*regcache
,
97 const mips_elf_gregset_t
*gregsetp
)
100 const mips_elf_greg_t
*regp
= *gregsetp
;
101 char zerobuf
[MAX_REGISTER_SIZE
];
102 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
104 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
106 for (regi
= EF_REG0
+ 1; regi
<= EF_REG31
; regi
++)
107 supply_32bit_reg (regcache
, regi
- EF_REG0
, regp
+ regi
);
109 if (mips_linux_restart_reg_p (gdbarch
))
110 supply_32bit_reg (regcache
, MIPS_RESTART_REGNUM
, regp
+ EF_REG0
);
112 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->lo
, regp
+ EF_LO
);
113 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->hi
, regp
+ EF_HI
);
115 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
117 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
118 regp
+ EF_CP0_BADVADDR
);
119 supply_32bit_reg (regcache
, MIPS_PS_REGNUM
, regp
+ EF_CP0_STATUS
);
120 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
121 regp
+ EF_CP0_CAUSE
);
123 /* Fill the inaccessible zero register with zero. */
124 regcache_raw_supply (regcache
, MIPS_ZERO_REGNUM
, zerobuf
);
128 mips_supply_gregset_wrapper (const struct regset
*regset
,
129 struct regcache
*regcache
,
130 int regnum
, const void *gregs
, size_t len
)
132 gdb_assert (len
== sizeof (mips_elf_gregset_t
));
134 mips_supply_gregset (regcache
, (const mips_elf_gregset_t
*)gregs
);
137 /* Pack our registers (or one register) into an elf_gregset_t. */
140 mips_fill_gregset (const struct regcache
*regcache
,
141 mips_elf_gregset_t
*gregsetp
, int regno
)
143 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
145 mips_elf_greg_t
*regp
= *gregsetp
;
150 memset (regp
, 0, sizeof (mips_elf_gregset_t
));
151 for (regi
= 1; regi
< 32; regi
++)
152 mips_fill_gregset (regcache
, gregsetp
, regi
);
153 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
154 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
155 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
156 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->badvaddr
);
157 mips_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
158 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
159 mips_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
163 if (regno
> 0 && regno
< 32)
165 dst
= regp
+ regno
+ EF_REG0
;
166 regcache_raw_collect (regcache
, regno
, dst
);
170 if (regno
== mips_regnum (gdbarch
)->lo
)
172 else if (regno
== mips_regnum (gdbarch
)->hi
)
174 else if (regno
== mips_regnum (gdbarch
)->pc
)
175 regaddr
= EF_CP0_EPC
;
176 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
177 regaddr
= EF_CP0_BADVADDR
;
178 else if (regno
== MIPS_PS_REGNUM
)
179 regaddr
= EF_CP0_STATUS
;
180 else if (regno
== mips_regnum (gdbarch
)->cause
)
181 regaddr
= EF_CP0_CAUSE
;
182 else if (mips_linux_restart_reg_p (gdbarch
)
183 && regno
== MIPS_RESTART_REGNUM
)
190 dst
= regp
+ regaddr
;
191 regcache_raw_collect (regcache
, regno
, dst
);
196 mips_fill_gregset_wrapper (const struct regset
*regset
,
197 const struct regcache
*regcache
,
198 int regnum
, void *gregs
, size_t len
)
200 gdb_assert (len
== sizeof (mips_elf_gregset_t
));
202 mips_fill_gregset (regcache
, (mips_elf_gregset_t
*)gregs
, regnum
);
205 /* Likewise, unpack an elf_fpregset_t. */
208 mips_supply_fpregset (struct regcache
*regcache
,
209 const mips_elf_fpregset_t
*fpregsetp
)
211 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
213 char zerobuf
[MAX_REGISTER_SIZE
];
215 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
217 for (regi
= 0; regi
< 32; regi
++)
218 regcache_raw_supply (regcache
,
219 gdbarch_fp0_regnum (gdbarch
) + regi
,
222 regcache_raw_supply (regcache
,
223 mips_regnum (gdbarch
)->fp_control_status
,
226 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
227 regcache_raw_supply (regcache
,
228 mips_regnum (gdbarch
)->fp_implementation_revision
,
233 mips_supply_fpregset_wrapper (const struct regset
*regset
,
234 struct regcache
*regcache
,
235 int regnum
, const void *gregs
, size_t len
)
237 gdb_assert (len
== sizeof (mips_elf_fpregset_t
));
239 mips_supply_fpregset (regcache
, (const mips_elf_fpregset_t
*)gregs
);
242 /* Likewise, pack one or all floating point registers into an
246 mips_fill_fpregset (const struct regcache
*regcache
,
247 mips_elf_fpregset_t
*fpregsetp
, int regno
)
249 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
252 if ((regno
>= gdbarch_fp0_regnum (gdbarch
))
253 && (regno
< gdbarch_fp0_regnum (gdbarch
) + 32))
255 to
= (char *) (*fpregsetp
+ regno
- gdbarch_fp0_regnum (gdbarch
));
256 regcache_raw_collect (regcache
, regno
, to
);
258 else if (regno
== mips_regnum (gdbarch
)->fp_control_status
)
260 to
= (char *) (*fpregsetp
+ 32);
261 regcache_raw_collect (regcache
, regno
, to
);
263 else if (regno
== -1)
267 for (regi
= 0; regi
< 32; regi
++)
268 mips_fill_fpregset (regcache
, fpregsetp
,
269 gdbarch_fp0_regnum (gdbarch
) + regi
);
270 mips_fill_fpregset (regcache
, fpregsetp
,
271 mips_regnum (gdbarch
)->fp_control_status
);
276 mips_fill_fpregset_wrapper (const struct regset
*regset
,
277 const struct regcache
*regcache
,
278 int regnum
, void *gregs
, size_t len
)
280 gdb_assert (len
== sizeof (mips_elf_fpregset_t
));
282 mips_fill_fpregset (regcache
, (mips_elf_fpregset_t
*)gregs
, regnum
);
285 /* Support for 64-bit ABIs. */
287 /* Figure out where the longjmp will land.
288 We expect the first arg to be a pointer to the jmp_buf structure
289 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
290 at. The pc is copied into PC. This routine returns 1 on
293 /* Details about jmp_buf. */
295 #define MIPS64_LINUX_JB_PC 0
298 mips64_linux_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
301 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
302 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
303 void *buf
= alloca (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
304 int element_size
= gdbarch_ptr_bit (gdbarch
) == 32 ? 4 : 8;
306 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
308 if (target_read_memory (jb_addr
+ MIPS64_LINUX_JB_PC
* element_size
,
310 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
313 *pc
= extract_unsigned_integer (buf
,
314 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
320 /* Register set support functions. These operate on standard 64-bit
321 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
322 target will still use the 64-bit format for PTRACE_GETREGS. */
324 /* Supply a 64-bit register. */
327 supply_64bit_reg (struct regcache
*regcache
, int regnum
,
330 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
331 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
332 && register_size (gdbarch
, regnum
) == 4)
333 regcache_raw_supply (regcache
, regnum
, buf
+ 4);
335 regcache_raw_supply (regcache
, regnum
, buf
);
338 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
341 mips64_supply_gregset (struct regcache
*regcache
,
342 const mips64_elf_gregset_t
*gregsetp
)
345 const mips64_elf_greg_t
*regp
= *gregsetp
;
346 gdb_byte zerobuf
[MAX_REGISTER_SIZE
];
347 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
349 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
351 for (regi
= MIPS64_EF_REG0
+ 1; regi
<= MIPS64_EF_REG31
; regi
++)
352 supply_64bit_reg (regcache
, regi
- MIPS64_EF_REG0
,
353 (const gdb_byte
*)(regp
+ regi
));
355 if (mips_linux_restart_reg_p (gdbarch
))
356 supply_64bit_reg (regcache
, MIPS_RESTART_REGNUM
,
357 (const gdb_byte
*)(regp
+ MIPS64_EF_REG0
));
359 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->lo
,
360 (const gdb_byte
*) (regp
+ MIPS64_EF_LO
));
361 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->hi
,
362 (const gdb_byte
*) (regp
+ MIPS64_EF_HI
));
364 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
365 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_EPC
));
366 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
367 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_BADVADDR
));
368 supply_64bit_reg (regcache
, MIPS_PS_REGNUM
,
369 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_STATUS
));
370 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
371 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_CAUSE
));
373 /* Fill the inaccessible zero register with zero. */
374 regcache_raw_supply (regcache
, MIPS_ZERO_REGNUM
, zerobuf
);
378 mips64_supply_gregset_wrapper (const struct regset
*regset
,
379 struct regcache
*regcache
,
380 int regnum
, const void *gregs
, size_t len
)
382 gdb_assert (len
== sizeof (mips64_elf_gregset_t
));
384 mips64_supply_gregset (regcache
, (const mips64_elf_gregset_t
*)gregs
);
387 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
390 mips64_fill_gregset (const struct regcache
*regcache
,
391 mips64_elf_gregset_t
*gregsetp
, int regno
)
393 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
394 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
396 mips64_elf_greg_t
*regp
= *gregsetp
;
401 memset (regp
, 0, sizeof (mips64_elf_gregset_t
));
402 for (regi
= 1; regi
< 32; regi
++)
403 mips64_fill_gregset (regcache
, gregsetp
, regi
);
404 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
405 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
406 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
407 mips64_fill_gregset (regcache
, gregsetp
,
408 mips_regnum (gdbarch
)->badvaddr
);
409 mips64_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
410 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
411 mips64_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
415 if (regno
> 0 && regno
< 32)
416 regaddr
= regno
+ MIPS64_EF_REG0
;
417 else if (regno
== mips_regnum (gdbarch
)->lo
)
418 regaddr
= MIPS64_EF_LO
;
419 else if (regno
== mips_regnum (gdbarch
)->hi
)
420 regaddr
= MIPS64_EF_HI
;
421 else if (regno
== mips_regnum (gdbarch
)->pc
)
422 regaddr
= MIPS64_EF_CP0_EPC
;
423 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
424 regaddr
= MIPS64_EF_CP0_BADVADDR
;
425 else if (regno
== MIPS_PS_REGNUM
)
426 regaddr
= MIPS64_EF_CP0_STATUS
;
427 else if (regno
== mips_regnum (gdbarch
)->cause
)
428 regaddr
= MIPS64_EF_CP0_CAUSE
;
429 else if (mips_linux_restart_reg_p (gdbarch
)
430 && regno
== MIPS_RESTART_REGNUM
)
431 regaddr
= MIPS64_EF_REG0
;
437 gdb_byte buf
[MAX_REGISTER_SIZE
];
440 regcache_raw_collect (regcache
, regno
, buf
);
441 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
443 dst
= regp
+ regaddr
;
444 store_signed_integer (dst
, 8, byte_order
, val
);
449 mips64_fill_gregset_wrapper (const struct regset
*regset
,
450 const struct regcache
*regcache
,
451 int regnum
, void *gregs
, size_t len
)
453 gdb_assert (len
== sizeof (mips64_elf_gregset_t
));
455 mips64_fill_gregset (regcache
, (mips64_elf_gregset_t
*)gregs
, regnum
);
458 /* Likewise, unpack an elf_fpregset_t. */
461 mips64_supply_fpregset (struct regcache
*regcache
,
462 const mips64_elf_fpregset_t
*fpregsetp
)
464 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
467 /* See mips_linux_o32_sigframe_init for a description of the
468 peculiar FP register layout. */
469 if (register_size (gdbarch
, gdbarch_fp0_regnum (gdbarch
)) == 4)
470 for (regi
= 0; regi
< 32; regi
++)
472 const gdb_byte
*reg_ptr
= (const gdb_byte
*)(*fpregsetp
+ (regi
& ~1));
473 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
475 regcache_raw_supply (regcache
,
476 gdbarch_fp0_regnum (gdbarch
) + regi
,
480 for (regi
= 0; regi
< 32; regi
++)
481 regcache_raw_supply (regcache
,
482 gdbarch_fp0_regnum (gdbarch
) + regi
,
483 (const char *)(*fpregsetp
+ regi
));
485 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->fp_control_status
,
486 (const gdb_byte
*)(*fpregsetp
+ 32));
488 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
489 include it - but the result of PTRACE_GETFPREGS does. The best we
490 can do is to assume that its value is present. */
491 supply_32bit_reg (regcache
,
492 mips_regnum (gdbarch
)->fp_implementation_revision
,
493 (const gdb_byte
*)(*fpregsetp
+ 32) + 4);
497 mips64_supply_fpregset_wrapper (const struct regset
*regset
,
498 struct regcache
*regcache
,
499 int regnum
, const void *gregs
, size_t len
)
501 gdb_assert (len
== sizeof (mips64_elf_fpregset_t
));
503 mips64_supply_fpregset (regcache
, (const mips64_elf_fpregset_t
*)gregs
);
506 /* Likewise, pack one or all floating point registers into an
510 mips64_fill_fpregset (const struct regcache
*regcache
,
511 mips64_elf_fpregset_t
*fpregsetp
, int regno
)
513 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
514 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
517 if ((regno
>= gdbarch_fp0_regnum (gdbarch
))
518 && (regno
< gdbarch_fp0_regnum (gdbarch
) + 32))
520 /* See mips_linux_o32_sigframe_init for a description of the
521 peculiar FP register layout. */
522 if (register_size (gdbarch
, regno
) == 4)
524 int regi
= regno
- gdbarch_fp0_regnum (gdbarch
);
526 to
= (gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
527 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
529 regcache_raw_collect (regcache
, regno
, to
);
533 to
= (gdb_byte
*) (*fpregsetp
+ regno
534 - gdbarch_fp0_regnum (gdbarch
));
535 regcache_raw_collect (regcache
, regno
, to
);
538 else if (regno
== mips_regnum (gdbarch
)->fp_control_status
)
540 gdb_byte buf
[MAX_REGISTER_SIZE
];
543 regcache_raw_collect (regcache
, regno
, buf
);
544 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
546 to
= (gdb_byte
*) (*fpregsetp
+ 32);
547 store_signed_integer (to
, 4, byte_order
, val
);
549 else if (regno
== mips_regnum (gdbarch
)->fp_implementation_revision
)
551 gdb_byte buf
[MAX_REGISTER_SIZE
];
554 regcache_raw_collect (regcache
, regno
, buf
);
555 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
557 to
= (gdb_byte
*) (*fpregsetp
+ 32) + 4;
558 store_signed_integer (to
, 4, byte_order
, val
);
560 else if (regno
== -1)
564 for (regi
= 0; regi
< 32; regi
++)
565 mips64_fill_fpregset (regcache
, fpregsetp
,
566 gdbarch_fp0_regnum (gdbarch
) + regi
);
567 mips64_fill_fpregset (regcache
, fpregsetp
,
568 mips_regnum (gdbarch
)->fp_control_status
);
569 mips64_fill_fpregset (regcache
, fpregsetp
,
570 (mips_regnum (gdbarch
)
571 ->fp_implementation_revision
));
576 mips64_fill_fpregset_wrapper (const struct regset
*regset
,
577 const struct regcache
*regcache
,
578 int regnum
, void *gregs
, size_t len
)
580 gdb_assert (len
== sizeof (mips64_elf_fpregset_t
));
582 mips64_fill_fpregset (regcache
, (mips64_elf_fpregset_t
*)gregs
, regnum
);
585 static const struct regset
*
586 mips_linux_regset_from_core_section (struct gdbarch
*gdbarch
,
587 const char *sect_name
, size_t sect_size
)
589 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
590 mips_elf_gregset_t gregset
;
591 mips_elf_fpregset_t fpregset
;
592 mips64_elf_gregset_t gregset64
;
593 mips64_elf_fpregset_t fpregset64
;
595 if (strcmp (sect_name
, ".reg") == 0)
597 if (sect_size
== sizeof (gregset
))
599 if (tdep
->gregset
== NULL
)
600 tdep
->gregset
= regset_alloc (gdbarch
,
601 mips_supply_gregset_wrapper
,
602 mips_fill_gregset_wrapper
);
603 return tdep
->gregset
;
605 else if (sect_size
== sizeof (gregset64
))
607 if (tdep
->gregset64
== NULL
)
608 tdep
->gregset64
= regset_alloc (gdbarch
,
609 mips64_supply_gregset_wrapper
,
610 mips64_fill_gregset_wrapper
);
611 return tdep
->gregset64
;
615 warning (_("wrong size gregset struct in core file"));
618 else if (strcmp (sect_name
, ".reg2") == 0)
620 if (sect_size
== sizeof (fpregset
))
622 if (tdep
->fpregset
== NULL
)
623 tdep
->fpregset
= regset_alloc (gdbarch
,
624 mips_supply_fpregset_wrapper
,
625 mips_fill_fpregset_wrapper
);
626 return tdep
->fpregset
;
628 else if (sect_size
== sizeof (fpregset64
))
630 if (tdep
->fpregset64
== NULL
)
631 tdep
->fpregset64
= regset_alloc (gdbarch
,
632 mips64_supply_fpregset_wrapper
,
633 mips64_fill_fpregset_wrapper
);
634 return tdep
->fpregset64
;
638 warning (_("wrong size fpregset struct in core file"));
645 static const struct target_desc
*
646 mips_linux_core_read_description (struct gdbarch
*gdbarch
,
647 struct target_ops
*target
,
650 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
654 switch (bfd_section_size (abfd
, section
))
656 case sizeof (mips_elf_gregset_t
):
657 return mips_tdesc_gp32
;
659 case sizeof (mips64_elf_gregset_t
):
660 return mips_tdesc_gp64
;
668 /* Check the code at PC for a dynamic linker lazy resolution stub.
669 Because they aren't in the .plt section, we pattern-match on the
670 code generated by GNU ld. They look like this:
677 (with the appropriate doubleword instructions for N64). Also
678 return the dynamic symbol index used in the last instruction. */
681 mips_linux_in_dynsym_stub (CORE_ADDR pc
, char *name
)
683 unsigned char buf
[28], *p
;
684 ULONGEST insn
, insn1
;
685 int n64
= (mips_abi (target_gdbarch ()) == MIPS_ABI_N64
);
686 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
688 read_memory (pc
- 12, buf
, 28);
692 /* ld t9,0x8010(gp) */
697 /* lw t9,0x8010(gp) */
704 insn
= extract_unsigned_integer (p
, 4, byte_order
);
712 insn
= extract_unsigned_integer (p
+ 4, 4, byte_order
);
716 if (insn
!= 0x03e0782d)
722 if (insn
!= 0x03e07821)
726 insn
= extract_unsigned_integer (p
+ 8, 4, byte_order
);
728 if (insn
!= 0x0320f809)
731 insn
= extract_unsigned_integer (p
+ 12, 4, byte_order
);
734 /* daddiu t8,zero,0 */
735 if ((insn
& 0xffff0000) != 0x64180000)
740 /* addiu t8,zero,0 */
741 if ((insn
& 0xffff0000) != 0x24180000)
745 return (insn
& 0xffff);
748 /* Return non-zero iff PC belongs to the dynamic linker resolution
749 code, a PLT entry, or a lazy binding stub. */
752 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
754 /* Check whether PC is in the dynamic linker. This also checks
755 whether it is in the .plt section, used by non-PIC executables. */
756 if (svr4_in_dynsym_resolve_code (pc
))
759 /* Pattern match for the stub. It would be nice if there were a
760 more efficient way to avoid this check. */
761 if (mips_linux_in_dynsym_stub (pc
, NULL
))
767 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
768 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
769 implementation of this triggers at "fixup" from the same objfile as
770 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
771 "__dl_runtime_resolve" directly. An unresolved lazy binding
772 stub will point to _dl_runtime_resolve, which will first call
773 __dl_runtime_resolve, and then pass control to the resolved
777 mips_linux_skip_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
779 struct minimal_symbol
*resolver
;
781 resolver
= lookup_minimal_symbol ("__dl_runtime_resolve", NULL
, NULL
);
783 if (resolver
&& SYMBOL_VALUE_ADDRESS (resolver
) == pc
)
784 return frame_unwind_caller_pc (get_current_frame ());
786 return glibc_skip_solib_resolver (gdbarch
, pc
);
789 /* Signal trampoline support. There are four supported layouts for a
790 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
791 n64 rt_sigframe. We handle them all independently; not the most
792 efficient way, but simplest. First, declare all the unwinders. */
794 static void mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
795 struct frame_info
*this_frame
,
796 struct trad_frame_cache
*this_cache
,
799 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
800 struct frame_info
*this_frame
,
801 struct trad_frame_cache
*this_cache
,
804 #define MIPS_NR_LINUX 4000
805 #define MIPS_NR_N64_LINUX 5000
806 #define MIPS_NR_N32_LINUX 6000
808 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
809 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
810 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
811 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
813 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
814 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
815 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
816 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
817 #define MIPS_INST_SYSCALL 0x0000000c
819 static const struct tramp_frame mips_linux_o32_sigframe
= {
823 { MIPS_INST_LI_V0_SIGRETURN
, -1 },
824 { MIPS_INST_SYSCALL
, -1 },
825 { TRAMP_SENTINEL_INSN
, -1 }
827 mips_linux_o32_sigframe_init
830 static const struct tramp_frame mips_linux_o32_rt_sigframe
= {
834 { MIPS_INST_LI_V0_RT_SIGRETURN
, -1 },
835 { MIPS_INST_SYSCALL
, -1 },
836 { TRAMP_SENTINEL_INSN
, -1 } },
837 mips_linux_o32_sigframe_init
840 static const struct tramp_frame mips_linux_n32_rt_sigframe
= {
844 { MIPS_INST_LI_V0_N32_RT_SIGRETURN
, -1 },
845 { MIPS_INST_SYSCALL
, -1 },
846 { TRAMP_SENTINEL_INSN
, -1 }
848 mips_linux_n32n64_sigframe_init
851 static const struct tramp_frame mips_linux_n64_rt_sigframe
= {
855 { MIPS_INST_LI_V0_N64_RT_SIGRETURN
, -1 },
856 { MIPS_INST_SYSCALL
, -1 },
857 { TRAMP_SENTINEL_INSN
, -1 }
859 mips_linux_n32n64_sigframe_init
863 /* The unwinder for o32 signal frames. The legacy structures look
867 u32 sf_ass[4]; [argument save space for o32]
868 u32 sf_code[2]; [signal trampoline or fill]
869 struct sigcontext sf_sc;
873 Pre-2.6.12 sigcontext:
876 unsigned int sc_regmask; [Unused]
877 unsigned int sc_status;
878 unsigned long long sc_pc;
879 unsigned long long sc_regs[32];
880 unsigned long long sc_fpregs[32];
881 unsigned int sc_ownedfp;
882 unsigned int sc_fpc_csr;
883 unsigned int sc_fpc_eir; [Unused]
884 unsigned int sc_used_math;
885 unsigned int sc_ssflags; [Unused]
886 [Alignment hole of four bytes]
887 unsigned long long sc_mdhi;
888 unsigned long long sc_mdlo;
890 unsigned int sc_cause; [Unused]
891 unsigned int sc_badvaddr; [Unused]
893 unsigned long sc_sigset[4]; [kernel's sigset_t]
896 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
899 unsigned int sc_regmask; [Unused]
900 unsigned int sc_status; [Unused]
901 unsigned long long sc_pc;
902 unsigned long long sc_regs[32];
903 unsigned long long sc_fpregs[32];
905 unsigned int sc_fpc_csr;
906 unsigned int sc_fpc_eir; [Unused]
907 unsigned int sc_used_math;
909 [Alignment hole of four bytes]
910 unsigned long long sc_mdhi;
911 unsigned long long sc_mdlo;
912 unsigned long sc_hi1;
913 unsigned long sc_lo1;
914 unsigned long sc_hi2;
915 unsigned long sc_lo2;
916 unsigned long sc_hi3;
917 unsigned long sc_lo3;
920 The RT signal frames look like this:
923 u32 rs_ass[4]; [argument save space for o32]
924 u32 rs_code[2] [signal trampoline or fill]
925 struct siginfo rs_info;
926 struct ucontext rs_uc;
930 unsigned long uc_flags;
931 struct ucontext *uc_link;
933 [Alignment hole of four bytes]
934 struct sigcontext uc_mcontext;
939 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
941 #define RTSIGFRAME_SIGINFO_SIZE 128
942 #define STACK_T_SIZE (3 * 4)
943 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
944 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
945 + RTSIGFRAME_SIGINFO_SIZE \
946 + UCONTEXT_SIGCONTEXT_OFFSET)
948 #define SIGCONTEXT_PC (1 * 8)
949 #define SIGCONTEXT_REGS (2 * 8)
950 #define SIGCONTEXT_FPREGS (34 * 8)
951 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
952 #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
953 #define SIGCONTEXT_HI (69 * 8)
954 #define SIGCONTEXT_LO (70 * 8)
955 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
956 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
957 #define SIGCONTEXT_HI1 (71 * 8 + 0)
958 #define SIGCONTEXT_LO1 (71 * 8 + 4)
959 #define SIGCONTEXT_HI2 (72 * 8 + 0)
960 #define SIGCONTEXT_LO2 (72 * 8 + 4)
961 #define SIGCONTEXT_HI3 (73 * 8 + 0)
962 #define SIGCONTEXT_LO3 (73 * 8 + 4)
964 #define SIGCONTEXT_REG_SIZE 8
967 mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
968 struct frame_info
*this_frame
,
969 struct trad_frame_cache
*this_cache
,
972 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
974 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
975 CORE_ADDR sigcontext_base
;
976 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
979 if (self
== &mips_linux_o32_sigframe
)
980 sigcontext_base
= frame_sp
+ SIGFRAME_SIGCONTEXT_OFFSET
;
982 sigcontext_base
= frame_sp
+ RTSIGFRAME_SIGCONTEXT_OFFSET
;
984 /* I'm not proud of this hack. Eventually we will have the
985 infrastructure to indicate the size of saved registers on a
986 per-frame basis, but right now we don't; the kernel saves eight
987 bytes but we only want four. Use regs_base to access any
989 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
990 regs_base
= sigcontext_base
+ 4;
992 regs_base
= sigcontext_base
;
994 if (mips_linux_restart_reg_p (gdbarch
))
995 trad_frame_set_reg_addr (this_cache
,
997 + gdbarch_num_regs (gdbarch
)),
998 regs_base
+ SIGCONTEXT_REGS
);
1000 for (ireg
= 1; ireg
< 32; ireg
++)
1001 trad_frame_set_reg_addr (this_cache
,
1002 ireg
+ MIPS_ZERO_REGNUM
1003 + gdbarch_num_regs (gdbarch
),
1004 regs_base
+ SIGCONTEXT_REGS
1005 + ireg
* SIGCONTEXT_REG_SIZE
);
1007 /* The way that floating point registers are saved, unfortunately,
1008 depends on the architecture the kernel is built for. For the r3000 and
1009 tx39, four bytes of each register are at the beginning of each of the
1010 32 eight byte slots. For everything else, the registers are saved
1011 using double precision; only the even-numbered slots are initialized,
1012 and the high bits are the odd-numbered register. Assume the latter
1013 layout, since we can't tell, and it's much more common. Which bits are
1014 the "high" bits depends on endianness. */
1015 for (ireg
= 0; ireg
< 32; ireg
++)
1016 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (ireg
& 1))
1017 trad_frame_set_reg_addr (this_cache
,
1019 gdbarch_num_regs (gdbarch
),
1020 sigcontext_base
+ SIGCONTEXT_FPREGS
+ 4
1021 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
);
1023 trad_frame_set_reg_addr (this_cache
,
1025 + gdbarch_num_regs (gdbarch
),
1026 sigcontext_base
+ SIGCONTEXT_FPREGS
1027 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
);
1029 trad_frame_set_reg_addr (this_cache
,
1030 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1031 regs_base
+ SIGCONTEXT_PC
);
1033 trad_frame_set_reg_addr (this_cache
,
1034 regs
->fp_control_status
1035 + gdbarch_num_regs (gdbarch
),
1036 sigcontext_base
+ SIGCONTEXT_FPCSR
);
1038 if (regs
->dspctl
!= -1)
1039 trad_frame_set_reg_addr (this_cache
,
1040 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1041 sigcontext_base
+ SIGCONTEXT_DSPCTL
);
1043 trad_frame_set_reg_addr (this_cache
,
1044 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1045 regs_base
+ SIGCONTEXT_HI
);
1046 trad_frame_set_reg_addr (this_cache
,
1047 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1048 regs_base
+ SIGCONTEXT_LO
);
1050 if (regs
->dspacc
!= -1)
1052 trad_frame_set_reg_addr (this_cache
,
1053 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1054 sigcontext_base
+ SIGCONTEXT_HI1
);
1055 trad_frame_set_reg_addr (this_cache
,
1056 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1057 sigcontext_base
+ SIGCONTEXT_LO1
);
1058 trad_frame_set_reg_addr (this_cache
,
1059 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1060 sigcontext_base
+ SIGCONTEXT_HI2
);
1061 trad_frame_set_reg_addr (this_cache
,
1062 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1063 sigcontext_base
+ SIGCONTEXT_LO2
);
1064 trad_frame_set_reg_addr (this_cache
,
1065 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1066 sigcontext_base
+ SIGCONTEXT_HI3
);
1067 trad_frame_set_reg_addr (this_cache
,
1068 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1069 sigcontext_base
+ SIGCONTEXT_LO3
);
1073 trad_frame_set_reg_addr (this_cache
,
1074 regs
->cause
+ gdbarch_num_regs (gdbarch
),
1075 sigcontext_base
+ SIGCONTEXT_CAUSE
);
1076 trad_frame_set_reg_addr (this_cache
,
1077 regs
->badvaddr
+ gdbarch_num_regs (gdbarch
),
1078 sigcontext_base
+ SIGCONTEXT_BADVADDR
);
1081 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1082 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1086 /* For N32/N64 things look different. There is no non-rt signal frame.
1088 struct rt_sigframe_n32 {
1089 u32 rs_ass[4]; [ argument save space for o32 ]
1090 u32 rs_code[2]; [ signal trampoline or fill ]
1091 struct siginfo rs_info;
1092 struct ucontextn32 rs_uc;
1095 struct ucontextn32 {
1099 struct sigcontext uc_mcontext;
1100 sigset_t uc_sigmask; [ mask last for extensibility ]
1103 struct rt_sigframe {
1104 u32 rs_ass[4]; [ argument save space for o32 ]
1105 u32 rs_code[2]; [ signal trampoline ]
1106 struct siginfo rs_info;
1107 struct ucontext rs_uc;
1111 unsigned long uc_flags;
1112 struct ucontext *uc_link;
1114 struct sigcontext uc_mcontext;
1115 sigset_t uc_sigmask; [ mask last for extensibility ]
1118 And the sigcontext is different (this is for both n32 and n64):
1121 unsigned long long sc_regs[32];
1122 unsigned long long sc_fpregs[32];
1123 unsigned long long sc_mdhi;
1124 unsigned long long sc_hi1;
1125 unsigned long long sc_hi2;
1126 unsigned long long sc_hi3;
1127 unsigned long long sc_mdlo;
1128 unsigned long long sc_lo1;
1129 unsigned long long sc_lo2;
1130 unsigned long long sc_lo3;
1131 unsigned long long sc_pc;
1132 unsigned int sc_fpc_csr;
1133 unsigned int sc_used_math;
1134 unsigned int sc_dsp;
1135 unsigned int sc_reserved;
1138 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1139 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1143 #define N32_STACK_T_SIZE STACK_T_SIZE
1144 #define N64_STACK_T_SIZE (2 * 8 + 4)
1145 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1146 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1147 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1148 + RTSIGFRAME_SIGINFO_SIZE \
1149 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1150 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1151 + RTSIGFRAME_SIGINFO_SIZE \
1152 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1154 #define N64_SIGCONTEXT_REGS (0 * 8)
1155 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1156 #define N64_SIGCONTEXT_HI (64 * 8)
1157 #define N64_SIGCONTEXT_HI1 (65 * 8)
1158 #define N64_SIGCONTEXT_HI2 (66 * 8)
1159 #define N64_SIGCONTEXT_HI3 (67 * 8)
1160 #define N64_SIGCONTEXT_LO (68 * 8)
1161 #define N64_SIGCONTEXT_LO1 (69 * 8)
1162 #define N64_SIGCONTEXT_LO2 (70 * 8)
1163 #define N64_SIGCONTEXT_LO3 (71 * 8)
1164 #define N64_SIGCONTEXT_PC (72 * 8)
1165 #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1166 #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1168 #define N64_SIGCONTEXT_REG_SIZE 8
1171 mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
1172 struct frame_info
*this_frame
,
1173 struct trad_frame_cache
*this_cache
,
1176 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1178 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
1179 CORE_ADDR sigcontext_base
;
1180 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
1182 if (self
== &mips_linux_n32_rt_sigframe
)
1183 sigcontext_base
= frame_sp
+ N32_SIGFRAME_SIGCONTEXT_OFFSET
;
1185 sigcontext_base
= frame_sp
+ N64_SIGFRAME_SIGCONTEXT_OFFSET
;
1187 if (mips_linux_restart_reg_p (gdbarch
))
1188 trad_frame_set_reg_addr (this_cache
,
1189 (MIPS_RESTART_REGNUM
1190 + gdbarch_num_regs (gdbarch
)),
1191 sigcontext_base
+ N64_SIGCONTEXT_REGS
);
1193 for (ireg
= 1; ireg
< 32; ireg
++)
1194 trad_frame_set_reg_addr (this_cache
,
1195 ireg
+ MIPS_ZERO_REGNUM
1196 + gdbarch_num_regs (gdbarch
),
1197 sigcontext_base
+ N64_SIGCONTEXT_REGS
1198 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
1200 for (ireg
= 0; ireg
< 32; ireg
++)
1201 trad_frame_set_reg_addr (this_cache
,
1203 + gdbarch_num_regs (gdbarch
),
1204 sigcontext_base
+ N64_SIGCONTEXT_FPREGS
1205 + ireg
* N64_SIGCONTEXT_REG_SIZE
);
1207 trad_frame_set_reg_addr (this_cache
,
1208 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1209 sigcontext_base
+ N64_SIGCONTEXT_PC
);
1211 trad_frame_set_reg_addr (this_cache
,
1212 regs
->fp_control_status
1213 + gdbarch_num_regs (gdbarch
),
1214 sigcontext_base
+ N64_SIGCONTEXT_FPCSR
);
1216 trad_frame_set_reg_addr (this_cache
,
1217 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1218 sigcontext_base
+ N64_SIGCONTEXT_HI
);
1219 trad_frame_set_reg_addr (this_cache
,
1220 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1221 sigcontext_base
+ N64_SIGCONTEXT_LO
);
1223 if (regs
->dspacc
!= -1)
1225 trad_frame_set_reg_addr (this_cache
,
1226 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1227 sigcontext_base
+ N64_SIGCONTEXT_HI1
);
1228 trad_frame_set_reg_addr (this_cache
,
1229 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1230 sigcontext_base
+ N64_SIGCONTEXT_LO1
);
1231 trad_frame_set_reg_addr (this_cache
,
1232 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1233 sigcontext_base
+ N64_SIGCONTEXT_HI2
);
1234 trad_frame_set_reg_addr (this_cache
,
1235 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1236 sigcontext_base
+ N64_SIGCONTEXT_LO2
);
1237 trad_frame_set_reg_addr (this_cache
,
1238 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1239 sigcontext_base
+ N64_SIGCONTEXT_HI3
);
1240 trad_frame_set_reg_addr (this_cache
,
1241 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1242 sigcontext_base
+ N64_SIGCONTEXT_LO3
);
1244 if (regs
->dspctl
!= -1)
1245 trad_frame_set_reg_addr (this_cache
,
1246 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1247 sigcontext_base
+ N64_SIGCONTEXT_DSPCTL
);
1249 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1250 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1253 /* Implement the "write_pc" gdbarch method. */
1256 mips_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1258 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1260 mips_write_pc (regcache
, pc
);
1262 /* Clear the syscall restart flag. */
1263 if (mips_linux_restart_reg_p (gdbarch
))
1264 regcache_cooked_write_unsigned (regcache
, MIPS_RESTART_REGNUM
, 0);
1267 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1270 mips_linux_restart_reg_p (struct gdbarch
*gdbarch
)
1272 /* If we do not have a target description with registers, then
1273 MIPS_RESTART_REGNUM will not be included in the register set. */
1274 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
1277 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1278 either be GPR-sized or missing. */
1279 return register_size (gdbarch
, MIPS_RESTART_REGNUM
) > 0;
1282 /* When FRAME is at a syscall instruction, return the PC of the next
1283 instruction to be executed. */
1286 mips_linux_syscall_next_pc (struct frame_info
*frame
)
1288 CORE_ADDR pc
= get_frame_pc (frame
);
1289 ULONGEST v0
= get_frame_register_unsigned (frame
, MIPS_V0_REGNUM
);
1291 /* If we are about to make a sigreturn syscall, use the unwinder to
1292 decode the signal frame. */
1293 if (v0
== MIPS_NR_sigreturn
1294 || v0
== MIPS_NR_rt_sigreturn
1295 || v0
== MIPS_NR_N64_rt_sigreturn
1296 || v0
== MIPS_NR_N32_rt_sigreturn
)
1297 return frame_unwind_caller_pc (get_current_frame ());
1302 /* Return the current system call's number present in the
1303 v0 register. When the function fails, it returns -1. */
1306 mips_linux_get_syscall_number (struct gdbarch
*gdbarch
,
1309 struct regcache
*regcache
= get_thread_regcache (ptid
);
1310 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1311 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1312 int regsize
= register_size (gdbarch
, MIPS_V0_REGNUM
);
1313 /* The content of a register */
1318 /* Make sure we're in a known ABI */
1319 gdb_assert (tdep
->mips_abi
== MIPS_ABI_O32
1320 || tdep
->mips_abi
== MIPS_ABI_N32
1321 || tdep
->mips_abi
== MIPS_ABI_N64
);
1323 gdb_assert (regsize
<= sizeof (buf
));
1325 /* Getting the system call number from the register.
1326 syscall number is in v0 or $2. */
1327 regcache_cooked_read (regcache
, MIPS_V0_REGNUM
, buf
);
1329 ret
= extract_signed_integer (buf
, regsize
, byte_order
);
1334 /* Translate signals based on MIPS signal values.
1335 Adapted from gdb/common/signals.c. */
1337 static enum gdb_signal
1338 mips_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signo
)
1343 return GDB_SIGNAL_0
;
1345 return GDB_SIGNAL_HUP
;
1347 return GDB_SIGNAL_INT
;
1349 return GDB_SIGNAL_QUIT
;
1351 return GDB_SIGNAL_ILL
;
1353 return GDB_SIGNAL_TRAP
;
1355 return GDB_SIGNAL_ABRT
;
1357 return GDB_SIGNAL_EMT
;
1359 return GDB_SIGNAL_FPE
;
1361 return GDB_SIGNAL_KILL
;
1363 return GDB_SIGNAL_BUS
;
1365 return GDB_SIGNAL_SEGV
;
1367 return GDB_SIGNAL_SYS
;
1369 return GDB_SIGNAL_PIPE
;
1371 return GDB_SIGNAL_ALRM
;
1373 return GDB_SIGNAL_TERM
;
1375 return GDB_SIGNAL_USR1
;
1377 return GDB_SIGNAL_USR2
;
1379 return GDB_SIGNAL_CHLD
;
1381 return GDB_SIGNAL_PWR
;
1383 return GDB_SIGNAL_WINCH
;
1385 return GDB_SIGNAL_URG
;
1387 return GDB_SIGNAL_POLL
;
1389 return GDB_SIGNAL_STOP
;
1391 return GDB_SIGNAL_TSTP
;
1393 return GDB_SIGNAL_CONT
;
1395 return GDB_SIGNAL_TTIN
;
1397 return GDB_SIGNAL_TTOU
;
1398 case MIPS_SIGVTALRM
:
1399 return GDB_SIGNAL_VTALRM
;
1401 return GDB_SIGNAL_PROF
;
1403 return GDB_SIGNAL_XCPU
;
1405 return GDB_SIGNAL_XFSZ
;
1408 if (signo
>= MIPS_SIGRTMIN
&& signo
<= MIPS_SIGRTMAX
)
1410 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1411 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1412 signo
-= MIPS_SIGRTMIN
;
1414 return GDB_SIGNAL_REALTIME_32
;
1415 else if (signo
< 32)
1416 return ((enum gdb_signal
) (signo
- 1 + (int) GDB_SIGNAL_REALTIME_33
));
1418 return ((enum gdb_signal
) (signo
- 32 + (int) GDB_SIGNAL_REALTIME_64
));
1421 return GDB_SIGNAL_UNKNOWN
;
1424 /* Initialize one of the GNU/Linux OS ABIs. */
1427 mips_linux_init_abi (struct gdbarch_info info
,
1428 struct gdbarch
*gdbarch
)
1430 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1431 enum mips_abi abi
= mips_abi (gdbarch
);
1432 struct tdesc_arch_data
*tdesc_data
= (void *) info
.tdep_info
;
1434 linux_init_abi (info
, gdbarch
);
1436 /* Get the syscall number from the arch's register. */
1437 set_gdbarch_get_syscall_number (gdbarch
, mips_linux_get_syscall_number
);
1442 set_gdbarch_get_longjmp_target (gdbarch
,
1443 mips_linux_get_longjmp_target
);
1444 set_solib_svr4_fetch_link_map_offsets
1445 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1446 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_sigframe
);
1447 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_rt_sigframe
);
1448 set_xml_syscall_file_name ("syscalls/mips-o32-linux.xml");
1451 set_gdbarch_get_longjmp_target (gdbarch
,
1452 mips_linux_get_longjmp_target
);
1453 set_solib_svr4_fetch_link_map_offsets
1454 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1455 set_gdbarch_long_double_bit (gdbarch
, 128);
1456 /* These floatformats should probably be renamed. MIPS uses
1457 the same 128-bit IEEE floating point format that IA-64 uses,
1458 except that the quiet/signalling NaN bit is reversed (GDB
1459 does not distinguish between quiet and signalling NaNs). */
1460 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1461 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n32_rt_sigframe
);
1462 set_xml_syscall_file_name ("syscalls/mips-n32-linux.xml");
1465 set_gdbarch_get_longjmp_target (gdbarch
,
1466 mips64_linux_get_longjmp_target
);
1467 set_solib_svr4_fetch_link_map_offsets
1468 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1469 set_gdbarch_long_double_bit (gdbarch
, 128);
1470 /* These floatformats should probably be renamed. MIPS uses
1471 the same 128-bit IEEE floating point format that IA-64 uses,
1472 except that the quiet/signalling NaN bit is reversed (GDB
1473 does not distinguish between quiet and signalling NaNs). */
1474 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1475 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n64_rt_sigframe
);
1476 set_xml_syscall_file_name ("syscalls/mips-n64-linux.xml");
1482 set_gdbarch_skip_solib_resolver (gdbarch
, mips_linux_skip_resolver
);
1484 set_gdbarch_software_single_step (gdbarch
, mips_software_single_step
);
1486 /* Enable TLS support. */
1487 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1488 svr4_fetch_objfile_link_map
);
1490 /* Initialize this lazily, to avoid an initialization order
1491 dependency on solib-svr4.c's _initialize routine. */
1492 if (mips_svr4_so_ops
.in_dynsym_resolve_code
== NULL
)
1494 mips_svr4_so_ops
= svr4_so_ops
;
1495 mips_svr4_so_ops
.in_dynsym_resolve_code
1496 = mips_linux_in_dynsym_resolve_code
;
1498 set_solib_ops (gdbarch
, &mips_svr4_so_ops
);
1500 set_gdbarch_write_pc (gdbarch
, mips_linux_write_pc
);
1502 set_gdbarch_core_read_description (gdbarch
,
1503 mips_linux_core_read_description
);
1505 set_gdbarch_regset_from_core_section (gdbarch
,
1506 mips_linux_regset_from_core_section
);
1508 set_gdbarch_gdb_signal_from_target (gdbarch
,
1509 mips_gdb_signal_from_target
);
1511 tdep
->syscall_next_pc
= mips_linux_syscall_next_pc
;
1515 const struct tdesc_feature
*feature
;
1517 /* If we have target-described registers, then we can safely
1518 reserve a number for MIPS_RESTART_REGNUM (whether it is
1519 described or not). */
1520 gdb_assert (gdbarch_num_regs (gdbarch
) <= MIPS_RESTART_REGNUM
);
1521 set_gdbarch_num_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1522 set_gdbarch_num_pseudo_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1524 /* If it's present, then assign it to the reserved number. */
1525 feature
= tdesc_find_feature (info
.target_desc
,
1526 "org.gnu.gdb.mips.linux");
1527 if (feature
!= NULL
)
1528 tdesc_numbered_register (feature
, tdesc_data
, MIPS_RESTART_REGNUM
,
1533 /* Provide a prototype to silence -Wmissing-prototypes. */
1534 extern initialize_file_ftype _initialize_mips_linux_tdep
;
1537 _initialize_mips_linux_tdep (void)
1539 const struct bfd_arch_info
*arch_info
;
1541 for (arch_info
= bfd_lookup_arch (bfd_arch_mips
, 0);
1543 arch_info
= arch_info
->next
)
1545 gdbarch_register_osabi (bfd_arch_mips
, arch_info
->mach
,
1547 mips_linux_init_abi
);