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 | |
66a1aa07 SG |
245 | /* Lookup the unwind (stack backtrace) info for the given PC. We search all |
246 | of the objfiles seeking the unwind table entry for this PC. Each objfile | |
247 | contains a sorted list of struct unwind_table_entry. Since we do a binary | |
248 | search of the unwind tables, we depend upon them to be sorted. */ | |
249 | ||
250 | static struct unwind_table_entry * | |
251 | find_unwind_entry(pc) | |
252 | CORE_ADDR pc; | |
253 | { | |
254 | int first, middle, last; | |
255 | struct objfile *objfile; | |
256 | ||
257 | ALL_OBJFILES (objfile) | |
258 | { | |
259 | struct obj_unwind_info *ui; | |
260 | ||
261 | ui = OBJ_UNWIND_INFO (objfile); | |
262 | ||
263 | if (!ui) | |
264 | continue; | |
265 | ||
266 | /* First, check the cache */ | |
267 | ||
268 | if (ui->cache | |
269 | && pc >= ui->cache->region_start | |
270 | && pc <= ui->cache->region_end) | |
271 | return ui->cache; | |
272 | ||
273 | /* Not in the cache, do a binary search */ | |
274 | ||
275 | first = 0; | |
276 | last = ui->last; | |
277 | ||
278 | while (first <= last) | |
279 | { | |
280 | middle = (first + last) / 2; | |
281 | if (pc >= ui->table[middle].region_start | |
282 | && pc <= ui->table[middle].region_end) | |
283 | { | |
284 | ui->cache = &ui->table[middle]; | |
285 | return &ui->table[middle]; | |
286 | } | |
287 | ||
288 | if (pc < ui->table[middle].region_start) | |
289 | last = middle - 1; | |
290 | else | |
291 | first = middle + 1; | |
292 | } | |
293 | } /* ALL_OBJFILES() */ | |
294 | return NULL; | |
295 | } | |
296 | ||
5ac7f56e JK |
297 | /* Called when no unwind descriptor was found for PC. Returns 1 if it |
298 | appears that PC is in a linker stub. */ | |
299 | static int pc_in_linker_stub PARAMS ((CORE_ADDR)); | |
300 | ||
301 | static int | |
302 | pc_in_linker_stub (pc) | |
303 | CORE_ADDR pc; | |
304 | { | |
5ac7f56e JK |
305 | int found_magic_instruction = 0; |
306 | int i; | |
08ecd8f3 JK |
307 | char buf[4]; |
308 | ||
309 | /* If unable to read memory, assume pc is not in a linker stub. */ | |
310 | if (target_read_memory (pc, buf, 4) != 0) | |
311 | return 0; | |
5ac7f56e | 312 | |
d08c6f4c JK |
313 | /* We are looking for something like |
314 | ||
315 | ; $$dyncall jams RP into this special spot in the frame (RP') | |
316 | ; before calling the "call stub" | |
317 | ldw -18(sp),rp | |
318 | ||
319 | ldsid (rp),r1 ; Get space associated with RP into r1 | |
320 | mtsp r1,sp ; Move it into space register 0 | |
321 | be,n 0(sr0),rp) ; back to your regularly scheduled program | |
322 | */ | |
323 | ||
5ac7f56e JK |
324 | /* Maximum known linker stub size is 4 instructions. Search forward |
325 | from the given PC, then backward. */ | |
326 | for (i = 0; i < 4; i++) | |
327 | { | |
328 | /* If we hit something with an unwind, stop searching this direction. | |
329 | ||
330 | if (find_unwind_entry (pc + i * 4) != 0) | |
331 | break; | |
332 | ||
333 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
334 | return from a cross-space function call. */ | |
335 | if (read_memory_integer (pc + i * 4, 4) == 0x004010a1) | |
336 | { | |
337 | found_magic_instruction = 1; | |
338 | break; | |
339 | } | |
340 | /* Add code to handle long call/branch and argument relocation stubs | |
341 | here. */ | |
342 | } | |
343 | ||
344 | if (found_magic_instruction != 0) | |
345 | return 1; | |
346 | ||
347 | /* Now look backward. */ | |
348 | for (i = 0; i < 4; i++) | |
349 | { | |
350 | /* If we hit something with an unwind, stop searching this direction. | |
351 | ||
352 | if (find_unwind_entry (pc - i * 4) != 0) | |
353 | break; | |
354 | ||
355 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
356 | return from a cross-space function call. */ | |
357 | if (read_memory_integer (pc - i * 4, 4) == 0x004010a1) | |
358 | { | |
359 | found_magic_instruction = 1; | |
360 | break; | |
361 | } | |
362 | /* Add code to handle long call/branch and argument relocation stubs | |
363 | here. */ | |
364 | } | |
365 | return found_magic_instruction; | |
366 | } | |
367 | ||
66a1aa07 SG |
368 | static int |
369 | find_return_regnum(pc) | |
370 | CORE_ADDR pc; | |
371 | { | |
372 | struct unwind_table_entry *u; | |
373 | ||
374 | u = find_unwind_entry (pc); | |
375 | ||
376 | if (!u) | |
377 | return RP_REGNUM; | |
378 | ||
379 | if (u->Millicode) | |
380 | return 31; | |
381 | ||
382 | return RP_REGNUM; | |
383 | } | |
384 | ||
5ac7f56e | 385 | /* Return size of frame, or -1 if we should use a frame pointer. */ |
66a1aa07 SG |
386 | int |
387 | find_proc_framesize(pc) | |
388 | CORE_ADDR pc; | |
389 | { | |
390 | struct unwind_table_entry *u; | |
391 | ||
66a1aa07 SG |
392 | u = find_unwind_entry (pc); |
393 | ||
394 | if (!u) | |
5ac7f56e JK |
395 | { |
396 | if (pc_in_linker_stub (pc)) | |
397 | /* Linker stubs have a zero size frame. */ | |
398 | return 0; | |
399 | else | |
400 | return -1; | |
401 | } | |
66a1aa07 | 402 | |
eabbe766 JK |
403 | if (u->Save_SP) |
404 | /* If this bit is set, it means there is a frame pointer and we should | |
405 | use it. */ | |
406 | return -1; | |
407 | ||
66a1aa07 SG |
408 | return u->Total_frame_size << 3; |
409 | } | |
410 | ||
5ac7f56e JK |
411 | /* Return offset from sp at which rp is saved, or 0 if not saved. */ |
412 | static int rp_saved PARAMS ((CORE_ADDR)); | |
413 | ||
414 | static int | |
415 | rp_saved (pc) | |
416 | CORE_ADDR pc; | |
66a1aa07 SG |
417 | { |
418 | struct unwind_table_entry *u; | |
419 | ||
420 | u = find_unwind_entry (pc); | |
421 | ||
422 | if (!u) | |
5ac7f56e JK |
423 | { |
424 | if (pc_in_linker_stub (pc)) | |
425 | /* This is the so-called RP'. */ | |
426 | return -24; | |
427 | else | |
428 | return 0; | |
429 | } | |
66a1aa07 SG |
430 | |
431 | if (u->Save_RP) | |
5ac7f56e | 432 | return -20; |
66a1aa07 SG |
433 | else |
434 | return 0; | |
435 | } | |
436 | \f | |
8fa74880 SG |
437 | int |
438 | frameless_function_invocation (frame) | |
439 | FRAME frame; | |
440 | { | |
b8ec9a79 | 441 | struct unwind_table_entry *u; |
8fa74880 | 442 | |
b8ec9a79 | 443 | u = find_unwind_entry (frame->pc); |
8fa74880 | 444 | |
b8ec9a79 | 445 | if (u == 0) |
8fa74880 | 446 | return frameless_look_for_prologue (frame); |
b8ec9a79 JK |
447 | |
448 | return (u->Total_frame_size == 0); | |
8fa74880 SG |
449 | } |
450 | ||
66a1aa07 SG |
451 | CORE_ADDR |
452 | saved_pc_after_call (frame) | |
453 | FRAME frame; | |
454 | { | |
455 | int ret_regnum; | |
456 | ||
457 | ret_regnum = find_return_regnum (get_frame_pc (frame)); | |
458 | ||
459 | return read_register (ret_regnum) & ~0x3; | |
460 | } | |
461 | \f | |
462 | CORE_ADDR | |
463 | frame_saved_pc (frame) | |
464 | FRAME frame; | |
465 | { | |
466 | CORE_ADDR pc = get_frame_pc (frame); | |
467 | ||
8fa74880 | 468 | if (frameless_function_invocation (frame)) |
66a1aa07 SG |
469 | { |
470 | int ret_regnum; | |
471 | ||
472 | ret_regnum = find_return_regnum (pc); | |
473 | ||
474 | return read_register (ret_regnum) & ~0x3; | |
475 | } | |
66a1aa07 | 476 | else |
5ac7f56e JK |
477 | { |
478 | int rp_offset = rp_saved (pc); | |
479 | ||
480 | if (rp_offset == 0) | |
481 | return read_register (RP_REGNUM) & ~0x3; | |
482 | else | |
28403b8e | 483 | return read_memory_integer (frame->frame + rp_offset, 4) & ~0x3; |
5ac7f56e | 484 | } |
66a1aa07 SG |
485 | } |
486 | \f | |
487 | /* We need to correct the PC and the FP for the outermost frame when we are | |
488 | in a system call. */ | |
489 | ||
490 | void | |
491 | init_extra_frame_info (fromleaf, frame) | |
492 | int fromleaf; | |
493 | struct frame_info *frame; | |
494 | { | |
495 | int flags; | |
496 | int framesize; | |
497 | ||
498 | if (frame->next) /* Only do this for outermost frame */ | |
499 | return; | |
500 | ||
501 | flags = read_register (FLAGS_REGNUM); | |
502 | if (flags & 2) /* In system call? */ | |
503 | frame->pc = read_register (31) & ~0x3; | |
504 | ||
505 | /* The outermost frame is always derived from PC-framesize */ | |
506 | framesize = find_proc_framesize(frame->pc); | |
507 | if (framesize == -1) | |
508 | frame->frame = read_register (FP_REGNUM); | |
509 | else | |
510 | frame->frame = read_register (SP_REGNUM) - framesize; | |
511 | ||
8fa74880 | 512 | if (!frameless_function_invocation (frame)) /* Frameless? */ |
66a1aa07 SG |
513 | return; /* No, quit now */ |
514 | ||
515 | /* For frameless functions, we need to look at the caller's frame */ | |
516 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
517 | if (framesize != -1) | |
518 | frame->frame -= framesize; | |
519 | } | |
520 | \f | |
521 | FRAME_ADDR | |
522 | frame_chain (frame) | |
523 | struct frame_info *frame; | |
524 | { | |
525 | int framesize; | |
526 | ||
527 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
528 | ||
529 | if (framesize != -1) | |
530 | return frame->frame - framesize; | |
531 | ||
532 | return read_memory_integer (frame->frame, 4); | |
533 | } | |
534 | \f | |
535 | /* To see if a frame chain is valid, see if the caller looks like it | |
536 | was compiled with gcc. */ | |
537 | ||
538 | int | |
539 | frame_chain_valid (chain, thisframe) | |
540 | FRAME_ADDR chain; | |
541 | FRAME thisframe; | |
542 | { | |
543 | struct minimal_symbol *msym; | |
544 | ||
545 | if (!chain) | |
546 | return 0; | |
547 | ||
b8ec9a79 | 548 | struct unwind_table_entry *u; |
4b01383b | 549 | |
b8ec9a79 | 550 | u = find_unwind_entry (thisframe->pc); |
4b01383b | 551 | |
b8ec9a79 JK |
552 | msym = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe)); |
553 | if (msym | |
554 | && (strcmp (SYMBOL_NAME (msym), "_start") == 0)) | |
555 | return 0; | |
5ac7f56e | 556 | |
b8ec9a79 JK |
557 | if (u == NULL) |
558 | return 1; | |
5ac7f56e | 559 | |
b8ec9a79 JK |
560 | if (u->Save_SP || u->Total_frame_size) |
561 | return 1; | |
5ac7f56e | 562 | |
b8ec9a79 JK |
563 | if (pc_in_linker_stub (thisframe->pc)) |
564 | return 1; | |
4b01383b | 565 | |
b8ec9a79 | 566 | return 0; |
66a1aa07 SG |
567 | } |
568 | ||
66a1aa07 SG |
569 | /* |
570 | * These functions deal with saving and restoring register state | |
571 | * around a function call in the inferior. They keep the stack | |
572 | * double-word aligned; eventually, on an hp700, the stack will have | |
573 | * to be aligned to a 64-byte boundary. | |
574 | */ | |
575 | ||
576 | int | |
577 | push_dummy_frame () | |
578 | { | |
579 | register CORE_ADDR sp; | |
580 | register int regnum; | |
581 | int int_buffer; | |
582 | double freg_buffer; | |
583 | ||
584 | /* Space for "arguments"; the RP goes in here. */ | |
585 | sp = read_register (SP_REGNUM) + 48; | |
586 | int_buffer = read_register (RP_REGNUM) | 0x3; | |
587 | write_memory (sp - 20, (char *)&int_buffer, 4); | |
588 | ||
589 | int_buffer = read_register (FP_REGNUM); | |
590 | write_memory (sp, (char *)&int_buffer, 4); | |
591 | ||
592 | write_register (FP_REGNUM, sp); | |
593 | ||
594 | sp += 8; | |
595 | ||
596 | for (regnum = 1; regnum < 32; regnum++) | |
597 | if (regnum != RP_REGNUM && regnum != FP_REGNUM) | |
598 | sp = push_word (sp, read_register (regnum)); | |
599 | ||
600 | sp += 4; | |
601 | ||
602 | for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++) | |
603 | { | |
604 | read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); | |
605 | sp = push_bytes (sp, (char *)&freg_buffer, 8); | |
606 | } | |
607 | sp = push_word (sp, read_register (IPSW_REGNUM)); | |
608 | sp = push_word (sp, read_register (SAR_REGNUM)); | |
609 | sp = push_word (sp, read_register (PCOQ_HEAD_REGNUM)); | |
610 | sp = push_word (sp, read_register (PCSQ_HEAD_REGNUM)); | |
611 | sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM)); | |
612 | sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM)); | |
613 | write_register (SP_REGNUM, sp); | |
614 | } | |
615 | ||
616 | find_dummy_frame_regs (frame, frame_saved_regs) | |
617 | struct frame_info *frame; | |
618 | struct frame_saved_regs *frame_saved_regs; | |
619 | { | |
620 | CORE_ADDR fp = frame->frame; | |
621 | int i; | |
622 | ||
623 | frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3; | |
624 | frame_saved_regs->regs[FP_REGNUM] = fp; | |
625 | frame_saved_regs->regs[1] = fp + 8; | |
66a1aa07 | 626 | |
b227992a SG |
627 | for (fp += 12, i = 3; i < 32; i++) |
628 | { | |
629 | if (i != FP_REGNUM) | |
630 | { | |
631 | frame_saved_regs->regs[i] = fp; | |
632 | fp += 4; | |
633 | } | |
634 | } | |
66a1aa07 SG |
635 | |
636 | fp += 4; | |
637 | for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8) | |
638 | frame_saved_regs->regs[i] = fp; | |
639 | ||
640 | frame_saved_regs->regs[IPSW_REGNUM] = fp; | |
b227992a SG |
641 | frame_saved_regs->regs[SAR_REGNUM] = fp + 4; |
642 | frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp + 8; | |
643 | frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp + 12; | |
644 | frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp + 16; | |
645 | frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp + 20; | |
66a1aa07 SG |
646 | } |
647 | ||
648 | int | |
649 | hppa_pop_frame () | |
650 | { | |
651 | register FRAME frame = get_current_frame (); | |
652 | register CORE_ADDR fp; | |
653 | register int regnum; | |
654 | struct frame_saved_regs fsr; | |
655 | struct frame_info *fi; | |
656 | double freg_buffer; | |
657 | ||
658 | fi = get_frame_info (frame); | |
659 | fp = fi->frame; | |
660 | get_frame_saved_regs (fi, &fsr); | |
661 | ||
662 | if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */ | |
663 | restore_pc_queue (&fsr); | |
664 | ||
665 | for (regnum = 31; regnum > 0; regnum--) | |
666 | if (fsr.regs[regnum]) | |
667 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); | |
668 | ||
669 | for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--) | |
670 | if (fsr.regs[regnum]) | |
671 | { | |
672 | read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8); | |
673 | write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); | |
674 | } | |
675 | ||
676 | if (fsr.regs[IPSW_REGNUM]) | |
677 | write_register (IPSW_REGNUM, | |
678 | read_memory_integer (fsr.regs[IPSW_REGNUM], 4)); | |
679 | ||
680 | if (fsr.regs[SAR_REGNUM]) | |
681 | write_register (SAR_REGNUM, | |
682 | read_memory_integer (fsr.regs[SAR_REGNUM], 4)); | |
683 | ||
684 | if (fsr.regs[PCOQ_TAIL_REGNUM]) | |
685 | write_register (PCOQ_TAIL_REGNUM, | |
686 | read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4)); | |
687 | ||
688 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); | |
689 | ||
690 | if (fsr.regs[IPSW_REGNUM]) /* call dummy */ | |
691 | write_register (SP_REGNUM, fp - 48); | |
692 | else | |
693 | write_register (SP_REGNUM, fp); | |
694 | ||
695 | flush_cached_frames (); | |
696 | set_current_frame (create_new_frame (read_register (FP_REGNUM), | |
697 | read_pc ())); | |
698 | } | |
699 | ||
700 | /* | |
701 | * After returning to a dummy on the stack, restore the instruction | |
702 | * queue space registers. */ | |
703 | ||
704 | static int | |
705 | restore_pc_queue (fsr) | |
706 | struct frame_saved_regs *fsr; | |
707 | { | |
708 | CORE_ADDR pc = read_pc (); | |
709 | CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4); | |
710 | int pid; | |
711 | WAITTYPE w; | |
712 | int insn_count; | |
713 | ||
714 | /* Advance past break instruction in the call dummy. */ | |
715 | write_register (PCOQ_HEAD_REGNUM, pc + 4); | |
716 | write_register (PCOQ_TAIL_REGNUM, pc + 8); | |
717 | ||
718 | /* | |
719 | * HPUX doesn't let us set the space registers or the space | |
720 | * registers of the PC queue through ptrace. Boo, hiss. | |
721 | * Conveniently, the call dummy has this sequence of instructions | |
722 | * after the break: | |
723 | * mtsp r21, sr0 | |
724 | * ble,n 0(sr0, r22) | |
725 | * | |
726 | * So, load up the registers and single step until we are in the | |
727 | * right place. | |
728 | */ | |
729 | ||
730 | write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4)); | |
731 | write_register (22, new_pc); | |
732 | ||
733 | for (insn_count = 0; insn_count < 3; insn_count++) | |
734 | { | |
735 | resume (1, 0); | |
736 | target_wait(&w); | |
737 | ||
738 | if (!WIFSTOPPED (w)) | |
739 | { | |
740 | stop_signal = WTERMSIG (w); | |
741 | terminal_ours_for_output (); | |
742 | printf ("\nProgram terminated with signal %d, %s\n", | |
743 | stop_signal, safe_strsignal (stop_signal)); | |
744 | fflush (stdout); | |
745 | return 0; | |
746 | } | |
747 | } | |
748 | fetch_inferior_registers (-1); | |
749 | return 1; | |
750 | } | |
751 | ||
752 | CORE_ADDR | |
753 | hppa_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
754 | int nargs; | |
755 | value *args; | |
756 | CORE_ADDR sp; | |
757 | int struct_return; | |
758 | CORE_ADDR struct_addr; | |
759 | { | |
760 | /* array of arguments' offsets */ | |
1edc5cd2 | 761 | int *offset = (int *)alloca(nargs * sizeof (int)); |
66a1aa07 SG |
762 | int cum = 0; |
763 | int i, alignment; | |
764 | ||
765 | for (i = 0; i < nargs; i++) | |
766 | { | |
767 | /* Coerce chars to int & float to double if necessary */ | |
768 | args[i] = value_arg_coerce (args[i]); | |
769 | ||
770 | cum += TYPE_LENGTH (VALUE_TYPE (args[i])); | |
771 | ||
772 | /* value must go at proper alignment. Assume alignment is a | |
773 | power of two.*/ | |
774 | alignment = hppa_alignof (VALUE_TYPE (args[i])); | |
775 | if (cum % alignment) | |
776 | cum = (cum + alignment) & -alignment; | |
777 | offset[i] = -cum; | |
778 | } | |
558f4183 | 779 | sp += max ((cum + 7) & -8, 16); |
66a1aa07 SG |
780 | |
781 | for (i = 0; i < nargs; i++) | |
782 | write_memory (sp + offset[i], VALUE_CONTENTS (args[i]), | |
783 | TYPE_LENGTH (VALUE_TYPE (args[i]))); | |
784 | ||
785 | if (struct_return) | |
786 | write_register (28, struct_addr); | |
787 | return sp + 32; | |
788 | } | |
789 | ||
790 | /* | |
791 | * Insert the specified number of args and function address | |
792 | * into a call sequence of the above form stored at DUMMYNAME. | |
793 | * | |
794 | * On the hppa we need to call the stack dummy through $$dyncall. | |
795 | * Therefore our version of FIX_CALL_DUMMY takes an extra argument, | |
796 | * real_pc, which is the location where gdb should start up the | |
797 | * inferior to do the function call. | |
798 | */ | |
799 | ||
800 | CORE_ADDR | |
801 | hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p) | |
802 | REGISTER_TYPE *dummy; | |
803 | CORE_ADDR pc; | |
804 | CORE_ADDR fun; | |
805 | int nargs; | |
806 | value *args; | |
807 | struct type *type; | |
808 | int gcc_p; | |
809 | { | |
810 | CORE_ADDR dyncall_addr, sr4export_addr; | |
811 | struct minimal_symbol *msymbol; | |
812 | ||
813 | msymbol = lookup_minimal_symbol ("$$dyncall", (struct objfile *) NULL); | |
814 | if (msymbol == NULL) | |
815 | error ("Can't find an address for $$dyncall trampoline"); | |
816 | ||
817 | dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
818 | ||
819 | msymbol = lookup_minimal_symbol ("_sr4export", (struct objfile *) NULL); | |
820 | if (msymbol == NULL) | |
821 | error ("Can't find an address for _sr4export trampoline"); | |
822 | ||
823 | sr4export_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
824 | ||
825 | dummy[9] = deposit_21 (fun >> 11, dummy[9]); | |
826 | dummy[10] = deposit_14 (fun & MASK_11, dummy[10]); | |
827 | dummy[12] = deposit_21 (sr4export_addr >> 11, dummy[12]); | |
828 | dummy[13] = deposit_14 (sr4export_addr & MASK_11, dummy[13]); | |
829 | ||
830 | write_register (22, pc); | |
831 | ||
832 | return dyncall_addr; | |
833 | } | |
834 | ||
835 | /* return the alignment of a type in bytes. Structures have the maximum | |
836 | alignment required by their fields. */ | |
837 | ||
838 | static int | |
839 | hppa_alignof (arg) | |
840 | struct type *arg; | |
841 | { | |
842 | int max_align, align, i; | |
843 | switch (TYPE_CODE (arg)) | |
844 | { | |
845 | case TYPE_CODE_PTR: | |
846 | case TYPE_CODE_INT: | |
847 | case TYPE_CODE_FLT: | |
848 | return TYPE_LENGTH (arg); | |
849 | case TYPE_CODE_ARRAY: | |
850 | return hppa_alignof (TYPE_FIELD_TYPE (arg, 0)); | |
851 | case TYPE_CODE_STRUCT: | |
852 | case TYPE_CODE_UNION: | |
853 | max_align = 2; | |
854 | for (i = 0; i < TYPE_NFIELDS (arg); i++) | |
855 | { | |
856 | /* Bit fields have no real alignment. */ | |
857 | if (!TYPE_FIELD_BITPOS (arg, i)) | |
858 | { | |
859 | align = hppa_alignof (TYPE_FIELD_TYPE (arg, i)); | |
860 | max_align = max (max_align, align); | |
861 | } | |
862 | } | |
863 | return max_align; | |
864 | default: | |
865 | return 4; | |
866 | } | |
867 | } | |
868 | ||
869 | /* Print the register regnum, or all registers if regnum is -1 */ | |
870 | ||
871 | pa_do_registers_info (regnum, fpregs) | |
872 | int regnum; | |
873 | int fpregs; | |
874 | { | |
875 | char raw_regs [REGISTER_BYTES]; | |
876 | int i; | |
877 | ||
878 | for (i = 0; i < NUM_REGS; i++) | |
879 | read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i)); | |
880 | if (regnum == -1) | |
881 | pa_print_registers (raw_regs, regnum, fpregs); | |
882 | else if (regnum < FP0_REGNUM) | |
883 | printf ("%s %x\n", reg_names[regnum], *(long *)(raw_regs + | |
884 | REGISTER_BYTE (regnum))); | |
885 | else | |
886 | pa_print_fp_reg (regnum); | |
887 | } | |
888 | ||
889 | pa_print_registers (raw_regs, regnum, fpregs) | |
890 | char *raw_regs; | |
891 | int regnum; | |
892 | int fpregs; | |
893 | { | |
894 | int i; | |
895 | ||
896 | for (i = 0; i < 18; i++) | |
897 | printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n", | |
898 | reg_names[i], | |
899 | *(int *)(raw_regs + REGISTER_BYTE (i)), | |
900 | reg_names[i + 18], | |
901 | *(int *)(raw_regs + REGISTER_BYTE (i + 18)), | |
902 | reg_names[i + 36], | |
903 | *(int *)(raw_regs + REGISTER_BYTE (i + 36)), | |
904 | reg_names[i + 54], | |
905 | *(int *)(raw_regs + REGISTER_BYTE (i + 54))); | |
906 | ||
907 | if (fpregs) | |
908 | for (i = 72; i < NUM_REGS; i++) | |
909 | pa_print_fp_reg (i); | |
910 | } | |
911 | ||
912 | pa_print_fp_reg (i) | |
913 | int i; | |
914 | { | |
915 | unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
916 | unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
917 | REGISTER_TYPE val; | |
918 | ||
919 | /* Get the data in raw format, then convert also to virtual format. */ | |
920 | read_relative_register_raw_bytes (i, raw_buffer); | |
921 | REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer); | |
922 | ||
923 | fputs_filtered (reg_names[i], stdout); | |
924 | print_spaces_filtered (15 - strlen (reg_names[i]), stdout); | |
925 | ||
926 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0, | |
927 | 1, 0, Val_pretty_default); | |
928 | printf_filtered ("\n"); | |
929 | } | |
930 | ||
931 | /* Function calls that pass into a new compilation unit must pass through a | |
932 | small piece of code that does long format (`external' in HPPA parlance) | |
933 | jumps. We figure out where the trampoline is going to end up, and return | |
934 | the PC of the final destination. If we aren't in a trampoline, we just | |
935 | return NULL. | |
936 | ||
937 | For computed calls, we just extract the new PC from r22. */ | |
938 | ||
939 | CORE_ADDR | |
940 | skip_trampoline_code (pc, name) | |
941 | CORE_ADDR pc; | |
942 | char *name; | |
943 | { | |
944 | long inst0, inst1; | |
945 | static CORE_ADDR dyncall = 0; | |
946 | struct minimal_symbol *msym; | |
947 | ||
948 | /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */ | |
949 | ||
950 | if (!dyncall) | |
951 | { | |
952 | msym = lookup_minimal_symbol ("$$dyncall", NULL); | |
953 | if (msym) | |
954 | dyncall = SYMBOL_VALUE_ADDRESS (msym); | |
955 | else | |
956 | dyncall = -1; | |
957 | } | |
958 | ||
959 | if (pc == dyncall) | |
960 | return (CORE_ADDR)(read_register (22) & ~0x3); | |
961 | ||
962 | inst0 = read_memory_integer (pc, 4); | |
963 | inst1 = read_memory_integer (pc+4, 4); | |
964 | ||
965 | if ( (inst0 & 0xffe00000) == 0x20200000 /* ldil xxx, r1 */ | |
966 | && (inst1 & 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */ | |
967 | pc = extract_21 (inst0) + extract_17 (inst1); | |
968 | else | |
969 | pc = (CORE_ADDR)NULL; | |
970 | ||
971 | return pc; | |
972 | } | |
973 | ||
974 | /* Advance PC across any function entry prologue instructions | |
975 | to reach some "real" code. */ | |
976 | ||
977 | /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp) | |
978 | for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */ | |
979 | ||
980 | CORE_ADDR | |
981 | skip_prologue(pc) | |
982 | CORE_ADDR pc; | |
983 | { | |
34df79fc JK |
984 | char buf[4]; |
985 | unsigned long inst; | |
66a1aa07 SG |
986 | int status; |
987 | ||
34df79fc JK |
988 | status = target_read_memory (pc, buf, 4); |
989 | inst = extract_unsigned_integer (buf, 4); | |
66a1aa07 SG |
990 | if (status != 0) |
991 | return pc; | |
992 | ||
993 | if (inst == 0x6BC23FD9) /* stw rp,-20(sp) */ | |
994 | { | |
995 | if (read_memory_integer (pc + 4, 4) == 0x8040241) /* copy r4,r1 */ | |
996 | pc += 16; | |
997 | else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
998 | pc += 8; | |
999 | } | |
1000 | else if (read_memory_integer (pc, 4) == 0x8040241) /* copy r4,r1 */ | |
1001 | pc += 12; | |
1002 | else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
1003 | pc += 4; | |
1004 | ||
1005 | return pc; | |
1006 | } | |
1007 | ||
1008 | static void | |
1009 | unwind_command (exp, from_tty) | |
1010 | char *exp; | |
1011 | int from_tty; | |
1012 | { | |
1013 | CORE_ADDR address; | |
1014 | union | |
1015 | { | |
1016 | int *foo; | |
1017 | struct unwind_table_entry *u; | |
1018 | } xxx; | |
1019 | ||
1020 | /* If we have an expression, evaluate it and use it as the address. */ | |
1021 | ||
1022 | if (exp != 0 && *exp != 0) | |
1023 | address = parse_and_eval_address (exp); | |
1024 | else | |
1025 | return; | |
1026 | ||
1027 | xxx.u = find_unwind_entry (address); | |
1028 | ||
1029 | if (!xxx.u) | |
1030 | { | |
1031 | printf ("Can't find unwind table entry for PC 0x%x\n", address); | |
1032 | return; | |
1033 | } | |
1034 | ||
1035 | printf ("%08x\n%08X\n%08X\n%08X\n", xxx.foo[0], xxx.foo[1], xxx.foo[2], | |
1036 | xxx.foo[3]); | |
1037 | } |