* Patches from Jeffrey Law <law@cs.utah.edu>.
[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
440 msym = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe));
441
442 if (msym
443 && (strcmp (SYMBOL_NAME (msym), "_start") == 0))
444 return 0;
445 else
446 return 1;
447}
448
66a1aa07
SG
449/*
450 * These functions deal with saving and restoring register state
451 * around a function call in the inferior. They keep the stack
452 * double-word aligned; eventually, on an hp700, the stack will have
453 * to be aligned to a 64-byte boundary.
454 */
455
456int
457push_dummy_frame ()
458{
459 register CORE_ADDR sp;
460 register int regnum;
461 int int_buffer;
462 double freg_buffer;
463
464 /* Space for "arguments"; the RP goes in here. */
465 sp = read_register (SP_REGNUM) + 48;
466 int_buffer = read_register (RP_REGNUM) | 0x3;
467 write_memory (sp - 20, (char *)&int_buffer, 4);
468
469 int_buffer = read_register (FP_REGNUM);
470 write_memory (sp, (char *)&int_buffer, 4);
471
472 write_register (FP_REGNUM, sp);
473
474 sp += 8;
475
476 for (regnum = 1; regnum < 32; regnum++)
477 if (regnum != RP_REGNUM && regnum != FP_REGNUM)
478 sp = push_word (sp, read_register (regnum));
479
480 sp += 4;
481
482 for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++)
483 {
484 read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
485 sp = push_bytes (sp, (char *)&freg_buffer, 8);
486 }
487 sp = push_word (sp, read_register (IPSW_REGNUM));
488 sp = push_word (sp, read_register (SAR_REGNUM));
489 sp = push_word (sp, read_register (PCOQ_HEAD_REGNUM));
490 sp = push_word (sp, read_register (PCSQ_HEAD_REGNUM));
491 sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM));
492 sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM));
493 write_register (SP_REGNUM, sp);
494}
495
496find_dummy_frame_regs (frame, frame_saved_regs)
497 struct frame_info *frame;
498 struct frame_saved_regs *frame_saved_regs;
499{
500 CORE_ADDR fp = frame->frame;
501 int i;
502
503 frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3;
504 frame_saved_regs->regs[FP_REGNUM] = fp;
505 frame_saved_regs->regs[1] = fp + 8;
506 frame_saved_regs->regs[3] = fp + 12;
507
508 for (fp += 16, i = 5; i < 32; fp += 4, i++)
509 frame_saved_regs->regs[i] = fp;
510
511 fp += 4;
512 for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8)
513 frame_saved_regs->regs[i] = fp;
514
515 frame_saved_regs->regs[IPSW_REGNUM] = fp;
516 fp += 4;
517 frame_saved_regs->regs[SAR_REGNUM] = fp;
518 fp += 4;
519 frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp;
520 fp +=4;
521 frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp;
522 fp +=4;
523 frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp;
524 fp +=4;
525 frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp;
526}
527
528int
529hppa_pop_frame ()
530{
531 register FRAME frame = get_current_frame ();
532 register CORE_ADDR fp;
533 register int regnum;
534 struct frame_saved_regs fsr;
535 struct frame_info *fi;
536 double freg_buffer;
537
538 fi = get_frame_info (frame);
539 fp = fi->frame;
540 get_frame_saved_regs (fi, &fsr);
541
542 if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */
543 restore_pc_queue (&fsr);
544
545 for (regnum = 31; regnum > 0; regnum--)
546 if (fsr.regs[regnum])
547 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
548
549 for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--)
550 if (fsr.regs[regnum])
551 {
552 read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8);
553 write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
554 }
555
556 if (fsr.regs[IPSW_REGNUM])
557 write_register (IPSW_REGNUM,
558 read_memory_integer (fsr.regs[IPSW_REGNUM], 4));
559
560 if (fsr.regs[SAR_REGNUM])
561 write_register (SAR_REGNUM,
562 read_memory_integer (fsr.regs[SAR_REGNUM], 4));
563
564 if (fsr.regs[PCOQ_TAIL_REGNUM])
565 write_register (PCOQ_TAIL_REGNUM,
566 read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4));
567
568 write_register (FP_REGNUM, read_memory_integer (fp, 4));
569
570 if (fsr.regs[IPSW_REGNUM]) /* call dummy */
571 write_register (SP_REGNUM, fp - 48);
572 else
573 write_register (SP_REGNUM, fp);
574
575 flush_cached_frames ();
576 set_current_frame (create_new_frame (read_register (FP_REGNUM),
577 read_pc ()));
578}
579
580/*
581 * After returning to a dummy on the stack, restore the instruction
582 * queue space registers. */
583
584static int
585restore_pc_queue (fsr)
586 struct frame_saved_regs *fsr;
587{
588 CORE_ADDR pc = read_pc ();
589 CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4);
590 int pid;
591 WAITTYPE w;
592 int insn_count;
593
594 /* Advance past break instruction in the call dummy. */
595 write_register (PCOQ_HEAD_REGNUM, pc + 4);
596 write_register (PCOQ_TAIL_REGNUM, pc + 8);
597
598 /*
599 * HPUX doesn't let us set the space registers or the space
600 * registers of the PC queue through ptrace. Boo, hiss.
601 * Conveniently, the call dummy has this sequence of instructions
602 * after the break:
603 * mtsp r21, sr0
604 * ble,n 0(sr0, r22)
605 *
606 * So, load up the registers and single step until we are in the
607 * right place.
608 */
609
610 write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4));
611 write_register (22, new_pc);
612
613 for (insn_count = 0; insn_count < 3; insn_count++)
614 {
615 resume (1, 0);
616 target_wait(&w);
617
618 if (!WIFSTOPPED (w))
619 {
620 stop_signal = WTERMSIG (w);
621 terminal_ours_for_output ();
622 printf ("\nProgram terminated with signal %d, %s\n",
623 stop_signal, safe_strsignal (stop_signal));
624 fflush (stdout);
625 return 0;
626 }
627 }
628 fetch_inferior_registers (-1);
629 return 1;
630}
631
632CORE_ADDR
633hppa_push_arguments (nargs, args, sp, struct_return, struct_addr)
634 int nargs;
635 value *args;
636 CORE_ADDR sp;
637 int struct_return;
638 CORE_ADDR struct_addr;
639{
640 /* array of arguments' offsets */
641 int *offset = (int *)alloca(nargs);
642 int cum = 0;
643 int i, alignment;
644
645 for (i = 0; i < nargs; i++)
646 {
647 /* Coerce chars to int & float to double if necessary */
648 args[i] = value_arg_coerce (args[i]);
649
650 cum += TYPE_LENGTH (VALUE_TYPE (args[i]));
651
652 /* value must go at proper alignment. Assume alignment is a
653 power of two.*/
654 alignment = hppa_alignof (VALUE_TYPE (args[i]));
655 if (cum % alignment)
656 cum = (cum + alignment) & -alignment;
657 offset[i] = -cum;
658 }
659 sp += min ((cum + 7) & -8, 16);
660
661 for (i = 0; i < nargs; i++)
662 write_memory (sp + offset[i], VALUE_CONTENTS (args[i]),
663 TYPE_LENGTH (VALUE_TYPE (args[i])));
664
665 if (struct_return)
666 write_register (28, struct_addr);
667 return sp + 32;
668}
669
670/*
671 * Insert the specified number of args and function address
672 * into a call sequence of the above form stored at DUMMYNAME.
673 *
674 * On the hppa we need to call the stack dummy through $$dyncall.
675 * Therefore our version of FIX_CALL_DUMMY takes an extra argument,
676 * real_pc, which is the location where gdb should start up the
677 * inferior to do the function call.
678 */
679
680CORE_ADDR
681hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p)
682 REGISTER_TYPE *dummy;
683 CORE_ADDR pc;
684 CORE_ADDR fun;
685 int nargs;
686 value *args;
687 struct type *type;
688 int gcc_p;
689{
690 CORE_ADDR dyncall_addr, sr4export_addr;
691 struct minimal_symbol *msymbol;
692
693 msymbol = lookup_minimal_symbol ("$$dyncall", (struct objfile *) NULL);
694 if (msymbol == NULL)
695 error ("Can't find an address for $$dyncall trampoline");
696
697 dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol);
698
699 msymbol = lookup_minimal_symbol ("_sr4export", (struct objfile *) NULL);
700 if (msymbol == NULL)
701 error ("Can't find an address for _sr4export trampoline");
702
703 sr4export_addr = SYMBOL_VALUE_ADDRESS (msymbol);
704
705 dummy[9] = deposit_21 (fun >> 11, dummy[9]);
706 dummy[10] = deposit_14 (fun & MASK_11, dummy[10]);
707 dummy[12] = deposit_21 (sr4export_addr >> 11, dummy[12]);
708 dummy[13] = deposit_14 (sr4export_addr & MASK_11, dummy[13]);
709
710 write_register (22, pc);
711
712 return dyncall_addr;
713}
714
715/* return the alignment of a type in bytes. Structures have the maximum
716 alignment required by their fields. */
717
718static int
719hppa_alignof (arg)
720 struct type *arg;
721{
722 int max_align, align, i;
723 switch (TYPE_CODE (arg))
724 {
725 case TYPE_CODE_PTR:
726 case TYPE_CODE_INT:
727 case TYPE_CODE_FLT:
728 return TYPE_LENGTH (arg);
729 case TYPE_CODE_ARRAY:
730 return hppa_alignof (TYPE_FIELD_TYPE (arg, 0));
731 case TYPE_CODE_STRUCT:
732 case TYPE_CODE_UNION:
733 max_align = 2;
734 for (i = 0; i < TYPE_NFIELDS (arg); i++)
735 {
736 /* Bit fields have no real alignment. */
737 if (!TYPE_FIELD_BITPOS (arg, i))
738 {
739 align = hppa_alignof (TYPE_FIELD_TYPE (arg, i));
740 max_align = max (max_align, align);
741 }
742 }
743 return max_align;
744 default:
745 return 4;
746 }
747}
748
749/* Print the register regnum, or all registers if regnum is -1 */
750
751pa_do_registers_info (regnum, fpregs)
752 int regnum;
753 int fpregs;
754{
755 char raw_regs [REGISTER_BYTES];
756 int i;
757
758 for (i = 0; i < NUM_REGS; i++)
759 read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i));
760 if (regnum == -1)
761 pa_print_registers (raw_regs, regnum, fpregs);
762 else if (regnum < FP0_REGNUM)
763 printf ("%s %x\n", reg_names[regnum], *(long *)(raw_regs +
764 REGISTER_BYTE (regnum)));
765 else
766 pa_print_fp_reg (regnum);
767}
768
769pa_print_registers (raw_regs, regnum, fpregs)
770 char *raw_regs;
771 int regnum;
772 int fpregs;
773{
774 int i;
775
776 for (i = 0; i < 18; i++)
777 printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n",
778 reg_names[i],
779 *(int *)(raw_regs + REGISTER_BYTE (i)),
780 reg_names[i + 18],
781 *(int *)(raw_regs + REGISTER_BYTE (i + 18)),
782 reg_names[i + 36],
783 *(int *)(raw_regs + REGISTER_BYTE (i + 36)),
784 reg_names[i + 54],
785 *(int *)(raw_regs + REGISTER_BYTE (i + 54)));
786
787 if (fpregs)
788 for (i = 72; i < NUM_REGS; i++)
789 pa_print_fp_reg (i);
790}
791
792pa_print_fp_reg (i)
793 int i;
794{
795 unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE];
796 unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
797 REGISTER_TYPE val;
798
799 /* Get the data in raw format, then convert also to virtual format. */
800 read_relative_register_raw_bytes (i, raw_buffer);
801 REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer);
802
803 fputs_filtered (reg_names[i], stdout);
804 print_spaces_filtered (15 - strlen (reg_names[i]), stdout);
805
806 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0,
807 1, 0, Val_pretty_default);
808 printf_filtered ("\n");
809}
810
811/* Function calls that pass into a new compilation unit must pass through a
812 small piece of code that does long format (`external' in HPPA parlance)
813 jumps. We figure out where the trampoline is going to end up, and return
814 the PC of the final destination. If we aren't in a trampoline, we just
815 return NULL.
816
817 For computed calls, we just extract the new PC from r22. */
818
819CORE_ADDR
820skip_trampoline_code (pc, name)
821 CORE_ADDR pc;
822 char *name;
823{
824 long inst0, inst1;
825 static CORE_ADDR dyncall = 0;
826 struct minimal_symbol *msym;
827
828/* FIXME XXX - dyncall must be initialized whenever we get a new exec file */
829
830 if (!dyncall)
831 {
832 msym = lookup_minimal_symbol ("$$dyncall", NULL);
833 if (msym)
834 dyncall = SYMBOL_VALUE_ADDRESS (msym);
835 else
836 dyncall = -1;
837 }
838
839 if (pc == dyncall)
840 return (CORE_ADDR)(read_register (22) & ~0x3);
841
842 inst0 = read_memory_integer (pc, 4);
843 inst1 = read_memory_integer (pc+4, 4);
844
845 if ( (inst0 & 0xffe00000) == 0x20200000 /* ldil xxx, r1 */
846 && (inst1 & 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */
847 pc = extract_21 (inst0) + extract_17 (inst1);
848 else
849 pc = (CORE_ADDR)NULL;
850
851 return pc;
852}
853
854/* Advance PC across any function entry prologue instructions
855 to reach some "real" code. */
856
857/* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp)
858 for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */
859
860CORE_ADDR
861skip_prologue(pc)
862 CORE_ADDR pc;
863{
864 int inst;
865 int status;
866
867 status = target_read_memory (pc, (char *)&inst, 4);
868 SWAP_TARGET_AND_HOST (&inst, sizeof (inst));
869 if (status != 0)
870 return pc;
871
872 if (inst == 0x6BC23FD9) /* stw rp,-20(sp) */
873 {
874 if (read_memory_integer (pc + 4, 4) == 0x8040241) /* copy r4,r1 */
875 pc += 16;
876 else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */
877 pc += 8;
878 }
879 else if (read_memory_integer (pc, 4) == 0x8040241) /* copy r4,r1 */
880 pc += 12;
881 else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */
882 pc += 4;
883
884 return pc;
885}
886
887static void
888unwind_command (exp, from_tty)
889 char *exp;
890 int from_tty;
891{
892 CORE_ADDR address;
893 union
894 {
895 int *foo;
896 struct unwind_table_entry *u;
897 } xxx;
898
899 /* If we have an expression, evaluate it and use it as the address. */
900
901 if (exp != 0 && *exp != 0)
902 address = parse_and_eval_address (exp);
903 else
904 return;
905
906 xxx.u = find_unwind_entry (address);
907
908 if (!xxx.u)
909 {
910 printf ("Can't find unwind table entry for PC 0x%x\n", address);
911 return;
912 }
913
914 printf ("%08x\n%08X\n%08X\n%08X\n", xxx.foo[0], xxx.foo[1], xxx.foo[2],
915 xxx.foo[3]);
916}
917
918void
919_initialize_hppah_tdep ()
920{
921 add_com ("unwind", class_obscure, unwind_command, "Print unwind info\n");
922 add_show_from_set
923 (add_set_cmd ("use_unwind", class_obscure, var_boolean,
924 (char *)&use_unwind,
925 "Set the usage of unwind info", &setlist),
926 &showlist);
927}
This page took 0.057027 seconds and 4 git commands to generate.