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