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. */
29 #include "xcoffsolib.h"
31 extern struct obstack frame_cache_obstack
;
35 /* Nonzero if we just simulated a single step break. */
38 /* Breakpoint shadows for the single step instructions will be kept here. */
40 static struct sstep_breaks
{
41 /* Address, or 0 if this is not in use. */
43 /* Shadow contents. */
47 /* Hook for determining the TOC address when calling functions in the
48 inferior under AIX. The initialization code in rs6000-nat.c sets
49 this hook to point to find_toc_address. */
51 CORE_ADDR (*find_toc_address_hook
) PARAMS ((CORE_ADDR
)) = NULL
;
53 /* Static function prototypes */
55 static CORE_ADDR branch_dest
PARAMS ((int opcode
, int instr
, CORE_ADDR pc
,
58 static void frame_get_cache_fsr
PARAMS ((struct frame_info
*fi
,
59 struct rs6000_framedata
*fdatap
));
61 static void pop_dummy_frame
PARAMS ((void));
63 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
66 branch_dest (opcode
, instr
, pc
, safety
)
77 absolute
= (int) ((instr
>> 1) & 1);
81 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
85 dest
= pc
+ immediate
;
89 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
93 dest
= pc
+ immediate
;
97 ext_op
= (instr
>>1) & 0x3ff;
99 if (ext_op
== 16) /* br conditional register */
101 dest
= read_register (LR_REGNUM
) & ~3;
103 /* If we are about to return from a signal handler, dest is
104 something like 0x3c90. The current frame is a signal handler
105 caller frame, upon completion of the sigreturn system call
106 execution will return to the saved PC in the frame. */
107 if (dest
< TEXT_SEGMENT_BASE
)
109 struct frame_info
*fi
;
111 fi
= get_current_frame ();
113 dest
= read_memory_integer (fi
->frame
+ SIG_FRAME_PC_OFFSET
,
118 else if (ext_op
== 528) /* br cond to count reg */
120 dest
= read_register (CTR_REGNUM
) & ~3;
122 /* If we are about to execute a system call, dest is something
123 like 0x22fc or 0x3b00. Upon completion the system call
124 will return to the address in the link register. */
125 if (dest
< TEXT_SEGMENT_BASE
)
126 dest
= read_register (LR_REGNUM
) & ~3;
133 return (dest
< TEXT_SEGMENT_BASE
) ? safety
: dest
;
138 /* AIX does not support PT_STEP. Simulate it. */
142 enum target_signal signal
;
144 #define INSNLEN(OPCODE) 4
146 static char le_breakp
[] = LITTLE_BREAKPOINT
;
147 static char be_breakp
[] = BIG_BREAKPOINT
;
148 char *breakp
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? be_breakp
: le_breakp
;
157 insn
= read_memory_integer (loc
, 4);
159 breaks
[0] = loc
+ INSNLEN(insn
);
161 breaks
[1] = branch_dest (opcode
, insn
, loc
, breaks
[0]);
163 /* Don't put two breakpoints on the same address. */
164 if (breaks
[1] == breaks
[0])
167 stepBreaks
[1].address
= 0;
169 for (ii
=0; ii
< 2; ++ii
) {
171 /* ignore invalid breakpoint. */
172 if ( breaks
[ii
] == -1)
175 read_memory (breaks
[ii
], stepBreaks
[ii
].data
, 4);
177 write_memory (breaks
[ii
], breakp
, 4);
178 stepBreaks
[ii
].address
= breaks
[ii
];
184 /* remove step breakpoints. */
185 for (ii
=0; ii
< 2; ++ii
)
186 if (stepBreaks
[ii
].address
!= 0)
188 (stepBreaks
[ii
].address
, stepBreaks
[ii
].data
, 4);
192 errno
= 0; /* FIXME, don't ignore errors! */
193 /* What errors? {read,write}_memory call error(). */
197 /* return pc value after skipping a function prologue and also return
198 information about a function frame.
200 in struct rs6000_frameinfo fdata:
201 - frameless is TRUE, if function does not have a frame.
202 - nosavedpc is TRUE, if function does not save %pc value in its frame.
203 - offset is the number of bytes used in the frame to save registers.
204 - saved_gpr is the number of the first saved gpr.
205 - saved_fpr is the number of the first saved fpr.
206 - alloca_reg is the number of the register used for alloca() handling.
208 - gpr_offset is the offset of the saved gprs
209 - fpr_offset is the offset of the saved fprs
210 - lr_offset is the offset of the saved lr
211 - cr_offset is the offset of the saved cr
214 #define SIGNED_SHORT(x) \
215 ((sizeof (short) == 2) \
216 ? ((int)(short)(x)) \
217 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
219 #define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
222 skip_prologue (pc
, fdata
)
224 struct rs6000_framedata
*fdata
;
226 CORE_ADDR orig_pc
= pc
;
234 int minimal_toc_loaded
= 0;
235 static struct rs6000_framedata zero_frame
;
238 fdata
->saved_gpr
= -1;
239 fdata
->saved_fpr
= -1;
240 fdata
->alloca_reg
= -1;
241 fdata
->frameless
= 1;
242 fdata
->nosavedpc
= 1;
244 if (target_read_memory (pc
, buf
, 4))
245 return pc
; /* Can't access it -- assume no prologue. */
247 /* Assume that subsequent fetches can fail with low probability. */
252 op
= read_memory_integer (pc
, 4);
254 if ((op
& 0xfc1fffff) == 0x7c0802a6) { /* mflr Rx */
255 lr_reg
= (op
& 0x03e00000) | 0x90010000;
258 } else if ((op
& 0xfc1fffff) == 0x7c000026) { /* mfcr Rx */
259 cr_reg
= (op
& 0x03e00000) | 0x90010000;
262 } else if ((op
& 0xfc1f0000) == 0xd8010000) { /* stfd Rx,NUM(r1) */
263 reg
= GET_SRC_REG (op
);
264 if (fdata
->saved_fpr
== -1 || fdata
->saved_fpr
> reg
) {
265 fdata
->saved_fpr
= reg
;
266 fdata
->fpr_offset
= SIGNED_SHORT (op
) + offset
;
270 } else if (((op
& 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
271 ((op
& 0xfc1f0000) == 0x90010000 && /* st rx,NUM(r1),
273 (op
& 0x03e00000) >= 0x01a00000)) {
275 reg
= GET_SRC_REG (op
);
276 if (fdata
->saved_gpr
== -1 || fdata
->saved_gpr
> reg
) {
277 fdata
->saved_gpr
= reg
;
278 fdata
->gpr_offset
= SIGNED_SHORT (op
) + offset
;
282 } else if ((op
& 0xffff0000) == 0x3c000000) { /* addis 0,0,NUM, used
284 fdata
->offset
= (op
& 0x0000ffff) << 16;
285 fdata
->frameless
= 0;
288 } else if ((op
& 0xffff0000) == 0x60000000) { /* ori 0,0,NUM, 2nd ha
289 lf of >= 32k frames */
290 fdata
->offset
|= (op
& 0x0000ffff);
291 fdata
->frameless
= 0;
294 } else if ((op
& 0xffff0000) == lr_reg
) { /* st Rx,NUM(r1)
296 fdata
->lr_offset
= SIGNED_SHORT (op
) + offset
;
297 fdata
->nosavedpc
= 0;
301 } else if ((op
& 0xffff0000) == cr_reg
) { /* st Rx,NUM(r1)
303 fdata
->cr_offset
= SIGNED_SHORT (op
) + offset
;
307 } else if (op
== 0x48000005) { /* bl .+4 used in
311 } else if (op
== 0x48000004) { /* b .+4 (xlc) */
314 } else if (((op
& 0xffff0000) == 0x801e0000 || /* lwz 0,NUM(r30), used
315 in V.4 -mrelocatable */
316 op
== 0x7fc0f214) && /* add r30,r0,r30, used
317 in V.4 -mrelocatable */
318 lr_reg
== 0x901e0000) {
321 } else if ((op
& 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
322 in V.4 -mminimal-toc */
323 (op
& 0xffff0000) == 0x3bde0000) { /* addi 30,30,foo@l */
326 } else if ((op
& 0xfc000000) == 0x48000000) { /* bl foo,
329 fdata
->frameless
= 0;
330 /* Don't skip over the subroutine call if it is not within the first
331 three instructions of the prologue. */
332 if ((pc
- orig_pc
) > 8)
335 op
= read_memory_integer (pc
+4, 4);
337 /* At this point, make sure this is not a trampoline function
338 (a function that simply calls another functions, and nothing else).
339 If the next is not a nop, this branch was part of the function
342 if (op
== 0x4def7b82 || op
== 0) /* crorc 15, 15, 15 */
343 break; /* don't skip over
347 /* update stack pointer */
348 } else if ((op
& 0xffff0000) == 0x94210000) { /* stu r1,NUM(r1) */
349 fdata
->frameless
= 0;
350 fdata
->offset
= SIGNED_SHORT (op
);
351 offset
= fdata
->offset
;
354 } else if (op
== 0x7c21016e) { /* stwux 1,1,0 */
355 fdata
->frameless
= 0;
356 offset
= fdata
->offset
;
359 /* Load up minimal toc pointer */
360 } else if ((op
>> 22) == 0x20f
361 && ! minimal_toc_loaded
) { /* l r31,... or l r30,... */
362 minimal_toc_loaded
= 1;
365 /* store parameters in stack */
366 } else if ((op
& 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
367 (op
& 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
368 (op
& 0xfc1f0000) == 0xfc010000) { /* frsp, fp?,NUM(r1) */
371 /* store parameters in stack via frame pointer */
373 ((op
& 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r1) */
374 (op
& 0xfc1f0000) == 0xd81f0000 || /* stfd Rx,NUM(r1) */
375 (op
& 0xfc1f0000) == 0xfc1f0000)) { /* frsp, fp?,NUM(r1) */
378 /* Set up frame pointer */
379 } else if (op
== 0x603f0000 /* oril r31, r1, 0x0 */
380 || op
== 0x7c3f0b78) { /* mr r31, r1 */
381 fdata
->frameless
= 0;
383 fdata
->alloca_reg
= 31;
386 /* Another way to set up the frame pointer. */
387 } else if ((op
& 0xfc1fffff) == 0x38010000) { /* addi rX, r1, 0x0 */
388 fdata
->frameless
= 0;
390 fdata
->alloca_reg
= (op
& ~0x38010000) >> 21;
399 /* I have problems with skipping over __main() that I need to address
400 * sometime. Previously, I used to use misc_function_vector which
401 * didn't work as well as I wanted to be. -MGO */
403 /* If the first thing after skipping a prolog is a branch to a function,
404 this might be a call to an initializer in main(), introduced by gcc2.
405 We'd like to skip over it as well. Fortunately, xlc does some extra
406 work before calling a function right after a prologue, thus we can
407 single out such gcc2 behaviour. */
410 if ((op
& 0xfc000001) == 0x48000001) { /* bl foo, an initializer function? */
411 op
= read_memory_integer (pc
+4, 4);
413 if (op
== 0x4def7b82) { /* cror 0xf, 0xf, 0xf (nop) */
415 /* check and see if we are in main. If so, skip over this initializer
418 tmp
= find_pc_misc_function (pc
);
419 if (tmp
>= 0 && STREQ (misc_function_vector
[tmp
].name
, "main"))
425 fdata
->offset
= - fdata
->offset
;
430 /*************************************************************************
431 Support for creating pushind a dummy frame into the stack, and popping
433 *************************************************************************/
435 /* The total size of dummy frame is 436, which is;
440 and 24 extra bytes for the callee's link area. The last 24 bytes
441 for the link area might not be necessary, since it will be taken
442 care of by push_arguments(). */
444 #define DUMMY_FRAME_SIZE 436
446 #define DUMMY_FRAME_ADDR_SIZE 10
448 /* Make sure you initialize these in somewhere, in case gdb gives up what it
449 was debugging and starts debugging something else. FIXMEibm */
451 static int dummy_frame_count
= 0;
452 static int dummy_frame_size
= 0;
453 static CORE_ADDR
*dummy_frame_addr
= 0;
455 extern int stop_stack_dummy
;
457 /* push a dummy frame into stack, save all register. Currently we are saving
458 only gpr's and fpr's, which is not good enough! FIXMEmgo */
465 /* Same thing, target byte order. */
470 /* Same thing, target byte order. */
473 /* Needed to figure out where to save the dummy link area.
474 FIXME: There should be an easier way to do this, no? tiemann 9/9/95. */
475 struct rs6000_framedata fdata
;
479 target_fetch_registers (-1);
481 if (dummy_frame_count
>= dummy_frame_size
) {
482 dummy_frame_size
+= DUMMY_FRAME_ADDR_SIZE
;
483 if (dummy_frame_addr
)
484 dummy_frame_addr
= (CORE_ADDR
*) xrealloc
485 (dummy_frame_addr
, sizeof(CORE_ADDR
) * (dummy_frame_size
));
487 dummy_frame_addr
= (CORE_ADDR
*)
488 xmalloc (sizeof(CORE_ADDR
) * (dummy_frame_size
));
491 sp
= read_register(SP_REGNUM
);
492 pc
= read_register(PC_REGNUM
);
493 store_address (pc_targ
, 4, pc
);
495 skip_prologue (get_pc_function_start (pc
) + FUNCTION_START_OFFSET
, &fdata
);
497 dummy_frame_addr
[dummy_frame_count
++] = sp
;
499 /* Be careful! If the stack pointer is not decremented first, then kernel
500 thinks he is free to use the space underneath it. And kernel actually
501 uses that area for IPC purposes when executing ptrace(2) calls. So
502 before writing register values into the new frame, decrement and update
503 %sp first in order to secure your frame. */
505 /* FIXME: We don't check if the stack really has this much space.
506 This is a problem on the ppc simulator (which only grants one page
507 (4096 bytes) by default. */
509 write_register (SP_REGNUM
, sp
-DUMMY_FRAME_SIZE
);
511 /* gdb relies on the state of current_frame. We'd better update it,
512 otherwise things like do_registers_info() wouldn't work properly! */
514 flush_cached_frames ();
516 /* save program counter in link register's space. */
517 write_memory (sp
+ (fdata
.lr_offset
? fdata
.lr_offset
: DEFAULT_LR_SAVE
),
520 /* save all floating point and general purpose registers here. */
523 for (ii
= 0; ii
< 32; ++ii
)
524 write_memory (sp
-8-(ii
*8), ®isters
[REGISTER_BYTE (31-ii
+FP0_REGNUM
)], 8);
527 for (ii
=1; ii
<=32; ++ii
)
528 write_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
530 /* so far, 32*2 + 32 words = 384 bytes have been written.
531 7 extra registers in our register set: pc, ps, cnd, lr, cnt, xer, mq */
533 for (ii
=1; ii
<= (LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
) {
534 write_memory (sp
-384-(ii
*4),
535 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
538 /* Save sp or so called back chain right here. */
539 store_address (sp_targ
, 4, sp
);
540 write_memory (sp
-DUMMY_FRAME_SIZE
, sp_targ
, 4);
541 sp
-= DUMMY_FRAME_SIZE
;
543 /* And finally, this is the back chain. */
544 write_memory (sp
+8, pc_targ
, 4);
548 /* Pop a dummy frame.
550 In rs6000 when we push a dummy frame, we save all of the registers. This
551 is usually done before user calls a function explicitly.
553 After a dummy frame is pushed, some instructions are copied into stack,
554 and stack pointer is decremented even more. Since we don't have a frame
555 pointer to get back to the parent frame of the dummy, we start having
556 trouble poping it. Therefore, we keep a dummy frame stack, keeping
557 addresses of dummy frames as such. When poping happens and when we
558 detect that was a dummy frame, we pop it back to its parent by using
559 dummy frame stack (`dummy_frame_addr' array).
561 FIXME: This whole concept is broken. You should be able to detect
562 a dummy stack frame *on the user's stack itself*. When you do,
563 then you know the format of that stack frame -- including its
564 saved SP register! There should *not* be a separate stack in the
565 GDB process that keeps track of these dummy frames! -- gnu@cygnus.com Aug92
573 sp
= dummy_frame_addr
[--dummy_frame_count
];
575 /* restore all fpr's. */
576 for (ii
= 1; ii
<= 32; ++ii
)
577 read_memory (sp
-(ii
*8), ®isters
[REGISTER_BYTE (32-ii
+FP0_REGNUM
)], 8);
579 /* restore all gpr's */
580 for (ii
=1; ii
<= 32; ++ii
) {
581 read_memory (sp
-256-(ii
*4), ®isters
[REGISTER_BYTE (32-ii
)], 4);
584 /* restore the rest of the registers. */
585 for (ii
=1; ii
<=(LAST_SP_REGNUM
-FIRST_SP_REGNUM
+1); ++ii
)
586 read_memory (sp
-384-(ii
*4),
587 ®isters
[REGISTER_BYTE (FPLAST_REGNUM
+ ii
)], 4);
589 read_memory (sp
-(DUMMY_FRAME_SIZE
-8),
590 ®isters
[REGISTER_BYTE(PC_REGNUM
)], 4);
592 /* when a dummy frame was being pushed, we had to decrement %sp first, in
593 order to secure astack space. Thus, saved %sp (or %r1) value, is not the
594 one we should restore. Change it with the one we need. */
596 memcpy (®isters
[REGISTER_BYTE(FP_REGNUM
)], (char *) &sp
, sizeof (int));
598 /* Now we can restore all registers. */
600 target_store_registers (-1);
602 flush_cached_frames ();
606 /* pop the innermost frame, go back to the caller. */
611 CORE_ADDR pc
, lr
, sp
, prev_sp
; /* %pc, %lr, %sp */
612 struct rs6000_framedata fdata
;
613 struct frame_info
*frame
= get_current_frame ();
617 sp
= FRAME_FP (frame
);
619 if (stop_stack_dummy
)
621 #ifdef USE_GENERIC_DUMMY_FRAMES
622 generic_pop_dummy_frame ();
623 flush_cached_frames ();
626 if (dummy_frame_count
)
632 /* Make sure that all registers are valid. */
633 read_register_bytes (0, NULL
, REGISTER_BYTES
);
635 /* figure out previous %pc value. If the function is frameless, it is
636 still in the link register, otherwise walk the frames and retrieve the
637 saved %pc value in the previous frame. */
639 addr
= get_pc_function_start (frame
->pc
) + FUNCTION_START_OFFSET
;
640 (void) skip_prologue (addr
, &fdata
);
645 prev_sp
= read_memory_integer (sp
, 4);
646 if (fdata
.lr_offset
== 0)
647 lr
= read_register (LR_REGNUM
);
649 lr
= read_memory_integer (prev_sp
+ fdata
.lr_offset
, 4);
651 /* reset %pc value. */
652 write_register (PC_REGNUM
, lr
);
654 /* reset register values if any was saved earlier. */
655 addr
= prev_sp
- fdata
.offset
;
657 if (fdata
.saved_gpr
!= -1)
658 for (ii
= fdata
.saved_gpr
; ii
<= 31; ++ii
) {
659 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
)], 4);
663 if (fdata
.saved_fpr
!= -1)
664 for (ii
= fdata
.saved_fpr
; ii
<= 31; ++ii
) {
665 read_memory (addr
, ®isters
[REGISTER_BYTE (ii
+FP0_REGNUM
)], 8);
669 write_register (SP_REGNUM
, prev_sp
);
670 target_store_registers (-1);
671 flush_cached_frames ();
674 /* fixup the call sequence of a dummy function, with the real function address.
675 its argumets will be passed by gdb. */
678 rs6000_fix_call_dummy (dummyname
, pc
, fun
, nargs
, args
, type
, gcc_p
)
687 #define TOC_ADDR_OFFSET 20
688 #define TARGET_ADDR_OFFSET 28
691 CORE_ADDR target_addr
;
693 if (find_toc_address_hook
!= NULL
)
697 tocvalue
= (*find_toc_address_hook
) (fun
);
698 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
);
699 ii
= (ii
& 0xffff0000) | (tocvalue
>> 16);
700 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
) = ii
;
702 ii
= *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4);
703 ii
= (ii
& 0xffff0000) | (tocvalue
& 0x0000ffff);
704 *(int*)((char*)dummyname
+ TOC_ADDR_OFFSET
+4) = ii
;
708 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
);
709 ii
= (ii
& 0xffff0000) | (target_addr
>> 16);
710 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
) = ii
;
712 ii
= *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4);
713 ii
= (ii
& 0xffff0000) | (target_addr
& 0x0000ffff);
714 *(int*)((char*)dummyname
+ TARGET_ADDR_OFFSET
+4) = ii
;
717 /* Pass the arguments in either registers, or in the stack. In RS6000,
718 the first eight words of the argument list (that might be less than
719 eight parameters if some parameters occupy more than one word) are
720 passed in r3..r11 registers. float and double parameters are
721 passed in fpr's, in addition to that. Rest of the parameters if any
722 are passed in user stack. There might be cases in which half of the
723 parameter is copied into registers, the other half is pushed into
726 If the function is returning a structure, then the return address is passed
727 in r3, then the first 7 words of the parameters can be passed in registers,
731 push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
736 CORE_ADDR struct_addr
;
740 int argno
; /* current argument number */
741 int argbytes
; /* current argument byte */
742 char tmp_buffer
[50];
743 int f_argno
= 0; /* current floating point argno */
750 #ifndef USE_GENERIC_DUMMY_FRAMES
751 if ( dummy_frame_count
<= 0)
752 printf_unfiltered ("FATAL ERROR -push_arguments()! frame not found!!\n");
753 #endif /* GENERIC_DUMMY_FRAMES */
755 /* The first eight words of ther arguments are passed in registers. Copy
758 If the function is returning a `struct', then the first word (which
759 will be passed in r3) is used for struct return address. In that
760 case we should advance one word and start from r4 register to copy
763 ii
= struct_return
? 1 : 0;
766 effectively indirect call... gcc does...
768 return_val example( float, int);
771 float in fp0, int in r3
772 offset of stack on overflow 8/16
773 for varargs, must go by type.
775 float in r3&r4, int in r5
776 offset of stack on overflow different
778 return in r3 or f0. If no float, must study how gcc emulates floats;
779 pay attention to arg promotion.
780 User may have to cast\args to handle promotion correctly
781 since gdb won't know if prototype supplied or not.
784 for (argno
=0, argbytes
=0; argno
< nargs
&& ii
<8; ++ii
) {
787 type
= check_typedef (VALUE_TYPE (arg
));
788 len
= TYPE_LENGTH (type
);
790 if (TYPE_CODE (type
) == TYPE_CODE_FLT
) {
792 /* floating point arguments are passed in fpr's, as well as gpr's.
793 There are 13 fpr's reserved for passing parameters. At this point
794 there is no way we would run out of them. */
798 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
800 memcpy (®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)],
801 VALUE_CONTENTS (arg
),
808 /* Argument takes more than one register. */
809 while (argbytes
< len
) {
810 memset (®isters
[REGISTER_BYTE(ii
+3)], 0, sizeof(int));
811 memcpy (®isters
[REGISTER_BYTE(ii
+3)],
812 ((char*)VALUE_CONTENTS (arg
))+argbytes
,
813 (len
- argbytes
) > 4 ? 4 : len
- argbytes
);
817 goto ran_out_of_registers_for_arguments
;
822 else { /* Argument can fit in one register. No problem. */
823 memset (®isters
[REGISTER_BYTE(ii
+3)], 0, sizeof(int));
824 memcpy (®isters
[REGISTER_BYTE(ii
+3)], VALUE_CONTENTS (arg
), len
);
829 ran_out_of_registers_for_arguments
:
831 #ifdef USE_GENERIC_DUMMY_FRAMES
832 saved_sp
= read_sp ();
834 /* location for 8 parameters are always reserved. */
837 /* another six words for back chain, TOC register, link register, etc. */
839 #endif /* GENERIC_DUMMY_FRAMES */
840 /* if there are more arguments, allocate space for them in
841 the stack, then push them starting from the ninth one. */
843 if ((argno
< nargs
) || argbytes
) {
847 space
+= ((len
- argbytes
+ 3) & -4);
853 for (; jj
< nargs
; ++jj
) {
854 value_ptr val
= args
[jj
];
855 space
+= ((TYPE_LENGTH (VALUE_TYPE (val
))) + 3) & -4;
858 /* add location required for the rest of the parameters */
859 space
= (space
+ 7) & -8;
862 /* This is another instance we need to be concerned about securing our
863 stack space. If we write anything underneath %sp (r1), we might conflict
864 with the kernel who thinks he is free to use this area. So, update %sp
865 first before doing anything else. */
867 write_register (SP_REGNUM
, sp
);
869 /* if the last argument copied into the registers didn't fit there
870 completely, push the rest of it into stack. */
873 write_memory (sp
+24+(ii
*4),
874 ((char*)VALUE_CONTENTS (arg
))+argbytes
,
877 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
880 /* push the rest of the arguments into stack. */
881 for (; argno
< nargs
; ++argno
) {
884 type
= check_typedef (VALUE_TYPE (arg
));
885 len
= TYPE_LENGTH (type
);
888 /* float types should be passed in fpr's, as well as in the stack. */
889 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& f_argno
< 13) {
893 "Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno
);
895 memcpy (®isters
[REGISTER_BYTE(FP0_REGNUM
+ 1 + f_argno
)],
896 VALUE_CONTENTS (arg
),
901 write_memory (sp
+24+(ii
*4), (char *) VALUE_CONTENTS (arg
), len
);
902 ii
+= ((len
+ 3) & -4) / 4;
906 /* Secure stack areas first, before doing anything else. */
907 write_register (SP_REGNUM
, sp
);
909 #ifndef USE_GENERIC_DUMMY_FRAMES
910 /* we want to copy 24 bytes of target's frame to dummy's frame,
911 then set back chain to point to new frame. */
913 saved_sp
= dummy_frame_addr
[dummy_frame_count
- 1];
914 read_memory (saved_sp
, tmp_buffer
, 24);
915 write_memory (sp
, tmp_buffer
, 24);
916 #endif /* GENERIC_DUMMY_FRAMES */
918 /* set back chain properly */
919 store_address (tmp_buffer
, 4, saved_sp
);
920 write_memory (sp
, tmp_buffer
, 4);
922 target_store_registers (-1);
925 #ifdef ELF_OBJECT_FORMAT
927 /* Function: ppc_push_return_address (pc, sp)
928 Set up the return address for the inferior function call. */
931 ppc_push_return_address (pc
, sp
)
935 write_register (LR_REGNUM
, CALL_DUMMY_ADDRESS ());
941 /* a given return value in `regbuf' with a type `valtype', extract and copy its
942 value into `valbuf' */
945 extract_return_value (valtype
, regbuf
, valbuf
)
946 struct type
*valtype
;
947 char regbuf
[REGISTER_BYTES
];
952 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
) {
955 /* floats and doubles are returned in fpr1. fpr's have a size of 8 bytes.
956 We need to truncate the return value into float size (4 byte) if
959 if (TYPE_LENGTH (valtype
) > 4) /* this is a double */
961 ®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)],
962 TYPE_LENGTH (valtype
));
964 memcpy (&dd
, ®buf
[REGISTER_BYTE (FP0_REGNUM
+ 1)], 8);
966 memcpy (valbuf
, &ff
, sizeof(float));
970 /* return value is copied starting from r3. */
971 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
972 && TYPE_LENGTH (valtype
) < REGISTER_RAW_SIZE (3))
973 offset
= REGISTER_RAW_SIZE (3) - TYPE_LENGTH (valtype
);
976 regbuf
+ REGISTER_BYTE (3) + offset
,
977 TYPE_LENGTH (valtype
));
982 /* keep structure return address in this variable.
983 FIXME: This is a horrid kludge which should not be allowed to continue
984 living. This only allows a single nested call to a structure-returning
985 function. Come on, guys! -- gnu@cygnus.com, Aug 92 */
987 CORE_ADDR rs6000_struct_return_address
;
990 /* Indirect function calls use a piece of trampoline code to do context
991 switching, i.e. to set the new TOC table. Skip such code if we are on
992 its first instruction (as when we have single-stepped to here).
993 Also skip shared library trampoline code (which is different from
994 indirect function call trampolines).
995 Result is desired PC to step until, or NULL if we are not in
999 skip_trampoline_code (pc
)
1002 register unsigned int ii
, op
;
1003 CORE_ADDR solib_target_pc
;
1005 static unsigned trampoline_code
[] = {
1006 0x800b0000, /* l r0,0x0(r11) */
1007 0x90410014, /* st r2,0x14(r1) */
1008 0x7c0903a6, /* mtctr r0 */
1009 0x804b0004, /* l r2,0x4(r11) */
1010 0x816b0008, /* l r11,0x8(r11) */
1011 0x4e800420, /* bctr */
1012 0x4e800020, /* br */
1016 /* If pc is in a shared library trampoline, return its target. */
1017 solib_target_pc
= find_solib_trampoline_target (pc
);
1018 if (solib_target_pc
)
1019 return solib_target_pc
;
1021 for (ii
=0; trampoline_code
[ii
]; ++ii
) {
1022 op
= read_memory_integer (pc
+ (ii
*4), 4);
1023 if (op
!= trampoline_code
[ii
])
1026 ii
= read_register (11); /* r11 holds destination addr */
1027 pc
= read_memory_integer (ii
, 4); /* (r11) value */
1031 /* Determines whether the function FI has a frame on the stack or not. */
1034 frameless_function_invocation (fi
)
1035 struct frame_info
*fi
;
1037 CORE_ADDR func_start
;
1038 struct rs6000_framedata fdata
;
1040 /* Don't even think about framelessness except on the innermost frame
1041 or if the function was interrupted by a signal. */
1042 if (fi
->next
!= NULL
&& !fi
->next
->signal_handler_caller
)
1045 func_start
= get_pc_function_start (fi
->pc
);
1047 /* If we failed to find the start of the function, it is a mistake
1048 to inspect the instructions. */
1052 /* A frame with a zero PC is usually created by dereferencing a NULL
1053 function pointer, normally causing an immediate core dump of the
1054 inferior. Mark function as frameless, as the inferior has no chance
1055 of setting up a stack frame. */
1062 func_start
+= FUNCTION_START_OFFSET
;
1063 (void) skip_prologue (func_start
, &fdata
);
1064 return fdata
.frameless
;
1067 /* Return the PC saved in a frame */
1071 struct frame_info
*fi
;
1073 CORE_ADDR func_start
;
1074 struct rs6000_framedata fdata
;
1076 if (fi
->signal_handler_caller
)
1077 return read_memory_integer (fi
->frame
+ SIG_FRAME_PC_OFFSET
, 4);
1079 #ifdef USE_GENERIC_DUMMY_FRAMES
1080 if (PC_IN_CALL_DUMMY (fi
->pc
, fi
->frame
, fi
->frame
))
1081 return generic_read_register_dummy(fi
->pc
, fi
->frame
, PC_REGNUM
);
1082 #endif /* GENERIC_DUMMY_FRAMES */
1084 func_start
= get_pc_function_start (fi
->pc
) + FUNCTION_START_OFFSET
;
1086 /* If we failed to find the start of the function, it is a mistake
1087 to inspect the instructions. */
1091 (void) skip_prologue (func_start
, &fdata
);
1093 if (fdata
.lr_offset
== 0 && fi
->next
!= NULL
)
1095 if (fi
->next
->signal_handler_caller
)
1096 return read_memory_integer (fi
->next
->frame
+ SIG_FRAME_LR_OFFSET
, 4);
1098 return read_memory_integer (rs6000_frame_chain (fi
) + DEFAULT_LR_SAVE
,
1102 if (fdata
.lr_offset
== 0)
1103 return read_register (LR_REGNUM
);
1105 return read_memory_integer (rs6000_frame_chain (fi
) + fdata
.lr_offset
, 4);
1108 /* If saved registers of frame FI are not known yet, read and cache them.
1109 &FDATAP contains rs6000_framedata; TDATAP can be NULL,
1110 in which case the framedata are read. */
1113 frame_get_cache_fsr (fi
, fdatap
)
1114 struct frame_info
*fi
;
1115 struct rs6000_framedata
*fdatap
;
1118 CORE_ADDR frame_addr
;
1119 struct rs6000_framedata work_fdata
;
1124 if (fdatap
== NULL
) {
1125 fdatap
= &work_fdata
;
1126 (void) skip_prologue (get_pc_function_start (fi
->pc
), fdatap
);
1129 fi
->cache_fsr
= (struct frame_saved_regs
*)
1130 obstack_alloc (&frame_cache_obstack
, sizeof (struct frame_saved_regs
));
1131 memset (fi
->cache_fsr
, '\0', sizeof (struct frame_saved_regs
));
1133 if (fi
->prev
&& fi
->prev
->frame
)
1134 frame_addr
= fi
->prev
->frame
;
1136 frame_addr
= read_memory_integer (fi
->frame
, 4);
1138 /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
1139 All fpr's from saved_fpr to fp31 are saved. */
1141 if (fdatap
->saved_fpr
>= 0) {
1142 int fpr_offset
= frame_addr
+ fdatap
->fpr_offset
;
1143 for (ii
= fdatap
->saved_fpr
; ii
< 32; ii
++) {
1144 fi
->cache_fsr
->regs
[FP0_REGNUM
+ ii
] = fpr_offset
;
1149 /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
1150 All gpr's from saved_gpr to gpr31 are saved. */
1152 if (fdatap
->saved_gpr
>= 0) {
1153 int gpr_offset
= frame_addr
+ fdatap
->gpr_offset
;
1154 for (ii
= fdatap
->saved_gpr
; ii
< 32; ii
++) {
1155 fi
->cache_fsr
->regs
[ii
] = gpr_offset
;
1160 /* If != 0, fdatap->cr_offset is the offset from the frame that holds
1162 if (fdatap
->cr_offset
!= 0)
1163 fi
->cache_fsr
->regs
[CR_REGNUM
] = frame_addr
+ fdatap
->cr_offset
;
1165 /* If != 0, fdatap->lr_offset is the offset from the frame that holds
1167 if (fdatap
->lr_offset
!= 0)
1168 fi
->cache_fsr
->regs
[LR_REGNUM
] = frame_addr
+ fdatap
->lr_offset
;
1171 /* Return the address of a frame. This is the inital %sp value when the frame
1172 was first allocated. For functions calling alloca(), it might be saved in
1173 an alloca register. */
1176 frame_initial_stack_address (fi
)
1177 struct frame_info
*fi
;
1180 struct rs6000_framedata fdata
;
1181 struct frame_info
*callee_fi
;
1183 /* if the initial stack pointer (frame address) of this frame is known,
1187 return fi
->initial_sp
;
1189 /* find out if this function is using an alloca register.. */
1191 (void) skip_prologue (get_pc_function_start (fi
->pc
), &fdata
);
1193 /* if saved registers of this frame are not known yet, read and cache them. */
1196 frame_get_cache_fsr (fi
, &fdata
);
1198 /* If no alloca register used, then fi->frame is the value of the %sp for
1199 this frame, and it is good enough. */
1201 if (fdata
.alloca_reg
< 0) {
1202 fi
->initial_sp
= fi
->frame
;
1203 return fi
->initial_sp
;
1206 /* This function has an alloca register. If this is the top-most frame
1207 (with the lowest address), the value in alloca register is good. */
1210 return fi
->initial_sp
= read_register (fdata
.alloca_reg
);
1212 /* Otherwise, this is a caller frame. Callee has usually already saved
1213 registers, but there are exceptions (such as when the callee
1214 has no parameters). Find the address in which caller's alloca
1215 register is saved. */
1217 for (callee_fi
= fi
->next
; callee_fi
; callee_fi
= callee_fi
->next
) {
1219 if (!callee_fi
->cache_fsr
)
1220 frame_get_cache_fsr (callee_fi
, NULL
);
1222 /* this is the address in which alloca register is saved. */
1224 tmpaddr
= callee_fi
->cache_fsr
->regs
[fdata
.alloca_reg
];
1226 fi
->initial_sp
= read_memory_integer (tmpaddr
, 4);
1227 return fi
->initial_sp
;
1230 /* Go look into deeper levels of the frame chain to see if any one of
1231 the callees has saved alloca register. */
1234 /* If alloca register was not saved, by the callee (or any of its callees)
1235 then the value in the register is still good. */
1237 return fi
->initial_sp
= read_register (fdata
.alloca_reg
);
1241 rs6000_frame_chain (thisframe
)
1242 struct frame_info
*thisframe
;
1246 #ifdef USE_GENERIC_DUMMY_FRAMES
1247 if (PC_IN_CALL_DUMMY (thisframe
->pc
, thisframe
->frame
, thisframe
->frame
))
1248 return thisframe
->frame
; /* dummy frame same as caller's frame */
1249 #endif /* GENERIC_DUMMY_FRAMES */
1251 if (inside_entry_file (thisframe
->pc
) ||
1252 thisframe
->pc
== entry_point_address ())
1255 if (thisframe
->signal_handler_caller
)
1256 fp
= read_memory_integer (thisframe
->frame
+ SIG_FRAME_FP_OFFSET
, 4);
1257 else if (thisframe
->next
!= NULL
1258 && thisframe
->next
->signal_handler_caller
1259 && frameless_function_invocation (thisframe
))
1260 /* A frameless function interrupted by a signal did not change the
1262 fp
= FRAME_FP (thisframe
);
1264 fp
= read_memory_integer ((thisframe
)->frame
, 4);
1266 #ifdef USE_GENERIC_DUMMY_FRAMES
1270 lr
= read_register (LR_REGNUM
);
1271 if (lr
== entry_point_address ())
1272 if (fp
!= 0 && (fpp
= read_memory_integer (fp
, 4)) != 0)
1273 if (PC_IN_CALL_DUMMY (lr
, fpp
, fpp
))
1276 #endif /* GENERIC_DUMMY_FRAMES */
1280 /* Return nonzero if ADDR (a function pointer) is in the data space and
1281 is therefore a special function pointer. */
1284 is_magic_function_pointer (addr
)
1287 struct obj_section
*s
;
1289 s
= find_pc_section (addr
);
1290 if (s
&& s
->the_bfd_section
->flags
& SEC_CODE
)
1296 #ifdef GDB_TARGET_POWERPC
1298 gdb_print_insn_powerpc (memaddr
, info
)
1300 disassemble_info
*info
;
1302 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1303 return print_insn_big_powerpc (memaddr
, info
);
1305 return print_insn_little_powerpc (memaddr
, info
);
1309 /* Function: get_saved_register
1310 Just call the generic_get_saved_register function. */
1312 #ifdef USE_GENERIC_DUMMY_FRAMES
1314 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
1318 struct frame_info
*frame
;
1320 enum lval_type
*lval
;
1322 generic_get_saved_register (raw_buffer
, optimized
, addrp
,
1323 frame
, regnum
, lval
);
1329 _initialize_rs6000_tdep ()
1331 /* FIXME, this should not be decided via ifdef. */
1332 #ifdef GDB_TARGET_POWERPC
1333 tm_print_insn
= gdb_print_insn_powerpc
;
1335 tm_print_insn
= print_insn_rs6000
;