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