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