Name change (It's hitacho micro systems, not hitachi data systems)
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
CommitLineData
7d9884b9
JG
1/* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
2 Copyright 1988, 1989, 1990, 1991 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 <stdio.h>
bd5635a1 23#include "defs.h"
bd5635a1
RP
24#include "frame.h"
25#include "inferior.h"
26#include "symtab.h"
27#include "value.h"
28#include "gdbcmd.h"
ef08856f 29#include "language.h"
bd5635a1
RP
30
31#ifdef USG
32#include <sys/types.h>
33#endif
34
35#include <sys/param.h>
36#include <sys/dir.h>
37#include <signal.h>
38#include <sys/ioctl.h>
39
40#include "gdbcore.h"
41
42#ifndef MIPSMAGIC
43#ifdef MIPSEL
44#define MIPSMAGIC MIPSELMAGIC
45#else
46#define MIPSMAGIC MIPSEBMAGIC
47#endif
48#endif
49
50#define VM_MIN_ADDRESS (unsigned)0x400000
51
52#include <sys/user.h> /* After a.out.h */
53#include <sys/file.h>
54#include <sys/stat.h>
55
56\f
57#define PROC_LOW_ADDR(proc) ((proc)->adr) /* least address */
58#define PROC_HIGH_ADDR(proc) ((proc)->pad2) /* upper address bound */
59#define PROC_FRAME_OFFSET(proc) ((proc)->framesize)
60#define PROC_FRAME_REG(proc) ((proc)->framereg)
61#define PROC_REG_MASK(proc) ((proc)->regmask)
62#define PROC_FREG_MASK(proc) ((proc)->fregmask)
63#define PROC_REG_OFFSET(proc) ((proc)->regoffset)
64#define PROC_FREG_OFFSET(proc) ((proc)->fregoffset)
65#define PROC_PC_REG(proc) ((proc)->pcreg)
66#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->isym)
67#define _PROC_MAGIC_ 0x0F0F0F0F
68#define PROC_DESC_IS_DUMMY(proc) ((proc)->isym == _PROC_MAGIC_)
69#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->isym = _PROC_MAGIC_)
70
71struct linked_proc_info
72{
73 struct mips_extra_func_info info;
74 struct linked_proc_info *next;
75} * linked_proc_desc_table = NULL;
76
77\f
78#define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
79
80int
81read_next_frame_reg(fi, regno)
82 FRAME fi;
83 int regno;
84{
85#define SIGFRAME_BASE sizeof(struct sigcontext)
86#define SIGFRAME_PC_OFF (-SIGFRAME_BASE+ 2*sizeof(int))
87#define SIGFRAME_SP_OFF (-SIGFRAME_BASE+32*sizeof(int))
88#define SIGFRAME_RA_OFF (-SIGFRAME_BASE+34*sizeof(int))
89 for (; fi; fi = fi->next)
90 if (in_sigtramp(fi->pc, 0)) {
91 /* No idea if this code works. --PB. */
92 int offset;
93 if (regno == PC_REGNUM) offset = SIGFRAME_PC_OFF;
94 else if (regno == RA_REGNUM) offset = SIGFRAME_RA_OFF;
95 else if (regno == SP_REGNUM) offset = SIGFRAME_SP_OFF;
96 else return 0;
97 return read_memory_integer(fi->frame + offset, 4);
98 }
99 else if (regno == SP_REGNUM) return fi->frame;
100 else if (fi->saved_regs->regs[regno])
101 return read_memory_integer(fi->saved_regs->regs[regno], 4);
102 return read_register(regno);
103}
104
105int
106mips_frame_saved_pc(frame)
107 FRAME frame;
108{
109 mips_extra_func_info_t proc_desc = (mips_extra_func_info_t)frame->proc_desc;
110 int pcreg = proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM;
111 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
112 return read_memory_integer(frame->frame - 4, 4);
113#if 0
114 /* If in the procedure prologue, RA_REGNUM might not have been saved yet.
115 * Assume non-leaf functions start with:
116 * addiu $sp,$sp,-frame_size
117 * sw $ra,ra_offset($sp)
118 * This if the pc is pointing at either of these instructions,
119 * then $ra hasn't been trashed.
120 * If the pc has advanced beyond these two instructions,
121 * then $ra has been saved.
122 * critical, and much more complex. Handling $ra is enough to get
123 * a stack trace, but some register values with be wrong.
124 */
125 if (frame->proc_desc && frame->pc < PROC_LOW_ADDR(proc_desc) + 8)
126 return read_register(pcreg);
127#endif
128 return read_next_frame_reg(frame, pcreg);
129}
130
131static struct mips_extra_func_info temp_proc_desc;
132static struct frame_saved_regs temp_saved_regs;
133
134CORE_ADDR heuristic_proc_start(pc)
135 CORE_ADDR pc;
136{
137
138 CORE_ADDR start_pc = pc;
139 CORE_ADDR fence = start_pc - 10000;
140 if (fence < VM_MIN_ADDRESS) fence = VM_MIN_ADDRESS;
141 /* search back for previous return */
142 for (start_pc -= 4; ; start_pc -= 4)
143 if (start_pc < fence) return 0;
144 else if (ABOUT_TO_RETURN(start_pc))
145 break;
146
147 start_pc += 8; /* skip return, and its delay slot */
148#if 0
149 /* skip nops (usually 1) 0 - is this */
150 while (start_pc < pc && read_memory_integer (start_pc, 4) == 0)
151 start_pc += 4;
152#endif
153 return start_pc;
154}
155
156mips_extra_func_info_t
157heuristic_proc_desc(start_pc, limit_pc, next_frame)
158 CORE_ADDR start_pc, limit_pc;
159 FRAME next_frame;
160{
161 CORE_ADDR sp = next_frame ? next_frame->frame : read_register (SP_REGNUM);
162 CORE_ADDR cur_pc;
163 int frame_size;
164 int has_frame_reg = 0;
165 int reg30; /* Value of $r30. Used by gcc for frame-pointer */
166 unsigned long reg_mask = 0;
167
168 if (start_pc == 0) return NULL;
169 bzero(&temp_proc_desc, sizeof(temp_proc_desc));
170 bzero(&temp_saved_regs, sizeof(struct frame_saved_regs));
171 if (start_pc + 200 < limit_pc) limit_pc = start_pc + 200;
172 restart:
173 frame_size = 0;
174 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
175 unsigned long word;
176 int status;
177
178 status = read_memory_nobpt (cur_pc, &word, 4);
179 if (status) memory_error (status, cur_pc);
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
226mips_extra_func_info_t
227find_proc_desc(pc, next_frame)
228 CORE_ADDR pc;
229 FRAME next_frame;
230{
231 mips_extra_func_info_t proc_desc;
232 extern struct block *block_for_pc();
233 struct block *b = block_for_pc(pc);
234
235 struct symbol *sym =
236 b ? lookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, 0, NULL) : NULL;
237 if (sym != NULL)
238 {
239 /* IF this is the topmost frame AND
240 * (this proc does not have debugging information OR
241 * the PC is in the procedure prologue)
242 * THEN create a "hueristic" proc_desc (by analyzing
243 * the actual code) to replace the "official" proc_desc.
244 */
245 proc_desc = (struct mips_extra_func_info *)sym->value.value;
246 if (next_frame == NULL) {
247 struct symtab_and_line val;
248 struct symbol *proc_symbol =
249 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
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 {
266 register struct linked_proc_info *link;
267 for (link = linked_proc_desc_table; link; link = link->next)
268 if (PROC_LOW_ADDR(&link->info) <= pc
269 && PROC_HIGH_ADDR(&link->info) > pc)
270 return &link->info;
271 proc_desc =
272 heuristic_proc_desc(heuristic_proc_start(pc), pc, next_frame);
273 }
274 return proc_desc;
275}
276
277mips_extra_func_info_t cached_proc_desc;
278
279FRAME_ADDR mips_frame_chain(frame)
280 FRAME frame;
281{
282 extern CORE_ADDR startup_file_start; /* From blockframe.c */
283 mips_extra_func_info_t proc_desc;
284 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
285 if (startup_file_start)
286 { /* has at least the __start symbol */
287 if (saved_pc == 0 || !outside_startup_file (saved_pc)) return 0;
288 }
289 else
290 { /* This hack depends on the internals of __start. */
291 /* We also assume the breakpoints are *not* inserted */
361bf6ee
JG
292 if (saved_pc == 0
293 || read_memory_integer (saved_pc + 8, 4) & 0xFC00003F == 0xD)
bd5635a1
RP
294 return 0; /* break */
295 }
296 proc_desc = find_proc_desc(saved_pc, frame);
297 if (!proc_desc) return 0;
298 cached_proc_desc = proc_desc;
299 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
300 + PROC_FRAME_OFFSET(proc_desc);
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);
311 fci->saved_regs = (struct frame_saved_regs*)
312 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
313 bzero(fci->saved_regs, sizeof(struct frame_saved_regs));
314 fci->proc_desc =
315 proc_desc == &temp_proc_desc ? (char*)NULL : (char*)proc_desc;
316 if (proc_desc)
317 {
318 int ireg;
319 CORE_ADDR reg_position;
320 unsigned long mask;
321 /* r0 bit means kernel trap */
322 int kernel_trap = PROC_REG_MASK(proc_desc) & 1;
323
324 /* Fixup frame-pointer - only needed for top frame */
325 /* This may not be quite right, if procedure has a real frame register */
326 if (fci->pc == PROC_LOW_ADDR(proc_desc))
327 fci->frame = read_register (SP_REGNUM);
328 else
329 fci->frame = READ_FRAME_REG(fci, PROC_FRAME_REG(proc_desc))
330 + PROC_FRAME_OFFSET(proc_desc);
331
332 if (proc_desc == &temp_proc_desc)
333 *fci->saved_regs = temp_saved_regs;
334 else
335 {
336 /* find which general-purpose registers were saved */
337 reg_position = fci->frame + PROC_REG_OFFSET(proc_desc);
338 mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
339 for (ireg= 31; mask; --ireg, mask <<= 1)
340 if (mask & 0x80000000)
341 {
342 fci->saved_regs->regs[ireg] = reg_position;
343 reg_position -= 4;
344 }
345 /* find which floating-point registers were saved */
346 reg_position = fci->frame + PROC_FREG_OFFSET(proc_desc);
347 /* The freg_offset points to where the first *double* register is saved.
348 * So skip to the high-order word. */
349 reg_position += 4;
350 mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
351 for (ireg = 31; mask; --ireg, mask <<= 1)
352 if (mask & 0x80000000)
353 {
354 fci->saved_regs->regs[32+ireg] = reg_position;
355 reg_position -= 4;
356 }
357 }
358
359 /* hack: if argument regs are saved, guess these contain args */
360 if ((PROC_REG_MASK(proc_desc) & 0xF0) == 0) fci->num_args = -1;
361 else if ((PROC_REG_MASK(proc_desc) & 0x80) == 0) fci->num_args = 4;
362 else if ((PROC_REG_MASK(proc_desc) & 0x40) == 0) fci->num_args = 3;
363 else if ((PROC_REG_MASK(proc_desc) & 0x20) == 0) fci->num_args = 2;
364 else if ((PROC_REG_MASK(proc_desc) & 0x10) == 0) fci->num_args = 1;
365
366 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
367 }
368 if (fci->next == 0)
369 supply_register(FP_REGNUM, &fci->frame);
370}
371
372
373CORE_ADDR mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
374 int nargs;
375 value *args;
376 CORE_ADDR sp;
377 int struct_return;
378 CORE_ADDR struct_addr;
379{
380 CORE_ADDR buf;
381 register i;
382 int accumulate_size = struct_return ? 4 : 0;
383 struct mips_arg { char *contents; int len; int offset; };
384 struct mips_arg *mips_args =
385 (struct mips_arg*)alloca(nargs * sizeof(struct mips_arg));
386 register struct mips_arg *m_arg;
387 for (i = 0, m_arg = mips_args; i < nargs; i++, m_arg++) {
388 extern value value_arg_coerce();
389 value arg = value_arg_coerce (args[i]);
390 m_arg->len = TYPE_LENGTH (VALUE_TYPE (arg));
391 /* This entire mips-specific routine is because doubles must be aligned
392 * on 8-byte boundaries. It still isn't quite right, because MIPS decided
393 * to align 'struct {int a, b}' on 4-byte boundaries (even though this
394 * breaks their varargs implementation...). A correct solution
395 * requires an simulation of gcc's 'alignof' (and use of 'alignof'
396 * in stdarg.h/varargs.h).
397 */
398 if (m_arg->len > 4) accumulate_size = (accumulate_size + 7) & -8;
399 m_arg->offset = accumulate_size;
400 accumulate_size = (accumulate_size + m_arg->len + 3) & -4;
401 m_arg->contents = VALUE_CONTENTS(arg);
402 }
403 accumulate_size = (accumulate_size + 7) & (-8);
404 if (accumulate_size < 16) accumulate_size = 16;
405 sp -= accumulate_size;
406 for (i = nargs; m_arg--, --i >= 0; )
407 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
408 if (struct_return) {
409 buf = struct_addr;
410 write_memory(sp, &buf, sizeof(CORE_ADDR));
411}
412 return sp;
413}
414
415/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
416#define MASK(i,j) ((1 << (j)+1)-1 ^ (1 << (i))-1)
417
418void
419mips_push_dummy_frame()
420{
421 int ireg;
422 struct linked_proc_info *link = (struct linked_proc_info*)
423 xmalloc(sizeof(struct linked_proc_info));
424 mips_extra_func_info_t proc_desc = &link->info;
425 CORE_ADDR sp = read_register (SP_REGNUM);
426 CORE_ADDR save_address;
427 REGISTER_TYPE buffer;
428 link->next = linked_proc_desc_table;
429 linked_proc_desc_table = link;
430#define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
431#define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<31)
432#define GEN_REG_SAVE_COUNT 22
433#define FLOAT_REG_SAVE_MASK MASK(0,19)
434#define FLOAT_REG_SAVE_COUNT 20
435#define SPECIAL_REG_SAVE_COUNT 4
436 /*
437 * The registers we must save are all those not preserved across
438 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
439 * In addition, we must save the PC, and PUSH_FP_REGNUM.
440 * (Ideally, we should also save MDLO/-HI and FP Control/Status reg.)
441 *
442 * Dummy frame layout:
443 * (high memory)
444 * Saved PC
445 * Saved MMHI, MMLO, FPC_CSR
446 * Saved R31
447 * Saved R28
448 * ...
449 * Saved R1
450 * Saved D18 (i.e. F19, F18)
451 * ...
452 * Saved D0 (i.e. F1, F0)
453 * CALL_DUMMY (subroutine stub; see m-mips.h)
454 * Parameter build area (not yet implemented)
455 * (low memory)
456 */
457 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
458 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
459 PROC_REG_OFFSET(proc_desc) = /* offset of (Saved R31) from FP */
460 -sizeof(long) - 4 * SPECIAL_REG_SAVE_COUNT;
461 PROC_FREG_OFFSET(proc_desc) = /* offset of (Saved D18) from FP */
462 -sizeof(double) - 4 * (SPECIAL_REG_SAVE_COUNT + GEN_REG_SAVE_COUNT);
463 /* save general registers */
464 save_address = sp + PROC_REG_OFFSET(proc_desc);
465 for (ireg = 32; --ireg >= 0; )
466 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
467 {
468 buffer = read_register (ireg);
469 write_memory (save_address, &buffer, sizeof(REGISTER_TYPE));
470 save_address -= 4;
471 }
472 /* save floating-points registers */
473 save_address = sp + PROC_FREG_OFFSET(proc_desc);
474 for (ireg = 32; --ireg >= 0; )
475 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
476 {
7d9884b9 477 buffer = read_register (ireg + FP0_REGNUM);
bd5635a1
RP
478 write_memory (save_address, &buffer, 4);
479 save_address -= 4;
480 }
481 write_register (PUSH_FP_REGNUM, sp);
482 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
483 PROC_FRAME_OFFSET(proc_desc) = 0;
484 buffer = read_register (PC_REGNUM);
485 write_memory (sp - 4, &buffer, sizeof(REGISTER_TYPE));
486 buffer = read_register (HI_REGNUM);
487 write_memory (sp - 8, &buffer, sizeof(REGISTER_TYPE));
488 buffer = read_register (LO_REGNUM);
489 write_memory (sp - 12, &buffer, sizeof(REGISTER_TYPE));
490 buffer = read_register (FCRCS_REGNUM);
491 write_memory (sp - 16, &buffer, sizeof(REGISTER_TYPE));
492 sp -= 4 * (GEN_REG_SAVE_COUNT+FLOAT_REG_SAVE_COUNT+SPECIAL_REG_SAVE_COUNT);
493 write_register (SP_REGNUM, sp);
494 PROC_LOW_ADDR(proc_desc) = sp - CALL_DUMMY_SIZE + CALL_DUMMY_START_OFFSET;
495 PROC_HIGH_ADDR(proc_desc) = sp;
496 SET_PROC_DESC_IS_DUMMY(proc_desc);
497 PROC_PC_REG(proc_desc) = RA_REGNUM;
498}
499
500void
501mips_pop_frame()
502{ register int regnum;
503 FRAME frame = get_current_frame ();
504 CORE_ADDR new_sp = frame->frame;
505 mips_extra_func_info_t proc_desc = (mips_extra_func_info_t)frame->proc_desc;
506 if (PROC_DESC_IS_DUMMY(proc_desc))
507 {
508 struct linked_proc_info **ptr = &linked_proc_desc_table;;
509 for (; &ptr[0]->info != proc_desc; ptr = &ptr[0]->next )
510 if (ptr[0] == NULL) abort();
511 *ptr = ptr[0]->next;
512 free (ptr[0]);
513 write_register (HI_REGNUM, read_memory_integer(new_sp - 8, 4));
514 write_register (LO_REGNUM, read_memory_integer(new_sp - 12, 4));
515 write_register (FCRCS_REGNUM, read_memory_integer(new_sp - 16, 4));
516 }
517 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
518 if (frame->proc_desc) {
519 for (regnum = 32; --regnum >= 0; )
520 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
521 write_register (regnum,
522 read_memory_integer (frame->saved_regs->regs[regnum], 4));
7d9884b9 523 for (regnum = 32; --regnum >= 0; )
bd5635a1 524 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
7d9884b9
JG
525 write_register (regnum + FP0_REGNUM,
526 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 4));
bd5635a1
RP
527 }
528 write_register (SP_REGNUM, new_sp);
529 flush_cached_frames ();
530 set_current_frame (create_new_frame (new_sp, read_pc ()));
531}
532
d8b3b00e
JG
533static
534mips_print_register(regnum, all)
bd5635a1
RP
535 int regnum, all;
536{
537 unsigned char raw_buffer[8];
538 REGISTER_TYPE val;
539
540 read_relative_register_raw_bytes (regnum, raw_buffer);
541
542 if (!(regnum & 1) && regnum >= FP0_REGNUM && regnum < FP0_REGNUM+32) {
543 read_relative_register_raw_bytes (regnum+1, raw_buffer+4);
544 printf_filtered ("(d%d: ", regnum&31);
545 val_print (builtin_type_double, raw_buffer, 0,
546 stdout, 0, 1, 0, Val_pretty_default);
547 printf_filtered ("); ", regnum&31);
548 }
549 fputs_filtered (reg_names[regnum], stdout);
550#ifndef NUMERIC_REG_NAMES
551 if (regnum < 32)
552 printf_filtered ("(r%d): ", regnum);
553 else
554#endif
555 printf_filtered (": ");
556
557 /* If virtual format is floating, print it that way. */
558 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
559 && ! INVALID_FLOAT (raw_buffer, REGISTER_VIRTUAL_SIZE(regnum))) {
560 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0,
561 stdout, 0, 1, 0, Val_pretty_default);
562 }
563 /* Else print as integer in hex. */
564 else
565 {
566 long val;
567
568 bcopy (raw_buffer, &val, sizeof (long));
569 if (val == 0)
570 printf_filtered ("0");
571 else if (all)
d8b3b00e 572 printf_filtered (local_hex_format(), val);
bd5635a1 573 else
d8b3b00e 574 printf_filtered ("%s=%d", local_hex_string(val), val);
bd5635a1
RP
575 }
576}
577
d8b3b00e 578/* Replacement for generic do_registers_info. */
361bf6ee 579mips_do_registers_info (regnum, fpregs)
bd5635a1 580 int regnum;
361bf6ee 581 int fpregs;
bd5635a1
RP
582{
583 if (regnum != -1) {
584 mips_print_register (regnum, 0);
585 printf_filtered ("\n");
586 }
587 else {
588 for (regnum = 0; regnum < NUM_REGS; ) {
d8b3b00e
JG
589 if ((!fpregs) && regnum >= FP0_REGNUM && regnum <= FCRIR_REGNUM) {
590 regnum++;
591 continue;
592 }
bd5635a1
RP
593 mips_print_register (regnum, 1);
594 regnum++;
595 if ((regnum & 3) == 0 || regnum == NUM_REGS)
596 printf_filtered (";\n");
597 else
598 printf_filtered ("; ");
599 }
600 }
601}
602/* Return number of args passed to a frame. described by FIP.
603 Can return -1, meaning no way to tell. */
604
605mips_frame_num_args(fip)
606 FRAME fip;
607{
608#if 0
609 struct chain_info_t *p;
610
611 p = mips_find_cached_frame(FRAME_FP(fip));
612 if (p->valid)
613 return p->the_info.numargs;
614#endif
615 return -1;
616}
617
618\f
619/* Bad floats: Returns 0 if P points to a valid IEEE floating point number,
620 1 if P points to a denormalized number or a NaN. LEN says whether this is
621 a single-precision or double-precision float */
622#define SINGLE_EXP_BITS 8
623#define DOUBLE_EXP_BITS 11
624int
625isa_NAN(p, len)
626 int *p, len;
627{
628 int exponent;
629 if (len == 4)
630 {
631 exponent = *p;
632 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
633 return ((exponent == -1) || (! exponent && *p));
634 }
635 else if (len == 8)
636 {
637 exponent = *(p+1);
638 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
639 return ((exponent == -1) || (! exponent && *p * *(p+1)));
640 }
641 else return 1;
642}
643
644/* To skip prologues, I use this predicate. Returns either PC
645 itself if the code at PC does not look like a function prologue,
646 PC+4 if it does (our caller does not need anything more fancy). */
647
648CORE_ADDR mips_skip_prologue(pc)
649 CORE_ADDR pc;
650{
651 struct symbol *f;
652 struct block *b;
653 unsigned long inst;
654
655 /* For -g modules and most functions anyways the
656 first instruction adjusts the stack. */
657 inst = read_memory_integer(pc, 4);
658 if ((inst & 0xffff0000) == 0x27bd0000)
659 return pc + 4;
660
661 /* Well, it looks like a frameless. Let's make sure.
662 Note that we are not called on the current PC,
663 but on the function`s start PC, and I have definitely
664 seen optimized code that adjusts the SP quite later */
665 b = block_for_pc(pc);
666 if (!b) return pc;
667
668 f = lookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, 0, NULL);
669 if (!f) return pc;
670 /* Ideally, I would like to use the adjusted info
671 from mips_frame_info(), but for all practical
672 purposes it will not matter (and it would require
673 a different definition of SKIP_PROLOGUE())
674
675 Actually, it would not hurt to skip the storing
676 of arguments on the stack as well. */
677 if (((struct mips_extra_func_info *)f->value.value)->framesize)
678 return pc + 4;
679
680 return pc;
681}
This page took 0.071568 seconds and 4 git commands to generate.