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 static FRAME_ADDR dig_fp_from_stack
PARAMS ((FRAME frame
,
65 struct unwind_table_entry
*u
));
66 CORE_ADDR frame_saved_pc
PARAMS ((FRAME frame
));
69 /* Routines to extract various sized constants out of hppa
72 /* This assumes that no garbage lies outside of the lower bits of
76 sign_extend (val
, bits
)
79 return (int)(val
>> bits
- 1 ? (-1 << bits
) | val
: val
);
82 /* For many immediate values the sign bit is the low bit! */
85 low_sign_extend (val
, bits
)
88 return (int)((val
& 0x1 ? (-1 << (bits
- 1)) : 0) | val
>> 1);
90 /* extract the immediate field from a ld{bhw}s instruction */
93 get_field (val
, from
, to
)
94 unsigned val
, from
, to
;
97 return val
& ((1 << 32 - from
) - 1);
101 set_field (val
, from
, to
, new_val
)
102 unsigned *val
, from
, to
;
104 unsigned mask
= ~((1 << (to
- from
+ 1)) << (31 - from
));
105 return *val
= *val
& mask
| (new_val
<< (31 - from
));
108 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
113 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
116 extract_5_load (word
)
119 return low_sign_extend (word
>> 16 & MASK_5
, 5);
122 /* extract the immediate field from a st{bhw}s instruction */
125 extract_5_store (word
)
128 return low_sign_extend (word
& MASK_5
, 5);
131 /* extract the immediate field from a break instruction */
134 extract_5r_store (word
)
137 return (word
& MASK_5
);
140 /* extract the immediate field from a {sr}sm instruction */
143 extract_5R_store (word
)
146 return (word
>> 16 & MASK_5
);
149 /* extract an 11 bit immediate field */
155 return low_sign_extend (word
& MASK_11
, 11);
158 /* extract a 14 bit immediate field */
164 return low_sign_extend (word
& MASK_14
, 14);
167 /* deposit a 14 bit constant in a word */
170 deposit_14 (opnd
, word
)
174 unsigned sign
= (opnd
< 0 ? 1 : 0);
176 return word
| ((unsigned)opnd
<< 1 & MASK_14
) | sign
;
179 /* extract a 21 bit constant */
189 val
= GET_FIELD (word
, 20, 20);
191 val
|= GET_FIELD (word
, 9, 19);
193 val
|= GET_FIELD (word
, 5, 6);
195 val
|= GET_FIELD (word
, 0, 4);
197 val
|= GET_FIELD (word
, 7, 8);
198 return sign_extend (val
, 21) << 11;
201 /* deposit a 21 bit constant in a word. Although 21 bit constants are
202 usually the top 21 bits of a 32 bit constant, we assume that only
203 the low 21 bits of opnd are relevant */
206 deposit_21 (opnd
, word
)
211 val
|= GET_FIELD (opnd
, 11 + 14, 11 + 18);
213 val
|= GET_FIELD (opnd
, 11 + 12, 11 + 13);
215 val
|= GET_FIELD (opnd
, 11 + 19, 11 + 20);
217 val
|= GET_FIELD (opnd
, 11 + 1, 11 + 11);
219 val
|= GET_FIELD (opnd
, 11 + 0, 11 + 0);
223 /* extract a 12 bit constant from branch instructions */
229 return sign_extend (GET_FIELD (word
, 19, 28) |
230 GET_FIELD (word
, 29, 29) << 10 |
231 (word
& 0x1) << 11, 12) << 2;
234 /* extract a 17 bit constant from branch instructions, returning the
235 19 bit signed value. */
241 return sign_extend (GET_FIELD (word
, 19, 28) |
242 GET_FIELD (word
, 29, 29) << 10 |
243 GET_FIELD (word
, 11, 15) << 11 |
244 (word
& 0x1) << 16, 17) << 2;
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. */
252 static struct unwind_table_entry
*
253 find_unwind_entry(pc
)
256 int first
, middle
, last
;
257 struct objfile
*objfile
;
259 ALL_OBJFILES (objfile
)
261 struct obj_unwind_info
*ui
;
263 ui
= OBJ_UNWIND_INFO (objfile
);
268 /* First, check the cache */
271 && pc
>= ui
->cache
->region_start
272 && pc
<= ui
->cache
->region_end
)
275 /* Not in the cache, do a binary search */
280 while (first
<= last
)
282 middle
= (first
+ last
) / 2;
283 if (pc
>= ui
->table
[middle
].region_start
284 && pc
<= ui
->table
[middle
].region_end
)
286 ui
->cache
= &ui
->table
[middle
];
287 return &ui
->table
[middle
];
290 if (pc
< ui
->table
[middle
].region_start
)
295 } /* ALL_OBJFILES() */
299 /* Called when no unwind descriptor was found for PC. Returns 1 if it
300 appears that PC is in a linker stub. */
301 static int pc_in_linker_stub
PARAMS ((CORE_ADDR
));
304 pc_in_linker_stub (pc
)
307 int found_magic_instruction
= 0;
311 /* If unable to read memory, assume pc is not in a linker stub. */
312 if (target_read_memory (pc
, buf
, 4) != 0)
315 /* We are looking for something like
317 ; $$dyncall jams RP into this special spot in the frame (RP')
318 ; before calling the "call stub"
321 ldsid (rp),r1 ; Get space associated with RP into r1
322 mtsp r1,sp ; Move it into space register 0
323 be,n 0(sr0),rp) ; back to your regularly scheduled program
326 /* Maximum known linker stub size is 4 instructions. Search forward
327 from the given PC, then backward. */
328 for (i
= 0; i
< 4; i
++)
330 /* If we hit something with an unwind, stop searching this direction. */
332 if (find_unwind_entry (pc
+ i
* 4) != 0)
335 /* Check for ldsid (rp),r1 which is the magic instruction for a
336 return from a cross-space function call. */
337 if (read_memory_integer (pc
+ i
* 4, 4) == 0x004010a1)
339 found_magic_instruction
= 1;
342 /* Add code to handle long call/branch and argument relocation stubs
346 if (found_magic_instruction
!= 0)
349 /* Now look backward. */
350 for (i
= 0; i
< 4; i
++)
352 /* If we hit something with an unwind, stop searching this direction. */
354 if (find_unwind_entry (pc
- i
* 4) != 0)
357 /* Check for ldsid (rp),r1 which is the magic instruction for a
358 return from a cross-space function call. */
359 if (read_memory_integer (pc
- i
* 4, 4) == 0x004010a1)
361 found_magic_instruction
= 1;
364 /* Add code to handle long call/branch and argument relocation stubs
367 return found_magic_instruction
;
371 find_return_regnum(pc
)
374 struct unwind_table_entry
*u
;
376 u
= find_unwind_entry (pc
);
387 /* Return size of frame, or -1 if we should use a frame pointer. */
389 find_proc_framesize(pc
)
392 struct unwind_table_entry
*u
;
394 u
= find_unwind_entry (pc
);
398 if (pc_in_linker_stub (pc
))
399 /* Linker stubs have a zero size frame. */
406 /* If this bit is set, it means there is a frame pointer and we should
410 return u
->Total_frame_size
<< 3;
413 /* Return offset from sp at which rp is saved, or 0 if not saved. */
414 static int rp_saved
PARAMS ((CORE_ADDR
));
420 struct unwind_table_entry
*u
;
422 u
= find_unwind_entry (pc
);
426 if (pc_in_linker_stub (pc
))
427 /* This is the so-called RP'. */
440 frameless_function_invocation (frame
)
443 struct unwind_table_entry
*u
;
445 u
= find_unwind_entry (frame
->pc
);
448 return frameless_look_for_prologue (frame
);
450 return (u
->Total_frame_size
== 0);
454 saved_pc_after_call (frame
)
459 ret_regnum
= find_return_regnum (get_frame_pc (frame
));
461 return read_register (ret_regnum
) & ~0x3;
465 frame_saved_pc (frame
)
468 CORE_ADDR pc
= get_frame_pc (frame
);
470 if (frameless_function_invocation (frame
))
474 ret_regnum
= find_return_regnum (pc
);
476 return read_register (ret_regnum
) & ~0x3;
480 int rp_offset
= rp_saved (pc
);
483 return read_register (RP_REGNUM
) & ~0x3;
485 return read_memory_integer (frame
->frame
+ rp_offset
, 4) & ~0x3;
489 /* We need to correct the PC and the FP for the outermost frame when we are
493 init_extra_frame_info (fromleaf
, frame
)
495 struct frame_info
*frame
;
500 if (frame
->next
) /* Only do this for outermost frame */
503 flags
= read_register (FLAGS_REGNUM
);
504 if (flags
& 2) /* In system call? */
505 frame
->pc
= read_register (31) & ~0x3;
507 /* The outermost frame is always derived from PC-framesize */
508 framesize
= find_proc_framesize(frame
->pc
);
510 frame
->frame
= read_register (FP_REGNUM
);
512 frame
->frame
= read_register (SP_REGNUM
) - framesize
;
514 if (!frameless_function_invocation (frame
)) /* Frameless? */
515 return; /* No, quit now */
517 /* For frameless functions, we need to look at the caller's frame */
518 framesize
= find_proc_framesize(FRAME_SAVED_PC(frame
));
520 frame
->frame
-= framesize
;
523 /* Given a GDB frame, determine the address of the calling function's frame.
524 This will be used to create a new GDB frame struct, and then
525 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
527 This may involve searching through prologues for several functions
528 at boundaries where GCC calls HP C code, or where code which has
529 a frame pointer calls code without a frame pointer. */
534 struct frame_info
*frame
;
536 int my_framesize
, caller_framesize
;
537 struct unwind_table_entry
*u
;
539 /* Get frame sizes for the current frame and the frame of the
541 my_framesize
= find_proc_framesize (frame
->pc
);
542 caller_framesize
= find_proc_framesize (FRAME_SAVED_PC(frame
));
544 /* If caller does not have a frame pointer, then its frame
545 can be found at current_frame - caller_framesize. */
546 if (caller_framesize
!= -1)
547 return frame
->frame
- caller_framesize
;
549 /* Both caller and callee have frame pointers and are GCC compiled
550 (SAVE_SP bit in unwind descriptor is on for both functions.
551 The previous frame pointer is found at the top of the current frame. */
552 if (caller_framesize
== -1 && my_framesize
== -1)
553 return read_memory_integer (frame
->frame
, 4);
555 /* Caller has a frame pointer, but callee does not. This is a little
556 more difficult as GCC and HP C lay out locals and callee register save
557 areas very differently.
559 The previous frame pointer could be in a register, or in one of
560 several areas on the stack.
562 Walk from the current frame to the innermost frame examining
563 unwind descriptors to determine if %r4 ever gets saved into the
564 stack. If so return whatever value got saved into the stack.
565 If it was never saved in the stack, then the value in %r4 is still
568 We use information from unwind descriptors to determine if %r4
569 is saved into the stack (Entry_GR field has this information). */
573 u
= find_unwind_entry (frame
->pc
);
577 /* We could find this information by examining prologues. I don't
578 think anyone has actually written any tools (not even "strip")
579 which leave them out of an executable, so maybe this is a moot
581 warning ("Unable to find unwind for PC 0x%x -- Help!", frame
->pc
);
585 /* Entry_GR specifies the number of callee-saved general registers
586 saved in the stack. It starts at %r3, so %r4 would be 2. */
587 if (u
->Entry_GR
>= 2 || u
->Save_SP
)
595 /* We may have walked down the chain into a function with a frame
598 return read_memory_integer (frame
->frame
, 4);
599 /* %r4 was saved somewhere in the stack. Dig it out. */
601 return dig_fp_from_stack (frame
, u
);
605 /* The value in %r4 was never saved into the stack (thus %r4 still
606 holds the value of the previous frame pointer). */
607 return read_register (4);
611 /* Given a frame and an unwind descriptor return the value for %fr (aka fp)
612 which was saved into the stack. FIXME: Why can't we just use the standard
616 dig_fp_from_stack (frame
, u
)
618 struct unwind_table_entry
*u
;
620 CORE_ADDR pc
= u
->region_start
;
622 /* Search the function for the save of %r4. */
623 while (pc
!= u
->region_end
)
629 /* We need only look for the standard stw %r4,X(%sp) instruction,
630 the other variants (eg stwm) are only used on the first register
632 status
= target_read_memory (pc
, buf
, 4);
633 inst
= extract_unsigned_integer (buf
, 4);
636 memory_error (status
, pc
);
638 /* Check for stw %r4,X(%sp). */
639 if ((inst
& 0xffffc000) == 0x6bc40000)
641 /* Found the instruction which saves %r4. The offset (relative
642 to this frame) is framesize + immed14 (derived from the
643 store instruction). */
644 int offset
= (u
->Total_frame_size
<< 3) + extract_14 (inst
);
646 return read_memory_integer (frame
->frame
+ offset
, 4);
653 warning ("Unable to find %%r4 in stack.\n");
658 /* To see if a frame chain is valid, see if the caller looks like it
659 was compiled with gcc. */
662 frame_chain_valid (chain
, thisframe
)
666 struct minimal_symbol
*msym_us
;
667 struct minimal_symbol
*msym_start
;
668 struct unwind_table_entry
*u
;
673 u
= find_unwind_entry (thisframe
->pc
);
675 /* We can't just check that the same of msym_us is "_start", because
676 someone idiotically decided that they were going to make a Ltext_end
677 symbol with the same address. This Ltext_end symbol is totally
678 indistinguishable (as nearly as I can tell) from the symbol for a function
679 which is (legitimately, since it is in the user's namespace)
680 named Ltext_end, so we can't just ignore it. */
681 msym_us
= lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe
));
682 msym_start
= lookup_minimal_symbol ("_start", NULL
);
685 && SYMBOL_VALUE_ADDRESS (msym_us
) == SYMBOL_VALUE_ADDRESS (msym_start
))
691 if (u
->Save_SP
|| u
->Total_frame_size
)
694 if (pc_in_linker_stub (thisframe
->pc
))
701 * These functions deal with saving and restoring register state
702 * around a function call in the inferior. They keep the stack
703 * double-word aligned; eventually, on an hp700, the stack will have
704 * to be aligned to a 64-byte boundary.
710 register CORE_ADDR sp
;
715 /* Space for "arguments"; the RP goes in here. */
716 sp
= read_register (SP_REGNUM
) + 48;
717 int_buffer
= read_register (RP_REGNUM
) | 0x3;
718 write_memory (sp
- 20, (char *)&int_buffer
, 4);
720 int_buffer
= read_register (FP_REGNUM
);
721 write_memory (sp
, (char *)&int_buffer
, 4);
723 write_register (FP_REGNUM
, sp
);
727 for (regnum
= 1; regnum
< 32; regnum
++)
728 if (regnum
!= RP_REGNUM
&& regnum
!= FP_REGNUM
)
729 sp
= push_word (sp
, read_register (regnum
));
733 for (regnum
= FP0_REGNUM
; regnum
< NUM_REGS
; regnum
++)
735 read_register_bytes (REGISTER_BYTE (regnum
), (char *)&freg_buffer
, 8);
736 sp
= push_bytes (sp
, (char *)&freg_buffer
, 8);
738 sp
= push_word (sp
, read_register (IPSW_REGNUM
));
739 sp
= push_word (sp
, read_register (SAR_REGNUM
));
740 sp
= push_word (sp
, read_register (PCOQ_HEAD_REGNUM
));
741 sp
= push_word (sp
, read_register (PCSQ_HEAD_REGNUM
));
742 sp
= push_word (sp
, read_register (PCOQ_TAIL_REGNUM
));
743 sp
= push_word (sp
, read_register (PCSQ_TAIL_REGNUM
));
744 write_register (SP_REGNUM
, sp
);
747 find_dummy_frame_regs (frame
, frame_saved_regs
)
748 struct frame_info
*frame
;
749 struct frame_saved_regs
*frame_saved_regs
;
751 CORE_ADDR fp
= frame
->frame
;
754 frame_saved_regs
->regs
[RP_REGNUM
] = fp
- 20 & ~0x3;
755 frame_saved_regs
->regs
[FP_REGNUM
] = fp
;
756 frame_saved_regs
->regs
[1] = fp
+ 8;
758 for (fp
+= 12, i
= 3; i
< 32; i
++)
762 frame_saved_regs
->regs
[i
] = fp
;
768 for (i
= FP0_REGNUM
; i
< NUM_REGS
; i
++, fp
+= 8)
769 frame_saved_regs
->regs
[i
] = fp
;
771 frame_saved_regs
->regs
[IPSW_REGNUM
] = fp
;
772 frame_saved_regs
->regs
[SAR_REGNUM
] = fp
+ 4;
773 frame_saved_regs
->regs
[PCOQ_HEAD_REGNUM
] = fp
+ 8;
774 frame_saved_regs
->regs
[PCSQ_HEAD_REGNUM
] = fp
+ 12;
775 frame_saved_regs
->regs
[PCOQ_TAIL_REGNUM
] = fp
+ 16;
776 frame_saved_regs
->regs
[PCSQ_TAIL_REGNUM
] = fp
+ 20;
782 register FRAME frame
= get_current_frame ();
783 register CORE_ADDR fp
;
785 struct frame_saved_regs fsr
;
786 struct frame_info
*fi
;
789 fi
= get_frame_info (frame
);
791 get_frame_saved_regs (fi
, &fsr
);
793 if (fsr
.regs
[IPSW_REGNUM
]) /* Restoring a call dummy frame */
794 restore_pc_queue (&fsr
);
796 for (regnum
= 31; regnum
> 0; regnum
--)
797 if (fsr
.regs
[regnum
])
798 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
], 4));
800 for (regnum
= NUM_REGS
- 1; regnum
>= FP0_REGNUM
; regnum
--)
801 if (fsr
.regs
[regnum
])
803 read_memory (fsr
.regs
[regnum
], (char *)&freg_buffer
, 8);
804 write_register_bytes (REGISTER_BYTE (regnum
), (char *)&freg_buffer
, 8);
807 if (fsr
.regs
[IPSW_REGNUM
])
808 write_register (IPSW_REGNUM
,
809 read_memory_integer (fsr
.regs
[IPSW_REGNUM
], 4));
811 if (fsr
.regs
[SAR_REGNUM
])
812 write_register (SAR_REGNUM
,
813 read_memory_integer (fsr
.regs
[SAR_REGNUM
], 4));
815 /* If the PC was explicitly saved, then just restore it. */
816 if (fsr
.regs
[PCOQ_TAIL_REGNUM
])
817 write_register (PCOQ_TAIL_REGNUM
,
818 read_memory_integer (fsr
.regs
[PCOQ_TAIL_REGNUM
], 4));
820 /* Else use the value in %rp to set the new PC. */
822 target_write_pc (read_register (RP_REGNUM
));
824 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
826 if (fsr
.regs
[IPSW_REGNUM
]) /* call dummy */
827 write_register (SP_REGNUM
, fp
- 48);
829 write_register (SP_REGNUM
, fp
);
831 flush_cached_frames ();
832 set_current_frame (create_new_frame (read_register (FP_REGNUM
),
837 * After returning to a dummy on the stack, restore the instruction
838 * queue space registers. */
841 restore_pc_queue (fsr
)
842 struct frame_saved_regs
*fsr
;
844 CORE_ADDR pc
= read_pc ();
845 CORE_ADDR new_pc
= read_memory_integer (fsr
->regs
[PCOQ_HEAD_REGNUM
], 4);
850 /* Advance past break instruction in the call dummy. */
851 write_register (PCOQ_HEAD_REGNUM
, pc
+ 4);
852 write_register (PCOQ_TAIL_REGNUM
, pc
+ 8);
855 * HPUX doesn't let us set the space registers or the space
856 * registers of the PC queue through ptrace. Boo, hiss.
857 * Conveniently, the call dummy has this sequence of instructions
862 * So, load up the registers and single step until we are in the
866 write_register (21, read_memory_integer (fsr
->regs
[PCSQ_HEAD_REGNUM
], 4));
867 write_register (22, new_pc
);
869 for (insn_count
= 0; insn_count
< 3; insn_count
++)
871 /* FIXME: What if the inferior gets a signal right now? Want to
872 merge this into wait_for_inferior (as a special kind of
873 watchpoint? By setting a breakpoint at the end? Is there
874 any other choice? Is there *any* way to do this stuff with
875 ptrace() or some equivalent?). */
877 target_wait(inferior_pid
, &w
);
881 stop_signal
= WTERMSIG (w
);
882 terminal_ours_for_output ();
883 printf ("\nProgram terminated with signal %d, %s\n",
884 stop_signal
, safe_strsignal (stop_signal
));
889 target_terminal_ours ();
890 fetch_inferior_registers (-1);
895 hppa_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
900 CORE_ADDR struct_addr
;
902 /* array of arguments' offsets */
903 int *offset
= (int *)alloca(nargs
* sizeof (int));
907 for (i
= 0; i
< nargs
; i
++)
909 /* Coerce chars to int & float to double if necessary */
910 args
[i
] = value_arg_coerce (args
[i
]);
912 cum
+= TYPE_LENGTH (VALUE_TYPE (args
[i
]));
914 /* value must go at proper alignment. Assume alignment is a
916 alignment
= hppa_alignof (VALUE_TYPE (args
[i
]));
918 cum
= (cum
+ alignment
) & -alignment
;
921 sp
+= max ((cum
+ 7) & -8, 16);
923 for (i
= 0; i
< nargs
; i
++)
924 write_memory (sp
+ offset
[i
], VALUE_CONTENTS (args
[i
]),
925 TYPE_LENGTH (VALUE_TYPE (args
[i
])));
928 write_register (28, struct_addr
);
933 * Insert the specified number of args and function address
934 * into a call sequence of the above form stored at DUMMYNAME.
936 * On the hppa we need to call the stack dummy through $$dyncall.
937 * Therefore our version of FIX_CALL_DUMMY takes an extra argument,
938 * real_pc, which is the location where gdb should start up the
939 * inferior to do the function call.
943 hppa_fix_call_dummy (dummy
, pc
, fun
, nargs
, args
, type
, gcc_p
)
944 REGISTER_TYPE
*dummy
;
952 CORE_ADDR dyncall_addr
, sr4export_addr
;
953 struct minimal_symbol
*msymbol
;
954 int flags
= read_register (FLAGS_REGNUM
);
956 msymbol
= lookup_minimal_symbol ("$$dyncall", (struct objfile
*) NULL
);
958 error ("Can't find an address for $$dyncall trampoline");
960 dyncall_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
962 msymbol
= lookup_minimal_symbol ("_sr4export", (struct objfile
*) NULL
);
964 error ("Can't find an address for _sr4export trampoline");
966 sr4export_addr
= SYMBOL_VALUE_ADDRESS (msymbol
);
968 dummy
[9] = deposit_21 (fun
>> 11, dummy
[9]);
969 dummy
[10] = deposit_14 (fun
& MASK_11
, dummy
[10]);
970 dummy
[12] = deposit_21 (sr4export_addr
>> 11, dummy
[12]);
971 dummy
[13] = deposit_14 (sr4export_addr
& MASK_11
, dummy
[13]);
973 write_register (22, pc
);
975 /* If we are in a syscall, then we should call the stack dummy
976 directly. $$dyncall is not needed as the kernel sets up the
977 space id registers properly based on the value in %r31. In
978 fact calling $$dyncall will not work because the value in %r22
979 will be clobbered on the syscall exit path. */
987 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
992 int flags
= read_register (FLAGS_REGNUM
);
995 return read_register (31) & ~0x3;
996 return read_register (PC_REGNUM
) & ~0x3;
999 /* Write out the PC. If currently in a syscall, then also write the new
1000 PC value into %r31. */
1005 int flags
= read_register (FLAGS_REGNUM
);
1007 /* If in a syscall, then set %r31. Also make sure to get the
1008 privilege bits set correctly. */
1010 write_register (31, (long) (v
| 0x3));
1012 write_register (PC_REGNUM
, (long) v
);
1013 write_register (NPC_REGNUM
, (long) v
+ 4);
1016 /* return the alignment of a type in bytes. Structures have the maximum
1017 alignment required by their fields. */
1023 int max_align
, align
, i
;
1024 switch (TYPE_CODE (arg
))
1029 return TYPE_LENGTH (arg
);
1030 case TYPE_CODE_ARRAY
:
1031 return hppa_alignof (TYPE_FIELD_TYPE (arg
, 0));
1032 case TYPE_CODE_STRUCT
:
1033 case TYPE_CODE_UNION
:
1035 for (i
= 0; i
< TYPE_NFIELDS (arg
); i
++)
1037 /* Bit fields have no real alignment. */
1038 if (!TYPE_FIELD_BITPOS (arg
, i
))
1040 align
= hppa_alignof (TYPE_FIELD_TYPE (arg
, i
));
1041 max_align
= max (max_align
, align
);
1050 /* Print the register regnum, or all registers if regnum is -1 */
1052 pa_do_registers_info (regnum
, fpregs
)
1056 char raw_regs
[REGISTER_BYTES
];
1059 for (i
= 0; i
< NUM_REGS
; i
++)
1060 read_relative_register_raw_bytes (i
, raw_regs
+ REGISTER_BYTE (i
));
1062 pa_print_registers (raw_regs
, regnum
, fpregs
);
1063 else if (regnum
< FP0_REGNUM
)
1064 printf ("%s %x\n", reg_names
[regnum
], *(long *)(raw_regs
+
1065 REGISTER_BYTE (regnum
)));
1067 pa_print_fp_reg (regnum
);
1070 pa_print_registers (raw_regs
, regnum
, fpregs
)
1077 for (i
= 0; i
< 18; i
++)
1078 printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n",
1080 *(int *)(raw_regs
+ REGISTER_BYTE (i
)),
1082 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 18)),
1084 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 36)),
1086 *(int *)(raw_regs
+ REGISTER_BYTE (i
+ 54)));
1089 for (i
= 72; i
< NUM_REGS
; i
++)
1090 pa_print_fp_reg (i
);
1096 unsigned char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1097 unsigned char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
1100 /* Get the data in raw format, then convert also to virtual format. */
1101 read_relative_register_raw_bytes (i
, raw_buffer
);
1102 REGISTER_CONVERT_TO_VIRTUAL (i
, raw_buffer
, virtual_buffer
);
1104 fputs_filtered (reg_names
[i
], stdout
);
1105 print_spaces_filtered (15 - strlen (reg_names
[i
]), stdout
);
1107 val_print (REGISTER_VIRTUAL_TYPE (i
), virtual_buffer
, 0, stdout
, 0,
1108 1, 0, Val_pretty_default
);
1109 printf_filtered ("\n");
1112 /* Function calls that pass into a new compilation unit must pass through a
1113 small piece of code that does long format (`external' in HPPA parlance)
1114 jumps. We figure out where the trampoline is going to end up, and return
1115 the PC of the final destination. If we aren't in a trampoline, we just
1118 For computed calls, we just extract the new PC from r22. */
1121 skip_trampoline_code (pc
, name
)
1126 static CORE_ADDR dyncall
= 0;
1127 struct minimal_symbol
*msym
;
1129 /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */
1133 msym
= lookup_minimal_symbol ("$$dyncall", NULL
);
1135 dyncall
= SYMBOL_VALUE_ADDRESS (msym
);
1141 return (CORE_ADDR
)(read_register (22) & ~0x3);
1143 inst0
= read_memory_integer (pc
, 4);
1144 inst1
= read_memory_integer (pc
+4, 4);
1146 if ( (inst0
& 0xffe00000) == 0x20200000 /* ldil xxx, r1 */
1147 && (inst1
& 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */
1148 pc
= extract_21 (inst0
) + extract_17 (inst1
);
1150 pc
= (CORE_ADDR
)NULL
;
1155 /* Advance PC across any function entry prologue instructions
1156 to reach some "real" code. */
1158 /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp)
1159 for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */
1169 status
= target_read_memory (pc
, buf
, 4);
1170 inst
= extract_unsigned_integer (buf
, 4);
1174 if (inst
== 0x6BC23FD9) /* stw rp,-20(sp) */
1176 if (read_memory_integer (pc
+ 4, 4) == 0x8040241) /* copy r4,r1 */
1178 else if ((read_memory_integer (pc
+ 4, 4) & ~MASK_14
) == 0x68810000) /* stw r1,(r4) */
1181 else if (read_memory_integer (pc
, 4) == 0x8040241) /* copy r4,r1 */
1183 else if ((read_memory_integer (pc
, 4) & ~MASK_14
) == 0x68810000) /* stw r1,(r4) */
1189 #ifdef MAINTENANCE_CMDS
1192 unwind_command (exp
, from_tty
)
1200 struct unwind_table_entry
*u
;
1203 /* If we have an expression, evaluate it and use it as the address. */
1205 if (exp
!= 0 && *exp
!= 0)
1206 address
= parse_and_eval_address (exp
);
1210 xxx
.u
= find_unwind_entry (address
);
1214 printf ("Can't find unwind table entry for PC 0x%x\n", address
);
1218 printf ("%08x\n%08X\n%08X\n%08X\n", xxx
.foo
[0], xxx
.foo
[1], xxx
.foo
[2],
1223 _initialize_hppa_tdep ()
1225 add_cmd ("unwind", class_maintenance
, unwind_command
,
1226 "Print unwind table entry at given address.",
1227 &maintenanceprintlist
);
1230 #endif /* MAINTENANCE_CMDS */