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