1 /* Target-machine dependent code for the AMD 29000
2 Copyright 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Jim Kingdon.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 extern CORE_ADDR text_start
; /* FIXME, kludge... */
30 /* Structure to hold cached info about function prologues. */
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;
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.
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
54 If MFP_USED is non-NULL, *MFP_USED is set to nonzero if a memory
55 frame pointer is being used. */
57 examine_prologue (pc
, rsize
, msize
, mfp_used
)
65 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (pc
);
66 struct prologue_info
*mi
= 0;
69 mi
= (struct prologue_info
*) msymbol
-> misc_info
;
77 valid
&= mi
->rsize_valid
;
82 valid
&= mi
->msize_valid
;
86 *mfp_used
= mi
->mfp_used
;
87 valid
&= mi
->mfp_valid
;
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)
105 /* If the frame is large, instead of a single instruction it
106 might be a pair of instructions:
107 const <reg>, <rsize * 4>
111 /* Possible value for rsize. */
114 if ((insn
& 0xff000000) != 0x03000000)
119 reg
= (insn
>> 8) & 0xff;
120 rsize0
= (((insn
>> 8) & 0xff00) | (insn
& 0xff));
122 insn
= read_memory_integer (p
, 4);
123 if ((insn
& 0xffffff00) != 0x24010100
124 || (insn
& 0xff) != reg
)
135 *rsize
= (insn
& 0xff);
139 /* Next instruction must be asgeu V_SPILL,gr1,rab. */
140 insn
= read_memory_integer (p
, 4);
141 if (insn
!= 0x5e40017e)
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)
158 /* However, for large frames it can be
159 const <reg>, <size *4>
165 if ((insn
& 0xff000000) == 0x03000000)
167 reg
= (insn
>> 8) & 0xff;
169 insn
= read_memory_integer (q
, 4);
170 if ((insn
& 0xffffff00) == 0x14810100
171 && (insn
& 0xff) == reg
)
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
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 */
191 if (mfp_used
!= NULL
)
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.
199 Normally this is just
202 insn
= read_memory_integer (p
, 4);
203 if ((insn
& 0xffffff00) == 0x257d7d00)
207 *msize
= insn
& 0xff;
211 /* For large frames, instead of a single instruction it might
215 consth <reg>, <msize> ; optional
222 if ((insn
& 0xff000000) == 0x03000000)
224 reg
= (insn
>> 8) & 0xff;
225 msize0
= ((insn
>> 8) & 0xff00) | (insn
& 0xff);
227 insn
= read_memory_integer (q
, 4);
228 /* Check for consth. */
229 if ((insn
& 0xff000000) == 0x02000000
230 && (insn
& 0x0000ff00) == reg
)
232 msize0
|= (insn
<< 8) & 0xff000000;
233 msize0
|= (insn
<< 16) & 0x00ff0000;
235 insn
= read_memory_integer (q
, 4);
237 /* Check for sub msp,msp,<reg>. */
238 if ((insn
& 0xffffff00) == 0x247d7d00
239 && (insn
& 0xff) == reg
)
253 /* Add a new cache entry. */
254 mi
= (struct prologue_info
*)xmalloc (sizeof (struct prologue_info
));
255 msymbol
-> misc_info
= (char *)mi
;
260 /* else, cache entry exists, but info is incomplete. */
272 if (mfp_used
!= NULL
)
274 mi
->mfp_used
= *mfp_used
;
281 /* Advance PC across any function entry prologue instructions
282 to reach some "real" code. */
288 return examine_prologue (pc
, (unsigned *)NULL
, (unsigned *)NULL
,
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. */
297 init_frame_info (innermost_frame
, fci
)
299 struct frame_info
*fci
;
311 fci
->frame
= read_register (GR1_REGNUM
);
313 fci
->frame
= fci
->next_frame
+ fci
->next
->rsize
;
315 #if CALL_DUMMY_LOCATION == ON_STACK
318 if (PC_IN_CALL_DUMMY (p
, 0, 0))
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. */
325 /* Dummy frames always use a memory frame pointer. */
327 read_register_stack_integer (fci
->frame
+ DUMMY_FRAME_RSIZE
- 4, 4);
331 func
= find_pc_function (p
);
333 p
= BLOCK_START (SYMBOL_BLOCK_VALUE (func
));
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)
345 /* Couldn't find the trace-back tag.
346 Something strange is going on. */
353 /* Advance to the first word of the function, i.e. the word
354 after the trace-back tag. */
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
);
366 fci
->saved_msp
= read_register (MSP_REGNUM
) + msize
;
372 read_register_stack_integer (fci
->frame
+ rsize
- 1, 4);
374 fci
->saved_msp
= fci
->next
->saved_msp
+ msize
;
379 init_extra_frame_info (fci
)
380 struct frame_info
*fci
;
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
);
387 /* We're in get_prev_frame_info.
388 Take care of everything in init_frame_pc. */
394 init_frame_pc (fromleaf
, fci
)
396 struct frame_info
*fci
;
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
);
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
408 frame_locals_address (fi
)
409 struct frame_info
*fi
;
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
;
416 return fi
->saved_msp
- fi
->msize
;
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. */
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. */
430 read_register_stack (memaddr
, myaddr
, actual_mem_addr
, lval
)
433 CORE_ADDR
*actual_mem_addr
;
434 enum lval_type
*lval
;
436 long rfb
= read_register (RFB_REGNUM
);
437 long rsp
= read_register (RSP_REGNUM
);
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.");
445 read_register_gen (regnum
, myaddr
);
447 *lval
= lval_register
;
448 if (actual_mem_addr
!= NULL
)
449 *actual_mem_addr
= REGISTER_BYTE (regnum
);
453 /* It's in the memory portion of the register stack. */
455 read_memory (memaddr
, myaddr
, 4);
458 if (actual_mem_addr
!= NULL
)
459 *actual_mem_addr
= memaddr
;
463 /* Analogous to read_memory_integer
464 except the length is understood to be 4. */
466 read_register_stack_integer (memaddr
, len
)
471 read_register_stack (memaddr
, &buf
, NULL
, NULL
);
472 SWAP_TARGET_AND_HOST (&buf
, 4);
476 /* Copy 4 bytes from GDB memory at MYADDR into inferior memory
477 at MEMADDR and put the actual address written into in
480 write_register_stack (memaddr
, myaddr
, actual_mem_addr
)
483 CORE_ADDR
*actual_mem_addr
;
485 long rfb
= read_register (RFB_REGNUM
);
486 long rsp
= read_register (RSP_REGNUM
);
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.");
494 write_register (regnum
, *(long *)myaddr
);
495 if (actual_mem_addr
!= NULL
)
496 *actual_mem_addr
= NULL
;
500 /* It's in the memory portion of the register stack. */
502 write_memory (memaddr
, myaddr
, 4);
503 if (actual_mem_addr
!= NULL
)
504 *actual_mem_addr
= memaddr
;
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.
514 The argument RAW_BUFFER must point to aligned memory. */
516 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lvalp
)
522 enum lval_type
*lvalp
;
524 struct frame_info
*fi
= get_frame_info (frame
);
528 /* Once something has a register number, it doesn't get optimized out. */
529 if (optimized
!= NULL
)
531 if (regnum
== RSP_REGNUM
)
533 if (raw_buffer
!= NULL
)
534 *(CORE_ADDR
*)raw_buffer
= fi
->frame
;
539 else if (regnum
== PC_REGNUM
)
541 if (raw_buffer
!= NULL
)
542 *(CORE_ADDR
*)raw_buffer
= fi
->pc
;
544 /* Not sure we have to do this. */
550 else if (regnum
== MSP_REGNUM
)
552 if (raw_buffer
!= NULL
)
554 if (fi
->next
!= NULL
)
555 *(CORE_ADDR
*)raw_buffer
= fi
->next
->saved_msp
;
557 *(CORE_ADDR
*)raw_buffer
= read_register (MSP_REGNUM
);
559 /* The value may have been computed, not fetched. */
564 else if (regnum
< LR0_REGNUM
|| regnum
>= LR0_REGNUM
+ 128)
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
);
571 *lvalp
= lval_register
;
573 *addrp
= REGISTER_BYTE (regnum
);
577 addr
= fi
->frame
+ (regnum
- LR0_REGNUM
) * 4;
578 if (raw_buffer
!= NULL
)
579 read_register_stack (addr
, raw_buffer
, &addr
, &lval
);
586 /* Discard from the stack the innermost frame,
587 restoring all saved registers. */
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
;
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
),
605 for (i
= 0; i
< DUMMY_SAVE_SR128
; ++i
)
607 (SR_REGNUM (i
+ 128),
608 read_register (LR0_REGNUM
+ DUMMY_ARG
/ 4 + i
));
609 for (i
= 0; i
< DUMMY_SAVE_GREGS
; ++i
)
612 read_register (LR0_REGNUM
+ DUMMY_ARG
/ 4 + DUMMY_SAVE_SR128
+ i
));
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);
624 int num_bytes
= lr1
- rfb
;
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)
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
);
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()));
643 /* Push an empty stack frame, to record the current PC, etc. */
650 CORE_ADDR msp
= read_register (MSP_REGNUM
);
654 write_register (LR0_REGNUM
, read_register (PC_REGNUM
));
656 /* Allocate the new frame. */
657 gr1
= read_register (GR1_REGNUM
) - DUMMY_FRAME_RSIZE
;
658 write_register (GR1_REGNUM
, gr1
);
660 rab
= read_register (RAB_REGNUM
);
663 /* We need to spill registers. */
664 int num_bytes
= rab
- gr1
;
665 CORE_ADDR rfb
= read_register (RFB_REGNUM
);
669 write_register (RFB_REGNUM
, rfb
- num_bytes
);
670 write_register (RAB_REGNUM
, gr1
);
671 for (i
= 0; i
< num_bytes
; i
+= 4)
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);
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);
683 /* Set the memory frame pointer. */
684 write_register (LR0_REGNUM
+ DUMMY_FRAME_RSIZE
/ 4 - 1, msp
);
686 /* Allocate arg_slop. */
687 write_register (MSP_REGNUM
, msp
- 16 * 4);
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)));
693 for (i
= 0; i
< DUMMY_SAVE_GREGS
; ++i
)
694 write_register (LR0_REGNUM
+ DUMMY_ARG
/ 4 + DUMMY_SAVE_SR128
+ i
,
695 read_register (RETURN_REGNUM
+ i
));
This page took 0.043993 seconds and 4 git commands to generate.