1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
29 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
31 #define VM_MIN_ADDRESS (CORE_ADDR)0x120000000
34 /* Forward declarations. */
37 read_next_frame_reg
PARAMS ((FRAME
, int));
40 heuristic_proc_start
PARAMS ((CORE_ADDR
));
42 static alpha_extra_func_info_t
43 heuristic_proc_desc
PARAMS ((CORE_ADDR
, CORE_ADDR
, FRAME
));
45 static alpha_extra_func_info_t
46 find_proc_desc
PARAMS ((CORE_ADDR
, FRAME
));
49 alpha_in_lenient_prologue
PARAMS ((CORE_ADDR
, CORE_ADDR
));
52 reinit_frame_cache_sfunc
PARAMS ((char *, int, struct cmd_list_element
*));
55 _initialize_alpha_tdep
PARAMS ((void));
57 /* Heuristic_proc_start may hunt through the text section for a long
58 time across a 2400 baud serial line. Allows the user to limit this
60 static unsigned int heuristic_fence_post
= 0;
62 /* Layout of a stack frame on the alpha:
65 pdr members: | 7th ... nth arg, |
66 | `pushed' by caller. |
68 ----------------|-------------------------------|<-- old_sp == vfp
71 | |localoff | Copies of 1st .. 6th |
72 | | | | | argument if necessary. |
74 | | | --- |-------------------------------|<-- FRAME_ARGS_ADDRESS,
75 | | | | | FRAME_LOCALS_ADDRESS
76 | | | | Locals and temporaries. |
78 | | | |-------------------------------|
80 |-fregoffset | Saved float registers. |
86 | | -------|-------------------------------|
88 | | | Saved registers. |
95 | ----------|-------------------------------|
97 frameoffset | Argument build area, gets |
98 | | 7th ... nth arg for any |
99 | | called procedure. |
101 -------------|-------------------------------|<-- sp
105 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
106 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
107 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
108 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
109 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
110 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
111 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
112 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
113 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
114 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
115 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
116 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
117 #define _PROC_MAGIC_ 0x0F0F0F0F
118 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
119 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
121 struct linked_proc_info
123 struct alpha_extra_func_info info
;
124 struct linked_proc_info
*next
;
125 } *linked_proc_desc_table
= NULL
;
128 #define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
131 read_next_frame_reg(fi
, regno
)
135 /* If it is the frame for sigtramp we have a pointer to the sigcontext
137 If the stack layout for __sigtramp changes or if sigcontext offsets
138 change we might have to update this code. */
139 #ifndef SIGFRAME_PC_OFF
140 #define SIGFRAME_PC_OFF (2 * 8)
141 #define SIGFRAME_REGSAVE_OFF (4 * 8)
143 for (; fi
; fi
= fi
->next
)
145 if (fi
->signal_handler_caller
)
148 CORE_ADDR sigcontext_addr
= read_memory_integer(fi
->frame
, 8);
150 if (regno
== PC_REGNUM
)
151 offset
= SIGFRAME_PC_OFF
;
153 offset
= SIGFRAME_REGSAVE_OFF
+ regno
* 8;
156 return read_memory_integer(sigcontext_addr
+ offset
, 8);
158 else if (regno
== SP_REGNUM
)
160 else if (fi
->saved_regs
->regs
[regno
])
161 return read_memory_integer(fi
->saved_regs
->regs
[regno
], 8);
163 return read_register(regno
);
167 alpha_frame_saved_pc(frame
)
170 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
171 int pcreg
= proc_desc
? PROC_PC_REG(proc_desc
) : RA_REGNUM
;
173 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
174 return read_memory_integer(frame
->frame
- 8, 8);
176 return read_next_frame_reg(frame
, pcreg
);
180 alpha_saved_pc_after_call (frame
)
183 alpha_extra_func_info_t proc_desc
= find_proc_desc (frame
->pc
, frame
->next
);
184 int pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
;
186 return read_register (pcreg
);
190 static struct alpha_extra_func_info temp_proc_desc
;
191 static struct frame_saved_regs temp_saved_regs
;
193 /* This fencepost looks highly suspicious to me. Removing it also
194 seems suspicious as it could affect remote debugging across serial
198 heuristic_proc_start(pc
)
201 CORE_ADDR start_pc
= pc
;
202 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
204 if (start_pc
== 0) return 0;
206 if (heuristic_fence_post
== UINT_MAX
207 || fence
< VM_MIN_ADDRESS
)
208 fence
= VM_MIN_ADDRESS
;
210 /* search back for previous return */
211 for (start_pc
-= 4; ; start_pc
-= 4)
212 if (start_pc
< fence
)
214 /* It's not clear to me why we reach this point when
215 stop_soon_quietly, but with this test, at least we
216 don't print out warnings for every child forked (eg, on
217 decstation). 22apr93 rich@cygnus.com. */
218 if (!stop_soon_quietly
)
220 static int blurb_printed
= 0;
222 if (fence
== VM_MIN_ADDRESS
)
223 warning("Hit beginning of text section without finding");
225 warning("Hit heuristic-fence-post without finding");
227 warning("enclosing function for address 0x%lx", pc
);
231 This warning occurs if you are debugging a function without any symbols\n\
232 (for example, in a stripped executable). In that case, you may wish to\n\
233 increase the size of the search with the `set heuristic-fence-post' command.\n\
235 Otherwise, you told GDB there was a function where there isn't one, or\n\
236 (more likely) you have encountered a bug in GDB.\n");
243 else if (ABOUT_TO_RETURN(start_pc
))
246 start_pc
+= 4; /* skip return */
250 static alpha_extra_func_info_t
251 heuristic_proc_desc(start_pc
, limit_pc
, next_frame
)
252 CORE_ADDR start_pc
, limit_pc
;
255 CORE_ADDR sp
= next_frame
? next_frame
->frame
: read_register (SP_REGNUM
);
258 int has_frame_reg
= 0;
259 unsigned long reg_mask
= 0;
263 memset(&temp_proc_desc
, '\0', sizeof(temp_proc_desc
));
264 memset(&temp_saved_regs
, '\0', sizeof(struct frame_saved_regs
));
265 PROC_LOW_ADDR(&temp_proc_desc
) = start_pc
;
267 if (start_pc
+ 200 < limit_pc
)
268 limit_pc
= start_pc
+ 200;
270 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
276 status
= read_memory_nobpt (cur_pc
, buf
, 4);
278 memory_error (status
, cur_pc
);
279 word
= extract_unsigned_integer (buf
, 4);
281 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
282 frame_size
+= (-word
) & 0xffff;
283 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
284 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
286 int reg
= (word
& 0x03e00000) >> 21;
287 reg_mask
|= 1 << reg
;
288 temp_saved_regs
.regs
[reg
] = sp
+ (short)word
;
290 else if (word
== 0x47de040f) /* bis sp,sp fp */
294 PROC_FRAME_REG(&temp_proc_desc
) = GCC_FP_REGNUM
;
296 PROC_FRAME_REG(&temp_proc_desc
) = SP_REGNUM
;
297 PROC_FRAME_OFFSET(&temp_proc_desc
) = frame_size
;
298 PROC_REG_MASK(&temp_proc_desc
) = reg_mask
;
299 PROC_PC_REG(&temp_proc_desc
) = RA_REGNUM
;
300 return &temp_proc_desc
;
303 static alpha_extra_func_info_t
304 find_proc_desc(pc
, next_frame
)
308 alpha_extra_func_info_t proc_desc
;
313 /* Try to get the proc_desc from the linked call dummy proc_descs
314 if the pc is in the call dummy.
315 This is hairy. In the case of nested dummy calls we have to find the
316 right proc_desc, but we might not yet know the frame for the dummy
317 as it will be contained in the proc_desc we are searching for.
318 So we have to find the proc_desc whose frame is closest to the current
320 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
322 struct linked_proc_info
*link
;
323 CORE_ADDR sp
= next_frame
? next_frame
->frame
: read_register (SP_REGNUM
);
324 alpha_extra_func_info_t found_proc_desc
= NULL
;
325 long min_distance
= LONG_MAX
;
327 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
329 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
330 if (distance
> 0 && distance
< min_distance
)
332 min_distance
= distance
;
333 found_proc_desc
= &link
->info
;
336 if (found_proc_desc
!= NULL
)
337 return found_proc_desc
;
340 b
= block_for_pc(pc
);
341 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
346 if (startaddr
> BLOCK_START (b
))
347 /* This is the "pathological" case referred to in a comment in
348 print_frame_info. It might be better to move this check into
352 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
358 /* IF (this is the topmost frame OR a frame interrupted by a signal)
359 * AND (this proc does not have debugging information OR
360 * the PC is in the procedure prologue)
361 * THEN create a "heuristic" proc_desc (by analyzing
362 * the actual code) to replace the "official" proc_desc.
364 proc_desc
= (alpha_extra_func_info_t
)SYMBOL_VALUE(sym
);
365 if (next_frame
== NULL
|| next_frame
->signal_handler_caller
) {
366 struct symtab_and_line val
;
367 struct symbol
*proc_symbol
=
368 PROC_DESC_IS_DUMMY(proc_desc
) ? 0 : PROC_SYMBOL(proc_desc
);
371 val
= find_pc_line (BLOCK_START
372 (SYMBOL_BLOCK_VALUE(proc_symbol
)),
374 val
.pc
= val
.end
? val
.end
: pc
;
376 if (!proc_symbol
|| pc
< val
.pc
) {
377 alpha_extra_func_info_t found_heuristic
=
378 heuristic_proc_desc(PROC_LOW_ADDR(proc_desc
),
382 /* The call to heuristic_proc_desc determines
383 which registers have been saved so far and if the
384 frame is already set up.
385 The heuristic algorithm doesn't work well for other
386 information in the procedure descriptor, so copy
387 it from the found procedure descriptor. */
388 PROC_LOCALOFF(found_heuristic
) = PROC_LOCALOFF(proc_desc
);
389 PROC_PC_REG(found_heuristic
) = PROC_PC_REG(proc_desc
);
390 proc_desc
= found_heuristic
;
398 startaddr
= heuristic_proc_start (pc
);
401 heuristic_proc_desc (startaddr
, pc
, next_frame
);
406 alpha_extra_func_info_t cached_proc_desc
;
409 alpha_frame_chain(frame
)
412 alpha_extra_func_info_t proc_desc
;
413 CORE_ADDR saved_pc
= FRAME_SAVED_PC(frame
);
415 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
418 proc_desc
= find_proc_desc(saved_pc
, frame
);
422 cached_proc_desc
= proc_desc
;
424 /* Fetch the frame pointer for a dummy frame from the procedure
426 if (PROC_DESC_IS_DUMMY(proc_desc
))
427 return (FRAME_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
429 /* If no frame pointer and frame size is zero, we must be at end
430 of stack (or otherwise hosed). If we don't check frame size,
431 we loop forever if we see a zero size frame. */
432 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
433 && PROC_FRAME_OFFSET (proc_desc
) == 0
434 /* The alpha __sigtramp routine is frameless and has a frame size
435 of zero. Luckily it is the only procedure which has PC_REGNUM
437 && PROC_PC_REG (proc_desc
) != PC_REGNUM
438 /* The previous frame from a sigtramp frame might be frameless
439 and have frame size zero. */
440 && !frame
->signal_handler_caller
)
443 return read_next_frame_reg(frame
, PROC_FRAME_REG(proc_desc
))
444 + PROC_FRAME_OFFSET(proc_desc
);
448 init_extra_frame_info(fci
)
449 struct frame_info
*fci
;
451 extern struct obstack frame_cache_obstack
;
452 /* Use proc_desc calculated in frame_chain */
453 alpha_extra_func_info_t proc_desc
=
454 fci
->next
? cached_proc_desc
: find_proc_desc(fci
->pc
, fci
->next
);
456 fci
->saved_regs
= (struct frame_saved_regs
*)
457 obstack_alloc (&frame_cache_obstack
, sizeof(struct frame_saved_regs
));
458 memset (fci
->saved_regs
, 0, sizeof (struct frame_saved_regs
));
460 proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
464 CORE_ADDR reg_position
;
468 /* Get the locals offset from the procedure descriptor, it is valid
469 even if we are in the middle of the prologue. */
470 fci
->localoff
= PROC_LOCALOFF(proc_desc
);
472 /* FIXME: This is a kludge for gcc-2.4.5.
473 gcc-2.4.5 builds frames for the alpha in a peculiar way.
474 It uses $fp as a frame register (which seems to be identical to $sp
475 in all procedures that do not use alloca).
476 It has the arguments and the locals above the frame register, if
477 there are few arguments then the locals are above the arguments,
478 otherwise the arguments are above the local.
479 Frame offsets for arguments and locals are relative to $fp and always
481 If we want to stay compatible with the native cc compiler we have
482 to set localoff to frameoffset so that FRAME_ARGS_ADDRESS and
483 FRAME_LOCALS_ADDRESS point to the right place in the frame.
484 Please note that the setting of localoff in the compiler won't work
485 as localoff is only 8 bits wide (which is enough for cc as it needs
486 at most number_of_arg_regs * 8 == 48). */
487 if (PROC_FRAME_REG(proc_desc
) == GCC_FP_REGNUM
)
488 fci
->localoff
= PROC_FRAME_OFFSET(proc_desc
);
490 /* Fixup frame-pointer - only needed for top frame */
491 /* Fetch the frame pointer for a dummy frame from the procedure
493 if (PROC_DESC_IS_DUMMY(proc_desc
))
494 fci
->frame
= (FRAME_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
495 /* This may not be quite right, if proc has a real frame register.
496 Get the value of the frame relative sp, procedure might have been
497 interrupted by a signal at it's very start. */
498 else if (fci
->pc
== PROC_LOW_ADDR(proc_desc
))
499 fci
->frame
= READ_FRAME_REG(fci
, SP_REGNUM
);
501 fci
->frame
= READ_FRAME_REG(fci
, PROC_FRAME_REG(proc_desc
))
502 + PROC_FRAME_OFFSET(proc_desc
);
504 /* If this is the innermost frame, and we are still in the
505 prologue (loosely defined), then the registers may not have
507 if (fci
->next
== NULL
508 && !PROC_DESC_IS_DUMMY(proc_desc
)
509 && alpha_in_lenient_prologue (PROC_LOW_ADDR (proc_desc
), fci
->pc
))
511 /* Can't just say that the registers are not saved, because they
512 might get clobbered halfway through the prologue.
513 heuristic_proc_desc already has the right code to figure out
514 exactly what has been saved, so use it. As far as I know we
515 could be doing this (as we do on the 68k, for example)
516 regardless of whether we are in the prologue; I'm leaving in
517 the check for being in the prologue only out of conservatism
518 (I'm not sure whether heuristic_proc_desc handles all cases,
521 This stuff is ugly (and getting uglier by the minute). Probably
522 the best way to clean it up is to ignore the proc_desc's from
523 the symbols altogher, and get all the information we need by
524 examining the prologue (provided we can make the prologue
525 examining code good enough to get all the cases...). */
527 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
532 if (proc_desc
== &temp_proc_desc
)
533 *fci
->saved_regs
= temp_saved_regs
;
536 /* Find which general-purpose registers were saved.
537 The return address register is the first saved register,
538 the other registers follow in ascending order. */
539 reg_position
= fci
->frame
+ PROC_REG_OFFSET(proc_desc
);
540 mask
= PROC_REG_MASK(proc_desc
) & 0xffffffffL
;
541 returnreg
= PROC_PC_REG(proc_desc
);
542 if (mask
& (1 << returnreg
))
544 fci
->saved_regs
->regs
[returnreg
] = reg_position
;
547 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
550 if (ireg
== returnreg
)
552 fci
->saved_regs
->regs
[ireg
] = reg_position
;
555 /* find which floating-point registers were saved */
556 reg_position
= fci
->frame
+ PROC_FREG_OFFSET(proc_desc
);
557 mask
= PROC_FREG_MASK(proc_desc
) & 0xffffffffL
;
558 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
561 fci
->saved_regs
->regs
[FP0_REGNUM
+ireg
] = reg_position
;
566 fci
->saved_regs
->regs
[PC_REGNUM
] = fci
->saved_regs
->regs
[PROC_PC_REG(proc_desc
)];
570 /* ALPHA stack frames are almost impenetrable. When execution stops,
571 we basically have to look at symbol information for the function
572 that we stopped in, which tells us *which* register (if any) is
573 the base of the frame pointer, and what offset from that register
574 the frame itself is at.
576 This presents a problem when trying to examine a stack in memory
577 (that isn't executing at the moment), using the "frame" command. We
578 don't have a PC, nor do we have any registers except SP.
580 This routine takes two arguments, SP and PC, and tries to make the
581 cached frames look as if these two arguments defined a frame on the
582 cache. This allows the rest of info frame to extract the important
583 arguments without difficulty. */
586 setup_arbitrary_frame (argc
, argv
)
591 error ("ALPHA frame specifications require two arguments: sp and pc");
593 return create_new_frame (argv
[0], argv
[1]);
596 /* The alpha passes the first six arguments in the registers, the rest on
597 the stack. The register arguments are eventually transferred to the
598 argument transfer area immediately below the stack by the called function
599 anyway. So we `push' at least six arguments on the stack, `reload' the
600 argument registers and then adjust the stack pointer to point past the
601 sixth argument. This algorithm simplifies the passing of a large struct
602 which extends from the registers to the stack.
603 If the called function is returning a structure, the address of the
604 structure to be returned is passed as a hidden first argument. */
606 #define NUM_ARG_REGS 6
609 alpha_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
614 CORE_ADDR struct_addr
;
617 int accumulate_size
= struct_return
? 8 : 0;
618 int arg_regs_size
= NUM_ARG_REGS
* 8;
619 struct alpha_arg
{ char *contents
; int len
; int offset
; };
620 struct alpha_arg
*alpha_args
=
621 (struct alpha_arg
*)alloca (nargs
* sizeof (struct alpha_arg
));
622 register struct alpha_arg
*m_arg
;
623 char raw_buffer
[sizeof (CORE_ADDR
)];
624 int required_arg_regs
;
626 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
628 value arg
= value_arg_coerce (args
[i
]);
629 /* Cast argument to long if necessary as the compiler does it too. */
630 if (TYPE_LENGTH (VALUE_TYPE (arg
)) < TYPE_LENGTH (builtin_type_long
))
631 arg
= value_cast (builtin_type_long
, arg
);
632 m_arg
->len
= TYPE_LENGTH (VALUE_TYPE (arg
));
633 m_arg
->offset
= accumulate_size
;
634 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
635 m_arg
->contents
= VALUE_CONTENTS(arg
);
638 /* Determine required argument register loads, loading an argument register
639 is expensive as it uses three ptrace calls. */
640 required_arg_regs
= accumulate_size
/ 8;
641 if (required_arg_regs
> NUM_ARG_REGS
)
642 required_arg_regs
= NUM_ARG_REGS
;
644 /* Make room for the arguments on the stack. */
645 if (accumulate_size
< arg_regs_size
)
646 accumulate_size
= arg_regs_size
;
647 sp
-= accumulate_size
;
649 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
652 /* `Push' arguments on the stack. */
653 for (i
= nargs
; m_arg
--, --i
>= 0; )
654 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
657 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
658 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
661 /* Load the argument registers. */
662 for (i
= 0; i
< required_arg_regs
; i
++)
666 val
= read_memory_integer (sp
+ i
* 8, 8);
667 write_register (A0_REGNUM
+ i
, val
);
668 write_register (FPA0_REGNUM
+ i
, val
);
671 return sp
+ arg_regs_size
;
675 alpha_push_dummy_frame()
678 struct linked_proc_info
*link
= (struct linked_proc_info
*)
679 xmalloc(sizeof (struct linked_proc_info
));
680 alpha_extra_func_info_t proc_desc
= &link
->info
;
681 CORE_ADDR sp
= read_register (SP_REGNUM
);
682 CORE_ADDR save_address
;
683 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
686 link
->next
= linked_proc_desc_table
;
687 linked_proc_desc_table
= link
;
690 * The registers we must save are all those not preserved across
692 * In addition, we must save the PC and RA.
694 * Dummy frame layout:
704 * Parameter build area
708 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
709 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
710 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
711 #define GEN_REG_SAVE_COUNT 24
712 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
713 #define FLOAT_REG_SAVE_COUNT 23
714 /* The special register is the PC as we have no bit for it in the save masks.
715 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
716 #define SPECIAL_REG_SAVE_COUNT 1
718 PROC_REG_MASK(proc_desc
) = GEN_REG_SAVE_MASK
;
719 PROC_FREG_MASK(proc_desc
) = FLOAT_REG_SAVE_MASK
;
720 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
721 but keep SP aligned to a multiple of 16. */
722 PROC_REG_OFFSET(proc_desc
) =
723 - ((8 * (SPECIAL_REG_SAVE_COUNT
725 + FLOAT_REG_SAVE_COUNT
)
727 PROC_FREG_OFFSET(proc_desc
) =
728 PROC_REG_OFFSET(proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
730 /* Save general registers.
731 The return address register is the first saved register, all other
732 registers follow in ascending order.
733 The PC is saved immediately below the SP. */
734 save_address
= sp
+ PROC_REG_OFFSET(proc_desc
);
735 store_address (raw_buffer
, 8, read_register (RA_REGNUM
));
736 write_memory (save_address
, raw_buffer
, 8);
738 mask
= PROC_REG_MASK(proc_desc
) & 0xffffffffL
;
739 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
742 if (ireg
== RA_REGNUM
)
744 store_address (raw_buffer
, 8, read_register (ireg
));
745 write_memory (save_address
, raw_buffer
, 8);
749 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
750 write_memory (sp
- 8, raw_buffer
, 8);
752 /* Save floating point registers. */
753 save_address
= sp
+ PROC_FREG_OFFSET(proc_desc
);
754 mask
= PROC_FREG_MASK(proc_desc
) & 0xffffffffL
;
755 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
758 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
759 write_memory (save_address
, raw_buffer
, 8);
763 /* Set and save the frame address for the dummy.
764 This is tricky. The only registers that are suitable for a frame save
765 are those that are preserved across procedure calls (s0-s6). But if
766 a read system call is interrupted and then a dummy call is made
767 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
768 is satisfied. Then it returns with the s0-s6 registers set to the values
769 on entry to the read system call and our dummy frame pointer would be
770 destroyed. So we save the dummy frame in the proc_desc and handle the
771 retrieval of the frame pointer of a dummy specifically. The frame register
772 is set to the virtual frame (pseudo) register, it's value will always
773 be read as zero and will help us to catch any errors in the dummy frame
775 PROC_DUMMY_FRAME(proc_desc
) = sp
;
776 PROC_FRAME_REG(proc_desc
) = FP_REGNUM
;
777 PROC_FRAME_OFFSET(proc_desc
) = 0;
778 sp
+= PROC_REG_OFFSET(proc_desc
);
779 write_register (SP_REGNUM
, sp
);
781 PROC_LOW_ADDR(proc_desc
) = entry_point_address ();
782 PROC_HIGH_ADDR(proc_desc
) = PROC_LOW_ADDR(proc_desc
) + 4;
784 SET_PROC_DESC_IS_DUMMY(proc_desc
);
785 PROC_PC_REG(proc_desc
) = RA_REGNUM
;
792 FRAME frame
= get_current_frame ();
793 CORE_ADDR new_sp
= frame
->frame
;
795 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
797 write_register (PC_REGNUM
, FRAME_SAVED_PC(frame
));
800 for (regnum
= 32; --regnum
>= 0; )
801 if (PROC_REG_MASK(proc_desc
) & (1 << regnum
))
802 write_register (regnum
,
803 read_memory_integer (frame
->saved_regs
->regs
[regnum
],
805 for (regnum
= 32; --regnum
>= 0; )
806 if (PROC_FREG_MASK(proc_desc
) & (1 << regnum
))
807 write_register (regnum
+ FP0_REGNUM
,
808 read_memory_integer (frame
->saved_regs
->regs
[regnum
+ FP0_REGNUM
], 8));
810 write_register (SP_REGNUM
, new_sp
);
811 flush_cached_frames ();
812 /* We let init_extra_frame_info figure out the frame pointer */
813 set_current_frame (create_new_frame (0, read_pc ()));
815 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
817 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
819 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
821 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
823 if (&pi_ptr
->info
== proc_desc
)
828 error ("Can't locate dummy extra frame info\n");
830 if (prev_ptr
!= NULL
)
831 prev_ptr
->next
= pi_ptr
->next
;
833 linked_proc_desc_table
= pi_ptr
->next
;
839 /* To skip prologues, I use this predicate. Returns either PC itself
840 if the code at PC does not look like a function prologue; otherwise
841 returns an address that (if we're lucky) follows the prologue. If
842 LENIENT, then we must skip everything which is involved in setting
843 up the frame (it's OK to skip more, just so long as we don't skip
844 anything which might clobber the registers which are being saved.
845 Currently we must not skip more on the alpha, but we might the lenient
849 alpha_skip_prologue (pc
, lenient
)
856 /* Skip the typical prologue instructions. These are the stack adjustment
857 instruction and the instructions that save registers on the stack
858 or in the gcc frame. */
859 for (offset
= 0; offset
< 100; offset
+= 4)
864 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
866 memory_error (status
, pc
+ offset
);
867 inst
= extract_unsigned_integer (buf
, 4);
869 /* The alpha has no delay slots. But let's keep the lenient stuff,
870 we might need it for something else in the future. */
874 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
876 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
878 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
880 else if ((inst
& 0xfc1f0000) == 0xb41e0000
881 && (inst
& 0xffff0000) != 0xb7fe0000)
882 continue; /* stq reg,n($sp) */
884 else if ((inst
& 0xfc1f0000) == 0x9c1e0000
885 && (inst
& 0xffff0000) != 0x9ffe0000)
886 continue; /* stt reg,n($sp) */
888 else if (inst
== 0x47de040f) /* bis sp,sp,fp */
896 /* Is address PC in the prologue (loosely defined) for function at
900 alpha_in_lenient_prologue (startaddr
, pc
)
904 CORE_ADDR end_prologue
= alpha_skip_prologue (startaddr
, 1);
905 return pc
>= startaddr
&& pc
< end_prologue
;
908 /* Given a return value in `regbuf' with a type `valtype',
909 extract and copy its value into `valbuf'. */
911 alpha_extract_return_value (valtype
, regbuf
, valbuf
)
912 struct type
*valtype
;
913 char regbuf
[REGISTER_BYTES
];
918 regnum
= TYPE_CODE (valtype
) == TYPE_CODE_FLT
? FP0_REGNUM
: V0_REGNUM
;
920 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (regnum
), TYPE_LENGTH (valtype
));
923 /* Given a return value in `regbuf' with a type `valtype',
924 write it's value into the appropriate register. */
926 alpha_store_return_value (valtype
, valbuf
)
927 struct type
*valtype
;
931 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
933 regnum
= TYPE_CODE (valtype
) == TYPE_CODE_FLT
? FP0_REGNUM
: V0_REGNUM
;
934 memcpy(raw_buffer
, valbuf
, TYPE_LENGTH (valtype
));
936 write_register_bytes(REGISTER_BYTE (regnum
), raw_buffer
, TYPE_LENGTH (valtype
));
939 /* Print the instruction at address MEMADDR in debugged memory,
940 on STREAM. Returns length of the instruction, in bytes. */
943 print_insn (memaddr
, stream
)
947 disassemble_info info
;
949 GDB_INIT_DISASSEMBLE_INFO(info
, stream
);
951 return print_insn_alpha (memaddr
, &info
);
954 /* Just like reinit_frame_cache, but with the right arguments to be
955 callable as an sfunc. */
957 reinit_frame_cache_sfunc (args
, from_tty
, c
)
960 struct cmd_list_element
*c
;
962 reinit_frame_cache ();
966 _initialize_alpha_tdep ()
968 struct cmd_list_element
*c
;
970 /* Let the user set the fence post for heuristic_proc_start. */
972 /* We really would like to have both "0" and "unlimited" work, but
973 command.c doesn't deal with that. So make it a var_zinteger
974 because the user can always use "999999" or some such for unlimited. */
975 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
976 (char *) &heuristic_fence_post
,
978 Set the distance searched for the start of a function.\n\
979 If you are debugging a stripped executable, GDB needs to search through the\n\
980 program for the start of a function. This command sets the distance of the\n\
981 search. The only need to set it is when debugging a stripped executable.",
983 /* We need to throw away the frame cache when we set this, since it
984 might change our ability to get backtraces. */
985 c
->function
.sfunc
= reinit_frame_cache_sfunc
;
986 add_show_from_set (c
, &showlist
);