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