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