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