Replace "exec" with "executable" in messages.
[deliverable/binutils-gdb.git] / gdb / rs6000-tdep.c
CommitLineData
41abdfbd 1/* Target-dependent code for GDB, the GNU debugger.
211b564e 2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
07aa9fdc 3 Free Software Foundation, Inc.
41abdfbd
JG
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
41abdfbd 20
41abdfbd 21#include "defs.h"
0ec1e44d 22#include "tm.h"
41abdfbd
JG
23#include "frame.h"
24#include "inferior.h"
25#include "symtab.h"
26#include "target.h"
030fb5cb 27#include "gdbcore.h"
65eaea27
JL
28#include "symfile.h"
29#include "objfiles.h"
2aefe6e4
JK
30#include "xcoffsolib.h"
31
d6434f39
JG
32extern struct obstack frame_cache_obstack;
33
41abdfbd 34extern int errno;
41abdfbd
JG
35
36/* Nonzero if we just simulated a single step break. */
37int one_stepped;
38
41abdfbd
JG
39/* Breakpoint shadows for the single step instructions will be kept here. */
40
41static struct sstep_breaks {
030fb5cb
JK
42 /* Address, or 0 if this is not in use. */
43 CORE_ADDR address;
44 /* Shadow contents. */
45 char data[4];
41abdfbd
JG
46} stepBreaks[2];
47
05d52ace
PS
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. */
51
52CORE_ADDR (*find_toc_address_hook) PARAMS ((CORE_ADDR)) = NULL;
ecf4059f 53
05d52ace 54/* Static function prototypes */
ecf4059f 55
cd8a3d84
SS
56static CORE_ADDR branch_dest PARAMS ((int opcode, int instr, CORE_ADDR pc,
57 CORE_ADDR safety));
ecf4059f 58
cd8a3d84
SS
59static void frame_get_cache_fsr PARAMS ((struct frame_info *fi,
60 struct rs6000_framedata *fdatap));
61
368f1e77
FF
62static void pop_dummy_frame PARAMS ((void));
63
cd8a3d84 64/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
41abdfbd 65
ecf4059f 66static CORE_ADDR
41abdfbd 67branch_dest (opcode, instr, pc, safety)
ecf4059f
JG
68 int opcode;
69 int instr;
70 CORE_ADDR pc;
71 CORE_ADDR safety;
41abdfbd 72{
ecf4059f 73 CORE_ADDR dest;
41abdfbd
JG
74 int immediate;
75 int absolute;
76 int ext_op;
77
78 absolute = (int) ((instr >> 1) & 1);
79
80 switch (opcode) {
81 case 18 :
ecf4059f 82 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
dc59e982
MM
83 if (absolute)
84 dest = immediate;
85 else
86 dest = pc + immediate;
87 break;
41abdfbd
JG
88
89 case 16 :
dc59e982 90 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
41abdfbd
JG
91 if (absolute)
92 dest = immediate;
93 else
94 dest = pc + immediate;
95 break;
96
97 case 19 :
98 ext_op = (instr>>1) & 0x3ff;
99
100 if (ext_op == 16) /* br conditional register */
0c6c5eeb
PS
101 {
102 dest = read_register (LR_REGNUM) & ~3;
103
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)
109 {
110 struct frame_info *fi;
111
112 fi = get_current_frame ();
113 if (fi != NULL)
114 dest = read_memory_integer (fi->frame + SIG_FRAME_PC_OFFSET,
115 4);
116 }
117 }
41abdfbd
JG
118
119 else if (ext_op == 528) /* br cond to count reg */
9aa31e91
JK
120 {
121 dest = read_register (CTR_REGNUM) & ~3;
122
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;
128 }
41abdfbd
JG
129 else return -1;
130 break;
131
132 default: return -1;
133 }
818de002 134 return (dest < TEXT_SEGMENT_BASE) ? safety : dest;
41abdfbd
JG
135}
136
137
138
139/* AIX does not support PT_STEP. Simulate it. */
140
997cc2c0 141void
41abdfbd 142single_step (signal)
b607efe7 143 enum target_signal signal;
41abdfbd
JG
144{
145#define INSNLEN(OPCODE) 4
146
5c172b4b
MM
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;
030fb5cb
JK
150 int ii, insn;
151 CORE_ADDR loc;
152 CORE_ADDR breaks[2];
153 int opcode;
41abdfbd
JG
154
155 if (!one_stepped) {
41abdfbd
JG
156 loc = read_pc ();
157
b112f2ae 158 insn = read_memory_integer (loc, 4);
41abdfbd
JG
159
160 breaks[0] = loc + INSNLEN(insn);
161 opcode = insn >> 26;
162 breaks[1] = branch_dest (opcode, insn, loc, breaks[0]);
163
818de002
PB
164 /* Don't put two breakpoints on the same address. */
165 if (breaks[1] == breaks[0])
166 breaks[1] = -1;
167
030fb5cb 168 stepBreaks[1].address = 0;
41abdfbd
JG
169
170 for (ii=0; ii < 2; ++ii) {
171
172 /* ignore invalid breakpoint. */
173 if ( breaks[ii] == -1)
174 continue;
175
030fb5cb 176 read_memory (breaks[ii], stepBreaks[ii].data, 4);
41abdfbd 177
030fb5cb 178 write_memory (breaks[ii], breakp, 4);
41abdfbd
JG
179 stepBreaks[ii].address = breaks[ii];
180 }
181
182 one_stepped = 1;
997cc2c0 183 } else {
41abdfbd
JG
184
185 /* remove step breakpoints. */
186 for (ii=0; ii < 2; ++ii)
030fb5cb 187 if (stepBreaks[ii].address != 0)
41abdfbd 188 write_memory
030fb5cb 189 (stepBreaks[ii].address, stepBreaks[ii].data, 4);
41abdfbd
JG
190
191 one_stepped = 0;
192 }
997cc2c0 193 errno = 0; /* FIXME, don't ignore errors! */
030fb5cb 194 /* What errors? {read,write}_memory call error(). */
41abdfbd 195}
41abdfbd
JG
196
197
068c9fd6
MM
198/* return pc value after skipping a function prologue and also return
199 information about a function frame.
41abdfbd 200
068c9fd6
MM
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.
208 Otherwise -1.
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
213 */
214
215#define SIGNED_SHORT(x) \
216 ((sizeof (short) == 2) \
217 ? ((int)(short)(x)) \
218 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
219
220#define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
221
222CORE_ADDR
223skip_prologue (pc, fdata)
224 CORE_ADDR pc;
225 struct rs6000_framedata *fdata;
41abdfbd 226{
068c9fd6 227 CORE_ADDR orig_pc = pc;
34df79fc 228 char buf[4];
34df79fc 229 unsigned long op;
4b4c6c96 230 long offset = 0;
068c9fd6
MM
231 int lr_reg = 0;
232 int cr_reg = 0;
233 int reg;
4b4c6c96 234 int framep = 0;
65eaea27 235 int minimal_toc_loaded = 0;
068c9fd6
MM
236 static struct rs6000_framedata zero_frame;
237
238 *fdata = 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;
41abdfbd 244
34df79fc 245 if (target_read_memory (pc, buf, 4))
41abdfbd 246 return pc; /* Can't access it -- assume no prologue. */
41abdfbd
JG
247
248 /* Assume that subsequent fetches can fail with low probability. */
068c9fd6
MM
249 pc -= 4;
250 for (;;)
251 {
252 pc += 4;
253 op = read_memory_integer (pc, 4);
41abdfbd 254
068c9fd6
MM
255 if ((op & 0xfc1fffff) == 0x7c0802a6) { /* mflr Rx */
256 lr_reg = (op & 0x03e00000) | 0x90010000;
257 continue;
258
259 } else if ((op & 0xfc1fffff) == 0x7c000026) { /* mfcr Rx */
260 cr_reg = (op & 0x03e00000) | 0x90010000;
261 continue;
262
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;
4b4c6c96 267 fdata->fpr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
268 }
269 continue;
270
271 } else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
75621b2b
MS
272 ((op & 0xfc1f0000) == 0x90010000 && /* st rx,NUM(r1),
273 rx >= r13 */
068c9fd6
MM
274 (op & 0x03e00000) >= 0x01a00000)) {
275
276 reg = GET_SRC_REG (op);
277 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg) {
278 fdata->saved_gpr = reg;
4b4c6c96 279 fdata->gpr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
280 }
281 continue;
282
75621b2b
MS
283 } else if ((op & 0xffff0000) == 0x3c000000) { /* addis 0,0,NUM, used
284 for >= 32k frames */
068c9fd6 285 fdata->offset = (op & 0x0000ffff) << 16;
65eaea27 286 fdata->frameless = 0;
068c9fd6
MM
287 continue;
288
75621b2b
MS
289 } else if ((op & 0xffff0000) == 0x60000000) { /* ori 0,0,NUM, 2nd ha
290 lf of >= 32k frames */
068c9fd6 291 fdata->offset |= (op & 0x0000ffff);
65eaea27 292 fdata->frameless = 0;
068c9fd6
MM
293 continue;
294
75621b2b
MS
295 } else if ((op & 0xffff0000) == lr_reg) { /* st Rx,NUM(r1)
296 where Rx == lr */
4b4c6c96 297 fdata->lr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
298 fdata->nosavedpc = 0;
299 lr_reg = 0;
300 continue;
301
75621b2b
MS
302 } else if ((op & 0xffff0000) == cr_reg) { /* st Rx,NUM(r1)
303 where Rx == cr */
4b4c6c96 304 fdata->cr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
305 cr_reg = 0;
306 continue;
307
75621b2b
MS
308 } else if (op == 0x48000005) { /* bl .+4 used in
309 -mrelocatable */
4b4c6c96
MM
310 continue;
311
65eaea27
JL
312 } else if (op == 0x48000004) { /* b .+4 (xlc) */
313 break;
314
75621b2b
MS
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 */
4b4c6c96
MM
319 lr_reg == 0x901e0000) {
320 continue;
321
75621b2b
MS
322 } else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used
323 in V.4 -mminimal-toc */
4b4c6c96
MM
324 (op & 0xffff0000) == 0x3bde0000) { /* addi 30,30,foo@l */
325 continue;
326
75621b2b
MS
327 } else if ((op & 0xfc000000) == 0x48000000) { /* bl foo,
328 to save fprs??? */
965dde97 329
65eaea27 330 fdata->frameless = 0;
965dde97
PS
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)
334 break;
335
068c9fd6
MM
336 op = read_memory_integer (pc+4, 4);
337
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
341 prologue. */
342
343 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */
75621b2b
MS
344 break; /* don't skip over
345 this branch */
068c9fd6
MM
346 continue;
347
4b4c6c96 348 /* update stack pointer */
068c9fd6 349 } else if ((op & 0xffff0000) == 0x94210000) { /* stu r1,NUM(r1) */
65eaea27 350 fdata->frameless = 0;
4b4c6c96
MM
351 fdata->offset = SIGNED_SHORT (op);
352 offset = fdata->offset;
353 continue;
1eeba686 354
068c9fd6 355 } else if (op == 0x7c21016e) { /* stwux 1,1,0 */
65eaea27 356 fdata->frameless = 0;
4b4c6c96
MM
357 offset = fdata->offset;
358 continue;
41abdfbd 359
4b4c6c96 360 /* Load up minimal toc pointer */
65eaea27
JL
361 } else if ((op >> 22) == 0x20f
362 && ! minimal_toc_loaded) { /* l r31,... or l r30,... */
363 minimal_toc_loaded = 1;
4b4c6c96 364 continue;
cdb1cc92 365
4b4c6c96
MM
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) */
370 continue;
e137e850 371
4b4c6c96
MM
372 /* store parameters in stack via frame pointer */
373 } else if (framep &&
58b4fad2 374 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r1) */
4b4c6c96 375 (op & 0xfc1f0000) == 0xd81f0000 || /* stfd Rx,NUM(r1) */
58b4fad2 376 (op & 0xfc1f0000) == 0xfc1f0000)) { /* frsp, fp?,NUM(r1) */
4b4c6c96 377 continue;
e137e850 378
4b4c6c96
MM
379 /* Set up frame pointer */
380 } else if (op == 0x603f0000 /* oril r31, r1, 0x0 */
381 || op == 0x7c3f0b78) { /* mr r31, r1 */
65eaea27 382 fdata->frameless = 0;
4b4c6c96 383 framep = 1;
965dde97 384 fdata->alloca_reg = 31;
4b4c6c96 385 continue;
41abdfbd 386
65eaea27
JL
387 /* Another way to set up the frame pointer. */
388 } else if ((op & 0xfc1fffff) == 0x38010000) { /* addi rX, r1, 0x0 */
389 fdata->frameless = 0;
390 framep = 1;
391 fdata->alloca_reg = (op & ~0x38010000) >> 21;
392 continue;
393
4b4c6c96
MM
394 } else {
395 break;
396 }
41abdfbd 397 }
068c9fd6 398
507e4004
PB
399#if 0
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 */
403
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. */
409
410
411 if ((op & 0xfc000001) == 0x48000001) { /* bl foo, an initializer function? */
412 op = read_memory_integer (pc+4, 4);
413
414 if (op == 0x4def7b82) { /* cror 0xf, 0xf, 0xf (nop) */
415
416 /* check and see if we are in main. If so, skip over this initializer
417 function as well. */
418
419 tmp = find_pc_misc_function (pc);
2e4964ad 420 if (tmp >= 0 && STREQ (misc_function_vector [tmp].name, "main"))
507e4004
PB
421 return pc + 8;
422 }
423 }
424#endif /* 0 */
425
4b4c6c96 426 fdata->offset = - fdata->offset;
41abdfbd
JG
427 return pc;
428}
429
818de002 430
41abdfbd
JG
431/*************************************************************************
432 Support for creating pushind a dummy frame into the stack, and popping
433 frames, etc.
434*************************************************************************/
435
818de002
PB
436/* The total size of dummy frame is 436, which is;
437
438 32 gpr's - 128 bytes
439 32 fpr's - 256 "
440 7 the rest - 28 "
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(). */
444
445#define DUMMY_FRAME_SIZE 436
446
41abdfbd
JG
447#define DUMMY_FRAME_ADDR_SIZE 10
448
449/* Make sure you initialize these in somewhere, in case gdb gives up what it
818de002 450 was debugging and starts debugging something else. FIXMEibm */
41abdfbd
JG
451
452static int dummy_frame_count = 0;
453static int dummy_frame_size = 0;
454static CORE_ADDR *dummy_frame_addr = 0;
455
456extern int stop_stack_dummy;
457
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 */
460
ecf4059f 461void
41abdfbd
JG
462push_dummy_frame ()
463{
359a097f
JK
464 /* stack pointer. */
465 CORE_ADDR sp;
b112f2ae
JK
466 /* Same thing, target byte order. */
467 char sp_targ[4];
359a097f
JK
468
469 /* link register. */
470 CORE_ADDR pc;
471 /* Same thing, target byte order. */
472 char pc_targ[4];
473
3a4f9786
MT
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;
477
41abdfbd
JG
478 int ii;
479
5f1c39ef 480 target_fetch_registers (-1);
6c6afbb9 481
41abdfbd
JG
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));
487 else
488 dummy_frame_addr = (CORE_ADDR*)
489 xmalloc (sizeof(CORE_ADDR) * (dummy_frame_size));
490 }
491
492 sp = read_register(SP_REGNUM);
359a097f 493 pc = read_register(PC_REGNUM);
5816555b 494 store_address (pc_targ, 4, pc);
41abdfbd 495
75621b2b 496 skip_prologue (get_pc_function_start (pc) + FUNCTION_START_OFFSET, &fdata);
3a4f9786 497
41abdfbd
JG
498 dummy_frame_addr [dummy_frame_count++] = sp;
499
500 /* Be careful! If the stack pointer is not decremented first, then kernel
6c6afbb9 501 thinks he is free to use the space underneath it. And kernel actually
41abdfbd
JG
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. */
505
3a4f9786
MT
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. */
509
818de002 510 write_register (SP_REGNUM, sp-DUMMY_FRAME_SIZE);
41abdfbd 511
41abdfbd
JG
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! */
514
515 flush_cached_frames ();
41abdfbd
JG
516
517 /* save program counter in link register's space. */
4f8710e6
PS
518 write_memory (sp + (fdata.lr_offset ? fdata.lr_offset : DEFAULT_LR_SAVE),
519 pc_targ, 4);
41abdfbd 520
6c6afbb9 521 /* save all floating point and general purpose registers here. */
41abdfbd
JG
522
523 /* fpr's, f0..f31 */
524 for (ii = 0; ii < 32; ++ii)
525 write_memory (sp-8-(ii*8), &registers[REGISTER_BYTE (31-ii+FP0_REGNUM)], 8);
526
527 /* gpr's r0..r31 */
528 for (ii=1; ii <=32; ++ii)
529 write_memory (sp-256-(ii*4), &registers[REGISTER_BYTE (32-ii)], 4);
530
818de002
PB
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 */
533
534 for (ii=1; ii <= (LAST_SP_REGNUM-FIRST_SP_REGNUM+1); ++ii) {
535 write_memory (sp-384-(ii*4),
75621b2b 536 &registers[REGISTER_BYTE (FPLAST_REGNUM + ii)], 4);
818de002
PB
537 }
538
539 /* Save sp or so called back chain right here. */
b112f2ae
JK
540 store_address (sp_targ, 4, sp);
541 write_memory (sp-DUMMY_FRAME_SIZE, sp_targ, 4);
818de002 542 sp -= DUMMY_FRAME_SIZE;
41abdfbd
JG
543
544 /* And finally, this is the back chain. */
359a097f 545 write_memory (sp+8, pc_targ, 4);
41abdfbd
JG
546}
547
548
549/* Pop a dummy frame.
550
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.
553
818de002
PB
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).
ecf4059f
JG
561
562FIXME: This whole concept is broken. You should be able to detect
563a dummy stack frame *on the user's stack itself*. When you do,
564then you know the format of that stack frame -- including its
565saved SP register! There should *not* be a separate stack in the
d6434f39 566GDB process that keeps track of these dummy frames! -- gnu@cygnus.com Aug92
41abdfbd
JG
567 */
568
368f1e77 569static void
41abdfbd
JG
570pop_dummy_frame ()
571{
572 CORE_ADDR sp, pc;
573 int ii;
574 sp = dummy_frame_addr [--dummy_frame_count];
575
576 /* restore all fpr's. */
577 for (ii = 1; ii <= 32; ++ii)
578 read_memory (sp-(ii*8), &registers[REGISTER_BYTE (32-ii+FP0_REGNUM)], 8);
579
580 /* restore all gpr's */
581 for (ii=1; ii <= 32; ++ii) {
582 read_memory (sp-256-(ii*4), &registers[REGISTER_BYTE (32-ii)], 4);
583 }
584
818de002
PB
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 &registers[REGISTER_BYTE (FPLAST_REGNUM + ii)], 4);
589
590 read_memory (sp-(DUMMY_FRAME_SIZE-8),
3a4f9786 591 &registers [REGISTER_BYTE(PC_REGNUM)], 4);
41abdfbd
JG
592
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. */
596
75621b2b 597 memcpy (&registers [REGISTER_BYTE(FP_REGNUM)], (char *) &sp, sizeof (int));
41abdfbd
JG
598
599 /* Now we can restore all registers. */
600
5f1c39ef 601 target_store_registers (-1);
41abdfbd
JG
602 pc = read_pc ();
603 flush_cached_frames ();
41abdfbd
JG
604}
605
606
607/* pop the innermost frame, go back to the caller. */
608
ecf4059f 609void
41abdfbd
JG
610pop_frame ()
611{
359a097f 612 CORE_ADDR pc, lr, sp, prev_sp; /* %pc, %lr, %sp */
63641491 613 struct rs6000_framedata fdata;
669caa9c 614 struct frame_info *frame = get_current_frame ();
41abdfbd 615 int addr, ii;
41abdfbd
JG
616
617 pc = read_pc ();
669caa9c 618 sp = FRAME_FP (frame);
41abdfbd 619
0ec1e44d
MA
620 if (stop_stack_dummy)
621 {
622#ifdef USE_GENERIC_DUMMY_FRAMES
623 generic_pop_dummy_frame ();
624 flush_cached_frames ();
625 return;
626#else
627 if (dummy_frame_count)
628 pop_dummy_frame ();
629 return;
630#endif
631 }
41abdfbd 632
07aa9fdc
PS
633 /* Make sure that all registers are valid. */
634 read_register_bytes (0, NULL, REGISTER_BYTES);
635
41abdfbd
JG
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. */
639
34a1a3bf 640 addr = get_pc_function_start (frame->pc) + FUNCTION_START_OFFSET;
068c9fd6 641 (void) skip_prologue (addr, &fdata);
41abdfbd 642
6c6afbb9 643 if (fdata.frameless)
07aa9fdc
PS
644 prev_sp = sp;
645 else
646 prev_sp = read_memory_integer (sp, 4);
068c9fd6 647 if (fdata.lr_offset == 0)
41abdfbd
JG
648 lr = read_register (LR_REGNUM);
649 else
068c9fd6 650 lr = read_memory_integer (prev_sp + fdata.lr_offset, 4);
41abdfbd
JG
651
652 /* reset %pc value. */
653 write_register (PC_REGNUM, lr);
654
655 /* reset register values if any was saved earlier. */
6c6afbb9 656 addr = prev_sp - fdata.offset;
41abdfbd 657
6c6afbb9 658 if (fdata.saved_gpr != -1)
669caa9c 659 for (ii = fdata.saved_gpr; ii <= 31; ++ii) {
41abdfbd 660 read_memory (addr, &registers [REGISTER_BYTE (ii)], 4);
cdb1cc92 661 addr += 4;
41abdfbd
JG
662 }
663
6c6afbb9 664 if (fdata.saved_fpr != -1)
669caa9c 665 for (ii = fdata.saved_fpr; ii <= 31; ++ii) {
41abdfbd
JG
666 read_memory (addr, &registers [REGISTER_BYTE (ii+FP0_REGNUM)], 8);
667 addr += 8;
668 }
669
670 write_register (SP_REGNUM, prev_sp);
5f1c39ef 671 target_store_registers (-1);
41abdfbd 672 flush_cached_frames ();
41abdfbd
JG
673}
674
41abdfbd
JG
675/* fixup the call sequence of a dummy function, with the real function address.
676 its argumets will be passed by gdb. */
677
ecf4059f 678void
2f163bc3 679rs6000_fix_call_dummy (dummyname, pc, fun, nargs, args, type, gcc_p)
cd8a3d84
SS
680 char *dummyname;
681 CORE_ADDR pc;
682 CORE_ADDR fun;
2f163bc3
SS
683 int nargs;
684 value_ptr *args;
685 struct type *type;
686 int gcc_p;
41abdfbd
JG
687{
688#define TOC_ADDR_OFFSET 20
689#define TARGET_ADDR_OFFSET 28
690
691 int ii;
ecf4059f 692 CORE_ADDR target_addr;
41abdfbd 693
05d52ace
PS
694 if (find_toc_address_hook != NULL)
695 {
696 CORE_ADDR tocvalue;
41abdfbd 697
05d52ace
PS
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;
41abdfbd 702
05d52ace
PS
703 ii = *(int*)((char*)dummyname + TOC_ADDR_OFFSET+4);
704 ii = (ii & 0xffff0000) | (tocvalue & 0x0000ffff);
705 *(int*)((char*)dummyname + TOC_ADDR_OFFSET+4) = ii;
706 }
41abdfbd 707
05d52ace 708 target_addr = fun;
41abdfbd
JG
709 ii = *(int*)((char*)dummyname + TARGET_ADDR_OFFSET);
710 ii = (ii & 0xffff0000) | (target_addr >> 16);
711 *(int*)((char*)dummyname + TARGET_ADDR_OFFSET) = ii;
712
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;
716}
717
cd8a3d84
SS
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
41abdfbd
JG
725 stack.
726
727 If the function is returning a structure, then the return address is passed
94b4f756 728 in r3, then the first 7 words of the parameters can be passed in registers,
41abdfbd
JG
729 starting from r4. */
730
731CORE_ADDR
732push_arguments (nargs, args, sp, struct_return, struct_addr)
cd8a3d84
SS
733 int nargs;
734 value_ptr *args;
735 CORE_ADDR sp;
736 int struct_return;
737 CORE_ADDR struct_addr;
41abdfbd 738{
368f1e77
FF
739 int ii;
740 int len = 0;
41abdfbd
JG
741 int argno; /* current argument number */
742 int argbytes; /* current argument byte */
743 char tmp_buffer [50];
41abdfbd 744 int f_argno = 0; /* current floating point argno */
0ec1e44d 745
368f1e77 746 value_ptr arg = 0;
940d5967 747 struct type *type;
41abdfbd 748
368f1e77 749 CORE_ADDR saved_sp;
41abdfbd 750
0ec1e44d 751#ifndef USE_GENERIC_DUMMY_FRAMES
41abdfbd 752 if ( dummy_frame_count <= 0)
199b2450 753 printf_unfiltered ("FATAL ERROR -push_arguments()! frame not found!!\n");
0ec1e44d 754#endif /* GENERIC_DUMMY_FRAMES */
41abdfbd
JG
755
756 /* The first eight words of ther arguments are passed in registers. Copy
757 them appropriately.
758
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
762 parameters. */
763
764 ii = struct_return ? 1 : 0;
765
0ec1e44d
MA
766/*
767effectively indirect call... gcc does...
768
769return_val example( float, int);
770
771eabi:
772 float in fp0, int in r3
773 offset of stack on overflow 8/16
774 for varargs, must go by type.
775power open:
776 float in r3&r4, int in r5
777 offset of stack on overflow different
778both:
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.
783*/
784
41abdfbd
JG
785 for (argno=0, argbytes=0; argno < nargs && ii<8; ++ii) {
786
5222ca60 787 arg = args[argno];
59c84318 788 type = check_typedef (VALUE_TYPE (arg));
940d5967 789 len = TYPE_LENGTH (type);
41abdfbd 790
940d5967 791 if (TYPE_CODE (type) == TYPE_CODE_FLT) {
41abdfbd
JG
792
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. */
796
797 if (len > 8)
199b2450 798 printf_unfiltered (
41abdfbd
JG
799"Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
800
75621b2b
MS
801 memcpy (&registers[REGISTER_BYTE(FP0_REGNUM + 1 + f_argno)],
802 VALUE_CONTENTS (arg),
803 len);
41abdfbd
JG
804 ++f_argno;
805 }
806
807 if (len > 4) {
808
809 /* Argument takes more than one register. */
810 while (argbytes < len) {
75621b2b 811 memset (&registers[REGISTER_BYTE(ii+3)], 0, sizeof(int));
ade40d31 812 memcpy (&registers[REGISTER_BYTE(ii+3)],
75621b2b
MS
813 ((char*)VALUE_CONTENTS (arg))+argbytes,
814 (len - argbytes) > 4 ? 4 : len - argbytes);
41abdfbd
JG
815 ++ii, argbytes += 4;
816
817 if (ii >= 8)
818 goto ran_out_of_registers_for_arguments;
819 }
820 argbytes = 0;
821 --ii;
822 }
823 else { /* Argument can fit in one register. No problem. */
75621b2b 824 memset (&registers[REGISTER_BYTE(ii+3)], 0, sizeof(int));
ade40d31 825 memcpy (&registers[REGISTER_BYTE(ii+3)], VALUE_CONTENTS (arg), len);
41abdfbd
JG
826 }
827 ++argno;
828 }
829
830ran_out_of_registers_for_arguments:
831
0ec1e44d
MA
832#ifdef USE_GENERIC_DUMMY_FRAMES
833 saved_sp = read_sp ();
834#else
41abdfbd
JG
835 /* location for 8 parameters are always reserved. */
836 sp -= 4 * 8;
837
838 /* another six words for back chain, TOC register, link register, etc. */
839 sp -= 24;
0ec1e44d 840#endif /* GENERIC_DUMMY_FRAMES */
41abdfbd
JG
841 /* if there are more arguments, allocate space for them in
842 the stack, then push them starting from the ninth one. */
843
844 if ((argno < nargs) || argbytes) {
845 int space = 0, jj;
41abdfbd
JG
846
847 if (argbytes) {
848 space += ((len - argbytes + 3) & -4);
849 jj = argno + 1;
850 }
851 else
852 jj = argno;
853
854 for (; jj < nargs; ++jj) {
940d5967 855 value_ptr val = args[jj];
41abdfbd
JG
856 space += ((TYPE_LENGTH (VALUE_TYPE (val))) + 3) & -4;
857 }
858
859 /* add location required for the rest of the parameters */
860 space = (space + 7) & -8;
861 sp -= space;
862
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. */
867
868 write_register (SP_REGNUM, sp);
869
41abdfbd
JG
870 /* if the last argument copied into the registers didn't fit there
871 completely, push the rest of it into stack. */
872
873 if (argbytes) {
75621b2b
MS
874 write_memory (sp+24+(ii*4),
875 ((char*)VALUE_CONTENTS (arg))+argbytes,
876 len - argbytes);
41abdfbd
JG
877 ++argno;
878 ii += ((len - argbytes + 3) & -4) / 4;
879 }
880
881 /* push the rest of the arguments into stack. */
882 for (; argno < nargs; ++argno) {
883
5222ca60 884 arg = args[argno];
940d5967
PB
885 type = check_typedef (VALUE_TYPE (arg));
886 len = TYPE_LENGTH (type);
41abdfbd
JG
887
888
889 /* float types should be passed in fpr's, as well as in the stack. */
940d5967 890 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13) {
41abdfbd
JG
891
892 if (len > 8)
199b2450 893 printf_unfiltered (
41abdfbd
JG
894"Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
895
75621b2b
MS
896 memcpy (&registers[REGISTER_BYTE(FP0_REGNUM + 1 + f_argno)],
897 VALUE_CONTENTS (arg),
898 len);
41abdfbd
JG
899 ++f_argno;
900 }
901
359a097f 902 write_memory (sp+24+(ii*4), (char *) VALUE_CONTENTS (arg), len);
41abdfbd
JG
903 ii += ((len + 3) & -4) / 4;
904 }
905 }
6c6afbb9 906 else
41abdfbd
JG
907 /* Secure stack areas first, before doing anything else. */
908 write_register (SP_REGNUM, sp);
909
0ec1e44d
MA
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. */
913
41abdfbd
JG
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);
0ec1e44d 917#endif /* GENERIC_DUMMY_FRAMES */
41abdfbd 918
b112f2ae
JK
919 /* set back chain properly */
920 store_address (tmp_buffer, 4, saved_sp);
921 write_memory (sp, tmp_buffer, 4);
41abdfbd 922
5f1c39ef 923 target_store_registers (-1);
41abdfbd
JG
924 return sp;
925}
0ec1e44d
MA
926#ifdef ELF_OBJECT_FORMAT
927
928/* Function: ppc_push_return_address (pc, sp)
929 Set up the return address for the inferior function call. */
930
931CORE_ADDR
932ppc_push_return_address (pc, sp)
933 CORE_ADDR pc;
934 CORE_ADDR sp;
935{
936 write_register (LR_REGNUM, CALL_DUMMY_ADDRESS ());
937 return sp;
938}
939
940#endif
41abdfbd
JG
941
942/* a given return value in `regbuf' with a type `valtype', extract and copy its
943 value into `valbuf' */
944
ecf4059f 945void
41abdfbd 946extract_return_value (valtype, regbuf, valbuf)
cd8a3d84
SS
947 struct type *valtype;
948 char regbuf[REGISTER_BYTES];
949 char *valbuf;
41abdfbd 950{
07781ac0 951 int offset = 0;
41abdfbd
JG
952
953 if (TYPE_CODE (valtype) == TYPE_CODE_FLT) {
954
955 double dd; float ff;
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
958 necessary. */
959
960 if (TYPE_LENGTH (valtype) > 4) /* this is a double */
75621b2b
MS
961 memcpy (valbuf,
962 &regbuf[REGISTER_BYTE (FP0_REGNUM + 1)],
963 TYPE_LENGTH (valtype));
41abdfbd 964 else { /* float */
ade40d31 965 memcpy (&dd, &regbuf[REGISTER_BYTE (FP0_REGNUM + 1)], 8);
41abdfbd 966 ff = (float)dd;
ade40d31 967 memcpy (valbuf, &ff, sizeof(float));
41abdfbd
JG
968 }
969 }
07781ac0 970 else {
41abdfbd 971 /* return value is copied starting from r3. */
07781ac0
PS
972 if (TARGET_BYTE_ORDER == BIG_ENDIAN
973 && TYPE_LENGTH (valtype) < REGISTER_RAW_SIZE (3))
974 offset = REGISTER_RAW_SIZE (3) - TYPE_LENGTH (valtype);
975
75621b2b
MS
976 memcpy (valbuf,
977 regbuf + REGISTER_BYTE (3) + offset,
07781ac0
PS
978 TYPE_LENGTH (valtype));
979 }
41abdfbd
JG
980}
981
982
ecf4059f
JG
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 */
41abdfbd
JG
987
988CORE_ADDR rs6000_struct_return_address;
989
990
c2e4669f
JG
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).
07aa9fdc
PS
994 Also skip shared library trampoline code (which is different from
995 indirect function call trampolines).
c2e4669f
JG
996 Result is desired PC to step until, or NULL if we are not in
997 trampoline code. */
41abdfbd 998
ecf4059f 999CORE_ADDR
41abdfbd 1000skip_trampoline_code (pc)
cd8a3d84 1001 CORE_ADDR pc;
41abdfbd
JG
1002{
1003 register unsigned int ii, op;
07aa9fdc 1004 CORE_ADDR solib_target_pc;
41abdfbd
JG
1005
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 */
1014 0
1015 };
1016
07aa9fdc
PS
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;
1021
41abdfbd
JG
1022 for (ii=0; trampoline_code[ii]; ++ii) {
1023 op = read_memory_integer (pc + (ii*4), 4);
1024 if (op != trampoline_code [ii])
359a097f 1025 return 0;
41abdfbd
JG
1026 }
1027 ii = read_register (11); /* r11 holds destination addr */
1028 pc = read_memory_integer (ii, 4); /* (r11) value */
1029 return pc;
1030}
1031
068c9fd6 1032/* Determines whether the function FI has a frame on the stack or not. */
cd8a3d84 1033
ecf4059f 1034int
068c9fd6
MM
1035frameless_function_invocation (fi)
1036 struct frame_info *fi;
ecf4059f
JG
1037{
1038 CORE_ADDR func_start;
63641491 1039 struct rs6000_framedata fdata;
ecf4059f 1040
4cc56716
PS
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)
b0e932ad
JK
1044 return 0;
1045
4cc56716 1046 func_start = get_pc_function_start (fi->pc);
ecf4059f
JG
1047
1048 /* If we failed to find the start of the function, it is a mistake
1049 to inspect the instructions. */
1050
1051 if (!func_start)
4cc56716
PS
1052 {
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. */
1057 if (fi->pc == 0)
1058 return 1;
1059 else
1060 return 0;
1061 }
ecf4059f 1062
4cc56716 1063 func_start += FUNCTION_START_OFFSET;
068c9fd6
MM
1064 (void) skip_prologue (func_start, &fdata);
1065 return fdata.frameless;
ecf4059f
JG
1066}
1067
068c9fd6 1068/* Return the PC saved in a frame */
cd8a3d84 1069
068c9fd6
MM
1070unsigned long
1071frame_saved_pc (fi)
1072 struct frame_info *fi;
1073{
1074 CORE_ADDR func_start;
1075 struct rs6000_framedata fdata;
068c9fd6 1076
965dde97
PS
1077 if (fi->signal_handler_caller)
1078 return read_memory_integer (fi->frame + SIG_FRAME_PC_OFFSET, 4);
1079
0ec1e44d
MA
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 */
1084
068c9fd6
MM
1085 func_start = get_pc_function_start (fi->pc) + FUNCTION_START_OFFSET;
1086
1087 /* If we failed to find the start of the function, it is a mistake
1088 to inspect the instructions. */
1089 if (!func_start)
1090 return 0;
1091
1092 (void) skip_prologue (func_start, &fdata);
068c9fd6 1093
4b4c6c96 1094 if (fdata.lr_offset == 0 && fi->next != NULL)
4cc56716
PS
1095 {
1096 if (fi->next->signal_handler_caller)
1097 return read_memory_integer (fi->next->frame + SIG_FRAME_LR_OFFSET, 4);
1098 else
1099 return read_memory_integer (rs6000_frame_chain (fi) + DEFAULT_LR_SAVE,
1100 4);
1101 }
4b4c6c96
MM
1102
1103 if (fdata.lr_offset == 0)
1104 return read_register (LR_REGNUM);
1105
068c9fd6
MM
1106 return read_memory_integer (rs6000_frame_chain (fi) + fdata.lr_offset, 4);
1107}
ecf4059f
JG
1108
1109/* If saved registers of frame FI are not known yet, read and cache them.
63641491 1110 &FDATAP contains rs6000_framedata; TDATAP can be NULL,
ecf4059f
JG
1111 in which case the framedata are read. */
1112
1113static void
1114frame_get_cache_fsr (fi, fdatap)
1115 struct frame_info *fi;
63641491 1116 struct rs6000_framedata *fdatap;
ecf4059f
JG
1117{
1118 int ii;
1119 CORE_ADDR frame_addr;
63641491 1120 struct rs6000_framedata work_fdata;
ecf4059f
JG
1121
1122 if (fi->cache_fsr)
1123 return;
1124
1125 if (fdatap == NULL) {
1126 fdatap = &work_fdata;
068c9fd6 1127 (void) skip_prologue (get_pc_function_start (fi->pc), fdatap);
ecf4059f
JG
1128 }
1129
1130 fi->cache_fsr = (struct frame_saved_regs *)
1131 obstack_alloc (&frame_cache_obstack, sizeof (struct frame_saved_regs));
4ed97c9a 1132 memset (fi->cache_fsr, '\0', sizeof (struct frame_saved_regs));
ecf4059f
JG
1133
1134 if (fi->prev && fi->prev->frame)
1135 frame_addr = fi->prev->frame;
1136 else
1137 frame_addr = read_memory_integer (fi->frame, 4);
1138
1139 /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
965dde97 1140 All fpr's from saved_fpr to fp31 are saved. */
ecf4059f
JG
1141
1142 if (fdatap->saved_fpr >= 0) {
965dde97
PS
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;
1146 fpr_offset += 8;
1147 }
ecf4059f
JG
1148 }
1149
1150 /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
965dde97 1151 All gpr's from saved_gpr to gpr31 are saved. */
ecf4059f 1152
965dde97
PS
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;
1157 gpr_offset += 4;
1158 }
1159 }
1160
1161 /* If != 0, fdatap->cr_offset is the offset from the frame that holds
1162 the CR. */
1163 if (fdatap->cr_offset != 0)
1164 fi->cache_fsr->regs [CR_REGNUM] = frame_addr + fdatap->cr_offset;
1165
1166 /* If != 0, fdatap->lr_offset is the offset from the frame that holds
1167 the LR. */
1168 if (fdatap->lr_offset != 0)
1169 fi->cache_fsr->regs [LR_REGNUM] = frame_addr + fdatap->lr_offset;
ecf4059f
JG
1170}
1171
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. */
1175
1176CORE_ADDR
1177frame_initial_stack_address (fi)
1178 struct frame_info *fi;
1179{
1180 CORE_ADDR tmpaddr;
63641491 1181 struct rs6000_framedata fdata;
ecf4059f
JG
1182 struct frame_info *callee_fi;
1183
1184 /* if the initial stack pointer (frame address) of this frame is known,
1185 just return it. */
1186
1187 if (fi->initial_sp)
1188 return fi->initial_sp;
1189
1190 /* find out if this function is using an alloca register.. */
1191
068c9fd6 1192 (void) skip_prologue (get_pc_function_start (fi->pc), &fdata);
ecf4059f
JG
1193
1194 /* if saved registers of this frame are not known yet, read and cache them. */
1195
1196 if (!fi->cache_fsr)
1197 frame_get_cache_fsr (fi, &fdata);
1198
1199 /* If no alloca register used, then fi->frame is the value of the %sp for
1200 this frame, and it is good enough. */
1201
1202 if (fdata.alloca_reg < 0) {
1203 fi->initial_sp = fi->frame;
1204 return fi->initial_sp;
1205 }
1206
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. */
1209
1210 if (!fi->next)
1211 return fi->initial_sp = read_register (fdata.alloca_reg);
1212
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. */
1217
1218 for (callee_fi = fi->next; callee_fi; callee_fi = callee_fi->next) {
1219
1220 if (!callee_fi->cache_fsr)
cdb1cc92 1221 frame_get_cache_fsr (callee_fi, NULL);
ecf4059f
JG
1222
1223 /* this is the address in which alloca register is saved. */
1224
1225 tmpaddr = callee_fi->cache_fsr->regs [fdata.alloca_reg];
1226 if (tmpaddr) {
1227 fi->initial_sp = read_memory_integer (tmpaddr, 4);
1228 return fi->initial_sp;
1229 }
1230
1231 /* Go look into deeper levels of the frame chain to see if any one of
1232 the callees has saved alloca register. */
1233 }
1234
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. */
1237
1238 return fi->initial_sp = read_register (fdata.alloca_reg);
1239}
1240
669caa9c 1241CORE_ADDR
f3649227
JK
1242rs6000_frame_chain (thisframe)
1243 struct frame_info *thisframe;
1244{
669caa9c 1245 CORE_ADDR fp;
0ec1e44d
MA
1246
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 */
1251
1252 if (inside_entry_file (thisframe->pc) ||
1253 thisframe->pc == entry_point_address ())
f3649227 1254 return 0;
0ec1e44d 1255
cee86be3 1256 if (thisframe->signal_handler_caller)
9ed8604f 1257 fp = read_memory_integer (thisframe->frame + SIG_FRAME_FP_OFFSET, 4);
4cc56716
PS
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
1262 frame pointer. */
1263 fp = FRAME_FP (thisframe);
cee86be3
JK
1264 else
1265 fp = read_memory_integer ((thisframe)->frame, 4);
1266
0ec1e44d
MA
1267#ifdef USE_GENERIC_DUMMY_FRAMES
1268 {
1269 CORE_ADDR fpp, lr;
1270
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))
1275 return fpp;
1276 }
1277#endif /* GENERIC_DUMMY_FRAMES */
f3649227
JK
1278 return fp;
1279}
ecf4059f 1280\f
65eaea27
JL
1281/* Return nonzero if ADDR (a function pointer) is in the data space and
1282 is therefore a special function pointer. */
1283
1284int
1285is_magic_function_pointer (addr)
1286 CORE_ADDR addr;
1287{
1288 struct obj_section *s;
1289
1290 s = find_pc_section (addr);
1291 if (s && s->the_bfd_section->flags & SEC_CODE)
1292 return 0;
1293 else
1294 return 1;
1295}
1296
5c172b4b
MM
1297#ifdef GDB_TARGET_POWERPC
1298int
1299gdb_print_insn_powerpc (memaddr, info)
1300 bfd_vma memaddr;
1301 disassemble_info *info;
1302{
1303 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1304 return print_insn_big_powerpc (memaddr, info);
1305 else
1306 return print_insn_little_powerpc (memaddr, info);
1307}
1308#endif
1309
0ec1e44d
MA
1310/* Function: get_saved_register
1311 Just call the generic_get_saved_register function. */
1312
1313void
1314get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
1315 char *raw_buffer;
1316 int *optimized;
1317 CORE_ADDR *addrp;
1318 struct frame_info *frame;
1319 int regnum;
1320 enum lval_type *lval;
1321{
1322 generic_get_saved_register (raw_buffer, optimized, addrp,
1323 frame, regnum, lval);
1324}
1325
1326
18b46e7c
SS
1327void
1328_initialize_rs6000_tdep ()
1329{
1330 /* FIXME, this should not be decided via ifdef. */
1331#ifdef GDB_TARGET_POWERPC
5c172b4b 1332 tm_print_insn = gdb_print_insn_powerpc;
18b46e7c
SS
1333#else
1334 tm_print_insn = print_insn_rs6000;
1335#endif
1336}
This page took 0.408936 seconds and 4 git commands to generate.