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