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"
37 /* Prologue looks like
38 [mov.l <regs>,@-r15]...
44 #define IS_STS(x) ((x) == 0x4f22)
45 #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
46 #define GET_PUSHED_REG(x) (((x) >> 4) & 0xf)
47 #define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
48 #define IS_ADD_SP(x) (((x) & 0xff00) == 0x7f00)
49 #define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
50 #define IS_SHLL_R3(x) ((x) == 0x4300)
51 #define IS_ADD_R3SP(x) ((x) == 0x3f3c)
53 /* Skip any prologue before the guts of a function */
56 sh_skip_prologue (start_pc)
61 w = read_memory_integer (start_pc, 2);
71 w = read_memory_integer (start_pc, 2);
77 /* Disassemble an instruction. */
80 gdb_print_insn_sh (memaddr, info)
82 disassemble_info *info;
84 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
85 return print_insn_sh (memaddr, info);
87 return print_insn_shl (memaddr, info);
90 /* Given a GDB frame, determine the address of the calling function's frame.
91 This will be used to create a new GDB frame struct, and then
92 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
94 For us, the frame address is its stack pointer value, so we look up
95 the function prologue to determine the caller's sp value, and return it. */
98 sh_frame_chain (frame)
99 struct frame_info *frame;
101 if (!inside_entry_file (frame->pc))
102 return read_memory_integer (FRAME_FP (frame) + frame->f_offset, 4);
107 /* Put here the code to store, into a struct frame_saved_regs,
108 the addresses of the saved registers of frame described by FRAME_INFO.
109 This includes special registers such as pc and fp saved in special
110 ways in the stack frame. sp is even more special:
111 the address we return for it IS the sp for the next frame. */
115 frame_find_saved_regs (fi, fsr)
116 struct frame_info *fi;
117 struct frame_saved_regs *fsr;
129 opc = pc = get_pc_function_start (fi->pc);
131 insn = read_memory_integer (pc, 2);
133 fi->leaf_function = 1;
136 for (rn = 0; rn < NUM_REGS; rn++)
141 /* Loop around examining the prologue insns, but give up
142 after 15 of them, since we're getting silly then */
143 while (pc < opc + 15 * 2)
145 /* See where the registers will be saved to */
149 rn = GET_PUSHED_REG (insn);
151 insn = read_memory_integer (pc, 2);
154 else if (IS_STS (insn))
157 where[PR_REGNUM] = depth;
158 insn = read_memory_integer (pc, 2);
159 /* If we're storing the pr then this isn't a leaf */
160 fi->leaf_function = 0;
163 else if (IS_MOV_R3 (insn))
165 r3_val = (char) (insn & 0xff);
167 insn = read_memory_integer (pc, 2);
169 else if (IS_SHLL_R3 (insn))
173 insn = read_memory_integer (pc, 2);
175 else if (IS_ADD_R3SP (insn))
179 insn = read_memory_integer (pc, 2);
181 else if (IS_ADD_SP (insn))
184 depth += -((char) (insn & 0xff));
185 insn = read_memory_integer (pc, 2);
191 /* Now we know how deep things are, we can work out their addresses */
193 for (rn = 0; rn < NUM_REGS; rn++)
200 fsr->regs[rn] = fi->frame - where[rn] + depth - 4;
210 fsr->regs[SP_REGNUM] = read_memory_integer (fsr->regs[FP_REGNUM], 4);
214 fsr->regs[SP_REGNUM] = fi->frame - 4;
217 fi->f_offset = depth - where[FP_REGNUM] - 4;
218 /* Work out the return pc - either from the saved pr or the pr
220 /* Just called, so dig out the real return */
221 if (fi->return_pc == 0)
223 fi->return_pc = read_register (PR_REGNUM) + 4;
228 if (fsr->regs[PR_REGNUM])
230 fi->return_pc = read_memory_integer (fsr->regs[PR_REGNUM], 4) + 4;
234 fi->return_pc = read_register (PR_REGNUM) + 4;
239 /* initialize the extra info saved in a FRAME */
242 init_extra_frame_info (fromleaf, fi)
244 struct frame_info *fi;
246 struct frame_saved_regs dummy;
247 frame_find_saved_regs (fi, &dummy);
251 /* Discard from the stack the innermost frame,
252 restoring all saved registers. */
257 register struct frame_info *frame = get_current_frame ();
258 register CORE_ADDR fp;
260 struct frame_saved_regs fsr;
262 fp = FRAME_FP (frame);
263 get_frame_saved_regs (frame, &fsr);
265 /* Copy regs from where they were saved in the frame */
266 for (regnum = 0; regnum < NUM_REGS; regnum++)
268 if (fsr.regs[regnum])
270 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
274 write_register (PC_REGNUM, frame->return_pc);
275 write_register (SP_REGNUM, fp + 4);
276 flush_cached_frames ();
279 /* Print the registers in a form similar to the E7000 */
282 show_regs (args, from_tty)
286 printf_filtered ("PC=%08x SR=%08x PR=%08x MACH=%08x MACHL=%08x\n",
287 read_register (PC_REGNUM),
288 read_register (SR_REGNUM),
289 read_register (PR_REGNUM),
290 read_register (MACH_REGNUM),
291 read_register (MACL_REGNUM));
293 printf_filtered ("R0-R7 %08x %08x %08x %08x %08x %08x %08x %08x\n",
302 printf_filtered ("R8-R15 %08x %08x %08x %08x %08x %08x %08x %08x\n",
315 _initialize_sh_tdep ()
317 extern int sim_memory_size;
319 tm_print_insn = gdb_print_insn_sh;
321 /* FIXME, there should be a way to make a CORE_ADDR variable settable. */
323 (add_set_cmd ("memory_size", class_support, var_uinteger,
324 (char *) &sim_memory_size,
325 "Set simulated memory size of simulator target.", &setlist),
328 add_com ("regs", class_vars, show_regs, "Print all registers");