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