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