]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/alpha-tdep.c
2003-04-08 Elena Zannoni <ezannoni@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / alpha-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
1e698235 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
b6ba6518 3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b
JM
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. */
c906108c
SS
21
22#include "defs.h"
23#include "frame.h"
24#include "inferior.h"
25#include "symtab.h"
26#include "value.h"
27#include "gdbcmd.h"
28#include "gdbcore.h"
29#include "dis-asm.h"
30#include "symfile.h"
31#include "objfiles.h"
32#include "gdb_string.h"
c5f0f3d0 33#include "linespec.h"
4e052eda 34#include "regcache.h"
d16aafd8 35#include "doublest.h"
dc129d82 36#include "arch-utils.h"
4be87837 37#include "osabi.h"
fe898f56 38#include "block.h"
dc129d82
JT
39
40#include "elf-bfd.h"
41
42#include "alpha-tdep.h"
43
44static gdbarch_init_ftype alpha_gdbarch_init;
45
46static gdbarch_register_name_ftype alpha_register_name;
47static gdbarch_register_raw_size_ftype alpha_register_raw_size;
48static gdbarch_register_virtual_size_ftype alpha_register_virtual_size;
49static gdbarch_register_virtual_type_ftype alpha_register_virtual_type;
50static gdbarch_register_byte_ftype alpha_register_byte;
51static gdbarch_cannot_fetch_register_ftype alpha_cannot_fetch_register;
52static gdbarch_cannot_store_register_ftype alpha_cannot_store_register;
53static gdbarch_register_convertible_ftype alpha_register_convertible;
54static gdbarch_register_convert_to_virtual_ftype
55 alpha_register_convert_to_virtual;
56static gdbarch_register_convert_to_raw_ftype alpha_register_convert_to_raw;
26e9b323 57static gdbarch_deprecated_extract_return_value_ftype alpha_extract_return_value;
26e9b323 58static gdbarch_deprecated_extract_struct_value_address_ftype
dc129d82
JT
59 alpha_extract_struct_value_address;
60static gdbarch_use_struct_convention_ftype alpha_use_struct_convention;
61
95b80706
JT
62static gdbarch_breakpoint_from_pc_ftype alpha_breakpoint_from_pc;
63
dc129d82
JT
64static gdbarch_frame_args_address_ftype alpha_frame_args_address;
65static gdbarch_frame_locals_address_ftype alpha_frame_locals_address;
66
67static gdbarch_skip_prologue_ftype alpha_skip_prologue;
dc129d82 68static gdbarch_saved_pc_after_call_ftype alpha_saved_pc_after_call;
dc129d82 69
dc129d82 70static gdbarch_fix_call_dummy_ftype alpha_fix_call_dummy;
c906108c 71
accc6d1f
JT
72static gdbarch_get_longjmp_target_ftype alpha_get_longjmp_target;
73
140f9984
JT
74struct frame_extra_info
75 {
76 alpha_extra_func_info_t proc_desc;
77 int localoff;
78 int pc_reg;
79 };
80
c906108c
SS
81/* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
82
83/* Prototypes for local functions. */
84
140f9984
JT
85static void alpha_find_saved_regs (struct frame_info *);
86
a14ed312 87static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
c906108c 88
a14ed312 89static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
c906108c 90
a14ed312 91static CORE_ADDR heuristic_proc_start (CORE_ADDR);
c906108c 92
a14ed312
KB
93static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
94 CORE_ADDR,
95 struct frame_info *);
c906108c 96
a14ed312
KB
97static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
98 struct frame_info *);
c906108c
SS
99
100#if 0
a14ed312 101static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
c906108c
SS
102#endif
103
a14ed312 104static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
c906108c 105
a14ed312
KB
106static CORE_ADDR after_prologue (CORE_ADDR pc,
107 alpha_extra_func_info_t proc_desc);
c906108c 108
a14ed312
KB
109static int alpha_in_prologue (CORE_ADDR pc,
110 alpha_extra_func_info_t proc_desc);
c906108c 111
a14ed312 112static int alpha_about_to_return (CORE_ADDR pc);
392a587b 113
a14ed312 114void _initialize_alpha_tdep (void);
392a587b 115
c906108c
SS
116/* Heuristic_proc_start may hunt through the text section for a long
117 time across a 2400 baud serial line. Allows the user to limit this
118 search. */
119static unsigned int heuristic_fence_post = 0;
c5aa993b 120/* *INDENT-OFF* */
c906108c
SS
121/* Layout of a stack frame on the alpha:
122
123 | |
124 pdr members: | 7th ... nth arg, |
125 | `pushed' by caller. |
126 | |
127----------------|-------------------------------|<-- old_sp == vfp
128 ^ ^ ^ ^ | |
129 | | | | | |
130 | |localoff | Copies of 1st .. 6th |
131 | | | | | argument if necessary. |
132 | | | v | |
133 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
134 | | | | |
135 | | | | Locals and temporaries. |
136 | | | | |
137 | | | |-------------------------------|
138 | | | | |
139 |-fregoffset | Saved float registers. |
140 | | | | F9 |
141 | | | | . |
142 | | | | . |
143 | | | | F2 |
144 | | v | |
145 | | -------|-------------------------------|
146 | | | |
147 | | | Saved registers. |
148 | | | S6 |
149 |-regoffset | . |
150 | | | . |
151 | | | S0 |
152 | | | pdr.pcreg |
153 | v | |
154 | ----------|-------------------------------|
155 | | |
156 frameoffset | Argument build area, gets |
157 | | 7th ... nth arg for any |
158 | | called procedure. |
159 v | |
160 -------------|-------------------------------|<-- sp
161 | |
162*/
c5aa993b
JM
163/* *INDENT-ON* */
164
c5aa993b 165#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
b83266a0
SS
166/* These next two fields are kind of being hijacked. I wonder if
167 iline is too small for the values it needs to hold, if GDB is
168 running on a 32-bit host. */
c5aa993b
JM
169#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
170#define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
c906108c
SS
171#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
172#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
173#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
174#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
175#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
176#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
177#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
178#define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
179#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
180#define _PROC_MAGIC_ 0x0F0F0F0F
181#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
182#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
183
184struct linked_proc_info
c5aa993b
JM
185 {
186 struct alpha_extra_func_info info;
187 struct linked_proc_info *next;
188 }
189 *linked_proc_desc_table = NULL;
c906108c 190\f
36a6271d
JT
191static CORE_ADDR
192alpha_frame_past_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc)
c906108c 193{
36a6271d
JT
194 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
195
196 if (tdep->skip_sigtramp_frame != NULL)
197 return (tdep->skip_sigtramp_frame (frame, pc));
198
199 return (0);
200}
201
202static LONGEST
203alpha_dynamic_sigtramp_offset (CORE_ADDR pc)
204{
205 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
206
207 /* Must be provided by OS/ABI variant code if supported. */
208 if (tdep->dynamic_sigtramp_offset != NULL)
209 return (tdep->dynamic_sigtramp_offset (pc));
210
211 return (-1);
212}
213
214#define ALPHA_PROC_SIGTRAMP_MAGIC 0x0e0f0f0f
215
216/* Return TRUE if the procedure descriptor PROC is a procedure
217 descriptor that refers to a dynamically generated signal
218 trampoline routine. */
219static int
220alpha_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc)
221{
222 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
223
224 if (tdep->dynamic_sigtramp_offset != NULL)
225 return (proc->pdr.isym == ALPHA_PROC_SIGTRAMP_MAGIC);
226
227 return (0);
228}
229
230static void
231alpha_set_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc)
232{
233 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
234
235 if (tdep->dynamic_sigtramp_offset != NULL)
236 proc->pdr.isym = ALPHA_PROC_SIGTRAMP_MAGIC;
c906108c 237}
c5aa993b 238
c906108c
SS
239/* Dynamically create a signal-handler caller procedure descriptor for
240 the signal-handler return code starting at address LOW_ADDR. The
241 descriptor is added to the linked_proc_desc_table. */
242
243static alpha_extra_func_info_t
fba45db2 244push_sigtramp_desc (CORE_ADDR low_addr)
c906108c
SS
245{
246 struct linked_proc_info *link;
247 alpha_extra_func_info_t proc_desc;
248
249 link = (struct linked_proc_info *)
250 xmalloc (sizeof (struct linked_proc_info));
251 link->next = linked_proc_desc_table;
252 linked_proc_desc_table = link;
253
254 proc_desc = &link->info;
255
256 proc_desc->numargs = 0;
c5aa993b
JM
257 PROC_LOW_ADDR (proc_desc) = low_addr;
258 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
259 PROC_DUMMY_FRAME (proc_desc) = 0;
260 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
261 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
262 PROC_REG_MASK (proc_desc) = 0xffff;
263 PROC_FREG_MASK (proc_desc) = 0xffff;
264 PROC_PC_REG (proc_desc) = 26;
265 PROC_LOCALOFF (proc_desc) = 0;
36a6271d 266 alpha_set_proc_desc_is_dyn_sigtramp (proc_desc);
c906108c
SS
267 return (proc_desc);
268}
c906108c 269\f
c5aa993b 270
fa88f677 271static const char *
636a6dfc
JT
272alpha_register_name (int regno)
273{
274 static char *register_names[] =
275 {
276 "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
277 "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
278 "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
279 "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero",
280 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
281 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
282 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
283 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr",
87d1b352 284 "pc", "vfp", "unique",
636a6dfc
JT
285 };
286
287 if (regno < 0)
288 return (NULL);
289 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
290 return (NULL);
291 return (register_names[regno]);
292}
d734c450 293
dc129d82 294static int
d734c450
JT
295alpha_cannot_fetch_register (int regno)
296{
dc129d82 297 return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM);
d734c450
JT
298}
299
dc129d82 300static int
d734c450
JT
301alpha_cannot_store_register (int regno)
302{
dc129d82 303 return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM);
d734c450
JT
304}
305
dc129d82 306static int
d734c450
JT
307alpha_register_convertible (int regno)
308{
309 return (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31);
310}
0d056799 311
dc129d82 312static struct type *
0d056799
JT
313alpha_register_virtual_type (int regno)
314{
315 return ((regno >= FP0_REGNUM && regno < (FP0_REGNUM+31))
316 ? builtin_type_double : builtin_type_long);
317}
f8453e34 318
dc129d82 319static int
f8453e34
JT
320alpha_register_byte (int regno)
321{
322 return (regno * 8);
323}
324
dc129d82 325static int
f8453e34
JT
326alpha_register_raw_size (int regno)
327{
328 return 8;
329}
330
dc129d82 331static int
f8453e34
JT
332alpha_register_virtual_size (int regno)
333{
334 return 8;
335}
636a6dfc
JT
336\f
337
5868c862
JT
338static CORE_ADDR
339alpha_sigcontext_addr (struct frame_info *fi)
340{
341 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
342
343 if (tdep->sigcontext_addr)
344 return (tdep->sigcontext_addr (fi));
345
346 return (0);
347}
348
c906108c
SS
349/* Guaranteed to set frame->saved_regs to some values (it never leaves it
350 NULL). */
351
140f9984 352static void
fba45db2 353alpha_find_saved_regs (struct frame_info *frame)
c906108c
SS
354{
355 int ireg;
356 CORE_ADDR reg_position;
357 unsigned long mask;
358 alpha_extra_func_info_t proc_desc;
359 int returnreg;
360
361 frame_saved_regs_zalloc (frame);
362
363 /* If it is the frame for __sigtramp, the saved registers are located
364 in a sigcontext structure somewhere on the stack. __sigtramp
365 passes a pointer to the sigcontext structure on the stack.
366 If the stack layout for __sigtramp changes, or if sigcontext offsets
367 change, we might have to update this code. */
368#ifndef SIGFRAME_PC_OFF
369#define SIGFRAME_PC_OFF (2 * 8)
370#define SIGFRAME_REGSAVE_OFF (4 * 8)
371#define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
372#endif
5a203e44 373 if ((get_frame_type (frame) == SIGTRAMP_FRAME))
c906108c
SS
374 {
375 CORE_ADDR sigcontext_addr;
376
5868c862
JT
377 sigcontext_addr = alpha_sigcontext_addr (frame);
378 if (sigcontext_addr == 0)
379 {
380 /* Don't know where the sigcontext is; just bail. */
381 return;
382 }
c906108c
SS
383 for (ireg = 0; ireg < 32; ireg++)
384 {
c5aa993b 385 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
b2fb4676 386 get_frame_saved_regs (frame)[ireg] = reg_position;
c906108c
SS
387 }
388 for (ireg = 0; ireg < 32; ireg++)
389 {
c5aa993b 390 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
b2fb4676 391 get_frame_saved_regs (frame)[FP0_REGNUM + ireg] = reg_position;
c906108c 392 }
b2fb4676 393 get_frame_saved_regs (frame)[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
c906108c
SS
394 return;
395 }
396
da50a4b7 397 proc_desc = get_frame_extra_info (frame)->proc_desc;
c906108c
SS
398 if (proc_desc == NULL)
399 /* I'm not sure how/whether this can happen. Normally when we can't
400 find a proc_desc, we "synthesize" one using heuristic_proc_desc
401 and set the saved_regs right away. */
402 return;
403
404 /* Fill in the offsets for the registers which gen_mask says
405 were saved. */
406
1e2330ba 407 reg_position = get_frame_base (frame) + PROC_REG_OFFSET (proc_desc);
c906108c
SS
408 mask = PROC_REG_MASK (proc_desc);
409
410 returnreg = PROC_PC_REG (proc_desc);
411
412 /* Note that RA is always saved first, regardless of its actual
413 register number. */
414 if (mask & (1 << returnreg))
415 {
b2fb4676 416 get_frame_saved_regs (frame)[returnreg] = reg_position;
c906108c 417 reg_position += 8;
c5aa993b
JM
418 mask &= ~(1 << returnreg); /* Clear bit for RA so we
419 don't save again later. */
c906108c
SS
420 }
421
c5aa993b 422 for (ireg = 0; ireg <= 31; ++ireg)
c906108c
SS
423 if (mask & (1 << ireg))
424 {
b2fb4676 425 get_frame_saved_regs (frame)[ireg] = reg_position;
c906108c
SS
426 reg_position += 8;
427 }
428
429 /* Fill in the offsets for the registers which float_mask says
430 were saved. */
431
1e2330ba 432 reg_position = get_frame_base (frame) + PROC_FREG_OFFSET (proc_desc);
c906108c
SS
433 mask = PROC_FREG_MASK (proc_desc);
434
c5aa993b 435 for (ireg = 0; ireg <= 31; ++ireg)
c906108c
SS
436 if (mask & (1 << ireg))
437 {
b2fb4676 438 get_frame_saved_regs (frame)[FP0_REGNUM + ireg] = reg_position;
c906108c
SS
439 reg_position += 8;
440 }
441
b2fb4676 442 get_frame_saved_regs (frame)[PC_REGNUM] = get_frame_saved_regs (frame)[returnreg];
c906108c
SS
443}
444
dc129d82 445static void
140f9984
JT
446alpha_frame_init_saved_regs (struct frame_info *fi)
447{
b2fb4676 448 if (get_frame_saved_regs (fi) == NULL)
140f9984 449 alpha_find_saved_regs (fi);
1e2330ba 450 get_frame_saved_regs (fi)[SP_REGNUM] = get_frame_base (fi);
140f9984
JT
451}
452
97f46953 453static CORE_ADDR
0d056799
JT
454alpha_init_frame_pc_first (int fromleaf, struct frame_info *prev)
455{
97f46953 456 return (fromleaf ? SAVED_PC_AFTER_CALL (get_next_frame (prev))
8bedc050 457 : get_next_frame (prev) ? DEPRECATED_FRAME_SAVED_PC (get_next_frame (prev))
97f46953 458 : read_pc ());
0d056799
JT
459}
460
c906108c 461static CORE_ADDR
fba45db2 462read_next_frame_reg (struct frame_info *fi, int regno)
c906108c 463{
11c02a10 464 for (; fi; fi = get_next_frame (fi))
c906108c
SS
465 {
466 /* We have to get the saved sp from the sigcontext
c5aa993b 467 if it is a signal handler frame. */
5a203e44 468 if (regno == SP_REGNUM && !(get_frame_type (fi) == SIGTRAMP_FRAME))
1e2330ba 469 return get_frame_base (fi);
c906108c
SS
470 else
471 {
b2fb4676 472 if (get_frame_saved_regs (fi) == NULL)
c906108c 473 alpha_find_saved_regs (fi);
b2fb4676
AC
474 if (get_frame_saved_regs (fi)[regno])
475 return read_memory_integer (get_frame_saved_regs (fi)[regno], 8);
c906108c
SS
476 }
477 }
c5aa993b 478 return read_register (regno);
c906108c
SS
479}
480
dc129d82 481static CORE_ADDR
fba45db2 482alpha_frame_saved_pc (struct frame_info *frame)
c906108c 483{
da50a4b7 484 alpha_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
c906108c
SS
485 /* We have to get the saved pc from the sigcontext
486 if it is a signal handler frame. */
da50a4b7
AC
487 int pcreg = ((get_frame_type (frame) == SIGTRAMP_FRAME)
488 ? PC_REGNUM
489 : get_frame_extra_info (frame)->pc_reg);
c906108c 490
c5aa993b 491 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
1e2330ba 492 return read_memory_integer (get_frame_base (frame) - 8, 8);
c906108c 493
c5aa993b 494 return read_next_frame_reg (frame, pcreg);
c906108c
SS
495}
496
dc129d82 497static CORE_ADDR
fba45db2 498alpha_saved_pc_after_call (struct frame_info *frame)
c906108c 499{
50abf9e5 500 CORE_ADDR pc = get_frame_pc (frame);
c906108c
SS
501 CORE_ADDR tmp;
502 alpha_extra_func_info_t proc_desc;
503 int pcreg;
504
505 /* Skip over shared library trampoline if necessary. */
506 tmp = SKIP_TRAMPOLINE_CODE (pc);
507 if (tmp != 0)
508 pc = tmp;
509
11c02a10 510 proc_desc = find_proc_desc (pc, get_next_frame (frame));
dc129d82 511 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : ALPHA_RA_REGNUM;
c906108c 512
5a203e44 513 if ((get_frame_type (frame) == SIGTRAMP_FRAME))
c906108c
SS
514 return alpha_frame_saved_pc (frame);
515 else
516 return read_register (pcreg);
517}
518
519
520static struct alpha_extra_func_info temp_proc_desc;
dc129d82 521static CORE_ADDR temp_saved_regs[ALPHA_NUM_REGS];
c906108c
SS
522
523/* Nonzero if instruction at PC is a return instruction. "ret
524 $zero,($ra),1" on alpha. */
525
526static int
fba45db2 527alpha_about_to_return (CORE_ADDR pc)
c906108c
SS
528{
529 return read_memory_integer (pc, 4) == 0x6bfa8001;
530}
531
532
533
534/* This fencepost looks highly suspicious to me. Removing it also
535 seems suspicious as it could affect remote debugging across serial
536 lines. */
537
538static CORE_ADDR
fba45db2 539heuristic_proc_start (CORE_ADDR pc)
c906108c 540{
d9b023cc 541 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
c5aa993b
JM
542 CORE_ADDR start_pc = pc;
543 CORE_ADDR fence = start_pc - heuristic_fence_post;
c906108c 544
c5aa993b
JM
545 if (start_pc == 0)
546 return 0;
c906108c 547
c5aa993b 548 if (heuristic_fence_post == UINT_MAX
d9b023cc
JT
549 || fence < tdep->vm_min_address)
550 fence = tdep->vm_min_address;
c906108c 551
c5aa993b
JM
552 /* search back for previous return */
553 for (start_pc -= 4;; start_pc -= 4)
554 if (start_pc < fence)
555 {
556 /* It's not clear to me why we reach this point when
c0236d92 557 stop_soon, but with this test, at least we
c5aa993b
JM
558 don't print out warnings for every child forked (eg, on
559 decstation). 22apr93 rich@cygnus.com. */
c0236d92 560 if (stop_soon == NO_STOP_QUIETLY)
c906108c 561 {
c5aa993b
JM
562 static int blurb_printed = 0;
563
d9b023cc 564 if (fence == tdep->vm_min_address)
c5aa993b
JM
565 warning ("Hit beginning of text section without finding");
566 else
567 warning ("Hit heuristic-fence-post without finding");
568
d4f3574e 569 warning ("enclosing function for address 0x%s", paddr_nz (pc));
c5aa993b 570 if (!blurb_printed)
c906108c 571 {
c5aa993b 572 printf_filtered ("\
c906108c
SS
573This warning occurs if you are debugging a function without any symbols\n\
574(for example, in a stripped executable). In that case, you may wish to\n\
575increase the size of the search with the `set heuristic-fence-post' command.\n\
576\n\
577Otherwise, you told GDB there was a function where there isn't one, or\n\
578(more likely) you have encountered a bug in GDB.\n");
c5aa993b 579 blurb_printed = 1;
c906108c 580 }
c906108c 581 }
c906108c 582
c5aa993b
JM
583 return 0;
584 }
585 else if (alpha_about_to_return (start_pc))
586 break;
587
588 start_pc += 4; /* skip return */
589 return start_pc;
c906108c
SS
590}
591
592static alpha_extra_func_info_t
fba45db2
KB
593heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
594 struct frame_info *next_frame)
c906108c 595{
c5aa993b 596 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
dc1b0db2 597 CORE_ADDR vfp = sp;
c5aa993b
JM
598 CORE_ADDR cur_pc;
599 int frame_size;
600 int has_frame_reg = 0;
601 unsigned long reg_mask = 0;
602 int pcreg = -1;
dc1b0db2 603 int regno;
c5aa993b
JM
604
605 if (start_pc == 0)
606 return NULL;
607 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
140f9984 608 memset (&temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS);
c5aa993b
JM
609 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
610
611 if (start_pc + 200 < limit_pc)
612 limit_pc = start_pc + 200;
613 frame_size = 0;
614 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
615 {
616 char buf[4];
617 unsigned long word;
618 int status;
c906108c 619
c5aa993b
JM
620 status = read_memory_nobpt (cur_pc, buf, 4);
621 if (status)
622 memory_error (status, cur_pc);
623 word = extract_unsigned_integer (buf, 4);
c906108c 624
c5aa993b
JM
625 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
626 {
627 if (word & 0x8000)
dc1b0db2
JB
628 {
629 /* Consider only the first stack allocation instruction
630 to contain the static size of the frame. */
631 if (frame_size == 0)
632 frame_size += (-word) & 0xffff;
633 }
c5aa993b
JM
634 else
635 /* Exit loop if a positive stack adjustment is found, which
636 usually means that the stack cleanup code in the function
637 epilogue is reached. */
638 break;
639 }
640 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
641 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
642 {
643 int reg = (word & 0x03e00000) >> 21;
644 reg_mask |= 1 << reg;
dc1b0db2
JB
645
646 /* Do not compute the address where the register was saved yet,
647 because we don't know yet if the offset will need to be
648 relative to $sp or $fp (we can not compute the address relative
649 to $sp if $sp is updated during the execution of the current
650 subroutine, for instance when doing some alloca). So just store
651 the offset for the moment, and compute the address later
652 when we know whether this frame has a frame pointer or not.
653 */
654 temp_saved_regs[reg] = (short) word;
c5aa993b
JM
655
656 /* Starting with OSF/1-3.2C, the system libraries are shipped
657 without local symbols, but they still contain procedure
658 descriptors without a symbol reference. GDB is currently
659 unable to find these procedure descriptors and uses
660 heuristic_proc_desc instead.
661 As some low level compiler support routines (__div*, __add*)
662 use a non-standard return address register, we have to
663 add some heuristics to determine the return address register,
664 or stepping over these routines will fail.
665 Usually the return address register is the first register
666 saved on the stack, but assembler optimization might
667 rearrange the register saves.
668 So we recognize only a few registers (t7, t9, ra) within
669 the procedure prologue as valid return address registers.
670 If we encounter a return instruction, we extract the
671 the return address register from it.
672
673 FIXME: Rewriting GDB to access the procedure descriptors,
674 e.g. via the minimal symbol table, might obviate this hack. */
675 if (pcreg == -1
676 && cur_pc < (start_pc + 80)
dc129d82
JT
677 && (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM
678 || reg == ALPHA_RA_REGNUM))
c5aa993b
JM
679 pcreg = reg;
680 }
681 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
682 pcreg = (word >> 16) & 0x1f;
dc1b0db2
JB
683 else if (word == 0x47de040f || word == 0x47fe040f) /* bis sp,sp fp */
684 {
685 /* ??? I am not sure what instruction is 0x47fe040f, and I
686 am suspecting that there was a typo and should have been
687 0x47fe040f. I'm keeping it in the test above until further
688 investigation */
689 has_frame_reg = 1;
690 vfp = read_next_frame_reg (next_frame, ALPHA_GCC_FP_REGNUM);
691 }
c5aa993b
JM
692 }
693 if (pcreg == -1)
694 {
695 /* If we haven't found a valid return address register yet,
696 keep searching in the procedure prologue. */
697 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
698 {
699 char buf[4];
700 unsigned long word;
c906108c 701
c5aa993b
JM
702 if (read_memory_nobpt (cur_pc, buf, 4))
703 break;
704 cur_pc += 4;
705 word = extract_unsigned_integer (buf, 4);
c906108c 706
c5aa993b
JM
707 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
708 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
709 {
710 int reg = (word & 0x03e00000) >> 21;
dc129d82
JT
711 if (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM
712 || reg == ALPHA_RA_REGNUM)
c5aa993b
JM
713 {
714 pcreg = reg;
715 break;
716 }
717 }
718 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
719 {
720 pcreg = (word >> 16) & 0x1f;
721 break;
722 }
723 }
724 }
c906108c 725
c5aa993b 726 if (has_frame_reg)
dc129d82 727 PROC_FRAME_REG (&temp_proc_desc) = ALPHA_GCC_FP_REGNUM;
c5aa993b
JM
728 else
729 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
dc1b0db2
JB
730
731 /* At this point, we know which of the Stack Pointer or the Frame Pointer
732 to use as the reference address to compute the saved registers address.
733 But in both cases, the processing above has set vfp to this reference
734 address, so just need to increment the offset of each saved register
735 by this address. */
736 for (regno = 0; regno < NUM_REGS; regno++)
737 {
738 if (reg_mask & 1 << regno)
739 temp_saved_regs[regno] += vfp;
740 }
741
c5aa993b
JM
742 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
743 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
dc129d82 744 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? ALPHA_RA_REGNUM : pcreg;
c5aa993b
JM
745 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
746 return &temp_proc_desc;
c906108c
SS
747}
748
749/* This returns the PC of the first inst after the prologue. If we can't
750 find the prologue, then return 0. */
751
752static CORE_ADDR
fba45db2 753after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
c906108c
SS
754{
755 struct symtab_and_line sal;
756 CORE_ADDR func_addr, func_end;
757
758 if (!proc_desc)
759 proc_desc = find_proc_desc (pc, NULL);
760
761 if (proc_desc)
762 {
36a6271d 763 if (alpha_proc_desc_is_dyn_sigtramp (proc_desc))
c906108c
SS
764 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
765
766 /* If function is frameless, then we need to do it the hard way. I
c5aa993b 767 strongly suspect that frameless always means prologueless... */
c906108c
SS
768 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
769 && PROC_FRAME_OFFSET (proc_desc) == 0)
770 return 0;
771 }
772
773 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
774 return 0; /* Unknown */
775
776 sal = find_pc_line (func_addr, 0);
777
778 if (sal.end < func_end)
779 return sal.end;
780
781 /* The line after the prologue is after the end of the function. In this
782 case, tell the caller to find the prologue the hard way. */
783
784 return 0;
785}
786
787/* Return non-zero if we *might* be in a function prologue. Return zero if we
788 are definitively *not* in a function prologue. */
789
790static int
fba45db2 791alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
c906108c
SS
792{
793 CORE_ADDR after_prologue_pc;
794
795 after_prologue_pc = after_prologue (pc, proc_desc);
796
797 if (after_prologue_pc == 0
798 || pc < after_prologue_pc)
799 return 1;
800 else
801 return 0;
802}
803
804static alpha_extra_func_info_t
fba45db2 805find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame)
c906108c
SS
806{
807 alpha_extra_func_info_t proc_desc;
808 struct block *b;
809 struct symbol *sym;
810 CORE_ADDR startaddr;
811
812 /* Try to get the proc_desc from the linked call dummy proc_descs
813 if the pc is in the call dummy.
814 This is hairy. In the case of nested dummy calls we have to find the
815 right proc_desc, but we might not yet know the frame for the dummy
816 as it will be contained in the proc_desc we are searching for.
817 So we have to find the proc_desc whose frame is closest to the current
818 stack pointer. */
819
ae45cd16 820 if (DEPRECATED_PC_IN_CALL_DUMMY (pc, 0, 0))
c906108c
SS
821 {
822 struct linked_proc_info *link;
823 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
824 alpha_extra_func_info_t found_proc_desc = NULL;
825 long min_distance = LONG_MAX;
826
827 for (link = linked_proc_desc_table; link; link = link->next)
828 {
829 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
830 if (distance > 0 && distance < min_distance)
831 {
832 min_distance = distance;
833 found_proc_desc = &link->info;
834 }
835 }
836 if (found_proc_desc != NULL)
837 return found_proc_desc;
838 }
839
c5aa993b 840 b = block_for_pc (pc);
c906108c
SS
841
842 find_pc_partial_function (pc, NULL, &startaddr, NULL);
843 if (b == NULL)
844 sym = NULL;
845 else
846 {
847 if (startaddr > BLOCK_START (b))
848 /* This is the "pathological" case referred to in a comment in
849 print_frame_info. It might be better to move this check into
850 symbol reading. */
851 sym = NULL;
852 else
853 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
854 0, NULL);
855 }
856
857 /* If we never found a PDR for this function in symbol reading, then
858 examine prologues to find the information. */
859 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
860 sym = NULL;
861
862 if (sym)
863 {
c5aa993b
JM
864 /* IF this is the topmost frame AND
865 * (this proc does not have debugging information OR
866 * the PC is in the procedure prologue)
867 * THEN create a "heuristic" proc_desc (by analyzing
868 * the actual code) to replace the "official" proc_desc.
869 */
870 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
871 if (next_frame == NULL)
872 {
873 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
874 {
875 alpha_extra_func_info_t found_heuristic =
876 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
877 pc, next_frame);
878 if (found_heuristic)
879 {
880 PROC_LOCALOFF (found_heuristic) =
881 PROC_LOCALOFF (proc_desc);
882 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
883 proc_desc = found_heuristic;
884 }
885 }
886 }
c906108c
SS
887 }
888 else
889 {
890 long offset;
891
892 /* Is linked_proc_desc_table really necessary? It only seems to be used
c5aa993b
JM
893 by procedure call dummys. However, the procedures being called ought
894 to have their own proc_descs, and even if they don't,
895 heuristic_proc_desc knows how to create them! */
c906108c
SS
896
897 register struct linked_proc_info *link;
898 for (link = linked_proc_desc_table; link; link = link->next)
c5aa993b
JM
899 if (PROC_LOW_ADDR (&link->info) <= pc
900 && PROC_HIGH_ADDR (&link->info) > pc)
901 return &link->info;
c906108c
SS
902
903 /* If PC is inside a dynamically generated sigtramp handler,
c5aa993b 904 create and push a procedure descriptor for that code: */
36a6271d 905 offset = alpha_dynamic_sigtramp_offset (pc);
c906108c
SS
906 if (offset >= 0)
907 return push_sigtramp_desc (pc - offset);
908
909 /* If heuristic_fence_post is non-zero, determine the procedure
c5aa993b
JM
910 start address by examining the instructions.
911 This allows us to find the start address of static functions which
912 have no symbolic information, as startaddr would have been set to
913 the preceding global function start address by the
914 find_pc_partial_function call above. */
c906108c
SS
915 if (startaddr == 0 || heuristic_fence_post != 0)
916 startaddr = heuristic_proc_start (pc);
917
918 proc_desc =
919 heuristic_proc_desc (startaddr, pc, next_frame);
920 }
921 return proc_desc;
922}
923
924alpha_extra_func_info_t cached_proc_desc;
925
dc129d82 926static CORE_ADDR
fba45db2 927alpha_frame_chain (struct frame_info *frame)
c906108c 928{
c5aa993b 929 alpha_extra_func_info_t proc_desc;
8bedc050 930 CORE_ADDR saved_pc = DEPRECATED_FRAME_SAVED_PC (frame);
c5aa993b
JM
931
932 if (saved_pc == 0 || inside_entry_file (saved_pc))
933 return 0;
934
935 proc_desc = find_proc_desc (saved_pc, frame);
936 if (!proc_desc)
937 return 0;
938
939 cached_proc_desc = proc_desc;
940
941 /* Fetch the frame pointer for a dummy frame from the procedure
942 descriptor. */
943 if (PROC_DESC_IS_DUMMY (proc_desc))
944 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
945
946 /* If no frame pointer and frame size is zero, we must be at end
947 of stack (or otherwise hosed). If we don't check frame size,
948 we loop forever if we see a zero size frame. */
949 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
950 && PROC_FRAME_OFFSET (proc_desc) == 0
951 /* The previous frame from a sigtramp frame might be frameless
952 and have frame size zero. */
5a203e44 953 && !(get_frame_type (frame) == SIGTRAMP_FRAME))
36a6271d 954 return alpha_frame_past_sigtramp_frame (frame, saved_pc);
c5aa993b
JM
955 else
956 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
957 + PROC_FRAME_OFFSET (proc_desc);
c906108c
SS
958}
959
960void
140f9984
JT
961alpha_print_extra_frame_info (struct frame_info *fi)
962{
963 if (fi
da50a4b7
AC
964 && get_frame_extra_info (fi)
965 && get_frame_extra_info (fi)->proc_desc
966 && get_frame_extra_info (fi)->proc_desc->pdr.framereg < NUM_REGS)
140f9984 967 printf_filtered (" frame pointer is at %s+%s\n",
da50a4b7
AC
968 REGISTER_NAME (get_frame_extra_info (fi)->proc_desc->pdr.framereg),
969 paddr_d (get_frame_extra_info (fi)->proc_desc->pdr.frameoffset));
140f9984
JT
970}
971
dc129d82 972static void
140f9984 973alpha_init_extra_frame_info (int fromleaf, struct frame_info *frame)
c906108c
SS
974{
975 /* Use proc_desc calculated in frame_chain */
976 alpha_extra_func_info_t proc_desc =
11c02a10
AC
977 get_next_frame (frame)
978 ? cached_proc_desc
979 : find_proc_desc (get_frame_pc (frame), get_next_frame (frame));
c906108c 980
a00a19e9 981 frame_extra_info_zalloc (frame, sizeof (struct frame_extra_info));
140f9984 982
b2fb4676
AC
983 /* NOTE: cagney/2003-01-03: No need to set saved_regs to NULL,
984 always NULL by default. */
985 /* frame->saved_regs = NULL; */
da50a4b7
AC
986 get_frame_extra_info (frame)->localoff = 0;
987 get_frame_extra_info (frame)->pc_reg = ALPHA_RA_REGNUM;
988 get_frame_extra_info (frame)->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
c906108c
SS
989 if (proc_desc)
990 {
991 /* Get the locals offset and the saved pc register from the
c5aa993b
JM
992 procedure descriptor, they are valid even if we are in the
993 middle of the prologue. */
da50a4b7
AC
994 get_frame_extra_info (frame)->localoff = PROC_LOCALOFF (proc_desc);
995 get_frame_extra_info (frame)->pc_reg = PROC_PC_REG (proc_desc);
c906108c
SS
996
997 /* Fixup frame-pointer - only needed for top frame */
998
999 /* Fetch the frame pointer for a dummy frame from the procedure
c5aa993b
JM
1000 descriptor. */
1001 if (PROC_DESC_IS_DUMMY (proc_desc))
8ccd593b 1002 deprecated_update_frame_base_hack (frame, (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc));
c906108c
SS
1003
1004 /* This may not be quite right, if proc has a real frame register.
c5aa993b
JM
1005 Get the value of the frame relative sp, procedure might have been
1006 interrupted by a signal at it's very start. */
50abf9e5 1007 else if (get_frame_pc (frame) == PROC_LOW_ADDR (proc_desc)
36a6271d 1008 && !alpha_proc_desc_is_dyn_sigtramp (proc_desc))
11c02a10 1009 deprecated_update_frame_base_hack (frame, read_next_frame_reg (get_next_frame (frame), SP_REGNUM));
c906108c 1010 else
11c02a10 1011 deprecated_update_frame_base_hack (frame, read_next_frame_reg (get_next_frame (frame), PROC_FRAME_REG (proc_desc))
8ccd593b 1012 + PROC_FRAME_OFFSET (proc_desc));
c906108c
SS
1013
1014 if (proc_desc == &temp_proc_desc)
1015 {
1016 char *name;
1017
1018 /* Do not set the saved registers for a sigtramp frame,
5a203e44
AC
1019 alpha_find_saved_registers will do that for us. We can't
1020 use (get_frame_type (frame) == SIGTRAMP_FRAME), it is not
1021 yet set. */
1022 /* FIXME: cagney/2002-11-18: This problem will go away once
1023 frame.c:get_prev_frame() is modified to set the frame's
1024 type before calling functions like this. */
50abf9e5 1025 find_pc_partial_function (get_frame_pc (frame), &name,
c5aa993b 1026 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
50abf9e5 1027 if (!PC_IN_SIGTRAMP (get_frame_pc (frame), name))
c906108c 1028 {
b2fb4676
AC
1029 frame_saved_regs_zalloc (frame);
1030 memcpy (get_frame_saved_regs (frame), temp_saved_regs,
140f9984 1031 SIZEOF_FRAME_SAVED_REGS);
b2fb4676
AC
1032 get_frame_saved_regs (frame)[PC_REGNUM]
1033 = get_frame_saved_regs (frame)[ALPHA_RA_REGNUM];
c906108c
SS
1034 }
1035 }
1036 }
1037}
1038
dc129d82 1039static CORE_ADDR
140f9984
JT
1040alpha_frame_locals_address (struct frame_info *fi)
1041{
da50a4b7 1042 return (get_frame_base (fi) - get_frame_extra_info (fi)->localoff);
140f9984
JT
1043}
1044
dc129d82 1045static CORE_ADDR
140f9984
JT
1046alpha_frame_args_address (struct frame_info *fi)
1047{
1e2330ba 1048 return (get_frame_base (fi) - (ALPHA_NUM_ARG_REGS * 8));
140f9984
JT
1049}
1050
c906108c
SS
1051/* ALPHA stack frames are almost impenetrable. When execution stops,
1052 we basically have to look at symbol information for the function
1053 that we stopped in, which tells us *which* register (if any) is
1054 the base of the frame pointer, and what offset from that register
1055 the frame itself is at.
1056
1057 This presents a problem when trying to examine a stack in memory
1058 (that isn't executing at the moment), using the "frame" command. We
1059 don't have a PC, nor do we have any registers except SP.
1060
1061 This routine takes two arguments, SP and PC, and tries to make the
1062 cached frames look as if these two arguments defined a frame on the
1063 cache. This allows the rest of info frame to extract the important
1064 arguments without difficulty. */
1065
1066struct frame_info *
a57f9e49 1067alpha_setup_arbitrary_frame (int argc, CORE_ADDR *argv)
c906108c
SS
1068{
1069 if (argc != 2)
1070 error ("ALPHA frame specifications require two arguments: sp and pc");
1071
1072 return create_new_frame (argv[0], argv[1]);
1073}
1074
1075/* The alpha passes the first six arguments in the registers, the rest on
1076 the stack. The register arguments are eventually transferred to the
1077 argument transfer area immediately below the stack by the called function
1078 anyway. So we `push' at least six arguments on the stack, `reload' the
1079 argument registers and then adjust the stack pointer to point past the
1080 sixth argument. This algorithm simplifies the passing of a large struct
1081 which extends from the registers to the stack.
1082 If the called function is returning a structure, the address of the
1083 structure to be returned is passed as a hidden first argument. */
1084
dc129d82 1085static CORE_ADDR
ea7c478f 1086alpha_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
fba45db2 1087 int struct_return, CORE_ADDR struct_addr)
c906108c 1088{
7a292a7a 1089 int i;
c906108c
SS
1090 int accumulate_size = struct_return ? 8 : 0;
1091 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
c5aa993b
JM
1092 struct alpha_arg
1093 {
1094 char *contents;
1095 int len;
1096 int offset;
1097 };
c906108c 1098 struct alpha_arg *alpha_args =
c5aa993b 1099 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
c906108c
SS
1100 register struct alpha_arg *m_arg;
1101 char raw_buffer[sizeof (CORE_ADDR)];
1102 int required_arg_regs;
1103
1104 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
1105 {
ea7c478f 1106 struct value *arg = args[i];
c906108c
SS
1107 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1108 /* Cast argument to long if necessary as the compiler does it too. */
1109 switch (TYPE_CODE (arg_type))
1110 {
1111 case TYPE_CODE_INT:
1112 case TYPE_CODE_BOOL:
1113 case TYPE_CODE_CHAR:
1114 case TYPE_CODE_RANGE:
1115 case TYPE_CODE_ENUM:
1116 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
1117 {
1118 arg_type = builtin_type_long;
1119 arg = value_cast (arg_type, arg);
1120 }
1121 break;
1122 default:
1123 break;
1124 }
1125 m_arg->len = TYPE_LENGTH (arg_type);
1126 m_arg->offset = accumulate_size;
1127 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
c5aa993b 1128 m_arg->contents = VALUE_CONTENTS (arg);
c906108c
SS
1129 }
1130
1131 /* Determine required argument register loads, loading an argument register
1132 is expensive as it uses three ptrace calls. */
1133 required_arg_regs = accumulate_size / 8;
1134 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
1135 required_arg_regs = ALPHA_NUM_ARG_REGS;
1136
1137 /* Make room for the arguments on the stack. */
1138 if (accumulate_size < arg_regs_size)
c5aa993b 1139 accumulate_size = arg_regs_size;
c906108c
SS
1140 sp -= accumulate_size;
1141
1142 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
1143 sp &= ~15;
1144
1145 /* `Push' arguments on the stack. */
c5aa993b
JM
1146 for (i = nargs; m_arg--, --i >= 0;)
1147 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
c906108c
SS
1148 if (struct_return)
1149 {
1150 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
1151 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
1152 }
1153
1154 /* Load the argument registers. */
1155 for (i = 0; i < required_arg_regs; i++)
1156 {
1157 LONGEST val;
1158
1159 val = read_memory_integer (sp + i * 8, 8);
dc129d82
JT
1160 write_register (ALPHA_A0_REGNUM + i, val);
1161 write_register (ALPHA_FPA0_REGNUM + i, val);
c906108c
SS
1162 }
1163
1164 return sp + arg_regs_size;
1165}
1166
dc129d82 1167static void
fba45db2 1168alpha_push_dummy_frame (void)
c906108c
SS
1169{
1170 int ireg;
1171 struct linked_proc_info *link;
1172 alpha_extra_func_info_t proc_desc;
1173 CORE_ADDR sp = read_register (SP_REGNUM);
1174 CORE_ADDR save_address;
dc129d82 1175 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
c906108c
SS
1176 unsigned long mask;
1177
c5aa993b 1178 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
c906108c
SS
1179 link->next = linked_proc_desc_table;
1180 linked_proc_desc_table = link;
c5aa993b 1181
c906108c
SS
1182 proc_desc = &link->info;
1183
1184 /*
1185 * The registers we must save are all those not preserved across
1186 * procedure calls.
1187 * In addition, we must save the PC and RA.
1188 *
1189 * Dummy frame layout:
1190 * (high memory)
c5aa993b 1191 * Saved PC
c906108c
SS
1192 * Saved F30
1193 * ...
1194 * Saved F0
c5aa993b
JM
1195 * Saved R29
1196 * ...
1197 * Saved R0
1198 * Saved R26 (RA)
1199 * Parameter build area
c906108c
SS
1200 * (low memory)
1201 */
1202
1203/* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1204#define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1205#define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1206#define GEN_REG_SAVE_COUNT 24
1207#define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1208#define FLOAT_REG_SAVE_COUNT 23
1209 /* The special register is the PC as we have no bit for it in the save masks.
1210 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1211#define SPECIAL_REG_SAVE_COUNT 1
1212
c5aa993b
JM
1213 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1214 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
c906108c
SS
1215 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1216 but keep SP aligned to a multiple of 16. */
c5aa993b
JM
1217 PROC_REG_OFFSET (proc_desc) =
1218 -((8 * (SPECIAL_REG_SAVE_COUNT
c906108c
SS
1219 + GEN_REG_SAVE_COUNT
1220 + FLOAT_REG_SAVE_COUNT)
c5aa993b
JM
1221 + 15) & ~15);
1222 PROC_FREG_OFFSET (proc_desc) =
1223 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
c906108c
SS
1224
1225 /* Save general registers.
1226 The return address register is the first saved register, all other
1227 registers follow in ascending order.
1228 The PC is saved immediately below the SP. */
c5aa993b 1229 save_address = sp + PROC_REG_OFFSET (proc_desc);
dc129d82 1230 store_address (raw_buffer, 8, read_register (ALPHA_RA_REGNUM));
c906108c
SS
1231 write_memory (save_address, raw_buffer, 8);
1232 save_address += 8;
c5aa993b 1233 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
c906108c
SS
1234 for (ireg = 0; mask; ireg++, mask >>= 1)
1235 if (mask & 1)
1236 {
dc129d82 1237 if (ireg == ALPHA_RA_REGNUM)
c906108c
SS
1238 continue;
1239 store_address (raw_buffer, 8, read_register (ireg));
1240 write_memory (save_address, raw_buffer, 8);
1241 save_address += 8;
1242 }
1243
1244 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1245 write_memory (sp - 8, raw_buffer, 8);
1246
1247 /* Save floating point registers. */
c5aa993b
JM
1248 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1249 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
c906108c
SS
1250 for (ireg = 0; mask; ireg++, mask >>= 1)
1251 if (mask & 1)
1252 {
1253 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1254 write_memory (save_address, raw_buffer, 8);
1255 save_address += 8;
1256 }
1257
1258 /* Set and save the frame address for the dummy.
1259 This is tricky. The only registers that are suitable for a frame save
1260 are those that are preserved across procedure calls (s0-s6). But if
1261 a read system call is interrupted and then a dummy call is made
1262 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1263 is satisfied. Then it returns with the s0-s6 registers set to the values
1264 on entry to the read system call and our dummy frame pointer would be
1265 destroyed. So we save the dummy frame in the proc_desc and handle the
1266 retrieval of the frame pointer of a dummy specifically. The frame register
1267 is set to the virtual frame (pseudo) register, it's value will always
1268 be read as zero and will help us to catch any errors in the dummy frame
1269 retrieval code. */
c5aa993b
JM
1270 PROC_DUMMY_FRAME (proc_desc) = sp;
1271 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1272 PROC_FRAME_OFFSET (proc_desc) = 0;
1273 sp += PROC_REG_OFFSET (proc_desc);
c906108c
SS
1274 write_register (SP_REGNUM, sp);
1275
c5aa993b
JM
1276 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1277 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
c906108c 1278
c5aa993b 1279 SET_PROC_DESC_IS_DUMMY (proc_desc);
dc129d82 1280 PROC_PC_REG (proc_desc) = ALPHA_RA_REGNUM;
c906108c
SS
1281}
1282
dc129d82 1283static void
fba45db2 1284alpha_pop_frame (void)
c906108c
SS
1285{
1286 register int regnum;
1287 struct frame_info *frame = get_current_frame ();
1e2330ba 1288 CORE_ADDR new_sp = get_frame_base (frame);
c906108c 1289
da50a4b7 1290 alpha_extra_func_info_t proc_desc = get_frame_extra_info (frame)->proc_desc;
c906108c 1291
9e0b60a8
JM
1292 /* we need proc_desc to know how to restore the registers;
1293 if it is NULL, construct (a temporary) one */
1294 if (proc_desc == NULL)
11c02a10 1295 proc_desc = find_proc_desc (get_frame_pc (frame), get_next_frame (frame));
9e0b60a8
JM
1296
1297 /* Question: should we copy this proc_desc and save it in
1298 frame->proc_desc? If we do, who will free it?
1299 For now, we don't save a copy... */
1300
8bedc050 1301 write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
b2fb4676 1302 if (get_frame_saved_regs (frame) == NULL)
c906108c
SS
1303 alpha_find_saved_regs (frame);
1304 if (proc_desc)
1305 {
c5aa993b
JM
1306 for (regnum = 32; --regnum >= 0;)
1307 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
c906108c 1308 write_register (regnum,
b2fb4676 1309 read_memory_integer (get_frame_saved_regs (frame)[regnum],
c906108c 1310 8));
c5aa993b
JM
1311 for (regnum = 32; --regnum >= 0;)
1312 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
c906108c 1313 write_register (regnum + FP0_REGNUM,
b2fb4676 1314 read_memory_integer (get_frame_saved_regs (frame)[regnum + FP0_REGNUM], 8));
c906108c
SS
1315 }
1316 write_register (SP_REGNUM, new_sp);
1317 flush_cached_frames ();
1318
c5aa993b 1319 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
36a6271d 1320 || alpha_proc_desc_is_dyn_sigtramp (proc_desc)))
c906108c
SS
1321 {
1322 struct linked_proc_info *pi_ptr, *prev_ptr;
1323
1324 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1325 pi_ptr != NULL;
1326 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1327 {
1328 if (&pi_ptr->info == proc_desc)
1329 break;
1330 }
1331
1332 if (pi_ptr == NULL)
1333 error ("Can't locate dummy extra frame info\n");
1334
1335 if (prev_ptr != NULL)
1336 prev_ptr->next = pi_ptr->next;
1337 else
1338 linked_proc_desc_table = pi_ptr->next;
1339
b8c9b27d 1340 xfree (pi_ptr);
c906108c
SS
1341 }
1342}
1343\f
1344/* To skip prologues, I use this predicate. Returns either PC itself
1345 if the code at PC does not look like a function prologue; otherwise
1346 returns an address that (if we're lucky) follows the prologue. If
1347 LENIENT, then we must skip everything which is involved in setting
1348 up the frame (it's OK to skip more, just so long as we don't skip
1349 anything which might clobber the registers which are being saved.
0fb34c3a
MS
1350 Currently we must not skip more on the alpha, but we might need the
1351 lenient stuff some day. */
c906108c 1352
f8453e34
JT
1353static CORE_ADDR
1354alpha_skip_prologue_internal (CORE_ADDR pc, int lenient)
c906108c 1355{
c5aa993b
JM
1356 unsigned long inst;
1357 int offset;
1358 CORE_ADDR post_prologue_pc;
1359 char buf[4];
c906108c 1360
c5aa993b
JM
1361 /* Silently return the unaltered pc upon memory errors.
1362 This could happen on OSF/1 if decode_line_1 tries to skip the
1363 prologue for quickstarted shared library functions when the
1364 shared library is not yet mapped in.
1365 Reading target memory is slow over serial lines, so we perform
15d72a92
JT
1366 this check only if the target has shared libraries (which all
1367 Alpha targets do). */
c5aa993b
JM
1368 if (target_read_memory (pc, buf, 4))
1369 return pc;
c906108c 1370
c5aa993b
JM
1371 /* See if we can determine the end of the prologue via the symbol table.
1372 If so, then return either PC, or the PC after the prologue, whichever
1373 is greater. */
c906108c 1374
c5aa993b 1375 post_prologue_pc = after_prologue (pc, NULL);
c906108c 1376
c5aa993b
JM
1377 if (post_prologue_pc != 0)
1378 return max (pc, post_prologue_pc);
c906108c 1379
c5aa993b
JM
1380 /* Can't determine prologue from the symbol table, need to examine
1381 instructions. */
c906108c 1382
c5aa993b
JM
1383 /* Skip the typical prologue instructions. These are the stack adjustment
1384 instruction and the instructions that save registers on the stack
1385 or in the gcc frame. */
1386 for (offset = 0; offset < 100; offset += 4)
1387 {
1388 int status;
1389
1390 status = read_memory_nobpt (pc + offset, buf, 4);
1391 if (status)
1392 memory_error (status, pc + offset);
1393 inst = extract_unsigned_integer (buf, 4);
1394
1395 /* The alpha has no delay slots. But let's keep the lenient stuff,
1396 we might need it for something else in the future. */
1397 if (lenient && 0)
1398 continue;
1399
1400 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1401 continue;
1402 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1403 continue;
1404 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1405 continue;
1406 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1407 continue;
1408
1409 if ((inst & 0xfc1f0000) == 0xb41e0000
1410 && (inst & 0xffff0000) != 0xb7fe0000)
1411 continue; /* stq reg,n($sp) */
1412 /* reg != $zero */
1413 if ((inst & 0xfc1f0000) == 0x9c1e0000
1414 && (inst & 0xffff0000) != 0x9ffe0000)
1415 continue; /* stt reg,n($sp) */
1416 /* reg != $zero */
1417 if (inst == 0x47de040f) /* bis sp,sp,fp */
1418 continue;
1419
1420 break;
c906108c 1421 }
c5aa993b 1422 return pc + offset;
c906108c
SS
1423}
1424
dc129d82 1425static CORE_ADDR
f8453e34
JT
1426alpha_skip_prologue (CORE_ADDR addr)
1427{
1428 return (alpha_skip_prologue_internal (addr, 0));
1429}
1430
c906108c
SS
1431#if 0
1432/* Is address PC in the prologue (loosely defined) for function at
1433 STARTADDR? */
1434
1435static int
fba45db2 1436alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc)
c906108c 1437{
f8453e34 1438 CORE_ADDR end_prologue = alpha_skip_prologue_internal (startaddr, 1);
c906108c
SS
1439 return pc >= startaddr && pc < end_prologue;
1440}
1441#endif
1442
1443/* The alpha needs a conversion between register and memory format if
1444 the register is a floating point register and
c5aa993b 1445 memory format is float, as the register format must be double
c906108c 1446 or
c5aa993b
JM
1447 memory format is an integer with 4 bytes or less, as the representation
1448 of integers in floating point registers is different. */
dc129d82 1449static void
fba45db2
KB
1450alpha_register_convert_to_virtual (int regnum, struct type *valtype,
1451 char *raw_buffer, char *virtual_buffer)
c906108c
SS
1452{
1453 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1454 {
1455 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1456 return;
1457 }
1458
1459 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1460 {
1461 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1462 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1463 }
1464 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1465 {
1466 ULONGEST l;
1467 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1468 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1469 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1470 }
1471 else
1472 error ("Cannot retrieve value from floating point register");
1473}
1474
dc129d82 1475static void
fba45db2
KB
1476alpha_register_convert_to_raw (struct type *valtype, int regnum,
1477 char *virtual_buffer, char *raw_buffer)
c906108c
SS
1478{
1479 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1480 {
1481 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1482 return;
1483 }
1484
1485 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1486 {
1487 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1488 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1489 }
1490 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1491 {
1492 ULONGEST l;
1493 if (TYPE_UNSIGNED (valtype))
1494 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1495 else
1496 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1497 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1498 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1499 }
1500 else
1501 error ("Cannot store value in floating point register");
1502}
1503
95b80706
JT
1504static const unsigned char *
1505alpha_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1506{
1507 static const unsigned char alpha_breakpoint[] =
1508 { 0x80, 0, 0, 0 }; /* call_pal bpt */
1509
1510 *lenptr = sizeof(alpha_breakpoint);
1511 return (alpha_breakpoint);
1512}
1513
c906108c
SS
1514/* Given a return value in `regbuf' with a type `valtype',
1515 extract and copy its value into `valbuf'. */
1516
dc129d82 1517static void
732a6b2d 1518alpha_extract_return_value (struct type *valtype,
997b20b8 1519 char regbuf[ALPHA_REGISTER_BYTES], char *valbuf)
c906108c
SS
1520{
1521 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1522 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1523 regbuf + REGISTER_BYTE (FP0_REGNUM),
1524 valbuf);
1525 else
dc129d82
JT
1526 memcpy (valbuf, regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM),
1527 TYPE_LENGTH (valtype));
c906108c
SS
1528}
1529
1530/* Given a return value in `regbuf' with a type `valtype',
1531 write its value into the appropriate register. */
1532
dc129d82 1533static void
fba45db2 1534alpha_store_return_value (struct type *valtype, char *valbuf)
c906108c 1535{
dc129d82
JT
1536 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
1537 int regnum = ALPHA_V0_REGNUM;
c906108c 1538 int length = TYPE_LENGTH (valtype);
c5aa993b 1539
c906108c
SS
1540 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1541 {
1542 regnum = FP0_REGNUM;
1543 length = REGISTER_RAW_SIZE (regnum);
1544 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1545 }
1546 else
1547 memcpy (raw_buffer, valbuf, length);
1548
73937e03 1549 deprecated_write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
c906108c
SS
1550}
1551
1552/* Just like reinit_frame_cache, but with the right arguments to be
1553 callable as an sfunc. */
1554
1555static void
fba45db2 1556reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
c906108c
SS
1557{
1558 reinit_frame_cache ();
1559}
1560
1561/* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1562 to find a convenient place in the text segment to stick a breakpoint to
1563 detect the completion of a target function call (ala call_function_by_hand).
1564 */
1565
1566CORE_ADDR
fba45db2 1567alpha_call_dummy_address (void)
c906108c
SS
1568{
1569 CORE_ADDR entry;
1570 struct minimal_symbol *sym;
1571
1572 entry = entry_point_address ();
1573
1574 if (entry != 0)
1575 return entry;
1576
1577 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1578
1579 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1580 return 0;
1581 else
1582 return SYMBOL_VALUE_ADDRESS (sym) + 4;
ec32e4be
JT
1583}
1584
dc129d82 1585static void
0d056799
JT
1586alpha_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
1587 struct value **args, struct type *type, int gcc_p)
1588{
1589 CORE_ADDR bp_address = CALL_DUMMY_ADDRESS ();
1590
1591 if (bp_address == 0)
1592 error ("no place to put call");
dc129d82
JT
1593 write_register (ALPHA_RA_REGNUM, bp_address);
1594 write_register (ALPHA_T12_REGNUM, fun);
0d056799
JT
1595}
1596
ee1f65f0
JT
1597/* On the Alpha, the call dummy code is nevery copied to user space
1598 (see alpha_fix_call_dummy() above). The contents of this do not
1599 matter. */
1600LONGEST alpha_call_dummy_words[] = { 0 };
1601
dc129d82 1602static int
d734c450
JT
1603alpha_use_struct_convention (int gcc_p, struct type *type)
1604{
1605 /* Structures are returned by ref in extra arg0. */
1606 return 1;
1607}
1608
dc129d82 1609static void
0d056799
JT
1610alpha_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1611{
1612 /* Store the address of the place in which to copy the structure the
1613 subroutine will return. Handled by alpha_push_arguments. */
1614}
1615
dc129d82 1616static CORE_ADDR
0d056799
JT
1617alpha_extract_struct_value_address (char *regbuf)
1618{
dc129d82
JT
1619 return (extract_address (regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM),
1620 REGISTER_RAW_SIZE (ALPHA_V0_REGNUM)));
0d056799
JT
1621}
1622
accc6d1f
JT
1623/* Figure out where the longjmp will land.
1624 We expect the first arg to be a pointer to the jmp_buf structure from
1625 which we extract the PC (JB_PC) that we will land at. The PC is copied
1626 into the "pc". This routine returns true on success. */
1627
1628static int
1629alpha_get_longjmp_target (CORE_ADDR *pc)
1630{
1631 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1632 CORE_ADDR jb_addr;
1633 char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE];
1634
1635 jb_addr = read_register (ALPHA_A0_REGNUM);
1636
1637 if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size),
1638 raw_buffer, tdep->jb_elt_size))
1639 return 0;
1640
1641 *pc = extract_address (raw_buffer, tdep->jb_elt_size);
1642 return 1;
1643}
1644
ec32e4be
JT
1645/* alpha_software_single_step() is called just before we want to resume
1646 the inferior, if we want to single-step it but there is no hardware
1647 or kernel single-step support (NetBSD on Alpha, for example). We find
1648 the target of the coming instruction and breakpoint it.
1649
1650 single_step is also called just after the inferior stops. If we had
1651 set up a simulated single-step, we undo our damage. */
1652
1653static CORE_ADDR
1654alpha_next_pc (CORE_ADDR pc)
1655{
1656 unsigned int insn;
1657 unsigned int op;
1658 int offset;
1659 LONGEST rav;
1660
1661 insn = read_memory_unsigned_integer (pc, sizeof (insn));
1662
1663 /* Opcode is top 6 bits. */
1664 op = (insn >> 26) & 0x3f;
1665
1666 if (op == 0x1a)
1667 {
1668 /* Jump format: target PC is:
1669 RB & ~3 */
1670 return (read_register ((insn >> 16) & 0x1f) & ~3);
1671 }
1672
1673 if ((op & 0x30) == 0x30)
1674 {
1675 /* Branch format: target PC is:
1676 (new PC) + (4 * sext(displacement)) */
1677 if (op == 0x30 || /* BR */
1678 op == 0x34) /* BSR */
1679 {
1680 branch_taken:
1681 offset = (insn & 0x001fffff);
1682 if (offset & 0x00100000)
1683 offset |= 0xffe00000;
1684 offset *= 4;
1685 return (pc + 4 + offset);
1686 }
1687
1688 /* Need to determine if branch is taken; read RA. */
1689 rav = (LONGEST) read_register ((insn >> 21) & 0x1f);
1690 switch (op)
1691 {
1692 case 0x38: /* BLBC */
1693 if ((rav & 1) == 0)
1694 goto branch_taken;
1695 break;
1696 case 0x3c: /* BLBS */
1697 if (rav & 1)
1698 goto branch_taken;
1699 break;
1700 case 0x39: /* BEQ */
1701 if (rav == 0)
1702 goto branch_taken;
1703 break;
1704 case 0x3d: /* BNE */
1705 if (rav != 0)
1706 goto branch_taken;
1707 break;
1708 case 0x3a: /* BLT */
1709 if (rav < 0)
1710 goto branch_taken;
1711 break;
1712 case 0x3b: /* BLE */
1713 if (rav <= 0)
1714 goto branch_taken;
1715 break;
1716 case 0x3f: /* BGT */
1717 if (rav > 0)
1718 goto branch_taken;
1719 break;
1720 case 0x3e: /* BGE */
1721 if (rav >= 0)
1722 goto branch_taken;
1723 break;
1724 }
1725 }
1726
1727 /* Not a branch or branch not taken; target PC is:
1728 pc + 4 */
1729 return (pc + 4);
1730}
1731
1732void
1733alpha_software_single_step (enum target_signal sig, int insert_breakpoints_p)
1734{
1735 static CORE_ADDR next_pc;
1736 typedef char binsn_quantum[BREAKPOINT_MAX];
1737 static binsn_quantum break_mem;
1738 CORE_ADDR pc;
1739
1740 if (insert_breakpoints_p)
1741 {
1742 pc = read_pc ();
1743 next_pc = alpha_next_pc (pc);
1744
1745 target_insert_breakpoint (next_pc, break_mem);
1746 }
1747 else
1748 {
1749 target_remove_breakpoint (next_pc, break_mem);
1750 write_pc (next_pc);
1751 }
c906108c
SS
1752}
1753
dc129d82 1754\f
44dffaac 1755
dc129d82
JT
1756/* Initialize the current architecture based on INFO. If possible, re-use an
1757 architecture from ARCHES, which is a list of architectures already created
1758 during this debugging session.
1759
1760 Called e.g. at program startup, when reading a core file, and when reading
1761 a binary file. */
1762
1763static struct gdbarch *
1764alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1765{
1766 struct gdbarch_tdep *tdep;
1767 struct gdbarch *gdbarch;
dc129d82
JT
1768
1769 /* Try to determine the ABI of the object we are loading. */
4be87837 1770 if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
dc129d82 1771 {
4be87837
DJ
1772 /* If it's an ECOFF file, assume it's OSF/1. */
1773 if (bfd_get_flavour (info.abfd) == bfd_target_ecoff_flavour)
aff87235 1774 info.osabi = GDB_OSABI_OSF1;
dc129d82
JT
1775 }
1776
1777 /* Find a candidate among extant architectures. */
4be87837
DJ
1778 arches = gdbarch_list_lookup_by_info (arches, &info);
1779 if (arches != NULL)
1780 return arches->gdbarch;
dc129d82
JT
1781
1782 tdep = xmalloc (sizeof (struct gdbarch_tdep));
1783 gdbarch = gdbarch_alloc (&info, tdep);
1784
d9b023cc
JT
1785 /* Lowest text address. This is used by heuristic_proc_start() to
1786 decide when to stop looking. */
1787 tdep->vm_min_address = (CORE_ADDR) 0x120000000;
1788
36a6271d
JT
1789 tdep->dynamic_sigtramp_offset = NULL;
1790 tdep->skip_sigtramp_frame = NULL;
5868c862 1791 tdep->sigcontext_addr = NULL;
36a6271d 1792
accc6d1f
JT
1793 tdep->jb_pc = -1; /* longjmp support not enabled by default */
1794
dc129d82
JT
1795 /* Type sizes */
1796 set_gdbarch_short_bit (gdbarch, 16);
1797 set_gdbarch_int_bit (gdbarch, 32);
1798 set_gdbarch_long_bit (gdbarch, 64);
1799 set_gdbarch_long_long_bit (gdbarch, 64);
1800 set_gdbarch_float_bit (gdbarch, 32);
1801 set_gdbarch_double_bit (gdbarch, 64);
1802 set_gdbarch_long_double_bit (gdbarch, 64);
1803 set_gdbarch_ptr_bit (gdbarch, 64);
1804
1805 /* Register info */
1806 set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS);
1807 set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM);
1808 set_gdbarch_fp_regnum (gdbarch, ALPHA_FP_REGNUM);
1809 set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM);
1810 set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM);
1811
1812 set_gdbarch_register_name (gdbarch, alpha_register_name);
1813 set_gdbarch_register_size (gdbarch, ALPHA_REGISTER_SIZE);
1814 set_gdbarch_register_bytes (gdbarch, ALPHA_REGISTER_BYTES);
1815 set_gdbarch_register_byte (gdbarch, alpha_register_byte);
1816 set_gdbarch_register_raw_size (gdbarch, alpha_register_raw_size);
a0ed5532 1817 set_gdbarch_deprecated_max_register_raw_size (gdbarch, ALPHA_MAX_REGISTER_RAW_SIZE);
dc129d82 1818 set_gdbarch_register_virtual_size (gdbarch, alpha_register_virtual_size);
a0ed5532 1819 set_gdbarch_deprecated_max_register_virtual_size (gdbarch,
dc129d82
JT
1820 ALPHA_MAX_REGISTER_VIRTUAL_SIZE);
1821 set_gdbarch_register_virtual_type (gdbarch, alpha_register_virtual_type);
1822
1823 set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register);
1824 set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register);
1825
1826 set_gdbarch_register_convertible (gdbarch, alpha_register_convertible);
1827 set_gdbarch_register_convert_to_virtual (gdbarch,
1828 alpha_register_convert_to_virtual);
1829 set_gdbarch_register_convert_to_raw (gdbarch, alpha_register_convert_to_raw);
1830
1831 set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue);
1832
1833 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1834 set_gdbarch_frameless_function_invocation (gdbarch,
1835 generic_frameless_function_invocation_not);
1836
1837 set_gdbarch_saved_pc_after_call (gdbarch, alpha_saved_pc_after_call);
1838
618ce49f 1839 set_gdbarch_deprecated_frame_chain (gdbarch, alpha_frame_chain);
8bedc050 1840 set_gdbarch_deprecated_frame_saved_pc (gdbarch, alpha_frame_saved_pc);
dc129d82 1841
f30ee0bc 1842 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, alpha_frame_init_saved_regs);
dc129d82
JT
1843
1844 set_gdbarch_use_struct_convention (gdbarch, alpha_use_struct_convention);
26e9b323 1845 set_gdbarch_deprecated_extract_return_value (gdbarch, alpha_extract_return_value);
dc129d82 1846
4183d812 1847 set_gdbarch_deprecated_store_struct_return (gdbarch, alpha_store_struct_return);
ebba8386 1848 set_gdbarch_deprecated_store_return_value (gdbarch, alpha_store_return_value);
26e9b323 1849 set_gdbarch_deprecated_extract_struct_value_address (gdbarch,
dc129d82
JT
1850 alpha_extract_struct_value_address);
1851
1852 /* Settings for calling functions in the inferior. */
07555a72 1853 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
b81774d8 1854 set_gdbarch_deprecated_push_arguments (gdbarch, alpha_push_arguments);
749b82f6 1855 set_gdbarch_deprecated_pop_frame (gdbarch, alpha_pop_frame);
dc129d82
JT
1856
1857 /* On the Alpha, the call dummy code is never copied to user space,
1858 stopping the user call is achieved via a bp_call_dummy breakpoint.
1859 But we need a fake CALL_DUMMY definition to enable the proper
1860 call_function_by_hand and to avoid zero length array warnings. */
dc129d82
JT
1861 set_gdbarch_call_dummy_words (gdbarch, alpha_call_dummy_words);
1862 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
1863 set_gdbarch_frame_args_address (gdbarch, alpha_frame_args_address);
1864 set_gdbarch_frame_locals_address (gdbarch, alpha_frame_locals_address);
e9582e71 1865 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, alpha_init_extra_frame_info);
dc129d82
JT
1866
1867 /* Alpha OSF/1 inhibits execution of code on the stack. But there is
1868 no need for a dummy on the Alpha. PUSH_ARGUMENTS takes care of all
1869 argument handling and bp_call_dummy takes care of stopping the dummy. */
dc129d82 1870 set_gdbarch_call_dummy_address (gdbarch, alpha_call_dummy_address);
ae45cd16 1871 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
f3824013 1872 set_gdbarch_deprecated_push_dummy_frame (gdbarch, alpha_push_dummy_frame);
6c0e89ed
AC
1873 /* Should be using push_dummy_call. */
1874 set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
dc129d82 1875 set_gdbarch_fix_call_dummy (gdbarch, alpha_fix_call_dummy);
a5afb99f 1876 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_noop);
2ca6c561 1877 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, alpha_init_frame_pc_first);
dc129d82
JT
1878
1879 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
36a6271d 1880 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
dc129d82 1881
95b80706 1882 set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc);
dc129d82 1883 set_gdbarch_decr_pc_after_break (gdbarch, 4);
95b80706
JT
1884
1885 set_gdbarch_function_start_offset (gdbarch, 0);
dc129d82
JT
1886 set_gdbarch_frame_args_skip (gdbarch, 0);
1887
44dffaac 1888 /* Hook in ABI-specific overrides, if they have been registered. */
4be87837 1889 gdbarch_init_osabi (info, gdbarch);
44dffaac 1890
accc6d1f
JT
1891 /* Now that we have tuned the configuration, set a few final things
1892 based on what the OS ABI has told us. */
1893
1894 if (tdep->jb_pc >= 0)
1895 set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target);
1896
dc129d82
JT
1897 return gdbarch;
1898}
1899
1900static void
1901alpha_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1902{
1903 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1904
1905 if (tdep == NULL)
1906 return;
1907
d9b023cc
JT
1908 fprintf_unfiltered (file,
1909 "alpha_dump_tdep: vm_min_address = 0x%lx\n",
1910 (long) tdep->vm_min_address);
accc6d1f
JT
1911
1912 fprintf_unfiltered (file,
1913 "alpha_dump_tdep: jb_pc = %d\n",
1914 tdep->jb_pc);
1915 fprintf_unfiltered (file,
1916 "alpha_dump_tdep: jb_elt_size = %ld\n",
1917 (long) tdep->jb_elt_size);
dc129d82
JT
1918}
1919
c906108c 1920void
fba45db2 1921_initialize_alpha_tdep (void)
c906108c
SS
1922{
1923 struct cmd_list_element *c;
1924
dc129d82
JT
1925 gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, alpha_dump_tdep);
1926
c906108c
SS
1927 tm_print_insn = print_insn_alpha;
1928
1929 /* Let the user set the fence post for heuristic_proc_start. */
1930
1931 /* We really would like to have both "0" and "unlimited" work, but
1932 command.c doesn't deal with that. So make it a var_zinteger
1933 because the user can always use "999999" or some such for unlimited. */
1934 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1935 (char *) &heuristic_fence_post,
1936 "\
1937Set the distance searched for the start of a function.\n\
1938If you are debugging a stripped executable, GDB needs to search through the\n\
1939program for the start of a function. This command sets the distance of the\n\
1940search. The only need to set it is when debugging a stripped executable.",
1941 &setlist);
1942 /* We need to throw away the frame cache when we set this, since it
1943 might change our ability to get backtraces. */
9f60d481 1944 set_cmd_sfunc (c, reinit_frame_cache_sfunc);
c906108c
SS
1945 add_show_from_set (c, &showlist);
1946}