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,
19 Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
38 struct frame_extra_info
45 /* these are the addresses the D10V-EVA board maps data */
46 /* and instruction memory to. */
48 #define DMEM_START 0x0000000
49 #define IMEM_START 0x1000000
50 #define STACK_START 0x0007ffe
52 /* d10v register naming conventions */
54 #define ARG1_REGNUM R0_REGNUM
56 #define RET1_REGNUM R0_REGNUM
60 extern void _initialize_d10v_tdep PARAMS ((void));
62 static void d10v_eva_prepare_to_trace PARAMS ((void));
64 static void d10v_eva_get_trace_data PARAMS ((void));
66 static int prologue_find_regs PARAMS ((unsigned short op, struct frame_info * fi, CORE_ADDR addr));
68 extern void d10v_frame_init_saved_regs PARAMS ((struct frame_info *));
70 static void do_d10v_pop_frame PARAMS ((struct frame_info * fi));
73 extern void remote_d10v_translate_xfer_address PARAMS ((CORE_ADDR gdb_addr, int gdb_len, CORE_ADDR * rem_addr, int *rem_len));
76 d10v_frame_chain_valid (chain, frame)
78 struct frame_info *frame; /* not used here */
80 return ((chain) != 0 && (frame) != 0 && (frame)->pc > IMEM_START);
84 /* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of
85 EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc
86 and TYPE is the type (which is known to be struct, union or array).
88 The d10v returns anything less than 8 bytes in size in
92 d10v_use_struct_convention (gcc_p, type)
96 return (TYPE_LENGTH (type) > 8);
101 d10v_breakpoint_from_pc (pcptr, lenptr)
105 static unsigned char breakpoint[] =
106 {0x2f, 0x90, 0x5e, 0x00};
107 *lenptr = sizeof (breakpoint);
112 d10v_register_name (reg_nr)
115 static char *register_names[] =
117 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
118 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
119 "psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c",
120 "rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15",
121 "imap0", "imap1", "dmap", "a0", "a1"
125 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
127 return register_names[reg_nr];
131 /* Index within `registers' of the first byte of the space for
135 d10v_register_byte (reg_nr)
138 if (reg_nr > A0_REGNUM)
139 return ((reg_nr - A0_REGNUM) * 8 + (A0_REGNUM * 2));
144 /* Number of bytes of storage in the actual machine representation for
148 d10v_register_raw_size (reg_nr)
151 if (reg_nr >= A0_REGNUM)
157 /* Number of bytes of storage in the program's representation
161 d10v_register_virtual_size (reg_nr)
164 if (reg_nr >= A0_REGNUM)
166 else if (reg_nr == PC_REGNUM || reg_nr == SP_REGNUM)
172 /* Return the GDB type object for the "standard" data type
173 of data in register N. */
176 d10v_register_virtual_type (reg_nr)
179 if (reg_nr >= A0_REGNUM)
180 return builtin_type_long_long;
181 else if (reg_nr == PC_REGNUM || reg_nr == SP_REGNUM)
182 return builtin_type_long;
184 return builtin_type_short;
187 /* convert $pc and $sp to/from virtual addresses */
189 d10v_register_convertible (nr)
192 return ((nr) == PC_REGNUM || (nr) == SP_REGNUM);
196 d10v_register_convert_to_virtual (regnum, type, from, to)
202 ULONGEST x = extract_unsigned_integer (from, REGISTER_RAW_SIZE (regnum));
203 if (regnum == PC_REGNUM)
204 x = (x << 2) | IMEM_START;
207 store_unsigned_integer (to, TYPE_LENGTH (type), x);
211 d10v_register_convert_to_raw (type, regnum, from, to)
217 ULONGEST x = extract_unsigned_integer (from, TYPE_LENGTH (type));
219 if (regnum == PC_REGNUM)
221 store_unsigned_integer (to, 2, x);
229 return ((x) | DMEM_START);
236 return (((x) << 2) | IMEM_START);
243 return (((x) & 0x3000000) == DMEM_START);
250 return (((x) & 0x3000000) == IMEM_START);
255 d10v_convert_iaddr_to_raw (x)
258 return (((x) >> 2) & 0xffff);
262 d10v_convert_daddr_to_raw (x)
265 return ((x) & 0xffff);
268 /* Store the address of the place in which to copy the structure the
269 subroutine will return. This is called from call_function.
271 We store structs through a pointer passed in the first Argument
275 d10v_store_struct_return (addr, sp)
279 write_register (ARG1_REGNUM, (addr));
282 /* Write into appropriate registers a function return value
283 of type TYPE, given in virtual format.
285 Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */
288 d10v_store_return_value (type, valbuf)
292 write_register_bytes (REGISTER_BYTE (RET1_REGNUM),
297 /* Extract from an array REGBUF containing the (raw) register state
298 the address in which a function should return its structure value,
299 as a CORE_ADDR (or an expression that can be used as one). */
302 d10v_extract_struct_value_address (regbuf)
305 return (extract_address ((regbuf) + REGISTER_BYTE (ARG1_REGNUM),
306 REGISTER_RAW_SIZE (ARG1_REGNUM))
311 d10v_frame_saved_pc (frame)
312 struct frame_info *frame;
314 return ((frame)->extra_info->return_pc);
318 d10v_frame_args_address (fi)
319 struct frame_info *fi;
325 d10v_frame_locals_address (fi)
326 struct frame_info *fi;
331 /* Immediately after a function call, return the saved pc. We can't
332 use frame->return_pc beause that is determined by reading R13 off
333 the stack and that may not be written yet. */
336 d10v_saved_pc_after_call (frame)
337 struct frame_info *frame;
339 return ((read_register (LR_REGNUM) << 2)
343 /* Discard from the stack the innermost frame, restoring all saved
349 generic_pop_current_frame (do_d10v_pop_frame);
353 do_d10v_pop_frame (fi)
354 struct frame_info *fi;
361 /* fill out fsr with the address of where each */
362 /* register was stored in the frame */
363 d10v_frame_init_saved_regs (fi);
365 /* now update the current registers with the old values */
366 for (regnum = A0_REGNUM; regnum < A0_REGNUM + 2; regnum++)
368 if (fi->saved_regs[regnum])
370 read_memory (fi->saved_regs[regnum], raw_buffer, REGISTER_RAW_SIZE (regnum));
371 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, REGISTER_RAW_SIZE (regnum));
374 for (regnum = 0; regnum < SP_REGNUM; regnum++)
376 if (fi->saved_regs[regnum])
378 write_register (regnum, read_memory_unsigned_integer (fi->saved_regs[regnum], REGISTER_RAW_SIZE (regnum)));
381 if (fi->saved_regs[PSW_REGNUM])
383 write_register (PSW_REGNUM, read_memory_unsigned_integer (fi->saved_regs[PSW_REGNUM], REGISTER_RAW_SIZE (PSW_REGNUM)));
386 write_register (PC_REGNUM, read_register (LR_REGNUM));
387 write_register (SP_REGNUM, fp + fi->extra_info->size);
388 target_store_registers (-1);
389 flush_cached_frames ();
397 if ((op & 0x7E1F) == 0x6C1F)
401 if ((op & 0x7E3F) == 0x6E1F)
405 if ((op & 0x7FE1) == 0x01E1)
417 if ((op & 0x7E1F) == 0x681E)
421 if ((op & 0x7E3F) == 0x3A1E)
428 d10v_skip_prologue (pc)
432 unsigned short op1, op2;
433 CORE_ADDR func_addr, func_end;
434 struct symtab_and_line sal;
436 /* If we have line debugging information, then the end of the */
437 /* prologue should the first assembly instruction of the first source line */
438 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
440 sal = find_pc_line (func_addr, 0);
441 if (sal.end && sal.end < func_end)
445 if (target_read_memory (pc, (char *) &op, 4))
446 return pc; /* Can't access it -- assume no prologue. */
450 op = (unsigned long) read_memory_integer (pc, 4);
451 if ((op & 0xC0000000) == 0xC0000000)
453 /* long instruction */
454 if (((op & 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */
455 ((op & 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */
456 ((op & 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */
461 /* short instructions */
462 if ((op & 0xC0000000) == 0x80000000)
464 op2 = (op & 0x3FFF8000) >> 15;
469 op1 = (op & 0x3FFF8000) >> 15;
472 if (check_prologue (op1))
474 if (!check_prologue (op2))
476 /* if the previous opcode was really part of the prologue */
477 /* and not just a NOP, then we want to break after both instructions */
491 /* Given a GDB frame, determine the address of the calling function's frame.
492 This will be used to create a new GDB frame struct, and then
493 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
497 d10v_frame_chain (fi)
498 struct frame_info *fi;
500 d10v_frame_init_saved_regs (fi);
502 if (fi->extra_info->return_pc == IMEM_START
503 || inside_entry_file (fi->extra_info->return_pc))
504 return (CORE_ADDR) 0;
506 if (!fi->saved_regs[FP_REGNUM])
508 if (!fi->saved_regs[SP_REGNUM]
509 || fi->saved_regs[SP_REGNUM] == STACK_START)
510 return (CORE_ADDR) 0;
512 return fi->saved_regs[SP_REGNUM];
515 if (!read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
516 REGISTER_RAW_SIZE (FP_REGNUM)))
517 return (CORE_ADDR) 0;
519 return D10V_MAKE_DADDR (read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
520 REGISTER_RAW_SIZE (FP_REGNUM)));
523 static int next_addr, uses_frame;
526 prologue_find_regs (op, fi, addr)
528 struct frame_info *fi;
534 if ((op & 0x7E1F) == 0x6C1F)
536 n = (op & 0x1E0) >> 5;
538 fi->saved_regs[n] = next_addr;
543 else if ((op & 0x7E3F) == 0x6E1F)
545 n = (op & 0x1E0) >> 5;
547 fi->saved_regs[n] = next_addr;
548 fi->saved_regs[n + 1] = next_addr + 2;
553 if ((op & 0x7FE1) == 0x01E1)
555 n = (op & 0x1E) >> 1;
574 if ((op & 0x7E1F) == 0x681E)
576 n = (op & 0x1E0) >> 5;
577 fi->saved_regs[n] = next_addr;
582 if ((op & 0x7E3F) == 0x3A1E)
584 n = (op & 0x1E0) >> 5;
585 fi->saved_regs[n] = next_addr;
586 fi->saved_regs[n + 1] = next_addr + 2;
593 /* Put here the code to store, into fi->saved_regs, the addresses of
594 the saved registers of frame described by FRAME_INFO. This
595 includes special registers such as pc and fp saved in special ways
596 in the stack frame. sp is even more special: the address we return
597 for it IS the sp for the next frame. */
600 d10v_frame_init_saved_regs (fi)
601 struct frame_info *fi;
605 unsigned short op1, op2;
609 memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
612 pc = get_pc_function_start (fi->pc);
617 op = (unsigned long) read_memory_integer (pc, 4);
618 if ((op & 0xC0000000) == 0xC0000000)
620 /* long instruction */
621 if ((op & 0x3FFF0000) == 0x01FF0000)
624 short n = op & 0xFFFF;
627 else if ((op & 0x3F0F0000) == 0x340F0000)
629 /* st rn, @(offset,sp) */
630 short offset = op & 0xFFFF;
631 short n = (op >> 20) & 0xF;
632 fi->saved_regs[n] = next_addr + offset;
634 else if ((op & 0x3F1F0000) == 0x350F0000)
636 /* st2w rn, @(offset,sp) */
637 short offset = op & 0xFFFF;
638 short n = (op >> 20) & 0xF;
639 fi->saved_regs[n] = next_addr + offset;
640 fi->saved_regs[n + 1] = next_addr + offset + 2;
647 /* short instructions */
648 if ((op & 0xC0000000) == 0x80000000)
650 op2 = (op & 0x3FFF8000) >> 15;
655 op1 = (op & 0x3FFF8000) >> 15;
658 if (!prologue_find_regs (op1, fi, pc) || !prologue_find_regs (op2, fi, pc))
664 fi->extra_info->size = -next_addr;
667 fp = D10V_MAKE_DADDR (read_register (SP_REGNUM));
669 for (i = 0; i < NUM_REGS - 1; i++)
670 if (fi->saved_regs[i])
672 fi->saved_regs[i] = fp - (next_addr - fi->saved_regs[i]);
675 if (fi->saved_regs[LR_REGNUM])
677 CORE_ADDR return_pc = read_memory_unsigned_integer (fi->saved_regs[LR_REGNUM], REGISTER_RAW_SIZE (LR_REGNUM));
678 fi->extra_info->return_pc = D10V_MAKE_IADDR (return_pc);
682 fi->extra_info->return_pc = D10V_MAKE_IADDR (read_register (LR_REGNUM));
685 /* th SP is not normally (ever?) saved, but check anyway */
686 if (!fi->saved_regs[SP_REGNUM])
688 /* if the FP was saved, that means the current FP is valid, */
689 /* otherwise, it isn't being used, so we use the SP instead */
691 fi->saved_regs[SP_REGNUM] = read_register (FP_REGNUM) + fi->extra_info->size;
694 fi->saved_regs[SP_REGNUM] = fp + fi->extra_info->size;
695 fi->extra_info->frameless = 1;
696 fi->saved_regs[FP_REGNUM] = 0;
702 d10v_init_extra_frame_info (fromleaf, fi)
704 struct frame_info *fi;
706 fi->extra_info = (struct frame_extra_info *)
707 frame_obstack_alloc (sizeof (struct frame_extra_info));
708 frame_saved_regs_zalloc (fi);
710 fi->extra_info->frameless = 0;
711 fi->extra_info->size = 0;
712 fi->extra_info->return_pc = 0;
714 /* The call dummy doesn't save any registers on the stack, so we can
716 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
722 d10v_frame_init_saved_regs (fi);
727 show_regs (args, from_tty)
732 printf_filtered ("PC=%04x (0x%x) PSW=%04x RPT_S=%04x RPT_E=%04x RPT_C=%04x\n",
733 read_register (PC_REGNUM), D10V_MAKE_IADDR (read_register (PC_REGNUM)),
734 read_register (PSW_REGNUM),
738 printf_filtered ("R0-R7 %04x %04x %04x %04x %04x %04x %04x %04x\n",
747 printf_filtered ("R8-R15 %04x %04x %04x %04x %04x %04x %04x %04x\n",
756 printf_filtered ("IMAP0 %04x IMAP1 %04x DMAP %04x\n",
757 read_register (IMAP0_REGNUM),
758 read_register (IMAP1_REGNUM),
759 read_register (DMAP_REGNUM));
760 printf_filtered ("A0-A1");
761 for (a = A0_REGNUM; a <= A0_REGNUM + 1; a++)
763 char num[MAX_REGISTER_RAW_SIZE];
765 printf_filtered (" ");
766 read_register_gen (a, (char *) &num);
767 for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++)
769 printf_filtered ("%02x", (num[i] & 0xff));
772 printf_filtered ("\n");
783 save_pid = inferior_pid;
785 pc = (int) read_register (PC_REGNUM);
786 inferior_pid = save_pid;
787 retval = D10V_MAKE_IADDR (pc);
792 d10v_write_pc (val, pid)
798 save_pid = inferior_pid;
800 write_register (PC_REGNUM, D10V_CONVERT_IADDR_TO_RAW (val));
801 inferior_pid = save_pid;
807 return (D10V_MAKE_DADDR (read_register (SP_REGNUM)));
814 write_register (SP_REGNUM, D10V_CONVERT_DADDR_TO_RAW (val));
821 write_register (FP_REGNUM, D10V_CONVERT_DADDR_TO_RAW (val));
827 return (D10V_MAKE_DADDR (read_register (FP_REGNUM)));
830 /* Function: push_return_address (pc)
831 Set up the return address for the inferior function call.
832 Needed for targets where we don't actually execute a JSR/BSR instruction */
835 d10v_push_return_address (pc, sp)
839 write_register (LR_REGNUM, D10V_CONVERT_IADDR_TO_RAW (CALL_DUMMY_ADDRESS ()));
844 /* When arguments must be pushed onto the stack, they go on in reverse
845 order. The below implements a FILO (stack) to do this. */
850 struct stack_item *prev;
854 static struct stack_item *push_stack_item PARAMS ((struct stack_item * prev, void *contents, int len));
855 static struct stack_item *
856 push_stack_item (prev, contents, len)
857 struct stack_item *prev;
861 struct stack_item *si;
862 si = xmalloc (sizeof (struct stack_item));
863 si->data = xmalloc (len);
866 memcpy (si->data, contents, len);
870 static struct stack_item *pop_stack_item PARAMS ((struct stack_item * si));
871 static struct stack_item *
873 struct stack_item *si;
875 struct stack_item *dead = si;
884 d10v_push_arguments (nargs, args, sp, struct_return, struct_addr)
889 CORE_ADDR struct_addr;
892 int regnum = ARG1_REGNUM;
893 struct stack_item *si = NULL;
895 /* Fill in registers and arg lists */
896 for (i = 0; i < nargs; i++)
898 value_ptr arg = args[i];
899 struct type *type = check_typedef (VALUE_TYPE (arg));
900 char *contents = VALUE_CONTENTS (arg);
901 int len = TYPE_LENGTH (type);
902 /* printf ("push: type=%d len=%d\n", type->code, len); */
903 if (TYPE_CODE (type) == TYPE_CODE_PTR)
905 /* pointers require special handling - first convert and
907 long val = extract_signed_integer (contents, len);
909 if (TYPE_TARGET_TYPE (type)
910 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC))
912 /* function pointer */
913 val = D10V_CONVERT_IADDR_TO_RAW (val);
915 else if (D10V_IADDR_P (val))
917 /* also function pointer! */
918 val = D10V_CONVERT_DADDR_TO_RAW (val);
925 if (regnum <= ARGN_REGNUM)
926 write_register (regnum++, val & 0xffff);
930 /* arg will go onto stack */
931 store_address (ptr, 2, val & 0xffff);
932 si = push_stack_item (si, ptr, 2);
937 int aligned_regnum = (regnum + 1) & ~1;
938 if (len <= 2 && regnum <= ARGN_REGNUM)
939 /* fits in a single register, do not align */
941 long val = extract_unsigned_integer (contents, len);
942 write_register (regnum++, val);
944 else if (len <= (ARGN_REGNUM - aligned_regnum + 1) * 2)
945 /* value fits in remaining registers, store keeping left
949 regnum = aligned_regnum;
950 for (b = 0; b < (len & ~1); b += 2)
952 long val = extract_unsigned_integer (&contents[b], 2);
953 write_register (regnum++, val);
957 long val = extract_unsigned_integer (&contents[b], 1);
958 write_register (regnum++, (val << 8));
963 /* arg will go onto stack */
964 regnum = ARGN_REGNUM + 1;
965 si = push_stack_item (si, contents, len);
972 sp = (sp - si->len) & ~1;
973 write_memory (sp, si->data, si->len);
974 si = pop_stack_item (si);
981 /* Given a return value in `regbuf' with a type `valtype',
982 extract and copy its value into `valbuf'. */
985 d10v_extract_return_value (type, regbuf, valbuf)
987 char regbuf[REGISTER_BYTES];
991 /* 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))); */
992 if (TYPE_CODE (type) == TYPE_CODE_PTR
993 && TYPE_TARGET_TYPE (type)
994 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC))
996 /* pointer to function */
999 snum = extract_address (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM));
1000 store_address (valbuf, 4, D10V_MAKE_IADDR (snum));
1002 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
1004 /* pointer to data */
1007 snum = extract_address (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM));
1008 store_address (valbuf, 4, D10V_MAKE_DADDR (snum));
1012 len = TYPE_LENGTH (type);
1015 unsigned short c = extract_unsigned_integer (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM));
1016 store_unsigned_integer (valbuf, 1, c);
1018 else if ((len & 1) == 0)
1019 memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM), len);
1022 /* For return values of odd size, the first byte is in the
1023 least significant part of the first register. The
1024 remaining bytes in remaining registers. Interestingly,
1025 when such values are passed in, the last byte is in the
1026 most significant byte of that same register - wierd. */
1027 memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM) + 1, len);
1032 /* The following code implements access to, and display of, the D10V's
1033 instruction trace buffer. The buffer consists of 64K or more
1034 4-byte words of data, of which each words includes an 8-bit count,
1035 an 8-bit segment number, and a 16-bit instruction address.
1037 In theory, the trace buffer is continuously capturing instruction
1038 data that the CPU presents on its "debug bus", but in practice, the
1039 ROMified GDB stub only enables tracing when it continues or steps
1040 the program, and stops tracing when the program stops; so it
1041 actually works for GDB to read the buffer counter out of memory and
1042 then read each trace word. The counter records where the tracing
1043 stops, but there is no record of where it started, so we remember
1044 the PC when we resumed and then search backwards in the trace
1045 buffer for a word that includes that address. This is not perfect,
1046 because you will miss trace data if the resumption PC is the target
1047 of a branch. (The value of the buffer counter is semi-random, any
1048 trace data from a previous program stop is gone.) */
1050 /* The address of the last word recorded in the trace buffer. */
1052 #define DBBC_ADDR (0xd80000)
1054 /* The base of the trace buffer, at least for the "Board_0". */
1056 #define TRACE_BUFFER_BASE (0xf40000)
1058 static void trace_command PARAMS ((char *, int));
1060 static void untrace_command PARAMS ((char *, int));
1062 static void trace_info PARAMS ((char *, int));
1064 static void tdisassemble_command PARAMS ((char *, int));
1066 static void display_trace PARAMS ((int, int));
1068 /* True when instruction traces are being collected. */
1072 /* Remembered PC. */
1074 static CORE_ADDR last_pc;
1076 /* True when trace output should be displayed whenever program stops. */
1078 static int trace_display;
1080 /* True when trace listing should include source lines. */
1082 static int default_trace_show_source = 1;
1093 trace_command (args, from_tty)
1097 /* Clear the host-side trace buffer, allocating space if needed. */
1098 trace_data.size = 0;
1099 if (trace_data.counts == NULL)
1100 trace_data.counts = (short *) xmalloc (65536 * sizeof (short));
1101 if (trace_data.addrs == NULL)
1102 trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof (CORE_ADDR));
1106 printf_filtered ("Tracing is now on.\n");
1110 untrace_command (args, from_tty)
1116 printf_filtered ("Tracing is now off.\n");
1120 trace_info (args, from_tty)
1126 if (trace_data.size)
1128 printf_filtered ("%d entries in trace buffer:\n", trace_data.size);
1130 for (i = 0; i < trace_data.size; ++i)
1132 printf_filtered ("%d: %d instruction%s at 0x%x\n",
1133 i, trace_data.counts[i],
1134 (trace_data.counts[i] == 1 ? "" : "s"),
1135 trace_data.addrs[i]);
1139 printf_filtered ("No entries in trace buffer.\n");
1141 printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off"));
1144 /* Print the instruction at address MEMADDR in debugged memory,
1145 on STREAM. Returns length of the instruction, in bytes. */
1148 print_insn (memaddr, stream)
1152 /* If there's no disassembler, something is very wrong. */
1153 if (tm_print_insn == NULL)
1156 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1157 tm_print_insn_info.endian = BFD_ENDIAN_BIG;
1159 tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
1160 return (*tm_print_insn) (memaddr, &tm_print_insn_info);
1164 d10v_eva_prepare_to_trace ()
1169 last_pc = read_register (PC_REGNUM);
1172 /* Collect trace data from the target board and format it into a form
1173 more useful for display. */
1176 d10v_eva_get_trace_data ()
1178 int count, i, j, oldsize;
1179 int trace_addr, trace_seg, trace_cnt, next_cnt;
1180 unsigned int last_trace, trace_word, next_word;
1181 unsigned int *tmpspace;
1186 tmpspace = xmalloc (65536 * sizeof (unsigned int));
1188 last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2;
1190 /* Collect buffer contents from the target, stopping when we reach
1191 the word recorded when execution resumed. */
1194 while (last_trace > 0)
1198 read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4);
1199 trace_addr = trace_word & 0xffff;
1201 /* Ignore an apparently nonsensical entry. */
1202 if (trace_addr == 0xffd5)
1204 tmpspace[count++] = trace_word;
1205 if (trace_addr == last_pc)
1211 /* Move the data to the host-side trace buffer, adjusting counts to
1212 include the last instruction executed and transforming the address
1213 into something that GDB likes. */
1215 for (i = 0; i < count; ++i)
1217 trace_word = tmpspace[i];
1218 next_word = ((i == 0) ? 0 : tmpspace[i - 1]);
1219 trace_addr = trace_word & 0xffff;
1220 next_cnt = (next_word >> 24) & 0xff;
1221 j = trace_data.size + count - i - 1;
1222 trace_data.addrs[j] = (trace_addr << 2) + 0x1000000;
1223 trace_data.counts[j] = next_cnt + 1;
1226 oldsize = trace_data.size;
1227 trace_data.size += count;
1232 display_trace (oldsize, trace_data.size);
1236 tdisassemble_command (arg, from_tty)
1241 CORE_ADDR low, high;
1247 high = trace_data.size;
1249 else if (!(space_index = (char *) strchr (arg, ' ')))
1251 low = parse_and_eval_address (arg);
1256 /* Two arguments. */
1257 *space_index = '\0';
1258 low = parse_and_eval_address (arg);
1259 high = parse_and_eval_address (space_index + 1);
1264 printf_filtered ("Dump of trace from %d to %d:\n", low, high);
1266 display_trace (low, high);
1268 printf_filtered ("End of trace dump.\n");
1269 gdb_flush (gdb_stdout);
1273 display_trace (low, high)
1276 int i, count, trace_show_source, first, suppress;
1277 CORE_ADDR next_address;
1279 trace_show_source = default_trace_show_source;
1280 if (!have_full_symbols () && !have_partial_symbols ())
1282 trace_show_source = 0;
1283 printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
1284 printf_filtered ("Trace will not display any source.\n");
1289 for (i = low; i < high; ++i)
1291 next_address = trace_data.addrs[i];
1292 count = trace_data.counts[i];
1296 if (trace_show_source)
1298 struct symtab_and_line sal, sal_prev;
1300 sal_prev = find_pc_line (next_address - 4, 0);
1301 sal = find_pc_line (next_address, 0);
1305 if (first || sal.line != sal_prev.line)
1306 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
1312 /* FIXME-32x64--assumes sal.pc fits in long. */
1313 printf_filtered ("No source file for address %s.\n",
1314 local_hex_string ((unsigned long) sal.pc));
1319 print_address (next_address, gdb_stdout);
1320 printf_filtered (":");
1321 printf_filtered ("\t");
1323 next_address = next_address + print_insn (next_address, gdb_stdout);
1324 printf_filtered ("\n");
1325 gdb_flush (gdb_stdout);
1331 static gdbarch_init_ftype d10v_gdbarch_init;
1332 static struct gdbarch *
1333 d10v_gdbarch_init (info, arches)
1334 struct gdbarch_info info;
1335 struct gdbarch_list *arches;
1337 static LONGEST d10v_call_dummy_words[] =
1339 struct gdbarch *gdbarch;
1340 int d10v_num_regs = 37;
1342 /* there is only one d10v architecture */
1344 return arches->gdbarch;
1345 gdbarch = gdbarch_alloc (&info, NULL);
1347 set_gdbarch_read_pc (gdbarch, d10v_read_pc);
1348 set_gdbarch_write_pc (gdbarch, d10v_write_pc);
1349 set_gdbarch_read_fp (gdbarch, d10v_read_fp);
1350 set_gdbarch_write_fp (gdbarch, d10v_write_fp);
1351 set_gdbarch_read_sp (gdbarch, d10v_read_sp);
1352 set_gdbarch_write_sp (gdbarch, d10v_write_sp);
1354 set_gdbarch_num_regs (gdbarch, d10v_num_regs);
1355 set_gdbarch_sp_regnum (gdbarch, 15);
1356 set_gdbarch_fp_regnum (gdbarch, 11);
1357 set_gdbarch_pc_regnum (gdbarch, 18);
1358 set_gdbarch_register_name (gdbarch, d10v_register_name);
1359 set_gdbarch_register_size (gdbarch, 2);
1360 set_gdbarch_register_bytes (gdbarch, (d10v_num_regs - 2) * 2 + 16);
1361 set_gdbarch_register_byte (gdbarch, d10v_register_byte);
1362 set_gdbarch_register_raw_size (gdbarch, d10v_register_raw_size);
1363 set_gdbarch_max_register_raw_size (gdbarch, 8);
1364 set_gdbarch_register_virtual_size (gdbarch, d10v_register_virtual_size);
1365 set_gdbarch_max_register_virtual_size (gdbarch, 8);
1366 set_gdbarch_register_virtual_type (gdbarch, d10v_register_virtual_type);
1368 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1369 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1370 set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT);
1371 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1372 set_gdbarch_long_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1373 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1374 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1375 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1377 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
1378 set_gdbarch_call_dummy_length (gdbarch, 0);
1379 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1380 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
1381 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
1382 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
1383 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
1384 set_gdbarch_pc_in_call_dummy (gdbarch, generic_pc_in_call_dummy);
1385 set_gdbarch_call_dummy_words (gdbarch, d10v_call_dummy_words);
1386 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (d10v_call_dummy_words));
1387 set_gdbarch_call_dummy_p (gdbarch, 1);
1388 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1389 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
1390 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
1392 set_gdbarch_register_convertible (gdbarch, d10v_register_convertible);
1393 set_gdbarch_register_convert_to_virtual (gdbarch, d10v_register_convert_to_virtual);
1394 set_gdbarch_register_convert_to_raw (gdbarch, d10v_register_convert_to_raw);
1396 set_gdbarch_extract_return_value (gdbarch, d10v_extract_return_value);
1397 set_gdbarch_push_arguments (gdbarch, d10v_push_arguments);
1398 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
1399 set_gdbarch_push_return_address (gdbarch, d10v_push_return_address);
1401 set_gdbarch_d10v_make_daddr (gdbarch, d10v_make_daddr);
1402 set_gdbarch_d10v_make_iaddr (gdbarch, d10v_make_iaddr);
1403 set_gdbarch_d10v_daddr_p (gdbarch, d10v_daddr_p);
1404 set_gdbarch_d10v_iaddr_p (gdbarch, d10v_iaddr_p);
1405 set_gdbarch_d10v_convert_daddr_to_raw (gdbarch, d10v_convert_daddr_to_raw);
1406 set_gdbarch_d10v_convert_iaddr_to_raw (gdbarch, d10v_convert_iaddr_to_raw);
1408 set_gdbarch_store_struct_return (gdbarch, d10v_store_struct_return);
1409 set_gdbarch_store_return_value (gdbarch, d10v_store_return_value);
1410 set_gdbarch_extract_struct_value_address (gdbarch, d10v_extract_struct_value_address);
1411 set_gdbarch_use_struct_convention (gdbarch, d10v_use_struct_convention);
1413 set_gdbarch_frame_init_saved_regs (gdbarch, d10v_frame_init_saved_regs);
1414 set_gdbarch_init_extra_frame_info (gdbarch, d10v_init_extra_frame_info);
1416 set_gdbarch_pop_frame (gdbarch, d10v_pop_frame);
1418 set_gdbarch_skip_prologue (gdbarch, d10v_skip_prologue);
1419 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1420 set_gdbarch_decr_pc_after_break (gdbarch, 4);
1421 set_gdbarch_function_start_offset (gdbarch, 0);
1422 set_gdbarch_breakpoint_from_pc (gdbarch, d10v_breakpoint_from_pc);
1424 set_gdbarch_remote_translate_xfer_address (gdbarch, remote_d10v_translate_xfer_address);
1426 set_gdbarch_frame_args_skip (gdbarch, 0);
1427 set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue);
1428 set_gdbarch_frame_chain (gdbarch, d10v_frame_chain);
1429 set_gdbarch_frame_chain_valid (gdbarch, d10v_frame_chain_valid);
1430 set_gdbarch_frame_saved_pc (gdbarch, d10v_frame_saved_pc);
1431 set_gdbarch_frame_args_address (gdbarch, d10v_frame_args_address);
1432 set_gdbarch_frame_locals_address (gdbarch, d10v_frame_locals_address);
1433 set_gdbarch_saved_pc_after_call (gdbarch, d10v_saved_pc_after_call);
1434 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1440 extern void (*target_resume_hook) PARAMS ((void));
1441 extern void (*target_wait_loop_hook) PARAMS ((void));
1444 _initialize_d10v_tdep ()
1446 register_gdbarch_init (bfd_arch_d10v, d10v_gdbarch_init);
1448 tm_print_insn = print_insn_d10v;
1450 target_resume_hook = d10v_eva_prepare_to_trace;
1451 target_wait_loop_hook = d10v_eva_get_trace_data;
1453 add_com ("regs", class_vars, show_regs, "Print all registers");
1455 add_com ("trace", class_support, trace_command,
1456 "Enable tracing of instruction execution.");
1458 add_com ("untrace", class_support, untrace_command,
1459 "Disable tracing of instruction execution.");
1461 add_com ("tdisassemble", class_vars, tdisassemble_command,
1462 "Disassemble the trace buffer.\n\
1463 Two optional arguments specify a range of trace buffer entries\n\
1464 as reported by info trace (NOT addresses!).");
1466 add_info ("trace", trace_info,
1467 "Display info about the trace data buffer.");
1469 add_show_from_set (add_set_cmd ("tracedisplay", no_class,
1470 var_integer, (char *) &trace_display,
1471 "Set automatic display of trace.\n", &setlist),
1473 add_show_from_set (add_set_cmd ("tracesource", no_class,
1474 var_integer, (char *) &default_trace_show_source,
1475 "Set display of source code with trace.\n", &setlist),