]>
Commit | Line | Data |
---|---|---|
fb1415ae JG |
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 Free Software Foundation, Inc. | |
4 | ||
5 | Contributed by the Center for Software Science at the | |
6 | University of Utah ([email protected]). | |
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> | |
fb1415ae | 53 | #include <machine/psl.h> |
9f739abd | 54 | #include "wait.h" |
fb1415ae JG |
55 | |
56 | #include "gdbcore.h" | |
57 | #include "gdbcmd.h" | |
9f739abd | 58 | #include "target.h" |
fa9265e5 SG |
59 | #include "symfile.h" |
60 | #include "objfiles.h" | |
fb1415ae | 61 | |
fb1415ae | 62 | \f |
fb1415ae JG |
63 | /* Routines to extract various sized constants out of hppa |
64 | instructions. */ | |
65 | ||
66 | /* This assumes that no garbage lies outside of the lower bits of | |
67 | value. */ | |
68 | ||
69 | int | |
70 | sign_extend (val, bits) | |
71 | unsigned val, bits; | |
72 | { | |
73 | return (int)(val >> bits - 1 ? (-1 << bits) | val : val); | |
74 | } | |
75 | ||
76 | /* For many immediate values the sign bit is the low bit! */ | |
77 | ||
78 | int | |
79 | low_sign_extend (val, bits) | |
80 | unsigned val, bits; | |
81 | { | |
82 | return (int)((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1); | |
83 | } | |
84 | /* extract the immediate field from a ld{bhw}s instruction */ | |
85 | ||
fb1415ae JG |
86 | unsigned |
87 | get_field (val, from, to) | |
88 | unsigned val, from, to; | |
89 | { | |
90 | val = val >> 31 - to; | |
91 | return val & ((1 << 32 - from) - 1); | |
92 | } | |
93 | ||
94 | unsigned | |
95 | set_field (val, from, to, new_val) | |
96 | unsigned *val, from, to; | |
97 | { | |
98 | unsigned mask = ~((1 << (to - from + 1)) << (31 - from)); | |
99 | return *val = *val & mask | (new_val << (31 - from)); | |
100 | } | |
101 | ||
102 | /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */ | |
103 | ||
104 | extract_3 (word) | |
105 | unsigned word; | |
106 | { | |
107 | return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17); | |
108 | } | |
109 | ||
110 | extract_5_load (word) | |
111 | unsigned word; | |
112 | { | |
113 | return low_sign_extend (word >> 16 & MASK_5, 5); | |
114 | } | |
115 | ||
116 | /* extract the immediate field from a st{bhw}s instruction */ | |
117 | ||
118 | int | |
119 | extract_5_store (word) | |
120 | unsigned word; | |
121 | { | |
122 | return low_sign_extend (word & MASK_5, 5); | |
123 | } | |
124 | ||
125 | /* extract an 11 bit immediate field */ | |
126 | ||
127 | int | |
128 | extract_11 (word) | |
129 | unsigned word; | |
130 | { | |
131 | return low_sign_extend (word & MASK_11, 11); | |
132 | } | |
133 | ||
134 | /* extract a 14 bit immediate field */ | |
135 | ||
136 | int | |
137 | extract_14 (word) | |
138 | unsigned word; | |
139 | { | |
140 | return low_sign_extend (word & MASK_14, 14); | |
141 | } | |
142 | ||
143 | /* deposit a 14 bit constant in a word */ | |
144 | ||
145 | unsigned | |
146 | deposit_14 (opnd, word) | |
147 | int opnd; | |
148 | unsigned word; | |
149 | { | |
150 | unsigned sign = (opnd < 0 ? 1 : 0); | |
151 | ||
152 | return word | ((unsigned)opnd << 1 & MASK_14) | sign; | |
153 | } | |
154 | ||
155 | /* extract a 21 bit constant */ | |
156 | ||
157 | int | |
158 | extract_21 (word) | |
159 | unsigned word; | |
160 | { | |
161 | int val; | |
162 | ||
163 | word &= MASK_21; | |
164 | word <<= 11; | |
165 | val = GET_FIELD (word, 20, 20); | |
166 | val <<= 11; | |
167 | val |= GET_FIELD (word, 9, 19); | |
168 | val <<= 2; | |
169 | val |= GET_FIELD (word, 5, 6); | |
170 | val <<= 5; | |
171 | val |= GET_FIELD (word, 0, 4); | |
172 | val <<= 2; | |
173 | val |= GET_FIELD (word, 7, 8); | |
174 | return sign_extend (val, 21) << 11; | |
175 | } | |
176 | ||
177 | /* deposit a 21 bit constant in a word. Although 21 bit constants are | |
178 | usually the top 21 bits of a 32 bit constant, we assume that only | |
179 | the low 21 bits of opnd are relevant */ | |
180 | ||
181 | unsigned | |
182 | deposit_21 (opnd, word) | |
183 | unsigned opnd, word; | |
184 | { | |
185 | unsigned val = 0; | |
186 | ||
187 | val |= GET_FIELD (opnd, 11 + 14, 11 + 18); | |
188 | val <<= 2; | |
189 | val |= GET_FIELD (opnd, 11 + 12, 11 + 13); | |
190 | val <<= 2; | |
191 | val |= GET_FIELD (opnd, 11 + 19, 11 + 20); | |
192 | val <<= 11; | |
193 | val |= GET_FIELD (opnd, 11 + 1, 11 + 11); | |
194 | val <<= 1; | |
195 | val |= GET_FIELD (opnd, 11 + 0, 11 + 0); | |
196 | return word | val; | |
197 | } | |
198 | ||
199 | /* extract a 12 bit constant from branch instructions */ | |
200 | ||
201 | int | |
202 | extract_12 (word) | |
203 | unsigned word; | |
204 | { | |
205 | return sign_extend (GET_FIELD (word, 19, 28) | | |
206 | GET_FIELD (word, 29, 29) << 10 | | |
207 | (word & 0x1) << 11, 12) << 2; | |
208 | } | |
209 | ||
210 | /* extract a 17 bit constant from branch instructions, returning the | |
211 | 19 bit signed value. */ | |
212 | ||
213 | int | |
214 | extract_17 (word) | |
215 | unsigned word; | |
216 | { | |
217 | return sign_extend (GET_FIELD (word, 19, 28) | | |
218 | GET_FIELD (word, 29, 29) << 10 | | |
219 | GET_FIELD (word, 11, 15) << 11 | | |
220 | (word & 0x1) << 16, 17) << 2; | |
221 | } | |
9f739abd | 222 | \f |
fa9265e5 SG |
223 | static int use_unwind = 0; |
224 | ||
225 | /* Lookup the unwind (stack backtrace) info for the given PC. We search all | |
226 | of the objfiles seeking the unwind table entry for this PC. Each objfile | |
227 | contains a sorted list of struct unwind_table_entry. Since we do a binary | |
228 | search of the unwind tables, we depend upon them to be sorted. */ | |
b5c10493 SG |
229 | |
230 | static struct unwind_table_entry * | |
231 | find_unwind_entry(pc) | |
232 | CORE_ADDR pc; | |
233 | { | |
0213d96f | 234 | int first, middle, last; |
fa9265e5 | 235 | struct objfile *objfile; |
b5c10493 | 236 | |
fa9265e5 | 237 | ALL_OBJFILES (objfile) |
b5c10493 | 238 | { |
fa9265e5 | 239 | struct obj_unwind_info *ui; |
b5c10493 | 240 | |
fa9265e5 | 241 | ui = OBJ_UNWIND_INFO (objfile); |
b5c10493 | 242 | |
fa9265e5 SG |
243 | if (!ui) |
244 | continue; | |
b5c10493 | 245 | |
fa9265e5 | 246 | /* First, check the cache */ |
b5c10493 | 247 | |
fa9265e5 SG |
248 | if (ui->cache |
249 | && pc >= ui->cache->region_start | |
250 | && pc <= ui->cache->region_end) | |
251 | return ui->cache; | |
0213d96f | 252 | |
fa9265e5 | 253 | /* Not in the cache, do a binary search */ |
0213d96f | 254 | |
fa9265e5 SG |
255 | first = 0; |
256 | last = ui->last; | |
0213d96f | 257 | |
fa9265e5 SG |
258 | while (first <= last) |
259 | { | |
260 | middle = (first + last) / 2; | |
261 | if (pc >= ui->table[middle].region_start | |
262 | && pc <= ui->table[middle].region_end) | |
263 | { | |
264 | ui->cache = &ui->table[middle]; | |
265 | return &ui->table[middle]; | |
266 | } | |
267 | ||
268 | if (pc < ui->table[middle].region_start) | |
269 | last = middle - 1; | |
270 | else | |
271 | first = middle + 1; | |
272 | } | |
273 | } /* ALL_OBJFILES() */ | |
274 | return NULL; | |
b5c10493 SG |
275 | } |
276 | ||
277 | static int | |
278 | find_return_regnum(pc) | |
279 | CORE_ADDR pc; | |
280 | { | |
281 | struct unwind_table_entry *u; | |
282 | ||
283 | u = find_unwind_entry (pc); | |
284 | ||
285 | if (!u) | |
286 | return RP_REGNUM; | |
287 | ||
288 | if (u->Millicode) | |
289 | return 31; | |
290 | ||
291 | return RP_REGNUM; | |
292 | } | |
293 | ||
294 | int | |
295 | find_proc_framesize(pc) | |
296 | CORE_ADDR pc; | |
297 | { | |
298 | struct unwind_table_entry *u; | |
299 | ||
0213d96f SG |
300 | if (!use_unwind) |
301 | return -1; | |
302 | ||
b5c10493 SG |
303 | u = find_unwind_entry (pc); |
304 | ||
305 | if (!u) | |
306 | return -1; | |
307 | ||
308 | return u->Total_frame_size << 3; | |
309 | } | |
0213d96f SG |
310 | |
311 | int | |
312 | rp_saved(pc) | |
313 | { | |
314 | struct unwind_table_entry *u; | |
315 | ||
316 | u = find_unwind_entry (pc); | |
317 | ||
318 | if (!u) | |
319 | return 0; | |
320 | ||
321 | if (u->Save_RP) | |
322 | return 1; | |
323 | else | |
324 | return 0; | |
325 | } | |
b5c10493 SG |
326 | \f |
327 | CORE_ADDR | |
328 | saved_pc_after_call (frame) | |
329 | FRAME frame; | |
330 | { | |
331 | int ret_regnum; | |
332 | ||
333 | ret_regnum = find_return_regnum (get_frame_pc (frame)); | |
334 | ||
335 | return read_register (ret_regnum) & ~0x3; | |
336 | } | |
337 | \f | |
fb1415ae JG |
338 | CORE_ADDR |
339 | frame_saved_pc (frame) | |
340 | FRAME frame; | |
341 | { | |
0213d96f SG |
342 | CORE_ADDR pc = get_frame_pc (frame); |
343 | ||
344 | if (frameless_look_for_prologue (frame)) | |
fb1415ae | 345 | { |
b5c10493 SG |
346 | int ret_regnum; |
347 | ||
348 | ret_regnum = find_return_regnum (pc); | |
349 | ||
350 | return read_register (ret_regnum) & ~0x3; | |
fb1415ae | 351 | } |
0213d96f SG |
352 | else if (rp_saved (pc)) |
353 | return read_memory_integer (frame->frame - 20, 4) & ~0x3; | |
354 | else | |
355 | return read_register (RP_REGNUM) & ~0x3; | |
fb1415ae | 356 | } |
b5c10493 SG |
357 | \f |
358 | /* We need to correct the PC and the FP for the outermost frame when we are | |
359 | in a system call. */ | |
360 | ||
361 | void | |
362 | init_extra_frame_info (fromleaf, frame) | |
363 | int fromleaf; | |
364 | struct frame_info *frame; | |
365 | { | |
366 | int flags; | |
367 | int framesize; | |
368 | ||
369 | if (frame->next) /* Only do this for outermost frame */ | |
370 | return; | |
fb1415ae | 371 | |
b5c10493 SG |
372 | flags = read_register (FLAGS_REGNUM); |
373 | if (flags & 2) /* In system call? */ | |
374 | frame->pc = read_register (31) & ~0x3; | |
375 | ||
376 | /* The outermost frame is always derived from PC-framesize */ | |
377 | framesize = find_proc_framesize(frame->pc); | |
378 | if (framesize == -1) | |
379 | frame->frame = read_register (FP_REGNUM); | |
380 | else | |
381 | frame->frame = read_register (SP_REGNUM) - framesize; | |
382 | ||
0213d96f SG |
383 | if (!frameless_look_for_prologue (frame)) /* Frameless? */ |
384 | return; /* No, quit now */ | |
b5c10493 SG |
385 | |
386 | /* For frameless functions, we need to look at the caller's frame */ | |
387 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
388 | if (framesize != -1) | |
389 | frame->frame -= framesize; | |
390 | } | |
391 | \f | |
392 | FRAME_ADDR | |
393 | frame_chain (frame) | |
394 | struct frame_info *frame; | |
395 | { | |
396 | int framesize; | |
397 | ||
398 | framesize = find_proc_framesize(FRAME_SAVED_PC(frame)); | |
399 | ||
400 | if (framesize != -1) | |
401 | return frame->frame - framesize; | |
402 | ||
403 | return read_memory_integer (frame->frame, 4); | |
404 | } | |
405 | \f | |
fb1415ae JG |
406 | /* To see if a frame chain is valid, see if the caller looks like it |
407 | was compiled with gcc. */ | |
408 | ||
0213d96f SG |
409 | int |
410 | frame_chain_valid (chain, thisframe) | |
fb1415ae JG |
411 | FRAME_ADDR chain; |
412 | FRAME thisframe; | |
413 | { | |
0213d96f SG |
414 | struct minimal_symbol *msym; |
415 | ||
416 | if (!chain) | |
fb1415ae | 417 | return 0; |
0213d96f SG |
418 | |
419 | msym = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe)); | |
420 | ||
421 | if (msym | |
422 | && (strcmp (SYMBOL_NAME (msym), "_start") == 0)) | |
423 | return 0; | |
424 | else | |
425 | return 1; | |
fb1415ae JG |
426 | } |
427 | ||
0213d96f | 428 | #if 0 |
fb1415ae JG |
429 | /* Some helper functions. gcc_p returns 1 if the function beginning at |
430 | pc appears to have been compiled with gcc. hpux_cc_p returns 1 if | |
431 | fn was compiled with hpux cc. gcc functions look like : | |
432 | ||
433 | stw rp,-0x14(sp) ; optional | |
434 | or r4,r0,r1 | |
435 | or sp,r0,r4 | |
436 | stwm r1,framesize(sp) | |
437 | ||
438 | hpux cc functions look like: | |
439 | ||
440 | stw rp,-0x14(sp) ; optional. | |
441 | stwm r3,framesiz(sp) | |
442 | */ | |
443 | ||
444 | gcc_p (pc) | |
445 | CORE_ADDR pc; | |
446 | { | |
447 | if (read_memory_integer (pc, 4) == 0x6BC23FD9) | |
448 | pc = pc + 4; | |
449 | ||
0213d96f SG |
450 | if (read_memory_integer (pc, 4) == 0x8040241 |
451 | && read_memory_integer (pc + 4, 4) == 0x81E0244) | |
fb1415ae JG |
452 | return 1; |
453 | return 0; | |
454 | } | |
0213d96f | 455 | #endif |
fb1415ae | 456 | |
9f739abd SG |
457 | /* |
458 | * These functions deal with saving and restoring register state | |
459 | * around a function call in the inferior. They keep the stack | |
460 | * double-word aligned; eventually, on an hp700, the stack will have | |
461 | * to be aligned to a 64-byte boundary. | |
462 | */ | |
463 | ||
464 | int | |
465 | push_dummy_frame () | |
466 | { | |
0213d96f | 467 | register CORE_ADDR sp; |
9f739abd SG |
468 | register int regnum; |
469 | int int_buffer; | |
470 | double freg_buffer; | |
0213d96f | 471 | |
9f739abd | 472 | /* Space for "arguments"; the RP goes in here. */ |
0213d96f | 473 | sp = read_register (SP_REGNUM) + 48; |
9f739abd SG |
474 | int_buffer = read_register (RP_REGNUM) | 0x3; |
475 | write_memory (sp - 20, (char *)&int_buffer, 4); | |
0213d96f | 476 | |
9f739abd SG |
477 | int_buffer = read_register (FP_REGNUM); |
478 | write_memory (sp, (char *)&int_buffer, 4); | |
0213d96f | 479 | |
9f739abd | 480 | write_register (FP_REGNUM, sp); |
0213d96f | 481 | |
9f739abd | 482 | sp += 8; |
0213d96f | 483 | |
9f739abd SG |
484 | for (regnum = 1; regnum < 32; regnum++) |
485 | if (regnum != RP_REGNUM && regnum != FP_REGNUM) | |
486 | sp = push_word (sp, read_register (regnum)); | |
0213d96f | 487 | |
9f739abd | 488 | sp += 4; |
0213d96f | 489 | |
9f739abd | 490 | for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++) |
0213d96f SG |
491 | { |
492 | read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); | |
493 | sp = push_bytes (sp, (char *)&freg_buffer, 8); | |
494 | } | |
9f739abd SG |
495 | sp = push_word (sp, read_register (IPSW_REGNUM)); |
496 | sp = push_word (sp, read_register (SAR_REGNUM)); | |
497 | sp = push_word (sp, read_register (PCOQ_HEAD_REGNUM)); | |
498 | sp = push_word (sp, read_register (PCSQ_HEAD_REGNUM)); | |
499 | sp = push_word (sp, read_register (PCOQ_TAIL_REGNUM)); | |
500 | sp = push_word (sp, read_register (PCSQ_TAIL_REGNUM)); | |
501 | write_register (SP_REGNUM, sp); | |
502 | } | |
503 | ||
fb1415ae JG |
504 | find_dummy_frame_regs (frame, frame_saved_regs) |
505 | struct frame_info *frame; | |
506 | struct frame_saved_regs *frame_saved_regs; | |
507 | { | |
508 | CORE_ADDR fp = frame->frame; | |
509 | int i; | |
9f739abd | 510 | |
fb1415ae JG |
511 | frame_saved_regs->regs[RP_REGNUM] = fp - 20 & ~0x3; |
512 | frame_saved_regs->regs[FP_REGNUM] = fp; | |
513 | frame_saved_regs->regs[1] = fp + 8; | |
514 | frame_saved_regs->regs[3] = fp + 12; | |
0213d96f | 515 | |
9f739abd | 516 | for (fp += 16, i = 5; i < 32; fp += 4, i++) |
fb1415ae | 517 | frame_saved_regs->regs[i] = fp; |
0213d96f | 518 | |
fb1415ae JG |
519 | fp += 4; |
520 | for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8) | |
521 | frame_saved_regs->regs[i] = fp; | |
0213d96f SG |
522 | |
523 | frame_saved_regs->regs[IPSW_REGNUM] = fp; | |
524 | fp += 4; | |
525 | frame_saved_regs->regs[SAR_REGNUM] = fp; | |
526 | fp += 4; | |
527 | frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp; | |
528 | fp +=4; | |
529 | frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp; | |
530 | fp +=4; | |
531 | frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp; | |
532 | fp +=4; | |
fb1415ae JG |
533 | frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp; |
534 | } | |
535 | ||
9f739abd SG |
536 | int |
537 | hp_pop_frame () | |
538 | { | |
539 | register FRAME frame = get_current_frame (); | |
540 | register CORE_ADDR fp; | |
541 | register int regnum; | |
542 | struct frame_saved_regs fsr; | |
543 | struct frame_info *fi; | |
544 | double freg_buffer; | |
0213d96f | 545 | |
9f739abd SG |
546 | fi = get_frame_info (frame); |
547 | fp = fi->frame; | |
548 | get_frame_saved_regs (fi, &fsr); | |
0213d96f | 549 | |
9f739abd SG |
550 | if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */ |
551 | hp_restore_pc_queue (&fsr); | |
0213d96f | 552 | |
9f739abd SG |
553 | for (regnum = 31; regnum > 0; regnum--) |
554 | if (fsr.regs[regnum]) | |
555 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); | |
0213d96f | 556 | |
9f739abd SG |
557 | for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--) |
558 | if (fsr.regs[regnum]) | |
0213d96f SG |
559 | { |
560 | read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8); | |
9f739abd SG |
561 | write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8); |
562 | } | |
0213d96f | 563 | |
9f739abd SG |
564 | if (fsr.regs[IPSW_REGNUM]) |
565 | write_register (IPSW_REGNUM, | |
566 | read_memory_integer (fsr.regs[IPSW_REGNUM], 4)); | |
0213d96f | 567 | |
9f739abd SG |
568 | if (fsr.regs[SAR_REGNUM]) |
569 | write_register (SAR_REGNUM, | |
570 | read_memory_integer (fsr.regs[SAR_REGNUM], 4)); | |
0213d96f | 571 | |
9f739abd SG |
572 | if (fsr.regs[PCOQ_TAIL_REGNUM]) |
573 | write_register (PCOQ_TAIL_REGNUM, | |
574 | read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4)); | |
0213d96f | 575 | |
9f739abd | 576 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); |
0213d96f | 577 | |
9f739abd SG |
578 | if (fsr.regs[IPSW_REGNUM]) /* call dummy */ |
579 | write_register (SP_REGNUM, fp - 48); | |
580 | else | |
581 | write_register (SP_REGNUM, fp); | |
0213d96f | 582 | |
9f739abd SG |
583 | flush_cached_frames (); |
584 | set_current_frame (create_new_frame (read_register (FP_REGNUM), | |
585 | read_pc ())); | |
586 | } | |
587 | ||
588 | /* | |
589 | * After returning to a dummy on the stack, restore the instruction | |
590 | * queue space registers. */ | |
591 | ||
592 | int | |
593 | hp_restore_pc_queue (fsr) | |
594 | struct frame_saved_regs *fsr; | |
595 | { | |
596 | CORE_ADDR pc = read_pc (); | |
597 | CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4); | |
598 | int pid; | |
599 | WAITTYPE w; | |
600 | int insn_count; | |
601 | ||
602 | /* Advance past break instruction in the call dummy. */ | |
0213d96f SG |
603 | write_register (PCOQ_HEAD_REGNUM, pc + 4); |
604 | write_register (PCOQ_TAIL_REGNUM, pc + 8); | |
9f739abd SG |
605 | |
606 | /* | |
607 | * HPUX doesn't let us set the space registers or the space | |
608 | * registers of the PC queue through ptrace. Boo, hiss. | |
609 | * Conveniently, the call dummy has this sequence of instructions | |
610 | * after the break: | |
611 | * mtsp r21, sr0 | |
612 | * ble,n 0(sr0, r22) | |
613 | * | |
614 | * So, load up the registers and single step until we are in the | |
615 | * right place. | |
616 | */ | |
617 | ||
618 | write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4)); | |
619 | write_register (22, new_pc); | |
620 | ||
621 | for (insn_count = 0; insn_count < 3; insn_count++) | |
622 | { | |
623 | resume (1, 0); | |
624 | target_wait(&w); | |
625 | ||
626 | if (!WIFSTOPPED (w)) | |
627 | { | |
628 | stop_signal = WTERMSIG (w); | |
629 | terminal_ours_for_output (); | |
630 | printf ("\nProgram terminated with signal %d, %s\n", | |
631 | stop_signal, safe_strsignal (stop_signal)); | |
632 | fflush (stdout); | |
633 | return 0; | |
634 | } | |
635 | } | |
636 | fetch_inferior_registers (-1); | |
637 | return 1; | |
638 | } | |
639 | ||
fb1415ae JG |
640 | CORE_ADDR |
641 | hp_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
642 | int nargs; | |
643 | value *args; | |
644 | CORE_ADDR sp; | |
645 | int struct_return; | |
646 | CORE_ADDR struct_addr; | |
647 | { | |
648 | /* array of arguments' offsets */ | |
649 | int *offset = (int *)alloca(nargs); | |
650 | int cum = 0; | |
651 | int i, alignment; | |
652 | ||
653 | for (i = 0; i < nargs; i++) | |
654 | { | |
655 | cum += TYPE_LENGTH (VALUE_TYPE (args[i])); | |
0213d96f SG |
656 | |
657 | /* value must go at proper alignment. Assume alignment is a | |
fb1415ae JG |
658 | power of two.*/ |
659 | alignment = hp_alignof (VALUE_TYPE (args[i])); | |
660 | if (cum % alignment) | |
661 | cum = (cum + alignment) & -alignment; | |
662 | offset[i] = -cum; | |
663 | } | |
9f739abd | 664 | sp += min ((cum + 7) & -8, 16); |
0213d96f | 665 | |
9f739abd | 666 | for (i = 0; i < nargs; i++) |
0213d96f SG |
667 | write_memory (sp + offset[i], VALUE_CONTENTS (args[i]), |
668 | TYPE_LENGTH (VALUE_TYPE (args[i]))); | |
669 | ||
fb1415ae JG |
670 | if (struct_return) |
671 | write_register (28, struct_addr); | |
9f739abd | 672 | return sp + 32; |
fb1415ae JG |
673 | } |
674 | ||
675 | /* return the alignment of a type in bytes. Structures have the maximum | |
676 | alignment required by their fields. */ | |
677 | ||
678 | int | |
679 | hp_alignof (arg) | |
680 | struct type *arg; | |
681 | { | |
682 | int max_align, align, i; | |
683 | switch (TYPE_CODE (arg)) | |
684 | { | |
685 | case TYPE_CODE_PTR: | |
686 | case TYPE_CODE_INT: | |
687 | case TYPE_CODE_FLT: | |
688 | return TYPE_LENGTH (arg); | |
689 | case TYPE_CODE_ARRAY: | |
690 | return hp_alignof (TYPE_FIELD_TYPE (arg, 0)); | |
691 | case TYPE_CODE_STRUCT: | |
692 | case TYPE_CODE_UNION: | |
693 | max_align = 2; | |
694 | for (i = 0; i < TYPE_NFIELDS (arg); i++) | |
695 | { | |
696 | /* Bit fields have no real alignment. */ | |
697 | if (!TYPE_FIELD_BITPOS (arg, i)) | |
698 | { | |
699 | align = hp_alignof (TYPE_FIELD_TYPE (arg, i)); | |
700 | max_align = max (max_align, align); | |
701 | } | |
702 | } | |
703 | return max_align; | |
704 | default: | |
705 | return 4; | |
706 | } | |
707 | } | |
708 | ||
709 | /* Print the register regnum, or all registers if regnum is -1 */ | |
710 | ||
711 | pa_do_registers_info (regnum, fpregs) | |
712 | int regnum; | |
713 | int fpregs; | |
714 | { | |
715 | char raw_regs [REGISTER_BYTES]; | |
716 | int i; | |
717 | ||
718 | for (i = 0; i < NUM_REGS; i++) | |
719 | read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i)); | |
9f739abd SG |
720 | if (regnum == -1) |
721 | pa_print_registers (raw_regs, regnum, fpregs); | |
fb1415ae | 722 | else if (regnum < FP0_REGNUM) |
0213d96f SG |
723 | printf ("%s %x\n", reg_names[regnum], *(long *)(raw_regs + |
724 | REGISTER_BYTE (regnum))); | |
fb1415ae JG |
725 | else |
726 | pa_print_fp_reg (regnum); | |
727 | } | |
728 | ||
9f739abd | 729 | pa_print_registers (raw_regs, regnum, fpregs) |
fb1415ae JG |
730 | char *raw_regs; |
731 | int regnum; | |
9f739abd | 732 | int fpregs; |
fb1415ae JG |
733 | { |
734 | int i; | |
735 | ||
736 | for (i = 0; i < 18; i++) | |
737 | printf ("%8.8s: %8x %8.8s: %8x %8.8s: %8x %8.8s: %8x\n", | |
0213d96f SG |
738 | reg_names[i], |
739 | *(int *)(raw_regs + REGISTER_BYTE (i)), | |
740 | reg_names[i + 18], | |
741 | *(int *)(raw_regs + REGISTER_BYTE (i + 18)), | |
742 | reg_names[i + 36], | |
743 | *(int *)(raw_regs + REGISTER_BYTE (i + 36)), | |
744 | reg_names[i + 54], | |
745 | *(int *)(raw_regs + REGISTER_BYTE (i + 54))); | |
9f739abd SG |
746 | |
747 | if (fpregs) | |
748 | for (i = 72; i < NUM_REGS; i++) | |
749 | pa_print_fp_reg (i); | |
fb1415ae JG |
750 | } |
751 | ||
752 | pa_print_fp_reg (i) | |
753 | int i; | |
754 | { | |
755 | unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
756 | unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
757 | REGISTER_TYPE val; | |
758 | ||
759 | /* Get the data in raw format, then convert also to virtual format. */ | |
760 | read_relative_register_raw_bytes (i, raw_buffer); | |
761 | REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer); | |
762 | ||
763 | fputs_filtered (reg_names[i], stdout); | |
764 | print_spaces_filtered (15 - strlen (reg_names[i]), stdout); | |
765 | ||
766 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, stdout, 0, | |
767 | 1, 0, Val_pretty_default); | |
768 | printf_filtered ("\n"); | |
fb1415ae JG |
769 | } |
770 | ||
9f739abd SG |
771 | /* Function calls that pass into a new compilation unit must pass through a |
772 | small piece of code that does long format (`external' in HPPA parlance) | |
773 | jumps. We figure out where the trampoline is going to end up, and return | |
774 | the PC of the final destination. If we aren't in a trampoline, we just | |
b5c10493 SG |
775 | return NULL. |
776 | ||
777 | For computed calls, we just extract the new PC from r22. */ | |
fb1415ae | 778 | |
9f739abd | 779 | CORE_ADDR |
b5c10493 | 780 | skip_trampoline_code (pc, name) |
9f739abd | 781 | CORE_ADDR pc; |
b5c10493 | 782 | char *name; |
fb1415ae | 783 | { |
9f739abd | 784 | long inst0, inst1; |
b5c10493 SG |
785 | static CORE_ADDR dyncall = 0; |
786 | struct minimal_symbol *msym; | |
787 | ||
788 | /* FIXME XXX - dyncall must be initialized whenever we get a new exec file */ | |
789 | ||
790 | if (!dyncall) | |
791 | { | |
792 | msym = lookup_minimal_symbol ("$$dyncall", NULL); | |
793 | if (msym) | |
b8ef8163 | 794 | dyncall = SYMBOL_VALUE_ADDRESS (msym); |
b5c10493 SG |
795 | else |
796 | dyncall = -1; | |
797 | } | |
798 | ||
799 | if (pc == dyncall) | |
800 | return (CORE_ADDR)(read_register (22) & ~0x3); | |
fb1415ae | 801 | |
9f739abd SG |
802 | inst0 = read_memory_integer (pc, 4); |
803 | inst1 = read_memory_integer (pc+4, 4); | |
fb1415ae | 804 | |
9f739abd SG |
805 | if ( (inst0 & 0xffe00000) == 0x20200000 /* ldil xxx, r1 */ |
806 | && (inst1 & 0xffe0e002) == 0xe0202002) /* be,n yyy(sr4, r1) */ | |
807 | pc = extract_21 (inst0) + extract_17 (inst1); | |
808 | else | |
b5c10493 | 809 | pc = (CORE_ADDR)NULL; |
fb1415ae | 810 | |
9f739abd | 811 | return pc; |
fb1415ae | 812 | } |
b5c10493 | 813 | |
0213d96f SG |
814 | /* Advance PC across any function entry prologue instructions |
815 | to reach some "real" code. */ | |
816 | ||
817 | /* skip (stw rp, -20(0,sp)); copy 4,1; copy sp, 4; stwm 1,framesize(sp) | |
818 | for gcc, or (stw rp, -20(0,sp); stwm 1, framesize(sp) for hcc */ | |
819 | ||
820 | CORE_ADDR | |
821 | skip_prologue(pc) | |
822 | CORE_ADDR pc; | |
823 | { | |
824 | int inst; | |
825 | int status; | |
826 | ||
fa9265e5 | 827 | status = target_read_memory (pc, (char *)&inst, 4); |
0213d96f SG |
828 | SWAP_TARGET_AND_HOST (&inst, sizeof (inst)); |
829 | if (status != 0) | |
830 | return pc; | |
831 | ||
832 | if (inst == 0x6BC23FD9) /* stw rp,-20(sp) */ | |
833 | { | |
834 | if (read_memory_integer (pc + 4, 4) == 0x8040241) /* copy r4,r1 */ | |
835 | pc += 16; | |
836 | else if ((read_memory_integer (pc + 4, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
837 | pc += 8; | |
838 | } | |
839 | else if (read_memory_integer (pc, 4) == 0x8040241) /* copy r4,r1 */ | |
840 | pc += 12; | |
841 | else if ((read_memory_integer (pc, 4) & ~MASK_14) == 0x68810000) /* stw r1,(r4) */ | |
842 | pc += 4; | |
843 | ||
844 | return pc; | |
845 | } | |
846 | ||
b5c10493 SG |
847 | static void |
848 | unwind_command (exp, from_tty) | |
849 | char *exp; | |
850 | int from_tty; | |
851 | { | |
852 | CORE_ADDR address; | |
853 | union | |
854 | { | |
855 | int *foo; | |
856 | struct unwind_table_entry *u; | |
857 | } xxx; | |
858 | ||
859 | /* If we have an expression, evaluate it and use it as the address. */ | |
860 | ||
861 | if (exp != 0 && *exp != 0) | |
862 | address = parse_and_eval_address (exp); | |
863 | else | |
864 | return; | |
865 | ||
866 | xxx.u = find_unwind_entry (address); | |
867 | ||
868 | if (!xxx.u) | |
869 | { | |
870 | printf ("Can't find unwind table entry for PC 0x%x\n", address); | |
871 | return; | |
872 | } | |
873 | ||
874 | printf ("%08x\n%08X\n%08X\n%08X\n", xxx.foo[0], xxx.foo[1], xxx.foo[2], | |
875 | xxx.foo[3]); | |
876 | } | |
877 | ||
878 | void | |
879 | _initialize_hppah_tdep () | |
880 | { | |
881 | add_com ("unwind", class_obscure, unwind_command, "Print unwind info\n"); | |
882 | add_show_from_set | |
883 | (add_set_cmd ("use_unwind", class_obscure, var_boolean, | |
884 | (char *)&use_unwind, | |
b8ef8163 | 885 | "Set the usage of unwind info", &setlist), |
b5c10493 SG |
886 | &showlist); |
887 | } |