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