Commit | Line | Data |
---|---|---|
66a1aa07 SG |
1 | /* Machine-dependent code which would otherwise be in inflow.c and core.c, |
2 | for GDB, the GNU debugger. This code is for the HP PA-RISC cpu. | |
3 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. | |
4 | ||
5 | Contributed by the Center for Software Science at the | |
6 | University of Utah (pa-gdb-bugs@cs.utah.edu). | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
23 | ||
24 | #include "defs.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "value.h" | |
28 | ||
29 | /* For argument passing to the inferior */ | |
30 | #include "symtab.h" | |
31 | ||
32 | #ifdef USG | |
33 | #include <sys/types.h> | |
34 | #endif | |
35 | ||
36 | #include <sys/param.h> | |
37 | #include <sys/dir.h> | |
38 | #include <signal.h> | |
39 | #include <sys/ioctl.h> | |
40 | ||
41 | #ifdef COFF_ENCAPSULATE | |
42 | #include "a.out.encap.h" | |
43 | #else | |
44 | #include <a.out.h> | |
45 | #endif | |
46 | #ifndef N_SET_MAGIC | |
47 | #define N_SET_MAGIC(exec, val) ((exec).a_magic = (val)) | |
48 | #endif | |
49 | ||
50 | /*#include <sys/user.h> After a.out.h */ | |
51 | #include <sys/file.h> | |
52 | #include <sys/stat.h> | |
53 | #include <machine/psl.h> | |
54 | #include "wait.h" | |
55 | ||
56 | #include "gdbcore.h" | |
57 | #include "gdbcmd.h" | |
58 | #include "target.h" | |
59 | #include "symfile.h" | |
60 | #include "objfiles.h" | |
61 | ||
62 | static int restore_pc_queue PARAMS ((struct frame_saved_regs *fsr)); | |
63 | static int hppa_alignof PARAMS ((struct type *arg)); | |
8fa74880 | 64 | CORE_ADDR frame_saved_pc PARAMS ((FRAME frame)); |
66a1aa07 SG |
65 | |
66 | \f | |
67 | /* Routines to extract various sized constants out of hppa | |
68 | instructions. */ | |
69 | ||
70 | /* This assumes that no garbage lies outside of the lower bits of | |
71 | value. */ | |
72 | ||
73 | int | |
74 | sign_extend (val, bits) | |
75 | unsigned val, bits; | |
76 | { | |
77 | return (int)(val >> bits - 1 ? (-1 << bits) | val : val); | |
78 | } | |
79 | ||
80 | /* For many immediate values the sign bit is the low bit! */ | |
81 | ||
82 | int | |
83 | low_sign_extend (val, bits) | |
84 | unsigned val, bits; | |
85 | { | |
86 | return (int)((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1); | |
87 | } | |
88 | /* extract the immediate field from a ld{bhw}s instruction */ | |
89 | ||
90 | unsigned | |
91 | get_field (val, from, to) | |
92 | unsigned val, from, to; | |
93 | { | |
94 | val = val >> 31 - to; | |
95 | return val & ((1 << 32 - from) - 1); | |
96 | } | |
97 | ||
98 | unsigned | |
99 | set_field (val, from, to, new_val) | |
100 | unsigned *val, from, to; | |
101 | { | |
102 | unsigned mask = ~((1 << (to - from + 1)) << (31 - from)); | |
103 | return *val = *val & mask | (new_val << (31 - from)); | |
104 | } | |
105 | ||
106 | /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */ | |
107 | ||
108 | extract_3 (word) | |
109 | unsigned word; | |
110 | { | |
111 | return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17); | |
112 | } | |
113 | ||
114 | extract_5_load (word) | |
115 | unsigned word; | |
116 | { | |
117 | return low_sign_extend (word >> 16 & MASK_5, 5); | |
118 | } | |
119 | ||
120 | /* extract the immediate field from a st{bhw}s instruction */ | |
121 | ||
122 | int | |
123 | extract_5_store (word) | |
124 | unsigned word; | |
125 | { | |
126 | return low_sign_extend (word & MASK_5, 5); | |
127 | } | |
128 | ||
68c8d698 SG |
129 | /* extract the immediate field from a break instruction */ |
130 | ||
131 | unsigned | |
132 | extract_5r_store (word) | |
133 | unsigned word; | |
134 | { | |
135 | return (word & MASK_5); | |
136 | } | |
137 | ||
138 | /* extract the immediate field from a {sr}sm instruction */ | |
139 | ||
140 | unsigned | |
141 | extract_5R_store (word) | |
142 | unsigned word; | |
143 | { | |
144 | return (word >> 16 & MASK_5); | |
145 | } | |
146 | ||
66a1aa07 SG |
147 | /* extract an 11 bit immediate field */ |
148 | ||
149 | int | |
150 | extract_11 (word) | |
151 | unsigned word; | |
152 | { | |
153 | return low_sign_extend (word & MASK_11, 11); | |
154 | } | |
155 | ||
156 | /* extract a 14 bit immediate field */ | |
157 | ||
158 | int | |
159 | extract_14 (word) | |
160 | unsigned word; | |
161 | { | |
162 | return low_sign_extend (word & MASK_14, 14); | |
163 | } | |
164 | ||
165 | /* deposit a 14 bit constant in a word */ | |
166 | ||
167 | unsigned | |
168 | deposit_14 (opnd, word) | |
169 | int opnd; | |
170 | unsigned word; | |
171 | { | |
172 | unsigned sign = (opnd < 0 ? 1 : 0); | |
173 | ||
174 | return word | ((unsigned)opnd << 1 & MASK_14) | sign; | |
175 | } | |
176 | ||
177 | /* extract a 21 bit constant */ | |
178 | ||
179 | int | |
180 | extract_21 (word) | |
181 | unsigned word; | |
182 | { | |
183 | int val; | |
184 | ||
185 | word &= MASK_21; | |
186 | word <<= 11; | |
187 | val = GET_FIELD (word, 20, 20); | |
188 | val <<= 11; | |
189 | val |= GET_FIELD (word, 9, 19); | |
190 | val <<= 2; | |
191 | val |= GET_FIELD (word, 5, 6); | |
192 | val <<= 5; | |
193 | val |= GET_FIELD (word, 0, 4); | |
194 | val <<= 2; | |
195 | val |= GET_FIELD (word, 7, 8); | |
196 | return sign_extend (val, 21) << 11; | |
197 | } | |
198 | ||
199 | /* deposit a 21 bit constant in a word. Although 21 bit constants are | |
200 | usually the top 21 bits of a 32 bit constant, we assume that only | |
201 | the low 21 bits of opnd are relevant */ | |
202 | ||
203 | unsigned | |
204 | deposit_21 (opnd, word) | |
205 | unsigned opnd, word; | |
206 | { | |
207 | unsigned val = 0; | |
208 | ||
209 | val |= GET_FIELD (opnd, 11 + 14, 11 + 18); | |
210 | val <<= 2; | |
211 | val |= GET_FIELD (opnd, 11 + 12, 11 + 13); | |
212 | val <<= 2; | |
213 | val |= GET_FIELD (opnd, 11 + 19, 11 + 20); | |
214 | val <<= 11; | |
215 | val |= GET_FIELD (opnd, 11 + 1, 11 + 11); | |
216 | val <<= 1; | |
217 | val |= GET_FIELD (opnd, 11 + 0, 11 + 0); | |
218 | return word | val; | |
219 | } | |
220 | ||
221 | /* extract a 12 bit constant from branch instructions */ | |
222 | ||
223 | int | |
224 | extract_12 (word) | |
225 | unsigned word; | |
226 | { | |
227 | return sign_extend (GET_FIELD (word, 19, 28) | | |
228 | GET_FIELD (word, 29, 29) << 10 | | |
229 | (word & 0x1) << 11, 12) << 2; | |
230 | } | |
231 | ||
232 | /* extract a 17 bit constant from branch instructions, returning the | |
233 | 19 bit signed value. */ | |
234 | ||
235 | int | |
236 | extract_17 (word) | |
237 | unsigned word; | |
238 | { | |
239 | return sign_extend (GET_FIELD (word, 19, 28) | | |
240 | GET_FIELD (word, 29, 29) << 10 | | |
241 | GET_FIELD (word, 11, 15) << 11 | | |
242 | (word & 0x1) << 16, 17) << 2; | |
243 | } | |
244 | \f | |
245 | static int use_unwind = 0; | |
246 | ||
247 | /* Lookup the unwind (stack backtrace) info for the given PC. We search all | |
248 | of the objfiles seeking the unwind table entry for this PC. Each objfile | |
249 | contains a sorted list of struct unwind_table_entry. Since we do a binary | |
250 | search of the unwind tables, we depend upon them to be sorted. */ | |
251 | ||
252 | static struct unwind_table_entry * | |
253 | find_unwind_entry(pc) | |
254 | CORE_ADDR pc; | |
255 | { | |
256 | int first, middle, last; | |
257 | struct objfile *objfile; | |
258 | ||
259 | ALL_OBJFILES (objfile) | |
260 | { | |
261 | struct obj_unwind_info *ui; | |
262 | ||
263 | ui = OBJ_UNWIND_INFO (objfile); | |
264 | ||
265 | if (!ui) | |
266 | continue; | |
267 | ||
268 | /* First, check the cache */ | |
269 | ||
270 | if (ui->cache | |
271 | && pc >= ui->cache->region_start | |
272 | && pc <= ui->cache->region_end) | |
273 | return ui->cache; | |
274 | ||
275 | /* Not in the cache, do a binary search */ | |
276 | ||
277 | first = 0; | |
278 | last = ui->last; | |
279 | ||
280 | while (first <= last) | |
281 | { | |
282 | middle = (first + last) / 2; | |
283 | if (pc >= ui->table[middle].region_start | |
284 | && pc <= ui->table[middle].region_end) | |
285 | { | |
286 | ui->cache = &ui->table[middle]; | |
287 | return &ui->table[middle]; | |
288 | } | |
289 | ||
290 | if (pc < ui->table[middle].region_start) | |
291 | last = middle - 1; | |
292 | else | |
293 | first = middle + 1; | |
294 | } | |
295 | } /* ALL_OBJFILES() */ | |
296 | return NULL; | |
297 | } | |
298 | ||
5ac7f56e JK |
299 | /* Called when no unwind descriptor was found for PC. Returns 1 if it |
300 | appears that PC is in a linker stub. */ | |
301 | static int pc_in_linker_stub PARAMS ((CORE_ADDR)); | |
302 | ||
303 | static int | |
304 | pc_in_linker_stub (pc) | |
305 | CORE_ADDR pc; | |
306 | { | |
5ac7f56e JK |
307 | int found_magic_instruction = 0; |
308 | int i; | |
08ecd8f3 JK |
309 | char buf[4]; |
310 | ||
311 | /* If unable to read memory, assume pc is not in a linker stub. */ | |
312 | if (target_read_memory (pc, buf, 4) != 0) | |
313 | return 0; | |
5ac7f56e | 314 | |
d08c6f4c JK |
315 | /* We are looking for something like |
316 | ||
317 | ; $$dyncall jams RP into this special spot in the frame (RP') | |
318 | ; before calling the "call stub" | |
319 | ldw -18(sp),rp | |
320 | ||
321 | ldsid (rp),r1 ; Get space associated with RP into r1 | |
322 | mtsp r1,sp ; Move it into space register 0 | |
323 | be,n 0(sr0),rp) ; back to your regularly scheduled program | |
324 | */ | |
325 | ||
5ac7f56e JK |
326 | /* Maximum known linker stub size is 4 instructions. Search forward |
327 | from the given PC, then backward. */ | |
328 | for (i = 0; i < 4; i++) | |
329 | { | |
330 | /* If we hit something with an unwind, stop searching this direction. | |
331 | ||
332 | if (find_unwind_entry (pc + i * 4) != 0) | |
333 | break; | |
334 | ||
335 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
336 | return from a cross-space function call. */ | |
337 | if (read_memory_integer (pc + i * 4, 4) == 0x004010a1) | |
338 | { | |
339 | found_magic_instruction = 1; | |
340 | break; | |
341 | } | |
342 | /* Add code to handle long call/branch and argument relocation stubs | |
343 | here. */ | |
344 | } | |
345 | ||
346 | if (found_magic_instruction != 0) | |
347 | return 1; | |
348 | ||
349 | /* Now look backward. */ | |
350 | for (i = 0; i < 4; i++) | |
351 | { | |
352 | /* If we hit something with an unwind, stop searching this direction. | |
353 | ||
354 | if (find_unwind_entry (pc - i * 4) != 0) | |
355 | break; | |
356 | ||
357 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
358 | return from a cross-space function call. */ | |
359 | if (read_memory_integer (pc - i * 4, 4) == 0x004010a1) | |
360 | { | |
361 | found_magic_instruction = 1; | |
362 | break; | |
363 | } | |
364 | /* Add code to handle long call/branch and argument relocation stubs | |
365 | here. */ | |
366 | } | |
367 | return found_magic_instruction; | |
368 | } | |
369 | ||
66a1aa07 SG |
370 | static int |
371 | find_return_regnum(pc) | |
372 | CORE_ADDR pc; | |
373 | { | |
374 | struct unwind_table_entry *u; | |
375 | ||
376 | u = find_unwind_entry (pc); | |
377 | ||
378 | if (!u) | |
379 | return RP_REGNUM; | |
380 | ||
381 | if (u->Millicode) | |
382 | return 31; | |
383 | ||
384 | return RP_REGNUM; | |
385 | } | |
386 | ||
5ac7f56e | 387 | /* Return size of frame, or -1 if we should use a frame pointer. */ |
66a1aa07 SG |
388 | int |
389 | find_proc_framesize(pc) | |
390 | CORE_ADDR pc; | |
391 | { | |
392 | struct unwind_table_entry *u; | |
393 | ||
394 | if (!use_unwind) | |
395 | return -1; | |
396 | ||
397 | u = find_unwind_entry (pc); | |
398 | ||
399 | if (!u) | |
5ac7f56e JK |
400 | { |
401 | if (pc_in_linker_stub (pc)) | |
402 | /* Linker stubs have a zero size frame. */ | |
403 | return 0; | |
404 | else | |
405 | return -1; | |
406 | } | |
66a1aa07 | 407 | |
eabbe766 JK |
408 | if (u->Save_SP) |
409 | /* If this bit is set, it means there is a frame pointer and we should | |
410 | use it. */ | |
411 | return -1; | |
412 | ||
66a1aa07 SG |
413 | return u->Total_frame_size << 3; |
414 | } | |
415 | ||
5ac7f56e JK |
416 | /* Return offset from sp at which rp is saved, or 0 if not saved. */ |
417 | static int rp_saved PARAMS ((CORE_ADDR)); | |
418 | ||
419 | static int | |
420 | rp_saved (pc) | |
421 | CORE_ADDR pc; | |
66a1aa07 SG |
422 | { |
423 | struct unwind_table_entry *u; | |
424 | ||
425 | u = find_unwind_entry (pc); | |
426 | ||
427 | if (!u) | |
5ac7f56e JK |
428 | { |
429 | if (pc_in_linker_stub (pc)) | |
430 | /* This is the so-called RP'. */ | |
431 | return -24; | |
432 | else | |
433 | return 0; | |
434 | } | |
66a1aa07 SG |
435 | |
436 | if (u->Save_RP) | |
5ac7f56e | 437 | return -20; |
66a1aa07 SG |
438 | else |
439 | return 0; | |
440 | } | |
441 | \f | |
8fa74880 SG |
442 | int |
443 | frameless_function_invocation (frame) | |
444 | FRAME frame; | |
445 | { | |
446 | ||
447 | if (use_unwind) | |
448 | { | |
449 | struct unwind_table_entry *u; | |
450 | ||
451 | u = find_unwind_entry (frame->pc); | |
452 | ||
453 | if (u == 0) | |
454 | return 0; | |
455 | ||
456 | return (u->Total_frame_size == 0); | |
457 | } | |
458 | else | |
459 | return frameless_look_for_prologue (frame); | |
460 | } | |
461 | ||
66a1aa07 SG |
462 | CORE_ADDR |
463 | saved_pc_after_call (frame) | |
464 | FRAME frame; | |
465 | { | |
466 | int ret_regnum; | |
467 | ||
468 | ret_regnum = find_return_regnum (get_frame_pc (frame)); | |
469 | ||
470 | return read_register (ret_regnum) & ~0x3; | |
471 | } | |
472 | \f | |
473 | CORE_ADDR | |
474 | frame_saved_pc (frame) | |
475 | FRAME frame; | |
476 | { | |
477 | CORE_ADDR pc = get_frame_pc (frame); | |
478 | ||
8fa74880 | 479 | if (frameless_function_invocation (frame)) |
66a1aa07 SG |
480 | { |
481 | int ret_regnum; | |
482 | ||
483 | ret_regnum = find_return_regnum (pc); | |
484 | ||
485 | return read_register (ret_regnum) & ~0x3; | |
486 | } | |
66a1aa07 | 487 | else |
5ac7f56e JK |
488 | { |
489 | int rp_offset = rp_saved (pc); | |
490 | ||
491 | if (rp_offset == 0) | |
492 | return read_register (RP_REGNUM) & ~0x3; | |
493 | else | |
28403b8e | 494 | return read_memory_integer (frame->frame + rp_offset, 4) & ~0x3; |
5ac7f56e | 495 | } |
66a1aa07 SG |
496 | } |
497 | \f | |
498 | /* We need to correct the PC and the FP for the outermost frame when we are | |
499 | in a system call. */ | |
500 | ||
501 | void | |
502 | init_extra_frame_info (fromleaf, frame) | |
503 | int fromleaf; | |
504 | struct frame_info *frame; | |
505 | { | |
506 | int flags; | |
507 | int framesize; | |
508 | ||
509 | if (frame->next) /* Only do this for outermost frame */ | |
510 | return; | |
511 | ||
512 | flags = read_register (FLAGS_REGNUM); | |
513 | if (flags & 2) /* In system call? */ | |
514 | frame->pc = read_register (31) & ~0x3; | |
515 | ||
516 | /* The outermost frame is always derived from PC-framesize */ | |
517 | framesize = find_proc_framesize(frame->pc); | |
518 | if (framesize == -1) | |
519 | frame->frame = read_register (FP_REGNUM); | |
520 | else | |
521 | frame->frame = read_register (SP_REGNUM) - framesize; | |
522 | ||
8fa74880 | 523 | if (!frameless_function_invocation (frame)) /* Frameless? */ |
66a1aa07 SG |
524 | return; /* No, quit now */ |
525 | ||
526 | /* For frameless functions, we need to look at the caller's frame */ | |
527 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
528 | if (framesize != -1) | |
529 | frame->frame -= framesize; | |
530 | } | |
531 | \f | |
532 | FRAME_ADDR | |
533 | frame_chain (frame) | |
534 | struct frame_info *frame; | |
535 | { | |
536 | int framesize; | |
537 | ||
538 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
539 | ||
540 | if (framesize != -1) | |
541 | return frame->frame - framesize; | |
542 | ||
543 | return read_memory_integer (frame->frame, 4); | |
544 | } | |
545 | \f | |
546 | /* To see if a frame chain is valid, see if the caller looks like it | |
547 | was compiled with gcc. */ | |
548 | ||
549 | int | |
550 | frame_chain_valid (chain, thisframe) | |
551 | FRAME_ADDR chain; | |
552 | FRAME thisframe; | |
553 | { | |
554 | struct minimal_symbol *msym; | |
555 | ||
556 | if (!chain) | |
557 | return 0; | |
558 | ||
4b01383b SG |
559 | if (use_unwind) |
560 | { | |
66a1aa07 | 561 | |
4b01383b SG |
562 | struct unwind_table_entry *u; |
563 | ||
564 | u = find_unwind_entry (thisframe->pc); | |
565 | ||
5ac7f56e JK |
566 | if (u == NULL) |
567 | /* FIXME, we should probably fall back to some other technique, | |
568 | if we want to deal gracefully with stripped executables or others | |
569 | without unwind info. */ | |
4b01383b | 570 | return 0; |
5ac7f56e JK |
571 | |
572 | if (u->Save_SP || u->Total_frame_size) | |
573 | return 1; | |
574 | ||
575 | if (pc_in_linker_stub (thisframe->pc)) | |
576 | return 1; | |
577 | ||
578 | return 0; | |
4b01383b | 579 | } |
66a1aa07 | 580 | else |
4b01383b SG |
581 | { |
582 | msym = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe)); | |
583 | ||
584 | if (msym | |
585 | && (strcmp (SYMBOL_NAME (msym), "_start") == 0)) | |
586 | return 0; | |
587 | else | |
588 | return 1; | |
589 | } | |
66a1aa07 SG |
590 | } |
591 | ||
66a1aa07 SG |
592 | /* |
593 | * These functions deal with saving and restoring register state | |
594 | * around a function call in the inferior. They keep the stack | |
595 | * double-word aligned; eventually, on an hp700, the stack will have | |
596 | * to be aligned to a 64-byte boundary. | |
597 | */ | |
598 | ||
599 | int | |
600 | push_dummy_frame () | |
601 | { | |
602 | register CORE_ADDR sp; | |
603 | register int regnum; | |
604 | int int_buffer; | |
605 | double freg_buffer; | |
606 | ||
607 | /* Space for "arguments"; the RP goes in here. */ | |
608 | sp = read_register (SP_REGNUM) + 48; | |
609 | int_buffer = read_register (RP_REGNUM) | 0x3; | |
610 | write_memory (sp - 20, (char *)&int_buffer, 4); | |
611 | ||
612 | int_buffer = read_register (FP_REGNUM); | |
613 | write_memory (sp, (char *)&int_buffer, 4); | |
614 | ||
615 | write_register (FP_REGNUM, sp); | |
616 | ||
617 | sp += 8; | |
618 | ||
619 | for (regnum = 1; regnum < 32; regnum++) | |
620 | if (regnum != RP_REGNUM && regnum != FP_REGNUM) | |
621 | sp = push_word (sp, read_register (regnum)); | |
622 | ||
623 | sp += 4; | |
624 | ||
625 | for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++) | |
626 | { | |
627 | read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); | |
628 | sp = push_bytes (sp, (char *)&freg_buffer, 8); | |
629 | } | |
630 | sp = push_word (sp, read_register (IPSW_REGNUM)); | |
631 | sp = push_word (sp, read_register (SAR_REGNUM)); | |
632 | sp = push_word (sp, read_register (PCOQ_HEAD_REGNUM)); | |
633 | sp = push_word (sp, read_register (PCSQ_HEAD_REGNUM)); | |
634 | sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM)); | |
635 | sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM)); | |
636 | write_register (SP_REGNUM, sp); | |
637 | } | |
638 | ||
639 | find_dummy_frame_regs (frame, frame_saved_regs) | |
640 | struct frame_info *frame; | |
641 | struct frame_saved_regs *frame_saved_regs; | |
642 | { | |
643 | CORE_ADDR fp = frame->frame; | |
644 | int i; | |
645 | ||
646 | frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3; | |
647 | frame_saved_regs->regs[FP_REGNUM] = fp; | |
648 | frame_saved_regs->regs[1] = fp + 8; | |
66a1aa07 | 649 | |
b227992a SG |
650 | for (fp += 12, i = 3; i < 32; i++) |
651 | { | |
652 | if (i != FP_REGNUM) | |
653 | { | |
654 | frame_saved_regs->regs[i] = fp; | |
655 | fp += 4; | |
656 | } | |
657 | } | |
66a1aa07 SG |
658 | |
659 | fp += 4; | |
660 | for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8) | |
661 | frame_saved_regs->regs[i] = fp; | |
662 | ||
663 | frame_saved_regs->regs[IPSW_REGNUM] = fp; | |
b227992a SG |
664 | frame_saved_regs->regs[SAR_REGNUM] = fp + 4; |
665 | frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp + 8; | |
666 | frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp + 12; | |
667 | frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp + 16; | |
668 | frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp + 20; | |
66a1aa07 SG |
669 | } |
670 | ||
671 | int | |
672 | hppa_pop_frame () | |
673 | { | |
674 | register FRAME frame = get_current_frame (); | |
675 | register CORE_ADDR fp; | |
676 | register int regnum; | |
677 | struct frame_saved_regs fsr; | |
678 | struct frame_info *fi; | |
679 | double freg_buffer; | |
680 | ||
681 | fi = get_frame_info (frame); | |
682 | fp = fi->frame; | |
683 | get_frame_saved_regs (fi, &fsr); | |
684 | ||
685 | if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */ | |
686 | restore_pc_queue (&fsr); | |
687 | ||
688 | for (regnum = 31; regnum > 0; regnum--) | |
689 | if (fsr.regs[regnum]) | |
690 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); | |
691 | ||
692 | for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--) | |
693 | if (fsr.regs[regnum]) | |
694 | { | |
695 | read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8); | |
696 | write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); | |
697 | } | |
698 | ||
699 | if (fsr.regs[IPSW_REGNUM]) | |
700 | write_register (IPSW_REGNUM, | |
701 | read_memory_integer (fsr.regs[IPSW_REGNUM], 4)); | |
702 | ||
703 | if (fsr.regs[SAR_REGNUM]) | |
704 | write_register (SAR_REGNUM, | |
705 | read_memory_integer (fsr.regs[SAR_REGNUM], 4)); | |
706 | ||
707 | if (fsr.regs[PCOQ_TAIL_REGNUM]) | |
708 | write_register (PCOQ_TAIL_REGNUM, | |
709 | read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4)); | |
710 | ||
711 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); | |
712 | ||
713 | if (fsr.regs[IPSW_REGNUM]) /* call dummy */ | |
714 | write_register (SP_REGNUM, fp - 48); | |
715 | else | |
716 | write_register (SP_REGNUM, fp); | |
717 | ||
718 | flush_cached_frames (); | |
719 | set_current_frame (create_new_frame (read_register (FP_REGNUM), | |
720 | read_pc ())); | |
721 | } | |
722 | ||
723 | /* | |
724 | * After returning to a dummy on the stack, restore the instruction | |
725 | * queue space registers. */ | |
726 | ||
727 | static int | |
728 | restore_pc_queue (fsr) | |
729 | struct frame_saved_regs *fsr; | |
730 | { | |
731 | CORE_ADDR pc = read_pc (); | |
732 | CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4); | |
733 | int pid; | |
734 | WAITTYPE w; | |
735 | int insn_count; | |
736 | ||
737 | /* Advance past break instruction in the call dummy. */ | |
738 | write_register (PCOQ_HEAD_REGNUM, pc + 4); | |
739 | write_register (PCOQ_TAIL_REGNUM, pc + 8); | |
740 | ||
741 | /* | |
742 | * HPUX doesn't let us set the space registers or the space | |
743 | * registers of the PC queue through ptrace. Boo, hiss. | |
744 | * Conveniently, the call dummy has this sequence of instructions | |
745 | * after the break: | |
746 | * mtsp r21, sr0 | |
747 | * ble,n 0(sr0, r22) | |
748 | * | |
749 | * So, load up the registers and single step until we are in the | |
750 | * right place. | |
751 | */ | |
752 | ||
753 | write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4)); | |
754 | write_register (22, new_pc); | |
755 | ||
756 | for (insn_count = 0; insn_count < 3; insn_count++) | |
757 | { | |
758 | resume (1, 0); | |
759 | target_wait(&w); | |
760 | ||
761 | if (!WIFSTOPPED (w)) | |
762 | { | |
763 | stop_signal = WTERMSIG (w); | |
764 | terminal_ours_for_output (); | |
765 | printf ("\nProgram terminated with signal %d, %s\n", | |
766 | stop_signal, safe_strsignal (stop_signal)); | |
767 | fflush (stdout); | |
768 | return 0; | |
769 | } | |
770 | } | |
771 | fetch_inferior_registers (-1); | |
772 | return 1; | |
773 | } | |
774 | ||
775 | CORE_ADDR | |
776 | hppa_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
777 | int nargs; | |
778 | value *args; | |
779 | CORE_ADDR sp; | |
780 | int struct_return; | |
781 | CORE_ADDR struct_addr; | |
782 | { | |
783 | /* array of arguments' offsets */ | |
1edc5cd2 | 784 | int *offset = (int *)alloca(nargs * sizeof (int)); |
66a1aa07 SG |
785 | int cum = 0; |
786 | int i, alignment; | |
787 | ||
788 | for (i = 0; i < nargs; i++) | |
789 | { | |
790 | /* Coerce chars to int & float to double if necessary */ | |
791 | args[i] = value_arg_coerce (args[i]); | |
792 | ||
793 | cum += TYPE_LENGTH (VALUE_TYPE (args[i])); | |
794 | ||
795 | /* value must go at proper alignment. Assume alignment is a | |
796 | power of two.*/ | |
797 | alignment = hppa_alignof (VALUE_TYPE (args[i])); | |
798 | if (cum % alignment) | |
799 | cum = (cum + alignment) & -alignment; | |
800 | offset[i] = -cum; | |
801 | } | |
558f4183 | 802 | sp += max ((cum + 7) & -8, 16); |
66a1aa07 SG |
803 | |
804 | for (i = 0; i < nargs; i++) | |
805 | write_memory (sp + offset[i], VALUE_CONTENTS (args[i]), | |
806 | TYPE_LENGTH (VALUE_TYPE (args[i]))); | |
807 | ||
808 | if (struct_return) | |
809 | write_register (28, struct_addr); | |
810 | return sp + 32; | |
811 | } | |
812 | ||
813 | /* | |
814 | * Insert the specified number of args and function address | |
815 | * into a call sequence of the above form stored at DUMMYNAME. | |
816 | * | |
817 | * On the hppa we need to call the stack dummy through $$dyncall. | |
818 | * Therefore our version of FIX_CALL_DUMMY takes an extra argument, | |
819 | * real_pc, which is the location where gdb should start up the | |
820 | * inferior to do the function call. | |
821 | */ | |
822 | ||
823 | CORE_ADDR | |
824 | hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p) | |
825 | REGISTER_TYPE *dummy; | |
826 | CORE_ADDR pc; | |
827 | CORE_ADDR fun; | |
828 | int nargs; | |
829 | value *args; | |
830 | struct type *type; | |
831 | int gcc_p; | |
832 | { | |
833 | CORE_ADDR dyncall_addr, sr4export_addr; | |
834 | struct minimal_symbol *msymbol; | |
835 | ||
836 | msymbol = lookup_minimal_symbol ("$$dyncall", (struct objfile *) NULL); | |
837 | if (msymbol == NULL) | |
838 | error ("Can't find an address for $$dyncall trampoline"); | |
839 | ||
840 | dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
841 | ||
842 | msymbol = lookup_minimal_symbol ("_sr4export", (struct objfile *) NULL); | |
843 | if (msymbol == NULL) | |
844 | error ("Can't find an address for _sr4export trampoline"); | |
845 | ||
846 | sr4export_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
847 | ||
848 | dummy[9] = deposit_21 (fun >> 11, dummy[9]); | |
849 | dummy[10] = deposit_14 (fun & MASK_11, dummy[10]); | |
850 | dummy[12] = deposit_21 (sr4export_addr >> 11, dummy[12]); | |
851 | dummy[13] = deposit_14 (sr4export_addr & MASK_11, dummy[13]); | |
852 | ||
853 | write_register (22, pc); | |
854 | ||
855 | return dyncall_addr; | |
856 | } | |
857 | ||
858 | /* return the alignment of a type in bytes. Structures have the maximum | |
859 | alignment required by their fields. */ | |
860 | ||
861 | static int | |
862 | hppa_alignof (arg) | |
863 | struct type *arg; | |
864 | { | |
865 | int max_align, align, i; | |
866 | switch (TYPE_CODE (arg)) | |
867 | { | |
868 | case TYPE_CODE_PTR: | |
869 | case TYPE_CODE_INT: | |
870 | case TYPE_CODE_FLT: | |
871 | return TYPE_LENGTH (arg); | |
872 | case TYPE_CODE_ARRAY: | |
873 | return hppa_alignof (TYPE_FIELD_TYPE (arg, 0)); | |
874 | case TYPE_CODE_STRUCT: | |
875 | case TYPE_CODE_UNION: | |
876 | max_align = 2; | |
877 | for (i = 0; i < TYPE_NFIELDS (arg); i++) | |
878 | { | |
879 | /* Bit fields have no real alignment. */ | |
880 | if (!TYPE_FIELD_BITPOS (arg, i)) | |
881 | { | |
882 | align = hppa_alignof (TYPE_FIELD_TYPE (arg, i)); | |
883 | max_align = max (max_align, align); | |
884 | } | |
885 | } | |
886 | return max_align; | |
887 | default: | |
888 | return 4; | |
889 | } | |
890 | } | |
891 | ||
892 | /* Print the register regnum, or all registers if regnum is -1 */ | |
893 | ||
894 | pa_do_registers_info (regnum, fpregs) | |
895 | int regnum; | |
896 | int fpregs; | |
897 | { | |
898 | char raw_regs [REGISTER_BYTES]; | |
899 | int i; | |
900 | ||
901 | for (i = 0; i < NUM_REGS; i++) | |
902 | read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i)); | |
903 | if (regnum == -1) | |
904 | pa_print_registers (raw_regs, regnum, fpregs); | |
905 | else if (regnum < FP0_REGNUM) | |
906 | printf ("%s %x\n", reg_names[regnum], *(long *)(raw_regs + | |
907 | REGISTER_BYTE (regnum))); | |
908 | else | |
909 | pa_print_fp_reg (regnum); | |
910 | } | |
911 | ||
912 | pa_print_registers (raw_regs, regnum, fpregs) | |
913 | char *raw_regs; | |
914 | int regnum; | |
915 | int fpregs; | |
916 | { | |
917 | int i; | |
918 | ||
919 | for (i = 0; i < 18; i++) | |
920 | printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n", | |
921 | reg_names[i], | |
922 | *(int *)(raw_regs + REGISTER_BYTE (i)), | |
923 | reg_names[i + 18], | |
924 | *(int *)(raw_regs + REGISTER_BYTE (i + 18)), | |
925 | reg_names[i + 36], | |
926 | *(int *)(raw_regs + REGISTER_BYTE (i + 36)), | |
927 | reg_names[i + 54], | |
928 | *(int *)(raw_regs + REGISTER_BYTE (i + 54))); | |
929 | ||
930 | if (fpregs) | |
931 | for (i = 72; i < NUM_REGS; i++) | |
932 | pa_print_fp_reg (i); | |
933 | } | |
934 | ||
935 | pa_print_fp_reg (i) | |
936 | int i; | |
937 | { | |
938 | unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
939 | unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
940 | REGISTER_TYPE val; | |
941 | ||
942 | /* Get the data in raw format, then convert also to virtual format. */ | |
943 | read_relative_register_raw_bytes (i, raw_buffer); | |
944 | REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer); | |
945 | ||
946 | fputs_filtered (reg_names[i], stdout); | |
947 | print_spaces_filtered (15 - strlen (reg_names[i]), stdout); | |
948 | ||
949 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0, | |
950 | 1, 0, Val_pretty_default); | |
951 | printf_filtered ("\n"); | |
952 | } | |
953 | ||
954 | /* Function calls that pass into a new compilation unit must pass through a | |
955 | small piece of code that does long format (`external' in HPPA parlance) | |
956 | jumps. We figure out where the trampoline is going to end up, and return | |
957 | the PC of the final destination. If we aren't in a trampoline, we just | |
958 | return NULL. | |
959 | ||
960 | For computed calls, we just extract the new PC from r22. */ | |
961 | ||
962 | CORE_ADDR | |
963 | skip_trampoline_code (pc, name) | |
964 | CORE_ADDR pc; | |
965 | char *name; | |
966 | { | |
967 | long inst0, inst1; | |
968 | static CORE_ADDR dyncall = 0; | |
969 | struct minimal_symbol *msym; | |
970 | ||
971 | /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */ | |
972 | ||
973 | if (!dyncall) | |
974 | { | |
975 | msym = lookup_minimal_symbol ("$$dyncall", NULL); | |
976 | if (msym) | |
977 | dyncall = SYMBOL_VALUE_ADDRESS (msym); | |
978 | else | |
979 | dyncall = -1; | |
980 | } | |
981 | ||
982 | if (pc == dyncall) | |
983 | return (CORE_ADDR)(read_register (22) & ~0x3); | |
984 | ||
985 | inst0 = read_memory_integer (pc, 4); | |
986 | inst1 = read_memory_integer (pc+4, 4); | |
987 | ||
988 | if ( (inst0 & 0xffe00000) == 0x20200000 /* ldil xxx, r1 */ | |
989 | && (inst1 & 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */ | |
990 | pc = extract_21 (inst0) + extract_17 (inst1); | |
991 | else | |
992 | pc = (CORE_ADDR)NULL; | |
993 | ||
994 | return pc; | |
995 | } | |
996 | ||
997 | /* Advance PC across any function entry prologue instructions | |
998 | to reach some "real" code. */ | |
999 | ||
1000 | /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp) | |
1001 | for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */ | |
1002 | ||
1003 | CORE_ADDR | |
1004 | skip_prologue(pc) | |
1005 | CORE_ADDR pc; | |
1006 | { | |
34df79fc JK |
1007 | char buf[4]; |
1008 | unsigned long inst; | |
66a1aa07 SG |
1009 | int status; |
1010 | ||
34df79fc JK |
1011 | status = target_read_memory (pc, buf, 4); |
1012 | inst = extract_unsigned_integer (buf, 4); | |
66a1aa07 SG |
1013 | if (status != 0) |
1014 | return pc; | |
1015 | ||
1016 | if (inst == 0x6BC23FD9) /* stw rp,-20(sp) */ | |
1017 | { | |
1018 | if (read_memory_integer (pc + 4, 4) == 0x8040241) /* copy r4,r1 */ | |
1019 | pc += 16; | |
1020 | else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
1021 | pc += 8; | |
1022 | } | |
1023 | else if (read_memory_integer (pc, 4) == 0x8040241) /* copy r4,r1 */ | |
1024 | pc += 12; | |
1025 | else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
1026 | pc += 4; | |
1027 | ||
1028 | return pc; | |
1029 | } | |
1030 | ||
1031 | static void | |
1032 | unwind_command (exp, from_tty) | |
1033 | char *exp; | |
1034 | int from_tty; | |
1035 | { | |
1036 | CORE_ADDR address; | |
1037 | union | |
1038 | { | |
1039 | int *foo; | |
1040 | struct unwind_table_entry *u; | |
1041 | } xxx; | |
1042 | ||
1043 | /* If we have an expression, evaluate it and use it as the address. */ | |
1044 | ||
1045 | if (exp != 0 && *exp != 0) | |
1046 | address = parse_and_eval_address (exp); | |
1047 | else | |
1048 | return; | |
1049 | ||
1050 | xxx.u = find_unwind_entry (address); | |
1051 | ||
1052 | if (!xxx.u) | |
1053 | { | |
1054 | printf ("Can't find unwind table entry for PC 0x%x\n", address); | |
1055 | return; | |
1056 | } | |
1057 | ||
1058 | printf ("%08x\n%08X\n%08X\n%08X\n", xxx.foo[0], xxx.foo[1], xxx.foo[2], | |
1059 | xxx.foo[3]); | |
1060 | } | |
1061 | ||
1062 | void | |
47976ba7 | 1063 | _initialize_hppa_tdep () |
66a1aa07 SG |
1064 | { |
1065 | add_com ("unwind", class_obscure, unwind_command, "Print unwind info\n"); | |
1066 | add_show_from_set | |
1067 | (add_set_cmd ("use_unwind", class_obscure, var_boolean, | |
1068 | (char *)&use_unwind, | |
1069 | "Set the usage of unwind info", &setlist), | |
1070 | &showlist); | |
1071 | } |