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