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