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