Thu Apr 9 14:20:59 1998 Martin M. Hunt <hunt@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
CommitLineData
7d9884b9 1/* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
97e091b2 2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
0434c1a0 3 Free Software Foundation, Inc.
bd5635a1
RP
4 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
5 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6
7This file is part of GDB.
8
361bf6ee 9This program is free software; you can redistribute it and/or modify
bd5635a1 10it under the terms of the GNU General Public License as published by
361bf6ee
JG
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
bd5635a1 13
361bf6ee 14This program is distributed in the hope that it will be useful,
bd5635a1
RP
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
361bf6ee 20along with this program; if not, write to the Free Software
09af5868 21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bd5635a1 22
bd5635a1 23#include "defs.h"
09af5868 24#include "gdb_string.h"
bd5635a1
RP
25#include "frame.h"
26#include "inferior.h"
27#include "symtab.h"
28#include "value.h"
29#include "gdbcmd.h"
ef08856f 30#include "language.h"
bd5635a1 31#include "gdbcore.h"
62a469e1
SG
32#include "symfile.h"
33#include "objfiles.h"
3fed1c4a 34#include "gdbtypes.h"
28444bf3 35#include "target.h"
bd5635a1 36
ee5fb959
JK
37#include "opcode/mips.h"
38
28444bf3 39#define VM_MIN_ADDRESS (CORE_ADDR)0x400000
70126bf9
KH
40
41/* FIXME: Put this declaration in frame.h. */
42extern struct obstack frame_cache_obstack;
28444bf3 43
002a422b 44#if 0
ee5fb959 45static int mips_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
002a422b 46#endif
ee5fb959 47
912e805f 48int gdb_print_insn_mips PARAMS ((bfd_vma, disassemble_info *));
28444bf3 49
f2bf454e
FF
50static void mips_print_register PARAMS ((int, int));
51
52static mips_extra_func_info_t
53heuristic_proc_desc PARAMS ((CORE_ADDR, CORE_ADDR, struct frame_info *));
54
55static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
56
28444bf3 57static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
f2bf454e 58
e4dbd248
PS
59static void mips_set_fpu_command PARAMS ((char *, int,
60 struct cmd_list_element *));
61
62static void mips_show_fpu_command PARAMS ((char *, int,
63 struct cmd_list_element *));
64
9f9f94aa
SS
65void mips_set_processor_type_command PARAMS ((char *, int));
66
1d9489c1
JK
67int mips_set_processor_type PARAMS ((char *));
68
69static void mips_show_processor_type_command PARAMS ((char *, int));
70
9f9f94aa
SS
71static void reinit_frame_cache_sfunc PARAMS ((char *, int,
72 struct cmd_list_element *));
73
f2bf454e
FF
74static mips_extra_func_info_t
75 find_proc_desc PARAMS ((CORE_ADDR pc, struct frame_info *next_frame));
76
77static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
78 mips_extra_func_info_t proc_desc));
79
9f9f94aa
SS
80/* This value is the model of MIPS in use. It is derived from the value
81 of the PrID register. */
82
83char *mips_processor_type;
84
85char *tmp_mips_processor_type;
86
c2a0f1cb
ILT
87/* Some MIPS boards don't support floating point, so we permit the
88 user to turn it off. */
9f9f94aa 89
e4dbd248
PS
90enum mips_fpu_type mips_fpu;
91
92static char *mips_fpu_string;
c2a0f1cb 93
9f9f94aa
SS
94/* A set of original names, to be used when restoring back to generic
95 registers from a specific set. */
96
97char *mips_generic_reg_names[] = REGISTER_NAMES;
98
99/* Names of IDT R3041 registers. */
100
101char *mips_r3041_reg_names[] = {
102 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
103 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
104 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
105 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
106 "sr", "lo", "hi", "bad", "cause","pc",
107 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
108 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
109 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
110 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
111 "fsr", "fir", "fp", "",
112 "", "", "bus", "ccfg", "", "", "", "",
113 "", "", "port", "cmp", "", "", "epc", "prid",
114};
115
116/* Names of IDT R3051 registers. */
117
118char *mips_r3051_reg_names[] = {
119 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
120 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
121 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
122 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
123 "sr", "lo", "hi", "bad", "cause","pc",
124 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
125 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
126 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
127 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
128 "fsr", "fir", "fp", "",
129 "inx", "rand", "elo", "", "ctxt", "", "", "",
130 "", "", "ehi", "", "", "", "epc", "prid",
131};
132
133/* Names of IDT R3081 registers. */
134
135char *mips_r3081_reg_names[] = {
136 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
137 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
138 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
139 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
140 "sr", "lo", "hi", "bad", "cause","pc",
141 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
142 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
143 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
144 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
145 "fsr", "fir", "fp", "",
146 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
147 "", "", "ehi", "", "", "", "epc", "prid",
148};
149
e4dbd248
PS
150/* Names of LSI 33k registers. */
151
152char *mips_lsi33k_reg_names[] = {
153 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
154 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
155 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
156 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
157 "epc", "hi", "lo", "sr", "cause","badvaddr",
158 "dcic", "bpc", "bda", "", "", "", "", "",
159 "", "", "", "", "", "", "", "",
160 "", "", "", "", "", "", "", "",
161 "", "", "", "", "", "", "", "",
162 "", "", "", "",
163 "", "", "", "", "", "", "", "",
164 "", "", "", "", "", "", "", "",
165};
166
9f9f94aa
SS
167struct {
168 char *name;
169 char **regnames;
170} mips_processor_type_table[] = {
171 { "generic", mips_generic_reg_names },
172 { "r3041", mips_r3041_reg_names },
173 { "r3051", mips_r3051_reg_names },
174 { "r3071", mips_r3081_reg_names },
175 { "r3081", mips_r3081_reg_names },
e4dbd248 176 { "lsi33k", mips_lsi33k_reg_names },
9f9f94aa
SS
177 { NULL, NULL }
178};
179
f9f8c14b
MA
180/* Table to translate MIPS16 register field to actual register number. */
181static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
182
3127785a
RP
183/* Heuristic_proc_start may hunt through the text section for a long
184 time across a 2400 baud serial line. Allows the user to limit this
185 search. */
9f9f94aa 186
3127785a
RP
187static unsigned int heuristic_fence_post = 0;
188
0f552c5f 189#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
28444bf3 190#define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
0f552c5f
JG
191#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
192#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
af774411 193#define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
0f552c5f
JG
194#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
195#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
196#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
197#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
198#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
199#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
bd5635a1 200#define _PROC_MAGIC_ 0x0F0F0F0F
0f552c5f
JG
201#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
202#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
bd5635a1
RP
203
204struct linked_proc_info
205{
206 struct mips_extra_func_info info;
207 struct linked_proc_info *next;
dac4929a 208} *linked_proc_desc_table = NULL;
bd5635a1 209
f2bf454e 210
899c4021
MA
211/* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
212
213static int
214pc_is_mips16 (bfd_vma memaddr)
215{
216 struct minimal_symbol *sym;
217
218 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
219 if (IS_MIPS16_ADDR (memaddr))
220 return 1;
221
222 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
223 the high bit of the info field. Use this to decide if the function is
224 MIPS16 or normal MIPS. */
225 sym = lookup_minimal_symbol_by_pc (memaddr);
226 if (sym)
227 return MSYMBOL_IS_SPECIAL (sym);
228 else
229 return 0;
230}
231
232
f2bf454e
FF
233/* This returns the PC of the first inst after the prologue. If we can't
234 find the prologue, then return 0. */
235
236static CORE_ADDR
237after_prologue (pc, proc_desc)
238 CORE_ADDR pc;
239 mips_extra_func_info_t proc_desc;
240{
241 struct symtab_and_line sal;
242 CORE_ADDR func_addr, func_end;
243
244 if (!proc_desc)
245 proc_desc = find_proc_desc (pc, NULL);
246
247 if (proc_desc)
248 {
249 /* If function is frameless, then we need to do it the hard way. I
250 strongly suspect that frameless always means prologueless... */
251 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
252 && PROC_FRAME_OFFSET (proc_desc) == 0)
253 return 0;
254 }
255
256 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
257 return 0; /* Unknown */
258
259 sal = find_pc_line (func_addr, 0);
260
261 if (sal.end < func_end)
262 return sal.end;
263
264 /* The line after the prologue is after the end of the function. In this
265 case, tell the caller to find the prologue the hard way. */
266
267 return 0;
268}
269
f9f8c14b
MA
270/* Decode a MIPS32 instruction that saves a register in the stack, and
271 set the appropriate bit in the general register mask or float register mask
272 to indicate which register is saved. This is a helper function
273 for mips_find_saved_regs. */
274
275static void
276mips32_decode_reg_save (inst, gen_mask, float_mask)
277 t_inst inst;
278 unsigned long *gen_mask;
279 unsigned long *float_mask;
280{
281 int reg;
282
283 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
284 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
285 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
286 {
287 /* It might be possible to use the instruction to
288 find the offset, rather than the code below which
289 is based on things being in a certain order in the
290 frame, but figuring out what the instruction's offset
291 is relative to might be a little tricky. */
292 reg = (inst & 0x001f0000) >> 16;
293 *gen_mask |= (1 << reg);
294 }
295 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
296 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
297 || (inst & 0xffe00000) == 0xf7a00000)/* sdc1 freg,n($sp) */
298
299 {
300 reg = ((inst & 0x001f0000) >> 16);
301 *float_mask |= (1 << reg);
302 }
303}
304
305/* Decode a MIPS16 instruction that saves a register in the stack, and
306 set the appropriate bit in the general register or float register mask
307 to indicate which register is saved. This is a helper function
308 for mips_find_saved_regs. */
309
310static void
311mips16_decode_reg_save (inst, gen_mask)
312 t_inst inst;
313 unsigned long *gen_mask;
314{
b348b9fd 315 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
f9f8c14b 316 {
b348b9fd
MA
317 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
318 *gen_mask |= (1 << reg);
319 }
320 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
321 {
322 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
f9f8c14b
MA
323 *gen_mask |= (1 << reg);
324 }
325 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
326 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
af774411 327 *gen_mask |= (1 << RA_REGNUM);
f9f8c14b
MA
328}
329
c81a76b3
MA
330
331/* Fetch and return instruction from the specified location. If the PC
332 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
333
334static t_inst
335mips_fetch_instruction (addr)
336 CORE_ADDR addr;
337{
338 char buf[MIPS_INSTLEN];
339 int instlen;
340 int status;
341
899c4021 342 if (pc_is_mips16 (addr))
c81a76b3
MA
343 {
344 instlen = MIPS16_INSTLEN;
345 addr = UNMAKE_MIPS16_ADDR (addr);
346 }
347 else
348 instlen = MIPS_INSTLEN;
349 status = read_memory_nobpt (addr, buf, instlen);
350 if (status)
351 memory_error (status, addr);
352 return extract_unsigned_integer (buf, instlen);
353}
354
355
70126bf9
KH
356/* Guaranteed to set fci->saved_regs to some values (it never leaves it
357 NULL). */
358
359void
360mips_find_saved_regs (fci)
9f9f94aa 361 struct frame_info *fci;
70126bf9
KH
362{
363 int ireg;
364 CORE_ADDR reg_position;
365 /* r0 bit means kernel trap */
366 int kernel_trap;
367 /* What registers have been saved? Bitmasks. */
368 unsigned long gen_mask, float_mask;
369 mips_extra_func_info_t proc_desc;
c81a76b3 370 t_inst inst;
70126bf9
KH
371
372 fci->saved_regs = (struct frame_saved_regs *)
373 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
374 memset (fci->saved_regs, 0, sizeof (struct frame_saved_regs));
375
e4dbd248
PS
376 /* If it is the frame for sigtramp, the saved registers are located
377 in a sigcontext structure somewhere on the stack.
378 If the stack layout for sigtramp changes we might have to change these
379 constants and the companion fixup_sigtramp in mdebugread.c */
380#ifndef SIGFRAME_BASE
381/* To satisfy alignment restrictions, sigcontext is located 4 bytes
382 above the sigtramp frame. */
28444bf3
DP
383#define SIGFRAME_BASE MIPS_REGSIZE
384/* FIXME! Are these correct?? */
385#define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
386#define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
387#define SIGFRAME_FPREGSAVE_OFF \
388 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
e4dbd248
PS
389#endif
390#ifndef SIGFRAME_REG_SIZE
28444bf3
DP
391/* FIXME! Is this correct?? */
392#define SIGFRAME_REG_SIZE MIPS_REGSIZE
e4dbd248
PS
393#endif
394 if (fci->signal_handler_caller)
395 {
28444bf3 396 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
e4dbd248
PS
397 {
398 reg_position = fci->frame + SIGFRAME_REGSAVE_OFF
399 + ireg * SIGFRAME_REG_SIZE;
400 fci->saved_regs->regs[ireg] = reg_position;
401 }
28444bf3 402 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
e4dbd248
PS
403 {
404 reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF
405 + ireg * SIGFRAME_REG_SIZE;
406 fci->saved_regs->regs[FP0_REGNUM + ireg] = reg_position;
407 }
408 fci->saved_regs->regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF;
409 return;
410 }
411
70126bf9
KH
412 proc_desc = fci->proc_desc;
413 if (proc_desc == NULL)
414 /* I'm not sure how/whether this can happen. Normally when we can't
415 find a proc_desc, we "synthesize" one using heuristic_proc_desc
416 and set the saved_regs right away. */
417 return;
418
419 kernel_trap = PROC_REG_MASK(proc_desc) & 1;
420 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
421 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
422
f9f8c14b
MA
423 if (/* In any frame other than the innermost or a frame interrupted by
424 a signal, we assume that all registers have been saved.
425 This assumes that all register saves in a function happen before
426 the first function call. */
427 (fci->next == NULL || fci->next->signal_handler_caller)
70126bf9
KH
428
429 /* In a dummy frame we know exactly where things are saved. */
430 && !PROC_DESC_IS_DUMMY (proc_desc)
431
f2bf454e
FF
432 /* Don't bother unless we are inside a function prologue. Outside the
433 prologue, we know where everything is. */
434
435 && in_prologue (fci->pc, PROC_LOW_ADDR (proc_desc))
436
70126bf9
KH
437 /* Not sure exactly what kernel_trap means, but if it means
438 the kernel saves the registers without a prologue doing it,
439 we better not examine the prologue to see whether registers
440 have been saved yet. */
441 && !kernel_trap)
442 {
443 /* We need to figure out whether the registers that the proc_desc
444 claims are saved have been saved yet. */
445
446 CORE_ADDR addr;
70126bf9
KH
447
448 /* Bitmasks; set if we have found a save for the register. */
449 unsigned long gen_save_found = 0;
450 unsigned long float_save_found = 0;
c81a76b3 451 int instlen;
70126bf9 452
c1fc0935
MA
453 /* If the address is odd, assume this is MIPS16 code. */
454 addr = PROC_LOW_ADDR (proc_desc);
899c4021 455 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
f9f8c14b 456
20fa0902
MA
457 /* Scan through this function's instructions preceding the current
458 PC, and look for those that save registers. */
f9f8c14b
MA
459 while (addr < fci->pc)
460 {
c81a76b3 461 inst = mips_fetch_instruction (addr);
899c4021 462 if (pc_is_mips16 (addr))
f9f8c14b
MA
463 mips16_decode_reg_save (inst, &gen_save_found);
464 else
465 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
466 addr += instlen;
70126bf9
KH
467 }
468 gen_mask = gen_save_found;
469 float_mask = float_save_found;
470 }
471
472 /* Fill in the offsets for the registers which gen_mask says
473 were saved. */
474 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
28444bf3 475 for (ireg= MIPS_NUMREGS-1; gen_mask; --ireg, gen_mask <<= 1)
70126bf9
KH
476 if (gen_mask & 0x80000000)
477 {
478 fci->saved_regs->regs[ireg] = reg_position;
479 reg_position -= MIPS_REGSIZE;
480 }
c81a76b3
MA
481
482 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
483 of that normally used by gcc. Therefore, we have to fetch the first
484 instruction of the function, and if it's an entry instruction that
485 saves $s0 or $s1, correct their saved addresses. */
899c4021 486 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
c81a76b3
MA
487 {
488 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
489 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
490 {
491 int reg;
492 int sreg_count = (inst >> 6) & 3;
493
494 /* Check if the ra register was pushed on the stack. */
495 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
496 if (inst & 0x20)
497 reg_position -= MIPS_REGSIZE;
498
499 /* Check if the s0 and s1 registers were pushed on the stack. */
500 for (reg = 16; reg < sreg_count+16; reg++)
501 {
502 fci->saved_regs->regs[reg] = reg_position;
503 reg_position -= MIPS_REGSIZE;
504 }
505 }
506 }
507
70126bf9
KH
508 /* Fill in the offsets for the registers which float_mask says
509 were saved. */
510 reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc);
511
512 /* The freg_offset points to where the first *double* register
513 is saved. So skip to the high-order word. */
28444bf3 514 if (! GDB_TARGET_IS_MIPS64)
c81a76b3 515 reg_position += MIPS_REGSIZE;
28444bf3 516
20fa0902
MA
517 /* Fill in the offsets for the float registers which float_mask says
518 were saved. */
28444bf3 519 for (ireg = MIPS_NUMREGS-1; float_mask; --ireg, float_mask <<= 1)
70126bf9
KH
520 if (float_mask & 0x80000000)
521 {
522 fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
523 reg_position -= MIPS_REGSIZE;
524 }
525
526 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
527}
bd5635a1 528
28444bf3 529static CORE_ADDR
bd5635a1 530read_next_frame_reg(fi, regno)
9f9f94aa 531 struct frame_info *fi;
bd5635a1
RP
532 int regno;
533{
bd5635a1 534 for (; fi; fi = fi->next)
70126bf9 535 {
e4dbd248
PS
536 /* We have to get the saved sp from the sigcontext
537 if it is a signal handler frame. */
538 if (regno == SP_REGNUM && !fi->signal_handler_caller)
539 return fi->frame;
70126bf9
KH
540 else
541 {
542 if (fi->saved_regs == NULL)
543 mips_find_saved_regs (fi);
544 if (fi->saved_regs->regs[regno])
545 return read_memory_integer(fi->saved_regs->regs[regno], MIPS_REGSIZE);
546 }
547 }
548 return read_register (regno);
bd5635a1
RP
549}
550
96431497
MA
551/* mips_addr_bits_remove - remove useless address bits */
552
553CORE_ADDR
554mips_addr_bits_remove (addr)
555 CORE_ADDR addr;
556{
97e091b2
MA
557#if GDB_TARGET_IS_MIPS64
558 if ((addr >> 32 == (CORE_ADDR)0xffffffff)
f781fe93
MA
559 && (strcmp (target_shortname,"pmon")==0
560 || strcmp (target_shortname,"ddb")==0
561 || strcmp (target_shortname,"sim")==0))
96431497
MA
562 {
563 /* This hack is a work-around for existing boards using PMON,
564 the simulator, and any other 64-bit targets that doesn't have
565 true 64-bit addressing. On these targets, the upper 32 bits
566 of addresses are ignored by the hardware. Thus, the PC or SP
567 are likely to have been sign extended to all 1s by instruction
568 sequences that load 32-bit addresses. For example, a typical
569 piece of code that loads an address is this:
570 lui $r2, <upper 16 bits>
571 ori $r2, <lower 16 bits>
572 But the lui sign-extends the value such that the upper 32 bits
573 may be all 1s. The workaround is simply to mask off these bits.
574 In the future, gcc may be changed to support true 64-bit
575 addressing, and this masking will have to be disabled. */
576 addr &= (CORE_ADDR)0xffffffff;
577 }
f9f8c14b
MA
578#else
579 /* Even when GDB is configured for some 32-bit targets (e.g. mips-elf),
580 BFD is configured to handle 64-bit targets, so CORE_ADDR is 64 bits.
581 So we still have to mask off useless bits from addresses. */
582 addr &= (CORE_ADDR)0xffffffff;
97e091b2 583#endif
96431497
MA
584
585 return addr;
586}
587
f781fe93
MA
588void
589mips_init_frame_pc_first (fromleaf, prev)
590 int fromleaf;
591 struct frame_info *prev;
592{
593 CORE_ADDR pc, tmp;
594
595 pc = ((fromleaf) ? SAVED_PC_AFTER_CALL (prev->next) :
596 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
597 tmp = mips_skip_stub (pc);
598 prev->pc = tmp ? tmp : pc;
599}
600
601
28444bf3 602CORE_ADDR
bd5635a1 603mips_frame_saved_pc(frame)
9f9f94aa 604 struct frame_info *frame;
bd5635a1 605{
28444bf3 606 CORE_ADDR saved_pc;
0f552c5f 607 mips_extra_func_info_t proc_desc = frame->proc_desc;
0434c1a0
PS
608 /* We have to get the saved pc from the sigcontext
609 if it is a signal handler frame. */
610 int pcreg = frame->signal_handler_caller ? PC_REGNUM
611 : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM);
0f552c5f 612
bd5635a1 613 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
28444bf3
DP
614 saved_pc = read_memory_integer(frame->frame - MIPS_REGSIZE, MIPS_REGSIZE);
615 else
616 saved_pc = read_next_frame_reg(frame, pcreg);
0f552c5f 617
96431497 618 return ADDR_BITS_REMOVE (saved_pc);
bd5635a1
RP
619}
620
621static struct mips_extra_func_info temp_proc_desc;
622static struct frame_saved_regs temp_saved_regs;
623
639c8612
MA
624/* Set a register's saved stack address in temp_saved_regs. If an address
625 has already been set for this register, do nothing; this way we will
626 only recognize the first save of a given register in a function prologue.
627 This is a helper function for mips{16,32}_heuristic_proc_desc. */
628
629static void
630set_reg_offset (regno, offset)
631 int regno;
632 CORE_ADDR offset;
633{
634 if (temp_saved_regs.regs[regno] == 0)
635 temp_saved_regs.regs[regno] = offset;
636}
637
638
a8172eea
RP
639/* This fencepost looks highly suspicious to me. Removing it also
640 seems suspicious as it could affect remote debugging across serial
3127785a 641 lines. */
a8172eea 642
0f552c5f
JG
643static CORE_ADDR
644heuristic_proc_start(pc)
bd5635a1
RP
645 CORE_ADDR pc;
646{
32dab603
MA
647 CORE_ADDR start_pc;
648 CORE_ADDR fence;
20fa0902 649 int instlen;
b348b9fd 650 int seen_adjsp = 0;
0f552c5f 651
32dab603
MA
652 pc = ADDR_BITS_REMOVE (pc);
653 start_pc = pc;
654 fence = start_pc - heuristic_fence_post;
0f552c5f 655 if (start_pc == 0) return 0;
3127785a
RP
656
657 if (heuristic_fence_post == UINT_MAX
658 || fence < VM_MIN_ADDRESS)
659 fence = VM_MIN_ADDRESS;
0f552c5f 660
899c4021 661 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
20fa0902 662
bd5635a1 663 /* search back for previous return */
20fa0902 664 for (start_pc -= instlen; ; start_pc -= instlen)
a8172eea
RP
665 if (start_pc < fence)
666 {
3127785a
RP
667 /* It's not clear to me why we reach this point when
668 stop_soon_quietly, but with this test, at least we
669 don't print out warnings for every child forked (eg, on
670 decstation). 22apr93 rich@cygnus.com. */
671 if (!stop_soon_quietly)
672 {
23d35572
JK
673 static int blurb_printed = 0;
674
3127785a
RP
675 if (fence == VM_MIN_ADDRESS)
676 warning("Hit beginning of text section without finding");
677 else
678 warning("Hit heuristic-fence-post without finding");
679
f781fe93 680 warning("enclosing function for address 0x%s", paddr_nz (pc));
23d35572
JK
681 if (!blurb_printed)
682 {
683 printf_filtered ("\
684This warning occurs if you are debugging a function without any symbols\n\
685(for example, in a stripped executable). In that case, you may wish to\n\
686increase the size of the search with the `set heuristic-fence-post' command.\n\
687\n\
688Otherwise, you told GDB there was a function where there isn't one, or\n\
689(more likely) you have encountered a bug in GDB.\n");
690 blurb_printed = 1;
691 }
3127785a
RP
692 }
693
a8172eea
RP
694 return 0;
695 }
899c4021 696 else if (pc_is_mips16 (start_pc))
20fa0902 697 {
c1fc0935
MA
698 unsigned short inst;
699
b348b9fd
MA
700 /* On MIPS16, any one of the following is likely to be the
701 start of a function:
702 entry
703 addiu sp,-n
704 daddiu sp,-n
705 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
c81a76b3 706 inst = mips_fetch_instruction (start_pc);
b348b9fd
MA
707 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
708 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
709 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
710 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
711 break;
712 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
713 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
714 seen_adjsp = 1;
715 else
716 seen_adjsp = 0;
20fa0902 717 }
bd5635a1 718 else if (ABOUT_TO_RETURN(start_pc))
20fa0902
MA
719 {
720 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
bd5635a1 721 break;
20fa0902 722 }
bd5635a1 723
bd5635a1
RP
724#if 0
725 /* skip nops (usually 1) 0 - is this */
28444bf3
DP
726 while (start_pc < pc && read_memory_integer (start_pc, MIPS_INSTLEN) == 0)
727 start_pc += MIPS_INSTLEN;
bd5635a1
RP
728#endif
729 return start_pc;
730}
731
c81a76b3 732/* Fetch the immediate value from a MIPS16 instruction.
b348b9fd
MA
733 If the previous instruction was an EXTEND, use it to extend
734 the upper bits of the immediate value. This is a helper function
735 for mips16_heuristic_proc_desc. */
736
737static int
738mips16_get_imm (prev_inst, inst, nbits, scale, is_signed)
739 unsigned short prev_inst; /* previous instruction */
af774411 740 unsigned short inst; /* current instruction */
b348b9fd
MA
741 int nbits; /* number of bits in imm field */
742 int scale; /* scale factor to be applied to imm */
743 int is_signed; /* is the imm field signed? */
744{
745 int offset;
746
747 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
748 {
7d9e8fac 749 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
b348b9fd
MA
750 if (offset & 0x8000) /* check for negative extend */
751 offset = 0 - (0x10000 - (offset & 0xffff));
752 return offset | (inst & 0x1f);
753 }
754 else
755 {
756 int max_imm = 1 << nbits;
757 int mask = max_imm - 1;
758 int sign_bit = max_imm >> 1;
759
760 offset = inst & mask;
761 if (is_signed && (offset & sign_bit))
762 offset = 0 - (max_imm - offset);
763 return offset * scale;
764 }
765}
766
767
768/* Fill in values in temp_proc_desc based on the MIPS16 instruction
769 stream from start_pc to limit_pc. */
770
771static void
772mips16_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
bd5635a1 773 CORE_ADDR start_pc, limit_pc;
9f9f94aa 774 struct frame_info *next_frame;
b348b9fd 775 CORE_ADDR sp;
bd5635a1 776{
b348b9fd
MA
777 CORE_ADDR cur_pc;
778 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
779 unsigned short prev_inst = 0; /* saved copy of previous instruction */
780 unsigned inst = 0; /* current instruction */
639c8612
MA
781 unsigned entry_inst = 0; /* the entry instruction */
782 int reg, offset;
bd5635a1 783
af774411
MA
784 PROC_FRAME_OFFSET(&temp_proc_desc) = 0; /* size of stack frame */
785 PROC_FRAME_ADJUST(&temp_proc_desc) = 0; /* offset of FP from SP */
34df79fc 786
b348b9fd
MA
787 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
788 {
b348b9fd
MA
789 /* Save the previous instruction. If it's an EXTEND, we'll extract
790 the immediate offset extension from it in mips16_get_imm. */
791 prev_inst = inst;
792
c81a76b3
MA
793 /* Fetch and decode the instruction. */
794 inst = (unsigned short) mips_fetch_instruction (cur_pc);
b348b9fd
MA
795 if ((inst & 0xff00) == 0x6300 /* addiu sp */
796 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
797 {
798 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
799 if (offset < 0) /* negative stack adjustment? */
800 PROC_FRAME_OFFSET(&temp_proc_desc) -= offset;
801 else
802 /* Exit loop if a positive stack adjustment is found, which
803 usually means that the stack cleanup code in the function
804 epilogue is reached. */
805 break;
806 }
807 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
808 {
809 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
810 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
811 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
639c8612 812 set_reg_offset (reg, sp + offset);
b348b9fd
MA
813 }
814 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
815 {
816 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
817 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
818 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
639c8612 819 set_reg_offset (reg, sp + offset);
b348b9fd
MA
820 }
821 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
822 {
823 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
af774411 824 PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM);
639c8612 825 set_reg_offset (RA_REGNUM, sp + offset);
97e091b2 826 }
b348b9fd
MA
827 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
828 {
829 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
af774411 830 PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM);
639c8612 831 set_reg_offset (RA_REGNUM, sp + offset);
bd5635a1 832 }
b348b9fd
MA
833 else if (inst == 0x673d) /* move $s1, $sp */
834 {
639c8612 835 frame_addr = sp;
b348b9fd 836 PROC_FRAME_REG (&temp_proc_desc) = 17;
97e091b2 837 }
32dab603
MA
838 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
839 {
840 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
841 frame_addr = sp + offset;
842 PROC_FRAME_REG (&temp_proc_desc) = 17;
af774411 843 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
32dab603 844 }
b348b9fd
MA
845 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
846 {
847 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
848 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
849 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
639c8612 850 set_reg_offset (reg, frame_addr + offset);
b348b9fd
MA
851 }
852 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
853 {
854 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
855 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
856 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
639c8612 857 set_reg_offset (reg, frame_addr + offset);
b348b9fd
MA
858 }
859 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
639c8612
MA
860 entry_inst = inst; /* save for later processing */
861 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
862 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
863 }
b348b9fd 864
639c8612
MA
865 /* The entry instruction is typically the first instruction in a function,
866 and it stores registers at offsets relative to the value of the old SP
867 (before the prologue). But the value of the sp parameter to this
868 function is the new SP (after the prologue has been executed). So we
869 can't calculate those offsets until we've seen the entire prologue,
870 and can calculate what the old SP must have been. */
871 if (entry_inst != 0)
872 {
873 int areg_count = (entry_inst >> 8) & 7;
874 int sreg_count = (entry_inst >> 6) & 3;
b348b9fd 875
639c8612
MA
876 /* The entry instruction always subtracts 32 from the SP. */
877 PROC_FRAME_OFFSET(&temp_proc_desc) += 32;
b348b9fd 878
639c8612
MA
879 /* Now we can calculate what the SP must have been at the
880 start of the function prologue. */
881 sp += PROC_FRAME_OFFSET(&temp_proc_desc);
b348b9fd 882
639c8612
MA
883 /* Check if a0-a3 were saved in the caller's argument save area. */
884 for (reg = 4, offset = 0; reg < areg_count+4; reg++)
885 {
886 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
887 set_reg_offset (reg, sp + offset);
888 offset += MIPS_REGSIZE;
889 }
890
891 /* Check if the ra register was pushed on the stack. */
892 offset = -4;
893 if (entry_inst & 0x20)
894 {
895 PROC_REG_MASK(&temp_proc_desc) |= 1 << RA_REGNUM;
896 set_reg_offset (RA_REGNUM, sp + offset);
897 offset -= MIPS_REGSIZE;
898 }
899
900 /* Check if the s0 and s1 registers were pushed on the stack. */
901 for (reg = 16; reg < sreg_count+16; reg++)
902 {
903 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
904 set_reg_offset (reg, sp + offset);
905 offset -= MIPS_REGSIZE;
906 }
907 }
b348b9fd
MA
908}
909
910static void
911mips32_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
912 CORE_ADDR start_pc, limit_pc;
913 struct frame_info *next_frame;
914 CORE_ADDR sp;
915{
916 CORE_ADDR cur_pc;
917 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
918restart:
919 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
639c8612 920 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
b348b9fd
MA
921 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
922 {
b348b9fd 923 unsigned long inst, high_word, low_word;
c81a76b3 924 int reg;
b348b9fd
MA
925
926 /* Fetch the instruction. */
c81a76b3 927 inst = (unsigned long) mips_fetch_instruction (cur_pc);
b348b9fd
MA
928
929 /* Save some code by pre-extracting some useful fields. */
930 high_word = (inst >> 16) & 0xffff;
931 low_word = inst & 0xffff;
932 reg = high_word & 0x1f;
933
934 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
935 || high_word == 0x23bd /* addi $sp,$sp,-i */
936 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
937 {
938 if (low_word & 0x8000) /* negative stack adjustment? */
939 PROC_FRAME_OFFSET(&temp_proc_desc) += 0x10000 - low_word;
940 else
941 /* Exit loop if a positive stack adjustment is found, which
942 usually means that the stack cleanup code in the function
943 epilogue is reached. */
944 break;
945 }
946 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
947 {
948 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
639c8612 949 set_reg_offset (reg, sp + low_word);
b348b9fd
MA
950 }
951 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
952 {
953 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
954 but the register size used is only 32 bits. Make the address
955 for the saved register point to the lower 32 bits. */
956 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
639c8612 957 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
b348b9fd
MA
958 }
959 else if (high_word == 0x27be) /* addiu $30,$sp,size */
960 {
961 /* Old gcc frame, r30 is virtual frame pointer. */
32dab603 962 if ((long)low_word != PROC_FRAME_OFFSET(&temp_proc_desc))
b348b9fd
MA
963 frame_addr = sp + low_word;
964 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
965 {
966 unsigned alloca_adjust;
967 PROC_FRAME_REG (&temp_proc_desc) = 30;
968 frame_addr = read_next_frame_reg(next_frame, 30);
969 alloca_adjust = (unsigned)(frame_addr - (sp + low_word));
970 if (alloca_adjust > 0)
971 {
972 /* FP > SP + frame_size. This may be because
973 * of an alloca or somethings similar.
974 * Fix sp to "pre-alloca" value, and try again.
975 */
976 sp += alloca_adjust;
977 goto restart;
bd5635a1
RP
978 }
979 }
980 }
b348b9fd
MA
981 /* move $30,$sp. With different versions of gas this will be either
982 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
983 Accept any one of these. */
984 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
985 {
986 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
987 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
988 {
989 unsigned alloca_adjust;
990 PROC_FRAME_REG (&temp_proc_desc) = 30;
991 frame_addr = read_next_frame_reg(next_frame, 30);
992 alloca_adjust = (unsigned)(frame_addr - sp);
993 if (alloca_adjust > 0)
994 {
995 /* FP > SP + frame_size. This may be because
996 * of an alloca or somethings similar.
997 * Fix sp to "pre-alloca" value, and try again.
998 */
999 sp += alloca_adjust;
1000 goto restart;
97e091b2
MA
1001 }
1002 }
1003 }
b348b9fd
MA
1004 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
1005 {
1006 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
639c8612 1007 set_reg_offset (reg, frame_addr + low_word);
bd5635a1
RP
1008 }
1009 }
b348b9fd
MA
1010}
1011
1012static mips_extra_func_info_t
1013heuristic_proc_desc(start_pc, limit_pc, next_frame)
1014 CORE_ADDR start_pc, limit_pc;
1015 struct frame_info *next_frame;
1016{
1017 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
1018
1019 if (start_pc == 0) return NULL;
1020 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
1021 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
1022 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
1023 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
1024 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
1025
1026 if (start_pc + 200 < limit_pc)
1027 limit_pc = start_pc + 200;
899c4021 1028 if (pc_is_mips16 (start_pc))
b348b9fd
MA
1029 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
1030 else
1031 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
1032 return &temp_proc_desc;
bd5635a1
RP
1033}
1034
0f552c5f 1035static mips_extra_func_info_t
c1fc0935 1036non_heuristic_proc_desc (pc, addrptr)
9f9f94aa 1037 CORE_ADDR pc;
c1fc0935 1038 CORE_ADDR *addrptr;
bd5635a1 1039{
c1fc0935 1040 CORE_ADDR startaddr;
bd5635a1 1041 mips_extra_func_info_t proc_desc;
0f552c5f 1042 struct block *b = block_for_pc(pc);
48be4c35 1043 struct symbol *sym;
48be4c35
JK
1044
1045 find_pc_partial_function (pc, NULL, &startaddr, NULL);
c1fc0935
MA
1046 if (addrptr)
1047 *addrptr = startaddr;
97e091b2 1048 if (b == NULL || PC_IN_CALL_DUMMY (pc, 0, 0))
48be4c35
JK
1049 sym = NULL;
1050 else
1051 {
1052 if (startaddr > BLOCK_START (b))
1053 /* This is the "pathological" case referred to in a comment in
1054 print_frame_info. It might be better to move this check into
1055 symbol reading. */
1056 sym = NULL;
1057 else
c1fc0935 1058 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
48be4c35 1059 }
0f552c5f 1060
e4dbd248
PS
1061 /* If we never found a PDR for this function in symbol reading, then
1062 examine prologues to find the information. */
0f552c5f 1063 if (sym)
bd5635a1 1064 {
c1fc0935
MA
1065 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
1066 if (PROC_FRAME_REG (proc_desc) == -1)
1067 return NULL;
1068 else
1069 return proc_desc;
1070 }
1071 else
1072 return NULL;
1073}
1074
1075
1076static mips_extra_func_info_t
1077find_proc_desc (pc, next_frame)
1078 CORE_ADDR pc;
1079 struct frame_info *next_frame;
1080{
1081 mips_extra_func_info_t proc_desc;
1082 CORE_ADDR startaddr;
1083
1084 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
1085
1086 if (proc_desc)
1087 {
1088 /* IF this is the topmost frame AND
1089 * (this proc does not have debugging information OR
1090 * the PC is in the procedure prologue)
1091 * THEN create a "heuristic" proc_desc (by analyzing
1092 * the actual code) to replace the "official" proc_desc.
1093 */
1094 if (next_frame == NULL)
1095 {
1096 struct symtab_and_line val;
1097 struct symbol *proc_symbol =
1098 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
1099
1100 if (proc_symbol)
1101 {
1102 val = find_pc_line (BLOCK_START
1103 (SYMBOL_BLOCK_VALUE(proc_symbol)),
1104 0);
1105 val.pc = val.end ? val.end : pc;
bd5635a1 1106 }
c1fc0935
MA
1107 if (!proc_symbol || pc < val.pc)
1108 {
1109 mips_extra_func_info_t found_heuristic =
1110 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
1111 pc, next_frame);
1112 if (found_heuristic)
1113 proc_desc = found_heuristic;
bd5635a1
RP
1114 }
1115 }
1116 }
1117 else
1118 {
0f552c5f
JG
1119 /* Is linked_proc_desc_table really necessary? It only seems to be used
1120 by procedure call dummys. However, the procedures being called ought
1121 to have their own proc_descs, and even if they don't,
1122 heuristic_proc_desc knows how to create them! */
1123
bd5635a1 1124 register struct linked_proc_info *link;
9f9f94aa 1125
bd5635a1 1126 for (link = linked_proc_desc_table; link; link = link->next)
9f9f94aa
SS
1127 if (PROC_LOW_ADDR(&link->info) <= pc
1128 && PROC_HIGH_ADDR(&link->info) > pc)
1129 return &link->info;
23d35572 1130
48be4c35
JK
1131 if (startaddr == 0)
1132 startaddr = heuristic_proc_start (pc);
1133
bd5635a1 1134 proc_desc =
48be4c35 1135 heuristic_proc_desc (startaddr, pc, next_frame);
bd5635a1
RP
1136 }
1137 return proc_desc;
1138}
1139
96431497
MA
1140static CORE_ADDR
1141get_frame_pointer(frame, proc_desc)
1142 struct frame_info *frame;
1143 mips_extra_func_info_t proc_desc;
1144{
af774411
MA
1145 return ADDR_BITS_REMOVE (
1146 read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc)) +
1147 PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc));
96431497
MA
1148}
1149
bd5635a1
RP
1150mips_extra_func_info_t cached_proc_desc;
1151
9f9f94aa 1152CORE_ADDR
0f552c5f 1153mips_frame_chain(frame)
9f9f94aa 1154 struct frame_info *frame;
bd5635a1 1155{
f781fe93
MA
1156 mips_extra_func_info_t proc_desc;
1157 CORE_ADDR tmp;
1158 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
1159
1160 if (saved_pc == 0 || inside_entry_file (saved_pc))
1161 return 0;
1162
1163 /* Check if the PC is inside a call stub. If it is, fetch the
1164 PC of the caller of that stub. */
1165 if ((tmp = mips_skip_stub (saved_pc)) != 0)
1166 saved_pc = tmp;
1167
1168 /* Look up the procedure descriptor for this PC. */
1169 proc_desc = find_proc_desc(saved_pc, frame);
1170 if (!proc_desc)
1171 return 0;
1172
1173 cached_proc_desc = proc_desc;
1174
1175 /* If no frame pointer and frame size is zero, we must be at end
1176 of stack (or otherwise hosed). If we don't check frame size,
1177 we loop forever if we see a zero size frame. */
1178 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
1179 && PROC_FRAME_OFFSET (proc_desc) == 0
1180 /* The previous frame from a sigtramp frame might be frameless
1181 and have frame size zero. */
1182 && !frame->signal_handler_caller)
1183 return 0;
1184 else
1185 return get_frame_pointer (frame, proc_desc);
bd5635a1
RP
1186}
1187
1188void
1189init_extra_frame_info(fci)
1190 struct frame_info *fci;
1191{
96431497
MA
1192 int regnum;
1193
bd5635a1 1194 /* Use proc_desc calculated in frame_chain */
ee5fb959
JK
1195 mips_extra_func_info_t proc_desc =
1196 fci->next ? cached_proc_desc : find_proc_desc(fci->pc, fci->next);
0f552c5f 1197
70126bf9 1198 fci->saved_regs = NULL;
bd5635a1 1199 fci->proc_desc =
ee5fb959 1200 proc_desc == &temp_proc_desc ? 0 : proc_desc;
bd5635a1
RP
1201 if (proc_desc)
1202 {
c2a0f1cb 1203 /* Fixup frame-pointer - only needed for top frame */
5efd597b
PS
1204 /* This may not be quite right, if proc has a real frame register.
1205 Get the value of the frame relative sp, procedure might have been
1206 interrupted by a signal at it's very start. */
70126bf9
KH
1207 if (fci->pc == PROC_LOW_ADDR (proc_desc)
1208 && !PROC_DESC_IS_DUMMY (proc_desc))
1209 fci->frame = read_next_frame_reg (fci->next, SP_REGNUM);
c2a0f1cb 1210 else
96431497 1211 fci->frame = get_frame_pointer (fci->next, proc_desc);
bd5635a1 1212
48be4c35 1213 if (proc_desc == &temp_proc_desc)
ee5fb959 1214 {
09af5868
PS
1215 char *name;
1216
1217 /* Do not set the saved registers for a sigtramp frame,
1218 mips_find_saved_registers will do that for us.
1219 We can't use fci->signal_handler_caller, it is not yet set. */
1220 find_pc_partial_function (fci->pc, &name,
1221 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
1222 if (!IN_SIGTRAMP (fci->pc, name))
1223 {
1224 fci->saved_regs = (struct frame_saved_regs*)
1225 obstack_alloc (&frame_cache_obstack,
1226 sizeof (struct frame_saved_regs));
1227 *fci->saved_regs = temp_saved_regs;
1228 fci->saved_regs->regs[PC_REGNUM]
1229 = fci->saved_regs->regs[RA_REGNUM];
1230 }
ee5fb959 1231 }
bd5635a1
RP
1232
1233 /* hack: if argument regs are saved, guess these contain args */
96431497
MA
1234 fci->num_args = -1; /* assume we can't tell how many args for now */
1235 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
1236 {
1237 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
1238 {
1239 fci->num_args = regnum - A0_REGNUM + 1;
1240 break;
1241 }
1242 }
bd5635a1 1243 }
bd5635a1
RP
1244}
1245
a70dc898
RP
1246/* MIPS stack frames are almost impenetrable. When execution stops,
1247 we basically have to look at symbol information for the function
1248 that we stopped in, which tells us *which* register (if any) is
1249 the base of the frame pointer, and what offset from that register
1250 the frame itself is at.
1251
1252 This presents a problem when trying to examine a stack in memory
1253 (that isn't executing at the moment), using the "frame" command. We
1254 don't have a PC, nor do we have any registers except SP.
1255
1256 This routine takes two arguments, SP and PC, and tries to make the
1257 cached frames look as if these two arguments defined a frame on the
1258 cache. This allows the rest of info frame to extract the important
1259 arguments without difficulty. */
1260
9f9f94aa 1261struct frame_info *
c2a0f1cb
ILT
1262setup_arbitrary_frame (argc, argv)
1263 int argc;
9f9f94aa 1264 CORE_ADDR *argv;
a70dc898 1265{
c2a0f1cb
ILT
1266 if (argc != 2)
1267 error ("MIPS frame specifications require two arguments: sp and pc");
1268
1269 return create_new_frame (argv[0], argv[1]);
a70dc898
RP
1270}
1271
0f552c5f
JG
1272CORE_ADDR
1273mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
97e091b2
MA
1274 int nargs;
1275 value_ptr *args;
1276 CORE_ADDR sp;
1277 int struct_return;
1278 CORE_ADDR struct_addr;
bd5635a1 1279{
97e091b2
MA
1280 int argreg;
1281 int float_argreg;
1282 int argnum;
1283 int len = 0;
781a59b2 1284 int stack_offset = 0;
97e091b2
MA
1285
1286 /* Macros to round N up or down to the next A boundary; A must be
1287 a power of two. */
1288#define ROUND_DOWN(n,a) ((n) & ~((a)-1))
1289#define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
28444bf3
DP
1290
1291 /* First ensure that the stack and structure return address (if any)
97e091b2
MA
1292 are properly aligned. The stack has to be 64-bit aligned even
1293 on 32-bit machines, because doubles must be 64-bit aligned. */
1294 sp = ROUND_DOWN (sp, 8);
1295 struct_addr = ROUND_DOWN (struct_addr, MIPS_REGSIZE);
28444bf3 1296
97e091b2
MA
1297 /* Now make space on the stack for the args. We allocate more
1298 than necessary for EABI, because the first few arguments are
1299 passed in registers, but that's OK. */
1300 for (argnum = 0; argnum < nargs; argnum++)
1301 len += ROUND_UP (TYPE_LENGTH(VALUE_TYPE(args[argnum])), MIPS_REGSIZE);
61d2d19a 1302 sp -= ROUND_UP (len, 8);
97e091b2
MA
1303
1304 /* Initialize the integer and float register pointers. */
1305 argreg = A0_REGNUM;
1306 float_argreg = FPA0_REGNUM;
1307
1308 /* the struct_return pointer occupies the first parameter-passing reg */
5efd597b 1309 if (struct_return)
97e091b2
MA
1310 write_register (argreg++, struct_addr);
1311
97e091b2
MA
1312 /* Now load as many as possible of the first arguments into
1313 registers, and push the rest onto the stack. Loop thru args
1314 from first to last. */
1315 for (argnum = 0; argnum < nargs; argnum++)
5efd597b 1316 {
97e091b2 1317 char *val;
912e805f 1318 char valbuf[MAX_REGISTER_RAW_SIZE];
97e091b2
MA
1319 value_ptr arg = args[argnum];
1320 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1321 int len = TYPE_LENGTH (arg_type);
1322 enum type_code typecode = TYPE_CODE (arg_type);
1323
61d2d19a
PS
1324 /* The EABI passes structures that do not fit in a register by
1325 reference. In all other cases, pass the structure by value. */
781a59b2
MS
1326 if (MIPS_EABI && len > MIPS_REGSIZE &&
1327 (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
97e091b2
MA
1328 {
1329 store_address (valbuf, MIPS_REGSIZE, VALUE_ADDRESS (arg));
08d8f995 1330 typecode = TYPE_CODE_PTR;
97e091b2
MA
1331 len = MIPS_REGSIZE;
1332 val = valbuf;
1333 }
1334 else
1335 val = (char *)VALUE_CONTENTS (arg);
1336
1337 /* 32-bit ABIs always start floating point arguments in an
1338 even-numbered floating point register. */
1339 if (!GDB_TARGET_IS_MIPS64 && typecode == TYPE_CODE_FLT
1340 && (float_argreg & 1))
1341 float_argreg++;
1342
1343 /* Floating point arguments passed in registers have to be
1344 treated specially. On 32-bit architectures, doubles
1345 are passed in register pairs; the even register gets
c81a76b3
MA
1346 the low word, and the odd register gets the high word.
1347 On non-EABI processors, the first two floating point arguments are
1348 also copied to general registers, because MIPS16 functions
1349 don't use float registers for arguments. This duplication of
1350 arguments in general registers can't hurt non-MIPS16 functions
1351 because those registers are normally skipped. */
97e091b2
MA
1352 if (typecode == TYPE_CODE_FLT
1353 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM
1354 && mips_fpu != MIPS_FPU_NONE)
1355 {
1356 if (!GDB_TARGET_IS_MIPS64 && len == 8)
1357 {
1358 int low_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 4 : 0;
1359 unsigned long regval;
1360
c81a76b3 1361 /* Write the low word of the double to the even register(s). */
97e091b2 1362 regval = extract_unsigned_integer (val+low_offset, 4);
c81a76b3
MA
1363 write_register (float_argreg++, regval);
1364 if (!MIPS_EABI)
1365 write_register (argreg+1, regval);
1366
1367 /* Write the high word of the double to the odd register(s). */
97e091b2 1368 regval = extract_unsigned_integer (val+4-low_offset, 4);
c81a76b3
MA
1369 write_register (float_argreg++, regval);
1370 if (!MIPS_EABI)
1371 {
1372 write_register (argreg, regval);
1373 argreg += 2;
1374 }
97e091b2
MA
1375
1376 }
1377 else
1378 {
c81a76b3
MA
1379 /* This is a floating point value that fits entirely
1380 in a single register. */
97e091b2
MA
1381 CORE_ADDR regval = extract_address (val, len);
1382 write_register (float_argreg++, regval);
c81a76b3
MA
1383 if (!MIPS_EABI)
1384 {
1385 write_register (argreg, regval);
1386 argreg += GDB_TARGET_IS_MIPS64 ? 1 : 2;
1387 }
97e091b2 1388 }
97e091b2
MA
1389 }
1390 else
1391 {
1392 /* Copy the argument to general registers or the stack in
1393 register-sized pieces. Large arguments are split between
1394 registers and stack. */
781a59b2
MS
1395 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
1396 are treated specially: Irix cc passes them in registers
1397 where gcc sometimes puts them on the stack. For maximum
1398 compatibility, we will put them in both places. */
1399
1400 int odd_sized_struct = ((len > MIPS_REGSIZE) &&
1401 (len % MIPS_REGSIZE != 0));
97e091b2
MA
1402 while (len > 0)
1403 {
1404 int partial_len = len < MIPS_REGSIZE ? len : MIPS_REGSIZE;
61d2d19a 1405
781a59b2
MS
1406 if (argreg > MIPS_LAST_ARG_REGNUM || odd_sized_struct)
1407 {
1408 /* Write this portion of the argument to the stack. */
912e805f
AC
1409 /* Should shorter than int integer values be
1410 promoted to int before being stored? */
781a59b2 1411
912e805f 1412 int longword_offset = 0;
781a59b2
MS
1413 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1414 if (MIPS_REGSIZE == 8 &&
1415 (typecode == TYPE_CODE_INT ||
1416 typecode == TYPE_CODE_PTR ||
1417 typecode == TYPE_CODE_FLT) && len <= 4)
912e805f 1418 longword_offset = MIPS_REGSIZE - len;
781a59b2
MS
1419 else if ((typecode == TYPE_CODE_STRUCT ||
1420 typecode == TYPE_CODE_UNION) &&
1421 TYPE_LENGTH (arg_type) < MIPS_REGSIZE)
1422 longword_offset = MIPS_REGSIZE - len;
1423
1424 write_memory (sp + stack_offset + longword_offset,
1425 val, partial_len);
1426 }
1427
1428 /* Note!!! This is NOT an else clause.
1429 Odd sized structs may go thru BOTH paths. */
97e091b2
MA
1430 if (argreg <= MIPS_LAST_ARG_REGNUM)
1431 {
61d2d19a
PS
1432 CORE_ADDR regval = extract_address (val, partial_len);
1433
c430260c
MS
1434 /* A non-floating-point argument being passed in a
1435 general register. If a struct or union, and if
91ee2779
JL
1436 the remaining length is smaller than the register
1437 size, we have to adjust the register value on
1438 big endian targets.
158bda58 1439
c430260c
MS
1440 It does not seem to be necessary to do the
1441 same for integral types.
158bda58 1442
c430260c 1443 Also don't do this adjustment on EABI targets. */
158bda58
MS
1444
1445 if (!MIPS_EABI &&
91ee2779
JL
1446 TARGET_BYTE_ORDER == BIG_ENDIAN &&
1447 partial_len < MIPS_REGSIZE &&
c430260c 1448 (typecode == TYPE_CODE_STRUCT ||
158bda58
MS
1449 typecode == TYPE_CODE_UNION))
1450 regval <<= ((MIPS_REGSIZE - partial_len) *
1451 TARGET_CHAR_BIT);
1452
97e091b2
MA
1453 write_register (argreg, regval);
1454 argreg++;
1455
1456 /* If this is the old ABI, prevent subsequent floating
1457 point arguments from being passed in floating point
1458 registers. */
1459 if (!MIPS_EABI)
1460 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
1461 }
97e091b2
MA
1462
1463 len -= partial_len;
1464 val += partial_len;
781a59b2
MS
1465
1466 /* The offset onto the stack at which we will start
1467 copying parameters (after the registers are used up)
1468 begins at (4 * MIPS_REGSIZE) in the old ABI. This
1469 leaves room for the "home" area for register parameters.
1470
1471 In the new EABI, the 8 register parameters do not
1472 have "home" stack space reserved for them, so the
1473 stack offset does not get incremented until after
1474 we have used up the 8 parameter registers. */
1475 if (!(MIPS_EABI && argnum < 8))
1476 stack_offset += ROUND_UP (partial_len, MIPS_REGSIZE);
97e091b2
MA
1477 }
1478 }
5efd597b 1479 }
97e091b2
MA
1480
1481 /* Set the return address register to point to the entry
1482 point of the program, where a breakpoint lies in wait. */
1483 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS());
1484
1485 /* Return adjusted stack pointer. */
bd5635a1
RP
1486 return sp;
1487}
1488
c81a76b3 1489static void
28444bf3
DP
1490mips_push_register(CORE_ADDR *sp, int regno)
1491{
1492 char buffer[MAX_REGISTER_RAW_SIZE];
1493 int regsize = REGISTER_RAW_SIZE (regno);
1494
1495 *sp -= regsize;
1496 read_register_gen (regno, buffer);
1497 write_memory (*sp, buffer, regsize);
1498}
1499
1500/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
e03c0cc6 1501#define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
bd5635a1
RP
1502
1503void
1504mips_push_dummy_frame()
1505{
1506 int ireg;
1507 struct linked_proc_info *link = (struct linked_proc_info*)
1508 xmalloc(sizeof(struct linked_proc_info));
1509 mips_extra_func_info_t proc_desc = &link->info;
96431497 1510 CORE_ADDR sp = ADDR_BITS_REMOVE (read_register (SP_REGNUM));
28444bf3 1511 CORE_ADDR old_sp = sp;
bd5635a1
RP
1512 link->next = linked_proc_desc_table;
1513 linked_proc_desc_table = link;
28444bf3
DP
1514
1515/* FIXME! are these correct ? */
bd5635a1 1516#define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
28444bf3 1517#define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
bd5635a1 1518#define FLOAT_REG_SAVE_MASK MASK(0,19)
e4dbd248
PS
1519#define FLOAT_SINGLE_REG_SAVE_MASK \
1520 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
bd5635a1
RP
1521 /*
1522 * The registers we must save are all those not preserved across
1523 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
28444bf3
DP
1524 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
1525 * and FP Control/Status registers.
1526 *
bd5635a1
RP
1527 *
1528 * Dummy frame layout:
1529 * (high memory)
1530 * Saved PC
1531 * Saved MMHI, MMLO, FPC_CSR
1532 * Saved R31
1533 * Saved R28
1534 * ...
1535 * Saved R1
1536 * Saved D18 (i.e. F19, F18)
1537 * ...
1538 * Saved D0 (i.e. F1, F0)
f9f8c14b 1539 * Argument build area and stack arguments written via mips_push_arguments
bd5635a1
RP
1540 * (low memory)
1541 */
28444bf3
DP
1542
1543 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
28444bf3
DP
1544 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
1545 PROC_FRAME_OFFSET(proc_desc) = 0;
639c8612 1546 PROC_FRAME_ADJUST(proc_desc) = 0;
28444bf3
DP
1547 mips_push_register (&sp, PC_REGNUM);
1548 mips_push_register (&sp, HI_REGNUM);
1549 mips_push_register (&sp, LO_REGNUM);
1550 mips_push_register (&sp, mips_fpu == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
1551
1552 /* Save general CPU registers */
bd5635a1 1553 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
28444bf3 1554 PROC_REG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved R31) from FP */
bd5635a1
RP
1555 for (ireg = 32; --ireg >= 0; )
1556 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
28444bf3 1557 mips_push_register (&sp, ireg);
3fed1c4a 1558
28444bf3
DP
1559 /* Save floating point registers starting with high order word */
1560 PROC_FREG_MASK(proc_desc) =
1561 mips_fpu == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
1562 : mips_fpu == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
1563 PROC_FREG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved D18) from FP */
bd5635a1
RP
1564 for (ireg = 32; --ireg >= 0; )
1565 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
28444bf3 1566 mips_push_register (&sp, ireg + FP0_REGNUM);
3fed1c4a 1567
f9f8c14b
MA
1568 /* Update the frame pointer for the call dummy and the stack pointer.
1569 Set the procedure's starting and ending addresses to point to the
1570 call dummy address at the entry point. */
1571 write_register (PUSH_FP_REGNUM, old_sp);
bd5635a1 1572 write_register (SP_REGNUM, sp);
97e091b2
MA
1573 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS();
1574 PROC_HIGH_ADDR(proc_desc) = CALL_DUMMY_ADDRESS() + 4;
bd5635a1
RP
1575 SET_PROC_DESC_IS_DUMMY(proc_desc);
1576 PROC_PC_REG(proc_desc) = RA_REGNUM;
1577}
1578
1579void
1580mips_pop_frame()
dac4929a
SG
1581{
1582 register int regnum;
9f9f94aa
SS
1583 struct frame_info *frame = get_current_frame ();
1584 CORE_ADDR new_sp = FRAME_FP (frame);
dac4929a 1585
a70dc898 1586 mips_extra_func_info_t proc_desc = frame->proc_desc;
dac4929a
SG
1587
1588 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
70126bf9
KH
1589 if (frame->saved_regs == NULL)
1590 mips_find_saved_regs (frame);
61d2d19a 1591 for (regnum = 0; regnum < NUM_REGS; regnum++)
dac4929a 1592 {
61d2d19a
PS
1593 if (regnum != SP_REGNUM && regnum != PC_REGNUM
1594 && frame->saved_regs->regs[regnum])
1595 write_register (regnum,
1596 read_memory_integer (frame->saved_regs->regs[regnum],
1597 MIPS_REGSIZE));
dac4929a
SG
1598 }
1599 write_register (SP_REGNUM, new_sp);
1600 flush_cached_frames ();
dac4929a 1601
199b2450 1602 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
bd5635a1 1603 {
dac4929a
SG
1604 struct linked_proc_info *pi_ptr, *prev_ptr;
1605
1606 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1607 pi_ptr != NULL;
1608 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1609 {
1610 if (&pi_ptr->info == proc_desc)
1611 break;
1612 }
1613
1614 if (pi_ptr == NULL)
1615 error ("Can't locate dummy extra frame info\n");
1616
1617 if (prev_ptr != NULL)
1618 prev_ptr->next = pi_ptr->next;
1619 else
1620 linked_proc_desc_table = pi_ptr->next;
1621
1622 free (pi_ptr);
1623
28444bf3
DP
1624 write_register (HI_REGNUM,
1625 read_memory_integer (new_sp - 2*MIPS_REGSIZE, MIPS_REGSIZE));
1626 write_register (LO_REGNUM,
1627 read_memory_integer (new_sp - 3*MIPS_REGSIZE, MIPS_REGSIZE));
e4dbd248 1628 if (mips_fpu != MIPS_FPU_NONE)
28444bf3
DP
1629 write_register (FCRCS_REGNUM,
1630 read_memory_integer (new_sp - 4*MIPS_REGSIZE, MIPS_REGSIZE));
bd5635a1 1631 }
bd5635a1
RP
1632}
1633
0f552c5f 1634static void
a70dc898 1635mips_print_register (regnum, all)
bd5635a1
RP
1636 int regnum, all;
1637{
e4dbd248 1638 char raw_buffer[MAX_REGISTER_RAW_SIZE];
bd5635a1 1639
48be4c35
JK
1640 /* Get the data in raw format. */
1641 if (read_relative_register_raw_bytes (regnum, raw_buffer))
1642 {
1643 printf_filtered ("%s: [Invalid]", reg_names[regnum]);
1644 return;
1645 }
1646
781a59b2 1647 /* If an even floating point register, also print as double. */
899c4021 1648 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
e4dbd248 1649 && !((regnum-FP0_REGNUM) & 1))
899c4021
MA
1650 if (REGISTER_RAW_SIZE(regnum) == 4) /* this would be silly on MIPS64 */
1651 {
1652 char dbuffer[2 * MAX_REGISTER_RAW_SIZE];
48be4c35 1653
899c4021
MA
1654 read_relative_register_raw_bytes (regnum, dbuffer);
1655 read_relative_register_raw_bytes (regnum+1, dbuffer+MIPS_REGSIZE);
1656 REGISTER_CONVERT_TO_TYPE (regnum, builtin_type_double, dbuffer);
c81a76b3 1657
899c4021
MA
1658 printf_filtered ("(d%d: ", regnum-FP0_REGNUM);
1659 val_print (builtin_type_double, dbuffer, 0,
1660 gdb_stdout, 0, 1, 0, Val_pretty_default);
1661 printf_filtered ("); ");
1662 }
199b2450 1663 fputs_filtered (reg_names[regnum], gdb_stdout);
48be4c35
JK
1664
1665 /* The problem with printing numeric register names (r26, etc.) is that
1666 the user can't use them on input. Probably the best solution is to
1667 fix it so that either the numeric or the funky (a2, etc.) names
1668 are accepted on input. */
28444bf3 1669 if (regnum < MIPS_NUMREGS)
48be4c35
JK
1670 printf_filtered ("(r%d): ", regnum);
1671 else
1672 printf_filtered (": ");
bd5635a1 1673
48be4c35 1674 /* If virtual format is floating, print it that way. */
ac57e5ad 1675 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
899c4021
MA
1676 if (REGISTER_RAW_SIZE(regnum) == 8)
1677 { /* show 8-byte floats as float AND double: */
1678 int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN);
1679
1680 printf_filtered (" (float) ");
1681 val_print (builtin_type_float, raw_buffer + offset, 0,
1682 gdb_stdout, 0, 1, 0, Val_pretty_default);
1683 printf_filtered (", (double) ");
1684 val_print (builtin_type_double, raw_buffer, 0,
1685 gdb_stdout, 0, 1, 0, Val_pretty_default);
1686 }
1687 else
1688 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0,
1689 gdb_stdout, 0, 1, 0, Val_pretty_default);
48be4c35
JK
1690 /* Else print as integer in hex. */
1691 else
ac57e5ad
SS
1692 print_scalar_formatted (raw_buffer, REGISTER_VIRTUAL_TYPE (regnum),
1693 'x', 0, gdb_stdout);
bd5635a1
RP
1694}
1695
899c4021
MA
1696/* Replacement for generic do_registers_info.
1697 Print regs in pretty columns. */
1698
1699static int
1700do_fp_register_row (regnum)
1701 int regnum;
1702{ /* do values for FP (float) regs */
1703 char raw_buffer[2] [REGISTER_RAW_SIZE(FP0_REGNUM)];
1704 char dbl_buffer[2 * REGISTER_RAW_SIZE(FP0_REGNUM)];
1705 /* use HI and LO to control the order of combining two flt regs */
1706 int HI = (TARGET_BYTE_ORDER == BIG_ENDIAN);
1707 int LO = (TARGET_BYTE_ORDER != BIG_ENDIAN);
1708 double doub, flt1, flt2; /* doubles extracted from raw hex data */
1709 int inv1, inv2, inv3;
1710
1711 /* Get the data in raw format. */
1712 if (read_relative_register_raw_bytes (regnum, raw_buffer[HI]))
1713 error ("can't read register %d (%s)", regnum, reg_names[regnum]);
1714 if (REGISTER_RAW_SIZE(regnum) == 4)
1715 {
1716 /* 4-byte registers: we can fit two registers per row. */
1717 /* Also print every pair of 4-byte regs as an 8-byte double. */
1718 if (read_relative_register_raw_bytes (regnum + 1, raw_buffer[LO]))
1719 error ("can't read register %d (%s)",
1720 regnum + 1, reg_names[regnum + 1]);
1721
1722 /* copy the two floats into one double, and unpack both */
1723 memcpy (dbl_buffer, raw_buffer, sizeof(dbl_buffer));
1724 flt1 = unpack_double (builtin_type_float, raw_buffer[HI], &inv1);
1725 flt2 = unpack_double (builtin_type_float, raw_buffer[LO], &inv2);
1726 doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
1727
1728 printf_filtered (inv1 ? " %-5s: <invalid float>" :
1729 " %-5s%-17.9g", reg_names[regnum], flt1);
1730 printf_filtered (inv2 ? " %-5s: <invalid float>" :
1731 " %-5s%-17.9g", reg_names[regnum + 1], flt2);
1732 printf_filtered (inv3 ? " dbl: <invalid double>\n" :
1733 " dbl: %-24.17g\n", doub);
1734 /* may want to do hex display here (future enhancement) */
1735 regnum +=2;
1736 }
1737 else
1738 { /* eight byte registers: print each one as float AND as double. */
1739 int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN);
1740
1741 memcpy (dbl_buffer, raw_buffer[HI], sizeof(dbl_buffer));
1742 flt1 = unpack_double (builtin_type_float,
1743 &raw_buffer[HI][offset], &inv1);
1744 doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
1745
1746 printf_filtered (inv1 ? " %-5s: <invalid float>" :
1747 " %-5s flt: %-17.9g", reg_names[regnum], flt1);
1748 printf_filtered (inv3 ? " dbl: <invalid double>\n" :
1749 " dbl: %-24.17g\n", doub);
1750 /* may want to do hex display here (future enhancement) */
1751 regnum++;
1752 }
1753 return regnum;
1754}
1755
1756/* Print a row's worth of GP (int) registers, with name labels above */
1757
1758static int
1759do_gp_register_row (regnum)
1760 int regnum;
912e805f
AC
1761{
1762 /* do values for GP (int) regs */
1763 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1764 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
1765 int col, byte;
1766 int start_regnum = regnum;
1767 int numregs = NUM_REGS;
1768
1769/* start-sanitize-sky */
1770#ifdef NUM_R5900_REGS
1771 numregs = NUM_R5900_REGS;
1772#endif
1773/* end-sanitize-sky */
899c4021
MA
1774
1775 /* For GP registers, we print a separate row of names above the vals */
1776 printf_filtered (" ");
912e805f 1777 for (col = 0; col < ncols && regnum < numregs; regnum++)
899c4021
MA
1778 {
1779 if (*reg_names[regnum] == '\0')
1780 continue; /* unused register */
1781 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
1782 break; /* end the row: reached FP register */
1783 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
1784 reg_names[regnum]);
1785 col++;
1786 }
1787 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
1788 start_regnum); /* print the R0 to R31 names */
1789
1790 regnum = start_regnum; /* go back to start of row */
1791 /* now print the values in hex, 4 or 8 to the row */
912e805f 1792 for (col = 0; col < ncols && regnum < numregs; regnum++)
899c4021
MA
1793 {
1794 if (*reg_names[regnum] == '\0')
1795 continue; /* unused register */
1796 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
1797 break; /* end row: reached FP register */
1798 /* OK: get the data in raw format. */
1799 if (read_relative_register_raw_bytes (regnum, raw_buffer))
1800 error ("can't read register %d (%s)", regnum, reg_names[regnum]);
912e805f
AC
1801 /* pad small registers */
1802 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_RAW_SIZE (regnum)); byte++)
1803 printf_filtered (" ");
899c4021
MA
1804 /* Now print the register value in hex, endian order. */
1805 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1806 for (byte = 0; byte < REGISTER_RAW_SIZE (regnum); byte++)
1807 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
1808 else
1809 for (byte = REGISTER_RAW_SIZE (regnum) - 1; byte >= 0; byte--)
1810 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
1811 printf_filtered (" ");
1812 col++;
1813 }
1814 if (col > 0) /* ie. if we actually printed anything... */
1815 printf_filtered ("\n");
1816
1817 return regnum;
1818}
1819
1820/* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
9f9f94aa 1821
0f552c5f 1822void
361bf6ee 1823mips_do_registers_info (regnum, fpregs)
bd5635a1 1824 int regnum;
361bf6ee 1825 int fpregs;
bd5635a1 1826{
899c4021 1827 if (regnum != -1) /* do one specified register */
9f9f94aa
SS
1828 {
1829 if (*(reg_names[regnum]) == '\0')
1830 error ("Not a valid register for the current processor type");
1831
bd5635a1
RP
1832 mips_print_register (regnum, 0);
1833 printf_filtered ("\n");
9f9f94aa 1834 }
899c4021 1835 else /* do all (or most) registers */
9f9f94aa 1836 {
899c4021
MA
1837 regnum = 0;
1838 while (regnum < NUM_REGS)
912e805f
AC
1839 {
1840 if (TYPE_CODE(REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
1841 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
1842 regnum = do_fp_register_row (regnum); /* FP regs */
1843 else
1844 regnum += MIPS_NUMREGS; /* skip floating point regs */
899c4021 1845 else
912e805f
AC
1846 regnum = do_gp_register_row (regnum); /* GP (int) regs */
1847/* start-sanitize-sky */
1848#ifdef NUM_R5900_REGS
1849 /* For the sky project, NUM_REGS includes the vector slaves,
1850 which are handled elsewhere */
1851 if (regnum >= NUM_R5900_REGS)
1852 break;
1853#endif
1854/* end-sanitize-sky */
1855 }
9f9f94aa 1856 }
bd5635a1 1857}
9f9f94aa 1858
bd5635a1
RP
1859/* Return number of args passed to a frame. described by FIP.
1860 Can return -1, meaning no way to tell. */
1861
0f552c5f 1862int
9f9f94aa
SS
1863mips_frame_num_args (frame)
1864 struct frame_info *frame;
bd5635a1 1865{
9f9f94aa
SS
1866#if 0 /* FIXME Use or lose this! */
1867 struct chain_info_t *p;
bd5635a1 1868
9f9f94aa
SS
1869 p = mips_find_cached_frame (FRAME_FP (frame));
1870 if (p->valid)
1871 return p->the_info.numargs;
bd5635a1 1872#endif
9f9f94aa 1873 return -1;
bd5635a1 1874}
96431497 1875
427fec5d 1876/* Is this a branch with a delay slot? */
9f9f94aa 1877
b5aff268
JK
1878static int is_delayed PARAMS ((unsigned long));
1879
ee5fb959
JK
1880static int
1881is_delayed (insn)
1882 unsigned long insn;
1883{
1884 int i;
1885 for (i = 0; i < NUMOPCODES; ++i)
1886 if (mips_opcodes[i].pinfo != INSN_MACRO
1887 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
1888 break;
427fec5d
JK
1889 return (i < NUMOPCODES
1890 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
1891 | INSN_COND_BRANCH_DELAY
1892 | INSN_COND_BRANCH_LIKELY)));
ee5fb959 1893}
b5aff268
JK
1894
1895int
1896mips_step_skips_delay (pc)
1897 CORE_ADDR pc;
1898{
96431497 1899 char buf[MIPS_INSTLEN];
b5aff268 1900
f9f8c14b 1901 /* There is no branch delay slot on MIPS16. */
899c4021 1902 if (pc_is_mips16 (pc))
f9f8c14b
MA
1903 return 0;
1904
96431497 1905 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
b5aff268
JK
1906 /* If error reading memory, guess that it is not a delayed branch. */
1907 return 0;
96431497 1908 return is_delayed ((unsigned long)extract_unsigned_integer (buf, MIPS_INSTLEN));
b5aff268 1909}
ee5fb959 1910
bd5635a1 1911
20fa0902
MA
1912/* Skip the PC past function prologue instructions (32-bit version).
1913 This is a helper function for mips_skip_prologue. */
1914
1915static CORE_ADDR
1916mips32_skip_prologue (pc, lenient)
1917 CORE_ADDR pc; /* starting PC to search from */
ee5fb959 1918 int lenient;
bd5635a1 1919{
28444bf3 1920 t_inst inst;
20fa0902 1921 CORE_ADDR end_pc;
0b0d6c3f 1922 int seen_sp_adjust = 0;
ac57e5ad 1923 int load_immediate_bytes = 0;
bd5635a1 1924
e157305c
PS
1925 /* Skip the typical prologue instructions. These are the stack adjustment
1926 instruction and the instructions that save registers on the stack
1927 or in the gcc frame. */
20fa0902 1928 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
ee5fb959 1929 {
b348b9fd 1930 unsigned long high_word;
ee5fb959 1931
c81a76b3 1932 inst = mips_fetch_instruction (pc);
b348b9fd 1933 high_word = (inst >> 16) & 0xffff;
ee5fb959 1934
002a422b 1935#if 0
ee5fb959
JK
1936 if (lenient && is_delayed (inst))
1937 continue;
002a422b 1938#endif
ee5fb959 1939
b348b9fd
MA
1940 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
1941 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
0b0d6c3f 1942 seen_sp_adjust = 1;
ac57e5ad
SS
1943 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
1944 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
1945 seen_sp_adjust = 1;
97e091b2
MA
1946 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
1947 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
1948 && (inst & 0x001F0000)) /* reg != $zero */
1949 continue;
1950
e157305c
PS
1951 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
1952 continue;
1953 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
1954 /* sx reg,n($s8) */
1955 continue; /* reg != $zero */
1d9489c1
JK
1956
1957 /* move $s8,$sp. With different versions of gas this will be either
20fa0902
MA
1958 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
1959 Accept any one of these. */
1960 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
0b0d6c3f 1961 continue;
1d9489c1 1962
1b71de8e
PS
1963 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
1964 continue;
b348b9fd 1965 else if (high_word == 0x3c1c) /* lui $gp,n */
e03c0cc6 1966 continue;
b348b9fd 1967 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
e03c0cc6
ILT
1968 continue;
1969 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
1970 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
1971 continue;
ac57e5ad
SS
1972 /* The following instructions load $at or $t0 with an immediate
1973 value in preparation for a stack adjustment via
1974 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
1975 a local variable, so we accept them only before a stack adjustment
1976 instruction was seen. */
1977 else if (!seen_sp_adjust)
1978 {
b348b9fd
MA
1979 if (high_word == 0x3c01 || /* lui $at,n */
1980 high_word == 0x3c08) /* lui $t0,n */
ac57e5ad 1981 {
28444bf3 1982 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
ac57e5ad
SS
1983 continue;
1984 }
b348b9fd
MA
1985 else if (high_word == 0x3421 || /* ori $at,$at,n */
1986 high_word == 0x3508 || /* ori $t0,$t0,n */
1987 high_word == 0x3401 || /* ori $at,$zero,n */
1988 high_word == 0x3408) /* ori $t0,$zero,n */
ac57e5ad 1989 {
28444bf3 1990 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
ac57e5ad
SS
1991 continue;
1992 }
1993 else
1994 break;
1995 }
0b0d6c3f 1996 else
ac57e5ad 1997 break;
d747e0af 1998 }
e157305c 1999
ac57e5ad
SS
2000 /* In a frameless function, we might have incorrectly
2001 skipped some load immediate instructions. Undo the skipping
2002 if the load immediate was not followed by a stack adjustment. */
2003 if (load_immediate_bytes && !seen_sp_adjust)
20fa0902
MA
2004 pc -= load_immediate_bytes;
2005 return pc;
2006}
2007
2008/* Skip the PC past function prologue instructions (16-bit version).
2009 This is a helper function for mips_skip_prologue. */
2010
2011static CORE_ADDR
2012mips16_skip_prologue (pc, lenient)
2013 CORE_ADDR pc; /* starting PC to search from */
2014 int lenient;
2015{
2016 CORE_ADDR end_pc;
c81a76b3
MA
2017 int extend_bytes = 0;
2018 int prev_extend_bytes;
20fa0902
MA
2019
2020 /* Table of instructions likely to be found in a function prologue. */
2021 static struct
2022 {
2023 unsigned short inst;
2024 unsigned short mask;
2025 } table[] =
2026 {
2027 { 0x6300, 0xff00 }, /* addiu $sp,offset */
2028 { 0xfb00, 0xff00 }, /* daddiu $sp,offset */
2029 { 0xd000, 0xf800 }, /* sw reg,n($sp) */
2030 { 0xf900, 0xff00 }, /* sd reg,n($sp) */
2031 { 0x6200, 0xff00 }, /* sw $ra,n($sp) */
2032 { 0xfa00, 0xff00 }, /* sd $ra,n($sp) */
2033 { 0x673d, 0xffff }, /* move $s1,sp */
2034 { 0xd980, 0xff80 }, /* sw $a0-$a3,n($s1) */
2035 { 0x6704, 0xff1c }, /* move reg,$a0-$a3 */
2036 { 0xe809, 0xf81f }, /* entry pseudo-op */
32dab603 2037 { 0x0100, 0xff00 }, /* addiu $s1,$sp,n */
20fa0902
MA
2038 { 0, 0 } /* end of table marker */
2039 };
2040
2041 /* Skip the typical prologue instructions. These are the stack adjustment
2042 instruction and the instructions that save registers on the stack
2043 or in the gcc frame. */
2044 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
2045 {
20fa0902 2046 unsigned short inst;
20fa0902
MA
2047 int i;
2048
c81a76b3 2049 inst = mips_fetch_instruction (pc);
20fa0902
MA
2050
2051 /* Normally we ignore an extend instruction. However, if it is
2052 not followed by a valid prologue instruction, we must adjust
2053 the pc back over the extend so that it won't be considered
2054 part of the prologue. */
2055 if ((inst & 0xf800) == 0xf000) /* extend */
2056 {
2057 extend_bytes = MIPS16_INSTLEN;
2058 continue;
2059 }
2060 prev_extend_bytes = extend_bytes;
2061 extend_bytes = 0;
2062
2063 /* Check for other valid prologue instructions besides extend. */
2064 for (i = 0; table[i].mask != 0; i++)
2065 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
2066 break;
2067 if (table[i].mask != 0) /* it was in table? */
32dab603 2068 continue; /* ignore it */
20fa0902
MA
2069 else /* non-prologue */
2070 {
2071 /* Return the current pc, adjusted backwards by 2 if
2072 the previous instruction was an extend. */
2073 return pc - prev_extend_bytes;
2074 }
2075 }
32dab603 2076 return pc;
20fa0902
MA
2077}
2078
2079/* To skip prologues, I use this predicate. Returns either PC itself
2080 if the code at PC does not look like a function prologue; otherwise
2081 returns an address that (if we're lucky) follows the prologue. If
2082 LENIENT, then we must skip everything which is involved in setting
2083 up the frame (it's OK to skip more, just so long as we don't skip
2084 anything which might clobber the registers which are being saved.
2085 We must skip more in the case where part of the prologue is in the
2086 delay slot of a non-prologue instruction). */
2087
2088CORE_ADDR
2089mips_skip_prologue (pc, lenient)
2090 CORE_ADDR pc;
2091 int lenient;
2092{
2093 /* See if we can determine the end of the prologue via the symbol table.
2094 If so, then return either PC, or the PC after the prologue, whichever
2095 is greater. */
2096
2097 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
2098
2099 if (post_prologue_pc != 0)
2100 return max (pc, post_prologue_pc);
2101
2102 /* Can't determine prologue from the symbol table, need to examine
2103 instructions. */
2104
899c4021 2105 if (pc_is_mips16 (pc))
20fa0902
MA
2106 return mips16_skip_prologue (pc, lenient);
2107 else
2108 return mips32_skip_prologue (pc, lenient);
bd5635a1 2109}
c2a0f1cb 2110
002a422b 2111#if 0
20fa0902 2112/* The lenient prologue stuff should be superseded by the code in
002a422b
JK
2113 init_extra_frame_info which looks to see whether the stores mentioned
2114 in the proc_desc have actually taken place. */
2115
ee5fb959
JK
2116/* Is address PC in the prologue (loosely defined) for function at
2117 STARTADDR? */
2118
2119static int
2120mips_in_lenient_prologue (startaddr, pc)
2121 CORE_ADDR startaddr;
2122 CORE_ADDR pc;
2123{
2124 CORE_ADDR end_prologue = mips_skip_prologue (startaddr, 1);
2125 return pc >= startaddr && pc < end_prologue;
2126}
002a422b 2127#endif
ee5fb959 2128
ac8cf67d
PS
2129/* Given a return value in `regbuf' with a type `valtype',
2130 extract and copy its value into `valbuf'. */
2131void
2132mips_extract_return_value (valtype, regbuf, valbuf)
2133 struct type *valtype;
2134 char regbuf[REGISTER_BYTES];
2135 char *valbuf;
2136{
2137 int regnum;
92a6d600 2138 int offset = 0;
c81a76b3 2139 int len = TYPE_LENGTH (valtype);
ac8cf67d 2140
e4dbd248
PS
2141 regnum = 2;
2142 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
0af60e03 2143 && (mips_fpu == MIPS_FPU_DOUBLE
912e805f 2144 || (mips_fpu == MIPS_FPU_SINGLE && len <= MIPS_FPU_SINGLE_REGSIZE)))
f781fe93 2145 regnum = FP0_REGNUM;
ac8cf67d 2146
0af60e03
MS
2147 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2148 { /* "un-left-justify" the value from the register */
87910097 2149 if (len < REGISTER_RAW_SIZE (regnum))
0af60e03
MS
2150 offset = REGISTER_RAW_SIZE (regnum) - len;
2151 if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */
2152 len < REGISTER_RAW_SIZE (regnum) * 2 &&
2153 (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
2154 TYPE_CODE (valtype) == TYPE_CODE_UNION))
2155 offset = 2 * REGISTER_RAW_SIZE (regnum) - len;
2156 }
c81a76b3 2157 memcpy (valbuf, regbuf + REGISTER_BYTE (regnum) + offset, len);
f781fe93 2158 REGISTER_CONVERT_TO_TYPE (regnum, valtype, valbuf);
ac8cf67d
PS
2159}
2160
2161/* Given a return value in `regbuf' with a type `valtype',
2162 write it's value into the appropriate register. */
2163void
2164mips_store_return_value (valtype, valbuf)
2165 struct type *valtype;
2166 char *valbuf;
2167{
2168 int regnum;
0af60e03
MS
2169 int offset = 0;
2170 int len = TYPE_LENGTH (valtype);
ac8cf67d
PS
2171 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2172
e4dbd248
PS
2173 regnum = 2;
2174 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
0af60e03
MS
2175 && (mips_fpu == MIPS_FPU_DOUBLE
2176 || (mips_fpu == MIPS_FPU_SINGLE && len <= MIPS_REGSIZE)))
e4dbd248
PS
2177 regnum = FP0_REGNUM;
2178
0af60e03
MS
2179 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2180 { /* "left-justify" the value in the register */
2181 if (len < REGISTER_RAW_SIZE (regnum))
2182 offset = REGISTER_RAW_SIZE (regnum) - len;
2183 if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */
2184 len < REGISTER_RAW_SIZE (regnum) * 2 &&
2185 (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
2186 TYPE_CODE (valtype) == TYPE_CODE_UNION))
2187 offset = 2 * REGISTER_RAW_SIZE (regnum) - len;
2188 }
2189 memcpy(raw_buffer + offset, valbuf, len);
ac8cf67d 2190 REGISTER_CONVERT_FROM_TYPE(regnum, valtype, raw_buffer);
0af60e03
MS
2191 write_register_bytes(REGISTER_BYTE (regnum), raw_buffer,
2192 len > REGISTER_RAW_SIZE (regnum) ?
2193 len : REGISTER_RAW_SIZE (regnum));
ac8cf67d
PS
2194}
2195
e03c0cc6
ILT
2196/* Exported procedure: Is PC in the signal trampoline code */
2197
2198int
2199in_sigtramp (pc, ignore)
2200 CORE_ADDR pc;
2201 char *ignore; /* function name */
2202{
2203 if (sigtramp_address == 0)
2204 fixup_sigtramp ();
2205 return (pc >= sigtramp_address && pc < sigtramp_end);
2206}
2207
e4dbd248
PS
2208/* Command to set FPU type. mips_fpu_string will have been set to the
2209 user's argument. Set mips_fpu based on mips_fpu_string, and then
2210 canonicalize mips_fpu_string. */
2211
2212/*ARGSUSED*/
2213static void
2214mips_set_fpu_command (args, from_tty, c)
2215 char *args;
2216 int from_tty;
2217 struct cmd_list_element *c;
2218{
2219 char *err = NULL;
2220
2221 if (mips_fpu_string == NULL || *mips_fpu_string == '\0')
2222 mips_fpu = MIPS_FPU_DOUBLE;
2223 else if (strcasecmp (mips_fpu_string, "double") == 0
2224 || strcasecmp (mips_fpu_string, "on") == 0
2225 || strcasecmp (mips_fpu_string, "1") == 0
2226 || strcasecmp (mips_fpu_string, "yes") == 0)
2227 mips_fpu = MIPS_FPU_DOUBLE;
2228 else if (strcasecmp (mips_fpu_string, "none") == 0
2229 || strcasecmp (mips_fpu_string, "off") == 0
2230 || strcasecmp (mips_fpu_string, "0") == 0
2231 || strcasecmp (mips_fpu_string, "no") == 0)
2232 mips_fpu = MIPS_FPU_NONE;
2233 else if (strcasecmp (mips_fpu_string, "single") == 0)
2234 mips_fpu = MIPS_FPU_SINGLE;
2235 else
2236 err = strsave (mips_fpu_string);
2237
2238 if (mips_fpu_string != NULL)
2239 free (mips_fpu_string);
2240
2241 switch (mips_fpu)
2242 {
2243 case MIPS_FPU_DOUBLE:
2244 mips_fpu_string = strsave ("double");
2245 break;
2246 case MIPS_FPU_SINGLE:
2247 mips_fpu_string = strsave ("single");
2248 break;
2249 case MIPS_FPU_NONE:
2250 mips_fpu_string = strsave ("none");
2251 break;
2252 }
2253
2254 if (err != NULL)
2255 {
2256 struct cleanup *cleanups = make_cleanup (free, err);
2257 error ("Unknown FPU type `%s'. Use `double', `none', or `single'.",
2258 err);
2259 do_cleanups (cleanups);
2260 }
2261}
2262
2263static void
2264mips_show_fpu_command (args, from_tty, c)
2265 char *args;
2266 int from_tty;
2267 struct cmd_list_element *c;
2268{
2269}
2270
9f9f94aa
SS
2271/* Command to set the processor type. */
2272
2273void
2274mips_set_processor_type_command (args, from_tty)
2275 char *args;
2276 int from_tty;
2277{
2278 int i;
2279
2280 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
2281 {
2282 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
2283 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
2284 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
2285
2286 /* Restore the value. */
2287 tmp_mips_processor_type = strsave (mips_processor_type);
2288
2289 return;
2290 }
2291
2292 if (!mips_set_processor_type (tmp_mips_processor_type))
2293 {
2294 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
2295 /* Restore its value. */
2296 tmp_mips_processor_type = strsave (mips_processor_type);
2297 }
2298}
2299
2300static void
2301mips_show_processor_type_command (args, from_tty)
2302 char *args;
2303 int from_tty;
2304{
2305}
2306
2307/* Modify the actual processor type. */
2308
2309int
2310mips_set_processor_type (str)
2311 char *str;
2312{
2313 int i, j;
2314
2315 if (str == NULL)
1d9489c1 2316 return 0;
9f9f94aa
SS
2317
2318 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
2319 {
2320 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
2321 {
2322 mips_processor_type = str;
2323
2324 for (j = 0; j < NUM_REGS; ++j)
2325 reg_names[j] = mips_processor_type_table[i].regnames[j];
2326
2327 return 1;
2328
2329 /* FIXME tweak fpu flag too */
2330 }
2331 }
2332
2333 return 0;
2334}
2335
2336/* Attempt to identify the particular processor model by reading the
2337 processor id. */
2338
2339char *
2340mips_read_processor_type ()
2341{
28444bf3 2342 CORE_ADDR prid;
9f9f94aa
SS
2343
2344 prid = read_register (PRID_REGNUM);
2345
80e0e92a 2346 if ((prid & ~0xf) == 0x700)
9f9f94aa
SS
2347 return savestring ("r3041", strlen("r3041"));
2348
2349 return NULL;
2350}
427fec5d
JK
2351
2352/* Just like reinit_frame_cache, but with the right arguments to be
2353 callable as an sfunc. */
9f9f94aa 2354
427fec5d
JK
2355static void
2356reinit_frame_cache_sfunc (args, from_tty, c)
2357 char *args;
2358 int from_tty;
2359 struct cmd_list_element *c;
2360{
2361 reinit_frame_cache ();
2362}
c2a0f1cb 2363
912e805f 2364int
18b46e7c
SS
2365gdb_print_insn_mips (memaddr, info)
2366 bfd_vma memaddr;
2367 disassemble_info *info;
2368{
f9f8c14b
MA
2369 mips_extra_func_info_t proc_desc;
2370
2371 /* Search for the function containing this address. Set the low bit
2372 of the address when searching, in case we were given an even address
2373 that is the start of a 16-bit function. If we didn't do this,
2374 the search would fail because the symbol table says the function
2375 starts at an odd address, i.e. 1 byte past the given address. */
c1fc0935
MA
2376 memaddr = ADDR_BITS_REMOVE (memaddr);
2377 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
f9f8c14b
MA
2378
2379 /* Make an attempt to determine if this is a 16-bit function. If
2380 the procedure descriptor exists and the address therein is odd,
2381 it's definitely a 16-bit function. Otherwise, we have to just
2382 guess that if the address passed in is odd, it's 16-bits. */
2383 if (proc_desc)
899c4021 2384 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ? 16 : 0;
f9f8c14b 2385 else
899c4021 2386 info->mach = pc_is_mips16 (memaddr) ? 16 : 0;
f9f8c14b 2387
c1fc0935 2388 /* Round down the instruction address to the appropriate boundary. */
f9f8c14b
MA
2389 memaddr &= (info->mach == 16 ? ~1 : ~3);
2390
2391 /* Call the appropriate disassembler based on the target endian-ness. */
18b46e7c
SS
2392 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2393 return print_insn_big_mips (memaddr, info);
2394 else
2395 return print_insn_little_mips (memaddr, info);
2396}
2397
f9f8c14b
MA
2398/* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
2399 counter value to determine whether a 16- or 32-bit breakpoint should be
2400 used. It returns a pointer to a string of bytes that encode a breakpoint
2401 instruction, stores the length of the string to *lenptr, and adjusts pc
2402 (if necessary) to point to the actual memory location where the
2403 breakpoint should be inserted. */
2404
2405unsigned char *mips_breakpoint_from_pc (pcptr, lenptr)
2406 CORE_ADDR *pcptr;
2407 int *lenptr;
2408{
2409 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2410 {
899c4021 2411 if (pc_is_mips16 (*pcptr))
f9f8c14b
MA
2412 {
2413 static char mips16_big_breakpoint[] = MIPS16_BIG_BREAKPOINT;
c1fc0935 2414 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
f9f8c14b
MA
2415 *lenptr = sizeof(mips16_big_breakpoint);
2416 return mips16_big_breakpoint;
2417 }
2418 else
2419 {
2420 static char big_breakpoint[] = BIG_BREAKPOINT;
f781fe93
MA
2421 static char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
2422 static char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
2423
f9f8c14b 2424 *lenptr = sizeof(big_breakpoint);
f781fe93
MA
2425
2426 if (strcmp (target_shortname, "mips") == 0)
2427 return idt_big_breakpoint;
2428 else if (strcmp (target_shortname, "ddb") == 0
2429 || strcmp (target_shortname, "pmon") == 0
2430 || strcmp (target_shortname, "lsi") == 0)
2431 return pmon_big_breakpoint;
2432 else
2433 return big_breakpoint;
f9f8c14b
MA
2434 }
2435 }
2436 else
2437 {
899c4021 2438 if (pc_is_mips16 (*pcptr))
f9f8c14b
MA
2439 {
2440 static char mips16_little_breakpoint[] = MIPS16_LITTLE_BREAKPOINT;
c1fc0935 2441 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
f9f8c14b
MA
2442 *lenptr = sizeof(mips16_little_breakpoint);
2443 return mips16_little_breakpoint;
2444 }
2445 else
2446 {
2447 static char little_breakpoint[] = LITTLE_BREAKPOINT;
f781fe93
MA
2448 static char pmon_little_breakpoint[] = PMON_LITTLE_BREAKPOINT;
2449 static char idt_little_breakpoint[] = IDT_LITTLE_BREAKPOINT;
2450
f9f8c14b 2451 *lenptr = sizeof(little_breakpoint);
f781fe93
MA
2452
2453 if (strcmp (target_shortname, "mips") == 0)
2454 return idt_little_breakpoint;
2455 else if (strcmp (target_shortname, "ddb") == 0
2456 || strcmp (target_shortname, "pmon") == 0
2457 || strcmp (target_shortname, "lsi") == 0)
2458 return pmon_little_breakpoint;
2459 else
2460 return little_breakpoint;
f9f8c14b
MA
2461 }
2462 }
2463}
2464
2465/* Test whether the PC points to the return instruction at the
2466 end of a function. This implements the ABOUT_TO_RETURN macro. */
2467
2468int
2469mips_about_to_return (pc)
2470 CORE_ADDR pc;
2471{
899c4021 2472 if (pc_is_mips16 (pc))
f9f8c14b
MA
2473 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2474 generates a "jr $ra"; other times it generates code to load
2475 the return address from the stack to an accessible register (such
2476 as $a3), then a "jr" using that register. This second case
2477 is almost impossible to distinguish from an indirect jump
2478 used for switch statements, so we don't even try. */
c81a76b3 2479 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
f9f8c14b 2480 else
c81a76b3 2481 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
f9f8c14b
MA
2482}
2483
2484
f781fe93
MA
2485/* If PC is in a mips16 call or return stub, return the address of the target
2486 PC, which is either the callee or the caller. There are several
2487 cases which must be handled:
2488
2489 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
2490 target PC is in $31 ($ra).
2491 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
2492 and the target PC is in $2.
2493 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
2494 before the jal instruction, this is effectively a call stub
2495 and the the target PC is in $2. Otherwise this is effectively
2496 a return stub and the target PC is in $18.
2497
2498 See the source code for the stubs in gcc/config/mips/mips16.S for
2499 gory details.
2500
2501 This function implements the SKIP_TRAMPOLINE_CODE macro.
2502*/
2503
2504CORE_ADDR
2505mips_skip_stub (pc)
2506 CORE_ADDR pc;
2507{
2508 char *name;
2509 CORE_ADDR start_addr;
2510
2511 /* Find the starting address and name of the function containing the PC. */
2512 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
2513 return 0;
2514
2515 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
2516 target PC is in $31 ($ra). */
2517 if (strcmp (name, "__mips16_ret_sf") == 0
2518 || strcmp (name, "__mips16_ret_df") == 0)
2519 return read_register (RA_REGNUM);
2520
2521 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
2522 {
2523 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
2524 and the target PC is in $2. */
2525 if (name[19] >= '0' && name[19] <= '9')
2526 return read_register (2);
2527
2528 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
2529 before the jal instruction, this is effectively a call stub
2530 and the the target PC is in $2. Otherwise this is effectively
2531 a return stub and the target PC is in $18. */
2532 else if (name[19] == 's' || name[19] == 'd')
2533 {
2534 if (pc == start_addr)
2535 {
2536 /* Check if the target of the stub is a compiler-generated
2537 stub. Such a stub for a function bar might have a name
2538 like __fn_stub_bar, and might look like this:
2539 mfc1 $4,$f13
2540 mfc1 $5,$f12
2541 mfc1 $6,$f15
2542 mfc1 $7,$f14
2543 la $1,bar (becomes a lui/addiu pair)
2544 jr $1
2545 So scan down to the lui/addi and extract the target
2546 address from those two instructions. */
2547
2548 CORE_ADDR target_pc = read_register (2);
2549 t_inst inst;
2550 int i;
2551
2552 /* See if the name of the target function is __fn_stub_*. */
2553 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
2554 return target_pc;
2555 if (strncmp (name, "__fn_stub_", 10) != 0
2556 && strcmp (name, "etext") != 0
2557 && strcmp (name, "_etext") != 0)
2558 return target_pc;
2559
2560 /* Scan through this _fn_stub_ code for the lui/addiu pair.
2561 The limit on the search is arbitrarily set to 20
2562 instructions. FIXME. */
2563 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
2564 {
2565 inst = mips_fetch_instruction (target_pc);
2566 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
2567 pc = (inst << 16) & 0xffff0000; /* high word */
2568 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
2569 return pc | (inst & 0xffff); /* low word */
2570 }
2571
2572 /* Couldn't find the lui/addui pair, so return stub address. */
2573 return target_pc;
2574 }
2575 else
2576 /* This is the 'return' part of a call stub. The return
2577 address is in $r18. */
2578 return read_register (18);
2579 }
2580 }
2581 return 0; /* not a stub */
2582}
2583
2584
2585/* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
2586 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
2587
2588int
2589mips_in_call_stub (pc, name)
2590 CORE_ADDR pc;
2591 char *name;
2592{
2593 CORE_ADDR start_addr;
2594
2595 /* Find the starting address of the function containing the PC. If the
2596 caller didn't give us a name, look it up at the same time. */
2597 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
2598 return 0;
2599
2600 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
2601 {
2602 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
2603 if (name[19] >= '0' && name[19] <= '9')
2604 return 1;
2605 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
2606 before the jal instruction, this is effectively a call stub. */
2607 else if (name[19] == 's' || name[19] == 'd')
2608 return pc == start_addr;
2609 }
2610
2611 return 0; /* not a stub */
2612}
2613
2614
2615/* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
2616 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
2617
2618int
2619mips_in_return_stub (pc, name)
2620 CORE_ADDR pc;
2621 char *name;
2622{
2623 CORE_ADDR start_addr;
2624
2625 /* Find the starting address of the function containing the PC. */
2626 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
2627 return 0;
2628
2629 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
2630 if (strcmp (name, "__mips16_ret_sf") == 0
2631 || strcmp (name, "__mips16_ret_df") == 0)
2632 return 1;
2633
2634 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
2635 i.e. after the jal instruction, this is effectively a return stub. */
2636 if (strncmp (name, "__mips16_call_stub_", 19) == 0
2637 && (name[19] == 's' || name[19] == 'd')
2638 && pc != start_addr)
2639 return 1;
2640
2641 return 0; /* not a stub */
2642}
2643
2644
2645/* Return non-zero if the PC is in a library helper function that should
2646 be ignored. This implements the IGNORE_HELPER_CALL macro. */
2647
2648int
2649mips_ignore_helper (pc)
2650 CORE_ADDR pc;
2651{
2652 char *name;
2653
2654 /* Find the starting address and name of the function containing the PC. */
2655 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
2656 return 0;
2657
2658 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
2659 that we want to ignore. */
2660 return (strcmp (name, "__mips16_ret_sf") == 0
2661 || strcmp (name, "__mips16_ret_df") == 0);
2662}
2663
2664
c2a0f1cb
ILT
2665void
2666_initialize_mips_tdep ()
2667{
427fec5d
JK
2668 struct cmd_list_element *c;
2669
912e805f
AC
2670 if (!tm_print_insn) /* Someone may have already set it */
2671 tm_print_insn = gdb_print_insn_mips;
18b46e7c 2672
427fec5d
JK
2673 /* Let the user turn off floating point and set the fence post for
2674 heuristic_proc_start. */
2675
e4dbd248
PS
2676 c = add_set_cmd ("mipsfpu", class_support, var_string_noescape,
2677 (char *) &mips_fpu_string,
2678 "Set use of floating point coprocessor.\n\
2679Set to `none' to avoid using floating point instructions when calling\n\
2680functions or dealing with return values. Set to `single' to use only\n\
2681single precision floating point as on the R4650. Set to `double' for\n\
2682normal floating point support.",
2683 &setlist);
2684 c->function.sfunc = mips_set_fpu_command;
2685 c = add_show_from_set (c, &showlist);
2686 c->function.sfunc = mips_show_fpu_command;
2687
91ee2779 2688#ifndef MIPS_DEFAULT_FPU_TYPE
e4dbd248
PS
2689 mips_fpu = MIPS_FPU_DOUBLE;
2690 mips_fpu_string = strsave ("double");
91ee2779
JL
2691#else
2692 mips_fpu = MIPS_DEFAULT_FPU_TYPE;
2693 switch (mips_fpu)
2694 {
2695 case MIPS_FPU_DOUBLE: mips_fpu_string = strsave ("double"); break;
2696 case MIPS_FPU_SINGLE: mips_fpu_string = strsave ("single"); break;
2697 case MIPS_FPU_NONE: mips_fpu_string = strsave ("none"); break;
2698 }
2699#endif
3127785a 2700
9f9f94aa
SS
2701 c = add_set_cmd ("processor", class_support, var_string_noescape,
2702 (char *) &tmp_mips_processor_type,
2703 "Set the type of MIPS processor in use.\n\
2704Set this to be able to access processor-type-specific registers.\n\
2705",
2706 &setlist);
2707 c->function.cfunc = mips_set_processor_type_command;
2708 c = add_show_from_set (c, &showlist);
2709 c->function.cfunc = mips_show_processor_type_command;
2710
2711 tmp_mips_processor_type = strsave (DEFAULT_MIPS_TYPE);
2712 mips_set_processor_type_command (strsave (DEFAULT_MIPS_TYPE), 0);
2713
bdef72d2
JK
2714 /* We really would like to have both "0" and "unlimited" work, but
2715 command.c doesn't deal with that. So make it a var_zinteger
2716 because the user can always use "999999" or some such for unlimited. */
2717 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
427fec5d
JK
2718 (char *) &heuristic_fence_post,
2719 "\
23d35572
JK
2720Set the distance searched for the start of a function.\n\
2721If you are debugging a stripped executable, GDB needs to search through the\n\
2722program for the start of a function. This command sets the distance of the\n\
2723search. The only need to set it is when debugging a stripped executable.",
427fec5d
JK
2724 &setlist);
2725 /* We need to throw away the frame cache when we set this, since it
2726 might change our ability to get backtraces. */
2727 c->function.sfunc = reinit_frame_cache_sfunc;
2728 add_show_from_set (c, &showlist);
c2a0f1cb 2729}
This page took 0.453662 seconds and 4 git commands to generate.