* mips-tdep.c (mips_pc_is_mips16): Reverse the order of checks
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
2
3 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 2010, 2011 Free Software Foundation, Inc.
6
7 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
8 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
9
10 This file is part of GDB.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24
25 #include "defs.h"
26 #include "gdb_string.h"
27 #include "gdb_assert.h"
28 #include "frame.h"
29 #include "inferior.h"
30 #include "symtab.h"
31 #include "value.h"
32 #include "gdbcmd.h"
33 #include "language.h"
34 #include "gdbcore.h"
35 #include "symfile.h"
36 #include "objfiles.h"
37 #include "gdbtypes.h"
38 #include "target.h"
39 #include "arch-utils.h"
40 #include "regcache.h"
41 #include "osabi.h"
42 #include "mips-tdep.h"
43 #include "block.h"
44 #include "reggroups.h"
45 #include "opcode/mips.h"
46 #include "elf/mips.h"
47 #include "elf-bfd.h"
48 #include "symcat.h"
49 #include "sim-regno.h"
50 #include "dis-asm.h"
51 #include "frame-unwind.h"
52 #include "frame-base.h"
53 #include "trad-frame.h"
54 #include "infcall.h"
55 #include "floatformat.h"
56 #include "remote.h"
57 #include "target-descriptions.h"
58 #include "dwarf2-frame.h"
59 #include "user-regs.h"
60 #include "valprint.h"
61 #include "ax.h"
62
63 static const struct objfile_data *mips_pdr_data;
64
65 static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum);
66
67 /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
68 /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
69 #define ST0_FR (1 << 26)
70
71 /* The sizes of floating point registers. */
72
73 enum
74 {
75 MIPS_FPU_SINGLE_REGSIZE = 4,
76 MIPS_FPU_DOUBLE_REGSIZE = 8
77 };
78
79 enum
80 {
81 MIPS32_REGSIZE = 4,
82 MIPS64_REGSIZE = 8
83 };
84
85 static const char *mips_abi_string;
86
87 static const char *mips_abi_strings[] = {
88 "auto",
89 "n32",
90 "o32",
91 "n64",
92 "o64",
93 "eabi32",
94 "eabi64",
95 NULL
96 };
97
98 /* The standard register names, and all the valid aliases for them. */
99 struct register_alias
100 {
101 const char *name;
102 int regnum;
103 };
104
105 /* Aliases for o32 and most other ABIs. */
106 const struct register_alias mips_o32_aliases[] = {
107 { "ta0", 12 },
108 { "ta1", 13 },
109 { "ta2", 14 },
110 { "ta3", 15 }
111 };
112
113 /* Aliases for n32 and n64. */
114 const struct register_alias mips_n32_n64_aliases[] = {
115 { "ta0", 8 },
116 { "ta1", 9 },
117 { "ta2", 10 },
118 { "ta3", 11 }
119 };
120
121 /* Aliases for ABI-independent registers. */
122 const struct register_alias mips_register_aliases[] = {
123 /* The architecture manuals specify these ABI-independent names for
124 the GPRs. */
125 #define R(n) { "r" #n, n }
126 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
127 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
128 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
129 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
130 #undef R
131
132 /* k0 and k1 are sometimes called these instead (for "kernel
133 temp"). */
134 { "kt0", 26 },
135 { "kt1", 27 },
136
137 /* This is the traditional GDB name for the CP0 status register. */
138 { "sr", MIPS_PS_REGNUM },
139
140 /* This is the traditional GDB name for the CP0 BadVAddr register. */
141 { "bad", MIPS_EMBED_BADVADDR_REGNUM },
142
143 /* This is the traditional GDB name for the FCSR. */
144 { "fsr", MIPS_EMBED_FP0_REGNUM + 32 }
145 };
146
147 const struct register_alias mips_numeric_register_aliases[] = {
148 #define R(n) { #n, n }
149 R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
150 R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
151 R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
152 R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
153 #undef R
154 };
155
156 #ifndef MIPS_DEFAULT_FPU_TYPE
157 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
158 #endif
159 static int mips_fpu_type_auto = 1;
160 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
161
162 static int mips_debug = 0;
163
164 /* Properties (for struct target_desc) describing the g/G packet
165 layout. */
166 #define PROPERTY_GP32 "internal: transfers-32bit-registers"
167 #define PROPERTY_GP64 "internal: transfers-64bit-registers"
168
169 struct target_desc *mips_tdesc_gp32;
170 struct target_desc *mips_tdesc_gp64;
171
172 const struct mips_regnum *
173 mips_regnum (struct gdbarch *gdbarch)
174 {
175 return gdbarch_tdep (gdbarch)->regnum;
176 }
177
178 static int
179 mips_fpa0_regnum (struct gdbarch *gdbarch)
180 {
181 return mips_regnum (gdbarch)->fp0 + 12;
182 }
183
184 #define MIPS_EABI(gdbarch) (gdbarch_tdep (gdbarch)->mips_abi \
185 == MIPS_ABI_EABI32 \
186 || gdbarch_tdep (gdbarch)->mips_abi == MIPS_ABI_EABI64)
187
188 #define MIPS_LAST_FP_ARG_REGNUM(gdbarch) \
189 (gdbarch_tdep (gdbarch)->mips_last_fp_arg_regnum)
190
191 #define MIPS_LAST_ARG_REGNUM(gdbarch) \
192 (gdbarch_tdep (gdbarch)->mips_last_arg_regnum)
193
194 #define MIPS_FPU_TYPE(gdbarch) (gdbarch_tdep (gdbarch)->mips_fpu_type)
195
196 /* MIPS16 function addresses are odd (bit 0 is set). Here are some
197 functions to test, set, or clear bit 0 of addresses. */
198
199 static CORE_ADDR
200 is_mips16_addr (CORE_ADDR addr)
201 {
202 return ((addr) & 1);
203 }
204
205 static CORE_ADDR
206 unmake_mips16_addr (CORE_ADDR addr)
207 {
208 return ((addr) & ~(CORE_ADDR) 1);
209 }
210
211 static CORE_ADDR
212 make_mips16_addr (CORE_ADDR addr)
213 {
214 return ((addr) | (CORE_ADDR) 1);
215 }
216
217 /* Return the MIPS ABI associated with GDBARCH. */
218 enum mips_abi
219 mips_abi (struct gdbarch *gdbarch)
220 {
221 return gdbarch_tdep (gdbarch)->mips_abi;
222 }
223
224 int
225 mips_isa_regsize (struct gdbarch *gdbarch)
226 {
227 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
228
229 /* If we know how big the registers are, use that size. */
230 if (tdep->register_size_valid_p)
231 return tdep->register_size;
232
233 /* Fall back to the previous behavior. */
234 return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word
235 / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte);
236 }
237
238 /* Return the currently configured (or set) saved register size. */
239
240 unsigned int
241 mips_abi_regsize (struct gdbarch *gdbarch)
242 {
243 switch (mips_abi (gdbarch))
244 {
245 case MIPS_ABI_EABI32:
246 case MIPS_ABI_O32:
247 return 4;
248 case MIPS_ABI_N32:
249 case MIPS_ABI_N64:
250 case MIPS_ABI_O64:
251 case MIPS_ABI_EABI64:
252 return 8;
253 case MIPS_ABI_UNKNOWN:
254 case MIPS_ABI_LAST:
255 default:
256 internal_error (__FILE__, __LINE__, _("bad switch"));
257 }
258 }
259
260 /* Functions for setting and testing a bit in a minimal symbol that
261 marks it as 16-bit function. The MSB of the minimal symbol's
262 "info" field is used for this purpose.
263
264 gdbarch_elf_make_msymbol_special tests whether an ELF symbol is "special",
265 i.e. refers to a 16-bit function, and sets a "special" bit in a
266 minimal symbol to mark it as a 16-bit function
267
268 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */
269
270 static void
271 mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
272 {
273 if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16)
274 {
275 MSYMBOL_TARGET_FLAG_1 (msym) = 1;
276 }
277 }
278
279 static int
280 msymbol_is_special (struct minimal_symbol *msym)
281 {
282 return MSYMBOL_TARGET_FLAG_1 (msym);
283 }
284
285 /* XFER a value from the big/little/left end of the register.
286 Depending on the size of the value it might occupy the entire
287 register or just part of it. Make an allowance for this, aligning
288 things accordingly. */
289
290 static void
291 mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache,
292 int reg_num, int length,
293 enum bfd_endian endian, gdb_byte *in,
294 const gdb_byte *out, int buf_offset)
295 {
296 int reg_offset = 0;
297
298 gdb_assert (reg_num >= gdbarch_num_regs (gdbarch));
299 /* Need to transfer the left or right part of the register, based on
300 the targets byte order. */
301 switch (endian)
302 {
303 case BFD_ENDIAN_BIG:
304 reg_offset = register_size (gdbarch, reg_num) - length;
305 break;
306 case BFD_ENDIAN_LITTLE:
307 reg_offset = 0;
308 break;
309 case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
310 reg_offset = 0;
311 break;
312 default:
313 internal_error (__FILE__, __LINE__, _("bad switch"));
314 }
315 if (mips_debug)
316 fprintf_unfiltered (gdb_stderr,
317 "xfer $%d, reg offset %d, buf offset %d, length %d, ",
318 reg_num, reg_offset, buf_offset, length);
319 if (mips_debug && out != NULL)
320 {
321 int i;
322 fprintf_unfiltered (gdb_stdlog, "out ");
323 for (i = 0; i < length; i++)
324 fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]);
325 }
326 if (in != NULL)
327 regcache_cooked_read_part (regcache, reg_num, reg_offset, length,
328 in + buf_offset);
329 if (out != NULL)
330 regcache_cooked_write_part (regcache, reg_num, reg_offset, length,
331 out + buf_offset);
332 if (mips_debug && in != NULL)
333 {
334 int i;
335 fprintf_unfiltered (gdb_stdlog, "in ");
336 for (i = 0; i < length; i++)
337 fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]);
338 }
339 if (mips_debug)
340 fprintf_unfiltered (gdb_stdlog, "\n");
341 }
342
343 /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
344 compatiblity mode. A return value of 1 means that we have
345 physical 64-bit registers, but should treat them as 32-bit registers. */
346
347 static int
348 mips2_fp_compat (struct frame_info *frame)
349 {
350 struct gdbarch *gdbarch = get_frame_arch (frame);
351 /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
352 meaningful. */
353 if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4)
354 return 0;
355
356 #if 0
357 /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
358 in all the places we deal with FP registers. PR gdb/413. */
359 /* Otherwise check the FR bit in the status register - it controls
360 the FP compatiblity mode. If it is clear we are in compatibility
361 mode. */
362 if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0)
363 return 1;
364 #endif
365
366 return 0;
367 }
368
369 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
370
371 static CORE_ADDR heuristic_proc_start (struct gdbarch *, CORE_ADDR);
372
373 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
374
375 /* The list of available "set mips " and "show mips " commands. */
376
377 static struct cmd_list_element *setmipscmdlist = NULL;
378 static struct cmd_list_element *showmipscmdlist = NULL;
379
380 /* Integer registers 0 thru 31 are handled explicitly by
381 mips_register_name(). Processor specific registers 32 and above
382 are listed in the following tables. */
383
384 enum
385 { NUM_MIPS_PROCESSOR_REGS = (90 - 32) };
386
387 /* Generic MIPS. */
388
389 static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
390 "sr", "lo", "hi", "bad", "cause", "pc",
391 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
392 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
393 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
394 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
395 "fsr", "fir", "" /*"fp" */ , "",
396 "", "", "", "", "", "", "", "",
397 "", "", "", "", "", "", "", "",
398 };
399
400 /* Names of IDT R3041 registers. */
401
402 static const char *mips_r3041_reg_names[] = {
403 "sr", "lo", "hi", "bad", "cause", "pc",
404 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
405 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
406 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
407 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
408 "fsr", "fir", "", /*"fp" */ "",
409 "", "", "bus", "ccfg", "", "", "", "",
410 "", "", "port", "cmp", "", "", "epc", "prid",
411 };
412
413 /* Names of tx39 registers. */
414
415 static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
416 "sr", "lo", "hi", "bad", "cause", "pc",
417 "", "", "", "", "", "", "", "",
418 "", "", "", "", "", "", "", "",
419 "", "", "", "", "", "", "", "",
420 "", "", "", "", "", "", "", "",
421 "", "", "", "",
422 "", "", "", "", "", "", "", "",
423 "", "", "config", "cache", "debug", "depc", "epc", ""
424 };
425
426 /* Names of IRIX registers. */
427 static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
428 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
429 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
430 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
431 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
432 "pc", "cause", "bad", "hi", "lo", "fsr", "fir"
433 };
434
435
436 /* Return the name of the register corresponding to REGNO. */
437 static const char *
438 mips_register_name (struct gdbarch *gdbarch, int regno)
439 {
440 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
441 /* GPR names for all ABIs other than n32/n64. */
442 static char *mips_gpr_names[] = {
443 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
444 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
445 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
446 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
447 };
448
449 /* GPR names for n32 and n64 ABIs. */
450 static char *mips_n32_n64_gpr_names[] = {
451 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
452 "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
453 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
454 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
455 };
456
457 enum mips_abi abi = mips_abi (gdbarch);
458
459 /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
460 but then don't make the raw register names visible. This (upper)
461 range of user visible register numbers are the pseudo-registers.
462
463 This approach was adopted accommodate the following scenario:
464 It is possible to debug a 64-bit device using a 32-bit
465 programming model. In such instances, the raw registers are
466 configured to be 64-bits wide, while the pseudo registers are
467 configured to be 32-bits wide. The registers that the user
468 sees - the pseudo registers - match the users expectations
469 given the programming model being used. */
470 int rawnum = regno % gdbarch_num_regs (gdbarch);
471 if (regno < gdbarch_num_regs (gdbarch))
472 return "";
473
474 /* The MIPS integer registers are always mapped from 0 to 31. The
475 names of the registers (which reflects the conventions regarding
476 register use) vary depending on the ABI. */
477 if (0 <= rawnum && rawnum < 32)
478 {
479 if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
480 return mips_n32_n64_gpr_names[rawnum];
481 else
482 return mips_gpr_names[rawnum];
483 }
484 else if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
485 return tdesc_register_name (gdbarch, rawnum);
486 else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch))
487 {
488 gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS);
489 return tdep->mips_processor_reg_names[rawnum - 32];
490 }
491 else
492 internal_error (__FILE__, __LINE__,
493 _("mips_register_name: bad register number %d"), rawnum);
494 }
495
496 /* Return the groups that a MIPS register can be categorised into. */
497
498 static int
499 mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
500 struct reggroup *reggroup)
501 {
502 int vector_p;
503 int float_p;
504 int raw_p;
505 int rawnum = regnum % gdbarch_num_regs (gdbarch);
506 int pseudo = regnum / gdbarch_num_regs (gdbarch);
507 if (reggroup == all_reggroup)
508 return pseudo;
509 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
510 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
511 /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
512 (gdbarch), as not all architectures are multi-arch. */
513 raw_p = rawnum < gdbarch_num_regs (gdbarch);
514 if (gdbarch_register_name (gdbarch, regnum) == NULL
515 || gdbarch_register_name (gdbarch, regnum)[0] == '\0')
516 return 0;
517 if (reggroup == float_reggroup)
518 return float_p && pseudo;
519 if (reggroup == vector_reggroup)
520 return vector_p && pseudo;
521 if (reggroup == general_reggroup)
522 return (!vector_p && !float_p) && pseudo;
523 /* Save the pseudo registers. Need to make certain that any code
524 extracting register values from a saved register cache also uses
525 pseudo registers. */
526 if (reggroup == save_reggroup)
527 return raw_p && pseudo;
528 /* Restore the same pseudo register. */
529 if (reggroup == restore_reggroup)
530 return raw_p && pseudo;
531 return 0;
532 }
533
534 /* Return the groups that a MIPS register can be categorised into.
535 This version is only used if we have a target description which
536 describes real registers (and their groups). */
537
538 static int
539 mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
540 struct reggroup *reggroup)
541 {
542 int rawnum = regnum % gdbarch_num_regs (gdbarch);
543 int pseudo = regnum / gdbarch_num_regs (gdbarch);
544 int ret;
545
546 /* Only save, restore, and display the pseudo registers. Need to
547 make certain that any code extracting register values from a
548 saved register cache also uses pseudo registers.
549
550 Note: saving and restoring the pseudo registers is slightly
551 strange; if we have 64 bits, we should save and restore all
552 64 bits. But this is hard and has little benefit. */
553 if (!pseudo)
554 return 0;
555
556 ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup);
557 if (ret != -1)
558 return ret;
559
560 return mips_register_reggroup_p (gdbarch, regnum, reggroup);
561 }
562
563 /* Map the symbol table registers which live in the range [1 *
564 gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
565 registers. Take care of alignment and size problems. */
566
567 static enum register_status
568 mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
569 int cookednum, gdb_byte *buf)
570 {
571 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
572 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
573 && cookednum < 2 * gdbarch_num_regs (gdbarch));
574 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
575 return regcache_raw_read (regcache, rawnum, buf);
576 else if (register_size (gdbarch, rawnum) >
577 register_size (gdbarch, cookednum))
578 {
579 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p)
580 return regcache_raw_read_part (regcache, rawnum, 0, 4, buf);
581 else
582 {
583 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
584 LONGEST regval;
585 enum register_status status;
586
587 status = regcache_raw_read_signed (regcache, rawnum, &regval);
588 if (status == REG_VALID)
589 store_signed_integer (buf, 4, byte_order, regval);
590 return status;
591 }
592 }
593 else
594 internal_error (__FILE__, __LINE__, _("bad register size"));
595 }
596
597 static void
598 mips_pseudo_register_write (struct gdbarch *gdbarch,
599 struct regcache *regcache, int cookednum,
600 const gdb_byte *buf)
601 {
602 int rawnum = cookednum % gdbarch_num_regs (gdbarch);
603 gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
604 && cookednum < 2 * gdbarch_num_regs (gdbarch));
605 if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
606 regcache_raw_write (regcache, rawnum, buf);
607 else if (register_size (gdbarch, rawnum) >
608 register_size (gdbarch, cookednum))
609 {
610 if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p)
611 regcache_raw_write_part (regcache, rawnum, 0, 4, buf);
612 else
613 {
614 /* Sign extend the shortened version of the register prior
615 to placing it in the raw register. This is required for
616 some mips64 parts in order to avoid unpredictable behavior. */
617 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
618 LONGEST regval = extract_signed_integer (buf, 4, byte_order);
619 regcache_raw_write_signed (regcache, rawnum, regval);
620 }
621 }
622 else
623 internal_error (__FILE__, __LINE__, _("bad register size"));
624 }
625
626 static int
627 mips_ax_pseudo_register_collect (struct gdbarch *gdbarch,
628 struct agent_expr *ax, int reg)
629 {
630 int rawnum = reg % gdbarch_num_regs (gdbarch);
631 gdb_assert (reg >= gdbarch_num_regs (gdbarch)
632 && reg < 2 * gdbarch_num_regs (gdbarch));
633
634 ax_reg_mask (ax, rawnum);
635
636 return 0;
637 }
638
639 static int
640 mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
641 struct agent_expr *ax, int reg)
642 {
643 int rawnum = reg % gdbarch_num_regs (gdbarch);
644 gdb_assert (reg >= gdbarch_num_regs (gdbarch)
645 && reg < 2 * gdbarch_num_regs (gdbarch));
646 if (register_size (gdbarch, rawnum) >= register_size (gdbarch, reg))
647 {
648 ax_reg (ax, rawnum);
649
650 if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
651 {
652 if (!gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p
653 || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
654 {
655 ax_const_l (ax, 32);
656 ax_simple (ax, aop_lsh);
657 }
658 ax_const_l (ax, 32);
659 ax_simple (ax, aop_rsh_signed);
660 }
661 }
662 else
663 internal_error (__FILE__, __LINE__, _("bad register size"));
664
665 return 0;
666 }
667
668 /* Table to translate MIPS16 register field to actual register number. */
669 static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
670
671 /* Heuristic_proc_start may hunt through the text section for a long
672 time across a 2400 baud serial line. Allows the user to limit this
673 search. */
674
675 static unsigned int heuristic_fence_post = 0;
676
677 /* Number of bytes of storage in the actual machine representation for
678 register N. NOTE: This defines the pseudo register type so need to
679 rebuild the architecture vector. */
680
681 static int mips64_transfers_32bit_regs_p = 0;
682
683 static void
684 set_mips64_transfers_32bit_regs (char *args, int from_tty,
685 struct cmd_list_element *c)
686 {
687 struct gdbarch_info info;
688 gdbarch_info_init (&info);
689 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
690 instead of relying on globals. Doing that would let generic code
691 handle the search for this specific architecture. */
692 if (!gdbarch_update_p (info))
693 {
694 mips64_transfers_32bit_regs_p = 0;
695 error (_("32-bit compatibility mode not supported"));
696 }
697 }
698
699 /* Convert to/from a register and the corresponding memory value. */
700
701 /* This predicate tests for the case of an 8 byte floating point
702 value that is being transferred to or from a pair of floating point
703 registers each of which are (or are considered to be) only 4 bytes
704 wide. */
705 static int
706 mips_convert_register_float_case_p (struct gdbarch *gdbarch, int regnum,
707 struct type *type)
708 {
709 return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
710 && register_size (gdbarch, regnum) == 4
711 && (regnum % gdbarch_num_regs (gdbarch))
712 >= mips_regnum (gdbarch)->fp0
713 && (regnum % gdbarch_num_regs (gdbarch))
714 < mips_regnum (gdbarch)->fp0 + 32
715 && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8);
716 }
717
718 /* This predicate tests for the case of a value of less than 8
719 bytes in width that is being transfered to or from an 8 byte
720 general purpose register. */
721 static int
722 mips_convert_register_gpreg_case_p (struct gdbarch *gdbarch, int regnum,
723 struct type *type)
724 {
725 int num_regs = gdbarch_num_regs (gdbarch);
726
727 return (register_size (gdbarch, regnum) == 8
728 && regnum % num_regs > 0 && regnum % num_regs < 32
729 && TYPE_LENGTH (type) < 8);
730 }
731
732 static int
733 mips_convert_register_p (struct gdbarch *gdbarch,
734 int regnum, struct type *type)
735 {
736 return mips_convert_register_float_case_p (gdbarch, regnum, type)
737 || mips_convert_register_gpreg_case_p (gdbarch, regnum, type);
738 }
739
740 static int
741 mips_register_to_value (struct frame_info *frame, int regnum,
742 struct type *type, gdb_byte *to,
743 int *optimizedp, int *unavailablep)
744 {
745 struct gdbarch *gdbarch = get_frame_arch (frame);
746
747 if (mips_convert_register_float_case_p (gdbarch, regnum, type))
748 {
749 get_frame_register (frame, regnum + 0, to + 4);
750 get_frame_register (frame, regnum + 1, to + 0);
751
752 if (!get_frame_register_bytes (frame, regnum + 0, 0, 4, to + 4,
753 optimizedp, unavailablep))
754 return 0;
755
756 if (!get_frame_register_bytes (frame, regnum + 1, 0, 4, to + 0,
757 optimizedp, unavailablep))
758 return 0;
759 *optimizedp = *unavailablep = 0;
760 return 1;
761 }
762 else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type))
763 {
764 int len = TYPE_LENGTH (type);
765 CORE_ADDR offset;
766
767 offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 - len : 0;
768 if (!get_frame_register_bytes (frame, regnum, offset, len, to,
769 optimizedp, unavailablep))
770 return 0;
771
772 *optimizedp = *unavailablep = 0;
773 return 1;
774 }
775 else
776 {
777 internal_error (__FILE__, __LINE__,
778 _("mips_register_to_value: unrecognized case"));
779 }
780 }
781
782 static void
783 mips_value_to_register (struct frame_info *frame, int regnum,
784 struct type *type, const gdb_byte *from)
785 {
786 struct gdbarch *gdbarch = get_frame_arch (frame);
787
788 if (mips_convert_register_float_case_p (gdbarch, regnum, type))
789 {
790 put_frame_register (frame, regnum + 0, from + 4);
791 put_frame_register (frame, regnum + 1, from + 0);
792 }
793 else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type))
794 {
795 gdb_byte fill[8];
796 int len = TYPE_LENGTH (type);
797
798 /* Sign extend values, irrespective of type, that are stored to
799 a 64-bit general purpose register. (32-bit unsigned values
800 are stored as signed quantities within a 64-bit register.
801 When performing an operation, in compiled code, that combines
802 a 32-bit unsigned value with a signed 64-bit value, a type
803 conversion is first performed that zeroes out the high 32 bits.) */
804 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
805 {
806 if (from[0] & 0x80)
807 store_signed_integer (fill, 8, BFD_ENDIAN_BIG, -1);
808 else
809 store_signed_integer (fill, 8, BFD_ENDIAN_BIG, 0);
810 put_frame_register_bytes (frame, regnum, 0, 8 - len, fill);
811 put_frame_register_bytes (frame, regnum, 8 - len, len, from);
812 }
813 else
814 {
815 if (from[len-1] & 0x80)
816 store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, -1);
817 else
818 store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, 0);
819 put_frame_register_bytes (frame, regnum, 0, len, from);
820 put_frame_register_bytes (frame, regnum, len, 8 - len, fill);
821 }
822 }
823 else
824 {
825 internal_error (__FILE__, __LINE__,
826 _("mips_value_to_register: unrecognized case"));
827 }
828 }
829
830 /* Return the GDB type object for the "standard" data type of data in
831 register REG. */
832
833 static struct type *
834 mips_register_type (struct gdbarch *gdbarch, int regnum)
835 {
836 gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch));
837 if ((regnum % gdbarch_num_regs (gdbarch)) >= mips_regnum (gdbarch)->fp0
838 && (regnum % gdbarch_num_regs (gdbarch))
839 < mips_regnum (gdbarch)->fp0 + 32)
840 {
841 /* The floating-point registers raw, or cooked, always match
842 mips_isa_regsize(), and also map 1:1, byte for byte. */
843 if (mips_isa_regsize (gdbarch) == 4)
844 return builtin_type (gdbarch)->builtin_float;
845 else
846 return builtin_type (gdbarch)->builtin_double;
847 }
848 else if (regnum < gdbarch_num_regs (gdbarch))
849 {
850 /* The raw or ISA registers. These are all sized according to
851 the ISA regsize. */
852 if (mips_isa_regsize (gdbarch) == 4)
853 return builtin_type (gdbarch)->builtin_int32;
854 else
855 return builtin_type (gdbarch)->builtin_int64;
856 }
857 else
858 {
859 /* The cooked or ABI registers. These are sized according to
860 the ABI (with a few complications). */
861 if (regnum >= (gdbarch_num_regs (gdbarch)
862 + mips_regnum (gdbarch)->fp_control_status)
863 && regnum <= gdbarch_num_regs (gdbarch) + MIPS_LAST_EMBED_REGNUM)
864 /* The pseudo/cooked view of the embedded registers is always
865 32-bit. The raw view is handled below. */
866 return builtin_type (gdbarch)->builtin_int32;
867 else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p)
868 /* The target, while possibly using a 64-bit register buffer,
869 is only transfering 32-bits of each integer register.
870 Reflect this in the cooked/pseudo (ABI) register value. */
871 return builtin_type (gdbarch)->builtin_int32;
872 else if (mips_abi_regsize (gdbarch) == 4)
873 /* The ABI is restricted to 32-bit registers (the ISA could be
874 32- or 64-bit). */
875 return builtin_type (gdbarch)->builtin_int32;
876 else
877 /* 64-bit ABI. */
878 return builtin_type (gdbarch)->builtin_int64;
879 }
880 }
881
882 /* Return the GDB type for the pseudo register REGNUM, which is the
883 ABI-level view. This function is only called if there is a target
884 description which includes registers, so we know precisely the
885 types of hardware registers. */
886
887 static struct type *
888 mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
889 {
890 const int num_regs = gdbarch_num_regs (gdbarch);
891 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
892 int rawnum = regnum % num_regs;
893 struct type *rawtype;
894
895 gdb_assert (regnum >= num_regs && regnum < 2 * num_regs);
896
897 /* Absent registers are still absent. */
898 rawtype = gdbarch_register_type (gdbarch, rawnum);
899 if (TYPE_LENGTH (rawtype) == 0)
900 return rawtype;
901
902 if (rawnum >= MIPS_EMBED_FP0_REGNUM && rawnum < MIPS_EMBED_FP0_REGNUM + 32)
903 /* Present the floating point registers however the hardware did;
904 do not try to convert between FPU layouts. */
905 return rawtype;
906
907 if (rawnum >= MIPS_EMBED_FP0_REGNUM + 32 && rawnum <= MIPS_LAST_EMBED_REGNUM)
908 {
909 /* The pseudo/cooked view of embedded registers is always
910 32-bit, even if the target transfers 64-bit values for them.
911 New targets relying on XML descriptions should only transfer
912 the necessary 32 bits, but older versions of GDB expected 64,
913 so allow the target to provide 64 bits without interfering
914 with the displayed type. */
915 return builtin_type (gdbarch)->builtin_int32;
916 }
917
918 /* Use pointer types for registers if we can. For n32 we can not,
919 since we do not have a 64-bit pointer type. */
920 if (mips_abi_regsize (gdbarch)
921 == TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr))
922 {
923 if (rawnum == MIPS_SP_REGNUM || rawnum == MIPS_EMBED_BADVADDR_REGNUM)
924 return builtin_type (gdbarch)->builtin_data_ptr;
925 else if (rawnum == MIPS_EMBED_PC_REGNUM)
926 return builtin_type (gdbarch)->builtin_func_ptr;
927 }
928
929 if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8
930 && rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_EMBED_PC_REGNUM)
931 return builtin_type (gdbarch)->builtin_int32;
932
933 /* For all other registers, pass through the hardware type. */
934 return rawtype;
935 }
936
937 /* Should the upper word of 64-bit addresses be zeroed? */
938 enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
939
940 static int
941 mips_mask_address_p (struct gdbarch_tdep *tdep)
942 {
943 switch (mask_address_var)
944 {
945 case AUTO_BOOLEAN_TRUE:
946 return 1;
947 case AUTO_BOOLEAN_FALSE:
948 return 0;
949 break;
950 case AUTO_BOOLEAN_AUTO:
951 return tdep->default_mask_address_p;
952 default:
953 internal_error (__FILE__, __LINE__,
954 _("mips_mask_address_p: bad switch"));
955 return -1;
956 }
957 }
958
959 static void
960 show_mask_address (struct ui_file *file, int from_tty,
961 struct cmd_list_element *c, const char *value)
962 {
963 struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
964
965 deprecated_show_value_hack (file, from_tty, c, value);
966 switch (mask_address_var)
967 {
968 case AUTO_BOOLEAN_TRUE:
969 printf_filtered ("The 32 bit mips address mask is enabled\n");
970 break;
971 case AUTO_BOOLEAN_FALSE:
972 printf_filtered ("The 32 bit mips address mask is disabled\n");
973 break;
974 case AUTO_BOOLEAN_AUTO:
975 printf_filtered
976 ("The 32 bit address mask is set automatically. Currently %s\n",
977 mips_mask_address_p (tdep) ? "enabled" : "disabled");
978 break;
979 default:
980 internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
981 break;
982 }
983 }
984
985 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
986
987 int
988 mips_pc_is_mips16 (CORE_ADDR memaddr)
989 {
990 struct minimal_symbol *sym;
991
992 /* A flag indicating that this is a MIPS16 function is stored by
993 elfread.c in the high bit of the info field. Use this to decide
994 if the function is MIPS16 or normal MIPS. Otherwise if bit 0 of
995 the address is set, assume this is a MIPS16 address. */
996 sym = lookup_minimal_symbol_by_pc (memaddr);
997 if (sym)
998 return msymbol_is_special (sym);
999 else
1000 return is_mips16_addr (memaddr);
1001 }
1002
1003 /* MIPS believes that the PC has a sign extended value. Perhaps the
1004 all registers should be sign extended for simplicity? */
1005
1006 static CORE_ADDR
1007 mips_read_pc (struct regcache *regcache)
1008 {
1009 ULONGEST pc;
1010 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
1011 regcache_cooked_read_signed (regcache, regnum, &pc);
1012 if (is_mips16_addr (pc))
1013 pc = unmake_mips16_addr (pc);
1014 return pc;
1015 }
1016
1017 static CORE_ADDR
1018 mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1019 {
1020 ULONGEST pc;
1021
1022 pc = frame_unwind_register_signed
1023 (next_frame, gdbarch_num_regs (gdbarch) + mips_regnum (gdbarch)->pc);
1024 if (is_mips16_addr (pc))
1025 pc = unmake_mips16_addr (pc);
1026 return pc;
1027 }
1028
1029 static CORE_ADDR
1030 mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1031 {
1032 return frame_unwind_register_signed
1033 (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM);
1034 }
1035
1036 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
1037 dummy frame. The frame ID's base needs to match the TOS value
1038 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
1039 breakpoint. */
1040
1041 static struct frame_id
1042 mips_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1043 {
1044 return frame_id_build
1045 (get_frame_register_signed (this_frame,
1046 gdbarch_num_regs (gdbarch)
1047 + MIPS_SP_REGNUM),
1048 get_frame_pc (this_frame));
1049 }
1050
1051 static void
1052 mips_write_pc (struct regcache *regcache, CORE_ADDR pc)
1053 {
1054 int regnum = mips_regnum (get_regcache_arch (regcache))->pc;
1055 if (mips_pc_is_mips16 (pc))
1056 regcache_cooked_write_unsigned (regcache, regnum, make_mips16_addr (pc));
1057 else
1058 regcache_cooked_write_unsigned (regcache, regnum, pc);
1059 }
1060
1061 /* Fetch and return instruction from the specified location. If the PC
1062 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
1063
1064 static ULONGEST
1065 mips_fetch_instruction (struct gdbarch *gdbarch, CORE_ADDR addr)
1066 {
1067 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1068 gdb_byte buf[MIPS_INSN32_SIZE];
1069 int instlen;
1070 int status;
1071
1072 if (mips_pc_is_mips16 (addr))
1073 {
1074 instlen = MIPS_INSN16_SIZE;
1075 addr = unmake_mips16_addr (addr);
1076 }
1077 else
1078 instlen = MIPS_INSN32_SIZE;
1079 status = target_read_memory (addr, buf, instlen);
1080 if (status)
1081 memory_error (status, addr);
1082 return extract_unsigned_integer (buf, instlen, byte_order);
1083 }
1084
1085 /* These are the fields of 32 bit mips instructions. */
1086 #define mips32_op(x) (x >> 26)
1087 #define itype_op(x) (x >> 26)
1088 #define itype_rs(x) ((x >> 21) & 0x1f)
1089 #define itype_rt(x) ((x >> 16) & 0x1f)
1090 #define itype_immediate(x) (x & 0xffff)
1091
1092 #define jtype_op(x) (x >> 26)
1093 #define jtype_target(x) (x & 0x03ffffff)
1094
1095 #define rtype_op(x) (x >> 26)
1096 #define rtype_rs(x) ((x >> 21) & 0x1f)
1097 #define rtype_rt(x) ((x >> 16) & 0x1f)
1098 #define rtype_rd(x) ((x >> 11) & 0x1f)
1099 #define rtype_shamt(x) ((x >> 6) & 0x1f)
1100 #define rtype_funct(x) (x & 0x3f)
1101
1102 static LONGEST
1103 mips32_relative_offset (ULONGEST inst)
1104 {
1105 return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2;
1106 }
1107
1108 /* Determine where to set a single step breakpoint while considering
1109 branch prediction. */
1110 static CORE_ADDR
1111 mips32_next_pc (struct frame_info *frame, CORE_ADDR pc)
1112 {
1113 struct gdbarch *gdbarch = get_frame_arch (frame);
1114 unsigned long inst;
1115 int op;
1116 inst = mips_fetch_instruction (gdbarch, pc);
1117 if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch
1118 instruction. */
1119 {
1120 if (itype_op (inst) >> 2 == 5)
1121 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
1122 {
1123 op = (itype_op (inst) & 0x03);
1124 switch (op)
1125 {
1126 case 0: /* BEQL */
1127 goto equal_branch;
1128 case 1: /* BNEL */
1129 goto neq_branch;
1130 case 2: /* BLEZL */
1131 goto less_branch;
1132 case 3: /* BGTZL */
1133 goto greater_branch;
1134 default:
1135 pc += 4;
1136 }
1137 }
1138 else if (itype_op (inst) == 17 && itype_rs (inst) == 8)
1139 /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
1140 {
1141 int tf = itype_rt (inst) & 0x01;
1142 int cnum = itype_rt (inst) >> 2;
1143 int fcrcs =
1144 get_frame_register_signed (frame,
1145 mips_regnum (get_frame_arch (frame))->
1146 fp_control_status);
1147 int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01);
1148
1149 if (((cond >> cnum) & 0x01) == tf)
1150 pc += mips32_relative_offset (inst) + 4;
1151 else
1152 pc += 8;
1153 }
1154 else
1155 pc += 4; /* Not a branch, next instruction is easy. */
1156 }
1157 else
1158 { /* This gets way messy. */
1159
1160 /* Further subdivide into SPECIAL, REGIMM and other. */
1161 switch (op = itype_op (inst) & 0x07) /* Extract bits 28,27,26. */
1162 {
1163 case 0: /* SPECIAL */
1164 op = rtype_funct (inst);
1165 switch (op)
1166 {
1167 case 8: /* JR */
1168 case 9: /* JALR */
1169 /* Set PC to that address. */
1170 pc = get_frame_register_signed (frame, rtype_rs (inst));
1171 break;
1172 case 12: /* SYSCALL */
1173 {
1174 struct gdbarch_tdep *tdep;
1175
1176 tdep = gdbarch_tdep (get_frame_arch (frame));
1177 if (tdep->syscall_next_pc != NULL)
1178 pc = tdep->syscall_next_pc (frame);
1179 else
1180 pc += 4;
1181 }
1182 break;
1183 default:
1184 pc += 4;
1185 }
1186
1187 break; /* end SPECIAL */
1188 case 1: /* REGIMM */
1189 {
1190 op = itype_rt (inst); /* branch condition */
1191 switch (op)
1192 {
1193 case 0: /* BLTZ */
1194 case 2: /* BLTZL */
1195 case 16: /* BLTZAL */
1196 case 18: /* BLTZALL */
1197 less_branch:
1198 if (get_frame_register_signed (frame, itype_rs (inst)) < 0)
1199 pc += mips32_relative_offset (inst) + 4;
1200 else
1201 pc += 8; /* after the delay slot */
1202 break;
1203 case 1: /* BGEZ */
1204 case 3: /* BGEZL */
1205 case 17: /* BGEZAL */
1206 case 19: /* BGEZALL */
1207 if (get_frame_register_signed (frame, itype_rs (inst)) >= 0)
1208 pc += mips32_relative_offset (inst) + 4;
1209 else
1210 pc += 8; /* after the delay slot */
1211 break;
1212 /* All of the other instructions in the REGIMM category */
1213 default:
1214 pc += 4;
1215 }
1216 }
1217 break; /* end REGIMM */
1218 case 2: /* J */
1219 case 3: /* JAL */
1220 {
1221 unsigned long reg;
1222 reg = jtype_target (inst) << 2;
1223 /* Upper four bits get never changed... */
1224 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff);
1225 }
1226 break;
1227 /* FIXME case JALX : */
1228 {
1229 unsigned long reg;
1230 reg = jtype_target (inst) << 2;
1231 pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + 1; /* yes, +1 */
1232 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
1233 }
1234 break; /* The new PC will be alternate mode */
1235 case 4: /* BEQ, BEQL */
1236 equal_branch:
1237 if (get_frame_register_signed (frame, itype_rs (inst)) ==
1238 get_frame_register_signed (frame, itype_rt (inst)))
1239 pc += mips32_relative_offset (inst) + 4;
1240 else
1241 pc += 8;
1242 break;
1243 case 5: /* BNE, BNEL */
1244 neq_branch:
1245 if (get_frame_register_signed (frame, itype_rs (inst)) !=
1246 get_frame_register_signed (frame, itype_rt (inst)))
1247 pc += mips32_relative_offset (inst) + 4;
1248 else
1249 pc += 8;
1250 break;
1251 case 6: /* BLEZ, BLEZL */
1252 if (get_frame_register_signed (frame, itype_rs (inst)) <= 0)
1253 pc += mips32_relative_offset (inst) + 4;
1254 else
1255 pc += 8;
1256 break;
1257 case 7:
1258 default:
1259 greater_branch: /* BGTZ, BGTZL */
1260 if (get_frame_register_signed (frame, itype_rs (inst)) > 0)
1261 pc += mips32_relative_offset (inst) + 4;
1262 else
1263 pc += 8;
1264 break;
1265 } /* switch */
1266 } /* else */
1267 return pc;
1268 } /* mips32_next_pc */
1269
1270 /* Decoding the next place to set a breakpoint is irregular for the
1271 mips 16 variant, but fortunately, there fewer instructions. We have
1272 to cope ith extensions for 16 bit instructions and a pair of actual
1273 32 bit instructions. We dont want to set a single step instruction
1274 on the extend instruction either. */
1275
1276 /* Lots of mips16 instruction formats */
1277 /* Predicting jumps requires itype,ritype,i8type
1278 and their extensions extItype,extritype,extI8type. */
1279 enum mips16_inst_fmts
1280 {
1281 itype, /* 0 immediate 5,10 */
1282 ritype, /* 1 5,3,8 */
1283 rrtype, /* 2 5,3,3,5 */
1284 rritype, /* 3 5,3,3,5 */
1285 rrrtype, /* 4 5,3,3,3,2 */
1286 rriatype, /* 5 5,3,3,1,4 */
1287 shifttype, /* 6 5,3,3,3,2 */
1288 i8type, /* 7 5,3,8 */
1289 i8movtype, /* 8 5,3,3,5 */
1290 i8mov32rtype, /* 9 5,3,5,3 */
1291 i64type, /* 10 5,3,8 */
1292 ri64type, /* 11 5,3,3,5 */
1293 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
1294 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
1295 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
1296 extRRItype, /* 15 5,5,5,5,3,3,5 */
1297 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
1298 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
1299 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
1300 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
1301 extRi64type, /* 20 5,6,5,5,3,3,5 */
1302 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
1303 };
1304 /* I am heaping all the fields of the formats into one structure and
1305 then, only the fields which are involved in instruction extension. */
1306 struct upk_mips16
1307 {
1308 CORE_ADDR offset;
1309 unsigned int regx; /* Function in i8 type. */
1310 unsigned int regy;
1311 };
1312
1313
1314 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
1315 for the bits which make up the immediate extension. */
1316
1317 static CORE_ADDR
1318 extended_offset (unsigned int extension)
1319 {
1320 CORE_ADDR value;
1321
1322 value = (extension >> 21) & 0x3f; /* Extract 15:11. */
1323 value = value << 6;
1324 value |= (extension >> 16) & 0x1f; /* Extract 10:5. */
1325 value = value << 5;
1326 value |= extension & 0x1f; /* Extract 4:0. */
1327
1328 return value;
1329 }
1330
1331 /* Only call this function if you know that this is an extendable
1332 instruction. It won't malfunction, but why make excess remote memory
1333 references? If the immediate operands get sign extended or something,
1334 do it after the extension is performed. */
1335 /* FIXME: Every one of these cases needs to worry about sign extension
1336 when the offset is to be used in relative addressing. */
1337
1338 static unsigned int
1339 fetch_mips_16 (struct gdbarch *gdbarch, CORE_ADDR pc)
1340 {
1341 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1342 gdb_byte buf[8];
1343 pc &= 0xfffffffe; /* Clear the low order bit. */
1344 target_read_memory (pc, buf, 2);
1345 return extract_unsigned_integer (buf, 2, byte_order);
1346 }
1347
1348 static void
1349 unpack_mips16 (struct gdbarch *gdbarch, CORE_ADDR pc,
1350 unsigned int extension,
1351 unsigned int inst,
1352 enum mips16_inst_fmts insn_format, struct upk_mips16 *upk)
1353 {
1354 CORE_ADDR offset;
1355 int regx;
1356 int regy;
1357 switch (insn_format)
1358 {
1359 case itype:
1360 {
1361 CORE_ADDR value;
1362 if (extension)
1363 {
1364 value = extended_offset (extension);
1365 value = value << 11; /* rom for the original value */
1366 value |= inst & 0x7ff; /* eleven bits from instruction */
1367 }
1368 else
1369 {
1370 value = inst & 0x7ff;
1371 /* FIXME : Consider sign extension. */
1372 }
1373 offset = value;
1374 regx = -1;
1375 regy = -1;
1376 }
1377 break;
1378 case ritype:
1379 case i8type:
1380 { /* A register identifier and an offset. */
1381 /* Most of the fields are the same as I type but the
1382 immediate value is of a different length. */
1383 CORE_ADDR value;
1384 if (extension)
1385 {
1386 value = extended_offset (extension);
1387 value = value << 8; /* from the original instruction */
1388 value |= inst & 0xff; /* eleven bits from instruction */
1389 regx = (extension >> 8) & 0x07; /* or i8 funct */
1390 if (value & 0x4000) /* Test the sign bit, bit 26. */
1391 {
1392 value &= ~0x3fff; /* Remove the sign bit. */
1393 value = -value;
1394 }
1395 }
1396 else
1397 {
1398 value = inst & 0xff; /* 8 bits */
1399 regx = (inst >> 8) & 0x07; /* or i8 funct */
1400 /* FIXME: Do sign extension, this format needs it. */
1401 if (value & 0x80) /* THIS CONFUSES ME. */
1402 {
1403 value &= 0xef; /* Remove the sign bit. */
1404 value = -value;
1405 }
1406 }
1407 offset = value;
1408 regy = -1;
1409 break;
1410 }
1411 case jalxtype:
1412 {
1413 unsigned long value;
1414 unsigned int nexthalf;
1415 value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
1416 value = value << 16;
1417 nexthalf = mips_fetch_instruction (gdbarch, pc + 2); /* low bit
1418 still set. */
1419 value |= nexthalf;
1420 offset = value;
1421 regx = -1;
1422 regy = -1;
1423 break;
1424 }
1425 default:
1426 internal_error (__FILE__, __LINE__, _("bad switch"));
1427 }
1428 upk->offset = offset;
1429 upk->regx = regx;
1430 upk->regy = regy;
1431 }
1432
1433
1434 static CORE_ADDR
1435 add_offset_16 (CORE_ADDR pc, int offset)
1436 {
1437 return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff)));
1438 }
1439
1440 static CORE_ADDR
1441 extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc,
1442 unsigned int extension, unsigned int insn)
1443 {
1444 struct gdbarch *gdbarch = get_frame_arch (frame);
1445 int op = (insn >> 11);
1446 switch (op)
1447 {
1448 case 2: /* Branch */
1449 {
1450 CORE_ADDR offset;
1451 struct upk_mips16 upk;
1452 unpack_mips16 (gdbarch, pc, extension, insn, itype, &upk);
1453 offset = upk.offset;
1454 if (offset & 0x800)
1455 {
1456 offset &= 0xeff;
1457 offset = -offset;
1458 }
1459 pc += (offset << 1) + 2;
1460 break;
1461 }
1462 case 3: /* JAL , JALX - Watch out, these are 32 bit
1463 instructions. */
1464 {
1465 struct upk_mips16 upk;
1466 unpack_mips16 (gdbarch, pc, extension, insn, jalxtype, &upk);
1467 pc = add_offset_16 (pc, upk.offset);
1468 if ((insn >> 10) & 0x01) /* Exchange mode */
1469 pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode. */
1470 else
1471 pc |= 0x01;
1472 break;
1473 }
1474 case 4: /* beqz */
1475 {
1476 struct upk_mips16 upk;
1477 int reg;
1478 unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk);
1479 reg = get_frame_register_signed (frame, upk.regx);
1480 if (reg == 0)
1481 pc += (upk.offset << 1) + 2;
1482 else
1483 pc += 2;
1484 break;
1485 }
1486 case 5: /* bnez */
1487 {
1488 struct upk_mips16 upk;
1489 int reg;
1490 unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk);
1491 reg = get_frame_register_signed (frame, upk.regx);
1492 if (reg != 0)
1493 pc += (upk.offset << 1) + 2;
1494 else
1495 pc += 2;
1496 break;
1497 }
1498 case 12: /* I8 Formats btez btnez */
1499 {
1500 struct upk_mips16 upk;
1501 int reg;
1502 unpack_mips16 (gdbarch, pc, extension, insn, i8type, &upk);
1503 /* upk.regx contains the opcode */
1504 reg = get_frame_register_signed (frame, 24); /* Test register is 24 */
1505 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
1506 || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
1507 /* pc = add_offset_16(pc,upk.offset) ; */
1508 pc += (upk.offset << 1) + 2;
1509 else
1510 pc += 2;
1511 break;
1512 }
1513 case 29: /* RR Formats JR, JALR, JALR-RA */
1514 {
1515 struct upk_mips16 upk;
1516 /* upk.fmt = rrtype; */
1517 op = insn & 0x1f;
1518 if (op == 0)
1519 {
1520 int reg;
1521 upk.regx = (insn >> 8) & 0x07;
1522 upk.regy = (insn >> 5) & 0x07;
1523 switch (upk.regy)
1524 {
1525 case 0:
1526 reg = upk.regx;
1527 break;
1528 case 1:
1529 reg = 31;
1530 break; /* Function return instruction. */
1531 case 2:
1532 reg = upk.regx;
1533 break;
1534 default:
1535 reg = 31;
1536 break; /* BOGUS Guess */
1537 }
1538 pc = get_frame_register_signed (frame, reg);
1539 }
1540 else
1541 pc += 2;
1542 break;
1543 }
1544 case 30:
1545 /* This is an instruction extension. Fetch the real instruction
1546 (which follows the extension) and decode things based on
1547 that. */
1548 {
1549 pc += 2;
1550 pc = extended_mips16_next_pc (frame, pc, insn,
1551 fetch_mips_16 (gdbarch, pc));
1552 break;
1553 }
1554 default:
1555 {
1556 pc += 2;
1557 break;
1558 }
1559 }
1560 return pc;
1561 }
1562
1563 static CORE_ADDR
1564 mips16_next_pc (struct frame_info *frame, CORE_ADDR pc)
1565 {
1566 struct gdbarch *gdbarch = get_frame_arch (frame);
1567 unsigned int insn = fetch_mips_16 (gdbarch, pc);
1568 return extended_mips16_next_pc (frame, pc, 0, insn);
1569 }
1570
1571 /* The mips_next_pc function supports single_step when the remote
1572 target monitor or stub is not developed enough to do a single_step.
1573 It works by decoding the current instruction and predicting where a
1574 branch will go. This isnt hard because all the data is available.
1575 The MIPS32 and MIPS16 variants are quite different. */
1576 static CORE_ADDR
1577 mips_next_pc (struct frame_info *frame, CORE_ADDR pc)
1578 {
1579 if (mips_pc_is_mips16 (pc))
1580 return mips16_next_pc (frame, pc);
1581 else
1582 return mips32_next_pc (frame, pc);
1583 }
1584
1585 struct mips_frame_cache
1586 {
1587 CORE_ADDR base;
1588 struct trad_frame_saved_reg *saved_regs;
1589 };
1590
1591 /* Set a register's saved stack address in temp_saved_regs. If an
1592 address has already been set for this register, do nothing; this
1593 way we will only recognize the first save of a given register in a
1594 function prologue.
1595
1596 For simplicity, save the address in both [0 .. gdbarch_num_regs) and
1597 [gdbarch_num_regs .. 2*gdbarch_num_regs).
1598 Strictly speaking, only the second range is used as it is only second
1599 range (the ABI instead of ISA registers) that comes into play when finding
1600 saved registers in a frame. */
1601
1602 static void
1603 set_reg_offset (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache,
1604 int regnum, CORE_ADDR offset)
1605 {
1606 if (this_cache != NULL
1607 && this_cache->saved_regs[regnum].addr == -1)
1608 {
1609 this_cache->saved_regs[regnum + 0 * gdbarch_num_regs (gdbarch)].addr
1610 = offset;
1611 this_cache->saved_regs[regnum + 1 * gdbarch_num_regs (gdbarch)].addr
1612 = offset;
1613 }
1614 }
1615
1616
1617 /* Fetch the immediate value from a MIPS16 instruction.
1618 If the previous instruction was an EXTEND, use it to extend
1619 the upper bits of the immediate value. This is a helper function
1620 for mips16_scan_prologue. */
1621
1622 static int
1623 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
1624 unsigned short inst, /* current instruction */
1625 int nbits, /* number of bits in imm field */
1626 int scale, /* scale factor to be applied to imm */
1627 int is_signed) /* is the imm field signed? */
1628 {
1629 int offset;
1630
1631 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1632 {
1633 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1634 if (offset & 0x8000) /* check for negative extend */
1635 offset = 0 - (0x10000 - (offset & 0xffff));
1636 return offset | (inst & 0x1f);
1637 }
1638 else
1639 {
1640 int max_imm = 1 << nbits;
1641 int mask = max_imm - 1;
1642 int sign_bit = max_imm >> 1;
1643
1644 offset = inst & mask;
1645 if (is_signed && (offset & sign_bit))
1646 offset = 0 - (max_imm - offset);
1647 return offset * scale;
1648 }
1649 }
1650
1651
1652 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
1653 the associated FRAME_CACHE if not null.
1654 Return the address of the first instruction past the prologue. */
1655
1656 static CORE_ADDR
1657 mips16_scan_prologue (struct gdbarch *gdbarch,
1658 CORE_ADDR start_pc, CORE_ADDR limit_pc,
1659 struct frame_info *this_frame,
1660 struct mips_frame_cache *this_cache)
1661 {
1662 CORE_ADDR cur_pc;
1663 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer. */
1664 CORE_ADDR sp;
1665 long frame_offset = 0; /* Size of stack frame. */
1666 long frame_adjust = 0; /* Offset of FP from SP. */
1667 int frame_reg = MIPS_SP_REGNUM;
1668 unsigned short prev_inst = 0; /* saved copy of previous instruction. */
1669 unsigned inst = 0; /* current instruction */
1670 unsigned entry_inst = 0; /* the entry instruction */
1671 unsigned save_inst = 0; /* the save instruction */
1672 int reg, offset;
1673
1674 int extend_bytes = 0;
1675 int prev_extend_bytes;
1676 CORE_ADDR end_prologue_addr = 0;
1677
1678 /* Can be called when there's no process, and hence when there's no
1679 THIS_FRAME. */
1680 if (this_frame != NULL)
1681 sp = get_frame_register_signed (this_frame,
1682 gdbarch_num_regs (gdbarch)
1683 + MIPS_SP_REGNUM);
1684 else
1685 sp = 0;
1686
1687 if (limit_pc > start_pc + 200)
1688 limit_pc = start_pc + 200;
1689
1690 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE)
1691 {
1692 /* Save the previous instruction. If it's an EXTEND, we'll extract
1693 the immediate offset extension from it in mips16_get_imm. */
1694 prev_inst = inst;
1695
1696 /* Fetch and decode the instruction. */
1697 inst = (unsigned short) mips_fetch_instruction (gdbarch, cur_pc);
1698
1699 /* Normally we ignore extend instructions. However, if it is
1700 not followed by a valid prologue instruction, then this
1701 instruction is not part of the prologue either. We must
1702 remember in this case to adjust the end_prologue_addr back
1703 over the extend. */
1704 if ((inst & 0xf800) == 0xf000) /* extend */
1705 {
1706 extend_bytes = MIPS_INSN16_SIZE;
1707 continue;
1708 }
1709
1710 prev_extend_bytes = extend_bytes;
1711 extend_bytes = 0;
1712
1713 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1714 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1715 {
1716 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1717 if (offset < 0) /* Negative stack adjustment? */
1718 frame_offset -= offset;
1719 else
1720 /* Exit loop if a positive stack adjustment is found, which
1721 usually means that the stack cleanup code in the function
1722 epilogue is reached. */
1723 break;
1724 }
1725 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1726 {
1727 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1728 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1729 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1730 }
1731 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1732 {
1733 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1734 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1735 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1736 }
1737 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1738 {
1739 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1740 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1741 }
1742 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1743 {
1744 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1745 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1746 }
1747 else if (inst == 0x673d) /* move $s1, $sp */
1748 {
1749 frame_addr = sp;
1750 frame_reg = 17;
1751 }
1752 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1753 {
1754 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1755 frame_addr = sp + offset;
1756 frame_reg = 17;
1757 frame_adjust = offset;
1758 }
1759 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1760 {
1761 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1762 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1763 set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
1764 }
1765 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1766 {
1767 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1768 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1769 set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
1770 }
1771 else if ((inst & 0xf81f) == 0xe809
1772 && (inst & 0x700) != 0x700) /* entry */
1773 entry_inst = inst; /* Save for later processing. */
1774 else if ((inst & 0xff80) == 0x6480) /* save */
1775 {
1776 save_inst = inst; /* Save for later processing. */
1777 if (prev_extend_bytes) /* extend */
1778 save_inst |= prev_inst << 16;
1779 }
1780 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
1781 cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */
1782 else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
1783 {
1784 /* This instruction is part of the prologue, but we don't
1785 need to do anything special to handle it. */
1786 }
1787 else
1788 {
1789 /* This instruction is not an instruction typically found
1790 in a prologue, so we must have reached the end of the
1791 prologue. */
1792 if (end_prologue_addr == 0)
1793 end_prologue_addr = cur_pc - prev_extend_bytes;
1794 }
1795 }
1796
1797 /* The entry instruction is typically the first instruction in a function,
1798 and it stores registers at offsets relative to the value of the old SP
1799 (before the prologue). But the value of the sp parameter to this
1800 function is the new SP (after the prologue has been executed). So we
1801 can't calculate those offsets until we've seen the entire prologue,
1802 and can calculate what the old SP must have been. */
1803 if (entry_inst != 0)
1804 {
1805 int areg_count = (entry_inst >> 8) & 7;
1806 int sreg_count = (entry_inst >> 6) & 3;
1807
1808 /* The entry instruction always subtracts 32 from the SP. */
1809 frame_offset += 32;
1810
1811 /* Now we can calculate what the SP must have been at the
1812 start of the function prologue. */
1813 sp += frame_offset;
1814
1815 /* Check if a0-a3 were saved in the caller's argument save area. */
1816 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
1817 {
1818 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1819 offset += mips_abi_regsize (gdbarch);
1820 }
1821
1822 /* Check if the ra register was pushed on the stack. */
1823 offset = -4;
1824 if (entry_inst & 0x20)
1825 {
1826 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1827 offset -= mips_abi_regsize (gdbarch);
1828 }
1829
1830 /* Check if the s0 and s1 registers were pushed on the stack. */
1831 for (reg = 16; reg < sreg_count + 16; reg++)
1832 {
1833 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1834 offset -= mips_abi_regsize (gdbarch);
1835 }
1836 }
1837
1838 /* The SAVE instruction is similar to ENTRY, except that defined by the
1839 MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
1840 size of the frame is specified as an immediate field of instruction
1841 and an extended variation exists which lets additional registers and
1842 frame space to be specified. The instruction always treats registers
1843 as 32-bit so its usefulness for 64-bit ABIs is questionable. */
1844 if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4)
1845 {
1846 static int args_table[16] = {
1847 0, 0, 0, 0, 1, 1, 1, 1,
1848 2, 2, 2, 0, 3, 3, 4, -1,
1849 };
1850 static int astatic_table[16] = {
1851 0, 1, 2, 3, 0, 1, 2, 3,
1852 0, 1, 2, 4, 0, 1, 0, -1,
1853 };
1854 int aregs = (save_inst >> 16) & 0xf;
1855 int xsregs = (save_inst >> 24) & 0x7;
1856 int args = args_table[aregs];
1857 int astatic = astatic_table[aregs];
1858 long frame_size;
1859
1860 if (args < 0)
1861 {
1862 warning (_("Invalid number of argument registers encoded in SAVE."));
1863 args = 0;
1864 }
1865 if (astatic < 0)
1866 {
1867 warning (_("Invalid number of static registers encoded in SAVE."));
1868 astatic = 0;
1869 }
1870
1871 /* For standard SAVE the frame size of 0 means 128. */
1872 frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf);
1873 if (frame_size == 0 && (save_inst >> 16) == 0)
1874 frame_size = 16;
1875 frame_size *= 8;
1876 frame_offset += frame_size;
1877
1878 /* Now we can calculate what the SP must have been at the
1879 start of the function prologue. */
1880 sp += frame_offset;
1881
1882 /* Check if A0-A3 were saved in the caller's argument save area. */
1883 for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++)
1884 {
1885 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1886 offset += mips_abi_regsize (gdbarch);
1887 }
1888
1889 offset = -4;
1890
1891 /* Check if the RA register was pushed on the stack. */
1892 if (save_inst & 0x40)
1893 {
1894 set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
1895 offset -= mips_abi_regsize (gdbarch);
1896 }
1897
1898 /* Check if the S8 register was pushed on the stack. */
1899 if (xsregs > 6)
1900 {
1901 set_reg_offset (gdbarch, this_cache, 30, sp + offset);
1902 offset -= mips_abi_regsize (gdbarch);
1903 xsregs--;
1904 }
1905 /* Check if S2-S7 were pushed on the stack. */
1906 for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--)
1907 {
1908 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1909 offset -= mips_abi_regsize (gdbarch);
1910 }
1911
1912 /* Check if the S1 register was pushed on the stack. */
1913 if (save_inst & 0x10)
1914 {
1915 set_reg_offset (gdbarch, this_cache, 17, sp + offset);
1916 offset -= mips_abi_regsize (gdbarch);
1917 }
1918 /* Check if the S0 register was pushed on the stack. */
1919 if (save_inst & 0x20)
1920 {
1921 set_reg_offset (gdbarch, this_cache, 16, sp + offset);
1922 offset -= mips_abi_regsize (gdbarch);
1923 }
1924
1925 /* Check if A0-A3 were pushed on the stack. */
1926 for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--)
1927 {
1928 set_reg_offset (gdbarch, this_cache, reg, sp + offset);
1929 offset -= mips_abi_regsize (gdbarch);
1930 }
1931 }
1932
1933 if (this_cache != NULL)
1934 {
1935 this_cache->base =
1936 (get_frame_register_signed (this_frame,
1937 gdbarch_num_regs (gdbarch) + frame_reg)
1938 + frame_offset - frame_adjust);
1939 /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
1940 be able to get rid of the assignment below, evetually. But it's
1941 still needed for now. */
1942 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
1943 + mips_regnum (gdbarch)->pc]
1944 = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM];
1945 }
1946
1947 /* If we didn't reach the end of the prologue when scanning the function
1948 instructions, then set end_prologue_addr to the address of the
1949 instruction immediately after the last one we scanned. */
1950 if (end_prologue_addr == 0)
1951 end_prologue_addr = cur_pc;
1952
1953 return end_prologue_addr;
1954 }
1955
1956 /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
1957 Procedures that use the 32-bit instruction set are handled by the
1958 mips_insn32 unwinder. */
1959
1960 static struct mips_frame_cache *
1961 mips_insn16_frame_cache (struct frame_info *this_frame, void **this_cache)
1962 {
1963 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1964 struct mips_frame_cache *cache;
1965
1966 if ((*this_cache) != NULL)
1967 return (*this_cache);
1968 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
1969 (*this_cache) = cache;
1970 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1971
1972 /* Analyze the function prologue. */
1973 {
1974 const CORE_ADDR pc = get_frame_address_in_block (this_frame);
1975 CORE_ADDR start_addr;
1976
1977 find_pc_partial_function (pc, NULL, &start_addr, NULL);
1978 if (start_addr == 0)
1979 start_addr = heuristic_proc_start (gdbarch, pc);
1980 /* We can't analyze the prologue if we couldn't find the begining
1981 of the function. */
1982 if (start_addr == 0)
1983 return cache;
1984
1985 mips16_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache);
1986 }
1987
1988 /* gdbarch_sp_regnum contains the value and not the address. */
1989 trad_frame_set_value (cache->saved_regs,
1990 gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM,
1991 cache->base);
1992
1993 return (*this_cache);
1994 }
1995
1996 static void
1997 mips_insn16_frame_this_id (struct frame_info *this_frame, void **this_cache,
1998 struct frame_id *this_id)
1999 {
2000 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
2001 this_cache);
2002 /* This marks the outermost frame. */
2003 if (info->base == 0)
2004 return;
2005 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
2006 }
2007
2008 static struct value *
2009 mips_insn16_frame_prev_register (struct frame_info *this_frame,
2010 void **this_cache, int regnum)
2011 {
2012 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
2013 this_cache);
2014 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
2015 }
2016
2017 static int
2018 mips_insn16_frame_sniffer (const struct frame_unwind *self,
2019 struct frame_info *this_frame, void **this_cache)
2020 {
2021 CORE_ADDR pc = get_frame_pc (this_frame);
2022 if (mips_pc_is_mips16 (pc))
2023 return 1;
2024 return 0;
2025 }
2026
2027 static const struct frame_unwind mips_insn16_frame_unwind =
2028 {
2029 NORMAL_FRAME,
2030 default_frame_unwind_stop_reason,
2031 mips_insn16_frame_this_id,
2032 mips_insn16_frame_prev_register,
2033 NULL,
2034 mips_insn16_frame_sniffer
2035 };
2036
2037 static CORE_ADDR
2038 mips_insn16_frame_base_address (struct frame_info *this_frame,
2039 void **this_cache)
2040 {
2041 struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
2042 this_cache);
2043 return info->base;
2044 }
2045
2046 static const struct frame_base mips_insn16_frame_base =
2047 {
2048 &mips_insn16_frame_unwind,
2049 mips_insn16_frame_base_address,
2050 mips_insn16_frame_base_address,
2051 mips_insn16_frame_base_address
2052 };
2053
2054 static const struct frame_base *
2055 mips_insn16_frame_base_sniffer (struct frame_info *this_frame)
2056 {
2057 CORE_ADDR pc = get_frame_pc (this_frame);
2058 if (mips_pc_is_mips16 (pc))
2059 return &mips_insn16_frame_base;
2060 else
2061 return NULL;
2062 }
2063
2064 /* Mark all the registers as unset in the saved_regs array
2065 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
2066
2067 static void
2068 reset_saved_regs (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache)
2069 {
2070 if (this_cache == NULL || this_cache->saved_regs == NULL)
2071 return;
2072
2073 {
2074 const int num_regs = gdbarch_num_regs (gdbarch);
2075 int i;
2076
2077 for (i = 0; i < num_regs; i++)
2078 {
2079 this_cache->saved_regs[i].addr = -1;
2080 }
2081 }
2082 }
2083
2084 /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
2085 the associated FRAME_CACHE if not null.
2086 Return the address of the first instruction past the prologue. */
2087
2088 static CORE_ADDR
2089 mips32_scan_prologue (struct gdbarch *gdbarch,
2090 CORE_ADDR start_pc, CORE_ADDR limit_pc,
2091 struct frame_info *this_frame,
2092 struct mips_frame_cache *this_cache)
2093 {
2094 CORE_ADDR cur_pc;
2095 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for
2096 frame-pointer. */
2097 CORE_ADDR sp;
2098 long frame_offset;
2099 int frame_reg = MIPS_SP_REGNUM;
2100
2101 CORE_ADDR end_prologue_addr = 0;
2102 int seen_sp_adjust = 0;
2103 int load_immediate_bytes = 0;
2104 int in_delay_slot = 0;
2105 int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8);
2106
2107 /* Can be called when there's no process, and hence when there's no
2108 THIS_FRAME. */
2109 if (this_frame != NULL)
2110 sp = get_frame_register_signed (this_frame,
2111 gdbarch_num_regs (gdbarch)
2112 + MIPS_SP_REGNUM);
2113 else
2114 sp = 0;
2115
2116 if (limit_pc > start_pc + 200)
2117 limit_pc = start_pc + 200;
2118
2119 restart:
2120
2121 frame_offset = 0;
2122 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE)
2123 {
2124 unsigned long inst, high_word, low_word;
2125 int reg;
2126
2127 /* Fetch the instruction. */
2128 inst = (unsigned long) mips_fetch_instruction (gdbarch, cur_pc);
2129
2130 /* Save some code by pre-extracting some useful fields. */
2131 high_word = (inst >> 16) & 0xffff;
2132 low_word = inst & 0xffff;
2133 reg = high_word & 0x1f;
2134
2135 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2136 || high_word == 0x23bd /* addi $sp,$sp,-i */
2137 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2138 {
2139 if (low_word & 0x8000) /* Negative stack adjustment? */
2140 frame_offset += 0x10000 - low_word;
2141 else
2142 /* Exit loop if a positive stack adjustment is found, which
2143 usually means that the stack cleanup code in the function
2144 epilogue is reached. */
2145 break;
2146 seen_sp_adjust = 1;
2147 }
2148 else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2149 && !regsize_is_64_bits)
2150 {
2151 set_reg_offset (gdbarch, this_cache, reg, sp + low_word);
2152 }
2153 else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2154 && regsize_is_64_bits)
2155 {
2156 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
2157 set_reg_offset (gdbarch, this_cache, reg, sp + low_word);
2158 }
2159 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2160 {
2161 /* Old gcc frame, r30 is virtual frame pointer. */
2162 if ((long) low_word != frame_offset)
2163 frame_addr = sp + low_word;
2164 else if (this_frame && frame_reg == MIPS_SP_REGNUM)
2165 {
2166 unsigned alloca_adjust;
2167
2168 frame_reg = 30;
2169 frame_addr = get_frame_register_signed
2170 (this_frame, gdbarch_num_regs (gdbarch) + 30);
2171
2172 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2173 if (alloca_adjust > 0)
2174 {
2175 /* FP > SP + frame_size. This may be because of
2176 an alloca or somethings similar. Fix sp to
2177 "pre-alloca" value, and try again. */
2178 sp += alloca_adjust;
2179 /* Need to reset the status of all registers. Otherwise,
2180 we will hit a guard that prevents the new address
2181 for each register to be recomputed during the second
2182 pass. */
2183 reset_saved_regs (gdbarch, this_cache);
2184 goto restart;
2185 }
2186 }
2187 }
2188 /* move $30,$sp. With different versions of gas this will be either
2189 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2190 Accept any one of these. */
2191 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2192 {
2193 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2194 if (this_frame && frame_reg == MIPS_SP_REGNUM)
2195 {
2196 unsigned alloca_adjust;
2197
2198 frame_reg = 30;
2199 frame_addr = get_frame_register_signed
2200 (this_frame, gdbarch_num_regs (gdbarch) + 30);
2201
2202 alloca_adjust = (unsigned) (frame_addr - sp);
2203 if (alloca_adjust > 0)
2204 {
2205 /* FP > SP + frame_size. This may be because of
2206 an alloca or somethings similar. Fix sp to
2207 "pre-alloca" value, and try again. */
2208 sp = frame_addr;
2209 /* Need to reset the status of all registers. Otherwise,
2210 we will hit a guard that prevents the new address
2211 for each register to be recomputed during the second
2212 pass. */
2213 reset_saved_regs (gdbarch, this_cache);
2214 goto restart;
2215 }
2216 }
2217 }
2218 else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
2219 && !regsize_is_64_bits)
2220 {
2221 set_reg_offset (gdbarch, this_cache, reg, frame_addr + low_word);
2222 }
2223 else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
2224 || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
2225 || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
2226 || high_word == 0x3c1c /* lui $gp,n */
2227 || high_word == 0x279c /* addiu $gp,$gp,n */
2228 || inst == 0x0399e021 /* addu $gp,$gp,$t9 */
2229 || inst == 0x033ce021 /* addu $gp,$t9,$gp */
2230 )
2231 {
2232 /* These instructions are part of the prologue, but we don't
2233 need to do anything special to handle them. */
2234 }
2235 /* The instructions below load $at or $t0 with an immediate
2236 value in preparation for a stack adjustment via
2237 subu $sp,$sp,[$at,$t0]. These instructions could also
2238 initialize a local variable, so we accept them only before
2239 a stack adjustment instruction was seen. */
2240 else if (!seen_sp_adjust
2241 && (high_word == 0x3c01 /* lui $at,n */
2242 || high_word == 0x3c08 /* lui $t0,n */
2243 || high_word == 0x3421 /* ori $at,$at,n */
2244 || high_word == 0x3508 /* ori $t0,$t0,n */
2245 || high_word == 0x3401 /* ori $at,$zero,n */
2246 || high_word == 0x3408 /* ori $t0,$zero,n */
2247 ))
2248 {
2249 load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */
2250 }
2251 else
2252 {
2253 /* This instruction is not an instruction typically found
2254 in a prologue, so we must have reached the end of the
2255 prologue. */
2256 /* FIXME: brobecker/2004-10-10: Can't we just break out of this
2257 loop now? Why would we need to continue scanning the function
2258 instructions? */
2259 if (end_prologue_addr == 0)
2260 end_prologue_addr = cur_pc;
2261
2262 /* Check for branches and jumps. For now, only jump to
2263 register are caught (i.e. returns). */
2264 if ((itype_op (inst) & 0x07) == 0 && rtype_funct (inst) == 8)
2265 in_delay_slot = 1;
2266 }
2267
2268 /* If the previous instruction was a jump, we must have reached
2269 the end of the prologue by now. Stop scanning so that we do
2270 not go past the function return. */
2271 if (in_delay_slot)
2272 break;
2273 }
2274
2275 if (this_cache != NULL)
2276 {
2277 this_cache->base =
2278 (get_frame_register_signed (this_frame,
2279 gdbarch_num_regs (gdbarch) + frame_reg)
2280 + frame_offset);
2281 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
2282 this assignment below, eventually. But it's still needed
2283 for now. */
2284 this_cache->saved_regs[gdbarch_num_regs (gdbarch)
2285 + mips_regnum (gdbarch)->pc]
2286 = this_cache->saved_regs[gdbarch_num_regs (gdbarch)
2287 + MIPS_RA_REGNUM];
2288 }
2289
2290 /* If we didn't reach the end of the prologue when scanning the function
2291 instructions, then set end_prologue_addr to the address of the
2292 instruction immediately after the last one we scanned. */
2293 /* brobecker/2004-10-10: I don't think this would ever happen, but
2294 we may as well be careful and do our best if we have a null
2295 end_prologue_addr. */
2296 if (end_prologue_addr == 0)
2297 end_prologue_addr = cur_pc;
2298
2299 /* In a frameless function, we might have incorrectly
2300 skipped some load immediate instructions. Undo the skipping
2301 if the load immediate was not followed by a stack adjustment. */
2302 if (load_immediate_bytes && !seen_sp_adjust)
2303 end_prologue_addr -= load_immediate_bytes;
2304
2305 return end_prologue_addr;
2306 }
2307
2308 /* Heuristic unwinder for procedures using 32-bit instructions (covers
2309 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
2310 instructions (a.k.a. MIPS16) are handled by the mips_insn16
2311 unwinder. */
2312
2313 static struct mips_frame_cache *
2314 mips_insn32_frame_cache (struct frame_info *this_frame, void **this_cache)
2315 {
2316 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2317 struct mips_frame_cache *cache;
2318
2319 if ((*this_cache) != NULL)
2320 return (*this_cache);
2321
2322 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
2323 (*this_cache) = cache;
2324 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2325
2326 /* Analyze the function prologue. */
2327 {
2328 const CORE_ADDR pc = get_frame_address_in_block (this_frame);
2329 CORE_ADDR start_addr;
2330
2331 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2332 if (start_addr == 0)
2333 start_addr = heuristic_proc_start (gdbarch, pc);
2334 /* We can't analyze the prologue if we couldn't find the begining
2335 of the function. */
2336 if (start_addr == 0)
2337 return cache;
2338
2339 mips32_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache);
2340 }
2341
2342 /* gdbarch_sp_regnum contains the value and not the address. */
2343 trad_frame_set_value (cache->saved_regs,
2344 gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM,
2345 cache->base);
2346
2347 return (*this_cache);
2348 }
2349
2350 static void
2351 mips_insn32_frame_this_id (struct frame_info *this_frame, void **this_cache,
2352 struct frame_id *this_id)
2353 {
2354 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2355 this_cache);
2356 /* This marks the outermost frame. */
2357 if (info->base == 0)
2358 return;
2359 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
2360 }
2361
2362 static struct value *
2363 mips_insn32_frame_prev_register (struct frame_info *this_frame,
2364 void **this_cache, int regnum)
2365 {
2366 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2367 this_cache);
2368 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
2369 }
2370
2371 static int
2372 mips_insn32_frame_sniffer (const struct frame_unwind *self,
2373 struct frame_info *this_frame, void **this_cache)
2374 {
2375 CORE_ADDR pc = get_frame_pc (this_frame);
2376 if (! mips_pc_is_mips16 (pc))
2377 return 1;
2378 return 0;
2379 }
2380
2381 static const struct frame_unwind mips_insn32_frame_unwind =
2382 {
2383 NORMAL_FRAME,
2384 default_frame_unwind_stop_reason,
2385 mips_insn32_frame_this_id,
2386 mips_insn32_frame_prev_register,
2387 NULL,
2388 mips_insn32_frame_sniffer
2389 };
2390
2391 static CORE_ADDR
2392 mips_insn32_frame_base_address (struct frame_info *this_frame,
2393 void **this_cache)
2394 {
2395 struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
2396 this_cache);
2397 return info->base;
2398 }
2399
2400 static const struct frame_base mips_insn32_frame_base =
2401 {
2402 &mips_insn32_frame_unwind,
2403 mips_insn32_frame_base_address,
2404 mips_insn32_frame_base_address,
2405 mips_insn32_frame_base_address
2406 };
2407
2408 static const struct frame_base *
2409 mips_insn32_frame_base_sniffer (struct frame_info *this_frame)
2410 {
2411 CORE_ADDR pc = get_frame_pc (this_frame);
2412 if (! mips_pc_is_mips16 (pc))
2413 return &mips_insn32_frame_base;
2414 else
2415 return NULL;
2416 }
2417
2418 static struct trad_frame_cache *
2419 mips_stub_frame_cache (struct frame_info *this_frame, void **this_cache)
2420 {
2421 CORE_ADDR pc;
2422 CORE_ADDR start_addr;
2423 CORE_ADDR stack_addr;
2424 struct trad_frame_cache *this_trad_cache;
2425 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2426 int num_regs = gdbarch_num_regs (gdbarch);
2427
2428 if ((*this_cache) != NULL)
2429 return (*this_cache);
2430 this_trad_cache = trad_frame_cache_zalloc (this_frame);
2431 (*this_cache) = this_trad_cache;
2432
2433 /* The return address is in the link register. */
2434 trad_frame_set_reg_realreg (this_trad_cache,
2435 gdbarch_pc_regnum (gdbarch),
2436 num_regs + MIPS_RA_REGNUM);
2437
2438 /* Frame ID, since it's a frameless / stackless function, no stack
2439 space is allocated and SP on entry is the current SP. */
2440 pc = get_frame_pc (this_frame);
2441 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2442 stack_addr = get_frame_register_signed (this_frame,
2443 num_regs + MIPS_SP_REGNUM);
2444 trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr));
2445
2446 /* Assume that the frame's base is the same as the
2447 stack-pointer. */
2448 trad_frame_set_this_base (this_trad_cache, stack_addr);
2449
2450 return this_trad_cache;
2451 }
2452
2453 static void
2454 mips_stub_frame_this_id (struct frame_info *this_frame, void **this_cache,
2455 struct frame_id *this_id)
2456 {
2457 struct trad_frame_cache *this_trad_cache
2458 = mips_stub_frame_cache (this_frame, this_cache);
2459 trad_frame_get_id (this_trad_cache, this_id);
2460 }
2461
2462 static struct value *
2463 mips_stub_frame_prev_register (struct frame_info *this_frame,
2464 void **this_cache, int regnum)
2465 {
2466 struct trad_frame_cache *this_trad_cache
2467 = mips_stub_frame_cache (this_frame, this_cache);
2468 return trad_frame_get_register (this_trad_cache, this_frame, regnum);
2469 }
2470
2471 static int
2472 mips_stub_frame_sniffer (const struct frame_unwind *self,
2473 struct frame_info *this_frame, void **this_cache)
2474 {
2475 gdb_byte dummy[4];
2476 struct obj_section *s;
2477 CORE_ADDR pc = get_frame_address_in_block (this_frame);
2478 struct minimal_symbol *msym;
2479
2480 /* Use the stub unwinder for unreadable code. */
2481 if (target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0)
2482 return 1;
2483
2484 if (in_plt_section (pc, NULL))
2485 return 1;
2486
2487 /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */
2488 s = find_pc_section (pc);
2489
2490 if (s != NULL
2491 && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section),
2492 ".MIPS.stubs") == 0)
2493 return 1;
2494
2495 /* Calling a PIC function from a non-PIC function passes through a
2496 stub. The stub for foo is named ".pic.foo". */
2497 msym = lookup_minimal_symbol_by_pc (pc);
2498 if (msym != NULL
2499 && SYMBOL_LINKAGE_NAME (msym) != NULL
2500 && strncmp (SYMBOL_LINKAGE_NAME (msym), ".pic.", 5) == 0)
2501 return 1;
2502
2503 return 0;
2504 }
2505
2506 static const struct frame_unwind mips_stub_frame_unwind =
2507 {
2508 NORMAL_FRAME,
2509 default_frame_unwind_stop_reason,
2510 mips_stub_frame_this_id,
2511 mips_stub_frame_prev_register,
2512 NULL,
2513 mips_stub_frame_sniffer
2514 };
2515
2516 static CORE_ADDR
2517 mips_stub_frame_base_address (struct frame_info *this_frame,
2518 void **this_cache)
2519 {
2520 struct trad_frame_cache *this_trad_cache
2521 = mips_stub_frame_cache (this_frame, this_cache);
2522 return trad_frame_get_this_base (this_trad_cache);
2523 }
2524
2525 static const struct frame_base mips_stub_frame_base =
2526 {
2527 &mips_stub_frame_unwind,
2528 mips_stub_frame_base_address,
2529 mips_stub_frame_base_address,
2530 mips_stub_frame_base_address
2531 };
2532
2533 static const struct frame_base *
2534 mips_stub_frame_base_sniffer (struct frame_info *this_frame)
2535 {
2536 if (mips_stub_frame_sniffer (&mips_stub_frame_unwind, this_frame, NULL))
2537 return &mips_stub_frame_base;
2538 else
2539 return NULL;
2540 }
2541
2542 /* mips_addr_bits_remove - remove useless address bits */
2543
2544 static CORE_ADDR
2545 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
2546 {
2547 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2548
2549 if (is_mips16_addr (addr))
2550 addr = unmake_mips16_addr (addr);
2551
2552 if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
2553 /* This hack is a work-around for existing boards using PMON, the
2554 simulator, and any other 64-bit targets that doesn't have true
2555 64-bit addressing. On these targets, the upper 32 bits of
2556 addresses are ignored by the hardware. Thus, the PC or SP are
2557 likely to have been sign extended to all 1s by instruction
2558 sequences that load 32-bit addresses. For example, a typical
2559 piece of code that loads an address is this:
2560
2561 lui $r2, <upper 16 bits>
2562 ori $r2, <lower 16 bits>
2563
2564 But the lui sign-extends the value such that the upper 32 bits
2565 may be all 1s. The workaround is simply to mask off these
2566 bits. In the future, gcc may be changed to support true 64-bit
2567 addressing, and this masking will have to be disabled. */
2568 return addr &= 0xffffffffUL;
2569 else
2570 return addr;
2571 }
2572
2573 /* Instructions used during single-stepping of atomic sequences. */
2574 #define LL_OPCODE 0x30
2575 #define LLD_OPCODE 0x34
2576 #define SC_OPCODE 0x38
2577 #define SCD_OPCODE 0x3c
2578
2579 /* Checks for an atomic sequence of instructions beginning with a LL/LLD
2580 instruction and ending with a SC/SCD instruction. If such a sequence
2581 is found, attempt to step through it. A breakpoint is placed at the end of
2582 the sequence. */
2583
2584 static int
2585 deal_with_atomic_sequence (struct gdbarch *gdbarch,
2586 struct address_space *aspace, CORE_ADDR pc)
2587 {
2588 CORE_ADDR breaks[2] = {-1, -1};
2589 CORE_ADDR loc = pc;
2590 CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */
2591 unsigned long insn;
2592 int insn_count;
2593 int index;
2594 int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
2595 const int atomic_sequence_length = 16; /* Instruction sequence length. */
2596
2597 if (pc & 0x01)
2598 return 0;
2599
2600 insn = mips_fetch_instruction (gdbarch, loc);
2601 /* Assume all atomic sequences start with a ll/lld instruction. */
2602 if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE)
2603 return 0;
2604
2605 /* Assume that no atomic sequence is longer than "atomic_sequence_length"
2606 instructions. */
2607 for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
2608 {
2609 int is_branch = 0;
2610 loc += MIPS_INSN32_SIZE;
2611 insn = mips_fetch_instruction (gdbarch, loc);
2612
2613 /* Assume that there is at most one branch in the atomic
2614 sequence. If a branch is found, put a breakpoint in its
2615 destination address. */
2616 switch (itype_op (insn))
2617 {
2618 case 0: /* SPECIAL */
2619 if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */
2620 return 0; /* fallback to the standard single-step code. */
2621 break;
2622 case 1: /* REGIMM */
2623 is_branch = ((itype_rt (insn) & 0xc0) == 0); /* B{LT,GE}Z* */
2624 break;
2625 case 2: /* J */
2626 case 3: /* JAL */
2627 return 0; /* fallback to the standard single-step code. */
2628 case 4: /* BEQ */
2629 case 5: /* BNE */
2630 case 6: /* BLEZ */
2631 case 7: /* BGTZ */
2632 case 20: /* BEQL */
2633 case 21: /* BNEL */
2634 case 22: /* BLEZL */
2635 case 23: /* BGTTL */
2636 is_branch = 1;
2637 break;
2638 case 17: /* COP1 */
2639 case 18: /* COP2 */
2640 case 19: /* COP3 */
2641 is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
2642 break;
2643 }
2644 if (is_branch)
2645 {
2646 branch_bp = loc + mips32_relative_offset (insn) + 4;
2647 if (last_breakpoint >= 1)
2648 return 0; /* More than one branch found, fallback to the
2649 standard single-step code. */
2650 breaks[1] = branch_bp;
2651 last_breakpoint++;
2652 }
2653
2654 if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE)
2655 break;
2656 }
2657
2658 /* Assume that the atomic sequence ends with a sc/scd instruction. */
2659 if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE)
2660 return 0;
2661
2662 loc += MIPS_INSN32_SIZE;
2663
2664 /* Insert a breakpoint right after the end of the atomic sequence. */
2665 breaks[0] = loc;
2666
2667 /* Check for duplicated breakpoints. Check also for a breakpoint
2668 placed (branch instruction's destination) in the atomic sequence. */
2669 if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0])
2670 last_breakpoint = 0;
2671
2672 /* Effectively inserts the breakpoints. */
2673 for (index = 0; index <= last_breakpoint; index++)
2674 insert_single_step_breakpoint (gdbarch, aspace, breaks[index]);
2675
2676 return 1;
2677 }
2678
2679 /* mips_software_single_step() is called just before we want to resume
2680 the inferior, if we want to single-step it but there is no hardware
2681 or kernel single-step support (MIPS on GNU/Linux for example). We find
2682 the target of the coming instruction and breakpoint it. */
2683
2684 int
2685 mips_software_single_step (struct frame_info *frame)
2686 {
2687 struct gdbarch *gdbarch = get_frame_arch (frame);
2688 struct address_space *aspace = get_frame_address_space (frame);
2689 CORE_ADDR pc, next_pc;
2690
2691 pc = get_frame_pc (frame);
2692 if (deal_with_atomic_sequence (gdbarch, aspace, pc))
2693 return 1;
2694
2695 next_pc = mips_next_pc (frame, pc);
2696
2697 insert_single_step_breakpoint (gdbarch, aspace, next_pc);
2698 return 1;
2699 }
2700
2701 /* Test whether the PC points to the return instruction at the
2702 end of a function. */
2703
2704 static int
2705 mips_about_to_return (struct gdbarch *gdbarch, CORE_ADDR pc)
2706 {
2707 if (mips_pc_is_mips16 (pc))
2708 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2709 generates a "jr $ra"; other times it generates code to load
2710 the return address from the stack to an accessible register (such
2711 as $a3), then a "jr" using that register. This second case
2712 is almost impossible to distinguish from an indirect jump
2713 used for switch statements, so we don't even try. */
2714 return mips_fetch_instruction (gdbarch, pc) == 0xe820; /* jr $ra */
2715 else
2716 return mips_fetch_instruction (gdbarch, pc) == 0x3e00008; /* jr $ra */
2717 }
2718
2719
2720 /* This fencepost looks highly suspicious to me. Removing it also
2721 seems suspicious as it could affect remote debugging across serial
2722 lines. */
2723
2724 static CORE_ADDR
2725 heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
2726 {
2727 CORE_ADDR start_pc;
2728 CORE_ADDR fence;
2729 int instlen;
2730 int seen_adjsp = 0;
2731 struct inferior *inf;
2732
2733 pc = gdbarch_addr_bits_remove (gdbarch, pc);
2734 start_pc = pc;
2735 fence = start_pc - heuristic_fence_post;
2736 if (start_pc == 0)
2737 return 0;
2738
2739 if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS)
2740 fence = VM_MIN_ADDRESS;
2741
2742 instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE;
2743
2744 inf = current_inferior ();
2745
2746 /* Search back for previous return. */
2747 for (start_pc -= instlen;; start_pc -= instlen)
2748 if (start_pc < fence)
2749 {
2750 /* It's not clear to me why we reach this point when
2751 stop_soon, but with this test, at least we
2752 don't print out warnings for every child forked (eg, on
2753 decstation). 22apr93 rich@cygnus.com. */
2754 if (inf->control.stop_soon == NO_STOP_QUIETLY)
2755 {
2756 static int blurb_printed = 0;
2757
2758 warning (_("GDB can't find the start of the function at %s."),
2759 paddress (gdbarch, pc));
2760
2761 if (!blurb_printed)
2762 {
2763 /* This actually happens frequently in embedded
2764 development, when you first connect to a board
2765 and your stack pointer and pc are nowhere in
2766 particular. This message needs to give people
2767 in that situation enough information to
2768 determine that it's no big deal. */
2769 printf_filtered ("\n\
2770 GDB is unable to find the start of the function at %s\n\
2771 and thus can't determine the size of that function's stack frame.\n\
2772 This means that GDB may be unable to access that stack frame, or\n\
2773 the frames below it.\n\
2774 This problem is most likely caused by an invalid program counter or\n\
2775 stack pointer.\n\
2776 However, if you think GDB should simply search farther back\n\
2777 from %s for code which looks like the beginning of a\n\
2778 function, you can increase the range of the search using the `set\n\
2779 heuristic-fence-post' command.\n",
2780 paddress (gdbarch, pc), paddress (gdbarch, pc));
2781 blurb_printed = 1;
2782 }
2783 }
2784
2785 return 0;
2786 }
2787 else if (mips_pc_is_mips16 (start_pc))
2788 {
2789 unsigned short inst;
2790
2791 /* On MIPS16, any one of the following is likely to be the
2792 start of a function:
2793 extend save
2794 save
2795 entry
2796 addiu sp,-n
2797 daddiu sp,-n
2798 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */
2799 inst = mips_fetch_instruction (gdbarch, start_pc);
2800 if ((inst & 0xff80) == 0x6480) /* save */
2801 {
2802 if (start_pc - instlen >= fence)
2803 {
2804 inst = mips_fetch_instruction (gdbarch, start_pc - instlen);
2805 if ((inst & 0xf800) == 0xf000) /* extend */
2806 start_pc -= instlen;
2807 }
2808 break;
2809 }
2810 else if (((inst & 0xf81f) == 0xe809
2811 && (inst & 0x700) != 0x700) /* entry */
2812 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2813 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2814 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
2815 break;
2816 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2817 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2818 seen_adjsp = 1;
2819 else
2820 seen_adjsp = 0;
2821 }
2822 else if (mips_about_to_return (gdbarch, start_pc))
2823 {
2824 /* Skip return and its delay slot. */
2825 start_pc += 2 * MIPS_INSN32_SIZE;
2826 break;
2827 }
2828
2829 return start_pc;
2830 }
2831
2832 struct mips_objfile_private
2833 {
2834 bfd_size_type size;
2835 char *contents;
2836 };
2837
2838 /* According to the current ABI, should the type be passed in a
2839 floating-point register (assuming that there is space)? When there
2840 is no FPU, FP are not even considered as possible candidates for
2841 FP registers and, consequently this returns false - forces FP
2842 arguments into integer registers. */
2843
2844 static int
2845 fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode,
2846 struct type *arg_type)
2847 {
2848 return ((typecode == TYPE_CODE_FLT
2849 || (MIPS_EABI (gdbarch)
2850 && (typecode == TYPE_CODE_STRUCT
2851 || typecode == TYPE_CODE_UNION)
2852 && TYPE_NFIELDS (arg_type) == 1
2853 && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0)))
2854 == TYPE_CODE_FLT))
2855 && MIPS_FPU_TYPE(gdbarch) != MIPS_FPU_NONE);
2856 }
2857
2858 /* On o32, argument passing in GPRs depends on the alignment of the type being
2859 passed. Return 1 if this type must be aligned to a doubleword boundary. */
2860
2861 static int
2862 mips_type_needs_double_align (struct type *type)
2863 {
2864 enum type_code typecode = TYPE_CODE (type);
2865
2866 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
2867 return 1;
2868 else if (typecode == TYPE_CODE_STRUCT)
2869 {
2870 if (TYPE_NFIELDS (type) < 1)
2871 return 0;
2872 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
2873 }
2874 else if (typecode == TYPE_CODE_UNION)
2875 {
2876 int i, n;
2877
2878 n = TYPE_NFIELDS (type);
2879 for (i = 0; i < n; i++)
2880 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
2881 return 1;
2882 return 0;
2883 }
2884 return 0;
2885 }
2886
2887 /* Adjust the address downward (direction of stack growth) so that it
2888 is correctly aligned for a new stack frame. */
2889 static CORE_ADDR
2890 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2891 {
2892 return align_down (addr, 16);
2893 }
2894
2895 static CORE_ADDR
2896 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2897 struct regcache *regcache, CORE_ADDR bp_addr,
2898 int nargs, struct value **args, CORE_ADDR sp,
2899 int struct_return, CORE_ADDR struct_addr)
2900 {
2901 int argreg;
2902 int float_argreg;
2903 int argnum;
2904 int len = 0;
2905 int stack_offset = 0;
2906 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2907 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2908 CORE_ADDR func_addr = find_function_addr (function, NULL);
2909 int regsize = mips_abi_regsize (gdbarch);
2910
2911 /* For shared libraries, "t9" needs to point at the function
2912 address. */
2913 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
2914
2915 /* Set the return address register to point to the entry point of
2916 the program, where a breakpoint lies in wait. */
2917 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
2918
2919 /* First ensure that the stack and structure return address (if any)
2920 are properly aligned. The stack has to be at least 64-bit
2921 aligned even on 32-bit machines, because doubles must be 64-bit
2922 aligned. For n32 and n64, stack frames need to be 128-bit
2923 aligned, so we round to this widest known alignment. */
2924
2925 sp = align_down (sp, 16);
2926 struct_addr = align_down (struct_addr, 16);
2927
2928 /* Now make space on the stack for the args. We allocate more
2929 than necessary for EABI, because the first few arguments are
2930 passed in registers, but that's OK. */
2931 for (argnum = 0; argnum < nargs; argnum++)
2932 len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize);
2933 sp -= align_up (len, 16);
2934
2935 if (mips_debug)
2936 fprintf_unfiltered (gdb_stdlog,
2937 "mips_eabi_push_dummy_call: sp=%s allocated %ld\n",
2938 paddress (gdbarch, sp), (long) align_up (len, 16));
2939
2940 /* Initialize the integer and float register pointers. */
2941 argreg = MIPS_A0_REGNUM;
2942 float_argreg = mips_fpa0_regnum (gdbarch);
2943
2944 /* The struct_return pointer occupies the first parameter-passing reg. */
2945 if (struct_return)
2946 {
2947 if (mips_debug)
2948 fprintf_unfiltered (gdb_stdlog,
2949 "mips_eabi_push_dummy_call: "
2950 "struct_return reg=%d %s\n",
2951 argreg, paddress (gdbarch, struct_addr));
2952 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
2953 }
2954
2955 /* Now load as many as possible of the first arguments into
2956 registers, and push the rest onto the stack. Loop thru args
2957 from first to last. */
2958 for (argnum = 0; argnum < nargs; argnum++)
2959 {
2960 const gdb_byte *val;
2961 gdb_byte valbuf[MAX_REGISTER_SIZE];
2962 struct value *arg = args[argnum];
2963 struct type *arg_type = check_typedef (value_type (arg));
2964 int len = TYPE_LENGTH (arg_type);
2965 enum type_code typecode = TYPE_CODE (arg_type);
2966
2967 if (mips_debug)
2968 fprintf_unfiltered (gdb_stdlog,
2969 "mips_eabi_push_dummy_call: %d len=%d type=%d",
2970 argnum + 1, len, (int) typecode);
2971
2972 /* Function pointer arguments to mips16 code need to be made into
2973 mips16 pointers. */
2974 if (typecode == TYPE_CODE_PTR
2975 && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC)
2976 {
2977 CORE_ADDR addr = extract_signed_integer (value_contents (arg),
2978 len, byte_order);
2979 if (mips_pc_is_mips16 (addr))
2980 {
2981 store_signed_integer (valbuf, len, byte_order,
2982 make_mips16_addr (addr));
2983 val = valbuf;
2984 }
2985 else
2986 val = value_contents (arg);
2987 }
2988 /* The EABI passes structures that do not fit in a register by
2989 reference. */
2990 else if (len > regsize
2991 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
2992 {
2993 store_unsigned_integer (valbuf, regsize, byte_order,
2994 value_address (arg));
2995 typecode = TYPE_CODE_PTR;
2996 len = regsize;
2997 val = valbuf;
2998 if (mips_debug)
2999 fprintf_unfiltered (gdb_stdlog, " push");
3000 }
3001 else
3002 val = value_contents (arg);
3003
3004 /* 32-bit ABIs always start floating point arguments in an
3005 even-numbered floating point register. Round the FP register
3006 up before the check to see if there are any FP registers
3007 left. Non MIPS_EABI targets also pass the FP in the integer
3008 registers so also round up normal registers. */
3009 if (regsize < 8 && fp_register_arg_p (gdbarch, typecode, arg_type))
3010 {
3011 if ((float_argreg & 1))
3012 float_argreg++;
3013 }
3014
3015 /* Floating point arguments passed in registers have to be
3016 treated specially. On 32-bit architectures, doubles
3017 are passed in register pairs; the even register gets
3018 the low word, and the odd register gets the high word.
3019 On non-EABI processors, the first two floating point arguments are
3020 also copied to general registers, because MIPS16 functions
3021 don't use float registers for arguments. This duplication of
3022 arguments in general registers can't hurt non-MIPS16 functions
3023 because those registers are normally skipped. */
3024 /* MIPS_EABI squeezes a struct that contains a single floating
3025 point value into an FP register instead of pushing it onto the
3026 stack. */
3027 if (fp_register_arg_p (gdbarch, typecode, arg_type)
3028 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
3029 {
3030 /* EABI32 will pass doubles in consecutive registers, even on
3031 64-bit cores. At one time, we used to check the size of
3032 `float_argreg' to determine whether or not to pass doubles
3033 in consecutive registers, but this is not sufficient for
3034 making the ABI determination. */
3035 if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32)
3036 {
3037 int low_offset = gdbarch_byte_order (gdbarch)
3038 == BFD_ENDIAN_BIG ? 4 : 0;
3039 long regval;
3040
3041 /* Write the low word of the double to the even register(s). */
3042 regval = extract_signed_integer (val + low_offset,
3043 4, byte_order);
3044 if (mips_debug)
3045 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3046 float_argreg, phex (regval, 4));
3047 regcache_cooked_write_signed (regcache, float_argreg++, regval);
3048
3049 /* Write the high word of the double to the odd register(s). */
3050 regval = extract_signed_integer (val + 4 - low_offset,
3051 4, byte_order);
3052 if (mips_debug)
3053 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3054 float_argreg, phex (regval, 4));
3055 regcache_cooked_write_signed (regcache, float_argreg++, regval);
3056 }
3057 else
3058 {
3059 /* This is a floating point value that fits entirely
3060 in a single register. */
3061 /* On 32 bit ABI's the float_argreg is further adjusted
3062 above to ensure that it is even register aligned. */
3063 LONGEST regval = extract_signed_integer (val, len, byte_order);
3064 if (mips_debug)
3065 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3066 float_argreg, phex (regval, len));
3067 regcache_cooked_write_signed (regcache, float_argreg++, regval);
3068 }
3069 }
3070 else
3071 {
3072 /* Copy the argument to general registers or the stack in
3073 register-sized pieces. Large arguments are split between
3074 registers and stack. */
3075 /* Note: structs whose size is not a multiple of regsize
3076 are treated specially: Irix cc passes
3077 them in registers where gcc sometimes puts them on the
3078 stack. For maximum compatibility, we will put them in
3079 both places. */
3080 int odd_sized_struct = (len > regsize && len % regsize != 0);
3081
3082 /* Note: Floating-point values that didn't fit into an FP
3083 register are only written to memory. */
3084 while (len > 0)
3085 {
3086 /* Remember if the argument was written to the stack. */
3087 int stack_used_p = 0;
3088 int partial_len = (len < regsize ? len : regsize);
3089
3090 if (mips_debug)
3091 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3092 partial_len);
3093
3094 /* Write this portion of the argument to the stack. */
3095 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
3096 || odd_sized_struct
3097 || fp_register_arg_p (gdbarch, typecode, arg_type))
3098 {
3099 /* Should shorter than int integer values be
3100 promoted to int before being stored? */
3101 int longword_offset = 0;
3102 CORE_ADDR addr;
3103 stack_used_p = 1;
3104 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3105 {
3106 if (regsize == 8
3107 && (typecode == TYPE_CODE_INT
3108 || typecode == TYPE_CODE_PTR
3109 || typecode == TYPE_CODE_FLT) && len <= 4)
3110 longword_offset = regsize - len;
3111 else if ((typecode == TYPE_CODE_STRUCT
3112 || typecode == TYPE_CODE_UNION)
3113 && TYPE_LENGTH (arg_type) < regsize)
3114 longword_offset = regsize - len;
3115 }
3116
3117 if (mips_debug)
3118 {
3119 fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s",
3120 paddress (gdbarch, stack_offset));
3121 fprintf_unfiltered (gdb_stdlog, " longword_offset=%s",
3122 paddress (gdbarch, longword_offset));
3123 }
3124
3125 addr = sp + stack_offset + longword_offset;
3126
3127 if (mips_debug)
3128 {
3129 int i;
3130 fprintf_unfiltered (gdb_stdlog, " @%s ",
3131 paddress (gdbarch, addr));
3132 for (i = 0; i < partial_len; i++)
3133 {
3134 fprintf_unfiltered (gdb_stdlog, "%02x",
3135 val[i] & 0xff);
3136 }
3137 }
3138 write_memory (addr, val, partial_len);
3139 }
3140
3141 /* Note!!! This is NOT an else clause. Odd sized
3142 structs may go thru BOTH paths. Floating point
3143 arguments will not. */
3144 /* Write this portion of the argument to a general
3145 purpose register. */
3146 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)
3147 && !fp_register_arg_p (gdbarch, typecode, arg_type))
3148 {
3149 LONGEST regval =
3150 extract_signed_integer (val, partial_len, byte_order);
3151
3152 if (mips_debug)
3153 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3154 argreg,
3155 phex (regval, regsize));
3156 regcache_cooked_write_signed (regcache, argreg, regval);
3157 argreg++;
3158 }
3159
3160 len -= partial_len;
3161 val += partial_len;
3162
3163 /* Compute the offset into the stack at which we will
3164 copy the next parameter.
3165
3166 In the new EABI (and the NABI32), the stack_offset
3167 only needs to be adjusted when it has been used. */
3168
3169 if (stack_used_p)
3170 stack_offset += align_up (partial_len, regsize);
3171 }
3172 }
3173 if (mips_debug)
3174 fprintf_unfiltered (gdb_stdlog, "\n");
3175 }
3176
3177 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3178
3179 /* Return adjusted stack pointer. */
3180 return sp;
3181 }
3182
3183 /* Determine the return value convention being used. */
3184
3185 static enum return_value_convention
3186 mips_eabi_return_value (struct gdbarch *gdbarch, struct type *func_type,
3187 struct type *type, struct regcache *regcache,
3188 gdb_byte *readbuf, const gdb_byte *writebuf)
3189 {
3190 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3191 int fp_return_type = 0;
3192 int offset, regnum, xfer;
3193
3194 if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch))
3195 return RETURN_VALUE_STRUCT_CONVENTION;
3196
3197 /* Floating point type? */
3198 if (tdep->mips_fpu_type != MIPS_FPU_NONE)
3199 {
3200 if (TYPE_CODE (type) == TYPE_CODE_FLT)
3201 fp_return_type = 1;
3202 /* Structs with a single field of float type
3203 are returned in a floating point register. */
3204 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
3205 || TYPE_CODE (type) == TYPE_CODE_UNION)
3206 && TYPE_NFIELDS (type) == 1)
3207 {
3208 struct type *fieldtype = TYPE_FIELD_TYPE (type, 0);
3209
3210 if (TYPE_CODE (check_typedef (fieldtype)) == TYPE_CODE_FLT)
3211 fp_return_type = 1;
3212 }
3213 }
3214
3215 if (fp_return_type)
3216 {
3217 /* A floating-point value belongs in the least significant part
3218 of FP0/FP1. */
3219 if (mips_debug)
3220 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
3221 regnum = mips_regnum (gdbarch)->fp0;
3222 }
3223 else
3224 {
3225 /* An integer value goes in V0/V1. */
3226 if (mips_debug)
3227 fprintf_unfiltered (gdb_stderr, "Return scalar in $v0\n");
3228 regnum = MIPS_V0_REGNUM;
3229 }
3230 for (offset = 0;
3231 offset < TYPE_LENGTH (type);
3232 offset += mips_abi_regsize (gdbarch), regnum++)
3233 {
3234 xfer = mips_abi_regsize (gdbarch);
3235 if (offset + xfer > TYPE_LENGTH (type))
3236 xfer = TYPE_LENGTH (type) - offset;
3237 mips_xfer_register (gdbarch, regcache,
3238 gdbarch_num_regs (gdbarch) + regnum, xfer,
3239 gdbarch_byte_order (gdbarch), readbuf, writebuf,
3240 offset);
3241 }
3242
3243 return RETURN_VALUE_REGISTER_CONVENTION;
3244 }
3245
3246
3247 /* N32/N64 ABI stuff. */
3248
3249 /* Search for a naturally aligned double at OFFSET inside a struct
3250 ARG_TYPE. The N32 / N64 ABIs pass these in floating point
3251 registers. */
3252
3253 static int
3254 mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type,
3255 int offset)
3256 {
3257 int i;
3258
3259 if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT)
3260 return 0;
3261
3262 if (MIPS_FPU_TYPE (gdbarch) != MIPS_FPU_DOUBLE)
3263 return 0;
3264
3265 if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE)
3266 return 0;
3267
3268 for (i = 0; i < TYPE_NFIELDS (arg_type); i++)
3269 {
3270 int pos;
3271 struct type *field_type;
3272
3273 /* We're only looking at normal fields. */
3274 if (field_is_static (&TYPE_FIELD (arg_type, i))
3275 || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0)
3276 continue;
3277
3278 /* If we have gone past the offset, there is no double to pass. */
3279 pos = TYPE_FIELD_BITPOS (arg_type, i) / 8;
3280 if (pos > offset)
3281 return 0;
3282
3283 field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i));
3284
3285 /* If this field is entirely before the requested offset, go
3286 on to the next one. */
3287 if (pos + TYPE_LENGTH (field_type) <= offset)
3288 continue;
3289
3290 /* If this is our special aligned double, we can stop. */
3291 if (TYPE_CODE (field_type) == TYPE_CODE_FLT
3292 && TYPE_LENGTH (field_type) == MIPS64_REGSIZE)
3293 return 1;
3294
3295 /* This field starts at or before the requested offset, and
3296 overlaps it. If it is a structure, recurse inwards. */
3297 return mips_n32n64_fp_arg_chunk_p (gdbarch, field_type, offset - pos);
3298 }
3299
3300 return 0;
3301 }
3302
3303 static CORE_ADDR
3304 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3305 struct regcache *regcache, CORE_ADDR bp_addr,
3306 int nargs, struct value **args, CORE_ADDR sp,
3307 int struct_return, CORE_ADDR struct_addr)
3308 {
3309 int argreg;
3310 int float_argreg;
3311 int argnum;
3312 int len = 0;
3313 int stack_offset = 0;
3314 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3315 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3316 CORE_ADDR func_addr = find_function_addr (function, NULL);
3317
3318 /* For shared libraries, "t9" needs to point at the function
3319 address. */
3320 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
3321
3322 /* Set the return address register to point to the entry point of
3323 the program, where a breakpoint lies in wait. */
3324 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
3325
3326 /* First ensure that the stack and structure return address (if any)
3327 are properly aligned. The stack has to be at least 64-bit
3328 aligned even on 32-bit machines, because doubles must be 64-bit
3329 aligned. For n32 and n64, stack frames need to be 128-bit
3330 aligned, so we round to this widest known alignment. */
3331
3332 sp = align_down (sp, 16);
3333 struct_addr = align_down (struct_addr, 16);
3334
3335 /* Now make space on the stack for the args. */
3336 for (argnum = 0; argnum < nargs; argnum++)
3337 len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE);
3338 sp -= align_up (len, 16);
3339
3340 if (mips_debug)
3341 fprintf_unfiltered (gdb_stdlog,
3342 "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n",
3343 paddress (gdbarch, sp), (long) align_up (len, 16));
3344
3345 /* Initialize the integer and float register pointers. */
3346 argreg = MIPS_A0_REGNUM;
3347 float_argreg = mips_fpa0_regnum (gdbarch);
3348
3349 /* The struct_return pointer occupies the first parameter-passing reg. */
3350 if (struct_return)
3351 {
3352 if (mips_debug)
3353 fprintf_unfiltered (gdb_stdlog,
3354 "mips_n32n64_push_dummy_call: "
3355 "struct_return reg=%d %s\n",
3356 argreg, paddress (gdbarch, struct_addr));
3357 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
3358 }
3359
3360 /* Now load as many as possible of the first arguments into
3361 registers, and push the rest onto the stack. Loop thru args
3362 from first to last. */
3363 for (argnum = 0; argnum < nargs; argnum++)
3364 {
3365 const gdb_byte *val;
3366 struct value *arg = args[argnum];
3367 struct type *arg_type = check_typedef (value_type (arg));
3368 int len = TYPE_LENGTH (arg_type);
3369 enum type_code typecode = TYPE_CODE (arg_type);
3370
3371 if (mips_debug)
3372 fprintf_unfiltered (gdb_stdlog,
3373 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3374 argnum + 1, len, (int) typecode);
3375
3376 val = value_contents (arg);
3377
3378 /* A 128-bit long double value requires an even-odd pair of
3379 floating-point registers. */
3380 if (len == 16
3381 && fp_register_arg_p (gdbarch, typecode, arg_type)
3382 && (float_argreg & 1))
3383 {
3384 float_argreg++;
3385 argreg++;
3386 }
3387
3388 if (fp_register_arg_p (gdbarch, typecode, arg_type)
3389 && argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3390 {
3391 /* This is a floating point value that fits entirely
3392 in a single register or a pair of registers. */
3393 int reglen = (len <= MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
3394 LONGEST regval = extract_unsigned_integer (val, reglen, byte_order);
3395 if (mips_debug)
3396 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3397 float_argreg, phex (regval, reglen));
3398 regcache_cooked_write_unsigned (regcache, float_argreg, regval);
3399
3400 if (mips_debug)
3401 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3402 argreg, phex (regval, reglen));
3403 regcache_cooked_write_unsigned (regcache, argreg, regval);
3404 float_argreg++;
3405 argreg++;
3406 if (len == 16)
3407 {
3408 regval = extract_unsigned_integer (val + reglen,
3409 reglen, byte_order);
3410 if (mips_debug)
3411 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3412 float_argreg, phex (regval, reglen));
3413 regcache_cooked_write_unsigned (regcache, float_argreg, regval);
3414
3415 if (mips_debug)
3416 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3417 argreg, phex (regval, reglen));
3418 regcache_cooked_write_unsigned (regcache, argreg, regval);
3419 float_argreg++;
3420 argreg++;
3421 }
3422 }
3423 else
3424 {
3425 /* Copy the argument to general registers or the stack in
3426 register-sized pieces. Large arguments are split between
3427 registers and stack. */
3428 /* For N32/N64, structs, unions, or other composite types are
3429 treated as a sequence of doublewords, and are passed in integer
3430 or floating point registers as though they were simple scalar
3431 parameters to the extent that they fit, with any excess on the
3432 stack packed according to the normal memory layout of the
3433 object.
3434 The caller does not reserve space for the register arguments;
3435 the callee is responsible for reserving it if required. */
3436 /* Note: Floating-point values that didn't fit into an FP
3437 register are only written to memory. */
3438 while (len > 0)
3439 {
3440 /* Remember if the argument was written to the stack. */
3441 int stack_used_p = 0;
3442 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
3443
3444 if (mips_debug)
3445 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3446 partial_len);
3447
3448 if (fp_register_arg_p (gdbarch, typecode, arg_type))
3449 gdb_assert (argreg > MIPS_LAST_ARG_REGNUM (gdbarch));
3450
3451 /* Write this portion of the argument to the stack. */
3452 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch))
3453 {
3454 /* Should shorter than int integer values be
3455 promoted to int before being stored? */
3456 int longword_offset = 0;
3457 CORE_ADDR addr;
3458 stack_used_p = 1;
3459 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
3460 {
3461 if ((typecode == TYPE_CODE_INT
3462 || typecode == TYPE_CODE_PTR)
3463 && len <= 4)
3464 longword_offset = MIPS64_REGSIZE - len;
3465 }
3466
3467 if (mips_debug)
3468 {
3469 fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s",
3470 paddress (gdbarch, stack_offset));
3471 fprintf_unfiltered (gdb_stdlog, " longword_offset=%s",
3472 paddress (gdbarch, longword_offset));
3473 }
3474
3475 addr = sp + stack_offset + longword_offset;
3476
3477 if (mips_debug)
3478 {
3479 int i;
3480 fprintf_unfiltered (gdb_stdlog, " @%s ",
3481 paddress (gdbarch, addr));
3482 for (i = 0; i < partial_len; i++)
3483 {
3484 fprintf_unfiltered (gdb_stdlog, "%02x",
3485 val[i] & 0xff);
3486 }
3487 }
3488 write_memory (addr, val, partial_len);
3489 }
3490
3491 /* Note!!! This is NOT an else clause. Odd sized
3492 structs may go thru BOTH paths. */
3493 /* Write this portion of the argument to a general
3494 purpose register. */
3495 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3496 {
3497 LONGEST regval;
3498
3499 /* Sign extend pointers, 32-bit integers and signed
3500 16-bit and 8-bit integers; everything else is taken
3501 as is. */
3502
3503 if ((partial_len == 4
3504 && (typecode == TYPE_CODE_PTR
3505 || typecode == TYPE_CODE_INT))
3506 || (partial_len < 4
3507 && typecode == TYPE_CODE_INT
3508 && !TYPE_UNSIGNED (arg_type)))
3509 regval = extract_signed_integer (val, partial_len,
3510 byte_order);
3511 else
3512 regval = extract_unsigned_integer (val, partial_len,
3513 byte_order);
3514
3515 /* A non-floating-point argument being passed in a
3516 general register. If a struct or union, and if
3517 the remaining length is smaller than the register
3518 size, we have to adjust the register value on
3519 big endian targets.
3520
3521 It does not seem to be necessary to do the
3522 same for integral types. */
3523
3524 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
3525 && partial_len < MIPS64_REGSIZE
3526 && (typecode == TYPE_CODE_STRUCT
3527 || typecode == TYPE_CODE_UNION))
3528 regval <<= ((MIPS64_REGSIZE - partial_len)
3529 * TARGET_CHAR_BIT);
3530
3531 if (mips_debug)
3532 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3533 argreg,
3534 phex (regval, MIPS64_REGSIZE));
3535 regcache_cooked_write_unsigned (regcache, argreg, regval);
3536
3537 if (mips_n32n64_fp_arg_chunk_p (gdbarch, arg_type,
3538 TYPE_LENGTH (arg_type) - len))
3539 {
3540 if (mips_debug)
3541 fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s",
3542 float_argreg,
3543 phex (regval, MIPS64_REGSIZE));
3544 regcache_cooked_write_unsigned (regcache, float_argreg,
3545 regval);
3546 }
3547
3548 float_argreg++;
3549 argreg++;
3550 }
3551
3552 len -= partial_len;
3553 val += partial_len;
3554
3555 /* Compute the offset into the stack at which we will
3556 copy the next parameter.
3557
3558 In N32 (N64?), the stack_offset only needs to be
3559 adjusted when it has been used. */
3560
3561 if (stack_used_p)
3562 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
3563 }
3564 }
3565 if (mips_debug)
3566 fprintf_unfiltered (gdb_stdlog, "\n");
3567 }
3568
3569 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3570
3571 /* Return adjusted stack pointer. */
3572 return sp;
3573 }
3574
3575 static enum return_value_convention
3576 mips_n32n64_return_value (struct gdbarch *gdbarch, struct type *func_type,
3577 struct type *type, struct regcache *regcache,
3578 gdb_byte *readbuf, const gdb_byte *writebuf)
3579 {
3580 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3581
3582 /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
3583
3584 Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
3585 if needed), as appropriate for the type. Composite results (struct,
3586 union, or array) are returned in $2/$f0 and $3/$f2 according to the
3587 following rules:
3588
3589 * A struct with only one or two floating point fields is returned in $f0
3590 (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
3591 case.
3592
3593 * Any other composite results of at most 128 bits are returned in
3594 $2 (first 64 bits) and $3 (remainder, if necessary).
3595
3596 * Larger composite results are handled by converting the function to a
3597 procedure with an implicit first parameter, which is a pointer to an area
3598 reserved by the caller to receive the result. [The o32-bit ABI requires
3599 that all composite results be handled by conversion to implicit first
3600 parameters. The MIPS/SGI Fortran implementation has always made a
3601 specific exception to return COMPLEX results in the floating point
3602 registers.] */
3603
3604 if (TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE)
3605 return RETURN_VALUE_STRUCT_CONVENTION;
3606 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3607 && TYPE_LENGTH (type) == 16
3608 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3609 {
3610 /* A 128-bit floating-point value fills both $f0 and $f2. The
3611 two registers are used in the same as memory order, so the
3612 eight bytes with the lower memory address are in $f0. */
3613 if (mips_debug)
3614 fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n");
3615 mips_xfer_register (gdbarch, regcache,
3616 gdbarch_num_regs (gdbarch)
3617 + mips_regnum (gdbarch)->fp0,
3618 8, gdbarch_byte_order (gdbarch),
3619 readbuf, writebuf, 0);
3620 mips_xfer_register (gdbarch, regcache,
3621 gdbarch_num_regs (gdbarch)
3622 + mips_regnum (gdbarch)->fp0 + 2,
3623 8, gdbarch_byte_order (gdbarch),
3624 readbuf ? readbuf + 8 : readbuf,
3625 writebuf ? writebuf + 8 : writebuf, 0);
3626 return RETURN_VALUE_REGISTER_CONVENTION;
3627 }
3628 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3629 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3630 {
3631 /* A single or double floating-point value that fits in FP0. */
3632 if (mips_debug)
3633 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
3634 mips_xfer_register (gdbarch, regcache,
3635 gdbarch_num_regs (gdbarch)
3636 + mips_regnum (gdbarch)->fp0,
3637 TYPE_LENGTH (type),
3638 gdbarch_byte_order (gdbarch),
3639 readbuf, writebuf, 0);
3640 return RETURN_VALUE_REGISTER_CONVENTION;
3641 }
3642 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3643 && TYPE_NFIELDS (type) <= 2
3644 && TYPE_NFIELDS (type) >= 1
3645 && ((TYPE_NFIELDS (type) == 1
3646 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
3647 == TYPE_CODE_FLT))
3648 || (TYPE_NFIELDS (type) == 2
3649 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0)))
3650 == TYPE_CODE_FLT)
3651 && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1)))
3652 == TYPE_CODE_FLT))))
3653 {
3654 /* A struct that contains one or two floats. Each value is part
3655 in the least significant part of their floating point
3656 register (or GPR, for soft float). */
3657 int regnum;
3658 int field;
3659 for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE
3660 ? mips_regnum (gdbarch)->fp0
3661 : MIPS_V0_REGNUM);
3662 field < TYPE_NFIELDS (type); field++, regnum += 2)
3663 {
3664 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3665 / TARGET_CHAR_BIT);
3666 if (mips_debug)
3667 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3668 offset);
3669 if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)) == 16)
3670 {
3671 /* A 16-byte long double field goes in two consecutive
3672 registers. */
3673 mips_xfer_register (gdbarch, regcache,
3674 gdbarch_num_regs (gdbarch) + regnum,
3675 8,
3676 gdbarch_byte_order (gdbarch),
3677 readbuf, writebuf, offset);
3678 mips_xfer_register (gdbarch, regcache,
3679 gdbarch_num_regs (gdbarch) + regnum + 1,
3680 8,
3681 gdbarch_byte_order (gdbarch),
3682 readbuf, writebuf, offset + 8);
3683 }
3684 else
3685 mips_xfer_register (gdbarch, regcache,
3686 gdbarch_num_regs (gdbarch) + regnum,
3687 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
3688 gdbarch_byte_order (gdbarch),
3689 readbuf, writebuf, offset);
3690 }
3691 return RETURN_VALUE_REGISTER_CONVENTION;
3692 }
3693 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3694 || TYPE_CODE (type) == TYPE_CODE_UNION
3695 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
3696 {
3697 /* A composite type. Extract the left justified value,
3698 regardless of the byte order. I.e. DO NOT USE
3699 mips_xfer_lower. */
3700 int offset;
3701 int regnum;
3702 for (offset = 0, regnum = MIPS_V0_REGNUM;
3703 offset < TYPE_LENGTH (type);
3704 offset += register_size (gdbarch, regnum), regnum++)
3705 {
3706 int xfer = register_size (gdbarch, regnum);
3707 if (offset + xfer > TYPE_LENGTH (type))
3708 xfer = TYPE_LENGTH (type) - offset;
3709 if (mips_debug)
3710 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3711 offset, xfer, regnum);
3712 mips_xfer_register (gdbarch, regcache,
3713 gdbarch_num_regs (gdbarch) + regnum,
3714 xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf,
3715 offset);
3716 }
3717 return RETURN_VALUE_REGISTER_CONVENTION;
3718 }
3719 else
3720 {
3721 /* A scalar extract each part but least-significant-byte
3722 justified. */
3723 int offset;
3724 int regnum;
3725 for (offset = 0, regnum = MIPS_V0_REGNUM;
3726 offset < TYPE_LENGTH (type);
3727 offset += register_size (gdbarch, regnum), regnum++)
3728 {
3729 int xfer = register_size (gdbarch, regnum);
3730 if (offset + xfer > TYPE_LENGTH (type))
3731 xfer = TYPE_LENGTH (type) - offset;
3732 if (mips_debug)
3733 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3734 offset, xfer, regnum);
3735 mips_xfer_register (gdbarch, regcache,
3736 gdbarch_num_regs (gdbarch) + regnum,
3737 xfer, gdbarch_byte_order (gdbarch),
3738 readbuf, writebuf, offset);
3739 }
3740 return RETURN_VALUE_REGISTER_CONVENTION;
3741 }
3742 }
3743
3744 /* O32 ABI stuff. */
3745
3746 static CORE_ADDR
3747 mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3748 struct regcache *regcache, CORE_ADDR bp_addr,
3749 int nargs, struct value **args, CORE_ADDR sp,
3750 int struct_return, CORE_ADDR struct_addr)
3751 {
3752 int argreg;
3753 int float_argreg;
3754 int argnum;
3755 int len = 0;
3756 int stack_offset = 0;
3757 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3758 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3759 CORE_ADDR func_addr = find_function_addr (function, NULL);
3760
3761 /* For shared libraries, "t9" needs to point at the function
3762 address. */
3763 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
3764
3765 /* Set the return address register to point to the entry point of
3766 the program, where a breakpoint lies in wait. */
3767 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
3768
3769 /* First ensure that the stack and structure return address (if any)
3770 are properly aligned. The stack has to be at least 64-bit
3771 aligned even on 32-bit machines, because doubles must be 64-bit
3772 aligned. For n32 and n64, stack frames need to be 128-bit
3773 aligned, so we round to this widest known alignment. */
3774
3775 sp = align_down (sp, 16);
3776 struct_addr = align_down (struct_addr, 16);
3777
3778 /* Now make space on the stack for the args. */
3779 for (argnum = 0; argnum < nargs; argnum++)
3780 {
3781 struct type *arg_type = check_typedef (value_type (args[argnum]));
3782 int arglen = TYPE_LENGTH (arg_type);
3783
3784 /* Align to double-word if necessary. */
3785 if (mips_type_needs_double_align (arg_type))
3786 len = align_up (len, MIPS32_REGSIZE * 2);
3787 /* Allocate space on the stack. */
3788 len += align_up (arglen, MIPS32_REGSIZE);
3789 }
3790 sp -= align_up (len, 16);
3791
3792 if (mips_debug)
3793 fprintf_unfiltered (gdb_stdlog,
3794 "mips_o32_push_dummy_call: sp=%s allocated %ld\n",
3795 paddress (gdbarch, sp), (long) align_up (len, 16));
3796
3797 /* Initialize the integer and float register pointers. */
3798 argreg = MIPS_A0_REGNUM;
3799 float_argreg = mips_fpa0_regnum (gdbarch);
3800
3801 /* The struct_return pointer occupies the first parameter-passing reg. */
3802 if (struct_return)
3803 {
3804 if (mips_debug)
3805 fprintf_unfiltered (gdb_stdlog,
3806 "mips_o32_push_dummy_call: "
3807 "struct_return reg=%d %s\n",
3808 argreg, paddress (gdbarch, struct_addr));
3809 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
3810 stack_offset += MIPS32_REGSIZE;
3811 }
3812
3813 /* Now load as many as possible of the first arguments into
3814 registers, and push the rest onto the stack. Loop thru args
3815 from first to last. */
3816 for (argnum = 0; argnum < nargs; argnum++)
3817 {
3818 const gdb_byte *val;
3819 struct value *arg = args[argnum];
3820 struct type *arg_type = check_typedef (value_type (arg));
3821 int len = TYPE_LENGTH (arg_type);
3822 enum type_code typecode = TYPE_CODE (arg_type);
3823
3824 if (mips_debug)
3825 fprintf_unfiltered (gdb_stdlog,
3826 "mips_o32_push_dummy_call: %d len=%d type=%d",
3827 argnum + 1, len, (int) typecode);
3828
3829 val = value_contents (arg);
3830
3831 /* 32-bit ABIs always start floating point arguments in an
3832 even-numbered floating point register. Round the FP register
3833 up before the check to see if there are any FP registers
3834 left. O32/O64 targets also pass the FP in the integer
3835 registers so also round up normal registers. */
3836 if (fp_register_arg_p (gdbarch, typecode, arg_type))
3837 {
3838 if ((float_argreg & 1))
3839 float_argreg++;
3840 }
3841
3842 /* Floating point arguments passed in registers have to be
3843 treated specially. On 32-bit architectures, doubles
3844 are passed in register pairs; the even register gets
3845 the low word, and the odd register gets the high word.
3846 On O32/O64, the first two floating point arguments are
3847 also copied to general registers, because MIPS16 functions
3848 don't use float registers for arguments. This duplication of
3849 arguments in general registers can't hurt non-MIPS16 functions
3850 because those registers are normally skipped. */
3851
3852 if (fp_register_arg_p (gdbarch, typecode, arg_type)
3853 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
3854 {
3855 if (register_size (gdbarch, float_argreg) < 8 && len == 8)
3856 {
3857 int low_offset = gdbarch_byte_order (gdbarch)
3858 == BFD_ENDIAN_BIG ? 4 : 0;
3859 unsigned long regval;
3860
3861 /* Write the low word of the double to the even register(s). */
3862 regval = extract_unsigned_integer (val + low_offset,
3863 4, byte_order);
3864 if (mips_debug)
3865 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3866 float_argreg, phex (regval, 4));
3867 regcache_cooked_write_unsigned (regcache,
3868 float_argreg++, regval);
3869 if (mips_debug)
3870 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3871 argreg, phex (regval, 4));
3872 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3873
3874 /* Write the high word of the double to the odd register(s). */
3875 regval = extract_unsigned_integer (val + 4 - low_offset,
3876 4, byte_order);
3877 if (mips_debug)
3878 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3879 float_argreg, phex (regval, 4));
3880 regcache_cooked_write_unsigned (regcache,
3881 float_argreg++, regval);
3882
3883 if (mips_debug)
3884 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3885 argreg, phex (regval, 4));
3886 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3887 }
3888 else
3889 {
3890 /* This is a floating point value that fits entirely
3891 in a single register. */
3892 /* On 32 bit ABI's the float_argreg is further adjusted
3893 above to ensure that it is even register aligned. */
3894 LONGEST regval = extract_unsigned_integer (val, len, byte_order);
3895 if (mips_debug)
3896 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3897 float_argreg, phex (regval, len));
3898 regcache_cooked_write_unsigned (regcache,
3899 float_argreg++, regval);
3900 /* Although two FP registers are reserved for each
3901 argument, only one corresponding integer register is
3902 reserved. */
3903 if (mips_debug)
3904 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3905 argreg, phex (regval, len));
3906 regcache_cooked_write_unsigned (regcache, argreg++, regval);
3907 }
3908 /* Reserve space for the FP register. */
3909 stack_offset += align_up (len, MIPS32_REGSIZE);
3910 }
3911 else
3912 {
3913 /* Copy the argument to general registers or the stack in
3914 register-sized pieces. Large arguments are split between
3915 registers and stack. */
3916 /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
3917 are treated specially: Irix cc passes
3918 them in registers where gcc sometimes puts them on the
3919 stack. For maximum compatibility, we will put them in
3920 both places. */
3921 int odd_sized_struct = (len > MIPS32_REGSIZE
3922 && len % MIPS32_REGSIZE != 0);
3923 /* Structures should be aligned to eight bytes (even arg registers)
3924 on MIPS_ABI_O32, if their first member has double precision. */
3925 if (mips_type_needs_double_align (arg_type))
3926 {
3927 if ((argreg & 1))
3928 {
3929 argreg++;
3930 stack_offset += MIPS32_REGSIZE;
3931 }
3932 }
3933 while (len > 0)
3934 {
3935 /* Remember if the argument was written to the stack. */
3936 int stack_used_p = 0;
3937 int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE);
3938
3939 if (mips_debug)
3940 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3941 partial_len);
3942
3943 /* Write this portion of the argument to the stack. */
3944 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
3945 || odd_sized_struct)
3946 {
3947 /* Should shorter than int integer values be
3948 promoted to int before being stored? */
3949 int longword_offset = 0;
3950 CORE_ADDR addr;
3951 stack_used_p = 1;
3952
3953 if (mips_debug)
3954 {
3955 fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s",
3956 paddress (gdbarch, stack_offset));
3957 fprintf_unfiltered (gdb_stdlog, " longword_offset=%s",
3958 paddress (gdbarch, longword_offset));
3959 }
3960
3961 addr = sp + stack_offset + longword_offset;
3962
3963 if (mips_debug)
3964 {
3965 int i;
3966 fprintf_unfiltered (gdb_stdlog, " @%s ",
3967 paddress (gdbarch, addr));
3968 for (i = 0; i < partial_len; i++)
3969 {
3970 fprintf_unfiltered (gdb_stdlog, "%02x",
3971 val[i] & 0xff);
3972 }
3973 }
3974 write_memory (addr, val, partial_len);
3975 }
3976
3977 /* Note!!! This is NOT an else clause. Odd sized
3978 structs may go thru BOTH paths. */
3979 /* Write this portion of the argument to a general
3980 purpose register. */
3981 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
3982 {
3983 LONGEST regval = extract_signed_integer (val, partial_len,
3984 byte_order);
3985 /* Value may need to be sign extended, because
3986 mips_isa_regsize() != mips_abi_regsize(). */
3987
3988 /* A non-floating-point argument being passed in a
3989 general register. If a struct or union, and if
3990 the remaining length is smaller than the register
3991 size, we have to adjust the register value on
3992 big endian targets.
3993
3994 It does not seem to be necessary to do the
3995 same for integral types.
3996
3997 Also don't do this adjustment on O64 binaries.
3998
3999 cagney/2001-07-23: gdb/179: Also, GCC, when
4000 outputting LE O32 with sizeof (struct) <
4001 mips_abi_regsize(), generates a left shift
4002 as part of storing the argument in a register
4003 (the left shift isn't generated when
4004 sizeof (struct) >= mips_abi_regsize()). Since
4005 it is quite possible that this is GCC
4006 contradicting the LE/O32 ABI, GDB has not been
4007 adjusted to accommodate this. Either someone
4008 needs to demonstrate that the LE/O32 ABI
4009 specifies such a left shift OR this new ABI gets
4010 identified as such and GDB gets tweaked
4011 accordingly. */
4012
4013 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
4014 && partial_len < MIPS32_REGSIZE
4015 && (typecode == TYPE_CODE_STRUCT
4016 || typecode == TYPE_CODE_UNION))
4017 regval <<= ((MIPS32_REGSIZE - partial_len)
4018 * TARGET_CHAR_BIT);
4019
4020 if (mips_debug)
4021 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4022 argreg,
4023 phex (regval, MIPS32_REGSIZE));
4024 regcache_cooked_write_unsigned (regcache, argreg, regval);
4025 argreg++;
4026
4027 /* Prevent subsequent floating point arguments from
4028 being passed in floating point registers. */
4029 float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1;
4030 }
4031
4032 len -= partial_len;
4033 val += partial_len;
4034
4035 /* Compute the offset into the stack at which we will
4036 copy the next parameter.
4037
4038 In older ABIs, the caller reserved space for
4039 registers that contained arguments. This was loosely
4040 refered to as their "home". Consequently, space is
4041 always allocated. */
4042
4043 stack_offset += align_up (partial_len, MIPS32_REGSIZE);
4044 }
4045 }
4046 if (mips_debug)
4047 fprintf_unfiltered (gdb_stdlog, "\n");
4048 }
4049
4050 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
4051
4052 /* Return adjusted stack pointer. */
4053 return sp;
4054 }
4055
4056 static enum return_value_convention
4057 mips_o32_return_value (struct gdbarch *gdbarch, struct type *func_type,
4058 struct type *type, struct regcache *regcache,
4059 gdb_byte *readbuf, const gdb_byte *writebuf)
4060 {
4061 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4062
4063 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4064 || TYPE_CODE (type) == TYPE_CODE_UNION
4065 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
4066 return RETURN_VALUE_STRUCT_CONVENTION;
4067 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4068 && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4069 {
4070 /* A single-precision floating-point value. It fits in the
4071 least significant part of FP0. */
4072 if (mips_debug)
4073 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4074 mips_xfer_register (gdbarch, regcache,
4075 gdbarch_num_regs (gdbarch)
4076 + mips_regnum (gdbarch)->fp0,
4077 TYPE_LENGTH (type),
4078 gdbarch_byte_order (gdbarch),
4079 readbuf, writebuf, 0);
4080 return RETURN_VALUE_REGISTER_CONVENTION;
4081 }
4082 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4083 && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4084 {
4085 /* A double-precision floating-point value. The most
4086 significant part goes in FP1, and the least significant in
4087 FP0. */
4088 if (mips_debug)
4089 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
4090 switch (gdbarch_byte_order (gdbarch))
4091 {
4092 case BFD_ENDIAN_LITTLE:
4093 mips_xfer_register (gdbarch, regcache,
4094 gdbarch_num_regs (gdbarch)
4095 + mips_regnum (gdbarch)->fp0 +
4096 0, 4, gdbarch_byte_order (gdbarch),
4097 readbuf, writebuf, 0);
4098 mips_xfer_register (gdbarch, regcache,
4099 gdbarch_num_regs (gdbarch)
4100 + mips_regnum (gdbarch)->fp0 + 1,
4101 4, gdbarch_byte_order (gdbarch),
4102 readbuf, writebuf, 4);
4103 break;
4104 case BFD_ENDIAN_BIG:
4105 mips_xfer_register (gdbarch, regcache,
4106 gdbarch_num_regs (gdbarch)
4107 + mips_regnum (gdbarch)->fp0 + 1,
4108 4, gdbarch_byte_order (gdbarch),
4109 readbuf, writebuf, 0);
4110 mips_xfer_register (gdbarch, regcache,
4111 gdbarch_num_regs (gdbarch)
4112 + mips_regnum (gdbarch)->fp0 + 0,
4113 4, gdbarch_byte_order (gdbarch),
4114 readbuf, writebuf, 4);
4115 break;
4116 default:
4117 internal_error (__FILE__, __LINE__, _("bad switch"));
4118 }
4119 return RETURN_VALUE_REGISTER_CONVENTION;
4120 }
4121 #if 0
4122 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4123 && TYPE_NFIELDS (type) <= 2
4124 && TYPE_NFIELDS (type) >= 1
4125 && ((TYPE_NFIELDS (type) == 1
4126 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4127 == TYPE_CODE_FLT))
4128 || (TYPE_NFIELDS (type) == 2
4129 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4130 == TYPE_CODE_FLT)
4131 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4132 == TYPE_CODE_FLT)))
4133 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4134 {
4135 /* A struct that contains one or two floats. Each value is part
4136 in the least significant part of their floating point
4137 register.. */
4138 gdb_byte reg[MAX_REGISTER_SIZE];
4139 int regnum;
4140 int field;
4141 for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
4142 field < TYPE_NFIELDS (type); field++, regnum += 2)
4143 {
4144 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4145 / TARGET_CHAR_BIT);
4146 if (mips_debug)
4147 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
4148 offset);
4149 mips_xfer_register (gdbarch, regcache,
4150 gdbarch_num_regs (gdbarch) + regnum,
4151 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4152 gdbarch_byte_order (gdbarch),
4153 readbuf, writebuf, offset);
4154 }
4155 return RETURN_VALUE_REGISTER_CONVENTION;
4156 }
4157 #endif
4158 #if 0
4159 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4160 || TYPE_CODE (type) == TYPE_CODE_UNION)
4161 {
4162 /* A structure or union. Extract the left justified value,
4163 regardless of the byte order. I.e. DO NOT USE
4164 mips_xfer_lower. */
4165 int offset;
4166 int regnum;
4167 for (offset = 0, regnum = MIPS_V0_REGNUM;
4168 offset < TYPE_LENGTH (type);
4169 offset += register_size (gdbarch, regnum), regnum++)
4170 {
4171 int xfer = register_size (gdbarch, regnum);
4172 if (offset + xfer > TYPE_LENGTH (type))
4173 xfer = TYPE_LENGTH (type) - offset;
4174 if (mips_debug)
4175 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4176 offset, xfer, regnum);
4177 mips_xfer_register (gdbarch, regcache,
4178 gdbarch_num_regs (gdbarch) + regnum, xfer,
4179 BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
4180 }
4181 return RETURN_VALUE_REGISTER_CONVENTION;
4182 }
4183 #endif
4184 else
4185 {
4186 /* A scalar extract each part but least-significant-byte
4187 justified. o32 thinks registers are 4 byte, regardless of
4188 the ISA. */
4189 int offset;
4190 int regnum;
4191 for (offset = 0, regnum = MIPS_V0_REGNUM;
4192 offset < TYPE_LENGTH (type);
4193 offset += MIPS32_REGSIZE, regnum++)
4194 {
4195 int xfer = MIPS32_REGSIZE;
4196 if (offset + xfer > TYPE_LENGTH (type))
4197 xfer = TYPE_LENGTH (type) - offset;
4198 if (mips_debug)
4199 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4200 offset, xfer, regnum);
4201 mips_xfer_register (gdbarch, regcache,
4202 gdbarch_num_regs (gdbarch) + regnum, xfer,
4203 gdbarch_byte_order (gdbarch),
4204 readbuf, writebuf, offset);
4205 }
4206 return RETURN_VALUE_REGISTER_CONVENTION;
4207 }
4208 }
4209
4210 /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
4211 ABI. */
4212
4213 static CORE_ADDR
4214 mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
4215 struct regcache *regcache, CORE_ADDR bp_addr,
4216 int nargs,
4217 struct value **args, CORE_ADDR sp,
4218 int struct_return, CORE_ADDR struct_addr)
4219 {
4220 int argreg;
4221 int float_argreg;
4222 int argnum;
4223 int len = 0;
4224 int stack_offset = 0;
4225 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4226 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4227 CORE_ADDR func_addr = find_function_addr (function, NULL);
4228
4229 /* For shared libraries, "t9" needs to point at the function
4230 address. */
4231 regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
4232
4233 /* Set the return address register to point to the entry point of
4234 the program, where a breakpoint lies in wait. */
4235 regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
4236
4237 /* First ensure that the stack and structure return address (if any)
4238 are properly aligned. The stack has to be at least 64-bit
4239 aligned even on 32-bit machines, because doubles must be 64-bit
4240 aligned. For n32 and n64, stack frames need to be 128-bit
4241 aligned, so we round to this widest known alignment. */
4242
4243 sp = align_down (sp, 16);
4244 struct_addr = align_down (struct_addr, 16);
4245
4246 /* Now make space on the stack for the args. */
4247 for (argnum = 0; argnum < nargs; argnum++)
4248 {
4249 struct type *arg_type = check_typedef (value_type (args[argnum]));
4250 int arglen = TYPE_LENGTH (arg_type);
4251
4252 /* Allocate space on the stack. */
4253 len += align_up (arglen, MIPS64_REGSIZE);
4254 }
4255 sp -= align_up (len, 16);
4256
4257 if (mips_debug)
4258 fprintf_unfiltered (gdb_stdlog,
4259 "mips_o64_push_dummy_call: sp=%s allocated %ld\n",
4260 paddress (gdbarch, sp), (long) align_up (len, 16));
4261
4262 /* Initialize the integer and float register pointers. */
4263 argreg = MIPS_A0_REGNUM;
4264 float_argreg = mips_fpa0_regnum (gdbarch);
4265
4266 /* The struct_return pointer occupies the first parameter-passing reg. */
4267 if (struct_return)
4268 {
4269 if (mips_debug)
4270 fprintf_unfiltered (gdb_stdlog,
4271 "mips_o64_push_dummy_call: "
4272 "struct_return reg=%d %s\n",
4273 argreg, paddress (gdbarch, struct_addr));
4274 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
4275 stack_offset += MIPS64_REGSIZE;
4276 }
4277
4278 /* Now load as many as possible of the first arguments into
4279 registers, and push the rest onto the stack. Loop thru args
4280 from first to last. */
4281 for (argnum = 0; argnum < nargs; argnum++)
4282 {
4283 const gdb_byte *val;
4284 gdb_byte valbuf[MAX_REGISTER_SIZE];
4285 struct value *arg = args[argnum];
4286 struct type *arg_type = check_typedef (value_type (arg));
4287 int len = TYPE_LENGTH (arg_type);
4288 enum type_code typecode = TYPE_CODE (arg_type);
4289
4290 if (mips_debug)
4291 fprintf_unfiltered (gdb_stdlog,
4292 "mips_o64_push_dummy_call: %d len=%d type=%d",
4293 argnum + 1, len, (int) typecode);
4294
4295 val = value_contents (arg);
4296
4297 /* Function pointer arguments to mips16 code need to be made into
4298 mips16 pointers. */
4299 if (typecode == TYPE_CODE_PTR
4300 && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC)
4301 {
4302 CORE_ADDR addr = extract_signed_integer (value_contents (arg),
4303 len, byte_order);
4304 if (mips_pc_is_mips16 (addr))
4305 {
4306 store_signed_integer (valbuf, len, byte_order,
4307 make_mips16_addr (addr));
4308 val = valbuf;
4309 }
4310 }
4311
4312 /* Floating point arguments passed in registers have to be
4313 treated specially. On 32-bit architectures, doubles
4314 are passed in register pairs; the even register gets
4315 the low word, and the odd register gets the high word.
4316 On O32/O64, the first two floating point arguments are
4317 also copied to general registers, because MIPS16 functions
4318 don't use float registers for arguments. This duplication of
4319 arguments in general registers can't hurt non-MIPS16 functions
4320 because those registers are normally skipped. */
4321
4322 if (fp_register_arg_p (gdbarch, typecode, arg_type)
4323 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch))
4324 {
4325 LONGEST regval = extract_unsigned_integer (val, len, byte_order);
4326 if (mips_debug)
4327 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4328 float_argreg, phex (regval, len));
4329 regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
4330 if (mips_debug)
4331 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4332 argreg, phex (regval, len));
4333 regcache_cooked_write_unsigned (regcache, argreg, regval);
4334 argreg++;
4335 /* Reserve space for the FP register. */
4336 stack_offset += align_up (len, MIPS64_REGSIZE);
4337 }
4338 else
4339 {
4340 /* Copy the argument to general registers or the stack in
4341 register-sized pieces. Large arguments are split between
4342 registers and stack. */
4343 /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
4344 are treated specially: Irix cc passes them in registers
4345 where gcc sometimes puts them on the stack. For maximum
4346 compatibility, we will put them in both places. */
4347 int odd_sized_struct = (len > MIPS64_REGSIZE
4348 && len % MIPS64_REGSIZE != 0);
4349 while (len > 0)
4350 {
4351 /* Remember if the argument was written to the stack. */
4352 int stack_used_p = 0;
4353 int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
4354
4355 if (mips_debug)
4356 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
4357 partial_len);
4358
4359 /* Write this portion of the argument to the stack. */
4360 if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)
4361 || odd_sized_struct)
4362 {
4363 /* Should shorter than int integer values be
4364 promoted to int before being stored? */
4365 int longword_offset = 0;
4366 CORE_ADDR addr;
4367 stack_used_p = 1;
4368 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4369 {
4370 if ((typecode == TYPE_CODE_INT
4371 || typecode == TYPE_CODE_PTR
4372 || typecode == TYPE_CODE_FLT)
4373 && len <= 4)
4374 longword_offset = MIPS64_REGSIZE - len;
4375 }
4376
4377 if (mips_debug)
4378 {
4379 fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s",
4380 paddress (gdbarch, stack_offset));
4381 fprintf_unfiltered (gdb_stdlog, " longword_offset=%s",
4382 paddress (gdbarch, longword_offset));
4383 }
4384
4385 addr = sp + stack_offset + longword_offset;
4386
4387 if (mips_debug)
4388 {
4389 int i;
4390 fprintf_unfiltered (gdb_stdlog, " @%s ",
4391 paddress (gdbarch, addr));
4392 for (i = 0; i < partial_len; i++)
4393 {
4394 fprintf_unfiltered (gdb_stdlog, "%02x",
4395 val[i] & 0xff);
4396 }
4397 }
4398 write_memory (addr, val, partial_len);
4399 }
4400
4401 /* Note!!! This is NOT an else clause. Odd sized
4402 structs may go thru BOTH paths. */
4403 /* Write this portion of the argument to a general
4404 purpose register. */
4405 if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch))
4406 {
4407 LONGEST regval = extract_signed_integer (val, partial_len,
4408 byte_order);
4409 /* Value may need to be sign extended, because
4410 mips_isa_regsize() != mips_abi_regsize(). */
4411
4412 /* A non-floating-point argument being passed in a
4413 general register. If a struct or union, and if
4414 the remaining length is smaller than the register
4415 size, we have to adjust the register value on
4416 big endian targets.
4417
4418 It does not seem to be necessary to do the
4419 same for integral types. */
4420
4421 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
4422 && partial_len < MIPS64_REGSIZE
4423 && (typecode == TYPE_CODE_STRUCT
4424 || typecode == TYPE_CODE_UNION))
4425 regval <<= ((MIPS64_REGSIZE - partial_len)
4426 * TARGET_CHAR_BIT);
4427
4428 if (mips_debug)
4429 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4430 argreg,
4431 phex (regval, MIPS64_REGSIZE));
4432 regcache_cooked_write_unsigned (regcache, argreg, regval);
4433 argreg++;
4434
4435 /* Prevent subsequent floating point arguments from
4436 being passed in floating point registers. */
4437 float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1;
4438 }
4439
4440 len -= partial_len;
4441 val += partial_len;
4442
4443 /* Compute the offset into the stack at which we will
4444 copy the next parameter.
4445
4446 In older ABIs, the caller reserved space for
4447 registers that contained arguments. This was loosely
4448 refered to as their "home". Consequently, space is
4449 always allocated. */
4450
4451 stack_offset += align_up (partial_len, MIPS64_REGSIZE);
4452 }
4453 }
4454 if (mips_debug)
4455 fprintf_unfiltered (gdb_stdlog, "\n");
4456 }
4457
4458 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
4459
4460 /* Return adjusted stack pointer. */
4461 return sp;
4462 }
4463
4464 static enum return_value_convention
4465 mips_o64_return_value (struct gdbarch *gdbarch, struct type *func_type,
4466 struct type *type, struct regcache *regcache,
4467 gdb_byte *readbuf, const gdb_byte *writebuf)
4468 {
4469 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4470
4471 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4472 || TYPE_CODE (type) == TYPE_CODE_UNION
4473 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
4474 return RETURN_VALUE_STRUCT_CONVENTION;
4475 else if (fp_register_arg_p (gdbarch, TYPE_CODE (type), type))
4476 {
4477 /* A floating-point value. It fits in the least significant
4478 part of FP0. */
4479 if (mips_debug)
4480 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4481 mips_xfer_register (gdbarch, regcache,
4482 gdbarch_num_regs (gdbarch)
4483 + mips_regnum (gdbarch)->fp0,
4484 TYPE_LENGTH (type),
4485 gdbarch_byte_order (gdbarch),
4486 readbuf, writebuf, 0);
4487 return RETURN_VALUE_REGISTER_CONVENTION;
4488 }
4489 else
4490 {
4491 /* A scalar extract each part but least-significant-byte
4492 justified. */
4493 int offset;
4494 int regnum;
4495 for (offset = 0, regnum = MIPS_V0_REGNUM;
4496 offset < TYPE_LENGTH (type);
4497 offset += MIPS64_REGSIZE, regnum++)
4498 {
4499 int xfer = MIPS64_REGSIZE;
4500 if (offset + xfer > TYPE_LENGTH (type))
4501 xfer = TYPE_LENGTH (type) - offset;
4502 if (mips_debug)
4503 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4504 offset, xfer, regnum);
4505 mips_xfer_register (gdbarch, regcache,
4506 gdbarch_num_regs (gdbarch) + regnum,
4507 xfer, gdbarch_byte_order (gdbarch),
4508 readbuf, writebuf, offset);
4509 }
4510 return RETURN_VALUE_REGISTER_CONVENTION;
4511 }
4512 }
4513
4514 /* Floating point register management.
4515
4516 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4517 64bit operations, these early MIPS cpus treat fp register pairs
4518 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4519 registers and offer a compatibility mode that emulates the MIPS2 fp
4520 model. When operating in MIPS2 fp compat mode, later cpu's split
4521 double precision floats into two 32-bit chunks and store them in
4522 consecutive fp regs. To display 64-bit floats stored in this
4523 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4524 Throw in user-configurable endianness and you have a real mess.
4525
4526 The way this works is:
4527 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4528 double-precision value will be split across two logical registers.
4529 The lower-numbered logical register will hold the low-order bits,
4530 regardless of the processor's endianness.
4531 - If we are on a 64-bit processor, and we are looking for a
4532 single-precision value, it will be in the low ordered bits
4533 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4534 save slot in memory.
4535 - If we are in 64-bit mode, everything is straightforward.
4536
4537 Note that this code only deals with "live" registers at the top of the
4538 stack. We will attempt to deal with saved registers later, when
4539 the raw/cooked register interface is in place. (We need a general
4540 interface that can deal with dynamic saved register sizes -- fp
4541 regs could be 32 bits wide in one frame and 64 on the frame above
4542 and below). */
4543
4544 /* Copy a 32-bit single-precision value from the current frame
4545 into rare_buffer. */
4546
4547 static void
4548 mips_read_fp_register_single (struct frame_info *frame, int regno,
4549 gdb_byte *rare_buffer)
4550 {
4551 struct gdbarch *gdbarch = get_frame_arch (frame);
4552 int raw_size = register_size (gdbarch, regno);
4553 gdb_byte *raw_buffer = alloca (raw_size);
4554
4555 if (!frame_register_read (frame, regno, raw_buffer))
4556 error (_("can't read register %d (%s)"),
4557 regno, gdbarch_register_name (gdbarch, regno));
4558 if (raw_size == 8)
4559 {
4560 /* We have a 64-bit value for this register. Find the low-order
4561 32 bits. */
4562 int offset;
4563
4564 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4565 offset = 4;
4566 else
4567 offset = 0;
4568
4569 memcpy (rare_buffer, raw_buffer + offset, 4);
4570 }
4571 else
4572 {
4573 memcpy (rare_buffer, raw_buffer, 4);
4574 }
4575 }
4576
4577 /* Copy a 64-bit double-precision value from the current frame into
4578 rare_buffer. This may include getting half of it from the next
4579 register. */
4580
4581 static void
4582 mips_read_fp_register_double (struct frame_info *frame, int regno,
4583 gdb_byte *rare_buffer)
4584 {
4585 struct gdbarch *gdbarch = get_frame_arch (frame);
4586 int raw_size = register_size (gdbarch, regno);
4587
4588 if (raw_size == 8 && !mips2_fp_compat (frame))
4589 {
4590 /* We have a 64-bit value for this register, and we should use
4591 all 64 bits. */
4592 if (!frame_register_read (frame, regno, rare_buffer))
4593 error (_("can't read register %d (%s)"),
4594 regno, gdbarch_register_name (gdbarch, regno));
4595 }
4596 else
4597 {
4598 int rawnum = regno % gdbarch_num_regs (gdbarch);
4599
4600 if ((rawnum - mips_regnum (gdbarch)->fp0) & 1)
4601 internal_error (__FILE__, __LINE__,
4602 _("mips_read_fp_register_double: bad access to "
4603 "odd-numbered FP register"));
4604
4605 /* mips_read_fp_register_single will find the correct 32 bits from
4606 each register. */
4607 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4608 {
4609 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4610 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4611 }
4612 else
4613 {
4614 mips_read_fp_register_single (frame, regno, rare_buffer);
4615 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4616 }
4617 }
4618 }
4619
4620 static void
4621 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4622 int regnum)
4623 { /* Do values for FP (float) regs. */
4624 struct gdbarch *gdbarch = get_frame_arch (frame);
4625 gdb_byte *raw_buffer;
4626 double doub, flt1; /* Doubles extracted from raw hex data. */
4627 int inv1, inv2;
4628
4629 raw_buffer = alloca (2 * register_size (gdbarch,
4630 mips_regnum (gdbarch)->fp0));
4631
4632 fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum));
4633 fprintf_filtered (file, "%*s",
4634 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)),
4635 "");
4636
4637 if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame))
4638 {
4639 struct value_print_options opts;
4640
4641 /* 4-byte registers: Print hex and floating. Also print even
4642 numbered registers as doubles. */
4643 mips_read_fp_register_single (frame, regnum, raw_buffer);
4644 flt1 = unpack_double (builtin_type (gdbarch)->builtin_float,
4645 raw_buffer, &inv1);
4646
4647 get_formatted_print_options (&opts, 'x');
4648 print_scalar_formatted (raw_buffer,
4649 builtin_type (gdbarch)->builtin_uint32,
4650 &opts, 'w', file);
4651
4652 fprintf_filtered (file, " flt: ");
4653 if (inv1)
4654 fprintf_filtered (file, " <invalid float> ");
4655 else
4656 fprintf_filtered (file, "%-17.9g", flt1);
4657
4658 if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0)
4659 {
4660 mips_read_fp_register_double (frame, regnum, raw_buffer);
4661 doub = unpack_double (builtin_type (gdbarch)->builtin_double,
4662 raw_buffer, &inv2);
4663
4664 fprintf_filtered (file, " dbl: ");
4665 if (inv2)
4666 fprintf_filtered (file, "<invalid double>");
4667 else
4668 fprintf_filtered (file, "%-24.17g", doub);
4669 }
4670 }
4671 else
4672 {
4673 struct value_print_options opts;
4674
4675 /* Eight byte registers: print each one as hex, float and double. */
4676 mips_read_fp_register_single (frame, regnum, raw_buffer);
4677 flt1 = unpack_double (builtin_type (gdbarch)->builtin_float,
4678 raw_buffer, &inv1);
4679
4680 mips_read_fp_register_double (frame, regnum, raw_buffer);
4681 doub = unpack_double (builtin_type (gdbarch)->builtin_double,
4682 raw_buffer, &inv2);
4683
4684 get_formatted_print_options (&opts, 'x');
4685 print_scalar_formatted (raw_buffer,
4686 builtin_type (gdbarch)->builtin_uint64,
4687 &opts, 'g', file);
4688
4689 fprintf_filtered (file, " flt: ");
4690 if (inv1)
4691 fprintf_filtered (file, "<invalid float>");
4692 else
4693 fprintf_filtered (file, "%-17.9g", flt1);
4694
4695 fprintf_filtered (file, " dbl: ");
4696 if (inv2)
4697 fprintf_filtered (file, "<invalid double>");
4698 else
4699 fprintf_filtered (file, "%-24.17g", doub);
4700 }
4701 }
4702
4703 static void
4704 mips_print_register (struct ui_file *file, struct frame_info *frame,
4705 int regnum)
4706 {
4707 struct gdbarch *gdbarch = get_frame_arch (frame);
4708 int offset;
4709 struct value_print_options opts;
4710 struct value *val;
4711
4712 if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4713 {
4714 mips_print_fp_register (file, frame, regnum);
4715 return;
4716 }
4717
4718 val = get_frame_register_value (frame, regnum);
4719 if (value_optimized_out (val))
4720 {
4721 fprintf_filtered (file, "%s: [Invalid]",
4722 gdbarch_register_name (gdbarch, regnum));
4723 return;
4724 }
4725
4726 fputs_filtered (gdbarch_register_name (gdbarch, regnum), file);
4727
4728 /* The problem with printing numeric register names (r26, etc.) is that
4729 the user can't use them on input. Probably the best solution is to
4730 fix it so that either the numeric or the funky (a2, etc.) names
4731 are accepted on input. */
4732 if (regnum < MIPS_NUMREGS)
4733 fprintf_filtered (file, "(r%d): ", regnum);
4734 else
4735 fprintf_filtered (file, ": ");
4736
4737 get_formatted_print_options (&opts, 'x');
4738 val_print_scalar_formatted (value_type (val),
4739 value_contents_for_printing (val),
4740 value_embedded_offset (val),
4741 val,
4742 &opts, 0, file);
4743 }
4744
4745 /* Replacement for generic do_registers_info.
4746 Print regs in pretty columns. */
4747
4748 static int
4749 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4750 int regnum)
4751 {
4752 fprintf_filtered (file, " ");
4753 mips_print_fp_register (file, frame, regnum);
4754 fprintf_filtered (file, "\n");
4755 return regnum + 1;
4756 }
4757
4758
4759 /* Print a row's worth of GP (int) registers, with name labels above. */
4760
4761 static int
4762 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4763 int start_regnum)
4764 {
4765 struct gdbarch *gdbarch = get_frame_arch (frame);
4766 /* Do values for GP (int) regs. */
4767 gdb_byte raw_buffer[MAX_REGISTER_SIZE];
4768 int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols
4769 per row. */
4770 int col, byte;
4771 int regnum;
4772
4773 /* For GP registers, we print a separate row of names above the vals. */
4774 for (col = 0, regnum = start_regnum;
4775 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4776 + gdbarch_num_pseudo_regs (gdbarch);
4777 regnum++)
4778 {
4779 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
4780 continue; /* unused register */
4781 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4782 TYPE_CODE_FLT)
4783 break; /* End the row: reached FP register. */
4784 /* Large registers are handled separately. */
4785 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
4786 {
4787 if (col > 0)
4788 break; /* End the row before this register. */
4789
4790 /* Print this register on a row by itself. */
4791 mips_print_register (file, frame, regnum);
4792 fprintf_filtered (file, "\n");
4793 return regnum + 1;
4794 }
4795 if (col == 0)
4796 fprintf_filtered (file, " ");
4797 fprintf_filtered (file,
4798 mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s",
4799 gdbarch_register_name (gdbarch, regnum));
4800 col++;
4801 }
4802
4803 if (col == 0)
4804 return regnum;
4805
4806 /* Print the R0 to R31 names. */
4807 if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS)
4808 fprintf_filtered (file, "\n R%-4d",
4809 start_regnum % gdbarch_num_regs (gdbarch));
4810 else
4811 fprintf_filtered (file, "\n ");
4812
4813 /* Now print the values in hex, 4 or 8 to the row. */
4814 for (col = 0, regnum = start_regnum;
4815 col < ncols && regnum < gdbarch_num_regs (gdbarch)
4816 + gdbarch_num_pseudo_regs (gdbarch);
4817 regnum++)
4818 {
4819 if (*gdbarch_register_name (gdbarch, regnum) == '\0')
4820 continue; /* unused register */
4821 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4822 TYPE_CODE_FLT)
4823 break; /* End row: reached FP register. */
4824 if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
4825 break; /* End row: large register. */
4826
4827 /* OK: get the data in raw format. */
4828 if (!frame_register_read (frame, regnum, raw_buffer))
4829 error (_("can't read register %d (%s)"),
4830 regnum, gdbarch_register_name (gdbarch, regnum));
4831 /* pad small registers */
4832 for (byte = 0;
4833 byte < (mips_abi_regsize (gdbarch)
4834 - register_size (gdbarch, regnum)); byte++)
4835 printf_filtered (" ");
4836 /* Now print the register value in hex, endian order. */
4837 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4838 for (byte =
4839 register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
4840 byte < register_size (gdbarch, regnum); byte++)
4841 fprintf_filtered (file, "%02x", raw_buffer[byte]);
4842 else
4843 for (byte = register_size (gdbarch, regnum) - 1;
4844 byte >= 0; byte--)
4845 fprintf_filtered (file, "%02x", raw_buffer[byte]);
4846 fprintf_filtered (file, " ");
4847 col++;
4848 }
4849 if (col > 0) /* ie. if we actually printed anything... */
4850 fprintf_filtered (file, "\n");
4851
4852 return regnum;
4853 }
4854
4855 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */
4856
4857 static void
4858 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
4859 struct frame_info *frame, int regnum, int all)
4860 {
4861 if (regnum != -1) /* Do one specified register. */
4862 {
4863 gdb_assert (regnum >= gdbarch_num_regs (gdbarch));
4864 if (*(gdbarch_register_name (gdbarch, regnum)) == '\0')
4865 error (_("Not a valid register for the current processor type"));
4866
4867 mips_print_register (file, frame, regnum);
4868 fprintf_filtered (file, "\n");
4869 }
4870 else
4871 /* Do all (or most) registers. */
4872 {
4873 regnum = gdbarch_num_regs (gdbarch);
4874 while (regnum < gdbarch_num_regs (gdbarch)
4875 + gdbarch_num_pseudo_regs (gdbarch))
4876 {
4877 if (TYPE_CODE (register_type (gdbarch, regnum)) ==
4878 TYPE_CODE_FLT)
4879 {
4880 if (all) /* True for "INFO ALL-REGISTERS" command. */
4881 regnum = print_fp_register_row (file, frame, regnum);
4882 else
4883 regnum += MIPS_NUMREGS; /* Skip floating point regs. */
4884 }
4885 else
4886 regnum = print_gp_register_row (file, frame, regnum);
4887 }
4888 }
4889 }
4890
4891 /* Is this a branch with a delay slot? */
4892
4893 static int
4894 is_delayed (unsigned long insn)
4895 {
4896 int i;
4897 for (i = 0; i < NUMOPCODES; ++i)
4898 if (mips_opcodes[i].pinfo != INSN_MACRO
4899 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
4900 break;
4901 return (i < NUMOPCODES
4902 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
4903 | INSN_COND_BRANCH_DELAY
4904 | INSN_COND_BRANCH_LIKELY)));
4905 }
4906
4907 static int
4908 mips_single_step_through_delay (struct gdbarch *gdbarch,
4909 struct frame_info *frame)
4910 {
4911 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4912 CORE_ADDR pc = get_frame_pc (frame);
4913 gdb_byte buf[MIPS_INSN32_SIZE];
4914
4915 /* There is no branch delay slot on MIPS16. */
4916 if (mips_pc_is_mips16 (pc))
4917 return 0;
4918
4919 if (!breakpoint_here_p (get_frame_address_space (frame), pc + 4))
4920 return 0;
4921
4922 if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf))
4923 /* If error reading memory, guess that it is not a delayed
4924 branch. */
4925 return 0;
4926 return is_delayed (extract_unsigned_integer (buf, sizeof buf, byte_order));
4927 }
4928
4929 /* To skip prologues, I use this predicate. Returns either PC itself
4930 if the code at PC does not look like a function prologue; otherwise
4931 returns an address that (if we're lucky) follows the prologue. If
4932 LENIENT, then we must skip everything which is involved in setting
4933 up the frame (it's OK to skip more, just so long as we don't skip
4934 anything which might clobber the registers which are being saved.
4935 We must skip more in the case where part of the prologue is in the
4936 delay slot of a non-prologue instruction). */
4937
4938 static CORE_ADDR
4939 mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
4940 {
4941 CORE_ADDR limit_pc;
4942 CORE_ADDR func_addr;
4943
4944 /* See if we can determine the end of the prologue via the symbol table.
4945 If so, then return either PC, or the PC after the prologue, whichever
4946 is greater. */
4947 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
4948 {
4949 CORE_ADDR post_prologue_pc
4950 = skip_prologue_using_sal (gdbarch, func_addr);
4951 if (post_prologue_pc != 0)
4952 return max (pc, post_prologue_pc);
4953 }
4954
4955 /* Can't determine prologue from the symbol table, need to examine
4956 instructions. */
4957
4958 /* Find an upper limit on the function prologue using the debug
4959 information. If the debug information could not be used to provide
4960 that bound, then use an arbitrary large number as the upper bound. */
4961 limit_pc = skip_prologue_using_sal (gdbarch, pc);
4962 if (limit_pc == 0)
4963 limit_pc = pc + 100; /* Magic. */
4964
4965 if (mips_pc_is_mips16 (pc))
4966 return mips16_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL);
4967 else
4968 return mips32_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL);
4969 }
4970
4971 /* Check whether the PC is in a function epilogue (32-bit version).
4972 This is a helper function for mips_in_function_epilogue_p. */
4973 static int
4974 mips32_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
4975 {
4976 CORE_ADDR func_addr = 0, func_end = 0;
4977
4978 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
4979 {
4980 /* The MIPS epilogue is max. 12 bytes long. */
4981 CORE_ADDR addr = func_end - 12;
4982
4983 if (addr < func_addr + 4)
4984 addr = func_addr + 4;
4985 if (pc < addr)
4986 return 0;
4987
4988 for (; pc < func_end; pc += MIPS_INSN32_SIZE)
4989 {
4990 unsigned long high_word;
4991 unsigned long inst;
4992
4993 inst = mips_fetch_instruction (gdbarch, pc);
4994 high_word = (inst >> 16) & 0xffff;
4995
4996 if (high_word != 0x27bd /* addiu $sp,$sp,offset */
4997 && high_word != 0x67bd /* daddiu $sp,$sp,offset */
4998 && inst != 0x03e00008 /* jr $ra */
4999 && inst != 0x00000000) /* nop */
5000 return 0;
5001 }
5002
5003 return 1;
5004 }
5005
5006 return 0;
5007 }
5008
5009 /* Check whether the PC is in a function epilogue (16-bit version).
5010 This is a helper function for mips_in_function_epilogue_p. */
5011 static int
5012 mips16_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
5013 {
5014 CORE_ADDR func_addr = 0, func_end = 0;
5015
5016 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
5017 {
5018 /* The MIPS epilogue is max. 12 bytes long. */
5019 CORE_ADDR addr = func_end - 12;
5020
5021 if (addr < func_addr + 4)
5022 addr = func_addr + 4;
5023 if (pc < addr)
5024 return 0;
5025
5026 for (; pc < func_end; pc += MIPS_INSN16_SIZE)
5027 {
5028 unsigned short inst;
5029
5030 inst = mips_fetch_instruction (gdbarch, pc);
5031
5032 if ((inst & 0xf800) == 0xf000) /* extend */
5033 continue;
5034
5035 if (inst != 0x6300 /* addiu $sp,offset */
5036 && inst != 0xfb00 /* daddiu $sp,$sp,offset */
5037 && inst != 0xe820 /* jr $ra */
5038 && inst != 0xe8a0 /* jrc $ra */
5039 && inst != 0x6500) /* nop */
5040 return 0;
5041 }
5042
5043 return 1;
5044 }
5045
5046 return 0;
5047 }
5048
5049 /* The epilogue is defined here as the area at the end of a function,
5050 after an instruction which destroys the function's stack frame. */
5051 static int
5052 mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
5053 {
5054 if (mips_pc_is_mips16 (pc))
5055 return mips16_in_function_epilogue_p (gdbarch, pc);
5056 else
5057 return mips32_in_function_epilogue_p (gdbarch, pc);
5058 }
5059
5060 /* Root of all "set mips "/"show mips " commands. This will eventually be
5061 used for all MIPS-specific commands. */
5062
5063 static void
5064 show_mips_command (char *args, int from_tty)
5065 {
5066 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5067 }
5068
5069 static void
5070 set_mips_command (char *args, int from_tty)
5071 {
5072 printf_unfiltered
5073 ("\"set mips\" must be followed by an appropriate subcommand.\n");
5074 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5075 }
5076
5077 /* Commands to show/set the MIPS FPU type. */
5078
5079 static void
5080 show_mipsfpu_command (char *args, int from_tty)
5081 {
5082 char *fpu;
5083
5084 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
5085 {
5086 printf_unfiltered
5087 ("The MIPS floating-point coprocessor is unknown "
5088 "because the current architecture is not MIPS.\n");
5089 return;
5090 }
5091
5092 switch (MIPS_FPU_TYPE (target_gdbarch))
5093 {
5094 case MIPS_FPU_SINGLE:
5095 fpu = "single-precision";
5096 break;
5097 case MIPS_FPU_DOUBLE:
5098 fpu = "double-precision";
5099 break;
5100 case MIPS_FPU_NONE:
5101 fpu = "absent (none)";
5102 break;
5103 default:
5104 internal_error (__FILE__, __LINE__, _("bad switch"));
5105 }
5106 if (mips_fpu_type_auto)
5107 printf_unfiltered ("The MIPS floating-point coprocessor "
5108 "is set automatically (currently %s)\n",
5109 fpu);
5110 else
5111 printf_unfiltered
5112 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu);
5113 }
5114
5115
5116 static void
5117 set_mipsfpu_command (char *args, int from_tty)
5118 {
5119 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", "
5120 "\"single\",\"none\" or \"auto\".\n");
5121 show_mipsfpu_command (args, from_tty);
5122 }
5123
5124 static void
5125 set_mipsfpu_single_command (char *args, int from_tty)
5126 {
5127 struct gdbarch_info info;
5128 gdbarch_info_init (&info);
5129 mips_fpu_type = MIPS_FPU_SINGLE;
5130 mips_fpu_type_auto = 0;
5131 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5132 instead of relying on globals. Doing that would let generic code
5133 handle the search for this specific architecture. */
5134 if (!gdbarch_update_p (info))
5135 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
5136 }
5137
5138 static void
5139 set_mipsfpu_double_command (char *args, int from_tty)
5140 {
5141 struct gdbarch_info info;
5142 gdbarch_info_init (&info);
5143 mips_fpu_type = MIPS_FPU_DOUBLE;
5144 mips_fpu_type_auto = 0;
5145 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5146 instead of relying on globals. Doing that would let generic code
5147 handle the search for this specific architecture. */
5148 if (!gdbarch_update_p (info))
5149 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
5150 }
5151
5152 static void
5153 set_mipsfpu_none_command (char *args, int from_tty)
5154 {
5155 struct gdbarch_info info;
5156 gdbarch_info_init (&info);
5157 mips_fpu_type = MIPS_FPU_NONE;
5158 mips_fpu_type_auto = 0;
5159 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5160 instead of relying on globals. Doing that would let generic code
5161 handle the search for this specific architecture. */
5162 if (!gdbarch_update_p (info))
5163 internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
5164 }
5165
5166 static void
5167 set_mipsfpu_auto_command (char *args, int from_tty)
5168 {
5169 mips_fpu_type_auto = 1;
5170 }
5171
5172 /* Attempt to identify the particular processor model by reading the
5173 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
5174 the relevant processor still exists (it dates back to '94) and
5175 secondly this is not the way to do this. The processor type should
5176 be set by forcing an architecture change. */
5177
5178 void
5179 deprecated_mips_set_processor_regs_hack (void)
5180 {
5181 struct regcache *regcache = get_current_regcache ();
5182 struct gdbarch *gdbarch = get_regcache_arch (regcache);
5183 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
5184 ULONGEST prid;
5185
5186 regcache_cooked_read_unsigned (regcache, MIPS_PRID_REGNUM, &prid);
5187 if ((prid & ~0xf) == 0x700)
5188 tdep->mips_processor_reg_names = mips_r3041_reg_names;
5189 }
5190
5191 /* Just like reinit_frame_cache, but with the right arguments to be
5192 callable as an sfunc. */
5193
5194 static void
5195 reinit_frame_cache_sfunc (char *args, int from_tty,
5196 struct cmd_list_element *c)
5197 {
5198 reinit_frame_cache ();
5199 }
5200
5201 static int
5202 gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
5203 {
5204 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5205 disassembler needs to be able to locally determine the ISA, and
5206 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5207 work. */
5208 if (mips_pc_is_mips16 (memaddr))
5209 info->mach = bfd_mach_mips16;
5210
5211 /* Round down the instruction address to the appropriate boundary. */
5212 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5213
5214 /* Set the disassembler options. */
5215 if (!info->disassembler_options)
5216 /* This string is not recognized explicitly by the disassembler,
5217 but it tells the disassembler to not try to guess the ABI from
5218 the bfd elf headers, such that, if the user overrides the ABI
5219 of a program linked as NewABI, the disassembly will follow the
5220 register naming conventions specified by the user. */
5221 info->disassembler_options = "gpr-names=32";
5222
5223 /* Call the appropriate disassembler based on the target endian-ness. */
5224 if (info->endian == BFD_ENDIAN_BIG)
5225 return print_insn_big_mips (memaddr, info);
5226 else
5227 return print_insn_little_mips (memaddr, info);
5228 }
5229
5230 static int
5231 gdb_print_insn_mips_n32 (bfd_vma memaddr, struct disassemble_info *info)
5232 {
5233 /* Set up the disassembler info, so that we get the right
5234 register names from libopcodes. */
5235 info->disassembler_options = "gpr-names=n32";
5236 info->flavour = bfd_target_elf_flavour;
5237
5238 return gdb_print_insn_mips (memaddr, info);
5239 }
5240
5241 static int
5242 gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info)
5243 {
5244 /* Set up the disassembler info, so that we get the right
5245 register names from libopcodes. */
5246 info->disassembler_options = "gpr-names=64";
5247 info->flavour = bfd_target_elf_flavour;
5248
5249 return gdb_print_insn_mips (memaddr, info);
5250 }
5251
5252 /* This function implements gdbarch_breakpoint_from_pc. It uses the
5253 program counter value to determine whether a 16- or 32-bit breakpoint
5254 should be used. It returns a pointer to a string of bytes that encode a
5255 breakpoint instruction, stores the length of the string to *lenptr, and
5256 adjusts pc (if necessary) to point to the actual memory location where
5257 the breakpoint should be inserted. */
5258
5259 static const gdb_byte *
5260 mips_breakpoint_from_pc (struct gdbarch *gdbarch,
5261 CORE_ADDR *pcptr, int *lenptr)
5262 {
5263 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
5264 {
5265 if (mips_pc_is_mips16 (*pcptr))
5266 {
5267 static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
5268 *pcptr = unmake_mips16_addr (*pcptr);
5269 *lenptr = sizeof (mips16_big_breakpoint);
5270 return mips16_big_breakpoint;
5271 }
5272 else
5273 {
5274 /* The IDT board uses an unusual breakpoint value, and
5275 sometimes gets confused when it sees the usual MIPS
5276 breakpoint instruction. */
5277 static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
5278 static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
5279 static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
5280 /* Likewise, IRIX appears to expect a different breakpoint,
5281 although this is not apparent until you try to use pthreads. */
5282 static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
5283
5284 *lenptr = sizeof (big_breakpoint);
5285
5286 if (strcmp (target_shortname, "mips") == 0)
5287 return idt_big_breakpoint;
5288 else if (strcmp (target_shortname, "ddb") == 0
5289 || strcmp (target_shortname, "pmon") == 0
5290 || strcmp (target_shortname, "lsi") == 0)
5291 return pmon_big_breakpoint;
5292 else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX)
5293 return irix_big_breakpoint;
5294 else
5295 return big_breakpoint;
5296 }
5297 }
5298 else
5299 {
5300 if (mips_pc_is_mips16 (*pcptr))
5301 {
5302 static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
5303 *pcptr = unmake_mips16_addr (*pcptr);
5304 *lenptr = sizeof (mips16_little_breakpoint);
5305 return mips16_little_breakpoint;
5306 }
5307 else
5308 {
5309 static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
5310 static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
5311 static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
5312
5313 *lenptr = sizeof (little_breakpoint);
5314
5315 if (strcmp (target_shortname, "mips") == 0)
5316 return idt_little_breakpoint;
5317 else if (strcmp (target_shortname, "ddb") == 0
5318 || strcmp (target_shortname, "pmon") == 0
5319 || strcmp (target_shortname, "lsi") == 0)
5320 return pmon_little_breakpoint;
5321 else
5322 return little_breakpoint;
5323 }
5324 }
5325 }
5326
5327 /* If PC is in a mips16 call or return stub, return the address of the target
5328 PC, which is either the callee or the caller. There are several
5329 cases which must be handled:
5330
5331 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5332 target PC is in $31 ($ra).
5333 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5334 and the target PC is in $2.
5335 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5336 before the jal instruction, this is effectively a call stub
5337 and the target PC is in $2. Otherwise this is effectively
5338 a return stub and the target PC is in $18.
5339
5340 See the source code for the stubs in gcc/config/mips/mips16.S for
5341 gory details. */
5342
5343 static CORE_ADDR
5344 mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5345 {
5346 struct gdbarch *gdbarch = get_frame_arch (frame);
5347 char *name;
5348 CORE_ADDR start_addr;
5349
5350 /* Find the starting address and name of the function containing the PC. */
5351 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5352 return 0;
5353
5354 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5355 target PC is in $31 ($ra). */
5356 if (strcmp (name, "__mips16_ret_sf") == 0
5357 || strcmp (name, "__mips16_ret_df") == 0)
5358 return get_frame_register_signed (frame, MIPS_RA_REGNUM);
5359
5360 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5361 {
5362 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5363 and the target PC is in $2. */
5364 if (name[19] >= '0' && name[19] <= '9')
5365 return get_frame_register_signed (frame, 2);
5366
5367 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5368 before the jal instruction, this is effectively a call stub
5369 and the target PC is in $2. Otherwise this is effectively
5370 a return stub and the target PC is in $18. */
5371 else if (name[19] == 's' || name[19] == 'd')
5372 {
5373 if (pc == start_addr)
5374 {
5375 /* Check if the target of the stub is a compiler-generated
5376 stub. Such a stub for a function bar might have a name
5377 like __fn_stub_bar, and might look like this:
5378 mfc1 $4,$f13
5379 mfc1 $5,$f12
5380 mfc1 $6,$f15
5381 mfc1 $7,$f14
5382 la $1,bar (becomes a lui/addiu pair)
5383 jr $1
5384 So scan down to the lui/addi and extract the target
5385 address from those two instructions. */
5386
5387 CORE_ADDR target_pc = get_frame_register_signed (frame, 2);
5388 ULONGEST inst;
5389 int i;
5390
5391 /* See if the name of the target function is __fn_stub_*. */
5392 if (find_pc_partial_function (target_pc, &name, NULL, NULL) ==
5393 0)
5394 return target_pc;
5395 if (strncmp (name, "__fn_stub_", 10) != 0
5396 && strcmp (name, "etext") != 0
5397 && strcmp (name, "_etext") != 0)
5398 return target_pc;
5399
5400 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5401 The limit on the search is arbitrarily set to 20
5402 instructions. FIXME. */
5403 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE)
5404 {
5405 inst = mips_fetch_instruction (gdbarch, target_pc);
5406 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5407 pc = (inst << 16) & 0xffff0000; /* high word */
5408 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5409 return pc | (inst & 0xffff); /* low word */
5410 }
5411
5412 /* Couldn't find the lui/addui pair, so return stub address. */
5413 return target_pc;
5414 }
5415 else
5416 /* This is the 'return' part of a call stub. The return
5417 address is in $r18. */
5418 return get_frame_register_signed (frame, 18);
5419 }
5420 }
5421 return 0; /* not a stub */
5422 }
5423
5424 /* If the current PC is the start of a non-PIC-to-PIC stub, return the
5425 PC of the stub target. The stub just loads $t9 and jumps to it,
5426 so that $t9 has the correct value at function entry. */
5427
5428 static CORE_ADDR
5429 mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5430 {
5431 struct gdbarch *gdbarch = get_frame_arch (frame);
5432 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5433 struct minimal_symbol *msym;
5434 int i;
5435 gdb_byte stub_code[16];
5436 int32_t stub_words[4];
5437
5438 /* The stub for foo is named ".pic.foo", and is either two
5439 instructions inserted before foo or a three instruction sequence
5440 which jumps to foo. */
5441 msym = lookup_minimal_symbol_by_pc (pc);
5442 if (msym == NULL
5443 || SYMBOL_VALUE_ADDRESS (msym) != pc
5444 || SYMBOL_LINKAGE_NAME (msym) == NULL
5445 || strncmp (SYMBOL_LINKAGE_NAME (msym), ".pic.", 5) != 0)
5446 return 0;
5447
5448 /* A two-instruction header. */
5449 if (MSYMBOL_SIZE (msym) == 8)
5450 return pc + 8;
5451
5452 /* A three-instruction (plus delay slot) trampoline. */
5453 if (MSYMBOL_SIZE (msym) == 16)
5454 {
5455 if (target_read_memory (pc, stub_code, 16) != 0)
5456 return 0;
5457 for (i = 0; i < 4; i++)
5458 stub_words[i] = extract_unsigned_integer (stub_code + i * 4,
5459 4, byte_order);
5460
5461 /* A stub contains these instructions:
5462 lui t9, %hi(target)
5463 j target
5464 addiu t9, t9, %lo(target)
5465 nop
5466
5467 This works even for N64, since stubs are only generated with
5468 -msym32. */
5469 if ((stub_words[0] & 0xffff0000U) == 0x3c190000
5470 && (stub_words[1] & 0xfc000000U) == 0x08000000
5471 && (stub_words[2] & 0xffff0000U) == 0x27390000
5472 && stub_words[3] == 0x00000000)
5473 return (((stub_words[0] & 0x0000ffff) << 16)
5474 + (stub_words[2] & 0x0000ffff));
5475 }
5476
5477 /* Not a recognized stub. */
5478 return 0;
5479 }
5480
5481 static CORE_ADDR
5482 mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
5483 {
5484 CORE_ADDR target_pc;
5485
5486 target_pc = mips_skip_mips16_trampoline_code (frame, pc);
5487 if (target_pc)
5488 return target_pc;
5489
5490 target_pc = find_solib_trampoline_target (frame, pc);
5491 if (target_pc)
5492 return target_pc;
5493
5494 target_pc = mips_skip_pic_trampoline_code (frame, pc);
5495 if (target_pc)
5496 return target_pc;
5497
5498 return 0;
5499 }
5500
5501 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5502 [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5503
5504 static int
5505 mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
5506 {
5507 int regnum;
5508 if (num >= 0 && num < 32)
5509 regnum = num;
5510 else if (num >= 38 && num < 70)
5511 regnum = num + mips_regnum (gdbarch)->fp0 - 38;
5512 else if (num == 70)
5513 regnum = mips_regnum (gdbarch)->hi;
5514 else if (num == 71)
5515 regnum = mips_regnum (gdbarch)->lo;
5516 else
5517 /* This will hopefully (eventually) provoke a warning. Should
5518 we be calling complaint() here? */
5519 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5520 return gdbarch_num_regs (gdbarch) + regnum;
5521 }
5522
5523
5524 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5525 gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
5526
5527 static int
5528 mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num)
5529 {
5530 int regnum;
5531 if (num >= 0 && num < 32)
5532 regnum = num;
5533 else if (num >= 32 && num < 64)
5534 regnum = num + mips_regnum (gdbarch)->fp0 - 32;
5535 else if (num == 64)
5536 regnum = mips_regnum (gdbarch)->hi;
5537 else if (num == 65)
5538 regnum = mips_regnum (gdbarch)->lo;
5539 else
5540 /* This will hopefully (eventually) provoke a warning. Should we
5541 be calling complaint() here? */
5542 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
5543 return gdbarch_num_regs (gdbarch) + regnum;
5544 }
5545
5546 static int
5547 mips_register_sim_regno (struct gdbarch *gdbarch, int regnum)
5548 {
5549 /* Only makes sense to supply raw registers. */
5550 gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
5551 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5552 decide if it is valid. Should instead define a standard sim/gdb
5553 register numbering scheme. */
5554 if (gdbarch_register_name (gdbarch,
5555 gdbarch_num_regs (gdbarch) + regnum) != NULL
5556 && gdbarch_register_name (gdbarch,
5557 gdbarch_num_regs (gdbarch)
5558 + regnum)[0] != '\0')
5559 return regnum;
5560 else
5561 return LEGACY_SIM_REGNO_IGNORE;
5562 }
5563
5564
5565 /* Convert an integer into an address. Extracting the value signed
5566 guarantees a correctly sign extended address. */
5567
5568 static CORE_ADDR
5569 mips_integer_to_address (struct gdbarch *gdbarch,
5570 struct type *type, const gdb_byte *buf)
5571 {
5572 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5573 return extract_signed_integer (buf, TYPE_LENGTH (type), byte_order);
5574 }
5575
5576 /* Dummy virtual frame pointer method. This is no more or less accurate
5577 than most other architectures; we just need to be explicit about it,
5578 because the pseudo-register gdbarch_sp_regnum will otherwise lead to
5579 an assertion failure. */
5580
5581 static void
5582 mips_virtual_frame_pointer (struct gdbarch *gdbarch,
5583 CORE_ADDR pc, int *reg, LONGEST *offset)
5584 {
5585 *reg = MIPS_SP_REGNUM;
5586 *offset = 0;
5587 }
5588
5589 static void
5590 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5591 {
5592 enum mips_abi *abip = (enum mips_abi *) obj;
5593 const char *name = bfd_get_section_name (abfd, sect);
5594
5595 if (*abip != MIPS_ABI_UNKNOWN)
5596 return;
5597
5598 if (strncmp (name, ".mdebug.", 8) != 0)
5599 return;
5600
5601 if (strcmp (name, ".mdebug.abi32") == 0)
5602 *abip = MIPS_ABI_O32;
5603 else if (strcmp (name, ".mdebug.abiN32") == 0)
5604 *abip = MIPS_ABI_N32;
5605 else if (strcmp (name, ".mdebug.abi64") == 0)
5606 *abip = MIPS_ABI_N64;
5607 else if (strcmp (name, ".mdebug.abiO64") == 0)
5608 *abip = MIPS_ABI_O64;
5609 else if (strcmp (name, ".mdebug.eabi32") == 0)
5610 *abip = MIPS_ABI_EABI32;
5611 else if (strcmp (name, ".mdebug.eabi64") == 0)
5612 *abip = MIPS_ABI_EABI64;
5613 else
5614 warning (_("unsupported ABI %s."), name + 8);
5615 }
5616
5617 static void
5618 mips_find_long_section (bfd *abfd, asection *sect, void *obj)
5619 {
5620 int *lbp = (int *) obj;
5621 const char *name = bfd_get_section_name (abfd, sect);
5622
5623 if (strncmp (name, ".gcc_compiled_long32", 20) == 0)
5624 *lbp = 32;
5625 else if (strncmp (name, ".gcc_compiled_long64", 20) == 0)
5626 *lbp = 64;
5627 else if (strncmp (name, ".gcc_compiled_long", 18) == 0)
5628 warning (_("unrecognized .gcc_compiled_longXX"));
5629 }
5630
5631 static enum mips_abi
5632 global_mips_abi (void)
5633 {
5634 int i;
5635
5636 for (i = 0; mips_abi_strings[i] != NULL; i++)
5637 if (mips_abi_strings[i] == mips_abi_string)
5638 return (enum mips_abi) i;
5639
5640 internal_error (__FILE__, __LINE__, _("unknown ABI string"));
5641 }
5642
5643 static void
5644 mips_register_g_packet_guesses (struct gdbarch *gdbarch)
5645 {
5646 /* If the size matches the set of 32-bit or 64-bit integer registers,
5647 assume that's what we've got. */
5648 register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32);
5649 register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64);
5650
5651 /* If the size matches the full set of registers GDB traditionally
5652 knows about, including floating point, for either 32-bit or
5653 64-bit, assume that's what we've got. */
5654 register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32);
5655 register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64);
5656
5657 /* Otherwise we don't have a useful guess. */
5658 }
5659
5660 static struct value *
5661 value_of_mips_user_reg (struct frame_info *frame, const void *baton)
5662 {
5663 const int *reg_p = baton;
5664 return value_of_register (*reg_p, frame);
5665 }
5666
5667 static struct gdbarch *
5668 mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5669 {
5670 struct gdbarch *gdbarch;
5671 struct gdbarch_tdep *tdep;
5672 int elf_flags;
5673 enum mips_abi mips_abi, found_abi, wanted_abi;
5674 int i, num_regs;
5675 enum mips_fpu_type fpu_type;
5676 struct tdesc_arch_data *tdesc_data = NULL;
5677 int elf_fpu_type = 0;
5678
5679 /* Check any target description for validity. */
5680 if (tdesc_has_registers (info.target_desc))
5681 {
5682 static const char *const mips_gprs[] = {
5683 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5684 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5685 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
5686 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
5687 };
5688 static const char *const mips_fprs[] = {
5689 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
5690 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
5691 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5692 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
5693 };
5694
5695 const struct tdesc_feature *feature;
5696 int valid_p;
5697
5698 feature = tdesc_find_feature (info.target_desc,
5699 "org.gnu.gdb.mips.cpu");
5700 if (feature == NULL)
5701 return NULL;
5702
5703 tdesc_data = tdesc_data_alloc ();
5704
5705 valid_p = 1;
5706 for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++)
5707 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
5708 mips_gprs[i]);
5709
5710
5711 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5712 MIPS_EMBED_LO_REGNUM, "lo");
5713 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5714 MIPS_EMBED_HI_REGNUM, "hi");
5715 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5716 MIPS_EMBED_PC_REGNUM, "pc");
5717
5718 if (!valid_p)
5719 {
5720 tdesc_data_cleanup (tdesc_data);
5721 return NULL;
5722 }
5723
5724 feature = tdesc_find_feature (info.target_desc,
5725 "org.gnu.gdb.mips.cp0");
5726 if (feature == NULL)
5727 {
5728 tdesc_data_cleanup (tdesc_data);
5729 return NULL;
5730 }
5731
5732 valid_p = 1;
5733 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5734 MIPS_EMBED_BADVADDR_REGNUM,
5735 "badvaddr");
5736 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5737 MIPS_PS_REGNUM, "status");
5738 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5739 MIPS_EMBED_CAUSE_REGNUM, "cause");
5740
5741 if (!valid_p)
5742 {
5743 tdesc_data_cleanup (tdesc_data);
5744 return NULL;
5745 }
5746
5747 /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
5748 backend is not prepared for that, though. */
5749 feature = tdesc_find_feature (info.target_desc,
5750 "org.gnu.gdb.mips.fpu");
5751 if (feature == NULL)
5752 {
5753 tdesc_data_cleanup (tdesc_data);
5754 return NULL;
5755 }
5756
5757 valid_p = 1;
5758 for (i = 0; i < 32; i++)
5759 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5760 i + MIPS_EMBED_FP0_REGNUM,
5761 mips_fprs[i]);
5762
5763 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5764 MIPS_EMBED_FP0_REGNUM + 32, "fcsr");
5765 valid_p &= tdesc_numbered_register (feature, tdesc_data,
5766 MIPS_EMBED_FP0_REGNUM + 33, "fir");
5767
5768 if (!valid_p)
5769 {
5770 tdesc_data_cleanup (tdesc_data);
5771 return NULL;
5772 }
5773
5774 /* It would be nice to detect an attempt to use a 64-bit ABI
5775 when only 32-bit registers are provided. */
5776 }
5777
5778 /* First of all, extract the elf_flags, if available. */
5779 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5780 elf_flags = elf_elfheader (info.abfd)->e_flags;
5781 else if (arches != NULL)
5782 elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags;
5783 else
5784 elf_flags = 0;
5785 if (gdbarch_debug)
5786 fprintf_unfiltered (gdb_stdlog,
5787 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags);
5788
5789 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5790 switch ((elf_flags & EF_MIPS_ABI))
5791 {
5792 case E_MIPS_ABI_O32:
5793 found_abi = MIPS_ABI_O32;
5794 break;
5795 case E_MIPS_ABI_O64:
5796 found_abi = MIPS_ABI_O64;
5797 break;
5798 case E_MIPS_ABI_EABI32:
5799 found_abi = MIPS_ABI_EABI32;
5800 break;
5801 case E_MIPS_ABI_EABI64:
5802 found_abi = MIPS_ABI_EABI64;
5803 break;
5804 default:
5805 if ((elf_flags & EF_MIPS_ABI2))
5806 found_abi = MIPS_ABI_N32;
5807 else
5808 found_abi = MIPS_ABI_UNKNOWN;
5809 break;
5810 }
5811
5812 /* GCC creates a pseudo-section whose name describes the ABI. */
5813 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5814 bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi);
5815
5816 /* If we have no useful BFD information, use the ABI from the last
5817 MIPS architecture (if there is one). */
5818 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
5819 found_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5820
5821 /* Try the architecture for any hint of the correct ABI. */
5822 if (found_abi == MIPS_ABI_UNKNOWN
5823 && info.bfd_arch_info != NULL
5824 && info.bfd_arch_info->arch == bfd_arch_mips)
5825 {
5826 switch (info.bfd_arch_info->mach)
5827 {
5828 case bfd_mach_mips3900:
5829 found_abi = MIPS_ABI_EABI32;
5830 break;
5831 case bfd_mach_mips4100:
5832 case bfd_mach_mips5000:
5833 found_abi = MIPS_ABI_EABI64;
5834 break;
5835 case bfd_mach_mips8000:
5836 case bfd_mach_mips10000:
5837 /* On Irix, ELF64 executables use the N64 ABI. The
5838 pseudo-sections which describe the ABI aren't present
5839 on IRIX. (Even for executables created by gcc.) */
5840 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5841 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5842 found_abi = MIPS_ABI_N64;
5843 else
5844 found_abi = MIPS_ABI_N32;
5845 break;
5846 }
5847 }
5848
5849 /* Default 64-bit objects to N64 instead of O32. */
5850 if (found_abi == MIPS_ABI_UNKNOWN
5851 && info.abfd != NULL
5852 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5853 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5854 found_abi = MIPS_ABI_N64;
5855
5856 if (gdbarch_debug)
5857 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n",
5858 found_abi);
5859
5860 /* What has the user specified from the command line? */
5861 wanted_abi = global_mips_abi ();
5862 if (gdbarch_debug)
5863 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n",
5864 wanted_abi);
5865
5866 /* Now that we have found what the ABI for this binary would be,
5867 check whether the user is overriding it. */
5868 if (wanted_abi != MIPS_ABI_UNKNOWN)
5869 mips_abi = wanted_abi;
5870 else if (found_abi != MIPS_ABI_UNKNOWN)
5871 mips_abi = found_abi;
5872 else
5873 mips_abi = MIPS_ABI_O32;
5874 if (gdbarch_debug)
5875 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n",
5876 mips_abi);
5877
5878 /* Also used when doing an architecture lookup. */
5879 if (gdbarch_debug)
5880 fprintf_unfiltered (gdb_stdlog,
5881 "mips_gdbarch_init: "
5882 "mips64_transfers_32bit_regs_p = %d\n",
5883 mips64_transfers_32bit_regs_p);
5884
5885 /* Determine the MIPS FPU type. */
5886 #ifdef HAVE_ELF
5887 if (info.abfd
5888 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5889 elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
5890 Tag_GNU_MIPS_ABI_FP);
5891 #endif /* HAVE_ELF */
5892
5893 if (!mips_fpu_type_auto)
5894 fpu_type = mips_fpu_type;
5895 else if (elf_fpu_type != 0)
5896 {
5897 switch (elf_fpu_type)
5898 {
5899 case 1:
5900 fpu_type = MIPS_FPU_DOUBLE;
5901 break;
5902 case 2:
5903 fpu_type = MIPS_FPU_SINGLE;
5904 break;
5905 case 3:
5906 default:
5907 /* Soft float or unknown. */
5908 fpu_type = MIPS_FPU_NONE;
5909 break;
5910 }
5911 }
5912 else if (info.bfd_arch_info != NULL
5913 && info.bfd_arch_info->arch == bfd_arch_mips)
5914 switch (info.bfd_arch_info->mach)
5915 {
5916 case bfd_mach_mips3900:
5917 case bfd_mach_mips4100:
5918 case bfd_mach_mips4111:
5919 case bfd_mach_mips4120:
5920 fpu_type = MIPS_FPU_NONE;
5921 break;
5922 case bfd_mach_mips4650:
5923 fpu_type = MIPS_FPU_SINGLE;
5924 break;
5925 default:
5926 fpu_type = MIPS_FPU_DOUBLE;
5927 break;
5928 }
5929 else if (arches != NULL)
5930 fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type;
5931 else
5932 fpu_type = MIPS_FPU_DOUBLE;
5933 if (gdbarch_debug)
5934 fprintf_unfiltered (gdb_stdlog,
5935 "mips_gdbarch_init: fpu_type = %d\n", fpu_type);
5936
5937 /* Check for blatant incompatibilities. */
5938
5939 /* If we have only 32-bit registers, then we can't debug a 64-bit
5940 ABI. */
5941 if (info.target_desc
5942 && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL
5943 && mips_abi != MIPS_ABI_EABI32
5944 && mips_abi != MIPS_ABI_O32)
5945 {
5946 if (tdesc_data != NULL)
5947 tdesc_data_cleanup (tdesc_data);
5948 return NULL;
5949 }
5950
5951 /* Try to find a pre-existing architecture. */
5952 for (arches = gdbarch_list_lookup_by_info (arches, &info);
5953 arches != NULL;
5954 arches = gdbarch_list_lookup_by_info (arches->next, &info))
5955 {
5956 /* MIPS needs to be pedantic about which ABI the object is
5957 using. */
5958 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
5959 continue;
5960 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
5961 continue;
5962 /* Need to be pedantic about which register virtual size is
5963 used. */
5964 if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p
5965 != mips64_transfers_32bit_regs_p)
5966 continue;
5967 /* Be pedantic about which FPU is selected. */
5968 if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type)
5969 continue;
5970
5971 if (tdesc_data != NULL)
5972 tdesc_data_cleanup (tdesc_data);
5973 return arches->gdbarch;
5974 }
5975
5976 /* Need a new architecture. Fill in a target specific vector. */
5977 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
5978 gdbarch = gdbarch_alloc (&info, tdep);
5979 tdep->elf_flags = elf_flags;
5980 tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p;
5981 tdep->found_abi = found_abi;
5982 tdep->mips_abi = mips_abi;
5983 tdep->mips_fpu_type = fpu_type;
5984 tdep->register_size_valid_p = 0;
5985 tdep->register_size = 0;
5986 tdep->gregset = NULL;
5987 tdep->gregset64 = NULL;
5988 tdep->fpregset = NULL;
5989 tdep->fpregset64 = NULL;
5990
5991 if (info.target_desc)
5992 {
5993 /* Some useful properties can be inferred from the target. */
5994 if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL)
5995 {
5996 tdep->register_size_valid_p = 1;
5997 tdep->register_size = 4;
5998 }
5999 else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL)
6000 {
6001 tdep->register_size_valid_p = 1;
6002 tdep->register_size = 8;
6003 }
6004 }
6005
6006 /* Initially set everything according to the default ABI/ISA. */
6007 set_gdbarch_short_bit (gdbarch, 16);
6008 set_gdbarch_int_bit (gdbarch, 32);
6009 set_gdbarch_float_bit (gdbarch, 32);
6010 set_gdbarch_double_bit (gdbarch, 64);
6011 set_gdbarch_long_double_bit (gdbarch, 64);
6012 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
6013 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
6014 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
6015
6016 set_gdbarch_ax_pseudo_register_collect (gdbarch,
6017 mips_ax_pseudo_register_collect);
6018 set_gdbarch_ax_pseudo_register_push_stack
6019 (gdbarch, mips_ax_pseudo_register_push_stack);
6020
6021 set_gdbarch_elf_make_msymbol_special (gdbarch,
6022 mips_elf_make_msymbol_special);
6023
6024 /* Fill in the OS dependant register numbers and names. */
6025 {
6026 const char **reg_names;
6027 struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch,
6028 struct mips_regnum);
6029 if (tdesc_has_registers (info.target_desc))
6030 {
6031 regnum->lo = MIPS_EMBED_LO_REGNUM;
6032 regnum->hi = MIPS_EMBED_HI_REGNUM;
6033 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
6034 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
6035 regnum->pc = MIPS_EMBED_PC_REGNUM;
6036 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
6037 regnum->fp_control_status = 70;
6038 regnum->fp_implementation_revision = 71;
6039 num_regs = MIPS_LAST_EMBED_REGNUM + 1;
6040 reg_names = NULL;
6041 }
6042 else if (info.osabi == GDB_OSABI_IRIX)
6043 {
6044 regnum->fp0 = 32;
6045 regnum->pc = 64;
6046 regnum->cause = 65;
6047 regnum->badvaddr = 66;
6048 regnum->hi = 67;
6049 regnum->lo = 68;
6050 regnum->fp_control_status = 69;
6051 regnum->fp_implementation_revision = 70;
6052 num_regs = 71;
6053 reg_names = mips_irix_reg_names;
6054 }
6055 else
6056 {
6057 regnum->lo = MIPS_EMBED_LO_REGNUM;
6058 regnum->hi = MIPS_EMBED_HI_REGNUM;
6059 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
6060 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
6061 regnum->pc = MIPS_EMBED_PC_REGNUM;
6062 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
6063 regnum->fp_control_status = 70;
6064 regnum->fp_implementation_revision = 71;
6065 num_regs = 90;
6066 if (info.bfd_arch_info != NULL
6067 && info.bfd_arch_info->mach == bfd_mach_mips3900)
6068 reg_names = mips_tx39_reg_names;
6069 else
6070 reg_names = mips_generic_reg_names;
6071 }
6072 /* FIXME: cagney/2003-11-15: For MIPS, hasn't gdbarch_pc_regnum been
6073 replaced by gdbarch_read_pc? */
6074 set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs);
6075 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
6076 set_gdbarch_fp0_regnum (gdbarch, regnum->fp0);
6077 set_gdbarch_num_regs (gdbarch, num_regs);
6078 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
6079 set_gdbarch_register_name (gdbarch, mips_register_name);
6080 set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer);
6081 tdep->mips_processor_reg_names = reg_names;
6082 tdep->regnum = regnum;
6083 }
6084
6085 switch (mips_abi)
6086 {
6087 case MIPS_ABI_O32:
6088 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
6089 set_gdbarch_return_value (gdbarch, mips_o32_return_value);
6090 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
6091 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
6092 tdep->default_mask_address_p = 0;
6093 set_gdbarch_long_bit (gdbarch, 32);
6094 set_gdbarch_ptr_bit (gdbarch, 32);
6095 set_gdbarch_long_long_bit (gdbarch, 64);
6096 break;
6097 case MIPS_ABI_O64:
6098 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
6099 set_gdbarch_return_value (gdbarch, mips_o64_return_value);
6100 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
6101 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
6102 tdep->default_mask_address_p = 0;
6103 set_gdbarch_long_bit (gdbarch, 32);
6104 set_gdbarch_ptr_bit (gdbarch, 32);
6105 set_gdbarch_long_long_bit (gdbarch, 64);
6106 break;
6107 case MIPS_ABI_EABI32:
6108 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
6109 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
6110 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
6111 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6112 tdep->default_mask_address_p = 0;
6113 set_gdbarch_long_bit (gdbarch, 32);
6114 set_gdbarch_ptr_bit (gdbarch, 32);
6115 set_gdbarch_long_long_bit (gdbarch, 64);
6116 break;
6117 case MIPS_ABI_EABI64:
6118 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
6119 set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
6120 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
6121 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6122 tdep->default_mask_address_p = 0;
6123 set_gdbarch_long_bit (gdbarch, 64);
6124 set_gdbarch_ptr_bit (gdbarch, 64);
6125 set_gdbarch_long_long_bit (gdbarch, 64);
6126 break;
6127 case MIPS_ABI_N32:
6128 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
6129 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
6130 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
6131 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6132 tdep->default_mask_address_p = 0;
6133 set_gdbarch_long_bit (gdbarch, 32);
6134 set_gdbarch_ptr_bit (gdbarch, 32);
6135 set_gdbarch_long_long_bit (gdbarch, 64);
6136 set_gdbarch_long_double_bit (gdbarch, 128);
6137 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
6138 break;
6139 case MIPS_ABI_N64:
6140 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
6141 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
6142 tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
6143 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6144 tdep->default_mask_address_p = 0;
6145 set_gdbarch_long_bit (gdbarch, 64);
6146 set_gdbarch_ptr_bit (gdbarch, 64);
6147 set_gdbarch_long_long_bit (gdbarch, 64);
6148 set_gdbarch_long_double_bit (gdbarch, 128);
6149 set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
6150 break;
6151 default:
6152 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
6153 }
6154
6155 /* GCC creates a pseudo-section whose name specifies the size of
6156 longs, since -mlong32 or -mlong64 may be used independent of
6157 other options. How those options affect pointer sizes is ABI and
6158 architecture dependent, so use them to override the default sizes
6159 set by the ABI. This table shows the relationship between ABI,
6160 -mlongXX, and size of pointers:
6161
6162 ABI -mlongXX ptr bits
6163 --- -------- --------
6164 o32 32 32
6165 o32 64 32
6166 n32 32 32
6167 n32 64 64
6168 o64 32 32
6169 o64 64 64
6170 n64 32 32
6171 n64 64 64
6172 eabi32 32 32
6173 eabi32 64 32
6174 eabi64 32 32
6175 eabi64 64 64
6176
6177 Note that for o32 and eabi32, pointers are always 32 bits
6178 regardless of any -mlongXX option. For all others, pointers and
6179 longs are the same, as set by -mlongXX or set by defaults. */
6180
6181 if (info.abfd != NULL)
6182 {
6183 int long_bit = 0;
6184
6185 bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit);
6186 if (long_bit)
6187 {
6188 set_gdbarch_long_bit (gdbarch, long_bit);
6189 switch (mips_abi)
6190 {
6191 case MIPS_ABI_O32:
6192 case MIPS_ABI_EABI32:
6193 break;
6194 case MIPS_ABI_N32:
6195 case MIPS_ABI_O64:
6196 case MIPS_ABI_N64:
6197 case MIPS_ABI_EABI64:
6198 set_gdbarch_ptr_bit (gdbarch, long_bit);
6199 break;
6200 default:
6201 internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
6202 }
6203 }
6204 }
6205
6206 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
6207 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
6208 comment:
6209
6210 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
6211 flag in object files because to do so would make it impossible to
6212 link with libraries compiled without "-gp32". This is
6213 unnecessarily restrictive.
6214
6215 We could solve this problem by adding "-gp32" multilibs to gcc,
6216 but to set this flag before gcc is built with such multilibs will
6217 break too many systems.''
6218
6219 But even more unhelpfully, the default linker output target for
6220 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
6221 for 64-bit programs - you need to change the ABI to change this,
6222 and not all gcc targets support that currently. Therefore using
6223 this flag to detect 32-bit mode would do the wrong thing given
6224 the current gcc - it would make GDB treat these 64-bit programs
6225 as 32-bit programs by default. */
6226
6227 set_gdbarch_read_pc (gdbarch, mips_read_pc);
6228 set_gdbarch_write_pc (gdbarch, mips_write_pc);
6229
6230 /* Add/remove bits from an address. The MIPS needs be careful to
6231 ensure that all 32 bit addresses are sign extended to 64 bits. */
6232 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
6233
6234 /* Unwind the frame. */
6235 set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc);
6236 set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp);
6237 set_gdbarch_dummy_id (gdbarch, mips_dummy_id);
6238
6239 /* Map debug register numbers onto internal register numbers. */
6240 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6241 set_gdbarch_ecoff_reg_to_regnum (gdbarch,
6242 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6243 set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
6244 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6245 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
6246
6247 /* MIPS version of CALL_DUMMY. */
6248
6249 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
6250 replaced by a command, and all targets will default to on stack
6251 (regardless of the stack's execute status). */
6252 set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL);
6253 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6254
6255 set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p);
6256 set_gdbarch_register_to_value (gdbarch, mips_register_to_value);
6257 set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
6258
6259 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6260 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6261
6262 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6263
6264 set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p);
6265
6266 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6267 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6268 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6269
6270 set_gdbarch_register_type (gdbarch, mips_register_type);
6271
6272 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
6273
6274 if (mips_abi == MIPS_ABI_N32)
6275 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n32);
6276 else if (mips_abi == MIPS_ABI_N64)
6277 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n64);
6278 else
6279 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
6280
6281 /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint,
6282 HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint
6283 need to all be folded into the target vector. Since they are
6284 being used as guards for target_stopped_by_watchpoint, why not have
6285 target_stopped_by_watchpoint return the type of watchpoint that the code
6286 is sitting on? */
6287 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
6288
6289 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code);
6290
6291 set_gdbarch_single_step_through_delay (gdbarch,
6292 mips_single_step_through_delay);
6293
6294 /* Virtual tables. */
6295 set_gdbarch_vbit_in_delta (gdbarch, 1);
6296
6297 mips_register_g_packet_guesses (gdbarch);
6298
6299 /* Hook in OS ABI-specific overrides, if they have been registered. */
6300 info.tdep_info = (void *) tdesc_data;
6301 gdbarch_init_osabi (info, gdbarch);
6302
6303 /* Unwind the frame. */
6304 dwarf2_append_unwinders (gdbarch);
6305 frame_unwind_append_unwinder (gdbarch, &mips_stub_frame_unwind);
6306 frame_unwind_append_unwinder (gdbarch, &mips_insn16_frame_unwind);
6307 frame_unwind_append_unwinder (gdbarch, &mips_insn32_frame_unwind);
6308 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
6309 frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer);
6310 frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer);
6311 frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer);
6312
6313 if (tdesc_data)
6314 {
6315 set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type);
6316 tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
6317
6318 /* Override the normal target description methods to handle our
6319 dual real and pseudo registers. */
6320 set_gdbarch_register_name (gdbarch, mips_register_name);
6321 set_gdbarch_register_reggroup_p (gdbarch,
6322 mips_tdesc_register_reggroup_p);
6323
6324 num_regs = gdbarch_num_regs (gdbarch);
6325 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
6326 set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs);
6327 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
6328 }
6329
6330 /* Add ABI-specific aliases for the registers. */
6331 if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
6332 for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++)
6333 user_reg_add (gdbarch, mips_n32_n64_aliases[i].name,
6334 value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum);
6335 else
6336 for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++)
6337 user_reg_add (gdbarch, mips_o32_aliases[i].name,
6338 value_of_mips_user_reg, &mips_o32_aliases[i].regnum);
6339
6340 /* Add some other standard aliases. */
6341 for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++)
6342 user_reg_add (gdbarch, mips_register_aliases[i].name,
6343 value_of_mips_user_reg, &mips_register_aliases[i].regnum);
6344
6345 for (i = 0; i < ARRAY_SIZE (mips_numeric_register_aliases); i++)
6346 user_reg_add (gdbarch, mips_numeric_register_aliases[i].name,
6347 value_of_mips_user_reg,
6348 &mips_numeric_register_aliases[i].regnum);
6349
6350 return gdbarch;
6351 }
6352
6353 static void
6354 mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c)
6355 {
6356 struct gdbarch_info info;
6357
6358 /* Force the architecture to update, and (if it's a MIPS architecture)
6359 mips_gdbarch_init will take care of the rest. */
6360 gdbarch_info_init (&info);
6361 gdbarch_update_p (info);
6362 }
6363
6364 /* Print out which MIPS ABI is in use. */
6365
6366 static void
6367 show_mips_abi (struct ui_file *file,
6368 int from_tty,
6369 struct cmd_list_element *ignored_cmd,
6370 const char *ignored_value)
6371 {
6372 if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
6373 fprintf_filtered
6374 (file,
6375 "The MIPS ABI is unknown because the current architecture "
6376 "is not MIPS.\n");
6377 else
6378 {
6379 enum mips_abi global_abi = global_mips_abi ();
6380 enum mips_abi actual_abi = mips_abi (target_gdbarch);
6381 const char *actual_abi_str = mips_abi_strings[actual_abi];
6382
6383 if (global_abi == MIPS_ABI_UNKNOWN)
6384 fprintf_filtered
6385 (file,
6386 "The MIPS ABI is set automatically (currently \"%s\").\n",
6387 actual_abi_str);
6388 else if (global_abi == actual_abi)
6389 fprintf_filtered
6390 (file,
6391 "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6392 actual_abi_str);
6393 else
6394 {
6395 /* Probably shouldn't happen... */
6396 fprintf_filtered (file,
6397 "The (auto detected) MIPS ABI \"%s\" is in use "
6398 "even though the user setting was \"%s\".\n",
6399 actual_abi_str, mips_abi_strings[global_abi]);
6400 }
6401 }
6402 }
6403
6404 static void
6405 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
6406 {
6407 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
6408 if (tdep != NULL)
6409 {
6410 int ef_mips_arch;
6411 int ef_mips_32bitmode;
6412 /* Determine the ISA. */
6413 switch (tdep->elf_flags & EF_MIPS_ARCH)
6414 {
6415 case E_MIPS_ARCH_1:
6416 ef_mips_arch = 1;
6417 break;
6418 case E_MIPS_ARCH_2:
6419 ef_mips_arch = 2;
6420 break;
6421 case E_MIPS_ARCH_3:
6422 ef_mips_arch = 3;
6423 break;
6424 case E_MIPS_ARCH_4:
6425 ef_mips_arch = 4;
6426 break;
6427 default:
6428 ef_mips_arch = 0;
6429 break;
6430 }
6431 /* Determine the size of a pointer. */
6432 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6433 fprintf_unfiltered (file,
6434 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6435 tdep->elf_flags);
6436 fprintf_unfiltered (file,
6437 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6438 ef_mips_32bitmode);
6439 fprintf_unfiltered (file,
6440 "mips_dump_tdep: ef_mips_arch = %d\n",
6441 ef_mips_arch);
6442 fprintf_unfiltered (file,
6443 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6444 tdep->mips_abi, mips_abi_strings[tdep->mips_abi]);
6445 fprintf_unfiltered (file,
6446 "mips_dump_tdep: "
6447 "mips_mask_address_p() %d (default %d)\n",
6448 mips_mask_address_p (tdep),
6449 tdep->default_mask_address_p);
6450 }
6451 fprintf_unfiltered (file,
6452 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6453 MIPS_DEFAULT_FPU_TYPE,
6454 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6455 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6456 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6457 : "???"));
6458 fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n",
6459 MIPS_EABI (gdbarch));
6460 fprintf_unfiltered (file,
6461 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6462 MIPS_FPU_TYPE (gdbarch),
6463 (MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_NONE ? "none"
6464 : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_SINGLE ? "single"
6465 : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_DOUBLE ? "double"
6466 : "???"));
6467 }
6468
6469 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6470
6471 void
6472 _initialize_mips_tdep (void)
6473 {
6474 static struct cmd_list_element *mipsfpulist = NULL;
6475 struct cmd_list_element *c;
6476
6477 mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN];
6478 if (MIPS_ABI_LAST + 1
6479 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6480 internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync"));
6481
6482 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6483
6484 mips_pdr_data = register_objfile_data ();
6485
6486 /* Create feature sets with the appropriate properties. The values
6487 are not important. */
6488 mips_tdesc_gp32 = allocate_target_description ();
6489 set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, "");
6490
6491 mips_tdesc_gp64 = allocate_target_description ();
6492 set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, "");
6493
6494 /* Add root prefix command for all "set mips"/"show mips" commands. */
6495 add_prefix_cmd ("mips", no_class, set_mips_command,
6496 _("Various MIPS specific commands."),
6497 &setmipscmdlist, "set mips ", 0, &setlist);
6498
6499 add_prefix_cmd ("mips", no_class, show_mips_command,
6500 _("Various MIPS specific commands."),
6501 &showmipscmdlist, "show mips ", 0, &showlist);
6502
6503 /* Allow the user to override the ABI. */
6504 add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings,
6505 &mips_abi_string, _("\
6506 Set the MIPS ABI used by this program."), _("\
6507 Show the MIPS ABI used by this program."), _("\
6508 This option can be set to one of:\n\
6509 auto - the default ABI associated with the current binary\n\
6510 o32\n\
6511 o64\n\
6512 n32\n\
6513 n64\n\
6514 eabi32\n\
6515 eabi64"),
6516 mips_abi_update,
6517 show_mips_abi,
6518 &setmipscmdlist, &showmipscmdlist);
6519
6520 /* Let the user turn off floating point and set the fence post for
6521 heuristic_proc_start. */
6522
6523 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6524 _("Set use of MIPS floating-point coprocessor."),
6525 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6526 add_cmd ("single", class_support, set_mipsfpu_single_command,
6527 _("Select single-precision MIPS floating-point coprocessor."),
6528 &mipsfpulist);
6529 add_cmd ("double", class_support, set_mipsfpu_double_command,
6530 _("Select double-precision MIPS floating-point coprocessor."),
6531 &mipsfpulist);
6532 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6533 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6534 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6535 add_cmd ("none", class_support, set_mipsfpu_none_command,
6536 _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
6537 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6538 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6539 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6540 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6541 _("Select MIPS floating-point coprocessor automatically."),
6542 &mipsfpulist);
6543 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6544 _("Show current use of MIPS floating-point coprocessor target."),
6545 &showlist);
6546
6547 /* We really would like to have both "0" and "unlimited" work, but
6548 command.c doesn't deal with that. So make it a var_zinteger
6549 because the user can always use "999999" or some such for unlimited. */
6550 add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
6551 &heuristic_fence_post, _("\
6552 Set the distance searched for the start of a function."), _("\
6553 Show the distance searched for the start of a function."), _("\
6554 If you are debugging a stripped executable, GDB needs to search through the\n\
6555 program for the start of a function. This command sets the distance of the\n\
6556 search. The only need to set it is when debugging a stripped executable."),
6557 reinit_frame_cache_sfunc,
6558 NULL, /* FIXME: i18n: The distance searched for
6559 the start of a function is %s. */
6560 &setlist, &showlist);
6561
6562 /* Allow the user to control whether the upper bits of 64-bit
6563 addresses should be zeroed. */
6564 add_setshow_auto_boolean_cmd ("mask-address", no_class,
6565 &mask_address_var, _("\
6566 Set zeroing of upper 32 bits of 64-bit addresses."), _("\
6567 Show zeroing of upper 32 bits of 64-bit addresses."), _("\
6568 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\
6569 allow GDB to determine the correct value."),
6570 NULL, show_mask_address,
6571 &setmipscmdlist, &showmipscmdlist);
6572
6573 /* Allow the user to control the size of 32 bit registers within the
6574 raw remote packet. */
6575 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure,
6576 &mips64_transfers_32bit_regs_p, _("\
6577 Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6578 _("\
6579 Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
6580 _("\
6581 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6582 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6583 64 bits for others. Use \"off\" to disable compatibility mode"),
6584 set_mips64_transfers_32bit_regs,
6585 NULL, /* FIXME: i18n: Compatibility with 64-bit
6586 MIPS target that transfers 32-bit
6587 quantities is %s. */
6588 &setlist, &showlist);
6589
6590 /* Debug this files internals. */
6591 add_setshow_zinteger_cmd ("mips", class_maintenance,
6592 &mips_debug, _("\
6593 Set mips debugging."), _("\
6594 Show mips debugging."), _("\
6595 When non-zero, mips specific debugging is enabled."),
6596 NULL,
6597 NULL, /* FIXME: i18n: Mips debugging is
6598 currently %s. */
6599 &setdebuglist, &showdebuglist);
6600 }
This page took 0.177136 seconds and 5 git commands to generate.