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