1 /* Target-dependent code for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "xcoffsolib.h"
32 extern struct obstack frame_cache_obstack
;
36 /* Nonzero if we just simulated a single step break. */
39 /* Breakpoint shadows for the single step instructions will be kept here. */
41 static struct sstep_breaks
{
42 /* Address, or 0 if this is not in use. */
44 /* Shadow contents. */
48 /* Hook for determining the TOC address when calling functions in the
49 inferior under AIX. The initialization code in rs6000-nat.c sets
50 this hook to point to find_toc_address. */
52 CORE_ADDR (*find_toc_address_hook
) PARAMS ((CORE_ADDR
)) = NULL
;
54 /* Static function prototypes */
56 static CORE_ADDR branch_dest
PARAMS ((int opcode
, int instr
, CORE_ADDR pc
,
59 static void frame_get_cache_fsr
PARAMS ((struct frame_info
*fi
,
60 struct rs6000_framedata
*fdatap
));
62 static void pop_dummy_frame
PARAMS ((void));
64 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
67 branch_dest (opcode
, instr
, pc
, safety
)
78 absolute
= (int) ((instr
>> 1) & 1);
82 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
86 dest
= pc
+ immediate
;
90 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
94 dest
= pc
+ immediate
;
98 ext_op
= (instr
>>1) & 0x3ff;
100 if (ext_op
== 16) /* br conditional register */
102 dest
= read_register (LR_REGNUM
) & ~3;
104 /* If we are about to return from a signal handler, dest is
105 something like 0x3c90. The current frame is a signal handler
106 caller frame, upon completion of the sigreturn system call
107 execution will return to the saved PC in the frame. */
108 if (dest
< TEXT_SEGMENT_BASE
)
110 struct frame_info
*fi
;
112 fi
= get_current_frame ();
114 dest
= read_memory_integer (fi
->frame
+ SIG_FRAME_PC_OFFSET
,
119 else if (ext_op
== 528) /* br cond to count reg */
121 dest
= read_register (CTR_REGNUM
) & ~3;
123 /* If we are about to execute a system call, dest is something
124 like 0x22fc or 0x3b00. Upon completion the system call
125 will return to the address in the link register. */
126 if (dest
< TEXT_SEGMENT_BASE
)
127 dest
= read_register (LR_REGNUM
) & ~3;
134 return (dest
< TEXT_SEGMENT_BASE
) ? safety
: dest
;
139 /* AIX does not support PT_STEP. Simulate it. */
143 enum target_signal signal
;
145 #define INSNLEN(OPCODE) 4
147 static char le_breakp
[] = LITTLE_BREAKPOINT
;
148 static char be_breakp
[] = BIG_BREAKPOINT
;
149 char *breakp
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? be_breakp
: le_breakp
;
158 insn
= read_memory_integer (loc
, 4);
160 breaks
[0] = loc
+ INSNLEN(insn
);
162 breaks
[1] = branch_dest (opcode
, insn
, loc
, breaks
[0]);
164 /* Don't put two breakpoints on the same address. */
165 if (breaks
[1] == breaks
[0])
168 stepBreaks
[1].address
= 0;
170 for (ii
=0; ii
< 2; ++ii
) {
172 /* ignore invalid breakpoint. */
173 if ( breaks
[ii
] == -1)
176 read_memory (breaks
[ii
], stepBreaks
[ii
].data
, 4);
178 write_memory (breaks
[ii
], breakp
, 4);
179 stepBreaks
[ii
].address
= breaks
[ii
];
185 /* remove step breakpoints. */
186 for (ii
=0; ii
< 2; ++ii
)
187 if (stepBreaks
[ii
].address
!= 0)
189 (stepBreaks
[ii
].address
, stepBreaks
[ii
].data
, 4);
193 errno
= 0; /* FIXME, don't ignore errors! */
194 /* What errors? {read,write}_memory call error(). */
198 /* return pc value after skipping a function prologue and also return
199 information about a function frame.
201 in struct rs6000_frameinfo fdata:
202 - frameless is TRUE, if function does not have a frame.
203 - nosavedpc is TRUE, if function does not save %pc value in its frame.
204 - offset is the number of bytes used in the frame to save registers.
205 - saved_gpr is the number of the first saved gpr.
206 - saved_fpr is the number of the first saved fpr.
207 - alloca_reg is the number of the register used for alloca() handling.
209 - gpr_offset is the offset of the saved gprs
210 - fpr_offset is the offset of the saved fprs
211 - lr_offset is the offset of the saved lr
212 - cr_offset is the offset of the saved cr
215 #define SIGNED_SHORT(x) \
216 ((sizeof (short) == 2) \
217 ? ((int)(short)(x)) \
218 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
220 #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
223 skip_prologue (pc
, fdata
)
225 struct rs6000_framedata
*fdata
;
227 CORE_ADDR orig_pc
= pc
;
235 int minimal_toc_loaded
= 0;
236 static struct rs6000_framedata zero_frame
;
239 fdata
->saved_gpr
= -1;
240 fdata
->saved_fpr
= -1;
241 fdata
->alloca_reg
= -1;
242 fdata
->frameless
= 1;
243 fdata
->nosavedpc
= 1;
245 if (target_read_memory (pc
, buf
, 4))
246 return pc
; /* Can't access it -- assume no prologue. */
248 /* Assume that subsequent fetches can fail with low probability. */
253 op
= read_memory_integer (pc
, 4);
255 if ((op
& 0xfc1fffff) == 0x7c0802a6) { /* mflr Rx */
256 lr_reg
= (op
& 0x03e00000) | 0x90010000;
259 } else if ((op
& 0xfc1fffff) == 0x7c000026) { /* mfcr Rx */
260 cr_reg
= (op
& 0x03e00000) | 0x90010000;
263 } else if ((op
& 0xfc1f0000) == 0xd8010000) { /* stfd Rx,NUM(r1) */
264 reg
= GET_SRC_REG (op
);
265 if (fdata
->saved_fpr
== -1 || fdata
->saved_fpr
> reg
) {
266 fdata
->saved_fpr
= reg
;
267 fdata
->fpr_offset
= SIGNED_SHORT (op
) + offset
;
271 } else if (((op
& 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
272 ((op
& 0xfc1f0000) == 0x90010000 && /* st rx,NUM(r1),
274 (op
& 0x03e00000) >= 0x01a00000)) {
276 reg
= GET_SRC_REG (op
);
277 if (fdata
->saved_gpr
== -1 || fdata
->saved_gpr
> reg
) {
278 fdata
->saved_gpr
= reg
;
279 fdata
->gpr_offset
= SIGNED_SHORT (op
) + offset
;
283 } else if ((op
& 0xffff0000) == 0x3c000000) { /* addis 0,0,NUM, used
285 fdata
->offset
= (op
& 0x0000ffff) << 16;
286 fdata
->frameless
= 0;
289 } else if ((op
& 0xffff0000) == 0x60000000) { /* ori 0,0,NUM, 2nd ha
290 lf of >= 32k frames */
291 fdata
->offset
|= (op
& 0x0000ffff);
292 fdata
->frameless
= 0;
295 } else if ((op
& 0xffff0000) == lr_reg
) { /* st Rx,NUM(r1)
297 fdata
->lr_offset
= SIGNED_SHORT (op
) + offset
;
298 fdata
->nosavedpc
= 0;
302 } else if ((op
& 0xffff0000) == cr_reg
) { /* st Rx,NUM(r1)
304 fdata
->cr_offset
= SIGNED_SHORT (op
) + offset
;
308 } else if (op
== 0x48000005) { /* bl .+4 used in
312 } else if (op
== 0x48000004) { /* b .+4 (xlc) */
315 } else if (((op
& 0xffff0000) == 0x801e0000 || /* lwz 0,NUM(r30), used
316 in V.4 -mrelocatable */
317 op
== 0x7fc0f214) && /* add r30,r0,r30, used
318 in V.4 -mrelocatable */
319 lr_reg
== 0x901e0000) {
322 } else if ((op
& 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
323 in V.4 -mminimal-toc */
324 (op
& 0xffff0000) == 0x3bde0000) { /* addi 30,30,foo@l */
327 } else if ((op
& 0xfc000000) == 0x48000000) { /* bl foo,
330 fdata
->frameless
= 0;
331 /* Don't skip over the subroutine call if it is not within the first
332 three instructions of the prologue. */
333 if ((pc
- orig_pc
) > 8)
336 op
= read_memory_integer (pc
+4, 4);
338 /* At this point, make sure this is not a trampoline function
339 (a function that simply calls another functions, and nothing else).
340 If the next is not a nop, this branch was part of the function
343 if (op
== 0x4def7b82 || op
== 0) /* crorc 15, 15, 15 */
344 break; /* don't skip over
348 /* update stack pointer */
349 } else if ((op
& 0xffff0000) == 0x94210000) { /* stu r1,NUM(r1) */
350 fdata
->frameless
= 0;
351 fdata
->offset
= SIGNED_SHORT (op
);
352 offset
= fdata
->offset
;
355 } else if (op
== 0x7c21016e) { /* stwux 1,1,0 */
356 fdata
->frameless
= 0;
357 offset
= fdata
->offset
;
360 /* Load up minimal toc pointer */
361 } else if ((op
>> 22) == 0x20f
362 && ! minimal_toc_loaded
) { /* l r31,... or l r30,... */
363 minimal_toc_loaded
= 1;
366 /* store parameters in stack */
367 } else if ((op
& 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
368 (op
& 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
369 (op
& 0xfc1f0000) == 0xfc010000) { /* frsp, fp?,NUM(r1) */
372 /* store parameters in stack via frame pointer */
374 ((op
& 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r1) */
375 (op
& 0xfc1f0000) == 0xd81f0000 || /* stfd Rx,NUM(r1) */
376 (op
& 0xfc1f0000) == 0xfc1f0000)) { /* frsp, fp?,NUM(r1) */
379 /* Set up frame pointer */
380 } else if (op
== 0x603f0000 /* oril r31, r1, 0x0 */
381 || op
== 0x7c3f0b78) { /* mr r31, r1 */
382 fdata
->frameless
= 0;
384 fdata
->alloca_reg
= 31;
387 /* Another way to set up the frame pointer. */
388 } else if ((op
& 0xfc1fffff) == 0x38010000) { /* addi rX, r1, 0x0 */
389 fdata
->frameless
= 0;
391 fdata
->alloca_reg
= (op
& ~0x38010000) >> 21;
400 /* I have problems with skipping over __main() that I need to address
401 * sometime. Previously, I used to use misc_function_vector which
402 * didn't work as well as I wanted to be. -MGO */
404 /* If the first thing after skipping a prolog is a branch to a function,
405 this might be a call to an initializer in main(), introduced by gcc2.
406 We'd like to skip over it as well. Fortunately, xlc does some extra
407 work before calling a function right after a prologue, thus we can
408 single out such gcc2 behaviour. */
411 if ((op
& 0xfc000001) == 0x48000001) { /* bl foo, an initializer function? */
412 op
= read_memory_integer (pc
+4, 4);
414 if (op
== 0x4def7b82) { /* cror 0xf, 0xf, 0xf (nop) */
416 /* check and see if we are in main. If so, skip over this initializer
419 tmp
= find_pc_misc_function (pc
);
420 if (tmp
>= 0 && STREQ (misc_function_vector
[tmp
].name
, "main"))
426 fdata
->offset
= - fdata
->offset
;
431 /*************************************************************************
432 Support for creating pushind a dummy frame into the stack, and popping
434 *************************************************************************/
436 /* The total size of dummy frame is 436, which is;
441 and 24 extra bytes for the callee's link area. The last 24 bytes
442 for the link area might not be necessary, since it will be taken
443 care of by push_arguments(). */
445 #define DUMMY_FRAME_SIZE 436
447 #define DUMMY_FRAME_ADDR_SIZE 10
449 /* Make sure you initialize these in somewhere, in case gdb gives up what it
450 was debugging and starts debugging something else. FIXMEibm */
452 static int dummy_frame_count
= 0;
453 static int dummy_frame_size
= 0;
454 static CORE_ADDR
*dummy_frame_addr
= 0;
456 extern int stop_stack_dummy
;
458 /* push a dummy frame into stack, save all register. Currently we are saving
459 only gpr's and fpr's, which is not good enough! FIXMEmgo */
466 /* Same thing, target byte order. */
471 /* Same thing, target byte order. */
474 /* Needed to figure out where to save the dummy link area.
475 FIXME: There should be an easier way to do this, no? tiemann 9/9/95. */
476 struct rs6000_framedata fdata
;
480 target_fetch_registers (-1);
482 if (dummy_frame_count
>= dummy_frame_size
) {
483 dummy_frame_size
+= DUMMY_FRAME_ADDR_SIZE
;
484 if (dummy_frame_addr
)
485 dummy_frame_addr
= (CORE_ADDR
*) xrealloc
486 (dummy_frame_addr
, sizeof(CORE_ADDR
) * (dummy_frame_size
));
488 dummy_frame_addr
= (CORE_ADDR
*)
489 xmalloc (sizeof(CORE_ADDR
) * (dummy_frame_size
));
492 sp
= read_register(SP_REGNUM
);
493 pc
= read_register(PC_REGNUM
);
494 store_address (pc_targ
, 4, pc
);
496 skip_prologue (get_pc_function_start (pc
) + FUNCTION_START_OFFSET
, &fdata
);
498 dummy_frame_addr
[dummy_frame_count
++] = sp
;
500 /* Be careful! If the stack pointer is not decremented first, then kernel
501 thinks he is free to use the space underneath it. And kernel actually
502 uses that area for IPC purposes when executing ptrace(2) calls. So
503 before writing register values into the new frame, decrement and update
504 %sp first in order to secure your frame. */
506 /* FIXME: We don't check if the stack really has this much space.
507 This is a problem on the ppc simulator (which only grants one page
508 (4096 bytes) by default. */
510 write_register (SP_REGNUM
, sp
-DUMMY_FRAME_SIZE
);
512 /* gdb relies on the state of current_frame. We'd better update it,
513 otherwise things like do_registers_info() wouldn't work properly! */
515 flush_cached_frames ();
517 /* save program counter in link register's space. */
518 write_memory (sp
+ (fdata
.lr_offset
? fdata
.lr_offset
: DEFAULT_LR_SAVE
),
521 /* save all floating point and general purpose registers here. */
524 for (ii
= 0; ii
< 32; ++ii
)
525 write_memory (sp
-8-(ii
*8), ®isters
[REGISTER_BYTE (31-ii
+FP0_REGNUM
)], 8);
528 for (ii
=1; ii
<=32; ++ii
)
529 write_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
531 /* so far, 32*2 + 32 words = 384 bytes have been written.
532 7 extra registers in our register set: pc, ps, cnd, lr, cnt, xer, mq */
534 for (ii
=1; ii
<= (LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
) {
535 write_memory (sp
-384-(ii
*4),
536 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
539 /* Save sp or so called back chain right here. */
540 store_address (sp_targ
, 4, sp
);
541 write_memory (sp
-DUMMY_FRAME_SIZE
, sp_targ
, 4);
542 sp
-= DUMMY_FRAME_SIZE
;
544 /* And finally, this is the back chain. */
545 write_memory (sp
+8, pc_targ
, 4);
549 /* Pop a dummy frame.
551 In rs6000 when we push a dummy frame, we save all of the registers. This
552 is usually done before user calls a function explicitly.
554 After a dummy frame is pushed, some instructions are copied into stack,
555 and stack pointer is decremented even more. Since we don't have a frame
556 pointer to get back to the parent frame of the dummy, we start having
557 trouble poping it. Therefore, we keep a dummy frame stack, keeping
558 addresses of dummy frames as such. When poping happens and when we
559 detect that was a dummy frame, we pop it back to its parent by using
560 dummy frame stack (`dummy_frame_addr' array).
562 FIXME: This whole concept is broken. You should be able to detect
563 a dummy stack frame *on the user's stack itself*. When you do,
564 then you know the format of that stack frame -- including its
565 saved SP register! There should *not* be a separate stack in the
566 GDB process that keeps track of these dummy frames! -- gnu@cygnus.com Aug92
574 sp
= dummy_frame_addr
[--dummy_frame_count
];
576 /* restore all fpr's. */
577 for (ii
= 1; ii
<= 32; ++ii
)
578 read_memory (sp
-(ii
*8), ®isters
[REGISTER_BYTE (32-ii
+FP0_REGNUM
)], 8);
580 /* restore all gpr's */
581 for (ii
=1; ii
<= 32; ++ii
) {
582 read_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
585 /* restore the rest of the registers. */
586 for (ii
=1; ii
<=(LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
)
587 read_memory (sp
-384-(ii
*4),
588 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
590 read_memory (sp
-(DUMMY_FRAME_SIZE
-8),
591 ®isters
[REGISTER_BYTE(PC_REGNUM
)], 4);
593 /* when a dummy frame was being pushed, we had to decrement %sp first, in
594 order to secure astack space. Thus, saved %sp (or %r1) value, is not the
595 one we should restore. Change it with the one we need. */
597 memcpy (®isters
[REGISTER_BYTE(FP_REGNUM
)], (char *) &sp
, sizeof (int));
599 /* Now we can restore all registers. */
601 target_store_registers (-1);
603 flush_cached_frames ();
607 /* pop the innermost frame, go back to the caller. */
612 CORE_ADDR pc
, lr
, sp
, prev_sp
; /* %pc, %lr, %sp */
613 struct rs6000_framedata fdata
;
614 struct frame_info
*frame
= get_current_frame ();
618 sp
= FRAME_FP (frame
);
620 if (stop_stack_dummy
)
622 #ifdef USE_GENERIC_DUMMY_FRAMES
623 generic_pop_dummy_frame ();
624 flush_cached_frames ();
627 if (dummy_frame_count
)
633 /* Make sure that all registers are valid. */
634 read_register_bytes (0, NULL
, REGISTER_BYTES
);
636 /* figure out previous %pc value. If the function is frameless, it is
637 still in the link register, otherwise walk the frames and retrieve the
638 saved %pc value in the previous frame. */
640 addr
= get_pc_function_start (frame
->pc
) + FUNCTION_START_OFFSET
;
641 (void) skip_prologue (addr
, &fdata
);
646 prev_sp
= read_memory_integer (sp
, 4);
647 if (fdata
.lr_offset
== 0)
648 lr
= read_register (LR_REGNUM
);
650 lr
= read_memory_integer (prev_sp
+ fdata
.lr_offset
, 4);
652 /* reset %pc value. */
653 write_register (PC_REGNUM
, lr
);
655 /* reset register values if any was saved earlier. */
656 addr
= prev_sp
- fdata
.offset
;
658 if (fdata
.saved_gpr
!= -1)
659 for (ii
= fdata
.saved_gpr
; ii
<= 31; ++ii
) {
660 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
)], 4);
664 if (fdata
.saved_fpr
!= -1)
665 for (ii
= fdata
.saved_fpr
; ii
<= 31; ++ii
) {
666 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
+FP0_REGNUM
)], 8);
670 write_register (SP_REGNUM
, prev_sp
);
671 target_store_registers (-1);
672 flush_cached_frames ();
675 /* fixup the call sequence of a dummy function, with the real function address.
676 its argumets will be passed by gdb. */
679 rs6000_fix_call_dummy (dummyname
, pc
, fun
, nargs
, args
, type
, gcc_p
)
688 #define TOC_ADDR_OFFSET 20
689 #define TARGET_ADDR_OFFSET 28
692 CORE_ADDR target_addr
;
694 if (find_toc_address_hook
!= NULL
)
698 tocvalue
= (*find_toc_address_hook
) (fun
);
699 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
);
700 ii
= (ii
& 0xffff0000) | (tocvalue
>> 16);
701 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
) = ii
;
703 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4);
704 ii
= (ii
& 0xffff0000) | (tocvalue
& 0x0000ffff);
705 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4) = ii
;
709 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
);
710 ii
= (ii
& 0xffff0000) | (target_addr
>> 16);
711 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
) = ii
;
713 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4);
714 ii
= (ii
& 0xffff0000) | (target_addr
& 0x0000ffff);
715 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4) = ii
;
718 /* Pass the arguments in either registers, or in the stack. In RS6000,
719 the first eight words of the argument list (that might be less than
720 eight parameters if some parameters occupy more than one word) are
721 passed in r3..r11 registers. float and double parameters are
722 passed in fpr's, in addition to that. Rest of the parameters if any
723 are passed in user stack. There might be cases in which half of the
724 parameter is copied into registers, the other half is pushed into
727 If the function is returning a structure, then the return address is passed
728 in r3, then the first 7 words of the parameters can be passed in registers,
732 push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
737 CORE_ADDR struct_addr
;
741 int argno
; /* current argument number */
742 int argbytes
; /* current argument byte */
743 char tmp_buffer
[50];
744 int f_argno
= 0; /* current floating point argno */
751 #ifndef USE_GENERIC_DUMMY_FRAMES
752 if ( dummy_frame_count
<= 0)
753 printf_unfiltered ("FATAL ERROR -push_arguments()! frame not found!!\n");
754 #endif /* GENERIC_DUMMY_FRAMES */
756 /* The first eight words of ther arguments are passed in registers. Copy
759 If the function is returning a `struct', then the first word (which
760 will be passed in r3) is used for struct return address. In that
761 case we should advance one word and start from r4 register to copy
764 ii
= struct_return
? 1 : 0;
767 effectively indirect call... gcc does...
769 return_val example( float, int);
772 float in fp0, int in r3
773 offset of stack on overflow 8/16
774 for varargs, must go by type.
776 float in r3&r4, int in r5
777 offset of stack on overflow different
779 return in r3 or f0. If no float, must study how gcc emulates floats;
780 pay attention to arg promotion.
781 User may have to cast\args to handle promotion correctly
782 since gdb won't know if prototype supplied or not.
785 for (argno
=0, argbytes
=0; argno
< nargs
&& ii
<8; ++ii
) {
788 type
= check_typedef (VALUE_TYPE (arg
));
789 len
= TYPE_LENGTH (type
);
791 if (TYPE_CODE (type
) == TYPE_CODE_FLT
) {
793 /* floating point arguments are passed in fpr's, as well as gpr's.
794 There are 13 fpr's reserved for passing parameters. At this point
795 there is no way we would run out of them. */
799 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
801 memcpy (®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)],
802 VALUE_CONTENTS (arg
),
809 /* Argument takes more than one register. */
810 while (argbytes
< len
) {
811 memset (®isters
[REGISTER_BYTE(ii
+3)], 0, sizeof(int));
812 memcpy (®isters
[REGISTER_BYTE(ii
+3)],
813 ((char*)VALUE_CONTENTS (arg
))+argbytes
,
814 (len
- argbytes
) > 4 ? 4 : len
- argbytes
);
818 goto ran_out_of_registers_for_arguments
;
823 else { /* Argument can fit in one register. No problem. */
824 memset (®isters
[REGISTER_BYTE(ii
+3)], 0, sizeof(int));
825 memcpy (®isters
[REGISTER_BYTE(ii
+3)], VALUE_CONTENTS (arg
), len
);
830 ran_out_of_registers_for_arguments
:
832 #ifdef USE_GENERIC_DUMMY_FRAMES
833 saved_sp
= read_sp ();
835 /* location for 8 parameters are always reserved. */
838 /* another six words for back chain, TOC register, link register, etc. */
840 #endif /* GENERIC_DUMMY_FRAMES */
841 /* if there are more arguments, allocate space for them in
842 the stack, then push them starting from the ninth one. */
844 if ((argno
< nargs
) || argbytes
) {
848 space
+= ((len
- argbytes
+ 3) & -4);
854 for (; jj
< nargs
; ++jj
) {
855 value_ptr val
= args
[jj
];
856 space
+= ((TYPE_LENGTH (VALUE_TYPE (val
))) + 3) & -4;
859 /* add location required for the rest of the parameters */
860 space
= (space
+ 7) & -8;
863 /* This is another instance we need to be concerned about securing our
864 stack space. If we write anything underneath %sp (r1), we might conflict
865 with the kernel who thinks he is free to use this area. So, update %sp
866 first before doing anything else. */
868 write_register (SP_REGNUM
, sp
);
870 /* if the last argument copied into the registers didn't fit there
871 completely, push the rest of it into stack. */
874 write_memory (sp
+24+(ii
*4),
875 ((char*)VALUE_CONTENTS (arg
))+argbytes
,
878 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
881 /* push the rest of the arguments into stack. */
882 for (; argno
< nargs
; ++argno
) {
885 type
= check_typedef (VALUE_TYPE (arg
));
886 len
= TYPE_LENGTH (type
);
889 /* float types should be passed in fpr's, as well as in the stack. */
890 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& f_argno
< 13) {
894 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
896 memcpy (®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)],
897 VALUE_CONTENTS (arg
),
902 write_memory (sp
+24+(ii
*4), (char *) VALUE_CONTENTS (arg
), len
);
903 ii
+= ((len
+ 3) & -4) / 4;
907 /* Secure stack areas first, before doing anything else. */
908 write_register (SP_REGNUM
, sp
);
910 #ifndef USE_GENERIC_DUMMY_FRAMES
911 /* we want to copy 24 bytes of target's frame to dummy's frame,
912 then set back chain to point to new frame. */
914 saved_sp
= dummy_frame_addr
[dummy_frame_count
- 1];
915 read_memory (saved_sp
, tmp_buffer
, 24);
916 write_memory (sp
, tmp_buffer
, 24);
917 #endif /* GENERIC_DUMMY_FRAMES */
919 /* set back chain properly */
920 store_address (tmp_buffer
, 4, saved_sp
);
921 write_memory (sp
, tmp_buffer
, 4);
923 target_store_registers (-1);
926 #ifdef ELF_OBJECT_FORMAT
928 /* Function: ppc_push_return_address (pc, sp)
929 Set up the return address for the inferior function call. */
932 ppc_push_return_address (pc
, sp
)
936 write_register (LR_REGNUM
, CALL_DUMMY_ADDRESS ());
942 /* a given return value in `regbuf' with a type `valtype', extract and copy its
943 value into `valbuf' */
946 extract_return_value (valtype
, regbuf
, valbuf
)
947 struct type
*valtype
;
948 char regbuf
[REGISTER_BYTES
];
953 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
) {
956 /* floats and doubles are returned in fpr1. fpr's have a size of 8 bytes.
957 We need to truncate the return value into float size (4 byte) if
960 if (TYPE_LENGTH (valtype
) > 4) /* this is a double */
962 ®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)],
963 TYPE_LENGTH (valtype
));
965 memcpy (&dd
, ®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)], 8);
967 memcpy (valbuf
, &ff
, sizeof(float));
971 /* return value is copied starting from r3. */
972 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
973 && TYPE_LENGTH (valtype
) < REGISTER_RAW_SIZE (3))
974 offset
= REGISTER_RAW_SIZE (3) - TYPE_LENGTH (valtype
);
977 regbuf
+ REGISTER_BYTE (3) + offset
,
978 TYPE_LENGTH (valtype
));
983 /* keep structure return address in this variable.
984 FIXME: This is a horrid kludge which should not be allowed to continue
985 living. This only allows a single nested call to a structure-returning
986 function. Come on, guys! -- gnu@cygnus.com, Aug 92 */
988 CORE_ADDR rs6000_struct_return_address
;
991 /* Indirect function calls use a piece of trampoline code to do context
992 switching, i.e. to set the new TOC table. Skip such code if we are on
993 its first instruction (as when we have single-stepped to here).
994 Also skip shared library trampoline code (which is different from
995 indirect function call trampolines).
996 Result is desired PC to step until, or NULL if we are not in
1000 skip_trampoline_code (pc
)
1003 register unsigned int ii
, op
;
1004 CORE_ADDR solib_target_pc
;
1006 static unsigned trampoline_code
[] = {
1007 0x800b0000, /* l r0,0x0(r11) */
1008 0x90410014, /* st r2,0x14(r1) */
1009 0x7c0903a6, /* mtctr r0 */
1010 0x804b0004, /* l r2,0x4(r11) */
1011 0x816b0008, /* l r11,0x8(r11) */
1012 0x4e800420, /* bctr */
1013 0x4e800020, /* br */
1017 /* If pc is in a shared library trampoline, return its target. */
1018 solib_target_pc
= find_solib_trampoline_target (pc
);
1019 if (solib_target_pc
)
1020 return solib_target_pc
;
1022 for (ii
=0; trampoline_code
[ii
]; ++ii
) {
1023 op
= read_memory_integer (pc
+ (ii
*4), 4);
1024 if (op
!= trampoline_code
[ii
])
1027 ii
= read_register (11); /* r11 holds destination addr */
1028 pc
= read_memory_integer (ii
, 4); /* (r11) value */
1032 /* Determines whether the function FI has a frame on the stack or not. */
1035 frameless_function_invocation (fi
)
1036 struct frame_info
*fi
;
1038 CORE_ADDR func_start
;
1039 struct rs6000_framedata fdata
;
1041 /* Don't even think about framelessness except on the innermost frame
1042 or if the function was interrupted by a signal. */
1043 if (fi
->next
!= NULL
&& !fi
->next
->signal_handler_caller
)
1046 func_start
= get_pc_function_start (fi
->pc
);
1048 /* If we failed to find the start of the function, it is a mistake
1049 to inspect the instructions. */
1053 /* A frame with a zero PC is usually created by dereferencing a NULL
1054 function pointer, normally causing an immediate core dump of the
1055 inferior. Mark function as frameless, as the inferior has no chance
1056 of setting up a stack frame. */
1063 func_start
+= FUNCTION_START_OFFSET
;
1064 (void) skip_prologue (func_start
, &fdata
);
1065 return fdata
.frameless
;
1068 /* Return the PC saved in a frame */
1072 struct frame_info
*fi
;
1074 CORE_ADDR func_start
;
1075 struct rs6000_framedata fdata
;
1077 if (fi
->signal_handler_caller
)
1078 return read_memory_integer (fi
->frame
+ SIG_FRAME_PC_OFFSET
, 4);
1080 #ifdef USE_GENERIC_DUMMY_FRAMES
1081 if (PC_IN_CALL_DUMMY (fi
->pc
, fi
->frame
, fi
->frame
))
1082 return generic_read_register_dummy(fi
->pc
, fi
->frame
, PC_REGNUM
);
1083 #endif /* GENERIC_DUMMY_FRAMES */
1085 func_start
= get_pc_function_start (fi
->pc
) + FUNCTION_START_OFFSET
;
1087 /* If we failed to find the start of the function, it is a mistake
1088 to inspect the instructions. */
1092 (void) skip_prologue (func_start
, &fdata
);
1094 if (fdata
.lr_offset
== 0 && fi
->next
!= NULL
)
1096 if (fi
->next
->signal_handler_caller
)
1097 return read_memory_integer (fi
->next
->frame
+ SIG_FRAME_LR_OFFSET
, 4);
1099 return read_memory_integer (rs6000_frame_chain (fi
) + DEFAULT_LR_SAVE
,
1103 if (fdata
.lr_offset
== 0)
1104 return read_register (LR_REGNUM
);
1106 return read_memory_integer (rs6000_frame_chain (fi
) + fdata
.lr_offset
, 4);
1109 /* If saved registers of frame FI are not known yet, read and cache them.
1110 &FDATAP contains rs6000_framedata; TDATAP can be NULL,
1111 in which case the framedata are read. */
1114 frame_get_cache_fsr (fi
, fdatap
)
1115 struct frame_info
*fi
;
1116 struct rs6000_framedata
*fdatap
;
1119 CORE_ADDR frame_addr
;
1120 struct rs6000_framedata work_fdata
;
1125 if (fdatap
== NULL
) {
1126 fdatap
= &work_fdata
;
1127 (void) skip_prologue (get_pc_function_start (fi
->pc
), fdatap
);
1130 fi
->cache_fsr
= (struct frame_saved_regs
*)
1131 obstack_alloc (&frame_cache_obstack
, sizeof (struct frame_saved_regs
));
1132 memset (fi
->cache_fsr
, '\0', sizeof (struct frame_saved_regs
));
1134 if (fi
->prev
&& fi
->prev
->frame
)
1135 frame_addr
= fi
->prev
->frame
;
1137 frame_addr
= read_memory_integer (fi
->frame
, 4);
1139 /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
1140 All fpr's from saved_fpr to fp31 are saved. */
1142 if (fdatap
->saved_fpr
>= 0) {
1143 int fpr_offset
= frame_addr
+ fdatap
->fpr_offset
;
1144 for (ii
= fdatap
->saved_fpr
; ii
< 32; ii
++) {
1145 fi
->cache_fsr
->regs
[FP0_REGNUM
+ ii
] = fpr_offset
;
1150 /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
1151 All gpr's from saved_gpr to gpr31 are saved. */
1153 if (fdatap
->saved_gpr
>= 0) {
1154 int gpr_offset
= frame_addr
+ fdatap
->gpr_offset
;
1155 for (ii
= fdatap
->saved_gpr
; ii
< 32; ii
++) {
1156 fi
->cache_fsr
->regs
[ii
] = gpr_offset
;
1161 /* If != 0, fdatap->cr_offset is the offset from the frame that holds
1163 if (fdatap
->cr_offset
!= 0)
1164 fi
->cache_fsr
->regs
[CR_REGNUM
] = frame_addr
+ fdatap
->cr_offset
;
1166 /* If != 0, fdatap->lr_offset is the offset from the frame that holds
1168 if (fdatap
->lr_offset
!= 0)
1169 fi
->cache_fsr
->regs
[LR_REGNUM
] = frame_addr
+ fdatap
->lr_offset
;
1172 /* Return the address of a frame. This is the inital %sp value when the frame
1173 was first allocated. For functions calling alloca(), it might be saved in
1174 an alloca register. */
1177 frame_initial_stack_address (fi
)
1178 struct frame_info
*fi
;
1181 struct rs6000_framedata fdata
;
1182 struct frame_info
*callee_fi
;
1184 /* if the initial stack pointer (frame address) of this frame is known,
1188 return fi
->initial_sp
;
1190 /* find out if this function is using an alloca register.. */
1192 (void) skip_prologue (get_pc_function_start (fi
->pc
), &fdata
);
1194 /* if saved registers of this frame are not known yet, read and cache them. */
1197 frame_get_cache_fsr (fi
, &fdata
);
1199 /* If no alloca register used, then fi->frame is the value of the %sp for
1200 this frame, and it is good enough. */
1202 if (fdata
.alloca_reg
< 0) {
1203 fi
->initial_sp
= fi
->frame
;
1204 return fi
->initial_sp
;
1207 /* This function has an alloca register. If this is the top-most frame
1208 (with the lowest address), the value in alloca register is good. */
1211 return fi
->initial_sp
= read_register (fdata
.alloca_reg
);
1213 /* Otherwise, this is a caller frame. Callee has usually already saved
1214 registers, but there are exceptions (such as when the callee
1215 has no parameters). Find the address in which caller's alloca
1216 register is saved. */
1218 for (callee_fi
= fi
->next
; callee_fi
; callee_fi
= callee_fi
->next
) {
1220 if (!callee_fi
->cache_fsr
)
1221 frame_get_cache_fsr (callee_fi
, NULL
);
1223 /* this is the address in which alloca register is saved. */
1225 tmpaddr
= callee_fi
->cache_fsr
->regs
[fdata
.alloca_reg
];
1227 fi
->initial_sp
= read_memory_integer (tmpaddr
, 4);
1228 return fi
->initial_sp
;
1231 /* Go look into deeper levels of the frame chain to see if any one of
1232 the callees has saved alloca register. */
1235 /* If alloca register was not saved, by the callee (or any of its callees)
1236 then the value in the register is still good. */
1238 return fi
->initial_sp
= read_register (fdata
.alloca_reg
);
1242 rs6000_frame_chain (thisframe
)
1243 struct frame_info
*thisframe
;
1247 #ifdef USE_GENERIC_DUMMY_FRAMES
1248 if (PC_IN_CALL_DUMMY (thisframe
->pc
, thisframe
->frame
, thisframe
->frame
))
1249 return thisframe
->frame
; /* dummy frame same as caller's frame */
1250 #endif /* GENERIC_DUMMY_FRAMES */
1252 if (inside_entry_file (thisframe
->pc
) ||
1253 thisframe
->pc
== entry_point_address ())
1256 if (thisframe
->signal_handler_caller
)
1257 fp
= read_memory_integer (thisframe
->frame
+ SIG_FRAME_FP_OFFSET
, 4);
1258 else if (thisframe
->next
!= NULL
1259 && thisframe
->next
->signal_handler_caller
1260 && frameless_function_invocation (thisframe
))
1261 /* A frameless function interrupted by a signal did not change the
1263 fp
= FRAME_FP (thisframe
);
1265 fp
= read_memory_integer ((thisframe
)->frame
, 4);
1267 #ifdef USE_GENERIC_DUMMY_FRAMES
1271 lr
= read_register (LR_REGNUM
);
1272 if (lr
== entry_point_address ())
1273 if (fp
!= 0 && (fpp
= read_memory_integer (fp
, 4)) != 0)
1274 if (PC_IN_CALL_DUMMY (lr
, fpp
, fpp
))
1277 #endif /* GENERIC_DUMMY_FRAMES */
1281 /* Return nonzero if ADDR (a function pointer) is in the data space and
1282 is therefore a special function pointer. */
1285 is_magic_function_pointer (addr
)
1288 struct obj_section
*s
;
1290 s
= find_pc_section (addr
);
1291 if (s
&& s
->the_bfd_section
->flags
& SEC_CODE
)
1297 #ifdef GDB_TARGET_POWERPC
1299 gdb_print_insn_powerpc (memaddr
, info
)
1301 disassemble_info
*info
;
1303 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1304 return print_insn_big_powerpc (memaddr
, info
);
1306 return print_insn_little_powerpc (memaddr
, info
);
1310 /* Function: get_saved_register
1311 Just call the generic_get_saved_register function. */
1313 #ifdef USE_GENERIC_DUMMY_FRAMES
1315 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
1319 struct frame_info
*frame
;
1321 enum lval_type
*lval
;
1323 generic_get_saved_register (raw_buffer
, optimized
, addrp
,
1324 frame
, regnum
, lval
);
1330 _initialize_rs6000_tdep ()
1332 /* FIXME, this should not be decided via ifdef. */
1333 #ifdef GDB_TARGET_POWERPC
1334 tm_print_insn
= gdb_print_insn_powerpc
;
1336 tm_print_insn
= print_insn_rs6000
;