]>
Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Target-machine dependent code for the AMD 29000 |
7d9884b9 | 2 | Copyright 1990, 1991 Free Software Foundation, Inc. |
dd3b648e RP |
3 | Contributed by Cygnus Support. Written by Jim Kingdon. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
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 | |
99a7de40 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
dd3b648e RP |
11 | |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
20 | |
21 | #include "defs.h" | |
22 | #include "gdbcore.h" | |
dd3b648e RP |
23 | #include "frame.h" |
24 | #include "value.h" | |
dd3b648e RP |
25 | #include "symtab.h" |
26 | #include "inferior.h" | |
27 | ||
7730bd5a JG |
28 | extern CORE_ADDR text_start; /* FIXME, kludge... */ |
29 | ||
dd3b648e RP |
30 | /* Structure to hold cached info about function prologues. */ |
31 | struct prologue_info | |
32 | { | |
33 | CORE_ADDR pc; /* First addr after fn prologue */ | |
34 | unsigned rsize, msize; /* register stack frame size, mem stack ditto */ | |
35 | unsigned mfp_used : 1; /* memory frame pointer used */ | |
36 | unsigned rsize_valid : 1; /* Validity bits for the above */ | |
37 | unsigned msize_valid : 1; | |
38 | unsigned mfp_valid : 1; | |
39 | }; | |
40 | ||
41 | /* Examine the prologue of a function which starts at PC. Return | |
42 | the first addess past the prologue. If MSIZE is non-NULL, then | |
43 | set *MSIZE to the memory stack frame size. If RSIZE is non-NULL, | |
44 | then set *RSIZE to the register stack frame size (not including | |
45 | incoming arguments and the return address & frame pointer stored | |
46 | with them). If no prologue is found, *RSIZE is set to zero. | |
47 | If no prologue is found, or a prologue which doesn't involve | |
48 | allocating a memory stack frame, then set *MSIZE to zero. | |
49 | ||
50 | Note that both msize and rsize are in bytes. This is not consistent | |
51 | with the _User's Manual_ with respect to rsize, but it is much more | |
52 | convenient. | |
53 | ||
54 | If MFP_USED is non-NULL, *MFP_USED is set to nonzero if a memory | |
55 | frame pointer is being used. */ | |
56 | CORE_ADDR | |
57 | examine_prologue (pc, rsize, msize, mfp_used) | |
58 | CORE_ADDR pc; | |
59 | unsigned *msize; | |
60 | unsigned *rsize; | |
61 | int *mfp_used; | |
62 | { | |
63 | long insn; | |
64 | CORE_ADDR p = pc; | |
1ab3bf1b | 65 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc); |
dd3b648e RP |
66 | struct prologue_info *mi = 0; |
67 | ||
1ab3bf1b JG |
68 | if (msymbol != NULL) |
69 | mi = (struct prologue_info *) msymbol -> misc_info; | |
dd3b648e RP |
70 | |
71 | if (mi != 0) | |
72 | { | |
73 | int valid = 1; | |
74 | if (rsize != NULL) | |
75 | { | |
76 | *rsize = mi->rsize; | |
77 | valid &= mi->rsize_valid; | |
78 | } | |
79 | if (msize != NULL) | |
80 | { | |
81 | *msize = mi->msize; | |
82 | valid &= mi->msize_valid; | |
83 | } | |
84 | if (mfp_used != NULL) | |
85 | { | |
86 | *mfp_used = mi->mfp_used; | |
87 | valid &= mi->mfp_valid; | |
88 | } | |
89 | if (valid) | |
90 | return mi->pc; | |
91 | } | |
92 | ||
93 | if (rsize != NULL) | |
94 | *rsize = 0; | |
95 | if (msize != NULL) | |
96 | *msize = 0; | |
97 | if (mfp_used != NULL) | |
98 | *mfp_used = 0; | |
99 | ||
100 | /* Prologue must start with subtracting a constant from gr1. | |
101 | Normally this is sub gr1,gr1,<rsize * 4>. */ | |
102 | insn = read_memory_integer (p, 4); | |
103 | if ((insn & 0xffffff00) != 0x25010100) | |
104 | { | |
105 | /* If the frame is large, instead of a single instruction it | |
106 | might be a pair of instructions: | |
107 | const <reg>, <rsize * 4> | |
108 | sub gr1,gr1,<reg> | |
109 | */ | |
110 | int reg; | |
111 | /* Possible value for rsize. */ | |
112 | unsigned int rsize0; | |
113 | ||
114 | if ((insn & 0xff000000) != 0x03000000) | |
115 | { | |
116 | p = pc; | |
117 | goto done; | |
118 | } | |
119 | reg = (insn >> 8) & 0xff; | |
120 | rsize0 = (((insn >> 8) & 0xff00) | (insn & 0xff)); | |
121 | p += 4; | |
122 | insn = read_memory_integer (p, 4); | |
123 | if ((insn & 0xffffff00) != 0x24010100 | |
124 | || (insn & 0xff) != reg) | |
125 | { | |
126 | p = pc; | |
127 | goto done; | |
128 | } | |
129 | if (rsize != NULL) | |
130 | *rsize = rsize0; | |
131 | } | |
132 | else | |
133 | { | |
134 | if (rsize != NULL) | |
135 | *rsize = (insn & 0xff); | |
136 | } | |
137 | p += 4; | |
138 | ||
139 | /* Next instruction must be asgeu V_SPILL,gr1,rab. */ | |
140 | insn = read_memory_integer (p, 4); | |
141 | if (insn != 0x5e40017e) | |
142 | { | |
143 | p = pc; | |
144 | goto done; | |
145 | } | |
146 | p += 4; | |
147 | ||
148 | /* Next instruction usually sets the frame pointer (lr1) by adding | |
149 | <size * 4> from gr1. However, this can (and high C does) be | |
150 | deferred until anytime before the first function call. So it is | |
151 | OK if we don't see anything which sets lr1. */ | |
152 | /* Normally this is just add lr1,gr1,<size * 4>. */ | |
153 | insn = read_memory_integer (p, 4); | |
154 | if ((insn & 0xffffff00) == 0x15810100) | |
155 | p += 4; | |
156 | else | |
157 | { | |
158 | /* However, for large frames it can be | |
159 | const <reg>, <size *4> | |
160 | add lr1,gr1,<reg> | |
161 | */ | |
162 | int reg; | |
163 | CORE_ADDR q; | |
164 | ||
165 | if ((insn & 0xff000000) == 0x03000000) | |
166 | { | |
167 | reg = (insn >> 8) & 0xff; | |
168 | q = p + 4; | |
169 | insn = read_memory_integer (q, 4); | |
170 | if ((insn & 0xffffff00) == 0x14810100 | |
171 | && (insn & 0xff) == reg) | |
172 | p = q; | |
173 | } | |
174 | } | |
175 | ||
176 | /* Next comes "add lr{<rsize-1>},msp,0", but only if a memory | |
177 | frame pointer is in use. We just check for add lr<anything>,msp,0; | |
178 | we don't check this rsize against the first instruction, and | |
179 | we don't check that the trace-back tag indicates a memory frame pointer | |
180 | is in use. | |
181 | ||
182 | The recommended instruction is actually "sll lr<whatever>,msp,0". | |
183 | We check for that, too. Originally Jim Kingdon's code seemed | |
184 | to be looking for a "sub" instruction here, but the mask was set | |
185 | up to lose all the time. */ | |
186 | insn = read_memory_integer (p, 4); | |
187 | if (((insn & 0xff80ffff) == 0x15807d00) /* add */ | |
188 | || ((insn & 0xff80ffff) == 0x81807d00) ) /* sll */ | |
189 | { | |
190 | p += 4; | |
191 | if (mfp_used != NULL) | |
192 | *mfp_used = 1; | |
193 | } | |
194 | ||
195 | /* Next comes a subtraction from msp to allocate a memory frame, | |
196 | but only if a memory frame is | |
197 | being used. We don't check msize against the trace-back tag. | |
198 | ||
199 | Normally this is just | |
200 | sub msp,msp,<msize> | |
201 | */ | |
202 | insn = read_memory_integer (p, 4); | |
203 | if ((insn & 0xffffff00) == 0x257d7d00) | |
204 | { | |
205 | p += 4; | |
206 | if (msize != NULL) | |
207 | *msize = insn & 0xff; | |
208 | } | |
209 | else | |
210 | { | |
211 | /* For large frames, instead of a single instruction it might | |
212 | be | |
213 | ||
214 | const <reg>, <msize> | |
215 | consth <reg>, <msize> ; optional | |
216 | sub msp,msp,<reg> | |
217 | */ | |
218 | int reg; | |
219 | unsigned msize0; | |
220 | CORE_ADDR q = p; | |
221 | ||
222 | if ((insn & 0xff000000) == 0x03000000) | |
223 | { | |
224 | reg = (insn >> 8) & 0xff; | |
225 | msize0 = ((insn >> 8) & 0xff00) | (insn & 0xff); | |
226 | q += 4; | |
227 | insn = read_memory_integer (q, 4); | |
228 | /* Check for consth. */ | |
229 | if ((insn & 0xff000000) == 0x02000000 | |
230 | && (insn & 0x0000ff00) == reg) | |
231 | { | |
232 | msize0 |= (insn << 8) & 0xff000000; | |
233 | msize0 |= (insn << 16) & 0x00ff0000; | |
234 | q += 4; | |
235 | insn = read_memory_integer (q, 4); | |
236 | } | |
237 | /* Check for sub msp,msp,<reg>. */ | |
238 | if ((insn & 0xffffff00) == 0x247d7d00 | |
239 | && (insn & 0xff) == reg) | |
240 | { | |
241 | p = q + 4; | |
242 | if (msize != NULL) | |
243 | *msize = msize0; | |
244 | } | |
245 | } | |
246 | } | |
247 | ||
248 | done: | |
1ab3bf1b | 249 | if (msymbol != NULL) |
dd3b648e RP |
250 | { |
251 | if (mi == 0) | |
252 | { | |
253 | /* Add a new cache entry. */ | |
254 | mi = (struct prologue_info *)xmalloc (sizeof (struct prologue_info)); | |
1ab3bf1b | 255 | msymbol -> misc_info = (char *)mi; |
dd3b648e RP |
256 | mi->rsize_valid = 0; |
257 | mi->msize_valid = 0; | |
258 | mi->mfp_valid = 0; | |
259 | } | |
260 | /* else, cache entry exists, but info is incomplete. */ | |
261 | mi->pc = p; | |
262 | if (rsize != NULL) | |
263 | { | |
264 | mi->rsize = *rsize; | |
265 | mi->rsize_valid = 1; | |
266 | } | |
267 | if (msize != NULL) | |
268 | { | |
269 | mi->msize = *msize; | |
270 | mi->msize_valid = 1; | |
271 | } | |
272 | if (mfp_used != NULL) | |
273 | { | |
274 | mi->mfp_used = *mfp_used; | |
275 | mi->mfp_valid = 1; | |
276 | } | |
277 | } | |
278 | return p; | |
279 | } | |
280 | ||
281 | /* Advance PC across any function entry prologue instructions | |
282 | to reach some "real" code. */ | |
283 | ||
284 | CORE_ADDR | |
285 | skip_prologue (pc) | |
286 | CORE_ADDR pc; | |
287 | { | |
288 | return examine_prologue (pc, (unsigned *)NULL, (unsigned *)NULL, | |
289 | (int *)NULL); | |
290 | } | |
291 | ||
292 | /* Initialize the frame. In addition to setting "extra" frame info, | |
293 | we also set ->frame because we use it in a nonstandard way, and ->pc | |
294 | because we need to know it to get the other stuff. See the diagram | |
295 | of stacks and the frame cache in tm-29k.h for more detail. */ | |
296 | static void | |
297 | init_frame_info (innermost_frame, fci) | |
298 | int innermost_frame; | |
299 | struct frame_info *fci; | |
300 | { | |
301 | CORE_ADDR p; | |
302 | long insn; | |
303 | unsigned rsize; | |
304 | unsigned msize; | |
305 | int mfp_used; | |
306 | struct symbol *func; | |
307 | ||
308 | p = fci->pc; | |
309 | ||
310 | if (innermost_frame) | |
311 | fci->frame = read_register (GR1_REGNUM); | |
312 | else | |
313 | fci->frame = fci->next_frame + fci->next->rsize; | |
314 | ||
315 | #if CALL_DUMMY_LOCATION == ON_STACK | |
316 | This wont work; | |
317 | #else | |
318 | if (PC_IN_CALL_DUMMY (p, 0, 0)) | |
319 | #endif | |
320 | { | |
321 | fci->rsize = DUMMY_FRAME_RSIZE; | |
322 | /* This doesn't matter since we never try to get locals or args | |
323 | from a dummy frame. */ | |
324 | fci->msize = 0; | |
325 | /* Dummy frames always use a memory frame pointer. */ | |
326 | fci->saved_msp = | |
327 | read_register_stack_integer (fci->frame + DUMMY_FRAME_RSIZE - 4, 4); | |
328 | return; | |
329 | } | |
330 | ||
331 | func = find_pc_function (p); | |
332 | if (func != NULL) | |
333 | p = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); | |
334 | else | |
335 | { | |
336 | /* Search backward to find the trace-back tag. However, | |
337 | do not trace back beyond the start of the text segment | |
338 | (just as a sanity check to avoid going into never-never land). */ | |
339 | while (p >= text_start | |
340 | && ((insn = read_memory_integer (p, 4)) & 0xff000000) != 0) | |
341 | p -= 4; | |
342 | ||
343 | if (p < text_start) | |
344 | { | |
345 | /* Couldn't find the trace-back tag. | |
346 | Something strange is going on. */ | |
347 | fci->saved_msp = 0; | |
348 | fci->rsize = 0; | |
349 | fci->msize = 0; | |
350 | return; | |
351 | } | |
352 | else | |
353 | /* Advance to the first word of the function, i.e. the word | |
354 | after the trace-back tag. */ | |
355 | p += 4; | |
356 | } | |
357 | /* We've found the start of the function. Since High C interchanges | |
358 | the meanings of bits 23 and 22 (as of Jul 90), and we | |
359 | need to look at the prologue anyway to figure out | |
360 | what rsize is, ignore the contents of the trace-back tag. */ | |
361 | examine_prologue (p, &rsize, &msize, &mfp_used); | |
362 | fci->rsize = rsize; | |
363 | fci->msize = msize; | |
364 | if (innermost_frame) | |
365 | { | |
366 | fci->saved_msp = read_register (MSP_REGNUM) + msize; | |
367 | } | |
368 | else | |
369 | { | |
370 | if (mfp_used) | |
371 | fci->saved_msp = | |
372 | read_register_stack_integer (fci->frame + rsize - 1, 4); | |
373 | else | |
374 | fci->saved_msp = fci->next->saved_msp + msize; | |
375 | } | |
376 | } | |
377 | ||
378 | void | |
379 | init_extra_frame_info (fci) | |
380 | struct frame_info *fci; | |
381 | { | |
382 | if (fci->next == 0) | |
383 | /* Assume innermost frame. May produce strange results for "info frame" | |
384 | but there isn't any way to tell the difference. */ | |
385 | init_frame_info (1, fci); | |
17f7e032 JG |
386 | else { |
387 | /* We're in get_prev_frame_info. | |
388 | Take care of everything in init_frame_pc. */ | |
389 | ; | |
390 | } | |
dd3b648e RP |
391 | } |
392 | ||
393 | void | |
394 | init_frame_pc (fromleaf, fci) | |
395 | int fromleaf; | |
396 | struct frame_info *fci; | |
397 | { | |
398 | fci->pc = (fromleaf ? SAVED_PC_AFTER_CALL (fci->next) : | |
399 | fci->next ? FRAME_SAVED_PC (fci->next) : read_pc ()); | |
400 | init_frame_info (0, fci); | |
401 | } | |
402 | \f | |
403 | /* Local variables (i.e. LOC_LOCAL) are on the memory stack, with their | |
404 | offsets being relative to the memory stack pointer (high C) or | |
405 | saved_msp (gcc). */ | |
406 | ||
407 | CORE_ADDR | |
408 | frame_locals_address (fi) | |
409 | struct frame_info *fi; | |
410 | { | |
411 | struct block *b = block_for_pc (fi->pc); | |
412 | /* If compiled without -g, assume GCC. */ | |
413 | if (b == NULL || BLOCK_GCC_COMPILED (b)) | |
414 | return fi->saved_msp; | |
415 | else | |
416 | return fi->saved_msp - fi->msize; | |
417 | } | |
418 | \f | |
419 | /* Routines for reading the register stack. The caller gets to treat | |
420 | the register stack as a uniform stack in memory, from address $gr1 | |
421 | straight through $rfb and beyond. */ | |
422 | ||
423 | /* Analogous to read_memory except the length is understood to be 4. | |
424 | Also, myaddr can be NULL (meaning don't bother to read), and | |
425 | if actual_mem_addr is non-NULL, store there the address that it | |
426 | was fetched from (or if from a register the offset within | |
427 | registers). Set *LVAL to lval_memory or lval_register, depending | |
428 | on where it came from. */ | |
429 | void | |
430 | read_register_stack (memaddr, myaddr, actual_mem_addr, lval) | |
431 | CORE_ADDR memaddr; | |
432 | char *myaddr; | |
433 | CORE_ADDR *actual_mem_addr; | |
434 | enum lval_type *lval; | |
435 | { | |
436 | long rfb = read_register (RFB_REGNUM); | |
437 | long rsp = read_register (RSP_REGNUM); | |
438 | if (memaddr < rfb) | |
439 | { | |
440 | /* It's in a register. */ | |
441 | int regnum = (memaddr - rsp) / 4 + LR0_REGNUM; | |
442 | if (regnum < LR0_REGNUM || regnum > LR0_REGNUM + 127) | |
443 | error ("Attempt to read register stack out of range."); | |
444 | if (myaddr != NULL) | |
445 | read_register_gen (regnum, myaddr); | |
446 | if (lval != NULL) | |
447 | *lval = lval_register; | |
448 | if (actual_mem_addr != NULL) | |
449 | *actual_mem_addr = REGISTER_BYTE (regnum); | |
450 | } | |
451 | else | |
452 | { | |
453 | /* It's in the memory portion of the register stack. */ | |
454 | if (myaddr != NULL) | |
455 | read_memory (memaddr, myaddr, 4); | |
456 | if (lval != NULL) | |
457 | *lval = lval_memory; | |
458 | if (actual_mem_addr != NULL) | |
17f7e032 | 459 | *actual_mem_addr = memaddr; |
dd3b648e RP |
460 | } |
461 | } | |
462 | ||
463 | /* Analogous to read_memory_integer | |
464 | except the length is understood to be 4. */ | |
465 | long | |
466 | read_register_stack_integer (memaddr, len) | |
467 | CORE_ADDR memaddr; | |
468 | int len; | |
469 | { | |
470 | long buf; | |
471 | read_register_stack (memaddr, &buf, NULL, NULL); | |
472 | SWAP_TARGET_AND_HOST (&buf, 4); | |
473 | return buf; | |
474 | } | |
475 | ||
476 | /* Copy 4 bytes from GDB memory at MYADDR into inferior memory | |
477 | at MEMADDR and put the actual address written into in | |
478 | *ACTUAL_MEM_ADDR. */ | |
479 | static void | |
480 | write_register_stack (memaddr, myaddr, actual_mem_addr) | |
481 | CORE_ADDR memaddr; | |
482 | char *myaddr; | |
483 | CORE_ADDR *actual_mem_addr; | |
484 | { | |
485 | long rfb = read_register (RFB_REGNUM); | |
486 | long rsp = read_register (RSP_REGNUM); | |
487 | if (memaddr < rfb) | |
488 | { | |
489 | /* It's in a register. */ | |
490 | int regnum = (memaddr - rsp) / 4 + LR0_REGNUM; | |
491 | if (regnum < LR0_REGNUM || regnum > LR0_REGNUM + 127) | |
492 | error ("Attempt to read register stack out of range."); | |
493 | if (myaddr != NULL) | |
494 | write_register (regnum, *(long *)myaddr); | |
495 | if (actual_mem_addr != NULL) | |
496 | *actual_mem_addr = NULL; | |
497 | } | |
498 | else | |
499 | { | |
500 | /* It's in the memory portion of the register stack. */ | |
501 | if (myaddr != NULL) | |
502 | write_memory (memaddr, myaddr, 4); | |
503 | if (actual_mem_addr != NULL) | |
17f7e032 | 504 | *actual_mem_addr = memaddr; |
dd3b648e RP |
505 | } |
506 | } | |
507 | \f | |
508 | /* Find register number REGNUM relative to FRAME and put its | |
509 | (raw) contents in *RAW_BUFFER. Set *OPTIMIZED if the variable | |
510 | was optimized out (and thus can't be fetched). If the variable | |
511 | was fetched from memory, set *ADDRP to where it was fetched from, | |
512 | otherwise it was fetched from a register. | |
513 | ||
514 | The argument RAW_BUFFER must point to aligned memory. */ | |
515 | void | |
516 | get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lvalp) | |
517 | char *raw_buffer; | |
518 | int *optimized; | |
519 | CORE_ADDR *addrp; | |
520 | FRAME frame; | |
521 | int regnum; | |
522 | enum lval_type *lvalp; | |
523 | { | |
524 | struct frame_info *fi = get_frame_info (frame); | |
525 | CORE_ADDR addr; | |
526 | enum lval_type lval; | |
527 | ||
528 | /* Once something has a register number, it doesn't get optimized out. */ | |
529 | if (optimized != NULL) | |
530 | *optimized = 0; | |
531 | if (regnum == RSP_REGNUM) | |
532 | { | |
533 | if (raw_buffer != NULL) | |
534 | *(CORE_ADDR *)raw_buffer = fi->frame; | |
535 | if (lvalp != NULL) | |
536 | *lvalp = not_lval; | |
537 | return; | |
538 | } | |
539 | else if (regnum == PC_REGNUM) | |
540 | { | |
541 | if (raw_buffer != NULL) | |
542 | *(CORE_ADDR *)raw_buffer = fi->pc; | |
543 | ||
544 | /* Not sure we have to do this. */ | |
545 | if (lvalp != NULL) | |
546 | *lvalp = not_lval; | |
547 | ||
548 | return; | |
549 | } | |
550 | else if (regnum == MSP_REGNUM) | |
551 | { | |
552 | if (raw_buffer != NULL) | |
553 | { | |
554 | if (fi->next != NULL) | |
555 | *(CORE_ADDR *)raw_buffer = fi->next->saved_msp; | |
556 | else | |
557 | *(CORE_ADDR *)raw_buffer = read_register (MSP_REGNUM); | |
558 | } | |
559 | /* The value may have been computed, not fetched. */ | |
560 | if (lvalp != NULL) | |
561 | *lvalp = not_lval; | |
562 | return; | |
563 | } | |
564 | else if (regnum < LR0_REGNUM || regnum >= LR0_REGNUM + 128) | |
565 | { | |
566 | /* These registers are not saved over procedure calls, | |
567 | so just print out the current values. */ | |
568 | if (raw_buffer != NULL) | |
569 | *(CORE_ADDR *)raw_buffer = read_register (regnum); | |
570 | if (lvalp != NULL) | |
571 | *lvalp = lval_register; | |
572 | if (addrp != NULL) | |
573 | *addrp = REGISTER_BYTE (regnum); | |
574 | return; | |
575 | } | |
576 | ||
577 | addr = fi->frame + (regnum - LR0_REGNUM) * 4; | |
578 | if (raw_buffer != NULL) | |
579 | read_register_stack (addr, raw_buffer, &addr, &lval); | |
580 | if (lvalp != NULL) | |
581 | *lvalp = lval; | |
582 | if (addrp != NULL) | |
583 | *addrp = addr; | |
584 | } | |
585 | \f | |
586 | /* Discard from the stack the innermost frame, | |
587 | restoring all saved registers. */ | |
588 | ||
589 | void | |
590 | pop_frame () | |
591 | { | |
592 | FRAME frame = get_current_frame (); | |
593 | struct frame_info *fi = get_frame_info (frame); | |
594 | CORE_ADDR rfb = read_register (RFB_REGNUM); | |
595 | CORE_ADDR gr1 = fi->frame + fi->rsize; | |
596 | CORE_ADDR lr1; | |
597 | CORE_ADDR ret_addr; | |
598 | int i; | |
599 | ||
600 | /* If popping a dummy frame, need to restore registers. */ | |
601 | if (PC_IN_CALL_DUMMY (read_register (PC_REGNUM), | |
602 | read_register (SP_REGNUM), | |
603 | FRAME_FP (fi))) | |
604 | { | |
605 | for (i = 0; i < DUMMY_SAVE_SR128; ++i) | |
606 | write_register | |
607 | (SR_REGNUM (i + 128), | |
608 | read_register (LR0_REGNUM + DUMMY_ARG / 4 + i)); | |
6093e5b0 | 609 | for (i = 0; i < DUMMY_SAVE_GREGS; ++i) |
dd3b648e | 610 | write_register |
6093e5b0 | 611 | (RETURN_REGNUM + i, |
dd3b648e RP |
612 | read_register (LR0_REGNUM + DUMMY_ARG / 4 + DUMMY_SAVE_SR128 + i)); |
613 | } | |
614 | ||
615 | /* Restore the memory stack pointer. */ | |
616 | write_register (MSP_REGNUM, fi->saved_msp); | |
617 | /* Restore the register stack pointer. */ | |
618 | write_register (GR1_REGNUM, gr1); | |
619 | /* Check whether we need to fill registers. */ | |
620 | lr1 = read_register (LR0_REGNUM + 1); | |
621 | if (lr1 > rfb) | |
622 | { | |
623 | /* Fill. */ | |
624 | int num_bytes = lr1 - rfb; | |
625 | int i; | |
626 | long word; | |
627 | write_register (RAB_REGNUM, read_register (RAB_REGNUM) + num_bytes); | |
628 | write_register (RFB_REGNUM, lr1); | |
629 | for (i = 0; i < num_bytes; i += 4) | |
630 | { | |
631 | /* Note: word is in host byte order. */ | |
632 | word = read_memory_integer (rfb + i, 4); | |
633 | write_register (LR0_REGNUM + ((rfb - gr1) % 0x80) + i / 4, word); | |
634 | } | |
635 | } | |
636 | ret_addr = read_register (LR0_REGNUM); | |
637 | write_register (PC_REGNUM, ret_addr); | |
638 | write_register (NPC_REGNUM, ret_addr + 4); | |
639 | flush_cached_frames (); | |
640 | set_current_frame (create_new_frame (0, read_pc())); | |
641 | } | |
642 | ||
643 | /* Push an empty stack frame, to record the current PC, etc. */ | |
644 | ||
645 | void | |
646 | push_dummy_frame () | |
647 | { | |
648 | long w; | |
649 | CORE_ADDR rab, gr1; | |
650 | CORE_ADDR msp = read_register (MSP_REGNUM); | |
651 | int i; | |
652 | ||
653 | /* Save the PC. */ | |
654 | write_register (LR0_REGNUM, read_register (PC_REGNUM)); | |
655 | ||
656 | /* Allocate the new frame. */ | |
657 | gr1 = read_register (GR1_REGNUM) - DUMMY_FRAME_RSIZE; | |
658 | write_register (GR1_REGNUM, gr1); | |
659 | ||
660 | rab = read_register (RAB_REGNUM); | |
661 | if (gr1 < rab) | |
662 | { | |
663 | /* We need to spill registers. */ | |
664 | int num_bytes = rab - gr1; | |
665 | CORE_ADDR rfb = read_register (RFB_REGNUM); | |
666 | int i; | |
667 | long word; | |
668 | ||
669 | write_register (RFB_REGNUM, rfb - num_bytes); | |
670 | write_register (RAB_REGNUM, gr1); | |
671 | for (i = 0; i < num_bytes; i += 4) | |
672 | { | |
673 | /* Note: word is in target byte order. */ | |
674 | read_register_gen (LR0_REGNUM + i / 4, &word, 4); | |
675 | write_memory (rfb - num_bytes + i, &word, 4); | |
676 | } | |
677 | } | |
678 | ||
679 | /* There are no arguments in to the dummy frame, so we don't need | |
680 | more than rsize plus the return address and lr1. */ | |
681 | write_register (LR0_REGNUM + 1, gr1 + DUMMY_FRAME_RSIZE + 2 * 4); | |
682 | ||
683 | /* Set the memory frame pointer. */ | |
684 | write_register (LR0_REGNUM + DUMMY_FRAME_RSIZE / 4 - 1, msp); | |
685 | ||
686 | /* Allocate arg_slop. */ | |
687 | write_register (MSP_REGNUM, msp - 16 * 4); | |
688 | ||
689 | /* Save registers. */ | |
690 | for (i = 0; i < DUMMY_SAVE_SR128; ++i) | |
691 | write_register (LR0_REGNUM + DUMMY_ARG / 4 + i, | |
692 | read_register (SR_REGNUM (i + 128))); | |
6093e5b0 | 693 | for (i = 0; i < DUMMY_SAVE_GREGS; ++i) |
dd3b648e | 694 | write_register (LR0_REGNUM + DUMMY_ARG / 4 + DUMMY_SAVE_SR128 + i, |
6093e5b0 | 695 | read_register (RETURN_REGNUM + i)); |
dd3b648e | 696 | } |