1 /* Target-machine dependent code for Hitachi Super-H, for GDB.
2 Copyright (C) 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 Contributed by Steve Chamberlain
33 #include "../opcodes/sh-opc.h"
36 /* Prologue looks like
37 [mov.l <regs>,@-r15]...
43 #define IS_STS(x) ((x) == 0x4f22)
44 #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
45 #define GET_PUSHED_REG(x) (((x) >> 4) & 0xf)
46 #define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
47 #define IS_ADD_SP(x) (((x) & 0xff00) == 0x7f00)
50 /* Skip any prologue before the guts of a function */
53 sh_skip_prologue (start_pc
)
59 w
= read_memory_integer (start_pc
, 2);
65 w
= read_memory_integer (start_pc
, 2);
71 /* Disassemble an instruction */
74 print_insn (memaddr
, stream
)
78 disassemble_info info
;
79 GDB_INIT_DISASSEMBLE_INFO (info
, stream
);
80 return print_insn_sh (memaddr
, &info
);
83 /* Given a GDB frame, determine the address of the calling function's frame.
84 This will be used to create a new GDB frame struct, and then
85 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
87 For us, the frame address is its stack pointer value, so we look up
88 the function prologue to determine the caller's sp value, and return it. */
91 sh_frame_chain (thisframe
)
94 if (!inside_entry_file (thisframe
->pc
))
95 return (read_memory_integer (FRAME_FP (thisframe
), 4));
100 /* Put here the code to store, into a struct frame_saved_regs,
101 the addresses of the saved registers of frame described by FRAME_INFO.
102 This includes special registers such as pc and fp saved in special
103 ways in the stack frame. sp is even more special:
104 the address we return for it IS the sp for the next frame. */
108 frame_find_saved_regs (fi
, fsr
)
109 struct frame_info
*fi
;
110 struct frame_saved_regs
*fsr
;
120 opc
= pc
= get_pc_function_start (fi
->pc
);
122 insn
= read_memory_integer (pc
, 2);
124 for (rn
= 0; rn
< NUM_REGS
; rn
++)
129 /* Loop around examining the prologue insns, but give up
130 after 15 of them, since we're getting silly then */
131 while (pc
< opc
+ 15 * 2)
133 /* See where the registers will be saved to */
137 rn
= GET_PUSHED_REG (insn
);
139 insn
= read_memory_integer (pc
, 2);
142 else if (IS_STS (insn
))
145 where
[PR_REGNUM
] = depth
;
146 insn
= read_memory_integer (pc
, 2);
149 else if (IS_ADD_SP (insn
))
152 depth
+= -((char) (insn
& 0xff));
153 insn
= read_memory_integer (pc
, 2);
158 /* Now we know how deep things are, we can work out their addresses */
160 for (rn
= 0; rn
< NUM_REGS
; rn
++)
167 fsr
->regs
[rn
] = fi
->frame
- where
[rn
] + depth
- 4;
178 fsr
->regs
[SP_REGNUM
] = read_memory_integer (fsr
->regs
[FP_REGNUM
], 4);
182 fsr
->regs
[SP_REGNUM
] = fi
->frame
- 4;
185 /* Remember the address of the frame pointer */
187 /* Work out the return pc - either from the saved pr or the pr
190 if (fsr
->regs
[PR_REGNUM
])
192 fi
->return_pc
= read_memory_integer (fsr
->regs
[PR_REGNUM
], 4) + 4;
196 fi
->return_pc
= read_register (PR_REGNUM
) + 4;
200 /* initialize the extra info saved in a FRAME */
203 init_extra_frame_info (fromleaf
, fi
)
205 struct frame_info
*fi
;
207 struct frame_saved_regs dummy
;
208 frame_find_saved_regs (fi
, &dummy
);
212 /* Discard from the stack the innermost frame,
213 restoring all saved registers. */
218 register FRAME frame
= get_current_frame ();
219 register CORE_ADDR fp
;
221 struct frame_saved_regs fsr
;
222 struct frame_info
*fi
;
224 fi
= get_frame_info (frame
);
226 get_frame_saved_regs (fi
, &fsr
);
228 /* Copy regs from where they were saved in the frame */
229 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
231 if (fsr
.regs
[regnum
])
233 write_register (regnum
, read_memory_integer (fsr
.regs
[regnum
], 4));
237 write_register (PC_REGNUM
, fi
->return_pc
);
238 write_register (SP_REGNUM
, fp
+ 4);
239 flush_cached_frames ();
240 set_current_frame (create_new_frame (read_register (FP_REGNUM
),
This page took 0.034407 seconds and 4 git commands to generate.