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