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