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