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