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