1 /* Target-dependent code for GNU/Linux on MIPS processors.
3 Copyright (C) 2001-2014 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"
28 #include "trad-frame.h"
29 #include "tramp-frame.h"
35 #include "target-descriptions.h"
37 #include "mips-linux-tdep.h"
38 #include "glibc-tdep.h"
39 #include "linux-tdep.h"
40 #include "xml-syscall.h"
41 #include "gdb_signals.h"
43 static struct target_so_ops mips_svr4_so_ops
;
45 /* This enum represents the signals' numbers on the MIPS
46 architecture. It just contains the signal definitions which are
47 different from the generic implementation.
49 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
50 from the Linux kernel tree. */
54 MIPS_LINUX_SIGEMT
= 7,
55 MIPS_LINUX_SIGBUS
= 10,
56 MIPS_LINUX_SIGSYS
= 12,
57 MIPS_LINUX_SIGUSR1
= 16,
58 MIPS_LINUX_SIGUSR2
= 17,
59 MIPS_LINUX_SIGCHLD
= 18,
60 MIPS_LINUX_SIGCLD
= MIPS_LINUX_SIGCHLD
,
61 MIPS_LINUX_SIGPWR
= 19,
62 MIPS_LINUX_SIGWINCH
= 20,
63 MIPS_LINUX_SIGURG
= 21,
64 MIPS_LINUX_SIGIO
= 22,
65 MIPS_LINUX_SIGPOLL
= MIPS_LINUX_SIGIO
,
66 MIPS_LINUX_SIGSTOP
= 23,
67 MIPS_LINUX_SIGTSTP
= 24,
68 MIPS_LINUX_SIGCONT
= 25,
69 MIPS_LINUX_SIGTTIN
= 26,
70 MIPS_LINUX_SIGTTOU
= 27,
71 MIPS_LINUX_SIGVTALRM
= 28,
72 MIPS_LINUX_SIGPROF
= 29,
73 MIPS_LINUX_SIGXCPU
= 30,
74 MIPS_LINUX_SIGXFSZ
= 31,
76 MIPS_LINUX_SIGRTMIN
= 32,
77 MIPS_LINUX_SIGRT64
= 64,
78 MIPS_LINUX_SIGRTMAX
= 127,
81 /* Figure out where the longjmp will land.
82 We expect the first arg to be a pointer to the jmp_buf structure
83 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
84 at. The pc is copied into PC. This routine returns 1 on
87 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
88 #define MIPS_LINUX_JB_PC 0
91 mips_linux_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
94 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
95 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
96 gdb_byte buf
[gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
];
98 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
100 if (target_read_memory ((jb_addr
101 + MIPS_LINUX_JB_PC
* MIPS_LINUX_JB_ELEMENT_SIZE
),
102 buf
, gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
105 *pc
= extract_unsigned_integer (buf
,
106 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
112 /* Transform the bits comprising a 32-bit register to the right size
113 for regcache_raw_supply(). This is needed when mips_isa_regsize()
117 supply_32bit_reg (struct regcache
*regcache
, int regnum
, const void *addr
)
119 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
120 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
121 gdb_byte buf
[MAX_REGISTER_SIZE
];
122 store_signed_integer (buf
, register_size (gdbarch
, regnum
), byte_order
,
123 extract_signed_integer (addr
, 4, byte_order
));
124 regcache_raw_supply (regcache
, regnum
, buf
);
127 /* Unpack an elf_gregset_t into GDB's register cache. */
130 mips_supply_gregset (struct regcache
*regcache
,
131 const mips_elf_gregset_t
*gregsetp
)
134 const mips_elf_greg_t
*regp
= *gregsetp
;
135 char zerobuf
[MAX_REGISTER_SIZE
];
136 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
138 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
140 for (regi
= EF_REG0
+ 1; regi
<= EF_REG31
; regi
++)
141 supply_32bit_reg (regcache
, regi
- EF_REG0
, regp
+ regi
);
143 if (mips_linux_restart_reg_p (gdbarch
))
144 supply_32bit_reg (regcache
, MIPS_RESTART_REGNUM
, regp
+ EF_REG0
);
146 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->lo
, regp
+ EF_LO
);
147 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->hi
, regp
+ EF_HI
);
149 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
151 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
152 regp
+ EF_CP0_BADVADDR
);
153 supply_32bit_reg (regcache
, MIPS_PS_REGNUM
, regp
+ EF_CP0_STATUS
);
154 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
155 regp
+ EF_CP0_CAUSE
);
157 /* Fill the inaccessible zero register with zero. */
158 regcache_raw_supply (regcache
, MIPS_ZERO_REGNUM
, zerobuf
);
162 mips_supply_gregset_wrapper (const struct regset
*regset
,
163 struct regcache
*regcache
,
164 int regnum
, const void *gregs
, size_t len
)
166 gdb_assert (len
== sizeof (mips_elf_gregset_t
));
168 mips_supply_gregset (regcache
, (const mips_elf_gregset_t
*)gregs
);
171 /* Pack our registers (or one register) into an elf_gregset_t. */
174 mips_fill_gregset (const struct regcache
*regcache
,
175 mips_elf_gregset_t
*gregsetp
, int regno
)
177 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
179 mips_elf_greg_t
*regp
= *gregsetp
;
184 memset (regp
, 0, sizeof (mips_elf_gregset_t
));
185 for (regi
= 1; regi
< 32; regi
++)
186 mips_fill_gregset (regcache
, gregsetp
, regi
);
187 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
188 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
189 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
190 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->badvaddr
);
191 mips_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
192 mips_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
193 mips_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
197 if (regno
> 0 && regno
< 32)
199 dst
= regp
+ regno
+ EF_REG0
;
200 regcache_raw_collect (regcache
, regno
, dst
);
204 if (regno
== mips_regnum (gdbarch
)->lo
)
206 else if (regno
== mips_regnum (gdbarch
)->hi
)
208 else if (regno
== mips_regnum (gdbarch
)->pc
)
209 regaddr
= EF_CP0_EPC
;
210 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
211 regaddr
= EF_CP0_BADVADDR
;
212 else if (regno
== MIPS_PS_REGNUM
)
213 regaddr
= EF_CP0_STATUS
;
214 else if (regno
== mips_regnum (gdbarch
)->cause
)
215 regaddr
= EF_CP0_CAUSE
;
216 else if (mips_linux_restart_reg_p (gdbarch
)
217 && regno
== MIPS_RESTART_REGNUM
)
224 dst
= regp
+ regaddr
;
225 regcache_raw_collect (regcache
, regno
, dst
);
230 mips_fill_gregset_wrapper (const struct regset
*regset
,
231 const struct regcache
*regcache
,
232 int regnum
, void *gregs
, size_t len
)
234 gdb_assert (len
== sizeof (mips_elf_gregset_t
));
236 mips_fill_gregset (regcache
, (mips_elf_gregset_t
*)gregs
, regnum
);
239 /* Likewise, unpack an elf_fpregset_t. */
242 mips_supply_fpregset (struct regcache
*regcache
,
243 const mips_elf_fpregset_t
*fpregsetp
)
245 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
247 char zerobuf
[MAX_REGISTER_SIZE
];
249 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
251 for (regi
= 0; regi
< 32; regi
++)
252 regcache_raw_supply (regcache
,
253 gdbarch_fp0_regnum (gdbarch
) + regi
,
256 regcache_raw_supply (regcache
,
257 mips_regnum (gdbarch
)->fp_control_status
,
260 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
261 regcache_raw_supply (regcache
,
262 mips_regnum (gdbarch
)->fp_implementation_revision
,
267 mips_supply_fpregset_wrapper (const struct regset
*regset
,
268 struct regcache
*regcache
,
269 int regnum
, const void *gregs
, size_t len
)
271 gdb_assert (len
== sizeof (mips_elf_fpregset_t
));
273 mips_supply_fpregset (regcache
, (const mips_elf_fpregset_t
*)gregs
);
276 /* Likewise, pack one or all floating point registers into an
280 mips_fill_fpregset (const struct regcache
*regcache
,
281 mips_elf_fpregset_t
*fpregsetp
, int regno
)
283 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
286 if ((regno
>= gdbarch_fp0_regnum (gdbarch
))
287 && (regno
< gdbarch_fp0_regnum (gdbarch
) + 32))
289 to
= (char *) (*fpregsetp
+ regno
- gdbarch_fp0_regnum (gdbarch
));
290 regcache_raw_collect (regcache
, regno
, to
);
292 else if (regno
== mips_regnum (gdbarch
)->fp_control_status
)
294 to
= (char *) (*fpregsetp
+ 32);
295 regcache_raw_collect (regcache
, regno
, to
);
297 else if (regno
== -1)
301 for (regi
= 0; regi
< 32; regi
++)
302 mips_fill_fpregset (regcache
, fpregsetp
,
303 gdbarch_fp0_regnum (gdbarch
) + regi
);
304 mips_fill_fpregset (regcache
, fpregsetp
,
305 mips_regnum (gdbarch
)->fp_control_status
);
310 mips_fill_fpregset_wrapper (const struct regset
*regset
,
311 const struct regcache
*regcache
,
312 int regnum
, void *gregs
, size_t len
)
314 gdb_assert (len
== sizeof (mips_elf_fpregset_t
));
316 mips_fill_fpregset (regcache
, (mips_elf_fpregset_t
*)gregs
, regnum
);
319 /* Support for 64-bit ABIs. */
321 /* Figure out where the longjmp will land.
322 We expect the first arg to be a pointer to the jmp_buf structure
323 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
324 at. The pc is copied into PC. This routine returns 1 on
327 /* Details about jmp_buf. */
329 #define MIPS64_LINUX_JB_PC 0
332 mips64_linux_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
335 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
336 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
337 void *buf
= alloca (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
338 int element_size
= gdbarch_ptr_bit (gdbarch
) == 32 ? 4 : 8;
340 jb_addr
= get_frame_register_unsigned (frame
, MIPS_A0_REGNUM
);
342 if (target_read_memory (jb_addr
+ MIPS64_LINUX_JB_PC
* element_size
,
344 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
))
347 *pc
= extract_unsigned_integer (buf
,
348 gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
,
354 /* Register set support functions. These operate on standard 64-bit
355 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
356 target will still use the 64-bit format for PTRACE_GETREGS. */
358 /* Supply a 64-bit register. */
361 supply_64bit_reg (struct regcache
*regcache
, int regnum
,
364 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
365 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
366 && register_size (gdbarch
, regnum
) == 4)
367 regcache_raw_supply (regcache
, regnum
, buf
+ 4);
369 regcache_raw_supply (regcache
, regnum
, buf
);
372 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
375 mips64_supply_gregset (struct regcache
*regcache
,
376 const mips64_elf_gregset_t
*gregsetp
)
379 const mips64_elf_greg_t
*regp
= *gregsetp
;
380 gdb_byte zerobuf
[MAX_REGISTER_SIZE
];
381 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
383 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
385 for (regi
= MIPS64_EF_REG0
+ 1; regi
<= MIPS64_EF_REG31
; regi
++)
386 supply_64bit_reg (regcache
, regi
- MIPS64_EF_REG0
,
387 (const gdb_byte
*) (regp
+ regi
));
389 if (mips_linux_restart_reg_p (gdbarch
))
390 supply_64bit_reg (regcache
, MIPS_RESTART_REGNUM
,
391 (const gdb_byte
*) (regp
+ MIPS64_EF_REG0
));
393 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->lo
,
394 (const gdb_byte
*) (regp
+ MIPS64_EF_LO
));
395 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->hi
,
396 (const gdb_byte
*) (regp
+ MIPS64_EF_HI
));
398 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->pc
,
399 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_EPC
));
400 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->badvaddr
,
401 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_BADVADDR
));
402 supply_64bit_reg (regcache
, MIPS_PS_REGNUM
,
403 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_STATUS
));
404 supply_64bit_reg (regcache
, mips_regnum (gdbarch
)->cause
,
405 (const gdb_byte
*) (regp
+ MIPS64_EF_CP0_CAUSE
));
407 /* Fill the inaccessible zero register with zero. */
408 regcache_raw_supply (regcache
, MIPS_ZERO_REGNUM
, zerobuf
);
412 mips64_supply_gregset_wrapper (const struct regset
*regset
,
413 struct regcache
*regcache
,
414 int regnum
, const void *gregs
, size_t len
)
416 gdb_assert (len
== sizeof (mips64_elf_gregset_t
));
418 mips64_supply_gregset (regcache
, (const mips64_elf_gregset_t
*)gregs
);
421 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
424 mips64_fill_gregset (const struct regcache
*regcache
,
425 mips64_elf_gregset_t
*gregsetp
, int regno
)
427 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
428 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
430 mips64_elf_greg_t
*regp
= *gregsetp
;
435 memset (regp
, 0, sizeof (mips64_elf_gregset_t
));
436 for (regi
= 1; regi
< 32; regi
++)
437 mips64_fill_gregset (regcache
, gregsetp
, regi
);
438 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->lo
);
439 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->hi
);
440 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->pc
);
441 mips64_fill_gregset (regcache
, gregsetp
,
442 mips_regnum (gdbarch
)->badvaddr
);
443 mips64_fill_gregset (regcache
, gregsetp
, MIPS_PS_REGNUM
);
444 mips64_fill_gregset (regcache
, gregsetp
, mips_regnum (gdbarch
)->cause
);
445 mips64_fill_gregset (regcache
, gregsetp
, MIPS_RESTART_REGNUM
);
449 if (regno
> 0 && regno
< 32)
450 regaddr
= regno
+ MIPS64_EF_REG0
;
451 else if (regno
== mips_regnum (gdbarch
)->lo
)
452 regaddr
= MIPS64_EF_LO
;
453 else if (regno
== mips_regnum (gdbarch
)->hi
)
454 regaddr
= MIPS64_EF_HI
;
455 else if (regno
== mips_regnum (gdbarch
)->pc
)
456 regaddr
= MIPS64_EF_CP0_EPC
;
457 else if (regno
== mips_regnum (gdbarch
)->badvaddr
)
458 regaddr
= MIPS64_EF_CP0_BADVADDR
;
459 else if (regno
== MIPS_PS_REGNUM
)
460 regaddr
= MIPS64_EF_CP0_STATUS
;
461 else if (regno
== mips_regnum (gdbarch
)->cause
)
462 regaddr
= MIPS64_EF_CP0_CAUSE
;
463 else if (mips_linux_restart_reg_p (gdbarch
)
464 && regno
== MIPS_RESTART_REGNUM
)
465 regaddr
= MIPS64_EF_REG0
;
471 gdb_byte buf
[MAX_REGISTER_SIZE
];
474 regcache_raw_collect (regcache
, regno
, buf
);
475 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
477 dst
= regp
+ regaddr
;
478 store_signed_integer (dst
, 8, byte_order
, val
);
483 mips64_fill_gregset_wrapper (const struct regset
*regset
,
484 const struct regcache
*regcache
,
485 int regnum
, void *gregs
, size_t len
)
487 gdb_assert (len
== sizeof (mips64_elf_gregset_t
));
489 mips64_fill_gregset (regcache
, (mips64_elf_gregset_t
*)gregs
, regnum
);
492 /* Likewise, unpack an elf_fpregset_t. */
495 mips64_supply_fpregset (struct regcache
*regcache
,
496 const mips64_elf_fpregset_t
*fpregsetp
)
498 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
501 /* See mips_linux_o32_sigframe_init for a description of the
502 peculiar FP register layout. */
503 if (register_size (gdbarch
, gdbarch_fp0_regnum (gdbarch
)) == 4)
504 for (regi
= 0; regi
< 32; regi
++)
506 const gdb_byte
*reg_ptr
507 = (const gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
508 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
510 regcache_raw_supply (regcache
,
511 gdbarch_fp0_regnum (gdbarch
) + regi
,
515 for (regi
= 0; regi
< 32; regi
++)
516 regcache_raw_supply (regcache
,
517 gdbarch_fp0_regnum (gdbarch
) + regi
,
518 (const char *) (*fpregsetp
+ regi
));
520 supply_32bit_reg (regcache
, mips_regnum (gdbarch
)->fp_control_status
,
521 (const gdb_byte
*) (*fpregsetp
+ 32));
523 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
524 include it - but the result of PTRACE_GETFPREGS does. The best we
525 can do is to assume that its value is present. */
526 supply_32bit_reg (regcache
,
527 mips_regnum (gdbarch
)->fp_implementation_revision
,
528 (const gdb_byte
*) (*fpregsetp
+ 32) + 4);
532 mips64_supply_fpregset_wrapper (const struct regset
*regset
,
533 struct regcache
*regcache
,
534 int regnum
, const void *gregs
, size_t len
)
536 gdb_assert (len
== sizeof (mips64_elf_fpregset_t
));
538 mips64_supply_fpregset (regcache
, (const mips64_elf_fpregset_t
*)gregs
);
541 /* Likewise, pack one or all floating point registers into an
545 mips64_fill_fpregset (const struct regcache
*regcache
,
546 mips64_elf_fpregset_t
*fpregsetp
, int regno
)
548 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
549 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
552 if ((regno
>= gdbarch_fp0_regnum (gdbarch
))
553 && (regno
< gdbarch_fp0_regnum (gdbarch
) + 32))
555 /* See mips_linux_o32_sigframe_init for a description of the
556 peculiar FP register layout. */
557 if (register_size (gdbarch
, regno
) == 4)
559 int regi
= regno
- gdbarch_fp0_regnum (gdbarch
);
561 to
= (gdb_byte
*) (*fpregsetp
+ (regi
& ~1));
562 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (regi
& 1))
564 regcache_raw_collect (regcache
, regno
, to
);
568 to
= (gdb_byte
*) (*fpregsetp
+ regno
569 - gdbarch_fp0_regnum (gdbarch
));
570 regcache_raw_collect (regcache
, regno
, to
);
573 else if (regno
== mips_regnum (gdbarch
)->fp_control_status
)
575 gdb_byte buf
[MAX_REGISTER_SIZE
];
578 regcache_raw_collect (regcache
, regno
, buf
);
579 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
581 to
= (gdb_byte
*) (*fpregsetp
+ 32);
582 store_signed_integer (to
, 4, byte_order
, val
);
584 else if (regno
== mips_regnum (gdbarch
)->fp_implementation_revision
)
586 gdb_byte buf
[MAX_REGISTER_SIZE
];
589 regcache_raw_collect (regcache
, regno
, buf
);
590 val
= extract_signed_integer (buf
, register_size (gdbarch
, regno
),
592 to
= (gdb_byte
*) (*fpregsetp
+ 32) + 4;
593 store_signed_integer (to
, 4, byte_order
, val
);
595 else if (regno
== -1)
599 for (regi
= 0; regi
< 32; regi
++)
600 mips64_fill_fpregset (regcache
, fpregsetp
,
601 gdbarch_fp0_regnum (gdbarch
) + regi
);
602 mips64_fill_fpregset (regcache
, fpregsetp
,
603 mips_regnum (gdbarch
)->fp_control_status
);
604 mips64_fill_fpregset (regcache
, fpregsetp
,
605 mips_regnum (gdbarch
)->fp_implementation_revision
);
610 mips64_fill_fpregset_wrapper (const struct regset
*regset
,
611 const struct regcache
*regcache
,
612 int regnum
, void *gregs
, size_t len
)
614 gdb_assert (len
== sizeof (mips64_elf_fpregset_t
));
616 mips64_fill_fpregset (regcache
, (mips64_elf_fpregset_t
*)gregs
, regnum
);
619 static const struct regset mips_linux_gregset
=
621 NULL
, mips_supply_gregset_wrapper
, mips_fill_gregset_wrapper
624 static const struct regset mips64_linux_gregset
=
626 NULL
, mips64_supply_gregset_wrapper
, mips64_fill_gregset_wrapper
629 static const struct regset mips_linux_fpregset
=
631 NULL
, mips_supply_fpregset_wrapper
, mips_fill_fpregset_wrapper
634 static const struct regset mips64_linux_fpregset
=
636 NULL
, mips64_supply_fpregset_wrapper
, mips64_fill_fpregset_wrapper
639 static const struct regset
*
640 mips_linux_regset_from_core_section (struct gdbarch
*gdbarch
,
641 const char *sect_name
, size_t sect_size
)
643 mips_elf_gregset_t gregset
;
644 mips_elf_fpregset_t fpregset
;
645 mips64_elf_gregset_t gregset64
;
646 mips64_elf_fpregset_t fpregset64
;
648 if (strcmp (sect_name
, ".reg") == 0)
650 if (sect_size
== sizeof (gregset
))
651 return &mips_linux_gregset
;
652 else if (sect_size
== sizeof (gregset64
))
653 return &mips64_linux_gregset
;
656 warning (_("wrong size gregset struct in core file"));
659 else if (strcmp (sect_name
, ".reg2") == 0)
661 if (sect_size
== sizeof (fpregset
))
662 return &mips_linux_fpregset
;
663 else if (sect_size
== sizeof (fpregset64
))
664 return &mips64_linux_fpregset
;
667 warning (_("wrong size fpregset struct in core file"));
674 static const struct target_desc
*
675 mips_linux_core_read_description (struct gdbarch
*gdbarch
,
676 struct target_ops
*target
,
679 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
683 switch (bfd_section_size (abfd
, section
))
685 case sizeof (mips_elf_gregset_t
):
686 return mips_tdesc_gp32
;
688 case sizeof (mips64_elf_gregset_t
):
689 return mips_tdesc_gp64
;
697 /* Check the code at PC for a dynamic linker lazy resolution stub.
698 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
699 section uniformly since version 2.15. If the pc is in that section,
700 then we are in such a stub. Before that ".stub" was used in 32-bit
701 ELF binaries, however we do not bother checking for that since we
702 have never had and that case should be extremely rare these days.
703 Instead we pattern-match on the code generated by GNU ld. They look
711 (with the appropriate doubleword instructions for N64). As any lazy
712 resolution stubs in microMIPS binaries will always be in a
713 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
716 mips_linux_in_dynsym_stub (CORE_ADDR pc
)
718 gdb_byte buf
[28], *p
;
719 ULONGEST insn
, insn1
;
720 int n64
= (mips_abi (target_gdbarch ()) == MIPS_ABI_N64
);
721 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
723 if (in_mips_stubs_section (pc
))
726 read_memory (pc
- 12, buf
, 28);
730 /* ld t9,0x8010(gp) */
735 /* lw t9,0x8010(gp) */
742 insn
= extract_unsigned_integer (p
, 4, byte_order
);
750 insn
= extract_unsigned_integer (p
+ 4, 4, byte_order
);
754 if (insn
!= 0x03e0782d)
760 if (insn
!= 0x03e07821)
764 insn
= extract_unsigned_integer (p
+ 8, 4, byte_order
);
766 if (insn
!= 0x0320f809)
769 insn
= extract_unsigned_integer (p
+ 12, 4, byte_order
);
772 /* daddiu t8,zero,0 */
773 if ((insn
& 0xffff0000) != 0x64180000)
778 /* addiu t8,zero,0 */
779 if ((insn
& 0xffff0000) != 0x24180000)
786 /* Return non-zero iff PC belongs to the dynamic linker resolution
787 code, a PLT entry, or a lazy binding stub. */
790 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc
)
792 /* Check whether PC is in the dynamic linker. This also checks
793 whether it is in the .plt section, used by non-PIC executables. */
794 if (svr4_in_dynsym_resolve_code (pc
))
797 /* Likewise for the stubs. They live in the .MIPS.stubs section these
798 days, so we check if the PC is within, than fall back to a pattern
800 if (mips_linux_in_dynsym_stub (pc
))
806 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
807 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
808 implementation of this triggers at "fixup" from the same objfile as
809 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
810 "__dl_runtime_resolve" directly. An unresolved lazy binding
811 stub will point to _dl_runtime_resolve, which will first call
812 __dl_runtime_resolve, and then pass control to the resolved
816 mips_linux_skip_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
818 struct bound_minimal_symbol resolver
;
820 resolver
= lookup_minimal_symbol ("__dl_runtime_resolve", NULL
, NULL
);
822 if (resolver
.minsym
&& BMSYMBOL_VALUE_ADDRESS (resolver
) == pc
)
823 return frame_unwind_caller_pc (get_current_frame ());
825 return glibc_skip_solib_resolver (gdbarch
, pc
);
828 /* Signal trampoline support. There are four supported layouts for a
829 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
830 n64 rt_sigframe. We handle them all independently; not the most
831 efficient way, but simplest. First, declare all the unwinders. */
833 static void mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
834 struct frame_info
*this_frame
,
835 struct trad_frame_cache
*this_cache
,
838 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
839 struct frame_info
*this_frame
,
840 struct trad_frame_cache
*this_cache
,
843 #define MIPS_NR_LINUX 4000
844 #define MIPS_NR_N64_LINUX 5000
845 #define MIPS_NR_N32_LINUX 6000
847 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
848 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
849 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
850 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
852 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
853 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
854 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
855 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
856 #define MIPS_INST_SYSCALL 0x0000000c
858 static const struct tramp_frame mips_linux_o32_sigframe
= {
862 { MIPS_INST_LI_V0_SIGRETURN
, -1 },
863 { MIPS_INST_SYSCALL
, -1 },
864 { TRAMP_SENTINEL_INSN
, -1 }
866 mips_linux_o32_sigframe_init
869 static const struct tramp_frame mips_linux_o32_rt_sigframe
= {
873 { MIPS_INST_LI_V0_RT_SIGRETURN
, -1 },
874 { MIPS_INST_SYSCALL
, -1 },
875 { TRAMP_SENTINEL_INSN
, -1 } },
876 mips_linux_o32_sigframe_init
879 static const struct tramp_frame mips_linux_n32_rt_sigframe
= {
883 { MIPS_INST_LI_V0_N32_RT_SIGRETURN
, -1 },
884 { MIPS_INST_SYSCALL
, -1 },
885 { TRAMP_SENTINEL_INSN
, -1 }
887 mips_linux_n32n64_sigframe_init
890 static const struct tramp_frame mips_linux_n64_rt_sigframe
= {
894 { MIPS_INST_LI_V0_N64_RT_SIGRETURN
, -1 },
895 { MIPS_INST_SYSCALL
, -1 },
896 { TRAMP_SENTINEL_INSN
, -1 }
898 mips_linux_n32n64_sigframe_init
902 /* The unwinder for o32 signal frames. The legacy structures look
906 u32 sf_ass[4]; [argument save space for o32]
907 u32 sf_code[2]; [signal trampoline or fill]
908 struct sigcontext sf_sc;
912 Pre-2.6.12 sigcontext:
915 unsigned int sc_regmask; [Unused]
916 unsigned int sc_status;
917 unsigned long long sc_pc;
918 unsigned long long sc_regs[32];
919 unsigned long long sc_fpregs[32];
920 unsigned int sc_ownedfp;
921 unsigned int sc_fpc_csr;
922 unsigned int sc_fpc_eir; [Unused]
923 unsigned int sc_used_math;
924 unsigned int sc_ssflags; [Unused]
925 [Alignment hole of four bytes]
926 unsigned long long sc_mdhi;
927 unsigned long long sc_mdlo;
929 unsigned int sc_cause; [Unused]
930 unsigned int sc_badvaddr; [Unused]
932 unsigned long sc_sigset[4]; [kernel's sigset_t]
935 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
938 unsigned int sc_regmask; [Unused]
939 unsigned int sc_status; [Unused]
940 unsigned long long sc_pc;
941 unsigned long long sc_regs[32];
942 unsigned long long sc_fpregs[32];
944 unsigned int sc_fpc_csr;
945 unsigned int sc_fpc_eir; [Unused]
946 unsigned int sc_used_math;
948 [Alignment hole of four bytes]
949 unsigned long long sc_mdhi;
950 unsigned long long sc_mdlo;
951 unsigned long sc_hi1;
952 unsigned long sc_lo1;
953 unsigned long sc_hi2;
954 unsigned long sc_lo2;
955 unsigned long sc_hi3;
956 unsigned long sc_lo3;
959 The RT signal frames look like this:
962 u32 rs_ass[4]; [argument save space for o32]
963 u32 rs_code[2] [signal trampoline or fill]
964 struct siginfo rs_info;
965 struct ucontext rs_uc;
969 unsigned long uc_flags;
970 struct ucontext *uc_link;
972 [Alignment hole of four bytes]
973 struct sigcontext uc_mcontext;
978 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
980 #define RTSIGFRAME_SIGINFO_SIZE 128
981 #define STACK_T_SIZE (3 * 4)
982 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
983 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
984 + RTSIGFRAME_SIGINFO_SIZE \
985 + UCONTEXT_SIGCONTEXT_OFFSET)
987 #define SIGCONTEXT_PC (1 * 8)
988 #define SIGCONTEXT_REGS (2 * 8)
989 #define SIGCONTEXT_FPREGS (34 * 8)
990 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
991 #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
992 #define SIGCONTEXT_HI (69 * 8)
993 #define SIGCONTEXT_LO (70 * 8)
994 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
995 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
996 #define SIGCONTEXT_HI1 (71 * 8 + 0)
997 #define SIGCONTEXT_LO1 (71 * 8 + 4)
998 #define SIGCONTEXT_HI2 (72 * 8 + 0)
999 #define SIGCONTEXT_LO2 (72 * 8 + 4)
1000 #define SIGCONTEXT_HI3 (73 * 8 + 0)
1001 #define SIGCONTEXT_LO3 (73 * 8 + 4)
1003 #define SIGCONTEXT_REG_SIZE 8
1006 mips_linux_o32_sigframe_init (const struct tramp_frame
*self
,
1007 struct frame_info
*this_frame
,
1008 struct trad_frame_cache
*this_cache
,
1011 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1013 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
1014 CORE_ADDR sigcontext_base
;
1015 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
1016 CORE_ADDR regs_base
;
1018 if (self
== &mips_linux_o32_sigframe
)
1019 sigcontext_base
= frame_sp
+ SIGFRAME_SIGCONTEXT_OFFSET
;
1021 sigcontext_base
= frame_sp
+ RTSIGFRAME_SIGCONTEXT_OFFSET
;
1023 /* I'm not proud of this hack. Eventually we will have the
1024 infrastructure to indicate the size of saved registers on a
1025 per-frame basis, but right now we don't; the kernel saves eight
1026 bytes but we only want four. Use regs_base to access any
1028 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
1029 regs_base
= sigcontext_base
+ 4;
1031 regs_base
= sigcontext_base
;
1033 if (mips_linux_restart_reg_p (gdbarch
))
1034 trad_frame_set_reg_addr (this_cache
,
1035 (MIPS_RESTART_REGNUM
1036 + gdbarch_num_regs (gdbarch
)),
1037 regs_base
+ SIGCONTEXT_REGS
);
1039 for (ireg
= 1; ireg
< 32; ireg
++)
1040 trad_frame_set_reg_addr (this_cache
,
1041 (ireg
+ MIPS_ZERO_REGNUM
1042 + gdbarch_num_regs (gdbarch
)),
1043 (regs_base
+ SIGCONTEXT_REGS
1044 + ireg
* SIGCONTEXT_REG_SIZE
));
1046 /* The way that floating point registers are saved, unfortunately,
1047 depends on the architecture the kernel is built for. For the r3000 and
1048 tx39, four bytes of each register are at the beginning of each of the
1049 32 eight byte slots. For everything else, the registers are saved
1050 using double precision; only the even-numbered slots are initialized,
1051 and the high bits are the odd-numbered register. Assume the latter
1052 layout, since we can't tell, and it's much more common. Which bits are
1053 the "high" bits depends on endianness. */
1054 for (ireg
= 0; ireg
< 32; ireg
++)
1055 if ((gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
) != (ireg
& 1))
1056 trad_frame_set_reg_addr (this_cache
,
1057 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1058 (sigcontext_base
+ SIGCONTEXT_FPREGS
+ 4
1059 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
));
1061 trad_frame_set_reg_addr (this_cache
,
1062 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1063 (sigcontext_base
+ SIGCONTEXT_FPREGS
1064 + (ireg
& ~1) * SIGCONTEXT_REG_SIZE
));
1066 trad_frame_set_reg_addr (this_cache
,
1067 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1068 regs_base
+ SIGCONTEXT_PC
);
1070 trad_frame_set_reg_addr (this_cache
,
1071 (regs
->fp_control_status
1072 + gdbarch_num_regs (gdbarch
)),
1073 sigcontext_base
+ SIGCONTEXT_FPCSR
);
1075 if (regs
->dspctl
!= -1)
1076 trad_frame_set_reg_addr (this_cache
,
1077 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1078 sigcontext_base
+ SIGCONTEXT_DSPCTL
);
1080 trad_frame_set_reg_addr (this_cache
,
1081 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1082 regs_base
+ SIGCONTEXT_HI
);
1083 trad_frame_set_reg_addr (this_cache
,
1084 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1085 regs_base
+ SIGCONTEXT_LO
);
1087 if (regs
->dspacc
!= -1)
1089 trad_frame_set_reg_addr (this_cache
,
1090 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1091 sigcontext_base
+ SIGCONTEXT_HI1
);
1092 trad_frame_set_reg_addr (this_cache
,
1093 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1094 sigcontext_base
+ SIGCONTEXT_LO1
);
1095 trad_frame_set_reg_addr (this_cache
,
1096 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1097 sigcontext_base
+ SIGCONTEXT_HI2
);
1098 trad_frame_set_reg_addr (this_cache
,
1099 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1100 sigcontext_base
+ SIGCONTEXT_LO2
);
1101 trad_frame_set_reg_addr (this_cache
,
1102 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1103 sigcontext_base
+ SIGCONTEXT_HI3
);
1104 trad_frame_set_reg_addr (this_cache
,
1105 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1106 sigcontext_base
+ SIGCONTEXT_LO3
);
1110 trad_frame_set_reg_addr (this_cache
,
1111 regs
->cause
+ gdbarch_num_regs (gdbarch
),
1112 sigcontext_base
+ SIGCONTEXT_CAUSE
);
1113 trad_frame_set_reg_addr (this_cache
,
1114 regs
->badvaddr
+ gdbarch_num_regs (gdbarch
),
1115 sigcontext_base
+ SIGCONTEXT_BADVADDR
);
1118 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1119 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1123 /* For N32/N64 things look different. There is no non-rt signal frame.
1125 struct rt_sigframe_n32 {
1126 u32 rs_ass[4]; [ argument save space for o32 ]
1127 u32 rs_code[2]; [ signal trampoline or fill ]
1128 struct siginfo rs_info;
1129 struct ucontextn32 rs_uc;
1132 struct ucontextn32 {
1136 struct sigcontext uc_mcontext;
1137 sigset_t uc_sigmask; [ mask last for extensibility ]
1140 struct rt_sigframe {
1141 u32 rs_ass[4]; [ argument save space for o32 ]
1142 u32 rs_code[2]; [ signal trampoline ]
1143 struct siginfo rs_info;
1144 struct ucontext rs_uc;
1148 unsigned long uc_flags;
1149 struct ucontext *uc_link;
1151 struct sigcontext uc_mcontext;
1152 sigset_t uc_sigmask; [ mask last for extensibility ]
1155 And the sigcontext is different (this is for both n32 and n64):
1158 unsigned long long sc_regs[32];
1159 unsigned long long sc_fpregs[32];
1160 unsigned long long sc_mdhi;
1161 unsigned long long sc_hi1;
1162 unsigned long long sc_hi2;
1163 unsigned long long sc_hi3;
1164 unsigned long long sc_mdlo;
1165 unsigned long long sc_lo1;
1166 unsigned long long sc_lo2;
1167 unsigned long long sc_lo3;
1168 unsigned long long sc_pc;
1169 unsigned int sc_fpc_csr;
1170 unsigned int sc_used_math;
1171 unsigned int sc_dsp;
1172 unsigned int sc_reserved;
1175 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1176 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1180 #define N32_STACK_T_SIZE STACK_T_SIZE
1181 #define N64_STACK_T_SIZE (2 * 8 + 4)
1182 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1183 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1184 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1185 + RTSIGFRAME_SIGINFO_SIZE \
1186 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1187 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1188 + RTSIGFRAME_SIGINFO_SIZE \
1189 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1191 #define N64_SIGCONTEXT_REGS (0 * 8)
1192 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1193 #define N64_SIGCONTEXT_HI (64 * 8)
1194 #define N64_SIGCONTEXT_HI1 (65 * 8)
1195 #define N64_SIGCONTEXT_HI2 (66 * 8)
1196 #define N64_SIGCONTEXT_HI3 (67 * 8)
1197 #define N64_SIGCONTEXT_LO (68 * 8)
1198 #define N64_SIGCONTEXT_LO1 (69 * 8)
1199 #define N64_SIGCONTEXT_LO2 (70 * 8)
1200 #define N64_SIGCONTEXT_LO3 (71 * 8)
1201 #define N64_SIGCONTEXT_PC (72 * 8)
1202 #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1203 #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
1205 #define N64_SIGCONTEXT_REG_SIZE 8
1208 mips_linux_n32n64_sigframe_init (const struct tramp_frame
*self
,
1209 struct frame_info
*this_frame
,
1210 struct trad_frame_cache
*this_cache
,
1213 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1215 CORE_ADDR frame_sp
= get_frame_sp (this_frame
);
1216 CORE_ADDR sigcontext_base
;
1217 const struct mips_regnum
*regs
= mips_regnum (gdbarch
);
1219 if (self
== &mips_linux_n32_rt_sigframe
)
1220 sigcontext_base
= frame_sp
+ N32_SIGFRAME_SIGCONTEXT_OFFSET
;
1222 sigcontext_base
= frame_sp
+ N64_SIGFRAME_SIGCONTEXT_OFFSET
;
1224 if (mips_linux_restart_reg_p (gdbarch
))
1225 trad_frame_set_reg_addr (this_cache
,
1226 (MIPS_RESTART_REGNUM
1227 + gdbarch_num_regs (gdbarch
)),
1228 sigcontext_base
+ N64_SIGCONTEXT_REGS
);
1230 for (ireg
= 1; ireg
< 32; ireg
++)
1231 trad_frame_set_reg_addr (this_cache
,
1232 (ireg
+ MIPS_ZERO_REGNUM
1233 + gdbarch_num_regs (gdbarch
)),
1234 (sigcontext_base
+ N64_SIGCONTEXT_REGS
1235 + ireg
* N64_SIGCONTEXT_REG_SIZE
));
1237 for (ireg
= 0; ireg
< 32; ireg
++)
1238 trad_frame_set_reg_addr (this_cache
,
1239 ireg
+ regs
->fp0
+ gdbarch_num_regs (gdbarch
),
1240 (sigcontext_base
+ N64_SIGCONTEXT_FPREGS
1241 + ireg
* N64_SIGCONTEXT_REG_SIZE
));
1243 trad_frame_set_reg_addr (this_cache
,
1244 regs
->pc
+ gdbarch_num_regs (gdbarch
),
1245 sigcontext_base
+ N64_SIGCONTEXT_PC
);
1247 trad_frame_set_reg_addr (this_cache
,
1248 (regs
->fp_control_status
1249 + gdbarch_num_regs (gdbarch
)),
1250 sigcontext_base
+ N64_SIGCONTEXT_FPCSR
);
1252 trad_frame_set_reg_addr (this_cache
,
1253 regs
->hi
+ gdbarch_num_regs (gdbarch
),
1254 sigcontext_base
+ N64_SIGCONTEXT_HI
);
1255 trad_frame_set_reg_addr (this_cache
,
1256 regs
->lo
+ gdbarch_num_regs (gdbarch
),
1257 sigcontext_base
+ N64_SIGCONTEXT_LO
);
1259 if (regs
->dspacc
!= -1)
1261 trad_frame_set_reg_addr (this_cache
,
1262 regs
->dspacc
+ 0 + gdbarch_num_regs (gdbarch
),
1263 sigcontext_base
+ N64_SIGCONTEXT_HI1
);
1264 trad_frame_set_reg_addr (this_cache
,
1265 regs
->dspacc
+ 1 + gdbarch_num_regs (gdbarch
),
1266 sigcontext_base
+ N64_SIGCONTEXT_LO1
);
1267 trad_frame_set_reg_addr (this_cache
,
1268 regs
->dspacc
+ 2 + gdbarch_num_regs (gdbarch
),
1269 sigcontext_base
+ N64_SIGCONTEXT_HI2
);
1270 trad_frame_set_reg_addr (this_cache
,
1271 regs
->dspacc
+ 3 + gdbarch_num_regs (gdbarch
),
1272 sigcontext_base
+ N64_SIGCONTEXT_LO2
);
1273 trad_frame_set_reg_addr (this_cache
,
1274 regs
->dspacc
+ 4 + gdbarch_num_regs (gdbarch
),
1275 sigcontext_base
+ N64_SIGCONTEXT_HI3
);
1276 trad_frame_set_reg_addr (this_cache
,
1277 regs
->dspacc
+ 5 + gdbarch_num_regs (gdbarch
),
1278 sigcontext_base
+ N64_SIGCONTEXT_LO3
);
1280 if (regs
->dspctl
!= -1)
1281 trad_frame_set_reg_addr (this_cache
,
1282 regs
->dspctl
+ gdbarch_num_regs (gdbarch
),
1283 sigcontext_base
+ N64_SIGCONTEXT_DSPCTL
);
1285 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1286 trad_frame_set_id (this_cache
, frame_id_build (frame_sp
, func
));
1289 /* Implement the "write_pc" gdbarch method. */
1292 mips_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1294 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1296 mips_write_pc (regcache
, pc
);
1298 /* Clear the syscall restart flag. */
1299 if (mips_linux_restart_reg_p (gdbarch
))
1300 regcache_cooked_write_unsigned (regcache
, MIPS_RESTART_REGNUM
, 0);
1303 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1306 mips_linux_restart_reg_p (struct gdbarch
*gdbarch
)
1308 /* If we do not have a target description with registers, then
1309 MIPS_RESTART_REGNUM will not be included in the register set. */
1310 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
1313 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1314 either be GPR-sized or missing. */
1315 return register_size (gdbarch
, MIPS_RESTART_REGNUM
) > 0;
1318 /* When FRAME is at a syscall instruction, return the PC of the next
1319 instruction to be executed. */
1322 mips_linux_syscall_next_pc (struct frame_info
*frame
)
1324 CORE_ADDR pc
= get_frame_pc (frame
);
1325 ULONGEST v0
= get_frame_register_unsigned (frame
, MIPS_V0_REGNUM
);
1327 /* If we are about to make a sigreturn syscall, use the unwinder to
1328 decode the signal frame. */
1329 if (v0
== MIPS_NR_sigreturn
1330 || v0
== MIPS_NR_rt_sigreturn
1331 || v0
== MIPS_NR_N64_rt_sigreturn
1332 || v0
== MIPS_NR_N32_rt_sigreturn
)
1333 return frame_unwind_caller_pc (get_current_frame ());
1338 /* Return the current system call's number present in the
1339 v0 register. When the function fails, it returns -1. */
1342 mips_linux_get_syscall_number (struct gdbarch
*gdbarch
,
1345 struct regcache
*regcache
= get_thread_regcache (ptid
);
1346 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1347 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1348 int regsize
= register_size (gdbarch
, MIPS_V0_REGNUM
);
1349 /* The content of a register */
1354 /* Make sure we're in a known ABI */
1355 gdb_assert (tdep
->mips_abi
== MIPS_ABI_O32
1356 || tdep
->mips_abi
== MIPS_ABI_N32
1357 || tdep
->mips_abi
== MIPS_ABI_N64
);
1359 gdb_assert (regsize
<= sizeof (buf
));
1361 /* Getting the system call number from the register.
1362 syscall number is in v0 or $2. */
1363 regcache_cooked_read (regcache
, MIPS_V0_REGNUM
, buf
);
1365 ret
= extract_signed_integer (buf
, regsize
, byte_order
);
1370 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1374 mips_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1375 enum gdb_signal signal
)
1379 case GDB_SIGNAL_EMT
:
1380 return MIPS_LINUX_SIGEMT
;
1382 case GDB_SIGNAL_BUS
:
1383 return MIPS_LINUX_SIGBUS
;
1385 case GDB_SIGNAL_SYS
:
1386 return MIPS_LINUX_SIGSYS
;
1388 case GDB_SIGNAL_USR1
:
1389 return MIPS_LINUX_SIGUSR1
;
1391 case GDB_SIGNAL_USR2
:
1392 return MIPS_LINUX_SIGUSR2
;
1394 case GDB_SIGNAL_CHLD
:
1395 return MIPS_LINUX_SIGCHLD
;
1397 case GDB_SIGNAL_PWR
:
1398 return MIPS_LINUX_SIGPWR
;
1400 case GDB_SIGNAL_WINCH
:
1401 return MIPS_LINUX_SIGWINCH
;
1403 case GDB_SIGNAL_URG
:
1404 return MIPS_LINUX_SIGURG
;
1407 return MIPS_LINUX_SIGIO
;
1409 case GDB_SIGNAL_POLL
:
1410 return MIPS_LINUX_SIGPOLL
;
1412 case GDB_SIGNAL_STOP
:
1413 return MIPS_LINUX_SIGSTOP
;
1415 case GDB_SIGNAL_TSTP
:
1416 return MIPS_LINUX_SIGTSTP
;
1418 case GDB_SIGNAL_CONT
:
1419 return MIPS_LINUX_SIGCONT
;
1421 case GDB_SIGNAL_TTIN
:
1422 return MIPS_LINUX_SIGTTIN
;
1424 case GDB_SIGNAL_TTOU
:
1425 return MIPS_LINUX_SIGTTOU
;
1427 case GDB_SIGNAL_VTALRM
:
1428 return MIPS_LINUX_SIGVTALRM
;
1430 case GDB_SIGNAL_PROF
:
1431 return MIPS_LINUX_SIGPROF
;
1433 case GDB_SIGNAL_XCPU
:
1434 return MIPS_LINUX_SIGXCPU
;
1436 case GDB_SIGNAL_XFSZ
:
1437 return MIPS_LINUX_SIGXFSZ
;
1439 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1440 therefore we have to handle it here. */
1441 case GDB_SIGNAL_REALTIME_32
:
1442 return MIPS_LINUX_SIGRTMIN
;
1445 if (signal
>= GDB_SIGNAL_REALTIME_33
1446 && signal
<= GDB_SIGNAL_REALTIME_63
)
1448 int offset
= signal
- GDB_SIGNAL_REALTIME_33
;
1450 return MIPS_LINUX_SIGRTMIN
+ 1 + offset
;
1452 else if (signal
>= GDB_SIGNAL_REALTIME_64
1453 && signal
<= GDB_SIGNAL_REALTIME_127
)
1455 int offset
= signal
- GDB_SIGNAL_REALTIME_64
;
1457 return MIPS_LINUX_SIGRT64
+ offset
;
1460 return linux_gdb_signal_to_target (gdbarch
, signal
);
1463 /* Translate signals based on MIPS signal values.
1464 Adapted from gdb/common/signals.c. */
1466 static enum gdb_signal
1467 mips_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1471 case MIPS_LINUX_SIGEMT
:
1472 return GDB_SIGNAL_EMT
;
1474 case MIPS_LINUX_SIGBUS
:
1475 return GDB_SIGNAL_BUS
;
1477 case MIPS_LINUX_SIGSYS
:
1478 return GDB_SIGNAL_SYS
;
1480 case MIPS_LINUX_SIGUSR1
:
1481 return GDB_SIGNAL_USR1
;
1483 case MIPS_LINUX_SIGUSR2
:
1484 return GDB_SIGNAL_USR2
;
1486 case MIPS_LINUX_SIGCHLD
:
1487 return GDB_SIGNAL_CHLD
;
1489 case MIPS_LINUX_SIGPWR
:
1490 return GDB_SIGNAL_PWR
;
1492 case MIPS_LINUX_SIGWINCH
:
1493 return GDB_SIGNAL_WINCH
;
1495 case MIPS_LINUX_SIGURG
:
1496 return GDB_SIGNAL_URG
;
1498 /* No way to differentiate between SIGIO and SIGPOLL.
1499 Therefore, we just handle the first one. */
1500 case MIPS_LINUX_SIGIO
:
1501 return GDB_SIGNAL_IO
;
1503 case MIPS_LINUX_SIGSTOP
:
1504 return GDB_SIGNAL_STOP
;
1506 case MIPS_LINUX_SIGTSTP
:
1507 return GDB_SIGNAL_TSTP
;
1509 case MIPS_LINUX_SIGCONT
:
1510 return GDB_SIGNAL_CONT
;
1512 case MIPS_LINUX_SIGTTIN
:
1513 return GDB_SIGNAL_TTIN
;
1515 case MIPS_LINUX_SIGTTOU
:
1516 return GDB_SIGNAL_TTOU
;
1518 case MIPS_LINUX_SIGVTALRM
:
1519 return GDB_SIGNAL_VTALRM
;
1521 case MIPS_LINUX_SIGPROF
:
1522 return GDB_SIGNAL_PROF
;
1524 case MIPS_LINUX_SIGXCPU
:
1525 return GDB_SIGNAL_XCPU
;
1527 case MIPS_LINUX_SIGXFSZ
:
1528 return GDB_SIGNAL_XFSZ
;
1531 if (signal
>= MIPS_LINUX_SIGRTMIN
&& signal
<= MIPS_LINUX_SIGRTMAX
)
1533 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1534 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
1535 int offset
= signal
- MIPS_LINUX_SIGRTMIN
;
1538 return GDB_SIGNAL_REALTIME_32
;
1539 else if (offset
< 32)
1540 return (enum gdb_signal
) (offset
- 1
1541 + (int) GDB_SIGNAL_REALTIME_33
);
1543 return (enum gdb_signal
) (offset
- 32
1544 + (int) GDB_SIGNAL_REALTIME_64
);
1547 return linux_gdb_signal_from_target (gdbarch
, signal
);
1550 /* Initialize one of the GNU/Linux OS ABIs. */
1553 mips_linux_init_abi (struct gdbarch_info info
,
1554 struct gdbarch
*gdbarch
)
1556 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1557 enum mips_abi abi
= mips_abi (gdbarch
);
1558 struct tdesc_arch_data
*tdesc_data
= (void *) info
.tdep_info
;
1560 linux_init_abi (info
, gdbarch
);
1562 /* Get the syscall number from the arch's register. */
1563 set_gdbarch_get_syscall_number (gdbarch
, mips_linux_get_syscall_number
);
1568 set_gdbarch_get_longjmp_target (gdbarch
,
1569 mips_linux_get_longjmp_target
);
1570 set_solib_svr4_fetch_link_map_offsets
1571 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1572 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_sigframe
);
1573 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_o32_rt_sigframe
);
1574 set_xml_syscall_file_name ("syscalls/mips-o32-linux.xml");
1577 set_gdbarch_get_longjmp_target (gdbarch
,
1578 mips_linux_get_longjmp_target
);
1579 set_solib_svr4_fetch_link_map_offsets
1580 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
1581 set_gdbarch_long_double_bit (gdbarch
, 128);
1582 /* These floatformats should probably be renamed. MIPS uses
1583 the same 128-bit IEEE floating point format that IA-64 uses,
1584 except that the quiet/signalling NaN bit is reversed (GDB
1585 does not distinguish between quiet and signalling NaNs). */
1586 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1587 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n32_rt_sigframe
);
1588 set_xml_syscall_file_name ("syscalls/mips-n32-linux.xml");
1591 set_gdbarch_get_longjmp_target (gdbarch
,
1592 mips64_linux_get_longjmp_target
);
1593 set_solib_svr4_fetch_link_map_offsets
1594 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
1595 set_gdbarch_long_double_bit (gdbarch
, 128);
1596 /* These floatformats should probably be renamed. MIPS uses
1597 the same 128-bit IEEE floating point format that IA-64 uses,
1598 except that the quiet/signalling NaN bit is reversed (GDB
1599 does not distinguish between quiet and signalling NaNs). */
1600 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
1601 tramp_frame_prepend_unwinder (gdbarch
, &mips_linux_n64_rt_sigframe
);
1602 set_xml_syscall_file_name ("syscalls/mips-n64-linux.xml");
1608 set_gdbarch_skip_solib_resolver (gdbarch
, mips_linux_skip_resolver
);
1610 set_gdbarch_software_single_step (gdbarch
, mips_software_single_step
);
1612 /* Enable TLS support. */
1613 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
1614 svr4_fetch_objfile_link_map
);
1616 /* Initialize this lazily, to avoid an initialization order
1617 dependency on solib-svr4.c's _initialize routine. */
1618 if (mips_svr4_so_ops
.in_dynsym_resolve_code
== NULL
)
1620 mips_svr4_so_ops
= svr4_so_ops
;
1621 mips_svr4_so_ops
.in_dynsym_resolve_code
1622 = mips_linux_in_dynsym_resolve_code
;
1624 set_solib_ops (gdbarch
, &mips_svr4_so_ops
);
1626 set_gdbarch_write_pc (gdbarch
, mips_linux_write_pc
);
1628 set_gdbarch_core_read_description (gdbarch
,
1629 mips_linux_core_read_description
);
1631 set_gdbarch_regset_from_core_section (gdbarch
,
1632 mips_linux_regset_from_core_section
);
1634 set_gdbarch_gdb_signal_from_target (gdbarch
,
1635 mips_gdb_signal_from_target
);
1637 set_gdbarch_gdb_signal_to_target (gdbarch
,
1638 mips_gdb_signal_to_target
);
1640 tdep
->syscall_next_pc
= mips_linux_syscall_next_pc
;
1644 const struct tdesc_feature
*feature
;
1646 /* If we have target-described registers, then we can safely
1647 reserve a number for MIPS_RESTART_REGNUM (whether it is
1648 described or not). */
1649 gdb_assert (gdbarch_num_regs (gdbarch
) <= MIPS_RESTART_REGNUM
);
1650 set_gdbarch_num_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1651 set_gdbarch_num_pseudo_regs (gdbarch
, MIPS_RESTART_REGNUM
+ 1);
1653 /* If it's present, then assign it to the reserved number. */
1654 feature
= tdesc_find_feature (info
.target_desc
,
1655 "org.gnu.gdb.mips.linux");
1656 if (feature
!= NULL
)
1657 tdesc_numbered_register (feature
, tdesc_data
, MIPS_RESTART_REGNUM
,
1662 /* Provide a prototype to silence -Wmissing-prototypes. */
1663 extern initialize_file_ftype _initialize_mips_linux_tdep
;
1666 _initialize_mips_linux_tdep (void)
1668 const struct bfd_arch_info
*arch_info
;
1670 for (arch_info
= bfd_lookup_arch (bfd_arch_mips
, 0);
1672 arch_info
= arch_info
->next
)
1674 gdbarch_register_osabi (bfd_arch_mips
, arch_info
->mach
,
1676 mips_linux_init_abi
);