Reindented to GNU standard. No semantic changes. This checkin is to
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
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.
5
6 This file is part of GDB.
7
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.
12
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.
17
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. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "symtab.h"
26 #include "value.h"
27 #include "gdbcmd.h"
28 #include "language.h"
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
39 #include "gdbcore.h"
40 #include "symfile.h"
41 #include "objfiles.h"
42
43 #ifndef MIPSMAGIC
44 #ifdef MIPSEL
45 #define MIPSMAGIC MIPSELMAGIC
46 #else
47 #define MIPSMAGIC MIPSEBMAGIC
48 #endif
49 #endif
50
51 #define VM_MIN_ADDRESS (unsigned)0x400000
52
53 #include <sys/user.h> /* After a.out.h */
54 #include <sys/file.h>
55 #include <sys/stat.h>
56
57 \f
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_)
71
72 struct linked_proc_info
73 {
74 struct mips_extra_func_info info;
75 struct linked_proc_info *next;
76 } *linked_proc_desc_table = NULL;
77
78 \f
79 #define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
80
81 static int
82 read_next_frame_reg(fi, regno)
83 FRAME fi;
84 int regno;
85 {
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. */
93 int offset;
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;
97 else return 0;
98 return read_memory_integer(fi->frame + offset, 4);
99 }
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);
104 }
105
106 int
107 mips_frame_saved_pc(frame)
108 FRAME frame;
109 {
110 mips_extra_func_info_t proc_desc = frame->proc_desc;
111 int pcreg = proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM;
112
113 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
114 return read_memory_integer(frame->frame - 4, 4);
115
116 return read_next_frame_reg(frame, pcreg);
117 }
118
119 static struct mips_extra_func_info temp_proc_desc;
120 static struct frame_saved_regs temp_saved_regs;
121
122 static CORE_ADDR
123 heuristic_proc_start(pc)
124 CORE_ADDR pc;
125 {
126 CORE_ADDR start_pc = pc;
127 CORE_ADDR fence = start_pc - 200;
128
129 if (start_pc == 0) return 0;
130 if (fence < VM_MIN_ADDRESS) fence = VM_MIN_ADDRESS;
131
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))
136 break;
137
138 start_pc += 8; /* skip return, and its delay slot */
139 #if 0
140 /* skip nops (usually 1) 0 - is this */
141 while (start_pc < pc && read_memory_integer (start_pc, 4) == 0)
142 start_pc += 4;
143 #endif
144 return start_pc;
145 }
146
147 static mips_extra_func_info_t
148 heuristic_proc_desc(start_pc, limit_pc, next_frame)
149 CORE_ADDR start_pc, limit_pc;
150 FRAME next_frame;
151 {
152 CORE_ADDR sp = next_frame ? next_frame->frame : read_register (SP_REGNUM);
153 CORE_ADDR cur_pc;
154 int frame_size;
155 int has_frame_reg = 0;
156 int reg30; /* Value of $r30. Used by gcc for frame-pointer */
157 unsigned long reg_mask = 0;
158
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;
163
164 if (start_pc + 200 < limit_pc) limit_pc = start_pc + 200;
165 restart:
166 frame_size = 0;
167 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) {
168 unsigned long word;
169 int status;
170
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;
182 }
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) {
187 int alloca_adjust;
188 has_frame_reg = 1;
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.
195 */
196 sp += alloca_adjust;
197 goto restart;
198 }
199 }
200 }
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;
205 }
206 }
207 if (has_frame_reg) {
208 PROC_FRAME_REG(&temp_proc_desc) = 30;
209 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
210 }
211 else {
212 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
213 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
214 }
215 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
216 PROC_PC_REG(&temp_proc_desc) = RA_REGNUM;
217 return &temp_proc_desc;
218 }
219
220 static mips_extra_func_info_t
221 find_proc_desc(pc, next_frame)
222 CORE_ADDR pc;
223 FRAME next_frame;
224 {
225 mips_extra_func_info_t proc_desc;
226 struct block *b = block_for_pc(pc);
227 struct symbol *sym =
228 b ? lookup_symbol(MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL) : NULL;
229
230 if (sym)
231 {
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.
237 */
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);
243
244 if (proc_symbol) {
245 val = find_pc_line (BLOCK_START
246 (SYMBOL_BLOCK_VALUE(proc_symbol)),
247 0);
248 val.pc = val.end ? val.end : pc;
249 }
250 if (!proc_symbol || pc < val.pc) {
251 mips_extra_func_info_t found_heuristic =
252 heuristic_proc_desc(PROC_LOW_ADDR(proc_desc),
253 pc, next_frame);
254 if (found_heuristic) proc_desc = found_heuristic;
255 }
256 }
257 }
258 else
259 {
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! */
264
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)
269 return &link->info;
270 proc_desc =
271 heuristic_proc_desc(heuristic_proc_start(pc), pc, next_frame);
272 }
273 return proc_desc;
274 }
275
276 mips_extra_func_info_t cached_proc_desc;
277
278 FRAME_ADDR
279 mips_frame_chain(frame)
280 FRAME frame;
281 {
282 mips_extra_func_info_t proc_desc;
283 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
284
285 if (saved_pc == 0 || inside_entry_file (saved_pc))
286 return 0;
287
288 proc_desc = find_proc_desc(saved_pc, frame);
289 if (!proc_desc)
290 return 0;
291
292 cached_proc_desc = proc_desc;
293 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
294 + PROC_FRAME_OFFSET(proc_desc);
295 }
296
297 void
298 init_extra_frame_info(fci)
299 struct frame_info *fci;
300 {
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);
305
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));
309 fci->proc_desc =
310 proc_desc == &temp_proc_desc ? 0 : proc_desc;
311 if (proc_desc)
312 {
313 int ireg;
314 CORE_ADDR reg_position;
315 unsigned long mask;
316 /* r0 bit means kernel trap */
317 int kernel_trap = PROC_REG_MASK(proc_desc) & 1;
318
319 if (fci->frame == 0)
320 {
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);
325 else
326 fci->frame = READ_FRAME_REG(fci, PROC_FRAME_REG(proc_desc))
327 + PROC_FRAME_OFFSET(proc_desc);
328 }
329
330 if (proc_desc == &temp_proc_desc)
331 *fci->saved_regs = temp_saved_regs;
332 else
333 {
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)
339 {
340 fci->saved_regs->regs[ireg] = reg_position;
341 reg_position -= 4;
342 }
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. */
347 reg_position += 4;
348 mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
349 for (ireg = 31; mask; --ireg, mask <<= 1)
350 if (mask & 0x80000000)
351 {
352 fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
353 reg_position -= 4;
354 }
355 }
356
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;
363
364 fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
365 }
366 }
367
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.
373
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.
377
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. */
382
383 FRAME
384 setup_arbitrary_frame (stack, pc)
385 FRAME_ADDR stack;
386 CORE_ADDR pc;
387 {
388 return create_new_frame (stack, pc);
389 }
390
391
392 CORE_ADDR
393 mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
394 int nargs;
395 value *args;
396 CORE_ADDR sp;
397 int struct_return;
398 CORE_ADDR struct_addr;
399 {
400 CORE_ADDR buf;
401 register i;
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).
417 */
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);
422 }
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);
428 if (struct_return) {
429 buf = struct_addr;
430 write_memory(sp, (char *)&buf, sizeof(CORE_ADDR));
431 }
432 return sp;
433 }
434
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)
437
438 void
439 mips_push_dummy_frame()
440 {
441 int ireg;
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
456 /*
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.)
461 *
462 * Dummy frame layout:
463 * (high memory)
464 * Saved PC
465 * Saved MMHI, MMLO, FPC_CSR
466 * Saved R31
467 * Saved R28
468 * ...
469 * Saved R1
470 * Saved D18 (i.e. F19, F18)
471 * ...
472 * Saved D0 (i.e. F1, F0)
473 * CALL_DUMMY (subroutine stub; see m-mips.h)
474 * Parameter build area (not yet implemented)
475 * (low memory)
476 */
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))
487 {
488 buffer = read_register (ireg);
489 write_memory (save_address, (char *)&buffer, sizeof(REGISTER_TYPE));
490 save_address -= 4;
491 }
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))
496 {
497 buffer = read_register (ireg + FP0_REGNUM);
498 write_memory (save_address, (char *)&buffer, 4);
499 save_address -= 4;
500 }
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;
518 }
519
520 void
521 mips_pop_frame()
522 {
523 register int regnum;
524 FRAME frame = get_current_frame ();
525 CORE_ADDR new_sp = frame->frame;
526
527 mips_extra_func_info_t proc_desc = frame->proc_desc;
528
529 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
530 if (proc_desc)
531 {
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],
536 4));
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));
541 }
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 ()));
546
547 if (PROC_DESC_IS_DUMMY(proc_desc))
548 {
549 struct linked_proc_info *pi_ptr, *prev_ptr;
550
551 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
552 pi_ptr != NULL;
553 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
554 {
555 if (&pi_ptr->info == proc_desc)
556 break;
557 }
558
559 if (pi_ptr == NULL)
560 error ("Can't locate dummy extra frame info\n");
561
562 if (prev_ptr != NULL)
563 prev_ptr->next = pi_ptr->next;
564 else
565 linked_proc_desc_table = pi_ptr->next;
566
567 free (pi_ptr);
568
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));
572 }
573 }
574
575 static void
576 mips_print_register (regnum, all)
577 int regnum, all;
578 {
579 unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE * 2]; /* *2 for doubles */
580 REGISTER_TYPE val;
581
582 /* Get the data in raw format. */
583 if (read_relative_register_raw_bytes (regnum, raw_buffer))
584 {
585 printf_filtered ("%s: [Invalid]", reg_names[regnum]);
586 return;
587 }
588
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 ("); ");
597 }
598 fputs_filtered (reg_names[regnum], stdout);
599 #ifndef NUMERIC_REG_NAMES
600 if (regnum < 32)
601 printf_filtered ("(r%d): ", regnum);
602 else
603 #endif
604 printf_filtered (": ");
605
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);
611 }
612 /* Else print as integer in hex. */
613 else
614 {
615 long val;
616
617 bcopy (raw_buffer, &val, sizeof (long));
618 SWAP_TARGET_AND_HOST ((char *)&val, sizeof (long));
619 if (val == 0)
620 printf_filtered ("0");
621 else if (all)
622 printf_filtered (local_hex_format(), val);
623 else
624 printf_filtered ("%s=%d", local_hex_string(val), val);
625 }
626 }
627
628 /* Replacement for generic do_registers_info. */
629 void
630 mips_do_registers_info (regnum, fpregs)
631 int regnum;
632 int fpregs;
633 {
634 if (regnum != -1) {
635 mips_print_register (regnum, 0);
636 printf_filtered ("\n");
637 }
638 else {
639 for (regnum = 0; regnum < NUM_REGS; ) {
640 if ((!fpregs) && regnum >= FP0_REGNUM && regnum <= FCRIR_REGNUM) {
641 regnum++;
642 continue;
643 }
644 mips_print_register (regnum, 1);
645 regnum++;
646 if ((regnum & 3) == 0 || regnum == NUM_REGS)
647 printf_filtered (";\n");
648 else
649 printf_filtered ("; ");
650 }
651 }
652 }
653 /* Return number of args passed to a frame. described by FIP.
654 Can return -1, meaning no way to tell. */
655
656 int
657 mips_frame_num_args(fip)
658 FRAME fip;
659 {
660 #if 0
661 struct chain_info_t *p;
662
663 p = mips_find_cached_frame(FRAME_FP(fip));
664 if (p->valid)
665 return p->the_info.numargs;
666 #endif
667 return -1;
668 }
669
670 \f
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
676 int
677 isa_NAN(p, len)
678 int *p, len;
679 {
680 int exponent;
681 if (len == 4)
682 {
683 exponent = *p;
684 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
685 return ((exponent == -1) || (! exponent && *p));
686 }
687 else if (len == 8)
688 {
689 exponent = *(p+1);
690 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
691 return ((exponent == -1) || (! exponent && *p * *(p+1)));
692 }
693 else return 1;
694 }
695 \f
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). */
699
700 CORE_ADDR
701 mips_skip_prologue(pc)
702 CORE_ADDR pc;
703 {
704 struct symbol *f;
705 struct block *b;
706 unsigned long inst;
707 int offset;
708
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) */
718 break;
719 }
720
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);
726 if (!b) return pc;
727
728 f = lookup_symbol(MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
729 if (!f) return pc;
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())
734
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)
738 return pc + 4;
739
740 return pc;
741 }
This page took 0.045707 seconds and 4 git commands to generate.