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