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.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This file is part of GDB.
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.
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.
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. */
29 /* For argument passing to the inferior */
33 #include <sys/types.h>
36 #include <sys/param.h>
39 #include <sys/ioctl.h>
41 #ifdef COFF_ENCAPSULATE
42 #include "a.out.encap.h"
47 #define N_SET_MAGIC(exec, val) ((exec).a_magic = (val))
50 /*#include <sys/user.h> After a.out.h */
53 #include <machine/psl.h>
62 static int restore_pc_queue
PARAMS ((struct frame_saved_regs
*fsr
));
63 static int hppa_alignof
PARAMS ((struct type
*arg
));
64 CORE_ADDR frame_saved_pc
PARAMS ((FRAME frame
));
65 static int prologue_inst_adjust_sp
PARAMS ((unsigned long));
66 static int is_branch
PARAMS ((unsigned long));
67 static int inst_saves_gr
PARAMS ((unsigned long));
68 static int inst_saves_fr
PARAMS ((unsigned long));
71 /* Routines to extract various sized constants out of hppa
74 /* This assumes that no garbage lies outside of the lower bits of
78 sign_extend (val
, bits
)
81 return (int)(val
>> bits
- 1 ? (-1 << bits
) | val
: val
);
84 /* For many immediate values the sign bit is the low bit! */
87 low_sign_extend (val
, bits
)
90 return (int)((val
& 0x1 ? (-1 << (bits
- 1)) : 0) | val
>> 1);
92 /* extract the immediate field from a ld{bhw}s instruction */
95 get_field (val
, from
, to
)
96 unsigned val
, from
, to
;
99 return val
& ((1 << 32 - from
) - 1);
103 set_field (val
, from
, to
, new_val
)
104 unsigned *val
, from
, to
;
106 unsigned mask
= ~((1 << (to
- from
+ 1)) << (31 - from
));
107 return *val
= *val
& mask
| (new_val
<< (31 - from
));
110 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
115 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
118 extract_5_load (word
)
121 return low_sign_extend (word
>> 16 & MASK_5
, 5);
124 /* extract the immediate field from a st{bhw}s instruction */
127 extract_5_store (word
)
130 return low_sign_extend (word
& MASK_5
, 5);
133 /* extract the immediate field from a break instruction */
136 extract_5r_store (word
)
139 return (word
& MASK_5
);
142 /* extract the immediate field from a {sr}sm instruction */
145 extract_5R_store (word
)
148 return (word
>> 16 & MASK_5
);
151 /* extract an 11 bit immediate field */
157 return low_sign_extend (word
& MASK_11
, 11);
160 /* extract a 14 bit immediate field */
166 return low_sign_extend (word
& MASK_14
, 14);
169 /* deposit a 14 bit constant in a word */
172 deposit_14 (opnd
, word
)
176 unsigned sign
= (opnd
< 0 ? 1 : 0);
178 return word
| ((unsigned)opnd
<< 1 & MASK_14
) | sign
;
181 /* extract a 21 bit constant */
191 val
= GET_FIELD (word
, 20, 20);
193 val
|= GET_FIELD (word
, 9, 19);
195 val
|= GET_FIELD (word
, 5, 6);
197 val
|= GET_FIELD (word
, 0, 4);
199 val
|= GET_FIELD (word
, 7, 8);
200 return sign_extend (val
, 21) << 11;
203 /* deposit a 21 bit constant in a word. Although 21 bit constants are
204 usually the top 21 bits of a 32 bit constant, we assume that only
205 the low 21 bits of opnd are relevant */
208 deposit_21 (opnd
, word
)
213 val
|= GET_FIELD (opnd
, 11 + 14, 11 + 18);
215 val
|= GET_FIELD (opnd
, 11 + 12, 11 + 13);
217 val
|= GET_FIELD (opnd
, 11 + 19, 11 + 20);
219 val
|= GET_FIELD (opnd
, 11 + 1, 11 + 11);
221 val
|= GET_FIELD (opnd
, 11 + 0, 11 + 0);
225 /* extract a 12 bit constant from branch instructions */
231 return sign_extend (GET_FIELD (word
, 19, 28) |
232 GET_FIELD (word
, 29, 29) << 10 |
233 (word
& 0x1) << 11, 12) << 2;
236 /* extract a 17 bit constant from branch instructions, returning the
237 19 bit signed value. */
243 return sign_extend (GET_FIELD (word
, 19, 28) |
244 GET_FIELD (word
, 29, 29) << 10 |
245 GET_FIELD (word
, 11, 15) << 11 |
246 (word
& 0x1) << 16, 17) << 2;
249 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
250 of the objfiles seeking the unwind table entry for this PC. Each objfile
251 contains a sorted list of struct unwind_table_entry. Since we do a binary
252 search of the unwind tables, we depend upon them to be sorted. */
254 static struct unwind_table_entry
*
255 find_unwind_entry(pc
)
258 int first
, middle
, last
;
259 struct objfile
*objfile
;
261 ALL_OBJFILES (objfile
)
263 struct obj_unwind_info
*ui
;
265 ui
= OBJ_UNWIND_INFO (objfile
);
270 /* First, check the cache */
273 && pc
>= ui
->cache
->region_start
274 && pc
<= ui
->cache
->region_end
)
277 /* Not in the cache, do a binary search */
282 while (first
<= last
)
284 middle
= (first
+ last
) / 2;
285 if (pc
>= ui
->table
[middle
].region_start
286 && pc
<= ui
->table
[middle
].region_end
)
288 ui
->cache
= &ui
->table
[middle
];
289 return &ui
->table
[middle
];
292 if (pc
< ui
->table
[middle
].region_start
)
297 } /* ALL_OBJFILES() */
301 /* Called when no unwind descriptor was found for PC. Returns 1 if it
302 appears that PC is in a linker stub. */
303 static int pc_in_linker_stub
PARAMS ((CORE_ADDR
));
306 pc_in_linker_stub (pc
)
309 int found_magic_instruction
= 0;
313 /* If unable to read memory, assume pc is not in a linker stub. */
314 if (target_read_memory (pc
, buf
, 4) != 0)
317 /* We are looking for something like
319 ; $$dyncall jams RP into this special spot in the frame (RP')
320 ; before calling the "call stub"
323 ldsid (rp),r1 ; Get space associated with RP into r1
324 mtsp r1,sp ; Move it into space register 0
325 be,n 0(sr0),rp) ; back to your regularly scheduled program
328 /* Maximum known linker stub size is 4 instructions. Search forward
329 from the given PC, then backward. */
330 for (i
= 0; i
< 4; i
++)
332 /* If we hit something with an unwind, stop searching this direction. */
334 if (find_unwind_entry (pc
+ i
* 4) != 0)
337 /* Check for ldsid (rp),r1 which is the magic instruction for a
338 return from a cross-space function call. */
339 if (read_memory_integer (pc
+ i
* 4, 4) == 0x004010a1)
341 found_magic_instruction
= 1;
344 /* Add code to handle long call/branch and argument relocation stubs
348 if (found_magic_instruction
!= 0)
351 /* Now look backward. */
352 for (i
= 0; i
< 4; i
++)
354 /* If we hit something with an unwind, stop searching this direction. */
356 if (find_unwind_entry (pc
- i
* 4) != 0)
359 /* Check for ldsid (rp),r1 which is the magic instruction for a
360 return from a cross-space function call. */
361 if (read_memory_integer (pc
- i
* 4, 4) == 0x004010a1)
363 found_magic_instruction
= 1;
366 /* Add code to handle long call/branch and argument relocation stubs
369 return found_magic_instruction
;
373 find_return_regnum(pc
)
376 struct unwind_table_entry
*u
;
378 u
= find_unwind_entry (pc
);
389 /* Return size of frame, or -1 if we should use a frame pointer. */
391 find_proc_framesize(pc
)
394 struct unwind_table_entry
*u
;
396 u
= find_unwind_entry (pc
);
400 if (pc_in_linker_stub (pc
))
401 /* Linker stubs have a zero size frame. */
408 /* If this bit is set, it means there is a frame pointer and we should
412 return u
->Total_frame_size
<< 3;
415 /* Return offset from sp at which rp is saved, or 0 if not saved. */
416 static int rp_saved
PARAMS ((CORE_ADDR
));
422 struct unwind_table_entry
*u
;
424 u
= find_unwind_entry (pc
);
428 if (pc_in_linker_stub (pc
))
429 /* This is the so-called RP'. */
437 else if (u
->stub_type
!= 0)
439 switch (u
->stub_type
)
443 case PARAMETER_RELOCATION
:
454 frameless_function_invocation (frame
)
457 struct unwind_table_entry
*u
;
459 u
= find_unwind_entry (frame
->pc
);
462 return frameless_look_for_prologue (frame
);
464 return (u
->Total_frame_size
== 0 && u
->stub_type
== 0);
468 saved_pc_after_call (frame
)
473 ret_regnum
= find_return_regnum (get_frame_pc (frame
));
475 return read_register (ret_regnum
) & ~0x3;
479 frame_saved_pc (frame
)
482 CORE_ADDR pc
= get_frame_pc (frame
);
484 if (frameless_function_invocation (frame
))
488 ret_regnum
= find_return_regnum (pc
);
490 return read_register (ret_regnum
) & ~0x3;
494 int rp_offset
= rp_saved (pc
);
497 return read_register (RP_REGNUM
) & ~0x3;
499 return read_memory_integer (frame
->frame
+ rp_offset
, 4) & ~0x3;
503 /* We need to correct the PC and the FP for the outermost frame when we are
507 init_extra_frame_info (fromleaf
, frame
)
509 struct frame_info
*frame
;
514 if (frame
->next
&& !fromleaf
)
517 /* If the next frame represents a frameless function invocation
518 then we have to do some adjustments that are normally done by
519 FRAME_CHAIN. (FRAME_CHAIN is not called in this case.) */
522 /* Find the framesize of *this* frame without peeking at the PC
523 in the current frame structure (it isn't set yet). */
524 framesize
= find_proc_framesize (FRAME_SAVED_PC (get_next_frame (frame
)));
526 /* Now adjust our base frame accordingly. If we have a frame pointer
527 use it, else subtract the size of this frame from the current
528 frame. (we always want frame->frame to point at the lowest address
531 frame
->frame
= read_register (FP_REGNUM
);
533 frame
->frame
-= framesize
;
537 flags
= read_register (FLAGS_REGNUM
);
538 if (flags
& 2) /* In system call? */
539 frame
->pc
= read_register (31) & ~0x3;
541 /* The outermost frame is always derived from PC-framesize
543 One might think frameless innermost frames should have
544 a frame->frame that is the same as the parent's frame->frame.
545 That is wrong; frame->frame in that case should be the *high*
546 address of the parent's frame. It's complicated as hell to
547 explain, but the parent *always* creates some stack space for
548 the child. So the child actually does have a frame of some
549 sorts, and its base is the high address in its parent's frame. */
550 framesize
= find_proc_framesize(frame
->pc
);
552 frame
->frame
= read_register (FP_REGNUM
);
554 frame
->frame
= read_register (SP_REGNUM
) - framesize
;
557 /* Given a GDB frame, determine the address of the calling function's frame.
558 This will be used to create a new GDB frame struct, and then
559 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
561 This may involve searching through prologues for several functions
562 at boundaries where GCC calls HP C code, or where code which has
563 a frame pointer calls code without a frame pointer. */
568 struct frame_info
*frame
;
570 int my_framesize
, caller_framesize
;
571 struct unwind_table_entry
*u
;
573 /* Get frame sizes for the current frame and the frame of the
575 my_framesize
= find_proc_framesize (frame
->pc
);
576 caller_framesize
= find_proc_framesize (FRAME_SAVED_PC(frame
));
578 /* If caller does not have a frame pointer, then its frame
579 can be found at current_frame - caller_framesize. */
580 if (caller_framesize
!= -1)
581 return frame
->frame
- caller_framesize
;
583 /* Both caller and callee have frame pointers and are GCC compiled
584 (SAVE_SP bit in unwind descriptor is on for both functions.
585 The previous frame pointer is found at the top of the current frame. */
586 if (caller_framesize
== -1 && my_framesize
== -1)
587 return read_memory_integer (frame
->frame
, 4);
589 /* Caller has a frame pointer, but callee does not. This is a little
590 more difficult as GCC and HP C lay out locals and callee register save
591 areas very differently.
593 The previous frame pointer could be in a register, or in one of
594 several areas on the stack.
596 Walk from the current frame to the innermost frame examining
597 unwind descriptors to determine if %r3 ever gets saved into the
598 stack. If so return whatever value got saved into the stack.
599 If it was never saved in the stack, then the value in %r3 is still
602 We use information from unwind descriptors to determine if %r3
603 is saved into the stack (Entry_GR field has this information). */
607 u
= find_unwind_entry (frame
->pc
);
611 /* We could find this information by examining prologues. I don't
612 think anyone has actually written any tools (not even "strip")
613 which leave them out of an executable, so maybe this is a moot
615 warning ("Unable to find unwind for PC 0x%x -- Help!", frame
->pc
);
619 /* Entry_GR specifies the number of callee-saved general registers
620 saved in the stack. It starts at %r3, so %r3 would be 1. */
621 if (u
->Entry_GR
>= 1 || u
->Save_SP
)
629 /* We may have walked down the chain into a function with a frame
632 return read_memory_integer (frame
->frame
, 4);
633 /* %r3 was saved somewhere in the stack. Dig it out. */
636 struct frame_info
*fi
;
637 struct frame_saved_regs saved_regs
;
639 fi
= get_frame_info (frame
);
640 get_frame_saved_regs (fi
, &saved_regs
);
641 return read_memory_integer (saved_regs
.regs
[FP_REGNUM
], 4);
646 /* The value in %r3 was never saved into the stack (thus %r3 still
647 holds the value of the previous frame pointer). */
648 return read_register (FP_REGNUM
);
653 /* To see if a frame chain is valid, see if the caller looks like it
654 was compiled with gcc. */
657 frame_chain_valid (chain
, thisframe
)
661 struct minimal_symbol
*msym_us
;
662 struct minimal_symbol
*msym_start
;
663 struct unwind_table_entry
*u
;
668 u
= find_unwind_entry (thisframe
->pc
);
670 /* We can't just check that the same of msym_us is "_start", because
671 someone idiotically decided that they were going to make a Ltext_end
672 symbol with the same address. This Ltext_end symbol is totally
673 indistinguishable (as nearly as I can tell) from the symbol for a function
674 which is (legitimately, since it is in the user's namespace)
675 named Ltext_end, so we can't just ignore it. */
676 msym_us
= lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe
));
677 msym_start
= lookup_minimal_symbol ("_start", NULL
);
680 && SYMBOL_VALUE_ADDRESS (msym_us
) == SYMBOL_VALUE_ADDRESS (msym_start
))
686 if (u
->Save_SP
|| u
->Total_frame_size
|| u
->stub_type
!= 0)
689 if (pc_in_linker_stub (thisframe
->pc
))
696 * These functions deal with saving and restoring register state
697 * around a function call in the inferior. They keep the stack
698 * double-word aligned; eventually, on an hp700, the stack will have
699 * to be aligned to a 64-byte boundary.
705 register CORE_ADDR sp
;
710 /* Space for "arguments"; the RP goes in here. */
711 sp
= read_register (SP_REGNUM
) + 48;
712 int_buffer
= read_register (RP_REGNUM
) | 0x3;
713 write_memory (sp
- 20, (char *)&int_buffer
, 4);
715 int_buffer
= read_register (FP_REGNUM
);
716 write_memory (sp
, (char *)&int_buffer
, 4);
718 write_register (FP_REGNUM
, sp
);
722 for (regnum
= 1; regnum
< 32; regnum
++)
723 if (regnum
!= RP_REGNUM
&& regnum
!= FP_REGNUM
)
724 sp
= push_word (sp
, read_register (regnum
));
728 for (regnum
= FP0_REGNUM
; regnum
< NUM_REGS
; regnum
++)
730 read_register_bytes (REGISTER_BYTE (regnum
), (char *)&freg_buffer
, 8);
731 sp
= push_bytes (sp
, (char *)&freg_buffer
, 8);
733 sp
= push_word (sp
, read_register (IPSW_REGNUM
));
734 sp
= push_word (sp
, read_register (SAR_REGNUM
));
735 sp
= push_word (sp
, read_register (PCOQ_HEAD_REGNUM
));
736 sp
= push_word (sp
, read_register (PCSQ_HEAD_REGNUM
));
737 sp
= push_word (sp
, read_register (PCOQ_TAIL_REGNUM
));
738 sp
= push_word (sp
, read_register (PCSQ_TAIL_REGNUM
));
739 write_register (SP_REGNUM
, sp
);
742 find_dummy_frame_regs (frame
, frame_saved_regs
)
743 struct frame_info
*frame
;
744 struct frame_saved_regs
*frame_saved_regs
;
746 CORE_ADDR fp
= frame
->frame
;
749 frame_saved_regs
->regs
[RP_REGNUM
] = fp
- 20 & ~0x3;
750 frame_saved_regs
->regs
[FP_REGNUM
] = fp
;
751 frame_saved_regs
->regs
[1] = fp
+ 8;
753 for (fp
+= 12, i
= 3; i
< 32; i
++)
757 frame_saved_regs
->regs
[i
] = fp
;
763 for (i
= FP0_REGNUM
; i
< NUM_REGS
; i
++, fp
+= 8)
764 frame_saved_regs
->regs
[i
] = fp
;
766 frame_saved_regs
->regs
[IPSW_REGNUM
] = fp
;
767 frame_saved_regs
->regs
[SAR_REGNUM
] = fp
+ 4;
768 frame_saved_regs
->regs
[PCOQ_HEAD_REGNUM
] = fp
+ 8;
769 frame_saved_regs
->regs
[PCSQ_HEAD_REGNUM
] = fp
+ 12;
770 frame_saved_regs
->regs
[PCOQ_TAIL_REGNUM
] = fp
+ 16;
771 frame_saved_regs
->regs
[PCSQ_TAIL_REGNUM
] = fp
+ 20;
777 register FRAME frame
= get_current_frame ();
778 register CORE_ADDR fp
;
780 struct frame_saved_regs fsr
;
781 struct frame_info
*fi
;
784 fi
= get_frame_info (frame
);
786 get_frame_saved_regs (fi
, &fsr
);
788 if (fsr
.regs
[IPSW_REGNUM
]) /* Restoring a call dummy frame */
789 restore_pc_queue (&fsr
);
791 for (regnum
= 31; regnum
> 0; regnum
--)
792 if (fsr
.regs
[regnum
])
793 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
], 4));
795 for (regnum
= NUM_REGS
- 1; regnum
>= FP0_REGNUM
; regnum
--)
796 if (fsr
.regs
[regnum
])
798 read_memory (fsr
.regs
[regnum
], (char *)&freg_buffer
, 8);
799 write_register_bytes (REGISTER_BYTE (regnum
), (char *)&freg_buffer
, 8);
802 if (fsr
.regs
[IPSW_REGNUM
])
803 write_register (IPSW_REGNUM
,
804 read_memory_integer (fsr
.regs
[IPSW_REGNUM
], 4));
806 if (fsr
.regs
[SAR_REGNUM
])
807 write_register (SAR_REGNUM
,
808 read_memory_integer (fsr
.regs
[SAR_REGNUM
], 4));
810 /* If the PC was explicitly saved, then just restore it. */
811 if (fsr
.regs
[PCOQ_TAIL_REGNUM
])
812 write_register (PCOQ_TAIL_REGNUM
,
813 read_memory_integer (fsr
.regs
[PCOQ_TAIL_REGNUM
], 4));
815 /* Else use the value in %rp to set the new PC. */
817 target_write_pc (read_register (RP_REGNUM
));
819 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
821 if (fsr
.regs
[IPSW_REGNUM
]) /* call dummy */
822 write_register (SP_REGNUM
, fp
- 48);
824 write_register (SP_REGNUM
, fp
);
826 flush_cached_frames ();
827 set_current_frame (create_new_frame (read_register (FP_REGNUM
),
832 * After returning to a dummy on the stack, restore the instruction
833 * queue space registers. */
836 restore_pc_queue (fsr
)
837 struct frame_saved_regs
*fsr
;
839 CORE_ADDR pc
= read_pc ();
840 CORE_ADDR new_pc
= read_memory_integer (fsr
->regs
[PCOQ_HEAD_REGNUM
], 4);
842 struct target_waitstatus w
;
845 /* Advance past break instruction in the call dummy. */
846 write_register (PCOQ_HEAD_REGNUM
, pc
+ 4);
847 write_register (PCOQ_TAIL_REGNUM
, pc
+ 8);
850 * HPUX doesn't let us set the space registers or the space
851 * registers of the PC queue through ptrace. Boo, hiss.
852 * Conveniently, the call dummy has this sequence of instructions
857 * So, load up the registers and single step until we are in the
861 write_register (21, read_memory_integer (fsr
->regs
[PCSQ_HEAD_REGNUM
], 4));
862 write_register (22, new_pc
);
864 for (insn_count
= 0; insn_count
< 3; insn_count
++)
866 /* FIXME: What if the inferior gets a signal right now? Want to
867 merge this into wait_for_inferior (as a special kind of
868 watchpoint? By setting a breakpoint at the end? Is there
869 any other choice? Is there *any* way to do this stuff with
870 ptrace() or some equivalent?). */
872 target_wait (inferior_pid
, &w
);
874 if (w
.kind
== TARGET_WAITKIND_SIGNALLED
)
876 stop_signal
= w
.value
.sig
;
877 terminal_ours_for_output ();
878 printf_unfiltered ("\nProgram terminated with signal %s, %s.\n",
879 target_signal_to_name (stop_signal
),
880 target_signal_to_string (stop_signal
));
881 gdb_flush (gdb_stdout
);
885 target_terminal_ours ();
886 fetch_inferior_registers (-1);
891 hppa_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
896 CORE_ADDR struct_addr
;
898 /* array of arguments' offsets */
899 int *offset
= (int *)alloca(nargs
* sizeof (int));
903 for (i
= 0; i
< nargs
; i
++)
905 /* Coerce chars to int & float to double if necessary */
906 args
[i
] = value_arg_coerce (args
[i
]);
908 cum
+= TYPE_LENGTH (VALUE_TYPE (args
[i
]));
910 /* value must go at proper alignment. Assume alignment is a
912 alignment
= hppa_alignof (VALUE_TYPE (args
[i
]));
914 cum
= (cum
+ alignment
) & -alignment
;
917 sp
+= max ((cum
+ 7) & -8, 16);
919 for (i
= 0; i
< nargs
; i
++)
920 write_memory (sp
+ offset
[i
], VALUE_CONTENTS (args
[i
]),
921 TYPE_LENGTH (VALUE_TYPE (args
[i
])));
924 write_register (28, struct_addr
);
929 * Insert the specified number of args and function address
930 * into a call sequence of the above form stored at DUMMYNAME.
932 * On the hppa we need to call the stack dummy through $$dyncall.
933 * Therefore our version of FIX_CALL_DUMMY takes an extra argument,
934 * real_pc, which is the location where gdb should start up the
935 * inferior to do the function call.
939 hppa_fix_call_dummy (dummy
, pc
, fun
, nargs
, args
, type
, gcc_p
)
948 CORE_ADDR dyncall_addr
, sr4export_addr
;
949 struct minimal_symbol
*msymbol
;
950 int flags
= read_register (FLAGS_REGNUM
);
952 msymbol
= lookup_minimal_symbol ("$$dyncall", (struct objfile
*) NULL
);
954 error ("Can't find an address for $$dyncall trampoline");
956 dyncall_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
958 msymbol
= lookup_minimal_symbol ("_sr4export", (struct objfile
*) NULL
);
960 error ("Can't find an address for _sr4export trampoline");
962 sr4export_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
964 store_unsigned_integer
965 (&dummy
[9*REGISTER_SIZE
],
967 deposit_21 (fun
>> 11,
968 extract_unsigned_integer (&dummy
[9*REGISTER_SIZE
],
970 store_unsigned_integer
971 (&dummy
[10*REGISTER_SIZE
],
973 deposit_14 (fun
& MASK_11
,
974 extract_unsigned_integer (&dummy
[10*REGISTER_SIZE
],
976 store_unsigned_integer
977 (&dummy
[12*REGISTER_SIZE
],
979 deposit_21 (sr4export_addr
>> 11,
980 extract_unsigned_integer (&dummy
[12*REGISTER_SIZE
],
982 store_unsigned_integer
983 (&dummy
[13*REGISTER_SIZE
],
985 deposit_14 (sr4export_addr
& MASK_11
,
986 extract_unsigned_integer (&dummy
[13*REGISTER_SIZE
],
989 write_register (22, pc
);
991 /* If we are in a syscall, then we should call the stack dummy
992 directly. $$dyncall is not needed as the kernel sets up the
993 space id registers properly based on the value in %r31. In
994 fact calling $$dyncall will not work because the value in %r22
995 will be clobbered on the syscall exit path. */
1003 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
1008 int flags
= read_register (FLAGS_REGNUM
);
1011 return read_register (31) & ~0x3;
1012 return read_register (PC_REGNUM
) & ~0x3;
1015 /* Write out the PC. If currently in a syscall, then also write the new
1016 PC value into %r31. */
1021 int flags
= read_register (FLAGS_REGNUM
);
1023 /* If in a syscall, then set %r31. Also make sure to get the
1024 privilege bits set correctly. */
1026 write_register (31, (long) (v
| 0x3));
1028 write_register (PC_REGNUM
, (long) v
);
1029 write_register (NPC_REGNUM
, (long) v
+ 4);
1032 /* return the alignment of a type in bytes. Structures have the maximum
1033 alignment required by their fields. */
1039 int max_align
, align
, i
;
1040 switch (TYPE_CODE (arg
))
1045 return TYPE_LENGTH (arg
);
1046 case TYPE_CODE_ARRAY
:
1047 return hppa_alignof (TYPE_FIELD_TYPE (arg
, 0));
1048 case TYPE_CODE_STRUCT
:
1049 case TYPE_CODE_UNION
:
1051 for (i
= 0; i
< TYPE_NFIELDS (arg
); i
++)
1053 /* Bit fields have no real alignment. */
1054 if (!TYPE_FIELD_BITPOS (arg
, i
))
1056 align
= hppa_alignof (TYPE_FIELD_TYPE (arg
, i
));
1057 max_align
= max (max_align
, align
);
1066 /* Print the register regnum, or all registers if regnum is -1 */
1068 pa_do_registers_info (regnum
, fpregs
)
1072 char raw_regs
[REGISTER_BYTES
];
1075 for (i
= 0; i
< NUM_REGS
; i
++)
1076 read_relative_register_raw_bytes (i
, raw_regs
+ REGISTER_BYTE (i
));
1078 pa_print_registers (raw_regs
, regnum
, fpregs
);
1079 else if (regnum
< FP0_REGNUM
)
1080 printf_unfiltered ("%s %x\n", reg_names
[regnum
], *(long *)(raw_regs
+
1081 REGISTER_BYTE (regnum
)));
1083 pa_print_fp_reg (regnum
);
1086 pa_print_registers (raw_regs
, regnum
, fpregs
)
1093 for (i
= 0; i
< 18; i
++)
1094 printf_unfiltered ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n",
1096 *(int *)(raw_regs
+ REGISTER_BYTE (i
)),
1098 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 18)),
1100 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 36)),
1102 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 54)));
1105 for (i
= 72; i
< NUM_REGS
; i
++)
1106 pa_print_fp_reg (i
);
1112 unsigned char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1113 unsigned char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
1115 /* Get the data in raw format. */
1116 read_relative_register_raw_bytes (i
, raw_buffer
);
1118 /* Convert raw data to virtual format if necessary. */
1119 #ifdef REGISTER_CONVERTIBLE
1120 if (REGISTER_CONVERTIBLE (i
))
1122 REGISTER_CONVERT_TO_VIRTUAL (i
, REGISTER_VIRTUAL_TYPE (i
),
1123 raw_buffer
, virtual_buffer
);
1127 memcpy (virtual_buffer
, raw_buffer
,
1128 REGISTER_VIRTUAL_SIZE (i
));
1130 fputs_filtered (reg_names
[i
], gdb_stdout
);
1131 print_spaces_filtered (15 - strlen (reg_names
[i
]), gdb_stdout
);
1133 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0, gdb_stdout
, 0,
1134 1, 0, Val_pretty_default
);
1135 printf_filtered ("\n");
1138 /* Function calls that pass into a new compilation unit must pass through a
1139 small piece of code that does long format (`external' in HPPA parlance)
1140 jumps. We figure out where the trampoline is going to end up, and return
1141 the PC of the final destination. If we aren't in a trampoline, we just
1144 For computed calls, we just extract the new PC from r22. */
1147 skip_trampoline_code (pc
, name
)
1152 static CORE_ADDR dyncall
= 0;
1153 struct minimal_symbol
*msym
;
1155 /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */
1159 msym
= lookup_minimal_symbol ("$$dyncall", NULL
);
1161 dyncall
= SYMBOL_VALUE_ADDRESS (msym
);
1167 return (CORE_ADDR
)(read_register (22) & ~0x3);
1169 inst0
= read_memory_integer (pc
, 4);
1170 inst1
= read_memory_integer (pc
+4, 4);
1172 if ( (inst0
& 0xffe00000) == 0x20200000 /* ldil xxx, r1 */
1173 && (inst1
& 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */
1174 pc
= extract_21 (inst0
) + extract_17 (inst1
);
1176 pc
= (CORE_ADDR
)NULL
;
1181 /* For the given instruction (INST), return any adjustment it makes
1182 to the stack pointer or zero for no adjustment.
1184 This only handles instructions commonly found in prologues. */
1187 prologue_inst_adjust_sp (inst
)
1190 /* This must persist across calls. */
1191 static int save_high21
;
1193 /* The most common way to perform a stack adjustment ldo X(sp),sp */
1194 if ((inst
& 0xffffc000) == 0x37de0000)
1195 return extract_14 (inst
);
1198 if ((inst
& 0xffe00000) == 0x6fc00000)
1199 return extract_14 (inst
);
1201 /* addil high21,%r1; ldo low11,(%r1),%r30)
1202 save high bits in save_high21 for later use. */
1203 if ((inst
& 0xffe00000) == 0x28200000)
1205 save_high21
= extract_21 (inst
);
1209 if ((inst
& 0xffff0000) == 0x343e0000)
1210 return save_high21
+ extract_14 (inst
);
1212 /* fstws as used by the HP compilers. */
1213 if ((inst
& 0xffffffe0) == 0x2fd01220)
1214 return extract_5_load (inst
);
1216 /* No adjustment. */
1220 /* Return nonzero if INST is a branch of some kind, else return zero. */
1250 /* Return the register number for a GR which is saved by INST or
1251 zero it INST does not save a GR.
1253 Note we only care about full 32bit register stores (that's the only
1254 kind of stores the prologue will use). */
1257 inst_saves_gr (inst
)
1260 /* Does it look like a stw? */
1261 if ((inst
>> 26) == 0x1a)
1262 return extract_5R_store (inst
);
1264 /* Does it look like a stwm? */
1265 if ((inst
>> 26) == 0x1b)
1266 return extract_5R_store (inst
);
1271 /* Return the register number for a FR which is saved by INST or
1272 zero it INST does not save a FR.
1274 Note we only care about full 64bit register stores (that's the only
1275 kind of stores the prologue will use). */
1278 inst_saves_fr (inst
)
1281 if ((inst
& 0xfc1fffe0) == 0x2c101220)
1282 return extract_5r_store (inst
);
1286 /* Advance PC across any function entry prologue instructions
1287 to reach some "real" code.
1289 Use information in the unwind table to determine what exactly should
1290 be in the prologue. */
1297 unsigned long inst
, stack_remaining
, save_gr
, save_fr
, save_rp
, save_sp
;
1299 struct unwind_table_entry
*u
;
1301 u
= find_unwind_entry (pc
);
1305 /* This is how much of a frame adjustment we need to account for. */
1306 stack_remaining
= u
->Total_frame_size
<< 3;
1308 /* Magic register saves we want to know about. */
1309 save_rp
= u
->Save_RP
;
1310 save_sp
= u
->Save_SP
;
1312 /* Turn the Entry_GR field into a bitmask. */
1314 for (i
= 3; i
< u
->Entry_GR
+ 3; i
++)
1316 /* Frame pointer gets saved into a special location. */
1317 if (u
->Save_SP
&& i
== FP_REGNUM
)
1320 save_gr
|= (1 << i
);
1323 /* Turn the Entry_FR field into a bitmask too. */
1325 for (i
= 12; i
< u
->Entry_FR
+ 12; i
++)
1326 save_fr
|= (1 << i
);
1328 /* Loop until we find everything of interest or hit a branch.
1330 For unoptimized GCC code and for any HP CC code this will never ever
1331 examine any user instructions.
1333 For optimzied GCC code we're faced with problems. GCC will schedule
1334 its prologue and make prologue instructions available for delay slot
1335 filling. The end result is user code gets mixed in with the prologue
1336 and a prologue instruction may be in the delay slot of the first branch
1339 Some unexpected things are expected with debugging optimized code, so
1340 we allow this routine to walk past user instructions in optimized
1342 while (save_gr
|| save_fr
|| save_rp
|| save_sp
|| stack_remaining
> 0)
1344 status
= target_read_memory (pc
, buf
, 4);
1345 inst
= extract_unsigned_integer (buf
, 4);
1351 /* Note the interesting effects of this instruction. */
1352 stack_remaining
-= prologue_inst_adjust_sp (inst
);
1354 /* There is only one instruction used for saving RP into the stack. */
1355 if (inst
== 0x6bc23fd9)
1358 /* This is the only way we save SP into the stack. At this time
1359 the HP compilers never bother to save SP into the stack. */
1360 if ((inst
& 0xffffc000) == 0x6fc10000)
1363 /* Account for general and floating-point register saves. */
1364 save_gr
&= ~(1 << inst_saves_gr (inst
));
1365 save_fr
&= ~(1 << inst_saves_fr (inst
));
1367 /* Quit if we hit any kind of branch. This can happen if a prologue
1368 instruction is in the delay slot of the first call/branch. */
1369 if (is_branch (inst
))
1379 /* Put here the code to store, into a struct frame_saved_regs,
1380 the addresses of the saved registers of frame described by FRAME_INFO.
1381 This includes special registers such as pc and fp saved in special
1382 ways in the stack frame. sp is even more special:
1383 the address we return for it IS the sp for the next frame. */
1386 hppa_frame_find_saved_regs (frame_info
, frame_saved_regs
)
1387 struct frame_info
*frame_info
;
1388 struct frame_saved_regs
*frame_saved_regs
;
1391 struct unwind_table_entry
*u
;
1392 unsigned long inst
, stack_remaining
, save_gr
, save_fr
, save_rp
, save_sp
;
1397 /* Zero out everything. */
1398 memset (frame_saved_regs
, '\0', sizeof (struct frame_saved_regs
));
1400 /* Call dummy frames always look the same, so there's no need to
1401 examine the dummy code to determine locations of saved registers;
1402 instead, let find_dummy_frame_regs fill in the correct offsets
1403 for the saved registers. */
1404 if ((frame_info
->pc
>= frame_info
->frame
1405 && frame_info
->pc
<= (frame_info
->frame
+ CALL_DUMMY_LENGTH
1406 + 32 * 4 + (NUM_REGS
- FP0_REGNUM
) * 8
1408 find_dummy_frame_regs (frame_info
, frame_saved_regs
);
1410 /* Get the starting address of the function referred to by the PC
1411 saved in frame_info. */
1412 pc
= get_pc_function_start (frame_info
->pc
);
1415 u
= find_unwind_entry (pc
);
1419 /* This is how much of a frame adjustment we need to account for. */
1420 stack_remaining
= u
->Total_frame_size
<< 3;
1422 /* Magic register saves we want to know about. */
1423 save_rp
= u
->Save_RP
;
1424 save_sp
= u
->Save_SP
;
1426 /* Turn the Entry_GR field into a bitmask. */
1428 for (i
= 3; i
< u
->Entry_GR
+ 3; i
++)
1430 /* Frame pointer gets saved into a special location. */
1431 if (u
->Save_SP
&& i
== FP_REGNUM
)
1434 save_gr
|= (1 << i
);
1437 /* Turn the Entry_FR field into a bitmask too. */
1439 for (i
= 12; i
< u
->Entry_FR
+ 12; i
++)
1440 save_fr
|= (1 << i
);
1442 /* Loop until we find everything of interest or hit a branch.
1444 For unoptimized GCC code and for any HP CC code this will never ever
1445 examine any user instructions.
1447 For optimzied GCC code we're faced with problems. GCC will schedule
1448 its prologue and make prologue instructions available for delay slot
1449 filling. The end result is user code gets mixed in with the prologue
1450 and a prologue instruction may be in the delay slot of the first branch
1453 Some unexpected things are expected with debugging optimized code, so
1454 we allow this routine to walk past user instructions in optimized
1456 while (save_gr
|| save_fr
|| save_rp
|| save_sp
|| stack_remaining
> 0)
1458 status
= target_read_memory (pc
, buf
, 4);
1459 inst
= extract_unsigned_integer (buf
, 4);
1465 /* Note the interesting effects of this instruction. */
1466 stack_remaining
-= prologue_inst_adjust_sp (inst
);
1468 /* There is only one instruction used for saving RP into the stack. */
1469 if (inst
== 0x6bc23fd9)
1472 frame_saved_regs
->regs
[RP_REGNUM
] = frame_info
->frame
- 20;
1475 /* This is the only way we save SP into the stack. At this time
1476 the HP compilers never bother to save SP into the stack. */
1477 if ((inst
& 0xffffc000) == 0x6fc10000)
1480 frame_saved_regs
->regs
[SP_REGNUM
] = frame_info
->frame
;
1483 /* Account for general and floating-point register saves. */
1484 reg
= inst_saves_gr (inst
);
1485 if (reg
>= 3 && reg
<= 18
1486 && (!u
->Save_SP
|| reg
!= FP_REGNUM
))
1488 save_gr
&= ~(1 << reg
);
1490 /* stwm with a positive displacement is a *post modify*. */
1491 if ((inst
>> 26) == 0x1b
1492 && extract_14 (inst
) >= 0)
1493 frame_saved_regs
->regs
[reg
] = frame_info
->frame
;
1496 /* Handle code with and without frame pointers. */
1498 frame_saved_regs
->regs
[reg
]
1499 = frame_info
->frame
+ extract_14 (inst
);
1501 frame_saved_regs
->regs
[reg
]
1502 = frame_info
->frame
+ (u
->Total_frame_size
<< 3)
1503 + extract_14 (inst
);
1508 /* GCC handles callee saved FP regs a little differently.
1510 It emits an instruction to put the value of the start of
1511 the FP store area into %r1. It then uses fstds,ma with
1512 a basereg of %r1 for the stores.
1514 HP CC emits them at the current stack pointer modifying
1515 the stack pointer as it stores each register. */
1517 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
1518 if ((inst
& 0xffffc000) == 0x34610000
1519 || (inst
& 0xffffc000) == 0x37c10000)
1520 fp_loc
= extract_14 (inst
);
1522 reg
= inst_saves_fr (inst
);
1523 if (reg
>= 12 && reg
<= 21)
1525 /* Note +4 braindamage below is necessary because the FP status
1526 registers are internally 8 registers rather than the expected
1528 save_fr
&= ~(1 << reg
);
1531 /* 1st HP CC FP register store. After this instruction
1532 we've set enough state that the GCC and HPCC code are
1533 both handled in the same manner. */
1534 frame_saved_regs
->regs
[reg
+ FP4_REGNUM
+ 4] = frame_info
->frame
;
1539 frame_saved_regs
->regs
[reg
+ FP0_REGNUM
+ 4]
1540 = frame_info
->frame
+ fp_loc
;
1545 /* Quit if we hit any kind of branch. This can happen if a prologue
1546 instruction is in the delay slot of the first call/branch. */
1547 if (is_branch (inst
))
1555 #ifdef MAINTENANCE_CMDS
1558 unwind_command (exp
, from_tty
)
1566 struct unwind_table_entry
*u
;
1569 /* If we have an expression, evaluate it and use it as the address. */
1571 if (exp
!= 0 && *exp
!= 0)
1572 address
= parse_and_eval_address (exp
);
1576 xxx
.u
= find_unwind_entry (address
);
1580 printf_unfiltered ("Can't find unwind table entry for PC 0x%x\n", address
);
1584 printf_unfiltered ("%08x\n%08X\n%08X\n%08X\n", xxx
.foo
[0], xxx
.foo
[1], xxx
.foo
[2],
1587 #endif /* MAINTENANCE_CMDS */
1590 _initialize_hppa_tdep ()
1592 #ifdef MAINTENANCE_CMDS
1593 add_cmd ("unwind", class_maintenance
, unwind_command
,
1594 "Print unwind table entry at given address.",
1595 &maintenanceprintlist
);
1596 #endif /* MAINTENANCE_CMDS */