* config/sparc/tm-sp64.h (CALL_DUMMY): Store and retrieve
[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"
41abdfbd
JG
22#include "frame.h"
23#include "inferior.h"
24#include "symtab.h"
25#include "target.h"
030fb5cb 26#include "gdbcore.h"
65eaea27
JL
27#include "symfile.h"
28#include "objfiles.h"
2aefe6e4
JK
29#include "xcoffsolib.h"
30
d6434f39
JG
31extern struct obstack frame_cache_obstack;
32
41abdfbd 33extern int errno;
41abdfbd
JG
34
35/* Nonzero if we just simulated a single step break. */
36int one_stepped;
37
41abdfbd
JG
38/* Breakpoint shadows for the single step instructions will be kept here. */
39
40static struct sstep_breaks {
030fb5cb
JK
41 /* Address, or 0 if this is not in use. */
42 CORE_ADDR address;
43 /* Shadow contents. */
44 char data[4];
41abdfbd
JG
45} stepBreaks[2];
46
05d52ace
PS
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. */
50
51CORE_ADDR (*find_toc_address_hook) PARAMS ((CORE_ADDR)) = NULL;
ecf4059f 52
05d52ace 53/* Static function prototypes */
ecf4059f 54
cd8a3d84
SS
55static CORE_ADDR branch_dest PARAMS ((int opcode, int instr, CORE_ADDR pc,
56 CORE_ADDR safety));
ecf4059f 57
cd8a3d84
SS
58static void frame_get_cache_fsr PARAMS ((struct frame_info *fi,
59 struct rs6000_framedata *fdatap));
60
368f1e77
FF
61static void pop_dummy_frame PARAMS ((void));
62
cd8a3d84 63/* Calculate the destination of a branch/jump. Return -1 if not a branch. */
41abdfbd 64
ecf4059f 65static CORE_ADDR
41abdfbd 66branch_dest (opcode, instr, pc, safety)
ecf4059f
JG
67 int opcode;
68 int instr;
69 CORE_ADDR pc;
70 CORE_ADDR safety;
41abdfbd 71{
ecf4059f 72 CORE_ADDR dest;
41abdfbd
JG
73 int immediate;
74 int absolute;
75 int ext_op;
76
77 absolute = (int) ((instr >> 1) & 1);
78
79 switch (opcode) {
80 case 18 :
ecf4059f 81 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
dc59e982
MM
82 if (absolute)
83 dest = immediate;
84 else
85 dest = pc + immediate;
86 break;
41abdfbd
JG
87
88 case 16 :
dc59e982 89 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
41abdfbd
JG
90 if (absolute)
91 dest = immediate;
92 else
93 dest = pc + immediate;
94 break;
95
96 case 19 :
97 ext_op = (instr>>1) & 0x3ff;
98
99 if (ext_op == 16) /* br conditional register */
0c6c5eeb
PS
100 {
101 dest = read_register (LR_REGNUM) & ~3;
102
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)
108 {
109 struct frame_info *fi;
110
111 fi = get_current_frame ();
112 if (fi != NULL)
113 dest = read_memory_integer (fi->frame + SIG_FRAME_PC_OFFSET,
114 4);
115 }
116 }
41abdfbd
JG
117
118 else if (ext_op == 528) /* br cond to count reg */
9aa31e91
JK
119 {
120 dest = read_register (CTR_REGNUM) & ~3;
121
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;
127 }
41abdfbd
JG
128 else return -1;
129 break;
130
131 default: return -1;
132 }
818de002 133 return (dest < TEXT_SEGMENT_BASE) ? safety : dest;
41abdfbd
JG
134}
135
136
137
138/* AIX does not support PT_STEP. Simulate it. */
139
997cc2c0 140void
41abdfbd 141single_step (signal)
b607efe7 142 enum target_signal signal;
41abdfbd
JG
143{
144#define INSNLEN(OPCODE) 4
145
5c172b4b
MM
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;
030fb5cb
JK
149 int ii, insn;
150 CORE_ADDR loc;
151 CORE_ADDR breaks[2];
152 int opcode;
41abdfbd
JG
153
154 if (!one_stepped) {
41abdfbd
JG
155 loc = read_pc ();
156
b112f2ae 157 insn = read_memory_integer (loc, 4);
41abdfbd
JG
158
159 breaks[0] = loc + INSNLEN(insn);
160 opcode = insn >> 26;
161 breaks[1] = branch_dest (opcode, insn, loc, breaks[0]);
162
818de002
PB
163 /* Don't put two breakpoints on the same address. */
164 if (breaks[1] == breaks[0])
165 breaks[1] = -1;
166
030fb5cb 167 stepBreaks[1].address = 0;
41abdfbd
JG
168
169 for (ii=0; ii < 2; ++ii) {
170
171 /* ignore invalid breakpoint. */
172 if ( breaks[ii] == -1)
173 continue;
174
030fb5cb 175 read_memory (breaks[ii], stepBreaks[ii].data, 4);
41abdfbd 176
030fb5cb 177 write_memory (breaks[ii], breakp, 4);
41abdfbd
JG
178 stepBreaks[ii].address = breaks[ii];
179 }
180
181 one_stepped = 1;
997cc2c0 182 } else {
41abdfbd
JG
183
184 /* remove step breakpoints. */
185 for (ii=0; ii < 2; ++ii)
030fb5cb 186 if (stepBreaks[ii].address != 0)
41abdfbd 187 write_memory
030fb5cb 188 (stepBreaks[ii].address, stepBreaks[ii].data, 4);
41abdfbd
JG
189
190 one_stepped = 0;
191 }
997cc2c0 192 errno = 0; /* FIXME, don't ignore errors! */
030fb5cb 193 /* What errors? {read,write}_memory call error(). */
41abdfbd 194}
41abdfbd
JG
195
196
068c9fd6
MM
197/* return pc value after skipping a function prologue and also return
198 information about a function frame.
41abdfbd 199
068c9fd6
MM
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.
207 Otherwise -1.
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
212 */
213
214#define SIGNED_SHORT(x) \
215 ((sizeof (short) == 2) \
216 ? ((int)(short)(x)) \
217 : ((int)((((x) & 0xffff) ^ 0x8000) - 0x8000)))
218
219#define GET_SRC_REG(x) (((x) >> 21) & 0x1f)
220
221CORE_ADDR
222skip_prologue (pc, fdata)
223 CORE_ADDR pc;
224 struct rs6000_framedata *fdata;
41abdfbd 225{
068c9fd6 226 CORE_ADDR orig_pc = pc;
34df79fc 227 char buf[4];
34df79fc 228 unsigned long op;
4b4c6c96 229 long offset = 0;
068c9fd6
MM
230 int lr_reg = 0;
231 int cr_reg = 0;
232 int reg;
4b4c6c96 233 int framep = 0;
65eaea27 234 int minimal_toc_loaded = 0;
068c9fd6
MM
235 static struct rs6000_framedata zero_frame;
236
237 *fdata = 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;
41abdfbd 243
34df79fc 244 if (target_read_memory (pc, buf, 4))
41abdfbd 245 return pc; /* Can't access it -- assume no prologue. */
41abdfbd
JG
246
247 /* Assume that subsequent fetches can fail with low probability. */
068c9fd6
MM
248 pc -= 4;
249 for (;;)
250 {
251 pc += 4;
252 op = read_memory_integer (pc, 4);
41abdfbd 253
068c9fd6
MM
254 if ((op & 0xfc1fffff) == 0x7c0802a6) { /* mflr Rx */
255 lr_reg = (op & 0x03e00000) | 0x90010000;
256 continue;
257
258 } else if ((op & 0xfc1fffff) == 0x7c000026) { /* mfcr Rx */
259 cr_reg = (op & 0x03e00000) | 0x90010000;
260 continue;
261
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;
4b4c6c96 266 fdata->fpr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
267 }
268 continue;
269
270 } else if (((op & 0xfc1f0000) == 0xbc010000) || /* stm Rx, NUM(r1) */
271 ((op & 0xfc1f0000) == 0x90010000 && /* st rx,NUM(r1), rx >= r13 */
272 (op & 0x03e00000) >= 0x01a00000)) {
273
274 reg = GET_SRC_REG (op);
275 if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg) {
276 fdata->saved_gpr = reg;
4b4c6c96 277 fdata->gpr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
278 }
279 continue;
280
281 } else if ((op & 0xffff0000) == 0x3c000000) { /* addis 0,0,NUM, used for >= 32k frames */
282 fdata->offset = (op & 0x0000ffff) << 16;
65eaea27 283 fdata->frameless = 0;
068c9fd6
MM
284 continue;
285
286 } else if ((op & 0xffff0000) == 0x60000000) { /* ori 0,0,NUM, 2nd half of >= 32k frames */
287 fdata->offset |= (op & 0x0000ffff);
65eaea27 288 fdata->frameless = 0;
068c9fd6
MM
289 continue;
290
291 } else if ((op & 0xffff0000) == lr_reg) { /* st Rx,NUM(r1) where Rx == lr */
4b4c6c96 292 fdata->lr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
293 fdata->nosavedpc = 0;
294 lr_reg = 0;
295 continue;
296
297 } else if ((op & 0xffff0000) == cr_reg) { /* st Rx,NUM(r1) where Rx == cr */
4b4c6c96 298 fdata->cr_offset = SIGNED_SHORT (op) + offset;
068c9fd6
MM
299 cr_reg = 0;
300 continue;
301
4b4c6c96
MM
302 } else if (op == 0x48000005) { /* bl .+4 used in -mrelocatable */
303 continue;
304
65eaea27
JL
305 } else if (op == 0x48000004) { /* b .+4 (xlc) */
306 break;
307
4b4c6c96
MM
308 } else if (((op & 0xffff0000) == 0x801e0000 || /* lwz 0,NUM(r30), used in V.4 -mrelocatable */
309 op == 0x7fc0f214) && /* add r30,r0,r30, used in V.4 -mrelocatable */
310 lr_reg == 0x901e0000) {
311 continue;
312
313 } else if ((op & 0xffff0000) == 0x3fc00000 || /* addis 30,0,foo@ha, used in V.4 -mminimal-toc */
314 (op & 0xffff0000) == 0x3bde0000) { /* addi 30,30,foo@l */
315 continue;
316
068c9fd6 317 } else if ((op & 0xfc000000) == 0x48000000) { /* bl foo, to save fprs??? */
965dde97 318
65eaea27 319 fdata->frameless = 0;
965dde97
PS
320 /* Don't skip over the subroutine call if it is not within the first
321 three instructions of the prologue. */
322 if ((pc - orig_pc) > 8)
323 break;
324
068c9fd6
MM
325 op = read_memory_integer (pc+4, 4);
326
327 /* At this point, make sure this is not a trampoline function
328 (a function that simply calls another functions, and nothing else).
329 If the next is not a nop, this branch was part of the function
330 prologue. */
331
332 if (op == 0x4def7b82 || op == 0) /* crorc 15, 15, 15 */
965dde97 333 break; /* don't skip over this branch */
068c9fd6
MM
334
335 continue;
336
4b4c6c96 337 /* update stack pointer */
068c9fd6 338 } else if ((op & 0xffff0000) == 0x94210000) { /* stu r1,NUM(r1) */
65eaea27 339 fdata->frameless = 0;
4b4c6c96
MM
340 fdata->offset = SIGNED_SHORT (op);
341 offset = fdata->offset;
342 continue;
1eeba686 343
068c9fd6 344 } else if (op == 0x7c21016e) { /* stwux 1,1,0 */
65eaea27 345 fdata->frameless = 0;
4b4c6c96
MM
346 offset = fdata->offset;
347 continue;
41abdfbd 348
4b4c6c96 349 /* Load up minimal toc pointer */
65eaea27
JL
350 } else if ((op >> 22) == 0x20f
351 && ! minimal_toc_loaded) { /* l r31,... or l r30,... */
352 minimal_toc_loaded = 1;
4b4c6c96 353 continue;
cdb1cc92 354
4b4c6c96
MM
355 /* store parameters in stack */
356 } else if ((op & 0xfc1f0000) == 0x90010000 || /* st rx,NUM(r1) */
357 (op & 0xfc1f0000) == 0xd8010000 || /* stfd Rx,NUM(r1) */
358 (op & 0xfc1f0000) == 0xfc010000) { /* frsp, fp?,NUM(r1) */
359 continue;
e137e850 360
4b4c6c96
MM
361 /* store parameters in stack via frame pointer */
362 } else if (framep &&
58b4fad2 363 ((op & 0xfc1f0000) == 0x901f0000 || /* st rx,NUM(r1) */
4b4c6c96 364 (op & 0xfc1f0000) == 0xd81f0000 || /* stfd Rx,NUM(r1) */
58b4fad2 365 (op & 0xfc1f0000) == 0xfc1f0000)) { /* frsp, fp?,NUM(r1) */
4b4c6c96 366 continue;
e137e850 367
4b4c6c96
MM
368 /* Set up frame pointer */
369 } else if (op == 0x603f0000 /* oril r31, r1, 0x0 */
370 || op == 0x7c3f0b78) { /* mr r31, r1 */
65eaea27 371 fdata->frameless = 0;
4b4c6c96 372 framep = 1;
965dde97 373 fdata->alloca_reg = 31;
4b4c6c96 374 continue;
41abdfbd 375
65eaea27
JL
376 /* Another way to set up the frame pointer. */
377 } else if ((op & 0xfc1fffff) == 0x38010000) { /* addi rX, r1, 0x0 */
378 fdata->frameless = 0;
379 framep = 1;
380 fdata->alloca_reg = (op & ~0x38010000) >> 21;
381 continue;
382
4b4c6c96
MM
383 } else {
384 break;
385 }
41abdfbd 386 }
068c9fd6 387
507e4004
PB
388#if 0
389/* I have problems with skipping over __main() that I need to address
390 * sometime. Previously, I used to use misc_function_vector which
391 * didn't work as well as I wanted to be. -MGO */
392
393 /* If the first thing after skipping a prolog is a branch to a function,
394 this might be a call to an initializer in main(), introduced by gcc2.
395 We'd like to skip over it as well. Fortunately, xlc does some extra
396 work before calling a function right after a prologue, thus we can
397 single out such gcc2 behaviour. */
398
399
400 if ((op & 0xfc000001) == 0x48000001) { /* bl foo, an initializer function? */
401 op = read_memory_integer (pc+4, 4);
402
403 if (op == 0x4def7b82) { /* cror 0xf, 0xf, 0xf (nop) */
404
405 /* check and see if we are in main. If so, skip over this initializer
406 function as well. */
407
408 tmp = find_pc_misc_function (pc);
2e4964ad 409 if (tmp >= 0 && STREQ (misc_function_vector [tmp].name, "main"))
507e4004
PB
410 return pc + 8;
411 }
412 }
413#endif /* 0 */
414
4b4c6c96 415 fdata->offset = - fdata->offset;
41abdfbd
JG
416 return pc;
417}
418
818de002 419
41abdfbd
JG
420/*************************************************************************
421 Support for creating pushind a dummy frame into the stack, and popping
422 frames, etc.
423*************************************************************************/
424
818de002
PB
425/* The total size of dummy frame is 436, which is;
426
427 32 gpr's - 128 bytes
428 32 fpr's - 256 "
429 7 the rest - 28 "
430 and 24 extra bytes for the callee's link area. The last 24 bytes
431 for the link area might not be necessary, since it will be taken
432 care of by push_arguments(). */
433
434#define DUMMY_FRAME_SIZE 436
435
41abdfbd
JG
436#define DUMMY_FRAME_ADDR_SIZE 10
437
438/* Make sure you initialize these in somewhere, in case gdb gives up what it
818de002 439 was debugging and starts debugging something else. FIXMEibm */
41abdfbd
JG
440
441static int dummy_frame_count = 0;
442static int dummy_frame_size = 0;
443static CORE_ADDR *dummy_frame_addr = 0;
444
445extern int stop_stack_dummy;
446
447/* push a dummy frame into stack, save all register. Currently we are saving
448 only gpr's and fpr's, which is not good enough! FIXMEmgo */
449
ecf4059f 450void
41abdfbd
JG
451push_dummy_frame ()
452{
359a097f
JK
453 /* stack pointer. */
454 CORE_ADDR sp;
b112f2ae
JK
455 /* Same thing, target byte order. */
456 char sp_targ[4];
359a097f
JK
457
458 /* link register. */
459 CORE_ADDR pc;
460 /* Same thing, target byte order. */
461 char pc_targ[4];
462
3a4f9786
MT
463 /* Needed to figure out where to save the dummy link area.
464 FIXME: There should be an easier way to do this, no? tiemann 9/9/95. */
465 struct rs6000_framedata fdata;
466
41abdfbd
JG
467 int ii;
468
5f1c39ef 469 target_fetch_registers (-1);
6c6afbb9 470
41abdfbd
JG
471 if (dummy_frame_count >= dummy_frame_size) {
472 dummy_frame_size += DUMMY_FRAME_ADDR_SIZE;
473 if (dummy_frame_addr)
474 dummy_frame_addr = (CORE_ADDR*) xrealloc
475 (dummy_frame_addr, sizeof(CORE_ADDR) * (dummy_frame_size));
476 else
477 dummy_frame_addr = (CORE_ADDR*)
478 xmalloc (sizeof(CORE_ADDR) * (dummy_frame_size));
479 }
480
481 sp = read_register(SP_REGNUM);
359a097f 482 pc = read_register(PC_REGNUM);
5816555b 483 store_address (pc_targ, 4, pc);
41abdfbd 484
3a4f9786
MT
485 (void) skip_prologue (get_pc_function_start (pc) + FUNCTION_START_OFFSET, &fdata);
486
41abdfbd
JG
487 dummy_frame_addr [dummy_frame_count++] = sp;
488
489 /* Be careful! If the stack pointer is not decremented first, then kernel
6c6afbb9 490 thinks he is free to use the space underneath it. And kernel actually
41abdfbd
JG
491 uses that area for IPC purposes when executing ptrace(2) calls. So
492 before writing register values into the new frame, decrement and update
493 %sp first in order to secure your frame. */
494
3a4f9786
MT
495 /* FIXME: We don't check if the stack really has this much space.
496 This is a problem on the ppc simulator (which only grants one page
497 (4096 bytes) by default. */
498
818de002 499 write_register (SP_REGNUM, sp-DUMMY_FRAME_SIZE);
41abdfbd 500
41abdfbd
JG
501 /* gdb relies on the state of current_frame. We'd better update it,
502 otherwise things like do_registers_info() wouldn't work properly! */
503
504 flush_cached_frames ();
41abdfbd
JG
505
506 /* save program counter in link register's space. */
4f8710e6
PS
507 write_memory (sp + (fdata.lr_offset ? fdata.lr_offset : DEFAULT_LR_SAVE),
508 pc_targ, 4);
41abdfbd 509
6c6afbb9 510 /* save all floating point and general purpose registers here. */
41abdfbd
JG
511
512 /* fpr's, f0..f31 */
513 for (ii = 0; ii < 32; ++ii)
514 write_memory (sp-8-(ii*8), &registers[REGISTER_BYTE (31-ii+FP0_REGNUM)], 8);
515
516 /* gpr's r0..r31 */
517 for (ii=1; ii <=32; ++ii)
518 write_memory (sp-256-(ii*4), &registers[REGISTER_BYTE (32-ii)], 4);
519
818de002
PB
520 /* so far, 32*2 + 32 words = 384 bytes have been written.
521 7 extra registers in our register set: pc, ps, cnd, lr, cnt, xer, mq */
522
523 for (ii=1; ii <= (LAST_SP_REGNUM-FIRST_SP_REGNUM+1); ++ii) {
524 write_memory (sp-384-(ii*4),
525 &registers[REGISTER_BYTE (FPLAST_REGNUM + ii)], 4);
526 }
527
528 /* Save sp or so called back chain right here. */
b112f2ae
JK
529 store_address (sp_targ, 4, sp);
530 write_memory (sp-DUMMY_FRAME_SIZE, sp_targ, 4);
818de002 531 sp -= DUMMY_FRAME_SIZE;
41abdfbd
JG
532
533 /* And finally, this is the back chain. */
359a097f 534 write_memory (sp+8, pc_targ, 4);
41abdfbd
JG
535}
536
537
538/* Pop a dummy frame.
539
540 In rs6000 when we push a dummy frame, we save all of the registers. This
541 is usually done before user calls a function explicitly.
542
818de002
PB
543 After a dummy frame is pushed, some instructions are copied into stack,
544 and stack pointer is decremented even more. Since we don't have a frame
545 pointer to get back to the parent frame of the dummy, we start having
546 trouble poping it. Therefore, we keep a dummy frame stack, keeping
547 addresses of dummy frames as such. When poping happens and when we
548 detect that was a dummy frame, we pop it back to its parent by using
549 dummy frame stack (`dummy_frame_addr' array).
ecf4059f
JG
550
551FIXME: This whole concept is broken. You should be able to detect
552a dummy stack frame *on the user's stack itself*. When you do,
553then you know the format of that stack frame -- including its
554saved SP register! There should *not* be a separate stack in the
d6434f39 555GDB process that keeps track of these dummy frames! -- gnu@cygnus.com Aug92
41abdfbd
JG
556 */
557
368f1e77 558static void
41abdfbd
JG
559pop_dummy_frame ()
560{
561 CORE_ADDR sp, pc;
562 int ii;
563 sp = dummy_frame_addr [--dummy_frame_count];
564
565 /* restore all fpr's. */
566 for (ii = 1; ii <= 32; ++ii)
567 read_memory (sp-(ii*8), &registers[REGISTER_BYTE (32-ii+FP0_REGNUM)], 8);
568
569 /* restore all gpr's */
570 for (ii=1; ii <= 32; ++ii) {
571 read_memory (sp-256-(ii*4), &registers[REGISTER_BYTE (32-ii)], 4);
572 }
573
818de002
PB
574 /* restore the rest of the registers. */
575 for (ii=1; ii <=(LAST_SP_REGNUM-FIRST_SP_REGNUM+1); ++ii)
576 read_memory (sp-384-(ii*4),
577 &registers[REGISTER_BYTE (FPLAST_REGNUM + ii)], 4);
578
579 read_memory (sp-(DUMMY_FRAME_SIZE-8),
3a4f9786 580 &registers [REGISTER_BYTE(PC_REGNUM)], 4);
41abdfbd
JG
581
582 /* when a dummy frame was being pushed, we had to decrement %sp first, in
583 order to secure astack space. Thus, saved %sp (or %r1) value, is not the
584 one we should restore. Change it with the one we need. */
585
586 *(int*)&registers [REGISTER_BYTE(FP_REGNUM)] = sp;
587
588 /* Now we can restore all registers. */
589
5f1c39ef 590 target_store_registers (-1);
41abdfbd
JG
591 pc = read_pc ();
592 flush_cached_frames ();
41abdfbd
JG
593}
594
595
596/* pop the innermost frame, go back to the caller. */
597
ecf4059f 598void
41abdfbd
JG
599pop_frame ()
600{
359a097f 601 CORE_ADDR pc, lr, sp, prev_sp; /* %pc, %lr, %sp */
63641491 602 struct rs6000_framedata fdata;
669caa9c 603 struct frame_info *frame = get_current_frame ();
41abdfbd 604 int addr, ii;
41abdfbd
JG
605
606 pc = read_pc ();
669caa9c 607 sp = FRAME_FP (frame);
41abdfbd
JG
608
609 if (stop_stack_dummy && dummy_frame_count) {
610 pop_dummy_frame ();
611 return;
612 }
613
07aa9fdc
PS
614 /* Make sure that all registers are valid. */
615 read_register_bytes (0, NULL, REGISTER_BYTES);
616
41abdfbd
JG
617 /* figure out previous %pc value. If the function is frameless, it is
618 still in the link register, otherwise walk the frames and retrieve the
619 saved %pc value in the previous frame. */
620
34a1a3bf 621 addr = get_pc_function_start (frame->pc) + FUNCTION_START_OFFSET;
068c9fd6 622 (void) skip_prologue (addr, &fdata);
41abdfbd 623
6c6afbb9 624 if (fdata.frameless)
07aa9fdc
PS
625 prev_sp = sp;
626 else
627 prev_sp = read_memory_integer (sp, 4);
068c9fd6 628 if (fdata.lr_offset == 0)
41abdfbd
JG
629 lr = read_register (LR_REGNUM);
630 else
068c9fd6 631 lr = read_memory_integer (prev_sp + fdata.lr_offset, 4);
41abdfbd
JG
632
633 /* reset %pc value. */
634 write_register (PC_REGNUM, lr);
635
636 /* reset register values if any was saved earlier. */
6c6afbb9 637 addr = prev_sp - fdata.offset;
41abdfbd 638
6c6afbb9 639 if (fdata.saved_gpr != -1)
669caa9c 640 for (ii = fdata.saved_gpr; ii <= 31; ++ii) {
41abdfbd 641 read_memory (addr, &registers [REGISTER_BYTE (ii)], 4);
cdb1cc92 642 addr += 4;
41abdfbd
JG
643 }
644
6c6afbb9 645 if (fdata.saved_fpr != -1)
669caa9c 646 for (ii = fdata.saved_fpr; ii <= 31; ++ii) {
41abdfbd
JG
647 read_memory (addr, &registers [REGISTER_BYTE (ii+FP0_REGNUM)], 8);
648 addr += 8;
649 }
650
651 write_register (SP_REGNUM, prev_sp);
5f1c39ef 652 target_store_registers (-1);
41abdfbd 653 flush_cached_frames ();
41abdfbd
JG
654}
655
41abdfbd
JG
656/* fixup the call sequence of a dummy function, with the real function address.
657 its argumets will be passed by gdb. */
658
ecf4059f 659void
2f163bc3 660rs6000_fix_call_dummy (dummyname, pc, fun, nargs, args, type, gcc_p)
cd8a3d84
SS
661 char *dummyname;
662 CORE_ADDR pc;
663 CORE_ADDR fun;
2f163bc3
SS
664 int nargs;
665 value_ptr *args;
666 struct type *type;
667 int gcc_p;
41abdfbd
JG
668{
669#define TOC_ADDR_OFFSET 20
670#define TARGET_ADDR_OFFSET 28
671
672 int ii;
ecf4059f 673 CORE_ADDR target_addr;
41abdfbd 674
05d52ace
PS
675 if (find_toc_address_hook != NULL)
676 {
677 CORE_ADDR tocvalue;
41abdfbd 678
05d52ace
PS
679 tocvalue = (*find_toc_address_hook) (fun);
680 ii = *(int*)((char*)dummyname + TOC_ADDR_OFFSET);
681 ii = (ii & 0xffff0000) | (tocvalue >> 16);
682 *(int*)((char*)dummyname + TOC_ADDR_OFFSET) = ii;
41abdfbd 683
05d52ace
PS
684 ii = *(int*)((char*)dummyname + TOC_ADDR_OFFSET+4);
685 ii = (ii & 0xffff0000) | (tocvalue & 0x0000ffff);
686 *(int*)((char*)dummyname + TOC_ADDR_OFFSET+4) = ii;
687 }
41abdfbd 688
05d52ace 689 target_addr = fun;
41abdfbd
JG
690 ii = *(int*)((char*)dummyname + TARGET_ADDR_OFFSET);
691 ii = (ii & 0xffff0000) | (target_addr >> 16);
692 *(int*)((char*)dummyname + TARGET_ADDR_OFFSET) = ii;
693
694 ii = *(int*)((char*)dummyname + TARGET_ADDR_OFFSET+4);
695 ii = (ii & 0xffff0000) | (target_addr & 0x0000ffff);
696 *(int*)((char*)dummyname + TARGET_ADDR_OFFSET+4) = ii;
697}
698
cd8a3d84
SS
699/* Pass the arguments in either registers, or in the stack. In RS6000,
700 the first eight words of the argument list (that might be less than
701 eight parameters if some parameters occupy more than one word) are
702 passed in r3..r11 registers. float and double parameters are
703 passed in fpr's, in addition to that. Rest of the parameters if any
704 are passed in user stack. There might be cases in which half of the
705 parameter is copied into registers, the other half is pushed into
41abdfbd
JG
706 stack.
707
708 If the function is returning a structure, then the return address is passed
94b4f756 709 in r3, then the first 7 words of the parameters can be passed in registers,
41abdfbd
JG
710 starting from r4. */
711
712CORE_ADDR
713push_arguments (nargs, args, sp, struct_return, struct_addr)
cd8a3d84
SS
714 int nargs;
715 value_ptr *args;
716 CORE_ADDR sp;
717 int struct_return;
718 CORE_ADDR struct_addr;
41abdfbd 719{
368f1e77
FF
720 int ii;
721 int len = 0;
41abdfbd
JG
722 int argno; /* current argument number */
723 int argbytes; /* current argument byte */
724 char tmp_buffer [50];
41abdfbd 725 int f_argno = 0; /* current floating point argno */
368f1e77 726 value_ptr arg = 0;
940d5967 727 struct type *type;
41abdfbd 728
368f1e77 729 CORE_ADDR saved_sp;
41abdfbd
JG
730
731 if ( dummy_frame_count <= 0)
199b2450 732 printf_unfiltered ("FATAL ERROR -push_arguments()! frame not found!!\n");
41abdfbd
JG
733
734 /* The first eight words of ther arguments are passed in registers. Copy
735 them appropriately.
736
737 If the function is returning a `struct', then the first word (which
738 will be passed in r3) is used for struct return address. In that
739 case we should advance one word and start from r4 register to copy
740 parameters. */
741
742 ii = struct_return ? 1 : 0;
743
744 for (argno=0, argbytes=0; argno < nargs && ii<8; ++ii) {
745
5222ca60 746 arg = args[argno];
59c84318 747 type = check_typedef (VALUE_TYPE (arg));
940d5967 748 len = TYPE_LENGTH (type);
41abdfbd 749
940d5967 750 if (TYPE_CODE (type) == TYPE_CODE_FLT) {
41abdfbd
JG
751
752 /* floating point arguments are passed in fpr's, as well as gpr's.
753 There are 13 fpr's reserved for passing parameters. At this point
754 there is no way we would run out of them. */
755
756 if (len > 8)
199b2450 757 printf_unfiltered (
41abdfbd
JG
758"Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
759
ade40d31
RP
760 memcpy (&registers[REGISTER_BYTE(FP0_REGNUM + 1 + f_argno)], VALUE_CONTENTS (arg),
761 len);
41abdfbd
JG
762 ++f_argno;
763 }
764
765 if (len > 4) {
766
767 /* Argument takes more than one register. */
768 while (argbytes < len) {
769
770 *(int*)&registers[REGISTER_BYTE(ii+3)] = 0;
ade40d31
RP
771 memcpy (&registers[REGISTER_BYTE(ii+3)],
772 ((char*)VALUE_CONTENTS (arg))+argbytes,
41abdfbd
JG
773 (len - argbytes) > 4 ? 4 : len - argbytes);
774 ++ii, argbytes += 4;
775
776 if (ii >= 8)
777 goto ran_out_of_registers_for_arguments;
778 }
779 argbytes = 0;
780 --ii;
781 }
782 else { /* Argument can fit in one register. No problem. */
783 *(int*)&registers[REGISTER_BYTE(ii+3)] = 0;
ade40d31 784 memcpy (&registers[REGISTER_BYTE(ii+3)], VALUE_CONTENTS (arg), len);
41abdfbd
JG
785 }
786 ++argno;
787 }
788
789ran_out_of_registers_for_arguments:
790
791 /* location for 8 parameters are always reserved. */
792 sp -= 4 * 8;
793
794 /* another six words for back chain, TOC register, link register, etc. */
795 sp -= 24;
796
797 /* if there are more arguments, allocate space for them in
798 the stack, then push them starting from the ninth one. */
799
800 if ((argno < nargs) || argbytes) {
801 int space = 0, jj;
41abdfbd
JG
802
803 if (argbytes) {
804 space += ((len - argbytes + 3) & -4);
805 jj = argno + 1;
806 }
807 else
808 jj = argno;
809
810 for (; jj < nargs; ++jj) {
940d5967 811 value_ptr val = args[jj];
41abdfbd
JG
812 space += ((TYPE_LENGTH (VALUE_TYPE (val))) + 3) & -4;
813 }
814
815 /* add location required for the rest of the parameters */
816 space = (space + 7) & -8;
817 sp -= space;
818
819 /* This is another instance we need to be concerned about securing our
820 stack space. If we write anything underneath %sp (r1), we might conflict
821 with the kernel who thinks he is free to use this area. So, update %sp
822 first before doing anything else. */
823
824 write_register (SP_REGNUM, sp);
825
41abdfbd
JG
826 /* if the last argument copied into the registers didn't fit there
827 completely, push the rest of it into stack. */
828
829 if (argbytes) {
830 write_memory (
831 sp+24+(ii*4), ((char*)VALUE_CONTENTS (arg))+argbytes, len - argbytes);
832 ++argno;
833 ii += ((len - argbytes + 3) & -4) / 4;
834 }
835
836 /* push the rest of the arguments into stack. */
837 for (; argno < nargs; ++argno) {
838
5222ca60 839 arg = args[argno];
940d5967
PB
840 type = check_typedef (VALUE_TYPE (arg));
841 len = TYPE_LENGTH (type);
41abdfbd
JG
842
843
844 /* float types should be passed in fpr's, as well as in the stack. */
940d5967 845 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13) {
41abdfbd
JG
846
847 if (len > 8)
199b2450 848 printf_unfiltered (
41abdfbd
JG
849"Fatal Error: a floating point parameter #%d with a size > 8 is found!\n", argno);
850
ade40d31
RP
851 memcpy (&registers[REGISTER_BYTE(FP0_REGNUM + 1 + f_argno)], VALUE_CONTENTS (arg),
852 len);
41abdfbd
JG
853 ++f_argno;
854 }
855
359a097f 856 write_memory (sp+24+(ii*4), (char *) VALUE_CONTENTS (arg), len);
41abdfbd
JG
857 ii += ((len + 3) & -4) / 4;
858 }
859 }
6c6afbb9 860 else
41abdfbd
JG
861 /* Secure stack areas first, before doing anything else. */
862 write_register (SP_REGNUM, sp);
863
41abdfbd
JG
864 saved_sp = dummy_frame_addr [dummy_frame_count - 1];
865 read_memory (saved_sp, tmp_buffer, 24);
866 write_memory (sp, tmp_buffer, 24);
867
b112f2ae
JK
868 /* set back chain properly */
869 store_address (tmp_buffer, 4, saved_sp);
870 write_memory (sp, tmp_buffer, 4);
41abdfbd 871
5f1c39ef 872 target_store_registers (-1);
41abdfbd
JG
873 return sp;
874}
875
876/* a given return value in `regbuf' with a type `valtype', extract and copy its
877 value into `valbuf' */
878
ecf4059f 879void
41abdfbd 880extract_return_value (valtype, regbuf, valbuf)
cd8a3d84
SS
881 struct type *valtype;
882 char regbuf[REGISTER_BYTES];
883 char *valbuf;
41abdfbd 884{
07781ac0 885 int offset = 0;
41abdfbd
JG
886
887 if (TYPE_CODE (valtype) == TYPE_CODE_FLT) {
888
889 double dd; float ff;
890 /* floats and doubles are returned in fpr1. fpr's have a size of 8 bytes.
891 We need to truncate the return value into float size (4 byte) if
892 necessary. */
893
894 if (TYPE_LENGTH (valtype) > 4) /* this is a double */
ade40d31 895 memcpy (valbuf, &regbuf[REGISTER_BYTE (FP0_REGNUM + 1)],
41abdfbd
JG
896 TYPE_LENGTH (valtype));
897 else { /* float */
ade40d31 898 memcpy (&dd, &regbuf[REGISTER_BYTE (FP0_REGNUM + 1)], 8);
41abdfbd 899 ff = (float)dd;
ade40d31 900 memcpy (valbuf, &ff, sizeof(float));
41abdfbd
JG
901 }
902 }
07781ac0 903 else {
41abdfbd 904 /* return value is copied starting from r3. */
07781ac0
PS
905 if (TARGET_BYTE_ORDER == BIG_ENDIAN
906 && TYPE_LENGTH (valtype) < REGISTER_RAW_SIZE (3))
907 offset = REGISTER_RAW_SIZE (3) - TYPE_LENGTH (valtype);
908
909 memcpy (valbuf, regbuf + REGISTER_BYTE (3) + offset,
910 TYPE_LENGTH (valtype));
911 }
41abdfbd
JG
912}
913
914
ecf4059f
JG
915/* keep structure return address in this variable.
916 FIXME: This is a horrid kludge which should not be allowed to continue
917 living. This only allows a single nested call to a structure-returning
918 function. Come on, guys! -- gnu@cygnus.com, Aug 92 */
41abdfbd
JG
919
920CORE_ADDR rs6000_struct_return_address;
921
922
c2e4669f
JG
923/* Indirect function calls use a piece of trampoline code to do context
924 switching, i.e. to set the new TOC table. Skip such code if we are on
925 its first instruction (as when we have single-stepped to here).
07aa9fdc
PS
926 Also skip shared library trampoline code (which is different from
927 indirect function call trampolines).
c2e4669f
JG
928 Result is desired PC to step until, or NULL if we are not in
929 trampoline code. */
41abdfbd 930
ecf4059f 931CORE_ADDR
41abdfbd 932skip_trampoline_code (pc)
cd8a3d84 933 CORE_ADDR pc;
41abdfbd
JG
934{
935 register unsigned int ii, op;
07aa9fdc 936 CORE_ADDR solib_target_pc;
41abdfbd
JG
937
938 static unsigned trampoline_code[] = {
939 0x800b0000, /* l r0,0x0(r11) */
940 0x90410014, /* st r2,0x14(r1) */
941 0x7c0903a6, /* mtctr r0 */
942 0x804b0004, /* l r2,0x4(r11) */
943 0x816b0008, /* l r11,0x8(r11) */
944 0x4e800420, /* bctr */
945 0x4e800020, /* br */
946 0
947 };
948
07aa9fdc
PS
949 /* If pc is in a shared library trampoline, return its target. */
950 solib_target_pc = find_solib_trampoline_target (pc);
951 if (solib_target_pc)
952 return solib_target_pc;
953
41abdfbd
JG
954 for (ii=0; trampoline_code[ii]; ++ii) {
955 op = read_memory_integer (pc + (ii*4), 4);
956 if (op != trampoline_code [ii])
359a097f 957 return 0;
41abdfbd
JG
958 }
959 ii = read_register (11); /* r11 holds destination addr */
960 pc = read_memory_integer (ii, 4); /* (r11) value */
961 return pc;
962}
963
068c9fd6 964/* Determines whether the function FI has a frame on the stack or not. */
cd8a3d84 965
ecf4059f 966int
068c9fd6
MM
967frameless_function_invocation (fi)
968 struct frame_info *fi;
ecf4059f
JG
969{
970 CORE_ADDR func_start;
63641491 971 struct rs6000_framedata fdata;
ecf4059f 972
4cc56716
PS
973 /* Don't even think about framelessness except on the innermost frame
974 or if the function was interrupted by a signal. */
975 if (fi->next != NULL && !fi->next->signal_handler_caller)
b0e932ad
JK
976 return 0;
977
4cc56716 978 func_start = get_pc_function_start (fi->pc);
ecf4059f
JG
979
980 /* If we failed to find the start of the function, it is a mistake
981 to inspect the instructions. */
982
983 if (!func_start)
4cc56716
PS
984 {
985 /* A frame with a zero PC is usually created by dereferencing a NULL
986 function pointer, normally causing an immediate core dump of the
987 inferior. Mark function as frameless, as the inferior has no chance
988 of setting up a stack frame. */
989 if (fi->pc == 0)
990 return 1;
991 else
992 return 0;
993 }
ecf4059f 994
4cc56716 995 func_start += FUNCTION_START_OFFSET;
068c9fd6
MM
996 (void) skip_prologue (func_start, &fdata);
997 return fdata.frameless;
ecf4059f
JG
998}
999
068c9fd6 1000/* Return the PC saved in a frame */
cd8a3d84 1001
068c9fd6
MM
1002unsigned long
1003frame_saved_pc (fi)
1004 struct frame_info *fi;
1005{
1006 CORE_ADDR func_start;
1007 struct rs6000_framedata fdata;
068c9fd6 1008
965dde97
PS
1009 if (fi->signal_handler_caller)
1010 return read_memory_integer (fi->frame + SIG_FRAME_PC_OFFSET, 4);
1011
068c9fd6
MM
1012 func_start = get_pc_function_start (fi->pc) + FUNCTION_START_OFFSET;
1013
1014 /* If we failed to find the start of the function, it is a mistake
1015 to inspect the instructions. */
1016 if (!func_start)
1017 return 0;
1018
1019 (void) skip_prologue (func_start, &fdata);
068c9fd6 1020
4b4c6c96 1021 if (fdata.lr_offset == 0 && fi->next != NULL)
4cc56716
PS
1022 {
1023 if (fi->next->signal_handler_caller)
1024 return read_memory_integer (fi->next->frame + SIG_FRAME_LR_OFFSET, 4);
1025 else
1026 return read_memory_integer (rs6000_frame_chain (fi) + DEFAULT_LR_SAVE,
1027 4);
1028 }
4b4c6c96
MM
1029
1030 if (fdata.lr_offset == 0)
1031 return read_register (LR_REGNUM);
1032
068c9fd6
MM
1033 return read_memory_integer (rs6000_frame_chain (fi) + fdata.lr_offset, 4);
1034}
ecf4059f
JG
1035
1036/* If saved registers of frame FI are not known yet, read and cache them.
63641491 1037 &FDATAP contains rs6000_framedata; TDATAP can be NULL,
ecf4059f
JG
1038 in which case the framedata are read. */
1039
1040static void
1041frame_get_cache_fsr (fi, fdatap)
1042 struct frame_info *fi;
63641491 1043 struct rs6000_framedata *fdatap;
ecf4059f
JG
1044{
1045 int ii;
1046 CORE_ADDR frame_addr;
63641491 1047 struct rs6000_framedata work_fdata;
ecf4059f
JG
1048
1049 if (fi->cache_fsr)
1050 return;
1051
1052 if (fdatap == NULL) {
1053 fdatap = &work_fdata;
068c9fd6 1054 (void) skip_prologue (get_pc_function_start (fi->pc), fdatap);
ecf4059f
JG
1055 }
1056
1057 fi->cache_fsr = (struct frame_saved_regs *)
1058 obstack_alloc (&frame_cache_obstack, sizeof (struct frame_saved_regs));
4ed97c9a 1059 memset (fi->cache_fsr, '\0', sizeof (struct frame_saved_regs));
ecf4059f
JG
1060
1061 if (fi->prev && fi->prev->frame)
1062 frame_addr = fi->prev->frame;
1063 else
1064 frame_addr = read_memory_integer (fi->frame, 4);
1065
1066 /* if != -1, fdatap->saved_fpr is the smallest number of saved_fpr.
965dde97 1067 All fpr's from saved_fpr to fp31 are saved. */
ecf4059f
JG
1068
1069 if (fdatap->saved_fpr >= 0) {
965dde97
PS
1070 int fpr_offset = frame_addr + fdatap->fpr_offset;
1071 for (ii = fdatap->saved_fpr; ii < 32; ii++) {
1072 fi->cache_fsr->regs [FP0_REGNUM + ii] = fpr_offset;
1073 fpr_offset += 8;
1074 }
ecf4059f
JG
1075 }
1076
1077 /* if != -1, fdatap->saved_gpr is the smallest number of saved_gpr.
965dde97 1078 All gpr's from saved_gpr to gpr31 are saved. */
ecf4059f 1079
965dde97
PS
1080 if (fdatap->saved_gpr >= 0) {
1081 int gpr_offset = frame_addr + fdatap->gpr_offset;
1082 for (ii = fdatap->saved_gpr; ii < 32; ii++) {
1083 fi->cache_fsr->regs [ii] = gpr_offset;
1084 gpr_offset += 4;
1085 }
1086 }
1087
1088 /* If != 0, fdatap->cr_offset is the offset from the frame that holds
1089 the CR. */
1090 if (fdatap->cr_offset != 0)
1091 fi->cache_fsr->regs [CR_REGNUM] = frame_addr + fdatap->cr_offset;
1092
1093 /* If != 0, fdatap->lr_offset is the offset from the frame that holds
1094 the LR. */
1095 if (fdatap->lr_offset != 0)
1096 fi->cache_fsr->regs [LR_REGNUM] = frame_addr + fdatap->lr_offset;
ecf4059f
JG
1097}
1098
1099/* Return the address of a frame. This is the inital %sp value when the frame
1100 was first allocated. For functions calling alloca(), it might be saved in
1101 an alloca register. */
1102
1103CORE_ADDR
1104frame_initial_stack_address (fi)
1105 struct frame_info *fi;
1106{
1107 CORE_ADDR tmpaddr;
63641491 1108 struct rs6000_framedata fdata;
ecf4059f
JG
1109 struct frame_info *callee_fi;
1110
1111 /* if the initial stack pointer (frame address) of this frame is known,
1112 just return it. */
1113
1114 if (fi->initial_sp)
1115 return fi->initial_sp;
1116
1117 /* find out if this function is using an alloca register.. */
1118
068c9fd6 1119 (void) skip_prologue (get_pc_function_start (fi->pc), &fdata);
ecf4059f
JG
1120
1121 /* if saved registers of this frame are not known yet, read and cache them. */
1122
1123 if (!fi->cache_fsr)
1124 frame_get_cache_fsr (fi, &fdata);
1125
1126 /* If no alloca register used, then fi->frame is the value of the %sp for
1127 this frame, and it is good enough. */
1128
1129 if (fdata.alloca_reg < 0) {
1130 fi->initial_sp = fi->frame;
1131 return fi->initial_sp;
1132 }
1133
1134 /* This function has an alloca register. If this is the top-most frame
1135 (with the lowest address), the value in alloca register is good. */
1136
1137 if (!fi->next)
1138 return fi->initial_sp = read_register (fdata.alloca_reg);
1139
1140 /* Otherwise, this is a caller frame. Callee has usually already saved
1141 registers, but there are exceptions (such as when the callee
1142 has no parameters). Find the address in which caller's alloca
1143 register is saved. */
1144
1145 for (callee_fi = fi->next; callee_fi; callee_fi = callee_fi->next) {
1146
1147 if (!callee_fi->cache_fsr)
cdb1cc92 1148 frame_get_cache_fsr (callee_fi, NULL);
ecf4059f
JG
1149
1150 /* this is the address in which alloca register is saved. */
1151
1152 tmpaddr = callee_fi->cache_fsr->regs [fdata.alloca_reg];
1153 if (tmpaddr) {
1154 fi->initial_sp = read_memory_integer (tmpaddr, 4);
1155 return fi->initial_sp;
1156 }
1157
1158 /* Go look into deeper levels of the frame chain to see if any one of
1159 the callees has saved alloca register. */
1160 }
1161
1162 /* If alloca register was not saved, by the callee (or any of its callees)
1163 then the value in the register is still good. */
1164
1165 return fi->initial_sp = read_register (fdata.alloca_reg);
1166}
1167
669caa9c 1168CORE_ADDR
f3649227
JK
1169rs6000_frame_chain (thisframe)
1170 struct frame_info *thisframe;
1171{
669caa9c 1172 CORE_ADDR fp;
f3649227
JK
1173 if (inside_entry_file ((thisframe)->pc))
1174 return 0;
cee86be3 1175 if (thisframe->signal_handler_caller)
9ed8604f 1176 fp = read_memory_integer (thisframe->frame + SIG_FRAME_FP_OFFSET, 4);
4cc56716
PS
1177 else if (thisframe->next != NULL
1178 && thisframe->next->signal_handler_caller
1179 && frameless_function_invocation (thisframe))
1180 /* A frameless function interrupted by a signal did not change the
1181 frame pointer. */
1182 fp = FRAME_FP (thisframe);
cee86be3
JK
1183 else
1184 fp = read_memory_integer ((thisframe)->frame, 4);
1185
f3649227
JK
1186 return fp;
1187}
ecf4059f 1188\f
65eaea27
JL
1189/* Return nonzero if ADDR (a function pointer) is in the data space and
1190 is therefore a special function pointer. */
1191
1192int
1193is_magic_function_pointer (addr)
1194 CORE_ADDR addr;
1195{
1196 struct obj_section *s;
1197
1198 s = find_pc_section (addr);
1199 if (s && s->the_bfd_section->flags & SEC_CODE)
1200 return 0;
1201 else
1202 return 1;
1203}
1204
5c172b4b
MM
1205#ifdef GDB_TARGET_POWERPC
1206int
1207gdb_print_insn_powerpc (memaddr, info)
1208 bfd_vma memaddr;
1209 disassemble_info *info;
1210{
1211 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1212 return print_insn_big_powerpc (memaddr, info);
1213 else
1214 return print_insn_little_powerpc (memaddr, info);
1215}
1216#endif
1217
18b46e7c
SS
1218void
1219_initialize_rs6000_tdep ()
1220{
1221 /* FIXME, this should not be decided via ifdef. */
1222#ifdef GDB_TARGET_POWERPC
5c172b4b 1223 tm_print_insn = gdb_print_insn_powerpc;
18b46e7c
SS
1224#else
1225 tm_print_insn = print_insn_rs6000;
1226#endif
1227}
This page took 0.386479 seconds and 4 git commands to generate.