1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
2 Copyright 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
4 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include <sys/types.h>
34 #include <sys/param.h>
37 #include <sys/ioctl.h>
45 #define MIPSMAGIC MIPSELMAGIC
47 #define MIPSMAGIC MIPSEBMAGIC
51 #define VM_MIN_ADDRESS (unsigned)0x400000
53 #include <sys/user.h> /* After a.out.h */
58 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
59 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
60 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
61 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
62 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
63 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
64 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
65 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
66 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
67 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
68 #define _PROC_MAGIC_ 0x0F0F0F0F
69 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
70 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
72 struct linked_proc_info
74 struct mips_extra_func_info info
;
75 struct linked_proc_info
*next
;
76 } *linked_proc_desc_table
= NULL
;
79 #define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
82 read_next_frame_reg(fi
, regno
)
86 #define SIGFRAME_BASE sizeof(struct sigcontext)
87 #define SIGFRAME_PC_OFF (-SIGFRAME_BASE+ 2*sizeof(int))
88 #define SIGFRAME_SP_OFF (-SIGFRAME_BASE+32*sizeof(int))
89 #define SIGFRAME_RA_OFF (-SIGFRAME_BASE+34*sizeof(int))
90 for (; fi
; fi
= fi
->next
)
91 if (in_sigtramp(fi
->pc
, 0)) {
92 /* No idea if this code works. --PB. */
94 if (regno
== PC_REGNUM
) offset
= SIGFRAME_PC_OFF
;
95 else if (regno
== RA_REGNUM
) offset
= SIGFRAME_RA_OFF
;
96 else if (regno
== SP_REGNUM
) offset
= SIGFRAME_SP_OFF
;
98 return read_memory_integer(fi
->frame
+ offset
, 4);
100 else if (regno
== SP_REGNUM
) return fi
->frame
;
101 else if (fi
->saved_regs
->regs
[regno
])
102 return read_memory_integer(fi
->saved_regs
->regs
[regno
], 4);
103 return read_register(regno
);
107 mips_frame_saved_pc(frame
)
110 mips_extra_func_info_t proc_desc
= frame
->proc_desc
;
111 int pcreg
= proc_desc
? PROC_PC_REG(proc_desc
) : RA_REGNUM
;
113 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
114 return read_memory_integer(frame
->frame
- 4, 4);
116 return read_next_frame_reg(frame
, pcreg
);
119 static struct mips_extra_func_info temp_proc_desc
;
120 static struct frame_saved_regs temp_saved_regs
;
123 heuristic_proc_start(pc
)
126 CORE_ADDR start_pc
= pc
;
127 CORE_ADDR fence
= start_pc
- 200;
129 if (start_pc
== 0) return 0;
130 if (fence
< VM_MIN_ADDRESS
) fence
= VM_MIN_ADDRESS
;
132 /* search back for previous return */
133 for (start_pc
-= 4; ; start_pc
-= 4)
134 if (start_pc
< fence
) return 0;
135 else if (ABOUT_TO_RETURN(start_pc
))
138 start_pc
+= 8; /* skip return, and its delay slot */
140 /* skip nops (usually 1) 0 - is this */
141 while (start_pc
< pc
&& read_memory_integer (start_pc
, 4) == 0)
147 static mips_extra_func_info_t
148 heuristic_proc_desc(start_pc
, limit_pc
, next_frame
)
149 CORE_ADDR start_pc
, limit_pc
;
152 CORE_ADDR sp
= next_frame
? next_frame
->frame
: read_register (SP_REGNUM
);
155 int has_frame_reg
= 0;
156 int reg30
; /* Value of $r30. Used by gcc for frame-pointer */
157 unsigned long reg_mask
= 0;
159 if (start_pc
== 0) return NULL
;
160 bzero(&temp_proc_desc
, sizeof(temp_proc_desc
));
161 bzero(&temp_saved_regs
, sizeof(struct frame_saved_regs
));
162 PROC_LOW_ADDR(&temp_proc_desc
) = start_pc
;
164 if (start_pc
+ 200 < limit_pc
) limit_pc
= start_pc
+ 200;
167 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4) {
171 status
= read_memory_nobpt (cur_pc
, (char *)&word
, 4);
172 if (status
) memory_error (status
, cur_pc
);
173 SWAP_TARGET_AND_HOST (&word
, sizeof (word
));
174 if ((word
& 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
175 frame_size
+= (-word
) & 0xFFFF;
176 else if ((word
& 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
177 frame_size
+= (-word
) & 0xFFFF;
178 else if ((word
& 0xFFE00000) == 0xafa00000) { /* sw reg,offset($sp) */
179 int reg
= (word
& 0x001F0000) >> 16;
180 reg_mask
|= 1 << reg
;
181 temp_saved_regs
.regs
[reg
] = sp
+ (short)word
;
183 else if ((word
& 0xFFFF0000) == 0x27be0000) { /* addiu $30,$sp,size */
184 if ((unsigned short)word
!= frame_size
)
185 reg30
= sp
+ (unsigned short)word
;
186 else if (!has_frame_reg
) {
189 reg30
= read_next_frame_reg(next_frame
, 30);
190 alloca_adjust
= reg30
- (sp
+ (unsigned short)word
);
191 if (alloca_adjust
> 0) {
192 /* FP > SP + frame_size. This may be because
193 /* of an alloca or somethings similar.
194 * Fix sp to "pre-alloca" value, and try again.
201 else if ((word
& 0xFFE00000) == 0xafc00000) { /* sw reg,offset($30) */
202 int reg
= (word
& 0x001F0000) >> 16;
203 reg_mask
|= 1 << reg
;
204 temp_saved_regs
.regs
[reg
] = reg30
+ (short)word
;
208 PROC_FRAME_REG(&temp_proc_desc
) = 30;
209 PROC_FRAME_OFFSET(&temp_proc_desc
) = 0;
212 PROC_FRAME_REG(&temp_proc_desc
) = SP_REGNUM
;
213 PROC_FRAME_OFFSET(&temp_proc_desc
) = frame_size
;
215 PROC_REG_MASK(&temp_proc_desc
) = reg_mask
;
216 PROC_PC_REG(&temp_proc_desc
) = RA_REGNUM
;
217 return &temp_proc_desc
;
220 static mips_extra_func_info_t
221 find_proc_desc(pc
, next_frame
)
225 mips_extra_func_info_t proc_desc
;
226 struct block
*b
= block_for_pc(pc
);
228 b
? lookup_symbol(MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, 0, NULL
) : NULL
;
232 /* IF this is the topmost frame AND
233 * (this proc does not have debugging information OR
234 * the PC is in the procedure prologue)
235 * THEN create a "heuristic" proc_desc (by analyzing
236 * the actual code) to replace the "official" proc_desc.
238 proc_desc
= (mips_extra_func_info_t
)SYMBOL_VALUE(sym
);
239 if (next_frame
== NULL
) {
240 struct symtab_and_line val
;
241 struct symbol
*proc_symbol
=
242 PROC_DESC_IS_DUMMY(proc_desc
) ? 0 : PROC_SYMBOL(proc_desc
);
245 val
= find_pc_line (BLOCK_START
246 (SYMBOL_BLOCK_VALUE(proc_symbol
)),
248 val
.pc
= val
.end
? val
.end
: pc
;
250 if (!proc_symbol
|| pc
< val
.pc
) {
251 mips_extra_func_info_t found_heuristic
=
252 heuristic_proc_desc(PROC_LOW_ADDR(proc_desc
),
254 if (found_heuristic
) proc_desc
= found_heuristic
;
260 /* Is linked_proc_desc_table really necessary? It only seems to be used
261 by procedure call dummys. However, the procedures being called ought
262 to have their own proc_descs, and even if they don't,
263 heuristic_proc_desc knows how to create them! */
265 register struct linked_proc_info
*link
;
266 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
267 if (PROC_LOW_ADDR(&link
->info
) <= pc
268 && PROC_HIGH_ADDR(&link
->info
) > pc
)
271 heuristic_proc_desc(heuristic_proc_start(pc
), pc
, next_frame
);
276 mips_extra_func_info_t cached_proc_desc
;
279 mips_frame_chain(frame
)
282 mips_extra_func_info_t proc_desc
;
283 CORE_ADDR saved_pc
= FRAME_SAVED_PC(frame
);
285 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
288 proc_desc
= find_proc_desc(saved_pc
, frame
);
292 cached_proc_desc
= proc_desc
;
293 return read_next_frame_reg(frame
, PROC_FRAME_REG(proc_desc
))
294 + PROC_FRAME_OFFSET(proc_desc
);
298 init_extra_frame_info(fci
)
299 struct frame_info
*fci
;
301 extern struct obstack frame_cache_obstack
;
302 /* Use proc_desc calculated in frame_chain */
303 mips_extra_func_info_t proc_desc
= fci
->next
? cached_proc_desc
:
304 find_proc_desc(fci
->pc
, fci
->next
);
306 fci
->saved_regs
= (struct frame_saved_regs
*)
307 obstack_alloc (&frame_cache_obstack
, sizeof(struct frame_saved_regs
));
308 bzero(fci
->saved_regs
, sizeof(struct frame_saved_regs
));
310 proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
314 CORE_ADDR reg_position
;
316 /* r0 bit means kernel trap */
317 int kernel_trap
= PROC_REG_MASK(proc_desc
) & 1;
321 /* Fixup frame-pointer - only needed for top frame */
322 /* This may not be quite right, if proc has a real frame register */
323 if (fci
->pc
== PROC_LOW_ADDR(proc_desc
))
324 fci
->frame
= read_register (SP_REGNUM
);
326 fci
->frame
= READ_FRAME_REG(fci
, PROC_FRAME_REG(proc_desc
))
327 + PROC_FRAME_OFFSET(proc_desc
);
330 if (proc_desc
== &temp_proc_desc
)
331 *fci
->saved_regs
= temp_saved_regs
;
334 /* find which general-purpose registers were saved */
335 reg_position
= fci
->frame
+ PROC_REG_OFFSET(proc_desc
);
336 mask
= kernel_trap
? 0xFFFFFFFF : PROC_REG_MASK(proc_desc
);
337 for (ireg
= 31; mask
; --ireg
, mask
<<= 1)
338 if (mask
& 0x80000000)
340 fci
->saved_regs
->regs
[ireg
] = reg_position
;
343 /* find which floating-point registers were saved */
344 reg_position
= fci
->frame
+ PROC_FREG_OFFSET(proc_desc
);
345 /* The freg_offset points to where the first *double* register is saved.
346 * So skip to the high-order word. */
348 mask
= kernel_trap
? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc
);
349 for (ireg
= 31; mask
; --ireg
, mask
<<= 1)
350 if (mask
& 0x80000000)
352 fci
->saved_regs
->regs
[FP0_REGNUM
+ireg
] = reg_position
;
357 /* hack: if argument regs are saved, guess these contain args */
358 if ((PROC_REG_MASK(proc_desc
) & 0xF0) == 0) fci
->num_args
= -1;
359 else if ((PROC_REG_MASK(proc_desc
) & 0x80) == 0) fci
->num_args
= 4;
360 else if ((PROC_REG_MASK(proc_desc
) & 0x40) == 0) fci
->num_args
= 3;
361 else if ((PROC_REG_MASK(proc_desc
) & 0x20) == 0) fci
->num_args
= 2;
362 else if ((PROC_REG_MASK(proc_desc
) & 0x10) == 0) fci
->num_args
= 1;
364 fci
->saved_regs
->regs
[PC_REGNUM
] = fci
->saved_regs
->regs
[RA_REGNUM
];
368 /* MIPS stack frames are almost impenetrable. When execution stops,
369 we basically have to look at symbol information for the function
370 that we stopped in, which tells us *which* register (if any) is
371 the base of the frame pointer, and what offset from that register
372 the frame itself is at.
374 This presents a problem when trying to examine a stack in memory
375 (that isn't executing at the moment), using the "frame" command. We
376 don't have a PC, nor do we have any registers except SP.
378 This routine takes two arguments, SP and PC, and tries to make the
379 cached frames look as if these two arguments defined a frame on the
380 cache. This allows the rest of info frame to extract the important
381 arguments without difficulty. */
384 setup_arbitrary_frame (stack
, pc
)
388 return create_new_frame (stack
, pc
);
393 mips_push_arguments(nargs
, args
, sp
, struct_return
, struct_addr
)
398 CORE_ADDR struct_addr
;
402 int accumulate_size
= struct_return
? 4 : 0;
403 struct mips_arg
{ char *contents
; int len
; int offset
; };
404 struct mips_arg
*mips_args
=
405 (struct mips_arg
*)alloca(nargs
* sizeof(struct mips_arg
));
406 register struct mips_arg
*m_arg
;
407 for (i
= 0, m_arg
= mips_args
; i
< nargs
; i
++, m_arg
++) {
408 extern value
value_arg_coerce();
409 value arg
= value_arg_coerce (args
[i
]);
410 m_arg
->len
= TYPE_LENGTH (VALUE_TYPE (arg
));
411 /* This entire mips-specific routine is because doubles must be aligned
412 * on 8-byte boundaries. It still isn't quite right, because MIPS decided
413 * to align 'struct {int a, b}' on 4-byte boundaries (even though this
414 * breaks their varargs implementation...). A correct solution
415 * requires an simulation of gcc's 'alignof' (and use of 'alignof'
416 * in stdarg.h/varargs.h).
418 if (m_arg
->len
> 4) accumulate_size
= (accumulate_size
+ 7) & -8;
419 m_arg
->offset
= accumulate_size
;
420 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 3) & -4;
421 m_arg
->contents
= VALUE_CONTENTS(arg
);
423 accumulate_size
= (accumulate_size
+ 7) & (-8);
424 if (accumulate_size
< 16) accumulate_size
= 16;
425 sp
-= accumulate_size
;
426 for (i
= nargs
; m_arg
--, --i
>= 0; )
427 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
430 write_memory(sp
, (char *)&buf
, sizeof(CORE_ADDR
));
435 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
436 #define MASK(i,j) ((1 << (j)+1)-1 ^ (1 << (i))-1)
439 mips_push_dummy_frame()
442 struct linked_proc_info
*link
= (struct linked_proc_info
*)
443 xmalloc(sizeof(struct linked_proc_info
));
444 mips_extra_func_info_t proc_desc
= &link
->info
;
445 CORE_ADDR sp
= read_register (SP_REGNUM
);
446 CORE_ADDR save_address
;
447 REGISTER_TYPE buffer
;
448 link
->next
= linked_proc_desc_table
;
449 linked_proc_desc_table
= link
;
450 #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
451 #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<31)
452 #define GEN_REG_SAVE_COUNT 22
453 #define FLOAT_REG_SAVE_MASK MASK(0,19)
454 #define FLOAT_REG_SAVE_COUNT 20
455 #define SPECIAL_REG_SAVE_COUNT 4
457 * The registers we must save are all those not preserved across
458 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
459 * In addition, we must save the PC, and PUSH_FP_REGNUM.
460 * (Ideally, we should also save MDLO/-HI and FP Control/Status reg.)
462 * Dummy frame layout:
465 * Saved MMHI, MMLO, FPC_CSR
470 * Saved D18 (i.e. F19, F18)
472 * Saved D0 (i.e. F1, F0)
473 * CALL_DUMMY (subroutine stub; see m-mips.h)
474 * Parameter build area (not yet implemented)
477 PROC_REG_MASK(proc_desc
) = GEN_REG_SAVE_MASK
;
478 PROC_FREG_MASK(proc_desc
) = FLOAT_REG_SAVE_MASK
;
479 PROC_REG_OFFSET(proc_desc
) = /* offset of (Saved R31) from FP */
480 -sizeof(long) - 4 * SPECIAL_REG_SAVE_COUNT
;
481 PROC_FREG_OFFSET(proc_desc
) = /* offset of (Saved D18) from FP */
482 -sizeof(double) - 4 * (SPECIAL_REG_SAVE_COUNT
+ GEN_REG_SAVE_COUNT
);
483 /* save general registers */
484 save_address
= sp
+ PROC_REG_OFFSET(proc_desc
);
485 for (ireg
= 32; --ireg
>= 0; )
486 if (PROC_REG_MASK(proc_desc
) & (1 << ireg
))
488 buffer
= read_register (ireg
);
489 write_memory (save_address
, (char *)&buffer
, sizeof(REGISTER_TYPE
));
492 /* save floating-points registers */
493 save_address
= sp
+ PROC_FREG_OFFSET(proc_desc
);
494 for (ireg
= 32; --ireg
>= 0; )
495 if (PROC_FREG_MASK(proc_desc
) & (1 << ireg
))
497 buffer
= read_register (ireg
+ FP0_REGNUM
);
498 write_memory (save_address
, (char *)&buffer
, 4);
501 write_register (PUSH_FP_REGNUM
, sp
);
502 PROC_FRAME_REG(proc_desc
) = PUSH_FP_REGNUM
;
503 PROC_FRAME_OFFSET(proc_desc
) = 0;
504 buffer
= read_register (PC_REGNUM
);
505 write_memory (sp
- 4, (char *)&buffer
, sizeof(REGISTER_TYPE
));
506 buffer
= read_register (HI_REGNUM
);
507 write_memory (sp
- 8, (char *)&buffer
, sizeof(REGISTER_TYPE
));
508 buffer
= read_register (LO_REGNUM
);
509 write_memory (sp
- 12, (char *)&buffer
, sizeof(REGISTER_TYPE
));
510 buffer
= read_register (FCRCS_REGNUM
);
511 write_memory (sp
- 16, (char *)&buffer
, sizeof(REGISTER_TYPE
));
512 sp
-= 4 * (GEN_REG_SAVE_COUNT
+FLOAT_REG_SAVE_COUNT
+SPECIAL_REG_SAVE_COUNT
);
513 write_register (SP_REGNUM
, sp
);
514 PROC_LOW_ADDR(proc_desc
) = sp
- CALL_DUMMY_SIZE
+ CALL_DUMMY_START_OFFSET
;
515 PROC_HIGH_ADDR(proc_desc
) = sp
;
516 SET_PROC_DESC_IS_DUMMY(proc_desc
);
517 PROC_PC_REG(proc_desc
) = RA_REGNUM
;
524 FRAME frame
= get_current_frame ();
525 CORE_ADDR new_sp
= frame
->frame
;
527 mips_extra_func_info_t proc_desc
= frame
->proc_desc
;
529 write_register (PC_REGNUM
, FRAME_SAVED_PC(frame
));
532 for (regnum
= 32; --regnum
>= 0; )
533 if (PROC_REG_MASK(proc_desc
) & (1 << regnum
))
534 write_register (regnum
,
535 read_memory_integer (frame
->saved_regs
->regs
[regnum
],
537 for (regnum
= 32; --regnum
>= 0; )
538 if (PROC_FREG_MASK(proc_desc
) & (1 << regnum
))
539 write_register (regnum
+ FP0_REGNUM
,
540 read_memory_integer (frame
->saved_regs
->regs
[regnum
+ FP0_REGNUM
], 4));
542 write_register (SP_REGNUM
, new_sp
);
543 flush_cached_frames ();
544 /* We let mips_init_extra_frame_info figure out the frame pointer */
545 set_current_frame (create_new_frame (0, read_pc ()));
547 if (PROC_DESC_IS_DUMMY(proc_desc
))
549 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
551 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
553 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
555 if (&pi_ptr
->info
== proc_desc
)
560 error ("Can't locate dummy extra frame info\n");
562 if (prev_ptr
!= NULL
)
563 prev_ptr
->next
= pi_ptr
->next
;
565 linked_proc_desc_table
= pi_ptr
->next
;
569 write_register (HI_REGNUM
, read_memory_integer(new_sp
- 8, 4));
570 write_register (LO_REGNUM
, read_memory_integer(new_sp
- 12, 4));
571 write_register (FCRCS_REGNUM
, read_memory_integer(new_sp
- 16, 4));
576 mips_print_register (regnum
, all
)
579 unsigned char raw_buffer
[MAX_REGISTER_RAW_SIZE
* 2]; /* *2 for doubles */
582 /* Get the data in raw format. */
583 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
585 printf_filtered ("%s: [Invalid]", reg_names
[regnum
]);
589 /* If an even floating pointer register, also print as double. */
590 if (regnum
>= FP0_REGNUM
&& regnum
< FP0_REGNUM
+32
591 && !((regnum
-FP0_REGNUM
) & 1)) {
592 read_relative_register_raw_bytes (regnum
+1, raw_buffer
+4);
593 printf_filtered ("(d%d: ", regnum
-FP0_REGNUM
);
594 val_print (builtin_type_double
, raw_buffer
, 0,
595 stdout
, 0, 1, 0, Val_pretty_default
);
596 printf_filtered ("); ");
598 fputs_filtered (reg_names
[regnum
], stdout
);
599 #ifndef NUMERIC_REG_NAMES
601 printf_filtered ("(r%d): ", regnum
);
604 printf_filtered (": ");
606 /* If virtual format is floating, print it that way. */
607 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum
)) == TYPE_CODE_FLT
608 && ! INVALID_FLOAT (raw_buffer
, REGISTER_VIRTUAL_SIZE(regnum
))) {
609 val_print (REGISTER_VIRTUAL_TYPE (regnum
), raw_buffer
, 0,
610 stdout
, 0, 1, 0, Val_pretty_default
);
612 /* Else print as integer in hex. */
617 bcopy (raw_buffer
, &val
, sizeof (long));
618 SWAP_TARGET_AND_HOST ((char *)&val
, sizeof (long));
620 printf_filtered ("0");
622 printf_filtered (local_hex_format(), val
);
624 printf_filtered ("%s=%d", local_hex_string(val
), val
);
628 /* Replacement for generic do_registers_info. */
630 mips_do_registers_info (regnum
, fpregs
)
635 mips_print_register (regnum
, 0);
636 printf_filtered ("\n");
639 for (regnum
= 0; regnum
< NUM_REGS
; ) {
640 if ((!fpregs
) && regnum
>= FP0_REGNUM
&& regnum
<= FCRIR_REGNUM
) {
644 mips_print_register (regnum
, 1);
646 if ((regnum
& 3) == 0 || regnum
== NUM_REGS
)
647 printf_filtered (";\n");
649 printf_filtered ("; ");
653 /* Return number of args passed to a frame. described by FIP.
654 Can return -1, meaning no way to tell. */
657 mips_frame_num_args(fip
)
661 struct chain_info_t
*p
;
663 p
= mips_find_cached_frame(FRAME_FP(fip
));
665 return p
->the_info
.numargs
;
671 /* Bad floats: Returns 0 if P points to a valid IEEE floating point number,
672 1 if P points to a denormalized number or a NaN. LEN says whether this is
673 a single-precision or double-precision float */
674 #define SINGLE_EXP_BITS 8
675 #define DOUBLE_EXP_BITS 11
684 exponent
= exponent
<< 1 >> (32 - SINGLE_EXP_BITS
- 1);
685 return ((exponent
== -1) || (! exponent
&& *p
));
690 exponent
= exponent
<< 1 >> (32 - DOUBLE_EXP_BITS
- 1);
691 return ((exponent
== -1) || (! exponent
&& *p
* *(p
+1)));
696 /* To skip prologues, I use this predicate. Returns either PC
697 itself if the code at PC does not look like a function prologue,
698 PC+4 if it does (our caller does not need anything more fancy). */
701 mips_skip_prologue(pc
)
709 /* For -g modules and most functions anyways the
710 first instruction adjusts the stack.
711 But we allow some number of stores before the stack adjustment.
712 (These are emitted by varags functions compiled by gcc-2.0. */
713 for (offset
= 0; offset
< 100; offset
+= 4) {
714 inst
= read_memory_integer(pc
+ offset
, 4);
715 if ((inst
& 0xffff0000) == 0x27bd0000) /* addiu $sp,$sp,offset */
716 return pc
+ offset
+ 4;
717 if ((inst
& 0xFFE00000) != 0xAFA00000) /* sw reg,n($sp) */
721 /* Well, it looks like a frameless. Let's make sure.
722 Note that we are not called on the current PC,
723 but on the function`s start PC, and I have definitely
724 seen optimized code that adjusts the SP quite later */
725 b
= block_for_pc(pc
);
728 f
= lookup_symbol(MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, 0, NULL
);
730 /* Ideally, I would like to use the adjusted info
731 from mips_frame_info(), but for all practical
732 purposes it will not matter (and it would require
733 a different definition of SKIP_PROLOGUE())
735 Actually, it would not hurt to skip the storing
736 of arguments on the stack as well. */
737 if (((mips_extra_func_info_t
)SYMBOL_VALUE(f
))->pdr
.frameoffset
)