1 /* Target-dependent code for Mitsubishi D10V, for GDB.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Contributed by Martin Hunt, hunt@cygnus.com */
29 #include "gdb_string.h"
38 extern void _initialize_d10v_tdep
PARAMS ((void));
40 static void d10v_eva_prepare_to_trace
PARAMS ((void));
42 static void d10v_eva_get_trace_data
PARAMS ((void));
45 d10v_frame_chain_valid (chain
, frame
)
47 struct frame_info
*frame
; /* not used here */
49 return ((chain
) != 0 && (frame
) != 0 && (frame
)->pc
> IMEM_START
);
53 /* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of
54 EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc
55 and TYPE is the type (which is known to be struct, union or array).
57 The d10v returns anything less than 8 bytes in size in
61 d10v_use_struct_convention (gcc_p
, type
)
65 return (TYPE_LENGTH (type
) > 8);
70 d10v_breakpoint_from_pc (pcptr
, lenptr
)
74 static unsigned char breakpoint
[] = {0x2f, 0x90, 0x5e, 0x00};
75 *lenptr
= sizeof (breakpoint
);
80 d10v_register_name (reg_nr
)
83 static char *register_names
[] = {
84 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
85 "r8", "r9", "r10","r11","r12", "r13", "r14","r15",
86 "psw","bpsw","pc","bpc", "cr4", "cr5", "cr6", "rpt_c",
87 "rpt_s","rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15",
88 "imap0","imap1","dmap","a0", "a1"
92 if (reg_nr
>= (sizeof (register_names
) / sizeof (*register_names
)))
94 return register_names
[reg_nr
];
98 /* Index within `registers' of the first byte of the space for
102 d10v_register_byte (reg_nr
)
105 if (reg_nr
> A0_REGNUM
)
106 return ((reg_nr
- A0_REGNUM
) * 8 + (A0_REGNUM
* 2));
111 /* Number of bytes of storage in the actual machine representation for
115 d10v_register_raw_size (reg_nr
)
118 if (reg_nr
>= A0_REGNUM
)
124 /* Number of bytes of storage in the program's representation
128 d10v_register_virtual_size (reg_nr
)
131 if (reg_nr
>= A0_REGNUM
)
133 else if (reg_nr
== PC_REGNUM
|| reg_nr
== SP_REGNUM
)
139 /* Return the GDB type object for the "standard" data type
140 of data in register N. */
143 d10v_register_virtual_type (reg_nr
)
146 if (reg_nr
>= A0_REGNUM
)
147 return builtin_type_long_long
;
148 else if (reg_nr
== PC_REGNUM
|| reg_nr
== SP_REGNUM
)
149 return builtin_type_long
;
151 return builtin_type_short
;
154 /* convert $pc and $sp to/from virtual addresses */
156 d10v_register_convertible (nr
)
159 return ((nr
) == PC_REGNUM
|| (nr
) == SP_REGNUM
);
163 d10v_register_convert_to_virtual (regnum
, type
, from
, to
)
169 ULONGEST x
= extract_unsigned_integer (from
, REGISTER_RAW_SIZE (regnum
));
170 if (regnum
== PC_REGNUM
)
171 x
= (x
<< 2) | IMEM_START
;
174 store_unsigned_integer (to
, TYPE_LENGTH (type
), x
);
178 d10v_register_convert_to_raw (type
, regnum
, from
, to
)
184 ULONGEST x
= extract_unsigned_integer (from
, TYPE_LENGTH (type
));
186 if (regnum
== PC_REGNUM
)
188 store_unsigned_integer (to
, 2, x
);
196 return ((x
) | DMEM_START
);
203 return (((x
) << 2) | IMEM_START
);
210 return (((x
) & 0x3000000) == DMEM_START
);
217 return (((x
) & 0x3000000) == IMEM_START
);
222 d10v_convert_iaddr_to_raw (x
)
225 return (((x
) >> 2) & 0xffff);
229 d10v_convert_daddr_to_raw(x
)
232 return ((x
) & 0xffff);
235 /* Store the address of the place in which to copy the structure the
236 subroutine will return. This is called from call_function.
238 We store structs through a pointer passed in the first Argument
242 d10v_store_struct_return (addr
, sp
)
246 write_register (ARG1_REGNUM
, (addr
));
249 /* Write into appropriate registers a function return value
250 of type TYPE, given in virtual format.
252 Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */
255 d10v_store_return_value (type
,valbuf
)
259 write_register_bytes (REGISTER_BYTE (RET1_REGNUM
),
264 /* Extract from an array REGBUF containing the (raw) register state
265 the address in which a function should return its structure value,
266 as a CORE_ADDR (or an expression that can be used as one). */
269 d10v_extract_struct_value_address (regbuf
)
272 return (extract_address ((regbuf
) + REGISTER_BYTE (ARG1_REGNUM
),
273 REGISTER_RAW_SIZE (ARG1_REGNUM
))
278 d10v_frame_saved_pc (frame
)
279 struct frame_info
*frame
;
281 return ((frame
)->return_pc
);
285 d10v_frame_args_address (fi
)
286 struct frame_info
*fi
;
292 d10v_frame_locals_address (fi
)
293 struct frame_info
*fi
;
298 /* Immediately after a function call, return the saved pc. We can't
299 use frame->return_pc beause that is determined by reading R13 off
300 the stack and that may not be written yet. */
303 d10v_saved_pc_after_call (frame
)
304 struct frame_info
*frame
;
306 return ((read_register(LR_REGNUM
) << 2)
310 /* Discard from the stack the innermost frame, restoring all saved
314 d10v_pop_frame (frame
)
315 struct frame_info
*frame
;
319 struct frame_saved_regs fsr
;
322 fp
= FRAME_FP (frame
);
323 /* fill out fsr with the address of where each */
324 /* register was stored in the frame */
325 get_frame_saved_regs (frame
, &fsr
);
327 /* now update the current registers with the old values */
328 for (regnum
= A0_REGNUM
; regnum
< A0_REGNUM
+2 ; regnum
++)
330 if (fsr
.regs
[regnum
])
332 read_memory (fsr
.regs
[regnum
], raw_buffer
, REGISTER_RAW_SIZE(regnum
));
333 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, REGISTER_RAW_SIZE(regnum
));
336 for (regnum
= 0; regnum
< SP_REGNUM
; regnum
++)
338 if (fsr
.regs
[regnum
])
340 write_register (regnum
, read_memory_unsigned_integer (fsr
.regs
[regnum
], REGISTER_RAW_SIZE(regnum
)));
343 if (fsr
.regs
[PSW_REGNUM
])
345 write_register (PSW_REGNUM
, read_memory_unsigned_integer (fsr
.regs
[PSW_REGNUM
], REGISTER_RAW_SIZE(PSW_REGNUM
)));
348 write_register (PC_REGNUM
, read_register (LR_REGNUM
));
349 write_register (SP_REGNUM
, fp
+ frame
->size
);
350 target_store_registers (-1);
351 flush_cached_frames ();
359 if ((op
& 0x7E1F) == 0x6C1F)
363 if ((op
& 0x7E3F) == 0x6E1F)
367 if ((op
& 0x7FE1) == 0x01E1)
379 if ((op
& 0x7E1F) == 0x681E)
383 if ((op
& 0x7E3F) == 0x3A1E)
390 d10v_skip_prologue (pc
)
394 unsigned short op1
, op2
;
395 CORE_ADDR func_addr
, func_end
;
396 struct symtab_and_line sal
;
398 /* If we have line debugging information, then the end of the */
399 /* prologue should the first assembly instruction of the first source line */
400 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
402 sal
= find_pc_line (func_addr
, 0);
403 if ( sal
.end
&& sal
.end
< func_end
)
407 if (target_read_memory (pc
, (char *)&op
, 4))
408 return pc
; /* Can't access it -- assume no prologue. */
412 op
= (unsigned long)read_memory_integer (pc
, 4);
413 if ((op
& 0xC0000000) == 0xC0000000)
415 /* long instruction */
416 if ( ((op
& 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */
417 ((op
& 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */
418 ((op
& 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */
423 /* short instructions */
424 if ((op
& 0xC0000000) == 0x80000000)
426 op2
= (op
& 0x3FFF8000) >> 15;
431 op1
= (op
& 0x3FFF8000) >> 15;
434 if (check_prologue(op1
))
436 if (!check_prologue(op2
))
438 /* if the previous opcode was really part of the prologue */
439 /* and not just a NOP, then we want to break after both instructions */
453 /* Given a GDB frame, determine the address of the calling function's frame.
454 This will be used to create a new GDB frame struct, and then
455 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
459 d10v_frame_chain (frame
)
460 struct frame_info
*frame
;
462 struct frame_saved_regs fsr
;
464 d10v_frame_find_saved_regs (frame
, &fsr
);
466 if (frame
->return_pc
== IMEM_START
|| inside_entry_file(frame
->return_pc
))
469 if (!fsr
.regs
[FP_REGNUM
])
471 if (!fsr
.regs
[SP_REGNUM
] || fsr
.regs
[SP_REGNUM
] == STACK_START
)
474 return fsr
.regs
[SP_REGNUM
];
477 if (!read_memory_unsigned_integer(fsr
.regs
[FP_REGNUM
], REGISTER_RAW_SIZE(FP_REGNUM
)))
480 return D10V_MAKE_DADDR (read_memory_unsigned_integer (fsr
.regs
[FP_REGNUM
], REGISTER_RAW_SIZE (FP_REGNUM
)));
483 static int next_addr
, uses_frame
;
486 prologue_find_regs (op
, fsr
, addr
)
488 struct frame_saved_regs
*fsr
;
494 if ((op
& 0x7E1F) == 0x6C1F)
496 n
= (op
& 0x1E0) >> 5;
498 fsr
->regs
[n
] = next_addr
;
503 else if ((op
& 0x7E3F) == 0x6E1F)
505 n
= (op
& 0x1E0) >> 5;
507 fsr
->regs
[n
] = next_addr
;
508 fsr
->regs
[n
+1] = next_addr
+2;
513 if ((op
& 0x7FE1) == 0x01E1)
515 n
= (op
& 0x1E) >> 1;
534 if ((op
& 0x7E1F) == 0x681E)
536 n
= (op
& 0x1E0) >> 5;
537 fsr
->regs
[n
] = next_addr
;
542 if ((op
& 0x7E3F) == 0x3A1E)
544 n
= (op
& 0x1E0) >> 5;
545 fsr
->regs
[n
] = next_addr
;
546 fsr
->regs
[n
+1] = next_addr
+2;
553 /* Put here the code to store, into a struct frame_saved_regs, the
554 addresses of the saved registers of frame described by FRAME_INFO.
555 This includes special registers such as pc and fp saved in special
556 ways in the stack frame. sp is even more special: the address we
557 return for it IS the sp for the next frame. */
559 d10v_frame_find_saved_regs (fi
, fsr
)
560 struct frame_info
*fi
;
561 struct frame_saved_regs
*fsr
;
565 unsigned short op1
, op2
;
569 memset (fsr
, 0, sizeof (*fsr
));
572 pc
= get_pc_function_start (fi
->pc
);
577 op
= (unsigned long)read_memory_integer (pc
, 4);
578 if ((op
& 0xC0000000) == 0xC0000000)
580 /* long instruction */
581 if ((op
& 0x3FFF0000) == 0x01FF0000)
584 short n
= op
& 0xFFFF;
587 else if ((op
& 0x3F0F0000) == 0x340F0000)
589 /* st rn, @(offset,sp) */
590 short offset
= op
& 0xFFFF;
591 short n
= (op
>> 20) & 0xF;
592 fsr
->regs
[n
] = next_addr
+ offset
;
594 else if ((op
& 0x3F1F0000) == 0x350F0000)
596 /* st2w rn, @(offset,sp) */
597 short offset
= op
& 0xFFFF;
598 short n
= (op
>> 20) & 0xF;
599 fsr
->regs
[n
] = next_addr
+ offset
;
600 fsr
->regs
[n
+1] = next_addr
+ offset
+ 2;
607 /* short instructions */
608 if ((op
& 0xC0000000) == 0x80000000)
610 op2
= (op
& 0x3FFF8000) >> 15;
615 op1
= (op
& 0x3FFF8000) >> 15;
618 if (!prologue_find_regs(op1
,fsr
,pc
) || !prologue_find_regs(op2
,fsr
,pc
))
624 fi
->size
= -next_addr
;
627 fp
= D10V_MAKE_DADDR (read_register(SP_REGNUM
));
629 for (i
=0; i
<NUM_REGS
-1; i
++)
632 fsr
->regs
[i
] = fp
- (next_addr
- fsr
->regs
[i
]);
635 if (fsr
->regs
[LR_REGNUM
])
637 CORE_ADDR return_pc
= read_memory_unsigned_integer (fsr
->regs
[LR_REGNUM
], REGISTER_RAW_SIZE (LR_REGNUM
));
638 fi
->return_pc
= D10V_MAKE_IADDR (return_pc
);
642 fi
->return_pc
= D10V_MAKE_IADDR (read_register(LR_REGNUM
));
645 /* th SP is not normally (ever?) saved, but check anyway */
646 if (!fsr
->regs
[SP_REGNUM
])
648 /* if the FP was saved, that means the current FP is valid, */
649 /* otherwise, it isn't being used, so we use the SP instead */
651 fsr
->regs
[SP_REGNUM
] = read_register(FP_REGNUM
) + fi
->size
;
654 fsr
->regs
[SP_REGNUM
] = fp
+ fi
->size
;
656 fsr
->regs
[FP_REGNUM
] = 0;
662 d10v_init_extra_frame_info (fromleaf
, fi
)
664 struct frame_info
*fi
;
670 /* The call dummy doesn't save any registers on the stack, so we can
672 if (PC_IN_CALL_DUMMY (fi
->pc
, fi
->frame
, fi
->frame
))
678 struct frame_saved_regs dummy
;
679 d10v_frame_find_saved_regs (fi
, &dummy
);
684 show_regs (args
, from_tty
)
689 printf_filtered ("PC=%04x (0x%x) PSW=%04x RPT_S=%04x RPT_E=%04x RPT_C=%04x\n",
690 read_register (PC_REGNUM
), D10V_MAKE_IADDR (read_register (PC_REGNUM
)),
691 read_register (PSW_REGNUM
),
695 printf_filtered ("R0-R7 %04x %04x %04x %04x %04x %04x %04x %04x\n",
704 printf_filtered ("R8-R15 %04x %04x %04x %04x %04x %04x %04x %04x\n",
713 printf_filtered ("IMAP0 %04x IMAP1 %04x DMAP %04x\n",
714 read_register (IMAP0_REGNUM
),
715 read_register (IMAP1_REGNUM
),
716 read_register (DMAP_REGNUM
));
717 printf_filtered ("A0-A1");
718 for (a
= A0_REGNUM
; a
<= A0_REGNUM
+ 1; a
++)
720 char num
[MAX_REGISTER_RAW_SIZE
];
722 printf_filtered (" ");
723 read_register_gen (a
, (char *)&num
);
724 for (i
= 0; i
< MAX_REGISTER_RAW_SIZE
; i
++)
726 printf_filtered ("%02x", (num
[i
] & 0xff));
729 printf_filtered ("\n");
740 save_pid
= inferior_pid
;
742 pc
= (int) read_register (PC_REGNUM
);
743 inferior_pid
= save_pid
;
744 retval
= D10V_MAKE_IADDR (pc
);
749 d10v_write_pc (val
, pid
)
755 save_pid
= inferior_pid
;
757 write_register (PC_REGNUM
, D10V_CONVERT_IADDR_TO_RAW (val
));
758 inferior_pid
= save_pid
;
764 return (D10V_MAKE_DADDR (read_register (SP_REGNUM
)));
771 write_register (SP_REGNUM
, D10V_CONVERT_DADDR_TO_RAW (val
));
778 write_register (FP_REGNUM
, D10V_CONVERT_DADDR_TO_RAW (val
));
784 return (D10V_MAKE_DADDR (read_register(FP_REGNUM
)));
787 /* Function: push_return_address (pc)
788 Set up the return address for the inferior function call.
789 Needed for targets where we don't actually execute a JSR/BSR instruction */
792 d10v_push_return_address (pc
, sp
)
796 write_register (LR_REGNUM
, D10V_CONVERT_IADDR_TO_RAW (CALL_DUMMY_ADDRESS ()));
801 /* When arguments must be pushed onto the stack, they go on in reverse
802 order. The below implements a FILO (stack) to do this. */
807 struct stack_item
*prev
;
811 static struct stack_item
*push_stack_item
PARAMS ((struct stack_item
*prev
, void *contents
, int len
));
812 static struct stack_item
*
813 push_stack_item (prev
, contents
, len
)
814 struct stack_item
*prev
;
818 struct stack_item
*si
;
819 si
= xmalloc (sizeof (struct stack_item
));
820 si
->data
= xmalloc (len
);
823 memcpy (si
->data
, contents
, len
);
827 static struct stack_item
*pop_stack_item
PARAMS ((struct stack_item
*si
));
828 static struct stack_item
*
830 struct stack_item
*si
;
832 struct stack_item
*dead
= si
;
841 d10v_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
846 CORE_ADDR struct_addr
;
849 int regnum
= ARG1_REGNUM
;
850 struct stack_item
*si
= NULL
;
852 /* Fill in registers and arg lists */
853 for (i
= 0; i
< nargs
; i
++)
855 value_ptr arg
= args
[i
];
856 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
857 char *contents
= VALUE_CONTENTS (arg
);
858 int len
= TYPE_LENGTH (type
);
859 /* printf ("push: type=%d len=%d\n", type->code, len); */
860 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
862 /* pointers require special handling - first convert and
864 long val
= extract_signed_integer (contents
, len
);
866 if (TYPE_TARGET_TYPE (type
)
867 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_FUNC
))
869 /* function pointer */
870 val
= D10V_CONVERT_IADDR_TO_RAW (val
);
872 else if (D10V_IADDR_P (val
))
874 /* also function pointer! */
875 val
= D10V_CONVERT_DADDR_TO_RAW (val
);
882 if (regnum
<= ARGN_REGNUM
)
883 write_register (regnum
++, val
& 0xffff);
887 /* arg will go onto stack */
888 store_address (ptr
, val
& 0xffff, 2);
889 si
= push_stack_item (si
, ptr
, 2);
894 int aligned_regnum
= (regnum
+ 1) & ~1;
895 if (len
<= 2 && regnum
<= ARGN_REGNUM
)
896 /* fits in a single register, do not align */
898 long val
= extract_unsigned_integer (contents
, len
);
899 write_register (regnum
++, val
);
901 else if (len
<= (ARGN_REGNUM
- aligned_regnum
+ 1) * 2)
902 /* value fits in remaining registers, store keeping left
906 regnum
= aligned_regnum
;
907 for (b
= 0; b
< (len
& ~1); b
+= 2)
909 long val
= extract_unsigned_integer (&contents
[b
], 2);
910 write_register (regnum
++, val
);
914 long val
= extract_unsigned_integer (&contents
[b
], 1);
915 write_register (regnum
++, (val
<< 8));
920 /* arg will go onto stack */
921 regnum
= ARGN_REGNUM
+ 1;
922 si
= push_stack_item (si
, contents
, len
);
929 sp
= (sp
- si
->len
) & ~1;
930 write_memory (sp
, si
->data
, si
->len
);
931 si
= pop_stack_item (si
);
938 /* Given a return value in `regbuf' with a type `valtype',
939 extract and copy its value into `valbuf'. */
942 d10v_extract_return_value (type
, regbuf
, valbuf
)
944 char regbuf
[REGISTER_BYTES
];
948 /* printf("RET: TYPE=%d len=%d r%d=0x%x\n",type->code, TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM, (int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM))); */
949 if (TYPE_CODE (type
) == TYPE_CODE_PTR
950 && TYPE_TARGET_TYPE (type
)
951 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_FUNC
))
953 /* pointer to function */
956 snum
= extract_address (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
957 store_address ( valbuf
, 4, D10V_MAKE_IADDR(snum
));
959 else if (TYPE_CODE(type
) == TYPE_CODE_PTR
)
961 /* pointer to data */
964 snum
= extract_address (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
965 store_address ( valbuf
, 4, D10V_MAKE_DADDR(snum
));
969 len
= TYPE_LENGTH (type
);
972 unsigned short c
= extract_unsigned_integer (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
973 store_unsigned_integer (valbuf
, 1, c
);
975 else if ((len
& 1) == 0)
976 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET1_REGNUM
), len
);
979 /* For return values of odd size, the first byte is in the
980 least significant part of the first register. The
981 remaining bytes in remaining registers. Interestingly,
982 when such values are passed in, the last byte is in the
983 most significant byte of that same register - wierd. */
984 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET1_REGNUM
) + 1, len
);
989 /* The following code implements access to, and display of, the D10V's
990 instruction trace buffer. The buffer consists of 64K or more
991 4-byte words of data, of which each words includes an 8-bit count,
992 an 8-bit segment number, and a 16-bit instruction address.
994 In theory, the trace buffer is continuously capturing instruction
995 data that the CPU presents on its "debug bus", but in practice, the
996 ROMified GDB stub only enables tracing when it continues or steps
997 the program, and stops tracing when the program stops; so it
998 actually works for GDB to read the buffer counter out of memory and
999 then read each trace word. The counter records where the tracing
1000 stops, but there is no record of where it started, so we remember
1001 the PC when we resumed and then search backwards in the trace
1002 buffer for a word that includes that address. This is not perfect,
1003 because you will miss trace data if the resumption PC is the target
1004 of a branch. (The value of the buffer counter is semi-random, any
1005 trace data from a previous program stop is gone.) */
1007 /* The address of the last word recorded in the trace buffer. */
1009 #define DBBC_ADDR (0xd80000)
1011 /* The base of the trace buffer, at least for the "Board_0". */
1013 #define TRACE_BUFFER_BASE (0xf40000)
1015 static void trace_command
PARAMS ((char *, int));
1017 static void untrace_command
PARAMS ((char *, int));
1019 static void trace_info
PARAMS ((char *, int));
1021 static void tdisassemble_command
PARAMS ((char *, int));
1023 static void display_trace
PARAMS ((int, int));
1025 /* True when instruction traces are being collected. */
1029 /* Remembered PC. */
1031 static CORE_ADDR last_pc
;
1033 /* True when trace output should be displayed whenever program stops. */
1035 static int trace_display
;
1037 /* True when trace listing should include source lines. */
1039 static int default_trace_show_source
= 1;
1041 struct trace_buffer
{
1048 trace_command (args
, from_tty
)
1052 /* Clear the host-side trace buffer, allocating space if needed. */
1053 trace_data
.size
= 0;
1054 if (trace_data
.counts
== NULL
)
1055 trace_data
.counts
= (short *) xmalloc (65536 * sizeof(short));
1056 if (trace_data
.addrs
== NULL
)
1057 trace_data
.addrs
= (CORE_ADDR
*) xmalloc (65536 * sizeof(CORE_ADDR
));
1061 printf_filtered ("Tracing is now on.\n");
1065 untrace_command (args
, from_tty
)
1071 printf_filtered ("Tracing is now off.\n");
1075 trace_info (args
, from_tty
)
1081 if (trace_data
.size
)
1083 printf_filtered ("%d entries in trace buffer:\n", trace_data
.size
);
1085 for (i
= 0; i
< trace_data
.size
; ++i
)
1087 printf_filtered ("%d: %d instruction%s at 0x%x\n",
1088 i
, trace_data
.counts
[i
],
1089 (trace_data
.counts
[i
] == 1 ? "" : "s"),
1090 trace_data
.addrs
[i
]);
1094 printf_filtered ("No entries in trace buffer.\n");
1096 printf_filtered ("Tracing is currently %s.\n", (tracing
? "on" : "off"));
1099 /* Print the instruction at address MEMADDR in debugged memory,
1100 on STREAM. Returns length of the instruction, in bytes. */
1103 print_insn (memaddr
, stream
)
1107 /* If there's no disassembler, something is very wrong. */
1108 if (tm_print_insn
== NULL
)
1111 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1112 tm_print_insn_info
.endian
= BFD_ENDIAN_BIG
;
1114 tm_print_insn_info
.endian
= BFD_ENDIAN_LITTLE
;
1115 return (*tm_print_insn
) (memaddr
, &tm_print_insn_info
);
1119 d10v_eva_prepare_to_trace ()
1124 last_pc
= read_register (PC_REGNUM
);
1127 /* Collect trace data from the target board and format it into a form
1128 more useful for display. */
1131 d10v_eva_get_trace_data ()
1133 int count
, i
, j
, oldsize
;
1134 int trace_addr
, trace_seg
, trace_cnt
, next_cnt
;
1135 unsigned int last_trace
, trace_word
, next_word
;
1136 unsigned int *tmpspace
;
1141 tmpspace
= xmalloc (65536 * sizeof(unsigned int));
1143 last_trace
= read_memory_unsigned_integer (DBBC_ADDR
, 2) << 2;
1145 /* Collect buffer contents from the target, stopping when we reach
1146 the word recorded when execution resumed. */
1149 while (last_trace
> 0)
1153 read_memory_unsigned_integer (TRACE_BUFFER_BASE
+ last_trace
, 4);
1154 trace_addr
= trace_word
& 0xffff;
1156 /* Ignore an apparently nonsensical entry. */
1157 if (trace_addr
== 0xffd5)
1159 tmpspace
[count
++] = trace_word
;
1160 if (trace_addr
== last_pc
)
1166 /* Move the data to the host-side trace buffer, adjusting counts to
1167 include the last instruction executed and transforming the address
1168 into something that GDB likes. */
1170 for (i
= 0; i
< count
; ++i
)
1172 trace_word
= tmpspace
[i
];
1173 next_word
= ((i
== 0) ? 0 : tmpspace
[i
- 1]);
1174 trace_addr
= trace_word
& 0xffff;
1175 next_cnt
= (next_word
>> 24) & 0xff;
1176 j
= trace_data
.size
+ count
- i
- 1;
1177 trace_data
.addrs
[j
] = (trace_addr
<< 2) + 0x1000000;
1178 trace_data
.counts
[j
] = next_cnt
+ 1;
1181 oldsize
= trace_data
.size
;
1182 trace_data
.size
+= count
;
1187 display_trace (oldsize
, trace_data
.size
);
1191 tdisassemble_command (arg
, from_tty
)
1196 CORE_ADDR low
, high
;
1202 high
= trace_data
.size
;
1204 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1206 low
= parse_and_eval_address (arg
);
1211 /* Two arguments. */
1212 *space_index
= '\0';
1213 low
= parse_and_eval_address (arg
);
1214 high
= parse_and_eval_address (space_index
+ 1);
1219 printf_filtered ("Dump of trace from %d to %d:\n", low
, high
);
1221 display_trace (low
, high
);
1223 printf_filtered ("End of trace dump.\n");
1224 gdb_flush (gdb_stdout
);
1228 display_trace (low
, high
)
1231 int i
, count
, trace_show_source
, first
, suppress
;
1232 CORE_ADDR next_address
;
1234 trace_show_source
= default_trace_show_source
;
1235 if (!have_full_symbols () && !have_partial_symbols())
1237 trace_show_source
= 0;
1238 printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
1239 printf_filtered ("Trace will not display any source.\n");
1244 for (i
= low
; i
< high
; ++i
)
1246 next_address
= trace_data
.addrs
[i
];
1247 count
= trace_data
.counts
[i
];
1251 if (trace_show_source
)
1253 struct symtab_and_line sal
, sal_prev
;
1255 sal_prev
= find_pc_line (next_address
- 4, 0);
1256 sal
= find_pc_line (next_address
, 0);
1260 if (first
|| sal
.line
!= sal_prev
.line
)
1261 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
1267 /* FIXME-32x64--assumes sal.pc fits in long. */
1268 printf_filtered ("No source file for address %s.\n",
1269 local_hex_string((unsigned long) sal
.pc
));
1274 print_address (next_address
, gdb_stdout
);
1275 printf_filtered (":");
1276 printf_filtered ("\t");
1278 next_address
= next_address
+ print_insn (next_address
, gdb_stdout
);
1279 printf_filtered ("\n");
1280 gdb_flush (gdb_stdout
);
1286 extern void (*target_resume_hook
) PARAMS ((void));
1287 extern void (*target_wait_loop_hook
) PARAMS ((void));
1290 _initialize_d10v_tdep ()
1292 tm_print_insn
= print_insn_d10v
;
1294 target_resume_hook
= d10v_eva_prepare_to_trace
;
1295 target_wait_loop_hook
= d10v_eva_get_trace_data
;
1297 add_com ("regs", class_vars
, show_regs
, "Print all registers");
1299 add_com ("trace", class_support
, trace_command
,
1300 "Enable tracing of instruction execution.");
1302 add_com ("untrace", class_support
, untrace_command
,
1303 "Disable tracing of instruction execution.");
1305 add_com ("tdisassemble", class_vars
, tdisassemble_command
,
1306 "Disassemble the trace buffer.\n\
1307 Two optional arguments specify a range of trace buffer entries\n\
1308 as reported by info trace (NOT addresses!).");
1310 add_info ("trace", trace_info
,
1311 "Display info about the trace data buffer.");
1313 add_show_from_set (add_set_cmd ("tracedisplay", no_class
,
1314 var_integer
, (char *)&trace_display
,
1315 "Set automatic display of trace.\n", &setlist
),
1317 add_show_from_set (add_set_cmd ("tracesource", no_class
,
1318 var_integer
, (char *)&default_trace_show_source
,
1319 "Set display of source code with trace.\n", &setlist
),