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