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