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