]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/mips-linux-tdep.c
* frame.c (frame_unwind_id): Renamed to ...
[thirdparty/binutils-gdb.git] / gdb / mips-linux-tdep.c
1 /* Target-dependent code for GNU/Linux on MIPS processors.
2
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "gdbcore.h"
23 #include "target.h"
24 #include "solib-svr4.h"
25 #include "osabi.h"
26 #include "mips-tdep.h"
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
29 #include "frame.h"
30 #include "regcache.h"
31 #include "trad-frame.h"
32 #include "tramp-frame.h"
33 #include "gdbtypes.h"
34 #include "solib.h"
35 #include "solib-svr4.h"
36 #include "solist.h"
37 #include "symtab.h"
38 #include "target-descriptions.h"
39 #include "mips-linux-tdep.h"
40 #include "glibc-tdep.h"
41
42 static struct target_so_ops mips_svr4_so_ops;
43
44 /* Figure out where the longjmp will land.
45 We expect the first arg to be a pointer to the jmp_buf structure
46 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
47 at. The pc is copied into PC. This routine returns 1 on
48 success. */
49
50 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
51 #define MIPS_LINUX_JB_PC 0
52
53 static int
54 mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
55 {
56 CORE_ADDR jb_addr;
57 struct gdbarch *gdbarch = get_frame_arch (frame);
58 char buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
59
60 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
61
62 if (target_read_memory (jb_addr
63 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE,
64 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
65 return 0;
66
67 *pc = extract_unsigned_integer (buf,
68 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
69
70 return 1;
71 }
72
73 /* Transform the bits comprising a 32-bit register to the right size
74 for regcache_raw_supply(). This is needed when mips_isa_regsize()
75 is 8. */
76
77 static void
78 supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
79 {
80 gdb_byte buf[MAX_REGISTER_SIZE];
81 store_signed_integer (buf,
82 register_size (get_regcache_arch (regcache), regnum),
83 extract_signed_integer (addr, 4));
84 regcache_raw_supply (regcache, regnum, buf);
85 }
86
87 /* Unpack an elf_gregset_t into GDB's register cache. */
88
89 void
90 mips_supply_gregset (struct regcache *regcache,
91 const mips_elf_gregset_t *gregsetp)
92 {
93 int regi;
94 const mips_elf_greg_t *regp = *gregsetp;
95 char zerobuf[MAX_REGISTER_SIZE];
96 struct gdbarch *gdbarch = get_regcache_arch (regcache);
97
98 memset (zerobuf, 0, MAX_REGISTER_SIZE);
99
100 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
101 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
102
103 if (mips_linux_restart_reg_p (gdbarch))
104 supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
105
106 supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
107 supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
108
109 supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
110 regp + EF_CP0_EPC);
111 supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
112 regp + EF_CP0_BADVADDR);
113 supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
114 supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
115 regp + EF_CP0_CAUSE);
116
117 /* Fill inaccessible registers with zero. */
118 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
119 regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf);
120 for (regi = MIPS_FIRST_EMBED_REGNUM;
121 regi <= MIPS_LAST_EMBED_REGNUM;
122 regi++)
123 regcache_raw_supply (regcache, regi, zerobuf);
124 }
125
126 /* Pack our registers (or one register) into an elf_gregset_t. */
127
128 void
129 mips_fill_gregset (const struct regcache *regcache,
130 mips_elf_gregset_t *gregsetp, int regno)
131 {
132 struct gdbarch *gdbarch = get_regcache_arch (regcache);
133 int regaddr, regi;
134 mips_elf_greg_t *regp = *gregsetp;
135 void *dst;
136
137 if (regno == -1)
138 {
139 memset (regp, 0, sizeof (mips_elf_gregset_t));
140 for (regi = 1; regi < 32; regi++)
141 mips_fill_gregset (regcache, gregsetp, regi);
142 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
143 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
144 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
145 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
146 mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
147 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
148 mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
149 return;
150 }
151
152 if (regno > 0 && regno < 32)
153 {
154 dst = regp + regno + EF_REG0;
155 regcache_raw_collect (regcache, regno, dst);
156 return;
157 }
158
159 if (regno == mips_regnum (gdbarch)->lo)
160 regaddr = EF_LO;
161 else if (regno == mips_regnum (gdbarch)->hi)
162 regaddr = EF_HI;
163 else if (regno == mips_regnum (gdbarch)->pc)
164 regaddr = EF_CP0_EPC;
165 else if (regno == mips_regnum (gdbarch)->badvaddr)
166 regaddr = EF_CP0_BADVADDR;
167 else if (regno == MIPS_PS_REGNUM)
168 regaddr = EF_CP0_STATUS;
169 else if (regno == mips_regnum (gdbarch)->cause)
170 regaddr = EF_CP0_CAUSE;
171 else if (mips_linux_restart_reg_p (gdbarch)
172 && regno == MIPS_RESTART_REGNUM)
173 regaddr = EF_REG0;
174 else
175 regaddr = -1;
176
177 if (regaddr != -1)
178 {
179 dst = regp + regaddr;
180 regcache_raw_collect (regcache, regno, dst);
181 }
182 }
183
184 /* Likewise, unpack an elf_fpregset_t. */
185
186 void
187 mips_supply_fpregset (struct regcache *regcache,
188 const mips_elf_fpregset_t *fpregsetp)
189 {
190 struct gdbarch *gdbarch = get_regcache_arch (regcache);
191 int regi;
192 char zerobuf[MAX_REGISTER_SIZE];
193
194 memset (zerobuf, 0, MAX_REGISTER_SIZE);
195
196 for (regi = 0; regi < 32; regi++)
197 regcache_raw_supply (regcache,
198 gdbarch_fp0_regnum (gdbarch) + regi,
199 *fpregsetp + regi);
200
201 regcache_raw_supply (regcache,
202 mips_regnum (gdbarch)->fp_control_status,
203 *fpregsetp + 32);
204
205 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
206 regcache_raw_supply (regcache,
207 mips_regnum (gdbarch)->fp_implementation_revision,
208 zerobuf);
209 }
210
211 /* Likewise, pack one or all floating point registers into an
212 elf_fpregset_t. */
213
214 void
215 mips_fill_fpregset (const struct regcache *regcache,
216 mips_elf_fpregset_t *fpregsetp, int regno)
217 {
218 struct gdbarch *gdbarch = get_regcache_arch (regcache);
219 char *from, *to;
220
221 if ((regno >= gdbarch_fp0_regnum (gdbarch))
222 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
223 {
224 to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
225 regcache_raw_collect (regcache, regno, to);
226 }
227 else if (regno == mips_regnum (gdbarch)->fp_control_status)
228 {
229 to = (char *) (*fpregsetp + 32);
230 regcache_raw_collect (regcache, regno, to);
231 }
232 else if (regno == -1)
233 {
234 int regi;
235
236 for (regi = 0; regi < 32; regi++)
237 mips_fill_fpregset (regcache, fpregsetp,
238 gdbarch_fp0_regnum (gdbarch) + regi);
239 mips_fill_fpregset (regcache, fpregsetp,
240 mips_regnum (gdbarch)->fp_control_status);
241 }
242 }
243
244 /* Support for 64-bit ABIs. */
245
246 /* Figure out where the longjmp will land.
247 We expect the first arg to be a pointer to the jmp_buf structure
248 from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
249 at. The pc is copied into PC. This routine returns 1 on
250 success. */
251
252 /* Details about jmp_buf. */
253
254 #define MIPS64_LINUX_JB_PC 0
255
256 static int
257 mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
258 {
259 CORE_ADDR jb_addr;
260 struct gdbarch *gdbarch = get_frame_arch (frame);
261 void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
262 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
263
264 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
265
266 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
267 buf,
268 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
269 return 0;
270
271 *pc = extract_unsigned_integer (buf,
272 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
273
274 return 1;
275 }
276
277 /* Register set support functions. These operate on standard 64-bit
278 regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
279 target will still use the 64-bit format for PTRACE_GETREGS. */
280
281 /* Supply a 64-bit register. */
282
283 static void
284 supply_64bit_reg (struct regcache *regcache, int regnum,
285 const gdb_byte *buf)
286 {
287 struct gdbarch *gdbarch = get_regcache_arch (regcache);
288 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
289 && register_size (gdbarch, regnum) == 4)
290 regcache_raw_supply (regcache, regnum, buf + 4);
291 else
292 regcache_raw_supply (regcache, regnum, buf);
293 }
294
295 /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
296
297 void
298 mips64_supply_gregset (struct regcache *regcache,
299 const mips64_elf_gregset_t *gregsetp)
300 {
301 int regi;
302 const mips64_elf_greg_t *regp = *gregsetp;
303 gdb_byte zerobuf[MAX_REGISTER_SIZE];
304 struct gdbarch *gdbarch = get_regcache_arch (regcache);
305
306 memset (zerobuf, 0, MAX_REGISTER_SIZE);
307
308 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
309 supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
310 (const gdb_byte *)(regp + regi));
311
312 if (mips_linux_restart_reg_p (gdbarch))
313 supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
314 (const gdb_byte *)(regp + MIPS64_EF_REG0));
315
316 supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
317 (const gdb_byte *) (regp + MIPS64_EF_LO));
318 supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
319 (const gdb_byte *) (regp + MIPS64_EF_HI));
320
321 supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
322 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
323 supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
324 (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
325 supply_64bit_reg (regcache, MIPS_PS_REGNUM,
326 (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
327 supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
328 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
329
330 /* Fill inaccessible registers with zero. */
331 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
332 regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf);
333 for (regi = MIPS_FIRST_EMBED_REGNUM;
334 regi <= MIPS_LAST_EMBED_REGNUM;
335 regi++)
336 regcache_raw_supply (regcache, regi, zerobuf);
337 }
338
339 /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
340
341 void
342 mips64_fill_gregset (const struct regcache *regcache,
343 mips64_elf_gregset_t *gregsetp, int regno)
344 {
345 struct gdbarch *gdbarch = get_regcache_arch (regcache);
346 int regaddr, regi;
347 mips64_elf_greg_t *regp = *gregsetp;
348 void *dst;
349
350 if (regno == -1)
351 {
352 memset (regp, 0, sizeof (mips64_elf_gregset_t));
353 for (regi = 1; regi < 32; regi++)
354 mips64_fill_gregset (regcache, gregsetp, regi);
355 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
356 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
357 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
358 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
359 mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
360 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
361 mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
362 return;
363 }
364
365 if (regno > 0 && regno < 32)
366 regaddr = regno + MIPS64_EF_REG0;
367 else if (regno == mips_regnum (gdbarch)->lo)
368 regaddr = MIPS64_EF_LO;
369 else if (regno == mips_regnum (gdbarch)->hi)
370 regaddr = MIPS64_EF_HI;
371 else if (regno == mips_regnum (gdbarch)->pc)
372 regaddr = MIPS64_EF_CP0_EPC;
373 else if (regno == mips_regnum (gdbarch)->badvaddr)
374 regaddr = MIPS64_EF_CP0_BADVADDR;
375 else if (regno == MIPS_PS_REGNUM)
376 regaddr = MIPS64_EF_CP0_STATUS;
377 else if (regno == mips_regnum (gdbarch)->cause)
378 regaddr = MIPS64_EF_CP0_CAUSE;
379 else if (mips_linux_restart_reg_p (gdbarch)
380 && regno == MIPS_RESTART_REGNUM)
381 regaddr = MIPS64_EF_REG0;
382 else
383 regaddr = -1;
384
385 if (regaddr != -1)
386 {
387 gdb_byte buf[MAX_REGISTER_SIZE];
388 LONGEST val;
389
390 regcache_raw_collect (regcache, regno, buf);
391 val = extract_signed_integer (buf, register_size (gdbarch, regno));
392 dst = regp + regaddr;
393 store_signed_integer (dst, 8, val);
394 }
395 }
396
397 /* Likewise, unpack an elf_fpregset_t. */
398
399 void
400 mips64_supply_fpregset (struct regcache *regcache,
401 const mips64_elf_fpregset_t *fpregsetp)
402 {
403 struct gdbarch *gdbarch = get_regcache_arch (regcache);
404 int regi;
405
406 /* See mips_linux_o32_sigframe_init for a description of the
407 peculiar FP register layout. */
408 if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
409 for (regi = 0; regi < 32; regi++)
410 {
411 const gdb_byte *reg_ptr = (const gdb_byte *)(*fpregsetp + (regi & ~1));
412 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
413 reg_ptr += 4;
414 regcache_raw_supply (regcache,
415 gdbarch_fp0_regnum (gdbarch) + regi,
416 reg_ptr);
417 }
418 else
419 for (regi = 0; regi < 32; regi++)
420 regcache_raw_supply (regcache,
421 gdbarch_fp0_regnum (gdbarch) + regi,
422 (const char *)(*fpregsetp + regi));
423
424 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
425 (const gdb_byte *)(*fpregsetp + 32));
426
427 /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
428 include it - but the result of PTRACE_GETFPREGS does. The best we
429 can do is to assume that its value is present. */
430 supply_32bit_reg (regcache,
431 mips_regnum (gdbarch)->fp_implementation_revision,
432 (const gdb_byte *)(*fpregsetp + 32) + 4);
433 }
434
435 /* Likewise, pack one or all floating point registers into an
436 elf_fpregset_t. */
437
438 void
439 mips64_fill_fpregset (const struct regcache *regcache,
440 mips64_elf_fpregset_t *fpregsetp, int regno)
441 {
442 struct gdbarch *gdbarch = get_regcache_arch (regcache);
443 gdb_byte *to;
444
445 if ((regno >= gdbarch_fp0_regnum (gdbarch))
446 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
447 {
448 /* See mips_linux_o32_sigframe_init for a description of the
449 peculiar FP register layout. */
450 if (register_size (gdbarch, regno) == 4)
451 {
452 int regi = regno - gdbarch_fp0_regnum (gdbarch);
453
454 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
455 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
456 to += 4;
457 regcache_raw_collect (regcache, regno, to);
458 }
459 else
460 {
461 to = (gdb_byte *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
462 regcache_raw_collect (regcache, regno, to);
463 }
464 }
465 else if (regno == mips_regnum (gdbarch)->fp_control_status)
466 {
467 gdb_byte buf[MAX_REGISTER_SIZE];
468 LONGEST val;
469
470 regcache_raw_collect (regcache, regno, buf);
471 val = extract_signed_integer (buf, register_size (gdbarch, regno));
472 to = (gdb_byte *) (*fpregsetp + 32);
473 store_signed_integer (to, 4, val);
474 }
475 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
476 {
477 gdb_byte buf[MAX_REGISTER_SIZE];
478 LONGEST val;
479
480 regcache_raw_collect (regcache, regno, buf);
481 val = extract_signed_integer (buf, register_size (gdbarch, regno));
482 to = (gdb_byte *) (*fpregsetp + 32) + 4;
483 store_signed_integer (to, 4, val);
484 }
485 else if (regno == -1)
486 {
487 int regi;
488
489 for (regi = 0; regi < 32; regi++)
490 mips64_fill_fpregset (regcache, fpregsetp,
491 gdbarch_fp0_regnum (gdbarch) + regi);
492 mips64_fill_fpregset (regcache, fpregsetp,
493 mips_regnum (gdbarch)->fp_control_status);
494 mips64_fill_fpregset (regcache, fpregsetp,
495 (mips_regnum (gdbarch)
496 ->fp_implementation_revision));
497 }
498 }
499
500
501 /* Use a local version of this function to get the correct types for
502 regsets, until multi-arch core support is ready. */
503
504 static void
505 fetch_core_registers (struct regcache *regcache,
506 char *core_reg_sect, unsigned core_reg_size,
507 int which, CORE_ADDR reg_addr)
508 {
509 mips_elf_gregset_t gregset;
510 mips_elf_fpregset_t fpregset;
511 mips64_elf_gregset_t gregset64;
512 mips64_elf_fpregset_t fpregset64;
513
514 if (which == 0)
515 {
516 if (core_reg_size == sizeof (gregset))
517 {
518 memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset));
519 mips_supply_gregset (regcache,
520 (const mips_elf_gregset_t *) &gregset);
521 }
522 else if (core_reg_size == sizeof (gregset64))
523 {
524 memcpy ((char *) &gregset64, core_reg_sect, sizeof (gregset64));
525 mips64_supply_gregset (regcache,
526 (const mips64_elf_gregset_t *) &gregset64);
527 }
528 else
529 {
530 warning (_("wrong size gregset struct in core file"));
531 }
532 }
533 else if (which == 2)
534 {
535 if (core_reg_size == sizeof (fpregset))
536 {
537 memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset));
538 mips_supply_fpregset (regcache,
539 (const mips_elf_fpregset_t *) &fpregset);
540 }
541 else if (core_reg_size == sizeof (fpregset64))
542 {
543 memcpy ((char *) &fpregset64, core_reg_sect,
544 sizeof (fpregset64));
545 mips64_supply_fpregset (regcache,
546 (const mips64_elf_fpregset_t *) &fpregset64);
547 }
548 else
549 {
550 warning (_("wrong size fpregset struct in core file"));
551 }
552 }
553 }
554
555 /* Register that we are able to handle ELF file formats using standard
556 procfs "regset" structures. */
557
558 static struct core_fns regset_core_fns =
559 {
560 bfd_target_elf_flavour, /* core_flavour */
561 default_check_format, /* check_format */
562 default_core_sniffer, /* core_sniffer */
563 fetch_core_registers, /* core_read_registers */
564 NULL /* next */
565 };
566
567 static const struct target_desc *
568 mips_linux_core_read_description (struct gdbarch *gdbarch,
569 struct target_ops *target,
570 bfd *abfd)
571 {
572 asection *section = bfd_get_section_by_name (abfd, ".reg");
573 if (! section)
574 return NULL;
575
576 switch (bfd_section_size (abfd, section))
577 {
578 case sizeof (mips_elf_gregset_t):
579 return mips_tdesc_gp32;
580
581 case sizeof (mips64_elf_gregset_t):
582 return mips_tdesc_gp64;
583
584 default:
585 return NULL;
586 }
587 }
588
589
590 /* Check the code at PC for a dynamic linker lazy resolution stub.
591 Because they aren't in the .plt section, we pattern-match on the
592 code generated by GNU ld. They look like this:
593
594 lw t9,0x8010(gp)
595 addu t7,ra
596 jalr t9,ra
597 addiu t8,zero,INDEX
598
599 (with the appropriate doubleword instructions for N64). Also
600 return the dynamic symbol index used in the last instruction. */
601
602 static int
603 mips_linux_in_dynsym_stub (CORE_ADDR pc, char *name)
604 {
605 unsigned char buf[28], *p;
606 ULONGEST insn, insn1;
607 int n64 = (mips_abi (target_gdbarch) == MIPS_ABI_N64);
608
609 read_memory (pc - 12, buf, 28);
610
611 if (n64)
612 {
613 /* ld t9,0x8010(gp) */
614 insn1 = 0xdf998010;
615 }
616 else
617 {
618 /* lw t9,0x8010(gp) */
619 insn1 = 0x8f998010;
620 }
621
622 p = buf + 12;
623 while (p >= buf)
624 {
625 insn = extract_unsigned_integer (p, 4);
626 if (insn == insn1)
627 break;
628 p -= 4;
629 }
630 if (p < buf)
631 return 0;
632
633 insn = extract_unsigned_integer (p + 4, 4);
634 if (n64)
635 {
636 /* daddu t7,ra */
637 if (insn != 0x03e0782d)
638 return 0;
639 }
640 else
641 {
642 /* addu t7,ra */
643 if (insn != 0x03e07821)
644 return 0;
645 }
646
647 insn = extract_unsigned_integer (p + 8, 4);
648 /* jalr t9,ra */
649 if (insn != 0x0320f809)
650 return 0;
651
652 insn = extract_unsigned_integer (p + 12, 4);
653 if (n64)
654 {
655 /* daddiu t8,zero,0 */
656 if ((insn & 0xffff0000) != 0x64180000)
657 return 0;
658 }
659 else
660 {
661 /* addiu t8,zero,0 */
662 if ((insn & 0xffff0000) != 0x24180000)
663 return 0;
664 }
665
666 return (insn & 0xffff);
667 }
668
669 /* Return non-zero iff PC belongs to the dynamic linker resolution
670 code, a PLT entry, or a lazy binding stub. */
671
672 static int
673 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
674 {
675 /* Check whether PC is in the dynamic linker. This also checks
676 whether it is in the .plt section, used by non-PIC executables. */
677 if (svr4_in_dynsym_resolve_code (pc))
678 return 1;
679
680 /* Pattern match for the stub. It would be nice if there were a
681 more efficient way to avoid this check. */
682 if (mips_linux_in_dynsym_stub (pc, NULL))
683 return 1;
684
685 return 0;
686 }
687
688 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
689 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
690 implementation of this triggers at "fixup" from the same objfile as
691 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
692 "__dl_runtime_resolve" directly. An unresolved lazy binding
693 stub will point to _dl_runtime_resolve, which will first call
694 __dl_runtime_resolve, and then pass control to the resolved
695 function. */
696
697 static CORE_ADDR
698 mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
699 {
700 struct minimal_symbol *resolver;
701
702 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
703
704 if (resolver && SYMBOL_VALUE_ADDRESS (resolver) == pc)
705 return frame_unwind_caller_pc (get_current_frame ());
706
707 return glibc_skip_solib_resolver (gdbarch, pc);
708 }
709
710 /* Signal trampoline support. There are four supported layouts for a
711 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
712 n64 rt_sigframe. We handle them all independently; not the most
713 efficient way, but simplest. First, declare all the unwinders. */
714
715 static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
716 struct frame_info *this_frame,
717 struct trad_frame_cache *this_cache,
718 CORE_ADDR func);
719
720 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
721 struct frame_info *this_frame,
722 struct trad_frame_cache *this_cache,
723 CORE_ADDR func);
724
725 #define MIPS_NR_LINUX 4000
726 #define MIPS_NR_N64_LINUX 5000
727 #define MIPS_NR_N32_LINUX 6000
728
729 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
730 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
731 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
732 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
733
734 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
735 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
736 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
737 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
738 #define MIPS_INST_SYSCALL 0x0000000c
739
740 static const struct tramp_frame mips_linux_o32_sigframe = {
741 SIGTRAMP_FRAME,
742 4,
743 {
744 { MIPS_INST_LI_V0_SIGRETURN, -1 },
745 { MIPS_INST_SYSCALL, -1 },
746 { TRAMP_SENTINEL_INSN, -1 }
747 },
748 mips_linux_o32_sigframe_init
749 };
750
751 static const struct tramp_frame mips_linux_o32_rt_sigframe = {
752 SIGTRAMP_FRAME,
753 4,
754 {
755 { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
756 { MIPS_INST_SYSCALL, -1 },
757 { TRAMP_SENTINEL_INSN, -1 } },
758 mips_linux_o32_sigframe_init
759 };
760
761 static const struct tramp_frame mips_linux_n32_rt_sigframe = {
762 SIGTRAMP_FRAME,
763 4,
764 {
765 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
766 { MIPS_INST_SYSCALL, -1 },
767 { TRAMP_SENTINEL_INSN, -1 }
768 },
769 mips_linux_n32n64_sigframe_init
770 };
771
772 static const struct tramp_frame mips_linux_n64_rt_sigframe = {
773 SIGTRAMP_FRAME,
774 4,
775 {
776 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
777 { MIPS_INST_SYSCALL, -1 },
778 { TRAMP_SENTINEL_INSN, -1 }
779 },
780 mips_linux_n32n64_sigframe_init
781 };
782
783 /* *INDENT-OFF* */
784 /* The unwinder for o32 signal frames. The legacy structures look
785 like this:
786
787 struct sigframe {
788 u32 sf_ass[4]; [argument save space for o32]
789 u32 sf_code[2]; [signal trampoline]
790 struct sigcontext sf_sc;
791 sigset_t sf_mask;
792 };
793
794 struct sigcontext {
795 unsigned int sc_regmask; [Unused]
796 unsigned int sc_status;
797 unsigned long long sc_pc;
798 unsigned long long sc_regs[32];
799 unsigned long long sc_fpregs[32];
800 unsigned int sc_ownedfp;
801 unsigned int sc_fpc_csr;
802 unsigned int sc_fpc_eir; [Unused]
803 unsigned int sc_used_math;
804 unsigned int sc_ssflags; [Unused]
805 [Alignment hole of four bytes]
806 unsigned long long sc_mdhi;
807 unsigned long long sc_mdlo;
808
809 unsigned int sc_cause; [Unused]
810 unsigned int sc_badvaddr; [Unused]
811
812 unsigned long sc_sigset[4]; [kernel's sigset_t]
813 };
814
815 The RT signal frames look like this:
816
817 struct rt_sigframe {
818 u32 rs_ass[4]; [argument save space for o32]
819 u32 rs_code[2] [signal trampoline]
820 struct siginfo rs_info;
821 struct ucontext rs_uc;
822 };
823
824 struct ucontext {
825 unsigned long uc_flags;
826 struct ucontext *uc_link;
827 stack_t uc_stack;
828 [Alignment hole of four bytes]
829 struct sigcontext uc_mcontext;
830 sigset_t uc_sigmask;
831 }; */
832 /* *INDENT-ON* */
833
834 #define SIGFRAME_CODE_OFFSET (4 * 4)
835 #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
836
837 #define RTSIGFRAME_SIGINFO_SIZE 128
838 #define STACK_T_SIZE (3 * 4)
839 #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
840 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
841 + RTSIGFRAME_SIGINFO_SIZE \
842 + UCONTEXT_SIGCONTEXT_OFFSET)
843
844 #define SIGCONTEXT_PC (1 * 8)
845 #define SIGCONTEXT_REGS (2 * 8)
846 #define SIGCONTEXT_FPREGS (34 * 8)
847 #define SIGCONTEXT_FPCSR (66 * 8 + 4)
848 #define SIGCONTEXT_HI (69 * 8)
849 #define SIGCONTEXT_LO (70 * 8)
850 #define SIGCONTEXT_CAUSE (71 * 8 + 0)
851 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
852
853 #define SIGCONTEXT_REG_SIZE 8
854
855 static void
856 mips_linux_o32_sigframe_init (const struct tramp_frame *self,
857 struct frame_info *this_frame,
858 struct trad_frame_cache *this_cache,
859 CORE_ADDR func)
860 {
861 struct gdbarch *gdbarch = get_frame_arch (this_frame);
862 int ireg, reg_position;
863 CORE_ADDR sigcontext_base = func - SIGFRAME_CODE_OFFSET;
864 const struct mips_regnum *regs = mips_regnum (gdbarch);
865 CORE_ADDR regs_base;
866
867 if (self == &mips_linux_o32_sigframe)
868 sigcontext_base += SIGFRAME_SIGCONTEXT_OFFSET;
869 else
870 sigcontext_base += RTSIGFRAME_SIGCONTEXT_OFFSET;
871
872 /* I'm not proud of this hack. Eventually we will have the
873 infrastructure to indicate the size of saved registers on a
874 per-frame basis, but right now we don't; the kernel saves eight
875 bytes but we only want four. Use regs_base to access any
876 64-bit fields. */
877 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
878 regs_base = sigcontext_base + 4;
879 else
880 regs_base = sigcontext_base;
881
882 if (mips_linux_restart_reg_p (gdbarch))
883 trad_frame_set_reg_addr (this_cache,
884 (MIPS_RESTART_REGNUM
885 + gdbarch_num_regs (gdbarch)),
886 regs_base + SIGCONTEXT_REGS);
887
888 for (ireg = 1; ireg < 32; ireg++)
889 trad_frame_set_reg_addr (this_cache,
890 ireg + MIPS_ZERO_REGNUM
891 + gdbarch_num_regs (gdbarch),
892 regs_base + SIGCONTEXT_REGS
893 + ireg * SIGCONTEXT_REG_SIZE);
894
895 /* The way that floating point registers are saved, unfortunately,
896 depends on the architecture the kernel is built for. For the r3000 and
897 tx39, four bytes of each register are at the beginning of each of the
898 32 eight byte slots. For everything else, the registers are saved
899 using double precision; only the even-numbered slots are initialized,
900 and the high bits are the odd-numbered register. Assume the latter
901 layout, since we can't tell, and it's much more common. Which bits are
902 the "high" bits depends on endianness. */
903 for (ireg = 0; ireg < 32; ireg++)
904 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
905 trad_frame_set_reg_addr (this_cache,
906 ireg + regs->fp0 +
907 gdbarch_num_regs (gdbarch),
908 sigcontext_base + SIGCONTEXT_FPREGS + 4
909 + (ireg & ~1) * SIGCONTEXT_REG_SIZE);
910 else
911 trad_frame_set_reg_addr (this_cache,
912 ireg + regs->fp0
913 + gdbarch_num_regs (gdbarch),
914 sigcontext_base + SIGCONTEXT_FPREGS
915 + (ireg & ~1) * SIGCONTEXT_REG_SIZE);
916
917 trad_frame_set_reg_addr (this_cache,
918 regs->pc + gdbarch_num_regs (gdbarch),
919 regs_base + SIGCONTEXT_PC);
920
921 trad_frame_set_reg_addr (this_cache,
922 regs->fp_control_status
923 + gdbarch_num_regs (gdbarch),
924 sigcontext_base + SIGCONTEXT_FPCSR);
925 trad_frame_set_reg_addr (this_cache,
926 regs->hi + gdbarch_num_regs (gdbarch),
927 regs_base + SIGCONTEXT_HI);
928 trad_frame_set_reg_addr (this_cache,
929 regs->lo + gdbarch_num_regs (gdbarch),
930 regs_base + SIGCONTEXT_LO);
931 trad_frame_set_reg_addr (this_cache,
932 regs->cause + gdbarch_num_regs (gdbarch),
933 sigcontext_base + SIGCONTEXT_CAUSE);
934 trad_frame_set_reg_addr (this_cache,
935 regs->badvaddr + gdbarch_num_regs (gdbarch),
936 sigcontext_base + SIGCONTEXT_BADVADDR);
937
938 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
939 trad_frame_set_id (this_cache,
940 frame_id_build (func - SIGFRAME_CODE_OFFSET,
941 func));
942 }
943
944 /* *INDENT-OFF* */
945 /* For N32/N64 things look different. There is no non-rt signal frame.
946
947 struct rt_sigframe_n32 {
948 u32 rs_ass[4]; [ argument save space for o32 ]
949 u32 rs_code[2]; [ signal trampoline ]
950 struct siginfo rs_info;
951 struct ucontextn32 rs_uc;
952 };
953
954 struct ucontextn32 {
955 u32 uc_flags;
956 s32 uc_link;
957 stack32_t uc_stack;
958 struct sigcontext uc_mcontext;
959 sigset_t uc_sigmask; [ mask last for extensibility ]
960 };
961
962 struct rt_sigframe {
963 u32 rs_ass[4]; [ argument save space for o32 ]
964 u32 rs_code[2]; [ signal trampoline ]
965 struct siginfo rs_info;
966 struct ucontext rs_uc;
967 };
968
969 struct ucontext {
970 unsigned long uc_flags;
971 struct ucontext *uc_link;
972 stack_t uc_stack;
973 struct sigcontext uc_mcontext;
974 sigset_t uc_sigmask; [ mask last for extensibility ]
975 };
976
977 And the sigcontext is different (this is for both n32 and n64):
978
979 struct sigcontext {
980 unsigned long long sc_regs[32];
981 unsigned long long sc_fpregs[32];
982 unsigned long long sc_mdhi;
983 unsigned long long sc_hi1;
984 unsigned long long sc_hi2;
985 unsigned long long sc_hi3;
986 unsigned long long sc_mdlo;
987 unsigned long long sc_lo1;
988 unsigned long long sc_lo2;
989 unsigned long long sc_lo3;
990 unsigned long long sc_pc;
991 unsigned int sc_fpc_csr;
992 unsigned int sc_used_math;
993 unsigned int sc_dsp;
994 unsigned int sc_reserved;
995 };
996
997 That is the post-2.6.12 definition of the 64-bit sigcontext; before
998 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
999 included too. */
1000 /* *INDENT-ON* */
1001
1002 #define N32_STACK_T_SIZE STACK_T_SIZE
1003 #define N64_STACK_T_SIZE (2 * 8 + 4)
1004 #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1005 #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1006 #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1007 + RTSIGFRAME_SIGINFO_SIZE \
1008 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1009 #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1010 + RTSIGFRAME_SIGINFO_SIZE \
1011 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1012
1013 #define N64_SIGCONTEXT_REGS (0 * 8)
1014 #define N64_SIGCONTEXT_FPREGS (32 * 8)
1015 #define N64_SIGCONTEXT_HI (64 * 8)
1016 #define N64_SIGCONTEXT_LO (68 * 8)
1017 #define N64_SIGCONTEXT_PC (72 * 8)
1018 #define N64_SIGCONTEXT_FPCSR (73 * 8)
1019
1020 #define N64_SIGCONTEXT_REG_SIZE 8
1021
1022 static void
1023 mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
1024 struct frame_info *this_frame,
1025 struct trad_frame_cache *this_cache,
1026 CORE_ADDR func)
1027 {
1028 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1029 int ireg, reg_position;
1030 CORE_ADDR sigcontext_base = func - SIGFRAME_CODE_OFFSET;
1031 const struct mips_regnum *regs = mips_regnum (gdbarch);
1032
1033 if (self == &mips_linux_n32_rt_sigframe)
1034 sigcontext_base += N32_SIGFRAME_SIGCONTEXT_OFFSET;
1035 else
1036 sigcontext_base += N64_SIGFRAME_SIGCONTEXT_OFFSET;
1037
1038 if (mips_linux_restart_reg_p (gdbarch))
1039 trad_frame_set_reg_addr (this_cache,
1040 (MIPS_RESTART_REGNUM
1041 + gdbarch_num_regs (gdbarch)),
1042 sigcontext_base + N64_SIGCONTEXT_REGS);
1043
1044 for (ireg = 1; ireg < 32; ireg++)
1045 trad_frame_set_reg_addr (this_cache,
1046 ireg + MIPS_ZERO_REGNUM
1047 + gdbarch_num_regs (gdbarch),
1048 sigcontext_base + N64_SIGCONTEXT_REGS
1049 + ireg * N64_SIGCONTEXT_REG_SIZE);
1050
1051 for (ireg = 0; ireg < 32; ireg++)
1052 trad_frame_set_reg_addr (this_cache,
1053 ireg + regs->fp0
1054 + gdbarch_num_regs (gdbarch),
1055 sigcontext_base + N64_SIGCONTEXT_FPREGS
1056 + ireg * N64_SIGCONTEXT_REG_SIZE);
1057
1058 trad_frame_set_reg_addr (this_cache,
1059 regs->pc + gdbarch_num_regs (gdbarch),
1060 sigcontext_base + N64_SIGCONTEXT_PC);
1061
1062 trad_frame_set_reg_addr (this_cache,
1063 regs->fp_control_status
1064 + gdbarch_num_regs (gdbarch),
1065 sigcontext_base + N64_SIGCONTEXT_FPCSR);
1066 trad_frame_set_reg_addr (this_cache,
1067 regs->hi + gdbarch_num_regs (gdbarch),
1068 sigcontext_base + N64_SIGCONTEXT_HI);
1069 trad_frame_set_reg_addr (this_cache,
1070 regs->lo + gdbarch_num_regs (gdbarch),
1071 sigcontext_base + N64_SIGCONTEXT_LO);
1072
1073 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
1074 trad_frame_set_id (this_cache,
1075 frame_id_build (func - SIGFRAME_CODE_OFFSET,
1076 func));
1077 }
1078
1079 static void
1080 mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1081 {
1082 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1083 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
1084
1085 /* Clear the syscall restart flag. */
1086 if (mips_linux_restart_reg_p (gdbarch))
1087 regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
1088 }
1089
1090 /* Return 1 if MIPS_RESTART_REGNUM is usable. */
1091
1092 int
1093 mips_linux_restart_reg_p (struct gdbarch *gdbarch)
1094 {
1095 /* If we do not have a target description with registers, then
1096 MIPS_RESTART_REGNUM will not be included in the register set. */
1097 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1098 return 0;
1099
1100 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1101 either be GPR-sized or missing. */
1102 return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
1103 }
1104
1105 /* When FRAME is at a syscall instruction, return the PC of the next
1106 instruction to be executed. */
1107
1108 static CORE_ADDR
1109 mips_linux_syscall_next_pc (struct frame_info *frame)
1110 {
1111 CORE_ADDR pc = get_frame_pc (frame);
1112 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1113
1114 /* If we are about to make a sigreturn syscall, use the unwinder to
1115 decode the signal frame. */
1116 if (v0 == MIPS_NR_sigreturn
1117 || v0 == MIPS_NR_rt_sigreturn
1118 || v0 == MIPS_NR_N64_rt_sigreturn
1119 || v0 == MIPS_NR_N32_rt_sigreturn)
1120 return frame_unwind_caller_pc (get_current_frame ());
1121
1122 return pc + 4;
1123 }
1124
1125 /* Initialize one of the GNU/Linux OS ABIs. */
1126
1127 static void
1128 mips_linux_init_abi (struct gdbarch_info info,
1129 struct gdbarch *gdbarch)
1130 {
1131 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1132 enum mips_abi abi = mips_abi (gdbarch);
1133 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
1134
1135 switch (abi)
1136 {
1137 case MIPS_ABI_O32:
1138 set_gdbarch_get_longjmp_target (gdbarch,
1139 mips_linux_get_longjmp_target);
1140 set_solib_svr4_fetch_link_map_offsets
1141 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1142 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
1143 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
1144 break;
1145 case MIPS_ABI_N32:
1146 set_gdbarch_get_longjmp_target (gdbarch,
1147 mips_linux_get_longjmp_target);
1148 set_solib_svr4_fetch_link_map_offsets
1149 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1150 set_gdbarch_long_double_bit (gdbarch, 128);
1151 /* These floatformats should probably be renamed. MIPS uses
1152 the same 128-bit IEEE floating point format that IA-64 uses,
1153 except that the quiet/signalling NaN bit is reversed (GDB
1154 does not distinguish between quiet and signalling NaNs). */
1155 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1156 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
1157 break;
1158 case MIPS_ABI_N64:
1159 set_gdbarch_get_longjmp_target (gdbarch,
1160 mips64_linux_get_longjmp_target);
1161 set_solib_svr4_fetch_link_map_offsets
1162 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1163 set_gdbarch_long_double_bit (gdbarch, 128);
1164 /* These floatformats should probably be renamed. MIPS uses
1165 the same 128-bit IEEE floating point format that IA-64 uses,
1166 except that the quiet/signalling NaN bit is reversed (GDB
1167 does not distinguish between quiet and signalling NaNs). */
1168 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
1169 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
1170 break;
1171 default:
1172 break;
1173 }
1174
1175 set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
1176
1177 set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
1178
1179 /* Enable TLS support. */
1180 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1181 svr4_fetch_objfile_link_map);
1182
1183 /* Initialize this lazily, to avoid an initialization order
1184 dependency on solib-svr4.c's _initialize routine. */
1185 if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
1186 {
1187 mips_svr4_so_ops = svr4_so_ops;
1188 mips_svr4_so_ops.in_dynsym_resolve_code
1189 = mips_linux_in_dynsym_resolve_code;
1190 }
1191 set_solib_ops (gdbarch, &mips_svr4_so_ops);
1192
1193 set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
1194
1195 set_gdbarch_core_read_description (gdbarch,
1196 mips_linux_core_read_description);
1197
1198 tdep->syscall_next_pc = mips_linux_syscall_next_pc;
1199
1200 if (tdesc_data)
1201 {
1202 const struct tdesc_feature *feature;
1203
1204 /* If we have target-described registers, then we can safely
1205 reserve a number for MIPS_RESTART_REGNUM (whether it is
1206 described or not). */
1207 gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
1208 set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
1209
1210 /* If it's present, then assign it to the reserved number. */
1211 feature = tdesc_find_feature (info.target_desc,
1212 "org.gnu.gdb.mips.linux");
1213 if (feature != NULL)
1214 tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
1215 "restart");
1216 }
1217 }
1218
1219 /* Provide a prototype to silence -Wmissing-prototypes. */
1220 extern initialize_file_ftype _initialize_mips_linux_tdep;
1221
1222 void
1223 _initialize_mips_linux_tdep (void)
1224 {
1225 const struct bfd_arch_info *arch_info;
1226
1227 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1228 arch_info != NULL;
1229 arch_info = arch_info->next)
1230 {
1231 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1232 GDB_OSABI_LINUX,
1233 mips_linux_init_abi);
1234 }
1235
1236 deprecated_add_core_fns (&regset_core_fns);
1237 }