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