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