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