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