* mips-tdep.c (mips16_decode_reg_save): Distinguish between
[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
DP
43
44/* FIXME! this code assumes 4-byte instructions. */
96431497 45#define MIPS_INSTLEN 4 /* Length of an instruction */
20fa0902 46#define MIPS16_INSTLEN 2 /* Length of an instruction on MIPS16*/
96431497
MA
47#define MIPS_NUMREGS 32 /* Number of integer or float registers */
48typedef unsigned long t_inst; /* Integer big enough to hold an instruction */
28444bf3 49
002a422b 50#if 0
ee5fb959 51static int mips_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
002a422b 52#endif
ee5fb959 53
28444bf3
DP
54static int gdb_print_insn_mips PARAMS ((bfd_vma, disassemble_info *));
55
f2bf454e
FF
56static void mips_print_register PARAMS ((int, int));
57
58static mips_extra_func_info_t
59heuristic_proc_desc PARAMS ((CORE_ADDR, CORE_ADDR, struct frame_info *));
60
61static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
62
28444bf3 63static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
f2bf454e 64
e4dbd248
PS
65static void mips_set_fpu_command PARAMS ((char *, int,
66 struct cmd_list_element *));
67
68static void mips_show_fpu_command PARAMS ((char *, int,
69 struct cmd_list_element *));
70
9f9f94aa
SS
71void mips_set_processor_type_command PARAMS ((char *, int));
72
1d9489c1
JK
73int mips_set_processor_type PARAMS ((char *));
74
75static void mips_show_processor_type_command PARAMS ((char *, int));
76
9f9f94aa
SS
77static void reinit_frame_cache_sfunc PARAMS ((char *, int,
78 struct cmd_list_element *));
79
f2bf454e
FF
80static mips_extra_func_info_t
81 find_proc_desc PARAMS ((CORE_ADDR pc, struct frame_info *next_frame));
82
83static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
84 mips_extra_func_info_t proc_desc));
85
9f9f94aa
SS
86/* This value is the model of MIPS in use. It is derived from the value
87 of the PrID register. */
88
89char *mips_processor_type;
90
91char *tmp_mips_processor_type;
92
c2a0f1cb
ILT
93/* Some MIPS boards don't support floating point, so we permit the
94 user to turn it off. */
9f9f94aa 95
e4dbd248
PS
96enum mips_fpu_type mips_fpu;
97
98static char *mips_fpu_string;
c2a0f1cb 99
9f9f94aa
SS
100/* A set of original names, to be used when restoring back to generic
101 registers from a specific set. */
102
103char *mips_generic_reg_names[] = REGISTER_NAMES;
104
105/* Names of IDT R3041 registers. */
106
107char *mips_r3041_reg_names[] = {
108 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
109 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
110 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
111 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
112 "sr", "lo", "hi", "bad", "cause","pc",
113 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
114 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
115 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
116 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
117 "fsr", "fir", "fp", "",
118 "", "", "bus", "ccfg", "", "", "", "",
119 "", "", "port", "cmp", "", "", "epc", "prid",
120};
121
122/* Names of IDT R3051 registers. */
123
124char *mips_r3051_reg_names[] = {
125 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
126 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
127 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
128 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
129 "sr", "lo", "hi", "bad", "cause","pc",
130 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
131 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
132 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
133 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
134 "fsr", "fir", "fp", "",
135 "inx", "rand", "elo", "", "ctxt", "", "", "",
136 "", "", "ehi", "", "", "", "epc", "prid",
137};
138
139/* Names of IDT R3081 registers. */
140
141char *mips_r3081_reg_names[] = {
142 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
143 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
144 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
145 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
146 "sr", "lo", "hi", "bad", "cause","pc",
147 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
148 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
149 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
150 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
151 "fsr", "fir", "fp", "",
152 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
153 "", "", "ehi", "", "", "", "epc", "prid",
154};
155
e4dbd248
PS
156/* Names of LSI 33k registers. */
157
158char *mips_lsi33k_reg_names[] = {
159 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
160 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
161 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
162 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
163 "epc", "hi", "lo", "sr", "cause","badvaddr",
164 "dcic", "bpc", "bda", "", "", "", "", "",
165 "", "", "", "", "", "", "", "",
166 "", "", "", "", "", "", "", "",
167 "", "", "", "", "", "", "", "",
168 "", "", "", "",
169 "", "", "", "", "", "", "", "",
170 "", "", "", "", "", "", "", "",
171};
172
9f9f94aa
SS
173struct {
174 char *name;
175 char **regnames;
176} mips_processor_type_table[] = {
177 { "generic", mips_generic_reg_names },
178 { "r3041", mips_r3041_reg_names },
179 { "r3051", mips_r3051_reg_names },
180 { "r3071", mips_r3081_reg_names },
181 { "r3081", mips_r3081_reg_names },
e4dbd248 182 { "lsi33k", mips_lsi33k_reg_names },
9f9f94aa
SS
183 { NULL, NULL }
184};
185
f9f8c14b
MA
186/* Table to translate MIPS16 register field to actual register number. */
187static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
188
3127785a
RP
189/* Heuristic_proc_start may hunt through the text section for a long
190 time across a 2400 baud serial line. Allows the user to limit this
191 search. */
9f9f94aa 192
3127785a
RP
193static unsigned int heuristic_fence_post = 0;
194
0f552c5f 195#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
28444bf3 196#define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
0f552c5f
JG
197#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
198#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
199#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
200#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
201#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
202#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
203#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
204#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
bd5635a1 205#define _PROC_MAGIC_ 0x0F0F0F0F
0f552c5f
JG
206#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
207#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
bd5635a1
RP
208
209struct linked_proc_info
210{
211 struct mips_extra_func_info info;
212 struct linked_proc_info *next;
dac4929a 213} *linked_proc_desc_table = NULL;
bd5635a1 214
f2bf454e
FF
215
216/* This returns the PC of the first inst after the prologue. If we can't
217 find the prologue, then return 0. */
218
219static CORE_ADDR
220after_prologue (pc, proc_desc)
221 CORE_ADDR pc;
222 mips_extra_func_info_t proc_desc;
223{
224 struct symtab_and_line sal;
225 CORE_ADDR func_addr, func_end;
226
227 if (!proc_desc)
228 proc_desc = find_proc_desc (pc, NULL);
229
230 if (proc_desc)
231 {
232 /* If function is frameless, then we need to do it the hard way. I
233 strongly suspect that frameless always means prologueless... */
234 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
235 && PROC_FRAME_OFFSET (proc_desc) == 0)
236 return 0;
237 }
238
239 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
240 return 0; /* Unknown */
241
242 sal = find_pc_line (func_addr, 0);
243
244 if (sal.end < func_end)
245 return sal.end;
246
247 /* The line after the prologue is after the end of the function. In this
248 case, tell the caller to find the prologue the hard way. */
249
250 return 0;
251}
252
f9f8c14b
MA
253/* Decode a MIPS32 instruction that saves a register in the stack, and
254 set the appropriate bit in the general register mask or float register mask
255 to indicate which register is saved. This is a helper function
256 for mips_find_saved_regs. */
257
258static void
259mips32_decode_reg_save (inst, gen_mask, float_mask)
260 t_inst inst;
261 unsigned long *gen_mask;
262 unsigned long *float_mask;
263{
264 int reg;
265
266 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
267 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
268 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
269 {
270 /* It might be possible to use the instruction to
271 find the offset, rather than the code below which
272 is based on things being in a certain order in the
273 frame, but figuring out what the instruction's offset
274 is relative to might be a little tricky. */
275 reg = (inst & 0x001f0000) >> 16;
276 *gen_mask |= (1 << reg);
277 }
278 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
279 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
280 || (inst & 0xffe00000) == 0xf7a00000)/* sdc1 freg,n($sp) */
281
282 {
283 reg = ((inst & 0x001f0000) >> 16);
284 *float_mask |= (1 << reg);
285 }
286}
287
288/* Decode a MIPS16 instruction that saves a register in the stack, and
289 set the appropriate bit in the general register or float register mask
290 to indicate which register is saved. This is a helper function
291 for mips_find_saved_regs. */
292
293static void
294mips16_decode_reg_save (inst, gen_mask)
295 t_inst inst;
296 unsigned long *gen_mask;
297{
b348b9fd 298 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
f9f8c14b 299 {
b348b9fd
MA
300 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
301 *gen_mask |= (1 << reg);
302 }
303 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
304 {
305 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
f9f8c14b
MA
306 *gen_mask |= (1 << reg);
307 }
308 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
309 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
310 *gen_mask |= (1 << 31);
311}
312
70126bf9
KH
313/* Guaranteed to set fci->saved_regs to some values (it never leaves it
314 NULL). */
315
316void
317mips_find_saved_regs (fci)
9f9f94aa 318 struct frame_info *fci;
70126bf9
KH
319{
320 int ireg;
321 CORE_ADDR reg_position;
322 /* r0 bit means kernel trap */
323 int kernel_trap;
324 /* What registers have been saved? Bitmasks. */
325 unsigned long gen_mask, float_mask;
326 mips_extra_func_info_t proc_desc;
327
328 fci->saved_regs = (struct frame_saved_regs *)
329 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
330 memset (fci->saved_regs, 0, sizeof (struct frame_saved_regs));
331
e4dbd248
PS
332 /* If it is the frame for sigtramp, the saved registers are located
333 in a sigcontext structure somewhere on the stack.
334 If the stack layout for sigtramp changes we might have to change these
335 constants and the companion fixup_sigtramp in mdebugread.c */
336#ifndef SIGFRAME_BASE
337/* To satisfy alignment restrictions, sigcontext is located 4 bytes
338 above the sigtramp frame. */
28444bf3
DP
339#define SIGFRAME_BASE MIPS_REGSIZE
340/* FIXME! Are these correct?? */
341#define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
342#define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
343#define SIGFRAME_FPREGSAVE_OFF \
344 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
e4dbd248
PS
345#endif
346#ifndef SIGFRAME_REG_SIZE
28444bf3
DP
347/* FIXME! Is this correct?? */
348#define SIGFRAME_REG_SIZE MIPS_REGSIZE
e4dbd248
PS
349#endif
350 if (fci->signal_handler_caller)
351 {
28444bf3 352 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
e4dbd248
PS
353 {
354 reg_position = fci->frame + SIGFRAME_REGSAVE_OFF
355 + ireg * SIGFRAME_REG_SIZE;
356 fci->saved_regs->regs[ireg] = reg_position;
357 }
28444bf3 358 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
e4dbd248
PS
359 {
360 reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF
361 + ireg * SIGFRAME_REG_SIZE;
362 fci->saved_regs->regs[FP0_REGNUM + ireg] = reg_position;
363 }
364 fci->saved_regs->regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF;
365 return;
366 }
367
70126bf9
KH
368 proc_desc = fci->proc_desc;
369 if (proc_desc == NULL)
370 /* I'm not sure how/whether this can happen. Normally when we can't
371 find a proc_desc, we "synthesize" one using heuristic_proc_desc
372 and set the saved_regs right away. */
373 return;
374
375 kernel_trap = PROC_REG_MASK(proc_desc) & 1;
376 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
377 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
378
f9f8c14b
MA
379 if (/* In any frame other than the innermost or a frame interrupted by
380 a signal, we assume that all registers have been saved.
381 This assumes that all register saves in a function happen before
382 the first function call. */
383 (fci->next == NULL || fci->next->signal_handler_caller)
70126bf9
KH
384
385 /* In a dummy frame we know exactly where things are saved. */
386 && !PROC_DESC_IS_DUMMY (proc_desc)
387
f2bf454e
FF
388 /* Don't bother unless we are inside a function prologue. Outside the
389 prologue, we know where everything is. */
390
391 && in_prologue (fci->pc, PROC_LOW_ADDR (proc_desc))
392
70126bf9
KH
393 /* Not sure exactly what kernel_trap means, but if it means
394 the kernel saves the registers without a prologue doing it,
395 we better not examine the prologue to see whether registers
396 have been saved yet. */
397 && !kernel_trap)
398 {
399 /* We need to figure out whether the registers that the proc_desc
400 claims are saved have been saved yet. */
401
402 CORE_ADDR addr;
403 int status;
28444bf3
DP
404 char buf[MIPS_INSTLEN];
405 t_inst inst;
f9f8c14b 406 int instlen;
70126bf9
KH
407
408 /* Bitmasks; set if we have found a save for the register. */
409 unsigned long gen_save_found = 0;
410 unsigned long float_save_found = 0;
411
f9f8c14b 412 if ((addr = PROC_LOW_ADDR (proc_desc)) & 1)
70126bf9 413 {
20fa0902 414 instlen = MIPS16_INSTLEN; /* MIPS16 */
f9f8c14b
MA
415 addr &= ~1;
416 }
417 else
20fa0902 418 instlen = MIPS_INSTLEN; /* MIPS32 */
f9f8c14b 419
20fa0902
MA
420 /* Scan through this function's instructions preceding the current
421 PC, and look for those that save registers. */
f9f8c14b
MA
422 while (addr < fci->pc)
423 {
424 status = read_memory_nobpt (addr, buf, instlen);
70126bf9
KH
425 if (status)
426 memory_error (status, addr);
f9f8c14b 427 inst = extract_unsigned_integer (buf, instlen);
20fa0902 428 if (instlen == MIPS16_INSTLEN)
f9f8c14b
MA
429 mips16_decode_reg_save (inst, &gen_save_found);
430 else
431 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
432 addr += instlen;
70126bf9
KH
433 }
434 gen_mask = gen_save_found;
435 float_mask = float_save_found;
436 }
437
438 /* Fill in the offsets for the registers which gen_mask says
439 were saved. */
440 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
28444bf3 441 for (ireg= MIPS_NUMREGS-1; gen_mask; --ireg, gen_mask <<= 1)
70126bf9
KH
442 if (gen_mask & 0x80000000)
443 {
444 fci->saved_regs->regs[ireg] = reg_position;
445 reg_position -= MIPS_REGSIZE;
446 }
447 /* Fill in the offsets for the registers which float_mask says
448 were saved. */
449 reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc);
450
451 /* The freg_offset points to where the first *double* register
452 is saved. So skip to the high-order word. */
28444bf3
DP
453 if (! GDB_TARGET_IS_MIPS64)
454 reg_position += 4;
455
20fa0902
MA
456 /* Fill in the offsets for the float registers which float_mask says
457 were saved. */
28444bf3 458 for (ireg = MIPS_NUMREGS-1; float_mask; --ireg, float_mask <<= 1)
70126bf9
KH
459 if (float_mask & 0x80000000)
460 {
461 fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
462 reg_position -= MIPS_REGSIZE;
463 }
464
465 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
466}
bd5635a1 467
28444bf3 468static CORE_ADDR
bd5635a1 469read_next_frame_reg(fi, regno)
9f9f94aa 470 struct frame_info *fi;
bd5635a1
RP
471 int regno;
472{
bd5635a1 473 for (; fi; fi = fi->next)
70126bf9 474 {
e4dbd248
PS
475 /* We have to get the saved sp from the sigcontext
476 if it is a signal handler frame. */
477 if (regno == SP_REGNUM && !fi->signal_handler_caller)
478 return fi->frame;
70126bf9
KH
479 else
480 {
481 if (fi->saved_regs == NULL)
482 mips_find_saved_regs (fi);
483 if (fi->saved_regs->regs[regno])
484 return read_memory_integer(fi->saved_regs->regs[regno], MIPS_REGSIZE);
485 }
486 }
487 return read_register (regno);
bd5635a1
RP
488}
489
96431497
MA
490/* mips_addr_bits_remove - remove useless address bits */
491
492CORE_ADDR
493mips_addr_bits_remove (addr)
494 CORE_ADDR addr;
495{
97e091b2
MA
496#if GDB_TARGET_IS_MIPS64
497 if ((addr >> 32 == (CORE_ADDR)0xffffffff)
96431497
MA
498 && (strcmp(target_shortname,"pmon")==0
499 || strcmp(target_shortname,"ddb")==0
500 || strcmp(target_shortname,"sim")==0))
501 {
502 /* This hack is a work-around for existing boards using PMON,
503 the simulator, and any other 64-bit targets that doesn't have
504 true 64-bit addressing. On these targets, the upper 32 bits
505 of addresses are ignored by the hardware. Thus, the PC or SP
506 are likely to have been sign extended to all 1s by instruction
507 sequences that load 32-bit addresses. For example, a typical
508 piece of code that loads an address is this:
509 lui $r2, <upper 16 bits>
510 ori $r2, <lower 16 bits>
511 But the lui sign-extends the value such that the upper 32 bits
512 may be all 1s. The workaround is simply to mask off these bits.
513 In the future, gcc may be changed to support true 64-bit
514 addressing, and this masking will have to be disabled. */
515 addr &= (CORE_ADDR)0xffffffff;
516 }
f9f8c14b
MA
517#else
518 /* Even when GDB is configured for some 32-bit targets (e.g. mips-elf),
519 BFD is configured to handle 64-bit targets, so CORE_ADDR is 64 bits.
520 So we still have to mask off useless bits from addresses. */
521 addr &= (CORE_ADDR)0xffffffff;
97e091b2 522#endif
96431497
MA
523
524 return addr;
525}
526
28444bf3 527CORE_ADDR
bd5635a1 528mips_frame_saved_pc(frame)
9f9f94aa 529 struct frame_info *frame;
bd5635a1 530{
28444bf3 531 CORE_ADDR saved_pc;
0f552c5f 532 mips_extra_func_info_t proc_desc = frame->proc_desc;
0434c1a0
PS
533 /* We have to get the saved pc from the sigcontext
534 if it is a signal handler frame. */
535 int pcreg = frame->signal_handler_caller ? PC_REGNUM
536 : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM);
0f552c5f 537
bd5635a1 538 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
28444bf3
DP
539 saved_pc = read_memory_integer(frame->frame - MIPS_REGSIZE, MIPS_REGSIZE);
540 else
541 saved_pc = read_next_frame_reg(frame, pcreg);
0f552c5f 542
96431497 543 return ADDR_BITS_REMOVE (saved_pc);
bd5635a1
RP
544}
545
546static struct mips_extra_func_info temp_proc_desc;
547static struct frame_saved_regs temp_saved_regs;
548
a8172eea
RP
549/* This fencepost looks highly suspicious to me. Removing it also
550 seems suspicious as it could affect remote debugging across serial
3127785a 551 lines. */
a8172eea 552
0f552c5f
JG
553static CORE_ADDR
554heuristic_proc_start(pc)
bd5635a1
RP
555 CORE_ADDR pc;
556{
bd5635a1 557 CORE_ADDR start_pc = pc;
3127785a 558 CORE_ADDR fence = start_pc - heuristic_fence_post;
20fa0902 559 int instlen;
b348b9fd 560 int seen_adjsp = 0;
0f552c5f
JG
561
562 if (start_pc == 0) return 0;
3127785a
RP
563
564 if (heuristic_fence_post == UINT_MAX
565 || fence < VM_MIN_ADDRESS)
566 fence = VM_MIN_ADDRESS;
0f552c5f 567
20fa0902
MA
568 instlen = pc & 1 ? MIPS16_INSTLEN : MIPS_INSTLEN;
569
bd5635a1 570 /* search back for previous return */
20fa0902 571 for (start_pc -= instlen; ; start_pc -= instlen)
a8172eea
RP
572 if (start_pc < fence)
573 {
3127785a
RP
574 /* It's not clear to me why we reach this point when
575 stop_soon_quietly, but with this test, at least we
576 don't print out warnings for every child forked (eg, on
577 decstation). 22apr93 rich@cygnus.com. */
578 if (!stop_soon_quietly)
579 {
23d35572
JK
580 static int blurb_printed = 0;
581
3127785a
RP
582 if (fence == VM_MIN_ADDRESS)
583 warning("Hit beginning of text section without finding");
584 else
585 warning("Hit heuristic-fence-post without finding");
586
96431497 587 warning("enclosing function for address 0x%s", paddr (pc));
23d35572
JK
588 if (!blurb_printed)
589 {
590 printf_filtered ("\
591This warning occurs if you are debugging a function without any symbols\n\
592(for example, in a stripped executable). In that case, you may wish to\n\
593increase the size of the search with the `set heuristic-fence-post' command.\n\
594\n\
595Otherwise, you told GDB there was a function where there isn't one, or\n\
596(more likely) you have encountered a bug in GDB.\n");
597 blurb_printed = 1;
598 }
3127785a
RP
599 }
600
a8172eea
RP
601 return 0;
602 }
20fa0902
MA
603 else if (start_pc & 1)
604 {
b348b9fd
MA
605 /* On MIPS16, any one of the following is likely to be the
606 start of a function:
607 entry
608 addiu sp,-n
609 daddiu sp,-n
610 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
611 unsigned short inst = read_memory_integer (start_pc & ~1, 2);
612 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
613 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
614 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
615 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
616 break;
617 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
618 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
619 seen_adjsp = 1;
620 else
621 seen_adjsp = 0;
20fa0902 622 }
bd5635a1 623 else if (ABOUT_TO_RETURN(start_pc))
20fa0902
MA
624 {
625 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
bd5635a1 626 break;
20fa0902 627 }
bd5635a1 628
bd5635a1
RP
629#if 0
630 /* skip nops (usually 1) 0 - is this */
28444bf3
DP
631 while (start_pc < pc && read_memory_integer (start_pc, MIPS_INSTLEN) == 0)
632 start_pc += MIPS_INSTLEN;
bd5635a1
RP
633#endif
634 return start_pc;
635}
636
b348b9fd
MA
637/* Fetch the immediate value from the current instruction.
638 If the previous instruction was an EXTEND, use it to extend
639 the upper bits of the immediate value. This is a helper function
640 for mips16_heuristic_proc_desc. */
641
642static int
643mips16_get_imm (prev_inst, inst, nbits, scale, is_signed)
644 unsigned short prev_inst; /* previous instruction */
645 unsigned short inst; /* current current instruction */
646 int nbits; /* number of bits in imm field */
647 int scale; /* scale factor to be applied to imm */
648 int is_signed; /* is the imm field signed? */
649{
650 int offset;
651
652 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
653 {
654 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e00);
655 if (offset & 0x8000) /* check for negative extend */
656 offset = 0 - (0x10000 - (offset & 0xffff));
657 return offset | (inst & 0x1f);
658 }
659 else
660 {
661 int max_imm = 1 << nbits;
662 int mask = max_imm - 1;
663 int sign_bit = max_imm >> 1;
664
665 offset = inst & mask;
666 if (is_signed && (offset & sign_bit))
667 offset = 0 - (max_imm - offset);
668 return offset * scale;
669 }
670}
671
672
673/* Fill in values in temp_proc_desc based on the MIPS16 instruction
674 stream from start_pc to limit_pc. */
675
676static void
677mips16_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
bd5635a1 678 CORE_ADDR start_pc, limit_pc;
9f9f94aa 679 struct frame_info *next_frame;
b348b9fd 680 CORE_ADDR sp;
bd5635a1 681{
b348b9fd
MA
682 CORE_ADDR cur_pc;
683 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
684 unsigned short prev_inst = 0; /* saved copy of previous instruction */
685 unsigned inst = 0; /* current instruction */
bd5635a1 686
b348b9fd 687 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
34df79fc 688
b348b9fd
MA
689 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
690 {
691 char buf[MIPS16_INSTLEN];
692 int status, reg, offset;
693
694 /* Save the previous instruction. If it's an EXTEND, we'll extract
695 the immediate offset extension from it in mips16_get_imm. */
696 prev_inst = inst;
697
698 /* Fetch the instruction. */
699 status = read_memory_nobpt (cur_pc & ~1, buf, MIPS16_INSTLEN);
700 if (status) memory_error (status, cur_pc);
701 inst = (unsigned short) extract_unsigned_integer (buf, MIPS16_INSTLEN);
702
703 if ((inst & 0xff00) == 0x6300 /* addiu sp */
704 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
705 {
706 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
707 if (offset < 0) /* negative stack adjustment? */
708 PROC_FRAME_OFFSET(&temp_proc_desc) -= offset;
709 else
710 /* Exit loop if a positive stack adjustment is found, which
711 usually means that the stack cleanup code in the function
712 epilogue is reached. */
713 break;
714 }
715 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
716 {
717 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
718 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
719 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
720 temp_saved_regs.regs[reg] = sp + offset;
721 }
722 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
723 {
724 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
725 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
726 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
727 temp_saved_regs.regs[reg] = sp + offset;
728 }
729 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
730 {
731 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
732 PROC_REG_MASK(&temp_proc_desc) |= (1 << 31);
733 temp_saved_regs.regs[31] = sp + offset;
97e091b2 734 }
b348b9fd
MA
735 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
736 {
737 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
738 PROC_REG_MASK(&temp_proc_desc) |= (1 << 31);
739 temp_saved_regs.regs[31] = sp + offset;
bd5635a1 740 }
b348b9fd
MA
741 else if (inst == 0x673d) /* move $s1, $sp */
742 {
743 frame_addr = read_next_frame_reg(next_frame, 30);
744 PROC_FRAME_REG (&temp_proc_desc) = 17;
97e091b2 745 }
b348b9fd
MA
746 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
747 {
748 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
749 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
750 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
751 temp_saved_regs.regs[reg] = frame_addr + offset;
752 }
753 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
754 {
755 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
756 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
757 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
758 temp_saved_regs.regs[reg] = frame_addr + offset;
759 }
760 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
761 {
762 int areg_count = (inst >> 8) & 7;
763 int sreg_count = (inst >> 6) & 3;
764
765 /* The entry instruction always subtracts 32 from the SP. */
766 PROC_FRAME_OFFSET(&temp_proc_desc) += 32;
767
768 /* Check if a0-a3 were saved in the caller's argument save area. */
769 for (reg = 4, offset = 32; reg < areg_count+4; reg++, offset += 4)
770 {
771 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
772 temp_saved_regs.regs[reg] = sp + offset;
773 }
774
775 /* Check if the ra register was pushed on the stack. */
776 offset = 28;
777 if (inst & 0x20)
778 {
779 PROC_REG_MASK(&temp_proc_desc) |= 1 << 31;
780 temp_saved_regs.regs[31] = sp + offset;
781 offset -= 4;
782 }
783
784 /* Check if the s0 and s1 registers were pushed on the stack. */
785 for (reg = 16; reg < sreg_count+16; reg++, offset -= 4)
786 {
787 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
788 temp_saved_regs.regs[reg] = sp + offset;
789 }
790 }
791 }
792}
793
794static void
795mips32_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
796 CORE_ADDR start_pc, limit_pc;
797 struct frame_info *next_frame;
798 CORE_ADDR sp;
799{
800 CORE_ADDR cur_pc;
801 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
802restart:
803 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
804 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
805 {
806 char buf[MIPS_INSTLEN];
807 unsigned long inst, high_word, low_word;
808 int status, reg;
809
810 /* Fetch the instruction. */
811 status = (unsigned long) read_memory_nobpt (cur_pc, buf, MIPS_INSTLEN);
812 if (status) memory_error (status, cur_pc);
813 inst = (unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN);
814
815 /* Save some code by pre-extracting some useful fields. */
816 high_word = (inst >> 16) & 0xffff;
817 low_word = inst & 0xffff;
818 reg = high_word & 0x1f;
819
820 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
821 || high_word == 0x23bd /* addi $sp,$sp,-i */
822 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
823 {
824 if (low_word & 0x8000) /* negative stack adjustment? */
825 PROC_FRAME_OFFSET(&temp_proc_desc) += 0x10000 - low_word;
826 else
827 /* Exit loop if a positive stack adjustment is found, which
828 usually means that the stack cleanup code in the function
829 epilogue is reached. */
830 break;
831 }
832 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
833 {
834 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
835 temp_saved_regs.regs[reg] = sp + low_word;
836 }
837 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
838 {
839 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
840 but the register size used is only 32 bits. Make the address
841 for the saved register point to the lower 32 bits. */
842 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
843 temp_saved_regs.regs[reg] = sp + low_word + 8 - MIPS_REGSIZE;
844 }
845 else if (high_word == 0x27be) /* addiu $30,$sp,size */
846 {
847 /* Old gcc frame, r30 is virtual frame pointer. */
848 if (low_word != PROC_FRAME_OFFSET(&temp_proc_desc))
849 frame_addr = sp + low_word;
850 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
851 {
852 unsigned alloca_adjust;
853 PROC_FRAME_REG (&temp_proc_desc) = 30;
854 frame_addr = read_next_frame_reg(next_frame, 30);
855 alloca_adjust = (unsigned)(frame_addr - (sp + low_word));
856 if (alloca_adjust > 0)
857 {
858 /* FP > SP + frame_size. This may be because
859 * of an alloca or somethings similar.
860 * Fix sp to "pre-alloca" value, and try again.
861 */
862 sp += alloca_adjust;
863 goto restart;
bd5635a1
RP
864 }
865 }
866 }
b348b9fd
MA
867 /* move $30,$sp. With different versions of gas this will be either
868 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
869 Accept any one of these. */
870 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
871 {
872 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
873 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
874 {
875 unsigned alloca_adjust;
876 PROC_FRAME_REG (&temp_proc_desc) = 30;
877 frame_addr = read_next_frame_reg(next_frame, 30);
878 alloca_adjust = (unsigned)(frame_addr - sp);
879 if (alloca_adjust > 0)
880 {
881 /* FP > SP + frame_size. This may be because
882 * of an alloca or somethings similar.
883 * Fix sp to "pre-alloca" value, and try again.
884 */
885 sp += alloca_adjust;
886 goto restart;
97e091b2
MA
887 }
888 }
889 }
b348b9fd
MA
890 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
891 {
892 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
893 temp_saved_regs.regs[reg] = frame_addr + low_word;
bd5635a1
RP
894 }
895 }
b348b9fd
MA
896}
897
898static mips_extra_func_info_t
899heuristic_proc_desc(start_pc, limit_pc, next_frame)
900 CORE_ADDR start_pc, limit_pc;
901 struct frame_info *next_frame;
902{
903 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
904
905 if (start_pc == 0) return NULL;
906 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
907 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
908 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
909 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
910 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
911
912 if (start_pc + 200 < limit_pc)
913 limit_pc = start_pc + 200;
914 if (start_pc & 1)
915 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
916 else
917 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
918 return &temp_proc_desc;
bd5635a1
RP
919}
920
0f552c5f 921static mips_extra_func_info_t
9f9f94aa
SS
922find_proc_desc (pc, next_frame)
923 CORE_ADDR pc;
924 struct frame_info *next_frame;
bd5635a1
RP
925{
926 mips_extra_func_info_t proc_desc;
0f552c5f 927 struct block *b = block_for_pc(pc);
48be4c35
JK
928 struct symbol *sym;
929 CORE_ADDR startaddr;
930
931 find_pc_partial_function (pc, NULL, &startaddr, NULL);
97e091b2 932 if (b == NULL || PC_IN_CALL_DUMMY (pc, 0, 0))
48be4c35
JK
933 sym = NULL;
934 else
935 {
936 if (startaddr > BLOCK_START (b))
937 /* This is the "pathological" case referred to in a comment in
938 print_frame_info. It might be better to move this check into
939 symbol reading. */
940 sym = NULL;
941 else
942 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
943 0, NULL);
944 }
0f552c5f 945
e4dbd248
PS
946 /* If we never found a PDR for this function in symbol reading, then
947 examine prologues to find the information. */
948 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
949 sym = NULL;
950
0f552c5f 951 if (sym)
bd5635a1
RP
952 {
953 /* IF this is the topmost frame AND
954 * (this proc does not have debugging information OR
955 * the PC is in the procedure prologue)
be772100 956 * THEN create a "heuristic" proc_desc (by analyzing
bd5635a1
RP
957 * the actual code) to replace the "official" proc_desc.
958 */
9f9f94aa 959 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
bd5635a1
RP
960 if (next_frame == NULL) {
961 struct symtab_and_line val;
962 struct symbol *proc_symbol =
963 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
0f552c5f 964
bd5635a1
RP
965 if (proc_symbol) {
966 val = find_pc_line (BLOCK_START
967 (SYMBOL_BLOCK_VALUE(proc_symbol)),
968 0);
969 val.pc = val.end ? val.end : pc;
970 }
971 if (!proc_symbol || pc < val.pc) {
972 mips_extra_func_info_t found_heuristic =
9f9f94aa
SS
973 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
974 pc, next_frame);
975 if (found_heuristic)
976 proc_desc = found_heuristic;
bd5635a1
RP
977 }
978 }
979 }
980 else
981 {
0f552c5f
JG
982 /* Is linked_proc_desc_table really necessary? It only seems to be used
983 by procedure call dummys. However, the procedures being called ought
984 to have their own proc_descs, and even if they don't,
985 heuristic_proc_desc knows how to create them! */
986
bd5635a1 987 register struct linked_proc_info *link;
9f9f94aa 988
bd5635a1 989 for (link = linked_proc_desc_table; link; link = link->next)
9f9f94aa
SS
990 if (PROC_LOW_ADDR(&link->info) <= pc
991 && PROC_HIGH_ADDR(&link->info) > pc)
992 return &link->info;
23d35572 993
48be4c35
JK
994 if (startaddr == 0)
995 startaddr = heuristic_proc_start (pc);
996
bd5635a1 997 proc_desc =
48be4c35 998 heuristic_proc_desc (startaddr, pc, next_frame);
bd5635a1
RP
999 }
1000 return proc_desc;
1001}
1002
96431497
MA
1003static CORE_ADDR
1004get_frame_pointer(frame, proc_desc)
1005 struct frame_info *frame;
1006 mips_extra_func_info_t proc_desc;
1007{
1008 return ADDR_BITS_REMOVE (read_next_frame_reg (frame,
1009 PROC_FRAME_REG(proc_desc)) + PROC_FRAME_OFFSET(proc_desc));
1010}
1011
bd5635a1
RP
1012mips_extra_func_info_t cached_proc_desc;
1013
9f9f94aa 1014CORE_ADDR
0f552c5f 1015mips_frame_chain(frame)
9f9f94aa 1016 struct frame_info *frame;
bd5635a1 1017{
bd5635a1
RP
1018 mips_extra_func_info_t proc_desc;
1019 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
be772100 1020
0f552c5f
JG
1021 if (saved_pc == 0 || inside_entry_file (saved_pc))
1022 return 0;
1023
bd5635a1 1024 proc_desc = find_proc_desc(saved_pc, frame);
0f552c5f
JG
1025 if (!proc_desc)
1026 return 0;
1027
bd5635a1 1028 cached_proc_desc = proc_desc;
e797b4bc
JK
1029
1030 /* If no frame pointer and frame size is zero, we must be at end
1031 of stack (or otherwise hosed). If we don't check frame size,
1032 we loop forever if we see a zero size frame. */
1033 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
3f528883 1034 && PROC_FRAME_OFFSET (proc_desc) == 0
199b2450
TL
1035 /* The previous frame from a sigtramp frame might be frameless
1036 and have frame size zero. */
1037 && !frame->signal_handler_caller)
bdef72d2
JK
1038 return 0;
1039 else
96431497 1040 return get_frame_pointer (frame, proc_desc);
bd5635a1
RP
1041}
1042
1043void
1044init_extra_frame_info(fci)
1045 struct frame_info *fci;
1046{
96431497
MA
1047 int regnum;
1048
bd5635a1 1049 /* Use proc_desc calculated in frame_chain */
ee5fb959
JK
1050 mips_extra_func_info_t proc_desc =
1051 fci->next ? cached_proc_desc : find_proc_desc(fci->pc, fci->next);
0f552c5f 1052
70126bf9 1053 fci->saved_regs = NULL;
bd5635a1 1054 fci->proc_desc =
ee5fb959 1055 proc_desc == &temp_proc_desc ? 0 : proc_desc;
bd5635a1
RP
1056 if (proc_desc)
1057 {
c2a0f1cb 1058 /* Fixup frame-pointer - only needed for top frame */
5efd597b
PS
1059 /* This may not be quite right, if proc has a real frame register.
1060 Get the value of the frame relative sp, procedure might have been
1061 interrupted by a signal at it's very start. */
70126bf9
KH
1062 if (fci->pc == PROC_LOW_ADDR (proc_desc)
1063 && !PROC_DESC_IS_DUMMY (proc_desc))
1064 fci->frame = read_next_frame_reg (fci->next, SP_REGNUM);
c2a0f1cb 1065 else
96431497 1066 fci->frame = get_frame_pointer (fci->next, proc_desc);
bd5635a1 1067
48be4c35 1068 if (proc_desc == &temp_proc_desc)
ee5fb959 1069 {
09af5868
PS
1070 char *name;
1071
1072 /* Do not set the saved registers for a sigtramp frame,
1073 mips_find_saved_registers will do that for us.
1074 We can't use fci->signal_handler_caller, it is not yet set. */
1075 find_pc_partial_function (fci->pc, &name,
1076 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
1077 if (!IN_SIGTRAMP (fci->pc, name))
1078 {
1079 fci->saved_regs = (struct frame_saved_regs*)
1080 obstack_alloc (&frame_cache_obstack,
1081 sizeof (struct frame_saved_regs));
1082 *fci->saved_regs = temp_saved_regs;
1083 fci->saved_regs->regs[PC_REGNUM]
1084 = fci->saved_regs->regs[RA_REGNUM];
1085 }
ee5fb959 1086 }
bd5635a1
RP
1087
1088 /* hack: if argument regs are saved, guess these contain args */
96431497
MA
1089 fci->num_args = -1; /* assume we can't tell how many args for now */
1090 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
1091 {
1092 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
1093 {
1094 fci->num_args = regnum - A0_REGNUM + 1;
1095 break;
1096 }
1097 }
bd5635a1 1098 }
bd5635a1
RP
1099}
1100
a70dc898
RP
1101/* MIPS stack frames are almost impenetrable. When execution stops,
1102 we basically have to look at symbol information for the function
1103 that we stopped in, which tells us *which* register (if any) is
1104 the base of the frame pointer, and what offset from that register
1105 the frame itself is at.
1106
1107 This presents a problem when trying to examine a stack in memory
1108 (that isn't executing at the moment), using the "frame" command. We
1109 don't have a PC, nor do we have any registers except SP.
1110
1111 This routine takes two arguments, SP and PC, and tries to make the
1112 cached frames look as if these two arguments defined a frame on the
1113 cache. This allows the rest of info frame to extract the important
1114 arguments without difficulty. */
1115
9f9f94aa 1116struct frame_info *
c2a0f1cb
ILT
1117setup_arbitrary_frame (argc, argv)
1118 int argc;
9f9f94aa 1119 CORE_ADDR *argv;
a70dc898 1120{
c2a0f1cb
ILT
1121 if (argc != 2)
1122 error ("MIPS frame specifications require two arguments: sp and pc");
1123
1124 return create_new_frame (argv[0], argv[1]);
a70dc898
RP
1125}
1126
0f552c5f
JG
1127CORE_ADDR
1128mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
97e091b2
MA
1129 int nargs;
1130 value_ptr *args;
1131 CORE_ADDR sp;
1132 int struct_return;
1133 CORE_ADDR struct_addr;
bd5635a1 1134{
97e091b2
MA
1135 int argreg;
1136 int float_argreg;
1137 int argnum;
1138 int len = 0;
1139 int stack_offset;
1140
1141 /* Macros to round N up or down to the next A boundary; A must be
1142 a power of two. */
1143#define ROUND_DOWN(n,a) ((n) & ~((a)-1))
1144#define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
28444bf3
DP
1145
1146 /* First ensure that the stack and structure return address (if any)
97e091b2
MA
1147 are properly aligned. The stack has to be 64-bit aligned even
1148 on 32-bit machines, because doubles must be 64-bit aligned. */
1149 sp = ROUND_DOWN (sp, 8);
1150 struct_addr = ROUND_DOWN (struct_addr, MIPS_REGSIZE);
28444bf3 1151
97e091b2
MA
1152 /* Now make space on the stack for the args. We allocate more
1153 than necessary for EABI, because the first few arguments are
1154 passed in registers, but that's OK. */
1155 for (argnum = 0; argnum < nargs; argnum++)
1156 len += ROUND_UP (TYPE_LENGTH(VALUE_TYPE(args[argnum])), MIPS_REGSIZE);
61d2d19a 1157 sp -= ROUND_UP (len, 8);
97e091b2
MA
1158
1159 /* Initialize the integer and float register pointers. */
1160 argreg = A0_REGNUM;
1161 float_argreg = FPA0_REGNUM;
1162
1163 /* the struct_return pointer occupies the first parameter-passing reg */
5efd597b 1164 if (struct_return)
97e091b2
MA
1165 write_register (argreg++, struct_addr);
1166
1167 /* The offset onto the stack at which we will start copying parameters
1168 (after the registers are used up) begins at 16 in the old ABI.
1169 This leaves room for the "home" area for register parameters. */
1170 stack_offset = MIPS_EABI ? 0 : MIPS_REGSIZE * 4;
1171
1172 /* Now load as many as possible of the first arguments into
1173 registers, and push the rest onto the stack. Loop thru args
1174 from first to last. */
1175 for (argnum = 0; argnum < nargs; argnum++)
5efd597b 1176 {
97e091b2
MA
1177 char *val;
1178 char valbuf[REGISTER_RAW_SIZE(A0_REGNUM)];
1179 value_ptr arg = args[argnum];
1180 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1181 int len = TYPE_LENGTH (arg_type);
1182 enum type_code typecode = TYPE_CODE (arg_type);
1183
61d2d19a
PS
1184 /* The EABI passes structures that do not fit in a register by
1185 reference. In all other cases, pass the structure by value. */
1186 if (typecode == TYPE_CODE_STRUCT && MIPS_EABI && len > MIPS_REGSIZE)
97e091b2
MA
1187 {
1188 store_address (valbuf, MIPS_REGSIZE, VALUE_ADDRESS (arg));
1189 len = MIPS_REGSIZE;
1190 val = valbuf;
1191 }
1192 else
1193 val = (char *)VALUE_CONTENTS (arg);
1194
1195 /* 32-bit ABIs always start floating point arguments in an
1196 even-numbered floating point register. */
1197 if (!GDB_TARGET_IS_MIPS64 && typecode == TYPE_CODE_FLT
1198 && (float_argreg & 1))
1199 float_argreg++;
1200
1201 /* Floating point arguments passed in registers have to be
1202 treated specially. On 32-bit architectures, doubles
1203 are passed in register pairs; the even register gets
1204 the low word, and the odd register gets the high word. */
1205 if (typecode == TYPE_CODE_FLT
1206 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM
1207 && mips_fpu != MIPS_FPU_NONE)
1208 {
1209 if (!GDB_TARGET_IS_MIPS64 && len == 8)
1210 {
1211 int low_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 4 : 0;
1212 unsigned long regval;
1213
1214 regval = extract_unsigned_integer (val+low_offset, 4);
1215 write_register (float_argreg++, regval); /* low word */
1216 regval = extract_unsigned_integer (val+4-low_offset, 4);
1217 write_register (float_argreg++, regval); /* high word */
1218
1219 }
1220 else
1221 {
1222 CORE_ADDR regval = extract_address (val, len);
1223 write_register (float_argreg++, regval);
1224 }
5efd597b 1225
97e091b2
MA
1226 /* If this is the old ABI, skip one or two general registers. */
1227 if (!MIPS_EABI)
1228 argreg += GDB_TARGET_IS_MIPS64 ? 1 : 2;
1229 }
1230 else
1231 {
1232 /* Copy the argument to general registers or the stack in
1233 register-sized pieces. Large arguments are split between
1234 registers and stack. */
1235 while (len > 0)
1236 {
1237 int partial_len = len < MIPS_REGSIZE ? len : MIPS_REGSIZE;
61d2d19a 1238
97e091b2
MA
1239 if (argreg <= MIPS_LAST_ARG_REGNUM)
1240 {
61d2d19a
PS
1241 CORE_ADDR regval = extract_address (val, partial_len);
1242
1243 /* It's a simple argument being passed in a general
1244 register.
1245 If the argument length is smaller than the register size,
b348b9fd
MA
1246 we have to adjust the argument on big endian targets.
1247 But don't do this adjustment on EABI targets. */
61d2d19a 1248 if (TARGET_BYTE_ORDER == BIG_ENDIAN
b348b9fd
MA
1249 && partial_len < MIPS_REGSIZE
1250 && !MIPS_EABI)
61d2d19a 1251 regval <<= ((MIPS_REGSIZE - partial_len) * TARGET_CHAR_BIT);
97e091b2
MA
1252 write_register (argreg, regval);
1253 argreg++;
1254
1255 /* If this is the old ABI, prevent subsequent floating
1256 point arguments from being passed in floating point
1257 registers. */
1258 if (!MIPS_EABI)
1259 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
1260 }
1261 else
1262 {
61d2d19a
PS
1263 /* Write this portion of the argument to the stack. */
1264 partial_len = len;
1265 write_memory (sp + stack_offset, val, partial_len);
1266 stack_offset += ROUND_UP (partial_len, MIPS_REGSIZE);
97e091b2
MA
1267 }
1268
1269 len -= partial_len;
1270 val += partial_len;
1271 }
1272 }
5efd597b 1273 }
97e091b2
MA
1274
1275 /* Set the return address register to point to the entry
1276 point of the program, where a breakpoint lies in wait. */
1277 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS());
1278
1279 /* Return adjusted stack pointer. */
bd5635a1
RP
1280 return sp;
1281}
1282
28444bf3
DP
1283void
1284mips_push_register(CORE_ADDR *sp, int regno)
1285{
1286 char buffer[MAX_REGISTER_RAW_SIZE];
1287 int regsize = REGISTER_RAW_SIZE (regno);
1288
1289 *sp -= regsize;
1290 read_register_gen (regno, buffer);
1291 write_memory (*sp, buffer, regsize);
1292}
1293
1294/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
e03c0cc6 1295#define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
bd5635a1
RP
1296
1297void
1298mips_push_dummy_frame()
1299{
1300 int ireg;
1301 struct linked_proc_info *link = (struct linked_proc_info*)
1302 xmalloc(sizeof(struct linked_proc_info));
1303 mips_extra_func_info_t proc_desc = &link->info;
96431497 1304 CORE_ADDR sp = ADDR_BITS_REMOVE (read_register (SP_REGNUM));
28444bf3 1305 CORE_ADDR old_sp = sp;
bd5635a1
RP
1306 link->next = linked_proc_desc_table;
1307 linked_proc_desc_table = link;
28444bf3
DP
1308
1309/* FIXME! are these correct ? */
bd5635a1 1310#define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
28444bf3 1311#define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
bd5635a1 1312#define FLOAT_REG_SAVE_MASK MASK(0,19)
e4dbd248
PS
1313#define FLOAT_SINGLE_REG_SAVE_MASK \
1314 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
bd5635a1
RP
1315 /*
1316 * The registers we must save are all those not preserved across
1317 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
28444bf3
DP
1318 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
1319 * and FP Control/Status registers.
1320 *
bd5635a1
RP
1321 *
1322 * Dummy frame layout:
1323 * (high memory)
1324 * Saved PC
1325 * Saved MMHI, MMLO, FPC_CSR
1326 * Saved R31
1327 * Saved R28
1328 * ...
1329 * Saved R1
1330 * Saved D18 (i.e. F19, F18)
1331 * ...
1332 * Saved D0 (i.e. F1, F0)
f9f8c14b 1333 * Argument build area and stack arguments written via mips_push_arguments
bd5635a1
RP
1334 * (low memory)
1335 */
28444bf3
DP
1336
1337 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
28444bf3
DP
1338 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
1339 PROC_FRAME_OFFSET(proc_desc) = 0;
1340 mips_push_register (&sp, PC_REGNUM);
1341 mips_push_register (&sp, HI_REGNUM);
1342 mips_push_register (&sp, LO_REGNUM);
1343 mips_push_register (&sp, mips_fpu == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
1344
1345 /* Save general CPU registers */
bd5635a1 1346 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
28444bf3 1347 PROC_REG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved R31) from FP */
bd5635a1
RP
1348 for (ireg = 32; --ireg >= 0; )
1349 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
28444bf3 1350 mips_push_register (&sp, ireg);
3fed1c4a 1351
28444bf3
DP
1352 /* Save floating point registers starting with high order word */
1353 PROC_FREG_MASK(proc_desc) =
1354 mips_fpu == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
1355 : mips_fpu == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
1356 PROC_FREG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved D18) from FP */
bd5635a1
RP
1357 for (ireg = 32; --ireg >= 0; )
1358 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
28444bf3 1359 mips_push_register (&sp, ireg + FP0_REGNUM);
3fed1c4a 1360
f9f8c14b
MA
1361 /* Update the frame pointer for the call dummy and the stack pointer.
1362 Set the procedure's starting and ending addresses to point to the
1363 call dummy address at the entry point. */
1364 write_register (PUSH_FP_REGNUM, old_sp);
bd5635a1 1365 write_register (SP_REGNUM, sp);
97e091b2
MA
1366 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS();
1367 PROC_HIGH_ADDR(proc_desc) = CALL_DUMMY_ADDRESS() + 4;
bd5635a1
RP
1368 SET_PROC_DESC_IS_DUMMY(proc_desc);
1369 PROC_PC_REG(proc_desc) = RA_REGNUM;
1370}
1371
1372void
1373mips_pop_frame()
dac4929a
SG
1374{
1375 register int regnum;
9f9f94aa
SS
1376 struct frame_info *frame = get_current_frame ();
1377 CORE_ADDR new_sp = FRAME_FP (frame);
dac4929a 1378
a70dc898 1379 mips_extra_func_info_t proc_desc = frame->proc_desc;
dac4929a
SG
1380
1381 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
70126bf9
KH
1382 if (frame->saved_regs == NULL)
1383 mips_find_saved_regs (frame);
61d2d19a 1384 for (regnum = 0; regnum < NUM_REGS; regnum++)
dac4929a 1385 {
61d2d19a
PS
1386 if (regnum != SP_REGNUM && regnum != PC_REGNUM
1387 && frame->saved_regs->regs[regnum])
1388 write_register (regnum,
1389 read_memory_integer (frame->saved_regs->regs[regnum],
1390 MIPS_REGSIZE));
dac4929a
SG
1391 }
1392 write_register (SP_REGNUM, new_sp);
1393 flush_cached_frames ();
dac4929a 1394
199b2450 1395 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
bd5635a1 1396 {
dac4929a
SG
1397 struct linked_proc_info *pi_ptr, *prev_ptr;
1398
1399 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1400 pi_ptr != NULL;
1401 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1402 {
1403 if (&pi_ptr->info == proc_desc)
1404 break;
1405 }
1406
1407 if (pi_ptr == NULL)
1408 error ("Can't locate dummy extra frame info\n");
1409
1410 if (prev_ptr != NULL)
1411 prev_ptr->next = pi_ptr->next;
1412 else
1413 linked_proc_desc_table = pi_ptr->next;
1414
1415 free (pi_ptr);
1416
28444bf3
DP
1417 write_register (HI_REGNUM,
1418 read_memory_integer (new_sp - 2*MIPS_REGSIZE, MIPS_REGSIZE));
1419 write_register (LO_REGNUM,
1420 read_memory_integer (new_sp - 3*MIPS_REGSIZE, MIPS_REGSIZE));
e4dbd248 1421 if (mips_fpu != MIPS_FPU_NONE)
28444bf3
DP
1422 write_register (FCRCS_REGNUM,
1423 read_memory_integer (new_sp - 4*MIPS_REGSIZE, MIPS_REGSIZE));
bd5635a1 1424 }
bd5635a1
RP
1425}
1426
0f552c5f 1427static void
a70dc898 1428mips_print_register (regnum, all)
bd5635a1
RP
1429 int regnum, all;
1430{
e4dbd248 1431 char raw_buffer[MAX_REGISTER_RAW_SIZE];
bd5635a1 1432
48be4c35
JK
1433 /* Get the data in raw format. */
1434 if (read_relative_register_raw_bytes (regnum, raw_buffer))
1435 {
1436 printf_filtered ("%s: [Invalid]", reg_names[regnum]);
1437 return;
1438 }
1439
1440 /* If an even floating pointer register, also print as double. */
28444bf3 1441 if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM+MIPS_NUMREGS
e4dbd248
PS
1442 && !((regnum-FP0_REGNUM) & 1))
1443 {
1444 char dbuffer[MAX_REGISTER_RAW_SIZE];
48be4c35 1445
e4dbd248 1446 read_relative_register_raw_bytes (regnum, dbuffer);
28444bf3 1447 read_relative_register_raw_bytes (regnum+1, dbuffer+4); /* FIXME!! */
ac8cf67d 1448#ifdef REGISTER_CONVERT_TO_TYPE
e4dbd248 1449 REGISTER_CONVERT_TO_TYPE(regnum, builtin_type_double, dbuffer);
ac8cf67d 1450#endif
e4dbd248
PS
1451 printf_filtered ("(d%d: ", regnum-FP0_REGNUM);
1452 val_print (builtin_type_double, dbuffer, 0,
1453 gdb_stdout, 0, 1, 0, Val_pretty_default);
1454 printf_filtered ("); ");
1455 }
199b2450 1456 fputs_filtered (reg_names[regnum], gdb_stdout);
48be4c35
JK
1457
1458 /* The problem with printing numeric register names (r26, etc.) is that
1459 the user can't use them on input. Probably the best solution is to
1460 fix it so that either the numeric or the funky (a2, etc.) names
1461 are accepted on input. */
28444bf3 1462 if (regnum < MIPS_NUMREGS)
48be4c35
JK
1463 printf_filtered ("(r%d): ", regnum);
1464 else
1465 printf_filtered (": ");
bd5635a1 1466
48be4c35 1467 /* If virtual format is floating, print it that way. */
ac57e5ad 1468 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
48be4c35 1469 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0,
199b2450 1470 gdb_stdout, 0, 1, 0, Val_pretty_default);
48be4c35
JK
1471 /* Else print as integer in hex. */
1472 else
ac57e5ad
SS
1473 print_scalar_formatted (raw_buffer, REGISTER_VIRTUAL_TYPE (regnum),
1474 'x', 0, gdb_stdout);
bd5635a1
RP
1475}
1476
d8b3b00e 1477/* Replacement for generic do_registers_info. */
9f9f94aa 1478
0f552c5f 1479void
361bf6ee 1480mips_do_registers_info (regnum, fpregs)
bd5635a1 1481 int regnum;
361bf6ee 1482 int fpregs;
bd5635a1 1483{
9f9f94aa
SS
1484 if (regnum != -1)
1485 {
1486 if (*(reg_names[regnum]) == '\0')
1487 error ("Not a valid register for the current processor type");
1488
bd5635a1
RP
1489 mips_print_register (regnum, 0);
1490 printf_filtered ("\n");
9f9f94aa
SS
1491 }
1492 else
1493 {
09af5868 1494 int did_newline = 0;
9f9f94aa
SS
1495
1496 for (regnum = 0; regnum < NUM_REGS; )
1497 {
1498 if (((!fpregs) && regnum >= FP0_REGNUM && regnum <= FCRIR_REGNUM)
1499 || *(reg_names[regnum]) == '\0')
1500 {
1501 regnum++;
1502 continue;
1503 }
bd5635a1
RP
1504 mips_print_register (regnum, 1);
1505 regnum++;
9f9f94aa
SS
1506 printf_filtered ("; ");
1507 did_newline = 0;
1508 if ((regnum & 3) == 0)
1509 {
1510 printf_filtered ("\n");
1511 did_newline = 1;
1512 }
1513 }
1514 if (!did_newline)
1515 printf_filtered ("\n");
1516 }
bd5635a1 1517}
9f9f94aa 1518
bd5635a1
RP
1519/* Return number of args passed to a frame. described by FIP.
1520 Can return -1, meaning no way to tell. */
1521
0f552c5f 1522int
9f9f94aa
SS
1523mips_frame_num_args (frame)
1524 struct frame_info *frame;
bd5635a1 1525{
9f9f94aa
SS
1526#if 0 /* FIXME Use or lose this! */
1527 struct chain_info_t *p;
bd5635a1 1528
9f9f94aa
SS
1529 p = mips_find_cached_frame (FRAME_FP (frame));
1530 if (p->valid)
1531 return p->the_info.numargs;
bd5635a1 1532#endif
9f9f94aa 1533 return -1;
bd5635a1 1534}
96431497 1535
427fec5d 1536/* Is this a branch with a delay slot? */
9f9f94aa 1537
b5aff268
JK
1538static int is_delayed PARAMS ((unsigned long));
1539
ee5fb959
JK
1540static int
1541is_delayed (insn)
1542 unsigned long insn;
1543{
1544 int i;
1545 for (i = 0; i < NUMOPCODES; ++i)
1546 if (mips_opcodes[i].pinfo != INSN_MACRO
1547 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
1548 break;
427fec5d
JK
1549 return (i < NUMOPCODES
1550 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
1551 | INSN_COND_BRANCH_DELAY
1552 | INSN_COND_BRANCH_LIKELY)));
ee5fb959 1553}
b5aff268
JK
1554
1555int
1556mips_step_skips_delay (pc)
1557 CORE_ADDR pc;
1558{
96431497 1559 char buf[MIPS_INSTLEN];
b5aff268 1560
f9f8c14b
MA
1561 /* There is no branch delay slot on MIPS16. */
1562 if (pc & 1)
1563 return 0;
1564
96431497 1565 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
b5aff268
JK
1566 /* If error reading memory, guess that it is not a delayed branch. */
1567 return 0;
96431497 1568 return is_delayed ((unsigned long)extract_unsigned_integer (buf, MIPS_INSTLEN));
b5aff268 1569}
ee5fb959 1570
bd5635a1 1571
20fa0902
MA
1572/* Skip the PC past function prologue instructions (32-bit version).
1573 This is a helper function for mips_skip_prologue. */
1574
1575static CORE_ADDR
1576mips32_skip_prologue (pc, lenient)
1577 CORE_ADDR pc; /* starting PC to search from */
ee5fb959 1578 int lenient;
bd5635a1 1579{
28444bf3 1580 t_inst inst;
20fa0902 1581 CORE_ADDR end_pc;
0b0d6c3f 1582 int seen_sp_adjust = 0;
ac57e5ad 1583 int load_immediate_bytes = 0;
bd5635a1 1584
e157305c
PS
1585 /* Skip the typical prologue instructions. These are the stack adjustment
1586 instruction and the instructions that save registers on the stack
1587 or in the gcc frame. */
20fa0902 1588 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
ee5fb959 1589 {
28444bf3 1590 char buf[MIPS_INSTLEN];
ee5fb959 1591 int status;
b348b9fd 1592 unsigned long high_word;
ee5fb959 1593
20fa0902 1594 status = read_memory_nobpt (pc, buf, MIPS_INSTLEN);
ee5fb959 1595 if (status)
20fa0902 1596 memory_error (status, pc);
28444bf3 1597 inst = (unsigned long)extract_unsigned_integer (buf, MIPS_INSTLEN);
b348b9fd 1598 high_word = (inst >> 16) & 0xffff;
ee5fb959 1599
002a422b 1600#if 0
ee5fb959
JK
1601 if (lenient && is_delayed (inst))
1602 continue;
002a422b 1603#endif
ee5fb959 1604
b348b9fd
MA
1605 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
1606 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
0b0d6c3f 1607 seen_sp_adjust = 1;
ac57e5ad
SS
1608 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
1609 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
1610 seen_sp_adjust = 1;
97e091b2
MA
1611 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
1612 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
1613 && (inst & 0x001F0000)) /* reg != $zero */
1614 continue;
1615
e157305c
PS
1616 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
1617 continue;
1618 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
1619 /* sx reg,n($s8) */
1620 continue; /* reg != $zero */
1d9489c1
JK
1621
1622 /* move $s8,$sp. With different versions of gas this will be either
20fa0902
MA
1623 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
1624 Accept any one of these. */
1625 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
0b0d6c3f 1626 continue;
1d9489c1 1627
1b71de8e
PS
1628 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
1629 continue;
b348b9fd 1630 else if (high_word == 0x3c1c) /* lui $gp,n */
e03c0cc6 1631 continue;
b348b9fd 1632 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
e03c0cc6
ILT
1633 continue;
1634 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
1635 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
1636 continue;
ac57e5ad
SS
1637 /* The following instructions load $at or $t0 with an immediate
1638 value in preparation for a stack adjustment via
1639 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
1640 a local variable, so we accept them only before a stack adjustment
1641 instruction was seen. */
1642 else if (!seen_sp_adjust)
1643 {
b348b9fd
MA
1644 if (high_word == 0x3c01 || /* lui $at,n */
1645 high_word == 0x3c08) /* lui $t0,n */
ac57e5ad 1646 {
28444bf3 1647 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
ac57e5ad
SS
1648 continue;
1649 }
b348b9fd
MA
1650 else if (high_word == 0x3421 || /* ori $at,$at,n */
1651 high_word == 0x3508 || /* ori $t0,$t0,n */
1652 high_word == 0x3401 || /* ori $at,$zero,n */
1653 high_word == 0x3408) /* ori $t0,$zero,n */
ac57e5ad 1654 {
28444bf3 1655 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
ac57e5ad
SS
1656 continue;
1657 }
1658 else
1659 break;
1660 }
0b0d6c3f 1661 else
ac57e5ad 1662 break;
d747e0af 1663 }
e157305c 1664
ac57e5ad
SS
1665 /* In a frameless function, we might have incorrectly
1666 skipped some load immediate instructions. Undo the skipping
1667 if the load immediate was not followed by a stack adjustment. */
1668 if (load_immediate_bytes && !seen_sp_adjust)
20fa0902
MA
1669 pc -= load_immediate_bytes;
1670 return pc;
1671}
1672
1673/* Skip the PC past function prologue instructions (16-bit version).
1674 This is a helper function for mips_skip_prologue. */
1675
1676static CORE_ADDR
1677mips16_skip_prologue (pc, lenient)
1678 CORE_ADDR pc; /* starting PC to search from */
1679 int lenient;
1680{
1681 CORE_ADDR end_pc;
1682
1683 /* Table of instructions likely to be found in a function prologue. */
1684 static struct
1685 {
1686 unsigned short inst;
1687 unsigned short mask;
1688 } table[] =
1689 {
1690 { 0x6300, 0xff00 }, /* addiu $sp,offset */
1691 { 0xfb00, 0xff00 }, /* daddiu $sp,offset */
1692 { 0xd000, 0xf800 }, /* sw reg,n($sp) */
1693 { 0xf900, 0xff00 }, /* sd reg,n($sp) */
1694 { 0x6200, 0xff00 }, /* sw $ra,n($sp) */
1695 { 0xfa00, 0xff00 }, /* sd $ra,n($sp) */
1696 { 0x673d, 0xffff }, /* move $s1,sp */
1697 { 0xd980, 0xff80 }, /* sw $a0-$a3,n($s1) */
1698 { 0x6704, 0xff1c }, /* move reg,$a0-$a3 */
1699 { 0xe809, 0xf81f }, /* entry pseudo-op */
1700 { 0, 0 } /* end of table marker */
1701 };
1702
1703 /* Skip the typical prologue instructions. These are the stack adjustment
1704 instruction and the instructions that save registers on the stack
1705 or in the gcc frame. */
1706 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
1707 {
1708 char buf[MIPS16_INSTLEN];
1709 int status;
1710 unsigned short inst;
1711 int extend_bytes;
1712 int prev_extend_bytes;
1713 int i;
1714
1715 status = read_memory_nobpt (pc & ~1, buf, MIPS16_INSTLEN);
1716 if (status)
1717 memory_error (status, pc);
1718 inst = (unsigned long)extract_unsigned_integer (buf, MIPS16_INSTLEN);
1719
1720#if 0
1721 if (lenient && is_delayed (inst))
1722 continue;
1723#endif
1724
1725 /* Normally we ignore an extend instruction. However, if it is
1726 not followed by a valid prologue instruction, we must adjust
1727 the pc back over the extend so that it won't be considered
1728 part of the prologue. */
1729 if ((inst & 0xf800) == 0xf000) /* extend */
1730 {
1731 extend_bytes = MIPS16_INSTLEN;
1732 continue;
1733 }
1734 prev_extend_bytes = extend_bytes;
1735 extend_bytes = 0;
1736
1737 /* Check for other valid prologue instructions besides extend. */
1738 for (i = 0; table[i].mask != 0; i++)
1739 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
1740 break;
1741 if (table[i].mask != 0) /* it was in table? */
1742 continue; /* ignore it
1743 else /* non-prologue */
1744 {
1745 /* Return the current pc, adjusted backwards by 2 if
1746 the previous instruction was an extend. */
1747 return pc - prev_extend_bytes;
1748 }
1749 }
1750}
1751
1752/* To skip prologues, I use this predicate. Returns either PC itself
1753 if the code at PC does not look like a function prologue; otherwise
1754 returns an address that (if we're lucky) follows the prologue. If
1755 LENIENT, then we must skip everything which is involved in setting
1756 up the frame (it's OK to skip more, just so long as we don't skip
1757 anything which might clobber the registers which are being saved.
1758 We must skip more in the case where part of the prologue is in the
1759 delay slot of a non-prologue instruction). */
1760
1761CORE_ADDR
1762mips_skip_prologue (pc, lenient)
1763 CORE_ADDR pc;
1764 int lenient;
1765{
1766 /* See if we can determine the end of the prologue via the symbol table.
1767 If so, then return either PC, or the PC after the prologue, whichever
1768 is greater. */
1769
1770 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
1771
1772 if (post_prologue_pc != 0)
1773 return max (pc, post_prologue_pc);
1774
1775 /* Can't determine prologue from the symbol table, need to examine
1776 instructions. */
1777
1778 if (pc & 1)
1779 return mips16_skip_prologue (pc, lenient);
1780 else
1781 return mips32_skip_prologue (pc, lenient);
bd5635a1 1782}
c2a0f1cb 1783
002a422b 1784#if 0
20fa0902 1785/* The lenient prologue stuff should be superseded by the code in
002a422b
JK
1786 init_extra_frame_info which looks to see whether the stores mentioned
1787 in the proc_desc have actually taken place. */
1788
ee5fb959
JK
1789/* Is address PC in the prologue (loosely defined) for function at
1790 STARTADDR? */
1791
1792static int
1793mips_in_lenient_prologue (startaddr, pc)
1794 CORE_ADDR startaddr;
1795 CORE_ADDR pc;
1796{
1797 CORE_ADDR end_prologue = mips_skip_prologue (startaddr, 1);
1798 return pc >= startaddr && pc < end_prologue;
1799}
002a422b 1800#endif
ee5fb959 1801
ac8cf67d
PS
1802/* Given a return value in `regbuf' with a type `valtype',
1803 extract and copy its value into `valbuf'. */
1804void
1805mips_extract_return_value (valtype, regbuf, valbuf)
1806 struct type *valtype;
1807 char regbuf[REGISTER_BYTES];
1808 char *valbuf;
1809{
1810 int regnum;
92a6d600 1811 int offset = 0;
ac8cf67d 1812
e4dbd248
PS
1813 regnum = 2;
1814 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
1815 && (mips_fpu == MIPS_FPU_DOUBLE
28444bf3 1816 || (mips_fpu == MIPS_FPU_SINGLE && TYPE_LENGTH (valtype) <= 4))) /* FIXME!! */
e4dbd248 1817 regnum = FP0_REGNUM;
ac8cf67d 1818
92a6d600
PS
1819 if (TARGET_BYTE_ORDER == BIG_ENDIAN
1820 && TYPE_CODE (valtype) != TYPE_CODE_FLT
1821 && TYPE_LENGTH (valtype) < REGISTER_RAW_SIZE (regnum))
1822 offset = REGISTER_RAW_SIZE (regnum) - TYPE_LENGTH (valtype);
1823
1824 memcpy (valbuf, regbuf + REGISTER_BYTE (regnum) + offset,
1825 TYPE_LENGTH (valtype));
ac8cf67d
PS
1826#ifdef REGISTER_CONVERT_TO_TYPE
1827 REGISTER_CONVERT_TO_TYPE(regnum, valtype, valbuf);
1828#endif
1829}
1830
1831/* Given a return value in `regbuf' with a type `valtype',
1832 write it's value into the appropriate register. */
1833void
1834mips_store_return_value (valtype, valbuf)
1835 struct type *valtype;
1836 char *valbuf;
1837{
1838 int regnum;
1839 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1840
e4dbd248
PS
1841 regnum = 2;
1842 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
1843 && (mips_fpu == MIPS_FPU_DOUBLE
28444bf3 1844 || (mips_fpu == MIPS_FPU_SINGLE && TYPE_LENGTH (valtype) <= 4))) /* FIXME!! */
e4dbd248
PS
1845 regnum = FP0_REGNUM;
1846
ac8cf67d
PS
1847 memcpy(raw_buffer, valbuf, TYPE_LENGTH (valtype));
1848
1849#ifdef REGISTER_CONVERT_FROM_TYPE
1850 REGISTER_CONVERT_FROM_TYPE(regnum, valtype, raw_buffer);
1851#endif
1852
1853 write_register_bytes(REGISTER_BYTE (regnum), raw_buffer, TYPE_LENGTH (valtype));
1854}
1855
e03c0cc6
ILT
1856/* Exported procedure: Is PC in the signal trampoline code */
1857
1858int
1859in_sigtramp (pc, ignore)
1860 CORE_ADDR pc;
1861 char *ignore; /* function name */
1862{
1863 if (sigtramp_address == 0)
1864 fixup_sigtramp ();
1865 return (pc >= sigtramp_address && pc < sigtramp_end);
1866}
1867
e4dbd248
PS
1868/* Command to set FPU type. mips_fpu_string will have been set to the
1869 user's argument. Set mips_fpu based on mips_fpu_string, and then
1870 canonicalize mips_fpu_string. */
1871
1872/*ARGSUSED*/
1873static void
1874mips_set_fpu_command (args, from_tty, c)
1875 char *args;
1876 int from_tty;
1877 struct cmd_list_element *c;
1878{
1879 char *err = NULL;
1880
1881 if (mips_fpu_string == NULL || *mips_fpu_string == '\0')
1882 mips_fpu = MIPS_FPU_DOUBLE;
1883 else if (strcasecmp (mips_fpu_string, "double") == 0
1884 || strcasecmp (mips_fpu_string, "on") == 0
1885 || strcasecmp (mips_fpu_string, "1") == 0
1886 || strcasecmp (mips_fpu_string, "yes") == 0)
1887 mips_fpu = MIPS_FPU_DOUBLE;
1888 else if (strcasecmp (mips_fpu_string, "none") == 0
1889 || strcasecmp (mips_fpu_string, "off") == 0
1890 || strcasecmp (mips_fpu_string, "0") == 0
1891 || strcasecmp (mips_fpu_string, "no") == 0)
1892 mips_fpu = MIPS_FPU_NONE;
1893 else if (strcasecmp (mips_fpu_string, "single") == 0)
1894 mips_fpu = MIPS_FPU_SINGLE;
1895 else
1896 err = strsave (mips_fpu_string);
1897
1898 if (mips_fpu_string != NULL)
1899 free (mips_fpu_string);
1900
1901 switch (mips_fpu)
1902 {
1903 case MIPS_FPU_DOUBLE:
1904 mips_fpu_string = strsave ("double");
1905 break;
1906 case MIPS_FPU_SINGLE:
1907 mips_fpu_string = strsave ("single");
1908 break;
1909 case MIPS_FPU_NONE:
1910 mips_fpu_string = strsave ("none");
1911 break;
1912 }
1913
1914 if (err != NULL)
1915 {
1916 struct cleanup *cleanups = make_cleanup (free, err);
1917 error ("Unknown FPU type `%s'. Use `double', `none', or `single'.",
1918 err);
1919 do_cleanups (cleanups);
1920 }
1921}
1922
1923static void
1924mips_show_fpu_command (args, from_tty, c)
1925 char *args;
1926 int from_tty;
1927 struct cmd_list_element *c;
1928{
1929}
1930
9f9f94aa
SS
1931/* Command to set the processor type. */
1932
1933void
1934mips_set_processor_type_command (args, from_tty)
1935 char *args;
1936 int from_tty;
1937{
1938 int i;
1939
1940 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
1941 {
1942 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
1943 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
1944 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
1945
1946 /* Restore the value. */
1947 tmp_mips_processor_type = strsave (mips_processor_type);
1948
1949 return;
1950 }
1951
1952 if (!mips_set_processor_type (tmp_mips_processor_type))
1953 {
1954 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
1955 /* Restore its value. */
1956 tmp_mips_processor_type = strsave (mips_processor_type);
1957 }
1958}
1959
1960static void
1961mips_show_processor_type_command (args, from_tty)
1962 char *args;
1963 int from_tty;
1964{
1965}
1966
1967/* Modify the actual processor type. */
1968
1969int
1970mips_set_processor_type (str)
1971 char *str;
1972{
1973 int i, j;
1974
1975 if (str == NULL)
1d9489c1 1976 return 0;
9f9f94aa
SS
1977
1978 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
1979 {
1980 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
1981 {
1982 mips_processor_type = str;
1983
1984 for (j = 0; j < NUM_REGS; ++j)
1985 reg_names[j] = mips_processor_type_table[i].regnames[j];
1986
1987 return 1;
1988
1989 /* FIXME tweak fpu flag too */
1990 }
1991 }
1992
1993 return 0;
1994}
1995
1996/* Attempt to identify the particular processor model by reading the
1997 processor id. */
1998
1999char *
2000mips_read_processor_type ()
2001{
28444bf3 2002 CORE_ADDR prid;
9f9f94aa
SS
2003
2004 prid = read_register (PRID_REGNUM);
2005
80e0e92a 2006 if ((prid & ~0xf) == 0x700)
9f9f94aa
SS
2007 return savestring ("r3041", strlen("r3041"));
2008
2009 return NULL;
2010}
427fec5d
JK
2011
2012/* Just like reinit_frame_cache, but with the right arguments to be
2013 callable as an sfunc. */
9f9f94aa 2014
427fec5d
JK
2015static void
2016reinit_frame_cache_sfunc (args, from_tty, c)
2017 char *args;
2018 int from_tty;
2019 struct cmd_list_element *c;
2020{
2021 reinit_frame_cache ();
2022}
c2a0f1cb 2023
28444bf3 2024static int
18b46e7c
SS
2025gdb_print_insn_mips (memaddr, info)
2026 bfd_vma memaddr;
2027 disassemble_info *info;
2028{
f9f8c14b
MA
2029 mips_extra_func_info_t proc_desc;
2030
2031 /* Search for the function containing this address. Set the low bit
2032 of the address when searching, in case we were given an even address
2033 that is the start of a 16-bit function. If we didn't do this,
2034 the search would fail because the symbol table says the function
2035 starts at an odd address, i.e. 1 byte past the given address. */
2036 proc_desc = find_proc_desc (memaddr | 1, NULL);
2037
2038 /* Make an attempt to determine if this is a 16-bit function. If
2039 the procedure descriptor exists and the address therein is odd,
2040 it's definitely a 16-bit function. Otherwise, we have to just
2041 guess that if the address passed in is odd, it's 16-bits. */
2042 if (proc_desc)
2043 info->mach = PROC_LOW_ADDR (proc_desc) & 1 ? 16 : 0;
2044 else
2045 info->mach = memaddr & 1 ? 16 : 0;
2046
2047 /* Round down the instruction address to the appropriate boundary.
2048 Save the amount rounded down and subtract it from the returned size of
2049 the instruction so that the next time through the address won't
2050 look bogus. */
2051 memaddr &= (info->mach == 16 ? ~1 : ~3);
2052
2053 /* Call the appropriate disassembler based on the target endian-ness. */
18b46e7c
SS
2054 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2055 return print_insn_big_mips (memaddr, info);
2056 else
2057 return print_insn_little_mips (memaddr, info);
2058}
2059
f9f8c14b
MA
2060/* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
2061 counter value to determine whether a 16- or 32-bit breakpoint should be
2062 used. It returns a pointer to a string of bytes that encode a breakpoint
2063 instruction, stores the length of the string to *lenptr, and adjusts pc
2064 (if necessary) to point to the actual memory location where the
2065 breakpoint should be inserted. */
2066
2067unsigned char *mips_breakpoint_from_pc (pcptr, lenptr)
2068 CORE_ADDR *pcptr;
2069 int *lenptr;
2070{
2071 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2072 {
2073 if (*pcptr & 1)
2074 {
2075 static char mips16_big_breakpoint[] = MIPS16_BIG_BREAKPOINT;
2076 *pcptr &= ~1;
2077 *lenptr = sizeof(mips16_big_breakpoint);
2078 return mips16_big_breakpoint;
2079 }
2080 else
2081 {
2082 static char big_breakpoint[] = BIG_BREAKPOINT;
2083 *lenptr = sizeof(big_breakpoint);
2084 return big_breakpoint;
2085 }
2086 }
2087 else
2088 {
2089 if (*pcptr & 1)
2090 {
2091 static char mips16_little_breakpoint[] = MIPS16_LITTLE_BREAKPOINT;
2092 *pcptr &= ~1;
2093 *lenptr = sizeof(mips16_little_breakpoint);
2094 return mips16_little_breakpoint;
2095 }
2096 else
2097 {
2098 static char little_breakpoint[] = LITTLE_BREAKPOINT;
2099 *lenptr = sizeof(little_breakpoint);
2100 return little_breakpoint;
2101 }
2102 }
2103}
2104
2105/* Test whether the PC points to the return instruction at the
2106 end of a function. This implements the ABOUT_TO_RETURN macro. */
2107
2108int
2109mips_about_to_return (pc)
2110 CORE_ADDR pc;
2111{
2112 if (pc & 1)
2113 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
2114 generates a "jr $ra"; other times it generates code to load
2115 the return address from the stack to an accessible register (such
2116 as $a3), then a "jr" using that register. This second case
2117 is almost impossible to distinguish from an indirect jump
2118 used for switch statements, so we don't even try. */
2119 return read_memory_integer (pc & ~1, 2) == 0xe820; /* jr $ra */
2120 else
2121 return read_memory_integer (pc, 4) == 0x3e00008; /* jr $ra */
2122}
2123
2124
c2a0f1cb
ILT
2125void
2126_initialize_mips_tdep ()
2127{
427fec5d
JK
2128 struct cmd_list_element *c;
2129
18b46e7c
SS
2130 tm_print_insn = gdb_print_insn_mips;
2131
427fec5d
JK
2132 /* Let the user turn off floating point and set the fence post for
2133 heuristic_proc_start. */
2134
e4dbd248
PS
2135 c = add_set_cmd ("mipsfpu", class_support, var_string_noescape,
2136 (char *) &mips_fpu_string,
2137 "Set use of floating point coprocessor.\n\
2138Set to `none' to avoid using floating point instructions when calling\n\
2139functions or dealing with return values. Set to `single' to use only\n\
2140single precision floating point as on the R4650. Set to `double' for\n\
2141normal floating point support.",
2142 &setlist);
2143 c->function.sfunc = mips_set_fpu_command;
2144 c = add_show_from_set (c, &showlist);
2145 c->function.sfunc = mips_show_fpu_command;
2146
2147 mips_fpu = MIPS_FPU_DOUBLE;
2148 mips_fpu_string = strsave ("double");
3127785a 2149
9f9f94aa
SS
2150 c = add_set_cmd ("processor", class_support, var_string_noescape,
2151 (char *) &tmp_mips_processor_type,
2152 "Set the type of MIPS processor in use.\n\
2153Set this to be able to access processor-type-specific registers.\n\
2154",
2155 &setlist);
2156 c->function.cfunc = mips_set_processor_type_command;
2157 c = add_show_from_set (c, &showlist);
2158 c->function.cfunc = mips_show_processor_type_command;
2159
2160 tmp_mips_processor_type = strsave (DEFAULT_MIPS_TYPE);
2161 mips_set_processor_type_command (strsave (DEFAULT_MIPS_TYPE), 0);
2162
bdef72d2
JK
2163 /* We really would like to have both "0" and "unlimited" work, but
2164 command.c doesn't deal with that. So make it a var_zinteger
2165 because the user can always use "999999" or some such for unlimited. */
2166 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
427fec5d
JK
2167 (char *) &heuristic_fence_post,
2168 "\
23d35572
JK
2169Set the distance searched for the start of a function.\n\
2170If you are debugging a stripped executable, GDB needs to search through the\n\
2171program for the start of a function. This command sets the distance of the\n\
2172search. The only need to set it is when debugging a stripped executable.",
427fec5d
JK
2173 &setlist);
2174 /* We need to throw away the frame cache when we set this, since it
2175 might change our ability to get backtraces. */
2176 c->function.sfunc = reinit_frame_cache_sfunc;
2177 add_show_from_set (c, &showlist);
c2a0f1cb 2178}
This page took 0.567128 seconds and 4 git commands to generate.