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