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