Zap partial-stab.h:GDB_TARGET_IS_HPPA item.
[deliverable/binutils-gdb.git] / gdb / sh-tdep.c
CommitLineData
66d05e03
SS
1/* Target-dependent code for Hitachi Super-H, for GDB.
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
9faacb92
SC
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
9faacb92
SC
19
20/*
21 Contributed by Steve Chamberlain
22 sac@cygnus.com
23 */
24
25#include "defs.h"
26#include "frame.h"
27#include "obstack.h"
28#include "symtab.h"
29#include "gdbtypes.h"
30#include "gdbcmd.h"
66d05e03 31#include "gdbcore.h"
9faacb92
SC
32#include "value.h"
33#include "dis-asm.h"
5f2f2809 34
9faacb92
SC
35/* Prologue looks like
36 [mov.l <regs>,@-r15]...
37 [sts.l pr,@-r15]
38 [mov.l r14,@-r15]
39 [mov r15,r14]
40*/
41
42#define IS_STS(x) ((x) == 0x4f22)
43#define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
44#define GET_PUSHED_REG(x) (((x) >> 4) & 0xf)
45#define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
46#define IS_ADD_SP(x) (((x) & 0xff00) == 0x7f00)
c4deed18
SC
47#define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
48#define IS_SHLL_R3(x) ((x) == 0x4300)
49#define IS_ADD_R3SP(x) ((x) == 0x3f3c)
9faacb92
SC
50
51/* Skip any prologue before the guts of a function */
52
53CORE_ADDR
54sh_skip_prologue (start_pc)
55 CORE_ADDR start_pc;
9faacb92
SC
56{
57 int w;
58
59 w = read_memory_integer (start_pc, 2);
60 while (IS_STS (w)
61 || IS_PUSH (w)
c4deed18 62 || IS_MOV_SP_FP (w)
5f2f2809
SC
63 || IS_MOV_R3 (w)
64 || IS_ADD_R3SP (w)
65 || IS_ADD_SP (w)
66 || IS_SHLL_R3 (w))
9faacb92
SC
67 {
68 start_pc += 2;
69 w = read_memory_integer (start_pc, 2);
70 }
71
72 return start_pc;
73}
74
18b46e7c 75/* Disassemble an instruction. */
9faacb92
SC
76
77int
18b46e7c
SS
78gdb_print_insn_sh (memaddr, info)
79 bfd_vma memaddr;
80 disassemble_info *info;
9faacb92 81{
5f2f2809 82 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
5076ecd0 83 return print_insn_sh (memaddr, info);
5f2f2809 84 else
5076ecd0 85 return print_insn_shl (memaddr, info);
9faacb92 86}
18b46e7c 87
9faacb92
SC
88/* Given a GDB frame, determine the address of the calling function's frame.
89 This will be used to create a new GDB frame struct, and then
90 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
91
92 For us, the frame address is its stack pointer value, so we look up
93 the function prologue to determine the caller's sp value, and return it. */
94
669caa9c
SS
95CORE_ADDR
96sh_frame_chain (frame)
97 struct frame_info *frame;
9faacb92 98{
669caa9c
SS
99 if (!inside_entry_file (frame->pc))
100 return read_memory_integer (FRAME_FP (frame) + frame->f_offset, 4);
9faacb92
SC
101 else
102 return 0;
103}
104
66d05e03
SS
105/* Put here the code to store, into a struct frame_saved_regs, the
106 addresses of the saved registers of frame described by FRAME_INFO.
9faacb92 107 This includes special registers such as pc and fp saved in special
66d05e03
SS
108 ways in the stack frame. sp is even more special: the address we
109 return for it IS the sp for the next frame. */
9faacb92
SC
110
111void
112frame_find_saved_regs (fi, fsr)
113 struct frame_info *fi;
114 struct frame_saved_regs *fsr;
115{
7ccb1e44 116 int where[NUM_REGS];
9faacb92
SC
117 int rn;
118 int have_fp = 0;
119 int depth;
120 int pc;
121 int opc;
122 int insn;
c4deed18 123 int r3_val = 0;
9faacb92
SC
124
125 opc = pc = get_pc_function_start (fi->pc);
126
127 insn = read_memory_integer (pc, 2);
128
c4deed18
SC
129 fi->leaf_function = 1;
130 fi->f_offset = 0;
131
9faacb92
SC
132 for (rn = 0; rn < NUM_REGS; rn++)
133 where[rn] = -1;
134
135 depth = 0;
136
137 /* Loop around examining the prologue insns, but give up
138 after 15 of them, since we're getting silly then */
139 while (pc < opc + 15 * 2)
140 {
141 /* See where the registers will be saved to */
142 if (IS_PUSH (insn))
143 {
144 pc += 2;
145 rn = GET_PUSHED_REG (insn);
146 where[rn] = depth;
147 insn = read_memory_integer (pc, 2);
148 depth += 4;
149 }
150 else if (IS_STS (insn))
151 {
152 pc += 2;
153 where[PR_REGNUM] = depth;
154 insn = read_memory_integer (pc, 2);
c4deed18
SC
155 /* If we're storing the pr then this isn't a leaf */
156 fi->leaf_function = 0;
9faacb92
SC
157 depth += 4;
158 }
c4deed18
SC
159 else if (IS_MOV_R3 (insn))
160 {
5f2f2809
SC
161 r3_val = (char) (insn & 0xff);
162 pc += 2;
c4deed18
SC
163 insn = read_memory_integer (pc, 2);
164 }
165 else if (IS_SHLL_R3 (insn))
166 {
5f2f2809
SC
167 r3_val <<= 1;
168 pc += 2;
c4deed18
SC
169 insn = read_memory_integer (pc, 2);
170 }
171 else if (IS_ADD_R3SP (insn))
172 {
173 depth += -r3_val;
5f2f2809 174 pc += 2;
c4deed18
SC
175 insn = read_memory_integer (pc, 2);
176 }
9faacb92
SC
177 else if (IS_ADD_SP (insn))
178 {
179 pc += 2;
180 depth += -((char) (insn & 0xff));
181 insn = read_memory_integer (pc, 2);
182 }
df14b38b
SC
183 else
184 break;
9faacb92
SC
185 }
186
187 /* Now we know how deep things are, we can work out their addresses */
188
189 for (rn = 0; rn < NUM_REGS; rn++)
190 {
191 if (where[rn] >= 0)
192 {
193 if (rn == FP_REGNUM)
194 have_fp = 1;
195
196 fsr->regs[rn] = fi->frame - where[rn] + depth - 4;
197 }
198 else
199 {
200 fsr->regs[rn] = 0;
201 }
202 }
203
204 if (have_fp)
205 {
9faacb92
SC
206 fsr->regs[SP_REGNUM] = read_memory_integer (fsr->regs[FP_REGNUM], 4);
207 }
208 else
209 {
210 fsr->regs[SP_REGNUM] = fi->frame - 4;
211 }
212
c4deed18 213 fi->f_offset = depth - where[FP_REGNUM] - 4;
9faacb92
SC
214 /* Work out the return pc - either from the saved pr or the pr
215 value */
c4deed18
SC
216 /* Just called, so dig out the real return */
217 if (fi->return_pc == 0)
9faacb92
SC
218 {
219 fi->return_pc = read_register (PR_REGNUM) + 4;
220 }
5f2f2809
SC
221 else
222 {
223
224 if (fsr->regs[PR_REGNUM])
225 {
226 fi->return_pc = read_memory_integer (fsr->regs[PR_REGNUM], 4) + 4;
227 }
228 else
229 {
230 fi->return_pc = read_register (PR_REGNUM) + 4;
231 }
232 }
9faacb92
SC
233}
234
235/* initialize the extra info saved in a FRAME */
236
237void
238init_extra_frame_info (fromleaf, fi)
239 int fromleaf;
240 struct frame_info *fi;
241{
242 struct frame_saved_regs dummy;
66d05e03 243
9faacb92
SC
244 frame_find_saved_regs (fi, &dummy);
245}
246
247
248/* Discard from the stack the innermost frame,
249 restoring all saved registers. */
250
251void
252pop_frame ()
253{
669caa9c 254 register struct frame_info *frame = get_current_frame ();
9faacb92
SC
255 register CORE_ADDR fp;
256 register int regnum;
257 struct frame_saved_regs fsr;
9faacb92 258
669caa9c
SS
259 fp = FRAME_FP (frame);
260 get_frame_saved_regs (frame, &fsr);
9faacb92
SC
261
262 /* Copy regs from where they were saved in the frame */
263 for (regnum = 0; regnum < NUM_REGS; regnum++)
264 {
265 if (fsr.regs[regnum])
266 {
267 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
268 }
269 }
270
5f2f2809 271 write_register (PC_REGNUM, frame->return_pc);
9faacb92
SC
272 write_register (SP_REGNUM, fp + 4);
273 flush_cached_frames ();
9faacb92 274}
edd01519
SC
275
276/* Print the registers in a form similar to the E7000 */
669caa9c 277
edd01519
SC
278static void
279show_regs (args, from_tty)
669caa9c
SS
280 char *args;
281 int from_tty;
edd01519 282{
5f2f2809
SC
283 printf_filtered ("PC=%08x SR=%08x PR=%08x MACH=%08x MACHL=%08x\n",
284 read_register (PC_REGNUM),
285 read_register (SR_REGNUM),
286 read_register (PR_REGNUM),
287 read_register (MACH_REGNUM),
288 read_register (MACL_REGNUM));
289
290 printf_filtered ("R0-R7 %08x %08x %08x %08x %08x %08x %08x %08x\n",
291 read_register (0),
292 read_register (1),
293 read_register (2),
294 read_register (3),
295 read_register (4),
296 read_register (5),
297 read_register (6),
298 read_register (7));
299 printf_filtered ("R8-R15 %08x %08x %08x %08x %08x %08x %08x %08x\n",
300 read_register (8),
301 read_register (9),
302 read_register (10),
303 read_register (11),
304 read_register (12),
305 read_register (13),
306 read_register (14),
307 read_register (15));
edd01519 308}
c853c90d 309\f
976bb0be 310void
df14b38b
SC
311_initialize_sh_tdep ()
312{
18b46e7c
SS
313 tm_print_insn = gdb_print_insn_sh;
314
5f2f2809 315 add_com ("regs", class_vars, show_regs, "Print all registers");
df14b38b 316}
This page took 0.305771 seconds and 4 git commands to generate.