1 |
1181 |
sfurman |
/* Target-dependent code for Mitsubishi D10V, for GDB.
|
2 |
|
|
|
3 |
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
|
4 |
|
|
Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
This file is part of GDB.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program; if not, write to the Free Software
|
20 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
21 |
|
|
Boston, MA 02111-1307, USA. */
|
22 |
|
|
|
23 |
|
|
/* Contributed by Martin Hunt, hunt@cygnus.com */
|
24 |
|
|
|
25 |
|
|
#include "defs.h"
|
26 |
|
|
#include "frame.h"
|
27 |
|
|
#include "symtab.h"
|
28 |
|
|
#include "gdbtypes.h"
|
29 |
|
|
#include "gdbcmd.h"
|
30 |
|
|
#include "gdbcore.h"
|
31 |
|
|
#include "gdb_string.h"
|
32 |
|
|
#include "value.h"
|
33 |
|
|
#include "inferior.h"
|
34 |
|
|
#include "dis-asm.h"
|
35 |
|
|
#include "symfile.h"
|
36 |
|
|
#include "objfiles.h"
|
37 |
|
|
#include "language.h"
|
38 |
|
|
#include "arch-utils.h"
|
39 |
|
|
#include "regcache.h"
|
40 |
|
|
|
41 |
|
|
#include "floatformat.h"
|
42 |
|
|
#include "gdb/sim-d10v.h"
|
43 |
|
|
#include "sim-regno.h"
|
44 |
|
|
|
45 |
|
|
struct frame_extra_info
|
46 |
|
|
{
|
47 |
|
|
CORE_ADDR return_pc;
|
48 |
|
|
int frameless;
|
49 |
|
|
int size;
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
struct gdbarch_tdep
|
53 |
|
|
{
|
54 |
|
|
int a0_regnum;
|
55 |
|
|
int nr_dmap_regs;
|
56 |
|
|
unsigned long (*dmap_register) (int nr);
|
57 |
|
|
unsigned long (*imap_register) (int nr);
|
58 |
|
|
};
|
59 |
|
|
|
60 |
|
|
/* These are the addresses the D10V-EVA board maps data and
|
61 |
|
|
instruction memory to. */
|
62 |
|
|
|
63 |
|
|
enum memspace {
|
64 |
|
|
DMEM_START = 0x2000000,
|
65 |
|
|
IMEM_START = 0x1000000,
|
66 |
|
|
STACK_START = 0x200bffe
|
67 |
|
|
};
|
68 |
|
|
|
69 |
|
|
/* d10v register names. */
|
70 |
|
|
|
71 |
|
|
enum
|
72 |
|
|
{
|
73 |
|
|
R0_REGNUM = 0,
|
74 |
|
|
R3_REGNUM = 3,
|
75 |
|
|
_FP_REGNUM = 11,
|
76 |
|
|
LR_REGNUM = 13,
|
77 |
|
|
_SP_REGNUM = 15,
|
78 |
|
|
PSW_REGNUM = 16,
|
79 |
|
|
_PC_REGNUM = 18,
|
80 |
|
|
NR_IMAP_REGS = 2,
|
81 |
|
|
NR_A_REGS = 2,
|
82 |
|
|
TS2_NUM_REGS = 37,
|
83 |
|
|
TS3_NUM_REGS = 42,
|
84 |
|
|
/* d10v calling convention. */
|
85 |
|
|
ARG1_REGNUM = R0_REGNUM,
|
86 |
|
|
ARGN_REGNUM = R3_REGNUM,
|
87 |
|
|
RET1_REGNUM = R0_REGNUM,
|
88 |
|
|
};
|
89 |
|
|
|
90 |
|
|
#define NR_DMAP_REGS (gdbarch_tdep (current_gdbarch)->nr_dmap_regs)
|
91 |
|
|
#define A0_REGNUM (gdbarch_tdep (current_gdbarch)->a0_regnum)
|
92 |
|
|
|
93 |
|
|
/* Local functions */
|
94 |
|
|
|
95 |
|
|
extern void _initialize_d10v_tdep (void);
|
96 |
|
|
|
97 |
|
|
static CORE_ADDR d10v_read_sp (void);
|
98 |
|
|
|
99 |
|
|
static CORE_ADDR d10v_read_fp (void);
|
100 |
|
|
|
101 |
|
|
static void d10v_eva_prepare_to_trace (void);
|
102 |
|
|
|
103 |
|
|
static void d10v_eva_get_trace_data (void);
|
104 |
|
|
|
105 |
|
|
static int prologue_find_regs (unsigned short op, struct frame_info *fi,
|
106 |
|
|
CORE_ADDR addr);
|
107 |
|
|
|
108 |
|
|
static void d10v_frame_init_saved_regs (struct frame_info *);
|
109 |
|
|
|
110 |
|
|
static void do_d10v_pop_frame (struct frame_info *fi);
|
111 |
|
|
|
112 |
|
|
static int
|
113 |
|
|
d10v_frame_chain_valid (CORE_ADDR chain, struct frame_info *frame)
|
114 |
|
|
{
|
115 |
|
|
if (chain != 0 && frame != NULL)
|
116 |
|
|
{
|
117 |
|
|
if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
|
118 |
|
|
return 1; /* Path back from a call dummy must be valid. */
|
119 |
|
|
return ((frame)->pc > IMEM_START
|
120 |
|
|
&& !inside_main_func (frame->pc));
|
121 |
|
|
}
|
122 |
|
|
else return 0;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
static CORE_ADDR
|
126 |
|
|
d10v_stack_align (CORE_ADDR len)
|
127 |
|
|
{
|
128 |
|
|
return (len + 1) & ~1;
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
/* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of
|
132 |
|
|
EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc
|
133 |
|
|
and TYPE is the type (which is known to be struct, union or array).
|
134 |
|
|
|
135 |
|
|
The d10v returns anything less than 8 bytes in size in
|
136 |
|
|
registers. */
|
137 |
|
|
|
138 |
|
|
static int
|
139 |
|
|
d10v_use_struct_convention (int gcc_p, struct type *type)
|
140 |
|
|
{
|
141 |
|
|
long alignment;
|
142 |
|
|
int i;
|
143 |
|
|
/* The d10v only passes a struct in a register when that structure
|
144 |
|
|
has an alignment that matches the size of a register. */
|
145 |
|
|
/* If the structure doesn't fit in 4 registers, put it on the
|
146 |
|
|
stack. */
|
147 |
|
|
if (TYPE_LENGTH (type) > 8)
|
148 |
|
|
return 1;
|
149 |
|
|
/* If the struct contains only one field, don't put it on the stack
|
150 |
|
|
- gcc can fit it in one or more registers. */
|
151 |
|
|
if (TYPE_NFIELDS (type) == 1)
|
152 |
|
|
return 0;
|
153 |
|
|
alignment = TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
|
154 |
|
|
for (i = 1; i < TYPE_NFIELDS (type); i++)
|
155 |
|
|
{
|
156 |
|
|
/* If the alignment changes, just assume it goes on the
|
157 |
|
|
stack. */
|
158 |
|
|
if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)) != alignment)
|
159 |
|
|
return 1;
|
160 |
|
|
}
|
161 |
|
|
/* If the alignment is suitable for the d10v's 16 bit registers,
|
162 |
|
|
don't put it on the stack. */
|
163 |
|
|
if (alignment == 2 || alignment == 4)
|
164 |
|
|
return 0;
|
165 |
|
|
return 1;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
static const unsigned char *
|
170 |
|
|
d10v_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
|
171 |
|
|
{
|
172 |
|
|
static unsigned char breakpoint[] =
|
173 |
|
|
{0x2f, 0x90, 0x5e, 0x00};
|
174 |
|
|
*lenptr = sizeof (breakpoint);
|
175 |
|
|
return breakpoint;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/* Map the REG_NR onto an ascii name. Return NULL or an empty string
|
179 |
|
|
when the reg_nr isn't valid. */
|
180 |
|
|
|
181 |
|
|
enum ts2_regnums
|
182 |
|
|
{
|
183 |
|
|
TS2_IMAP0_REGNUM = 32,
|
184 |
|
|
TS2_DMAP_REGNUM = 34,
|
185 |
|
|
TS2_NR_DMAP_REGS = 1,
|
186 |
|
|
TS2_A0_REGNUM = 35
|
187 |
|
|
};
|
188 |
|
|
|
189 |
|
|
static const char *
|
190 |
|
|
d10v_ts2_register_name (int reg_nr)
|
191 |
|
|
{
|
192 |
|
|
static char *register_names[] =
|
193 |
|
|
{
|
194 |
|
|
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
195 |
|
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
196 |
|
|
"psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c",
|
197 |
|
|
"rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15",
|
198 |
|
|
"imap0", "imap1", "dmap", "a0", "a1"
|
199 |
|
|
};
|
200 |
|
|
if (reg_nr < 0)
|
201 |
|
|
return NULL;
|
202 |
|
|
if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
|
203 |
|
|
return NULL;
|
204 |
|
|
return register_names[reg_nr];
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
enum ts3_regnums
|
208 |
|
|
{
|
209 |
|
|
TS3_IMAP0_REGNUM = 36,
|
210 |
|
|
TS3_DMAP0_REGNUM = 38,
|
211 |
|
|
TS3_NR_DMAP_REGS = 4,
|
212 |
|
|
TS3_A0_REGNUM = 32
|
213 |
|
|
};
|
214 |
|
|
|
215 |
|
|
static const char *
|
216 |
|
|
d10v_ts3_register_name (int reg_nr)
|
217 |
|
|
{
|
218 |
|
|
static char *register_names[] =
|
219 |
|
|
{
|
220 |
|
|
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
221 |
|
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
222 |
|
|
"psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c",
|
223 |
|
|
"rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15",
|
224 |
|
|
"a0", "a1",
|
225 |
|
|
"spi", "spu",
|
226 |
|
|
"imap0", "imap1",
|
227 |
|
|
"dmap0", "dmap1", "dmap2", "dmap3"
|
228 |
|
|
};
|
229 |
|
|
if (reg_nr < 0)
|
230 |
|
|
return NULL;
|
231 |
|
|
if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
|
232 |
|
|
return NULL;
|
233 |
|
|
return register_names[reg_nr];
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
/* Access the DMAP/IMAP registers in a target independent way.
|
237 |
|
|
|
238 |
|
|
Divide the D10V's 64k data space into four 16k segments:
|
239 |
|
|
0x0000 -- 0x3fff, 0x4000 -- 0x7fff, 0x8000 -- 0xbfff, and
|
240 |
|
|
0xc000 -- 0xffff.
|
241 |
|
|
|
242 |
|
|
On the TS2, the first two segments (0x0000 -- 0x3fff, 0x4000 --
|
243 |
|
|
0x7fff) always map to the on-chip data RAM, and the fourth always
|
244 |
|
|
maps to I/O space. The third (0x8000 - 0xbfff) can be mapped into
|
245 |
|
|
unified memory or instruction memory, under the control of the
|
246 |
|
|
single DMAP register.
|
247 |
|
|
|
248 |
|
|
On the TS3, there are four DMAP registers, each of which controls
|
249 |
|
|
one of the segments. */
|
250 |
|
|
|
251 |
|
|
static unsigned long
|
252 |
|
|
d10v_ts2_dmap_register (int reg_nr)
|
253 |
|
|
{
|
254 |
|
|
switch (reg_nr)
|
255 |
|
|
{
|
256 |
|
|
case 0:
|
257 |
|
|
case 1:
|
258 |
|
|
return 0x2000;
|
259 |
|
|
case 2:
|
260 |
|
|
return read_register (TS2_DMAP_REGNUM);
|
261 |
|
|
default:
|
262 |
|
|
return 0;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
static unsigned long
|
267 |
|
|
d10v_ts3_dmap_register (int reg_nr)
|
268 |
|
|
{
|
269 |
|
|
return read_register (TS3_DMAP0_REGNUM + reg_nr);
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
static unsigned long
|
273 |
|
|
d10v_dmap_register (int reg_nr)
|
274 |
|
|
{
|
275 |
|
|
return gdbarch_tdep (current_gdbarch)->dmap_register (reg_nr);
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
static unsigned long
|
279 |
|
|
d10v_ts2_imap_register (int reg_nr)
|
280 |
|
|
{
|
281 |
|
|
return read_register (TS2_IMAP0_REGNUM + reg_nr);
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
static unsigned long
|
285 |
|
|
d10v_ts3_imap_register (int reg_nr)
|
286 |
|
|
{
|
287 |
|
|
return read_register (TS3_IMAP0_REGNUM + reg_nr);
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
static unsigned long
|
291 |
|
|
d10v_imap_register (int reg_nr)
|
292 |
|
|
{
|
293 |
|
|
return gdbarch_tdep (current_gdbarch)->imap_register (reg_nr);
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
/* MAP GDB's internal register numbering (determined by the layout fo
|
297 |
|
|
the REGISTER_BYTE array) onto the simulator's register
|
298 |
|
|
numbering. */
|
299 |
|
|
|
300 |
|
|
static int
|
301 |
|
|
d10v_ts2_register_sim_regno (int nr)
|
302 |
|
|
{
|
303 |
|
|
if (legacy_register_sim_regno (nr) < 0)
|
304 |
|
|
return legacy_register_sim_regno (nr);
|
305 |
|
|
if (nr >= TS2_IMAP0_REGNUM
|
306 |
|
|
&& nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS)
|
307 |
|
|
return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
|
308 |
|
|
if (nr == TS2_DMAP_REGNUM)
|
309 |
|
|
return nr - TS2_DMAP_REGNUM + SIM_D10V_TS2_DMAP_REGNUM;
|
310 |
|
|
if (nr >= TS2_A0_REGNUM
|
311 |
|
|
&& nr < TS2_A0_REGNUM + NR_A_REGS)
|
312 |
|
|
return nr - TS2_A0_REGNUM + SIM_D10V_A0_REGNUM;
|
313 |
|
|
return nr;
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
static int
|
317 |
|
|
d10v_ts3_register_sim_regno (int nr)
|
318 |
|
|
{
|
319 |
|
|
if (legacy_register_sim_regno (nr) < 0)
|
320 |
|
|
return legacy_register_sim_regno (nr);
|
321 |
|
|
if (nr >= TS3_IMAP0_REGNUM
|
322 |
|
|
&& nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS)
|
323 |
|
|
return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
|
324 |
|
|
if (nr >= TS3_DMAP0_REGNUM
|
325 |
|
|
&& nr < TS3_DMAP0_REGNUM + TS3_NR_DMAP_REGS)
|
326 |
|
|
return nr - TS3_DMAP0_REGNUM + SIM_D10V_DMAP0_REGNUM;
|
327 |
|
|
if (nr >= TS3_A0_REGNUM
|
328 |
|
|
&& nr < TS3_A0_REGNUM + NR_A_REGS)
|
329 |
|
|
return nr - TS3_A0_REGNUM + SIM_D10V_A0_REGNUM;
|
330 |
|
|
return nr;
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
/* Index within `registers' of the first byte of the space for
|
334 |
|
|
register REG_NR. */
|
335 |
|
|
|
336 |
|
|
static int
|
337 |
|
|
d10v_register_byte (int reg_nr)
|
338 |
|
|
{
|
339 |
|
|
if (reg_nr < A0_REGNUM)
|
340 |
|
|
return (reg_nr * 2);
|
341 |
|
|
else if (reg_nr < (A0_REGNUM + NR_A_REGS))
|
342 |
|
|
return (A0_REGNUM * 2
|
343 |
|
|
+ (reg_nr - A0_REGNUM) * 8);
|
344 |
|
|
else
|
345 |
|
|
return (A0_REGNUM * 2
|
346 |
|
|
+ NR_A_REGS * 8
|
347 |
|
|
+ (reg_nr - A0_REGNUM - NR_A_REGS) * 2);
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
/* Number of bytes of storage in the actual machine representation for
|
351 |
|
|
register REG_NR. */
|
352 |
|
|
|
353 |
|
|
static int
|
354 |
|
|
d10v_register_raw_size (int reg_nr)
|
355 |
|
|
{
|
356 |
|
|
if (reg_nr < A0_REGNUM)
|
357 |
|
|
return 2;
|
358 |
|
|
else if (reg_nr < (A0_REGNUM + NR_A_REGS))
|
359 |
|
|
return 8;
|
360 |
|
|
else
|
361 |
|
|
return 2;
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
/* Return the GDB type object for the "standard" data type
|
365 |
|
|
of data in register N. */
|
366 |
|
|
|
367 |
|
|
static struct type *
|
368 |
|
|
d10v_register_virtual_type (int reg_nr)
|
369 |
|
|
{
|
370 |
|
|
if (reg_nr == PC_REGNUM)
|
371 |
|
|
return builtin_type_void_func_ptr;
|
372 |
|
|
if (reg_nr == _SP_REGNUM || reg_nr == _FP_REGNUM)
|
373 |
|
|
return builtin_type_void_data_ptr;
|
374 |
|
|
else if (reg_nr >= A0_REGNUM
|
375 |
|
|
&& reg_nr < (A0_REGNUM + NR_A_REGS))
|
376 |
|
|
return builtin_type_int64;
|
377 |
|
|
else
|
378 |
|
|
return builtin_type_int16;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
static int
|
382 |
|
|
d10v_daddr_p (CORE_ADDR x)
|
383 |
|
|
{
|
384 |
|
|
return (((x) & 0x3000000) == DMEM_START);
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
static int
|
388 |
|
|
d10v_iaddr_p (CORE_ADDR x)
|
389 |
|
|
{
|
390 |
|
|
return (((x) & 0x3000000) == IMEM_START);
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
static CORE_ADDR
|
394 |
|
|
d10v_make_daddr (CORE_ADDR x)
|
395 |
|
|
{
|
396 |
|
|
return ((x) | DMEM_START);
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
static CORE_ADDR
|
400 |
|
|
d10v_make_iaddr (CORE_ADDR x)
|
401 |
|
|
{
|
402 |
|
|
if (d10v_iaddr_p (x))
|
403 |
|
|
return x; /* Idempotency -- x is already in the IMEM space. */
|
404 |
|
|
else
|
405 |
|
|
return (((x) << 2) | IMEM_START);
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
static CORE_ADDR
|
409 |
|
|
d10v_convert_iaddr_to_raw (CORE_ADDR x)
|
410 |
|
|
{
|
411 |
|
|
return (((x) >> 2) & 0xffff);
|
412 |
|
|
}
|
413 |
|
|
|
414 |
|
|
static CORE_ADDR
|
415 |
|
|
d10v_convert_daddr_to_raw (CORE_ADDR x)
|
416 |
|
|
{
|
417 |
|
|
return ((x) & 0xffff);
|
418 |
|
|
}
|
419 |
|
|
|
420 |
|
|
static void
|
421 |
|
|
d10v_address_to_pointer (struct type *type, void *buf, CORE_ADDR addr)
|
422 |
|
|
{
|
423 |
|
|
/* Is it a code address? */
|
424 |
|
|
if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|
425 |
|
|
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
|
426 |
|
|
{
|
427 |
|
|
store_unsigned_integer (buf, TYPE_LENGTH (type),
|
428 |
|
|
d10v_convert_iaddr_to_raw (addr));
|
429 |
|
|
}
|
430 |
|
|
else
|
431 |
|
|
{
|
432 |
|
|
/* Strip off any upper segment bits. */
|
433 |
|
|
store_unsigned_integer (buf, TYPE_LENGTH (type),
|
434 |
|
|
d10v_convert_daddr_to_raw (addr));
|
435 |
|
|
}
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
static CORE_ADDR
|
439 |
|
|
d10v_pointer_to_address (struct type *type, void *buf)
|
440 |
|
|
{
|
441 |
|
|
CORE_ADDR addr = extract_address (buf, TYPE_LENGTH (type));
|
442 |
|
|
|
443 |
|
|
/* Is it a code address? */
|
444 |
|
|
if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|
445 |
|
|
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
|
446 |
|
|
|| TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
|
447 |
|
|
return d10v_make_iaddr (addr);
|
448 |
|
|
else
|
449 |
|
|
return d10v_make_daddr (addr);
|
450 |
|
|
}
|
451 |
|
|
|
452 |
|
|
/* Don't do anything if we have an integer, this way users can type 'x
|
453 |
|
|
<addr>' w/o having gdb outsmart them. The internal gdb conversions
|
454 |
|
|
to the correct space are taken care of in the pointer_to_address
|
455 |
|
|
function. If we don't do this, 'x $fp' wouldn't work. */
|
456 |
|
|
static CORE_ADDR
|
457 |
|
|
d10v_integer_to_address (struct type *type, void *buf)
|
458 |
|
|
{
|
459 |
|
|
LONGEST val;
|
460 |
|
|
val = unpack_long (type, buf);
|
461 |
|
|
return val;
|
462 |
|
|
}
|
463 |
|
|
|
464 |
|
|
/* Store the address of the place in which to copy the structure the
|
465 |
|
|
subroutine will return. This is called from call_function.
|
466 |
|
|
|
467 |
|
|
We store structs through a pointer passed in the first Argument
|
468 |
|
|
register. */
|
469 |
|
|
|
470 |
|
|
static void
|
471 |
|
|
d10v_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
|
472 |
|
|
{
|
473 |
|
|
write_register (ARG1_REGNUM, (addr));
|
474 |
|
|
}
|
475 |
|
|
|
476 |
|
|
/* Write into appropriate registers a function return value
|
477 |
|
|
of type TYPE, given in virtual format.
|
478 |
|
|
|
479 |
|
|
Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */
|
480 |
|
|
|
481 |
|
|
static void
|
482 |
|
|
d10v_store_return_value (struct type *type, char *valbuf)
|
483 |
|
|
{
|
484 |
|
|
char tmp = 0;
|
485 |
|
|
/* Only char return values need to be shifted right within R0. */
|
486 |
|
|
if (TYPE_LENGTH (type) == 1
|
487 |
|
|
&& TYPE_CODE (type) == TYPE_CODE_INT)
|
488 |
|
|
{
|
489 |
|
|
write_register_bytes (REGISTER_BYTE (RET1_REGNUM),
|
490 |
|
|
&tmp, 1); /* zero the high byte */
|
491 |
|
|
write_register_bytes (REGISTER_BYTE (RET1_REGNUM) + 1,
|
492 |
|
|
valbuf, 1); /* copy the low byte */
|
493 |
|
|
}
|
494 |
|
|
else
|
495 |
|
|
write_register_bytes (REGISTER_BYTE (RET1_REGNUM),
|
496 |
|
|
valbuf,
|
497 |
|
|
TYPE_LENGTH (type));
|
498 |
|
|
}
|
499 |
|
|
|
500 |
|
|
/* Extract from an array REGBUF containing the (raw) register state
|
501 |
|
|
the address in which a function should return its structure value,
|
502 |
|
|
as a CORE_ADDR (or an expression that can be used as one). */
|
503 |
|
|
|
504 |
|
|
static CORE_ADDR
|
505 |
|
|
d10v_extract_struct_value_address (char *regbuf)
|
506 |
|
|
{
|
507 |
|
|
return (extract_address ((regbuf) + REGISTER_BYTE (ARG1_REGNUM),
|
508 |
|
|
REGISTER_RAW_SIZE (ARG1_REGNUM))
|
509 |
|
|
| DMEM_START);
|
510 |
|
|
}
|
511 |
|
|
|
512 |
|
|
static CORE_ADDR
|
513 |
|
|
d10v_frame_saved_pc (struct frame_info *frame)
|
514 |
|
|
{
|
515 |
|
|
if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
|
516 |
|
|
return d10v_make_iaddr (generic_read_register_dummy (frame->pc,
|
517 |
|
|
frame->frame,
|
518 |
|
|
PC_REGNUM));
|
519 |
|
|
else
|
520 |
|
|
return ((frame)->extra_info->return_pc);
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
/* Immediately after a function call, return the saved pc. We can't
|
524 |
|
|
use frame->return_pc beause that is determined by reading R13 off
|
525 |
|
|
the stack and that may not be written yet. */
|
526 |
|
|
|
527 |
|
|
static CORE_ADDR
|
528 |
|
|
d10v_saved_pc_after_call (struct frame_info *frame)
|
529 |
|
|
{
|
530 |
|
|
return ((read_register (LR_REGNUM) << 2)
|
531 |
|
|
| IMEM_START);
|
532 |
|
|
}
|
533 |
|
|
|
534 |
|
|
/* Discard from the stack the innermost frame, restoring all saved
|
535 |
|
|
registers. */
|
536 |
|
|
|
537 |
|
|
static void
|
538 |
|
|
d10v_pop_frame (void)
|
539 |
|
|
{
|
540 |
|
|
generic_pop_current_frame (do_d10v_pop_frame);
|
541 |
|
|
}
|
542 |
|
|
|
543 |
|
|
static void
|
544 |
|
|
do_d10v_pop_frame (struct frame_info *fi)
|
545 |
|
|
{
|
546 |
|
|
CORE_ADDR fp;
|
547 |
|
|
int regnum;
|
548 |
|
|
char raw_buffer[8];
|
549 |
|
|
|
550 |
|
|
fp = FRAME_FP (fi);
|
551 |
|
|
/* fill out fsr with the address of where each */
|
552 |
|
|
/* register was stored in the frame */
|
553 |
|
|
d10v_frame_init_saved_regs (fi);
|
554 |
|
|
|
555 |
|
|
/* now update the current registers with the old values */
|
556 |
|
|
for (regnum = A0_REGNUM; regnum < A0_REGNUM + NR_A_REGS; regnum++)
|
557 |
|
|
{
|
558 |
|
|
if (fi->saved_regs[regnum])
|
559 |
|
|
{
|
560 |
|
|
read_memory (fi->saved_regs[regnum], raw_buffer, REGISTER_RAW_SIZE (regnum));
|
561 |
|
|
write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, REGISTER_RAW_SIZE (regnum));
|
562 |
|
|
}
|
563 |
|
|
}
|
564 |
|
|
for (regnum = 0; regnum < SP_REGNUM; regnum++)
|
565 |
|
|
{
|
566 |
|
|
if (fi->saved_regs[regnum])
|
567 |
|
|
{
|
568 |
|
|
write_register (regnum, read_memory_unsigned_integer (fi->saved_regs[regnum], REGISTER_RAW_SIZE (regnum)));
|
569 |
|
|
}
|
570 |
|
|
}
|
571 |
|
|
if (fi->saved_regs[PSW_REGNUM])
|
572 |
|
|
{
|
573 |
|
|
write_register (PSW_REGNUM, read_memory_unsigned_integer (fi->saved_regs[PSW_REGNUM], REGISTER_RAW_SIZE (PSW_REGNUM)));
|
574 |
|
|
}
|
575 |
|
|
|
576 |
|
|
write_register (PC_REGNUM, read_register (LR_REGNUM));
|
577 |
|
|
write_register (SP_REGNUM, fp + fi->extra_info->size);
|
578 |
|
|
target_store_registers (-1);
|
579 |
|
|
flush_cached_frames ();
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
static int
|
583 |
|
|
check_prologue (unsigned short op)
|
584 |
|
|
{
|
585 |
|
|
/* st rn, @-sp */
|
586 |
|
|
if ((op & 0x7E1F) == 0x6C1F)
|
587 |
|
|
return 1;
|
588 |
|
|
|
589 |
|
|
/* st2w rn, @-sp */
|
590 |
|
|
if ((op & 0x7E3F) == 0x6E1F)
|
591 |
|
|
return 1;
|
592 |
|
|
|
593 |
|
|
/* subi sp, n */
|
594 |
|
|
if ((op & 0x7FE1) == 0x01E1)
|
595 |
|
|
return 1;
|
596 |
|
|
|
597 |
|
|
/* mv r11, sp */
|
598 |
|
|
if (op == 0x417E)
|
599 |
|
|
return 1;
|
600 |
|
|
|
601 |
|
|
/* nop */
|
602 |
|
|
if (op == 0x5E00)
|
603 |
|
|
return 1;
|
604 |
|
|
|
605 |
|
|
/* st rn, @sp */
|
606 |
|
|
if ((op & 0x7E1F) == 0x681E)
|
607 |
|
|
return 1;
|
608 |
|
|
|
609 |
|
|
/* st2w rn, @sp */
|
610 |
|
|
if ((op & 0x7E3F) == 0x3A1E)
|
611 |
|
|
return 1;
|
612 |
|
|
|
613 |
|
|
return 0;
|
614 |
|
|
}
|
615 |
|
|
|
616 |
|
|
static CORE_ADDR
|
617 |
|
|
d10v_skip_prologue (CORE_ADDR pc)
|
618 |
|
|
{
|
619 |
|
|
unsigned long op;
|
620 |
|
|
unsigned short op1, op2;
|
621 |
|
|
CORE_ADDR func_addr, func_end;
|
622 |
|
|
struct symtab_and_line sal;
|
623 |
|
|
|
624 |
|
|
/* If we have line debugging information, then the end of the */
|
625 |
|
|
/* prologue should the first assembly instruction of the first source line */
|
626 |
|
|
if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
|
627 |
|
|
{
|
628 |
|
|
sal = find_pc_line (func_addr, 0);
|
629 |
|
|
if (sal.end && sal.end < func_end)
|
630 |
|
|
return sal.end;
|
631 |
|
|
}
|
632 |
|
|
|
633 |
|
|
if (target_read_memory (pc, (char *) &op, 4))
|
634 |
|
|
return pc; /* Can't access it -- assume no prologue. */
|
635 |
|
|
|
636 |
|
|
while (1)
|
637 |
|
|
{
|
638 |
|
|
op = (unsigned long) read_memory_integer (pc, 4);
|
639 |
|
|
if ((op & 0xC0000000) == 0xC0000000)
|
640 |
|
|
{
|
641 |
|
|
/* long instruction */
|
642 |
|
|
if (((op & 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */
|
643 |
|
|
((op & 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */
|
644 |
|
|
((op & 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */
|
645 |
|
|
break;
|
646 |
|
|
}
|
647 |
|
|
else
|
648 |
|
|
{
|
649 |
|
|
/* short instructions */
|
650 |
|
|
if ((op & 0xC0000000) == 0x80000000)
|
651 |
|
|
{
|
652 |
|
|
op2 = (op & 0x3FFF8000) >> 15;
|
653 |
|
|
op1 = op & 0x7FFF;
|
654 |
|
|
}
|
655 |
|
|
else
|
656 |
|
|
{
|
657 |
|
|
op1 = (op & 0x3FFF8000) >> 15;
|
658 |
|
|
op2 = op & 0x7FFF;
|
659 |
|
|
}
|
660 |
|
|
if (check_prologue (op1))
|
661 |
|
|
{
|
662 |
|
|
if (!check_prologue (op2))
|
663 |
|
|
{
|
664 |
|
|
/* if the previous opcode was really part of the prologue */
|
665 |
|
|
/* and not just a NOP, then we want to break after both instructions */
|
666 |
|
|
if (op1 != 0x5E00)
|
667 |
|
|
pc += 4;
|
668 |
|
|
break;
|
669 |
|
|
}
|
670 |
|
|
}
|
671 |
|
|
else
|
672 |
|
|
break;
|
673 |
|
|
}
|
674 |
|
|
pc += 4;
|
675 |
|
|
}
|
676 |
|
|
return pc;
|
677 |
|
|
}
|
678 |
|
|
|
679 |
|
|
/* Given a GDB frame, determine the address of the calling function's frame.
|
680 |
|
|
This will be used to create a new GDB frame struct, and then
|
681 |
|
|
INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
|
682 |
|
|
*/
|
683 |
|
|
|
684 |
|
|
static CORE_ADDR
|
685 |
|
|
d10v_frame_chain (struct frame_info *fi)
|
686 |
|
|
{
|
687 |
|
|
CORE_ADDR addr;
|
688 |
|
|
|
689 |
|
|
/* A generic call dummy's frame is the same as caller's. */
|
690 |
|
|
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
|
691 |
|
|
return fi->frame;
|
692 |
|
|
|
693 |
|
|
d10v_frame_init_saved_regs (fi);
|
694 |
|
|
|
695 |
|
|
|
696 |
|
|
if (fi->extra_info->return_pc == IMEM_START
|
697 |
|
|
|| inside_entry_file (fi->extra_info->return_pc))
|
698 |
|
|
{
|
699 |
|
|
/* This is meant to halt the backtrace at "_start".
|
700 |
|
|
Make sure we don't halt it at a generic dummy frame. */
|
701 |
|
|
if (!PC_IN_CALL_DUMMY (fi->extra_info->return_pc, 0, 0))
|
702 |
|
|
return (CORE_ADDR) 0;
|
703 |
|
|
}
|
704 |
|
|
|
705 |
|
|
if (!fi->saved_regs[FP_REGNUM])
|
706 |
|
|
{
|
707 |
|
|
if (!fi->saved_regs[SP_REGNUM]
|
708 |
|
|
|| fi->saved_regs[SP_REGNUM] == STACK_START)
|
709 |
|
|
return (CORE_ADDR) 0;
|
710 |
|
|
|
711 |
|
|
return fi->saved_regs[SP_REGNUM];
|
712 |
|
|
}
|
713 |
|
|
|
714 |
|
|
addr = read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
|
715 |
|
|
REGISTER_RAW_SIZE (FP_REGNUM));
|
716 |
|
|
if (addr == 0)
|
717 |
|
|
return (CORE_ADDR) 0;
|
718 |
|
|
|
719 |
|
|
return d10v_make_daddr (addr);
|
720 |
|
|
}
|
721 |
|
|
|
722 |
|
|
static int next_addr, uses_frame;
|
723 |
|
|
|
724 |
|
|
static int
|
725 |
|
|
prologue_find_regs (unsigned short op, struct frame_info *fi, CORE_ADDR addr)
|
726 |
|
|
{
|
727 |
|
|
int n;
|
728 |
|
|
|
729 |
|
|
/* st rn, @-sp */
|
730 |
|
|
if ((op & 0x7E1F) == 0x6C1F)
|
731 |
|
|
{
|
732 |
|
|
n = (op & 0x1E0) >> 5;
|
733 |
|
|
next_addr -= 2;
|
734 |
|
|
fi->saved_regs[n] = next_addr;
|
735 |
|
|
return 1;
|
736 |
|
|
}
|
737 |
|
|
|
738 |
|
|
/* st2w rn, @-sp */
|
739 |
|
|
else if ((op & 0x7E3F) == 0x6E1F)
|
740 |
|
|
{
|
741 |
|
|
n = (op & 0x1E0) >> 5;
|
742 |
|
|
next_addr -= 4;
|
743 |
|
|
fi->saved_regs[n] = next_addr;
|
744 |
|
|
fi->saved_regs[n + 1] = next_addr + 2;
|
745 |
|
|
return 1;
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
/* subi sp, n */
|
749 |
|
|
if ((op & 0x7FE1) == 0x01E1)
|
750 |
|
|
{
|
751 |
|
|
n = (op & 0x1E) >> 1;
|
752 |
|
|
if (n == 0)
|
753 |
|
|
n = 16;
|
754 |
|
|
next_addr -= n;
|
755 |
|
|
return 1;
|
756 |
|
|
}
|
757 |
|
|
|
758 |
|
|
/* mv r11, sp */
|
759 |
|
|
if (op == 0x417E)
|
760 |
|
|
{
|
761 |
|
|
uses_frame = 1;
|
762 |
|
|
return 1;
|
763 |
|
|
}
|
764 |
|
|
|
765 |
|
|
/* nop */
|
766 |
|
|
if (op == 0x5E00)
|
767 |
|
|
return 1;
|
768 |
|
|
|
769 |
|
|
/* st rn, @sp */
|
770 |
|
|
if ((op & 0x7E1F) == 0x681E)
|
771 |
|
|
{
|
772 |
|
|
n = (op & 0x1E0) >> 5;
|
773 |
|
|
fi->saved_regs[n] = next_addr;
|
774 |
|
|
return 1;
|
775 |
|
|
}
|
776 |
|
|
|
777 |
|
|
/* st2w rn, @sp */
|
778 |
|
|
if ((op & 0x7E3F) == 0x3A1E)
|
779 |
|
|
{
|
780 |
|
|
n = (op & 0x1E0) >> 5;
|
781 |
|
|
fi->saved_regs[n] = next_addr;
|
782 |
|
|
fi->saved_regs[n + 1] = next_addr + 2;
|
783 |
|
|
return 1;
|
784 |
|
|
}
|
785 |
|
|
|
786 |
|
|
return 0;
|
787 |
|
|
}
|
788 |
|
|
|
789 |
|
|
/* Put here the code to store, into fi->saved_regs, the addresses of
|
790 |
|
|
the saved registers of frame described by FRAME_INFO. This
|
791 |
|
|
includes special registers such as pc and fp saved in special ways
|
792 |
|
|
in the stack frame. sp is even more special: the address we return
|
793 |
|
|
for it IS the sp for the next frame. */
|
794 |
|
|
|
795 |
|
|
static void
|
796 |
|
|
d10v_frame_init_saved_regs (struct frame_info *fi)
|
797 |
|
|
{
|
798 |
|
|
CORE_ADDR fp, pc;
|
799 |
|
|
unsigned long op;
|
800 |
|
|
unsigned short op1, op2;
|
801 |
|
|
int i;
|
802 |
|
|
|
803 |
|
|
fp = fi->frame;
|
804 |
|
|
memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
|
805 |
|
|
next_addr = 0;
|
806 |
|
|
|
807 |
|
|
pc = get_pc_function_start (fi->pc);
|
808 |
|
|
|
809 |
|
|
uses_frame = 0;
|
810 |
|
|
while (1)
|
811 |
|
|
{
|
812 |
|
|
op = (unsigned long) read_memory_integer (pc, 4);
|
813 |
|
|
if ((op & 0xC0000000) == 0xC0000000)
|
814 |
|
|
{
|
815 |
|
|
/* long instruction */
|
816 |
|
|
if ((op & 0x3FFF0000) == 0x01FF0000)
|
817 |
|
|
{
|
818 |
|
|
/* add3 sp,sp,n */
|
819 |
|
|
short n = op & 0xFFFF;
|
820 |
|
|
next_addr += n;
|
821 |
|
|
}
|
822 |
|
|
else if ((op & 0x3F0F0000) == 0x340F0000)
|
823 |
|
|
{
|
824 |
|
|
/* st rn, @(offset,sp) */
|
825 |
|
|
short offset = op & 0xFFFF;
|
826 |
|
|
short n = (op >> 20) & 0xF;
|
827 |
|
|
fi->saved_regs[n] = next_addr + offset;
|
828 |
|
|
}
|
829 |
|
|
else if ((op & 0x3F1F0000) == 0x350F0000)
|
830 |
|
|
{
|
831 |
|
|
/* st2w rn, @(offset,sp) */
|
832 |
|
|
short offset = op & 0xFFFF;
|
833 |
|
|
short n = (op >> 20) & 0xF;
|
834 |
|
|
fi->saved_regs[n] = next_addr + offset;
|
835 |
|
|
fi->saved_regs[n + 1] = next_addr + offset + 2;
|
836 |
|
|
}
|
837 |
|
|
else
|
838 |
|
|
break;
|
839 |
|
|
}
|
840 |
|
|
else
|
841 |
|
|
{
|
842 |
|
|
/* short instructions */
|
843 |
|
|
if ((op & 0xC0000000) == 0x80000000)
|
844 |
|
|
{
|
845 |
|
|
op2 = (op & 0x3FFF8000) >> 15;
|
846 |
|
|
op1 = op & 0x7FFF;
|
847 |
|
|
}
|
848 |
|
|
else
|
849 |
|
|
{
|
850 |
|
|
op1 = (op & 0x3FFF8000) >> 15;
|
851 |
|
|
op2 = op & 0x7FFF;
|
852 |
|
|
}
|
853 |
|
|
if (!prologue_find_regs (op1, fi, pc)
|
854 |
|
|
|| !prologue_find_regs (op2, fi, pc))
|
855 |
|
|
break;
|
856 |
|
|
}
|
857 |
|
|
pc += 4;
|
858 |
|
|
}
|
859 |
|
|
|
860 |
|
|
fi->extra_info->size = -next_addr;
|
861 |
|
|
|
862 |
|
|
if (!(fp & 0xffff))
|
863 |
|
|
fp = d10v_read_sp ();
|
864 |
|
|
|
865 |
|
|
for (i = 0; i < NUM_REGS - 1; i++)
|
866 |
|
|
if (fi->saved_regs[i])
|
867 |
|
|
{
|
868 |
|
|
fi->saved_regs[i] = fp - (next_addr - fi->saved_regs[i]);
|
869 |
|
|
}
|
870 |
|
|
|
871 |
|
|
if (fi->saved_regs[LR_REGNUM])
|
872 |
|
|
{
|
873 |
|
|
CORE_ADDR return_pc
|
874 |
|
|
= read_memory_unsigned_integer (fi->saved_regs[LR_REGNUM],
|
875 |
|
|
REGISTER_RAW_SIZE (LR_REGNUM));
|
876 |
|
|
fi->extra_info->return_pc = d10v_make_iaddr (return_pc);
|
877 |
|
|
}
|
878 |
|
|
else
|
879 |
|
|
{
|
880 |
|
|
fi->extra_info->return_pc = d10v_make_iaddr (read_register (LR_REGNUM));
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
/* The SP is not normally (ever?) saved, but check anyway */
|
884 |
|
|
if (!fi->saved_regs[SP_REGNUM])
|
885 |
|
|
{
|
886 |
|
|
/* if the FP was saved, that means the current FP is valid, */
|
887 |
|
|
/* otherwise, it isn't being used, so we use the SP instead */
|
888 |
|
|
if (uses_frame)
|
889 |
|
|
fi->saved_regs[SP_REGNUM]
|
890 |
|
|
= d10v_read_fp () + fi->extra_info->size;
|
891 |
|
|
else
|
892 |
|
|
{
|
893 |
|
|
fi->saved_regs[SP_REGNUM] = fp + fi->extra_info->size;
|
894 |
|
|
fi->extra_info->frameless = 1;
|
895 |
|
|
fi->saved_regs[FP_REGNUM] = 0;
|
896 |
|
|
}
|
897 |
|
|
}
|
898 |
|
|
}
|
899 |
|
|
|
900 |
|
|
static void
|
901 |
|
|
d10v_init_extra_frame_info (int fromleaf, struct frame_info *fi)
|
902 |
|
|
{
|
903 |
|
|
fi->extra_info = (struct frame_extra_info *)
|
904 |
|
|
frame_obstack_alloc (sizeof (struct frame_extra_info));
|
905 |
|
|
frame_saved_regs_zalloc (fi);
|
906 |
|
|
|
907 |
|
|
fi->extra_info->frameless = 0;
|
908 |
|
|
fi->extra_info->size = 0;
|
909 |
|
|
fi->extra_info->return_pc = 0;
|
910 |
|
|
|
911 |
|
|
/* If fi->pc is zero, but this is not the outermost frame,
|
912 |
|
|
then let's snatch the return_pc from the callee, so that
|
913 |
|
|
PC_IN_CALL_DUMMY will work. */
|
914 |
|
|
if (fi->pc == 0 && fi->level != 0 && fi->next != NULL)
|
915 |
|
|
fi->pc = d10v_frame_saved_pc (fi->next);
|
916 |
|
|
|
917 |
|
|
/* The call dummy doesn't save any registers on the stack, so we can
|
918 |
|
|
return now. */
|
919 |
|
|
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
|
920 |
|
|
{
|
921 |
|
|
return;
|
922 |
|
|
}
|
923 |
|
|
else
|
924 |
|
|
{
|
925 |
|
|
d10v_frame_init_saved_regs (fi);
|
926 |
|
|
}
|
927 |
|
|
}
|
928 |
|
|
|
929 |
|
|
static void
|
930 |
|
|
show_regs (char *args, int from_tty)
|
931 |
|
|
{
|
932 |
|
|
int a;
|
933 |
|
|
printf_filtered ("PC=%04lx (0x%lx) PSW=%04lx RPT_S=%04lx RPT_E=%04lx RPT_C=%04lx\n",
|
934 |
|
|
(long) read_register (PC_REGNUM),
|
935 |
|
|
(long) d10v_make_iaddr (read_register (PC_REGNUM)),
|
936 |
|
|
(long) read_register (PSW_REGNUM),
|
937 |
|
|
(long) read_register (24),
|
938 |
|
|
(long) read_register (25),
|
939 |
|
|
(long) read_register (23));
|
940 |
|
|
printf_filtered ("R0-R7 %04lx %04lx %04lx %04lx %04lx %04lx %04lx %04lx\n",
|
941 |
|
|
(long) read_register (0),
|
942 |
|
|
(long) read_register (1),
|
943 |
|
|
(long) read_register (2),
|
944 |
|
|
(long) read_register (3),
|
945 |
|
|
(long) read_register (4),
|
946 |
|
|
(long) read_register (5),
|
947 |
|
|
(long) read_register (6),
|
948 |
|
|
(long) read_register (7));
|
949 |
|
|
printf_filtered ("R8-R15 %04lx %04lx %04lx %04lx %04lx %04lx %04lx %04lx\n",
|
950 |
|
|
(long) read_register (8),
|
951 |
|
|
(long) read_register (9),
|
952 |
|
|
(long) read_register (10),
|
953 |
|
|
(long) read_register (11),
|
954 |
|
|
(long) read_register (12),
|
955 |
|
|
(long) read_register (13),
|
956 |
|
|
(long) read_register (14),
|
957 |
|
|
(long) read_register (15));
|
958 |
|
|
for (a = 0; a < NR_IMAP_REGS; a++)
|
959 |
|
|
{
|
960 |
|
|
if (a > 0)
|
961 |
|
|
printf_filtered (" ");
|
962 |
|
|
printf_filtered ("IMAP%d %04lx", a, d10v_imap_register (a));
|
963 |
|
|
}
|
964 |
|
|
if (NR_DMAP_REGS == 1)
|
965 |
|
|
printf_filtered (" DMAP %04lx\n", d10v_dmap_register (2));
|
966 |
|
|
else
|
967 |
|
|
{
|
968 |
|
|
for (a = 0; a < NR_DMAP_REGS; a++)
|
969 |
|
|
{
|
970 |
|
|
printf_filtered (" DMAP%d %04lx", a, d10v_dmap_register (a));
|
971 |
|
|
}
|
972 |
|
|
printf_filtered ("\n");
|
973 |
|
|
}
|
974 |
|
|
printf_filtered ("A0-A%d", NR_A_REGS - 1);
|
975 |
|
|
for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++)
|
976 |
|
|
{
|
977 |
|
|
char num[MAX_REGISTER_RAW_SIZE];
|
978 |
|
|
int i;
|
979 |
|
|
printf_filtered (" ");
|
980 |
|
|
read_register_gen (a, (char *) &num);
|
981 |
|
|
for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
|
982 |
|
|
{
|
983 |
|
|
printf_filtered ("%02x", (num[i] & 0xff));
|
984 |
|
|
}
|
985 |
|
|
}
|
986 |
|
|
printf_filtered ("\n");
|
987 |
|
|
}
|
988 |
|
|
|
989 |
|
|
static CORE_ADDR
|
990 |
|
|
d10v_read_pc (ptid_t ptid)
|
991 |
|
|
{
|
992 |
|
|
ptid_t save_ptid;
|
993 |
|
|
CORE_ADDR pc;
|
994 |
|
|
CORE_ADDR retval;
|
995 |
|
|
|
996 |
|
|
save_ptid = inferior_ptid;
|
997 |
|
|
inferior_ptid = ptid;
|
998 |
|
|
pc = (int) read_register (PC_REGNUM);
|
999 |
|
|
inferior_ptid = save_ptid;
|
1000 |
|
|
retval = d10v_make_iaddr (pc);
|
1001 |
|
|
return retval;
|
1002 |
|
|
}
|
1003 |
|
|
|
1004 |
|
|
static void
|
1005 |
|
|
d10v_write_pc (CORE_ADDR val, ptid_t ptid)
|
1006 |
|
|
{
|
1007 |
|
|
ptid_t save_ptid;
|
1008 |
|
|
|
1009 |
|
|
save_ptid = inferior_ptid;
|
1010 |
|
|
inferior_ptid = ptid;
|
1011 |
|
|
write_register (PC_REGNUM, d10v_convert_iaddr_to_raw (val));
|
1012 |
|
|
inferior_ptid = save_ptid;
|
1013 |
|
|
}
|
1014 |
|
|
|
1015 |
|
|
static CORE_ADDR
|
1016 |
|
|
d10v_read_sp (void)
|
1017 |
|
|
{
|
1018 |
|
|
return (d10v_make_daddr (read_register (SP_REGNUM)));
|
1019 |
|
|
}
|
1020 |
|
|
|
1021 |
|
|
static void
|
1022 |
|
|
d10v_write_sp (CORE_ADDR val)
|
1023 |
|
|
{
|
1024 |
|
|
write_register (SP_REGNUM, d10v_convert_daddr_to_raw (val));
|
1025 |
|
|
}
|
1026 |
|
|
|
1027 |
|
|
static CORE_ADDR
|
1028 |
|
|
d10v_read_fp (void)
|
1029 |
|
|
{
|
1030 |
|
|
return (d10v_make_daddr (read_register (FP_REGNUM)));
|
1031 |
|
|
}
|
1032 |
|
|
|
1033 |
|
|
/* Function: push_return_address (pc)
|
1034 |
|
|
Set up the return address for the inferior function call.
|
1035 |
|
|
Needed for targets where we don't actually execute a JSR/BSR instruction */
|
1036 |
|
|
|
1037 |
|
|
static CORE_ADDR
|
1038 |
|
|
d10v_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
|
1039 |
|
|
{
|
1040 |
|
|
write_register (LR_REGNUM, d10v_convert_iaddr_to_raw (CALL_DUMMY_ADDRESS ()));
|
1041 |
|
|
return sp;
|
1042 |
|
|
}
|
1043 |
|
|
|
1044 |
|
|
|
1045 |
|
|
/* When arguments must be pushed onto the stack, they go on in reverse
|
1046 |
|
|
order. The below implements a FILO (stack) to do this. */
|
1047 |
|
|
|
1048 |
|
|
struct stack_item
|
1049 |
|
|
{
|
1050 |
|
|
int len;
|
1051 |
|
|
struct stack_item *prev;
|
1052 |
|
|
void *data;
|
1053 |
|
|
};
|
1054 |
|
|
|
1055 |
|
|
static struct stack_item *push_stack_item (struct stack_item *prev,
|
1056 |
|
|
void *contents, int len);
|
1057 |
|
|
static struct stack_item *
|
1058 |
|
|
push_stack_item (struct stack_item *prev, void *contents, int len)
|
1059 |
|
|
{
|
1060 |
|
|
struct stack_item *si;
|
1061 |
|
|
si = xmalloc (sizeof (struct stack_item));
|
1062 |
|
|
si->data = xmalloc (len);
|
1063 |
|
|
si->len = len;
|
1064 |
|
|
si->prev = prev;
|
1065 |
|
|
memcpy (si->data, contents, len);
|
1066 |
|
|
return si;
|
1067 |
|
|
}
|
1068 |
|
|
|
1069 |
|
|
static struct stack_item *pop_stack_item (struct stack_item *si);
|
1070 |
|
|
static struct stack_item *
|
1071 |
|
|
pop_stack_item (struct stack_item *si)
|
1072 |
|
|
{
|
1073 |
|
|
struct stack_item *dead = si;
|
1074 |
|
|
si = si->prev;
|
1075 |
|
|
xfree (dead->data);
|
1076 |
|
|
xfree (dead);
|
1077 |
|
|
return si;
|
1078 |
|
|
}
|
1079 |
|
|
|
1080 |
|
|
|
1081 |
|
|
static CORE_ADDR
|
1082 |
|
|
d10v_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
|
1083 |
|
|
int struct_return, CORE_ADDR struct_addr)
|
1084 |
|
|
{
|
1085 |
|
|
int i;
|
1086 |
|
|
int regnum = ARG1_REGNUM;
|
1087 |
|
|
struct stack_item *si = NULL;
|
1088 |
|
|
long val;
|
1089 |
|
|
|
1090 |
|
|
/* If struct_return is true, then the struct return address will
|
1091 |
|
|
consume one argument-passing register. No need to actually
|
1092 |
|
|
write the value to the register -- that's done by
|
1093 |
|
|
d10v_store_struct_return(). */
|
1094 |
|
|
|
1095 |
|
|
if (struct_return)
|
1096 |
|
|
regnum++;
|
1097 |
|
|
|
1098 |
|
|
/* Fill in registers and arg lists */
|
1099 |
|
|
for (i = 0; i < nargs; i++)
|
1100 |
|
|
{
|
1101 |
|
|
struct value *arg = args[i];
|
1102 |
|
|
struct type *type = check_typedef (VALUE_TYPE (arg));
|
1103 |
|
|
char *contents = VALUE_CONTENTS (arg);
|
1104 |
|
|
int len = TYPE_LENGTH (type);
|
1105 |
|
|
int aligned_regnum = (regnum + 1) & ~1;
|
1106 |
|
|
|
1107 |
|
|
/* printf ("push: type=%d len=%d\n", TYPE_CODE (type), len); */
|
1108 |
|
|
if (len <= 2 && regnum <= ARGN_REGNUM)
|
1109 |
|
|
/* fits in a single register, do not align */
|
1110 |
|
|
{
|
1111 |
|
|
val = extract_unsigned_integer (contents, len);
|
1112 |
|
|
write_register (regnum++, val);
|
1113 |
|
|
}
|
1114 |
|
|
else if (len <= (ARGN_REGNUM - aligned_regnum + 1) * 2)
|
1115 |
|
|
/* value fits in remaining registers, store keeping left
|
1116 |
|
|
aligned */
|
1117 |
|
|
{
|
1118 |
|
|
int b;
|
1119 |
|
|
regnum = aligned_regnum;
|
1120 |
|
|
for (b = 0; b < (len & ~1); b += 2)
|
1121 |
|
|
{
|
1122 |
|
|
val = extract_unsigned_integer (&contents[b], 2);
|
1123 |
|
|
write_register (regnum++, val);
|
1124 |
|
|
}
|
1125 |
|
|
if (b < len)
|
1126 |
|
|
{
|
1127 |
|
|
val = extract_unsigned_integer (&contents[b], 1);
|
1128 |
|
|
write_register (regnum++, (val << 8));
|
1129 |
|
|
}
|
1130 |
|
|
}
|
1131 |
|
|
else
|
1132 |
|
|
{
|
1133 |
|
|
/* arg will go onto stack */
|
1134 |
|
|
regnum = ARGN_REGNUM + 1;
|
1135 |
|
|
si = push_stack_item (si, contents, len);
|
1136 |
|
|
}
|
1137 |
|
|
}
|
1138 |
|
|
|
1139 |
|
|
while (si)
|
1140 |
|
|
{
|
1141 |
|
|
sp = (sp - si->len) & ~1;
|
1142 |
|
|
write_memory (sp, si->data, si->len);
|
1143 |
|
|
si = pop_stack_item (si);
|
1144 |
|
|
}
|
1145 |
|
|
|
1146 |
|
|
return sp;
|
1147 |
|
|
}
|
1148 |
|
|
|
1149 |
|
|
|
1150 |
|
|
/* Given a return value in `regbuf' with a type `valtype',
|
1151 |
|
|
extract and copy its value into `valbuf'. */
|
1152 |
|
|
|
1153 |
|
|
static void
|
1154 |
|
|
d10v_extract_return_value (struct type *type, char regbuf[REGISTER_BYTES],
|
1155 |
|
|
char *valbuf)
|
1156 |
|
|
{
|
1157 |
|
|
int len;
|
1158 |
|
|
#if 0
|
1159 |
|
|
printf("RET: TYPE=%d len=%d r%d=0x%x\n", TYPE_CODE (type),
|
1160 |
|
|
TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM,
|
1161 |
|
|
(int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM),
|
1162 |
|
|
REGISTER_RAW_SIZE (RET1_REGNUM)));
|
1163 |
|
|
#endif
|
1164 |
|
|
len = TYPE_LENGTH (type);
|
1165 |
|
|
if (len == 1)
|
1166 |
|
|
{
|
1167 |
|
|
unsigned short c;
|
1168 |
|
|
|
1169 |
|
|
c = extract_unsigned_integer (regbuf + REGISTER_BYTE (RET1_REGNUM),
|
1170 |
|
|
REGISTER_RAW_SIZE (RET1_REGNUM));
|
1171 |
|
|
store_unsigned_integer (valbuf, 1, c);
|
1172 |
|
|
}
|
1173 |
|
|
else if ((len & 1) == 0)
|
1174 |
|
|
memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM), len);
|
1175 |
|
|
else
|
1176 |
|
|
{
|
1177 |
|
|
/* For return values of odd size, the first byte is in the
|
1178 |
|
|
least significant part of the first register. The
|
1179 |
|
|
remaining bytes in remaining registers. Interestingly,
|
1180 |
|
|
when such values are passed in, the last byte is in the
|
1181 |
|
|
most significant byte of that same register - wierd. */
|
1182 |
|
|
memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM) + 1, len);
|
1183 |
|
|
}
|
1184 |
|
|
}
|
1185 |
|
|
|
1186 |
|
|
/* Translate a GDB virtual ADDR/LEN into a format the remote target
|
1187 |
|
|
understands. Returns number of bytes that can be transfered
|
1188 |
|
|
starting at TARG_ADDR. Return ZERO if no bytes can be transfered
|
1189 |
|
|
(segmentation fault). Since the simulator knows all about how the
|
1190 |
|
|
VM system works, we just call that to do the translation. */
|
1191 |
|
|
|
1192 |
|
|
static void
|
1193 |
|
|
remote_d10v_translate_xfer_address (CORE_ADDR memaddr, int nr_bytes,
|
1194 |
|
|
CORE_ADDR *targ_addr, int *targ_len)
|
1195 |
|
|
{
|
1196 |
|
|
long out_addr;
|
1197 |
|
|
long out_len;
|
1198 |
|
|
out_len = sim_d10v_translate_addr (memaddr, nr_bytes,
|
1199 |
|
|
&out_addr,
|
1200 |
|
|
d10v_dmap_register,
|
1201 |
|
|
d10v_imap_register);
|
1202 |
|
|
*targ_addr = out_addr;
|
1203 |
|
|
*targ_len = out_len;
|
1204 |
|
|
}
|
1205 |
|
|
|
1206 |
|
|
|
1207 |
|
|
/* The following code implements access to, and display of, the D10V's
|
1208 |
|
|
instruction trace buffer. The buffer consists of 64K or more
|
1209 |
|
|
4-byte words of data, of which each words includes an 8-bit count,
|
1210 |
|
|
an 8-bit segment number, and a 16-bit instruction address.
|
1211 |
|
|
|
1212 |
|
|
In theory, the trace buffer is continuously capturing instruction
|
1213 |
|
|
data that the CPU presents on its "debug bus", but in practice, the
|
1214 |
|
|
ROMified GDB stub only enables tracing when it continues or steps
|
1215 |
|
|
the program, and stops tracing when the program stops; so it
|
1216 |
|
|
actually works for GDB to read the buffer counter out of memory and
|
1217 |
|
|
then read each trace word. The counter records where the tracing
|
1218 |
|
|
stops, but there is no record of where it started, so we remember
|
1219 |
|
|
the PC when we resumed and then search backwards in the trace
|
1220 |
|
|
buffer for a word that includes that address. This is not perfect,
|
1221 |
|
|
because you will miss trace data if the resumption PC is the target
|
1222 |
|
|
of a branch. (The value of the buffer counter is semi-random, any
|
1223 |
|
|
trace data from a previous program stop is gone.) */
|
1224 |
|
|
|
1225 |
|
|
/* The address of the last word recorded in the trace buffer. */
|
1226 |
|
|
|
1227 |
|
|
#define DBBC_ADDR (0xd80000)
|
1228 |
|
|
|
1229 |
|
|
/* The base of the trace buffer, at least for the "Board_0". */
|
1230 |
|
|
|
1231 |
|
|
#define TRACE_BUFFER_BASE (0xf40000)
|
1232 |
|
|
|
1233 |
|
|
static void trace_command (char *, int);
|
1234 |
|
|
|
1235 |
|
|
static void untrace_command (char *, int);
|
1236 |
|
|
|
1237 |
|
|
static void trace_info (char *, int);
|
1238 |
|
|
|
1239 |
|
|
static void tdisassemble_command (char *, int);
|
1240 |
|
|
|
1241 |
|
|
static void display_trace (int, int);
|
1242 |
|
|
|
1243 |
|
|
/* True when instruction traces are being collected. */
|
1244 |
|
|
|
1245 |
|
|
static int tracing;
|
1246 |
|
|
|
1247 |
|
|
/* Remembered PC. */
|
1248 |
|
|
|
1249 |
|
|
static CORE_ADDR last_pc;
|
1250 |
|
|
|
1251 |
|
|
/* True when trace output should be displayed whenever program stops. */
|
1252 |
|
|
|
1253 |
|
|
static int trace_display;
|
1254 |
|
|
|
1255 |
|
|
/* True when trace listing should include source lines. */
|
1256 |
|
|
|
1257 |
|
|
static int default_trace_show_source = 1;
|
1258 |
|
|
|
1259 |
|
|
struct trace_buffer
|
1260 |
|
|
{
|
1261 |
|
|
int size;
|
1262 |
|
|
short *counts;
|
1263 |
|
|
CORE_ADDR *addrs;
|
1264 |
|
|
}
|
1265 |
|
|
trace_data;
|
1266 |
|
|
|
1267 |
|
|
static void
|
1268 |
|
|
trace_command (char *args, int from_tty)
|
1269 |
|
|
{
|
1270 |
|
|
/* Clear the host-side trace buffer, allocating space if needed. */
|
1271 |
|
|
trace_data.size = 0;
|
1272 |
|
|
if (trace_data.counts == NULL)
|
1273 |
|
|
trace_data.counts = (short *) xmalloc (65536 * sizeof (short));
|
1274 |
|
|
if (trace_data.addrs == NULL)
|
1275 |
|
|
trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof (CORE_ADDR));
|
1276 |
|
|
|
1277 |
|
|
tracing = 1;
|
1278 |
|
|
|
1279 |
|
|
printf_filtered ("Tracing is now on.\n");
|
1280 |
|
|
}
|
1281 |
|
|
|
1282 |
|
|
static void
|
1283 |
|
|
untrace_command (char *args, int from_tty)
|
1284 |
|
|
{
|
1285 |
|
|
tracing = 0;
|
1286 |
|
|
|
1287 |
|
|
printf_filtered ("Tracing is now off.\n");
|
1288 |
|
|
}
|
1289 |
|
|
|
1290 |
|
|
static void
|
1291 |
|
|
trace_info (char *args, int from_tty)
|
1292 |
|
|
{
|
1293 |
|
|
int i;
|
1294 |
|
|
|
1295 |
|
|
if (trace_data.size)
|
1296 |
|
|
{
|
1297 |
|
|
printf_filtered ("%d entries in trace buffer:\n", trace_data.size);
|
1298 |
|
|
|
1299 |
|
|
for (i = 0; i < trace_data.size; ++i)
|
1300 |
|
|
{
|
1301 |
|
|
printf_filtered ("%d: %d instruction%s at 0x%s\n",
|
1302 |
|
|
i,
|
1303 |
|
|
trace_data.counts[i],
|
1304 |
|
|
(trace_data.counts[i] == 1 ? "" : "s"),
|
1305 |
|
|
paddr_nz (trace_data.addrs[i]));
|
1306 |
|
|
}
|
1307 |
|
|
}
|
1308 |
|
|
else
|
1309 |
|
|
printf_filtered ("No entries in trace buffer.\n");
|
1310 |
|
|
|
1311 |
|
|
printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off"));
|
1312 |
|
|
}
|
1313 |
|
|
|
1314 |
|
|
/* Print the instruction at address MEMADDR in debugged memory,
|
1315 |
|
|
on STREAM. Returns length of the instruction, in bytes. */
|
1316 |
|
|
|
1317 |
|
|
static int
|
1318 |
|
|
print_insn (CORE_ADDR memaddr, struct ui_file *stream)
|
1319 |
|
|
{
|
1320 |
|
|
/* If there's no disassembler, something is very wrong. */
|
1321 |
|
|
if (tm_print_insn == NULL)
|
1322 |
|
|
internal_error (__FILE__, __LINE__,
|
1323 |
|
|
"print_insn: no disassembler");
|
1324 |
|
|
|
1325 |
|
|
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
|
1326 |
|
|
tm_print_insn_info.endian = BFD_ENDIAN_BIG;
|
1327 |
|
|
else
|
1328 |
|
|
tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
|
1329 |
|
|
return TARGET_PRINT_INSN (memaddr, &tm_print_insn_info);
|
1330 |
|
|
}
|
1331 |
|
|
|
1332 |
|
|
static void
|
1333 |
|
|
d10v_eva_prepare_to_trace (void)
|
1334 |
|
|
{
|
1335 |
|
|
if (!tracing)
|
1336 |
|
|
return;
|
1337 |
|
|
|
1338 |
|
|
last_pc = read_register (PC_REGNUM);
|
1339 |
|
|
}
|
1340 |
|
|
|
1341 |
|
|
/* Collect trace data from the target board and format it into a form
|
1342 |
|
|
more useful for display. */
|
1343 |
|
|
|
1344 |
|
|
static void
|
1345 |
|
|
d10v_eva_get_trace_data (void)
|
1346 |
|
|
{
|
1347 |
|
|
int count, i, j, oldsize;
|
1348 |
|
|
int trace_addr, trace_seg, trace_cnt, next_cnt;
|
1349 |
|
|
unsigned int last_trace, trace_word, next_word;
|
1350 |
|
|
unsigned int *tmpspace;
|
1351 |
|
|
|
1352 |
|
|
if (!tracing)
|
1353 |
|
|
return;
|
1354 |
|
|
|
1355 |
|
|
tmpspace = xmalloc (65536 * sizeof (unsigned int));
|
1356 |
|
|
|
1357 |
|
|
last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2;
|
1358 |
|
|
|
1359 |
|
|
/* Collect buffer contents from the target, stopping when we reach
|
1360 |
|
|
the word recorded when execution resumed. */
|
1361 |
|
|
|
1362 |
|
|
count = 0;
|
1363 |
|
|
while (last_trace > 0)
|
1364 |
|
|
{
|
1365 |
|
|
QUIT;
|
1366 |
|
|
trace_word =
|
1367 |
|
|
read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4);
|
1368 |
|
|
trace_addr = trace_word & 0xffff;
|
1369 |
|
|
last_trace -= 4;
|
1370 |
|
|
/* Ignore an apparently nonsensical entry. */
|
1371 |
|
|
if (trace_addr == 0xffd5)
|
1372 |
|
|
continue;
|
1373 |
|
|
tmpspace[count++] = trace_word;
|
1374 |
|
|
if (trace_addr == last_pc)
|
1375 |
|
|
break;
|
1376 |
|
|
if (count > 65535)
|
1377 |
|
|
break;
|
1378 |
|
|
}
|
1379 |
|
|
|
1380 |
|
|
/* Move the data to the host-side trace buffer, adjusting counts to
|
1381 |
|
|
include the last instruction executed and transforming the address
|
1382 |
|
|
into something that GDB likes. */
|
1383 |
|
|
|
1384 |
|
|
for (i = 0; i < count; ++i)
|
1385 |
|
|
{
|
1386 |
|
|
trace_word = tmpspace[i];
|
1387 |
|
|
next_word = ((i == 0) ? 0 : tmpspace[i - 1]);
|
1388 |
|
|
trace_addr = trace_word & 0xffff;
|
1389 |
|
|
next_cnt = (next_word >> 24) & 0xff;
|
1390 |
|
|
j = trace_data.size + count - i - 1;
|
1391 |
|
|
trace_data.addrs[j] = (trace_addr << 2) + 0x1000000;
|
1392 |
|
|
trace_data.counts[j] = next_cnt + 1;
|
1393 |
|
|
}
|
1394 |
|
|
|
1395 |
|
|
oldsize = trace_data.size;
|
1396 |
|
|
trace_data.size += count;
|
1397 |
|
|
|
1398 |
|
|
xfree (tmpspace);
|
1399 |
|
|
|
1400 |
|
|
if (trace_display)
|
1401 |
|
|
display_trace (oldsize, trace_data.size);
|
1402 |
|
|
}
|
1403 |
|
|
|
1404 |
|
|
static void
|
1405 |
|
|
tdisassemble_command (char *arg, int from_tty)
|
1406 |
|
|
{
|
1407 |
|
|
int i, count;
|
1408 |
|
|
CORE_ADDR low, high;
|
1409 |
|
|
char *space_index;
|
1410 |
|
|
|
1411 |
|
|
if (!arg)
|
1412 |
|
|
{
|
1413 |
|
|
low = 0;
|
1414 |
|
|
high = trace_data.size;
|
1415 |
|
|
}
|
1416 |
|
|
else if (!(space_index = (char *) strchr (arg, ' ')))
|
1417 |
|
|
{
|
1418 |
|
|
low = parse_and_eval_address (arg);
|
1419 |
|
|
high = low + 5;
|
1420 |
|
|
}
|
1421 |
|
|
else
|
1422 |
|
|
{
|
1423 |
|
|
/* Two arguments. */
|
1424 |
|
|
*space_index = '\0';
|
1425 |
|
|
low = parse_and_eval_address (arg);
|
1426 |
|
|
high = parse_and_eval_address (space_index + 1);
|
1427 |
|
|
if (high < low)
|
1428 |
|
|
high = low;
|
1429 |
|
|
}
|
1430 |
|
|
|
1431 |
|
|
printf_filtered ("Dump of trace from %s to %s:\n", paddr_u (low), paddr_u (high));
|
1432 |
|
|
|
1433 |
|
|
display_trace (low, high);
|
1434 |
|
|
|
1435 |
|
|
printf_filtered ("End of trace dump.\n");
|
1436 |
|
|
gdb_flush (gdb_stdout);
|
1437 |
|
|
}
|
1438 |
|
|
|
1439 |
|
|
static void
|
1440 |
|
|
display_trace (int low, int high)
|
1441 |
|
|
{
|
1442 |
|
|
int i, count, trace_show_source, first, suppress;
|
1443 |
|
|
CORE_ADDR next_address;
|
1444 |
|
|
|
1445 |
|
|
trace_show_source = default_trace_show_source;
|
1446 |
|
|
if (!have_full_symbols () && !have_partial_symbols ())
|
1447 |
|
|
{
|
1448 |
|
|
trace_show_source = 0;
|
1449 |
|
|
printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
|
1450 |
|
|
printf_filtered ("Trace will not display any source.\n");
|
1451 |
|
|
}
|
1452 |
|
|
|
1453 |
|
|
first = 1;
|
1454 |
|
|
suppress = 0;
|
1455 |
|
|
for (i = low; i < high; ++i)
|
1456 |
|
|
{
|
1457 |
|
|
next_address = trace_data.addrs[i];
|
1458 |
|
|
count = trace_data.counts[i];
|
1459 |
|
|
while (count-- > 0)
|
1460 |
|
|
{
|
1461 |
|
|
QUIT;
|
1462 |
|
|
if (trace_show_source)
|
1463 |
|
|
{
|
1464 |
|
|
struct symtab_and_line sal, sal_prev;
|
1465 |
|
|
|
1466 |
|
|
sal_prev = find_pc_line (next_address - 4, 0);
|
1467 |
|
|
sal = find_pc_line (next_address, 0);
|
1468 |
|
|
|
1469 |
|
|
if (sal.symtab)
|
1470 |
|
|
{
|
1471 |
|
|
if (first || sal.line != sal_prev.line)
|
1472 |
|
|
print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
|
1473 |
|
|
suppress = 0;
|
1474 |
|
|
}
|
1475 |
|
|
else
|
1476 |
|
|
{
|
1477 |
|
|
if (!suppress)
|
1478 |
|
|
/* FIXME-32x64--assumes sal.pc fits in long. */
|
1479 |
|
|
printf_filtered ("No source file for address %s.\n",
|
1480 |
|
|
local_hex_string ((unsigned long) sal.pc));
|
1481 |
|
|
suppress = 1;
|
1482 |
|
|
}
|
1483 |
|
|
}
|
1484 |
|
|
first = 0;
|
1485 |
|
|
print_address (next_address, gdb_stdout);
|
1486 |
|
|
printf_filtered (":");
|
1487 |
|
|
printf_filtered ("\t");
|
1488 |
|
|
wrap_here (" ");
|
1489 |
|
|
next_address = next_address + print_insn (next_address, gdb_stdout);
|
1490 |
|
|
printf_filtered ("\n");
|
1491 |
|
|
gdb_flush (gdb_stdout);
|
1492 |
|
|
}
|
1493 |
|
|
}
|
1494 |
|
|
}
|
1495 |
|
|
|
1496 |
|
|
|
1497 |
|
|
static gdbarch_init_ftype d10v_gdbarch_init;
|
1498 |
|
|
|
1499 |
|
|
static struct gdbarch *
|
1500 |
|
|
d10v_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
|
1501 |
|
|
{
|
1502 |
|
|
static LONGEST d10v_call_dummy_words[] =
|
1503 |
|
|
{0};
|
1504 |
|
|
struct gdbarch *gdbarch;
|
1505 |
|
|
int d10v_num_regs;
|
1506 |
|
|
struct gdbarch_tdep *tdep;
|
1507 |
|
|
gdbarch_register_name_ftype *d10v_register_name;
|
1508 |
|
|
gdbarch_register_sim_regno_ftype *d10v_register_sim_regno;
|
1509 |
|
|
|
1510 |
|
|
/* Find a candidate among the list of pre-declared architectures. */
|
1511 |
|
|
arches = gdbarch_list_lookup_by_info (arches, &info);
|
1512 |
|
|
if (arches != NULL)
|
1513 |
|
|
return arches->gdbarch;
|
1514 |
|
|
|
1515 |
|
|
/* None found, create a new architecture from the information
|
1516 |
|
|
provided. */
|
1517 |
|
|
tdep = XMALLOC (struct gdbarch_tdep);
|
1518 |
|
|
gdbarch = gdbarch_alloc (&info, tdep);
|
1519 |
|
|
|
1520 |
|
|
switch (info.bfd_arch_info->mach)
|
1521 |
|
|
{
|
1522 |
|
|
case bfd_mach_d10v_ts2:
|
1523 |
|
|
d10v_num_regs = 37;
|
1524 |
|
|
d10v_register_name = d10v_ts2_register_name;
|
1525 |
|
|
d10v_register_sim_regno = d10v_ts2_register_sim_regno;
|
1526 |
|
|
tdep->a0_regnum = TS2_A0_REGNUM;
|
1527 |
|
|
tdep->nr_dmap_regs = TS2_NR_DMAP_REGS;
|
1528 |
|
|
tdep->dmap_register = d10v_ts2_dmap_register;
|
1529 |
|
|
tdep->imap_register = d10v_ts2_imap_register;
|
1530 |
|
|
break;
|
1531 |
|
|
default:
|
1532 |
|
|
case bfd_mach_d10v_ts3:
|
1533 |
|
|
d10v_num_regs = 42;
|
1534 |
|
|
d10v_register_name = d10v_ts3_register_name;
|
1535 |
|
|
d10v_register_sim_regno = d10v_ts3_register_sim_regno;
|
1536 |
|
|
tdep->a0_regnum = TS3_A0_REGNUM;
|
1537 |
|
|
tdep->nr_dmap_regs = TS3_NR_DMAP_REGS;
|
1538 |
|
|
tdep->dmap_register = d10v_ts3_dmap_register;
|
1539 |
|
|
tdep->imap_register = d10v_ts3_imap_register;
|
1540 |
|
|
break;
|
1541 |
|
|
}
|
1542 |
|
|
|
1543 |
|
|
set_gdbarch_read_pc (gdbarch, d10v_read_pc);
|
1544 |
|
|
set_gdbarch_write_pc (gdbarch, d10v_write_pc);
|
1545 |
|
|
set_gdbarch_read_fp (gdbarch, d10v_read_fp);
|
1546 |
|
|
set_gdbarch_read_sp (gdbarch, d10v_read_sp);
|
1547 |
|
|
set_gdbarch_write_sp (gdbarch, d10v_write_sp);
|
1548 |
|
|
|
1549 |
|
|
set_gdbarch_num_regs (gdbarch, d10v_num_regs);
|
1550 |
|
|
set_gdbarch_sp_regnum (gdbarch, 15);
|
1551 |
|
|
set_gdbarch_fp_regnum (gdbarch, 11);
|
1552 |
|
|
set_gdbarch_pc_regnum (gdbarch, 18);
|
1553 |
|
|
set_gdbarch_register_name (gdbarch, d10v_register_name);
|
1554 |
|
|
set_gdbarch_register_size (gdbarch, 2);
|
1555 |
|
|
set_gdbarch_register_bytes (gdbarch, (d10v_num_regs - 2) * 2 + 16);
|
1556 |
|
|
set_gdbarch_register_byte (gdbarch, d10v_register_byte);
|
1557 |
|
|
set_gdbarch_register_raw_size (gdbarch, d10v_register_raw_size);
|
1558 |
|
|
set_gdbarch_max_register_raw_size (gdbarch, 8);
|
1559 |
|
|
set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
|
1560 |
|
|
set_gdbarch_max_register_virtual_size (gdbarch, 8);
|
1561 |
|
|
set_gdbarch_register_virtual_type (gdbarch, d10v_register_virtual_type);
|
1562 |
|
|
|
1563 |
|
|
set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
|
1564 |
|
|
set_gdbarch_addr_bit (gdbarch, 32);
|
1565 |
|
|
set_gdbarch_address_to_pointer (gdbarch, d10v_address_to_pointer);
|
1566 |
|
|
set_gdbarch_pointer_to_address (gdbarch, d10v_pointer_to_address);
|
1567 |
|
|
set_gdbarch_integer_to_address (gdbarch, d10v_integer_to_address);
|
1568 |
|
|
set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
|
1569 |
|
|
set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT);
|
1570 |
|
|
set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
|
1571 |
|
|
set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
|
1572 |
|
|
/* NOTE: The d10v as a 32 bit ``float'' and ``double''. ``long
|
1573 |
|
|
double'' is 64 bits. */
|
1574 |
|
|
set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
|
1575 |
|
|
set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
|
1576 |
|
|
set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
|
1577 |
|
|
switch (info.byte_order)
|
1578 |
|
|
{
|
1579 |
|
|
case BFD_ENDIAN_BIG:
|
1580 |
|
|
set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_big);
|
1581 |
|
|
set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_big);
|
1582 |
|
|
set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
|
1583 |
|
|
break;
|
1584 |
|
|
case BFD_ENDIAN_LITTLE:
|
1585 |
|
|
set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_little);
|
1586 |
|
|
set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_little);
|
1587 |
|
|
set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_little);
|
1588 |
|
|
break;
|
1589 |
|
|
default:
|
1590 |
|
|
internal_error (__FILE__, __LINE__,
|
1591 |
|
|
"d10v_gdbarch_init: bad byte order for float format");
|
1592 |
|
|
}
|
1593 |
|
|
|
1594 |
|
|
set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
|
1595 |
|
|
set_gdbarch_call_dummy_length (gdbarch, 0);
|
1596 |
|
|
set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
|
1597 |
|
|
set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
|
1598 |
|
|
set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
|
1599 |
|
|
set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
|
1600 |
|
|
set_gdbarch_call_dummy_start_offset (gdbarch, 0);
|
1601 |
|
|
set_gdbarch_pc_in_call_dummy (gdbarch, generic_pc_in_call_dummy);
|
1602 |
|
|
set_gdbarch_call_dummy_words (gdbarch, d10v_call_dummy_words);
|
1603 |
|
|
set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (d10v_call_dummy_words));
|
1604 |
|
|
set_gdbarch_call_dummy_p (gdbarch, 1);
|
1605 |
|
|
set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
|
1606 |
|
|
set_gdbarch_get_saved_register (gdbarch, generic_unwind_get_saved_register);
|
1607 |
|
|
set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
|
1608 |
|
|
|
1609 |
|
|
set_gdbarch_deprecated_extract_return_value (gdbarch, d10v_extract_return_value);
|
1610 |
|
|
set_gdbarch_push_arguments (gdbarch, d10v_push_arguments);
|
1611 |
|
|
set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
|
1612 |
|
|
set_gdbarch_push_return_address (gdbarch, d10v_push_return_address);
|
1613 |
|
|
|
1614 |
|
|
set_gdbarch_store_struct_return (gdbarch, d10v_store_struct_return);
|
1615 |
|
|
set_gdbarch_deprecated_store_return_value (gdbarch, d10v_store_return_value);
|
1616 |
|
|
set_gdbarch_deprecated_extract_struct_value_address (gdbarch, d10v_extract_struct_value_address);
|
1617 |
|
|
set_gdbarch_use_struct_convention (gdbarch, d10v_use_struct_convention);
|
1618 |
|
|
|
1619 |
|
|
set_gdbarch_frame_init_saved_regs (gdbarch, d10v_frame_init_saved_regs);
|
1620 |
|
|
set_gdbarch_init_extra_frame_info (gdbarch, d10v_init_extra_frame_info);
|
1621 |
|
|
|
1622 |
|
|
set_gdbarch_pop_frame (gdbarch, d10v_pop_frame);
|
1623 |
|
|
|
1624 |
|
|
set_gdbarch_skip_prologue (gdbarch, d10v_skip_prologue);
|
1625 |
|
|
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
|
1626 |
|
|
set_gdbarch_decr_pc_after_break (gdbarch, 4);
|
1627 |
|
|
set_gdbarch_function_start_offset (gdbarch, 0);
|
1628 |
|
|
set_gdbarch_breakpoint_from_pc (gdbarch, d10v_breakpoint_from_pc);
|
1629 |
|
|
|
1630 |
|
|
set_gdbarch_remote_translate_xfer_address (gdbarch, remote_d10v_translate_xfer_address);
|
1631 |
|
|
|
1632 |
|
|
set_gdbarch_frame_args_skip (gdbarch, 0);
|
1633 |
|
|
set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue);
|
1634 |
|
|
set_gdbarch_frame_chain (gdbarch, d10v_frame_chain);
|
1635 |
|
|
set_gdbarch_frame_chain_valid (gdbarch, d10v_frame_chain_valid);
|
1636 |
|
|
set_gdbarch_frame_saved_pc (gdbarch, d10v_frame_saved_pc);
|
1637 |
|
|
set_gdbarch_frame_args_address (gdbarch, default_frame_address);
|
1638 |
|
|
set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
|
1639 |
|
|
set_gdbarch_saved_pc_after_call (gdbarch, d10v_saved_pc_after_call);
|
1640 |
|
|
set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
|
1641 |
|
|
set_gdbarch_stack_align (gdbarch, d10v_stack_align);
|
1642 |
|
|
|
1643 |
|
|
set_gdbarch_register_sim_regno (gdbarch, d10v_register_sim_regno);
|
1644 |
|
|
set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
|
1645 |
|
|
|
1646 |
|
|
return gdbarch;
|
1647 |
|
|
}
|
1648 |
|
|
|
1649 |
|
|
|
1650 |
|
|
extern void (*target_resume_hook) (void);
|
1651 |
|
|
extern void (*target_wait_loop_hook) (void);
|
1652 |
|
|
|
1653 |
|
|
void
|
1654 |
|
|
_initialize_d10v_tdep (void)
|
1655 |
|
|
{
|
1656 |
|
|
register_gdbarch_init (bfd_arch_d10v, d10v_gdbarch_init);
|
1657 |
|
|
|
1658 |
|
|
tm_print_insn = print_insn_d10v;
|
1659 |
|
|
|
1660 |
|
|
target_resume_hook = d10v_eva_prepare_to_trace;
|
1661 |
|
|
target_wait_loop_hook = d10v_eva_get_trace_data;
|
1662 |
|
|
|
1663 |
|
|
add_com ("regs", class_vars, show_regs, "Print all registers");
|
1664 |
|
|
|
1665 |
|
|
add_com ("itrace", class_support, trace_command,
|
1666 |
|
|
"Enable tracing of instruction execution.");
|
1667 |
|
|
|
1668 |
|
|
add_com ("iuntrace", class_support, untrace_command,
|
1669 |
|
|
"Disable tracing of instruction execution.");
|
1670 |
|
|
|
1671 |
|
|
add_com ("itdisassemble", class_vars, tdisassemble_command,
|
1672 |
|
|
"Disassemble the trace buffer.\n\
|
1673 |
|
|
Two optional arguments specify a range of trace buffer entries\n\
|
1674 |
|
|
as reported by info trace (NOT addresses!).");
|
1675 |
|
|
|
1676 |
|
|
add_info ("itrace", trace_info,
|
1677 |
|
|
"Display info about the trace data buffer.");
|
1678 |
|
|
|
1679 |
|
|
add_show_from_set (add_set_cmd ("itracedisplay", no_class,
|
1680 |
|
|
var_integer, (char *) &trace_display,
|
1681 |
|
|
"Set automatic display of trace.\n", &setlist),
|
1682 |
|
|
&showlist);
|
1683 |
|
|
add_show_from_set (add_set_cmd ("itracesource", no_class,
|
1684 |
|
|
var_integer, (char *) &default_trace_show_source,
|
1685 |
|
|
"Set display of source code with trace.\n", &setlist),
|
1686 |
|
|
&showlist);
|
1687 |
|
|
|
1688 |
|
|
}
|