Fix uninitialized value access when very first GDB command entered is <RET>
[deliverable/binutils-gdb.git] / gdb / mips-linux-tdep.c
CommitLineData
75c9abc6 1/* Target-dependent code for GNU/Linux on MIPS processors.
a094c6fb 2
ecd75fc8 3 Copyright (C) 2001-2014 Free Software Foundation, Inc.
2aa830e4
DJ
4
5 This file is part of GDB.
6
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
2aa830e4
DJ
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
2aa830e4
DJ
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "target.h"
23#include "solib-svr4.h"
19ed69dd 24#include "osabi.h"
96f026fc 25#include "mips-tdep.h"
6de918a6 26#include "frame.h"
2fdf551c 27#include "regcache.h"
5792a79b
DJ
28#include "trad-frame.h"
29#include "tramp-frame.h"
e6bb342a 30#include "gdbtypes.h"
3e5d3a5a 31#include "objfiles.h"
5ea03926 32#include "solib.h"
7d522c90 33#include "solist.h"
982e9687 34#include "symtab.h"
822b6570 35#include "target-descriptions.h"
50e8a0d5 36#include "regset.h"
d37eb719 37#include "mips-linux-tdep.h"
db5f024e 38#include "glibc-tdep.h"
a5ee0f0c 39#include "linux-tdep.h"
385203ed 40#include "xml-syscall.h"
232b8704 41#include "gdb_signals.h"
2aa830e4 42
7d522c90
DJ
43static struct target_so_ops mips_svr4_so_ops;
44
eb14d406
SDJ
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.
48
49 It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
50 from the Linux kernel tree. */
51
52enum
53 {
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,
75
76 MIPS_LINUX_SIGRTMIN = 32,
77 MIPS_LINUX_SIGRT64 = 64,
78 MIPS_LINUX_SIGRTMAX = 127,
79 };
80
2aa830e4 81/* Figure out where the longjmp will land.
295093a4
MS
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
85 success. */
2aa830e4 86
19ed69dd
KB
87#define MIPS_LINUX_JB_ELEMENT_SIZE 4
88#define MIPS_LINUX_JB_PC 0
89
90static int
60ade65d 91mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
2aa830e4
DJ
92{
93 CORE_ADDR jb_addr;
2eb4d78b 94 struct gdbarch *gdbarch = get_frame_arch (frame);
e17a4113 95 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e362b510 96 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
2aa830e4 97
60ade65d 98 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
2aa830e4 99
7d266584
MR
100 if (target_read_memory ((jb_addr
101 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
2eb4d78b 102 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
2aa830e4
DJ
103 return 0;
104
819844ad 105 *pc = extract_unsigned_integer (buf,
e17a4113
UW
106 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
107 byte_order);
2aa830e4
DJ
108
109 return 1;
110}
111
4246e332 112/* Transform the bits comprising a 32-bit register to the right size
23a6d369
AC
113 for regcache_raw_supply(). This is needed when mips_isa_regsize()
114 is 8. */
96f026fc
KB
115
116static void
28f5035f 117supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
96f026fc 118{
e17a4113
UW
119 struct gdbarch *gdbarch = get_regcache_arch (regcache);
120 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
d37eb719 121 gdb_byte buf[MAX_REGISTER_SIZE];
e17a4113 122 store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
7d266584 123 extract_signed_integer (addr, 4, byte_order));
28f5035f 124 regcache_raw_supply (regcache, regnum, buf);
96f026fc
KB
125}
126
2aa830e4
DJ
127/* Unpack an elf_gregset_t into GDB's register cache. */
128
d37eb719 129void
28f5035f
UW
130mips_supply_gregset (struct regcache *regcache,
131 const mips_elf_gregset_t *gregsetp)
2aa830e4
DJ
132{
133 int regi;
28f5035f 134 const mips_elf_greg_t *regp = *gregsetp;
d9d9c31f 135 char zerobuf[MAX_REGISTER_SIZE];
2eb4d78b 136 struct gdbarch *gdbarch = get_regcache_arch (regcache);
bf072999 137
d9d9c31f 138 memset (zerobuf, 0, MAX_REGISTER_SIZE);
2aa830e4 139
822b6570 140 for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
28f5035f 141 supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
2aa830e4 142
2eb4d78b 143 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
144 supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
145
2eb4d78b
UW
146 supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
147 supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
56cea623 148
2eb4d78b 149 supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
28f5035f 150 regp + EF_CP0_EPC);
2eb4d78b 151 supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
28f5035f
UW
152 regp + EF_CP0_BADVADDR);
153 supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
2eb4d78b 154 supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
28f5035f 155 regp + EF_CP0_CAUSE);
2aa830e4 156
1faeff08 157 /* Fill the inaccessible zero register with zero. */
822b6570 158 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
2aa830e4
DJ
159}
160
50e8a0d5
HZ
161static void
162mips_supply_gregset_wrapper (const struct regset *regset,
7d266584
MR
163 struct regcache *regcache,
164 int regnum, const void *gregs, size_t len)
50e8a0d5
HZ
165{
166 gdb_assert (len == sizeof (mips_elf_gregset_t));
167
168 mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
169}
170
2aa830e4
DJ
171/* Pack our registers (or one register) into an elf_gregset_t. */
172
d37eb719 173void
28f5035f
UW
174mips_fill_gregset (const struct regcache *regcache,
175 mips_elf_gregset_t *gregsetp, int regno)
2aa830e4 176{
2eb4d78b 177 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2aa830e4 178 int regaddr, regi;
d37eb719 179 mips_elf_greg_t *regp = *gregsetp;
96f026fc 180 void *dst;
2aa830e4
DJ
181
182 if (regno == -1)
183 {
d37eb719 184 memset (regp, 0, sizeof (mips_elf_gregset_t));
822b6570 185 for (regi = 1; regi < 32; regi++)
28f5035f 186 mips_fill_gregset (regcache, gregsetp, regi);
2eb4d78b
UW
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);
28f5035f 191 mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
2eb4d78b 192 mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
822b6570 193 mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
2aa830e4
DJ
194 return;
195 }
196
822b6570 197 if (regno > 0 && regno < 32)
2aa830e4 198 {
2aa830e4 199 dst = regp + regno + EF_REG0;
28f5035f 200 regcache_raw_collect (regcache, regno, dst);
2aa830e4
DJ
201 return;
202 }
203
2eb4d78b
UW
204 if (regno == mips_regnum (gdbarch)->lo)
205 regaddr = EF_LO;
206 else if (regno == mips_regnum (gdbarch)->hi)
56cea623 207 regaddr = EF_HI;
2eb4d78b 208 else if (regno == mips_regnum (gdbarch)->pc)
56cea623 209 regaddr = EF_CP0_EPC;
2eb4d78b 210 else if (regno == mips_regnum (gdbarch)->badvaddr)
56cea623 211 regaddr = EF_CP0_BADVADDR;
24e05951 212 else if (regno == MIPS_PS_REGNUM)
56cea623 213 regaddr = EF_CP0_STATUS;
2eb4d78b 214 else if (regno == mips_regnum (gdbarch)->cause)
56cea623 215 regaddr = EF_CP0_CAUSE;
2eb4d78b 216 else if (mips_linux_restart_reg_p (gdbarch)
822b6570
DJ
217 && regno == MIPS_RESTART_REGNUM)
218 regaddr = EF_REG0;
56cea623
AC
219 else
220 regaddr = -1;
2aa830e4
DJ
221
222 if (regaddr != -1)
223 {
2aa830e4 224 dst = regp + regaddr;
28f5035f 225 regcache_raw_collect (regcache, regno, dst);
2aa830e4
DJ
226 }
227}
228
50e8a0d5
HZ
229static void
230mips_fill_gregset_wrapper (const struct regset *regset,
231 const struct regcache *regcache,
232 int regnum, void *gregs, size_t len)
233{
234 gdb_assert (len == sizeof (mips_elf_gregset_t));
235
236 mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
237}
238
2aa830e4
DJ
239/* Likewise, unpack an elf_fpregset_t. */
240
d37eb719 241void
28f5035f
UW
242mips_supply_fpregset (struct regcache *regcache,
243 const mips_elf_fpregset_t *fpregsetp)
2aa830e4 244{
2eb4d78b 245 struct gdbarch *gdbarch = get_regcache_arch (regcache);
52f0bd74 246 int regi;
d9d9c31f 247 char zerobuf[MAX_REGISTER_SIZE];
bf072999 248
d9d9c31f 249 memset (zerobuf, 0, MAX_REGISTER_SIZE);
2aa830e4
DJ
250
251 for (regi = 0; regi < 32; regi++)
3e8c568d 252 regcache_raw_supply (regcache,
2eb4d78b 253 gdbarch_fp0_regnum (gdbarch) + regi,
3e8c568d 254 *fpregsetp + regi);
2aa830e4 255
28f5035f 256 regcache_raw_supply (regcache,
2eb4d78b 257 mips_regnum (gdbarch)->fp_control_status,
28f5035f 258 *fpregsetp + 32);
2aa830e4 259
295093a4 260 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
28f5035f 261 regcache_raw_supply (regcache,
2eb4d78b 262 mips_regnum (gdbarch)->fp_implementation_revision,
23a6d369 263 zerobuf);
2aa830e4
DJ
264}
265
50e8a0d5
HZ
266static void
267mips_supply_fpregset_wrapper (const struct regset *regset,
7d266584
MR
268 struct regcache *regcache,
269 int regnum, const void *gregs, size_t len)
50e8a0d5
HZ
270{
271 gdb_assert (len == sizeof (mips_elf_fpregset_t));
272
273 mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *)gregs);
274}
275
2aa830e4
DJ
276/* Likewise, pack one or all floating point registers into an
277 elf_fpregset_t. */
278
d37eb719 279void
28f5035f
UW
280mips_fill_fpregset (const struct regcache *regcache,
281 mips_elf_fpregset_t *fpregsetp, int regno)
2aa830e4 282{
2eb4d78b 283 struct gdbarch *gdbarch = get_regcache_arch (regcache);
22e048c9 284 char *to;
2aa830e4 285
2eb4d78b
UW
286 if ((regno >= gdbarch_fp0_regnum (gdbarch))
287 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
2aa830e4 288 {
2eb4d78b 289 to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
28f5035f 290 regcache_raw_collect (regcache, regno, to);
2aa830e4 291 }
2eb4d78b 292 else if (regno == mips_regnum (gdbarch)->fp_control_status)
2aa830e4 293 {
2aa830e4 294 to = (char *) (*fpregsetp + 32);
28f5035f 295 regcache_raw_collect (regcache, regno, to);
2aa830e4
DJ
296 }
297 else if (regno == -1)
298 {
299 int regi;
300
301 for (regi = 0; regi < 32; regi++)
3e8c568d 302 mips_fill_fpregset (regcache, fpregsetp,
2eb4d78b 303 gdbarch_fp0_regnum (gdbarch) + regi);
28f5035f 304 mips_fill_fpregset (regcache, fpregsetp,
2eb4d78b 305 mips_regnum (gdbarch)->fp_control_status);
2aa830e4
DJ
306 }
307}
308
50e8a0d5
HZ
309static void
310mips_fill_fpregset_wrapper (const struct regset *regset,
311 const struct regcache *regcache,
312 int regnum, void *gregs, size_t len)
313{
314 gdb_assert (len == sizeof (mips_elf_fpregset_t));
315
316 mips_fill_fpregset (regcache, (mips_elf_fpregset_t *)gregs, regnum);
317}
318
96f026fc
KB
319/* Support for 64-bit ABIs. */
320
96f026fc 321/* Figure out where the longjmp will land.
295093a4
MS
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
325 success. */
96f026fc
KB
326
327/* Details about jmp_buf. */
328
329#define MIPS64_LINUX_JB_PC 0
330
331static int
60ade65d 332mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
96f026fc
KB
333{
334 CORE_ADDR jb_addr;
2eb4d78b 335 struct gdbarch *gdbarch = get_frame_arch (frame);
e17a4113 336 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2eb4d78b
UW
337 void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
338 int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
96f026fc 339
60ade65d 340 jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
96f026fc
KB
341
342 if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
819844ad 343 buf,
2eb4d78b 344 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
96f026fc
KB
345 return 0;
346
819844ad 347 *pc = extract_unsigned_integer (buf,
e17a4113
UW
348 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
349 byte_order);
96f026fc
KB
350
351 return 1;
352}
353
d37eb719
DJ
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. */
357
358/* Supply a 64-bit register. */
96f026fc 359
63807e1d 360static void
28f5035f
UW
361supply_64bit_reg (struct regcache *regcache, int regnum,
362 const gdb_byte *buf)
d37eb719 363{
2eb4d78b
UW
364 struct gdbarch *gdbarch = get_regcache_arch (regcache);
365 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
366 && register_size (gdbarch, regnum) == 4)
28f5035f 367 regcache_raw_supply (regcache, regnum, buf + 4);
d37eb719 368 else
28f5035f 369 regcache_raw_supply (regcache, regnum, buf);
d37eb719
DJ
370}
371
372/* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
373
374void
28f5035f
UW
375mips64_supply_gregset (struct regcache *regcache,
376 const mips64_elf_gregset_t *gregsetp)
96f026fc
KB
377{
378 int regi;
28f5035f 379 const mips64_elf_greg_t *regp = *gregsetp;
d37eb719 380 gdb_byte zerobuf[MAX_REGISTER_SIZE];
2eb4d78b 381 struct gdbarch *gdbarch = get_regcache_arch (regcache);
96f026fc 382
d9d9c31f 383 memset (zerobuf, 0, MAX_REGISTER_SIZE);
96f026fc 384
822b6570 385 for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
28f5035f 386 supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
7d266584 387 (const gdb_byte *) (regp + regi));
28f5035f 388
2eb4d78b 389 if (mips_linux_restart_reg_p (gdbarch))
822b6570 390 supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
7d266584 391 (const gdb_byte *) (regp + MIPS64_EF_REG0));
822b6570 392
2eb4d78b 393 supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
28f5035f 394 (const gdb_byte *) (regp + MIPS64_EF_LO));
2eb4d78b 395 supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
28f5035f
UW
396 (const gdb_byte *) (regp + MIPS64_EF_HI));
397
2eb4d78b 398 supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
28f5035f 399 (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
2eb4d78b 400 supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
28f5035f
UW
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));
2eb4d78b 404 supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
28f5035f 405 (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
96f026fc 406
1faeff08 407 /* Fill the inaccessible zero register with zero. */
822b6570 408 regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
96f026fc
KB
409}
410
50e8a0d5
HZ
411static void
412mips64_supply_gregset_wrapper (const struct regset *regset,
7d266584
MR
413 struct regcache *regcache,
414 int regnum, const void *gregs, size_t len)
50e8a0d5
HZ
415{
416 gdb_assert (len == sizeof (mips64_elf_gregset_t));
417
418 mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
419}
420
d37eb719 421/* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
96f026fc 422
d37eb719 423void
28f5035f
UW
424mips64_fill_gregset (const struct regcache *regcache,
425 mips64_elf_gregset_t *gregsetp, int regno)
96f026fc 426{
2eb4d78b 427 struct gdbarch *gdbarch = get_regcache_arch (regcache);
e17a4113 428 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
96f026fc
KB
429 int regaddr, regi;
430 mips64_elf_greg_t *regp = *gregsetp;
2ba93934 431 void *dst;
96f026fc
KB
432
433 if (regno == -1)
434 {
435 memset (regp, 0, sizeof (mips64_elf_gregset_t));
822b6570 436 for (regi = 1; regi < 32; regi++)
7d266584 437 mips64_fill_gregset (regcache, gregsetp, regi);
2eb4d78b
UW
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);
025bb325
MS
441 mips64_fill_gregset (regcache, gregsetp,
442 mips_regnum (gdbarch)->badvaddr);
28f5035f 443 mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
2eb4d78b 444 mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
822b6570 445 mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
96f026fc
KB
446 return;
447 }
448
822b6570 449 if (regno > 0 && regno < 32)
d37eb719 450 regaddr = regno + MIPS64_EF_REG0;
2eb4d78b 451 else if (regno == mips_regnum (gdbarch)->lo)
56cea623 452 regaddr = MIPS64_EF_LO;
2eb4d78b 453 else if (regno == mips_regnum (gdbarch)->hi)
56cea623 454 regaddr = MIPS64_EF_HI;
2eb4d78b 455 else if (regno == mips_regnum (gdbarch)->pc)
56cea623 456 regaddr = MIPS64_EF_CP0_EPC;
2eb4d78b 457 else if (regno == mips_regnum (gdbarch)->badvaddr)
56cea623 458 regaddr = MIPS64_EF_CP0_BADVADDR;
24e05951 459 else if (regno == MIPS_PS_REGNUM)
56cea623 460 regaddr = MIPS64_EF_CP0_STATUS;
2eb4d78b 461 else if (regno == mips_regnum (gdbarch)->cause)
56cea623 462 regaddr = MIPS64_EF_CP0_CAUSE;
2eb4d78b 463 else if (mips_linux_restart_reg_p (gdbarch)
822b6570
DJ
464 && regno == MIPS_RESTART_REGNUM)
465 regaddr = MIPS64_EF_REG0;
56cea623
AC
466 else
467 regaddr = -1;
96f026fc
KB
468
469 if (regaddr != -1)
470 {
d37eb719
DJ
471 gdb_byte buf[MAX_REGISTER_SIZE];
472 LONGEST val;
473
28f5035f 474 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
475 val = extract_signed_integer (buf, register_size (gdbarch, regno),
476 byte_order);
96f026fc 477 dst = regp + regaddr;
e17a4113 478 store_signed_integer (dst, 8, byte_order, val);
96f026fc
KB
479 }
480}
481
50e8a0d5
HZ
482static void
483mips64_fill_gregset_wrapper (const struct regset *regset,
484 const struct regcache *regcache,
485 int regnum, void *gregs, size_t len)
486{
487 gdb_assert (len == sizeof (mips64_elf_gregset_t));
488
489 mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
490}
491
96f026fc
KB
492/* Likewise, unpack an elf_fpregset_t. */
493
d37eb719 494void
28f5035f
UW
495mips64_supply_fpregset (struct regcache *regcache,
496 const mips64_elf_fpregset_t *fpregsetp)
96f026fc 497{
2eb4d78b 498 struct gdbarch *gdbarch = get_regcache_arch (regcache);
52f0bd74 499 int regi;
96f026fc 500
d37eb719
DJ
501 /* See mips_linux_o32_sigframe_init for a description of the
502 peculiar FP register layout. */
2eb4d78b 503 if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
d37eb719
DJ
504 for (regi = 0; regi < 32; regi++)
505 {
7d266584
MR
506 const gdb_byte *reg_ptr
507 = (const gdb_byte *) (*fpregsetp + (regi & ~1));
2eb4d78b 508 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
d37eb719 509 reg_ptr += 4;
3e8c568d 510 regcache_raw_supply (regcache,
2eb4d78b 511 gdbarch_fp0_regnum (gdbarch) + regi,
3e8c568d 512 reg_ptr);
d37eb719
DJ
513 }
514 else
515 for (regi = 0; regi < 32; regi++)
3e8c568d 516 regcache_raw_supply (regcache,
2eb4d78b 517 gdbarch_fp0_regnum (gdbarch) + regi,
7d266584 518 (const char *) (*fpregsetp + regi));
d37eb719 519
2eb4d78b 520 supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
7d266584 521 (const gdb_byte *) (*fpregsetp + 32));
d37eb719
DJ
522
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. */
28f5035f 526 supply_32bit_reg (regcache,
2eb4d78b 527 mips_regnum (gdbarch)->fp_implementation_revision,
7d266584 528 (const gdb_byte *) (*fpregsetp + 32) + 4);
96f026fc
KB
529}
530
50e8a0d5
HZ
531static void
532mips64_supply_fpregset_wrapper (const struct regset *regset,
7d266584
MR
533 struct regcache *regcache,
534 int regnum, const void *gregs, size_t len)
50e8a0d5
HZ
535{
536 gdb_assert (len == sizeof (mips64_elf_fpregset_t));
537
538 mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
539}
540
96f026fc
KB
541/* Likewise, pack one or all floating point registers into an
542 elf_fpregset_t. */
543
d37eb719 544void
28f5035f
UW
545mips64_fill_fpregset (const struct regcache *regcache,
546 mips64_elf_fpregset_t *fpregsetp, int regno)
96f026fc 547{
2eb4d78b 548 struct gdbarch *gdbarch = get_regcache_arch (regcache);
e17a4113 549 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
d37eb719 550 gdb_byte *to;
96f026fc 551
2eb4d78b
UW
552 if ((regno >= gdbarch_fp0_regnum (gdbarch))
553 && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
96f026fc 554 {
d37eb719
DJ
555 /* See mips_linux_o32_sigframe_init for a description of the
556 peculiar FP register layout. */
2eb4d78b 557 if (register_size (gdbarch, regno) == 4)
d37eb719 558 {
2eb4d78b 559 int regi = regno - gdbarch_fp0_regnum (gdbarch);
d37eb719
DJ
560
561 to = (gdb_byte *) (*fpregsetp + (regi & ~1));
2eb4d78b 562 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
d37eb719 563 to += 4;
28f5035f 564 regcache_raw_collect (regcache, regno, to);
d37eb719
DJ
565 }
566 else
567 {
025bb325
MS
568 to = (gdb_byte *) (*fpregsetp + regno
569 - gdbarch_fp0_regnum (gdbarch));
28f5035f 570 regcache_raw_collect (regcache, regno, to);
d37eb719 571 }
96f026fc 572 }
2eb4d78b 573 else if (regno == mips_regnum (gdbarch)->fp_control_status)
96f026fc 574 {
d37eb719
DJ
575 gdb_byte buf[MAX_REGISTER_SIZE];
576 LONGEST val;
577
28f5035f 578 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
579 val = extract_signed_integer (buf, register_size (gdbarch, regno),
580 byte_order);
d37eb719 581 to = (gdb_byte *) (*fpregsetp + 32);
e17a4113 582 store_signed_integer (to, 4, byte_order, val);
d37eb719 583 }
2eb4d78b 584 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
d37eb719
DJ
585 {
586 gdb_byte buf[MAX_REGISTER_SIZE];
587 LONGEST val;
588
28f5035f 589 regcache_raw_collect (regcache, regno, buf);
e17a4113
UW
590 val = extract_signed_integer (buf, register_size (gdbarch, regno),
591 byte_order);
d37eb719 592 to = (gdb_byte *) (*fpregsetp + 32) + 4;
e17a4113 593 store_signed_integer (to, 4, byte_order, val);
96f026fc
KB
594 }
595 else if (regno == -1)
596 {
597 int regi;
598
599 for (regi = 0; regi < 32; regi++)
3e8c568d 600 mips64_fill_fpregset (regcache, fpregsetp,
2eb4d78b 601 gdbarch_fp0_regnum (gdbarch) + regi);
28f5035f 602 mips64_fill_fpregset (regcache, fpregsetp,
2eb4d78b 603 mips_regnum (gdbarch)->fp_control_status);
28f5035f 604 mips64_fill_fpregset (regcache, fpregsetp,
7d266584 605 mips_regnum (gdbarch)->fp_implementation_revision);
96f026fc
KB
606 }
607}
608
50e8a0d5
HZ
609static void
610mips64_fill_fpregset_wrapper (const struct regset *regset,
611 const struct regcache *regcache,
612 int regnum, void *gregs, size_t len)
613{
614 gdb_assert (len == sizeof (mips64_elf_fpregset_t));
96f026fc 615
50e8a0d5
HZ
616 mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
617}
2aa830e4 618
b7195f27
AA
619static const struct regset mips_linux_gregset =
620 {
621 NULL, mips_supply_gregset_wrapper, mips_fill_gregset_wrapper
622 };
623
624static const struct regset mips64_linux_gregset =
625 {
626 NULL, mips64_supply_gregset_wrapper, mips64_fill_gregset_wrapper
627 };
628
629static const struct regset mips_linux_fpregset =
630 {
631 NULL, mips_supply_fpregset_wrapper, mips_fill_fpregset_wrapper
632 };
633
634static const struct regset mips64_linux_fpregset =
635 {
636 NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
637 };
638
d4036235
AA
639static void
640mips_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
641 iterate_over_regset_sections_cb *cb,
642 void *cb_data,
643 const struct regcache *regcache)
2aa830e4 644{
d4036235 645 if (register_size (gdbarch, MIPS_ZERO_REGNUM) == 4)
2aa830e4 646 {
d4036235
AA
647 cb (".reg", sizeof (mips_elf_gregset_t), &mips_linux_gregset,
648 NULL, cb_data);
649 cb (".reg2", sizeof (mips_elf_fpregset_t), &mips_linux_fpregset,
650 NULL, cb_data);
2aa830e4 651 }
d4036235 652 else
2aa830e4 653 {
d4036235
AA
654 cb (".reg", sizeof (mips64_elf_gregset_t), &mips64_linux_gregset,
655 NULL, cb_data);
656 cb (".reg2", sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
657 NULL, cb_data);
2aa830e4 658 }
50e8a0d5 659}
2aa830e4 660
4eb0ad19
DJ
661static const struct target_desc *
662mips_linux_core_read_description (struct gdbarch *gdbarch,
663 struct target_ops *target,
664 bfd *abfd)
665{
666 asection *section = bfd_get_section_by_name (abfd, ".reg");
667 if (! section)
668 return NULL;
669
670 switch (bfd_section_size (abfd, section))
671 {
672 case sizeof (mips_elf_gregset_t):
673 return mips_tdesc_gp32;
674
675 case sizeof (mips64_elf_gregset_t):
676 return mips_tdesc_gp64;
677
678 default:
679 return NULL;
680 }
681}
682
96f026fc 683
295093a4 684/* Check the code at PC for a dynamic linker lazy resolution stub.
3e5d3a5a
MR
685 GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
686 section uniformly since version 2.15. If the pc is in that section,
687 then we are in such a stub. Before that ".stub" was used in 32-bit
688 ELF binaries, however we do not bother checking for that since we
689 have never had and that case should be extremely rare these days.
690 Instead we pattern-match on the code generated by GNU ld. They look
691 like this:
6de918a6
DJ
692
693 lw t9,0x8010(gp)
694 addu t7,ra
695 jalr t9,ra
696 addiu t8,zero,INDEX
697
3e5d3a5a
MR
698 (with the appropriate doubleword instructions for N64). As any lazy
699 resolution stubs in microMIPS binaries will always be in a
700 ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
6de918a6
DJ
701
702static int
3e5d3a5a 703mips_linux_in_dynsym_stub (CORE_ADDR pc)
6de918a6 704{
e362b510 705 gdb_byte buf[28], *p;
6de918a6 706 ULONGEST insn, insn1;
f5656ead
TT
707 int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
708 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
6de918a6 709
3e5d3a5a
MR
710 if (in_mips_stubs_section (pc))
711 return 1;
712
6de918a6
DJ
713 read_memory (pc - 12, buf, 28);
714
715 if (n64)
716 {
717 /* ld t9,0x8010(gp) */
718 insn1 = 0xdf998010;
719 }
720 else
721 {
722 /* lw t9,0x8010(gp) */
723 insn1 = 0x8f998010;
724 }
725
726 p = buf + 12;
727 while (p >= buf)
728 {
e17a4113 729 insn = extract_unsigned_integer (p, 4, byte_order);
6de918a6
DJ
730 if (insn == insn1)
731 break;
732 p -= 4;
733 }
734 if (p < buf)
735 return 0;
736
e17a4113 737 insn = extract_unsigned_integer (p + 4, 4, byte_order);
6de918a6
DJ
738 if (n64)
739 {
740 /* daddu t7,ra */
741 if (insn != 0x03e0782d)
742 return 0;
743 }
744 else
745 {
746 /* addu t7,ra */
747 if (insn != 0x03e07821)
748 return 0;
749 }
295093a4 750
e17a4113 751 insn = extract_unsigned_integer (p + 8, 4, byte_order);
6de918a6
DJ
752 /* jalr t9,ra */
753 if (insn != 0x0320f809)
754 return 0;
755
e17a4113 756 insn = extract_unsigned_integer (p + 12, 4, byte_order);
6de918a6
DJ
757 if (n64)
758 {
759 /* daddiu t8,zero,0 */
760 if ((insn & 0xffff0000) != 0x64180000)
761 return 0;
762 }
763 else
764 {
765 /* addiu t8,zero,0 */
766 if ((insn & 0xffff0000) != 0x24180000)
767 return 0;
768 }
769
3e5d3a5a 770 return 1;
6de918a6
DJ
771}
772
295093a4 773/* Return non-zero iff PC belongs to the dynamic linker resolution
db5f024e 774 code, a PLT entry, or a lazy binding stub. */
6de918a6 775
7d522c90 776static int
6de918a6
DJ
777mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
778{
295093a4 779 /* Check whether PC is in the dynamic linker. This also checks
db5f024e 780 whether it is in the .plt section, used by non-PIC executables. */
7d522c90 781 if (svr4_in_dynsym_resolve_code (pc))
6de918a6
DJ
782 return 1;
783
3e5d3a5a
MR
784 /* Likewise for the stubs. They live in the .MIPS.stubs section these
785 days, so we check if the PC is within, than fall back to a pattern
786 match. */
787 if (mips_linux_in_dynsym_stub (pc))
6de918a6
DJ
788 return 1;
789
790 return 0;
791}
792
793/* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
794 and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
795 implementation of this triggers at "fixup" from the same objfile as
c4c5b7ba 796 "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
db5f024e
DJ
797 "__dl_runtime_resolve" directly. An unresolved lazy binding
798 stub will point to _dl_runtime_resolve, which will first call
c4c5b7ba
AC
799 __dl_runtime_resolve, and then pass control to the resolved
800 function. */
6de918a6
DJ
801
802static CORE_ADDR
803mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
804{
3b7344d5 805 struct bound_minimal_symbol resolver;
6de918a6
DJ
806
807 resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
808
77e371c0 809 if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
c7ce8faa 810 return frame_unwind_caller_pc (get_current_frame ());
6de918a6 811
db5f024e 812 return glibc_skip_solib_resolver (gdbarch, pc);
295093a4 813}
6de918a6 814
5792a79b
DJ
815/* Signal trampoline support. There are four supported layouts for a
816 signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
817 n64 rt_sigframe. We handle them all independently; not the most
818 efficient way, but simplest. First, declare all the unwinders. */
819
820static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
b8a22b94 821 struct frame_info *this_frame,
5792a79b
DJ
822 struct trad_frame_cache *this_cache,
823 CORE_ADDR func);
824
825static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
b8a22b94 826 struct frame_info *this_frame,
5792a79b
DJ
827 struct trad_frame_cache *this_cache,
828 CORE_ADDR func);
829
830#define MIPS_NR_LINUX 4000
831#define MIPS_NR_N64_LINUX 5000
832#define MIPS_NR_N32_LINUX 6000
833
834#define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
835#define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
836#define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
837#define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
838
839#define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
840#define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
841#define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
842#define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
843#define MIPS_INST_SYSCALL 0x0000000c
844
2cd8546d
AC
845static const struct tramp_frame mips_linux_o32_sigframe = {
846 SIGTRAMP_FRAME,
5792a79b 847 4,
2cd8546d
AC
848 {
849 { MIPS_INST_LI_V0_SIGRETURN, -1 },
850 { MIPS_INST_SYSCALL, -1 },
851 { TRAMP_SENTINEL_INSN, -1 }
852 },
5792a79b
DJ
853 mips_linux_o32_sigframe_init
854};
855
2cd8546d
AC
856static const struct tramp_frame mips_linux_o32_rt_sigframe = {
857 SIGTRAMP_FRAME,
5792a79b 858 4,
2cd8546d
AC
859 {
860 { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
861 { MIPS_INST_SYSCALL, -1 },
862 { TRAMP_SENTINEL_INSN, -1 } },
5792a79b
DJ
863 mips_linux_o32_sigframe_init
864};
865
2cd8546d
AC
866static const struct tramp_frame mips_linux_n32_rt_sigframe = {
867 SIGTRAMP_FRAME,
5792a79b 868 4,
2cd8546d
AC
869 {
870 { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
871 { MIPS_INST_SYSCALL, -1 },
872 { TRAMP_SENTINEL_INSN, -1 }
873 },
5792a79b
DJ
874 mips_linux_n32n64_sigframe_init
875};
876
2cd8546d
AC
877static const struct tramp_frame mips_linux_n64_rt_sigframe = {
878 SIGTRAMP_FRAME,
5792a79b 879 4,
fcbd8a5c
TS
880 {
881 { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
882 { MIPS_INST_SYSCALL, -1 },
883 { TRAMP_SENTINEL_INSN, -1 }
884 },
5792a79b
DJ
885 mips_linux_n32n64_sigframe_init
886};
887
888/* *INDENT-OFF* */
889/* The unwinder for o32 signal frames. The legacy structures look
890 like this:
891
892 struct sigframe {
893 u32 sf_ass[4]; [argument save space for o32]
eb195664 894 u32 sf_code[2]; [signal trampoline or fill]
5792a79b
DJ
895 struct sigcontext sf_sc;
896 sigset_t sf_mask;
897 };
898
d0e64392
MR
899 Pre-2.6.12 sigcontext:
900
5792a79b
DJ
901 struct sigcontext {
902 unsigned int sc_regmask; [Unused]
903 unsigned int sc_status;
904 unsigned long long sc_pc;
905 unsigned long long sc_regs[32];
906 unsigned long long sc_fpregs[32];
907 unsigned int sc_ownedfp;
908 unsigned int sc_fpc_csr;
909 unsigned int sc_fpc_eir; [Unused]
910 unsigned int sc_used_math;
911 unsigned int sc_ssflags; [Unused]
912 [Alignment hole of four bytes]
913 unsigned long long sc_mdhi;
914 unsigned long long sc_mdlo;
915
916 unsigned int sc_cause; [Unused]
917 unsigned int sc_badvaddr; [Unused]
918
919 unsigned long sc_sigset[4]; [kernel's sigset_t]
920 };
921
d0e64392
MR
922 Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
923
924 struct sigcontext {
925 unsigned int sc_regmask; [Unused]
926 unsigned int sc_status; [Unused]
927 unsigned long long sc_pc;
928 unsigned long long sc_regs[32];
929 unsigned long long sc_fpregs[32];
930 unsigned int sc_acx;
931 unsigned int sc_fpc_csr;
932 unsigned int sc_fpc_eir; [Unused]
933 unsigned int sc_used_math;
934 unsigned int sc_dsp;
935 [Alignment hole of four bytes]
936 unsigned long long sc_mdhi;
937 unsigned long long sc_mdlo;
938 unsigned long sc_hi1;
939 unsigned long sc_lo1;
940 unsigned long sc_hi2;
941 unsigned long sc_lo2;
942 unsigned long sc_hi3;
943 unsigned long sc_lo3;
944 };
945
5792a79b
DJ
946 The RT signal frames look like this:
947
948 struct rt_sigframe {
949 u32 rs_ass[4]; [argument save space for o32]
eb195664 950 u32 rs_code[2] [signal trampoline or fill]
5792a79b
DJ
951 struct siginfo rs_info;
952 struct ucontext rs_uc;
953 };
954
955 struct ucontext {
956 unsigned long uc_flags;
957 struct ucontext *uc_link;
958 stack_t uc_stack;
959 [Alignment hole of four bytes]
960 struct sigcontext uc_mcontext;
961 sigset_t uc_sigmask;
962 }; */
963/* *INDENT-ON* */
964
5792a79b
DJ
965#define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
966
967#define RTSIGFRAME_SIGINFO_SIZE 128
968#define STACK_T_SIZE (3 * 4)
969#define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
970#define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
971 + RTSIGFRAME_SIGINFO_SIZE \
972 + UCONTEXT_SIGCONTEXT_OFFSET)
973
974#define SIGCONTEXT_PC (1 * 8)
975#define SIGCONTEXT_REGS (2 * 8)
976#define SIGCONTEXT_FPREGS (34 * 8)
977#define SIGCONTEXT_FPCSR (66 * 8 + 4)
d0e64392 978#define SIGCONTEXT_DSPCTL (68 * 8 + 0)
5792a79b
DJ
979#define SIGCONTEXT_HI (69 * 8)
980#define SIGCONTEXT_LO (70 * 8)
981#define SIGCONTEXT_CAUSE (71 * 8 + 0)
982#define SIGCONTEXT_BADVADDR (71 * 8 + 4)
d0e64392
MR
983#define SIGCONTEXT_HI1 (71 * 8 + 0)
984#define SIGCONTEXT_LO1 (71 * 8 + 4)
985#define SIGCONTEXT_HI2 (72 * 8 + 0)
986#define SIGCONTEXT_LO2 (72 * 8 + 4)
987#define SIGCONTEXT_HI3 (73 * 8 + 0)
988#define SIGCONTEXT_LO3 (73 * 8 + 4)
5792a79b
DJ
989
990#define SIGCONTEXT_REG_SIZE 8
991
992static void
993mips_linux_o32_sigframe_init (const struct tramp_frame *self,
b8a22b94 994 struct frame_info *this_frame,
5792a79b
DJ
995 struct trad_frame_cache *this_cache,
996 CORE_ADDR func)
997{
b8a22b94 998 struct gdbarch *gdbarch = get_frame_arch (this_frame);
22e048c9 999 int ireg;
eb195664
DD
1000 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1001 CORE_ADDR sigcontext_base;
2eb4d78b 1002 const struct mips_regnum *regs = mips_regnum (gdbarch);
37c4d197 1003 CORE_ADDR regs_base;
5792a79b
DJ
1004
1005 if (self == &mips_linux_o32_sigframe)
eb195664 1006 sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
5792a79b 1007 else
eb195664 1008 sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
295093a4
MS
1009
1010 /* I'm not proud of this hack. Eventually we will have the
1011 infrastructure to indicate the size of saved registers on a
1012 per-frame basis, but right now we don't; the kernel saves eight
37c4d197
DJ
1013 bytes but we only want four. Use regs_base to access any
1014 64-bit fields. */
2eb4d78b 1015 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
37c4d197
DJ
1016 regs_base = sigcontext_base + 4;
1017 else
1018 regs_base = sigcontext_base;
5792a79b 1019
2eb4d78b 1020 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
1021 trad_frame_set_reg_addr (this_cache,
1022 (MIPS_RESTART_REGNUM
2eb4d78b 1023 + gdbarch_num_regs (gdbarch)),
822b6570 1024 regs_base + SIGCONTEXT_REGS);
5792a79b
DJ
1025
1026 for (ireg = 1; ireg < 32; ireg++)
295093a4 1027 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1028 (ireg + MIPS_ZERO_REGNUM
1029 + gdbarch_num_regs (gdbarch)),
1030 (regs_base + SIGCONTEXT_REGS
1031 + ireg * SIGCONTEXT_REG_SIZE));
5792a79b 1032
37c4d197
DJ
1033 /* The way that floating point registers are saved, unfortunately,
1034 depends on the architecture the kernel is built for. For the r3000 and
1035 tx39, four bytes of each register are at the beginning of each of the
1036 32 eight byte slots. For everything else, the registers are saved
1037 using double precision; only the even-numbered slots are initialized,
1038 and the high bits are the odd-numbered register. Assume the latter
1039 layout, since we can't tell, and it's much more common. Which bits are
1040 the "high" bits depends on endianness. */
5792a79b 1041 for (ireg = 0; ireg < 32; ireg++)
2eb4d78b 1042 if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
f57d151a 1043 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1044 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1045 (sigcontext_base + SIGCONTEXT_FPREGS + 4
1046 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
37c4d197 1047 else
f57d151a 1048 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1049 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1050 (sigcontext_base + SIGCONTEXT_FPREGS
1051 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
5792a79b 1052
f57d151a 1053 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1054 regs->pc + gdbarch_num_regs (gdbarch),
37c4d197 1055 regs_base + SIGCONTEXT_PC);
5792a79b 1056
295093a4 1057 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1058 (regs->fp_control_status
1059 + gdbarch_num_regs (gdbarch)),
5792a79b 1060 sigcontext_base + SIGCONTEXT_FPCSR);
d0e64392
MR
1061
1062 if (regs->dspctl != -1)
1063 trad_frame_set_reg_addr (this_cache,
1064 regs->dspctl + gdbarch_num_regs (gdbarch),
1065 sigcontext_base + SIGCONTEXT_DSPCTL);
1066
f57d151a 1067 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1068 regs->hi + gdbarch_num_regs (gdbarch),
37c4d197 1069 regs_base + SIGCONTEXT_HI);
f57d151a 1070 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1071 regs->lo + gdbarch_num_regs (gdbarch),
37c4d197 1072 regs_base + SIGCONTEXT_LO);
d0e64392
MR
1073
1074 if (regs->dspacc != -1)
1075 {
1076 trad_frame_set_reg_addr (this_cache,
1077 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1078 sigcontext_base + SIGCONTEXT_HI1);
1079 trad_frame_set_reg_addr (this_cache,
1080 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1081 sigcontext_base + SIGCONTEXT_LO1);
1082 trad_frame_set_reg_addr (this_cache,
1083 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1084 sigcontext_base + SIGCONTEXT_HI2);
1085 trad_frame_set_reg_addr (this_cache,
1086 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1087 sigcontext_base + SIGCONTEXT_LO2);
1088 trad_frame_set_reg_addr (this_cache,
1089 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1090 sigcontext_base + SIGCONTEXT_HI3);
1091 trad_frame_set_reg_addr (this_cache,
1092 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1093 sigcontext_base + SIGCONTEXT_LO3);
1094 }
1095 else
1096 {
1097 trad_frame_set_reg_addr (this_cache,
1098 regs->cause + gdbarch_num_regs (gdbarch),
1099 sigcontext_base + SIGCONTEXT_CAUSE);
1100 trad_frame_set_reg_addr (this_cache,
1101 regs->badvaddr + gdbarch_num_regs (gdbarch),
1102 sigcontext_base + SIGCONTEXT_BADVADDR);
1103 }
5792a79b
DJ
1104
1105 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
eb195664 1106 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
5792a79b
DJ
1107}
1108
1109/* *INDENT-OFF* */
1110/* For N32/N64 things look different. There is no non-rt signal frame.
1111
1112 struct rt_sigframe_n32 {
1113 u32 rs_ass[4]; [ argument save space for o32 ]
eb195664 1114 u32 rs_code[2]; [ signal trampoline or fill ]
5792a79b
DJ
1115 struct siginfo rs_info;
1116 struct ucontextn32 rs_uc;
1117 };
1118
1119 struct ucontextn32 {
1120 u32 uc_flags;
1121 s32 uc_link;
1122 stack32_t uc_stack;
1123 struct sigcontext uc_mcontext;
1124 sigset_t uc_sigmask; [ mask last for extensibility ]
1125 };
295093a4 1126
e741f4d4 1127 struct rt_sigframe {
5792a79b
DJ
1128 u32 rs_ass[4]; [ argument save space for o32 ]
1129 u32 rs_code[2]; [ signal trampoline ]
1130 struct siginfo rs_info;
1131 struct ucontext rs_uc;
1132 };
1133
1134 struct ucontext {
1135 unsigned long uc_flags;
1136 struct ucontext *uc_link;
1137 stack_t uc_stack;
1138 struct sigcontext uc_mcontext;
1139 sigset_t uc_sigmask; [ mask last for extensibility ]
1140 };
1141
1142 And the sigcontext is different (this is for both n32 and n64):
1143
1144 struct sigcontext {
1145 unsigned long long sc_regs[32];
1146 unsigned long long sc_fpregs[32];
1147 unsigned long long sc_mdhi;
e741f4d4
DJ
1148 unsigned long long sc_hi1;
1149 unsigned long long sc_hi2;
1150 unsigned long long sc_hi3;
5792a79b 1151 unsigned long long sc_mdlo;
e741f4d4
DJ
1152 unsigned long long sc_lo1;
1153 unsigned long long sc_lo2;
1154 unsigned long long sc_lo3;
5792a79b 1155 unsigned long long sc_pc;
5792a79b 1156 unsigned int sc_fpc_csr;
5792a79b 1157 unsigned int sc_used_math;
e741f4d4
DJ
1158 unsigned int sc_dsp;
1159 unsigned int sc_reserved;
1160 };
1161
1162 That is the post-2.6.12 definition of the 64-bit sigcontext; before
1163 then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
1164 included too. */
5792a79b
DJ
1165/* *INDENT-ON* */
1166
1167#define N32_STACK_T_SIZE STACK_T_SIZE
1168#define N64_STACK_T_SIZE (2 * 8 + 4)
1169#define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
1170#define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
1171#define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1172 + RTSIGFRAME_SIGINFO_SIZE \
1173 + N32_UCONTEXT_SIGCONTEXT_OFFSET)
1174#define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
1175 + RTSIGFRAME_SIGINFO_SIZE \
1176 + N64_UCONTEXT_SIGCONTEXT_OFFSET)
1177
1178#define N64_SIGCONTEXT_REGS (0 * 8)
1179#define N64_SIGCONTEXT_FPREGS (32 * 8)
1180#define N64_SIGCONTEXT_HI (64 * 8)
d0e64392
MR
1181#define N64_SIGCONTEXT_HI1 (65 * 8)
1182#define N64_SIGCONTEXT_HI2 (66 * 8)
1183#define N64_SIGCONTEXT_HI3 (67 * 8)
e741f4d4 1184#define N64_SIGCONTEXT_LO (68 * 8)
d0e64392
MR
1185#define N64_SIGCONTEXT_LO1 (69 * 8)
1186#define N64_SIGCONTEXT_LO2 (70 * 8)
1187#define N64_SIGCONTEXT_LO3 (71 * 8)
e741f4d4 1188#define N64_SIGCONTEXT_PC (72 * 8)
d0e64392
MR
1189#define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
1190#define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
5792a79b
DJ
1191
1192#define N64_SIGCONTEXT_REG_SIZE 8
295093a4 1193
5792a79b
DJ
1194static void
1195mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
b8a22b94 1196 struct frame_info *this_frame,
5792a79b
DJ
1197 struct trad_frame_cache *this_cache,
1198 CORE_ADDR func)
1199{
b8a22b94 1200 struct gdbarch *gdbarch = get_frame_arch (this_frame);
22e048c9 1201 int ireg;
eb195664
DD
1202 CORE_ADDR frame_sp = get_frame_sp (this_frame);
1203 CORE_ADDR sigcontext_base;
2eb4d78b 1204 const struct mips_regnum *regs = mips_regnum (gdbarch);
5792a79b
DJ
1205
1206 if (self == &mips_linux_n32_rt_sigframe)
eb195664 1207 sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
5792a79b 1208 else
eb195664 1209 sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
295093a4 1210
2eb4d78b 1211 if (mips_linux_restart_reg_p (gdbarch))
822b6570
DJ
1212 trad_frame_set_reg_addr (this_cache,
1213 (MIPS_RESTART_REGNUM
2eb4d78b 1214 + gdbarch_num_regs (gdbarch)),
822b6570 1215 sigcontext_base + N64_SIGCONTEXT_REGS);
5792a79b
DJ
1216
1217 for (ireg = 1; ireg < 32; ireg++)
295093a4 1218 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1219 (ireg + MIPS_ZERO_REGNUM
1220 + gdbarch_num_regs (gdbarch)),
1221 (sigcontext_base + N64_SIGCONTEXT_REGS
1222 + ireg * N64_SIGCONTEXT_REG_SIZE));
5792a79b
DJ
1223
1224 for (ireg = 0; ireg < 32; ireg++)
f57d151a 1225 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1226 ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
1227 (sigcontext_base + N64_SIGCONTEXT_FPREGS
1228 + ireg * N64_SIGCONTEXT_REG_SIZE));
5792a79b 1229
f57d151a 1230 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1231 regs->pc + gdbarch_num_regs (gdbarch),
5792a79b
DJ
1232 sigcontext_base + N64_SIGCONTEXT_PC);
1233
295093a4 1234 trad_frame_set_reg_addr (this_cache,
7d266584
MR
1235 (regs->fp_control_status
1236 + gdbarch_num_regs (gdbarch)),
5792a79b 1237 sigcontext_base + N64_SIGCONTEXT_FPCSR);
d0e64392 1238
f57d151a 1239 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1240 regs->hi + gdbarch_num_regs (gdbarch),
5792a79b 1241 sigcontext_base + N64_SIGCONTEXT_HI);
f57d151a 1242 trad_frame_set_reg_addr (this_cache,
2eb4d78b 1243 regs->lo + gdbarch_num_regs (gdbarch),
5792a79b 1244 sigcontext_base + N64_SIGCONTEXT_LO);
5792a79b 1245
d0e64392
MR
1246 if (regs->dspacc != -1)
1247 {
1248 trad_frame_set_reg_addr (this_cache,
1249 regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
1250 sigcontext_base + N64_SIGCONTEXT_HI1);
1251 trad_frame_set_reg_addr (this_cache,
1252 regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
1253 sigcontext_base + N64_SIGCONTEXT_LO1);
1254 trad_frame_set_reg_addr (this_cache,
1255 regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
1256 sigcontext_base + N64_SIGCONTEXT_HI2);
1257 trad_frame_set_reg_addr (this_cache,
1258 regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
1259 sigcontext_base + N64_SIGCONTEXT_LO2);
1260 trad_frame_set_reg_addr (this_cache,
1261 regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
1262 sigcontext_base + N64_SIGCONTEXT_HI3);
1263 trad_frame_set_reg_addr (this_cache,
1264 regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
1265 sigcontext_base + N64_SIGCONTEXT_LO3);
1266 }
1267 if (regs->dspctl != -1)
1268 trad_frame_set_reg_addr (this_cache,
1269 regs->dspctl + gdbarch_num_regs (gdbarch),
1270 sigcontext_base + N64_SIGCONTEXT_DSPCTL);
1271
5792a79b 1272 /* Choice of the bottom of the sigframe is somewhat arbitrary. */
eb195664 1273 trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
5792a79b
DJ
1274}
1275
5a439849
MR
1276/* Implement the "write_pc" gdbarch method. */
1277
822b6570 1278static void
61a1198a 1279mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
822b6570 1280{
2eb4d78b 1281 struct gdbarch *gdbarch = get_regcache_arch (regcache);
5a439849
MR
1282
1283 mips_write_pc (regcache, pc);
822b6570
DJ
1284
1285 /* Clear the syscall restart flag. */
2eb4d78b 1286 if (mips_linux_restart_reg_p (gdbarch))
61a1198a 1287 regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
822b6570
DJ
1288}
1289
1290/* Return 1 if MIPS_RESTART_REGNUM is usable. */
1291
1292int
1293mips_linux_restart_reg_p (struct gdbarch *gdbarch)
1294{
1295 /* If we do not have a target description with registers, then
1296 MIPS_RESTART_REGNUM will not be included in the register set. */
1297 if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
1298 return 0;
1299
1300 /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
1301 either be GPR-sized or missing. */
1302 return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
1303}
9f62d0e2 1304
e38d4e1a
DJ
1305/* When FRAME is at a syscall instruction, return the PC of the next
1306 instruction to be executed. */
1307
63807e1d 1308static CORE_ADDR
e38d4e1a
DJ
1309mips_linux_syscall_next_pc (struct frame_info *frame)
1310{
1311 CORE_ADDR pc = get_frame_pc (frame);
1312 ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
1313
1314 /* If we are about to make a sigreturn syscall, use the unwinder to
1315 decode the signal frame. */
1316 if (v0 == MIPS_NR_sigreturn
1317 || v0 == MIPS_NR_rt_sigreturn
1318 || v0 == MIPS_NR_N64_rt_sigreturn
1319 || v0 == MIPS_NR_N32_rt_sigreturn)
c7ce8faa 1320 return frame_unwind_caller_pc (get_current_frame ());
e38d4e1a
DJ
1321
1322 return pc + 4;
1323}
1324
385203ed
DD
1325/* Return the current system call's number present in the
1326 v0 register. When the function fails, it returns -1. */
1327
1328static LONGEST
1329mips_linux_get_syscall_number (struct gdbarch *gdbarch,
1330 ptid_t ptid)
1331{
1332 struct regcache *regcache = get_thread_regcache (ptid);
1333 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1334 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1335 int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
1336 /* The content of a register */
1337 gdb_byte buf[8];
1338 /* The result */
1339 LONGEST ret;
1340
1341 /* Make sure we're in a known ABI */
1342 gdb_assert (tdep->mips_abi == MIPS_ABI_O32
1343 || tdep->mips_abi == MIPS_ABI_N32
1344 || tdep->mips_abi == MIPS_ABI_N64);
1345
1346 gdb_assert (regsize <= sizeof (buf));
1347
1348 /* Getting the system call number from the register.
1349 syscall number is in v0 or $2. */
1350 regcache_cooked_read (regcache, MIPS_V0_REGNUM, buf);
1351
1352 ret = extract_signed_integer (buf, regsize, byte_order);
1353
1354 return ret;
1355}
1356
eb14d406
SDJ
1357/* Implementation of `gdbarch_gdb_signal_to_target', as defined in
1358 gdbarch.h. */
1359
1360static int
1361mips_gdb_signal_to_target (struct gdbarch *gdbarch,
1362 enum gdb_signal signal)
1363{
1364 switch (signal)
1365 {
1366 case GDB_SIGNAL_EMT:
1367 return MIPS_LINUX_SIGEMT;
1368
1369 case GDB_SIGNAL_BUS:
1370 return MIPS_LINUX_SIGBUS;
1371
1372 case GDB_SIGNAL_SYS:
1373 return MIPS_LINUX_SIGSYS;
1374
1375 case GDB_SIGNAL_USR1:
1376 return MIPS_LINUX_SIGUSR1;
1377
1378 case GDB_SIGNAL_USR2:
1379 return MIPS_LINUX_SIGUSR2;
1380
1381 case GDB_SIGNAL_CHLD:
1382 return MIPS_LINUX_SIGCHLD;
1383
1384 case GDB_SIGNAL_PWR:
1385 return MIPS_LINUX_SIGPWR;
1386
1387 case GDB_SIGNAL_WINCH:
1388 return MIPS_LINUX_SIGWINCH;
1389
1390 case GDB_SIGNAL_URG:
1391 return MIPS_LINUX_SIGURG;
1392
1393 case GDB_SIGNAL_IO:
1394 return MIPS_LINUX_SIGIO;
1395
1396 case GDB_SIGNAL_POLL:
1397 return MIPS_LINUX_SIGPOLL;
1398
1399 case GDB_SIGNAL_STOP:
1400 return MIPS_LINUX_SIGSTOP;
1401
1402 case GDB_SIGNAL_TSTP:
1403 return MIPS_LINUX_SIGTSTP;
1404
1405 case GDB_SIGNAL_CONT:
1406 return MIPS_LINUX_SIGCONT;
1407
1408 case GDB_SIGNAL_TTIN:
1409 return MIPS_LINUX_SIGTTIN;
1410
1411 case GDB_SIGNAL_TTOU:
1412 return MIPS_LINUX_SIGTTOU;
1413
1414 case GDB_SIGNAL_VTALRM:
1415 return MIPS_LINUX_SIGVTALRM;
1416
1417 case GDB_SIGNAL_PROF:
1418 return MIPS_LINUX_SIGPROF;
1419
1420 case GDB_SIGNAL_XCPU:
1421 return MIPS_LINUX_SIGXCPU;
1422
1423 case GDB_SIGNAL_XFSZ:
1424 return MIPS_LINUX_SIGXFSZ;
1425
1426 /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
1427 therefore we have to handle it here. */
1428 case GDB_SIGNAL_REALTIME_32:
1429 return MIPS_LINUX_SIGRTMIN;
1430 }
1431
1432 if (signal >= GDB_SIGNAL_REALTIME_33
1433 && signal <= GDB_SIGNAL_REALTIME_63)
1434 {
1435 int offset = signal - GDB_SIGNAL_REALTIME_33;
1436
1437 return MIPS_LINUX_SIGRTMIN + 1 + offset;
1438 }
1439 else if (signal >= GDB_SIGNAL_REALTIME_64
1440 && signal <= GDB_SIGNAL_REALTIME_127)
1441 {
1442 int offset = signal - GDB_SIGNAL_REALTIME_64;
1443
1444 return MIPS_LINUX_SIGRT64 + offset;
1445 }
1446
1447 return linux_gdb_signal_to_target (gdbarch, signal);
1448}
1449
7d266584 1450/* Translate signals based on MIPS signal values.
232b8704
ME
1451 Adapted from gdb/common/signals.c. */
1452
1453static enum gdb_signal
eb14d406 1454mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
232b8704 1455{
eb14d406 1456 switch (signal)
232b8704 1457 {
eb14d406 1458 case MIPS_LINUX_SIGEMT:
232b8704 1459 return GDB_SIGNAL_EMT;
eb14d406
SDJ
1460
1461 case MIPS_LINUX_SIGBUS:
232b8704 1462 return GDB_SIGNAL_BUS;
eb14d406
SDJ
1463
1464 case MIPS_LINUX_SIGSYS:
232b8704 1465 return GDB_SIGNAL_SYS;
eb14d406
SDJ
1466
1467 case MIPS_LINUX_SIGUSR1:
232b8704 1468 return GDB_SIGNAL_USR1;
eb14d406
SDJ
1469
1470 case MIPS_LINUX_SIGUSR2:
232b8704 1471 return GDB_SIGNAL_USR2;
eb14d406
SDJ
1472
1473 case MIPS_LINUX_SIGCHLD:
232b8704 1474 return GDB_SIGNAL_CHLD;
eb14d406
SDJ
1475
1476 case MIPS_LINUX_SIGPWR:
232b8704 1477 return GDB_SIGNAL_PWR;
eb14d406
SDJ
1478
1479 case MIPS_LINUX_SIGWINCH:
232b8704 1480 return GDB_SIGNAL_WINCH;
eb14d406
SDJ
1481
1482 case MIPS_LINUX_SIGURG:
232b8704 1483 return GDB_SIGNAL_URG;
eb14d406
SDJ
1484
1485 /* No way to differentiate between SIGIO and SIGPOLL.
1486 Therefore, we just handle the first one. */
1487 case MIPS_LINUX_SIGIO:
1488 return GDB_SIGNAL_IO;
1489
1490 case MIPS_LINUX_SIGSTOP:
232b8704 1491 return GDB_SIGNAL_STOP;
eb14d406
SDJ
1492
1493 case MIPS_LINUX_SIGTSTP:
232b8704 1494 return GDB_SIGNAL_TSTP;
eb14d406
SDJ
1495
1496 case MIPS_LINUX_SIGCONT:
232b8704 1497 return GDB_SIGNAL_CONT;
eb14d406
SDJ
1498
1499 case MIPS_LINUX_SIGTTIN:
232b8704 1500 return GDB_SIGNAL_TTIN;
eb14d406
SDJ
1501
1502 case MIPS_LINUX_SIGTTOU:
232b8704 1503 return GDB_SIGNAL_TTOU;
eb14d406
SDJ
1504
1505 case MIPS_LINUX_SIGVTALRM:
232b8704 1506 return GDB_SIGNAL_VTALRM;
eb14d406
SDJ
1507
1508 case MIPS_LINUX_SIGPROF:
232b8704 1509 return GDB_SIGNAL_PROF;
eb14d406
SDJ
1510
1511 case MIPS_LINUX_SIGXCPU:
232b8704 1512 return GDB_SIGNAL_XCPU;
eb14d406
SDJ
1513
1514 case MIPS_LINUX_SIGXFSZ:
232b8704 1515 return GDB_SIGNAL_XFSZ;
eb14d406 1516 }
232b8704 1517
eb14d406 1518 if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
232b8704
ME
1519 {
1520 /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
1521 the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
eb14d406
SDJ
1522 int offset = signal - MIPS_LINUX_SIGRTMIN;
1523
1524 if (offset == 0)
232b8704 1525 return GDB_SIGNAL_REALTIME_32;
eb14d406
SDJ
1526 else if (offset < 32)
1527 return (enum gdb_signal) (offset - 1
1528 + (int) GDB_SIGNAL_REALTIME_33);
232b8704 1529 else
eb14d406
SDJ
1530 return (enum gdb_signal) (offset - 32
1531 + (int) GDB_SIGNAL_REALTIME_64);
232b8704
ME
1532 }
1533
eb14d406 1534 return linux_gdb_signal_from_target (gdbarch, signal);
232b8704
ME
1535}
1536
5792a79b
DJ
1537/* Initialize one of the GNU/Linux OS ABIs. */
1538
19ed69dd 1539static void
295093a4
MS
1540mips_linux_init_abi (struct gdbarch_info info,
1541 struct gdbarch *gdbarch)
19ed69dd 1542{
96f026fc
KB
1543 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1544 enum mips_abi abi = mips_abi (gdbarch);
822b6570 1545 struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
96f026fc 1546
a5ee0f0c
PA
1547 linux_init_abi (info, gdbarch);
1548
385203ed
DD
1549 /* Get the syscall number from the arch's register. */
1550 set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);
1551
96f026fc
KB
1552 switch (abi)
1553 {
1554 case MIPS_ABI_O32:
1555 set_gdbarch_get_longjmp_target (gdbarch,
7d266584 1556 mips_linux_get_longjmp_target);
96f026fc 1557 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1558 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
fb2be677
AC
1559 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
1560 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
385203ed 1561 set_xml_syscall_file_name ("syscalls/mips-o32-linux.xml");
96f026fc
KB
1562 break;
1563 case MIPS_ABI_N32:
1564 set_gdbarch_get_longjmp_target (gdbarch,
7d266584 1565 mips_linux_get_longjmp_target);
96f026fc 1566 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1567 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
d05f6826
DJ
1568 set_gdbarch_long_double_bit (gdbarch, 128);
1569 /* These floatformats should probably be renamed. MIPS uses
1570 the same 128-bit IEEE floating point format that IA-64 uses,
1571 except that the quiet/signalling NaN bit is reversed (GDB
1572 does not distinguish between quiet and signalling NaNs). */
8da61cc4 1573 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
fb2be677 1574 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
385203ed 1575 set_xml_syscall_file_name ("syscalls/mips-n32-linux.xml");
96f026fc
KB
1576 break;
1577 case MIPS_ABI_N64:
1578 set_gdbarch_get_longjmp_target (gdbarch,
7d266584 1579 mips64_linux_get_longjmp_target);
96f026fc 1580 set_solib_svr4_fetch_link_map_offsets
76a9d10f 1581 (gdbarch, svr4_lp64_fetch_link_map_offsets);
d05f6826
DJ
1582 set_gdbarch_long_double_bit (gdbarch, 128);
1583 /* These floatformats should probably be renamed. MIPS uses
1584 the same 128-bit IEEE floating point format that IA-64 uses,
1585 except that the quiet/signalling NaN bit is reversed (GDB
1586 does not distinguish between quiet and signalling NaNs). */
8da61cc4 1587 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
fb2be677 1588 tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
385203ed 1589 set_xml_syscall_file_name ("syscalls/mips-n64-linux.xml");
96f026fc
KB
1590 break;
1591 default:
96f026fc
KB
1592 break;
1593 }
6de918a6
DJ
1594
1595 set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
1596
0d0266c6 1597 set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
b2756930
KB
1598
1599 /* Enable TLS support. */
1600 set_gdbarch_fetch_tls_load_module_address (gdbarch,
7d266584 1601 svr4_fetch_objfile_link_map);
7d522c90
DJ
1602
1603 /* Initialize this lazily, to avoid an initialization order
1604 dependency on solib-svr4.c's _initialize routine. */
1605 if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
1606 {
1607 mips_svr4_so_ops = svr4_so_ops;
1608 mips_svr4_so_ops.in_dynsym_resolve_code
1609 = mips_linux_in_dynsym_resolve_code;
1610 }
1611 set_solib_ops (gdbarch, &mips_svr4_so_ops);
822b6570
DJ
1612
1613 set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
1614
4eb0ad19
DJ
1615 set_gdbarch_core_read_description (gdbarch,
1616 mips_linux_core_read_description);
1617
d4036235
AA
1618 set_gdbarch_iterate_over_regset_sections
1619 (gdbarch, mips_linux_iterate_over_regset_sections);
50e8a0d5 1620
232b8704
ME
1621 set_gdbarch_gdb_signal_from_target (gdbarch,
1622 mips_gdb_signal_from_target);
1623
eb14d406
SDJ
1624 set_gdbarch_gdb_signal_to_target (gdbarch,
1625 mips_gdb_signal_to_target);
1626
e38d4e1a
DJ
1627 tdep->syscall_next_pc = mips_linux_syscall_next_pc;
1628
822b6570
DJ
1629 if (tdesc_data)
1630 {
1631 const struct tdesc_feature *feature;
1632
1633 /* If we have target-described registers, then we can safely
1634 reserve a number for MIPS_RESTART_REGNUM (whether it is
1635 described or not). */
1636 gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
1637 set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
cf233303 1638 set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
822b6570
DJ
1639
1640 /* If it's present, then assign it to the reserved number. */
1641 feature = tdesc_find_feature (info.target_desc,
1642 "org.gnu.gdb.mips.linux");
1643 if (feature != NULL)
1644 tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
1645 "restart");
1646 }
19ed69dd
KB
1647}
1648
63807e1d
PA
1649/* Provide a prototype to silence -Wmissing-prototypes. */
1650extern initialize_file_ftype _initialize_mips_linux_tdep;
1651
2aa830e4 1652void
d1bacddc 1653_initialize_mips_linux_tdep (void)
2aa830e4 1654{
96f026fc
KB
1655 const struct bfd_arch_info *arch_info;
1656
96f026fc
KB
1657 for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
1658 arch_info != NULL;
1659 arch_info = arch_info->next)
1660 {
295093a4
MS
1661 gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
1662 GDB_OSABI_LINUX,
96f026fc
KB
1663 mips_linux_init_abi);
1664 }
2aa830e4 1665}
This page took 1.234596 seconds and 4 git commands to generate.