fix typo, added @table
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
CommitLineData
7d9884b9 1/* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
5e2e79f8 2 Copyright 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
bd5635a1
RP
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
5
6This file is part of GDB.
7
361bf6ee 8This program is free software; you can redistribute it and/or modify
bd5635a1 9it under the terms of the GNU General Public License as published by
361bf6ee
JG
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
bd5635a1 12
361bf6ee 13This program is distributed in the hope that it will be useful,
bd5635a1
RP
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
361bf6ee
JG
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 21
bd5635a1 22#include "defs.h"
bd5635a1
RP
23#include "frame.h"
24#include "inferior.h"
25#include "symtab.h"
26#include "value.h"
27#include "gdbcmd.h"
ef08856f 28#include "language.h"
bd5635a1
RP
29
30#ifdef USG
31#include <sys/types.h>
32#endif
33
34#include <sys/param.h>
35#include <sys/dir.h>
36#include <signal.h>
37#include <sys/ioctl.h>
38
407a8389
SG
39#ifdef sgi
40/* Must do it this way only for SGIs, as other mips platforms get their
41 JB_ symbols from machine/pcb.h (included via sys/user.h). */
42#include <setjmp.h>
43#endif
44
bd5635a1 45#include "gdbcore.h"
62a469e1
SG
46#include "symfile.h"
47#include "objfiles.h"
bd5635a1
RP
48
49#ifndef MIPSMAGIC
50#ifdef MIPSEL
51#define MIPSMAGIC MIPSELMAGIC
52#else
53#define MIPSMAGIC MIPSEBMAGIC
54#endif
55#endif
56
57#define VM_MIN_ADDRESS (unsigned)0x400000
58
59#include <sys/user.h> /* After a.out.h */
60#include <sys/file.h>
61#include <sys/stat.h>
62
63\f
0f552c5f
JG
64#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
65#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
66#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
67#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
68#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
69#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
70#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
71#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
72#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
73#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
bd5635a1 74#define _PROC_MAGIC_ 0x0F0F0F0F
0f552c5f
JG
75#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
76#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
bd5635a1
RP
77
78struct linked_proc_info
79{
80 struct mips_extra_func_info info;
81 struct linked_proc_info *next;
82} * linked_proc_desc_table = NULL;
83
84\f
85#define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
86
0f552c5f 87static int
bd5635a1
RP
88read_next_frame_reg(fi, regno)
89 FRAME fi;
90 int regno;
91{
92#define SIGFRAME_BASE sizeof(struct sigcontext)
93#define SIGFRAME_PC_OFF (-SIGFRAME_BASE+ 2*sizeof(int))
94#define SIGFRAME_SP_OFF (-SIGFRAME_BASE+32*sizeof(int))
95#define SIGFRAME_RA_OFF (-SIGFRAME_BASE+34*sizeof(int))
96 for (; fi; fi = fi->next)
97 if (in_sigtramp(fi->pc, 0)) {
98 /* No idea if this code works. --PB. */
99 int offset;
100 if (regno == PC_REGNUM) offset = SIGFRAME_PC_OFF;
101 else if (regno == RA_REGNUM) offset = SIGFRAME_RA_OFF;
102 else if (regno == SP_REGNUM) offset = SIGFRAME_SP_OFF;
103 else return 0;
104 return read_memory_integer(fi->frame + offset, 4);
105 }
106 else if (regno == SP_REGNUM) return fi->frame;
107 else if (fi->saved_regs->regs[regno])
108 return read_memory_integer(fi->saved_regs->regs[regno], 4);
109 return read_register(regno);
110}
111
112int
113mips_frame_saved_pc(frame)
114 FRAME frame;
115{
0f552c5f 116 mips_extra_func_info_t proc_desc = frame->proc_desc;
bd5635a1 117 int pcreg = proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM;
0f552c5f 118
bd5635a1
RP
119 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
120 return read_memory_integer(frame->frame - 4, 4);
0f552c5f 121
bd5635a1
RP
122 return read_next_frame_reg(frame, pcreg);
123}
124
125static struct mips_extra_func_info temp_proc_desc;
126static struct frame_saved_regs temp_saved_regs;
127
0f552c5f
JG
128static CORE_ADDR
129heuristic_proc_start(pc)
bd5635a1
RP
130 CORE_ADDR pc;
131{
bd5635a1 132 CORE_ADDR start_pc = pc;
5e2e79f8 133 CORE_ADDR fence = start_pc - 200;
0f552c5f
JG
134
135 if (start_pc == 0) return 0;
bd5635a1 136 if (fence < VM_MIN_ADDRESS) fence = VM_MIN_ADDRESS;
0f552c5f 137
bd5635a1
RP
138 /* search back for previous return */
139 for (start_pc -= 4; ; start_pc -= 4)
140 if (start_pc < fence) return 0;
141 else if (ABOUT_TO_RETURN(start_pc))
142 break;
143
144 start_pc += 8; /* skip return, and its delay slot */
145#if 0
146 /* skip nops (usually 1) 0 - is this */
147 while (start_pc < pc && read_memory_integer (start_pc, 4) == 0)
148 start_pc += 4;
149#endif
150 return start_pc;
151}
152
0f552c5f 153static mips_extra_func_info_t
bd5635a1
RP
154heuristic_proc_desc(start_pc, limit_pc, next_frame)
155 CORE_ADDR start_pc, limit_pc;
156 FRAME next_frame;
157{
158 CORE_ADDR sp = next_frame ? next_frame->frame : read_register (SP_REGNUM);
159 CORE_ADDR cur_pc;
160 int frame_size;
161 int has_frame_reg = 0;
162 int reg30; /* Value of $r30. Used by gcc for frame-pointer */
163 unsigned long reg_mask = 0;
164
165 if (start_pc == 0) return NULL;
166 bzero(&temp_proc_desc, sizeof(temp_proc_desc));
167 bzero(&temp_saved_regs, sizeof(struct frame_saved_regs));
a70dc898
RP
168 PROC_LOW_ADDR(&temp_proc_desc) = start_pc;
169
bd5635a1
RP
170 if (start_pc + 200 < limit_pc) limit_pc = start_pc + 200;
171 restart:
172 frame_size = 0;
173 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
174 unsigned long word;
175 int status;
176
a70dc898 177 status = read_memory_nobpt (cur_pc, (char *)&word, 4);
bd5635a1 178 if (status) memory_error (status, cur_pc);
5e2e79f8 179 SWAP_TARGET_AND_HOST (&word, sizeof (word));
bd5635a1
RP
180 if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
181 frame_size += (-word) & 0xFFFF;
182 else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
183 frame_size += (-word) & 0xFFFF;
184 else if ((word & 0xFFE00000) == 0xafa00000) { /* sw reg,offset($sp) */
185 int reg = (word & 0x001F0000) >> 16;
186 reg_mask |= 1 << reg;
187 temp_saved_regs.regs[reg] = sp + (short)word;
188 }
189 else if ((word & 0xFFFF0000) == 0x27be0000) { /* addiu $30,$sp,size */
190 if ((unsigned short)word != frame_size)
191 reg30 = sp + (unsigned short)word;
192 else if (!has_frame_reg) {
193 int alloca_adjust;
194 has_frame_reg = 1;
195 reg30 = read_next_frame_reg(next_frame, 30);
196 alloca_adjust = reg30 - (sp + (unsigned short)word);
197 if (alloca_adjust > 0) {
198 /* FP > SP + frame_size. This may be because
199 /* of an alloca or somethings similar.
200 * Fix sp to "pre-alloca" value, and try again.
201 */
202 sp += alloca_adjust;
203 goto restart;
204 }
205 }
206 }
207 else if ((word & 0xFFE00000) == 0xafc00000) { /* sw reg,offset($30) */
208 int reg = (word & 0x001F0000) >> 16;
209 reg_mask |= 1 << reg;
210 temp_saved_regs.regs[reg] = reg30 + (short)word;
211 }
212 }
213 if (has_frame_reg) {
214 PROC_FRAME_REG(&temp_proc_desc) = 30;
215 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
216 }
217 else {
218 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
219 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
220 }
221 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
222 PROC_PC_REG(&temp_proc_desc) = RA_REGNUM;
223 return &temp_proc_desc;
224}
225
0f552c5f 226static mips_extra_func_info_t
bd5635a1
RP
227find_proc_desc(pc, next_frame)
228 CORE_ADDR pc;
229 FRAME next_frame;
230{
231 mips_extra_func_info_t proc_desc;
0f552c5f 232 struct block *b = block_for_pc(pc);
bd5635a1
RP
233 struct symbol *sym =
234 b ? lookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, 0, NULL) : NULL;
0f552c5f
JG
235
236 if (sym)
bd5635a1
RP
237 {
238 /* IF this is the topmost frame AND
239 * (this proc does not have debugging information OR
240 * the PC is in the procedure prologue)
be772100 241 * THEN create a "heuristic" proc_desc (by analyzing
bd5635a1
RP
242 * the actual code) to replace the "official" proc_desc.
243 */
0f552c5f 244 proc_desc = (mips_extra_func_info_t)SYMBOL_VALUE(sym);
bd5635a1
RP
245 if (next_frame == NULL) {
246 struct symtab_and_line val;
247 struct symbol *proc_symbol =
248 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
0f552c5f 249
bd5635a1
RP
250 if (proc_symbol) {
251 val = find_pc_line (BLOCK_START
252 (SYMBOL_BLOCK_VALUE(proc_symbol)),
253 0);
254 val.pc = val.end ? val.end : pc;
255 }
256 if (!proc_symbol || pc < val.pc) {
257 mips_extra_func_info_t found_heuristic =
258 heuristic_proc_desc(PROC_LOW_ADDR(proc_desc),
259 pc, next_frame);
260 if (found_heuristic) proc_desc = found_heuristic;
261 }
262 }
263 }
264 else
265 {
0f552c5f
JG
266 /* Is linked_proc_desc_table really necessary? It only seems to be used
267 by procedure call dummys. However, the procedures being called ought
268 to have their own proc_descs, and even if they don't,
269 heuristic_proc_desc knows how to create them! */
270
bd5635a1
RP
271 register struct linked_proc_info *link;
272 for (link = linked_proc_desc_table; link; link = link->next)
273 if (PROC_LOW_ADDR(&link->info) <= pc
274 && PROC_HIGH_ADDR(&link->info) > pc)
275 return &link->info;
276 proc_desc =
277 heuristic_proc_desc(heuristic_proc_start(pc), pc, next_frame);
278 }
279 return proc_desc;
280}
281
282mips_extra_func_info_t cached_proc_desc;
283
0f552c5f
JG
284FRAME_ADDR
285mips_frame_chain(frame)
bd5635a1
RP
286 FRAME frame;
287{
bd5635a1
RP
288 mips_extra_func_info_t proc_desc;
289 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
be772100 290
0f552c5f
JG
291 if (saved_pc == 0 || inside_entry_file (saved_pc))
292 return 0;
293
bd5635a1 294 proc_desc = find_proc_desc(saved_pc, frame);
0f552c5f
JG
295 if (!proc_desc)
296 return 0;
297
bd5635a1
RP
298 cached_proc_desc = proc_desc;
299 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
0f552c5f 300 + PROC_FRAME_OFFSET(proc_desc);
bd5635a1
RP
301}
302
303void
304init_extra_frame_info(fci)
305 struct frame_info *fci;
306{
307 extern struct obstack frame_cache_obstack;
308 /* Use proc_desc calculated in frame_chain */
309 mips_extra_func_info_t proc_desc = fci->next ? cached_proc_desc :
310 find_proc_desc(fci->pc, fci->next);
0f552c5f 311
bd5635a1
RP
312 fci->saved_regs = (struct frame_saved_regs*)
313 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
314 bzero(fci->saved_regs, sizeof(struct frame_saved_regs));
315 fci->proc_desc =
0f552c5f 316 proc_desc == &temp_proc_desc ? 0 : proc_desc;
bd5635a1
RP
317 if (proc_desc)
318 {
319 int ireg;
320 CORE_ADDR reg_position;
321 unsigned long mask;
322 /* r0 bit means kernel trap */
323 int kernel_trap = PROC_REG_MASK(proc_desc) & 1;
324
a70dc898
RP
325 if (fci->frame == 0)
326 {
327 /* Fixup frame-pointer - only needed for top frame */
328 /* This may not be quite right, if proc has a real frame register */
329 if (fci->pc == PROC_LOW_ADDR(proc_desc))
330 fci->frame = read_register (SP_REGNUM);
331 else
bd5635a1 332 fci->frame = READ_FRAME_REG(fci, PROC_FRAME_REG(proc_desc))
a70dc898
RP
333 + PROC_FRAME_OFFSET(proc_desc);
334 }
bd5635a1
RP
335
336 if (proc_desc == &temp_proc_desc)
337 *fci->saved_regs = temp_saved_regs;
338 else
339 {
340 /* find which general-purpose registers were saved */
341 reg_position = fci->frame + PROC_REG_OFFSET(proc_desc);
342 mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
343 for (ireg= 31; mask; --ireg, mask <<= 1)
344 if (mask & 0x80000000)
345 {
346 fci->saved_regs->regs[ireg] = reg_position;
347 reg_position -= 4;
348 }
349 /* find which floating-point registers were saved */
350 reg_position = fci->frame + PROC_FREG_OFFSET(proc_desc);
351 /* The freg_offset points to where the first *double* register is saved.
352 * So skip to the high-order word. */
353 reg_position += 4;
354 mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
355 for (ireg = 31; mask; --ireg, mask <<= 1)
356 if (mask & 0x80000000)
357 {
d747e0af 358 fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
bd5635a1
RP
359 reg_position -= 4;
360 }
361 }
362
363 /* hack: if argument regs are saved, guess these contain args */
364 if ((PROC_REG_MASK(proc_desc) & 0xF0) == 0) fci->num_args = -1;
365 else if ((PROC_REG_MASK(proc_desc) & 0x80) == 0) fci->num_args = 4;
366 else if ((PROC_REG_MASK(proc_desc) & 0x40) == 0) fci->num_args = 3;
367 else if ((PROC_REG_MASK(proc_desc) & 0x20) == 0) fci->num_args = 2;
368 else if ((PROC_REG_MASK(proc_desc) & 0x10) == 0) fci->num_args = 1;
369
370 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
371 }
bd5635a1
RP
372}
373
a70dc898
RP
374/* MIPS stack frames are almost impenetrable. When execution stops,
375 we basically have to look at symbol information for the function
376 that we stopped in, which tells us *which* register (if any) is
377 the base of the frame pointer, and what offset from that register
378 the frame itself is at.
379
380 This presents a problem when trying to examine a stack in memory
381 (that isn't executing at the moment), using the "frame" command. We
382 don't have a PC, nor do we have any registers except SP.
383
384 This routine takes two arguments, SP and PC, and tries to make the
385 cached frames look as if these two arguments defined a frame on the
386 cache. This allows the rest of info frame to extract the important
387 arguments without difficulty. */
388
389FRAME
390setup_arbitrary_frame (stack, pc)
391 FRAME_ADDR stack;
392 CORE_ADDR pc;
393{
394 return create_new_frame (stack, pc);
395}
396
bd5635a1 397
0f552c5f
JG
398CORE_ADDR
399mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
bd5635a1
RP
400 int nargs;
401 value *args;
402 CORE_ADDR sp;
403 int struct_return;
404 CORE_ADDR struct_addr;
405{
406 CORE_ADDR buf;
407 register i;
408 int accumulate_size = struct_return ? 4 : 0;
409 struct mips_arg { char *contents; int len; int offset; };
410 struct mips_arg *mips_args =
411 (struct mips_arg*)alloca(nargs * sizeof(struct mips_arg));
412 register struct mips_arg *m_arg;
413 for (i = 0, m_arg = mips_args; i < nargs; i++, m_arg++) {
414 extern value value_arg_coerce();
415 value arg = value_arg_coerce (args[i]);
416 m_arg->len = TYPE_LENGTH (VALUE_TYPE (arg));
417 /* This entire mips-specific routine is because doubles must be aligned
418 * on 8-byte boundaries. It still isn't quite right, because MIPS decided
419 * to align 'struct {int a, b}' on 4-byte boundaries (even though this
420 * breaks their varargs implementation...). A correct solution
421 * requires an simulation of gcc's 'alignof' (and use of 'alignof'
422 * in stdarg.h/varargs.h).
423 */
424 if (m_arg->len > 4) accumulate_size = (accumulate_size + 7) & -8;
425 m_arg->offset = accumulate_size;
426 accumulate_size = (accumulate_size + m_arg->len + 3) & -4;
427 m_arg->contents = VALUE_CONTENTS(arg);
428 }
429 accumulate_size = (accumulate_size + 7) & (-8);
430 if (accumulate_size < 16) accumulate_size = 16;
431 sp -= accumulate_size;
432 for (i = nargs; m_arg--, --i >= 0; )
433 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
434 if (struct_return) {
435 buf = struct_addr;
a70dc898
RP
436 write_memory(sp, (char *)&buf, sizeof(CORE_ADDR));
437 }
bd5635a1
RP
438 return sp;
439}
440
441/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
442#define MASK(i,j) ((1 << (j)+1)-1 ^ (1 << (i))-1)
443
444void
445mips_push_dummy_frame()
446{
447 int ireg;
448 struct linked_proc_info *link = (struct linked_proc_info*)
449 xmalloc(sizeof(struct linked_proc_info));
450 mips_extra_func_info_t proc_desc = &link->info;
451 CORE_ADDR sp = read_register (SP_REGNUM);
452 CORE_ADDR save_address;
453 REGISTER_TYPE buffer;
454 link->next = linked_proc_desc_table;
455 linked_proc_desc_table = link;
456#define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
457#define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<31)
458#define GEN_REG_SAVE_COUNT 22
459#define FLOAT_REG_SAVE_MASK MASK(0,19)
460#define FLOAT_REG_SAVE_COUNT 20
461#define SPECIAL_REG_SAVE_COUNT 4
462 /*
463 * The registers we must save are all those not preserved across
464 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
465 * In addition, we must save the PC, and PUSH_FP_REGNUM.
466 * (Ideally, we should also save MDLO/-HI and FP Control/Status reg.)
467 *
468 * Dummy frame layout:
469 * (high memory)
470 * Saved PC
471 * Saved MMHI, MMLO, FPC_CSR
472 * Saved R31
473 * Saved R28
474 * ...
475 * Saved R1
476 * Saved D18 (i.e. F19, F18)
477 * ...
478 * Saved D0 (i.e. F1, F0)
479 * CALL_DUMMY (subroutine stub; see m-mips.h)
480 * Parameter build area (not yet implemented)
481 * (low memory)
482 */
483 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
484 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
485 PROC_REG_OFFSET(proc_desc) = /* offset of (Saved R31) from FP */
486 -sizeof(long) - 4 * SPECIAL_REG_SAVE_COUNT;
487 PROC_FREG_OFFSET(proc_desc) = /* offset of (Saved D18) from FP */
488 -sizeof(double) - 4 * (SPECIAL_REG_SAVE_COUNT + GEN_REG_SAVE_COUNT);
489 /* save general registers */
490 save_address = sp + PROC_REG_OFFSET(proc_desc);
491 for (ireg = 32; --ireg >= 0; )
492 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
493 {
494 buffer = read_register (ireg);
a70dc898 495 write_memory (save_address, (char *)&buffer, sizeof(REGISTER_TYPE));
bd5635a1
RP
496 save_address -= 4;
497 }
498 /* save floating-points registers */
499 save_address = sp + PROC_FREG_OFFSET(proc_desc);
500 for (ireg = 32; --ireg >= 0; )
501 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
502 {
7d9884b9 503 buffer = read_register (ireg + FP0_REGNUM);
a70dc898 504 write_memory (save_address, (char *)&buffer, 4);
bd5635a1
RP
505 save_address -= 4;
506 }
507 write_register (PUSH_FP_REGNUM, sp);
508 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
509 PROC_FRAME_OFFSET(proc_desc) = 0;
510 buffer = read_register (PC_REGNUM);
a70dc898 511 write_memory (sp - 4, (char *)&buffer, sizeof(REGISTER_TYPE));
bd5635a1 512 buffer = read_register (HI_REGNUM);
a70dc898 513 write_memory (sp - 8, (char *)&buffer, sizeof(REGISTER_TYPE));
bd5635a1 514 buffer = read_register (LO_REGNUM);
a70dc898 515 write_memory (sp - 12, (char *)&buffer, sizeof(REGISTER_TYPE));
bd5635a1 516 buffer = read_register (FCRCS_REGNUM);
a70dc898 517 write_memory (sp - 16, (char *)&buffer, sizeof(REGISTER_TYPE));
bd5635a1
RP
518 sp -= 4 * (GEN_REG_SAVE_COUNT+FLOAT_REG_SAVE_COUNT+SPECIAL_REG_SAVE_COUNT);
519 write_register (SP_REGNUM, sp);
520 PROC_LOW_ADDR(proc_desc) = sp - CALL_DUMMY_SIZE + CALL_DUMMY_START_OFFSET;
521 PROC_HIGH_ADDR(proc_desc) = sp;
522 SET_PROC_DESC_IS_DUMMY(proc_desc);
523 PROC_PC_REG(proc_desc) = RA_REGNUM;
524}
525
526void
527mips_pop_frame()
528{ register int regnum;
529 FRAME frame = get_current_frame ();
530 CORE_ADDR new_sp = frame->frame;
a70dc898 531 mips_extra_func_info_t proc_desc = frame->proc_desc;
bd5635a1
RP
532 if (PROC_DESC_IS_DUMMY(proc_desc))
533 {
534 struct linked_proc_info **ptr = &linked_proc_desc_table;;
535 for (; &ptr[0]->info != proc_desc; ptr = &ptr[0]->next )
536 if (ptr[0] == NULL) abort();
537 *ptr = ptr[0]->next;
538 free (ptr[0]);
539 write_register (HI_REGNUM, read_memory_integer(new_sp - 8, 4));
540 write_register (LO_REGNUM, read_memory_integer(new_sp - 12, 4));
541 write_register (FCRCS_REGNUM, read_memory_integer(new_sp - 16, 4));
542 }
543 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
544 if (frame->proc_desc) {
545 for (regnum = 32; --regnum >= 0; )
546 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
547 write_register (regnum,
548 read_memory_integer (frame->saved_regs->regs[regnum], 4));
7d9884b9 549 for (regnum = 32; --regnum >= 0; )
bd5635a1 550 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
7d9884b9
JG
551 write_register (regnum + FP0_REGNUM,
552 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 4));
bd5635a1
RP
553 }
554 write_register (SP_REGNUM, new_sp);
555 flush_cached_frames ();
556 set_current_frame (create_new_frame (new_sp, read_pc ()));
557}
558
0f552c5f 559static void
a70dc898 560mips_print_register (regnum, all)
bd5635a1
RP
561 int regnum, all;
562{
a70dc898 563 unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE * 2]; /* *2 for doubles */
bd5635a1
RP
564 REGISTER_TYPE val;
565
5e2e79f8
FF
566 /* Get the data in raw format. */
567 if (read_relative_register_raw_bytes (regnum, raw_buffer))
568 {
569 printf_filtered ("%s: [Invalid]", reg_names[regnum]);
570 return;
571 }
572
d747e0af
MT
573 /* If an even floating pointer register, also print as double. */
574 if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM+32
575 && !((regnum-FP0_REGNUM) & 1)) {
bd5635a1 576 read_relative_register_raw_bytes (regnum+1, raw_buffer+4);
d747e0af 577 printf_filtered ("(d%d: ", regnum-FP0_REGNUM);
bd5635a1
RP
578 val_print (builtin_type_double, raw_buffer, 0,
579 stdout, 0, 1, 0, Val_pretty_default);
d747e0af 580 printf_filtered ("); ");
bd5635a1
RP
581 }
582 fputs_filtered (reg_names[regnum], stdout);
583#ifndef NUMERIC_REG_NAMES
584 if (regnum < 32)
585 printf_filtered ("(r%d): ", regnum);
586 else
587#endif
588 printf_filtered (": ");
589
590 /* If virtual format is floating, print it that way. */
591 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
592 && ! INVALID_FLOAT (raw_buffer, REGISTER_VIRTUAL_SIZE(regnum))) {
593 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0,
594 stdout, 0, 1, 0, Val_pretty_default);
595 }
596 /* Else print as integer in hex. */
597 else
598 {
599 long val;
600
601 bcopy (raw_buffer, &val, sizeof (long));
5e2e79f8 602 SWAP_TARGET_AND_HOST ((char *)&val, sizeof (long));
bd5635a1
RP
603 if (val == 0)
604 printf_filtered ("0");
605 else if (all)
d8b3b00e 606 printf_filtered (local_hex_format(), val);
bd5635a1 607 else
d8b3b00e 608 printf_filtered ("%s=%d", local_hex_string(val), val);
bd5635a1
RP
609 }
610}
611
d8b3b00e 612/* Replacement for generic do_registers_info. */
0f552c5f 613void
361bf6ee 614mips_do_registers_info (regnum, fpregs)
bd5635a1 615 int regnum;
361bf6ee 616 int fpregs;
bd5635a1
RP
617{
618 if (regnum != -1) {
619 mips_print_register (regnum, 0);
620 printf_filtered ("\n");
621 }
622 else {
623 for (regnum = 0; regnum < NUM_REGS; ) {
d8b3b00e
JG
624 if ((!fpregs) && regnum >= FP0_REGNUM && regnum <= FCRIR_REGNUM) {
625 regnum++;
626 continue;
627 }
bd5635a1
RP
628 mips_print_register (regnum, 1);
629 regnum++;
630 if ((regnum & 3) == 0 || regnum == NUM_REGS)
631 printf_filtered (";\n");
632 else
633 printf_filtered ("; ");
634 }
635 }
636}
637/* Return number of args passed to a frame. described by FIP.
638 Can return -1, meaning no way to tell. */
639
0f552c5f 640int
bd5635a1
RP
641mips_frame_num_args(fip)
642 FRAME fip;
643{
644#if 0
645 struct chain_info_t *p;
646
647 p = mips_find_cached_frame(FRAME_FP(fip));
648 if (p->valid)
649 return p->the_info.numargs;
650#endif
651 return -1;
652}
653
654\f
655/* Bad floats: Returns 0 if P points to a valid IEEE floating point number,
656 1 if P points to a denormalized number or a NaN. LEN says whether this is
657 a single-precision or double-precision float */
658#define SINGLE_EXP_BITS 8
659#define DOUBLE_EXP_BITS 11
660int
661isa_NAN(p, len)
662 int *p, len;
663{
664 int exponent;
665 if (len == 4)
666 {
667 exponent = *p;
668 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
669 return ((exponent == -1) || (! exponent && *p));
670 }
671 else if (len == 8)
672 {
673 exponent = *(p+1);
674 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
675 return ((exponent == -1) || (! exponent && *p * *(p+1)));
676 }
677 else return 1;
678}
407a8389 679\f
bd5635a1
RP
680/* To skip prologues, I use this predicate. Returns either PC
681 itself if the code at PC does not look like a function prologue,
682 PC+4 if it does (our caller does not need anything more fancy). */
683
be772100
JG
684CORE_ADDR
685mips_skip_prologue(pc)
bd5635a1
RP
686 CORE_ADDR pc;
687{
688 struct symbol *f;
689 struct block *b;
690 unsigned long inst;
d747e0af 691 int offset;
bd5635a1
RP
692
693 /* For -g modules and most functions anyways the
d747e0af
MT
694 first instruction adjusts the stack.
695 But we allow some number of stores before the stack adjustment.
696 (These are emitted by varags functions compiled by gcc-2.0. */
697 for (offset = 0; offset < 100; offset += 4) {
698 inst = read_memory_integer(pc + offset, 4);
699 if ((inst & 0xffff0000) == 0x27bd0000) /* addiu $sp,$sp,offset */
700 return pc + offset + 4;
701 if ((inst & 0xFFE00000) != 0xAFA00000) /* sw reg,n($sp) */
702 break;
703 }
bd5635a1
RP
704
705 /* Well, it looks like a frameless. Let's make sure.
706 Note that we are not called on the current PC,
707 but on the function`s start PC, and I have definitely
708 seen optimized code that adjusts the SP quite later */
709 b = block_for_pc(pc);
710 if (!b) return pc;
711
712 f = lookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, 0, NULL);
713 if (!f) return pc;
714 /* Ideally, I would like to use the adjusted info
715 from mips_frame_info(), but for all practical
716 purposes it will not matter (and it would require
717 a different definition of SKIP_PROLOGUE())
718
719 Actually, it would not hurt to skip the storing
720 of arguments on the stack as well. */
0f552c5f 721 if (((mips_extra_func_info_t)SYMBOL_VALUE(f))->pdr.frameoffset)
bd5635a1
RP
722 return pc + 4;
723
724 return pc;
725}
d747e0af
MT
726
727/* Figure out where the longjmp will land.
728 We expect the first arg to be a pointer to the jmp_buf structure from which
729 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
730 This routine returns true on success. */
731
732int
733get_longjmp_target(pc)
734 CORE_ADDR *pc;
735{
736 CORE_ADDR jb_addr;
737
738 jb_addr = read_register(A0_REGNUM);
739
740 if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, pc,
741 sizeof(CORE_ADDR)))
742 return 0;
743
744 SWAP_TARGET_AND_HOST(pc, sizeof(CORE_ADDR));
745
746 return 1;
747}
This page took 0.100217 seconds and 4 git commands to generate.