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