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