Commit | Line | Data |
---|---|---|
cef4c2e7 | 1 | /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger. |
a1a0d974 | 2 | Copyright 1993, 1994, 1995 Free Software Foundation, Inc. |
cef4c2e7 PS |
3 | |
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "inferior.h" | |
23 | #include "symtab.h" | |
24 | #include "value.h" | |
25 | #include "gdbcmd.h" | |
26 | #include "gdbcore.h" | |
27 | #include "dis-asm.h" | |
72bba93b SG |
28 | #include "symfile.h" |
29 | #include "objfiles.h" | |
a1a0d974 | 30 | #include <string.h> |
cef4c2e7 PS |
31 | |
32 | /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */ | |
33 | ||
72bba93b SG |
34 | /* FIXME: Put this declaration in frame.h. */ |
35 | extern struct obstack frame_cache_obstack; | |
cef4c2e7 PS |
36 | \f |
37 | ||
38 | /* Forward declarations. */ | |
39 | ||
669caa9c | 40 | static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int)); |
cef4c2e7 | 41 | |
669caa9c | 42 | static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR)); |
cef4c2e7 | 43 | |
669caa9c SS |
44 | static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR, |
45 | CORE_ADDR, | |
46 | struct frame_info *)); | |
cef4c2e7 | 47 | |
e3be225e SS |
48 | static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR, |
49 | struct frame_info *)); | |
cef4c2e7 | 50 | |
e3be225e | 51 | #if 0 |
669caa9c | 52 | static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR)); |
e3be225e | 53 | #endif |
cef4c2e7 | 54 | |
e3be225e SS |
55 | static void reinit_frame_cache_sfunc PARAMS ((char *, int, |
56 | struct cmd_list_element *)); | |
cef4c2e7 | 57 | |
72bba93b SG |
58 | static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc, |
59 | alpha_extra_func_info_t proc_desc)); | |
60 | ||
61 | static int in_prologue PARAMS ((CORE_ADDR pc, | |
62 | alpha_extra_func_info_t proc_desc)); | |
63 | ||
cef4c2e7 PS |
64 | /* Heuristic_proc_start may hunt through the text section for a long |
65 | time across a 2400 baud serial line. Allows the user to limit this | |
66 | search. */ | |
67 | static unsigned int heuristic_fence_post = 0; | |
68 | ||
69 | /* Layout of a stack frame on the alpha: | |
70 | ||
71 | | | | |
72 | pdr members: | 7th ... nth arg, | | |
73 | | `pushed' by caller. | | |
74 | | | | |
75 | ----------------|-------------------------------|<-- old_sp == vfp | |
76 | ^ ^ ^ ^ | | | |
77 | | | | | | | | |
78 | | |localoff | Copies of 1st .. 6th | | |
79 | | | | | | argument if necessary. | | |
80 | | | | v | | | |
3e6b0674 PS |
81 | | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS |
82 | | | | | | | |
cef4c2e7 PS |
83 | | | | | Locals and temporaries. | |
84 | | | | | | | |
85 | | | | |-------------------------------| | |
86 | | | | | | | |
87 | |-fregoffset | Saved float registers. | | |
88 | | | | | F9 | | |
89 | | | | | . | | |
90 | | | | | . | | |
91 | | | | | F2 | | |
92 | | | v | | | |
93 | | | -------|-------------------------------| | |
94 | | | | | | |
95 | | | | Saved registers. | | |
96 | | | | S6 | | |
97 | |-regoffset | . | | |
98 | | | | . | | |
99 | | | | S0 | | |
100 | | | | pdr.pcreg | | |
101 | | v | | | |
102 | | ----------|-------------------------------| | |
103 | | | | | |
104 | frameoffset | Argument build area, gets | | |
105 | | | 7th ... nth arg for any | | |
106 | | | called procedure. | | |
107 | v | | | |
108 | -------------|-------------------------------|<-- sp | |
109 | | | | |
110 | */ | |
111 | ||
112 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */ | |
113 | #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */ | |
114 | #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */ | |
115 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) | |
116 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) | |
117 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) | |
118 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) | |
119 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) | |
120 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) | |
121 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) | |
122 | #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff) | |
123 | #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym) | |
124 | #define _PROC_MAGIC_ 0x0F0F0F0F | |
125 | #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_) | |
126 | #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_) | |
127 | ||
128 | struct linked_proc_info | |
129 | { | |
130 | struct alpha_extra_func_info info; | |
131 | struct linked_proc_info *next; | |
132 | } *linked_proc_desc_table = NULL; | |
133 | ||
134 | \f | |
72bba93b SG |
135 | /* Guaranteed to set fci->saved_regs to some values (it never leaves it |
136 | NULL). */ | |
137 | ||
138 | void | |
669caa9c SS |
139 | alpha_find_saved_regs (frame) |
140 | struct frame_info *frame; | |
72bba93b SG |
141 | { |
142 | int ireg; | |
143 | CORE_ADDR reg_position; | |
144 | unsigned long mask; | |
145 | alpha_extra_func_info_t proc_desc; | |
146 | int returnreg; | |
147 | ||
669caa9c | 148 | frame->saved_regs = (struct frame_saved_regs *) |
72bba93b | 149 | obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs)); |
669caa9c | 150 | memset (frame->saved_regs, 0, sizeof (struct frame_saved_regs)); |
72bba93b | 151 | |
669caa9c | 152 | proc_desc = frame->proc_desc; |
72bba93b SG |
153 | if (proc_desc == NULL) |
154 | /* I'm not sure how/whether this can happen. Normally when we can't | |
155 | find a proc_desc, we "synthesize" one using heuristic_proc_desc | |
156 | and set the saved_regs right away. */ | |
157 | return; | |
158 | ||
159 | /* Fill in the offsets for the registers which gen_mask says | |
160 | were saved. */ | |
161 | ||
669caa9c | 162 | reg_position = frame->frame + PROC_REG_OFFSET (proc_desc); |
72bba93b SG |
163 | mask = PROC_REG_MASK (proc_desc); |
164 | ||
165 | returnreg = PROC_PC_REG (proc_desc); | |
166 | ||
167 | /* Note that RA is always saved first, regardless of it's actual | |
168 | register number. */ | |
169 | if (mask & (1 << returnreg)) | |
170 | { | |
669caa9c | 171 | frame->saved_regs->regs[returnreg] = reg_position; |
72bba93b SG |
172 | reg_position += 8; |
173 | mask &= ~(1 << returnreg); /* Clear bit for RA so we | |
174 | don't save again later. */ | |
175 | } | |
176 | ||
177 | for (ireg = 0; ireg <= 31 ; ++ireg) | |
178 | if (mask & (1 << ireg)) | |
179 | { | |
669caa9c | 180 | frame->saved_regs->regs[ireg] = reg_position; |
72bba93b SG |
181 | reg_position += 8; |
182 | } | |
183 | ||
184 | /* Fill in the offsets for the registers which float_mask says | |
185 | were saved. */ | |
186 | ||
669caa9c | 187 | reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc); |
72bba93b SG |
188 | mask = PROC_FREG_MASK (proc_desc); |
189 | ||
190 | for (ireg = 0; ireg <= 31 ; ++ireg) | |
191 | if (mask & (1 << ireg)) | |
192 | { | |
669caa9c | 193 | frame->saved_regs->regs[FP0_REGNUM+ireg] = reg_position; |
72bba93b SG |
194 | reg_position += 8; |
195 | } | |
196 | ||
669caa9c | 197 | frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[returnreg]; |
72bba93b | 198 | } |
cef4c2e7 PS |
199 | |
200 | static CORE_ADDR | |
201 | read_next_frame_reg(fi, regno) | |
669caa9c | 202 | struct frame_info *fi; |
cef4c2e7 PS |
203 | int regno; |
204 | { | |
205 | /* If it is the frame for sigtramp we have a pointer to the sigcontext | |
206 | on the stack. | |
207 | If the stack layout for __sigtramp changes or if sigcontext offsets | |
208 | change we might have to update this code. */ | |
209 | #ifndef SIGFRAME_PC_OFF | |
210 | #define SIGFRAME_PC_OFF (2 * 8) | |
211 | #define SIGFRAME_REGSAVE_OFF (4 * 8) | |
212 | #endif | |
213 | for (; fi; fi = fi->next) | |
214 | { | |
215 | if (fi->signal_handler_caller) | |
216 | { | |
217 | int offset; | |
218 | CORE_ADDR sigcontext_addr = read_memory_integer(fi->frame, 8); | |
219 | ||
220 | if (regno == PC_REGNUM) | |
221 | offset = SIGFRAME_PC_OFF; | |
222 | else if (regno < 32) | |
223 | offset = SIGFRAME_REGSAVE_OFF + regno * 8; | |
224 | else | |
225 | return 0; | |
226 | return read_memory_integer(sigcontext_addr + offset, 8); | |
227 | } | |
228 | else if (regno == SP_REGNUM) | |
229 | return fi->frame; | |
72bba93b SG |
230 | else |
231 | { | |
232 | if (fi->saved_regs == NULL) | |
233 | alpha_find_saved_regs (fi); | |
234 | if (fi->saved_regs->regs[regno]) | |
235 | return read_memory_integer(fi->saved_regs->regs[regno], 8); | |
236 | } | |
cef4c2e7 PS |
237 | } |
238 | return read_register(regno); | |
239 | } | |
240 | ||
241 | CORE_ADDR | |
242 | alpha_frame_saved_pc(frame) | |
669caa9c | 243 | struct frame_info *frame; |
cef4c2e7 PS |
244 | { |
245 | alpha_extra_func_info_t proc_desc = frame->proc_desc; | |
0434c1a0 PS |
246 | /* We have to get the saved pc from the sigcontext |
247 | if it is a signal handler frame. */ | |
248 | int pcreg = frame->signal_handler_caller ? PC_REGNUM | |
249 | : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM); | |
cef4c2e7 PS |
250 | |
251 | if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc)) | |
252 | return read_memory_integer(frame->frame - 8, 8); | |
253 | ||
254 | return read_next_frame_reg(frame, pcreg); | |
255 | } | |
256 | ||
257 | CORE_ADDR | |
258 | alpha_saved_pc_after_call (frame) | |
669caa9c | 259 | struct frame_info *frame; |
cef4c2e7 PS |
260 | { |
261 | alpha_extra_func_info_t proc_desc = find_proc_desc (frame->pc, frame->next); | |
262 | int pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM; | |
263 | ||
264 | return read_register (pcreg); | |
265 | } | |
266 | ||
267 | ||
268 | static struct alpha_extra_func_info temp_proc_desc; | |
269 | static struct frame_saved_regs temp_saved_regs; | |
270 | ||
271 | /* This fencepost looks highly suspicious to me. Removing it also | |
272 | seems suspicious as it could affect remote debugging across serial | |
273 | lines. */ | |
274 | ||
275 | static CORE_ADDR | |
276 | heuristic_proc_start(pc) | |
277 | CORE_ADDR pc; | |
278 | { | |
279 | CORE_ADDR start_pc = pc; | |
280 | CORE_ADDR fence = start_pc - heuristic_fence_post; | |
281 | ||
282 | if (start_pc == 0) return 0; | |
283 | ||
284 | if (heuristic_fence_post == UINT_MAX | |
285 | || fence < VM_MIN_ADDRESS) | |
286 | fence = VM_MIN_ADDRESS; | |
287 | ||
288 | /* search back for previous return */ | |
289 | for (start_pc -= 4; ; start_pc -= 4) | |
290 | if (start_pc < fence) | |
291 | { | |
292 | /* It's not clear to me why we reach this point when | |
293 | stop_soon_quietly, but with this test, at least we | |
294 | don't print out warnings for every child forked (eg, on | |
295 | decstation). 22apr93 rich@cygnus.com. */ | |
296 | if (!stop_soon_quietly) | |
297 | { | |
298 | static int blurb_printed = 0; | |
299 | ||
300 | if (fence == VM_MIN_ADDRESS) | |
301 | warning("Hit beginning of text section without finding"); | |
302 | else | |
303 | warning("Hit heuristic-fence-post without finding"); | |
304 | ||
305 | warning("enclosing function for address 0x%lx", pc); | |
306 | if (!blurb_printed) | |
307 | { | |
308 | printf_filtered ("\ | |
309 | This warning occurs if you are debugging a function without any symbols\n\ | |
310 | (for example, in a stripped executable). In that case, you may wish to\n\ | |
311 | increase the size of the search with the `set heuristic-fence-post' command.\n\ | |
312 | \n\ | |
313 | Otherwise, you told GDB there was a function where there isn't one, or\n\ | |
314 | (more likely) you have encountered a bug in GDB.\n"); | |
315 | blurb_printed = 1; | |
316 | } | |
317 | } | |
318 | ||
319 | return 0; | |
320 | } | |
321 | else if (ABOUT_TO_RETURN(start_pc)) | |
322 | break; | |
323 | ||
324 | start_pc += 4; /* skip return */ | |
325 | return start_pc; | |
326 | } | |
327 | ||
328 | static alpha_extra_func_info_t | |
329 | heuristic_proc_desc(start_pc, limit_pc, next_frame) | |
330 | CORE_ADDR start_pc, limit_pc; | |
669caa9c | 331 | struct frame_info *next_frame; |
cef4c2e7 | 332 | { |
2fe3b329 | 333 | CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM); |
cef4c2e7 PS |
334 | CORE_ADDR cur_pc; |
335 | int frame_size; | |
336 | int has_frame_reg = 0; | |
337 | unsigned long reg_mask = 0; | |
338 | ||
339 | if (start_pc == 0) | |
340 | return NULL; | |
669caa9c SS |
341 | memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc)); |
342 | memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs)); | |
343 | PROC_LOW_ADDR (&temp_proc_desc) = start_pc; | |
cef4c2e7 PS |
344 | |
345 | if (start_pc + 200 < limit_pc) | |
346 | limit_pc = start_pc + 200; | |
347 | frame_size = 0; | |
348 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) | |
349 | { | |
350 | char buf[4]; | |
351 | unsigned long word; | |
352 | int status; | |
353 | ||
354 | status = read_memory_nobpt (cur_pc, buf, 4); | |
355 | if (status) | |
356 | memory_error (status, cur_pc); | |
357 | word = extract_unsigned_integer (buf, 4); | |
358 | ||
359 | if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ | |
360 | frame_size += (-word) & 0xffff; | |
361 | else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */ | |
362 | && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */ | |
363 | { | |
364 | int reg = (word & 0x03e00000) >> 21; | |
365 | reg_mask |= 1 << reg; | |
366 | temp_saved_regs.regs[reg] = sp + (short)word; | |
367 | } | |
368 | else if (word == 0x47de040f) /* bis sp,sp fp */ | |
369 | has_frame_reg = 1; | |
370 | } | |
371 | if (has_frame_reg) | |
372 | PROC_FRAME_REG(&temp_proc_desc) = GCC_FP_REGNUM; | |
373 | else | |
374 | PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM; | |
375 | PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size; | |
376 | PROC_REG_MASK(&temp_proc_desc) = reg_mask; | |
377 | PROC_PC_REG(&temp_proc_desc) = RA_REGNUM; | |
72bba93b | 378 | PROC_LOCALOFF(&temp_proc_desc) = 0; /* XXX - bogus */ |
cef4c2e7 PS |
379 | return &temp_proc_desc; |
380 | } | |
381 | ||
72bba93b SG |
382 | /* This returns the PC of the first inst after the prologue. If we can't |
383 | find the prologue, then return 0. */ | |
384 | ||
385 | static CORE_ADDR | |
386 | after_prologue (pc, proc_desc) | |
387 | CORE_ADDR pc; | |
388 | alpha_extra_func_info_t proc_desc; | |
389 | { | |
72bba93b SG |
390 | struct symtab_and_line sal; |
391 | CORE_ADDR func_addr, func_end; | |
392 | ||
393 | if (!proc_desc) | |
394 | proc_desc = find_proc_desc (pc, NULL); | |
395 | ||
396 | if (proc_desc) | |
397 | { | |
398 | /* If function is frameless, then we need to do it the hard way. I | |
399 | strongly suspect that frameless always means prologueless... */ | |
400 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM | |
401 | && PROC_FRAME_OFFSET (proc_desc) == 0) | |
402 | return 0; | |
403 | } | |
404 | ||
405 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
406 | return 0; /* Unknown */ | |
407 | ||
408 | sal = find_pc_line (func_addr, 0); | |
409 | ||
410 | if (sal.end < func_end) | |
411 | return sal.end; | |
412 | ||
413 | /* The line after the prologue is after the end of the function. In this | |
414 | case, tell the caller to find the prologue the hard way. */ | |
415 | ||
416 | return 0; | |
417 | } | |
418 | ||
419 | /* Return non-zero if we *might* be in a function prologue. Return zero if we | |
420 | are definatly *not* in a function prologue. */ | |
421 | ||
422 | static int | |
423 | in_prologue (pc, proc_desc) | |
424 | CORE_ADDR pc; | |
425 | alpha_extra_func_info_t proc_desc; | |
426 | { | |
427 | CORE_ADDR after_prologue_pc; | |
428 | ||
429 | after_prologue_pc = after_prologue (pc, proc_desc); | |
430 | ||
431 | if (after_prologue_pc == 0 | |
432 | || pc < after_prologue_pc) | |
433 | return 1; | |
434 | else | |
435 | return 0; | |
436 | } | |
437 | ||
cef4c2e7 | 438 | static alpha_extra_func_info_t |
669caa9c | 439 | find_proc_desc (pc, next_frame) |
cef4c2e7 | 440 | CORE_ADDR pc; |
669caa9c | 441 | struct frame_info *next_frame; |
cef4c2e7 PS |
442 | { |
443 | alpha_extra_func_info_t proc_desc; | |
444 | struct block *b; | |
445 | struct symbol *sym; | |
446 | CORE_ADDR startaddr; | |
447 | ||
448 | /* Try to get the proc_desc from the linked call dummy proc_descs | |
449 | if the pc is in the call dummy. | |
450 | This is hairy. In the case of nested dummy calls we have to find the | |
451 | right proc_desc, but we might not yet know the frame for the dummy | |
452 | as it will be contained in the proc_desc we are searching for. | |
453 | So we have to find the proc_desc whose frame is closest to the current | |
454 | stack pointer. */ | |
72bba93b | 455 | |
cef4c2e7 PS |
456 | if (PC_IN_CALL_DUMMY (pc, 0, 0)) |
457 | { | |
458 | struct linked_proc_info *link; | |
2fe3b329 | 459 | CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM); |
cef4c2e7 PS |
460 | alpha_extra_func_info_t found_proc_desc = NULL; |
461 | long min_distance = LONG_MAX; | |
462 | ||
463 | for (link = linked_proc_desc_table; link; link = link->next) | |
464 | { | |
465 | long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp; | |
466 | if (distance > 0 && distance < min_distance) | |
467 | { | |
468 | min_distance = distance; | |
469 | found_proc_desc = &link->info; | |
470 | } | |
471 | } | |
472 | if (found_proc_desc != NULL) | |
473 | return found_proc_desc; | |
474 | } | |
475 | ||
476 | b = block_for_pc(pc); | |
72bba93b | 477 | |
cef4c2e7 PS |
478 | find_pc_partial_function (pc, NULL, &startaddr, NULL); |
479 | if (b == NULL) | |
480 | sym = NULL; | |
481 | else | |
482 | { | |
483 | if (startaddr > BLOCK_START (b)) | |
484 | /* This is the "pathological" case referred to in a comment in | |
485 | print_frame_info. It might be better to move this check into | |
486 | symbol reading. */ | |
487 | sym = NULL; | |
488 | else | |
489 | sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, | |
490 | 0, NULL); | |
491 | } | |
492 | ||
4f69fe46 JK |
493 | /* If we never found a PDR for this function in symbol reading, then |
494 | examine prologues to find the information. */ | |
495 | if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1) | |
496 | sym = NULL; | |
497 | ||
cef4c2e7 PS |
498 | if (sym) |
499 | { | |
72bba93b SG |
500 | /* IF this is the topmost frame AND |
501 | * (this proc does not have debugging information OR | |
cef4c2e7 PS |
502 | * the PC is in the procedure prologue) |
503 | * THEN create a "heuristic" proc_desc (by analyzing | |
504 | * the actual code) to replace the "official" proc_desc. | |
505 | */ | |
506 | proc_desc = (alpha_extra_func_info_t)SYMBOL_VALUE(sym); | |
72bba93b SG |
507 | if (next_frame == NULL) |
508 | { | |
509 | if (PROC_DESC_IS_DUMMY (proc_desc) || in_prologue (pc, proc_desc)) | |
510 | { | |
cef4c2e7 | 511 | alpha_extra_func_info_t found_heuristic = |
72bba93b SG |
512 | heuristic_proc_desc (PROC_LOW_ADDR (proc_desc), |
513 | pc, next_frame); | |
cef4c2e7 | 514 | if (found_heuristic) |
de7ad6d8 JK |
515 | { |
516 | PROC_LOCALOFF (found_heuristic) = | |
517 | PROC_LOCALOFF (proc_desc); | |
518 | proc_desc = found_heuristic; | |
519 | } | |
72bba93b SG |
520 | } |
521 | } | |
cef4c2e7 PS |
522 | } |
523 | else | |
524 | { | |
72bba93b SG |
525 | /* Is linked_proc_desc_table really necessary? It only seems to be used |
526 | by procedure call dummys. However, the procedures being called ought | |
527 | to have their own proc_descs, and even if they don't, | |
528 | heuristic_proc_desc knows how to create them! */ | |
529 | ||
530 | register struct linked_proc_info *link; | |
531 | for (link = linked_proc_desc_table; link; link = link->next) | |
532 | if (PROC_LOW_ADDR(&link->info) <= pc | |
533 | && PROC_HIGH_ADDR(&link->info) > pc) | |
534 | return &link->info; | |
535 | ||
cef4c2e7 PS |
536 | if (startaddr == 0) |
537 | startaddr = heuristic_proc_start (pc); | |
538 | ||
539 | proc_desc = | |
540 | heuristic_proc_desc (startaddr, pc, next_frame); | |
541 | } | |
542 | return proc_desc; | |
543 | } | |
544 | ||
545 | alpha_extra_func_info_t cached_proc_desc; | |
546 | ||
669caa9c | 547 | CORE_ADDR |
cef4c2e7 | 548 | alpha_frame_chain(frame) |
669caa9c | 549 | struct frame_info *frame; |
cef4c2e7 PS |
550 | { |
551 | alpha_extra_func_info_t proc_desc; | |
552 | CORE_ADDR saved_pc = FRAME_SAVED_PC(frame); | |
553 | ||
554 | if (saved_pc == 0 || inside_entry_file (saved_pc)) | |
555 | return 0; | |
556 | ||
557 | proc_desc = find_proc_desc(saved_pc, frame); | |
558 | if (!proc_desc) | |
559 | return 0; | |
560 | ||
561 | cached_proc_desc = proc_desc; | |
562 | ||
563 | /* Fetch the frame pointer for a dummy frame from the procedure | |
564 | descriptor. */ | |
565 | if (PROC_DESC_IS_DUMMY(proc_desc)) | |
669caa9c | 566 | return (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc); |
cef4c2e7 PS |
567 | |
568 | /* If no frame pointer and frame size is zero, we must be at end | |
569 | of stack (or otherwise hosed). If we don't check frame size, | |
570 | we loop forever if we see a zero size frame. */ | |
571 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM | |
572 | && PROC_FRAME_OFFSET (proc_desc) == 0 | |
cef4c2e7 PS |
573 | /* The previous frame from a sigtramp frame might be frameless |
574 | and have frame size zero. */ | |
575 | && !frame->signal_handler_caller) | |
0434c1a0 PS |
576 | { |
577 | /* The alpha __sigtramp routine is frameless and has a frame size | |
578 | of zero, but we are able to backtrace through it. */ | |
579 | char *name; | |
580 | find_pc_partial_function (saved_pc, &name, | |
581 | (CORE_ADDR *)NULL, (CORE_ADDR *)NULL); | |
582 | if (IN_SIGTRAMP (saved_pc, name)) | |
583 | return frame->frame; | |
584 | else | |
585 | return 0; | |
586 | } | |
cef4c2e7 PS |
587 | else |
588 | return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc)) | |
0434c1a0 | 589 | + PROC_FRAME_OFFSET(proc_desc); |
cef4c2e7 PS |
590 | } |
591 | ||
592 | void | |
669caa9c SS |
593 | init_extra_frame_info (frame) |
594 | struct frame_info *frame; | |
cef4c2e7 | 595 | { |
cef4c2e7 PS |
596 | /* Use proc_desc calculated in frame_chain */ |
597 | alpha_extra_func_info_t proc_desc = | |
669caa9c | 598 | frame->next ? cached_proc_desc : find_proc_desc(frame->pc, frame->next); |
cef4c2e7 | 599 | |
669caa9c SS |
600 | frame->saved_regs = NULL; |
601 | frame->proc_desc = | |
cef4c2e7 PS |
602 | proc_desc == &temp_proc_desc ? 0 : proc_desc; |
603 | if (proc_desc) | |
604 | { | |
cef4c2e7 PS |
605 | /* Get the locals offset from the procedure descriptor, it is valid |
606 | even if we are in the middle of the prologue. */ | |
669caa9c | 607 | frame->localoff = PROC_LOCALOFF(proc_desc); |
cef4c2e7 | 608 | |
cef4c2e7 | 609 | /* Fixup frame-pointer - only needed for top frame */ |
72bba93b | 610 | |
cef4c2e7 PS |
611 | /* Fetch the frame pointer for a dummy frame from the procedure |
612 | descriptor. */ | |
613 | if (PROC_DESC_IS_DUMMY(proc_desc)) | |
669caa9c | 614 | frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc); |
72bba93b | 615 | |
cef4c2e7 PS |
616 | /* This may not be quite right, if proc has a real frame register. |
617 | Get the value of the frame relative sp, procedure might have been | |
618 | interrupted by a signal at it's very start. */ | |
669caa9c SS |
619 | else if (frame->pc == PROC_LOW_ADDR (proc_desc) && !PROC_DESC_IS_DUMMY (proc_desc)) |
620 | frame->frame = read_next_frame_reg (frame->next, SP_REGNUM); | |
cef4c2e7 | 621 | else |
669caa9c SS |
622 | frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc)) |
623 | + PROC_FRAME_OFFSET (proc_desc); | |
cef4c2e7 PS |
624 | |
625 | if (proc_desc == &temp_proc_desc) | |
cef4c2e7 | 626 | { |
669caa9c | 627 | frame->saved_regs = (struct frame_saved_regs*) |
72bba93b SG |
628 | obstack_alloc (&frame_cache_obstack, |
629 | sizeof (struct frame_saved_regs)); | |
669caa9c SS |
630 | *frame->saved_regs = temp_saved_regs; |
631 | frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[RA_REGNUM]; | |
cef4c2e7 | 632 | } |
cef4c2e7 PS |
633 | } |
634 | } | |
635 | ||
636 | /* ALPHA stack frames are almost impenetrable. When execution stops, | |
637 | we basically have to look at symbol information for the function | |
638 | that we stopped in, which tells us *which* register (if any) is | |
639 | the base of the frame pointer, and what offset from that register | |
640 | the frame itself is at. | |
641 | ||
642 | This presents a problem when trying to examine a stack in memory | |
643 | (that isn't executing at the moment), using the "frame" command. We | |
644 | don't have a PC, nor do we have any registers except SP. | |
645 | ||
646 | This routine takes two arguments, SP and PC, and tries to make the | |
647 | cached frames look as if these two arguments defined a frame on the | |
648 | cache. This allows the rest of info frame to extract the important | |
649 | arguments without difficulty. */ | |
650 | ||
669caa9c | 651 | struct frame_info * |
cef4c2e7 PS |
652 | setup_arbitrary_frame (argc, argv) |
653 | int argc; | |
669caa9c | 654 | CORE_ADDR *argv; |
cef4c2e7 PS |
655 | { |
656 | if (argc != 2) | |
657 | error ("ALPHA frame specifications require two arguments: sp and pc"); | |
658 | ||
659 | return create_new_frame (argv[0], argv[1]); | |
660 | } | |
661 | ||
662 | /* The alpha passes the first six arguments in the registers, the rest on | |
663 | the stack. The register arguments are eventually transferred to the | |
664 | argument transfer area immediately below the stack by the called function | |
665 | anyway. So we `push' at least six arguments on the stack, `reload' the | |
666 | argument registers and then adjust the stack pointer to point past the | |
667 | sixth argument. This algorithm simplifies the passing of a large struct | |
668 | which extends from the registers to the stack. | |
669 | If the called function is returning a structure, the address of the | |
670 | structure to be returned is passed as a hidden first argument. */ | |
671 | ||
cef4c2e7 PS |
672 | CORE_ADDR |
673 | alpha_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
7810d333 JK |
674 | int nargs; |
675 | value_ptr *args; | |
676 | CORE_ADDR sp; | |
677 | int struct_return; | |
678 | CORE_ADDR struct_addr; | |
cef4c2e7 PS |
679 | { |
680 | register i; | |
681 | int accumulate_size = struct_return ? 8 : 0; | |
3e6b0674 | 682 | int arg_regs_size = ALPHA_NUM_ARG_REGS * 8; |
cef4c2e7 PS |
683 | struct alpha_arg { char *contents; int len; int offset; }; |
684 | struct alpha_arg *alpha_args = | |
685 | (struct alpha_arg*)alloca (nargs * sizeof (struct alpha_arg)); | |
686 | register struct alpha_arg *m_arg; | |
687 | char raw_buffer[sizeof (CORE_ADDR)]; | |
688 | int required_arg_regs; | |
689 | ||
690 | for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++) | |
691 | { | |
5222ca60 | 692 | value_ptr arg = args[i]; |
cef4c2e7 | 693 | /* Cast argument to long if necessary as the compiler does it too. */ |
b3636ee5 JK |
694 | switch (TYPE_CODE (VALUE_TYPE (arg))) |
695 | { | |
696 | case TYPE_CODE_INT: | |
697 | case TYPE_CODE_BOOL: | |
698 | case TYPE_CODE_CHAR: | |
699 | case TYPE_CODE_RANGE: | |
700 | case TYPE_CODE_ENUM: | |
701 | if (TYPE_LENGTH (VALUE_TYPE (arg)) < TYPE_LENGTH (builtin_type_long)) | |
702 | arg = value_cast (builtin_type_long, arg); | |
703 | break; | |
704 | default: | |
705 | break; | |
706 | } | |
cef4c2e7 PS |
707 | m_arg->len = TYPE_LENGTH (VALUE_TYPE (arg)); |
708 | m_arg->offset = accumulate_size; | |
709 | accumulate_size = (accumulate_size + m_arg->len + 7) & ~7; | |
710 | m_arg->contents = VALUE_CONTENTS(arg); | |
711 | } | |
712 | ||
713 | /* Determine required argument register loads, loading an argument register | |
714 | is expensive as it uses three ptrace calls. */ | |
715 | required_arg_regs = accumulate_size / 8; | |
3e6b0674 PS |
716 | if (required_arg_regs > ALPHA_NUM_ARG_REGS) |
717 | required_arg_regs = ALPHA_NUM_ARG_REGS; | |
cef4c2e7 PS |
718 | |
719 | /* Make room for the arguments on the stack. */ | |
720 | if (accumulate_size < arg_regs_size) | |
721 | accumulate_size = arg_regs_size; | |
722 | sp -= accumulate_size; | |
723 | ||
724 | /* Keep sp aligned to a multiple of 16 as the compiler does it too. */ | |
725 | sp &= ~15; | |
726 | ||
727 | /* `Push' arguments on the stack. */ | |
728 | for (i = nargs; m_arg--, --i >= 0; ) | |
729 | write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len); | |
730 | if (struct_return) | |
731 | { | |
732 | store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr); | |
733 | write_memory (sp, raw_buffer, sizeof (CORE_ADDR)); | |
734 | } | |
735 | ||
736 | /* Load the argument registers. */ | |
737 | for (i = 0; i < required_arg_regs; i++) | |
738 | { | |
739 | LONGEST val; | |
740 | ||
741 | val = read_memory_integer (sp + i * 8, 8); | |
742 | write_register (A0_REGNUM + i, val); | |
743 | write_register (FPA0_REGNUM + i, val); | |
744 | } | |
745 | ||
746 | return sp + arg_regs_size; | |
747 | } | |
748 | ||
749 | void | |
750 | alpha_push_dummy_frame() | |
751 | { | |
752 | int ireg; | |
72bba93b SG |
753 | struct linked_proc_info *link; |
754 | alpha_extra_func_info_t proc_desc; | |
cef4c2e7 PS |
755 | CORE_ADDR sp = read_register (SP_REGNUM); |
756 | CORE_ADDR save_address; | |
757 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
758 | unsigned long mask; | |
759 | ||
72bba93b | 760 | link = (struct linked_proc_info *) xmalloc(sizeof (struct linked_proc_info)); |
cef4c2e7 PS |
761 | link->next = linked_proc_desc_table; |
762 | linked_proc_desc_table = link; | |
72bba93b SG |
763 | |
764 | proc_desc = &link->info; | |
cef4c2e7 PS |
765 | |
766 | /* | |
767 | * The registers we must save are all those not preserved across | |
768 | * procedure calls. | |
769 | * In addition, we must save the PC and RA. | |
770 | * | |
771 | * Dummy frame layout: | |
772 | * (high memory) | |
773 | * Saved PC | |
774 | * Saved F30 | |
775 | * ... | |
776 | * Saved F0 | |
777 | * Saved R29 | |
778 | * ... | |
779 | * Saved R0 | |
780 | * Saved R26 (RA) | |
781 | * Parameter build area | |
782 | * (low memory) | |
783 | */ | |
784 | ||
785 | /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */ | |
786 | #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1)) | |
787 | #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29)) | |
788 | #define GEN_REG_SAVE_COUNT 24 | |
789 | #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30)) | |
790 | #define FLOAT_REG_SAVE_COUNT 23 | |
791 | /* The special register is the PC as we have no bit for it in the save masks. | |
792 | alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */ | |
793 | #define SPECIAL_REG_SAVE_COUNT 1 | |
794 | ||
795 | PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK; | |
796 | PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK; | |
797 | /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA, | |
798 | but keep SP aligned to a multiple of 16. */ | |
799 | PROC_REG_OFFSET(proc_desc) = | |
800 | - ((8 * (SPECIAL_REG_SAVE_COUNT | |
801 | + GEN_REG_SAVE_COUNT | |
802 | + FLOAT_REG_SAVE_COUNT) | |
803 | + 15) & ~15); | |
804 | PROC_FREG_OFFSET(proc_desc) = | |
805 | PROC_REG_OFFSET(proc_desc) + 8 * GEN_REG_SAVE_COUNT; | |
806 | ||
807 | /* Save general registers. | |
808 | The return address register is the first saved register, all other | |
809 | registers follow in ascending order. | |
810 | The PC is saved immediately below the SP. */ | |
811 | save_address = sp + PROC_REG_OFFSET(proc_desc); | |
812 | store_address (raw_buffer, 8, read_register (RA_REGNUM)); | |
813 | write_memory (save_address, raw_buffer, 8); | |
814 | save_address += 8; | |
815 | mask = PROC_REG_MASK(proc_desc) & 0xffffffffL; | |
816 | for (ireg = 0; mask; ireg++, mask >>= 1) | |
817 | if (mask & 1) | |
818 | { | |
819 | if (ireg == RA_REGNUM) | |
820 | continue; | |
821 | store_address (raw_buffer, 8, read_register (ireg)); | |
822 | write_memory (save_address, raw_buffer, 8); | |
823 | save_address += 8; | |
824 | } | |
825 | ||
826 | store_address (raw_buffer, 8, read_register (PC_REGNUM)); | |
827 | write_memory (sp - 8, raw_buffer, 8); | |
828 | ||
829 | /* Save floating point registers. */ | |
830 | save_address = sp + PROC_FREG_OFFSET(proc_desc); | |
831 | mask = PROC_FREG_MASK(proc_desc) & 0xffffffffL; | |
832 | for (ireg = 0; mask; ireg++, mask >>= 1) | |
833 | if (mask & 1) | |
834 | { | |
835 | store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM)); | |
836 | write_memory (save_address, raw_buffer, 8); | |
837 | save_address += 8; | |
838 | } | |
839 | ||
840 | /* Set and save the frame address for the dummy. | |
841 | This is tricky. The only registers that are suitable for a frame save | |
842 | are those that are preserved across procedure calls (s0-s6). But if | |
843 | a read system call is interrupted and then a dummy call is made | |
844 | (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read | |
845 | is satisfied. Then it returns with the s0-s6 registers set to the values | |
846 | on entry to the read system call and our dummy frame pointer would be | |
847 | destroyed. So we save the dummy frame in the proc_desc and handle the | |
848 | retrieval of the frame pointer of a dummy specifically. The frame register | |
849 | is set to the virtual frame (pseudo) register, it's value will always | |
850 | be read as zero and will help us to catch any errors in the dummy frame | |
851 | retrieval code. */ | |
852 | PROC_DUMMY_FRAME(proc_desc) = sp; | |
853 | PROC_FRAME_REG(proc_desc) = FP_REGNUM; | |
854 | PROC_FRAME_OFFSET(proc_desc) = 0; | |
855 | sp += PROC_REG_OFFSET(proc_desc); | |
856 | write_register (SP_REGNUM, sp); | |
857 | ||
72bba93b | 858 | PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS (); |
cef4c2e7 PS |
859 | PROC_HIGH_ADDR(proc_desc) = PROC_LOW_ADDR(proc_desc) + 4; |
860 | ||
861 | SET_PROC_DESC_IS_DUMMY(proc_desc); | |
862 | PROC_PC_REG(proc_desc) = RA_REGNUM; | |
863 | } | |
864 | ||
865 | void | |
866 | alpha_pop_frame() | |
867 | { | |
868 | register int regnum; | |
669caa9c | 869 | struct frame_info *frame = get_current_frame (); |
cef4c2e7 PS |
870 | CORE_ADDR new_sp = frame->frame; |
871 | ||
872 | alpha_extra_func_info_t proc_desc = frame->proc_desc; | |
873 | ||
874 | write_register (PC_REGNUM, FRAME_SAVED_PC(frame)); | |
72bba93b SG |
875 | if (frame->saved_regs == NULL) |
876 | alpha_find_saved_regs (frame); | |
cef4c2e7 PS |
877 | if (proc_desc) |
878 | { | |
879 | for (regnum = 32; --regnum >= 0; ) | |
880 | if (PROC_REG_MASK(proc_desc) & (1 << regnum)) | |
881 | write_register (regnum, | |
882 | read_memory_integer (frame->saved_regs->regs[regnum], | |
883 | 8)); | |
884 | for (regnum = 32; --regnum >= 0; ) | |
885 | if (PROC_FREG_MASK(proc_desc) & (1 << regnum)) | |
886 | write_register (regnum + FP0_REGNUM, | |
887 | read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 8)); | |
888 | } | |
889 | write_register (SP_REGNUM, new_sp); | |
890 | flush_cached_frames (); | |
cef4c2e7 PS |
891 | |
892 | if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc)) | |
893 | { | |
894 | struct linked_proc_info *pi_ptr, *prev_ptr; | |
895 | ||
896 | for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL; | |
897 | pi_ptr != NULL; | |
898 | prev_ptr = pi_ptr, pi_ptr = pi_ptr->next) | |
899 | { | |
900 | if (&pi_ptr->info == proc_desc) | |
901 | break; | |
902 | } | |
903 | ||
904 | if (pi_ptr == NULL) | |
905 | error ("Can't locate dummy extra frame info\n"); | |
906 | ||
907 | if (prev_ptr != NULL) | |
908 | prev_ptr->next = pi_ptr->next; | |
909 | else | |
910 | linked_proc_desc_table = pi_ptr->next; | |
911 | ||
912 | free (pi_ptr); | |
913 | } | |
914 | } | |
915 | \f | |
916 | /* To skip prologues, I use this predicate. Returns either PC itself | |
917 | if the code at PC does not look like a function prologue; otherwise | |
918 | returns an address that (if we're lucky) follows the prologue. If | |
919 | LENIENT, then we must skip everything which is involved in setting | |
920 | up the frame (it's OK to skip more, just so long as we don't skip | |
921 | anything which might clobber the registers which are being saved. | |
922 | Currently we must not skip more on the alpha, but we might the lenient | |
923 | stuff some day. */ | |
924 | ||
925 | CORE_ADDR | |
926 | alpha_skip_prologue (pc, lenient) | |
927 | CORE_ADDR pc; | |
928 | int lenient; | |
929 | { | |
930 | unsigned long inst; | |
931 | int offset; | |
72bba93b | 932 | CORE_ADDR post_prologue_pc; |
2fe3b329 PS |
933 | char buf[4]; |
934 | ||
935 | #ifdef GDB_TARGET_HAS_SHARED_LIBS | |
936 | /* Silently return the unaltered pc upon memory errors. | |
937 | This could happen on OSF/1 if decode_line_1 tries to skip the | |
938 | prologue for quickstarted shared library functions when the | |
939 | shared library is not yet mapped in. | |
940 | Reading target memory is slow over serial lines, so we perform | |
941 | this check only if the target has shared libraries. */ | |
942 | if (target_read_memory (pc, buf, 4)) | |
943 | return pc; | |
944 | #endif | |
72bba93b SG |
945 | |
946 | /* See if we can determine the end of the prologue via the symbol table. | |
947 | If so, then return either PC, or the PC after the prologue, whichever | |
948 | is greater. */ | |
949 | ||
950 | post_prologue_pc = after_prologue (pc, NULL); | |
951 | ||
952 | if (post_prologue_pc != 0) | |
953 | return max (pc, post_prologue_pc); | |
954 | ||
955 | /* Can't determine prologue from the symbol table, need to examine | |
956 | instructions. */ | |
cef4c2e7 PS |
957 | |
958 | /* Skip the typical prologue instructions. These are the stack adjustment | |
959 | instruction and the instructions that save registers on the stack | |
960 | or in the gcc frame. */ | |
961 | for (offset = 0; offset < 100; offset += 4) | |
962 | { | |
cef4c2e7 PS |
963 | int status; |
964 | ||
965 | status = read_memory_nobpt (pc + offset, buf, 4); | |
966 | if (status) | |
967 | memory_error (status, pc + offset); | |
968 | inst = extract_unsigned_integer (buf, 4); | |
969 | ||
970 | /* The alpha has no delay slots. But let's keep the lenient stuff, | |
971 | we might need it for something else in the future. */ | |
972 | if (lenient && 0) | |
973 | continue; | |
974 | ||
975 | if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */ | |
976 | continue; | |
977 | if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */ | |
978 | continue; | |
979 | if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ | |
980 | continue; | |
981 | else if ((inst & 0xfc1f0000) == 0xb41e0000 | |
982 | && (inst & 0xffff0000) != 0xb7fe0000) | |
983 | continue; /* stq reg,n($sp) */ | |
984 | /* reg != $zero */ | |
985 | else if ((inst & 0xfc1f0000) == 0x9c1e0000 | |
986 | && (inst & 0xffff0000) != 0x9ffe0000) | |
987 | continue; /* stt reg,n($sp) */ | |
988 | /* reg != $zero */ | |
989 | else if (inst == 0x47de040f) /* bis sp,sp,fp */ | |
990 | continue; | |
991 | else | |
992 | break; | |
993 | } | |
994 | return pc + offset; | |
995 | } | |
996 | ||
e3be225e | 997 | #if 0 |
cef4c2e7 PS |
998 | /* Is address PC in the prologue (loosely defined) for function at |
999 | STARTADDR? */ | |
1000 | ||
1001 | static int | |
1002 | alpha_in_lenient_prologue (startaddr, pc) | |
1003 | CORE_ADDR startaddr; | |
1004 | CORE_ADDR pc; | |
1005 | { | |
1006 | CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1); | |
1007 | return pc >= startaddr && pc < end_prologue; | |
1008 | } | |
e3be225e | 1009 | #endif |
cef4c2e7 | 1010 | |
ad09cb2b PS |
1011 | /* The alpha needs a conversion between register and memory format if |
1012 | the register is a floating point register and | |
1013 | memory format is float, as the register format must be double | |
1014 | or | |
1015 | memory format is an integer with 4 bytes or less, as the representation | |
1016 | of integers in floating point registers is different. */ | |
1017 | void | |
1018 | alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer) | |
1019 | int regnum; | |
1020 | struct type *valtype; | |
1021 | char *raw_buffer; | |
1022 | char *virtual_buffer; | |
1023 | { | |
1024 | if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum)) | |
1025 | { | |
1026 | memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum)); | |
1027 | return; | |
1028 | } | |
1029 | ||
1030 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1031 | { | |
1032 | double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
1033 | store_floating (virtual_buffer, TYPE_LENGTH (valtype), d); | |
1034 | } | |
1035 | else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4) | |
1036 | { | |
1037 | unsigned LONGEST l; | |
1038 | l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
1039 | l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff); | |
1040 | store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l); | |
1041 | } | |
1042 | else | |
1043 | error ("Cannot retrieve value from floating point register"); | |
1044 | } | |
1045 | ||
1046 | void | |
1047 | alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer) | |
1048 | struct type *valtype; | |
1049 | int regnum; | |
1050 | char *virtual_buffer; | |
1051 | char *raw_buffer; | |
1052 | { | |
1053 | if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum)) | |
1054 | { | |
1055 | memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum)); | |
1056 | return; | |
1057 | } | |
1058 | ||
1059 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1060 | { | |
1061 | double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype)); | |
1062 | store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d); | |
1063 | } | |
1064 | else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4) | |
1065 | { | |
1066 | unsigned LONGEST l; | |
1067 | if (TYPE_UNSIGNED (valtype)) | |
1068 | l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype)); | |
1069 | else | |
1070 | l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype)); | |
1071 | l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29); | |
1072 | store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l); | |
1073 | } | |
1074 | else | |
1075 | error ("Cannot store value in floating point register"); | |
1076 | } | |
1077 | ||
cef4c2e7 PS |
1078 | /* Given a return value in `regbuf' with a type `valtype', |
1079 | extract and copy its value into `valbuf'. */ | |
669caa9c | 1080 | |
cef4c2e7 PS |
1081 | void |
1082 | alpha_extract_return_value (valtype, regbuf, valbuf) | |
1083 | struct type *valtype; | |
1084 | char regbuf[REGISTER_BYTES]; | |
1085 | char *valbuf; | |
1086 | { | |
1087 | int regnum; | |
1088 | ||
1089 | regnum = TYPE_CODE (valtype) == TYPE_CODE_FLT ? FP0_REGNUM : V0_REGNUM; | |
1090 | ||
1091 | memcpy (valbuf, regbuf + REGISTER_BYTE (regnum), TYPE_LENGTH (valtype)); | |
1092 | } | |
1093 | ||
1094 | /* Given a return value in `regbuf' with a type `valtype', | |
7810d333 | 1095 | write its value into the appropriate register. */ |
669caa9c | 1096 | |
cef4c2e7 PS |
1097 | void |
1098 | alpha_store_return_value (valtype, valbuf) | |
1099 | struct type *valtype; | |
1100 | char *valbuf; | |
1101 | { | |
1102 | int regnum; | |
1103 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
1104 | ||
1105 | regnum = TYPE_CODE (valtype) == TYPE_CODE_FLT ? FP0_REGNUM : V0_REGNUM; | |
1106 | memcpy(raw_buffer, valbuf, TYPE_LENGTH (valtype)); | |
1107 | ||
1108 | write_register_bytes(REGISTER_BYTE (regnum), raw_buffer, TYPE_LENGTH (valtype)); | |
1109 | } | |
1110 | ||
cef4c2e7 PS |
1111 | /* Just like reinit_frame_cache, but with the right arguments to be |
1112 | callable as an sfunc. */ | |
669caa9c | 1113 | |
cef4c2e7 PS |
1114 | static void |
1115 | reinit_frame_cache_sfunc (args, from_tty, c) | |
1116 | char *args; | |
1117 | int from_tty; | |
1118 | struct cmd_list_element *c; | |
1119 | { | |
1120 | reinit_frame_cache (); | |
1121 | } | |
1122 | ||
72bba93b SG |
1123 | /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used |
1124 | to find a convenient place in the text segment to stick a breakpoint to | |
1125 | detect the completion of a target function call (ala call_function_by_hand). | |
1126 | */ | |
1127 | ||
1128 | CORE_ADDR | |
1129 | alpha_call_dummy_address () | |
1130 | { | |
1131 | CORE_ADDR entry; | |
1132 | struct minimal_symbol *sym; | |
1133 | ||
1134 | entry = entry_point_address (); | |
1135 | ||
1136 | if (entry != 0) | |
1137 | return entry; | |
1138 | ||
2d336b1b | 1139 | sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile); |
72bba93b SG |
1140 | |
1141 | if (!sym || MSYMBOL_TYPE (sym) != mst_text) | |
1142 | return 0; | |
1143 | else | |
1144 | return SYMBOL_VALUE_ADDRESS (sym) + 4; | |
1145 | } | |
1146 | ||
cef4c2e7 PS |
1147 | void |
1148 | _initialize_alpha_tdep () | |
1149 | { | |
1150 | struct cmd_list_element *c; | |
1151 | ||
18b46e7c SS |
1152 | tm_print_insn = print_insn_alpha; |
1153 | ||
cef4c2e7 PS |
1154 | /* Let the user set the fence post for heuristic_proc_start. */ |
1155 | ||
1156 | /* We really would like to have both "0" and "unlimited" work, but | |
1157 | command.c doesn't deal with that. So make it a var_zinteger | |
1158 | because the user can always use "999999" or some such for unlimited. */ | |
1159 | c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger, | |
1160 | (char *) &heuristic_fence_post, | |
1161 | "\ | |
1162 | Set the distance searched for the start of a function.\n\ | |
1163 | If you are debugging a stripped executable, GDB needs to search through the\n\ | |
1164 | program for the start of a function. This command sets the distance of the\n\ | |
1165 | search. The only need to set it is when debugging a stripped executable.", | |
1166 | &setlist); | |
1167 | /* We need to throw away the frame cache when we set this, since it | |
1168 | might change our ability to get backtraces. */ | |
1169 | c->function.sfunc = reinit_frame_cache_sfunc; | |
1170 | add_show_from_set (c, &showlist); | |
1171 | } |