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