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