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