* monitor.c (monitor_load_srec monitor_make_srec): Move all
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
CommitLineData
7d9884b9 1/* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
18b46e7c 2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
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"
bd5635a1 35
ee5fb959
JK
36#include "opcode/mips.h"
37
bd5635a1 38#define VM_MIN_ADDRESS (unsigned)0x400000
70126bf9
KH
39
40/* FIXME: Put this declaration in frame.h. */
41extern struct obstack frame_cache_obstack;
bd5635a1 42\f
002a422b 43#if 0
ee5fb959 44static int mips_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
002a422b 45#endif
ee5fb959 46
e4dbd248
PS
47static void mips_set_fpu_command PARAMS ((char *, int,
48 struct cmd_list_element *));
49
50static void mips_show_fpu_command PARAMS ((char *, int,
51 struct cmd_list_element *));
52
9f9f94aa
SS
53void mips_set_processor_type_command PARAMS ((char *, int));
54
1d9489c1
JK
55int mips_set_processor_type PARAMS ((char *));
56
57static void mips_show_processor_type_command PARAMS ((char *, int));
58
9f9f94aa
SS
59static void reinit_frame_cache_sfunc PARAMS ((char *, int,
60 struct cmd_list_element *));
61
62/* This value is the model of MIPS in use. It is derived from the value
63 of the PrID register. */
64
65char *mips_processor_type;
66
67char *tmp_mips_processor_type;
68
c2a0f1cb
ILT
69/* Some MIPS boards don't support floating point, so we permit the
70 user to turn it off. */
9f9f94aa 71
e4dbd248
PS
72enum mips_fpu_type mips_fpu;
73
74static char *mips_fpu_string;
c2a0f1cb 75
9f9f94aa
SS
76/* A set of original names, to be used when restoring back to generic
77 registers from a specific set. */
78
79char *mips_generic_reg_names[] = REGISTER_NAMES;
80
81/* Names of IDT R3041 registers. */
82
83char *mips_r3041_reg_names[] = {
84 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
85 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
86 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
87 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
88 "sr", "lo", "hi", "bad", "cause","pc",
89 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
90 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
91 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
92 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
93 "fsr", "fir", "fp", "",
94 "", "", "bus", "ccfg", "", "", "", "",
95 "", "", "port", "cmp", "", "", "epc", "prid",
96};
97
98/* Names of IDT R3051 registers. */
99
100char *mips_r3051_reg_names[] = {
101 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
102 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
103 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
104 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
105 "sr", "lo", "hi", "bad", "cause","pc",
106 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
107 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
108 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
109 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
110 "fsr", "fir", "fp", "",
111 "inx", "rand", "elo", "", "ctxt", "", "", "",
112 "", "", "ehi", "", "", "", "epc", "prid",
113};
114
115/* Names of IDT R3081 registers. */
116
117char *mips_r3081_reg_names[] = {
118 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
119 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
120 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
121 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
122 "sr", "lo", "hi", "bad", "cause","pc",
123 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
124 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
125 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
126 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
127 "fsr", "fir", "fp", "",
128 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
129 "", "", "ehi", "", "", "", "epc", "prid",
130};
131
e4dbd248
PS
132/* Names of LSI 33k registers. */
133
134char *mips_lsi33k_reg_names[] = {
135 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
136 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
137 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
138 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
139 "epc", "hi", "lo", "sr", "cause","badvaddr",
140 "dcic", "bpc", "bda", "", "", "", "", "",
141 "", "", "", "", "", "", "", "",
142 "", "", "", "", "", "", "", "",
143 "", "", "", "", "", "", "", "",
144 "", "", "", "",
145 "", "", "", "", "", "", "", "",
146 "", "", "", "", "", "", "", "",
147};
148
9f9f94aa
SS
149struct {
150 char *name;
151 char **regnames;
152} mips_processor_type_table[] = {
153 { "generic", mips_generic_reg_names },
154 { "r3041", mips_r3041_reg_names },
155 { "r3051", mips_r3051_reg_names },
156 { "r3071", mips_r3081_reg_names },
157 { "r3081", mips_r3081_reg_names },
e4dbd248 158 { "lsi33k", mips_lsi33k_reg_names },
9f9f94aa
SS
159 { NULL, NULL }
160};
161
3127785a
RP
162/* Heuristic_proc_start may hunt through the text section for a long
163 time across a 2400 baud serial line. Allows the user to limit this
164 search. */
9f9f94aa 165
3127785a
RP
166static unsigned int heuristic_fence_post = 0;
167
0f552c5f
JG
168#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
169#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
170#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
171#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
172#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
173#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
174#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
175#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
176#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
177#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
bd5635a1 178#define _PROC_MAGIC_ 0x0F0F0F0F
0f552c5f
JG
179#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
180#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
bd5635a1
RP
181
182struct linked_proc_info
183{
184 struct mips_extra_func_info info;
185 struct linked_proc_info *next;
dac4929a 186} *linked_proc_desc_table = NULL;
bd5635a1
RP
187
188\f
70126bf9
KH
189/* Guaranteed to set fci->saved_regs to some values (it never leaves it
190 NULL). */
191
192void
193mips_find_saved_regs (fci)
9f9f94aa 194 struct frame_info *fci;
70126bf9
KH
195{
196 int ireg;
197 CORE_ADDR reg_position;
198 /* r0 bit means kernel trap */
199 int kernel_trap;
200 /* What registers have been saved? Bitmasks. */
201 unsigned long gen_mask, float_mask;
202 mips_extra_func_info_t proc_desc;
203
204 fci->saved_regs = (struct frame_saved_regs *)
205 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
206 memset (fci->saved_regs, 0, sizeof (struct frame_saved_regs));
207
e4dbd248
PS
208 /* If it is the frame for sigtramp, the saved registers are located
209 in a sigcontext structure somewhere on the stack.
210 If the stack layout for sigtramp changes we might have to change these
211 constants and the companion fixup_sigtramp in mdebugread.c */
212#ifndef SIGFRAME_BASE
213/* To satisfy alignment restrictions, sigcontext is located 4 bytes
214 above the sigtramp frame. */
215#define SIGFRAME_BASE 4
216#define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * 4)
217#define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * 4)
218#define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 4 + 3 * 4)
219#endif
220#ifndef SIGFRAME_REG_SIZE
221#define SIGFRAME_REG_SIZE 4
222#endif
223 if (fci->signal_handler_caller)
224 {
225 for (ireg = 0; ireg < 32; ireg++)
226 {
227 reg_position = fci->frame + SIGFRAME_REGSAVE_OFF
228 + ireg * SIGFRAME_REG_SIZE;
229 fci->saved_regs->regs[ireg] = reg_position;
230 }
231 for (ireg = 0; ireg < 32; ireg++)
232 {
233 reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF
234 + ireg * SIGFRAME_REG_SIZE;
235 fci->saved_regs->regs[FP0_REGNUM + ireg] = reg_position;
236 }
237 fci->saved_regs->regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF;
238 return;
239 }
240
70126bf9
KH
241 proc_desc = fci->proc_desc;
242 if (proc_desc == NULL)
243 /* I'm not sure how/whether this can happen. Normally when we can't
244 find a proc_desc, we "synthesize" one using heuristic_proc_desc
245 and set the saved_regs right away. */
246 return;
247
248 kernel_trap = PROC_REG_MASK(proc_desc) & 1;
249 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
250 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
251
252 if (/* In any frame other than the innermost, we assume that all
253 registers have been saved. This assumes that all register
254 saves in a function happen before the first function
255 call. */
256 fci->next == NULL
257
258 /* In a dummy frame we know exactly where things are saved. */
259 && !PROC_DESC_IS_DUMMY (proc_desc)
260
261 /* Not sure exactly what kernel_trap means, but if it means
262 the kernel saves the registers without a prologue doing it,
263 we better not examine the prologue to see whether registers
264 have been saved yet. */
265 && !kernel_trap)
266 {
267 /* We need to figure out whether the registers that the proc_desc
268 claims are saved have been saved yet. */
269
270 CORE_ADDR addr;
271 int status;
272 char buf[4];
273 unsigned long inst;
274
275 /* Bitmasks; set if we have found a save for the register. */
276 unsigned long gen_save_found = 0;
277 unsigned long float_save_found = 0;
278
279 for (addr = PROC_LOW_ADDR (proc_desc);
280 addr < fci->pc /*&& (gen_mask != gen_save_found
281 || float_mask != float_save_found)*/;
282 addr += 4)
283 {
284 status = read_memory_nobpt (addr, buf, 4);
285 if (status)
286 memory_error (status, addr);
287 inst = extract_unsigned_integer (buf, 4);
288 if (/* sw reg,n($sp) */
289 (inst & 0xffe00000) == 0xafa00000
290
291 /* sw reg,n($r30) */
292 || (inst & 0xffe00000) == 0xafc00000
293
294 /* sd reg,n($sp) */
295 || (inst & 0xffe00000) == 0xffa00000)
296 {
297 /* It might be possible to use the instruction to
298 find the offset, rather than the code below which
299 is based on things being in a certain order in the
300 frame, but figuring out what the instruction's offset
301 is relative to might be a little tricky. */
302 int reg = (inst & 0x001f0000) >> 16;
303 gen_save_found |= (1 << reg);
304 }
305 else if (/* swc1 freg,n($sp) */
306 (inst & 0xffe00000) == 0xe7a00000
307
308 /* swc1 freg,n($r30) */
309 || (inst & 0xffe00000) == 0xe7c00000
310
311 /* sdc1 freg,n($sp) */
312 || (inst & 0xffe00000) == 0xf7a00000)
313
314 {
315 int reg = ((inst & 0x001f0000) >> 16);
316 float_save_found |= (1 << reg);
317 }
318 }
319 gen_mask = gen_save_found;
320 float_mask = float_save_found;
321 }
322
323 /* Fill in the offsets for the registers which gen_mask says
324 were saved. */
325 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
326 for (ireg= 31; gen_mask; --ireg, gen_mask <<= 1)
327 if (gen_mask & 0x80000000)
328 {
329 fci->saved_regs->regs[ireg] = reg_position;
330 reg_position -= MIPS_REGSIZE;
331 }
332 /* Fill in the offsets for the registers which float_mask says
333 were saved. */
334 reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc);
335
336 /* The freg_offset points to where the first *double* register
337 is saved. So skip to the high-order word. */
338 reg_position += 4;
339 for (ireg = 31; float_mask; --ireg, float_mask <<= 1)
340 if (float_mask & 0x80000000)
341 {
342 fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
343 reg_position -= MIPS_REGSIZE;
344 }
345
346 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
347}
bd5635a1 348
0f552c5f 349static int
bd5635a1 350read_next_frame_reg(fi, regno)
9f9f94aa 351 struct frame_info *fi;
bd5635a1
RP
352 int regno;
353{
bd5635a1 354 for (; fi; fi = fi->next)
70126bf9 355 {
e4dbd248
PS
356 /* We have to get the saved sp from the sigcontext
357 if it is a signal handler frame. */
358 if (regno == SP_REGNUM && !fi->signal_handler_caller)
359 return fi->frame;
70126bf9
KH
360 else
361 {
362 if (fi->saved_regs == NULL)
363 mips_find_saved_regs (fi);
364 if (fi->saved_regs->regs[regno])
365 return read_memory_integer(fi->saved_regs->regs[regno], MIPS_REGSIZE);
366 }
367 }
368 return read_register (regno);
bd5635a1
RP
369}
370
371int
372mips_frame_saved_pc(frame)
9f9f94aa 373 struct frame_info *frame;
bd5635a1 374{
0f552c5f 375 mips_extra_func_info_t proc_desc = frame->proc_desc;
0434c1a0
PS
376 /* We have to get the saved pc from the sigcontext
377 if it is a signal handler frame. */
378 int pcreg = frame->signal_handler_caller ? PC_REGNUM
379 : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM);
0f552c5f 380
bd5635a1
RP
381 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
382 return read_memory_integer(frame->frame - 4, 4);
0f552c5f 383
bd5635a1
RP
384 return read_next_frame_reg(frame, pcreg);
385}
386
387static struct mips_extra_func_info temp_proc_desc;
388static struct frame_saved_regs temp_saved_regs;
389
a8172eea
RP
390/* This fencepost looks highly suspicious to me. Removing it also
391 seems suspicious as it could affect remote debugging across serial
3127785a 392 lines. */
a8172eea 393
0f552c5f
JG
394static CORE_ADDR
395heuristic_proc_start(pc)
bd5635a1
RP
396 CORE_ADDR pc;
397{
bd5635a1 398 CORE_ADDR start_pc = pc;
3127785a 399 CORE_ADDR fence = start_pc - heuristic_fence_post;
0f552c5f
JG
400
401 if (start_pc == 0) return 0;
3127785a
RP
402
403 if (heuristic_fence_post == UINT_MAX
404 || fence < VM_MIN_ADDRESS)
405 fence = VM_MIN_ADDRESS;
0f552c5f 406
bd5635a1
RP
407 /* search back for previous return */
408 for (start_pc -= 4; ; start_pc -= 4)
a8172eea
RP
409 if (start_pc < fence)
410 {
3127785a
RP
411 /* It's not clear to me why we reach this point when
412 stop_soon_quietly, but with this test, at least we
413 don't print out warnings for every child forked (eg, on
414 decstation). 22apr93 rich@cygnus.com. */
415 if (!stop_soon_quietly)
416 {
23d35572
JK
417 static int blurb_printed = 0;
418
3127785a
RP
419 if (fence == VM_MIN_ADDRESS)
420 warning("Hit beginning of text section without finding");
421 else
422 warning("Hit heuristic-fence-post without finding");
423
23d35572
JK
424 warning("enclosing function for address 0x%x", pc);
425 if (!blurb_printed)
426 {
427 printf_filtered ("\
428This warning occurs if you are debugging a function without any symbols\n\
429(for example, in a stripped executable). In that case, you may wish to\n\
430increase the size of the search with the `set heuristic-fence-post' command.\n\
431\n\
432Otherwise, you told GDB there was a function where there isn't one, or\n\
433(more likely) you have encountered a bug in GDB.\n");
434 blurb_printed = 1;
435 }
3127785a
RP
436 }
437
a8172eea
RP
438 return 0;
439 }
bd5635a1
RP
440 else if (ABOUT_TO_RETURN(start_pc))
441 break;
442
443 start_pc += 8; /* skip return, and its delay slot */
444#if 0
445 /* skip nops (usually 1) 0 - is this */
446 while (start_pc < pc && read_memory_integer (start_pc, 4) == 0)
447 start_pc += 4;
448#endif
449 return start_pc;
450}
451
0f552c5f 452static mips_extra_func_info_t
bd5635a1
RP
453heuristic_proc_desc(start_pc, limit_pc, next_frame)
454 CORE_ADDR start_pc, limit_pc;
9f9f94aa 455 struct frame_info *next_frame;
bd5635a1 456{
ac57e5ad 457 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
bd5635a1
RP
458 CORE_ADDR cur_pc;
459 int frame_size;
460 int has_frame_reg = 0;
e03c0cc6 461 int reg30 = 0; /* Value of $r30. Used by gcc for frame-pointer */
bd5635a1
RP
462 unsigned long reg_mask = 0;
463
464 if (start_pc == 0) return NULL;
9f9f94aa
SS
465 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
466 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
467 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
a70dc898 468
9f9f94aa
SS
469 if (start_pc + 200 < limit_pc)
470 limit_pc = start_pc + 200;
bd5635a1
RP
471 restart:
472 frame_size = 0;
473 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
34df79fc 474 char buf[4];
bd5635a1
RP
475 unsigned long word;
476 int status;
477
34df79fc
JK
478 status = read_memory_nobpt (cur_pc, buf, 4);
479 if (status) memory_error (status, cur_pc);
480 word = extract_unsigned_integer (buf, 4);
481
bd5635a1
RP
482 if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
483 frame_size += (-word) & 0xFFFF;
484 else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
485 frame_size += (-word) & 0xFFFF;
486 else if ((word & 0xFFE00000) == 0xafa00000) { /* sw reg,offset($sp) */
487 int reg = (word & 0x001F0000) >> 16;
488 reg_mask |= 1 << reg;
002a422b 489 temp_saved_regs.regs[reg] = sp + (word & 0xffff);
bd5635a1
RP
490 }
491 else if ((word & 0xFFFF0000) == 0x27be0000) { /* addiu $30,$sp,size */
002a422b
JK
492 if ((word & 0xffff) != frame_size)
493 reg30 = sp + (word & 0xffff);
bd5635a1
RP
494 else if (!has_frame_reg) {
495 int alloca_adjust;
496 has_frame_reg = 1;
497 reg30 = read_next_frame_reg(next_frame, 30);
002a422b 498 alloca_adjust = reg30 - (sp + (word & 0xffff));
bd5635a1
RP
499 if (alloca_adjust > 0) {
500 /* FP > SP + frame_size. This may be because
e03c0cc6 501 * of an alloca or somethings similar.
bd5635a1
RP
502 * Fix sp to "pre-alloca" value, and try again.
503 */
504 sp += alloca_adjust;
505 goto restart;
506 }
507 }
508 }
509 else if ((word & 0xFFE00000) == 0xafc00000) { /* sw reg,offset($30) */
510 int reg = (word & 0x001F0000) >> 16;
511 reg_mask |= 1 << reg;
002a422b 512 temp_saved_regs.regs[reg] = reg30 + (word & 0xffff);
bd5635a1
RP
513 }
514 }
515 if (has_frame_reg) {
516 PROC_FRAME_REG(&temp_proc_desc) = 30;
517 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
518 }
519 else {
520 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
521 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
522 }
523 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
524 PROC_PC_REG(&temp_proc_desc) = RA_REGNUM;
525 return &temp_proc_desc;
526}
527
0f552c5f 528static mips_extra_func_info_t
9f9f94aa
SS
529find_proc_desc (pc, next_frame)
530 CORE_ADDR pc;
531 struct frame_info *next_frame;
bd5635a1
RP
532{
533 mips_extra_func_info_t proc_desc;
0f552c5f 534 struct block *b = block_for_pc(pc);
48be4c35
JK
535 struct symbol *sym;
536 CORE_ADDR startaddr;
537
538 find_pc_partial_function (pc, NULL, &startaddr, NULL);
539 if (b == NULL)
540 sym = NULL;
541 else
542 {
543 if (startaddr > BLOCK_START (b))
544 /* This is the "pathological" case referred to in a comment in
545 print_frame_info. It might be better to move this check into
546 symbol reading. */
547 sym = NULL;
548 else
549 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
550 0, NULL);
551 }
0f552c5f 552
e4dbd248
PS
553 /* If we never found a PDR for this function in symbol reading, then
554 examine prologues to find the information. */
555 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
556 sym = NULL;
557
0f552c5f 558 if (sym)
bd5635a1
RP
559 {
560 /* IF this is the topmost frame AND
561 * (this proc does not have debugging information OR
562 * the PC is in the procedure prologue)
be772100 563 * THEN create a "heuristic" proc_desc (by analyzing
bd5635a1
RP
564 * the actual code) to replace the "official" proc_desc.
565 */
9f9f94aa 566 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
bd5635a1
RP
567 if (next_frame == NULL) {
568 struct symtab_and_line val;
569 struct symbol *proc_symbol =
570 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
0f552c5f 571
bd5635a1
RP
572 if (proc_symbol) {
573 val = find_pc_line (BLOCK_START
574 (SYMBOL_BLOCK_VALUE(proc_symbol)),
575 0);
576 val.pc = val.end ? val.end : pc;
577 }
578 if (!proc_symbol || pc < val.pc) {
579 mips_extra_func_info_t found_heuristic =
9f9f94aa
SS
580 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
581 pc, next_frame);
582 if (found_heuristic)
583 proc_desc = found_heuristic;
bd5635a1
RP
584 }
585 }
586 }
587 else
588 {
0f552c5f
JG
589 /* Is linked_proc_desc_table really necessary? It only seems to be used
590 by procedure call dummys. However, the procedures being called ought
591 to have their own proc_descs, and even if they don't,
592 heuristic_proc_desc knows how to create them! */
593
bd5635a1 594 register struct linked_proc_info *link;
9f9f94aa 595
bd5635a1 596 for (link = linked_proc_desc_table; link; link = link->next)
9f9f94aa
SS
597 if (PROC_LOW_ADDR(&link->info) <= pc
598 && PROC_HIGH_ADDR(&link->info) > pc)
599 return &link->info;
23d35572 600
48be4c35
JK
601 if (startaddr == 0)
602 startaddr = heuristic_proc_start (pc);
603
bd5635a1 604 proc_desc =
48be4c35 605 heuristic_proc_desc (startaddr, pc, next_frame);
bd5635a1
RP
606 }
607 return proc_desc;
608}
609
610mips_extra_func_info_t cached_proc_desc;
611
9f9f94aa 612CORE_ADDR
0f552c5f 613mips_frame_chain(frame)
9f9f94aa 614 struct frame_info *frame;
bd5635a1 615{
bd5635a1
RP
616 mips_extra_func_info_t proc_desc;
617 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
be772100 618
0f552c5f
JG
619 if (saved_pc == 0 || inside_entry_file (saved_pc))
620 return 0;
621
bd5635a1 622 proc_desc = find_proc_desc(saved_pc, frame);
0f552c5f
JG
623 if (!proc_desc)
624 return 0;
625
bd5635a1 626 cached_proc_desc = proc_desc;
e797b4bc
JK
627
628 /* If no frame pointer and frame size is zero, we must be at end
629 of stack (or otherwise hosed). If we don't check frame size,
630 we loop forever if we see a zero size frame. */
631 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
3f528883 632 && PROC_FRAME_OFFSET (proc_desc) == 0
199b2450
TL
633 /* The previous frame from a sigtramp frame might be frameless
634 and have frame size zero. */
635 && !frame->signal_handler_caller)
bdef72d2
JK
636 return 0;
637 else
638 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
639 + PROC_FRAME_OFFSET(proc_desc);
bd5635a1
RP
640}
641
642void
643init_extra_frame_info(fci)
644 struct frame_info *fci;
645{
bd5635a1 646 /* Use proc_desc calculated in frame_chain */
ee5fb959
JK
647 mips_extra_func_info_t proc_desc =
648 fci->next ? cached_proc_desc : find_proc_desc(fci->pc, fci->next);
0f552c5f 649
70126bf9 650 fci->saved_regs = NULL;
bd5635a1 651 fci->proc_desc =
ee5fb959 652 proc_desc == &temp_proc_desc ? 0 : proc_desc;
bd5635a1
RP
653 if (proc_desc)
654 {
c2a0f1cb 655 /* Fixup frame-pointer - only needed for top frame */
5efd597b
PS
656 /* This may not be quite right, if proc has a real frame register.
657 Get the value of the frame relative sp, procedure might have been
658 interrupted by a signal at it's very start. */
70126bf9
KH
659 if (fci->pc == PROC_LOW_ADDR (proc_desc)
660 && !PROC_DESC_IS_DUMMY (proc_desc))
661 fci->frame = read_next_frame_reg (fci->next, SP_REGNUM);
c2a0f1cb 662 else
70126bf9
KH
663 fci->frame =
664 read_next_frame_reg (fci->next, PROC_FRAME_REG (proc_desc))
665 + PROC_FRAME_OFFSET (proc_desc);
bd5635a1 666
48be4c35 667 if (proc_desc == &temp_proc_desc)
ee5fb959 668 {
09af5868
PS
669 char *name;
670
671 /* Do not set the saved registers for a sigtramp frame,
672 mips_find_saved_registers will do that for us.
673 We can't use fci->signal_handler_caller, it is not yet set. */
674 find_pc_partial_function (fci->pc, &name,
675 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
676 if (!IN_SIGTRAMP (fci->pc, name))
677 {
678 fci->saved_regs = (struct frame_saved_regs*)
679 obstack_alloc (&frame_cache_obstack,
680 sizeof (struct frame_saved_regs));
681 *fci->saved_regs = temp_saved_regs;
682 fci->saved_regs->regs[PC_REGNUM]
683 = fci->saved_regs->regs[RA_REGNUM];
684 }
ee5fb959 685 }
bd5635a1
RP
686
687 /* hack: if argument regs are saved, guess these contain args */
688 if ((PROC_REG_MASK(proc_desc) & 0xF0) == 0) fci->num_args = -1;
689 else if ((PROC_REG_MASK(proc_desc) & 0x80) == 0) fci->num_args = 4;
690 else if ((PROC_REG_MASK(proc_desc) & 0x40) == 0) fci->num_args = 3;
691 else if ((PROC_REG_MASK(proc_desc) & 0x20) == 0) fci->num_args = 2;
692 else if ((PROC_REG_MASK(proc_desc) & 0x10) == 0) fci->num_args = 1;
bd5635a1 693 }
bd5635a1
RP
694}
695
a70dc898
RP
696/* MIPS stack frames are almost impenetrable. When execution stops,
697 we basically have to look at symbol information for the function
698 that we stopped in, which tells us *which* register (if any) is
699 the base of the frame pointer, and what offset from that register
700 the frame itself is at.
701
702 This presents a problem when trying to examine a stack in memory
703 (that isn't executing at the moment), using the "frame" command. We
704 don't have a PC, nor do we have any registers except SP.
705
706 This routine takes two arguments, SP and PC, and tries to make the
707 cached frames look as if these two arguments defined a frame on the
708 cache. This allows the rest of info frame to extract the important
709 arguments without difficulty. */
710
9f9f94aa 711struct frame_info *
c2a0f1cb
ILT
712setup_arbitrary_frame (argc, argv)
713 int argc;
9f9f94aa 714 CORE_ADDR *argv;
a70dc898 715{
c2a0f1cb
ILT
716 if (argc != 2)
717 error ("MIPS frame specifications require two arguments: sp and pc");
718
719 return create_new_frame (argv[0], argv[1]);
a70dc898
RP
720}
721
bd5635a1 722
0f552c5f
JG
723CORE_ADDR
724mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
bd5635a1 725 int nargs;
ac57e5ad 726 value_ptr *args;
bd5635a1
RP
727 CORE_ADDR sp;
728 int struct_return;
729 CORE_ADDR struct_addr;
730{
bd5635a1 731 register i;
70126bf9 732 int accumulate_size = struct_return ? MIPS_REGSIZE : 0;
bd5635a1
RP
733 struct mips_arg { char *contents; int len; int offset; };
734 struct mips_arg *mips_args =
70126bf9 735 (struct mips_arg*)alloca((nargs + 4) * sizeof(struct mips_arg));
bd5635a1 736 register struct mips_arg *m_arg;
70126bf9
KH
737 int fake_args = 0;
738
bd5635a1 739 for (i = 0, m_arg = mips_args; i < nargs; i++, m_arg++) {
e4dbd248 740 value_ptr arg = args[i];
bd5635a1
RP
741 m_arg->len = TYPE_LENGTH (VALUE_TYPE (arg));
742 /* This entire mips-specific routine is because doubles must be aligned
743 * on 8-byte boundaries. It still isn't quite right, because MIPS decided
744 * to align 'struct {int a, b}' on 4-byte boundaries (even though this
745 * breaks their varargs implementation...). A correct solution
746 * requires an simulation of gcc's 'alignof' (and use of 'alignof'
747 * in stdarg.h/varargs.h).
70126bf9
KH
748 * On the 64 bit r4000 we always pass the first four arguments
749 * using eight bytes each, so that we can load them up correctly
750 * in CALL_DUMMY.
bd5635a1 751 */
70126bf9
KH
752 if (m_arg->len > 4)
753 accumulate_size = (accumulate_size + 7) & -8;
bd5635a1 754 m_arg->offset = accumulate_size;
bd5635a1 755 m_arg->contents = VALUE_CONTENTS(arg);
9f9f94aa
SS
756 if (! GDB_TARGET_IS_MIPS64)
757 accumulate_size = (accumulate_size + m_arg->len + 3) & -4;
70126bf9
KH
758 else
759 {
9f9f94aa
SS
760 if (accumulate_size >= 4 * MIPS_REGSIZE)
761 accumulate_size = (accumulate_size + m_arg->len + 3) &~ 4;
762 else
70126bf9 763 {
9f9f94aa
SS
764 static char zeroes[8] = { 0 };
765 int len = m_arg->len;
766
767 if (len < 8)
768 {
769 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
770 m_arg->offset += 8 - len;
771 ++m_arg;
772 m_arg->len = 8 - len;
773 m_arg->contents = zeroes;
774 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
775 m_arg->offset = accumulate_size;
776 else
777 m_arg->offset = accumulate_size + len;
778 ++fake_args;
779 }
780 accumulate_size = (accumulate_size + len + 7) & ~8;
70126bf9 781 }
70126bf9 782 }
bd5635a1
RP
783 }
784 accumulate_size = (accumulate_size + 7) & (-8);
70126bf9
KH
785 if (accumulate_size < 4 * MIPS_REGSIZE)
786 accumulate_size = 4 * MIPS_REGSIZE;
bd5635a1 787 sp -= accumulate_size;
70126bf9 788 for (i = nargs + fake_args; m_arg--, --i >= 0; )
bd5635a1 789 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
5efd597b
PS
790 if (struct_return)
791 {
792 char buf[TARGET_PTR_BIT / HOST_CHAR_BIT];
793
794 store_address (buf, sizeof buf, struct_addr);
795 write_memory (sp, buf, sizeof buf);
796 }
bd5635a1
RP
797 return sp;
798}
799
800/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
e03c0cc6 801#define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
bd5635a1
RP
802
803void
804mips_push_dummy_frame()
805{
5efd597b 806 char buffer[MAX_REGISTER_RAW_SIZE];
bd5635a1
RP
807 int ireg;
808 struct linked_proc_info *link = (struct linked_proc_info*)
809 xmalloc(sizeof(struct linked_proc_info));
810 mips_extra_func_info_t proc_desc = &link->info;
811 CORE_ADDR sp = read_register (SP_REGNUM);
812 CORE_ADDR save_address;
bd5635a1
RP
813 link->next = linked_proc_desc_table;
814 linked_proc_desc_table = link;
815#define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
816#define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<31)
817#define GEN_REG_SAVE_COUNT 22
818#define FLOAT_REG_SAVE_MASK MASK(0,19)
819#define FLOAT_REG_SAVE_COUNT 20
e4dbd248
PS
820#define FLOAT_SINGLE_REG_SAVE_MASK \
821 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
822#define FLOAT_SINGLE_REG_SAVE_COUNT 10
bd5635a1
RP
823#define SPECIAL_REG_SAVE_COUNT 4
824 /*
825 * The registers we must save are all those not preserved across
826 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
827 * In addition, we must save the PC, and PUSH_FP_REGNUM.
828 * (Ideally, we should also save MDLO/-HI and FP Control/Status reg.)
829 *
830 * Dummy frame layout:
831 * (high memory)
832 * Saved PC
833 * Saved MMHI, MMLO, FPC_CSR
834 * Saved R31
835 * Saved R28
836 * ...
837 * Saved R1
838 * Saved D18 (i.e. F19, F18)
839 * ...
840 * Saved D0 (i.e. F1, F0)
c2a0f1cb 841 * CALL_DUMMY (subroutine stub; see tm-mips.h)
bd5635a1
RP
842 * Parameter build area (not yet implemented)
843 * (low memory)
844 */
845 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
e4dbd248
PS
846 switch (mips_fpu)
847 {
848 case MIPS_FPU_DOUBLE:
849 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
850 break;
851 case MIPS_FPU_SINGLE:
852 PROC_FREG_MASK(proc_desc) = FLOAT_SINGLE_REG_SAVE_MASK;
853 break;
854 case MIPS_FPU_NONE:
855 PROC_FREG_MASK(proc_desc) = 0;
856 break;
857 }
bd5635a1
RP
858 PROC_REG_OFFSET(proc_desc) = /* offset of (Saved R31) from FP */
859 -sizeof(long) - 4 * SPECIAL_REG_SAVE_COUNT;
860 PROC_FREG_OFFSET(proc_desc) = /* offset of (Saved D18) from FP */
861 -sizeof(double) - 4 * (SPECIAL_REG_SAVE_COUNT + GEN_REG_SAVE_COUNT);
862 /* save general registers */
863 save_address = sp + PROC_REG_OFFSET(proc_desc);
864 for (ireg = 32; --ireg >= 0; )
865 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
866 {
3fed1c4a
JK
867 read_register_gen (ireg, buffer);
868
869 /* Need to fix the save_address decrement below, and also make sure
870 that we don't run into problems with the size of the dummy frame
871 or any of the offsets within it. */
872 if (REGISTER_RAW_SIZE (ireg) > 4)
873 error ("Cannot call functions on mips64");
874
5efd597b 875 write_memory (save_address, buffer, REGISTER_RAW_SIZE (ireg));
bd5635a1
RP
876 save_address -= 4;
877 }
0b0d6c3f
PS
878 /* save floating-points registers starting with high order word */
879 save_address = sp + PROC_FREG_OFFSET(proc_desc) + 4;
bd5635a1
RP
880 for (ireg = 32; --ireg >= 0; )
881 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
882 {
3fed1c4a
JK
883 read_register_gen (ireg + FP0_REGNUM, buffer);
884
885 if (REGISTER_RAW_SIZE (ireg + FP0_REGNUM) > 4)
886 error ("Cannot call functions on mips64");
887
888 write_memory (save_address, buffer,
889 REGISTER_RAW_SIZE (ireg + FP0_REGNUM));
bd5635a1
RP
890 save_address -= 4;
891 }
892 write_register (PUSH_FP_REGNUM, sp);
893 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
894 PROC_FRAME_OFFSET(proc_desc) = 0;
3fed1c4a 895 read_register_gen (PC_REGNUM, buffer);
5efd597b 896 write_memory (sp - 4, buffer, REGISTER_RAW_SIZE (PC_REGNUM));
3fed1c4a 897 read_register_gen (HI_REGNUM, buffer);
5efd597b 898 write_memory (sp - 8, buffer, REGISTER_RAW_SIZE (HI_REGNUM));
3fed1c4a 899 read_register_gen (LO_REGNUM, buffer);
5efd597b 900 write_memory (sp - 12, buffer, REGISTER_RAW_SIZE (LO_REGNUM));
e4dbd248 901 if (mips_fpu != MIPS_FPU_NONE)
3fed1c4a
JK
902 read_register_gen (FCRCS_REGNUM, buffer);
903 else
904 memset (buffer, 0, REGISTER_RAW_SIZE (FCRCS_REGNUM));
5efd597b 905 write_memory (sp - 16, buffer, REGISTER_RAW_SIZE (FCRCS_REGNUM));
e4dbd248
PS
906 sp -= 4 * (GEN_REG_SAVE_COUNT + SPECIAL_REG_SAVE_COUNT);
907 if (mips_fpu == MIPS_FPU_DOUBLE)
908 sp -= 4 * FLOAT_REG_SAVE_COUNT;
909 else if (mips_fpu == MIPS_FPU_SINGLE)
910 sp -= 4 * FLOAT_SINGLE_REG_SAVE_COUNT;
bd5635a1
RP
911 write_register (SP_REGNUM, sp);
912 PROC_LOW_ADDR(proc_desc) = sp - CALL_DUMMY_SIZE + CALL_DUMMY_START_OFFSET;
913 PROC_HIGH_ADDR(proc_desc) = sp;
914 SET_PROC_DESC_IS_DUMMY(proc_desc);
915 PROC_PC_REG(proc_desc) = RA_REGNUM;
916}
917
918void
919mips_pop_frame()
dac4929a
SG
920{
921 register int regnum;
9f9f94aa
SS
922 struct frame_info *frame = get_current_frame ();
923 CORE_ADDR new_sp = FRAME_FP (frame);
dac4929a 924
a70dc898 925 mips_extra_func_info_t proc_desc = frame->proc_desc;
dac4929a
SG
926
927 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
70126bf9
KH
928 if (frame->saved_regs == NULL)
929 mips_find_saved_regs (frame);
dac4929a
SG
930 if (proc_desc)
931 {
932 for (regnum = 32; --regnum >= 0; )
933 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
934 write_register (regnum,
935 read_memory_integer (frame->saved_regs->regs[regnum],
936 4));
937 for (regnum = 32; --regnum >= 0; )
938 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
939 write_register (regnum + FP0_REGNUM,
940 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 4));
941 }
942 write_register (SP_REGNUM, new_sp);
943 flush_cached_frames ();
dac4929a 944
199b2450 945 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
bd5635a1 946 {
dac4929a
SG
947 struct linked_proc_info *pi_ptr, *prev_ptr;
948
949 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
950 pi_ptr != NULL;
951 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
952 {
953 if (&pi_ptr->info == proc_desc)
954 break;
955 }
956
957 if (pi_ptr == NULL)
958 error ("Can't locate dummy extra frame info\n");
959
960 if (prev_ptr != NULL)
961 prev_ptr->next = pi_ptr->next;
962 else
963 linked_proc_desc_table = pi_ptr->next;
964
965 free (pi_ptr);
966
bd5635a1
RP
967 write_register (HI_REGNUM, read_memory_integer(new_sp - 8, 4));
968 write_register (LO_REGNUM, read_memory_integer(new_sp - 12, 4));
e4dbd248 969 if (mips_fpu != MIPS_FPU_NONE)
c2a0f1cb 970 write_register (FCRCS_REGNUM, read_memory_integer(new_sp - 16, 4));
bd5635a1 971 }
bd5635a1
RP
972}
973
0f552c5f 974static void
a70dc898 975mips_print_register (regnum, all)
bd5635a1
RP
976 int regnum, all;
977{
e4dbd248 978 char raw_buffer[MAX_REGISTER_RAW_SIZE];
bd5635a1 979
48be4c35
JK
980 /* Get the data in raw format. */
981 if (read_relative_register_raw_bytes (regnum, raw_buffer))
982 {
983 printf_filtered ("%s: [Invalid]", reg_names[regnum]);
984 return;
985 }
986
987 /* If an even floating pointer register, also print as double. */
988 if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM+32
e4dbd248
PS
989 && !((regnum-FP0_REGNUM) & 1))
990 {
991 char dbuffer[MAX_REGISTER_RAW_SIZE];
48be4c35 992
e4dbd248
PS
993 read_relative_register_raw_bytes (regnum, dbuffer);
994 read_relative_register_raw_bytes (regnum+1, dbuffer+4);
ac8cf67d 995#ifdef REGISTER_CONVERT_TO_TYPE
e4dbd248 996 REGISTER_CONVERT_TO_TYPE(regnum, builtin_type_double, dbuffer);
ac8cf67d 997#endif
e4dbd248
PS
998 printf_filtered ("(d%d: ", regnum-FP0_REGNUM);
999 val_print (builtin_type_double, dbuffer, 0,
1000 gdb_stdout, 0, 1, 0, Val_pretty_default);
1001 printf_filtered ("); ");
1002 }
199b2450 1003 fputs_filtered (reg_names[regnum], gdb_stdout);
48be4c35
JK
1004
1005 /* The problem with printing numeric register names (r26, etc.) is that
1006 the user can't use them on input. Probably the best solution is to
1007 fix it so that either the numeric or the funky (a2, etc.) names
1008 are accepted on input. */
1009 if (regnum < 32)
1010 printf_filtered ("(r%d): ", regnum);
1011 else
1012 printf_filtered (": ");
bd5635a1 1013
48be4c35 1014 /* If virtual format is floating, print it that way. */
ac57e5ad 1015 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
48be4c35 1016 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0,
199b2450 1017 gdb_stdout, 0, 1, 0, Val_pretty_default);
48be4c35
JK
1018 /* Else print as integer in hex. */
1019 else
ac57e5ad
SS
1020 print_scalar_formatted (raw_buffer, REGISTER_VIRTUAL_TYPE (regnum),
1021 'x', 0, gdb_stdout);
bd5635a1
RP
1022}
1023
d8b3b00e 1024/* Replacement for generic do_registers_info. */
9f9f94aa 1025
0f552c5f 1026void
361bf6ee 1027mips_do_registers_info (regnum, fpregs)
bd5635a1 1028 int regnum;
361bf6ee 1029 int fpregs;
bd5635a1 1030{
9f9f94aa
SS
1031 if (regnum != -1)
1032 {
1033 if (*(reg_names[regnum]) == '\0')
1034 error ("Not a valid register for the current processor type");
1035
bd5635a1
RP
1036 mips_print_register (regnum, 0);
1037 printf_filtered ("\n");
9f9f94aa
SS
1038 }
1039 else
1040 {
09af5868 1041 int did_newline = 0;
9f9f94aa
SS
1042
1043 for (regnum = 0; regnum < NUM_REGS; )
1044 {
1045 if (((!fpregs) && regnum >= FP0_REGNUM && regnum <= FCRIR_REGNUM)
1046 || *(reg_names[regnum]) == '\0')
1047 {
1048 regnum++;
1049 continue;
1050 }
bd5635a1
RP
1051 mips_print_register (regnum, 1);
1052 regnum++;
9f9f94aa
SS
1053 printf_filtered ("; ");
1054 did_newline = 0;
1055 if ((regnum & 3) == 0)
1056 {
1057 printf_filtered ("\n");
1058 did_newline = 1;
1059 }
1060 }
1061 if (!did_newline)
1062 printf_filtered ("\n");
1063 }
bd5635a1 1064}
9f9f94aa 1065
bd5635a1
RP
1066/* Return number of args passed to a frame. described by FIP.
1067 Can return -1, meaning no way to tell. */
1068
0f552c5f 1069int
9f9f94aa
SS
1070mips_frame_num_args (frame)
1071 struct frame_info *frame;
bd5635a1 1072{
9f9f94aa
SS
1073#if 0 /* FIXME Use or lose this! */
1074 struct chain_info_t *p;
bd5635a1 1075
9f9f94aa
SS
1076 p = mips_find_cached_frame (FRAME_FP (frame));
1077 if (p->valid)
1078 return p->the_info.numargs;
bd5635a1 1079#endif
9f9f94aa 1080 return -1;
bd5635a1 1081}
407a8389 1082\f
427fec5d 1083/* Is this a branch with a delay slot? */
9f9f94aa 1084
b5aff268
JK
1085static int is_delayed PARAMS ((unsigned long));
1086
ee5fb959
JK
1087static int
1088is_delayed (insn)
1089 unsigned long insn;
1090{
1091 int i;
1092 for (i = 0; i < NUMOPCODES; ++i)
1093 if (mips_opcodes[i].pinfo != INSN_MACRO
1094 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
1095 break;
427fec5d
JK
1096 return (i < NUMOPCODES
1097 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
1098 | INSN_COND_BRANCH_DELAY
1099 | INSN_COND_BRANCH_LIKELY)));
ee5fb959 1100}
b5aff268
JK
1101
1102int
1103mips_step_skips_delay (pc)
1104 CORE_ADDR pc;
1105{
1106 char buf[4];
1107
1108 if (target_read_memory (pc, buf, 4) != 0)
1109 /* If error reading memory, guess that it is not a delayed branch. */
1110 return 0;
1111 return is_delayed (extract_unsigned_integer (buf, 4));
1112}
ee5fb959
JK
1113
1114/* To skip prologues, I use this predicate. Returns either PC itself
1115 if the code at PC does not look like a function prologue; otherwise
1116 returns an address that (if we're lucky) follows the prologue. If
1117 LENIENT, then we must skip everything which is involved in setting
1118 up the frame (it's OK to skip more, just so long as we don't skip
1119 anything which might clobber the registers which are being saved.
1120 We must skip more in the case where part of the prologue is in the
1121 delay slot of a non-prologue instruction). */
bd5635a1 1122
be772100 1123CORE_ADDR
ee5fb959 1124mips_skip_prologue (pc, lenient)
bd5635a1 1125 CORE_ADDR pc;
ee5fb959 1126 int lenient;
bd5635a1 1127{
bd5635a1 1128 unsigned long inst;
d747e0af 1129 int offset;
0b0d6c3f 1130 int seen_sp_adjust = 0;
ac57e5ad 1131 int load_immediate_bytes = 0;
bd5635a1 1132
e157305c
PS
1133 /* Skip the typical prologue instructions. These are the stack adjustment
1134 instruction and the instructions that save registers on the stack
1135 or in the gcc frame. */
ee5fb959
JK
1136 for (offset = 0; offset < 100; offset += 4)
1137 {
1138 char buf[4];
1139 int status;
1140
1141 status = read_memory_nobpt (pc + offset, buf, 4);
1142 if (status)
1143 memory_error (status, pc + offset);
1144 inst = extract_unsigned_integer (buf, 4);
1145
002a422b 1146#if 0
ee5fb959
JK
1147 if (lenient && is_delayed (inst))
1148 continue;
002a422b 1149#endif
ee5fb959 1150
e157305c 1151 if ((inst & 0xffff0000) == 0x27bd0000) /* addiu $sp,$sp,offset */
0b0d6c3f 1152 seen_sp_adjust = 1;
ac57e5ad
SS
1153 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
1154 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
1155 seen_sp_adjust = 1;
e157305c
PS
1156 else if ((inst & 0xFFE00000) == 0xAFA00000 && (inst & 0x001F0000))
1157 continue; /* sw reg,n($sp) */
1158 /* reg != $zero */
1159 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
1160 continue;
1161 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
1162 /* sx reg,n($s8) */
1163 continue; /* reg != $zero */
1d9489c1
JK
1164
1165 /* move $s8,$sp. With different versions of gas this will be either
1166 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero'. Accept either. */
1167 else if (inst == 0x03A0F021 || inst == 0x03a0f025)
0b0d6c3f 1168 continue;
1d9489c1 1169
1b71de8e
PS
1170 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
1171 continue;
e03c0cc6
ILT
1172 else if ((inst & 0xffff0000) == 0x3c1c0000) /* lui $gp,n */
1173 continue;
1174 else if ((inst & 0xffff0000) == 0x279c0000) /* addiu $gp,$gp,n */
1175 continue;
1176 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
1177 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
1178 continue;
ac57e5ad
SS
1179 /* The following instructions load $at or $t0 with an immediate
1180 value in preparation for a stack adjustment via
1181 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
1182 a local variable, so we accept them only before a stack adjustment
1183 instruction was seen. */
1184 else if (!seen_sp_adjust)
1185 {
1186 if ((inst & 0xffff0000) == 0x3c010000 || /* lui $at,n */
1187 (inst & 0xffff0000) == 0x3c080000) /* lui $t0,n */
1188 {
1189 load_immediate_bytes += 4;
1190 continue;
1191 }
1192 else if ((inst & 0xffff0000) == 0x34210000 || /* ori $at,$at,n */
1193 (inst & 0xffff0000) == 0x35080000 || /* ori $t0,$t0,n */
1194 (inst & 0xffff0000) == 0x34010000 || /* ori $at,$zero,n */
1195 (inst & 0xffff0000) == 0x34080000) /* ori $t0,$zero,n */
1196 {
1197 load_immediate_bytes += 4;
1198 continue;
1199 }
1200 else
1201 break;
1202 }
0b0d6c3f 1203 else
ac57e5ad 1204 break;
d747e0af 1205 }
e157305c 1206
ac57e5ad
SS
1207 /* In a frameless function, we might have incorrectly
1208 skipped some load immediate instructions. Undo the skipping
1209 if the load immediate was not followed by a stack adjustment. */
1210 if (load_immediate_bytes && !seen_sp_adjust)
1211 offset -= load_immediate_bytes;
1212 return pc + offset;
bd5635a1 1213}
c2a0f1cb 1214
002a422b
JK
1215#if 0
1216/* The lenient prologue stuff should be superceded by the code in
1217 init_extra_frame_info which looks to see whether the stores mentioned
1218 in the proc_desc have actually taken place. */
1219
ee5fb959
JK
1220/* Is address PC in the prologue (loosely defined) for function at
1221 STARTADDR? */
1222
1223static int
1224mips_in_lenient_prologue (startaddr, pc)
1225 CORE_ADDR startaddr;
1226 CORE_ADDR pc;
1227{
1228 CORE_ADDR end_prologue = mips_skip_prologue (startaddr, 1);
1229 return pc >= startaddr && pc < end_prologue;
1230}
002a422b 1231#endif
ee5fb959 1232
ac8cf67d
PS
1233/* Given a return value in `regbuf' with a type `valtype',
1234 extract and copy its value into `valbuf'. */
1235void
1236mips_extract_return_value (valtype, regbuf, valbuf)
1237 struct type *valtype;
1238 char regbuf[REGISTER_BYTES];
1239 char *valbuf;
1240{
1241 int regnum;
92a6d600 1242 int offset = 0;
ac8cf67d 1243
e4dbd248
PS
1244 regnum = 2;
1245 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
1246 && (mips_fpu == MIPS_FPU_DOUBLE
1247 || (mips_fpu == MIPS_FPU_SINGLE && TYPE_LENGTH (valtype) <= 4)))
1248 regnum = FP0_REGNUM;
ac8cf67d 1249
92a6d600
PS
1250 if (TARGET_BYTE_ORDER == BIG_ENDIAN
1251 && TYPE_CODE (valtype) != TYPE_CODE_FLT
1252 && TYPE_LENGTH (valtype) < REGISTER_RAW_SIZE (regnum))
1253 offset = REGISTER_RAW_SIZE (regnum) - TYPE_LENGTH (valtype);
1254
1255 memcpy (valbuf, regbuf + REGISTER_BYTE (regnum) + offset,
1256 TYPE_LENGTH (valtype));
ac8cf67d
PS
1257#ifdef REGISTER_CONVERT_TO_TYPE
1258 REGISTER_CONVERT_TO_TYPE(regnum, valtype, valbuf);
1259#endif
1260}
1261
1262/* Given a return value in `regbuf' with a type `valtype',
1263 write it's value into the appropriate register. */
1264void
1265mips_store_return_value (valtype, valbuf)
1266 struct type *valtype;
1267 char *valbuf;
1268{
1269 int regnum;
1270 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1271
e4dbd248
PS
1272 regnum = 2;
1273 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
1274 && (mips_fpu == MIPS_FPU_DOUBLE
1275 || (mips_fpu == MIPS_FPU_SINGLE && TYPE_LENGTH (valtype) <= 4)))
1276 regnum = FP0_REGNUM;
1277
ac8cf67d
PS
1278 memcpy(raw_buffer, valbuf, TYPE_LENGTH (valtype));
1279
1280#ifdef REGISTER_CONVERT_FROM_TYPE
1281 REGISTER_CONVERT_FROM_TYPE(regnum, valtype, raw_buffer);
1282#endif
1283
1284 write_register_bytes(REGISTER_BYTE (regnum), raw_buffer, TYPE_LENGTH (valtype));
1285}
1286
e03c0cc6
ILT
1287/* These exist in mdebugread.c. */
1288extern CORE_ADDR sigtramp_address, sigtramp_end;
1289extern void fixup_sigtramp PARAMS ((void));
1290
1291/* Exported procedure: Is PC in the signal trampoline code */
1292
1293int
1294in_sigtramp (pc, ignore)
1295 CORE_ADDR pc;
1296 char *ignore; /* function name */
1297{
1298 if (sigtramp_address == 0)
1299 fixup_sigtramp ();
1300 return (pc >= sigtramp_address && pc < sigtramp_end);
1301}
1302
e4dbd248
PS
1303/* Command to set FPU type. mips_fpu_string will have been set to the
1304 user's argument. Set mips_fpu based on mips_fpu_string, and then
1305 canonicalize mips_fpu_string. */
1306
1307/*ARGSUSED*/
1308static void
1309mips_set_fpu_command (args, from_tty, c)
1310 char *args;
1311 int from_tty;
1312 struct cmd_list_element *c;
1313{
1314 char *err = NULL;
1315
1316 if (mips_fpu_string == NULL || *mips_fpu_string == '\0')
1317 mips_fpu = MIPS_FPU_DOUBLE;
1318 else if (strcasecmp (mips_fpu_string, "double") == 0
1319 || strcasecmp (mips_fpu_string, "on") == 0
1320 || strcasecmp (mips_fpu_string, "1") == 0
1321 || strcasecmp (mips_fpu_string, "yes") == 0)
1322 mips_fpu = MIPS_FPU_DOUBLE;
1323 else if (strcasecmp (mips_fpu_string, "none") == 0
1324 || strcasecmp (mips_fpu_string, "off") == 0
1325 || strcasecmp (mips_fpu_string, "0") == 0
1326 || strcasecmp (mips_fpu_string, "no") == 0)
1327 mips_fpu = MIPS_FPU_NONE;
1328 else if (strcasecmp (mips_fpu_string, "single") == 0)
1329 mips_fpu = MIPS_FPU_SINGLE;
1330 else
1331 err = strsave (mips_fpu_string);
1332
1333 if (mips_fpu_string != NULL)
1334 free (mips_fpu_string);
1335
1336 switch (mips_fpu)
1337 {
1338 case MIPS_FPU_DOUBLE:
1339 mips_fpu_string = strsave ("double");
1340 break;
1341 case MIPS_FPU_SINGLE:
1342 mips_fpu_string = strsave ("single");
1343 break;
1344 case MIPS_FPU_NONE:
1345 mips_fpu_string = strsave ("none");
1346 break;
1347 }
1348
1349 if (err != NULL)
1350 {
1351 struct cleanup *cleanups = make_cleanup (free, err);
1352 error ("Unknown FPU type `%s'. Use `double', `none', or `single'.",
1353 err);
1354 do_cleanups (cleanups);
1355 }
1356}
1357
1358static void
1359mips_show_fpu_command (args, from_tty, c)
1360 char *args;
1361 int from_tty;
1362 struct cmd_list_element *c;
1363{
1364}
1365
9f9f94aa
SS
1366/* Command to set the processor type. */
1367
1368void
1369mips_set_processor_type_command (args, from_tty)
1370 char *args;
1371 int from_tty;
1372{
1373 int i;
1374
1375 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
1376 {
1377 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
1378 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
1379 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
1380
1381 /* Restore the value. */
1382 tmp_mips_processor_type = strsave (mips_processor_type);
1383
1384 return;
1385 }
1386
1387 if (!mips_set_processor_type (tmp_mips_processor_type))
1388 {
1389 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
1390 /* Restore its value. */
1391 tmp_mips_processor_type = strsave (mips_processor_type);
1392 }
1393}
1394
1395static void
1396mips_show_processor_type_command (args, from_tty)
1397 char *args;
1398 int from_tty;
1399{
1400}
1401
1402/* Modify the actual processor type. */
1403
1404int
1405mips_set_processor_type (str)
1406 char *str;
1407{
1408 int i, j;
1409
1410 if (str == NULL)
1d9489c1 1411 return 0;
9f9f94aa
SS
1412
1413 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
1414 {
1415 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
1416 {
1417 mips_processor_type = str;
1418
1419 for (j = 0; j < NUM_REGS; ++j)
1420 reg_names[j] = mips_processor_type_table[i].regnames[j];
1421
1422 return 1;
1423
1424 /* FIXME tweak fpu flag too */
1425 }
1426 }
1427
1428 return 0;
1429}
1430
1431/* Attempt to identify the particular processor model by reading the
1432 processor id. */
1433
1434char *
1435mips_read_processor_type ()
1436{
1437 int prid;
1438
1439 prid = read_register (PRID_REGNUM);
1440
1441 if (prid & ~0xf == 0x700)
1442 return savestring ("r3041", strlen("r3041"));
1443
1444 return NULL;
1445}
427fec5d
JK
1446
1447/* Just like reinit_frame_cache, but with the right arguments to be
1448 callable as an sfunc. */
9f9f94aa 1449
427fec5d
JK
1450static void
1451reinit_frame_cache_sfunc (args, from_tty, c)
1452 char *args;
1453 int from_tty;
1454 struct cmd_list_element *c;
1455{
1456 reinit_frame_cache ();
1457}
c2a0f1cb 1458
18b46e7c
SS
1459int
1460gdb_print_insn_mips (memaddr, info)
1461 bfd_vma memaddr;
1462 disassemble_info *info;
1463{
1464 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1465 return print_insn_big_mips (memaddr, info);
1466 else
1467 return print_insn_little_mips (memaddr, info);
1468}
1469
c2a0f1cb
ILT
1470void
1471_initialize_mips_tdep ()
1472{
427fec5d
JK
1473 struct cmd_list_element *c;
1474
18b46e7c
SS
1475 tm_print_insn = gdb_print_insn_mips;
1476
427fec5d
JK
1477 /* Let the user turn off floating point and set the fence post for
1478 heuristic_proc_start. */
1479
e4dbd248
PS
1480 c = add_set_cmd ("mipsfpu", class_support, var_string_noescape,
1481 (char *) &mips_fpu_string,
1482 "Set use of floating point coprocessor.\n\
1483Set to `none' to avoid using floating point instructions when calling\n\
1484functions or dealing with return values. Set to `single' to use only\n\
1485single precision floating point as on the R4650. Set to `double' for\n\
1486normal floating point support.",
1487 &setlist);
1488 c->function.sfunc = mips_set_fpu_command;
1489 c = add_show_from_set (c, &showlist);
1490 c->function.sfunc = mips_show_fpu_command;
1491
1492 mips_fpu = MIPS_FPU_DOUBLE;
1493 mips_fpu_string = strsave ("double");
3127785a 1494
9f9f94aa
SS
1495 c = add_set_cmd ("processor", class_support, var_string_noescape,
1496 (char *) &tmp_mips_processor_type,
1497 "Set the type of MIPS processor in use.\n\
1498Set this to be able to access processor-type-specific registers.\n\
1499",
1500 &setlist);
1501 c->function.cfunc = mips_set_processor_type_command;
1502 c = add_show_from_set (c, &showlist);
1503 c->function.cfunc = mips_show_processor_type_command;
1504
1505 tmp_mips_processor_type = strsave (DEFAULT_MIPS_TYPE);
1506 mips_set_processor_type_command (strsave (DEFAULT_MIPS_TYPE), 0);
1507
bdef72d2
JK
1508 /* We really would like to have both "0" and "unlimited" work, but
1509 command.c doesn't deal with that. So make it a var_zinteger
1510 because the user can always use "999999" or some such for unlimited. */
1511 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
427fec5d
JK
1512 (char *) &heuristic_fence_post,
1513 "\
23d35572
JK
1514Set the distance searched for the start of a function.\n\
1515If you are debugging a stripped executable, GDB needs to search through the\n\
1516program for the start of a function. This command sets the distance of the\n\
1517search. The only need to set it is when debugging a stripped executable.",
427fec5d
JK
1518 &setlist);
1519 /* We need to throw away the frame cache when we set this, since it
1520 might change our ability to get backtraces. */
1521 c->function.sfunc = reinit_frame_cache_sfunc;
1522 add_show_from_set (c, &showlist);
c2a0f1cb 1523}
This page took 0.60904 seconds and 4 git commands to generate.