4 #include "gdb/callback.h"
5 #include "gdb/remote-sim.h"
8 #include "gdb/sim-d10v.h"
9 #include "gdb/signals.h"
11 enum _leftright { LEFT_FIRST, RIGHT_FIRST };
14 static SIM_OPEN_KIND sim_kind;
17 /* Set this to true to get the previous segment layout. */
19 int old_segment_mapping;
21 host_callback *d10v_callback;
22 unsigned long ins_type_counters[ (int)INS_MAX ];
26 static int init_text_p = 0;
27 /* non-zero if we opened prog_bfd */
28 static int prog_bfd_was_opened_p;
34 static long hash PARAMS ((long insn, int format));
35 static struct hash_entry *lookup_hash PARAMS ((uint32 ins, int size));
36 static void get_operands PARAMS ((struct simops *s, uint32 ins));
37 static void do_long PARAMS ((uint32 ins));
38 static void do_2_short PARAMS ((uint16 ins1, uint16 ins2, enum _leftright leftright));
39 static void do_parallel PARAMS ((uint16 ins1, uint16 ins2));
40 static char *add_commas PARAMS ((char *buf, int sizeof_buf, unsigned long value));
41 extern void sim_set_profile PARAMS ((int n));
42 extern void sim_set_profile_size PARAMS ((int n));
43 static INLINE uint8 *map_memory (unsigned phys_addr);
45 #ifdef NEED_UI_LOOP_HOOK
46 /* How often to run the ui_loop update, when in use */
47 #define UI_LOOP_POLL_INTERVAL 0x14000
49 /* Counter for the ui_loop_hook update */
50 static long ui_loop_hook_counter = UI_LOOP_POLL_INTERVAL;
52 /* Actual hook to call to run through gdb's gui event loop */
53 extern int (*deprecated_ui_loop_hook) PARAMS ((int signo));
54 #endif /* NEED_UI_LOOP_HOOK */
57 #if defined(__GNUC__) && defined(__OPTIMIZE__)
58 #define INLINE __inline__
67 struct hash_entry *next;
74 struct hash_entry hash_table[MAX_HASH+1];
81 if (format & LONG_OPCODE)
82 return ((insn & 0x3F000000) >> 24);
84 return((insn & 0x7E00) >> 9);
87 INLINE static struct hash_entry *
88 lookup_hash (ins, size)
95 h = &hash_table[(ins & 0x3F000000) >> 24];
97 h = &hash_table[(ins & 0x7E00) >> 9];
99 while ((ins & h->mask) != h->opcode || h->size != size)
103 State.exception = SIGILL;
104 State.pc_changed = 1; /* Don't increment the PC. */
113 get_operands (struct simops *s, uint32 ins)
115 int i, shift, bits, flags;
117 for (i=0; i < s->numops; i++)
119 shift = s->operands[3*i];
120 bits = s->operands[3*i+1];
121 flags = s->operands[3*i+2];
122 mask = 0x7FFFFFFF >> (31 - bits);
123 OP[i] = (ins >> shift) & mask;
125 /* FIXME: for tracing, update values that need to be updated each
126 instruction decode cycle */
127 State.trace.psw = PSW;
134 if (!init_text_p && prog_bfd != NULL)
137 for (s = prog_bfd->sections; s; s = s->next)
138 if (strcmp (bfd_get_section_name (prog_bfd, s), ".text") == 0)
141 text_start = bfd_get_section_vma (prog_bfd, s);
142 text_end = text_start + bfd_section_size (prog_bfd, s);
147 return (PC << 2) + text_start;
154 struct hash_entry *h;
156 if ((d10v_debug & DEBUG_INSTRUCTION) != 0)
157 (*d10v_callback->printf_filtered) (d10v_callback, "do_long 0x%x\n", ins);
159 h = lookup_hash (ins, 1);
162 get_operands (h->ops, ins);
163 State.ins_type = INS_LONG;
164 ins_type_counters[ (int)State.ins_type ]++;
169 do_2_short (ins1, ins2, leftright)
171 enum _leftright leftright;
173 struct hash_entry *h;
174 enum _ins_type first, second;
177 if ((d10v_debug & DEBUG_INSTRUCTION) != 0)
178 (*d10v_callback->printf_filtered) (d10v_callback, "do_2_short 0x%x (%s) -> 0x%x\n",
179 ins1, (leftright) ? "left" : "right", ins2);
182 if (leftright == LEFT_FIRST)
186 ins_type_counters[ (int)INS_LEFTRIGHT ]++;
192 ins_type_counters[ (int)INS_RIGHTLEFT ]++;
195 /* Issue the first instruction */
196 h = lookup_hash (ins1, 0);
199 get_operands (h->ops, ins1);
200 State.ins_type = first;
201 ins_type_counters[ (int)State.ins_type ]++;
204 /* Issue the second instruction (if the PC hasn't changed) */
205 if (!State.pc_changed && !State.exception)
207 /* finish any existing instructions */
209 h = lookup_hash (ins2, 0);
212 get_operands (h->ops, ins2);
213 State.ins_type = second;
214 ins_type_counters[ (int)State.ins_type ]++;
215 ins_type_counters[ (int)INS_CYCLES ]++;
218 else if (!State.exception)
219 ins_type_counters[ (int)INS_COND_JUMP ]++;
223 do_parallel (ins1, ins2)
226 struct hash_entry *h1, *h2;
228 if ((d10v_debug & DEBUG_INSTRUCTION) != 0)
229 (*d10v_callback->printf_filtered) (d10v_callback, "do_parallel 0x%x || 0x%x\n", ins1, ins2);
231 ins_type_counters[ (int)INS_PARALLEL ]++;
232 h1 = lookup_hash (ins1, 0);
235 h2 = lookup_hash (ins2, 0);
239 if (h1->ops->exec_type == PARONLY)
241 get_operands (h1->ops, ins1);
242 State.ins_type = INS_LEFT_COND_TEST;
243 ins_type_counters[ (int)State.ins_type ]++;
247 ins_type_counters[ (int)INS_COND_TRUE ]++;
248 get_operands (h2->ops, ins2);
249 State.ins_type = INS_RIGHT_COND_EXE;
250 ins_type_counters[ (int)State.ins_type ]++;
254 ins_type_counters[ (int)INS_COND_FALSE ]++;
256 else if (h2->ops->exec_type == PARONLY)
258 get_operands (h2->ops, ins2);
259 State.ins_type = INS_RIGHT_COND_TEST;
260 ins_type_counters[ (int)State.ins_type ]++;
264 ins_type_counters[ (int)INS_COND_TRUE ]++;
265 get_operands (h1->ops, ins1);
266 State.ins_type = INS_LEFT_COND_EXE;
267 ins_type_counters[ (int)State.ins_type ]++;
271 ins_type_counters[ (int)INS_COND_FALSE ]++;
275 get_operands (h1->ops, ins1);
276 State.ins_type = INS_LEFT_PARALLEL;
277 ins_type_counters[ (int)State.ins_type ]++;
279 if (!State.exception)
281 get_operands (h2->ops, ins2);
282 State.ins_type = INS_RIGHT_PARALLEL;
283 ins_type_counters[ (int)State.ins_type ]++;
290 add_commas(buf, sizeof_buf, value)
296 char *endbuf = buf + sizeof_buf - 1;
306 *--endbuf = (value % 10) + '0';
307 } while ((value /= 10) != 0);
318 for (i = 0; i < IMEM_SEGMENTS; i++)
320 if (State.mem.insn[i])
321 free (State.mem.insn[i]);
323 for (i = 0; i < DMEM_SEGMENTS; i++)
325 if (State.mem.data[i])
326 free (State.mem.data[i]);
328 for (i = 0; i < UMEM_SEGMENTS; i++)
330 if (State.mem.unif[i])
331 free (State.mem.unif[i]);
333 /* Always allocate dmem segment 0. This contains the IMAP and DMAP
335 State.mem.data[0] = calloc (1, SEGMENT_SIZE);
338 /* For tracing - leave info on last access around. */
339 static char *last_segname = "invalid";
340 static char *last_from = "invalid";
341 static char *last_to = "invalid";
345 IMAP0_OFFSET = 0xff00,
346 DMAP0_OFFSET = 0xff08,
347 DMAP2_SHADDOW = 0xff04,
348 DMAP2_OFFSET = 0xff0c
352 set_dmap_register (int reg_nr, unsigned long value)
354 uint8 *raw = map_memory (SIM_D10V_MEMORY_DATA
355 + DMAP0_OFFSET + 2 * reg_nr);
356 WRITE_16 (raw, value);
358 if ((d10v_debug & DEBUG_MEMORY))
360 (*d10v_callback->printf_filtered)
361 (d10v_callback, "mem: dmap%d=0x%04lx\n", reg_nr, value);
367 dmap_register (void *regcache, int reg_nr)
369 uint8 *raw = map_memory (SIM_D10V_MEMORY_DATA
370 + DMAP0_OFFSET + 2 * reg_nr);
371 return READ_16 (raw);
375 set_imap_register (int reg_nr, unsigned long value)
377 uint8 *raw = map_memory (SIM_D10V_MEMORY_DATA
378 + IMAP0_OFFSET + 2 * reg_nr);
379 WRITE_16 (raw, value);
381 if ((d10v_debug & DEBUG_MEMORY))
383 (*d10v_callback->printf_filtered)
384 (d10v_callback, "mem: imap%d=0x%04lx\n", reg_nr, value);
390 imap_register (void *regcache, int reg_nr)
392 uint8 *raw = map_memory (SIM_D10V_MEMORY_DATA
393 + IMAP0_OFFSET + 2 * reg_nr);
394 return READ_16 (raw);
409 return HELD_SP (HELD_SPU_IDX);
418 return HELD_SP (HELD_SPI_IDX);
422 set_spi_register (unsigned long value)
425 SET_GPR (SP_IDX, value);
426 SET_HELD_SP (HELD_SPI_IDX, value);
430 set_spu_register (unsigned long value)
433 SET_GPR (SP_IDX, value);
434 SET_HELD_SP (HELD_SPU_IDX, value);
437 /* Given a virtual address in the DMAP address space, translate it
438 into a physical address. */
441 sim_d10v_translate_dmap_addr (unsigned long offset,
445 unsigned long (*dmap_register) (void *regcache,
450 last_from = "logical-data";
451 if (offset >= DMAP_BLOCK_SIZE * SIM_D10V_NR_DMAP_REGS)
453 /* Logical address out side of data segments, not supported */
456 regno = (offset / DMAP_BLOCK_SIZE);
457 offset = (offset % DMAP_BLOCK_SIZE);
458 if ((offset % DMAP_BLOCK_SIZE) + nr_bytes > DMAP_BLOCK_SIZE)
460 /* Don't cross a BLOCK boundary */
461 nr_bytes = DMAP_BLOCK_SIZE - (offset % DMAP_BLOCK_SIZE);
463 map = dmap_register (regcache, regno);
466 /* Always maps to data memory */
467 int iospi = (offset / 0x1000) % 4;
468 int iosp = (map >> (4 * (3 - iospi))) % 0x10;
469 last_to = "io-space";
470 *phys = (SIM_D10V_MEMORY_DATA + (iosp * 0x10000) + 0xc000 + offset);
474 int sp = ((map & 0x3000) >> 12);
475 int segno = (map & 0x3ff);
478 case 0: /* 00: Unified memory */
479 *phys = SIM_D10V_MEMORY_UNIFIED + (segno * DMAP_BLOCK_SIZE) + offset;
482 case 1: /* 01: Instruction Memory */
483 *phys = SIM_D10V_MEMORY_INSN + (segno * DMAP_BLOCK_SIZE) + offset;
484 last_to = "chip-insn";
486 case 2: /* 10: Internal data memory */
487 *phys = SIM_D10V_MEMORY_DATA + (segno << 16) + (regno * DMAP_BLOCK_SIZE) + offset;
488 last_to = "chip-data";
490 case 3: /* 11: Reserved */
497 /* Given a virtual address in the IMAP address space, translate it
498 into a physical address. */
501 sim_d10v_translate_imap_addr (unsigned long offset,
505 unsigned long (*imap_register) (void *regcache,
512 last_from = "logical-insn";
513 if (offset >= (IMAP_BLOCK_SIZE * SIM_D10V_NR_IMAP_REGS))
515 /* Logical address outside of IMAP segments, not supported */
518 regno = (offset / IMAP_BLOCK_SIZE);
519 offset = (offset % IMAP_BLOCK_SIZE);
520 if (offset + nr_bytes > IMAP_BLOCK_SIZE)
522 /* Don't cross a BLOCK boundary */
523 nr_bytes = IMAP_BLOCK_SIZE - offset;
525 map = imap_register (regcache, regno);
526 sp = (map & 0x3000) >> 12;
527 segno = (map & 0x007f);
530 case 0: /* 00: unified memory */
531 *phys = SIM_D10V_MEMORY_UNIFIED + (segno << 17) + offset;
534 case 1: /* 01: instruction memory */
535 *phys = SIM_D10V_MEMORY_INSN + (IMAP_BLOCK_SIZE * regno) + offset;
536 last_to = "chip-insn";
541 case 3: /* 11: for testing - instruction memory */
542 offset = (offset % 0x800);
543 *phys = SIM_D10V_MEMORY_INSN + offset;
544 if (offset + nr_bytes > 0x800)
545 /* don't cross VM boundary */
546 nr_bytes = 0x800 - offset;
547 last_to = "test-insn";
554 sim_d10v_translate_addr (unsigned long memaddr,
556 unsigned long *targ_addr,
558 unsigned long (*dmap_register) (void *regcache,
560 unsigned long (*imap_register) (void *regcache,
567 last_from = "unknown";
570 seg = (memaddr >> 24);
571 off = (memaddr & 0xffffffL);
573 /* However, if we've asked to use the previous generation of segment
574 mapping, rearrange the segments as follows. */
576 if (old_segment_mapping)
580 case 0x00: /* DMAP translated memory */
583 case 0x01: /* IMAP translated memory */
586 case 0x10: /* On-chip data memory */
589 case 0x11: /* On-chip insn memory */
592 case 0x12: /* Unified memory */
600 case 0x00: /* Physical unified memory */
601 last_from = "phys-unified";
603 phys = SIM_D10V_MEMORY_UNIFIED + off;
604 if ((off % SEGMENT_SIZE) + nr_bytes > SEGMENT_SIZE)
605 nr_bytes = SEGMENT_SIZE - (off % SEGMENT_SIZE);
608 case 0x01: /* Physical instruction memory */
609 last_from = "phys-insn";
610 last_to = "chip-insn";
611 phys = SIM_D10V_MEMORY_INSN + off;
612 if ((off % SEGMENT_SIZE) + nr_bytes > SEGMENT_SIZE)
613 nr_bytes = SEGMENT_SIZE - (off % SEGMENT_SIZE);
616 case 0x02: /* Physical data memory segment */
617 last_from = "phys-data";
618 last_to = "chip-data";
619 phys = SIM_D10V_MEMORY_DATA + off;
620 if ((off % SEGMENT_SIZE) + nr_bytes > SEGMENT_SIZE)
621 nr_bytes = SEGMENT_SIZE - (off % SEGMENT_SIZE);
624 case 0x10: /* in logical data address segment */
625 nr_bytes = sim_d10v_translate_dmap_addr (off, nr_bytes, &phys, regcache,
629 case 0x11: /* in logical instruction address segment */
630 nr_bytes = sim_d10v_translate_imap_addr (off, nr_bytes, &phys, regcache,
642 /* Return a pointer into the raw buffer designated by phys_addr. It
643 is assumed that the client has already ensured that the access
644 isn't going to cross a segment boundary. */
647 map_memory (unsigned phys_addr)
652 int segment = ((phys_addr >> 24) & 0xff);
657 case 0x00: /* Unified memory */
659 memory = &State.mem.unif[(phys_addr / SEGMENT_SIZE) % UMEM_SEGMENTS];
660 last_segname = "umem";
664 case 0x01: /* On-chip insn memory */
666 memory = &State.mem.insn[(phys_addr / SEGMENT_SIZE) % IMEM_SEGMENTS];
667 last_segname = "imem";
671 case 0x02: /* On-chip data memory */
673 if ((phys_addr & 0xff00) == 0xff00)
675 phys_addr = (phys_addr & 0xffff);
676 if (phys_addr == DMAP2_SHADDOW)
678 phys_addr = DMAP2_OFFSET;
679 last_segname = "dmap";
682 last_segname = "reg";
685 last_segname = "dmem";
686 memory = &State.mem.data[(phys_addr / SEGMENT_SIZE) % DMEM_SEGMENTS];
692 last_segname = "scrap";
693 return State.mem.fault;
698 *memory = calloc (1, SEGMENT_SIZE);
701 (*d10v_callback->printf_filtered) (d10v_callback, "Malloc failed.\n");
702 return State.mem.fault;
706 offset = (phys_addr % SEGMENT_SIZE);
707 raw = *memory + offset;
711 /* Transfer data to/from simulated memory. Since a bug in either the
712 simulated program or in gdb or the simulator itself may cause a
713 bogus address to be passed in, we need to do some sanity checking
714 on addresses to make sure they are within bounds. When an address
715 fails the bounds check, treat it as a zero length read/write rather
716 than aborting the entire run. */
719 xfer_mem (SIM_ADDR virt,
720 unsigned char *buffer,
727 phys_size = sim_d10v_translate_addr (virt, size, &phys, NULL,
728 dmap_register, imap_register);
732 memory = map_memory (phys);
735 if ((d10v_debug & DEBUG_INSTRUCTION) != 0)
737 (*d10v_callback->printf_filtered)
739 "sim_%s %d bytes: 0x%08lx (%s) -> 0x%08lx (%s) -> 0x%08lx (%s)\n",
740 (write_p ? "write" : "read"),
741 phys_size, virt, last_from,
743 (long) memory, last_segname);
749 memcpy (memory, buffer, phys_size);
753 memcpy (buffer, memory, phys_size);
761 sim_write (sd, addr, buffer, size)
764 unsigned char *buffer;
767 /* FIXME: this should be performing a virtual transfer */
768 return xfer_mem( addr, buffer, size, 1);
772 sim_read (sd, addr, buffer, size)
775 unsigned char *buffer;
778 /* FIXME: this should be performing a virtual transfer */
779 return xfer_mem( addr, buffer, size, 0);
784 sim_open (kind, callback, abfd, argv)
786 host_callback *callback;
791 struct hash_entry *h;
792 static int init_p = 0;
796 d10v_callback = callback;
798 old_segment_mapping = 0;
800 /* NOTE: This argument parsing is only effective when this function
801 is called by GDB. Standalone argument parsing is handled by
803 for (p = argv + 1; *p; ++p)
805 if (strcmp (*p, "-oldseg") == 0)
806 old_segment_mapping = 1;
808 else if (strcmp (*p, "-t") == 0)
810 else if (strncmp (*p, "-t", 2) == 0)
811 d10v_debug = atoi (*p + 2);
814 (*d10v_callback->printf_filtered) (d10v_callback, "ERROR: unsupported option(s): %s\n",*p);
817 /* put all the opcodes in the hash table */
820 for (s = Simops; s->func; s++)
822 h = &hash_table[hash(s->opcode,s->format)];
824 /* go to the last entry in the chain */
830 h->next = (struct hash_entry *) calloc(1,sizeof(struct hash_entry));
832 perror ("malloc failure");
838 h->opcode = s->opcode;
839 h->size = s->is_long;
843 /* reset the processor state */
844 if (!State.mem.data[0])
846 sim_create_inferior ((SIM_DESC) 1, NULL, NULL, NULL);
848 /* Fudge our descriptor. */
854 sim_close (sd, quitting)
858 if (prog_bfd != NULL && prog_bfd_was_opened_p)
860 bfd_close (prog_bfd);
862 prog_bfd_was_opened_p = 0;
870 (*d10v_callback->printf_filtered) (d10v_callback, "sim_set_profile %d\n",n);
874 sim_set_profile_size (n)
877 (*d10v_callback->printf_filtered) (d10v_callback, "sim_set_profile_size %d\n",n);
881 dmem_addr (uint16 offset)
887 /* Note: DMEM address range is 0..0x10000. Calling code can compute
888 things like ``0xfffe + 0x0e60 == 0x10e5d''. Since offset's type
889 is uint16 this is modulo'ed onto 0x0e5d. */
891 phys_size = sim_d10v_translate_dmap_addr (offset, 1, &phys, NULL,
895 mem = State.mem.fault;
898 mem = map_memory (phys);
900 if ((d10v_debug & DEBUG_MEMORY))
902 (*d10v_callback->printf_filtered)
904 "mem: 0x%08x (%s) -> 0x%08lx %d (%s) -> 0x%08lx (%s)\n",
906 phys, phys_size, last_to,
907 (long) mem, last_segname);
914 imem_addr (uint32 offset)
918 int phys_size = sim_d10v_translate_imap_addr (offset, 1, &phys, NULL,
922 return State.mem.fault;
924 mem = map_memory (phys);
926 if ((d10v_debug & DEBUG_MEMORY))
928 (*d10v_callback->printf_filtered)
930 "mem: 0x%08x (%s) -> 0x%08lx %d (%s) -> 0x%08lx (%s)\n",
932 phys, phys_size, last_to,
933 (long) mem, last_segname);
939 static int stop_simulator = 0;
950 /* Run (or resume) the program. */
952 sim_resume (sd, step, siggnal)
959 /* (*d10v_callback->printf_filtered) (d10v_callback, "sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
974 SET_HW_PSW ((PSW & (PSW_F0_BIT | PSW_F1_BIT | PSW_C_BIT)));
975 JMP (AE_VECTOR_START);
981 SET_HW_PSW ((PSW & (PSW_F0_BIT | PSW_F1_BIT | PSW_C_BIT)));
982 JMP (RIE_VECTOR_START);
992 iaddr = imem_addr ((uint32)PC << 2);
993 if (iaddr == State.mem.fault)
995 State.exception = SIGBUS;
999 inst = get_longword( iaddr );
1001 State.pc_changed = 0;
1002 ins_type_counters[ (int)INS_CYCLES ]++;
1004 switch (inst & 0xC0000000)
1007 /* long instruction */
1008 do_long (inst & 0x3FFFFFFF);
1012 do_2_short ( inst & 0x7FFF, (inst & 0x3FFF8000) >> 15, RIGHT_FIRST);
1016 do_2_short ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF, LEFT_FIRST);
1019 do_parallel ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF);
1023 /* If the PC of the current instruction matches RPT_E then
1024 schedule a branch to the loop start. If one of those
1025 instructions happens to be a branch, than that instruction
1027 if (!State.pc_changed)
1029 if (PSW_RP && PC == RPT_E)
1031 /* Note: The behavour of a branch instruction at RPT_E
1032 is implementation dependant, this simulator takes the
1033 branch. Branching to RPT_E is valid, the instruction
1034 must be executed before the loop is taken. */
1043 SET_RPT_C (RPT_C - 1);
1051 /* Check for a breakpoint trap on this instruction. This
1052 overrides any pending branches or loops */
1053 if (PSW_DB && PC == IBA)
1057 SET_PSW (PSW & PSW_SM_BIT);
1058 SET_PC (SDBT_VECTOR_START);
1061 /* Writeback all the DATA / PC changes */
1064 #ifdef NEED_UI_LOOP_HOOK
1065 if (deprecated_ui_loop_hook != NULL && ui_loop_hook_counter-- < 0)
1067 ui_loop_hook_counter = UI_LOOP_POLL_INTERVAL;
1068 deprecated_ui_loop_hook (0);
1070 #endif /* NEED_UI_LOOP_HOOK */
1072 while ( !State.exception && !stop_simulator);
1074 if (step && !State.exception)
1075 State.exception = SIGTRAP;
1079 sim_set_trace (void)
1087 sim_info (sd, verbose)
1096 unsigned long left = ins_type_counters[ (int)INS_LEFT ] + ins_type_counters[ (int)INS_LEFT_COND_EXE ];
1097 unsigned long left_nops = ins_type_counters[ (int)INS_LEFT_NOPS ];
1098 unsigned long left_parallel = ins_type_counters[ (int)INS_LEFT_PARALLEL ];
1099 unsigned long left_cond = ins_type_counters[ (int)INS_LEFT_COND_TEST ];
1100 unsigned long left_total = left + left_parallel + left_cond + left_nops;
1102 unsigned long right = ins_type_counters[ (int)INS_RIGHT ] + ins_type_counters[ (int)INS_RIGHT_COND_EXE ];
1103 unsigned long right_nops = ins_type_counters[ (int)INS_RIGHT_NOPS ];
1104 unsigned long right_parallel = ins_type_counters[ (int)INS_RIGHT_PARALLEL ];
1105 unsigned long right_cond = ins_type_counters[ (int)INS_RIGHT_COND_TEST ];
1106 unsigned long right_total = right + right_parallel + right_cond + right_nops;
1108 unsigned long unknown = ins_type_counters[ (int)INS_UNKNOWN ];
1109 unsigned long ins_long = ins_type_counters[ (int)INS_LONG ];
1110 unsigned long parallel = ins_type_counters[ (int)INS_PARALLEL ];
1111 unsigned long leftright = ins_type_counters[ (int)INS_LEFTRIGHT ];
1112 unsigned long rightleft = ins_type_counters[ (int)INS_RIGHTLEFT ];
1113 unsigned long cond_true = ins_type_counters[ (int)INS_COND_TRUE ];
1114 unsigned long cond_false = ins_type_counters[ (int)INS_COND_FALSE ];
1115 unsigned long cond_jump = ins_type_counters[ (int)INS_COND_JUMP ];
1116 unsigned long cycles = ins_type_counters[ (int)INS_CYCLES ];
1117 unsigned long total = (unknown + left_total + right_total + ins_long);
1119 int size = strlen (add_commas (buf1, sizeof (buf1), total));
1120 int parallel_size = strlen (add_commas (buf1, sizeof (buf1),
1121 (left_parallel > right_parallel) ? left_parallel : right_parallel));
1122 int cond_size = strlen (add_commas (buf1, sizeof (buf1), (left_cond > right_cond) ? left_cond : right_cond));
1123 int nop_size = strlen (add_commas (buf1, sizeof (buf1), (left_nops > right_nops) ? left_nops : right_nops));
1124 int normal_size = strlen (add_commas (buf1, sizeof (buf1), (left > right) ? left : right));
1126 (*d10v_callback->printf_filtered) (d10v_callback,
1127 "executed %*s left instruction(s), %*s normal, %*s parallel, %*s EXExxx, %*s nops\n",
1128 size, add_commas (buf1, sizeof (buf1), left_total),
1129 normal_size, add_commas (buf2, sizeof (buf2), left),
1130 parallel_size, add_commas (buf3, sizeof (buf3), left_parallel),
1131 cond_size, add_commas (buf4, sizeof (buf4), left_cond),
1132 nop_size, add_commas (buf5, sizeof (buf5), left_nops));
1134 (*d10v_callback->printf_filtered) (d10v_callback,
1135 "executed %*s right instruction(s), %*s normal, %*s parallel, %*s EXExxx, %*s nops\n",
1136 size, add_commas (buf1, sizeof (buf1), right_total),
1137 normal_size, add_commas (buf2, sizeof (buf2), right),
1138 parallel_size, add_commas (buf3, sizeof (buf3), right_parallel),
1139 cond_size, add_commas (buf4, sizeof (buf4), right_cond),
1140 nop_size, add_commas (buf5, sizeof (buf5), right_nops));
1143 (*d10v_callback->printf_filtered) (d10v_callback,
1144 "executed %*s long instruction(s)\n",
1145 size, add_commas (buf1, sizeof (buf1), ins_long));
1148 (*d10v_callback->printf_filtered) (d10v_callback,
1149 "executed %*s parallel instruction(s)\n",
1150 size, add_commas (buf1, sizeof (buf1), parallel));
1153 (*d10v_callback->printf_filtered) (d10v_callback,
1154 "executed %*s instruction(s) encoded L->R\n",
1155 size, add_commas (buf1, sizeof (buf1), leftright));
1158 (*d10v_callback->printf_filtered) (d10v_callback,
1159 "executed %*s instruction(s) encoded R->L\n",
1160 size, add_commas (buf1, sizeof (buf1), rightleft));
1163 (*d10v_callback->printf_filtered) (d10v_callback,
1164 "executed %*s unknown instruction(s)\n",
1165 size, add_commas (buf1, sizeof (buf1), unknown));
1168 (*d10v_callback->printf_filtered) (d10v_callback,
1169 "executed %*s instruction(s) due to EXExxx condition being true\n",
1170 size, add_commas (buf1, sizeof (buf1), cond_true));
1173 (*d10v_callback->printf_filtered) (d10v_callback,
1174 "skipped %*s instruction(s) due to EXExxx condition being false\n",
1175 size, add_commas (buf1, sizeof (buf1), cond_false));
1178 (*d10v_callback->printf_filtered) (d10v_callback,
1179 "skipped %*s instruction(s) due to conditional branch succeeding\n",
1180 size, add_commas (buf1, sizeof (buf1), cond_jump));
1182 (*d10v_callback->printf_filtered) (d10v_callback,
1183 "executed %*s cycle(s)\n",
1184 size, add_commas (buf1, sizeof (buf1), cycles));
1186 (*d10v_callback->printf_filtered) (d10v_callback,
1187 "executed %*s total instructions\n",
1188 size, add_commas (buf1, sizeof (buf1), total));
1192 sim_create_inferior (sd, abfd, argv, env)
1198 bfd_vma start_address;
1200 /* reset all state information */
1201 memset (&State.regs, 0, (int)&State.mem - (int)&State.regs);
1203 /* There was a hack here to copy the values of argc and argv into r0
1204 and r1. The values were also saved into some high memory that
1205 won't be overwritten by the stack (0x7C00). The reason for doing
1206 this was to allow the 'run' program to accept arguments. Without
1207 the hack, this is not possible anymore. If the simulator is run
1208 from the debugger, arguments cannot be passed in, so this makes
1213 start_address = bfd_get_start_address (abfd);
1215 start_address = 0xffc0 << 2;
1218 (*d10v_callback->printf_filtered) (d10v_callback, "sim_create_inferior: PC=0x%lx\n", (long) start_address);
1220 SET_CREG (PC_CR, start_address >> 2);
1222 /* cpu resets imap0 to 0 and imap1 to 0x7f, but D10V-EVA board
1223 initializes imap0 and imap1 to 0x1000 as part of its ROM
1225 if (old_segment_mapping)
1227 /* External memory startup. This is the HARD reset state. */
1228 set_imap_register (0, 0x0000);
1229 set_imap_register (1, 0x007f);
1230 set_dmap_register (0, 0x2000);
1231 set_dmap_register (1, 0x2000);
1232 set_dmap_register (2, 0x0000); /* Old DMAP */
1233 set_dmap_register (3, 0x0000);
1237 /* Internal memory startup. This is the ROM intialized state. */
1238 set_imap_register (0, 0x1000);
1239 set_imap_register (1, 0x1000);
1240 set_dmap_register (0, 0x2000);
1241 set_dmap_register (1, 0x2000);
1242 set_dmap_register (2, 0x2000); /* DMAP2 initial internal value is
1243 0x2000 on the new board. */
1244 set_dmap_register (3, 0x0000);
1253 sim_set_callbacks (p)
1260 sim_stop_reason (sd, reason, sigrc)
1262 enum sim_stop *reason;
1265 /* (*d10v_callback->printf_filtered) (d10v_callback, "sim_stop_reason: PC=0x%x\n",PC<<2); */
1267 switch (State.exception)
1269 case SIG_D10V_STOP: /* stop instruction */
1270 *reason = sim_exited;
1274 case SIG_D10V_EXIT: /* exit trap */
1275 *reason = sim_exited;
1280 *reason = sim_stopped;
1281 *reson = TARGET_SIGNAL_BUS;
1284 default: /* some signal */
1285 *reason = sim_stopped;
1286 if (stop_simulator && !State.exception)
1287 *sigrc = TARGET_SIGNAL_INT;
1289 *sigrc = State.exception;
1297 sim_fetch_register (sd, rn, memory, length)
1300 unsigned char *memory;
1304 switch ((enum sim_d10v_regs) rn)
1306 case SIM_D10V_R0_REGNUM:
1307 case SIM_D10V_R1_REGNUM:
1308 case SIM_D10V_R2_REGNUM:
1309 case SIM_D10V_R3_REGNUM:
1310 case SIM_D10V_R4_REGNUM:
1311 case SIM_D10V_R5_REGNUM:
1312 case SIM_D10V_R6_REGNUM:
1313 case SIM_D10V_R7_REGNUM:
1314 case SIM_D10V_R8_REGNUM:
1315 case SIM_D10V_R9_REGNUM:
1316 case SIM_D10V_R10_REGNUM:
1317 case SIM_D10V_R11_REGNUM:
1318 case SIM_D10V_R12_REGNUM:
1319 case SIM_D10V_R13_REGNUM:
1320 case SIM_D10V_R14_REGNUM:
1321 case SIM_D10V_R15_REGNUM:
1322 WRITE_16 (memory, GPR (rn - SIM_D10V_R0_REGNUM));
1325 case SIM_D10V_CR0_REGNUM:
1326 case SIM_D10V_CR1_REGNUM:
1327 case SIM_D10V_CR2_REGNUM:
1328 case SIM_D10V_CR3_REGNUM:
1329 case SIM_D10V_CR4_REGNUM:
1330 case SIM_D10V_CR5_REGNUM:
1331 case SIM_D10V_CR6_REGNUM:
1332 case SIM_D10V_CR7_REGNUM:
1333 case SIM_D10V_CR8_REGNUM:
1334 case SIM_D10V_CR9_REGNUM:
1335 case SIM_D10V_CR10_REGNUM:
1336 case SIM_D10V_CR11_REGNUM:
1337 case SIM_D10V_CR12_REGNUM:
1338 case SIM_D10V_CR13_REGNUM:
1339 case SIM_D10V_CR14_REGNUM:
1340 case SIM_D10V_CR15_REGNUM:
1341 WRITE_16 (memory, CREG (rn - SIM_D10V_CR0_REGNUM));
1344 case SIM_D10V_A0_REGNUM:
1345 case SIM_D10V_A1_REGNUM:
1346 WRITE_64 (memory, ACC (rn - SIM_D10V_A0_REGNUM));
1349 case SIM_D10V_SPI_REGNUM:
1350 /* PSW_SM indicates that the current SP is the USER
1352 WRITE_16 (memory, spi_register ());
1355 case SIM_D10V_SPU_REGNUM:
1356 /* PSW_SM indicates that the current SP is the USER
1358 WRITE_16 (memory, spu_register ());
1361 case SIM_D10V_IMAP0_REGNUM:
1362 case SIM_D10V_IMAP1_REGNUM:
1363 WRITE_16 (memory, imap_register (NULL, rn - SIM_D10V_IMAP0_REGNUM));
1366 case SIM_D10V_DMAP0_REGNUM:
1367 case SIM_D10V_DMAP1_REGNUM:
1368 case SIM_D10V_DMAP2_REGNUM:
1369 case SIM_D10V_DMAP3_REGNUM:
1370 WRITE_16 (memory, dmap_register (NULL, rn - SIM_D10V_DMAP0_REGNUM));
1373 case SIM_D10V_TS2_DMAP_REGNUM:
1384 sim_store_register (sd, rn, memory, length)
1387 unsigned char *memory;
1391 switch ((enum sim_d10v_regs) rn)
1393 case SIM_D10V_R0_REGNUM:
1394 case SIM_D10V_R1_REGNUM:
1395 case SIM_D10V_R2_REGNUM:
1396 case SIM_D10V_R3_REGNUM:
1397 case SIM_D10V_R4_REGNUM:
1398 case SIM_D10V_R5_REGNUM:
1399 case SIM_D10V_R6_REGNUM:
1400 case SIM_D10V_R7_REGNUM:
1401 case SIM_D10V_R8_REGNUM:
1402 case SIM_D10V_R9_REGNUM:
1403 case SIM_D10V_R10_REGNUM:
1404 case SIM_D10V_R11_REGNUM:
1405 case SIM_D10V_R12_REGNUM:
1406 case SIM_D10V_R13_REGNUM:
1407 case SIM_D10V_R14_REGNUM:
1408 case SIM_D10V_R15_REGNUM:
1409 SET_GPR (rn - SIM_D10V_R0_REGNUM, READ_16 (memory));
1412 case SIM_D10V_CR0_REGNUM:
1413 case SIM_D10V_CR1_REGNUM:
1414 case SIM_D10V_CR2_REGNUM:
1415 case SIM_D10V_CR3_REGNUM:
1416 case SIM_D10V_CR4_REGNUM:
1417 case SIM_D10V_CR5_REGNUM:
1418 case SIM_D10V_CR6_REGNUM:
1419 case SIM_D10V_CR7_REGNUM:
1420 case SIM_D10V_CR8_REGNUM:
1421 case SIM_D10V_CR9_REGNUM:
1422 case SIM_D10V_CR10_REGNUM:
1423 case SIM_D10V_CR11_REGNUM:
1424 case SIM_D10V_CR12_REGNUM:
1425 case SIM_D10V_CR13_REGNUM:
1426 case SIM_D10V_CR14_REGNUM:
1427 case SIM_D10V_CR15_REGNUM:
1428 SET_CREG (rn - SIM_D10V_CR0_REGNUM, READ_16 (memory));
1431 case SIM_D10V_A0_REGNUM:
1432 case SIM_D10V_A1_REGNUM:
1433 SET_ACC (rn - SIM_D10V_A0_REGNUM, READ_64 (memory) & MASK40);
1436 case SIM_D10V_SPI_REGNUM:
1437 /* PSW_SM indicates that the current SP is the USER
1439 set_spi_register (READ_16 (memory));
1442 case SIM_D10V_SPU_REGNUM:
1443 set_spu_register (READ_16 (memory));
1446 case SIM_D10V_IMAP0_REGNUM:
1447 case SIM_D10V_IMAP1_REGNUM:
1448 set_imap_register (rn - SIM_D10V_IMAP0_REGNUM, READ_16(memory));
1451 case SIM_D10V_DMAP0_REGNUM:
1452 case SIM_D10V_DMAP1_REGNUM:
1453 case SIM_D10V_DMAP2_REGNUM:
1454 case SIM_D10V_DMAP3_REGNUM:
1455 set_dmap_register (rn - SIM_D10V_DMAP0_REGNUM, READ_16(memory));
1458 case SIM_D10V_TS2_DMAP_REGNUM:
1471 sim_do_command (sd, cmd)
1475 (*d10v_callback->printf_filtered) (d10v_callback, "sim_do_command: %s\n",cmd);
1479 sim_load (sd, prog, abfd, from_tty)
1485 extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
1487 if (prog_bfd != NULL && prog_bfd_was_opened_p)
1489 bfd_close (prog_bfd);
1490 prog_bfd_was_opened_p = 0;
1492 prog_bfd = sim_load_file (sd, myname, d10v_callback, prog, abfd,
1493 sim_kind == SIM_OPEN_DEBUG,
1494 1/*LMA*/, sim_write);
1495 if (prog_bfd == NULL)
1497 prog_bfd_was_opened_p = abfd == NULL;