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