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