1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "gdb_string.h"
36 #include "arch-utils.h"
41 #include "alpha-tdep.h"
43 static gdbarch_init_ftype alpha_gdbarch_init
;
45 static gdbarch_register_name_ftype alpha_register_name
;
46 static gdbarch_register_raw_size_ftype alpha_register_raw_size
;
47 static gdbarch_register_virtual_size_ftype alpha_register_virtual_size
;
48 static gdbarch_register_virtual_type_ftype alpha_register_virtual_type
;
49 static gdbarch_register_byte_ftype alpha_register_byte
;
50 static gdbarch_cannot_fetch_register_ftype alpha_cannot_fetch_register
;
51 static gdbarch_cannot_store_register_ftype alpha_cannot_store_register
;
52 static gdbarch_register_convertible_ftype alpha_register_convertible
;
53 static gdbarch_register_convert_to_virtual_ftype
54 alpha_register_convert_to_virtual
;
55 static gdbarch_register_convert_to_raw_ftype alpha_register_convert_to_raw
;
56 static gdbarch_store_struct_return_ftype alpha_store_struct_return
;
57 static gdbarch_deprecated_extract_return_value_ftype alpha_extract_return_value
;
58 static gdbarch_deprecated_extract_struct_value_address_ftype
59 alpha_extract_struct_value_address
;
60 static gdbarch_use_struct_convention_ftype alpha_use_struct_convention
;
62 static gdbarch_breakpoint_from_pc_ftype alpha_breakpoint_from_pc
;
64 static gdbarch_frame_args_address_ftype alpha_frame_args_address
;
65 static gdbarch_frame_locals_address_ftype alpha_frame_locals_address
;
67 static gdbarch_skip_prologue_ftype alpha_skip_prologue
;
68 static gdbarch_saved_pc_after_call_ftype alpha_saved_pc_after_call
;
69 static gdbarch_frame_chain_ftype alpha_frame_chain
;
70 static gdbarch_frame_saved_pc_ftype alpha_frame_saved_pc
;
71 static gdbarch_frame_init_saved_regs_ftype alpha_frame_init_saved_regs
;
73 static gdbarch_push_arguments_ftype alpha_push_arguments
;
74 static gdbarch_push_dummy_frame_ftype alpha_push_dummy_frame
;
75 static gdbarch_pop_frame_ftype alpha_pop_frame
;
76 static gdbarch_fix_call_dummy_ftype alpha_fix_call_dummy
;
77 static gdbarch_init_extra_frame_info_ftype alpha_init_extra_frame_info
;
79 static gdbarch_get_longjmp_target_ftype alpha_get_longjmp_target
;
81 struct frame_extra_info
83 alpha_extra_func_info_t proc_desc
;
88 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
90 /* Prototypes for local functions. */
92 static void alpha_find_saved_regs (struct frame_info
*);
94 static alpha_extra_func_info_t
push_sigtramp_desc (CORE_ADDR low_addr
);
96 static CORE_ADDR
read_next_frame_reg (struct frame_info
*, int);
98 static CORE_ADDR
heuristic_proc_start (CORE_ADDR
);
100 static alpha_extra_func_info_t
heuristic_proc_desc (CORE_ADDR
,
102 struct frame_info
*);
104 static alpha_extra_func_info_t
find_proc_desc (CORE_ADDR
,
105 struct frame_info
*);
108 static int alpha_in_lenient_prologue (CORE_ADDR
, CORE_ADDR
);
111 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element
*);
113 static CORE_ADDR
after_prologue (CORE_ADDR pc
,
114 alpha_extra_func_info_t proc_desc
);
116 static int alpha_in_prologue (CORE_ADDR pc
,
117 alpha_extra_func_info_t proc_desc
);
119 static int alpha_about_to_return (CORE_ADDR pc
);
121 void _initialize_alpha_tdep (void);
123 /* Heuristic_proc_start may hunt through the text section for a long
124 time across a 2400 baud serial line. Allows the user to limit this
126 static unsigned int heuristic_fence_post
= 0;
128 /* Layout of a stack frame on the alpha:
131 pdr members: | 7th ... nth arg, |
132 | `pushed' by caller. |
134 ----------------|-------------------------------|<-- old_sp == vfp
137 | |localoff | Copies of 1st .. 6th |
138 | | | | | argument if necessary. |
140 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
142 | | | | Locals and temporaries. |
144 | | | |-------------------------------|
146 |-fregoffset | Saved float registers. |
152 | | -------|-------------------------------|
154 | | | Saved registers. |
161 | ----------|-------------------------------|
163 frameoffset | Argument build area, gets |
164 | | 7th ... nth arg for any |
165 | | called procedure. |
167 -------------|-------------------------------|<-- sp
172 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
173 /* These next two fields are kind of being hijacked. I wonder if
174 iline is too small for the values it needs to hold, if GDB is
175 running on a 32-bit host. */
176 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
177 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
178 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
179 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
180 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
181 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
182 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
183 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
184 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
185 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
186 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
187 #define _PROC_MAGIC_ 0x0F0F0F0F
188 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
189 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
191 struct linked_proc_info
193 struct alpha_extra_func_info info
;
194 struct linked_proc_info
*next
;
196 *linked_proc_desc_table
= NULL
;
199 alpha_frame_past_sigtramp_frame (struct frame_info
*frame
, CORE_ADDR pc
)
201 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
203 if (tdep
->skip_sigtramp_frame
!= NULL
)
204 return (tdep
->skip_sigtramp_frame (frame
, pc
));
210 alpha_dynamic_sigtramp_offset (CORE_ADDR pc
)
212 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
214 /* Must be provided by OS/ABI variant code if supported. */
215 if (tdep
->dynamic_sigtramp_offset
!= NULL
)
216 return (tdep
->dynamic_sigtramp_offset (pc
));
221 #define ALPHA_PROC_SIGTRAMP_MAGIC 0x0e0f0f0f
223 /* Return TRUE if the procedure descriptor PROC is a procedure
224 descriptor that refers to a dynamically generated signal
225 trampoline routine. */
227 alpha_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info
*proc
)
229 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
231 if (tdep
->dynamic_sigtramp_offset
!= NULL
)
232 return (proc
->pdr
.isym
== ALPHA_PROC_SIGTRAMP_MAGIC
);
238 alpha_set_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info
*proc
)
240 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
242 if (tdep
->dynamic_sigtramp_offset
!= NULL
)
243 proc
->pdr
.isym
= ALPHA_PROC_SIGTRAMP_MAGIC
;
246 /* Dynamically create a signal-handler caller procedure descriptor for
247 the signal-handler return code starting at address LOW_ADDR. The
248 descriptor is added to the linked_proc_desc_table. */
250 static alpha_extra_func_info_t
251 push_sigtramp_desc (CORE_ADDR low_addr
)
253 struct linked_proc_info
*link
;
254 alpha_extra_func_info_t proc_desc
;
256 link
= (struct linked_proc_info
*)
257 xmalloc (sizeof (struct linked_proc_info
));
258 link
->next
= linked_proc_desc_table
;
259 linked_proc_desc_table
= link
;
261 proc_desc
= &link
->info
;
263 proc_desc
->numargs
= 0;
264 PROC_LOW_ADDR (proc_desc
) = low_addr
;
265 PROC_HIGH_ADDR (proc_desc
) = low_addr
+ 3 * 4;
266 PROC_DUMMY_FRAME (proc_desc
) = 0;
267 PROC_FRAME_OFFSET (proc_desc
) = 0x298; /* sizeof(struct sigcontext_struct) */
268 PROC_FRAME_REG (proc_desc
) = SP_REGNUM
;
269 PROC_REG_MASK (proc_desc
) = 0xffff;
270 PROC_FREG_MASK (proc_desc
) = 0xffff;
271 PROC_PC_REG (proc_desc
) = 26;
272 PROC_LOCALOFF (proc_desc
) = 0;
273 alpha_set_proc_desc_is_dyn_sigtramp (proc_desc
);
279 alpha_register_name (int regno
)
281 static char *register_names
[] =
283 "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
284 "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
285 "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
286 "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero",
287 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
288 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
289 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
290 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr",
296 if (regno
>= (sizeof(register_names
) / sizeof(*register_names
)))
298 return (register_names
[regno
]);
302 alpha_cannot_fetch_register (int regno
)
304 return (regno
== FP_REGNUM
|| regno
== ALPHA_ZERO_REGNUM
);
308 alpha_cannot_store_register (int regno
)
310 return (regno
== FP_REGNUM
|| regno
== ALPHA_ZERO_REGNUM
);
314 alpha_register_convertible (int regno
)
316 return (regno
>= FP0_REGNUM
&& regno
<= FP0_REGNUM
+ 31);
320 alpha_register_virtual_type (int regno
)
322 return ((regno
>= FP0_REGNUM
&& regno
< (FP0_REGNUM
+31))
323 ? builtin_type_double
: builtin_type_long
);
327 alpha_register_byte (int regno
)
333 alpha_register_raw_size (int regno
)
339 alpha_register_virtual_size (int regno
)
346 alpha_sigcontext_addr (struct frame_info
*fi
)
348 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
350 if (tdep
->sigcontext_addr
)
351 return (tdep
->sigcontext_addr (fi
));
356 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
360 alpha_find_saved_regs (struct frame_info
*frame
)
363 CORE_ADDR reg_position
;
365 alpha_extra_func_info_t proc_desc
;
368 frame_saved_regs_zalloc (frame
);
370 /* If it is the frame for __sigtramp, the saved registers are located
371 in a sigcontext structure somewhere on the stack. __sigtramp
372 passes a pointer to the sigcontext structure on the stack.
373 If the stack layout for __sigtramp changes, or if sigcontext offsets
374 change, we might have to update this code. */
375 #ifndef SIGFRAME_PC_OFF
376 #define SIGFRAME_PC_OFF (2 * 8)
377 #define SIGFRAME_REGSAVE_OFF (4 * 8)
378 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
380 if ((get_frame_type (frame
) == SIGTRAMP_FRAME
))
382 CORE_ADDR sigcontext_addr
;
384 sigcontext_addr
= alpha_sigcontext_addr (frame
);
385 if (sigcontext_addr
== 0)
387 /* Don't know where the sigcontext is; just bail. */
390 for (ireg
= 0; ireg
< 32; ireg
++)
392 reg_position
= sigcontext_addr
+ SIGFRAME_REGSAVE_OFF
+ ireg
* 8;
393 get_frame_saved_regs (frame
)[ireg
] = reg_position
;
395 for (ireg
= 0; ireg
< 32; ireg
++)
397 reg_position
= sigcontext_addr
+ SIGFRAME_FPREGSAVE_OFF
+ ireg
* 8;
398 get_frame_saved_regs (frame
)[FP0_REGNUM
+ ireg
] = reg_position
;
400 get_frame_saved_regs (frame
)[PC_REGNUM
] = sigcontext_addr
+ SIGFRAME_PC_OFF
;
404 proc_desc
= frame
->extra_info
->proc_desc
;
405 if (proc_desc
== NULL
)
406 /* I'm not sure how/whether this can happen. Normally when we can't
407 find a proc_desc, we "synthesize" one using heuristic_proc_desc
408 and set the saved_regs right away. */
411 /* Fill in the offsets for the registers which gen_mask says
414 reg_position
= frame
->frame
+ PROC_REG_OFFSET (proc_desc
);
415 mask
= PROC_REG_MASK (proc_desc
);
417 returnreg
= PROC_PC_REG (proc_desc
);
419 /* Note that RA is always saved first, regardless of its actual
421 if (mask
& (1 << returnreg
))
423 get_frame_saved_regs (frame
)[returnreg
] = reg_position
;
425 mask
&= ~(1 << returnreg
); /* Clear bit for RA so we
426 don't save again later. */
429 for (ireg
= 0; ireg
<= 31; ++ireg
)
430 if (mask
& (1 << ireg
))
432 get_frame_saved_regs (frame
)[ireg
] = reg_position
;
436 /* Fill in the offsets for the registers which float_mask says
439 reg_position
= frame
->frame
+ PROC_FREG_OFFSET (proc_desc
);
440 mask
= PROC_FREG_MASK (proc_desc
);
442 for (ireg
= 0; ireg
<= 31; ++ireg
)
443 if (mask
& (1 << ireg
))
445 get_frame_saved_regs (frame
)[FP0_REGNUM
+ ireg
] = reg_position
;
449 get_frame_saved_regs (frame
)[PC_REGNUM
] = get_frame_saved_regs (frame
)[returnreg
];
453 alpha_frame_init_saved_regs (struct frame_info
*fi
)
455 if (get_frame_saved_regs (fi
) == NULL
)
456 alpha_find_saved_regs (fi
);
457 get_frame_saved_regs (fi
)[SP_REGNUM
] = fi
->frame
;
461 alpha_init_frame_pc_first (int fromleaf
, struct frame_info
*prev
)
463 return (fromleaf
? SAVED_PC_AFTER_CALL (get_next_frame (prev
))
464 : get_next_frame (prev
) ? FRAME_SAVED_PC (prev
->next
)
469 read_next_frame_reg (struct frame_info
*fi
, int regno
)
471 for (; fi
; fi
= fi
->next
)
473 /* We have to get the saved sp from the sigcontext
474 if it is a signal handler frame. */
475 if (regno
== SP_REGNUM
&& !(get_frame_type (fi
) == SIGTRAMP_FRAME
))
479 if (get_frame_saved_regs (fi
) == NULL
)
480 alpha_find_saved_regs (fi
);
481 if (get_frame_saved_regs (fi
)[regno
])
482 return read_memory_integer (get_frame_saved_regs (fi
)[regno
], 8);
485 return read_register (regno
);
489 alpha_frame_saved_pc (struct frame_info
*frame
)
491 alpha_extra_func_info_t proc_desc
= frame
->extra_info
->proc_desc
;
492 /* We have to get the saved pc from the sigcontext
493 if it is a signal handler frame. */
494 int pcreg
= (get_frame_type (frame
) == SIGTRAMP_FRAME
) ? PC_REGNUM
495 : frame
->extra_info
->pc_reg
;
497 if (proc_desc
&& PROC_DESC_IS_DUMMY (proc_desc
))
498 return read_memory_integer (frame
->frame
- 8, 8);
500 return read_next_frame_reg (frame
, pcreg
);
504 alpha_saved_pc_after_call (struct frame_info
*frame
)
506 CORE_ADDR pc
= get_frame_pc (frame
);
508 alpha_extra_func_info_t proc_desc
;
511 /* Skip over shared library trampoline if necessary. */
512 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
516 proc_desc
= find_proc_desc (pc
, frame
->next
);
517 pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : ALPHA_RA_REGNUM
;
519 if ((get_frame_type (frame
) == SIGTRAMP_FRAME
))
520 return alpha_frame_saved_pc (frame
);
522 return read_register (pcreg
);
526 static struct alpha_extra_func_info temp_proc_desc
;
527 static CORE_ADDR temp_saved_regs
[ALPHA_NUM_REGS
];
529 /* Nonzero if instruction at PC is a return instruction. "ret
530 $zero,($ra),1" on alpha. */
533 alpha_about_to_return (CORE_ADDR pc
)
535 return read_memory_integer (pc
, 4) == 0x6bfa8001;
540 /* This fencepost looks highly suspicious to me. Removing it also
541 seems suspicious as it could affect remote debugging across serial
545 heuristic_proc_start (CORE_ADDR pc
)
547 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
548 CORE_ADDR start_pc
= pc
;
549 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
554 if (heuristic_fence_post
== UINT_MAX
555 || fence
< tdep
->vm_min_address
)
556 fence
= tdep
->vm_min_address
;
558 /* search back for previous return */
559 for (start_pc
-= 4;; start_pc
-= 4)
560 if (start_pc
< fence
)
562 /* It's not clear to me why we reach this point when
563 stop_soon_quietly, but with this test, at least we
564 don't print out warnings for every child forked (eg, on
565 decstation). 22apr93 rich@cygnus.com. */
566 if (!stop_soon_quietly
)
568 static int blurb_printed
= 0;
570 if (fence
== tdep
->vm_min_address
)
571 warning ("Hit beginning of text section without finding");
573 warning ("Hit heuristic-fence-post without finding");
575 warning ("enclosing function for address 0x%s", paddr_nz (pc
));
579 This warning occurs if you are debugging a function without any symbols\n\
580 (for example, in a stripped executable). In that case, you may wish to\n\
581 increase the size of the search with the `set heuristic-fence-post' command.\n\
583 Otherwise, you told GDB there was a function where there isn't one, or\n\
584 (more likely) you have encountered a bug in GDB.\n");
591 else if (alpha_about_to_return (start_pc
))
594 start_pc
+= 4; /* skip return */
598 static alpha_extra_func_info_t
599 heuristic_proc_desc (CORE_ADDR start_pc
, CORE_ADDR limit_pc
,
600 struct frame_info
*next_frame
)
602 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
606 int has_frame_reg
= 0;
607 unsigned long reg_mask
= 0;
613 memset (&temp_proc_desc
, '\0', sizeof (temp_proc_desc
));
614 memset (&temp_saved_regs
, '\0', SIZEOF_FRAME_SAVED_REGS
);
615 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
617 if (start_pc
+ 200 < limit_pc
)
618 limit_pc
= start_pc
+ 200;
620 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
626 status
= read_memory_nobpt (cur_pc
, buf
, 4);
628 memory_error (status
, cur_pc
);
629 word
= extract_unsigned_integer (buf
, 4);
631 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
635 /* Consider only the first stack allocation instruction
636 to contain the static size of the frame. */
638 frame_size
+= (-word
) & 0xffff;
641 /* Exit loop if a positive stack adjustment is found, which
642 usually means that the stack cleanup code in the function
643 epilogue is reached. */
646 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
647 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
649 int reg
= (word
& 0x03e00000) >> 21;
650 reg_mask
|= 1 << reg
;
652 /* Do not compute the address where the register was saved yet,
653 because we don't know yet if the offset will need to be
654 relative to $sp or $fp (we can not compute the address relative
655 to $sp if $sp is updated during the execution of the current
656 subroutine, for instance when doing some alloca). So just store
657 the offset for the moment, and compute the address later
658 when we know whether this frame has a frame pointer or not.
660 temp_saved_regs
[reg
] = (short) word
;
662 /* Starting with OSF/1-3.2C, the system libraries are shipped
663 without local symbols, but they still contain procedure
664 descriptors without a symbol reference. GDB is currently
665 unable to find these procedure descriptors and uses
666 heuristic_proc_desc instead.
667 As some low level compiler support routines (__div*, __add*)
668 use a non-standard return address register, we have to
669 add some heuristics to determine the return address register,
670 or stepping over these routines will fail.
671 Usually the return address register is the first register
672 saved on the stack, but assembler optimization might
673 rearrange the register saves.
674 So we recognize only a few registers (t7, t9, ra) within
675 the procedure prologue as valid return address registers.
676 If we encounter a return instruction, we extract the
677 the return address register from it.
679 FIXME: Rewriting GDB to access the procedure descriptors,
680 e.g. via the minimal symbol table, might obviate this hack. */
682 && cur_pc
< (start_pc
+ 80)
683 && (reg
== ALPHA_T7_REGNUM
|| reg
== ALPHA_T9_REGNUM
684 || reg
== ALPHA_RA_REGNUM
))
687 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
688 pcreg
= (word
>> 16) & 0x1f;
689 else if (word
== 0x47de040f || word
== 0x47fe040f) /* bis sp,sp fp */
691 /* ??? I am not sure what instruction is 0x47fe040f, and I
692 am suspecting that there was a typo and should have been
693 0x47fe040f. I'm keeping it in the test above until further
696 vfp
= read_next_frame_reg (next_frame
, ALPHA_GCC_FP_REGNUM
);
701 /* If we haven't found a valid return address register yet,
702 keep searching in the procedure prologue. */
703 while (cur_pc
< (limit_pc
+ 80) && cur_pc
< (start_pc
+ 80))
708 if (read_memory_nobpt (cur_pc
, buf
, 4))
711 word
= extract_unsigned_integer (buf
, 4);
713 if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
714 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
716 int reg
= (word
& 0x03e00000) >> 21;
717 if (reg
== ALPHA_T7_REGNUM
|| reg
== ALPHA_T9_REGNUM
718 || reg
== ALPHA_RA_REGNUM
)
724 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
726 pcreg
= (word
>> 16) & 0x1f;
733 PROC_FRAME_REG (&temp_proc_desc
) = ALPHA_GCC_FP_REGNUM
;
735 PROC_FRAME_REG (&temp_proc_desc
) = SP_REGNUM
;
737 /* At this point, we know which of the Stack Pointer or the Frame Pointer
738 to use as the reference address to compute the saved registers address.
739 But in both cases, the processing above has set vfp to this reference
740 address, so just need to increment the offset of each saved register
742 for (regno
= 0; regno
< NUM_REGS
; regno
++)
744 if (reg_mask
& 1 << regno
)
745 temp_saved_regs
[regno
] += vfp
;
748 PROC_FRAME_OFFSET (&temp_proc_desc
) = frame_size
;
749 PROC_REG_MASK (&temp_proc_desc
) = reg_mask
;
750 PROC_PC_REG (&temp_proc_desc
) = (pcreg
== -1) ? ALPHA_RA_REGNUM
: pcreg
;
751 PROC_LOCALOFF (&temp_proc_desc
) = 0; /* XXX - bogus */
752 return &temp_proc_desc
;
755 /* This returns the PC of the first inst after the prologue. If we can't
756 find the prologue, then return 0. */
759 after_prologue (CORE_ADDR pc
, alpha_extra_func_info_t proc_desc
)
761 struct symtab_and_line sal
;
762 CORE_ADDR func_addr
, func_end
;
765 proc_desc
= find_proc_desc (pc
, NULL
);
769 if (alpha_proc_desc_is_dyn_sigtramp (proc_desc
))
770 return PROC_LOW_ADDR (proc_desc
); /* "prologue" is in kernel */
772 /* If function is frameless, then we need to do it the hard way. I
773 strongly suspect that frameless always means prologueless... */
774 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
775 && PROC_FRAME_OFFSET (proc_desc
) == 0)
779 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
780 return 0; /* Unknown */
782 sal
= find_pc_line (func_addr
, 0);
784 if (sal
.end
< func_end
)
787 /* The line after the prologue is after the end of the function. In this
788 case, tell the caller to find the prologue the hard way. */
793 /* Return non-zero if we *might* be in a function prologue. Return zero if we
794 are definitively *not* in a function prologue. */
797 alpha_in_prologue (CORE_ADDR pc
, alpha_extra_func_info_t proc_desc
)
799 CORE_ADDR after_prologue_pc
;
801 after_prologue_pc
= after_prologue (pc
, proc_desc
);
803 if (after_prologue_pc
== 0
804 || pc
< after_prologue_pc
)
810 static alpha_extra_func_info_t
811 find_proc_desc (CORE_ADDR pc
, struct frame_info
*next_frame
)
813 alpha_extra_func_info_t proc_desc
;
818 /* Try to get the proc_desc from the linked call dummy proc_descs
819 if the pc is in the call dummy.
820 This is hairy. In the case of nested dummy calls we have to find the
821 right proc_desc, but we might not yet know the frame for the dummy
822 as it will be contained in the proc_desc we are searching for.
823 So we have to find the proc_desc whose frame is closest to the current
826 if (DEPRECATED_PC_IN_CALL_DUMMY (pc
, 0, 0))
828 struct linked_proc_info
*link
;
829 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
830 alpha_extra_func_info_t found_proc_desc
= NULL
;
831 long min_distance
= LONG_MAX
;
833 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
835 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
836 if (distance
> 0 && distance
< min_distance
)
838 min_distance
= distance
;
839 found_proc_desc
= &link
->info
;
842 if (found_proc_desc
!= NULL
)
843 return found_proc_desc
;
846 b
= block_for_pc (pc
);
848 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
853 if (startaddr
> BLOCK_START (b
))
854 /* This is the "pathological" case referred to in a comment in
855 print_frame_info. It might be better to move this check into
859 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
863 /* If we never found a PDR for this function in symbol reading, then
864 examine prologues to find the information. */
865 if (sym
&& ((mips_extra_func_info_t
) SYMBOL_VALUE (sym
))->pdr
.framereg
== -1)
870 /* IF this is the topmost frame AND
871 * (this proc does not have debugging information OR
872 * the PC is in the procedure prologue)
873 * THEN create a "heuristic" proc_desc (by analyzing
874 * the actual code) to replace the "official" proc_desc.
876 proc_desc
= (alpha_extra_func_info_t
) SYMBOL_VALUE (sym
);
877 if (next_frame
== NULL
)
879 if (PROC_DESC_IS_DUMMY (proc_desc
) || alpha_in_prologue (pc
, proc_desc
))
881 alpha_extra_func_info_t found_heuristic
=
882 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
886 PROC_LOCALOFF (found_heuristic
) =
887 PROC_LOCALOFF (proc_desc
);
888 PROC_PC_REG (found_heuristic
) = PROC_PC_REG (proc_desc
);
889 proc_desc
= found_heuristic
;
898 /* Is linked_proc_desc_table really necessary? It only seems to be used
899 by procedure call dummys. However, the procedures being called ought
900 to have their own proc_descs, and even if they don't,
901 heuristic_proc_desc knows how to create them! */
903 register struct linked_proc_info
*link
;
904 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
905 if (PROC_LOW_ADDR (&link
->info
) <= pc
906 && PROC_HIGH_ADDR (&link
->info
) > pc
)
909 /* If PC is inside a dynamically generated sigtramp handler,
910 create and push a procedure descriptor for that code: */
911 offset
= alpha_dynamic_sigtramp_offset (pc
);
913 return push_sigtramp_desc (pc
- offset
);
915 /* If heuristic_fence_post is non-zero, determine the procedure
916 start address by examining the instructions.
917 This allows us to find the start address of static functions which
918 have no symbolic information, as startaddr would have been set to
919 the preceding global function start address by the
920 find_pc_partial_function call above. */
921 if (startaddr
== 0 || heuristic_fence_post
!= 0)
922 startaddr
= heuristic_proc_start (pc
);
925 heuristic_proc_desc (startaddr
, pc
, next_frame
);
930 alpha_extra_func_info_t cached_proc_desc
;
933 alpha_frame_chain (struct frame_info
*frame
)
935 alpha_extra_func_info_t proc_desc
;
936 CORE_ADDR saved_pc
= FRAME_SAVED_PC (frame
);
938 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
941 proc_desc
= find_proc_desc (saved_pc
, frame
);
945 cached_proc_desc
= proc_desc
;
947 /* Fetch the frame pointer for a dummy frame from the procedure
949 if (PROC_DESC_IS_DUMMY (proc_desc
))
950 return (CORE_ADDR
) PROC_DUMMY_FRAME (proc_desc
);
952 /* If no frame pointer and frame size is zero, we must be at end
953 of stack (or otherwise hosed). If we don't check frame size,
954 we loop forever if we see a zero size frame. */
955 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
956 && PROC_FRAME_OFFSET (proc_desc
) == 0
957 /* The previous frame from a sigtramp frame might be frameless
958 and have frame size zero. */
959 && !(get_frame_type (frame
) == SIGTRAMP_FRAME
))
960 return alpha_frame_past_sigtramp_frame (frame
, saved_pc
);
962 return read_next_frame_reg (frame
, PROC_FRAME_REG (proc_desc
))
963 + PROC_FRAME_OFFSET (proc_desc
);
967 alpha_print_extra_frame_info (struct frame_info
*fi
)
971 && fi
->extra_info
->proc_desc
972 && fi
->extra_info
->proc_desc
->pdr
.framereg
< NUM_REGS
)
973 printf_filtered (" frame pointer is at %s+%s\n",
974 REGISTER_NAME (fi
->extra_info
->proc_desc
->pdr
.framereg
),
975 paddr_d (fi
->extra_info
->proc_desc
->pdr
.frameoffset
));
979 alpha_init_extra_frame_info (int fromleaf
, struct frame_info
*frame
)
981 /* Use proc_desc calculated in frame_chain */
982 alpha_extra_func_info_t proc_desc
=
983 frame
->next
? cached_proc_desc
: find_proc_desc (get_frame_pc (frame
), frame
->next
);
985 frame
->extra_info
= (struct frame_extra_info
*)
986 frame_obstack_alloc (sizeof (struct frame_extra_info
));
988 /* NOTE: cagney/2003-01-03: No need to set saved_regs to NULL,
989 always NULL by default. */
990 /* frame->saved_regs = NULL; */
991 frame
->extra_info
->localoff
= 0;
992 frame
->extra_info
->pc_reg
= ALPHA_RA_REGNUM
;
993 frame
->extra_info
->proc_desc
= proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
996 /* Get the locals offset and the saved pc register from the
997 procedure descriptor, they are valid even if we are in the
998 middle of the prologue. */
999 frame
->extra_info
->localoff
= PROC_LOCALOFF (proc_desc
);
1000 frame
->extra_info
->pc_reg
= PROC_PC_REG (proc_desc
);
1002 /* Fixup frame-pointer - only needed for top frame */
1004 /* Fetch the frame pointer for a dummy frame from the procedure
1006 if (PROC_DESC_IS_DUMMY (proc_desc
))
1007 deprecated_update_frame_base_hack (frame
, (CORE_ADDR
) PROC_DUMMY_FRAME (proc_desc
));
1009 /* This may not be quite right, if proc has a real frame register.
1010 Get the value of the frame relative sp, procedure might have been
1011 interrupted by a signal at it's very start. */
1012 else if (get_frame_pc (frame
) == PROC_LOW_ADDR (proc_desc
)
1013 && !alpha_proc_desc_is_dyn_sigtramp (proc_desc
))
1014 deprecated_update_frame_base_hack (frame
, read_next_frame_reg (frame
->next
, SP_REGNUM
));
1016 deprecated_update_frame_base_hack (frame
, read_next_frame_reg (frame
->next
, PROC_FRAME_REG (proc_desc
))
1017 + PROC_FRAME_OFFSET (proc_desc
));
1019 if (proc_desc
== &temp_proc_desc
)
1023 /* Do not set the saved registers for a sigtramp frame,
1024 alpha_find_saved_registers will do that for us. We can't
1025 use (get_frame_type (frame) == SIGTRAMP_FRAME), it is not
1027 /* FIXME: cagney/2002-11-18: This problem will go away once
1028 frame.c:get_prev_frame() is modified to set the frame's
1029 type before calling functions like this. */
1030 find_pc_partial_function (get_frame_pc (frame
), &name
,
1031 (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
1032 if (!PC_IN_SIGTRAMP (get_frame_pc (frame
), name
))
1034 frame_saved_regs_zalloc (frame
);
1035 memcpy (get_frame_saved_regs (frame
), temp_saved_regs
,
1036 SIZEOF_FRAME_SAVED_REGS
);
1037 get_frame_saved_regs (frame
)[PC_REGNUM
]
1038 = get_frame_saved_regs (frame
)[ALPHA_RA_REGNUM
];
1045 alpha_frame_locals_address (struct frame_info
*fi
)
1047 return (fi
->frame
- fi
->extra_info
->localoff
);
1051 alpha_frame_args_address (struct frame_info
*fi
)
1053 return (fi
->frame
- (ALPHA_NUM_ARG_REGS
* 8));
1056 /* ALPHA stack frames are almost impenetrable. When execution stops,
1057 we basically have to look at symbol information for the function
1058 that we stopped in, which tells us *which* register (if any) is
1059 the base of the frame pointer, and what offset from that register
1060 the frame itself is at.
1062 This presents a problem when trying to examine a stack in memory
1063 (that isn't executing at the moment), using the "frame" command. We
1064 don't have a PC, nor do we have any registers except SP.
1066 This routine takes two arguments, SP and PC, and tries to make the
1067 cached frames look as if these two arguments defined a frame on the
1068 cache. This allows the rest of info frame to extract the important
1069 arguments without difficulty. */
1072 alpha_setup_arbitrary_frame (int argc
, CORE_ADDR
*argv
)
1075 error ("ALPHA frame specifications require two arguments: sp and pc");
1077 return create_new_frame (argv
[0], argv
[1]);
1080 /* The alpha passes the first six arguments in the registers, the rest on
1081 the stack. The register arguments are eventually transferred to the
1082 argument transfer area immediately below the stack by the called function
1083 anyway. So we `push' at least six arguments on the stack, `reload' the
1084 argument registers and then adjust the stack pointer to point past the
1085 sixth argument. This algorithm simplifies the passing of a large struct
1086 which extends from the registers to the stack.
1087 If the called function is returning a structure, the address of the
1088 structure to be returned is passed as a hidden first argument. */
1091 alpha_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
1092 int struct_return
, CORE_ADDR struct_addr
)
1095 int accumulate_size
= struct_return
? 8 : 0;
1096 int arg_regs_size
= ALPHA_NUM_ARG_REGS
* 8;
1103 struct alpha_arg
*alpha_args
=
1104 (struct alpha_arg
*) alloca (nargs
* sizeof (struct alpha_arg
));
1105 register struct alpha_arg
*m_arg
;
1106 char raw_buffer
[sizeof (CORE_ADDR
)];
1107 int required_arg_regs
;
1109 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
1111 struct value
*arg
= args
[i
];
1112 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
1113 /* Cast argument to long if necessary as the compiler does it too. */
1114 switch (TYPE_CODE (arg_type
))
1117 case TYPE_CODE_BOOL
:
1118 case TYPE_CODE_CHAR
:
1119 case TYPE_CODE_RANGE
:
1120 case TYPE_CODE_ENUM
:
1121 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
1123 arg_type
= builtin_type_long
;
1124 arg
= value_cast (arg_type
, arg
);
1130 m_arg
->len
= TYPE_LENGTH (arg_type
);
1131 m_arg
->offset
= accumulate_size
;
1132 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
1133 m_arg
->contents
= VALUE_CONTENTS (arg
);
1136 /* Determine required argument register loads, loading an argument register
1137 is expensive as it uses three ptrace calls. */
1138 required_arg_regs
= accumulate_size
/ 8;
1139 if (required_arg_regs
> ALPHA_NUM_ARG_REGS
)
1140 required_arg_regs
= ALPHA_NUM_ARG_REGS
;
1142 /* Make room for the arguments on the stack. */
1143 if (accumulate_size
< arg_regs_size
)
1144 accumulate_size
= arg_regs_size
;
1145 sp
-= accumulate_size
;
1147 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
1150 /* `Push' arguments on the stack. */
1151 for (i
= nargs
; m_arg
--, --i
>= 0;)
1152 write_memory (sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
1155 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
1156 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
1159 /* Load the argument registers. */
1160 for (i
= 0; i
< required_arg_regs
; i
++)
1164 val
= read_memory_integer (sp
+ i
* 8, 8);
1165 write_register (ALPHA_A0_REGNUM
+ i
, val
);
1166 write_register (ALPHA_FPA0_REGNUM
+ i
, val
);
1169 return sp
+ arg_regs_size
;
1173 alpha_push_dummy_frame (void)
1176 struct linked_proc_info
*link
;
1177 alpha_extra_func_info_t proc_desc
;
1178 CORE_ADDR sp
= read_register (SP_REGNUM
);
1179 CORE_ADDR save_address
;
1180 char raw_buffer
[ALPHA_MAX_REGISTER_RAW_SIZE
];
1183 link
= (struct linked_proc_info
*) xmalloc (sizeof (struct linked_proc_info
));
1184 link
->next
= linked_proc_desc_table
;
1185 linked_proc_desc_table
= link
;
1187 proc_desc
= &link
->info
;
1190 * The registers we must save are all those not preserved across
1192 * In addition, we must save the PC and RA.
1194 * Dummy frame layout:
1204 * Parameter build area
1208 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1209 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1210 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1211 #define GEN_REG_SAVE_COUNT 24
1212 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1213 #define FLOAT_REG_SAVE_COUNT 23
1214 /* The special register is the PC as we have no bit for it in the save masks.
1215 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1216 #define SPECIAL_REG_SAVE_COUNT 1
1218 PROC_REG_MASK (proc_desc
) = GEN_REG_SAVE_MASK
;
1219 PROC_FREG_MASK (proc_desc
) = FLOAT_REG_SAVE_MASK
;
1220 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1221 but keep SP aligned to a multiple of 16. */
1222 PROC_REG_OFFSET (proc_desc
) =
1223 -((8 * (SPECIAL_REG_SAVE_COUNT
1224 + GEN_REG_SAVE_COUNT
1225 + FLOAT_REG_SAVE_COUNT
)
1227 PROC_FREG_OFFSET (proc_desc
) =
1228 PROC_REG_OFFSET (proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
1230 /* Save general registers.
1231 The return address register is the first saved register, all other
1232 registers follow in ascending order.
1233 The PC is saved immediately below the SP. */
1234 save_address
= sp
+ PROC_REG_OFFSET (proc_desc
);
1235 store_address (raw_buffer
, 8, read_register (ALPHA_RA_REGNUM
));
1236 write_memory (save_address
, raw_buffer
, 8);
1238 mask
= PROC_REG_MASK (proc_desc
) & 0xffffffffL
;
1239 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1242 if (ireg
== ALPHA_RA_REGNUM
)
1244 store_address (raw_buffer
, 8, read_register (ireg
));
1245 write_memory (save_address
, raw_buffer
, 8);
1249 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
1250 write_memory (sp
- 8, raw_buffer
, 8);
1252 /* Save floating point registers. */
1253 save_address
= sp
+ PROC_FREG_OFFSET (proc_desc
);
1254 mask
= PROC_FREG_MASK (proc_desc
) & 0xffffffffL
;
1255 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1258 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
1259 write_memory (save_address
, raw_buffer
, 8);
1263 /* Set and save the frame address for the dummy.
1264 This is tricky. The only registers that are suitable for a frame save
1265 are those that are preserved across procedure calls (s0-s6). But if
1266 a read system call is interrupted and then a dummy call is made
1267 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1268 is satisfied. Then it returns with the s0-s6 registers set to the values
1269 on entry to the read system call and our dummy frame pointer would be
1270 destroyed. So we save the dummy frame in the proc_desc and handle the
1271 retrieval of the frame pointer of a dummy specifically. The frame register
1272 is set to the virtual frame (pseudo) register, it's value will always
1273 be read as zero and will help us to catch any errors in the dummy frame
1275 PROC_DUMMY_FRAME (proc_desc
) = sp
;
1276 PROC_FRAME_REG (proc_desc
) = FP_REGNUM
;
1277 PROC_FRAME_OFFSET (proc_desc
) = 0;
1278 sp
+= PROC_REG_OFFSET (proc_desc
);
1279 write_register (SP_REGNUM
, sp
);
1281 PROC_LOW_ADDR (proc_desc
) = CALL_DUMMY_ADDRESS ();
1282 PROC_HIGH_ADDR (proc_desc
) = PROC_LOW_ADDR (proc_desc
) + 4;
1284 SET_PROC_DESC_IS_DUMMY (proc_desc
);
1285 PROC_PC_REG (proc_desc
) = ALPHA_RA_REGNUM
;
1289 alpha_pop_frame (void)
1291 register int regnum
;
1292 struct frame_info
*frame
= get_current_frame ();
1293 CORE_ADDR new_sp
= frame
->frame
;
1295 alpha_extra_func_info_t proc_desc
= frame
->extra_info
->proc_desc
;
1297 /* we need proc_desc to know how to restore the registers;
1298 if it is NULL, construct (a temporary) one */
1299 if (proc_desc
== NULL
)
1300 proc_desc
= find_proc_desc (get_frame_pc (frame
), frame
->next
);
1302 /* Question: should we copy this proc_desc and save it in
1303 frame->proc_desc? If we do, who will free it?
1304 For now, we don't save a copy... */
1306 write_register (PC_REGNUM
, FRAME_SAVED_PC (frame
));
1307 if (get_frame_saved_regs (frame
) == NULL
)
1308 alpha_find_saved_regs (frame
);
1311 for (regnum
= 32; --regnum
>= 0;)
1312 if (PROC_REG_MASK (proc_desc
) & (1 << regnum
))
1313 write_register (regnum
,
1314 read_memory_integer (get_frame_saved_regs (frame
)[regnum
],
1316 for (regnum
= 32; --regnum
>= 0;)
1317 if (PROC_FREG_MASK (proc_desc
) & (1 << regnum
))
1318 write_register (regnum
+ FP0_REGNUM
,
1319 read_memory_integer (get_frame_saved_regs (frame
)[regnum
+ FP0_REGNUM
], 8));
1321 write_register (SP_REGNUM
, new_sp
);
1322 flush_cached_frames ();
1324 if (proc_desc
&& (PROC_DESC_IS_DUMMY (proc_desc
)
1325 || alpha_proc_desc_is_dyn_sigtramp (proc_desc
)))
1327 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
1329 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
1331 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
1333 if (&pi_ptr
->info
== proc_desc
)
1338 error ("Can't locate dummy extra frame info\n");
1340 if (prev_ptr
!= NULL
)
1341 prev_ptr
->next
= pi_ptr
->next
;
1343 linked_proc_desc_table
= pi_ptr
->next
;
1349 /* To skip prologues, I use this predicate. Returns either PC itself
1350 if the code at PC does not look like a function prologue; otherwise
1351 returns an address that (if we're lucky) follows the prologue. If
1352 LENIENT, then we must skip everything which is involved in setting
1353 up the frame (it's OK to skip more, just so long as we don't skip
1354 anything which might clobber the registers which are being saved.
1355 Currently we must not skip more on the alpha, but we might need the
1356 lenient stuff some day. */
1359 alpha_skip_prologue_internal (CORE_ADDR pc
, int lenient
)
1363 CORE_ADDR post_prologue_pc
;
1366 /* Silently return the unaltered pc upon memory errors.
1367 This could happen on OSF/1 if decode_line_1 tries to skip the
1368 prologue for quickstarted shared library functions when the
1369 shared library is not yet mapped in.
1370 Reading target memory is slow over serial lines, so we perform
1371 this check only if the target has shared libraries (which all
1372 Alpha targets do). */
1373 if (target_read_memory (pc
, buf
, 4))
1376 /* See if we can determine the end of the prologue via the symbol table.
1377 If so, then return either PC, or the PC after the prologue, whichever
1380 post_prologue_pc
= after_prologue (pc
, NULL
);
1382 if (post_prologue_pc
!= 0)
1383 return max (pc
, post_prologue_pc
);
1385 /* Can't determine prologue from the symbol table, need to examine
1388 /* Skip the typical prologue instructions. These are the stack adjustment
1389 instruction and the instructions that save registers on the stack
1390 or in the gcc frame. */
1391 for (offset
= 0; offset
< 100; offset
+= 4)
1395 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
1397 memory_error (status
, pc
+ offset
);
1398 inst
= extract_unsigned_integer (buf
, 4);
1400 /* The alpha has no delay slots. But let's keep the lenient stuff,
1401 we might need it for something else in the future. */
1405 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1407 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1409 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1411 if ((inst
& 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1414 if ((inst
& 0xfc1f0000) == 0xb41e0000
1415 && (inst
& 0xffff0000) != 0xb7fe0000)
1416 continue; /* stq reg,n($sp) */
1418 if ((inst
& 0xfc1f0000) == 0x9c1e0000
1419 && (inst
& 0xffff0000) != 0x9ffe0000)
1420 continue; /* stt reg,n($sp) */
1422 if (inst
== 0x47de040f) /* bis sp,sp,fp */
1431 alpha_skip_prologue (CORE_ADDR addr
)
1433 return (alpha_skip_prologue_internal (addr
, 0));
1437 /* Is address PC in the prologue (loosely defined) for function at
1441 alpha_in_lenient_prologue (CORE_ADDR startaddr
, CORE_ADDR pc
)
1443 CORE_ADDR end_prologue
= alpha_skip_prologue_internal (startaddr
, 1);
1444 return pc
>= startaddr
&& pc
< end_prologue
;
1448 /* The alpha needs a conversion between register and memory format if
1449 the register is a floating point register and
1450 memory format is float, as the register format must be double
1452 memory format is an integer with 4 bytes or less, as the representation
1453 of integers in floating point registers is different. */
1455 alpha_register_convert_to_virtual (int regnum
, struct type
*valtype
,
1456 char *raw_buffer
, char *virtual_buffer
)
1458 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1460 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
1464 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1466 double d
= extract_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1467 store_floating (virtual_buffer
, TYPE_LENGTH (valtype
), d
);
1469 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1472 l
= extract_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1473 l
= ((l
>> 32) & 0xc0000000) | ((l
>> 29) & 0x3fffffff);
1474 store_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
), l
);
1477 error ("Cannot retrieve value from floating point register");
1481 alpha_register_convert_to_raw (struct type
*valtype
, int regnum
,
1482 char *virtual_buffer
, char *raw_buffer
)
1484 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1486 memcpy (raw_buffer
, virtual_buffer
, REGISTER_RAW_SIZE (regnum
));
1490 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1492 double d
= extract_floating (virtual_buffer
, TYPE_LENGTH (valtype
));
1493 store_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
), d
);
1495 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1498 if (TYPE_UNSIGNED (valtype
))
1499 l
= extract_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1501 l
= extract_signed_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1502 l
= ((l
& 0xc0000000) << 32) | ((l
& 0x3fffffff) << 29);
1503 store_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
), l
);
1506 error ("Cannot store value in floating point register");
1509 static const unsigned char *
1510 alpha_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
1512 static const unsigned char alpha_breakpoint
[] =
1513 { 0x80, 0, 0, 0 }; /* call_pal bpt */
1515 *lenptr
= sizeof(alpha_breakpoint
);
1516 return (alpha_breakpoint
);
1519 /* Given a return value in `regbuf' with a type `valtype',
1520 extract and copy its value into `valbuf'. */
1523 alpha_extract_return_value (struct type
*valtype
,
1524 char regbuf
[ALPHA_REGISTER_BYTES
], char *valbuf
)
1526 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1527 alpha_register_convert_to_virtual (FP0_REGNUM
, valtype
,
1528 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
1531 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (ALPHA_V0_REGNUM
),
1532 TYPE_LENGTH (valtype
));
1535 /* Given a return value in `regbuf' with a type `valtype',
1536 write its value into the appropriate register. */
1539 alpha_store_return_value (struct type
*valtype
, char *valbuf
)
1541 char raw_buffer
[ALPHA_MAX_REGISTER_RAW_SIZE
];
1542 int regnum
= ALPHA_V0_REGNUM
;
1543 int length
= TYPE_LENGTH (valtype
);
1545 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1547 regnum
= FP0_REGNUM
;
1548 length
= REGISTER_RAW_SIZE (regnum
);
1549 alpha_register_convert_to_raw (valtype
, regnum
, valbuf
, raw_buffer
);
1552 memcpy (raw_buffer
, valbuf
, length
);
1554 deprecated_write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, length
);
1557 /* Just like reinit_frame_cache, but with the right arguments to be
1558 callable as an sfunc. */
1561 reinit_frame_cache_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
1563 reinit_frame_cache ();
1566 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1567 to find a convenient place in the text segment to stick a breakpoint to
1568 detect the completion of a target function call (ala call_function_by_hand).
1572 alpha_call_dummy_address (void)
1575 struct minimal_symbol
*sym
;
1577 entry
= entry_point_address ();
1582 sym
= lookup_minimal_symbol ("_Prelude", NULL
, symfile_objfile
);
1584 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1587 return SYMBOL_VALUE_ADDRESS (sym
) + 4;
1591 alpha_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
1592 struct value
**args
, struct type
*type
, int gcc_p
)
1594 CORE_ADDR bp_address
= CALL_DUMMY_ADDRESS ();
1596 if (bp_address
== 0)
1597 error ("no place to put call");
1598 write_register (ALPHA_RA_REGNUM
, bp_address
);
1599 write_register (ALPHA_T12_REGNUM
, fun
);
1602 /* On the Alpha, the call dummy code is nevery copied to user space
1603 (see alpha_fix_call_dummy() above). The contents of this do not
1605 LONGEST alpha_call_dummy_words
[] = { 0 };
1608 alpha_use_struct_convention (int gcc_p
, struct type
*type
)
1610 /* Structures are returned by ref in extra arg0. */
1615 alpha_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
1617 /* Store the address of the place in which to copy the structure the
1618 subroutine will return. Handled by alpha_push_arguments. */
1622 alpha_extract_struct_value_address (char *regbuf
)
1624 return (extract_address (regbuf
+ REGISTER_BYTE (ALPHA_V0_REGNUM
),
1625 REGISTER_RAW_SIZE (ALPHA_V0_REGNUM
)));
1628 /* Figure out where the longjmp will land.
1629 We expect the first arg to be a pointer to the jmp_buf structure from
1630 which we extract the PC (JB_PC) that we will land at. The PC is copied
1631 into the "pc". This routine returns true on success. */
1634 alpha_get_longjmp_target (CORE_ADDR
*pc
)
1636 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1638 char raw_buffer
[ALPHA_MAX_REGISTER_RAW_SIZE
];
1640 jb_addr
= read_register (ALPHA_A0_REGNUM
);
1642 if (target_read_memory (jb_addr
+ (tdep
->jb_pc
* tdep
->jb_elt_size
),
1643 raw_buffer
, tdep
->jb_elt_size
))
1646 *pc
= extract_address (raw_buffer
, tdep
->jb_elt_size
);
1650 /* alpha_software_single_step() is called just before we want to resume
1651 the inferior, if we want to single-step it but there is no hardware
1652 or kernel single-step support (NetBSD on Alpha, for example). We find
1653 the target of the coming instruction and breakpoint it.
1655 single_step is also called just after the inferior stops. If we had
1656 set up a simulated single-step, we undo our damage. */
1659 alpha_next_pc (CORE_ADDR pc
)
1666 insn
= read_memory_unsigned_integer (pc
, sizeof (insn
));
1668 /* Opcode is top 6 bits. */
1669 op
= (insn
>> 26) & 0x3f;
1673 /* Jump format: target PC is:
1675 return (read_register ((insn
>> 16) & 0x1f) & ~3);
1678 if ((op
& 0x30) == 0x30)
1680 /* Branch format: target PC is:
1681 (new PC) + (4 * sext(displacement)) */
1682 if (op
== 0x30 || /* BR */
1683 op
== 0x34) /* BSR */
1686 offset
= (insn
& 0x001fffff);
1687 if (offset
& 0x00100000)
1688 offset
|= 0xffe00000;
1690 return (pc
+ 4 + offset
);
1693 /* Need to determine if branch is taken; read RA. */
1694 rav
= (LONGEST
) read_register ((insn
>> 21) & 0x1f);
1697 case 0x38: /* BLBC */
1701 case 0x3c: /* BLBS */
1705 case 0x39: /* BEQ */
1709 case 0x3d: /* BNE */
1713 case 0x3a: /* BLT */
1717 case 0x3b: /* BLE */
1721 case 0x3f: /* BGT */
1725 case 0x3e: /* BGE */
1732 /* Not a branch or branch not taken; target PC is:
1738 alpha_software_single_step (enum target_signal sig
, int insert_breakpoints_p
)
1740 static CORE_ADDR next_pc
;
1741 typedef char binsn_quantum
[BREAKPOINT_MAX
];
1742 static binsn_quantum break_mem
;
1745 if (insert_breakpoints_p
)
1748 next_pc
= alpha_next_pc (pc
);
1750 target_insert_breakpoint (next_pc
, break_mem
);
1754 target_remove_breakpoint (next_pc
, break_mem
);
1761 /* Initialize the current architecture based on INFO. If possible, re-use an
1762 architecture from ARCHES, which is a list of architectures already created
1763 during this debugging session.
1765 Called e.g. at program startup, when reading a core file, and when reading
1768 static struct gdbarch
*
1769 alpha_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1771 struct gdbarch_tdep
*tdep
;
1772 struct gdbarch
*gdbarch
;
1774 /* Try to determine the ABI of the object we are loading. */
1775 if (info
.abfd
!= NULL
&& info
.osabi
== GDB_OSABI_UNKNOWN
)
1777 /* If it's an ECOFF file, assume it's OSF/1. */
1778 if (bfd_get_flavour (info
.abfd
) == bfd_target_ecoff_flavour
)
1779 osabi
= GDB_OSABI_OSF1
;
1782 /* Find a candidate among extant architectures. */
1783 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1785 return arches
->gdbarch
;
1787 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
1788 gdbarch
= gdbarch_alloc (&info
, tdep
);
1790 /* Lowest text address. This is used by heuristic_proc_start() to
1791 decide when to stop looking. */
1792 tdep
->vm_min_address
= (CORE_ADDR
) 0x120000000;
1794 tdep
->dynamic_sigtramp_offset
= NULL
;
1795 tdep
->skip_sigtramp_frame
= NULL
;
1796 tdep
->sigcontext_addr
= NULL
;
1798 tdep
->jb_pc
= -1; /* longjmp support not enabled by default */
1801 set_gdbarch_short_bit (gdbarch
, 16);
1802 set_gdbarch_int_bit (gdbarch
, 32);
1803 set_gdbarch_long_bit (gdbarch
, 64);
1804 set_gdbarch_long_long_bit (gdbarch
, 64);
1805 set_gdbarch_float_bit (gdbarch
, 32);
1806 set_gdbarch_double_bit (gdbarch
, 64);
1807 set_gdbarch_long_double_bit (gdbarch
, 64);
1808 set_gdbarch_ptr_bit (gdbarch
, 64);
1811 set_gdbarch_num_regs (gdbarch
, ALPHA_NUM_REGS
);
1812 set_gdbarch_sp_regnum (gdbarch
, ALPHA_SP_REGNUM
);
1813 set_gdbarch_fp_regnum (gdbarch
, ALPHA_FP_REGNUM
);
1814 set_gdbarch_pc_regnum (gdbarch
, ALPHA_PC_REGNUM
);
1815 set_gdbarch_fp0_regnum (gdbarch
, ALPHA_FP0_REGNUM
);
1817 set_gdbarch_register_name (gdbarch
, alpha_register_name
);
1818 set_gdbarch_register_size (gdbarch
, ALPHA_REGISTER_SIZE
);
1819 set_gdbarch_register_bytes (gdbarch
, ALPHA_REGISTER_BYTES
);
1820 set_gdbarch_register_byte (gdbarch
, alpha_register_byte
);
1821 set_gdbarch_register_raw_size (gdbarch
, alpha_register_raw_size
);
1822 set_gdbarch_max_register_raw_size (gdbarch
, ALPHA_MAX_REGISTER_RAW_SIZE
);
1823 set_gdbarch_register_virtual_size (gdbarch
, alpha_register_virtual_size
);
1824 set_gdbarch_max_register_virtual_size (gdbarch
,
1825 ALPHA_MAX_REGISTER_VIRTUAL_SIZE
);
1826 set_gdbarch_register_virtual_type (gdbarch
, alpha_register_virtual_type
);
1828 set_gdbarch_cannot_fetch_register (gdbarch
, alpha_cannot_fetch_register
);
1829 set_gdbarch_cannot_store_register (gdbarch
, alpha_cannot_store_register
);
1831 set_gdbarch_register_convertible (gdbarch
, alpha_register_convertible
);
1832 set_gdbarch_register_convert_to_virtual (gdbarch
,
1833 alpha_register_convert_to_virtual
);
1834 set_gdbarch_register_convert_to_raw (gdbarch
, alpha_register_convert_to_raw
);
1836 set_gdbarch_skip_prologue (gdbarch
, alpha_skip_prologue
);
1838 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
1839 set_gdbarch_frameless_function_invocation (gdbarch
,
1840 generic_frameless_function_invocation_not
);
1842 set_gdbarch_saved_pc_after_call (gdbarch
, alpha_saved_pc_after_call
);
1844 set_gdbarch_frame_chain (gdbarch
, alpha_frame_chain
);
1845 set_gdbarch_frame_saved_pc (gdbarch
, alpha_frame_saved_pc
);
1847 set_gdbarch_frame_init_saved_regs (gdbarch
, alpha_frame_init_saved_regs
);
1849 set_gdbarch_use_struct_convention (gdbarch
, alpha_use_struct_convention
);
1850 set_gdbarch_deprecated_extract_return_value (gdbarch
, alpha_extract_return_value
);
1852 set_gdbarch_store_struct_return (gdbarch
, alpha_store_struct_return
);
1853 set_gdbarch_deprecated_store_return_value (gdbarch
, alpha_store_return_value
);
1854 set_gdbarch_deprecated_extract_struct_value_address (gdbarch
,
1855 alpha_extract_struct_value_address
);
1857 /* Settings for calling functions in the inferior. */
1858 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch
, 0);
1859 set_gdbarch_call_dummy_length (gdbarch
, 0);
1860 set_gdbarch_push_arguments (gdbarch
, alpha_push_arguments
);
1861 set_gdbarch_pop_frame (gdbarch
, alpha_pop_frame
);
1863 /* On the Alpha, the call dummy code is never copied to user space,
1864 stopping the user call is achieved via a bp_call_dummy breakpoint.
1865 But we need a fake CALL_DUMMY definition to enable the proper
1866 call_function_by_hand and to avoid zero length array warnings. */
1867 set_gdbarch_call_dummy_p (gdbarch
, 1);
1868 set_gdbarch_call_dummy_words (gdbarch
, alpha_call_dummy_words
);
1869 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
1870 set_gdbarch_frame_args_address (gdbarch
, alpha_frame_args_address
);
1871 set_gdbarch_frame_locals_address (gdbarch
, alpha_frame_locals_address
);
1872 set_gdbarch_init_extra_frame_info (gdbarch
, alpha_init_extra_frame_info
);
1874 /* Alpha OSF/1 inhibits execution of code on the stack. But there is
1875 no need for a dummy on the Alpha. PUSH_ARGUMENTS takes care of all
1876 argument handling and bp_call_dummy takes care of stopping the dummy. */
1877 set_gdbarch_call_dummy_address (gdbarch
, alpha_call_dummy_address
);
1878 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
1879 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
1880 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
1881 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
1882 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
1883 set_gdbarch_push_dummy_frame (gdbarch
, alpha_push_dummy_frame
);
1884 set_gdbarch_fix_call_dummy (gdbarch
, alpha_fix_call_dummy
);
1885 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_noop
);
1886 set_gdbarch_deprecated_init_frame_pc_first (gdbarch
, alpha_init_frame_pc_first
);
1888 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1889 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1891 set_gdbarch_breakpoint_from_pc (gdbarch
, alpha_breakpoint_from_pc
);
1892 set_gdbarch_decr_pc_after_break (gdbarch
, 4);
1894 set_gdbarch_function_start_offset (gdbarch
, 0);
1895 set_gdbarch_frame_args_skip (gdbarch
, 0);
1897 /* Hook in ABI-specific overrides, if they have been registered. */
1898 gdbarch_init_osabi (info
, gdbarch
);
1900 /* Now that we have tuned the configuration, set a few final things
1901 based on what the OS ABI has told us. */
1903 if (tdep
->jb_pc
>= 0)
1904 set_gdbarch_get_longjmp_target (gdbarch
, alpha_get_longjmp_target
);
1910 alpha_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1912 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1917 fprintf_unfiltered (file
,
1918 "alpha_dump_tdep: vm_min_address = 0x%lx\n",
1919 (long) tdep
->vm_min_address
);
1921 fprintf_unfiltered (file
,
1922 "alpha_dump_tdep: jb_pc = %d\n",
1924 fprintf_unfiltered (file
,
1925 "alpha_dump_tdep: jb_elt_size = %ld\n",
1926 (long) tdep
->jb_elt_size
);
1930 _initialize_alpha_tdep (void)
1932 struct cmd_list_element
*c
;
1934 gdbarch_register (bfd_arch_alpha
, alpha_gdbarch_init
, alpha_dump_tdep
);
1936 tm_print_insn
= print_insn_alpha
;
1938 /* Let the user set the fence post for heuristic_proc_start. */
1940 /* We really would like to have both "0" and "unlimited" work, but
1941 command.c doesn't deal with that. So make it a var_zinteger
1942 because the user can always use "999999" or some such for unlimited. */
1943 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
1944 (char *) &heuristic_fence_post
,
1946 Set the distance searched for the start of a function.\n\
1947 If you are debugging a stripped executable, GDB needs to search through the\n\
1948 program for the start of a function. This command sets the distance of the\n\
1949 search. The only need to set it is when debugging a stripped executable.",
1951 /* We need to throw away the frame cache when we set this, since it
1952 might change our ability to get backtraces. */
1953 set_cmd_sfunc (c
, reinit_frame_cache_sfunc
);
1954 add_show_from_set (c
, &showlist
);