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