ba8722cc9671711c849f8ef045024ae7a1414993
[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
1854 /* Scan through this function's instructions preceding the
1855 current PC, and look for those that save registers. */
1856 while (addr < frame_pc_unwind (next_frame))
1857 {
1858 mips16_decode_reg_save (mips16_fetch_instruction (addr),
1859 &gen_save_found);
1860 addr += MIPS16_INSTLEN;
1861 }
1862 gen_mask = gen_save_found;
1863 float_mask = float_save_found;
1864 }
1865
1866 /* Fill in the offsets for the registers which gen_mask says were
1867 saved. */
1868 {
1869 CORE_ADDR reg_position = (cache->base
1870 + PROC_REG_OFFSET (proc_desc));
1871 int ireg;
1872 for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
1873 if (gen_mask & 0x80000000)
1874 {
1875 cache->saved_regs[NUM_REGS + ireg].addr = reg_position;
1876 reg_position -= mips_abi_regsize (gdbarch);
1877 }
1878 }
1879
1880 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse
1881 order of that normally used by gcc. Therefore, we have to fetch
1882 the first instruction of the function, and if it's an entry
1883 instruction that saves $s0 or $s1, correct their saved addresses. */
1884 {
1885 ULONGEST inst = mips16_fetch_instruction (PROC_LOW_ADDR (proc_desc));
1886 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700)
1887 /* entry */
1888 {
1889 int reg;
1890 int sreg_count = (inst >> 6) & 3;
1891
1892 /* Check if the ra register was pushed on the stack. */
1893 CORE_ADDR reg_position = (cache->base
1894 + PROC_REG_OFFSET (proc_desc));
1895 if (inst & 0x20)
1896 reg_position -= mips_abi_regsize (gdbarch);
1897
1898 /* Check if the s0 and s1 registers were pushed on the
1899 stack. */
1900 /* NOTE: cagney/2004-02-08: Huh? This is doing no such
1901 check. */
1902 for (reg = 16; reg < sreg_count + 16; reg++)
1903 {
1904 cache->saved_regs[NUM_REGS + reg].addr = reg_position;
1905 reg_position -= mips_abi_regsize (gdbarch);
1906 }
1907 }
1908 }
1909
1910 /* Fill in the offsets for the registers which float_mask says were
1911 saved. */
1912 {
1913 CORE_ADDR reg_position = (cache->base
1914 + PROC_FREG_OFFSET (proc_desc));
1915 int ireg;
1916 /* Fill in the offsets for the float registers which float_mask
1917 says were saved. */
1918 for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1)
1919 if (float_mask & 0x80000000)
1920 {
1921 if (mips_abi_regsize (gdbarch) == 4
1922 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
1923 {
1924 /* On a big endian 32 bit ABI, floating point registers
1925 are paired to form doubles such that the most
1926 significant part is in $f[N+1] and the least
1927 significant in $f[N] vis: $f[N+1] ||| $f[N]. The
1928 registers are also spilled as a pair and stored as a
1929 double.
1930
1931 When little-endian the least significant part is
1932 stored first leading to the memory order $f[N] and
1933 then $f[N+1].
1934
1935 Unfortunately, when big-endian the most significant
1936 part of the double is stored first, and the least
1937 significant is stored second. This leads to the
1938 registers being ordered in memory as firt $f[N+1] and
1939 then $f[N].
1940
1941 For the big-endian case make certain that the
1942 addresses point at the correct (swapped) locations
1943 $f[N] and $f[N+1] pair (keep in mind that
1944 reg_position is decremented each time through the
1945 loop). */
1946 if ((ireg & 1))
1947 cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg]
1948 .addr = reg_position - mips_abi_regsize (gdbarch);
1949 else
1950 cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg]
1951 .addr = reg_position + mips_abi_regsize (gdbarch);
1952 }
1953 else
1954 cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg]
1955 .addr = reg_position;
1956 reg_position -= mips_abi_regsize (gdbarch);
1957 }
1958
1959 cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc]
1960 = cache->saved_regs[NUM_REGS + RA_REGNUM];
1961 }
1962
1963 /* SP_REGNUM, contains the value and not the address. */
1964 trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base);
1965
1966 return (*this_cache);
1967 }
1968
1969 static void
1970 mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache,
1971 struct frame_id *this_id)
1972 {
1973 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
1974 this_cache);
1975 (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
1976 }
1977
1978 static void
1979 mips_insn16_frame_prev_register (struct frame_info *next_frame,
1980 void **this_cache,
1981 int regnum, int *optimizedp,
1982 enum lval_type *lvalp, CORE_ADDR *addrp,
1983 int *realnump, void *valuep)
1984 {
1985 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
1986 this_cache);
1987 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
1988 optimizedp, lvalp, addrp, realnump, valuep);
1989 }
1990
1991 static const struct frame_unwind mips_insn16_frame_unwind =
1992 {
1993 NORMAL_FRAME,
1994 mips_insn16_frame_this_id,
1995 mips_insn16_frame_prev_register
1996 };
1997
1998 static const struct frame_unwind *
1999 mips_insn16_frame_sniffer (struct frame_info *next_frame)
2000 {
2001 CORE_ADDR pc = frame_pc_unwind (next_frame);
2002 if (pc_is_mips16 (pc))
2003 return &mips_insn16_frame_unwind;
2004 return NULL;
2005 }
2006
2007 static CORE_ADDR
2008 mips_insn16_frame_base_address (struct frame_info *next_frame,
2009 void **this_cache)
2010 {
2011 struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame,
2012 this_cache);
2013 return info->base;
2014 }
2015
2016 static const struct frame_base mips_insn16_frame_base =
2017 {
2018 &mips_insn16_frame_unwind,
2019 mips_insn16_frame_base_address,
2020 mips_insn16_frame_base_address,
2021 mips_insn16_frame_base_address
2022 };
2023
2024 static const struct frame_base *
2025 mips_insn16_frame_base_sniffer (struct frame_info *next_frame)
2026 {
2027 if (mips_insn16_frame_sniffer (next_frame) != NULL)
2028 return &mips_insn16_frame_base;
2029 else
2030 return NULL;
2031 }
2032
2033 /* Heuristic unwinder for procedures using 32-bit instructions (covers
2034 both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
2035 instructions (a.k.a. MIPS16) are handled by the mips_insn16
2036 unwinder. */
2037
2038 static struct mips_frame_cache *
2039 mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache)
2040 {
2041 mips_extra_func_info_t proc_desc;
2042 struct mips_frame_cache *cache;
2043 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2044 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2045 /* r0 bit means kernel trap */
2046 int kernel_trap;
2047 /* What registers have been saved? Bitmasks. */
2048 unsigned long gen_mask, float_mask;
2049
2050 if ((*this_cache) != NULL)
2051 return (*this_cache);
2052
2053 cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
2054 (*this_cache) = cache;
2055 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2056
2057 /* Synthesize a proc descriptor. */
2058 {
2059 const CORE_ADDR pc = frame_pc_unwind (next_frame);
2060 CORE_ADDR start_addr;
2061
2062 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2063 if (start_addr == 0)
2064 start_addr = heuristic_proc_start (pc);
2065
2066 proc_desc = heuristic_proc_desc (start_addr, pc, next_frame, *this_cache);
2067 }
2068
2069 if (proc_desc == NULL)
2070 /* I'm not sure how/whether this can happen. Normally when we
2071 can't find a proc_desc, we "synthesize" one using
2072 heuristic_proc_desc and set the saved_regs right away. */
2073 return cache;
2074
2075 /* SP_REGNUM, contains the value and not the address. */
2076 trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base);
2077
2078 return (*this_cache);
2079 }
2080
2081 static void
2082 mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache,
2083 struct frame_id *this_id)
2084 {
2085 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2086 this_cache);
2087 (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
2088 }
2089
2090 static void
2091 mips_insn32_frame_prev_register (struct frame_info *next_frame,
2092 void **this_cache,
2093 int regnum, int *optimizedp,
2094 enum lval_type *lvalp, CORE_ADDR *addrp,
2095 int *realnump, void *valuep)
2096 {
2097 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2098 this_cache);
2099 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
2100 optimizedp, lvalp, addrp, realnump, valuep);
2101 }
2102
2103 static const struct frame_unwind mips_insn32_frame_unwind =
2104 {
2105 NORMAL_FRAME,
2106 mips_insn32_frame_this_id,
2107 mips_insn32_frame_prev_register
2108 };
2109
2110 static const struct frame_unwind *
2111 mips_insn32_frame_sniffer (struct frame_info *next_frame)
2112 {
2113 CORE_ADDR pc = frame_pc_unwind (next_frame);
2114 if (! pc_is_mips16 (pc))
2115 return &mips_insn32_frame_unwind;
2116 return NULL;
2117 }
2118
2119 static CORE_ADDR
2120 mips_insn32_frame_base_address (struct frame_info *next_frame,
2121 void **this_cache)
2122 {
2123 struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame,
2124 this_cache);
2125 return info->base;
2126 }
2127
2128 static const struct frame_base mips_insn32_frame_base =
2129 {
2130 &mips_insn32_frame_unwind,
2131 mips_insn32_frame_base_address,
2132 mips_insn32_frame_base_address,
2133 mips_insn32_frame_base_address
2134 };
2135
2136 static const struct frame_base *
2137 mips_insn32_frame_base_sniffer (struct frame_info *next_frame)
2138 {
2139 if (mips_insn32_frame_sniffer (next_frame) != NULL)
2140 return &mips_insn32_frame_base;
2141 else
2142 return NULL;
2143 }
2144
2145 static struct trad_frame_cache *
2146 mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache)
2147 {
2148 CORE_ADDR pc;
2149 CORE_ADDR start_addr;
2150 CORE_ADDR stack_addr;
2151 struct trad_frame_cache *this_trad_cache;
2152
2153 if ((*this_cache) != NULL)
2154 return (*this_cache);
2155 this_trad_cache = trad_frame_cache_zalloc (next_frame);
2156 (*this_cache) = this_trad_cache;
2157
2158 /* The return address is in the link register. */
2159 trad_frame_set_reg_realreg (this_trad_cache, PC_REGNUM, RA_REGNUM);
2160
2161 /* Frame ID, since it's a frameless / stackless function, no stack
2162 space is allocated and SP on entry is the current SP. */
2163 pc = frame_pc_unwind (next_frame);
2164 find_pc_partial_function (pc, NULL, &start_addr, NULL);
2165 stack_addr = frame_unwind_register_signed (next_frame, SP_REGNUM);
2166 trad_frame_set_id (this_trad_cache, frame_id_build (start_addr, stack_addr));
2167
2168 /* Assume that the frame's base is the same as the
2169 stack-pointer. */
2170 trad_frame_set_this_base (this_trad_cache, stack_addr);
2171
2172 return this_trad_cache;
2173 }
2174
2175 static void
2176 mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache,
2177 struct frame_id *this_id)
2178 {
2179 struct trad_frame_cache *this_trad_cache
2180 = mips_stub_frame_cache (next_frame, this_cache);
2181 trad_frame_get_id (this_trad_cache, this_id);
2182 }
2183
2184 static void
2185 mips_stub_frame_prev_register (struct frame_info *next_frame,
2186 void **this_cache,
2187 int regnum, int *optimizedp,
2188 enum lval_type *lvalp, CORE_ADDR *addrp,
2189 int *realnump, void *valuep)
2190 {
2191 struct trad_frame_cache *this_trad_cache
2192 = mips_stub_frame_cache (next_frame, this_cache);
2193 trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp,
2194 lvalp, addrp, realnump, valuep);
2195 }
2196
2197 static const struct frame_unwind mips_stub_frame_unwind =
2198 {
2199 NORMAL_FRAME,
2200 mips_stub_frame_this_id,
2201 mips_stub_frame_prev_register
2202 };
2203
2204 static const struct frame_unwind *
2205 mips_stub_frame_sniffer (struct frame_info *next_frame)
2206 {
2207 CORE_ADDR pc = frame_pc_unwind (next_frame);
2208 if (in_plt_section (pc, NULL))
2209 return &mips_stub_frame_unwind;
2210 else
2211 return NULL;
2212 }
2213
2214 static CORE_ADDR
2215 mips_stub_frame_base_address (struct frame_info *next_frame,
2216 void **this_cache)
2217 {
2218 struct trad_frame_cache *this_trad_cache
2219 = mips_stub_frame_cache (next_frame, this_cache);
2220 return trad_frame_get_this_base (this_trad_cache);
2221 }
2222
2223 static const struct frame_base mips_stub_frame_base =
2224 {
2225 &mips_stub_frame_unwind,
2226 mips_stub_frame_base_address,
2227 mips_stub_frame_base_address,
2228 mips_stub_frame_base_address
2229 };
2230
2231 static const struct frame_base *
2232 mips_stub_frame_base_sniffer (struct frame_info *next_frame)
2233 {
2234 if (mips_stub_frame_sniffer (next_frame) != NULL)
2235 return &mips_stub_frame_base;
2236 else
2237 return NULL;
2238 }
2239
2240 static CORE_ADDR
2241 read_next_frame_reg (struct frame_info *fi, int regno)
2242 {
2243 /* Always a pseudo. */
2244 gdb_assert (regno >= NUM_REGS);
2245 if (fi == NULL)
2246 {
2247 LONGEST val;
2248 regcache_cooked_read_signed (current_regcache, regno, &val);
2249 return val;
2250 }
2251 else
2252 return frame_unwind_register_signed (fi, regno);
2253
2254 }
2255
2256 /* mips_addr_bits_remove - remove useless address bits */
2257
2258 static CORE_ADDR
2259 mips_addr_bits_remove (CORE_ADDR addr)
2260 {
2261 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2262 if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
2263 /* This hack is a work-around for existing boards using PMON, the
2264 simulator, and any other 64-bit targets that doesn't have true
2265 64-bit addressing. On these targets, the upper 32 bits of
2266 addresses are ignored by the hardware. Thus, the PC or SP are
2267 likely to have been sign extended to all 1s by instruction
2268 sequences that load 32-bit addresses. For example, a typical
2269 piece of code that loads an address is this:
2270
2271 lui $r2, <upper 16 bits>
2272 ori $r2, <lower 16 bits>
2273
2274 But the lui sign-extends the value such that the upper 32 bits
2275 may be all 1s. The workaround is simply to mask off these
2276 bits. In the future, gcc may be changed to support true 64-bit
2277 addressing, and this masking will have to be disabled. */
2278 return addr &= 0xffffffffUL;
2279 else
2280 return addr;
2281 }
2282
2283 /* mips_software_single_step() is called just before we want to resume
2284 the inferior, if we want to single-step it but there is no hardware
2285 or kernel single-step support (MIPS on GNU/Linux for example). We find
2286 the target of the coming instruction and breakpoint it.
2287
2288 single_step is also called just after the inferior stops. If we had
2289 set up a simulated single-step, we undo our damage. */
2290
2291 void
2292 mips_software_single_step (enum target_signal sig, int insert_breakpoints_p)
2293 {
2294 static CORE_ADDR next_pc;
2295 typedef char binsn_quantum[BREAKPOINT_MAX];
2296 static binsn_quantum break_mem;
2297 CORE_ADDR pc;
2298
2299 if (insert_breakpoints_p)
2300 {
2301 pc = read_register (mips_regnum (current_gdbarch)->pc);
2302 next_pc = mips_next_pc (pc);
2303
2304 target_insert_breakpoint (next_pc, break_mem);
2305 }
2306 else
2307 target_remove_breakpoint (next_pc, break_mem);
2308 }
2309
2310 static struct mips_extra_func_info temp_proc_desc;
2311
2312 /* Set a register's saved stack address in temp_saved_regs. If an
2313 address has already been set for this register, do nothing; this
2314 way we will only recognize the first save of a given register in a
2315 function prologue.
2316
2317 For simplicity, save the address in both [0 .. NUM_REGS) and
2318 [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range
2319 is used as it is only second range (the ABI instead of ISA
2320 registers) that comes into play when finding saved registers in a
2321 frame. */
2322
2323 static void
2324 set_reg_offset (struct mips_frame_cache *this_cache, int regnum,
2325 CORE_ADDR offset)
2326 {
2327 if (this_cache != NULL
2328 && this_cache->saved_regs[regnum].addr == -1)
2329 {
2330 this_cache->saved_regs[regnum + 0 * NUM_REGS].addr = offset;
2331 this_cache->saved_regs[regnum + 1 * NUM_REGS].addr = offset;
2332 }
2333 }
2334
2335
2336 /* Test whether the PC points to the return instruction at the
2337 end of a function. */
2338
2339 static int
2340 mips_about_to_return (CORE_ADDR pc)
2341 {
2342 if (pc_is_mips16 (pc))
2343 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2344 generates a "jr $ra"; other times it generates code to load
2345 the return address from the stack to an accessible register (such
2346 as $a3), then a "jr" using that register. This second case
2347 is almost impossible to distinguish from an indirect jump
2348 used for switch statements, so we don't even try. */
2349 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
2350 else
2351 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
2352 }
2353
2354
2355 /* This fencepost looks highly suspicious to me. Removing it also
2356 seems suspicious as it could affect remote debugging across serial
2357 lines. */
2358
2359 static CORE_ADDR
2360 heuristic_proc_start (CORE_ADDR pc)
2361 {
2362 CORE_ADDR start_pc;
2363 CORE_ADDR fence;
2364 int instlen;
2365 int seen_adjsp = 0;
2366
2367 pc = ADDR_BITS_REMOVE (pc);
2368 start_pc = pc;
2369 fence = start_pc - heuristic_fence_post;
2370 if (start_pc == 0)
2371 return 0;
2372
2373 if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS)
2374 fence = VM_MIN_ADDRESS;
2375
2376 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
2377
2378 /* search back for previous return */
2379 for (start_pc -= instlen;; start_pc -= instlen)
2380 if (start_pc < fence)
2381 {
2382 /* It's not clear to me why we reach this point when
2383 stop_soon, but with this test, at least we
2384 don't print out warnings for every child forked (eg, on
2385 decstation). 22apr93 rich@cygnus.com. */
2386 if (stop_soon == NO_STOP_QUIETLY)
2387 {
2388 static int blurb_printed = 0;
2389
2390 warning ("GDB can't find the start of the function at 0x%s.",
2391 paddr_nz (pc));
2392
2393 if (!blurb_printed)
2394 {
2395 /* This actually happens frequently in embedded
2396 development, when you first connect to a board
2397 and your stack pointer and pc are nowhere in
2398 particular. This message needs to give people
2399 in that situation enough information to
2400 determine that it's no big deal. */
2401 printf_filtered ("\n\
2402 GDB is unable to find the start of the function at 0x%s\n\
2403 and thus can't determine the size of that function's stack frame.\n\
2404 This means that GDB may be unable to access that stack frame, or\n\
2405 the frames below it.\n\
2406 This problem is most likely caused by an invalid program counter or\n\
2407 stack pointer.\n\
2408 However, if you think GDB should simply search farther back\n\
2409 from 0x%s for code which looks like the beginning of a\n\
2410 function, you can increase the range of the search using the `set\n\
2411 heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc));
2412 blurb_printed = 1;
2413 }
2414 }
2415
2416 return 0;
2417 }
2418 else if (pc_is_mips16 (start_pc))
2419 {
2420 unsigned short inst;
2421
2422 /* On MIPS16, any one of the following is likely to be the
2423 start of a function:
2424 entry
2425 addiu sp,-n
2426 daddiu sp,-n
2427 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
2428 inst = mips_fetch_instruction (start_pc);
2429 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2430 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
2431 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
2432 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
2433 break;
2434 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
2435 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2436 seen_adjsp = 1;
2437 else
2438 seen_adjsp = 0;
2439 }
2440 else if (mips_about_to_return (start_pc))
2441 {
2442 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
2443 break;
2444 }
2445
2446 return start_pc;
2447 }
2448
2449 /* Fetch the immediate value from a MIPS16 instruction.
2450 If the previous instruction was an EXTEND, use it to extend
2451 the upper bits of the immediate value. This is a helper function
2452 for mips16_heuristic_proc_desc. */
2453
2454 static int
2455 mips16_get_imm (unsigned short prev_inst, /* previous instruction */
2456 unsigned short inst, /* current instruction */
2457 int nbits, /* number of bits in imm field */
2458 int scale, /* scale factor to be applied to imm */
2459 int is_signed) /* is the imm field signed? */
2460 {
2461 int offset;
2462
2463 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
2464 {
2465 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
2466 if (offset & 0x8000) /* check for negative extend */
2467 offset = 0 - (0x10000 - (offset & 0xffff));
2468 return offset | (inst & 0x1f);
2469 }
2470 else
2471 {
2472 int max_imm = 1 << nbits;
2473 int mask = max_imm - 1;
2474 int sign_bit = max_imm >> 1;
2475
2476 offset = inst & mask;
2477 if (is_signed && (offset & sign_bit))
2478 offset = 0 - (max_imm - offset);
2479 return offset * scale;
2480 }
2481 }
2482
2483
2484 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
2485 stream from start_pc to limit_pc. */
2486
2487 static void
2488 mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2489 CORE_ADDR sp,
2490 struct frame_info *next_frame,
2491 struct mips_frame_cache *this_cache)
2492 {
2493 CORE_ADDR cur_pc;
2494 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
2495 unsigned short prev_inst = 0; /* saved copy of previous instruction */
2496 unsigned inst = 0; /* current instruction */
2497 unsigned entry_inst = 0; /* the entry instruction */
2498 int reg, offset;
2499 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2500
2501 PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */
2502 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
2503
2504 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
2505 {
2506 /* Save the previous instruction. If it's an EXTEND, we'll extract
2507 the immediate offset extension from it in mips16_get_imm. */
2508 prev_inst = inst;
2509
2510 /* Fetch and decode the instruction. */
2511 inst = (unsigned short) mips_fetch_instruction (cur_pc);
2512 if ((inst & 0xff00) == 0x6300 /* addiu sp */
2513 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
2514 {
2515 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
2516 if (offset < 0) /* negative stack adjustment? */
2517 PROC_FRAME_OFFSET (&temp_proc_desc) -= offset;
2518 else
2519 /* Exit loop if a positive stack adjustment is found, which
2520 usually means that the stack cleanup code in the function
2521 epilogue is reached. */
2522 break;
2523 }
2524 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
2525 {
2526 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2527 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
2528 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2529 set_reg_offset (this_cache, reg, sp + offset);
2530 }
2531 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
2532 {
2533 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2534 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2535 PROC_REG_MASK (&temp_proc_desc) |= (1 << reg);
2536 set_reg_offset (this_cache, reg, sp + offset);
2537 }
2538 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
2539 {
2540 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2541 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2542 set_reg_offset (this_cache, RA_REGNUM, sp + offset);
2543 }
2544 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
2545 {
2546 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
2547 PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM);
2548 set_reg_offset (this_cache, RA_REGNUM, sp + offset);
2549 }
2550 else if (inst == 0x673d) /* move $s1, $sp */
2551 {
2552 frame_addr = sp;
2553 PROC_FRAME_REG (&temp_proc_desc) = 17;
2554 }
2555 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
2556 {
2557 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
2558 frame_addr = sp + offset;
2559 PROC_FRAME_REG (&temp_proc_desc) = 17;
2560 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
2561 }
2562 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
2563 {
2564 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
2565 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2566 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2567 set_reg_offset (this_cache, reg, frame_addr + offset);
2568 }
2569 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
2570 {
2571 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
2572 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
2573 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2574 set_reg_offset (this_cache, reg, frame_addr + offset);
2575 }
2576 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
2577 entry_inst = inst; /* save for later processing */
2578 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
2579 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
2580 }
2581
2582 /* The entry instruction is typically the first instruction in a function,
2583 and it stores registers at offsets relative to the value of the old SP
2584 (before the prologue). But the value of the sp parameter to this
2585 function is the new SP (after the prologue has been executed). So we
2586 can't calculate those offsets until we've seen the entire prologue,
2587 and can calculate what the old SP must have been. */
2588 if (entry_inst != 0)
2589 {
2590 int areg_count = (entry_inst >> 8) & 7;
2591 int sreg_count = (entry_inst >> 6) & 3;
2592
2593 /* The entry instruction always subtracts 32 from the SP. */
2594 PROC_FRAME_OFFSET (&temp_proc_desc) += 32;
2595
2596 /* Now we can calculate what the SP must have been at the
2597 start of the function prologue. */
2598 sp += PROC_FRAME_OFFSET (&temp_proc_desc);
2599
2600 /* Check if a0-a3 were saved in the caller's argument save area. */
2601 for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
2602 {
2603 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2604 set_reg_offset (this_cache, reg, sp + offset);
2605 offset += mips_abi_regsize (current_gdbarch);
2606 }
2607
2608 /* Check if the ra register was pushed on the stack. */
2609 offset = -4;
2610 if (entry_inst & 0x20)
2611 {
2612 PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM;
2613 set_reg_offset (this_cache, RA_REGNUM, sp + offset);
2614 offset -= mips_abi_regsize (current_gdbarch);
2615 }
2616
2617 /* Check if the s0 and s1 registers were pushed on the stack. */
2618 for (reg = 16; reg < sreg_count + 16; reg++)
2619 {
2620 PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
2621 set_reg_offset (this_cache, reg, sp + offset);
2622 offset -= mips_abi_regsize (current_gdbarch);
2623 }
2624 }
2625 }
2626
2627 /* Mark all the registers as unset in the saved_regs array
2628 of THIS_CACHE. Do nothing if THIS_CACHE is null. */
2629
2630 void
2631 reset_saved_regs (struct mips_frame_cache *this_cache)
2632 {
2633 if (this_cache == NULL || this_cache->saved_regs == NULL)
2634 return;
2635
2636 {
2637 const int num_regs = NUM_REGS;
2638 int i;
2639
2640 for (i = 0; i < num_regs; i++)
2641 {
2642 this_cache->saved_regs[i].addr = -1;
2643 }
2644 }
2645 }
2646
2647 static void
2648 mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2649 CORE_ADDR sp, struct frame_info *next_frame,
2650 struct mips_frame_cache *this_cache)
2651 {
2652 CORE_ADDR cur_pc;
2653 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
2654 long frame_offset;
2655 int frame_reg = MIPS_SP_REGNUM;
2656
2657 restart:
2658
2659 frame_offset = 0;
2660 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
2661 {
2662 unsigned long inst, high_word, low_word;
2663 int reg;
2664
2665 /* Fetch the instruction. */
2666 inst = (unsigned long) mips_fetch_instruction (cur_pc);
2667
2668 /* Save some code by pre-extracting some useful fields. */
2669 high_word = (inst >> 16) & 0xffff;
2670 low_word = inst & 0xffff;
2671 reg = high_word & 0x1f;
2672
2673 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
2674 || high_word == 0x23bd /* addi $sp,$sp,-i */
2675 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
2676 {
2677 if (low_word & 0x8000) /* negative stack adjustment? */
2678 frame_offset += 0x10000 - low_word;
2679 else
2680 /* Exit loop if a positive stack adjustment is found, which
2681 usually means that the stack cleanup code in the function
2682 epilogue is reached. */
2683 break;
2684 }
2685 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
2686 {
2687 set_reg_offset (this_cache, reg, sp + low_word);
2688 }
2689 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
2690 {
2691 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and
2692 $ra. */
2693 set_reg_offset (this_cache, reg, sp + low_word);
2694 }
2695 else if (high_word == 0x27be) /* addiu $30,$sp,size */
2696 {
2697 /* Old gcc frame, r30 is virtual frame pointer. */
2698 if ((long) low_word != frame_offset)
2699 frame_addr = sp + low_word;
2700 else if (frame_reg == MIPS_SP_REGNUM)
2701 {
2702 unsigned alloca_adjust;
2703
2704 frame_reg = 30;
2705 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2706 alloca_adjust = (unsigned) (frame_addr - (sp + low_word));
2707 if (alloca_adjust > 0)
2708 {
2709 /* FP > SP + frame_size. This may be because of
2710 an alloca or somethings similar. Fix sp to
2711 "pre-alloca" value, and try again. */
2712 sp += alloca_adjust;
2713 /* Need to reset the status of all registers. Otherwise,
2714 we will hit a guard that prevents the new address
2715 for each register to be recomputed during the second
2716 pass. */
2717 reset_saved_regs (this_cache);
2718 goto restart;
2719 }
2720 }
2721 }
2722 /* move $30,$sp. With different versions of gas this will be either
2723 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
2724 Accept any one of these. */
2725 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2726 {
2727 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
2728 if (frame_reg == MIPS_SP_REGNUM)
2729 {
2730 unsigned alloca_adjust;
2731
2732 frame_reg = 30;
2733 frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30);
2734 alloca_adjust = (unsigned) (frame_addr - sp);
2735 if (alloca_adjust > 0)
2736 {
2737 /* FP > SP + frame_size. This may be because of
2738 an alloca or somethings similar. Fix sp to
2739 "pre-alloca" value, and try again. */
2740 sp = frame_addr;
2741 /* Need to reset the status of all registers. Otherwise,
2742 we will hit a guard that prevents the new address
2743 for each register to be recomputed during the second
2744 pass. */
2745 reset_saved_regs (this_cache);
2746 goto restart;
2747 }
2748 }
2749 }
2750 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
2751 {
2752 set_reg_offset (this_cache, reg, frame_addr + low_word);
2753 }
2754 }
2755
2756 if (this_cache != NULL)
2757 {
2758 this_cache->base =
2759 (frame_unwind_register_signed (next_frame, NUM_REGS + frame_reg)
2760 + frame_offset);
2761 /* FIXME: brobecker/2004-09-15: We should be able to get rid of
2762 this assignment below, eventually. But it's still needed
2763 for now. */
2764 this_cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc]
2765 = this_cache->saved_regs[NUM_REGS + RA_REGNUM];
2766 }
2767 }
2768
2769 static mips_extra_func_info_t
2770 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
2771 struct frame_info *next_frame,
2772 struct mips_frame_cache *this_cache)
2773 {
2774 CORE_ADDR sp;
2775
2776 /* Can be called when there's no process, and hence when there's no
2777 NEXT_FRAME. */
2778 if (next_frame != NULL)
2779 sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM);
2780 else
2781 sp = 0;
2782
2783 if (start_pc == 0)
2784 return NULL;
2785 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
2786 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
2787 PROC_FRAME_REG (&temp_proc_desc) = MIPS_SP_REGNUM;
2788 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
2789
2790 if (start_pc + 200 < limit_pc)
2791 limit_pc = start_pc + 200;
2792 if (pc_is_mips16 (start_pc))
2793 mips16_heuristic_proc_desc (start_pc, limit_pc, sp,
2794 next_frame, this_cache);
2795 else
2796 mips32_heuristic_proc_desc (start_pc, limit_pc, sp,
2797 next_frame, this_cache);
2798 return &temp_proc_desc;
2799 }
2800
2801 struct mips_objfile_private
2802 {
2803 bfd_size_type size;
2804 char *contents;
2805 };
2806
2807 /* Global used to communicate between non_heuristic_proc_desc and
2808 compare_pdr_entries within qsort (). */
2809 static bfd *the_bfd;
2810
2811 static int
2812 compare_pdr_entries (const void *a, const void *b)
2813 {
2814 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
2815 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
2816
2817 if (lhs < rhs)
2818 return -1;
2819 else if (lhs == rhs)
2820 return 0;
2821 else
2822 return 1;
2823 }
2824
2825 static mips_extra_func_info_t
2826 non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr)
2827 {
2828 CORE_ADDR startaddr;
2829 mips_extra_func_info_t proc_desc;
2830 struct block *b = block_for_pc (pc);
2831 struct symbol *sym;
2832 struct obj_section *sec;
2833 struct mips_objfile_private *priv;
2834
2835 find_pc_partial_function (pc, NULL, &startaddr, NULL);
2836 if (addrptr)
2837 *addrptr = startaddr;
2838
2839 priv = NULL;
2840
2841 sec = find_pc_section (pc);
2842 if (sec != NULL)
2843 {
2844 priv = (struct mips_objfile_private *) objfile_data (sec->objfile, mips_pdr_data);
2845
2846 /* Search the ".pdr" section generated by GAS. This includes most of
2847 the information normally found in ECOFF PDRs. */
2848
2849 the_bfd = sec->objfile->obfd;
2850 if (priv == NULL
2851 && (the_bfd->format == bfd_object
2852 && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour
2853 && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64))
2854 {
2855 /* Right now GAS only outputs the address as a four-byte sequence.
2856 This means that we should not bother with this method on 64-bit
2857 targets (until that is fixed). */
2858
2859 priv = obstack_alloc (&sec->objfile->objfile_obstack,
2860 sizeof (struct mips_objfile_private));
2861 priv->size = 0;
2862 set_objfile_data (sec->objfile, mips_pdr_data, priv);
2863 }
2864 else if (priv == NULL)
2865 {
2866 asection *bfdsec;
2867
2868 priv = obstack_alloc (&sec->objfile->objfile_obstack,
2869 sizeof (struct mips_objfile_private));
2870
2871 bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr");
2872 if (bfdsec != NULL)
2873 {
2874 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
2875 priv->contents = obstack_alloc (&sec->objfile->objfile_obstack,
2876 priv->size);
2877 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
2878 priv->contents, 0, priv->size);
2879
2880 /* In general, the .pdr section is sorted. However, in the
2881 presence of multiple code sections (and other corner cases)
2882 it can become unsorted. Sort it so that we can use a faster
2883 binary search. */
2884 qsort (priv->contents, priv->size / 32, 32,
2885 compare_pdr_entries);
2886 }
2887 else
2888 priv->size = 0;
2889
2890 set_objfile_data (sec->objfile, mips_pdr_data, priv);
2891 }
2892 the_bfd = NULL;
2893
2894 if (priv->size != 0)
2895 {
2896 int low, mid, high;
2897 char *ptr;
2898 CORE_ADDR pdr_pc;
2899
2900 low = 0;
2901 high = priv->size / 32;
2902
2903 /* We've found a .pdr section describing this objfile. We want to
2904 find the entry which describes this code address. The .pdr
2905 information is not very descriptive; we have only a function
2906 start address. We have to look for the closest entry, because
2907 the local symbol at the beginning of this function may have
2908 been stripped - so if we ask the symbol table for the start
2909 address we may get a preceding global function. */
2910
2911 /* First, find the last .pdr entry starting at or before PC. */
2912 do
2913 {
2914 mid = (low + high) / 2;
2915
2916 ptr = priv->contents + mid * 32;
2917 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2918 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2919 SECT_OFF_TEXT (sec->objfile));
2920
2921 if (pdr_pc > pc)
2922 high = mid;
2923 else
2924 low = mid + 1;
2925 }
2926 while (low != high);
2927
2928 /* Both low and high point one past the PDR of interest. If
2929 both are zero, that means this PC is before any region
2930 covered by a PDR, i.e. pdr_pc for the first PDR entry is
2931 greater than PC. */
2932 if (low > 0)
2933 {
2934 ptr = priv->contents + (low - 1) * 32;
2935 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
2936 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
2937 SECT_OFF_TEXT (sec->objfile));
2938 }
2939
2940 /* We don't have a range, so we have no way to know for sure
2941 whether we're in the correct PDR or a PDR for a preceding
2942 function and the current function was a stripped local
2943 symbol. But if the PDR's PC is at least as great as the
2944 best guess from the symbol table, assume that it does cover
2945 the right area; if a .pdr section is present at all then
2946 nearly every function will have an entry. The biggest exception
2947 will be the dynamic linker stubs; conveniently these are
2948 placed before .text instead of after. */
2949
2950 if (pc >= pdr_pc && pdr_pc >= startaddr)
2951 {
2952 struct symbol *sym = find_pc_function (pc);
2953
2954 if (addrptr)
2955 *addrptr = pdr_pc;
2956
2957 /* Fill in what we need of the proc_desc. */
2958 proc_desc = (mips_extra_func_info_t)
2959 obstack_alloc (&sec->objfile->objfile_obstack,
2960 sizeof (struct mips_extra_func_info));
2961 PROC_LOW_ADDR (proc_desc) = pdr_pc;
2962
2963 /* Only used for dummy frames. */
2964 PROC_HIGH_ADDR (proc_desc) = 0;
2965
2966 PROC_FRAME_OFFSET (proc_desc)
2967 = bfd_get_32 (sec->objfile->obfd, ptr + 20);
2968 PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2969 ptr + 24);
2970 PROC_FRAME_ADJUST (proc_desc) = 0;
2971 PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2972 ptr + 4);
2973 PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2974 ptr + 12);
2975 PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2976 ptr + 8);
2977 PROC_FREG_OFFSET (proc_desc)
2978 = bfd_get_32 (sec->objfile->obfd, ptr + 16);
2979 PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd,
2980 ptr + 28);
2981 proc_desc->pdr.isym = (long) sym;
2982
2983 return proc_desc;
2984 }
2985 }
2986 }
2987
2988 if (b == NULL)
2989 return NULL;
2990
2991 if (startaddr > BLOCK_START (b))
2992 {
2993 /* This is the "pathological" case referred to in a comment in
2994 print_frame_info. It might be better to move this check into
2995 symbol reading. */
2996 return NULL;
2997 }
2998
2999 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL);
3000
3001 /* If we never found a PDR for this function in symbol reading, then
3002 examine prologues to find the information. */
3003 if (sym)
3004 {
3005 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
3006 if (PROC_FRAME_REG (proc_desc) == -1)
3007 return NULL;
3008 else
3009 return proc_desc;
3010 }
3011 else
3012 return NULL;
3013 }
3014
3015 /* MIPS stack frames are almost impenetrable. When execution stops,
3016 we basically have to look at symbol information for the function
3017 that we stopped in, which tells us *which* register (if any) is
3018 the base of the frame pointer, and what offset from that register
3019 the frame itself is at.
3020
3021 This presents a problem when trying to examine a stack in memory
3022 (that isn't executing at the moment), using the "frame" command. We
3023 don't have a PC, nor do we have any registers except SP.
3024
3025 This routine takes two arguments, SP and PC, and tries to make the
3026 cached frames look as if these two arguments defined a frame on the
3027 cache. This allows the rest of info frame to extract the important
3028 arguments without difficulty. */
3029
3030 struct frame_info *
3031 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
3032 {
3033 if (argc != 2)
3034 error ("MIPS frame specifications require two arguments: sp and pc");
3035
3036 return create_new_frame (argv[0], argv[1]);
3037 }
3038
3039 /* According to the current ABI, should the type be passed in a
3040 floating-point register (assuming that there is space)? When there
3041 is no FPU, FP are not even considered as possibile candidates for
3042 FP registers and, consequently this returns false - forces FP
3043 arguments into integer registers. */
3044
3045 static int
3046 fp_register_arg_p (enum type_code typecode, struct type *arg_type)
3047 {
3048 return ((typecode == TYPE_CODE_FLT
3049 || (MIPS_EABI
3050 && (typecode == TYPE_CODE_STRUCT
3051 || typecode == TYPE_CODE_UNION)
3052 && TYPE_NFIELDS (arg_type) == 1
3053 && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT))
3054 && MIPS_FPU_TYPE != MIPS_FPU_NONE);
3055 }
3056
3057 /* On o32, argument passing in GPRs depends on the alignment of the type being
3058 passed. Return 1 if this type must be aligned to a doubleword boundary. */
3059
3060 static int
3061 mips_type_needs_double_align (struct type *type)
3062 {
3063 enum type_code typecode = TYPE_CODE (type);
3064
3065 if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
3066 return 1;
3067 else if (typecode == TYPE_CODE_STRUCT)
3068 {
3069 if (TYPE_NFIELDS (type) < 1)
3070 return 0;
3071 return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
3072 }
3073 else if (typecode == TYPE_CODE_UNION)
3074 {
3075 int i, n;
3076
3077 n = TYPE_NFIELDS (type);
3078 for (i = 0; i < n; i++)
3079 if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
3080 return 1;
3081 return 0;
3082 }
3083 return 0;
3084 }
3085
3086 /* Adjust the address downward (direction of stack growth) so that it
3087 is correctly aligned for a new stack frame. */
3088 static CORE_ADDR
3089 mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
3090 {
3091 return align_down (addr, 16);
3092 }
3093
3094 /* Determine how a return value is stored within the MIPS register
3095 file, given the return type `valtype'. */
3096
3097 struct return_value_word
3098 {
3099 int len;
3100 int reg;
3101 int reg_offset;
3102 int buf_offset;
3103 };
3104
3105 static void
3106 return_value_location (struct type *valtype,
3107 struct return_value_word *hi,
3108 struct return_value_word *lo)
3109 {
3110 int len = TYPE_LENGTH (valtype);
3111 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3112
3113 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
3114 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
3115 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
3116 {
3117 if (mips_abi_regsize (current_gdbarch) < 8 && len == 8)
3118 {
3119 /* We need to break a 64bit float in two 32 bit halves and
3120 spread them across a floating-point register pair. */
3121 lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3122 hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4;
3123 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3124 && register_size (current_gdbarch,
3125 mips_regnum (current_gdbarch)->
3126 fp0) == 8) ? 4 : 0);
3127 hi->reg_offset = lo->reg_offset;
3128 lo->reg = mips_regnum (current_gdbarch)->fp0 + 0;
3129 hi->reg = mips_regnum (current_gdbarch)->fp0 + 1;
3130 lo->len = 4;
3131 hi->len = 4;
3132 }
3133 else
3134 {
3135 /* The floating point value fits in a single floating-point
3136 register. */
3137 lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3138 && register_size (current_gdbarch,
3139 mips_regnum (current_gdbarch)->
3140 fp0) == 8
3141 && len == 4) ? 4 : 0);
3142 lo->reg = mips_regnum (current_gdbarch)->fp0;
3143 lo->len = len;
3144 lo->buf_offset = 0;
3145 hi->len = 0;
3146 hi->reg_offset = 0;
3147 hi->buf_offset = 0;
3148 hi->reg = 0;
3149 }
3150 }
3151 else
3152 {
3153 /* Locate a result possibly spread across two registers. */
3154 int regnum = 2;
3155 lo->reg = regnum + 0;
3156 hi->reg = regnum + 1;
3157 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3158 && len < mips_abi_regsize (current_gdbarch))
3159 {
3160 /* "un-left-justify" the value in the low register */
3161 lo->reg_offset = mips_abi_regsize (current_gdbarch) - len;
3162 lo->len = len;
3163 hi->reg_offset = 0;
3164 hi->len = 0;
3165 }
3166 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG && len > mips_abi_regsize (current_gdbarch) /* odd-size structs */
3167 && len < mips_abi_regsize (current_gdbarch) * 2
3168 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
3169 TYPE_CODE (valtype) == TYPE_CODE_UNION))
3170 {
3171 /* "un-left-justify" the value spread across two registers. */
3172 lo->reg_offset = 2 * mips_abi_regsize (current_gdbarch) - len;
3173 lo->len = mips_abi_regsize (current_gdbarch) - lo->reg_offset;
3174 hi->reg_offset = 0;
3175 hi->len = len - lo->len;
3176 }
3177 else
3178 {
3179 /* Only perform a partial copy of the second register. */
3180 lo->reg_offset = 0;
3181 hi->reg_offset = 0;
3182 if (len > mips_abi_regsize (current_gdbarch))
3183 {
3184 lo->len = mips_abi_regsize (current_gdbarch);
3185 hi->len = len - mips_abi_regsize (current_gdbarch);
3186 }
3187 else
3188 {
3189 lo->len = len;
3190 hi->len = 0;
3191 }
3192 }
3193 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3194 && register_size (current_gdbarch, regnum) == 8
3195 && mips_abi_regsize (current_gdbarch) == 4)
3196 {
3197 /* Account for the fact that only the least-signficant part
3198 of the register is being used */
3199 lo->reg_offset += 4;
3200 hi->reg_offset += 4;
3201 }
3202 lo->buf_offset = 0;
3203 hi->buf_offset = lo->len;
3204 }
3205 }
3206
3207 /* Should call_function allocate stack space for a struct return? */
3208
3209 static int
3210 mips_eabi_use_struct_convention (int gcc_p, struct type *type)
3211 {
3212 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3213 return (TYPE_LENGTH (type) > 2 * mips_abi_regsize (current_gdbarch));
3214 }
3215
3216 /* Should call_function pass struct by reference?
3217 For each architecture, structs are passed either by
3218 value or by reference, depending on their size. */
3219
3220 static int
3221 mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type)
3222 {
3223 enum type_code typecode = TYPE_CODE (check_typedef (type));
3224 int len = TYPE_LENGTH (check_typedef (type));
3225 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3226
3227 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
3228 return (len > mips_abi_regsize (current_gdbarch));
3229
3230 return 0;
3231 }
3232
3233 static CORE_ADDR
3234 mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3235 struct regcache *regcache, CORE_ADDR bp_addr,
3236 int nargs, struct value **args, CORE_ADDR sp,
3237 int struct_return, CORE_ADDR struct_addr)
3238 {
3239 int argreg;
3240 int float_argreg;
3241 int argnum;
3242 int len = 0;
3243 int stack_offset = 0;
3244 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3245 CORE_ADDR func_addr = find_function_addr (function, NULL);
3246
3247 /* For shared libraries, "t9" needs to point at the function
3248 address. */
3249 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3250
3251 /* Set the return address register to point to the entry point of
3252 the program, where a breakpoint lies in wait. */
3253 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3254
3255 /* First ensure that the stack and structure return address (if any)
3256 are properly aligned. The stack has to be at least 64-bit
3257 aligned even on 32-bit machines, because doubles must be 64-bit
3258 aligned. For n32 and n64, stack frames need to be 128-bit
3259 aligned, so we round to this widest known alignment. */
3260
3261 sp = align_down (sp, 16);
3262 struct_addr = align_down (struct_addr, 16);
3263
3264 /* Now make space on the stack for the args. We allocate more
3265 than necessary for EABI, because the first few arguments are
3266 passed in registers, but that's OK. */
3267 for (argnum = 0; argnum < nargs; argnum++)
3268 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3269 mips_stack_argsize (gdbarch));
3270 sp -= align_up (len, 16);
3271
3272 if (mips_debug)
3273 fprintf_unfiltered (gdb_stdlog,
3274 "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n",
3275 paddr_nz (sp), (long) align_up (len, 16));
3276
3277 /* Initialize the integer and float register pointers. */
3278 argreg = A0_REGNUM;
3279 float_argreg = mips_fpa0_regnum (current_gdbarch);
3280
3281 /* The struct_return pointer occupies the first parameter-passing reg. */
3282 if (struct_return)
3283 {
3284 if (mips_debug)
3285 fprintf_unfiltered (gdb_stdlog,
3286 "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n",
3287 argreg, paddr_nz (struct_addr));
3288 write_register (argreg++, struct_addr);
3289 }
3290
3291 /* Now load as many as possible of the first arguments into
3292 registers, and push the rest onto the stack. Loop thru args
3293 from first to last. */
3294 for (argnum = 0; argnum < nargs; argnum++)
3295 {
3296 char *val;
3297 char valbuf[MAX_REGISTER_SIZE];
3298 struct value *arg = args[argnum];
3299 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3300 int len = TYPE_LENGTH (arg_type);
3301 enum type_code typecode = TYPE_CODE (arg_type);
3302
3303 if (mips_debug)
3304 fprintf_unfiltered (gdb_stdlog,
3305 "mips_eabi_push_dummy_call: %d len=%d type=%d",
3306 argnum + 1, len, (int) typecode);
3307
3308 /* The EABI passes structures that do not fit in a register by
3309 reference. */
3310 if (len > mips_abi_regsize (gdbarch)
3311 && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
3312 {
3313 store_unsigned_integer (valbuf, mips_abi_regsize (gdbarch),
3314 VALUE_ADDRESS (arg));
3315 typecode = TYPE_CODE_PTR;
3316 len = mips_abi_regsize (gdbarch);
3317 val = valbuf;
3318 if (mips_debug)
3319 fprintf_unfiltered (gdb_stdlog, " push");
3320 }
3321 else
3322 val = (char *) VALUE_CONTENTS (arg);
3323
3324 /* 32-bit ABIs always start floating point arguments in an
3325 even-numbered floating point register. Round the FP register
3326 up before the check to see if there are any FP registers
3327 left. Non MIPS_EABI targets also pass the FP in the integer
3328 registers so also round up normal registers. */
3329 if (mips_abi_regsize (gdbarch) < 8
3330 && fp_register_arg_p (typecode, arg_type))
3331 {
3332 if ((float_argreg & 1))
3333 float_argreg++;
3334 }
3335
3336 /* Floating point arguments passed in registers have to be
3337 treated specially. On 32-bit architectures, doubles
3338 are passed in register pairs; the even register gets
3339 the low word, and the odd register gets the high word.
3340 On non-EABI processors, the first two floating point arguments are
3341 also copied to general registers, because MIPS16 functions
3342 don't use float registers for arguments. This duplication of
3343 arguments in general registers can't hurt non-MIPS16 functions
3344 because those registers are normally skipped. */
3345 /* MIPS_EABI squeezes a struct that contains a single floating
3346 point value into an FP register instead of pushing it onto the
3347 stack. */
3348 if (fp_register_arg_p (typecode, arg_type)
3349 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3350 {
3351 if (mips_abi_regsize (gdbarch) < 8 && len == 8)
3352 {
3353 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3354 unsigned long regval;
3355
3356 /* Write the low word of the double to the even register(s). */
3357 regval = extract_unsigned_integer (val + low_offset, 4);
3358 if (mips_debug)
3359 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3360 float_argreg, phex (regval, 4));
3361 write_register (float_argreg++, regval);
3362
3363 /* Write the high word of the double to the odd register(s). */
3364 regval = extract_unsigned_integer (val + 4 - low_offset, 4);
3365 if (mips_debug)
3366 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3367 float_argreg, phex (regval, 4));
3368 write_register (float_argreg++, regval);
3369 }
3370 else
3371 {
3372 /* This is a floating point value that fits entirely
3373 in a single register. */
3374 /* On 32 bit ABI's the float_argreg is further adjusted
3375 above to ensure that it is even register aligned. */
3376 LONGEST regval = extract_unsigned_integer (val, len);
3377 if (mips_debug)
3378 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3379 float_argreg, phex (regval, len));
3380 write_register (float_argreg++, regval);
3381 }
3382 }
3383 else
3384 {
3385 /* Copy the argument to general registers or the stack in
3386 register-sized pieces. Large arguments are split between
3387 registers and stack. */
3388 /* Note: structs whose size is not a multiple of
3389 mips_abi_regsize() are treated specially: Irix cc passes
3390 them in registers where gcc sometimes puts them on the
3391 stack. For maximum compatibility, we will put them in
3392 both places. */
3393 int odd_sized_struct = ((len > mips_abi_regsize (gdbarch))
3394 && (len % mips_abi_regsize (gdbarch) != 0));
3395
3396 /* Note: Floating-point values that didn't fit into an FP
3397 register are only written to memory. */
3398 while (len > 0)
3399 {
3400 /* Remember if the argument was written to the stack. */
3401 int stack_used_p = 0;
3402 int partial_len = (len < mips_abi_regsize (gdbarch)
3403 ? len : mips_abi_regsize (gdbarch));
3404
3405 if (mips_debug)
3406 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3407 partial_len);
3408
3409 /* Write this portion of the argument to the stack. */
3410 if (argreg > MIPS_LAST_ARG_REGNUM
3411 || odd_sized_struct
3412 || fp_register_arg_p (typecode, arg_type))
3413 {
3414 /* Should shorter than int integer values be
3415 promoted to int before being stored? */
3416 int longword_offset = 0;
3417 CORE_ADDR addr;
3418 stack_used_p = 1;
3419 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3420 {
3421 if (mips_stack_argsize (gdbarch) == 8
3422 && (typecode == TYPE_CODE_INT
3423 || typecode == TYPE_CODE_PTR
3424 || typecode == TYPE_CODE_FLT) && len <= 4)
3425 longword_offset = mips_stack_argsize (gdbarch) - len;
3426 else if ((typecode == TYPE_CODE_STRUCT
3427 || typecode == TYPE_CODE_UNION)
3428 && (TYPE_LENGTH (arg_type)
3429 < mips_stack_argsize (gdbarch)))
3430 longword_offset = mips_stack_argsize (gdbarch) - len;
3431 }
3432
3433 if (mips_debug)
3434 {
3435 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3436 paddr_nz (stack_offset));
3437 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3438 paddr_nz (longword_offset));
3439 }
3440
3441 addr = sp + stack_offset + longword_offset;
3442
3443 if (mips_debug)
3444 {
3445 int i;
3446 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3447 paddr_nz (addr));
3448 for (i = 0; i < partial_len; i++)
3449 {
3450 fprintf_unfiltered (gdb_stdlog, "%02x",
3451 val[i] & 0xff);
3452 }
3453 }
3454 write_memory (addr, val, partial_len);
3455 }
3456
3457 /* Note!!! This is NOT an else clause. Odd sized
3458 structs may go thru BOTH paths. Floating point
3459 arguments will not. */
3460 /* Write this portion of the argument to a general
3461 purpose register. */
3462 if (argreg <= MIPS_LAST_ARG_REGNUM
3463 && !fp_register_arg_p (typecode, arg_type))
3464 {
3465 LONGEST regval =
3466 extract_unsigned_integer (val, partial_len);
3467
3468 if (mips_debug)
3469 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3470 argreg,
3471 phex (regval,
3472 mips_abi_regsize (gdbarch)));
3473 write_register (argreg, regval);
3474 argreg++;
3475 }
3476
3477 len -= partial_len;
3478 val += partial_len;
3479
3480 /* Compute the the offset into the stack at which we
3481 will copy the next parameter.
3482
3483 In the new EABI (and the NABI32), the stack_offset
3484 only needs to be adjusted when it has been used. */
3485
3486 if (stack_used_p)
3487 stack_offset += align_up (partial_len,
3488 mips_stack_argsize (gdbarch));
3489 }
3490 }
3491 if (mips_debug)
3492 fprintf_unfiltered (gdb_stdlog, "\n");
3493 }
3494
3495 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3496
3497 /* Return adjusted stack pointer. */
3498 return sp;
3499 }
3500
3501 /* Given a return value in `regbuf' with a type `valtype', extract and
3502 copy its value into `valbuf'. */
3503
3504 static void
3505 mips_eabi_extract_return_value (struct type *valtype,
3506 char regbuf[], char *valbuf)
3507 {
3508 struct return_value_word lo;
3509 struct return_value_word hi;
3510 return_value_location (valtype, &hi, &lo);
3511
3512 memcpy (valbuf + lo.buf_offset,
3513 regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + lo.reg) +
3514 lo.reg_offset, lo.len);
3515
3516 if (hi.len > 0)
3517 memcpy (valbuf + hi.buf_offset,
3518 regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + hi.reg) +
3519 hi.reg_offset, hi.len);
3520 }
3521
3522 /* Given a return value in `valbuf' with a type `valtype', write it's
3523 value into the appropriate register. */
3524
3525 static void
3526 mips_eabi_store_return_value (struct type *valtype, char *valbuf)
3527 {
3528 char raw_buffer[MAX_REGISTER_SIZE];
3529 struct return_value_word lo;
3530 struct return_value_word hi;
3531 return_value_location (valtype, &hi, &lo);
3532
3533 memset (raw_buffer, 0, sizeof (raw_buffer));
3534 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
3535 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg),
3536 raw_buffer, register_size (current_gdbarch,
3537 lo.reg));
3538
3539 if (hi.len > 0)
3540 {
3541 memset (raw_buffer, 0, sizeof (raw_buffer));
3542 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
3543 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg),
3544 raw_buffer,
3545 register_size (current_gdbarch,
3546 hi.reg));
3547 }
3548 }
3549
3550 /* N32/N64 ABI stuff. */
3551
3552 static CORE_ADDR
3553 mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3554 struct regcache *regcache, CORE_ADDR bp_addr,
3555 int nargs, struct value **args, CORE_ADDR sp,
3556 int struct_return, CORE_ADDR struct_addr)
3557 {
3558 int argreg;
3559 int float_argreg;
3560 int argnum;
3561 int len = 0;
3562 int stack_offset = 0;
3563 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3564 CORE_ADDR func_addr = find_function_addr (function, NULL);
3565
3566 /* For shared libraries, "t9" needs to point at the function
3567 address. */
3568 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3569
3570 /* Set the return address register to point to the entry point of
3571 the program, where a breakpoint lies in wait. */
3572 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3573
3574 /* First ensure that the stack and structure return address (if any)
3575 are properly aligned. The stack has to be at least 64-bit
3576 aligned even on 32-bit machines, because doubles must be 64-bit
3577 aligned. For n32 and n64, stack frames need to be 128-bit
3578 aligned, so we round to this widest known alignment. */
3579
3580 sp = align_down (sp, 16);
3581 struct_addr = align_down (struct_addr, 16);
3582
3583 /* Now make space on the stack for the args. */
3584 for (argnum = 0; argnum < nargs; argnum++)
3585 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3586 mips_stack_argsize (gdbarch));
3587 sp -= align_up (len, 16);
3588
3589 if (mips_debug)
3590 fprintf_unfiltered (gdb_stdlog,
3591 "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n",
3592 paddr_nz (sp), (long) align_up (len, 16));
3593
3594 /* Initialize the integer and float register pointers. */
3595 argreg = A0_REGNUM;
3596 float_argreg = mips_fpa0_regnum (current_gdbarch);
3597
3598 /* The struct_return pointer occupies the first parameter-passing reg. */
3599 if (struct_return)
3600 {
3601 if (mips_debug)
3602 fprintf_unfiltered (gdb_stdlog,
3603 "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n",
3604 argreg, paddr_nz (struct_addr));
3605 write_register (argreg++, struct_addr);
3606 }
3607
3608 /* Now load as many as possible of the first arguments into
3609 registers, and push the rest onto the stack. Loop thru args
3610 from first to last. */
3611 for (argnum = 0; argnum < nargs; argnum++)
3612 {
3613 char *val;
3614 struct value *arg = args[argnum];
3615 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3616 int len = TYPE_LENGTH (arg_type);
3617 enum type_code typecode = TYPE_CODE (arg_type);
3618
3619 if (mips_debug)
3620 fprintf_unfiltered (gdb_stdlog,
3621 "mips_n32n64_push_dummy_call: %d len=%d type=%d",
3622 argnum + 1, len, (int) typecode);
3623
3624 val = (char *) VALUE_CONTENTS (arg);
3625
3626 if (fp_register_arg_p (typecode, arg_type)
3627 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3628 {
3629 /* This is a floating point value that fits entirely
3630 in a single register. */
3631 /* On 32 bit ABI's the float_argreg is further adjusted
3632 above to ensure that it is even register aligned. */
3633 LONGEST regval = extract_unsigned_integer (val, len);
3634 if (mips_debug)
3635 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
3636 float_argreg, phex (regval, len));
3637 write_register (float_argreg++, regval);
3638
3639 if (mips_debug)
3640 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
3641 argreg, phex (regval, len));
3642 write_register (argreg, regval);
3643 argreg += 1;
3644 }
3645 else
3646 {
3647 /* Copy the argument to general registers or the stack in
3648 register-sized pieces. Large arguments are split between
3649 registers and stack. */
3650 /* Note: structs whose size is not a multiple of
3651 mips_abi_regsize() are treated specially: Irix cc passes
3652 them in registers where gcc sometimes puts them on the
3653 stack. For maximum compatibility, we will put them in
3654 both places. */
3655 int odd_sized_struct = ((len > mips_abi_regsize (gdbarch))
3656 && (len % mips_abi_regsize (gdbarch) != 0));
3657 /* Note: Floating-point values that didn't fit into an FP
3658 register are only written to memory. */
3659 while (len > 0)
3660 {
3661 /* Rememer if the argument was written to the stack. */
3662 int stack_used_p = 0;
3663 int partial_len = (len < mips_abi_regsize (gdbarch)
3664 ? len : mips_abi_regsize (gdbarch));
3665
3666 if (mips_debug)
3667 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
3668 partial_len);
3669
3670 /* Write this portion of the argument to the stack. */
3671 if (argreg > MIPS_LAST_ARG_REGNUM
3672 || odd_sized_struct
3673 || fp_register_arg_p (typecode, arg_type))
3674 {
3675 /* Should shorter than int integer values be
3676 promoted to int before being stored? */
3677 int longword_offset = 0;
3678 CORE_ADDR addr;
3679 stack_used_p = 1;
3680 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3681 {
3682 if (mips_stack_argsize (gdbarch) == 8
3683 && (typecode == TYPE_CODE_INT
3684 || typecode == TYPE_CODE_PTR
3685 || typecode == TYPE_CODE_FLT) && len <= 4)
3686 longword_offset = mips_stack_argsize (gdbarch) - len;
3687 }
3688
3689 if (mips_debug)
3690 {
3691 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
3692 paddr_nz (stack_offset));
3693 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
3694 paddr_nz (longword_offset));
3695 }
3696
3697 addr = sp + stack_offset + longword_offset;
3698
3699 if (mips_debug)
3700 {
3701 int i;
3702 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
3703 paddr_nz (addr));
3704 for (i = 0; i < partial_len; i++)
3705 {
3706 fprintf_unfiltered (gdb_stdlog, "%02x",
3707 val[i] & 0xff);
3708 }
3709 }
3710 write_memory (addr, val, partial_len);
3711 }
3712
3713 /* Note!!! This is NOT an else clause. Odd sized
3714 structs may go thru BOTH paths. Floating point
3715 arguments will not. */
3716 /* Write this portion of the argument to a general
3717 purpose register. */
3718 if (argreg <= MIPS_LAST_ARG_REGNUM
3719 && !fp_register_arg_p (typecode, arg_type))
3720 {
3721 LONGEST regval =
3722 extract_unsigned_integer (val, partial_len);
3723
3724 /* A non-floating-point argument being passed in a
3725 general register. If a struct or union, and if
3726 the remaining length is smaller than the register
3727 size, we have to adjust the register value on
3728 big endian targets.
3729
3730 It does not seem to be necessary to do the
3731 same for integral types.
3732
3733 cagney/2001-07-23: gdb/179: Also, GCC, when
3734 outputting LE O32 with sizeof (struct) <
3735 mips_abi_regsize(), generates a left shift as
3736 part of storing the argument in a register a
3737 register (the left shift isn't generated when
3738 sizeof (struct) >= mips_abi_regsize()). Since
3739 it is quite possible that this is GCC
3740 contradicting the LE/O32 ABI, GDB has not been
3741 adjusted to accommodate this. Either someone
3742 needs to demonstrate that the LE/O32 ABI
3743 specifies such a left shift OR this new ABI gets
3744 identified as such and GDB gets tweaked
3745 accordingly. */
3746
3747 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3748 && partial_len < mips_abi_regsize (gdbarch)
3749 && (typecode == TYPE_CODE_STRUCT ||
3750 typecode == TYPE_CODE_UNION))
3751 regval <<= ((mips_abi_regsize (gdbarch) - partial_len) *
3752 TARGET_CHAR_BIT);
3753
3754 if (mips_debug)
3755 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
3756 argreg,
3757 phex (regval,
3758 mips_abi_regsize (gdbarch)));
3759 write_register (argreg, regval);
3760 argreg++;
3761 }
3762
3763 len -= partial_len;
3764 val += partial_len;
3765
3766 /* Compute the the offset into the stack at which we
3767 will copy the next parameter.
3768
3769 In N32 (N64?), the stack_offset only needs to be
3770 adjusted when it has been used. */
3771
3772 if (stack_used_p)
3773 stack_offset += align_up (partial_len,
3774 mips_stack_argsize (gdbarch));
3775 }
3776 }
3777 if (mips_debug)
3778 fprintf_unfiltered (gdb_stdlog, "\n");
3779 }
3780
3781 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
3782
3783 /* Return adjusted stack pointer. */
3784 return sp;
3785 }
3786
3787 static enum return_value_convention
3788 mips_n32n64_return_value (struct gdbarch *gdbarch,
3789 struct type *type, struct regcache *regcache,
3790 void *readbuf, const void *writebuf)
3791 {
3792 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3793 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3794 || TYPE_CODE (type) == TYPE_CODE_UNION
3795 || TYPE_CODE (type) == TYPE_CODE_ARRAY
3796 || TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch))
3797 return RETURN_VALUE_STRUCT_CONVENTION;
3798 else if (TYPE_CODE (type) == TYPE_CODE_FLT
3799 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3800 {
3801 /* A floating-point value belongs in the least significant part
3802 of FP0. */
3803 if (mips_debug)
3804 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
3805 mips_xfer_register (regcache,
3806 NUM_REGS + mips_regnum (current_gdbarch)->fp0,
3807 TYPE_LENGTH (type),
3808 TARGET_BYTE_ORDER, readbuf, writebuf, 0);
3809 return RETURN_VALUE_REGISTER_CONVENTION;
3810 }
3811 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3812 && TYPE_NFIELDS (type) <= 2
3813 && TYPE_NFIELDS (type) >= 1
3814 && ((TYPE_NFIELDS (type) == 1
3815 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3816 == TYPE_CODE_FLT))
3817 || (TYPE_NFIELDS (type) == 2
3818 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
3819 == TYPE_CODE_FLT)
3820 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
3821 == TYPE_CODE_FLT)))
3822 && tdep->mips_fpu_type != MIPS_FPU_NONE)
3823 {
3824 /* A struct that contains one or two floats. Each value is part
3825 in the least significant part of their floating point
3826 register.. */
3827 int regnum;
3828 int field;
3829 for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0;
3830 field < TYPE_NFIELDS (type); field++, regnum += 2)
3831 {
3832 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
3833 / TARGET_CHAR_BIT);
3834 if (mips_debug)
3835 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
3836 offset);
3837 mips_xfer_register (regcache, NUM_REGS + regnum,
3838 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
3839 TARGET_BYTE_ORDER, readbuf, writebuf, offset);
3840 }
3841 return RETURN_VALUE_REGISTER_CONVENTION;
3842 }
3843 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
3844 || TYPE_CODE (type) == TYPE_CODE_UNION)
3845 {
3846 /* A structure or union. Extract the left justified value,
3847 regardless of the byte order. I.e. DO NOT USE
3848 mips_xfer_lower. */
3849 int offset;
3850 int regnum;
3851 for (offset = 0, regnum = V0_REGNUM;
3852 offset < TYPE_LENGTH (type);
3853 offset += register_size (current_gdbarch, regnum), regnum++)
3854 {
3855 int xfer = register_size (current_gdbarch, regnum);
3856 if (offset + xfer > TYPE_LENGTH (type))
3857 xfer = TYPE_LENGTH (type) - offset;
3858 if (mips_debug)
3859 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
3860 offset, xfer, regnum);
3861 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
3862 BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
3863 }
3864 return RETURN_VALUE_REGISTER_CONVENTION;
3865 }
3866 else
3867 {
3868 /* A scalar extract each part but least-significant-byte
3869 justified. */
3870 int offset;
3871 int regnum;
3872 for (offset = 0, regnum = V0_REGNUM;
3873 offset < TYPE_LENGTH (type);
3874 offset += register_size (current_gdbarch, regnum), regnum++)
3875 {
3876 int xfer = register_size (current_gdbarch, regnum);
3877 if (offset + xfer > TYPE_LENGTH (type))
3878 xfer = TYPE_LENGTH (type) - offset;
3879 if (mips_debug)
3880 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
3881 offset, xfer, regnum);
3882 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
3883 TARGET_BYTE_ORDER, readbuf, writebuf, offset);
3884 }
3885 return RETURN_VALUE_REGISTER_CONVENTION;
3886 }
3887 }
3888
3889 /* O32 ABI stuff. */
3890
3891 static CORE_ADDR
3892 mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3893 struct regcache *regcache, CORE_ADDR bp_addr,
3894 int nargs, struct value **args, CORE_ADDR sp,
3895 int struct_return, CORE_ADDR struct_addr)
3896 {
3897 int argreg;
3898 int float_argreg;
3899 int argnum;
3900 int len = 0;
3901 int stack_offset = 0;
3902 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3903 CORE_ADDR func_addr = find_function_addr (function, NULL);
3904
3905 /* For shared libraries, "t9" needs to point at the function
3906 address. */
3907 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
3908
3909 /* Set the return address register to point to the entry point of
3910 the program, where a breakpoint lies in wait. */
3911 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
3912
3913 /* First ensure that the stack and structure return address (if any)
3914 are properly aligned. The stack has to be at least 64-bit
3915 aligned even on 32-bit machines, because doubles must be 64-bit
3916 aligned. For n32 and n64, stack frames need to be 128-bit
3917 aligned, so we round to this widest known alignment. */
3918
3919 sp = align_down (sp, 16);
3920 struct_addr = align_down (struct_addr, 16);
3921
3922 /* Now make space on the stack for the args. */
3923 for (argnum = 0; argnum < nargs; argnum++)
3924 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
3925 mips_stack_argsize (gdbarch));
3926 sp -= align_up (len, 16);
3927
3928 if (mips_debug)
3929 fprintf_unfiltered (gdb_stdlog,
3930 "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n",
3931 paddr_nz (sp), (long) align_up (len, 16));
3932
3933 /* Initialize the integer and float register pointers. */
3934 argreg = A0_REGNUM;
3935 float_argreg = mips_fpa0_regnum (current_gdbarch);
3936
3937 /* The struct_return pointer occupies the first parameter-passing reg. */
3938 if (struct_return)
3939 {
3940 if (mips_debug)
3941 fprintf_unfiltered (gdb_stdlog,
3942 "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n",
3943 argreg, paddr_nz (struct_addr));
3944 write_register (argreg++, struct_addr);
3945 stack_offset += mips_stack_argsize (gdbarch);
3946 }
3947
3948 /* Now load as many as possible of the first arguments into
3949 registers, and push the rest onto the stack. Loop thru args
3950 from first to last. */
3951 for (argnum = 0; argnum < nargs; argnum++)
3952 {
3953 char *val;
3954 struct value *arg = args[argnum];
3955 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
3956 int len = TYPE_LENGTH (arg_type);
3957 enum type_code typecode = TYPE_CODE (arg_type);
3958
3959 if (mips_debug)
3960 fprintf_unfiltered (gdb_stdlog,
3961 "mips_o32_push_dummy_call: %d len=%d type=%d",
3962 argnum + 1, len, (int) typecode);
3963
3964 val = (char *) VALUE_CONTENTS (arg);
3965
3966 /* 32-bit ABIs always start floating point arguments in an
3967 even-numbered floating point register. Round the FP register
3968 up before the check to see if there are any FP registers
3969 left. O32/O64 targets also pass the FP in the integer
3970 registers so also round up normal registers. */
3971 if (mips_abi_regsize (gdbarch) < 8
3972 && fp_register_arg_p (typecode, arg_type))
3973 {
3974 if ((float_argreg & 1))
3975 float_argreg++;
3976 }
3977
3978 /* Floating point arguments passed in registers have to be
3979 treated specially. On 32-bit architectures, doubles
3980 are passed in register pairs; the even register gets
3981 the low word, and the odd register gets the high word.
3982 On O32/O64, the first two floating point arguments are
3983 also copied to general registers, because MIPS16 functions
3984 don't use float registers for arguments. This duplication of
3985 arguments in general registers can't hurt non-MIPS16 functions
3986 because those registers are normally skipped. */
3987
3988 if (fp_register_arg_p (typecode, arg_type)
3989 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
3990 {
3991 if (mips_abi_regsize (gdbarch) < 8 && len == 8)
3992 {
3993 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
3994 unsigned long regval;
3995
3996 /* Write the low word of the double to the even register(s). */
3997 regval = extract_unsigned_integer (val + low_offset, 4);
3998 if (mips_debug)
3999 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4000 float_argreg, phex (regval, 4));
4001 write_register (float_argreg++, regval);
4002 if (mips_debug)
4003 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4004 argreg, phex (regval, 4));
4005 write_register (argreg++, regval);
4006
4007 /* Write the high word of the double to the odd register(s). */
4008 regval = extract_unsigned_integer (val + 4 - 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
4014 if (mips_debug)
4015 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4016 argreg, phex (regval, 4));
4017 write_register (argreg++, regval);
4018 }
4019 else
4020 {
4021 /* This is a floating point value that fits entirely
4022 in a single register. */
4023 /* On 32 bit ABI's the float_argreg is further adjusted
4024 above to ensure that it is even register aligned. */
4025 LONGEST regval = extract_unsigned_integer (val, len);
4026 if (mips_debug)
4027 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4028 float_argreg, phex (regval, len));
4029 write_register (float_argreg++, regval);
4030 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
4031 registers for each argument. The below is (my
4032 guess) to ensure that the corresponding integer
4033 register has reserved the same space. */
4034 if (mips_debug)
4035 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4036 argreg, phex (regval, len));
4037 write_register (argreg, regval);
4038 argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2;
4039 }
4040 /* Reserve space for the FP register. */
4041 stack_offset += align_up (len, mips_stack_argsize (gdbarch));
4042 }
4043 else
4044 {
4045 /* Copy the argument to general registers or the stack in
4046 register-sized pieces. Large arguments are split between
4047 registers and stack. */
4048 /* Note: structs whose size is not a multiple of
4049 mips_abi_regsize() are treated specially: Irix cc passes
4050 them in registers where gcc sometimes puts them on the
4051 stack. For maximum compatibility, we will put them in
4052 both places. */
4053 int odd_sized_struct = ((len > mips_abi_regsize (gdbarch))
4054 && (len % mips_abi_regsize (gdbarch) != 0));
4055 /* Structures should be aligned to eight bytes (even arg registers)
4056 on MIPS_ABI_O32, if their first member has double precision. */
4057 if (mips_abi_regsize (gdbarch) < 8
4058 && mips_type_needs_double_align (arg_type))
4059 {
4060 if ((argreg & 1))
4061 argreg++;
4062 }
4063 /* Note: Floating-point values that didn't fit into an FP
4064 register are only written to memory. */
4065 while (len > 0)
4066 {
4067 /* Remember if the argument was written to the stack. */
4068 int stack_used_p = 0;
4069 int partial_len = (len < mips_abi_regsize (gdbarch)
4070 ? len : mips_abi_regsize (gdbarch));
4071
4072 if (mips_debug)
4073 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
4074 partial_len);
4075
4076 /* Write this portion of the argument to the stack. */
4077 if (argreg > MIPS_LAST_ARG_REGNUM
4078 || odd_sized_struct
4079 || fp_register_arg_p (typecode, arg_type))
4080 {
4081 /* Should shorter than int integer values be
4082 promoted to int before being stored? */
4083 int longword_offset = 0;
4084 CORE_ADDR addr;
4085 stack_used_p = 1;
4086 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4087 {
4088 if (mips_stack_argsize (gdbarch) == 8
4089 && (typecode == TYPE_CODE_INT
4090 || typecode == TYPE_CODE_PTR
4091 || typecode == TYPE_CODE_FLT) && len <= 4)
4092 longword_offset = mips_stack_argsize (gdbarch) - len;
4093 }
4094
4095 if (mips_debug)
4096 {
4097 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
4098 paddr_nz (stack_offset));
4099 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
4100 paddr_nz (longword_offset));
4101 }
4102
4103 addr = sp + stack_offset + longword_offset;
4104
4105 if (mips_debug)
4106 {
4107 int i;
4108 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
4109 paddr_nz (addr));
4110 for (i = 0; i < partial_len; i++)
4111 {
4112 fprintf_unfiltered (gdb_stdlog, "%02x",
4113 val[i] & 0xff);
4114 }
4115 }
4116 write_memory (addr, val, partial_len);
4117 }
4118
4119 /* Note!!! This is NOT an else clause. Odd sized
4120 structs may go thru BOTH paths. Floating point
4121 arguments will not. */
4122 /* Write this portion of the argument to a general
4123 purpose register. */
4124 if (argreg <= MIPS_LAST_ARG_REGNUM
4125 && !fp_register_arg_p (typecode, arg_type))
4126 {
4127 LONGEST regval = extract_signed_integer (val, partial_len);
4128 /* Value may need to be sign extended, because
4129 mips_isa_regsize() != mips_abi_regsize(). */
4130
4131 /* A non-floating-point argument being passed in a
4132 general register. If a struct or union, and if
4133 the remaining length is smaller than the register
4134 size, we have to adjust the register value on
4135 big endian targets.
4136
4137 It does not seem to be necessary to do the
4138 same for integral types.
4139
4140 Also don't do this adjustment on O64 binaries.
4141
4142 cagney/2001-07-23: gdb/179: Also, GCC, when
4143 outputting LE O32 with sizeof (struct) <
4144 mips_abi_regsize(), generates a left shift as
4145 part of storing the argument in a register a
4146 register (the left shift isn't generated when
4147 sizeof (struct) >= mips_abi_regsize()). Since
4148 it is quite possible that this is GCC
4149 contradicting the LE/O32 ABI, GDB has not been
4150 adjusted to accommodate this. Either someone
4151 needs to demonstrate that the LE/O32 ABI
4152 specifies such a left shift OR this new ABI gets
4153 identified as such and GDB gets tweaked
4154 accordingly. */
4155
4156 if (mips_abi_regsize (gdbarch) < 8
4157 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4158 && partial_len < mips_abi_regsize (gdbarch)
4159 && (typecode == TYPE_CODE_STRUCT ||
4160 typecode == TYPE_CODE_UNION))
4161 regval <<= ((mips_abi_regsize (gdbarch) - partial_len) *
4162 TARGET_CHAR_BIT);
4163
4164 if (mips_debug)
4165 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4166 argreg,
4167 phex (regval,
4168 mips_abi_regsize (gdbarch)));
4169 write_register (argreg, regval);
4170 argreg++;
4171
4172 /* Prevent subsequent floating point arguments from
4173 being passed in floating point registers. */
4174 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
4175 }
4176
4177 len -= partial_len;
4178 val += partial_len;
4179
4180 /* Compute the the offset into the stack at which we
4181 will copy the next parameter.
4182
4183 In older ABIs, the caller reserved space for
4184 registers that contained arguments. This was loosely
4185 refered to as their "home". Consequently, space is
4186 always allocated. */
4187
4188 stack_offset += align_up (partial_len,
4189 mips_stack_argsize (gdbarch));
4190 }
4191 }
4192 if (mips_debug)
4193 fprintf_unfiltered (gdb_stdlog, "\n");
4194 }
4195
4196 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
4197
4198 /* Return adjusted stack pointer. */
4199 return sp;
4200 }
4201
4202 static enum return_value_convention
4203 mips_o32_return_value (struct gdbarch *gdbarch, struct type *type,
4204 struct regcache *regcache,
4205 void *readbuf, const void *writebuf)
4206 {
4207 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4208
4209 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4210 || TYPE_CODE (type) == TYPE_CODE_UNION
4211 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
4212 return RETURN_VALUE_STRUCT_CONVENTION;
4213 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4214 && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4215 {
4216 /* A single-precision floating-point value. It fits in the
4217 least significant part of FP0. */
4218 if (mips_debug)
4219 fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n");
4220 mips_xfer_register (regcache,
4221 NUM_REGS + mips_regnum (current_gdbarch)->fp0,
4222 TYPE_LENGTH (type),
4223 TARGET_BYTE_ORDER, readbuf, writebuf, 0);
4224 return RETURN_VALUE_REGISTER_CONVENTION;
4225 }
4226 else if (TYPE_CODE (type) == TYPE_CODE_FLT
4227 && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4228 {
4229 /* A double-precision floating-point value. The most
4230 significant part goes in FP1, and the least significant in
4231 FP0. */
4232 if (mips_debug)
4233 fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n");
4234 switch (TARGET_BYTE_ORDER)
4235 {
4236 case BFD_ENDIAN_LITTLE:
4237 mips_xfer_register (regcache,
4238 NUM_REGS + mips_regnum (current_gdbarch)->fp0 +
4239 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0);
4240 mips_xfer_register (regcache,
4241 NUM_REGS + mips_regnum (current_gdbarch)->fp0 +
4242 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4);
4243 break;
4244 case BFD_ENDIAN_BIG:
4245 mips_xfer_register (regcache,
4246 NUM_REGS + mips_regnum (current_gdbarch)->fp0 +
4247 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0);
4248 mips_xfer_register (regcache,
4249 NUM_REGS + mips_regnum (current_gdbarch)->fp0 +
4250 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4);
4251 break;
4252 default:
4253 internal_error (__FILE__, __LINE__, "bad switch");
4254 }
4255 return RETURN_VALUE_REGISTER_CONVENTION;
4256 }
4257 #if 0
4258 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4259 && TYPE_NFIELDS (type) <= 2
4260 && TYPE_NFIELDS (type) >= 1
4261 && ((TYPE_NFIELDS (type) == 1
4262 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4263 == TYPE_CODE_FLT))
4264 || (TYPE_NFIELDS (type) == 2
4265 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
4266 == TYPE_CODE_FLT)
4267 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
4268 == TYPE_CODE_FLT)))
4269 && tdep->mips_fpu_type != MIPS_FPU_NONE)
4270 {
4271 /* A struct that contains one or two floats. Each value is part
4272 in the least significant part of their floating point
4273 register.. */
4274 bfd_byte reg[MAX_REGISTER_SIZE];
4275 int regnum;
4276 int field;
4277 for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0;
4278 field < TYPE_NFIELDS (type); field++, regnum += 2)
4279 {
4280 int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
4281 / TARGET_CHAR_BIT);
4282 if (mips_debug)
4283 fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
4284 offset);
4285 mips_xfer_register (regcache, NUM_REGS + regnum,
4286 TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)),
4287 TARGET_BYTE_ORDER, readbuf, writebuf, offset);
4288 }
4289 return RETURN_VALUE_REGISTER_CONVENTION;
4290 }
4291 #endif
4292 #if 0
4293 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
4294 || TYPE_CODE (type) == TYPE_CODE_UNION)
4295 {
4296 /* A structure or union. Extract the left justified value,
4297 regardless of the byte order. I.e. DO NOT USE
4298 mips_xfer_lower. */
4299 int offset;
4300 int regnum;
4301 for (offset = 0, regnum = V0_REGNUM;
4302 offset < TYPE_LENGTH (type);
4303 offset += register_size (current_gdbarch, regnum), regnum++)
4304 {
4305 int xfer = register_size (current_gdbarch, regnum);
4306 if (offset + xfer > TYPE_LENGTH (type))
4307 xfer = TYPE_LENGTH (type) - offset;
4308 if (mips_debug)
4309 fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n",
4310 offset, xfer, regnum);
4311 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4312 BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
4313 }
4314 return RETURN_VALUE_REGISTER_CONVENTION;
4315 }
4316 #endif
4317 else
4318 {
4319 /* A scalar extract each part but least-significant-byte
4320 justified. o32 thinks registers are 4 byte, regardless of
4321 the ISA. mips_stack_argsize controls this. */
4322 int offset;
4323 int regnum;
4324 for (offset = 0, regnum = V0_REGNUM;
4325 offset < TYPE_LENGTH (type);
4326 offset += mips_stack_argsize (gdbarch), regnum++)
4327 {
4328 int xfer = mips_stack_argsize (gdbarch);
4329 if (offset + xfer > TYPE_LENGTH (type))
4330 xfer = TYPE_LENGTH (type) - offset;
4331 if (mips_debug)
4332 fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n",
4333 offset, xfer, regnum);
4334 mips_xfer_register (regcache, NUM_REGS + regnum, xfer,
4335 TARGET_BYTE_ORDER, readbuf, writebuf, offset);
4336 }
4337 return RETURN_VALUE_REGISTER_CONVENTION;
4338 }
4339 }
4340
4341 /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
4342 ABI. */
4343
4344 static CORE_ADDR
4345 mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
4346 struct regcache *regcache, CORE_ADDR bp_addr,
4347 int nargs,
4348 struct value **args, CORE_ADDR sp,
4349 int struct_return, CORE_ADDR struct_addr)
4350 {
4351 int argreg;
4352 int float_argreg;
4353 int argnum;
4354 int len = 0;
4355 int stack_offset = 0;
4356 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4357 CORE_ADDR func_addr = find_function_addr (function, NULL);
4358
4359 /* For shared libraries, "t9" needs to point at the function
4360 address. */
4361 regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr);
4362
4363 /* Set the return address register to point to the entry point of
4364 the program, where a breakpoint lies in wait. */
4365 regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr);
4366
4367 /* First ensure that the stack and structure return address (if any)
4368 are properly aligned. The stack has to be at least 64-bit
4369 aligned even on 32-bit machines, because doubles must be 64-bit
4370 aligned. For n32 and n64, stack frames need to be 128-bit
4371 aligned, so we round to this widest known alignment. */
4372
4373 sp = align_down (sp, 16);
4374 struct_addr = align_down (struct_addr, 16);
4375
4376 /* Now make space on the stack for the args. */
4377 for (argnum = 0; argnum < nargs; argnum++)
4378 len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])),
4379 mips_stack_argsize (gdbarch));
4380 sp -= align_up (len, 16);
4381
4382 if (mips_debug)
4383 fprintf_unfiltered (gdb_stdlog,
4384 "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n",
4385 paddr_nz (sp), (long) align_up (len, 16));
4386
4387 /* Initialize the integer and float register pointers. */
4388 argreg = A0_REGNUM;
4389 float_argreg = mips_fpa0_regnum (current_gdbarch);
4390
4391 /* The struct_return pointer occupies the first parameter-passing reg. */
4392 if (struct_return)
4393 {
4394 if (mips_debug)
4395 fprintf_unfiltered (gdb_stdlog,
4396 "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n",
4397 argreg, paddr_nz (struct_addr));
4398 write_register (argreg++, struct_addr);
4399 stack_offset += mips_stack_argsize (gdbarch);
4400 }
4401
4402 /* Now load as many as possible of the first arguments into
4403 registers, and push the rest onto the stack. Loop thru args
4404 from first to last. */
4405 for (argnum = 0; argnum < nargs; argnum++)
4406 {
4407 char *val;
4408 struct value *arg = args[argnum];
4409 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
4410 int len = TYPE_LENGTH (arg_type);
4411 enum type_code typecode = TYPE_CODE (arg_type);
4412
4413 if (mips_debug)
4414 fprintf_unfiltered (gdb_stdlog,
4415 "mips_o64_push_dummy_call: %d len=%d type=%d",
4416 argnum + 1, len, (int) typecode);
4417
4418 val = (char *) VALUE_CONTENTS (arg);
4419
4420 /* 32-bit ABIs always start floating point arguments in an
4421 even-numbered floating point register. Round the FP register
4422 up before the check to see if there are any FP registers
4423 left. O32/O64 targets also pass the FP in the integer
4424 registers so also round up normal registers. */
4425 if (mips_abi_regsize (gdbarch) < 8
4426 && fp_register_arg_p (typecode, arg_type))
4427 {
4428 if ((float_argreg & 1))
4429 float_argreg++;
4430 }
4431
4432 /* Floating point arguments passed in registers have to be
4433 treated specially. On 32-bit architectures, doubles
4434 are passed in register pairs; the even register gets
4435 the low word, and the odd register gets the high word.
4436 On O32/O64, the first two floating point arguments are
4437 also copied to general registers, because MIPS16 functions
4438 don't use float registers for arguments. This duplication of
4439 arguments in general registers can't hurt non-MIPS16 functions
4440 because those registers are normally skipped. */
4441
4442 if (fp_register_arg_p (typecode, arg_type)
4443 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM)
4444 {
4445 if (mips_abi_regsize (gdbarch) < 8 && len == 8)
4446 {
4447 int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0;
4448 unsigned long regval;
4449
4450 /* Write the low word of the double to the even register(s). */
4451 regval = extract_unsigned_integer (val + low_offset, 4);
4452 if (mips_debug)
4453 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4454 float_argreg, phex (regval, 4));
4455 write_register (float_argreg++, regval);
4456 if (mips_debug)
4457 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4458 argreg, phex (regval, 4));
4459 write_register (argreg++, regval);
4460
4461 /* Write the high word of the double to the odd register(s). */
4462 regval = extract_unsigned_integer (val + 4 - 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
4468 if (mips_debug)
4469 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4470 argreg, phex (regval, 4));
4471 write_register (argreg++, regval);
4472 }
4473 else
4474 {
4475 /* This is a floating point value that fits entirely
4476 in a single register. */
4477 /* On 32 bit ABI's the float_argreg is further adjusted
4478 above to ensure that it is even register aligned. */
4479 LONGEST regval = extract_unsigned_integer (val, len);
4480 if (mips_debug)
4481 fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s",
4482 float_argreg, phex (regval, len));
4483 write_register (float_argreg++, regval);
4484 /* CAGNEY: 32 bit MIPS ABI's always reserve two FP
4485 registers for each argument. The below is (my
4486 guess) to ensure that the corresponding integer
4487 register has reserved the same space. */
4488 if (mips_debug)
4489 fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s",
4490 argreg, phex (regval, len));
4491 write_register (argreg, regval);
4492 argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2;
4493 }
4494 /* Reserve space for the FP register. */
4495 stack_offset += align_up (len, mips_stack_argsize (gdbarch));
4496 }
4497 else
4498 {
4499 /* Copy the argument to general registers or the stack in
4500 register-sized pieces. Large arguments are split between
4501 registers and stack. */
4502 /* Note: structs whose size is not a multiple of
4503 mips_abi_regsize() are treated specially: Irix cc passes
4504 them in registers where gcc sometimes puts them on the
4505 stack. For maximum compatibility, we will put them in
4506 both places. */
4507 int odd_sized_struct = ((len > mips_abi_regsize (gdbarch))
4508 && (len % mips_abi_regsize (gdbarch) != 0));
4509 /* Structures should be aligned to eight bytes (even arg registers)
4510 on MIPS_ABI_O32, if their first member has double precision. */
4511 if (mips_abi_regsize (gdbarch) < 8
4512 && mips_type_needs_double_align (arg_type))
4513 {
4514 if ((argreg & 1))
4515 argreg++;
4516 }
4517 /* Note: Floating-point values that didn't fit into an FP
4518 register are only written to memory. */
4519 while (len > 0)
4520 {
4521 /* Remember if the argument was written to the stack. */
4522 int stack_used_p = 0;
4523 int partial_len = (len < mips_abi_regsize (gdbarch)
4524 ? len : mips_abi_regsize (gdbarch));
4525
4526 if (mips_debug)
4527 fprintf_unfiltered (gdb_stdlog, " -- partial=%d",
4528 partial_len);
4529
4530 /* Write this portion of the argument to the stack. */
4531 if (argreg > MIPS_LAST_ARG_REGNUM
4532 || odd_sized_struct
4533 || fp_register_arg_p (typecode, arg_type))
4534 {
4535 /* Should shorter than int integer values be
4536 promoted to int before being stored? */
4537 int longword_offset = 0;
4538 CORE_ADDR addr;
4539 stack_used_p = 1;
4540 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4541 {
4542 if (mips_stack_argsize (gdbarch) == 8
4543 && (typecode == TYPE_CODE_INT
4544 || typecode == TYPE_CODE_PTR
4545 || typecode == TYPE_CODE_FLT) && len <= 4)
4546 longword_offset = mips_stack_argsize (gdbarch) - len;
4547 }
4548
4549 if (mips_debug)
4550 {
4551 fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s",
4552 paddr_nz (stack_offset));
4553 fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s",
4554 paddr_nz (longword_offset));
4555 }
4556
4557 addr = sp + stack_offset + longword_offset;
4558
4559 if (mips_debug)
4560 {
4561 int i;
4562 fprintf_unfiltered (gdb_stdlog, " @0x%s ",
4563 paddr_nz (addr));
4564 for (i = 0; i < partial_len; i++)
4565 {
4566 fprintf_unfiltered (gdb_stdlog, "%02x",
4567 val[i] & 0xff);
4568 }
4569 }
4570 write_memory (addr, val, partial_len);
4571 }
4572
4573 /* Note!!! This is NOT an else clause. Odd sized
4574 structs may go thru BOTH paths. Floating point
4575 arguments will not. */
4576 /* Write this portion of the argument to a general
4577 purpose register. */
4578 if (argreg <= MIPS_LAST_ARG_REGNUM
4579 && !fp_register_arg_p (typecode, arg_type))
4580 {
4581 LONGEST regval = extract_signed_integer (val, partial_len);
4582 /* Value may need to be sign extended, because
4583 mips_isa_regsize() != mips_abi_regsize(). */
4584
4585 /* A non-floating-point argument being passed in a
4586 general register. If a struct or union, and if
4587 the remaining length is smaller than the register
4588 size, we have to adjust the register value on
4589 big endian targets.
4590
4591 It does not seem to be necessary to do the
4592 same for integral types.
4593
4594 Also don't do this adjustment on O64 binaries.
4595
4596 cagney/2001-07-23: gdb/179: Also, GCC, when
4597 outputting LE O32 with sizeof (struct) <
4598 mips_abi_regsize(), generates a left shift as
4599 part of storing the argument in a register a
4600 register (the left shift isn't generated when
4601 sizeof (struct) >= mips_abi_regsize()). Since
4602 it is quite possible that this is GCC
4603 contradicting the LE/O32 ABI, GDB has not been
4604 adjusted to accommodate this. Either someone
4605 needs to demonstrate that the LE/O32 ABI
4606 specifies such a left shift OR this new ABI gets
4607 identified as such and GDB gets tweaked
4608 accordingly. */
4609
4610 if (mips_abi_regsize (gdbarch) < 8
4611 && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
4612 && partial_len < mips_abi_regsize (gdbarch)
4613 && (typecode == TYPE_CODE_STRUCT ||
4614 typecode == TYPE_CODE_UNION))
4615 regval <<= ((mips_abi_regsize (gdbarch) - partial_len) *
4616 TARGET_CHAR_BIT);
4617
4618 if (mips_debug)
4619 fprintf_filtered (gdb_stdlog, " - reg=%d val=%s",
4620 argreg,
4621 phex (regval,
4622 mips_abi_regsize (gdbarch)));
4623 write_register (argreg, regval);
4624 argreg++;
4625
4626 /* Prevent subsequent floating point arguments from
4627 being passed in floating point registers. */
4628 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
4629 }
4630
4631 len -= partial_len;
4632 val += partial_len;
4633
4634 /* Compute the the offset into the stack at which we
4635 will copy the next parameter.
4636
4637 In older ABIs, the caller reserved space for
4638 registers that contained arguments. This was loosely
4639 refered to as their "home". Consequently, space is
4640 always allocated. */
4641
4642 stack_offset += align_up (partial_len,
4643 mips_stack_argsize (gdbarch));
4644 }
4645 }
4646 if (mips_debug)
4647 fprintf_unfiltered (gdb_stdlog, "\n");
4648 }
4649
4650 regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
4651
4652 /* Return adjusted stack pointer. */
4653 return sp;
4654 }
4655
4656 static void
4657 mips_o64_extract_return_value (struct type *valtype,
4658 char regbuf[], char *valbuf)
4659 {
4660 struct return_value_word lo;
4661 struct return_value_word hi;
4662 return_value_location (valtype, &hi, &lo);
4663
4664 memcpy (valbuf + lo.buf_offset,
4665 regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + lo.reg) +
4666 lo.reg_offset, lo.len);
4667
4668 if (hi.len > 0)
4669 memcpy (valbuf + hi.buf_offset,
4670 regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + hi.reg) +
4671 hi.reg_offset, hi.len);
4672 }
4673
4674 static void
4675 mips_o64_store_return_value (struct type *valtype, char *valbuf)
4676 {
4677 char raw_buffer[MAX_REGISTER_SIZE];
4678 struct return_value_word lo;
4679 struct return_value_word hi;
4680 return_value_location (valtype, &hi, &lo);
4681
4682 memset (raw_buffer, 0, sizeof (raw_buffer));
4683 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
4684 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg),
4685 raw_buffer, register_size (current_gdbarch,
4686 lo.reg));
4687
4688 if (hi.len > 0)
4689 {
4690 memset (raw_buffer, 0, sizeof (raw_buffer));
4691 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
4692 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg),
4693 raw_buffer,
4694 register_size (current_gdbarch,
4695 hi.reg));
4696 }
4697 }
4698
4699 /* Floating point register management.
4700
4701 Background: MIPS1 & 2 fp registers are 32 bits wide. To support
4702 64bit operations, these early MIPS cpus treat fp register pairs
4703 (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
4704 registers and offer a compatibility mode that emulates the MIPS2 fp
4705 model. When operating in MIPS2 fp compat mode, later cpu's split
4706 double precision floats into two 32-bit chunks and store them in
4707 consecutive fp regs. To display 64-bit floats stored in this
4708 fashion, we have to combine 32 bits from f0 and 32 bits from f1.
4709 Throw in user-configurable endianness and you have a real mess.
4710
4711 The way this works is:
4712 - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
4713 double-precision value will be split across two logical registers.
4714 The lower-numbered logical register will hold the low-order bits,
4715 regardless of the processor's endianness.
4716 - If we are on a 64-bit processor, and we are looking for a
4717 single-precision value, it will be in the low ordered bits
4718 of a 64-bit GPR (after mfc1, for example) or a 64-bit register
4719 save slot in memory.
4720 - If we are in 64-bit mode, everything is straightforward.
4721
4722 Note that this code only deals with "live" registers at the top of the
4723 stack. We will attempt to deal with saved registers later, when
4724 the raw/cooked register interface is in place. (We need a general
4725 interface that can deal with dynamic saved register sizes -- fp
4726 regs could be 32 bits wide in one frame and 64 on the frame above
4727 and below). */
4728
4729 static struct type *
4730 mips_float_register_type (void)
4731 {
4732 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4733 return builtin_type_ieee_single_big;
4734 else
4735 return builtin_type_ieee_single_little;
4736 }
4737
4738 static struct type *
4739 mips_double_register_type (void)
4740 {
4741 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4742 return builtin_type_ieee_double_big;
4743 else
4744 return builtin_type_ieee_double_little;
4745 }
4746
4747 /* Copy a 32-bit single-precision value from the current frame
4748 into rare_buffer. */
4749
4750 static void
4751 mips_read_fp_register_single (struct frame_info *frame, int regno,
4752 char *rare_buffer)
4753 {
4754 int raw_size = register_size (current_gdbarch, regno);
4755 char *raw_buffer = alloca (raw_size);
4756
4757 if (!frame_register_read (frame, regno, raw_buffer))
4758 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4759 if (raw_size == 8)
4760 {
4761 /* We have a 64-bit value for this register. Find the low-order
4762 32 bits. */
4763 int offset;
4764
4765 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4766 offset = 4;
4767 else
4768 offset = 0;
4769
4770 memcpy (rare_buffer, raw_buffer + offset, 4);
4771 }
4772 else
4773 {
4774 memcpy (rare_buffer, raw_buffer, 4);
4775 }
4776 }
4777
4778 /* Copy a 64-bit double-precision value from the current frame into
4779 rare_buffer. This may include getting half of it from the next
4780 register. */
4781
4782 static void
4783 mips_read_fp_register_double (struct frame_info *frame, int regno,
4784 char *rare_buffer)
4785 {
4786 int raw_size = register_size (current_gdbarch, regno);
4787
4788 if (raw_size == 8 && !mips2_fp_compat ())
4789 {
4790 /* We have a 64-bit value for this register, and we should use
4791 all 64 bits. */
4792 if (!frame_register_read (frame, regno, rare_buffer))
4793 error ("can't read register %d (%s)", regno, REGISTER_NAME (regno));
4794 }
4795 else
4796 {
4797 if ((regno - mips_regnum (current_gdbarch)->fp0) & 1)
4798 internal_error (__FILE__, __LINE__,
4799 "mips_read_fp_register_double: bad access to "
4800 "odd-numbered FP register");
4801
4802 /* mips_read_fp_register_single will find the correct 32 bits from
4803 each register. */
4804 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4805 {
4806 mips_read_fp_register_single (frame, regno, rare_buffer + 4);
4807 mips_read_fp_register_single (frame, regno + 1, rare_buffer);
4808 }
4809 else
4810 {
4811 mips_read_fp_register_single (frame, regno, rare_buffer);
4812 mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
4813 }
4814 }
4815 }
4816
4817 static void
4818 mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
4819 int regnum)
4820 { /* do values for FP (float) regs */
4821 char *raw_buffer;
4822 double doub, flt1; /* doubles extracted from raw hex data */
4823 int inv1, inv2;
4824
4825 raw_buffer =
4826 (char *) alloca (2 *
4827 register_size (current_gdbarch,
4828 mips_regnum (current_gdbarch)->fp0));
4829
4830 fprintf_filtered (file, "%s:", REGISTER_NAME (regnum));
4831 fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)),
4832 "");
4833
4834 if (register_size (current_gdbarch, regnum) == 4 || mips2_fp_compat ())
4835 {
4836 /* 4-byte registers: Print hex and floating. Also print even
4837 numbered registers as doubles. */
4838 mips_read_fp_register_single (frame, regnum, raw_buffer);
4839 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4840
4841 print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w',
4842 file);
4843
4844 fprintf_filtered (file, " flt: ");
4845 if (inv1)
4846 fprintf_filtered (file, " <invalid float> ");
4847 else
4848 fprintf_filtered (file, "%-17.9g", flt1);
4849
4850 if (regnum % 2 == 0)
4851 {
4852 mips_read_fp_register_double (frame, regnum, raw_buffer);
4853 doub = unpack_double (mips_double_register_type (), raw_buffer,
4854 &inv2);
4855
4856 fprintf_filtered (file, " dbl: ");
4857 if (inv2)
4858 fprintf_filtered (file, "<invalid double>");
4859 else
4860 fprintf_filtered (file, "%-24.17g", doub);
4861 }
4862 }
4863 else
4864 {
4865 /* Eight byte registers: print each one as hex, float and double. */
4866 mips_read_fp_register_single (frame, regnum, raw_buffer);
4867 flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1);
4868
4869 mips_read_fp_register_double (frame, regnum, raw_buffer);
4870 doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2);
4871
4872
4873 print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g',
4874 file);
4875
4876 fprintf_filtered (file, " flt: ");
4877 if (inv1)
4878 fprintf_filtered (file, "<invalid float>");
4879 else
4880 fprintf_filtered (file, "%-17.9g", flt1);
4881
4882 fprintf_filtered (file, " dbl: ");
4883 if (inv2)
4884 fprintf_filtered (file, "<invalid double>");
4885 else
4886 fprintf_filtered (file, "%-24.17g", doub);
4887 }
4888 }
4889
4890 static void
4891 mips_print_register (struct ui_file *file, struct frame_info *frame,
4892 int regnum, int all)
4893 {
4894 struct gdbarch *gdbarch = get_frame_arch (frame);
4895 char raw_buffer[MAX_REGISTER_SIZE];
4896 int offset;
4897
4898 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
4899 {
4900 mips_print_fp_register (file, frame, regnum);
4901 return;
4902 }
4903
4904 /* Get the data in raw format. */
4905 if (!frame_register_read (frame, regnum, raw_buffer))
4906 {
4907 fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum));
4908 return;
4909 }
4910
4911 fputs_filtered (REGISTER_NAME (regnum), file);
4912
4913 /* The problem with printing numeric register names (r26, etc.) is that
4914 the user can't use them on input. Probably the best solution is to
4915 fix it so that either the numeric or the funky (a2, etc.) names
4916 are accepted on input. */
4917 if (regnum < MIPS_NUMREGS)
4918 fprintf_filtered (file, "(r%d): ", regnum);
4919 else
4920 fprintf_filtered (file, ": ");
4921
4922 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
4923 offset =
4924 register_size (current_gdbarch,
4925 regnum) - register_size (current_gdbarch, regnum);
4926 else
4927 offset = 0;
4928
4929 print_scalar_formatted (raw_buffer + offset,
4930 gdbarch_register_type (gdbarch, regnum), 'x', 0,
4931 file);
4932 }
4933
4934 /* Replacement for generic do_registers_info.
4935 Print regs in pretty columns. */
4936
4937 static int
4938 print_fp_register_row (struct ui_file *file, struct frame_info *frame,
4939 int regnum)
4940 {
4941 fprintf_filtered (file, " ");
4942 mips_print_fp_register (file, frame, regnum);
4943 fprintf_filtered (file, "\n");
4944 return regnum + 1;
4945 }
4946
4947
4948 /* Print a row's worth of GP (int) registers, with name labels above */
4949
4950 static int
4951 print_gp_register_row (struct ui_file *file, struct frame_info *frame,
4952 int start_regnum)
4953 {
4954 struct gdbarch *gdbarch = get_frame_arch (frame);
4955 /* do values for GP (int) regs */
4956 char raw_buffer[MAX_REGISTER_SIZE];
4957 int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */
4958 int col, byte;
4959 int regnum;
4960
4961 /* For GP registers, we print a separate row of names above the vals */
4962 fprintf_filtered (file, " ");
4963 for (col = 0, regnum = start_regnum;
4964 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
4965 {
4966 if (*REGISTER_NAME (regnum) == '\0')
4967 continue; /* unused register */
4968 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
4969 TYPE_CODE_FLT)
4970 break; /* end the row: reached FP register */
4971 fprintf_filtered (file,
4972 mips_abi_regsize (current_gdbarch) == 8 ? "%17s" : "%9s",
4973 REGISTER_NAME (regnum));
4974 col++;
4975 }
4976 /* print the R0 to R31 names */
4977 if ((start_regnum % NUM_REGS) < MIPS_NUMREGS)
4978 fprintf_filtered (file, "\n R%-4d", start_regnum % NUM_REGS);
4979 else
4980 fprintf_filtered (file, "\n ");
4981
4982 /* now print the values in hex, 4 or 8 to the row */
4983 for (col = 0, regnum = start_regnum;
4984 col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
4985 {
4986 if (*REGISTER_NAME (regnum) == '\0')
4987 continue; /* unused register */
4988 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
4989 TYPE_CODE_FLT)
4990 break; /* end row: reached FP register */
4991 /* OK: get the data in raw format. */
4992 if (!frame_register_read (frame, regnum, raw_buffer))
4993 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
4994 /* pad small registers */
4995 for (byte = 0;
4996 byte < (mips_abi_regsize (current_gdbarch)
4997 - register_size (current_gdbarch, regnum)); byte++)
4998 printf_filtered (" ");
4999 /* Now print the register value in hex, endian order. */
5000 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5001 for (byte =
5002 register_size (current_gdbarch,
5003 regnum) - register_size (current_gdbarch, regnum);
5004 byte < register_size (current_gdbarch, regnum); byte++)
5005 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
5006 else
5007 for (byte = register_size (current_gdbarch, regnum) - 1;
5008 byte >= 0; byte--)
5009 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]);
5010 fprintf_filtered (file, " ");
5011 col++;
5012 }
5013 if (col > 0) /* ie. if we actually printed anything... */
5014 fprintf_filtered (file, "\n");
5015
5016 return regnum;
5017 }
5018
5019 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
5020
5021 static void
5022 mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
5023 struct frame_info *frame, int regnum, int all)
5024 {
5025 if (regnum != -1) /* do one specified register */
5026 {
5027 gdb_assert (regnum >= NUM_REGS);
5028 if (*(REGISTER_NAME (regnum)) == '\0')
5029 error ("Not a valid register for the current processor type");
5030
5031 mips_print_register (file, frame, regnum, 0);
5032 fprintf_filtered (file, "\n");
5033 }
5034 else
5035 /* do all (or most) registers */
5036 {
5037 regnum = NUM_REGS;
5038 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
5039 {
5040 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
5041 TYPE_CODE_FLT)
5042 {
5043 if (all) /* true for "INFO ALL-REGISTERS" command */
5044 regnum = print_fp_register_row (file, frame, regnum);
5045 else
5046 regnum += MIPS_NUMREGS; /* skip floating point regs */
5047 }
5048 else
5049 regnum = print_gp_register_row (file, frame, regnum);
5050 }
5051 }
5052 }
5053
5054 /* Is this a branch with a delay slot? */
5055
5056 static int is_delayed (unsigned long);
5057
5058 static int
5059 is_delayed (unsigned long insn)
5060 {
5061 int i;
5062 for (i = 0; i < NUMOPCODES; ++i)
5063 if (mips_opcodes[i].pinfo != INSN_MACRO
5064 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
5065 break;
5066 return (i < NUMOPCODES
5067 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
5068 | INSN_COND_BRANCH_DELAY
5069 | INSN_COND_BRANCH_LIKELY)));
5070 }
5071
5072 int
5073 mips_step_skips_delay (CORE_ADDR pc)
5074 {
5075 char buf[MIPS_INSTLEN];
5076
5077 /* There is no branch delay slot on MIPS16. */
5078 if (pc_is_mips16 (pc))
5079 return 0;
5080
5081 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
5082 /* If error reading memory, guess that it is not a delayed branch. */
5083 return 0;
5084 return is_delayed ((unsigned long)
5085 extract_unsigned_integer (buf, MIPS_INSTLEN));
5086 }
5087
5088 /* Skip the PC past function prologue instructions (32-bit version).
5089 This is a helper function for mips_skip_prologue. */
5090
5091 static CORE_ADDR
5092 mips32_skip_prologue (CORE_ADDR pc)
5093 {
5094 t_inst inst;
5095 CORE_ADDR end_pc;
5096 int seen_sp_adjust = 0;
5097 int load_immediate_bytes = 0;
5098
5099 /* Find an upper bound on the prologue. */
5100 end_pc = skip_prologue_using_sal (pc);
5101 if (end_pc == 0)
5102 end_pc = pc + 100; /* Magic. */
5103
5104 /* Skip the typical prologue instructions. These are the stack adjustment
5105 instruction and the instructions that save registers on the stack
5106 or in the gcc frame. */
5107 for (; pc < end_pc; pc += MIPS_INSTLEN)
5108 {
5109 unsigned long high_word;
5110
5111 inst = mips_fetch_instruction (pc);
5112 high_word = (inst >> 16) & 0xffff;
5113
5114 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
5115 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
5116 seen_sp_adjust = 1;
5117 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
5118 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
5119 seen_sp_adjust = 1;
5120 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
5121 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
5122 && (inst & 0x001F0000)) /* reg != $zero */
5123 continue;
5124
5125 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
5126 continue;
5127 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
5128 /* sx reg,n($s8) */
5129 continue; /* reg != $zero */
5130
5131 /* move $s8,$sp. With different versions of gas this will be either
5132 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
5133 Accept any one of these. */
5134 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
5135 continue;
5136
5137 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
5138 continue;
5139 else if (high_word == 0x3c1c) /* lui $gp,n */
5140 continue;
5141 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
5142 continue;
5143 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
5144 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
5145 continue;
5146 /* The following instructions load $at or $t0 with an immediate
5147 value in preparation for a stack adjustment via
5148 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
5149 a local variable, so we accept them only before a stack adjustment
5150 instruction was seen. */
5151 else if (!seen_sp_adjust)
5152 {
5153 if (high_word == 0x3c01 || /* lui $at,n */
5154 high_word == 0x3c08) /* lui $t0,n */
5155 {
5156 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
5157 continue;
5158 }
5159 else if (high_word == 0x3421 || /* ori $at,$at,n */
5160 high_word == 0x3508 || /* ori $t0,$t0,n */
5161 high_word == 0x3401 || /* ori $at,$zero,n */
5162 high_word == 0x3408) /* ori $t0,$zero,n */
5163 {
5164 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
5165 continue;
5166 }
5167 else
5168 break;
5169 }
5170 else
5171 break;
5172 }
5173
5174 /* In a frameless function, we might have incorrectly
5175 skipped some load immediate instructions. Undo the skipping
5176 if the load immediate was not followed by a stack adjustment. */
5177 if (load_immediate_bytes && !seen_sp_adjust)
5178 pc -= load_immediate_bytes;
5179 return pc;
5180 }
5181
5182 /* Skip the PC past function prologue instructions (16-bit version).
5183 This is a helper function for mips_skip_prologue. */
5184
5185 static CORE_ADDR
5186 mips16_skip_prologue (CORE_ADDR pc)
5187 {
5188 CORE_ADDR end_pc;
5189 int extend_bytes = 0;
5190 int prev_extend_bytes;
5191
5192 /* Table of instructions likely to be found in a function prologue. */
5193 static struct
5194 {
5195 unsigned short inst;
5196 unsigned short mask;
5197 }
5198 table[] =
5199 {
5200 {
5201 0x6300, 0xff00}
5202 , /* addiu $sp,offset */
5203 {
5204 0xfb00, 0xff00}
5205 , /* daddiu $sp,offset */
5206 {
5207 0xd000, 0xf800}
5208 , /* sw reg,n($sp) */
5209 {
5210 0xf900, 0xff00}
5211 , /* sd reg,n($sp) */
5212 {
5213 0x6200, 0xff00}
5214 , /* sw $ra,n($sp) */
5215 {
5216 0xfa00, 0xff00}
5217 , /* sd $ra,n($sp) */
5218 {
5219 0x673d, 0xffff}
5220 , /* move $s1,sp */
5221 {
5222 0xd980, 0xff80}
5223 , /* sw $a0-$a3,n($s1) */
5224 {
5225 0x6704, 0xff1c}
5226 , /* move reg,$a0-$a3 */
5227 {
5228 0xe809, 0xf81f}
5229 , /* entry pseudo-op */
5230 {
5231 0x0100, 0xff00}
5232 , /* addiu $s1,$sp,n */
5233 {
5234 0, 0} /* end of table marker */
5235 };
5236
5237 /* Find an upper bound on the prologue. */
5238 end_pc = skip_prologue_using_sal (pc);
5239 if (end_pc == 0)
5240 end_pc = pc + 100; /* Magic. */
5241
5242 /* Skip the typical prologue instructions. These are the stack adjustment
5243 instruction and the instructions that save registers on the stack
5244 or in the gcc frame. */
5245 for (; pc < end_pc; pc += MIPS16_INSTLEN)
5246 {
5247 unsigned short inst;
5248 int i;
5249
5250 inst = mips_fetch_instruction (pc);
5251
5252 /* Normally we ignore an extend instruction. However, if it is
5253 not followed by a valid prologue instruction, we must adjust
5254 the pc back over the extend so that it won't be considered
5255 part of the prologue. */
5256 if ((inst & 0xf800) == 0xf000) /* extend */
5257 {
5258 extend_bytes = MIPS16_INSTLEN;
5259 continue;
5260 }
5261 prev_extend_bytes = extend_bytes;
5262 extend_bytes = 0;
5263
5264 /* Check for other valid prologue instructions besides extend. */
5265 for (i = 0; table[i].mask != 0; i++)
5266 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
5267 break;
5268 if (table[i].mask != 0) /* it was in table? */
5269 continue; /* ignore it */
5270 else
5271 /* non-prologue */
5272 {
5273 /* Return the current pc, adjusted backwards by 2 if
5274 the previous instruction was an extend. */
5275 return pc - prev_extend_bytes;
5276 }
5277 }
5278 return pc;
5279 }
5280
5281 /* To skip prologues, I use this predicate. Returns either PC itself
5282 if the code at PC does not look like a function prologue; otherwise
5283 returns an address that (if we're lucky) follows the prologue. If
5284 LENIENT, then we must skip everything which is involved in setting
5285 up the frame (it's OK to skip more, just so long as we don't skip
5286 anything which might clobber the registers which are being saved.
5287 We must skip more in the case where part of the prologue is in the
5288 delay slot of a non-prologue instruction). */
5289
5290 static CORE_ADDR
5291 mips_skip_prologue (CORE_ADDR pc)
5292 {
5293 /* See if we can determine the end of the prologue via the symbol table.
5294 If so, then return either PC, or the PC after the prologue, whichever
5295 is greater. */
5296
5297 CORE_ADDR post_prologue_pc = after_prologue (pc);
5298
5299 if (post_prologue_pc != 0)
5300 return max (pc, post_prologue_pc);
5301
5302 /* Can't determine prologue from the symbol table, need to examine
5303 instructions. */
5304
5305 if (pc_is_mips16 (pc))
5306 return mips16_skip_prologue (pc);
5307 else
5308 return mips32_skip_prologue (pc);
5309 }
5310
5311 /* Root of all "set mips "/"show mips " commands. This will eventually be
5312 used for all MIPS-specific commands. */
5313
5314 static void
5315 show_mips_command (char *args, int from_tty)
5316 {
5317 help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout);
5318 }
5319
5320 static void
5321 set_mips_command (char *args, int from_tty)
5322 {
5323 printf_unfiltered
5324 ("\"set mips\" must be followed by an appropriate subcommand.\n");
5325 help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout);
5326 }
5327
5328 /* Commands to show/set the MIPS FPU type. */
5329
5330 static void
5331 show_mipsfpu_command (char *args, int from_tty)
5332 {
5333 char *fpu;
5334 switch (MIPS_FPU_TYPE)
5335 {
5336 case MIPS_FPU_SINGLE:
5337 fpu = "single-precision";
5338 break;
5339 case MIPS_FPU_DOUBLE:
5340 fpu = "double-precision";
5341 break;
5342 case MIPS_FPU_NONE:
5343 fpu = "absent (none)";
5344 break;
5345 default:
5346 internal_error (__FILE__, __LINE__, "bad switch");
5347 }
5348 if (mips_fpu_type_auto)
5349 printf_unfiltered
5350 ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
5351 fpu);
5352 else
5353 printf_unfiltered
5354 ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu);
5355 }
5356
5357
5358 static void
5359 set_mipsfpu_command (char *args, int from_tty)
5360 {
5361 printf_unfiltered
5362 ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
5363 show_mipsfpu_command (args, from_tty);
5364 }
5365
5366 static void
5367 set_mipsfpu_single_command (char *args, int from_tty)
5368 {
5369 struct gdbarch_info info;
5370 gdbarch_info_init (&info);
5371 mips_fpu_type = MIPS_FPU_SINGLE;
5372 mips_fpu_type_auto = 0;
5373 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5374 instead of relying on globals. Doing that would let generic code
5375 handle the search for this specific architecture. */
5376 if (!gdbarch_update_p (info))
5377 internal_error (__FILE__, __LINE__, "set mipsfpu failed");
5378 }
5379
5380 static void
5381 set_mipsfpu_double_command (char *args, int from_tty)
5382 {
5383 struct gdbarch_info info;
5384 gdbarch_info_init (&info);
5385 mips_fpu_type = MIPS_FPU_DOUBLE;
5386 mips_fpu_type_auto = 0;
5387 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5388 instead of relying on globals. Doing that would let generic code
5389 handle the search for this specific architecture. */
5390 if (!gdbarch_update_p (info))
5391 internal_error (__FILE__, __LINE__, "set mipsfpu failed");
5392 }
5393
5394 static void
5395 set_mipsfpu_none_command (char *args, int from_tty)
5396 {
5397 struct gdbarch_info info;
5398 gdbarch_info_init (&info);
5399 mips_fpu_type = MIPS_FPU_NONE;
5400 mips_fpu_type_auto = 0;
5401 /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
5402 instead of relying on globals. Doing that would let generic code
5403 handle the search for this specific architecture. */
5404 if (!gdbarch_update_p (info))
5405 internal_error (__FILE__, __LINE__, "set mipsfpu failed");
5406 }
5407
5408 static void
5409 set_mipsfpu_auto_command (char *args, int from_tty)
5410 {
5411 mips_fpu_type_auto = 1;
5412 }
5413
5414 /* Attempt to identify the particular processor model by reading the
5415 processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that
5416 the relevant processor still exists (it dates back to '94) and
5417 secondly this is not the way to do this. The processor type should
5418 be set by forcing an architecture change. */
5419
5420 void
5421 deprecated_mips_set_processor_regs_hack (void)
5422 {
5423 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
5424 CORE_ADDR prid;
5425
5426 prid = read_register (PRID_REGNUM);
5427
5428 if ((prid & ~0xf) == 0x700)
5429 tdep->mips_processor_reg_names = mips_r3041_reg_names;
5430 }
5431
5432 /* Just like reinit_frame_cache, but with the right arguments to be
5433 callable as an sfunc. */
5434
5435 static void
5436 reinit_frame_cache_sfunc (char *args, int from_tty,
5437 struct cmd_list_element *c)
5438 {
5439 reinit_frame_cache ();
5440 }
5441
5442 static int
5443 gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
5444 {
5445 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
5446 mips_extra_func_info_t proc_desc;
5447
5448 /* Search for the function containing this address. Set the low bit
5449 of the address when searching, in case we were given an even address
5450 that is the start of a 16-bit function. If we didn't do this,
5451 the search would fail because the symbol table says the function
5452 starts at an odd address, i.e. 1 byte past the given address. */
5453 memaddr = ADDR_BITS_REMOVE (memaddr);
5454 proc_desc = non_heuristic_proc_desc (make_mips16_addr (memaddr), NULL);
5455
5456 /* Make an attempt to determine if this is a 16-bit function. If
5457 the procedure descriptor exists and the address therein is odd,
5458 it's definitely a 16-bit function. Otherwise, we have to just
5459 guess that if the address passed in is odd, it's 16-bits. */
5460 /* FIXME: cagney/2003-06-26: Is this even necessary? The
5461 disassembler needs to be able to locally determine the ISA, and
5462 not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
5463 work. */
5464 if (proc_desc)
5465 {
5466 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
5467 info->mach = bfd_mach_mips16;
5468 }
5469 else
5470 {
5471 if (pc_is_mips16 (memaddr))
5472 info->mach = bfd_mach_mips16;
5473 }
5474
5475 /* Round down the instruction address to the appropriate boundary. */
5476 memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3);
5477
5478 /* Set the disassembler options. */
5479 if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64)
5480 {
5481 /* Set up the disassembler info, so that we get the right
5482 register names from libopcodes. */
5483 if (tdep->mips_abi == MIPS_ABI_N32)
5484 info->disassembler_options = "gpr-names=n32";
5485 else
5486 info->disassembler_options = "gpr-names=64";
5487 info->flavour = bfd_target_elf_flavour;
5488 }
5489 else
5490 /* This string is not recognized explicitly by the disassembler,
5491 but it tells the disassembler to not try to guess the ABI from
5492 the bfd elf headers, such that, if the user overrides the ABI
5493 of a program linked as NewABI, the disassembly will follow the
5494 register naming conventions specified by the user. */
5495 info->disassembler_options = "gpr-names=32";
5496
5497 /* Call the appropriate disassembler based on the target endian-ness. */
5498 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5499 return print_insn_big_mips (memaddr, info);
5500 else
5501 return print_insn_little_mips (memaddr, info);
5502 }
5503
5504 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
5505 counter value to determine whether a 16- or 32-bit breakpoint should be
5506 used. It returns a pointer to a string of bytes that encode a breakpoint
5507 instruction, stores the length of the string to *lenptr, and adjusts pc
5508 (if necessary) to point to the actual memory location where the
5509 breakpoint should be inserted. */
5510
5511 static const unsigned char *
5512 mips_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
5513 {
5514 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
5515 {
5516 if (pc_is_mips16 (*pcptr))
5517 {
5518 static unsigned char mips16_big_breakpoint[] = { 0xe8, 0xa5 };
5519 *pcptr = unmake_mips16_addr (*pcptr);
5520 *lenptr = sizeof (mips16_big_breakpoint);
5521 return mips16_big_breakpoint;
5522 }
5523 else
5524 {
5525 /* The IDT board uses an unusual breakpoint value, and
5526 sometimes gets confused when it sees the usual MIPS
5527 breakpoint instruction. */
5528 static unsigned char big_breakpoint[] = { 0, 0x5, 0, 0xd };
5529 static unsigned char pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
5530 static unsigned char idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
5531
5532 *lenptr = sizeof (big_breakpoint);
5533
5534 if (strcmp (target_shortname, "mips") == 0)
5535 return idt_big_breakpoint;
5536 else if (strcmp (target_shortname, "ddb") == 0
5537 || strcmp (target_shortname, "pmon") == 0
5538 || strcmp (target_shortname, "lsi") == 0)
5539 return pmon_big_breakpoint;
5540 else
5541 return big_breakpoint;
5542 }
5543 }
5544 else
5545 {
5546 if (pc_is_mips16 (*pcptr))
5547 {
5548 static unsigned char mips16_little_breakpoint[] = { 0xa5, 0xe8 };
5549 *pcptr = unmake_mips16_addr (*pcptr);
5550 *lenptr = sizeof (mips16_little_breakpoint);
5551 return mips16_little_breakpoint;
5552 }
5553 else
5554 {
5555 static unsigned char little_breakpoint[] = { 0xd, 0, 0x5, 0 };
5556 static unsigned char pmon_little_breakpoint[] = { 0xd, 0, 0, 0 };
5557 static unsigned char idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 };
5558
5559 *lenptr = sizeof (little_breakpoint);
5560
5561 if (strcmp (target_shortname, "mips") == 0)
5562 return idt_little_breakpoint;
5563 else if (strcmp (target_shortname, "ddb") == 0
5564 || strcmp (target_shortname, "pmon") == 0
5565 || strcmp (target_shortname, "lsi") == 0)
5566 return pmon_little_breakpoint;
5567 else
5568 return little_breakpoint;
5569 }
5570 }
5571 }
5572
5573 /* If PC is in a mips16 call or return stub, return the address of the target
5574 PC, which is either the callee or the caller. There are several
5575 cases which must be handled:
5576
5577 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5578 target PC is in $31 ($ra).
5579 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5580 and the target PC is in $2.
5581 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5582 before the jal instruction, this is effectively a call stub
5583 and the the target PC is in $2. Otherwise this is effectively
5584 a return stub and the target PC is in $18.
5585
5586 See the source code for the stubs in gcc/config/mips/mips16.S for
5587 gory details.
5588
5589 This function implements the SKIP_TRAMPOLINE_CODE macro.
5590 */
5591
5592 static CORE_ADDR
5593 mips_skip_stub (CORE_ADDR pc)
5594 {
5595 char *name;
5596 CORE_ADDR start_addr;
5597
5598 /* Find the starting address and name of the function containing the PC. */
5599 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
5600 return 0;
5601
5602 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
5603 target PC is in $31 ($ra). */
5604 if (strcmp (name, "__mips16_ret_sf") == 0
5605 || strcmp (name, "__mips16_ret_df") == 0)
5606 return read_signed_register (RA_REGNUM);
5607
5608 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5609 {
5610 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
5611 and the target PC is in $2. */
5612 if (name[19] >= '0' && name[19] <= '9')
5613 return read_signed_register (2);
5614
5615 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5616 before the jal instruction, this is effectively a call stub
5617 and the the target PC is in $2. Otherwise this is effectively
5618 a return stub and the target PC is in $18. */
5619 else if (name[19] == 's' || name[19] == 'd')
5620 {
5621 if (pc == start_addr)
5622 {
5623 /* Check if the target of the stub is a compiler-generated
5624 stub. Such a stub for a function bar might have a name
5625 like __fn_stub_bar, and might look like this:
5626 mfc1 $4,$f13
5627 mfc1 $5,$f12
5628 mfc1 $6,$f15
5629 mfc1 $7,$f14
5630 la $1,bar (becomes a lui/addiu pair)
5631 jr $1
5632 So scan down to the lui/addi and extract the target
5633 address from those two instructions. */
5634
5635 CORE_ADDR target_pc = read_signed_register (2);
5636 t_inst inst;
5637 int i;
5638
5639 /* See if the name of the target function is __fn_stub_*. */
5640 if (find_pc_partial_function (target_pc, &name, NULL, NULL) ==
5641 0)
5642 return target_pc;
5643 if (strncmp (name, "__fn_stub_", 10) != 0
5644 && strcmp (name, "etext") != 0
5645 && strcmp (name, "_etext") != 0)
5646 return target_pc;
5647
5648 /* Scan through this _fn_stub_ code for the lui/addiu pair.
5649 The limit on the search is arbitrarily set to 20
5650 instructions. FIXME. */
5651 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
5652 {
5653 inst = mips_fetch_instruction (target_pc);
5654 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
5655 pc = (inst << 16) & 0xffff0000; /* high word */
5656 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
5657 return pc | (inst & 0xffff); /* low word */
5658 }
5659
5660 /* Couldn't find the lui/addui pair, so return stub address. */
5661 return target_pc;
5662 }
5663 else
5664 /* This is the 'return' part of a call stub. The return
5665 address is in $r18. */
5666 return read_signed_register (18);
5667 }
5668 }
5669 return 0; /* not a stub */
5670 }
5671
5672
5673 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
5674 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
5675
5676 static int
5677 mips_in_call_stub (CORE_ADDR pc, char *name)
5678 {
5679 CORE_ADDR start_addr;
5680
5681 /* Find the starting address of the function containing the PC. If the
5682 caller didn't give us a name, look it up at the same time. */
5683 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) ==
5684 0)
5685 return 0;
5686
5687 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
5688 {
5689 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
5690 if (name[19] >= '0' && name[19] <= '9')
5691 return 1;
5692 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
5693 before the jal instruction, this is effectively a call stub. */
5694 else if (name[19] == 's' || name[19] == 'd')
5695 return pc == start_addr;
5696 }
5697
5698 return 0; /* not a stub */
5699 }
5700
5701
5702 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
5703 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
5704
5705 static int
5706 mips_in_return_stub (CORE_ADDR pc, char *name)
5707 {
5708 CORE_ADDR start_addr;
5709
5710 /* Find the starting address of the function containing the PC. */
5711 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
5712 return 0;
5713
5714 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
5715 if (strcmp (name, "__mips16_ret_sf") == 0
5716 || strcmp (name, "__mips16_ret_df") == 0)
5717 return 1;
5718
5719 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
5720 i.e. after the jal instruction, this is effectively a return stub. */
5721 if (strncmp (name, "__mips16_call_stub_", 19) == 0
5722 && (name[19] == 's' || name[19] == 'd') && pc != start_addr)
5723 return 1;
5724
5725 return 0; /* not a stub */
5726 }
5727
5728
5729 /* Return non-zero if the PC is in a library helper function that
5730 should be ignored. This implements the
5731 DEPRECATED_IGNORE_HELPER_CALL macro. */
5732
5733 int
5734 mips_ignore_helper (CORE_ADDR pc)
5735 {
5736 char *name;
5737
5738 /* Find the starting address and name of the function containing the PC. */
5739 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
5740 return 0;
5741
5742 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
5743 that we want to ignore. */
5744 return (strcmp (name, "__mips16_ret_sf") == 0
5745 || strcmp (name, "__mips16_ret_df") == 0);
5746 }
5747
5748
5749 /* Convert a dbx stab register number (from `r' declaration) to a GDB
5750 [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5751
5752 static int
5753 mips_stab_reg_to_regnum (int num)
5754 {
5755 int regnum;
5756 if (num >= 0 && num < 32)
5757 regnum = num;
5758 else if (num >= 38 && num < 70)
5759 regnum = num + mips_regnum (current_gdbarch)->fp0 - 38;
5760 else if (num == 70)
5761 regnum = mips_regnum (current_gdbarch)->hi;
5762 else if (num == 71)
5763 regnum = mips_regnum (current_gdbarch)->lo;
5764 else
5765 /* This will hopefully (eventually) provoke a warning. Should
5766 we be calling complaint() here? */
5767 return NUM_REGS + NUM_PSEUDO_REGS;
5768 return NUM_REGS + regnum;
5769 }
5770
5771
5772 /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
5773 NUM_REGS .. 2 * NUM_REGS) REGNUM. */
5774
5775 static int
5776 mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num)
5777 {
5778 int regnum;
5779 if (num >= 0 && num < 32)
5780 regnum = num;
5781 else if (num >= 32 && num < 64)
5782 regnum = num + mips_regnum (current_gdbarch)->fp0 - 32;
5783 else if (num == 64)
5784 regnum = mips_regnum (current_gdbarch)->hi;
5785 else if (num == 65)
5786 regnum = mips_regnum (current_gdbarch)->lo;
5787 else
5788 /* This will hopefully (eventually) provoke a warning. Should we
5789 be calling complaint() here? */
5790 return NUM_REGS + NUM_PSEUDO_REGS;
5791 return NUM_REGS + regnum;
5792 }
5793
5794 static int
5795 mips_register_sim_regno (int regnum)
5796 {
5797 /* Only makes sense to supply raw registers. */
5798 gdb_assert (regnum >= 0 && regnum < NUM_REGS);
5799 /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
5800 decide if it is valid. Should instead define a standard sim/gdb
5801 register numbering scheme. */
5802 if (REGISTER_NAME (NUM_REGS + regnum) != NULL
5803 && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0')
5804 return regnum;
5805 else
5806 return LEGACY_SIM_REGNO_IGNORE;
5807 }
5808
5809
5810 /* Convert an integer into an address. By first converting the value
5811 into a pointer and then extracting it signed, the address is
5812 guarenteed to be correctly sign extended. */
5813
5814 static CORE_ADDR
5815 mips_integer_to_address (struct type *type, void *buf)
5816 {
5817 char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr));
5818 LONGEST val = unpack_long (type, buf);
5819 store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val);
5820 return extract_signed_integer (tmp,
5821 TYPE_LENGTH (builtin_type_void_data_ptr));
5822 }
5823
5824 static void
5825 mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
5826 {
5827 enum mips_abi *abip = (enum mips_abi *) obj;
5828 const char *name = bfd_get_section_name (abfd, sect);
5829
5830 if (*abip != MIPS_ABI_UNKNOWN)
5831 return;
5832
5833 if (strncmp (name, ".mdebug.", 8) != 0)
5834 return;
5835
5836 if (strcmp (name, ".mdebug.abi32") == 0)
5837 *abip = MIPS_ABI_O32;
5838 else if (strcmp (name, ".mdebug.abiN32") == 0)
5839 *abip = MIPS_ABI_N32;
5840 else if (strcmp (name, ".mdebug.abi64") == 0)
5841 *abip = MIPS_ABI_N64;
5842 else if (strcmp (name, ".mdebug.abiO64") == 0)
5843 *abip = MIPS_ABI_O64;
5844 else if (strcmp (name, ".mdebug.eabi32") == 0)
5845 *abip = MIPS_ABI_EABI32;
5846 else if (strcmp (name, ".mdebug.eabi64") == 0)
5847 *abip = MIPS_ABI_EABI64;
5848 else
5849 warning ("unsupported ABI %s.", name + 8);
5850 }
5851
5852 static enum mips_abi
5853 global_mips_abi (void)
5854 {
5855 int i;
5856
5857 for (i = 0; mips_abi_strings[i] != NULL; i++)
5858 if (mips_abi_strings[i] == mips_abi_string)
5859 return (enum mips_abi) i;
5860
5861 internal_error (__FILE__, __LINE__, "unknown ABI string");
5862 }
5863
5864 static struct gdbarch *
5865 mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
5866 {
5867 struct gdbarch *gdbarch;
5868 struct gdbarch_tdep *tdep;
5869 int elf_flags;
5870 enum mips_abi mips_abi, found_abi, wanted_abi;
5871 int num_regs;
5872 enum mips_fpu_type fpu_type;
5873
5874 /* First of all, extract the elf_flags, if available. */
5875 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
5876 elf_flags = elf_elfheader (info.abfd)->e_flags;
5877 else if (arches != NULL)
5878 elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags;
5879 else
5880 elf_flags = 0;
5881 if (gdbarch_debug)
5882 fprintf_unfiltered (gdb_stdlog,
5883 "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags);
5884
5885 /* Check ELF_FLAGS to see if it specifies the ABI being used. */
5886 switch ((elf_flags & EF_MIPS_ABI))
5887 {
5888 case E_MIPS_ABI_O32:
5889 found_abi = MIPS_ABI_O32;
5890 break;
5891 case E_MIPS_ABI_O64:
5892 found_abi = MIPS_ABI_O64;
5893 break;
5894 case E_MIPS_ABI_EABI32:
5895 found_abi = MIPS_ABI_EABI32;
5896 break;
5897 case E_MIPS_ABI_EABI64:
5898 found_abi = MIPS_ABI_EABI64;
5899 break;
5900 default:
5901 if ((elf_flags & EF_MIPS_ABI2))
5902 found_abi = MIPS_ABI_N32;
5903 else
5904 found_abi = MIPS_ABI_UNKNOWN;
5905 break;
5906 }
5907
5908 /* GCC creates a pseudo-section whose name describes the ABI. */
5909 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
5910 bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi);
5911
5912 /* If we have no useful BFD information, use the ABI from the last
5913 MIPS architecture (if there is one). */
5914 if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
5915 found_abi = gdbarch_tdep (arches->gdbarch)->found_abi;
5916
5917 /* Try the architecture for any hint of the correct ABI. */
5918 if (found_abi == MIPS_ABI_UNKNOWN
5919 && info.bfd_arch_info != NULL
5920 && info.bfd_arch_info->arch == bfd_arch_mips)
5921 {
5922 switch (info.bfd_arch_info->mach)
5923 {
5924 case bfd_mach_mips3900:
5925 found_abi = MIPS_ABI_EABI32;
5926 break;
5927 case bfd_mach_mips4100:
5928 case bfd_mach_mips5000:
5929 found_abi = MIPS_ABI_EABI64;
5930 break;
5931 case bfd_mach_mips8000:
5932 case bfd_mach_mips10000:
5933 /* On Irix, ELF64 executables use the N64 ABI. The
5934 pseudo-sections which describe the ABI aren't present
5935 on IRIX. (Even for executables created by gcc.) */
5936 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
5937 && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
5938 found_abi = MIPS_ABI_N64;
5939 else
5940 found_abi = MIPS_ABI_N32;
5941 break;
5942 }
5943 }
5944
5945 if (gdbarch_debug)
5946 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n",
5947 found_abi);
5948
5949 /* What has the user specified from the command line? */
5950 wanted_abi = global_mips_abi ();
5951 if (gdbarch_debug)
5952 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n",
5953 wanted_abi);
5954
5955 /* Now that we have found what the ABI for this binary would be,
5956 check whether the user is overriding it. */
5957 if (wanted_abi != MIPS_ABI_UNKNOWN)
5958 mips_abi = wanted_abi;
5959 else if (found_abi != MIPS_ABI_UNKNOWN)
5960 mips_abi = found_abi;
5961 else
5962 mips_abi = MIPS_ABI_O32;
5963 if (gdbarch_debug)
5964 fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n",
5965 mips_abi);
5966
5967 /* Also used when doing an architecture lookup. */
5968 if (gdbarch_debug)
5969 fprintf_unfiltered (gdb_stdlog,
5970 "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n",
5971 mips64_transfers_32bit_regs_p);
5972
5973 /* Determine the MIPS FPU type. */
5974 if (!mips_fpu_type_auto)
5975 fpu_type = mips_fpu_type;
5976 else if (info.bfd_arch_info != NULL
5977 && info.bfd_arch_info->arch == bfd_arch_mips)
5978 switch (info.bfd_arch_info->mach)
5979 {
5980 case bfd_mach_mips3900:
5981 case bfd_mach_mips4100:
5982 case bfd_mach_mips4111:
5983 case bfd_mach_mips4120:
5984 fpu_type = MIPS_FPU_NONE;
5985 break;
5986 case bfd_mach_mips4650:
5987 fpu_type = MIPS_FPU_SINGLE;
5988 break;
5989 default:
5990 fpu_type = MIPS_FPU_DOUBLE;
5991 break;
5992 }
5993 else if (arches != NULL)
5994 fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type;
5995 else
5996 fpu_type = MIPS_FPU_DOUBLE;
5997 if (gdbarch_debug)
5998 fprintf_unfiltered (gdb_stdlog,
5999 "mips_gdbarch_init: fpu_type = %d\n", fpu_type);
6000
6001 /* try to find a pre-existing architecture */
6002 for (arches = gdbarch_list_lookup_by_info (arches, &info);
6003 arches != NULL;
6004 arches = gdbarch_list_lookup_by_info (arches->next, &info))
6005 {
6006 /* MIPS needs to be pedantic about which ABI the object is
6007 using. */
6008 if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags)
6009 continue;
6010 if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi)
6011 continue;
6012 /* Need to be pedantic about which register virtual size is
6013 used. */
6014 if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p
6015 != mips64_transfers_32bit_regs_p)
6016 continue;
6017 /* Be pedantic about which FPU is selected. */
6018 if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type)
6019 continue;
6020 return arches->gdbarch;
6021 }
6022
6023 /* Need a new architecture. Fill in a target specific vector. */
6024 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
6025 gdbarch = gdbarch_alloc (&info, tdep);
6026 tdep->elf_flags = elf_flags;
6027 tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p;
6028 tdep->found_abi = found_abi;
6029 tdep->mips_abi = mips_abi;
6030 tdep->mips_fpu_type = fpu_type;
6031
6032 /* Initially set everything according to the default ABI/ISA. */
6033 set_gdbarch_short_bit (gdbarch, 16);
6034 set_gdbarch_int_bit (gdbarch, 32);
6035 set_gdbarch_float_bit (gdbarch, 32);
6036 set_gdbarch_double_bit (gdbarch, 64);
6037 set_gdbarch_long_double_bit (gdbarch, 64);
6038 set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
6039 set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
6040 set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
6041
6042 set_gdbarch_elf_make_msymbol_special (gdbarch,
6043 mips_elf_make_msymbol_special);
6044
6045 /* Fill in the OS dependant register numbers and names. */
6046 {
6047 const char **reg_names;
6048 struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch,
6049 struct mips_regnum);
6050 if (info.osabi == GDB_OSABI_IRIX)
6051 {
6052 regnum->fp0 = 32;
6053 regnum->pc = 64;
6054 regnum->cause = 65;
6055 regnum->badvaddr = 66;
6056 regnum->hi = 67;
6057 regnum->lo = 68;
6058 regnum->fp_control_status = 69;
6059 regnum->fp_implementation_revision = 70;
6060 num_regs = 71;
6061 reg_names = mips_irix_reg_names;
6062 }
6063 else
6064 {
6065 regnum->lo = MIPS_EMBED_LO_REGNUM;
6066 regnum->hi = MIPS_EMBED_HI_REGNUM;
6067 regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
6068 regnum->cause = MIPS_EMBED_CAUSE_REGNUM;
6069 regnum->pc = MIPS_EMBED_PC_REGNUM;
6070 regnum->fp0 = MIPS_EMBED_FP0_REGNUM;
6071 regnum->fp_control_status = 70;
6072 regnum->fp_implementation_revision = 71;
6073 num_regs = 90;
6074 if (info.bfd_arch_info != NULL
6075 && info.bfd_arch_info->mach == bfd_mach_mips3900)
6076 reg_names = mips_tx39_reg_names;
6077 else
6078 reg_names = mips_generic_reg_names;
6079 }
6080 /* FIXME: cagney/2003-11-15: For MIPS, hasn't PC_REGNUM been
6081 replaced by read_pc? */
6082 set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs);
6083 set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
6084 set_gdbarch_fp0_regnum (gdbarch, regnum->fp0);
6085 set_gdbarch_num_regs (gdbarch, num_regs);
6086 set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
6087 set_gdbarch_register_name (gdbarch, mips_register_name);
6088 tdep->mips_processor_reg_names = reg_names;
6089 tdep->regnum = regnum;
6090 }
6091
6092 switch (mips_abi)
6093 {
6094 case MIPS_ABI_O32:
6095 set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
6096 set_gdbarch_return_value (gdbarch, mips_o32_return_value);
6097 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
6098 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
6099 tdep->default_mask_address_p = 0;
6100 set_gdbarch_long_bit (gdbarch, 32);
6101 set_gdbarch_ptr_bit (gdbarch, 32);
6102 set_gdbarch_long_long_bit (gdbarch, 64);
6103 break;
6104 case MIPS_ABI_O64:
6105 set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
6106 set_gdbarch_deprecated_store_return_value (gdbarch,
6107 mips_o64_store_return_value);
6108 set_gdbarch_deprecated_extract_return_value (gdbarch,
6109 mips_o64_extract_return_value);
6110 tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1;
6111 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
6112 tdep->default_mask_address_p = 0;
6113 set_gdbarch_long_bit (gdbarch, 32);
6114 set_gdbarch_ptr_bit (gdbarch, 32);
6115 set_gdbarch_long_long_bit (gdbarch, 64);
6116 set_gdbarch_deprecated_use_struct_convention (gdbarch, always_use_struct_convention);
6117 break;
6118 case MIPS_ABI_EABI32:
6119 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
6120 set_gdbarch_deprecated_store_return_value (gdbarch,
6121 mips_eabi_store_return_value);
6122 set_gdbarch_deprecated_extract_return_value (gdbarch,
6123 mips_eabi_extract_return_value);
6124 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6125 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6126 tdep->default_mask_address_p = 0;
6127 set_gdbarch_long_bit (gdbarch, 32);
6128 set_gdbarch_ptr_bit (gdbarch, 32);
6129 set_gdbarch_long_long_bit (gdbarch, 64);
6130 set_gdbarch_deprecated_reg_struct_has_addr
6131 (gdbarch, mips_eabi_reg_struct_has_addr);
6132 set_gdbarch_deprecated_use_struct_convention (gdbarch, mips_eabi_use_struct_convention);
6133 break;
6134 case MIPS_ABI_EABI64:
6135 set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
6136 set_gdbarch_deprecated_store_return_value (gdbarch,
6137 mips_eabi_store_return_value);
6138 set_gdbarch_deprecated_extract_return_value (gdbarch,
6139 mips_eabi_extract_return_value);
6140 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6141 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6142 tdep->default_mask_address_p = 0;
6143 set_gdbarch_long_bit (gdbarch, 64);
6144 set_gdbarch_ptr_bit (gdbarch, 64);
6145 set_gdbarch_long_long_bit (gdbarch, 64);
6146 set_gdbarch_deprecated_reg_struct_has_addr
6147 (gdbarch, mips_eabi_reg_struct_has_addr);
6148 set_gdbarch_deprecated_use_struct_convention (gdbarch, mips_eabi_use_struct_convention);
6149 break;
6150 case MIPS_ABI_N32:
6151 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
6152 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
6153 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6154 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6155 tdep->default_mask_address_p = 0;
6156 set_gdbarch_long_bit (gdbarch, 32);
6157 set_gdbarch_ptr_bit (gdbarch, 32);
6158 set_gdbarch_long_long_bit (gdbarch, 64);
6159 set_gdbarch_long_double_bit (gdbarch, 128);
6160 set_gdbarch_long_double_format (gdbarch,
6161 &floatformat_n32n64_long_double_big);
6162 break;
6163 case MIPS_ABI_N64:
6164 set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
6165 set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
6166 tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1;
6167 tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
6168 tdep->default_mask_address_p = 0;
6169 set_gdbarch_long_bit (gdbarch, 64);
6170 set_gdbarch_ptr_bit (gdbarch, 64);
6171 set_gdbarch_long_long_bit (gdbarch, 64);
6172 set_gdbarch_long_double_bit (gdbarch, 128);
6173 set_gdbarch_long_double_format (gdbarch,
6174 &floatformat_n32n64_long_double_big);
6175 break;
6176 default:
6177 internal_error (__FILE__, __LINE__, "unknown ABI in switch");
6178 }
6179
6180 /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
6181 that could indicate -gp32 BUT gas/config/tc-mips.c contains the
6182 comment:
6183
6184 ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
6185 flag in object files because to do so would make it impossible to
6186 link with libraries compiled without "-gp32". This is
6187 unnecessarily restrictive.
6188
6189 We could solve this problem by adding "-gp32" multilibs to gcc,
6190 but to set this flag before gcc is built with such multilibs will
6191 break too many systems.''
6192
6193 But even more unhelpfully, the default linker output target for
6194 mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
6195 for 64-bit programs - you need to change the ABI to change this,
6196 and not all gcc targets support that currently. Therefore using
6197 this flag to detect 32-bit mode would do the wrong thing given
6198 the current gcc - it would make GDB treat these 64-bit programs
6199 as 32-bit programs by default. */
6200
6201 set_gdbarch_read_pc (gdbarch, mips_read_pc);
6202 set_gdbarch_write_pc (gdbarch, mips_write_pc);
6203 set_gdbarch_read_sp (gdbarch, mips_read_sp);
6204
6205 /* Add/remove bits from an address. The MIPS needs be careful to
6206 ensure that all 32 bit addresses are sign extended to 64 bits. */
6207 set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
6208
6209 /* Unwind the frame. */
6210 set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc);
6211 set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id);
6212
6213 /* Map debug register numbers onto internal register numbers. */
6214 set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
6215 set_gdbarch_ecoff_reg_to_regnum (gdbarch,
6216 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6217 set_gdbarch_dwarf_reg_to_regnum (gdbarch,
6218 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6219 set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
6220 mips_dwarf_dwarf2_ecoff_reg_to_regnum);
6221 set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
6222
6223 /* MIPS version of CALL_DUMMY */
6224
6225 /* NOTE: cagney/2003-08-05: Eventually call dummy location will be
6226 replaced by a command, and all targets will default to on stack
6227 (regardless of the stack's execute status). */
6228 set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL);
6229 set_gdbarch_frame_align (gdbarch, mips_frame_align);
6230
6231 set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p);
6232 set_gdbarch_register_to_value (gdbarch, mips_register_to_value);
6233 set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
6234
6235 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
6236 set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc);
6237
6238 set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
6239
6240 set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
6241 set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
6242 set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
6243
6244 set_gdbarch_register_type (gdbarch, mips_register_type);
6245
6246 set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
6247
6248 set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
6249
6250 /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT,
6251 HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT
6252 need to all be folded into the target vector. Since they are
6253 being used as guards for STOPPED_BY_WATCHPOINT, why not have
6254 STOPPED_BY_WATCHPOINT return the type of watchpoint that the code
6255 is sitting on? */
6256 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
6257
6258 set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub);
6259
6260 /* NOTE drow/2004-02-11: We overload the core solib trampoline code
6261 to support MIPS16. This is a bad thing. Make sure not to do it
6262 if we have an OS ABI that actually supports shared libraries, since
6263 shared library support is more important. If we have an OS someday
6264 that supports both shared libraries and MIPS16, we'll have to find
6265 a better place for these. */
6266 if (info.osabi == GDB_OSABI_UNKNOWN)
6267 {
6268 set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub);
6269 set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
6270 }
6271
6272 /* Hook in OS ABI-specific overrides, if they have been registered. */
6273 gdbarch_init_osabi (info, gdbarch);
6274
6275 /* Unwind the frame. */
6276 frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer);
6277 frame_unwind_append_sniffer (gdbarch, mips_mdebug_frame_sniffer);
6278 frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer);
6279 frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer);
6280 frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer);
6281 frame_base_append_sniffer (gdbarch, mips_mdebug_frame_base_sniffer);
6282 frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer);
6283 frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer);
6284
6285 return gdbarch;
6286 }
6287
6288 static void
6289 mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c)
6290 {
6291 struct gdbarch_info info;
6292
6293 /* Force the architecture to update, and (if it's a MIPS architecture)
6294 mips_gdbarch_init will take care of the rest. */
6295 gdbarch_info_init (&info);
6296 gdbarch_update_p (info);
6297 }
6298
6299 /* Print out which MIPS ABI is in use. */
6300
6301 static void
6302 show_mips_abi (char *ignore_args, int from_tty)
6303 {
6304 if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
6305 printf_filtered
6306 ("The MIPS ABI is unknown because the current architecture is not MIPS.\n");
6307 else
6308 {
6309 enum mips_abi global_abi = global_mips_abi ();
6310 enum mips_abi actual_abi = mips_abi (current_gdbarch);
6311 const char *actual_abi_str = mips_abi_strings[actual_abi];
6312
6313 if (global_abi == MIPS_ABI_UNKNOWN)
6314 printf_filtered
6315 ("The MIPS ABI is set automatically (currently \"%s\").\n",
6316 actual_abi_str);
6317 else if (global_abi == actual_abi)
6318 printf_filtered
6319 ("The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
6320 actual_abi_str);
6321 else
6322 {
6323 /* Probably shouldn't happen... */
6324 printf_filtered
6325 ("The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n",
6326 actual_abi_str, mips_abi_strings[global_abi]);
6327 }
6328 }
6329 }
6330
6331 static void
6332 mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
6333 {
6334 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
6335 if (tdep != NULL)
6336 {
6337 int ef_mips_arch;
6338 int ef_mips_32bitmode;
6339 /* determine the ISA */
6340 switch (tdep->elf_flags & EF_MIPS_ARCH)
6341 {
6342 case E_MIPS_ARCH_1:
6343 ef_mips_arch = 1;
6344 break;
6345 case E_MIPS_ARCH_2:
6346 ef_mips_arch = 2;
6347 break;
6348 case E_MIPS_ARCH_3:
6349 ef_mips_arch = 3;
6350 break;
6351 case E_MIPS_ARCH_4:
6352 ef_mips_arch = 4;
6353 break;
6354 default:
6355 ef_mips_arch = 0;
6356 break;
6357 }
6358 /* determine the size of a pointer */
6359 ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
6360 fprintf_unfiltered (file,
6361 "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
6362 tdep->elf_flags);
6363 fprintf_unfiltered (file,
6364 "mips_dump_tdep: ef_mips_32bitmode = %d\n",
6365 ef_mips_32bitmode);
6366 fprintf_unfiltered (file,
6367 "mips_dump_tdep: ef_mips_arch = %d\n",
6368 ef_mips_arch);
6369 fprintf_unfiltered (file,
6370 "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
6371 tdep->mips_abi, mips_abi_strings[tdep->mips_abi]);
6372 fprintf_unfiltered (file,
6373 "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n",
6374 mips_mask_address_p (tdep),
6375 tdep->default_mask_address_p);
6376 }
6377 fprintf_unfiltered (file,
6378 "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
6379 MIPS_DEFAULT_FPU_TYPE,
6380 (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none"
6381 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6382 : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6383 : "???"));
6384 fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI);
6385 fprintf_unfiltered (file,
6386 "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
6387 MIPS_FPU_TYPE,
6388 (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none"
6389 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single"
6390 : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double"
6391 : "???"));
6392 fprintf_unfiltered (file,
6393 "mips_dump_tdep: mips_stack_argsize() = %d\n",
6394 mips_stack_argsize (current_gdbarch));
6395 fprintf_unfiltered (file, "mips_dump_tdep: A0_REGNUM = %d\n", A0_REGNUM);
6396 fprintf_unfiltered (file,
6397 "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n",
6398 XSTRING (ADDR_BITS_REMOVE (ADDR)));
6399 fprintf_unfiltered (file,
6400 "mips_dump_tdep: ATTACH_DETACH # %s\n",
6401 XSTRING (ATTACH_DETACH));
6402 fprintf_unfiltered (file,
6403 "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n",
6404 XSTRING (DWARF_REG_TO_REGNUM (REGNUM)));
6405 fprintf_unfiltered (file,
6406 "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n",
6407 XSTRING (ECOFF_REG_TO_REGNUM (REGNUM)));
6408 fprintf_unfiltered (file,
6409 "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n",
6410 FIRST_EMBED_REGNUM);
6411 fprintf_unfiltered (file,
6412 "mips_dump_tdep: DEPRECATED_IGNORE_HELPER_CALL # %s\n",
6413 XSTRING (DEPRECATED_IGNORE_HELPER_CALL (PC)));
6414 fprintf_unfiltered (file,
6415 "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n",
6416 XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME)));
6417 fprintf_unfiltered (file,
6418 "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n",
6419 XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME)));
6420 fprintf_unfiltered (file,
6421 "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n",
6422 LAST_EMBED_REGNUM);
6423 #ifdef MACHINE_CPROC_FP_OFFSET
6424 fprintf_unfiltered (file,
6425 "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n",
6426 MACHINE_CPROC_FP_OFFSET);
6427 #endif
6428 #ifdef MACHINE_CPROC_PC_OFFSET
6429 fprintf_unfiltered (file,
6430 "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n",
6431 MACHINE_CPROC_PC_OFFSET);
6432 #endif
6433 #ifdef MACHINE_CPROC_SP_OFFSET
6434 fprintf_unfiltered (file,
6435 "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n",
6436 MACHINE_CPROC_SP_OFFSET);
6437 #endif
6438 fprintf_unfiltered (file,
6439 "mips_dump_tdep: MIPS16_INSTLEN = %d\n",
6440 MIPS16_INSTLEN);
6441 fprintf_unfiltered (file, "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n");
6442 fprintf_unfiltered (file,
6443 "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n");
6444 fprintf_unfiltered (file,
6445 "mips_dump_tdep: MIPS_INSTLEN = %d\n", MIPS_INSTLEN);
6446 fprintf_unfiltered (file,
6447 "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n",
6448 MIPS_LAST_ARG_REGNUM,
6449 MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1);
6450 fprintf_unfiltered (file,
6451 "mips_dump_tdep: MIPS_NUMREGS = %d\n", MIPS_NUMREGS);
6452 fprintf_unfiltered (file,
6453 "mips_dump_tdep: mips_abi_regsize() = %d\n",
6454 mips_abi_regsize (current_gdbarch));
6455 fprintf_unfiltered (file,
6456 "mips_dump_tdep: PRID_REGNUM = %d\n", PRID_REGNUM);
6457 fprintf_unfiltered (file,
6458 "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n");
6459 fprintf_unfiltered (file,
6460 "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n");
6461 fprintf_unfiltered (file, "mips_dump_tdep: PROC_FRAME_REG = function?\n");
6462 fprintf_unfiltered (file, "mips_dump_tdep: PROC_FREG_MASK = function?\n");
6463 fprintf_unfiltered (file, "mips_dump_tdep: PROC_FREG_OFFSET = function?\n");
6464 fprintf_unfiltered (file, "mips_dump_tdep: PROC_HIGH_ADDR = function?\n");
6465 fprintf_unfiltered (file, "mips_dump_tdep: PROC_LOW_ADDR = function?\n");
6466 fprintf_unfiltered (file, "mips_dump_tdep: PROC_PC_REG = function?\n");
6467 fprintf_unfiltered (file, "mips_dump_tdep: PROC_REG_MASK = function?\n");
6468 fprintf_unfiltered (file, "mips_dump_tdep: PROC_REG_OFFSET = function?\n");
6469 fprintf_unfiltered (file, "mips_dump_tdep: PROC_SYMBOL = function?\n");
6470 fprintf_unfiltered (file, "mips_dump_tdep: PS_REGNUM = %d\n", PS_REGNUM);
6471 fprintf_unfiltered (file, "mips_dump_tdep: RA_REGNUM = %d\n", RA_REGNUM);
6472 #ifdef SAVED_BYTES
6473 fprintf_unfiltered (file,
6474 "mips_dump_tdep: SAVED_BYTES = %d\n", SAVED_BYTES);
6475 #endif
6476 #ifdef SAVED_FP
6477 fprintf_unfiltered (file, "mips_dump_tdep: SAVED_FP = %d\n", SAVED_FP);
6478 #endif
6479 #ifdef SAVED_PC
6480 fprintf_unfiltered (file, "mips_dump_tdep: SAVED_PC = %d\n", SAVED_PC);
6481 #endif
6482 fprintf_unfiltered (file,
6483 "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n",
6484 XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS)));
6485 fprintf_unfiltered (file,
6486 "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n",
6487 XSTRING (SKIP_TRAMPOLINE_CODE (PC)));
6488 fprintf_unfiltered (file,
6489 "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n",
6490 XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P)));
6491 fprintf_unfiltered (file,
6492 "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n",
6493 SOFTWARE_SINGLE_STEP_P ());
6494 fprintf_unfiltered (file,
6495 "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n",
6496 XSTRING (STAB_REG_TO_REGNUM (REGNUM)));
6497 #ifdef STACK_END_ADDR
6498 fprintf_unfiltered (file,
6499 "mips_dump_tdep: STACK_END_ADDR = %d\n",
6500 STACK_END_ADDR);
6501 #endif
6502 fprintf_unfiltered (file,
6503 "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n",
6504 XSTRING (STEP_SKIPS_DELAY (PC)));
6505 fprintf_unfiltered (file,
6506 "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n",
6507 STEP_SKIPS_DELAY_P);
6508 fprintf_unfiltered (file,
6509 "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n",
6510 XSTRING (STOPPED_BY_WATCHPOINT (WS)));
6511 fprintf_unfiltered (file, "mips_dump_tdep: T9_REGNUM = %d\n", T9_REGNUM);
6512 fprintf_unfiltered (file,
6513 "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n");
6514 fprintf_unfiltered (file,
6515 "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n",
6516 XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT
6517 (TYPE, CNT, OTHERTYPE)));
6518 #ifdef TRACE_CLEAR
6519 fprintf_unfiltered (file,
6520 "mips_dump_tdep: TRACE_CLEAR # %s\n",
6521 XSTRING (TRACE_CLEAR (THREAD, STATE)));
6522 #endif
6523 #ifdef TRACE_FLAVOR
6524 fprintf_unfiltered (file,
6525 "mips_dump_tdep: TRACE_FLAVOR = %d\n", TRACE_FLAVOR);
6526 #endif
6527 #ifdef TRACE_FLAVOR_SIZE
6528 fprintf_unfiltered (file,
6529 "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n",
6530 TRACE_FLAVOR_SIZE);
6531 #endif
6532 #ifdef TRACE_SET
6533 fprintf_unfiltered (file,
6534 "mips_dump_tdep: TRACE_SET # %s\n",
6535 XSTRING (TRACE_SET (X, STATE)));
6536 #endif
6537 #ifdef UNUSED_REGNUM
6538 fprintf_unfiltered (file,
6539 "mips_dump_tdep: UNUSED_REGNUM = %d\n", UNUSED_REGNUM);
6540 #endif
6541 fprintf_unfiltered (file, "mips_dump_tdep: V0_REGNUM = %d\n", V0_REGNUM);
6542 fprintf_unfiltered (file,
6543 "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n",
6544 (long) VM_MIN_ADDRESS);
6545 fprintf_unfiltered (file,
6546 "mips_dump_tdep: ZERO_REGNUM = %d\n", ZERO_REGNUM);
6547 }
6548
6549 extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */
6550
6551 void
6552 _initialize_mips_tdep (void)
6553 {
6554 static struct cmd_list_element *mipsfpulist = NULL;
6555 struct cmd_list_element *c;
6556
6557 mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN];
6558 if (MIPS_ABI_LAST + 1
6559 != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
6560 internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync");
6561
6562 gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
6563
6564 mips_pdr_data = register_objfile_data ();
6565
6566 /* Add root prefix command for all "set mips"/"show mips" commands */
6567 add_prefix_cmd ("mips", no_class, set_mips_command,
6568 "Various MIPS specific commands.",
6569 &setmipscmdlist, "set mips ", 0, &setlist);
6570
6571 add_prefix_cmd ("mips", no_class, show_mips_command,
6572 "Various MIPS specific commands.",
6573 &showmipscmdlist, "show mips ", 0, &showlist);
6574
6575 /* Allow the user to override the saved register size. */
6576 deprecated_add_show_from_set (add_set_enum_cmd ("saved-gpreg-size",
6577 class_obscure,
6578 size_enums,
6579 &mips_abi_regsize_string, "\
6580 Set size of general purpose registers saved on the stack.\n\
6581 This option can be set to one of:\n\
6582 32 - Force GDB to treat saved GP registers as 32-bit\n\
6583 64 - Force GDB to treat saved GP registers as 64-bit\n\
6584 auto - Allow GDB to use the target's default setting or autodetect the\n\
6585 saved GP register size from information contained in the executable.\n\
6586 (default: auto)", &setmipscmdlist), &showmipscmdlist);
6587
6588 /* Allow the user to override the argument stack size. */
6589 deprecated_add_show_from_set
6590 (add_set_enum_cmd ("stack-arg-size",
6591 class_obscure,
6592 size_enums,
6593 &mips_stack_argsize_string, "\
6594 Set the amount of stack space reserved for each argument.\n\
6595 This option can be set to one of:\n\
6596 32 - Force GDB to allocate 32-bit chunks per argument\n\
6597 64 - Force GDB to allocate 64-bit chunks per argument\n\
6598 auto - Allow GDB to determine the correct setting from the current\n\
6599 target and executable (default)", &setmipscmdlist),
6600 &showmipscmdlist);
6601
6602 /* Allow the user to override the ABI. */
6603 c = add_set_enum_cmd
6604 ("abi", class_obscure, mips_abi_strings, &mips_abi_string,
6605 "Set the ABI used by this program.\n"
6606 "This option can be set to one of:\n"
6607 " auto - the default ABI associated with the current binary\n"
6608 " o32\n"
6609 " o64\n" " n32\n" " n64\n" " eabi32\n" " eabi64", &setmipscmdlist);
6610 set_cmd_sfunc (c, mips_abi_update);
6611 add_cmd ("abi", class_obscure, show_mips_abi,
6612 "Show ABI in use by MIPS target", &showmipscmdlist);
6613
6614 /* Let the user turn off floating point and set the fence post for
6615 heuristic_proc_start. */
6616
6617 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
6618 "Set use of MIPS floating-point coprocessor.",
6619 &mipsfpulist, "set mipsfpu ", 0, &setlist);
6620 add_cmd ("single", class_support, set_mipsfpu_single_command,
6621 "Select single-precision MIPS floating-point coprocessor.",
6622 &mipsfpulist);
6623 add_cmd ("double", class_support, set_mipsfpu_double_command,
6624 "Select double-precision MIPS floating-point coprocessor.",
6625 &mipsfpulist);
6626 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
6627 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
6628 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
6629 add_cmd ("none", class_support, set_mipsfpu_none_command,
6630 "Select no MIPS floating-point coprocessor.", &mipsfpulist);
6631 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
6632 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
6633 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
6634 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
6635 "Select MIPS floating-point coprocessor automatically.",
6636 &mipsfpulist);
6637 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
6638 "Show current use of MIPS floating-point coprocessor target.",
6639 &showlist);
6640
6641 /* We really would like to have both "0" and "unlimited" work, but
6642 command.c doesn't deal with that. So make it a var_zinteger
6643 because the user can always use "999999" or some such for unlimited. */
6644 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
6645 (char *) &heuristic_fence_post, "\
6646 Set the distance searched for the start of a function.\n\
6647 If you are debugging a stripped executable, GDB needs to search through the\n\
6648 program for the start of a function. This command sets the distance of the\n\
6649 search. The only need to set it is when debugging a stripped executable.", &setlist);
6650 /* We need to throw away the frame cache when we set this, since it
6651 might change our ability to get backtraces. */
6652 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
6653 deprecated_add_show_from_set (c, &showlist);
6654
6655 /* Allow the user to control whether the upper bits of 64-bit
6656 addresses should be zeroed. */
6657 add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\
6658 Set zeroing of upper 32 bits of 64-bit addresses.", "\
6659 Show zeroing of upper 32 bits of 64-bit addresses.", "\
6660 Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\
6661 allow GDB to determine the correct value.\n", "\
6662 Zerroing of upper 32 bits of 64-bit address is %s.",
6663 NULL, show_mask_address, &setmipscmdlist, &showmipscmdlist);
6664
6665 /* Allow the user to control the size of 32 bit registers within the
6666 raw remote packet. */
6667 add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure,
6668 &mips64_transfers_32bit_regs_p, "\
6669 Set compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\
6670 Show compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\
6671 Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
6672 that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
6673 64 bits for others. Use \"off\" to disable compatibility mode", "\
6674 Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s.",
6675 set_mips64_transfers_32bit_regs, NULL, &setlist, &showlist);
6676
6677 /* Debug this files internals. */
6678 deprecated_add_show_from_set
6679 (add_set_cmd ("mips", class_maintenance, var_zinteger,
6680 &mips_debug, "Set mips debugging.\n\
6681 When non-zero, mips specific debugging is enabled.", &setdebuglist),
6682 &showdebuglist);
6683 }
This page took 0.173146 seconds and 4 git commands to generate.