1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
32 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
34 /* FIXME: Put this declaration in frame.h. */
35 extern struct obstack frame_cache_obstack
;
38 /* Forward declarations. */
40 static CORE_ADDR read_next_frame_reg
PARAMS ((struct frame_info
*, int));
42 static CORE_ADDR heuristic_proc_start
PARAMS ((CORE_ADDR
));
44 static alpha_extra_func_info_t heuristic_proc_desc
PARAMS ((CORE_ADDR
,
46 struct frame_info
*));
48 static alpha_extra_func_info_t find_proc_desc
PARAMS ((CORE_ADDR
,
49 struct frame_info
*));
52 static int alpha_in_lenient_prologue
PARAMS ((CORE_ADDR
, CORE_ADDR
));
55 static void reinit_frame_cache_sfunc
PARAMS ((char *, int,
56 struct cmd_list_element
*));
58 static CORE_ADDR after_prologue
PARAMS ((CORE_ADDR pc
,
59 alpha_extra_func_info_t proc_desc
));
61 static int alpha_in_prologue
PARAMS ((CORE_ADDR pc
,
62 alpha_extra_func_info_t proc_desc
));
64 /* Heuristic_proc_start may hunt through the text section for a long
65 time across a 2400 baud serial line. Allows the user to limit this
67 static unsigned int heuristic_fence_post
= 0;
69 /* Layout of a stack frame on the alpha:
72 pdr members: | 7th ... nth arg, |
73 | `pushed' by caller. |
75 ----------------|-------------------------------|<-- old_sp == vfp
78 | |localoff | Copies of 1st .. 6th |
79 | | | | | argument if necessary. |
81 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
83 | | | | Locals and temporaries. |
85 | | | |-------------------------------|
87 |-fregoffset | Saved float registers. |
93 | | -------|-------------------------------|
95 | | | Saved registers. |
102 | ----------|-------------------------------|
104 frameoffset | Argument build area, gets |
105 | | 7th ... nth arg for any |
106 | | called procedure. |
108 -------------|-------------------------------|<-- sp
112 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
113 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
114 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
115 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
116 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
117 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
118 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
119 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
120 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
121 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
122 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
123 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
124 #define _PROC_MAGIC_ 0x0F0F0F0F
125 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
126 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
128 struct linked_proc_info
130 struct alpha_extra_func_info info
;
131 struct linked_proc_info
*next
;
132 } *linked_proc_desc_table
= NULL
;
135 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
139 alpha_find_saved_regs (frame
)
140 struct frame_info
*frame
;
143 CORE_ADDR reg_position
;
145 alpha_extra_func_info_t proc_desc
;
148 frame
->saved_regs
= (struct frame_saved_regs
*)
149 obstack_alloc (&frame_cache_obstack
, sizeof(struct frame_saved_regs
));
150 memset (frame
->saved_regs
, 0, sizeof (struct frame_saved_regs
));
152 /* If it is the frame for __sigtramp, the saved registers are located
153 in a sigcontext structure somewhere on the stack. __sigtramp
154 passes a pointer to the sigcontext structure on the stack.
155 If the stack layout for __sigtramp changes, or if sigcontext offsets
156 change, we might have to update this code. */
157 #ifndef SIGFRAME_PC_OFF
158 #define SIGFRAME_PC_OFF (2 * 8)
159 #define SIGFRAME_REGSAVE_OFF (4 * 8)
160 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
162 if (frame
->signal_handler_caller
)
164 CORE_ADDR sigcontext_pointer_addr
;
165 CORE_ADDR sigcontext_addr
;
168 sigcontext_pointer_addr
= frame
->next
->frame
;
170 sigcontext_pointer_addr
= frame
->frame
;
171 sigcontext_addr
= read_memory_integer(sigcontext_pointer_addr
, 8);
172 for (ireg
= 0; ireg
< 32; ireg
++)
174 reg_position
= sigcontext_addr
+ SIGFRAME_REGSAVE_OFF
+ ireg
* 8;
175 frame
->saved_regs
->regs
[ireg
] = reg_position
;
177 for (ireg
= 0; ireg
< 32; ireg
++)
179 reg_position
= sigcontext_addr
+ SIGFRAME_FPREGSAVE_OFF
+ ireg
* 8;
180 frame
->saved_regs
->regs
[FP0_REGNUM
+ ireg
] = reg_position
;
182 frame
->saved_regs
->regs
[PC_REGNUM
] = sigcontext_addr
+ SIGFRAME_PC_OFF
;
186 proc_desc
= frame
->proc_desc
;
187 if (proc_desc
== NULL
)
188 /* I'm not sure how/whether this can happen. Normally when we can't
189 find a proc_desc, we "synthesize" one using heuristic_proc_desc
190 and set the saved_regs right away. */
193 /* Fill in the offsets for the registers which gen_mask says
196 reg_position
= frame
->frame
+ PROC_REG_OFFSET (proc_desc
);
197 mask
= PROC_REG_MASK (proc_desc
);
199 returnreg
= PROC_PC_REG (proc_desc
);
201 /* Note that RA is always saved first, regardless of its actual
203 if (mask
& (1 << returnreg
))
205 frame
->saved_regs
->regs
[returnreg
] = reg_position
;
207 mask
&= ~(1 << returnreg
); /* Clear bit for RA so we
208 don't save again later. */
211 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
212 if (mask
& (1 << ireg
))
214 frame
->saved_regs
->regs
[ireg
] = reg_position
;
218 /* Fill in the offsets for the registers which float_mask says
221 reg_position
= frame
->frame
+ PROC_FREG_OFFSET (proc_desc
);
222 mask
= PROC_FREG_MASK (proc_desc
);
224 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
225 if (mask
& (1 << ireg
))
227 frame
->saved_regs
->regs
[FP0_REGNUM
+ireg
] = reg_position
;
231 frame
->saved_regs
->regs
[PC_REGNUM
] = frame
->saved_regs
->regs
[returnreg
];
235 read_next_frame_reg(fi
, regno
)
236 struct frame_info
*fi
;
239 for (; fi
; fi
= fi
->next
)
241 /* We have to get the saved sp from the sigcontext
242 if it is a signal handler frame. */
243 if (regno
== SP_REGNUM
&& !fi
->signal_handler_caller
)
247 if (fi
->saved_regs
== NULL
)
248 alpha_find_saved_regs (fi
);
249 if (fi
->saved_regs
->regs
[regno
])
250 return read_memory_integer(fi
->saved_regs
->regs
[regno
], 8);
253 return read_register(regno
);
257 alpha_frame_saved_pc(frame
)
258 struct frame_info
*frame
;
260 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
261 /* We have to get the saved pc from the sigcontext
262 if it is a signal handler frame. */
263 int pcreg
= frame
->signal_handler_caller
? PC_REGNUM
: frame
->pc_reg
;
265 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
266 return read_memory_integer(frame
->frame
- 8, 8);
268 return read_next_frame_reg(frame
, pcreg
);
272 alpha_saved_pc_after_call (frame
)
273 struct frame_info
*frame
;
275 CORE_ADDR pc
= frame
->pc
;
277 alpha_extra_func_info_t proc_desc
;
280 /* Skip over shared library trampoline if necessary. */
281 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
285 proc_desc
= find_proc_desc (pc
, frame
->next
);
286 pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
;
288 return read_register (pcreg
);
292 static struct alpha_extra_func_info temp_proc_desc
;
293 static struct frame_saved_regs temp_saved_regs
;
295 /* This fencepost looks highly suspicious to me. Removing it also
296 seems suspicious as it could affect remote debugging across serial
300 heuristic_proc_start(pc
)
303 CORE_ADDR start_pc
= pc
;
304 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
306 if (start_pc
== 0) return 0;
308 if (heuristic_fence_post
== UINT_MAX
309 || fence
< VM_MIN_ADDRESS
)
310 fence
= VM_MIN_ADDRESS
;
312 /* search back for previous return */
313 for (start_pc
-= 4; ; start_pc
-= 4)
314 if (start_pc
< fence
)
316 /* It's not clear to me why we reach this point when
317 stop_soon_quietly, but with this test, at least we
318 don't print out warnings for every child forked (eg, on
319 decstation). 22apr93 rich@cygnus.com. */
320 if (!stop_soon_quietly
)
322 static int blurb_printed
= 0;
324 if (fence
== VM_MIN_ADDRESS
)
325 warning("Hit beginning of text section without finding");
327 warning("Hit heuristic-fence-post without finding");
329 warning("enclosing function for address 0x%lx", pc
);
333 This warning occurs if you are debugging a function without any symbols\n\
334 (for example, in a stripped executable). In that case, you may wish to\n\
335 increase the size of the search with the `set heuristic-fence-post' command.\n\
337 Otherwise, you told GDB there was a function where there isn't one, or\n\
338 (more likely) you have encountered a bug in GDB.\n");
345 else if (ABOUT_TO_RETURN(start_pc
))
348 start_pc
+= 4; /* skip return */
352 static alpha_extra_func_info_t
353 heuristic_proc_desc(start_pc
, limit_pc
, next_frame
)
354 CORE_ADDR start_pc
, limit_pc
;
355 struct frame_info
*next_frame
;
357 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
360 int has_frame_reg
= 0;
361 unsigned long reg_mask
= 0;
365 memset (&temp_proc_desc
, '\0', sizeof(temp_proc_desc
));
366 memset (&temp_saved_regs
, '\0', sizeof(struct frame_saved_regs
));
367 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
369 if (start_pc
+ 200 < limit_pc
)
370 limit_pc
= start_pc
+ 200;
372 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
378 status
= read_memory_nobpt (cur_pc
, buf
, 4);
380 memory_error (status
, cur_pc
);
381 word
= extract_unsigned_integer (buf
, 4);
383 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
384 frame_size
+= (-word
) & 0xffff;
385 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
386 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
388 int reg
= (word
& 0x03e00000) >> 21;
389 reg_mask
|= 1 << reg
;
390 temp_saved_regs
.regs
[reg
] = sp
+ (short)word
;
392 else if (word
== 0x47de040f) /* bis sp,sp fp */
396 PROC_FRAME_REG(&temp_proc_desc
) = GCC_FP_REGNUM
;
398 PROC_FRAME_REG(&temp_proc_desc
) = SP_REGNUM
;
399 PROC_FRAME_OFFSET(&temp_proc_desc
) = frame_size
;
400 PROC_REG_MASK(&temp_proc_desc
) = reg_mask
;
401 PROC_PC_REG(&temp_proc_desc
) = RA_REGNUM
;
402 PROC_LOCALOFF(&temp_proc_desc
) = 0; /* XXX - bogus */
403 return &temp_proc_desc
;
406 /* This returns the PC of the first inst after the prologue. If we can't
407 find the prologue, then return 0. */
410 after_prologue (pc
, proc_desc
)
412 alpha_extra_func_info_t proc_desc
;
414 struct symtab_and_line sal
;
415 CORE_ADDR func_addr
, func_end
;
418 proc_desc
= find_proc_desc (pc
, NULL
);
422 /* If function is frameless, then we need to do it the hard way. I
423 strongly suspect that frameless always means prologueless... */
424 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
425 && PROC_FRAME_OFFSET (proc_desc
) == 0)
429 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
430 return 0; /* Unknown */
432 sal
= find_pc_line (func_addr
, 0);
434 if (sal
.end
< func_end
)
437 /* The line after the prologue is after the end of the function. In this
438 case, tell the caller to find the prologue the hard way. */
443 /* Return non-zero if we *might* be in a function prologue. Return zero if we
444 are definatly *not* in a function prologue. */
447 alpha_in_prologue (pc
, proc_desc
)
449 alpha_extra_func_info_t proc_desc
;
451 CORE_ADDR after_prologue_pc
;
453 after_prologue_pc
= after_prologue (pc
, proc_desc
);
455 if (after_prologue_pc
== 0
456 || pc
< after_prologue_pc
)
462 static alpha_extra_func_info_t
463 find_proc_desc (pc
, next_frame
)
465 struct frame_info
*next_frame
;
467 alpha_extra_func_info_t proc_desc
;
472 /* Try to get the proc_desc from the linked call dummy proc_descs
473 if the pc is in the call dummy.
474 This is hairy. In the case of nested dummy calls we have to find the
475 right proc_desc, but we might not yet know the frame for the dummy
476 as it will be contained in the proc_desc we are searching for.
477 So we have to find the proc_desc whose frame is closest to the current
480 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
482 struct linked_proc_info
*link
;
483 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
484 alpha_extra_func_info_t found_proc_desc
= NULL
;
485 long min_distance
= LONG_MAX
;
487 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
489 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
490 if (distance
> 0 && distance
< min_distance
)
492 min_distance
= distance
;
493 found_proc_desc
= &link
->info
;
496 if (found_proc_desc
!= NULL
)
497 return found_proc_desc
;
500 b
= block_for_pc(pc
);
502 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
507 if (startaddr
> BLOCK_START (b
))
508 /* This is the "pathological" case referred to in a comment in
509 print_frame_info. It might be better to move this check into
513 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
517 /* If we never found a PDR for this function in symbol reading, then
518 examine prologues to find the information. */
519 if (sym
&& ((mips_extra_func_info_t
) SYMBOL_VALUE (sym
))->pdr
.framereg
== -1)
524 /* IF this is the topmost frame AND
525 * (this proc does not have debugging information OR
526 * the PC is in the procedure prologue)
527 * THEN create a "heuristic" proc_desc (by analyzing
528 * the actual code) to replace the "official" proc_desc.
530 proc_desc
= (alpha_extra_func_info_t
)SYMBOL_VALUE(sym
);
531 if (next_frame
== NULL
)
533 if (PROC_DESC_IS_DUMMY (proc_desc
) || alpha_in_prologue (pc
, proc_desc
))
535 alpha_extra_func_info_t found_heuristic
=
536 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
540 PROC_LOCALOFF (found_heuristic
) =
541 PROC_LOCALOFF (proc_desc
);
542 PROC_PC_REG (found_heuristic
) = PROC_PC_REG (proc_desc
);
543 proc_desc
= found_heuristic
;
550 /* Is linked_proc_desc_table really necessary? It only seems to be used
551 by procedure call dummys. However, the procedures being called ought
552 to have their own proc_descs, and even if they don't,
553 heuristic_proc_desc knows how to create them! */
555 register struct linked_proc_info
*link
;
556 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
557 if (PROC_LOW_ADDR(&link
->info
) <= pc
558 && PROC_HIGH_ADDR(&link
->info
) > pc
)
562 startaddr
= heuristic_proc_start (pc
);
565 heuristic_proc_desc (startaddr
, pc
, next_frame
);
570 alpha_extra_func_info_t cached_proc_desc
;
573 alpha_frame_chain(frame
)
574 struct frame_info
*frame
;
576 alpha_extra_func_info_t proc_desc
;
577 CORE_ADDR saved_pc
= FRAME_SAVED_PC(frame
);
579 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
582 proc_desc
= find_proc_desc(saved_pc
, frame
);
586 cached_proc_desc
= proc_desc
;
588 /* Fetch the frame pointer for a dummy frame from the procedure
590 if (PROC_DESC_IS_DUMMY(proc_desc
))
591 return (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
593 /* If no frame pointer and frame size is zero, we must be at end
594 of stack (or otherwise hosed). If we don't check frame size,
595 we loop forever if we see a zero size frame. */
596 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
597 && PROC_FRAME_OFFSET (proc_desc
) == 0
598 /* The previous frame from a sigtramp frame might be frameless
599 and have frame size zero. */
600 && !frame
->signal_handler_caller
)
602 /* The alpha __sigtramp routine is frameless and has a frame size
603 of zero, but we are able to backtrace through it. */
605 find_pc_partial_function (saved_pc
, &name
,
606 (CORE_ADDR
*)NULL
, (CORE_ADDR
*)NULL
);
607 if (IN_SIGTRAMP (saved_pc
, name
))
613 return read_next_frame_reg(frame
, PROC_FRAME_REG(proc_desc
))
614 + PROC_FRAME_OFFSET(proc_desc
);
618 init_extra_frame_info (frame
)
619 struct frame_info
*frame
;
621 /* Use proc_desc calculated in frame_chain */
622 alpha_extra_func_info_t proc_desc
=
623 frame
->next
? cached_proc_desc
: find_proc_desc(frame
->pc
, frame
->next
);
625 frame
->saved_regs
= NULL
;
627 frame
->pc_reg
= RA_REGNUM
;
628 frame
->proc_desc
= proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
631 /* Get the locals offset and the saved pc register from the
632 procedure descriptor, they are valid even if we are in the
633 middle of the prologue. */
634 frame
->localoff
= PROC_LOCALOFF(proc_desc
);
635 frame
->pc_reg
= PROC_PC_REG(proc_desc
);
637 /* Fixup frame-pointer - only needed for top frame */
639 /* Fetch the frame pointer for a dummy frame from the procedure
641 if (PROC_DESC_IS_DUMMY(proc_desc
))
642 frame
->frame
= (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
644 /* This may not be quite right, if proc has a real frame register.
645 Get the value of the frame relative sp, procedure might have been
646 interrupted by a signal at it's very start. */
647 else if (frame
->pc
== PROC_LOW_ADDR (proc_desc
) && !PROC_DESC_IS_DUMMY (proc_desc
))
648 frame
->frame
= read_next_frame_reg (frame
->next
, SP_REGNUM
);
650 frame
->frame
= read_next_frame_reg (frame
->next
, PROC_FRAME_REG (proc_desc
))
651 + PROC_FRAME_OFFSET (proc_desc
);
653 if (proc_desc
== &temp_proc_desc
)
657 /* Do not set the saved registers for a sigtramp frame,
658 alpha_find_saved_registers will do that for us.
659 We can't use frame->signal_handler_caller, it is not yet set. */
660 find_pc_partial_function (frame
->pc
, &name
,
661 (CORE_ADDR
*)NULL
,(CORE_ADDR
*)NULL
);
662 if (!IN_SIGTRAMP (frame
->pc
, name
))
664 frame
->saved_regs
= (struct frame_saved_regs
*)
665 obstack_alloc (&frame_cache_obstack
,
666 sizeof (struct frame_saved_regs
));
667 *frame
->saved_regs
= temp_saved_regs
;
668 frame
->saved_regs
->regs
[PC_REGNUM
]
669 = frame
->saved_regs
->regs
[RA_REGNUM
];
675 /* ALPHA stack frames are almost impenetrable. When execution stops,
676 we basically have to look at symbol information for the function
677 that we stopped in, which tells us *which* register (if any) is
678 the base of the frame pointer, and what offset from that register
679 the frame itself is at.
681 This presents a problem when trying to examine a stack in memory
682 (that isn't executing at the moment), using the "frame" command. We
683 don't have a PC, nor do we have any registers except SP.
685 This routine takes two arguments, SP and PC, and tries to make the
686 cached frames look as if these two arguments defined a frame on the
687 cache. This allows the rest of info frame to extract the important
688 arguments without difficulty. */
691 setup_arbitrary_frame (argc
, argv
)
696 error ("ALPHA frame specifications require two arguments: sp and pc");
698 return create_new_frame (argv
[0], argv
[1]);
701 /* The alpha passes the first six arguments in the registers, the rest on
702 the stack. The register arguments are eventually transferred to the
703 argument transfer area immediately below the stack by the called function
704 anyway. So we `push' at least six arguments on the stack, `reload' the
705 argument registers and then adjust the stack pointer to point past the
706 sixth argument. This algorithm simplifies the passing of a large struct
707 which extends from the registers to the stack.
708 If the called function is returning a structure, the address of the
709 structure to be returned is passed as a hidden first argument. */
712 alpha_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
717 CORE_ADDR struct_addr
;
720 int accumulate_size
= struct_return
? 8 : 0;
721 int arg_regs_size
= ALPHA_NUM_ARG_REGS
* 8;
722 struct alpha_arg
{ char *contents
; int len
; int offset
; };
723 struct alpha_arg
*alpha_args
=
724 (struct alpha_arg
*)alloca (nargs
* sizeof (struct alpha_arg
));
725 register struct alpha_arg
*m_arg
;
726 char raw_buffer
[sizeof (CORE_ADDR
)];
727 int required_arg_regs
;
729 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
731 value_ptr arg
= args
[i
];
732 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
733 /* Cast argument to long if necessary as the compiler does it too. */
734 switch (TYPE_CODE (arg_type
))
739 case TYPE_CODE_RANGE
:
741 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
743 arg_type
= builtin_type_long
;
744 arg
= value_cast (arg_type
, arg
);
750 m_arg
->len
= TYPE_LENGTH (arg_type
);
751 m_arg
->offset
= accumulate_size
;
752 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
753 m_arg
->contents
= VALUE_CONTENTS(arg
);
756 /* Determine required argument register loads, loading an argument register
757 is expensive as it uses three ptrace calls. */
758 required_arg_regs
= accumulate_size
/ 8;
759 if (required_arg_regs
> ALPHA_NUM_ARG_REGS
)
760 required_arg_regs
= ALPHA_NUM_ARG_REGS
;
762 /* Make room for the arguments on the stack. */
763 if (accumulate_size
< arg_regs_size
)
764 accumulate_size
= arg_regs_size
;
765 sp
-= accumulate_size
;
767 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
770 /* `Push' arguments on the stack. */
771 for (i
= nargs
; m_arg
--, --i
>= 0; )
772 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
775 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
776 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
779 /* Load the argument registers. */
780 for (i
= 0; i
< required_arg_regs
; i
++)
784 val
= read_memory_integer (sp
+ i
* 8, 8);
785 write_register (A0_REGNUM
+ i
, val
);
786 write_register (FPA0_REGNUM
+ i
, val
);
789 return sp
+ arg_regs_size
;
793 alpha_push_dummy_frame()
796 struct linked_proc_info
*link
;
797 alpha_extra_func_info_t proc_desc
;
798 CORE_ADDR sp
= read_register (SP_REGNUM
);
799 CORE_ADDR save_address
;
800 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
803 link
= (struct linked_proc_info
*) xmalloc(sizeof (struct linked_proc_info
));
804 link
->next
= linked_proc_desc_table
;
805 linked_proc_desc_table
= link
;
807 proc_desc
= &link
->info
;
810 * The registers we must save are all those not preserved across
812 * In addition, we must save the PC and RA.
814 * Dummy frame layout:
824 * Parameter build area
828 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
829 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
830 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
831 #define GEN_REG_SAVE_COUNT 24
832 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
833 #define FLOAT_REG_SAVE_COUNT 23
834 /* The special register is the PC as we have no bit for it in the save masks.
835 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
836 #define SPECIAL_REG_SAVE_COUNT 1
838 PROC_REG_MASK(proc_desc
) = GEN_REG_SAVE_MASK
;
839 PROC_FREG_MASK(proc_desc
) = FLOAT_REG_SAVE_MASK
;
840 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
841 but keep SP aligned to a multiple of 16. */
842 PROC_REG_OFFSET(proc_desc
) =
843 - ((8 * (SPECIAL_REG_SAVE_COUNT
845 + FLOAT_REG_SAVE_COUNT
)
847 PROC_FREG_OFFSET(proc_desc
) =
848 PROC_REG_OFFSET(proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
850 /* Save general registers.
851 The return address register is the first saved register, all other
852 registers follow in ascending order.
853 The PC is saved immediately below the SP. */
854 save_address
= sp
+ PROC_REG_OFFSET(proc_desc
);
855 store_address (raw_buffer
, 8, read_register (RA_REGNUM
));
856 write_memory (save_address
, raw_buffer
, 8);
858 mask
= PROC_REG_MASK(proc_desc
) & 0xffffffffL
;
859 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
862 if (ireg
== RA_REGNUM
)
864 store_address (raw_buffer
, 8, read_register (ireg
));
865 write_memory (save_address
, raw_buffer
, 8);
869 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
870 write_memory (sp
- 8, raw_buffer
, 8);
872 /* Save floating point registers. */
873 save_address
= sp
+ PROC_FREG_OFFSET(proc_desc
);
874 mask
= PROC_FREG_MASK(proc_desc
) & 0xffffffffL
;
875 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
878 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
879 write_memory (save_address
, raw_buffer
, 8);
883 /* Set and save the frame address for the dummy.
884 This is tricky. The only registers that are suitable for a frame save
885 are those that are preserved across procedure calls (s0-s6). But if
886 a read system call is interrupted and then a dummy call is made
887 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
888 is satisfied. Then it returns with the s0-s6 registers set to the values
889 on entry to the read system call and our dummy frame pointer would be
890 destroyed. So we save the dummy frame in the proc_desc and handle the
891 retrieval of the frame pointer of a dummy specifically. The frame register
892 is set to the virtual frame (pseudo) register, it's value will always
893 be read as zero and will help us to catch any errors in the dummy frame
895 PROC_DUMMY_FRAME(proc_desc
) = sp
;
896 PROC_FRAME_REG(proc_desc
) = FP_REGNUM
;
897 PROC_FRAME_OFFSET(proc_desc
) = 0;
898 sp
+= PROC_REG_OFFSET(proc_desc
);
899 write_register (SP_REGNUM
, sp
);
901 PROC_LOW_ADDR(proc_desc
) = CALL_DUMMY_ADDRESS ();
902 PROC_HIGH_ADDR(proc_desc
) = PROC_LOW_ADDR(proc_desc
) + 4;
904 SET_PROC_DESC_IS_DUMMY(proc_desc
);
905 PROC_PC_REG(proc_desc
) = RA_REGNUM
;
912 struct frame_info
*frame
= get_current_frame ();
913 CORE_ADDR new_sp
= frame
->frame
;
915 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
917 write_register (PC_REGNUM
, FRAME_SAVED_PC(frame
));
918 if (frame
->saved_regs
== NULL
)
919 alpha_find_saved_regs (frame
);
922 for (regnum
= 32; --regnum
>= 0; )
923 if (PROC_REG_MASK(proc_desc
) & (1 << regnum
))
924 write_register (regnum
,
925 read_memory_integer (frame
->saved_regs
->regs
[regnum
],
927 for (regnum
= 32; --regnum
>= 0; )
928 if (PROC_FREG_MASK(proc_desc
) & (1 << regnum
))
929 write_register (regnum
+ FP0_REGNUM
,
930 read_memory_integer (frame
->saved_regs
->regs
[regnum
+ FP0_REGNUM
], 8));
932 write_register (SP_REGNUM
, new_sp
);
933 flush_cached_frames ();
935 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
937 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
939 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
941 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
943 if (&pi_ptr
->info
== proc_desc
)
948 error ("Can't locate dummy extra frame info\n");
950 if (prev_ptr
!= NULL
)
951 prev_ptr
->next
= pi_ptr
->next
;
953 linked_proc_desc_table
= pi_ptr
->next
;
959 /* To skip prologues, I use this predicate. Returns either PC itself
960 if the code at PC does not look like a function prologue; otherwise
961 returns an address that (if we're lucky) follows the prologue. If
962 LENIENT, then we must skip everything which is involved in setting
963 up the frame (it's OK to skip more, just so long as we don't skip
964 anything which might clobber the registers which are being saved.
965 Currently we must not skip more on the alpha, but we might the lenient
969 alpha_skip_prologue (pc
, lenient
)
975 CORE_ADDR post_prologue_pc
;
978 #ifdef GDB_TARGET_HAS_SHARED_LIBS
979 /* Silently return the unaltered pc upon memory errors.
980 This could happen on OSF/1 if decode_line_1 tries to skip the
981 prologue for quickstarted shared library functions when the
982 shared library is not yet mapped in.
983 Reading target memory is slow over serial lines, so we perform
984 this check only if the target has shared libraries. */
985 if (target_read_memory (pc
, buf
, 4))
989 /* See if we can determine the end of the prologue via the symbol table.
990 If so, then return either PC, or the PC after the prologue, whichever
993 post_prologue_pc
= after_prologue (pc
, NULL
);
995 if (post_prologue_pc
!= 0)
996 return max (pc
, post_prologue_pc
);
998 /* Can't determine prologue from the symbol table, need to examine
1001 /* Skip the typical prologue instructions. These are the stack adjustment
1002 instruction and the instructions that save registers on the stack
1003 or in the gcc frame. */
1004 for (offset
= 0; offset
< 100; offset
+= 4)
1008 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
1010 memory_error (status
, pc
+ offset
);
1011 inst
= extract_unsigned_integer (buf
, 4);
1013 /* The alpha has no delay slots. But let's keep the lenient stuff,
1014 we might need it for something else in the future. */
1018 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1020 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1022 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1024 else if ((inst
& 0xfc1f0000) == 0xb41e0000
1025 && (inst
& 0xffff0000) != 0xb7fe0000)
1026 continue; /* stq reg,n($sp) */
1028 else if ((inst
& 0xfc1f0000) == 0x9c1e0000
1029 && (inst
& 0xffff0000) != 0x9ffe0000)
1030 continue; /* stt reg,n($sp) */
1032 else if (inst
== 0x47de040f) /* bis sp,sp,fp */
1041 /* Is address PC in the prologue (loosely defined) for function at
1045 alpha_in_lenient_prologue (startaddr
, pc
)
1046 CORE_ADDR startaddr
;
1049 CORE_ADDR end_prologue
= alpha_skip_prologue (startaddr
, 1);
1050 return pc
>= startaddr
&& pc
< end_prologue
;
1054 /* The alpha needs a conversion between register and memory format if
1055 the register is a floating point register and
1056 memory format is float, as the register format must be double
1058 memory format is an integer with 4 bytes or less, as the representation
1059 of integers in floating point registers is different. */
1061 alpha_register_convert_to_virtual (regnum
, valtype
, raw_buffer
, virtual_buffer
)
1063 struct type
*valtype
;
1065 char *virtual_buffer
;
1067 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1069 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
1073 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1075 double d
= extract_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1076 store_floating (virtual_buffer
, TYPE_LENGTH (valtype
), d
);
1078 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1081 l
= extract_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1082 l
= ((l
>> 32) & 0xc0000000) | ((l
>> 29) & 0x3fffffff);
1083 store_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
), l
);
1086 error ("Cannot retrieve value from floating point register");
1090 alpha_register_convert_to_raw (valtype
, regnum
, virtual_buffer
, raw_buffer
)
1091 struct type
*valtype
;
1093 char *virtual_buffer
;
1096 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1098 memcpy (raw_buffer
, virtual_buffer
, REGISTER_RAW_SIZE (regnum
));
1102 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1104 double d
= extract_floating (virtual_buffer
, TYPE_LENGTH (valtype
));
1105 store_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
), d
);
1107 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1110 if (TYPE_UNSIGNED (valtype
))
1111 l
= extract_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1113 l
= extract_signed_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1114 l
= ((l
& 0xc0000000) << 32) | ((l
& 0x3fffffff) << 29);
1115 store_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
), l
);
1118 error ("Cannot store value in floating point register");
1121 /* Given a return value in `regbuf' with a type `valtype',
1122 extract and copy its value into `valbuf'. */
1125 alpha_extract_return_value (valtype
, regbuf
, valbuf
)
1126 struct type
*valtype
;
1127 char regbuf
[REGISTER_BYTES
];
1130 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1131 alpha_register_convert_to_virtual (FP0_REGNUM
, valtype
,
1132 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
1135 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (V0_REGNUM
), TYPE_LENGTH (valtype
));
1138 /* Given a return value in `regbuf' with a type `valtype',
1139 write its value into the appropriate register. */
1142 alpha_store_return_value (valtype
, valbuf
)
1143 struct type
*valtype
;
1146 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1147 int regnum
= V0_REGNUM
;
1148 int length
= TYPE_LENGTH (valtype
);
1150 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1152 regnum
= FP0_REGNUM
;
1153 length
= REGISTER_RAW_SIZE (regnum
);
1154 alpha_register_convert_to_raw (valtype
, regnum
, valbuf
, raw_buffer
);
1157 memcpy (raw_buffer
, valbuf
, length
);
1159 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, length
);
1162 /* Just like reinit_frame_cache, but with the right arguments to be
1163 callable as an sfunc. */
1166 reinit_frame_cache_sfunc (args
, from_tty
, c
)
1169 struct cmd_list_element
*c
;
1171 reinit_frame_cache ();
1174 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1175 to find a convenient place in the text segment to stick a breakpoint to
1176 detect the completion of a target function call (ala call_function_by_hand).
1180 alpha_call_dummy_address ()
1183 struct minimal_symbol
*sym
;
1185 entry
= entry_point_address ();
1190 sym
= lookup_minimal_symbol ("_Prelude", NULL
, symfile_objfile
);
1192 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1195 return SYMBOL_VALUE_ADDRESS (sym
) + 4;
1199 _initialize_alpha_tdep ()
1201 struct cmd_list_element
*c
;
1203 tm_print_insn
= print_insn_alpha
;
1205 /* Let the user set the fence post for heuristic_proc_start. */
1207 /* We really would like to have both "0" and "unlimited" work, but
1208 command.c doesn't deal with that. So make it a var_zinteger
1209 because the user can always use "999999" or some such for unlimited. */
1210 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
1211 (char *) &heuristic_fence_post
,
1213 Set the distance searched for the start of a function.\n\
1214 If you are debugging a stripped executable, GDB needs to search through the\n\
1215 program for the start of a function. This command sets the distance of the\n\
1216 search. The only need to set it is when debugging a stripped executable.",
1218 /* We need to throw away the frame cache when we set this, since it
1219 might change our ability to get backtraces. */
1220 c
->function
.sfunc
= reinit_frame_cache_sfunc
;
1221 add_show_from_set (c
, &showlist
);