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