1 /* Target-dependent code for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include <sys/param.h>
30 #include <sys/ioctl.h>
33 #include <sys/ptrace.h>
42 extern int attach_flag
;
44 /* Nonzero if we just simulated a single step break. */
48 /* Breakpoint shadows for the single step instructions will be kept here. */
50 static struct sstep_breaks
{
57 * Calculate the destination of a branch/jump. Return -1 if not a branch.
60 branch_dest (opcode
, instr
, pc
, safety
)
61 int opcode
, instr
, pc
, safety
;
69 absolute
= (int) ((instr
>> 1) & 1);
73 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditionl */
76 if (opcode
!= 18) /* br conditional */
77 immediate
= ((instr
& ~3) << 16) >> 16;
81 dest
= pc
+ immediate
;
85 ext_op
= (instr
>>1) & 0x3ff;
87 if (ext_op
== 16) /* br conditional register */
88 dest
= read_register (LR_REGNUM
) & ~3;
90 else if (ext_op
== 528) /* br cond to count reg */
91 dest
= read_register (CTR_REGNUM
) & ~3;
98 return (dest
< TEXT_SEGMENT_BASE
) ? safety
: dest
;
103 /* AIX does not support PT_STEP. Simulate it. */
109 #define INSNLEN(OPCODE) 4
111 static char breakp
[] = BREAKPOINT
;
112 int ii
, insn
, ret
, loc
;
113 int breaks
[2], opcode
;
116 extern CORE_ADDR text_start
;
119 ret
= read_memory (loc
, &insn
, sizeof (int));
121 printf ("Error in single_step()!!\n");
123 breaks
[0] = loc
+ INSNLEN(insn
);
125 breaks
[1] = branch_dest (opcode
, insn
, loc
, breaks
[0]);
127 /* Don't put two breakpoints on the same address. */
128 if (breaks
[1] == breaks
[0])
131 stepBreaks
[1].address
= -1;
133 for (ii
=0; ii
< 2; ++ii
) {
135 /* ignore invalid breakpoint. */
136 if ( breaks
[ii
] == -1)
139 read_memory (breaks
[ii
], &(stepBreaks
[ii
].data
), sizeof(int));
141 ret
= write_memory (breaks
[ii
], breakp
, sizeof(int));
142 stepBreaks
[ii
].address
= breaks
[ii
];
146 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
, 0);
150 /* remove step breakpoints. */
151 for (ii
=0; ii
< 2; ++ii
)
152 if (stepBreaks
[ii
].address
!= -1)
154 (stepBreaks
[ii
].address
, &(stepBreaks
[ii
].data
), sizeof(int));
163 /* return pc value after skipping a function prologue. */
171 if (target_read_memory (pc
, (char *)&op
, sizeof (op
)))
172 return pc
; /* Can't access it -- assume no prologue. */
173 SWAP_TARGET_AND_HOST (&op
, sizeof (op
));
175 /* Assume that subsequent fetches can fail with low probability. */
177 if (op
== 0x7c0802a6) { /* mflr r0 */
179 op
= read_memory_integer (pc
, 4);
182 if ((op
& 0xfc00003e) == 0x7c000026) { /* mfcr Rx */
184 op
= read_memory_integer (pc
, 4);
187 if ((op
& 0xfc000000) == 0x48000000) { /* bl foo, to save fprs??? */
189 op
= read_memory_integer (pc
, 4);
191 /* At this point, make sure this is not a trampoline function
192 (a function that simply calls another functions, and nothing else).
193 If the next is not a nop, this branch was part of the function
196 if (op
== 0x4def7b82 || /* crorc 15, 15, 15 */
198 return pc
- 4; /* don't skip over this branch */
201 if ((op
& 0xfc1f0000) == 0xbc010000) { /* stm Rx, NUM(r1) */
203 op
= read_memory_integer (pc
, 4);
206 while (((tmp
= op
>> 16) == 0x9001) || /* st r0, NUM(r1) */
207 (tmp
== 0x9421) || /* stu r1, NUM(r1) */
208 (op
== 0x93e1fffc)) /* st r31,-4(r1) */
211 op
= read_memory_integer (pc
, 4);
214 while ((tmp
= (op
>> 22)) == 0x20f) { /* l r31, ... or */
215 pc
+= 4; /* l r30, ... */
216 op
= read_memory_integer (pc
, 4);
219 /* store parameters into stack */
221 (op
& 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
222 (op
& 0xfc1f0000) == 0x90010000 || /* st r?, NUM(r1) */
223 (op
& 0xfc000000) == 0xfc000000 || /* frsp, fp?, .. */
224 (op
& 0xd0000000) == 0xd0000000) /* stfs, fp?, .. */
226 pc
+= 4; /* store fpr double */
227 op
= read_memory_integer (pc
, 4);
230 if (op
== 0x603f0000) { /* oril r31, r1, 0x0 */
231 pc
+= 4; /* this happens if r31 is used as */
232 op
= read_memory_integer (pc
, 4); /* frame ptr. (gcc does that) */
235 while ((op
>> 16) == (0x907f + tmp
)) { /* st r3, NUM(r31) */
236 pc
+= 4; /* st r4, NUM(r31), ... */
237 op
= read_memory_integer (pc
, 4);
242 /* I have problems with skipping over __main() that I need to address
243 * sometime. Previously, I used to use misc_function_vector which
244 * didn't work as well as I wanted to be. -MGO */
246 /* If the first thing after skipping a prolog is a branch to a function,
247 this might be a call to an initializer in main(), introduced by gcc2.
248 We'd like to skip over it as well. Fortunately, xlc does some extra
249 work before calling a function right after a prologue, thus we can
250 single out such gcc2 behaviour. */
253 if ((op
& 0xfc000001) == 0x48000001) { /* bl foo, an initializer function? */
254 op
= read_memory_integer (pc
+4, 4);
256 if (op
== 0x4def7b82) { /* cror 0xf, 0xf, 0xf (nop) */
258 /* check and see if we are in main. If so, skip over this initializer
261 tmp
= find_pc_misc_function (pc
);
262 if (tmp
>= 0 && !strcmp (misc_function_vector
[tmp
].name
, "main"))
272 /* text start and end addresses in virtual memory. */
274 CORE_ADDR text_start
;
278 /*************************************************************************
279 Support for creating pushind a dummy frame into the stack, and popping
281 *************************************************************************/
283 /* The total size of dummy frame is 436, which is;
288 and 24 extra bytes for the callee's link area. The last 24 bytes
289 for the link area might not be necessary, since it will be taken
290 care of by push_arguments(). */
292 #define DUMMY_FRAME_SIZE 436
294 #define DUMMY_FRAME_ADDR_SIZE 10
296 /* Make sure you initialize these in somewhere, in case gdb gives up what it
297 was debugging and starts debugging something else. FIXMEibm */
299 static int dummy_frame_count
= 0;
300 static int dummy_frame_size
= 0;
301 static CORE_ADDR
*dummy_frame_addr
= 0;
303 extern int stop_stack_dummy
;
305 /* push a dummy frame into stack, save all register. Currently we are saving
306 only gpr's and fpr's, which is not good enough! FIXMEmgo */
310 int sp
, pc
; /* stack pointer and link register */
313 fetch_inferior_registers (-1);
315 if (dummy_frame_count
>= dummy_frame_size
) {
316 dummy_frame_size
+= DUMMY_FRAME_ADDR_SIZE
;
317 if (dummy_frame_addr
)
318 dummy_frame_addr
= (CORE_ADDR
*) xrealloc
319 (dummy_frame_addr
, sizeof(CORE_ADDR
) * (dummy_frame_size
));
321 dummy_frame_addr
= (CORE_ADDR
*)
322 xmalloc (sizeof(CORE_ADDR
) * (dummy_frame_size
));
325 sp
= read_register(SP_REGNUM
);
326 pc
= read_register(PC_REGNUM
);
328 dummy_frame_addr
[dummy_frame_count
++] = sp
;
330 /* Be careful! If the stack pointer is not decremented first, then kernel
331 thinks he is free to use the space underneath it. And kernel actually
332 uses that area for IPC purposes when executing ptrace(2) calls. So
333 before writing register values into the new frame, decrement and update
334 %sp first in order to secure your frame. */
336 write_register (SP_REGNUM
, sp
-DUMMY_FRAME_SIZE
);
338 /* gdb relies on the state of current_frame. We'd better update it,
339 otherwise things like do_registers_info() wouldn't work properly! */
341 flush_cached_frames ();
342 set_current_frame (create_new_frame (sp
-DUMMY_FRAME_SIZE
, pc
));
344 /* save program counter in link register's space. */
345 write_memory (sp
+8, &pc
, 4);
347 /* save all floating point and general purpose registers here. */
350 for (ii
= 0; ii
< 32; ++ii
)
351 write_memory (sp
-8-(ii
*8), ®isters
[REGISTER_BYTE (31-ii
+FP0_REGNUM
)], 8);
354 for (ii
=1; ii
<=32; ++ii
)
355 write_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
357 /* so far, 32*2 + 32 words = 384 bytes have been written.
358 7 extra registers in our register set: pc, ps, cnd, lr, cnt, xer, mq */
360 for (ii
=1; ii
<= (LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
) {
361 write_memory (sp
-384-(ii
*4),
362 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
365 /* Save sp or so called back chain right here. */
366 write_memory (sp
-DUMMY_FRAME_SIZE
, &sp
, 4);
367 sp
-= DUMMY_FRAME_SIZE
;
369 /* And finally, this is the back chain. */
370 write_memory (sp
+8, &pc
, 4);
374 /* Pop a dummy frame.
376 In rs6000 when we push a dummy frame, we save all of the registers. This
377 is usually done before user calls a function explicitly.
379 After a dummy frame is pushed, some instructions are copied into stack,
380 and stack pointer is decremented even more. Since we don't have a frame
381 pointer to get back to the parent frame of the dummy, we start having
382 trouble poping it. Therefore, we keep a dummy frame stack, keeping
383 addresses of dummy frames as such. When poping happens and when we
384 detect that was a dummy frame, we pop it back to its parent by using
385 dummy frame stack (`dummy_frame_addr' array).
392 sp
= dummy_frame_addr
[--dummy_frame_count
];
394 /* restore all fpr's. */
395 for (ii
= 1; ii
<= 32; ++ii
)
396 read_memory (sp
-(ii
*8), ®isters
[REGISTER_BYTE (32-ii
+FP0_REGNUM
)], 8);
398 /* restore all gpr's */
399 for (ii
=1; ii
<= 32; ++ii
) {
400 read_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
403 /* restore the rest of the registers. */
404 for (ii
=1; ii
<=(LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
)
405 read_memory (sp
-384-(ii
*4),
406 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
408 read_memory (sp
-(DUMMY_FRAME_SIZE
-8),
409 ®isters
[REGISTER_BYTE(PC_REGNUM
)], 4);
411 /* when a dummy frame was being pushed, we had to decrement %sp first, in
412 order to secure astack space. Thus, saved %sp (or %r1) value, is not the
413 one we should restore. Change it with the one we need. */
415 *(int*)®isters
[REGISTER_BYTE(FP_REGNUM
)] = sp
;
417 /* Now we can restore all registers. */
419 store_inferior_registers (-1);
421 flush_cached_frames ();
422 set_current_frame (create_new_frame (sp
, pc
));
426 /* pop the innermost frame, go back to the caller. */
430 int pc
, lr
, sp
, prev_sp
; /* %pc, %lr, %sp */
431 struct aix_framedata fdata
;
432 FRAME fr
= get_current_frame ();
438 if (stop_stack_dummy
&& dummy_frame_count
) {
443 /* figure out previous %pc value. If the function is frameless, it is
444 still in the link register, otherwise walk the frames and retrieve the
445 saved %pc value in the previous frame. */
447 addr
= get_pc_function_start (fr
->pc
) + FUNCTION_START_OFFSET
;
448 function_frame_info (addr
, &fdata
);
450 read_memory (sp
, &prev_sp
, 4);
452 lr
= read_register (LR_REGNUM
);
454 read_memory (prev_sp
+8, &lr
, 4);
456 /* reset %pc value. */
457 write_register (PC_REGNUM
, lr
);
459 /* reset register values if any was saved earlier. */
460 addr
= prev_sp
- fdata
.offset
;
462 if (fdata
.saved_gpr
!= -1)
463 for (ii
=fdata
.saved_gpr
; ii
<= 31; ++ii
) {
464 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
)], 4);
465 addr
+= sizeof (int);
468 if (fdata
.saved_fpr
!= -1)
469 for (ii
=fdata
.saved_fpr
; ii
<= 31; ++ii
) {
470 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
+FP0_REGNUM
)], 8);
474 write_register (SP_REGNUM
, prev_sp
);
475 store_inferior_registers (-1);
476 flush_cached_frames ();
477 set_current_frame (create_new_frame (prev_sp
, lr
));
481 /* fixup the call sequence of a dummy function, with the real function address.
482 its argumets will be passed by gdb. */
484 fix_call_dummy(dummyname
, pc
, fun
, nargs
, type
)
488 int nargs
; /* not used */
489 int type
; /* not used */
492 #define TOC_ADDR_OFFSET 20
493 #define TARGET_ADDR_OFFSET 28
496 unsigned long target_addr
;
497 unsigned long tocvalue
;
500 tocvalue
= find_toc_address (target_addr
);
502 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
);
503 ii
= (ii
& 0xffff0000) | (tocvalue
>> 16);
504 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
) = ii
;
506 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4);
507 ii
= (ii
& 0xffff0000) | (tocvalue
& 0x0000ffff);
508 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4) = ii
;
510 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
);
511 ii
= (ii
& 0xffff0000) | (target_addr
>> 16);
512 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
) = ii
;
514 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4);
515 ii
= (ii
& 0xffff0000) | (target_addr
& 0x0000ffff);
516 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4) = ii
;
521 /* return information about a function frame.
522 in struct aix_frameinfo fdata:
523 - frameless is TRUE, if function does not save %pc value in its frame.
524 - offset is the number of bytes used in the frame to save registers.
525 - saved_gpr is the number of the first saved gpr.
526 - saved_fpr is the number of the first saved fpr.
527 - alloca_reg is the number of the register used for alloca() handling.
530 function_frame_info (pc
, fdata
)
532 struct aix_framedata
*fdata
;
535 register unsigned int op
;
538 fdata
->saved_gpr
= fdata
->saved_fpr
= fdata
->alloca_reg
= -1;
540 op
= read_memory_integer (pc
, 4);
541 if (op
== 0x7c0802a6) { /* mflr r0 */
543 op
= read_memory_integer (pc
, 4);
544 fdata
->frameless
= 0;
546 else /* else, this is a frameless invocation */
547 fdata
->frameless
= 1;
550 if ((op
& 0xfc00003e) == 0x7c000026) { /* mfcr Rx */
552 op
= read_memory_integer (pc
, 4);
555 if ((op
& 0xfc000000) == 0x48000000) { /* bl foo, to save fprs??? */
557 op
= read_memory_integer (pc
, 4);
558 /* At this point, make sure this is not a trampoline function
559 (a function that simply calls another functions, and nothing else).
560 If the next is not a nop, this branch was part of the function
563 if (op
== 0x4def7b82 || /* crorc 15, 15, 15 */
565 return; /* prologue is over */
568 if ((op
& 0xfc1f0000) == 0xd8010000) { /* stfd Rx,NUM(r1) */
569 pc
+= 4; /* store floating register double */
570 op
= read_memory_integer (pc
, 4);
573 if ((op
& 0xfc1f0000) == 0xbc010000) { /* stm Rx, NUM(r1) */
575 fdata
->saved_gpr
= (op
>> 21) & 0x1f;
578 tmp2
= 0xffff0000 | tmp2
;
582 fdata
->saved_fpr
= (tmp2
- ((32 - fdata
->saved_gpr
) * 4)) / 8;
583 if ( fdata
->saved_fpr
> 0)
584 fdata
->saved_fpr
= 32 - fdata
->saved_fpr
;
586 fdata
->saved_fpr
= -1;
588 fdata
->offset
= tmp2
;
590 op
= read_memory_integer (pc
, 4);
593 while (((tmp
= op
>> 16) == 0x9001) || /* st r0, NUM(r1) */
594 (tmp
== 0x9421) || /* stu r1, NUM(r1) */
595 (op
== 0x93e1fffc)) /* st r31,-4(r1) */
597 /* gcc takes a short cut and uses this instruction to save r31 only. */
599 if (op
== 0x93e1fffc) {
601 /* fatal ("Unrecognized prolog."); */
602 printf ("Unrecognized prolog!\n");
604 fdata
->saved_gpr
= 31;
608 op
= read_memory_integer (pc
, 4);
611 while ((tmp
= (op
>> 22)) == 0x20f) { /* l r31, ... or */
612 pc
+= 4; /* l r30, ... */
613 op
= read_memory_integer (pc
, 4);
616 /* store parameters into stack */
618 (op
& 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
619 (op
& 0xfc1f0000) == 0x90010000 || /* st r?, NUM(r1) */
620 (op
& 0xfc000000) == 0xfc000000 || /* frsp, fp?, .. */
621 (op
& 0xd0000000) == 0xd0000000) /* stfs, fp?, .. */
623 pc
+= 4; /* store fpr double */
624 op
= read_memory_integer (pc
, 4);
627 if (op
== 0x603f0000) /* oril r31, r1, 0x0 */
628 fdata
->alloca_reg
= 31;
632 /* Pass the arguments in either registers, or in the stack. In RS6000, the first
633 eight words of the argument list (that might be less than eight parameters if
634 some parameters occupy more than one word) are passed in r3..r11 registers.
635 float and double parameters are passed in fpr's, in addition to that. Rest of
636 the parameters if any are passed in user stack. There might be cases in which
637 half of the parameter is copied into registers, the other half is pushed into
640 If the function is returning a structure, then the return address is passed
641 in r3, then the first 7 words of the parametes can be passed in registers,
645 push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
650 CORE_ADDR struct_addr
;
653 int argno
; /* current argument number */
654 int argbytes
; /* current argument byte */
655 char tmp_buffer
[50];
657 int f_argno
= 0; /* current floating point argno */
659 CORE_ADDR saved_sp
, pc
;
661 if ( dummy_frame_count
<= 0)
662 printf ("FATAL ERROR -push_arguments()! frame not found!!\n");
664 /* The first eight words of ther arguments are passed in registers. Copy
667 If the function is returning a `struct', then the first word (which
668 will be passed in r3) is used for struct return address. In that
669 case we should advance one word and start from r4 register to copy
672 ii
= struct_return
? 1 : 0;
674 for (argno
=0, argbytes
=0; argno
< nargs
&& ii
<8; ++ii
) {
676 arg
= value_arg_coerce (args
[argno
]);
677 len
= TYPE_LENGTH (VALUE_TYPE (arg
));
679 if (TYPE_CODE (VALUE_TYPE (arg
)) == TYPE_CODE_FLT
) {
681 /* floating point arguments are passed in fpr's, as well as gpr's.
682 There are 13 fpr's reserved for passing parameters. At this point
683 there is no way we would run out of them. */
687 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
689 bcopy (VALUE_CONTENTS (arg
),
690 ®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)], len
);
696 /* Argument takes more than one register. */
697 while (argbytes
< len
) {
699 *(int*)®isters
[REGISTER_BYTE(ii
+3)] = 0;
700 bcopy ( ((char*)VALUE_CONTENTS (arg
))+argbytes
,
701 ®isters
[REGISTER_BYTE(ii
+3)],
702 (len
- argbytes
) > 4 ? 4 : len
- argbytes
);
706 goto ran_out_of_registers_for_arguments
;
711 else { /* Argument can fit in one register. No problem. */
712 *(int*)®isters
[REGISTER_BYTE(ii
+3)] = 0;
713 bcopy (VALUE_CONTENTS (arg
), ®isters
[REGISTER_BYTE(ii
+3)], len
);
718 ran_out_of_registers_for_arguments
:
720 /* location for 8 parameters are always reserved. */
723 /* another six words for back chain, TOC register, link register, etc. */
726 /* if there are more arguments, allocate space for them in
727 the stack, then push them starting from the ninth one. */
729 if ((argno
< nargs
) || argbytes
) {
734 space
+= ((len
- argbytes
+ 3) & -4);
740 for (; jj
< nargs
; ++jj
) {
741 val
= value_arg_coerce (args
[jj
]);
742 space
+= ((TYPE_LENGTH (VALUE_TYPE (val
))) + 3) & -4;
745 /* add location required for the rest of the parameters */
746 space
= (space
+ 7) & -8;
749 /* This is another instance we need to be concerned about securing our
750 stack space. If we write anything underneath %sp (r1), we might conflict
751 with the kernel who thinks he is free to use this area. So, update %sp
752 first before doing anything else. */
754 write_register (SP_REGNUM
, sp
);
756 /* if the last argument copied into the registers didn't fit there
757 completely, push the rest of it into stack. */
761 sp
+24+(ii
*4), ((char*)VALUE_CONTENTS (arg
))+argbytes
, len
- argbytes
);
763 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
766 /* push the rest of the arguments into stack. */
767 for (; argno
< nargs
; ++argno
) {
769 arg
= value_arg_coerce (args
[argno
]);
770 len
= TYPE_LENGTH (VALUE_TYPE (arg
));
773 /* float types should be passed in fpr's, as well as in the stack. */
774 if (TYPE_CODE (VALUE_TYPE (arg
)) == TYPE_CODE_FLT
&& f_argno
< 13) {
778 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
780 bcopy (VALUE_CONTENTS (arg
),
781 ®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)], len
);
785 write_memory (sp
+24+(ii
*4), VALUE_CONTENTS (arg
), len
);
786 ii
+= ((len
+ 3) & -4) / 4;
790 /* Secure stack areas first, before doing anything else. */
791 write_register (SP_REGNUM
, sp
);
793 saved_sp
= dummy_frame_addr
[dummy_frame_count
- 1];
794 read_memory (saved_sp
, tmp_buffer
, 24);
795 write_memory (sp
, tmp_buffer
, 24);
797 write_memory (sp
, &saved_sp
, 4); /* set back chain properly */
799 store_inferior_registers (-1);
803 /* a given return value in `regbuf' with a type `valtype', extract and copy its
804 value into `valbuf' */
806 extract_return_value (valtype
, regbuf
, valbuf
)
807 struct type
*valtype
;
808 char regbuf
[REGISTER_BYTES
];
812 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
) {
815 /* floats and doubles are returned in fpr1. fpr's have a size of 8 bytes.
816 We need to truncate the return value into float size (4 byte) if
819 if (TYPE_LENGTH (valtype
) > 4) /* this is a double */
820 bcopy (®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)], valbuf
,
821 TYPE_LENGTH (valtype
));
823 bcopy (®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)], &dd
, 8);
825 bcopy (&ff
, valbuf
, sizeof(float));
829 /* return value is copied starting from r3. */
830 bcopy (®buf
[REGISTER_BYTE (3)], valbuf
, TYPE_LENGTH (valtype
));
834 /* keep keep structure return address in this variable. */
836 CORE_ADDR rs6000_struct_return_address
;
839 /* Throw away this debugging code. FIXMEmgo. */
844 for (ii
=0; ii
<40; ++ii
) {
847 val
= read_memory_integer (fram
+ ii
* 4, 4);
848 printf ("0x%08x\t", val
);
855 /* Indirect function calls use a piece of trampoline code to do context
856 switching, i.e. to set the new TOC table. Skip such code if we are on
857 its first instruction (as when we have single-stepped to here).
858 Result is desired PC to step until, or NULL if we are not in
861 skip_trampoline_code (pc
)
864 register unsigned int ii
, op
;
866 static unsigned trampoline_code
[] = {
867 0x800b0000, /* l r0,0x0(r11) */
868 0x90410014, /* st r2,0x14(r1) */
869 0x7c0903a6, /* mtctr r0 */
870 0x804b0004, /* l r2,0x4(r11) */
871 0x816b0008, /* l r11,0x8(r11) */
872 0x4e800420, /* bctr */
877 for (ii
=0; trampoline_code
[ii
]; ++ii
) {
878 op
= read_memory_integer (pc
+ (ii
*4), 4);
879 if (op
!= trampoline_code
[ii
])
882 ii
= read_register (11); /* r11 holds destination addr */
883 pc
= read_memory_integer (ii
, 4); /* (r11) value */