* hppa-tdep.c (find_proc_framesize): If there is a frame pointer,
[deliverable/binutils-gdb.git] / gdb / hppa-tdep.c
1 /* Machine-dependent code which would otherwise be in inflow.c and core.c,
2 for GDB, the GNU debugger. This code is for the HP PA-RISC cpu.
3 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24 #include "defs.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "value.h"
28
29 /* For argument passing to the inferior */
30 #include "symtab.h"
31
32 #ifdef USG
33 #include <sys/types.h>
34 #endif
35
36 #include <sys/param.h>
37 #include <sys/dir.h>
38 #include <signal.h>
39 #include <sys/ioctl.h>
40
41 #ifdef COFF_ENCAPSULATE
42 #include "a.out.encap.h"
43 #else
44 #include <a.out.h>
45 #endif
46 #ifndef N_SET_MAGIC
47 #define N_SET_MAGIC(exec, val) ((exec).a_magic = (val))
48 #endif
49
50 /*#include <sys/user.h> After a.out.h */
51 #include <sys/file.h>
52 #include <sys/stat.h>
53 #include <machine/psl.h>
54 #include "wait.h"
55
56 #include "gdbcore.h"
57 #include "gdbcmd.h"
58 #include "target.h"
59 #include "symfile.h"
60 #include "objfiles.h"
61
62 static int restore_pc_queue PARAMS ((struct frame_saved_regs *fsr));
63 static int hppa_alignof PARAMS ((struct type *arg));
64 CORE_ADDR frame_saved_pc PARAMS ((FRAME frame));
65
66 \f
67 /* Routines to extract various sized constants out of hppa
68 instructions. */
69
70 /* This assumes that no garbage lies outside of the lower bits of
71 value. */
72
73 int
74 sign_extend (val, bits)
75 unsigned val, bits;
76 {
77 return (int)(val >> bits - 1 ? (-1 << bits) | val : val);
78 }
79
80 /* For many immediate values the sign bit is the low bit! */
81
82 int
83 low_sign_extend (val, bits)
84 unsigned val, bits;
85 {
86 return (int)((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
87 }
88 /* extract the immediate field from a ld{bhw}s instruction */
89
90 unsigned
91 get_field (val, from, to)
92 unsigned val, from, to;
93 {
94 val = val >> 31 - to;
95 return val & ((1 << 32 - from) - 1);
96 }
97
98 unsigned
99 set_field (val, from, to, new_val)
100 unsigned *val, from, to;
101 {
102 unsigned mask = ~((1 << (to - from + 1)) << (31 - from));
103 return *val = *val & mask | (new_val << (31 - from));
104 }
105
106 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
107
108 extract_3 (word)
109 unsigned word;
110 {
111 return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);
112 }
113
114 extract_5_load (word)
115 unsigned word;
116 {
117 return low_sign_extend (word >> 16 & MASK_5, 5);
118 }
119
120 /* extract the immediate field from a st{bhw}s instruction */
121
122 int
123 extract_5_store (word)
124 unsigned word;
125 {
126 return low_sign_extend (word & MASK_5, 5);
127 }
128
129 /* extract the immediate field from a break instruction */
130
131 unsigned
132 extract_5r_store (word)
133 unsigned word;
134 {
135 return (word & MASK_5);
136 }
137
138 /* extract the immediate field from a {sr}sm instruction */
139
140 unsigned
141 extract_5R_store (word)
142 unsigned word;
143 {
144 return (word >> 16 & MASK_5);
145 }
146
147 /* extract an 11 bit immediate field */
148
149 int
150 extract_11 (word)
151 unsigned word;
152 {
153 return low_sign_extend (word & MASK_11, 11);
154 }
155
156 /* extract a 14 bit immediate field */
157
158 int
159 extract_14 (word)
160 unsigned word;
161 {
162 return low_sign_extend (word & MASK_14, 14);
163 }
164
165 /* deposit a 14 bit constant in a word */
166
167 unsigned
168 deposit_14 (opnd, word)
169 int opnd;
170 unsigned word;
171 {
172 unsigned sign = (opnd < 0 ? 1 : 0);
173
174 return word | ((unsigned)opnd << 1 & MASK_14) | sign;
175 }
176
177 /* extract a 21 bit constant */
178
179 int
180 extract_21 (word)
181 unsigned word;
182 {
183 int val;
184
185 word &= MASK_21;
186 word <<= 11;
187 val = GET_FIELD (word, 20, 20);
188 val <<= 11;
189 val |= GET_FIELD (word, 9, 19);
190 val <<= 2;
191 val |= GET_FIELD (word, 5, 6);
192 val <<= 5;
193 val |= GET_FIELD (word, 0, 4);
194 val <<= 2;
195 val |= GET_FIELD (word, 7, 8);
196 return sign_extend (val, 21) << 11;
197 }
198
199 /* deposit a 21 bit constant in a word. Although 21 bit constants are
200 usually the top 21 bits of a 32 bit constant, we assume that only
201 the low 21 bits of opnd are relevant */
202
203 unsigned
204 deposit_21 (opnd, word)
205 unsigned opnd, word;
206 {
207 unsigned val = 0;
208
209 val |= GET_FIELD (opnd, 11 + 14, 11 + 18);
210 val <<= 2;
211 val |= GET_FIELD (opnd, 11 + 12, 11 + 13);
212 val <<= 2;
213 val |= GET_FIELD (opnd, 11 + 19, 11 + 20);
214 val <<= 11;
215 val |= GET_FIELD (opnd, 11 + 1, 11 + 11);
216 val <<= 1;
217 val |= GET_FIELD (opnd, 11 + 0, 11 + 0);
218 return word | val;
219 }
220
221 /* extract a 12 bit constant from branch instructions */
222
223 int
224 extract_12 (word)
225 unsigned word;
226 {
227 return sign_extend (GET_FIELD (word, 19, 28) |
228 GET_FIELD (word, 29, 29) << 10 |
229 (word & 0x1) << 11, 12) << 2;
230 }
231
232 /* extract a 17 bit constant from branch instructions, returning the
233 19 bit signed value. */
234
235 int
236 extract_17 (word)
237 unsigned word;
238 {
239 return sign_extend (GET_FIELD (word, 19, 28) |
240 GET_FIELD (word, 29, 29) << 10 |
241 GET_FIELD (word, 11, 15) << 11 |
242 (word & 0x1) << 16, 17) << 2;
243 }
244 \f
245 static int use_unwind = 0;
246
247 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
248 of the objfiles seeking the unwind table entry for this PC. Each objfile
249 contains a sorted list of struct unwind_table_entry. Since we do a binary
250 search of the unwind tables, we depend upon them to be sorted. */
251
252 static struct unwind_table_entry *
253 find_unwind_entry(pc)
254 CORE_ADDR pc;
255 {
256 int first, middle, last;
257 struct objfile *objfile;
258
259 ALL_OBJFILES (objfile)
260 {
261 struct obj_unwind_info *ui;
262
263 ui = OBJ_UNWIND_INFO (objfile);
264
265 if (!ui)
266 continue;
267
268 /* First, check the cache */
269
270 if (ui->cache
271 && pc >= ui->cache->region_start
272 && pc <= ui->cache->region_end)
273 return ui->cache;
274
275 /* Not in the cache, do a binary search */
276
277 first = 0;
278 last = ui->last;
279
280 while (first <= last)
281 {
282 middle = (first + last) / 2;
283 if (pc >= ui->table[middle].region_start
284 && pc <= ui->table[middle].region_end)
285 {
286 ui->cache = &ui->table[middle];
287 return &ui->table[middle];
288 }
289
290 if (pc < ui->table[middle].region_start)
291 last = middle - 1;
292 else
293 first = middle + 1;
294 }
295 } /* ALL_OBJFILES() */
296 return NULL;
297 }
298
299 static int
300 find_return_regnum(pc)
301 CORE_ADDR pc;
302 {
303 struct unwind_table_entry *u;
304
305 u = find_unwind_entry (pc);
306
307 if (!u)
308 return RP_REGNUM;
309
310 if (u->Millicode)
311 return 31;
312
313 return RP_REGNUM;
314 }
315
316 int
317 find_proc_framesize(pc)
318 CORE_ADDR pc;
319 {
320 struct unwind_table_entry *u;
321
322 if (!use_unwind)
323 return -1;
324
325 u = find_unwind_entry (pc);
326
327 if (!u)
328 return -1;
329
330 if (u->Save_SP)
331 /* If this bit is set, it means there is a frame pointer and we should
332 use it. */
333 return -1;
334
335 return u->Total_frame_size << 3;
336 }
337
338 int
339 rp_saved(pc)
340 {
341 struct unwind_table_entry *u;
342
343 u = find_unwind_entry (pc);
344
345 if (!u)
346 return 0;
347
348 if (u->Save_RP)
349 return 1;
350 else
351 return 0;
352 }
353 \f
354 int
355 frameless_function_invocation (frame)
356 FRAME frame;
357 {
358
359 if (use_unwind)
360 {
361 struct unwind_table_entry *u;
362
363 u = find_unwind_entry (frame->pc);
364
365 if (u == 0)
366 return 0;
367
368 return (u->Total_frame_size == 0);
369 }
370 else
371 return frameless_look_for_prologue (frame);
372 }
373
374 CORE_ADDR
375 saved_pc_after_call (frame)
376 FRAME frame;
377 {
378 int ret_regnum;
379
380 ret_regnum = find_return_regnum (get_frame_pc (frame));
381
382 return read_register (ret_regnum) & ~0x3;
383 }
384 \f
385 CORE_ADDR
386 frame_saved_pc (frame)
387 FRAME frame;
388 {
389 CORE_ADDR pc = get_frame_pc (frame);
390
391 if (frameless_function_invocation (frame))
392 {
393 int ret_regnum;
394
395 ret_regnum = find_return_regnum (pc);
396
397 return read_register (ret_regnum) & ~0x3;
398 }
399 else if (rp_saved (pc))
400 return read_memory_integer (frame->frame - 20, 4) & ~0x3;
401 else
402 return read_register (RP_REGNUM) & ~0x3;
403 }
404 \f
405 /* We need to correct the PC and the FP for the outermost frame when we are
406 in a system call. */
407
408 void
409 init_extra_frame_info (fromleaf, frame)
410 int fromleaf;
411 struct frame_info *frame;
412 {
413 int flags;
414 int framesize;
415
416 if (frame->next) /* Only do this for outermost frame */
417 return;
418
419 flags = read_register (FLAGS_REGNUM);
420 if (flags & 2) /* In system call? */
421 frame->pc = read_register (31) & ~0x3;
422
423 /* The outermost frame is always derived from PC-framesize */
424 framesize = find_proc_framesize(frame->pc);
425 if (framesize == -1)
426 frame->frame = read_register (FP_REGNUM);
427 else
428 frame->frame = read_register (SP_REGNUM) - framesize;
429
430 if (!frameless_function_invocation (frame)) /* Frameless? */
431 return; /* No, quit now */
432
433 /* For frameless functions, we need to look at the caller's frame */
434 framesize = find_proc_framesize(FRAME_SAVED_PC(frame));
435 if (framesize != -1)
436 frame->frame -= framesize;
437 }
438 \f
439 FRAME_ADDR
440 frame_chain (frame)
441 struct frame_info *frame;
442 {
443 int framesize;
444
445 framesize = find_proc_framesize(FRAME_SAVED_PC(frame));
446
447 if (framesize != -1)
448 return frame->frame - framesize;
449
450 return read_memory_integer (frame->frame, 4);
451 }
452 \f
453 /* To see if a frame chain is valid, see if the caller looks like it
454 was compiled with gcc. */
455
456 int
457 frame_chain_valid (chain, thisframe)
458 FRAME_ADDR chain;
459 FRAME thisframe;
460 {
461 struct minimal_symbol *msym;
462
463 if (!chain)
464 return 0;
465
466 if (use_unwind)
467 {
468
469 struct unwind_table_entry *u;
470
471 u = find_unwind_entry (thisframe->pc);
472
473 if (u && (u->Save_SP || u->Total_frame_size))
474 return 1;
475 else
476 return 0;
477 }
478 else
479 {
480 msym = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe));
481
482 if (msym
483 && (strcmp (SYMBOL_NAME (msym), "_start") == 0))
484 return 0;
485 else
486 return 1;
487 }
488 }
489
490 /*
491 * These functions deal with saving and restoring register state
492 * around a function call in the inferior. They keep the stack
493 * double-word aligned; eventually, on an hp700, the stack will have
494 * to be aligned to a 64-byte boundary.
495 */
496
497 int
498 push_dummy_frame ()
499 {
500 register CORE_ADDR sp;
501 register int regnum;
502 int int_buffer;
503 double freg_buffer;
504
505 /* Space for "arguments"; the RP goes in here. */
506 sp = read_register (SP_REGNUM) + 48;
507 int_buffer = read_register (RP_REGNUM) | 0x3;
508 write_memory (sp - 20, (char *)&int_buffer, 4);
509
510 int_buffer = read_register (FP_REGNUM);
511 write_memory (sp, (char *)&int_buffer, 4);
512
513 write_register (FP_REGNUM, sp);
514
515 sp += 8;
516
517 for (regnum = 1; regnum < 32; regnum++)
518 if (regnum != RP_REGNUM && regnum != FP_REGNUM)
519 sp = push_word (sp, read_register (regnum));
520
521 sp += 4;
522
523 for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++)
524 {
525 read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
526 sp = push_bytes (sp, (char *)&freg_buffer, 8);
527 }
528 sp = push_word (sp, read_register (IPSW_REGNUM));
529 sp = push_word (sp, read_register (SAR_REGNUM));
530 sp = push_word (sp, read_register (PCOQ_HEAD_REGNUM));
531 sp = push_word (sp, read_register (PCSQ_HEAD_REGNUM));
532 sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM));
533 sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM));
534 write_register (SP_REGNUM, sp);
535 }
536
537 find_dummy_frame_regs (frame, frame_saved_regs)
538 struct frame_info *frame;
539 struct frame_saved_regs *frame_saved_regs;
540 {
541 CORE_ADDR fp = frame->frame;
542 int i;
543
544 frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3;
545 frame_saved_regs->regs[FP_REGNUM] = fp;
546 frame_saved_regs->regs[1] = fp + 8;
547
548 for (fp += 12, i = 3; i < 32; i++)
549 {
550 if (i != FP_REGNUM)
551 {
552 frame_saved_regs->regs[i] = fp;
553 fp += 4;
554 }
555 }
556
557 fp += 4;
558 for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8)
559 frame_saved_regs->regs[i] = fp;
560
561 frame_saved_regs->regs[IPSW_REGNUM] = fp;
562 frame_saved_regs->regs[SAR_REGNUM] = fp + 4;
563 frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp + 8;
564 frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp + 12;
565 frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp + 16;
566 frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp + 20;
567 }
568
569 int
570 hppa_pop_frame ()
571 {
572 register FRAME frame = get_current_frame ();
573 register CORE_ADDR fp;
574 register int regnum;
575 struct frame_saved_regs fsr;
576 struct frame_info *fi;
577 double freg_buffer;
578
579 fi = get_frame_info (frame);
580 fp = fi->frame;
581 get_frame_saved_regs (fi, &fsr);
582
583 if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */
584 restore_pc_queue (&fsr);
585
586 for (regnum = 31; regnum > 0; regnum--)
587 if (fsr.regs[regnum])
588 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
589
590 for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--)
591 if (fsr.regs[regnum])
592 {
593 read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8);
594 write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
595 }
596
597 if (fsr.regs[IPSW_REGNUM])
598 write_register (IPSW_REGNUM,
599 read_memory_integer (fsr.regs[IPSW_REGNUM], 4));
600
601 if (fsr.regs[SAR_REGNUM])
602 write_register (SAR_REGNUM,
603 read_memory_integer (fsr.regs[SAR_REGNUM], 4));
604
605 if (fsr.regs[PCOQ_TAIL_REGNUM])
606 write_register (PCOQ_TAIL_REGNUM,
607 read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4));
608
609 write_register (FP_REGNUM, read_memory_integer (fp, 4));
610
611 if (fsr.regs[IPSW_REGNUM]) /* call dummy */
612 write_register (SP_REGNUM, fp - 48);
613 else
614 write_register (SP_REGNUM, fp);
615
616 flush_cached_frames ();
617 set_current_frame (create_new_frame (read_register (FP_REGNUM),
618 read_pc ()));
619 }
620
621 /*
622 * After returning to a dummy on the stack, restore the instruction
623 * queue space registers. */
624
625 static int
626 restore_pc_queue (fsr)
627 struct frame_saved_regs *fsr;
628 {
629 CORE_ADDR pc = read_pc ();
630 CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4);
631 int pid;
632 WAITTYPE w;
633 int insn_count;
634
635 /* Advance past break instruction in the call dummy. */
636 write_register (PCOQ_HEAD_REGNUM, pc + 4);
637 write_register (PCOQ_TAIL_REGNUM, pc + 8);
638
639 /*
640 * HPUX doesn't let us set the space registers or the space
641 * registers of the PC queue through ptrace. Boo, hiss.
642 * Conveniently, the call dummy has this sequence of instructions
643 * after the break:
644 * mtsp r21, sr0
645 * ble,n 0(sr0, r22)
646 *
647 * So, load up the registers and single step until we are in the
648 * right place.
649 */
650
651 write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4));
652 write_register (22, new_pc);
653
654 for (insn_count = 0; insn_count < 3; insn_count++)
655 {
656 resume (1, 0);
657 target_wait(&w);
658
659 if (!WIFSTOPPED (w))
660 {
661 stop_signal = WTERMSIG (w);
662 terminal_ours_for_output ();
663 printf ("\nProgram terminated with signal %d, %s\n",
664 stop_signal, safe_strsignal (stop_signal));
665 fflush (stdout);
666 return 0;
667 }
668 }
669 fetch_inferior_registers (-1);
670 return 1;
671 }
672
673 CORE_ADDR
674 hppa_push_arguments (nargs, args, sp, struct_return, struct_addr)
675 int nargs;
676 value *args;
677 CORE_ADDR sp;
678 int struct_return;
679 CORE_ADDR struct_addr;
680 {
681 /* array of arguments' offsets */
682 int *offset = (int *)alloca(nargs * sizeof (int));
683 int cum = 0;
684 int i, alignment;
685
686 for (i = 0; i < nargs; i++)
687 {
688 /* Coerce chars to int & float to double if necessary */
689 args[i] = value_arg_coerce (args[i]);
690
691 cum += TYPE_LENGTH (VALUE_TYPE (args[i]));
692
693 /* value must go at proper alignment. Assume alignment is a
694 power of two.*/
695 alignment = hppa_alignof (VALUE_TYPE (args[i]));
696 if (cum % alignment)
697 cum = (cum + alignment) & -alignment;
698 offset[i] = -cum;
699 }
700 sp += max ((cum + 7) & -8, 16);
701
702 for (i = 0; i < nargs; i++)
703 write_memory (sp + offset[i], VALUE_CONTENTS (args[i]),
704 TYPE_LENGTH (VALUE_TYPE (args[i])));
705
706 if (struct_return)
707 write_register (28, struct_addr);
708 return sp + 32;
709 }
710
711 /*
712 * Insert the specified number of args and function address
713 * into a call sequence of the above form stored at DUMMYNAME.
714 *
715 * On the hppa we need to call the stack dummy through $$dyncall.
716 * Therefore our version of FIX_CALL_DUMMY takes an extra argument,
717 * real_pc, which is the location where gdb should start up the
718 * inferior to do the function call.
719 */
720
721 CORE_ADDR
722 hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p)
723 REGISTER_TYPE *dummy;
724 CORE_ADDR pc;
725 CORE_ADDR fun;
726 int nargs;
727 value *args;
728 struct type *type;
729 int gcc_p;
730 {
731 CORE_ADDR dyncall_addr, sr4export_addr;
732 struct minimal_symbol *msymbol;
733
734 msymbol = lookup_minimal_symbol ("$$dyncall", (struct objfile *) NULL);
735 if (msymbol == NULL)
736 error ("Can't find an address for $$dyncall trampoline");
737
738 dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol);
739
740 msymbol = lookup_minimal_symbol ("_sr4export", (struct objfile *) NULL);
741 if (msymbol == NULL)
742 error ("Can't find an address for _sr4export trampoline");
743
744 sr4export_addr = SYMBOL_VALUE_ADDRESS (msymbol);
745
746 dummy[9] = deposit_21 (fun >> 11, dummy[9]);
747 dummy[10] = deposit_14 (fun & MASK_11, dummy[10]);
748 dummy[12] = deposit_21 (sr4export_addr >> 11, dummy[12]);
749 dummy[13] = deposit_14 (sr4export_addr & MASK_11, dummy[13]);
750
751 write_register (22, pc);
752
753 return dyncall_addr;
754 }
755
756 /* return the alignment of a type in bytes. Structures have the maximum
757 alignment required by their fields. */
758
759 static int
760 hppa_alignof (arg)
761 struct type *arg;
762 {
763 int max_align, align, i;
764 switch (TYPE_CODE (arg))
765 {
766 case TYPE_CODE_PTR:
767 case TYPE_CODE_INT:
768 case TYPE_CODE_FLT:
769 return TYPE_LENGTH (arg);
770 case TYPE_CODE_ARRAY:
771 return hppa_alignof (TYPE_FIELD_TYPE (arg, 0));
772 case TYPE_CODE_STRUCT:
773 case TYPE_CODE_UNION:
774 max_align = 2;
775 for (i = 0; i < TYPE_NFIELDS (arg); i++)
776 {
777 /* Bit fields have no real alignment. */
778 if (!TYPE_FIELD_BITPOS (arg, i))
779 {
780 align = hppa_alignof (TYPE_FIELD_TYPE (arg, i));
781 max_align = max (max_align, align);
782 }
783 }
784 return max_align;
785 default:
786 return 4;
787 }
788 }
789
790 /* Print the register regnum, or all registers if regnum is -1 */
791
792 pa_do_registers_info (regnum, fpregs)
793 int regnum;
794 int fpregs;
795 {
796 char raw_regs [REGISTER_BYTES];
797 int i;
798
799 for (i = 0; i < NUM_REGS; i++)
800 read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i));
801 if (regnum == -1)
802 pa_print_registers (raw_regs, regnum, fpregs);
803 else if (regnum < FP0_REGNUM)
804 printf ("%s %x\n", reg_names[regnum], *(long *)(raw_regs +
805 REGISTER_BYTE (regnum)));
806 else
807 pa_print_fp_reg (regnum);
808 }
809
810 pa_print_registers (raw_regs, regnum, fpregs)
811 char *raw_regs;
812 int regnum;
813 int fpregs;
814 {
815 int i;
816
817 for (i = 0; i < 18; i++)
818 printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n",
819 reg_names[i],
820 *(int *)(raw_regs + REGISTER_BYTE (i)),
821 reg_names[i + 18],
822 *(int *)(raw_regs + REGISTER_BYTE (i + 18)),
823 reg_names[i + 36],
824 *(int *)(raw_regs + REGISTER_BYTE (i + 36)),
825 reg_names[i + 54],
826 *(int *)(raw_regs + REGISTER_BYTE (i + 54)));
827
828 if (fpregs)
829 for (i = 72; i < NUM_REGS; i++)
830 pa_print_fp_reg (i);
831 }
832
833 pa_print_fp_reg (i)
834 int i;
835 {
836 unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE];
837 unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
838 REGISTER_TYPE val;
839
840 /* Get the data in raw format, then convert also to virtual format. */
841 read_relative_register_raw_bytes (i, raw_buffer);
842 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
843
844 fputs_filtered (reg_names[i], stdout);
845 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
846
847 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0,
848 1, 0, Val_pretty_default);
849 printf_filtered ("\n");
850 }
851
852 /* Function calls that pass into a new compilation unit must pass through a
853 small piece of code that does long format (`external' in HPPA parlance)
854 jumps. We figure out where the trampoline is going to end up, and return
855 the PC of the final destination. If we aren't in a trampoline, we just
856 return NULL.
857
858 For computed calls, we just extract the new PC from r22. */
859
860 CORE_ADDR
861 skip_trampoline_code (pc, name)
862 CORE_ADDR pc;
863 char *name;
864 {
865 long inst0, inst1;
866 static CORE_ADDR dyncall = 0;
867 struct minimal_symbol *msym;
868
869 /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */
870
871 if (!dyncall)
872 {
873 msym = lookup_minimal_symbol ("$$dyncall", NULL);
874 if (msym)
875 dyncall = SYMBOL_VALUE_ADDRESS (msym);
876 else
877 dyncall = -1;
878 }
879
880 if (pc == dyncall)
881 return (CORE_ADDR)(read_register (22) & ~0x3);
882
883 inst0 = read_memory_integer (pc, 4);
884 inst1 = read_memory_integer (pc+4, 4);
885
886 if ( (inst0 & 0xffe00000) == 0x20200000 /* ldil xxx, r1 */
887 && (inst1 & 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */
888 pc = extract_21 (inst0) + extract_17 (inst1);
889 else
890 pc = (CORE_ADDR)NULL;
891
892 return pc;
893 }
894
895 /* Advance PC across any function entry prologue instructions
896 to reach some "real" code. */
897
898 /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp)
899 for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */
900
901 CORE_ADDR
902 skip_prologue(pc)
903 CORE_ADDR pc;
904 {
905 char buf[4];
906 unsigned long inst;
907 int status;
908
909 status = target_read_memory (pc, buf, 4);
910 inst = extract_unsigned_integer (buf, 4);
911 if (status != 0)
912 return pc;
913
914 if (inst == 0x6BC23FD9) /* stw rp,-20(sp) */
915 {
916 if (read_memory_integer (pc + 4, 4) == 0x8040241) /* copy r4,r1 */
917 pc += 16;
918 else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */
919 pc += 8;
920 }
921 else if (read_memory_integer (pc, 4) == 0x8040241) /* copy r4,r1 */
922 pc += 12;
923 else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */
924 pc += 4;
925
926 return pc;
927 }
928
929 static void
930 unwind_command (exp, from_tty)
931 char *exp;
932 int from_tty;
933 {
934 CORE_ADDR address;
935 union
936 {
937 int *foo;
938 struct unwind_table_entry *u;
939 } xxx;
940
941 /* If we have an expression, evaluate it and use it as the address. */
942
943 if (exp != 0 && *exp != 0)
944 address = parse_and_eval_address (exp);
945 else
946 return;
947
948 xxx.u = find_unwind_entry (address);
949
950 if (!xxx.u)
951 {
952 printf ("Can't find unwind table entry for PC 0x%x\n", address);
953 return;
954 }
955
956 printf ("%08x\n%08X\n%08X\n%08X\n", xxx.foo[0], xxx.foo[1], xxx.foo[2],
957 xxx.foo[3]);
958 }
959
960 void
961 _initialize_hppa_tdep ()
962 {
963 add_com ("unwind", class_obscure, unwind_command, "Print unwind info\n");
964 add_show_from_set
965 (add_set_cmd ("use_unwind", class_obscure, var_boolean,
966 (char *)&use_unwind,
967 "Set the usage of unwind info", &setlist),
968 &showlist);
969 }
This page took 0.049321 seconds and 5 git commands to generate.