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
;
155 /* convert $pc and $sp to/from virtual addresses */
156 #define REGISTER_CONVERTIBLE(N) ((N) == PC_REGNUM || (N) == SP_REGNUM)
157 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,TYPE,FROM,TO) \
159 ULONGEST x = extract_unsigned_integer ((FROM), REGISTER_RAW_SIZE (REGNUM)); \
160 if (REGNUM == PC_REGNUM) x = (x << 2) | IMEM_START; \
161 else x |= DMEM_START; \
162 store_unsigned_integer ((TO), TYPE_LENGTH(TYPE), x); \
164 #define REGISTER_CONVERT_TO_RAW(TYPE,REGNUM,FROM,TO) \
166 ULONGEST x = extract_unsigned_integer ((FROM), TYPE_LENGTH(TYPE)); \
168 if (REGNUM == PC_REGNUM) x >>= 2; \
169 store_unsigned_integer ((TO), 2, x); \
177 return ((x
) | DMEM_START
);
184 return (((x
) << 2) | IMEM_START
);
191 return (((x
) & 0x3000000) == DMEM_START
);
198 return (((x
) & 0x3000000) == IMEM_START
);
203 d10v_convert_iaddr_to_raw (x
)
206 return (((x
) >> 2) & 0xffff);
210 d10v_convert_daddr_to_raw(x
)
213 return ((x
) & 0xffff);
216 /* Store the address of the place in which to copy the structure the
217 subroutine will return. This is called from call_function.
219 We store structs through a pointer passed in the first Argument
223 d10v_store_struct_return (addr
, sp
)
227 write_register (ARG1_REGNUM
, (addr
));
230 /* Write into appropriate registers a function return value
231 of type TYPE, given in virtual format.
233 Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */
236 d10v_store_return_value (type
,valbuf
)
240 write_register_bytes (REGISTER_BYTE (RET1_REGNUM
),
245 /* Extract from an array REGBUF containing the (raw) register state
246 the address in which a function should return its structure value,
247 as a CORE_ADDR (or an expression that can be used as one). */
250 d10v_extract_struct_value_address (regbuf
)
253 return (extract_address ((regbuf
) + REGISTER_BYTE (ARG1_REGNUM
),
254 REGISTER_RAW_SIZE (ARG1_REGNUM
))
259 d10v_frame_saved_pc (frame
)
260 struct frame_info
*frame
;
262 return ((frame
)->return_pc
);
266 d10v_frame_args_address (fi
)
267 struct frame_info
*fi
;
273 d10v_frame_locals_address (fi
)
274 struct frame_info
*fi
;
279 /* Immediately after a function call, return the saved pc. We can't
280 use frame->return_pc beause that is determined by reading R13 off
281 the stack and that may not be written yet. */
284 d10v_saved_pc_after_call (frame
)
285 struct frame_info
*frame
;
287 return ((read_register(LR_REGNUM
) << 2)
291 /* Discard from the stack the innermost frame, restoring all saved
295 d10v_pop_frame (frame
)
296 struct frame_info
*frame
;
300 struct frame_saved_regs fsr
;
303 fp
= FRAME_FP (frame
);
304 /* fill out fsr with the address of where each */
305 /* register was stored in the frame */
306 get_frame_saved_regs (frame
, &fsr
);
308 /* now update the current registers with the old values */
309 for (regnum
= A0_REGNUM
; regnum
< A0_REGNUM
+2 ; regnum
++)
311 if (fsr
.regs
[regnum
])
313 read_memory (fsr
.regs
[regnum
], raw_buffer
, REGISTER_RAW_SIZE(regnum
));
314 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, REGISTER_RAW_SIZE(regnum
));
317 for (regnum
= 0; regnum
< SP_REGNUM
; regnum
++)
319 if (fsr
.regs
[regnum
])
321 write_register (regnum
, read_memory_unsigned_integer (fsr
.regs
[regnum
], REGISTER_RAW_SIZE(regnum
)));
324 if (fsr
.regs
[PSW_REGNUM
])
326 write_register (PSW_REGNUM
, read_memory_unsigned_integer (fsr
.regs
[PSW_REGNUM
], REGISTER_RAW_SIZE(PSW_REGNUM
)));
329 write_register (PC_REGNUM
, read_register (LR_REGNUM
));
330 write_register (SP_REGNUM
, fp
+ frame
->size
);
331 target_store_registers (-1);
332 flush_cached_frames ();
340 if ((op
& 0x7E1F) == 0x6C1F)
344 if ((op
& 0x7E3F) == 0x6E1F)
348 if ((op
& 0x7FE1) == 0x01E1)
360 if ((op
& 0x7E1F) == 0x681E)
364 if ((op
& 0x7E3F) == 0x3A1E)
371 d10v_skip_prologue (pc
)
375 unsigned short op1
, op2
;
376 CORE_ADDR func_addr
, func_end
;
377 struct symtab_and_line sal
;
379 /* If we have line debugging information, then the end of the */
380 /* prologue should the first assembly instruction of the first source line */
381 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
383 sal
= find_pc_line (func_addr
, 0);
384 if ( sal
.end
&& sal
.end
< func_end
)
388 if (target_read_memory (pc
, (char *)&op
, 4))
389 return pc
; /* Can't access it -- assume no prologue. */
393 op
= (unsigned long)read_memory_integer (pc
, 4);
394 if ((op
& 0xC0000000) == 0xC0000000)
396 /* long instruction */
397 if ( ((op
& 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */
398 ((op
& 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */
399 ((op
& 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */
404 /* short instructions */
405 if ((op
& 0xC0000000) == 0x80000000)
407 op2
= (op
& 0x3FFF8000) >> 15;
412 op1
= (op
& 0x3FFF8000) >> 15;
415 if (check_prologue(op1
))
417 if (!check_prologue(op2
))
419 /* if the previous opcode was really part of the prologue */
420 /* and not just a NOP, then we want to break after both instructions */
434 /* Given a GDB frame, determine the address of the calling function's frame.
435 This will be used to create a new GDB frame struct, and then
436 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
440 d10v_frame_chain (frame
)
441 struct frame_info
*frame
;
443 struct frame_saved_regs fsr
;
445 d10v_frame_find_saved_regs (frame
, &fsr
);
447 if (frame
->return_pc
== IMEM_START
|| inside_entry_file(frame
->return_pc
))
450 if (!fsr
.regs
[FP_REGNUM
])
452 if (!fsr
.regs
[SP_REGNUM
] || fsr
.regs
[SP_REGNUM
] == STACK_START
)
455 return fsr
.regs
[SP_REGNUM
];
458 if (!read_memory_unsigned_integer(fsr
.regs
[FP_REGNUM
], REGISTER_RAW_SIZE(FP_REGNUM
)))
461 return D10V_MAKE_DADDR (read_memory_unsigned_integer (fsr
.regs
[FP_REGNUM
], REGISTER_RAW_SIZE (FP_REGNUM
)));
464 static int next_addr
, uses_frame
;
467 prologue_find_regs (op
, fsr
, addr
)
469 struct frame_saved_regs
*fsr
;
475 if ((op
& 0x7E1F) == 0x6C1F)
477 n
= (op
& 0x1E0) >> 5;
479 fsr
->regs
[n
] = next_addr
;
484 else if ((op
& 0x7E3F) == 0x6E1F)
486 n
= (op
& 0x1E0) >> 5;
488 fsr
->regs
[n
] = next_addr
;
489 fsr
->regs
[n
+1] = next_addr
+2;
494 if ((op
& 0x7FE1) == 0x01E1)
496 n
= (op
& 0x1E) >> 1;
515 if ((op
& 0x7E1F) == 0x681E)
517 n
= (op
& 0x1E0) >> 5;
518 fsr
->regs
[n
] = next_addr
;
523 if ((op
& 0x7E3F) == 0x3A1E)
525 n
= (op
& 0x1E0) >> 5;
526 fsr
->regs
[n
] = next_addr
;
527 fsr
->regs
[n
+1] = next_addr
+2;
534 /* Put here the code to store, into a struct frame_saved_regs, the
535 addresses of the saved registers of frame described by FRAME_INFO.
536 This includes special registers such as pc and fp saved in special
537 ways in the stack frame. sp is even more special: the address we
538 return for it IS the sp for the next frame. */
540 d10v_frame_find_saved_regs (fi
, fsr
)
541 struct frame_info
*fi
;
542 struct frame_saved_regs
*fsr
;
546 unsigned short op1
, op2
;
550 memset (fsr
, 0, sizeof (*fsr
));
553 pc
= get_pc_function_start (fi
->pc
);
558 op
= (unsigned long)read_memory_integer (pc
, 4);
559 if ((op
& 0xC0000000) == 0xC0000000)
561 /* long instruction */
562 if ((op
& 0x3FFF0000) == 0x01FF0000)
565 short n
= op
& 0xFFFF;
568 else if ((op
& 0x3F0F0000) == 0x340F0000)
570 /* st rn, @(offset,sp) */
571 short offset
= op
& 0xFFFF;
572 short n
= (op
>> 20) & 0xF;
573 fsr
->regs
[n
] = next_addr
+ offset
;
575 else if ((op
& 0x3F1F0000) == 0x350F0000)
577 /* st2w rn, @(offset,sp) */
578 short offset
= op
& 0xFFFF;
579 short n
= (op
>> 20) & 0xF;
580 fsr
->regs
[n
] = next_addr
+ offset
;
581 fsr
->regs
[n
+1] = next_addr
+ offset
+ 2;
588 /* short instructions */
589 if ((op
& 0xC0000000) == 0x80000000)
591 op2
= (op
& 0x3FFF8000) >> 15;
596 op1
= (op
& 0x3FFF8000) >> 15;
599 if (!prologue_find_regs(op1
,fsr
,pc
) || !prologue_find_regs(op2
,fsr
,pc
))
605 fi
->size
= -next_addr
;
608 fp
= D10V_MAKE_DADDR (read_register(SP_REGNUM
));
610 for (i
=0; i
<NUM_REGS
-1; i
++)
613 fsr
->regs
[i
] = fp
- (next_addr
- fsr
->regs
[i
]);
616 if (fsr
->regs
[LR_REGNUM
])
618 CORE_ADDR return_pc
= read_memory_unsigned_integer (fsr
->regs
[LR_REGNUM
], REGISTER_RAW_SIZE (LR_REGNUM
));
619 fi
->return_pc
= D10V_MAKE_IADDR (return_pc
);
623 fi
->return_pc
= D10V_MAKE_IADDR (read_register(LR_REGNUM
));
626 /* th SP is not normally (ever?) saved, but check anyway */
627 if (!fsr
->regs
[SP_REGNUM
])
629 /* if the FP was saved, that means the current FP is valid, */
630 /* otherwise, it isn't being used, so we use the SP instead */
632 fsr
->regs
[SP_REGNUM
] = read_register(FP_REGNUM
) + fi
->size
;
635 fsr
->regs
[SP_REGNUM
] = fp
+ fi
->size
;
637 fsr
->regs
[FP_REGNUM
] = 0;
643 d10v_init_extra_frame_info (fromleaf
, fi
)
645 struct frame_info
*fi
;
651 /* The call dummy doesn't save any registers on the stack, so we can
653 if (PC_IN_CALL_DUMMY (fi
->pc
, fi
->frame
, fi
->frame
))
659 struct frame_saved_regs dummy
;
660 d10v_frame_find_saved_regs (fi
, &dummy
);
665 show_regs (args
, from_tty
)
670 printf_filtered ("PC=%04x (0x%x) PSW=%04x RPT_S=%04x RPT_E=%04x RPT_C=%04x\n",
671 read_register (PC_REGNUM
), D10V_MAKE_IADDR (read_register (PC_REGNUM
)),
672 read_register (PSW_REGNUM
),
676 printf_filtered ("R0-R7 %04x %04x %04x %04x %04x %04x %04x %04x\n",
685 printf_filtered ("R8-R15 %04x %04x %04x %04x %04x %04x %04x %04x\n",
694 printf_filtered ("IMAP0 %04x IMAP1 %04x DMAP %04x\n",
695 read_register (IMAP0_REGNUM
),
696 read_register (IMAP1_REGNUM
),
697 read_register (DMAP_REGNUM
));
698 printf_filtered ("A0-A1");
699 for (a
= A0_REGNUM
; a
<= A0_REGNUM
+ 1; a
++)
701 char num
[MAX_REGISTER_RAW_SIZE
];
703 printf_filtered (" ");
704 read_register_gen (a
, (char *)&num
);
705 for (i
= 0; i
< MAX_REGISTER_RAW_SIZE
; i
++)
707 printf_filtered ("%02x", (num
[i
] & 0xff));
710 printf_filtered ("\n");
721 save_pid
= inferior_pid
;
723 pc
= (int) read_register (PC_REGNUM
);
724 inferior_pid
= save_pid
;
725 retval
= D10V_MAKE_IADDR (pc
);
730 d10v_write_pc (val
, pid
)
736 save_pid
= inferior_pid
;
738 write_register (PC_REGNUM
, D10V_CONVERT_IADDR_TO_RAW (val
));
739 inferior_pid
= save_pid
;
745 return (D10V_MAKE_DADDR (read_register (SP_REGNUM
)));
752 write_register (SP_REGNUM
, D10V_CONVERT_DADDR_TO_RAW (val
));
759 write_register (FP_REGNUM
, D10V_CONVERT_DADDR_TO_RAW (val
));
765 return (D10V_MAKE_DADDR (read_register(FP_REGNUM
)));
768 /* Function: push_return_address (pc)
769 Set up the return address for the inferior function call.
770 Needed for targets where we don't actually execute a JSR/BSR instruction */
773 d10v_push_return_address (pc
, sp
)
777 write_register (LR_REGNUM
, D10V_CONVERT_IADDR_TO_RAW (CALL_DUMMY_ADDRESS ()));
782 /* When arguments must be pushed onto the stack, they go on in reverse
783 order. The below implements a FILO (stack) to do this. */
788 struct stack_item
*prev
;
792 static struct stack_item
*push_stack_item
PARAMS ((struct stack_item
*prev
, void *contents
, int len
));
793 static struct stack_item
*
794 push_stack_item (prev
, contents
, len
)
795 struct stack_item
*prev
;
799 struct stack_item
*si
;
800 si
= xmalloc (sizeof (struct stack_item
));
801 si
->data
= xmalloc (len
);
804 memcpy (si
->data
, contents
, len
);
808 static struct stack_item
*pop_stack_item
PARAMS ((struct stack_item
*si
));
809 static struct stack_item
*
811 struct stack_item
*si
;
813 struct stack_item
*dead
= si
;
822 d10v_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
827 CORE_ADDR struct_addr
;
830 int regnum
= ARG1_REGNUM
;
831 struct stack_item
*si
= NULL
;
833 /* Fill in registers and arg lists */
834 for (i
= 0; i
< nargs
; i
++)
836 value_ptr arg
= args
[i
];
837 struct type
*type
= check_typedef (VALUE_TYPE (arg
));
838 char *contents
= VALUE_CONTENTS (arg
);
839 int len
= TYPE_LENGTH (type
);
840 /* printf ("push: type=%d len=%d\n", type->code, len); */
841 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
843 /* pointers require special handling - first convert and
845 long val
= extract_signed_integer (contents
, len
);
847 if (TYPE_TARGET_TYPE (type
)
848 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_FUNC
))
850 /* function pointer */
851 val
= D10V_CONVERT_IADDR_TO_RAW (val
);
853 else if (D10V_IADDR_P (val
))
855 /* also function pointer! */
856 val
= D10V_CONVERT_DADDR_TO_RAW (val
);
863 if (regnum
<= ARGN_REGNUM
)
864 write_register (regnum
++, val
& 0xffff);
868 /* arg will go onto stack */
869 store_address (ptr
, val
& 0xffff, 2);
870 si
= push_stack_item (si
, ptr
, 2);
875 int aligned_regnum
= (regnum
+ 1) & ~1;
876 if (len
<= 2 && regnum
<= ARGN_REGNUM
)
877 /* fits in a single register, do not align */
879 long val
= extract_unsigned_integer (contents
, len
);
880 write_register (regnum
++, val
);
882 else if (len
<= (ARGN_REGNUM
- aligned_regnum
+ 1) * 2)
883 /* value fits in remaining registers, store keeping left
887 regnum
= aligned_regnum
;
888 for (b
= 0; b
< (len
& ~1); b
+= 2)
890 long val
= extract_unsigned_integer (&contents
[b
], 2);
891 write_register (regnum
++, val
);
895 long val
= extract_unsigned_integer (&contents
[b
], 1);
896 write_register (regnum
++, (val
<< 8));
901 /* arg will go onto stack */
902 regnum
= ARGN_REGNUM
+ 1;
903 si
= push_stack_item (si
, contents
, len
);
910 sp
= (sp
- si
->len
) & ~1;
911 write_memory (sp
, si
->data
, si
->len
);
912 si
= pop_stack_item (si
);
919 /* Given a return value in `regbuf' with a type `valtype',
920 extract and copy its value into `valbuf'. */
923 d10v_extract_return_value (type
, regbuf
, valbuf
)
925 char regbuf
[REGISTER_BYTES
];
929 /* 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))); */
930 if (TYPE_CODE (type
) == TYPE_CODE_PTR
931 && TYPE_TARGET_TYPE (type
)
932 && (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_FUNC
))
934 /* pointer to function */
937 snum
= extract_address (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
938 store_address ( valbuf
, 4, D10V_MAKE_IADDR(snum
));
940 else if (TYPE_CODE(type
) == TYPE_CODE_PTR
)
942 /* pointer to data */
945 snum
= extract_address (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
946 store_address ( valbuf
, 4, D10V_MAKE_DADDR(snum
));
950 len
= TYPE_LENGTH (type
);
953 unsigned short c
= extract_unsigned_integer (regbuf
+ REGISTER_BYTE (RET1_REGNUM
), REGISTER_RAW_SIZE (RET1_REGNUM
));
954 store_unsigned_integer (valbuf
, 1, c
);
956 else if ((len
& 1) == 0)
957 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET1_REGNUM
), len
);
960 /* For return values of odd size, the first byte is in the
961 least significant part of the first register. The
962 remaining bytes in remaining registers. Interestingly,
963 when such values are passed in, the last byte is in the
964 most significant byte of that same register - wierd. */
965 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (RET1_REGNUM
) + 1, len
);
970 /* The following code implements access to, and display of, the D10V's
971 instruction trace buffer. The buffer consists of 64K or more
972 4-byte words of data, of which each words includes an 8-bit count,
973 an 8-bit segment number, and a 16-bit instruction address.
975 In theory, the trace buffer is continuously capturing instruction
976 data that the CPU presents on its "debug bus", but in practice, the
977 ROMified GDB stub only enables tracing when it continues or steps
978 the program, and stops tracing when the program stops; so it
979 actually works for GDB to read the buffer counter out of memory and
980 then read each trace word. The counter records where the tracing
981 stops, but there is no record of where it started, so we remember
982 the PC when we resumed and then search backwards in the trace
983 buffer for a word that includes that address. This is not perfect,
984 because you will miss trace data if the resumption PC is the target
985 of a branch. (The value of the buffer counter is semi-random, any
986 trace data from a previous program stop is gone.) */
988 /* The address of the last word recorded in the trace buffer. */
990 #define DBBC_ADDR (0xd80000)
992 /* The base of the trace buffer, at least for the "Board_0". */
994 #define TRACE_BUFFER_BASE (0xf40000)
996 static void trace_command
PARAMS ((char *, int));
998 static void untrace_command
PARAMS ((char *, int));
1000 static void trace_info
PARAMS ((char *, int));
1002 static void tdisassemble_command
PARAMS ((char *, int));
1004 static void display_trace
PARAMS ((int, int));
1006 /* True when instruction traces are being collected. */
1010 /* Remembered PC. */
1012 static CORE_ADDR last_pc
;
1014 /* True when trace output should be displayed whenever program stops. */
1016 static int trace_display
;
1018 /* True when trace listing should include source lines. */
1020 static int default_trace_show_source
= 1;
1022 struct trace_buffer
{
1029 trace_command (args
, from_tty
)
1033 /* Clear the host-side trace buffer, allocating space if needed. */
1034 trace_data
.size
= 0;
1035 if (trace_data
.counts
== NULL
)
1036 trace_data
.counts
= (short *) xmalloc (65536 * sizeof(short));
1037 if (trace_data
.addrs
== NULL
)
1038 trace_data
.addrs
= (CORE_ADDR
*) xmalloc (65536 * sizeof(CORE_ADDR
));
1042 printf_filtered ("Tracing is now on.\n");
1046 untrace_command (args
, from_tty
)
1052 printf_filtered ("Tracing is now off.\n");
1056 trace_info (args
, from_tty
)
1062 if (trace_data
.size
)
1064 printf_filtered ("%d entries in trace buffer:\n", trace_data
.size
);
1066 for (i
= 0; i
< trace_data
.size
; ++i
)
1068 printf_filtered ("%d: %d instruction%s at 0x%x\n",
1069 i
, trace_data
.counts
[i
],
1070 (trace_data
.counts
[i
] == 1 ? "" : "s"),
1071 trace_data
.addrs
[i
]);
1075 printf_filtered ("No entries in trace buffer.\n");
1077 printf_filtered ("Tracing is currently %s.\n", (tracing
? "on" : "off"));
1080 /* Print the instruction at address MEMADDR in debugged memory,
1081 on STREAM. Returns length of the instruction, in bytes. */
1084 print_insn (memaddr
, stream
)
1088 /* If there's no disassembler, something is very wrong. */
1089 if (tm_print_insn
== NULL
)
1092 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1093 tm_print_insn_info
.endian
= BFD_ENDIAN_BIG
;
1095 tm_print_insn_info
.endian
= BFD_ENDIAN_LITTLE
;
1096 return (*tm_print_insn
) (memaddr
, &tm_print_insn_info
);
1100 d10v_eva_prepare_to_trace ()
1105 last_pc
= read_register (PC_REGNUM
);
1108 /* Collect trace data from the target board and format it into a form
1109 more useful for display. */
1112 d10v_eva_get_trace_data ()
1114 int count
, i
, j
, oldsize
;
1115 int trace_addr
, trace_seg
, trace_cnt
, next_cnt
;
1116 unsigned int last_trace
, trace_word
, next_word
;
1117 unsigned int *tmpspace
;
1122 tmpspace
= xmalloc (65536 * sizeof(unsigned int));
1124 last_trace
= read_memory_unsigned_integer (DBBC_ADDR
, 2) << 2;
1126 /* Collect buffer contents from the target, stopping when we reach
1127 the word recorded when execution resumed. */
1130 while (last_trace
> 0)
1134 read_memory_unsigned_integer (TRACE_BUFFER_BASE
+ last_trace
, 4);
1135 trace_addr
= trace_word
& 0xffff;
1137 /* Ignore an apparently nonsensical entry. */
1138 if (trace_addr
== 0xffd5)
1140 tmpspace
[count
++] = trace_word
;
1141 if (trace_addr
== last_pc
)
1147 /* Move the data to the host-side trace buffer, adjusting counts to
1148 include the last instruction executed and transforming the address
1149 into something that GDB likes. */
1151 for (i
= 0; i
< count
; ++i
)
1153 trace_word
= tmpspace
[i
];
1154 next_word
= ((i
== 0) ? 0 : tmpspace
[i
- 1]);
1155 trace_addr
= trace_word
& 0xffff;
1156 next_cnt
= (next_word
>> 24) & 0xff;
1157 j
= trace_data
.size
+ count
- i
- 1;
1158 trace_data
.addrs
[j
] = (trace_addr
<< 2) + 0x1000000;
1159 trace_data
.counts
[j
] = next_cnt
+ 1;
1162 oldsize
= trace_data
.size
;
1163 trace_data
.size
+= count
;
1168 display_trace (oldsize
, trace_data
.size
);
1172 tdisassemble_command (arg
, from_tty
)
1177 CORE_ADDR low
, high
;
1183 high
= trace_data
.size
;
1185 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1187 low
= parse_and_eval_address (arg
);
1192 /* Two arguments. */
1193 *space_index
= '\0';
1194 low
= parse_and_eval_address (arg
);
1195 high
= parse_and_eval_address (space_index
+ 1);
1200 printf_filtered ("Dump of trace from %d to %d:\n", low
, high
);
1202 display_trace (low
, high
);
1204 printf_filtered ("End of trace dump.\n");
1205 gdb_flush (gdb_stdout
);
1209 display_trace (low
, high
)
1212 int i
, count
, trace_show_source
, first
, suppress
;
1213 CORE_ADDR next_address
;
1215 trace_show_source
= default_trace_show_source
;
1216 if (!have_full_symbols () && !have_partial_symbols())
1218 trace_show_source
= 0;
1219 printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
1220 printf_filtered ("Trace will not display any source.\n");
1225 for (i
= low
; i
< high
; ++i
)
1227 next_address
= trace_data
.addrs
[i
];
1228 count
= trace_data
.counts
[i
];
1232 if (trace_show_source
)
1234 struct symtab_and_line sal
, sal_prev
;
1236 sal_prev
= find_pc_line (next_address
- 4, 0);
1237 sal
= find_pc_line (next_address
, 0);
1241 if (first
|| sal
.line
!= sal_prev
.line
)
1242 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
1248 /* FIXME-32x64--assumes sal.pc fits in long. */
1249 printf_filtered ("No source file for address %s.\n",
1250 local_hex_string((unsigned long) sal
.pc
));
1255 print_address (next_address
, gdb_stdout
);
1256 printf_filtered (":");
1257 printf_filtered ("\t");
1259 next_address
= next_address
+ print_insn (next_address
, gdb_stdout
);
1260 printf_filtered ("\n");
1261 gdb_flush (gdb_stdout
);
1266 extern void (*target_resume_hook
) PARAMS ((void));
1267 extern void (*target_wait_loop_hook
) PARAMS ((void));
1270 _initialize_d10v_tdep ()
1272 tm_print_insn
= print_insn_d10v
;
1274 target_resume_hook
= d10v_eva_prepare_to_trace
;
1275 target_wait_loop_hook
= d10v_eva_get_trace_data
;
1277 add_com ("regs", class_vars
, show_regs
, "Print all registers");
1279 add_com ("trace", class_support
, trace_command
,
1280 "Enable tracing of instruction execution.");
1282 add_com ("untrace", class_support
, untrace_command
,
1283 "Disable tracing of instruction execution.");
1285 add_com ("tdisassemble", class_vars
, tdisassemble_command
,
1286 "Disassemble the trace buffer.\n\
1287 Two optional arguments specify a range of trace buffer entries\n\
1288 as reported by info trace (NOT addresses!).");
1290 add_info ("trace", trace_info
,
1291 "Display info about the trace data buffer.");
1293 add_show_from_set (add_set_cmd ("tracedisplay", no_class
,
1294 var_integer
, (char *)&trace_display
,
1295 "Set automatic display of trace.\n", &setlist
),
1297 add_show_from_set (add_set_cmd ("tracesource", no_class
,
1298 var_integer
, (char *)&default_trace_show_source
,
1299 "Set display of source code with trace.\n", &setlist
),