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