📄 interp.c
字号:
switch (inst & 0xC0000000) { case 0xC0000000: /* long instruction */ do_long (inst & 0x3FFFFFFF); break; case 0x80000000: /* R -> L */ do_2_short ( inst & 0x7FFF, (inst & 0x3FFF8000) >> 15, RIGHT_FIRST); break; case 0x40000000: /* L -> R */ do_2_short ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF, LEFT_FIRST); break; case 0: do_parallel ((inst & 0x3FFF8000) >> 15, inst & 0x7FFF); break; } /* If the PC of the current instruction matches RPT_E then schedule a branch to the loop start. If one of those instructions happens to be a branch, than that instruction will be ignored */ if (!State.pc_changed) { if (PSW_RP && PC == RPT_E) { /* Note: The behavour of a branch instruction at RPT_E is implementation dependant, this simulator takes the branch. Branching to RPT_E is valid, the instruction must be executed before the loop is taken. */ if (RPT_C == 1) { SET_PSW_RP (0); SET_RPT_C (0); SET_PC (PC + 1); } else { SET_RPT_C (RPT_C - 1); SET_PC (RPT_S); } } else SET_PC (PC + 1); } /* Check for a breakpoint trap on this instruction. This overrides any pending branches or loops */ if (PSW_DB && PC == IBA) { SET_BPC (PC); SET_BPSW (PSW); SET_PSW (PSW & PSW_SM_BIT); SET_PC (SDBT_VECTOR_START); } /* Writeback all the DATA / PC changes */ SLOT_FLUSH ();#ifdef NEED_UI_LOOP_HOOK if (deprecated_ui_loop_hook != NULL && ui_loop_hook_counter-- < 0) { ui_loop_hook_counter = UI_LOOP_POLL_INTERVAL; deprecated_ui_loop_hook (0); }#endif /* NEED_UI_LOOP_HOOK */ } while ( !State.exception && !stop_simulator); if (step && !State.exception) State.exception = SIGTRAP;}voidsim_set_trace (void){#ifdef DEBUG d10v_debug = DEBUG;#endif}voidsim_info (sd, verbose) SIM_DESC sd; int verbose;{ char buf1[40]; char buf2[40]; char buf3[40]; char buf4[40]; char buf5[40]; unsigned long left = ins_type_counters[ (int)INS_LEFT ] + ins_type_counters[ (int)INS_LEFT_COND_EXE ]; unsigned long left_nops = ins_type_counters[ (int)INS_LEFT_NOPS ]; unsigned long left_parallel = ins_type_counters[ (int)INS_LEFT_PARALLEL ]; unsigned long left_cond = ins_type_counters[ (int)INS_LEFT_COND_TEST ]; unsigned long left_total = left + left_parallel + left_cond + left_nops; unsigned long right = ins_type_counters[ (int)INS_RIGHT ] + ins_type_counters[ (int)INS_RIGHT_COND_EXE ]; unsigned long right_nops = ins_type_counters[ (int)INS_RIGHT_NOPS ]; unsigned long right_parallel = ins_type_counters[ (int)INS_RIGHT_PARALLEL ]; unsigned long right_cond = ins_type_counters[ (int)INS_RIGHT_COND_TEST ]; unsigned long right_total = right + right_parallel + right_cond + right_nops; unsigned long unknown = ins_type_counters[ (int)INS_UNKNOWN ]; unsigned long ins_long = ins_type_counters[ (int)INS_LONG ]; unsigned long parallel = ins_type_counters[ (int)INS_PARALLEL ]; unsigned long leftright = ins_type_counters[ (int)INS_LEFTRIGHT ]; unsigned long rightleft = ins_type_counters[ (int)INS_RIGHTLEFT ]; unsigned long cond_true = ins_type_counters[ (int)INS_COND_TRUE ]; unsigned long cond_false = ins_type_counters[ (int)INS_COND_FALSE ]; unsigned long cond_jump = ins_type_counters[ (int)INS_COND_JUMP ]; unsigned long cycles = ins_type_counters[ (int)INS_CYCLES ]; unsigned long total = (unknown + left_total + right_total + ins_long); int size = strlen (add_commas (buf1, sizeof (buf1), total)); int parallel_size = strlen (add_commas (buf1, sizeof (buf1), (left_parallel > right_parallel) ? left_parallel : right_parallel)); int cond_size = strlen (add_commas (buf1, sizeof (buf1), (left_cond > right_cond) ? left_cond : right_cond)); int nop_size = strlen (add_commas (buf1, sizeof (buf1), (left_nops > right_nops) ? left_nops : right_nops)); int normal_size = strlen (add_commas (buf1, sizeof (buf1), (left > right) ? left : right)); (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s left instruction(s), %*s normal, %*s parallel, %*s EXExxx, %*s nops\n", size, add_commas (buf1, sizeof (buf1), left_total), normal_size, add_commas (buf2, sizeof (buf2), left), parallel_size, add_commas (buf3, sizeof (buf3), left_parallel), cond_size, add_commas (buf4, sizeof (buf4), left_cond), nop_size, add_commas (buf5, sizeof (buf5), left_nops)); (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s right instruction(s), %*s normal, %*s parallel, %*s EXExxx, %*s nops\n", size, add_commas (buf1, sizeof (buf1), right_total), normal_size, add_commas (buf2, sizeof (buf2), right), parallel_size, add_commas (buf3, sizeof (buf3), right_parallel), cond_size, add_commas (buf4, sizeof (buf4), right_cond), nop_size, add_commas (buf5, sizeof (buf5), right_nops)); if (ins_long) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s long instruction(s)\n", size, add_commas (buf1, sizeof (buf1), ins_long)); if (parallel) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s parallel instruction(s)\n", size, add_commas (buf1, sizeof (buf1), parallel)); if (leftright) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s instruction(s) encoded L->R\n", size, add_commas (buf1, sizeof (buf1), leftright)); if (rightleft) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s instruction(s) encoded R->L\n", size, add_commas (buf1, sizeof (buf1), rightleft)); if (unknown) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s unknown instruction(s)\n", size, add_commas (buf1, sizeof (buf1), unknown)); if (cond_true) (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s instruction(s) due to EXExxx condition being true\n", size, add_commas (buf1, sizeof (buf1), cond_true)); if (cond_false) (*d10v_callback->printf_filtered) (d10v_callback, "skipped %*s instruction(s) due to EXExxx condition being false\n", size, add_commas (buf1, sizeof (buf1), cond_false)); if (cond_jump) (*d10v_callback->printf_filtered) (d10v_callback, "skipped %*s instruction(s) due to conditional branch succeeding\n", size, add_commas (buf1, sizeof (buf1), cond_jump)); (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s cycle(s)\n", size, add_commas (buf1, sizeof (buf1), cycles)); (*d10v_callback->printf_filtered) (d10v_callback, "executed %*s total instructions\n", size, add_commas (buf1, sizeof (buf1), total));}SIM_RCsim_create_inferior (sd, abfd, argv, env) SIM_DESC sd; struct bfd *abfd; char **argv; char **env;{ bfd_vma start_address; /* reset all state information */ memset (&State.regs, 0, (int)&State.mem - (int)&State.regs); /* There was a hack here to copy the values of argc and argv into r0 and r1. The values were also saved into some high memory that won't be overwritten by the stack (0x7C00). The reason for doing this was to allow the 'run' program to accept arguments. Without the hack, this is not possible anymore. If the simulator is run from the debugger, arguments cannot be passed in, so this makes no difference. */ /* set PC */ if (abfd != NULL) start_address = bfd_get_start_address (abfd); else start_address = 0xffc0 << 2;#ifdef DEBUG if (d10v_debug) (*d10v_callback->printf_filtered) (d10v_callback, "sim_create_inferior: PC=0x%lx\n", (long) start_address);#endif SET_CREG (PC_CR, start_address >> 2); /* cpu resets imap0 to 0 and imap1 to 0x7f, but D10V-EVA board initializes imap0 and imap1 to 0x1000 as part of its ROM initialization. */ if (old_segment_mapping) { /* External memory startup. This is the HARD reset state. */ set_imap_register (0, 0x0000); set_imap_register (1, 0x007f); set_dmap_register (0, 0x2000); set_dmap_register (1, 0x2000); set_dmap_register (2, 0x0000); /* Old DMAP */ set_dmap_register (3, 0x0000); } else { /* Internal memory startup. This is the ROM intialized state. */ set_imap_register (0, 0x1000); set_imap_register (1, 0x1000); set_dmap_register (0, 0x2000); set_dmap_register (1, 0x2000); set_dmap_register (2, 0x2000); /* DMAP2 initial internal value is 0x2000 on the new board. */ set_dmap_register (3, 0x0000); } SLOT_FLUSH (); return SIM_RC_OK;}voidsim_set_callbacks (p) host_callback *p;{ d10v_callback = p;}voidsim_stop_reason (sd, reason, sigrc) SIM_DESC sd; enum sim_stop *reason; int *sigrc;{/* (*d10v_callback->printf_filtered) (d10v_callback, "sim_stop_reason: PC=0x%x\n",PC<<2); */ switch (State.exception) { case SIG_D10V_STOP: /* stop instruction */ *reason = sim_exited; *sigrc = 0; break; case SIG_D10V_EXIT: /* exit trap */ *reason = sim_exited; *sigrc = GPR (0); break; case SIG_D10V_BUS: *reason = sim_stopped;#ifdef SIGBUS *sigrc = SIGBUS;#else *sigrc = SIGSEGV;#endif break; default: /* some signal */ *reason = sim_stopped; if (stop_simulator && !State.exception) *sigrc = SIGINT; else *sigrc = State.exception; break; } stop_simulator = 0;}intsim_fetch_register (sd, rn, memory, length) SIM_DESC sd; int rn; unsigned char *memory; int length;{ int size; switch ((enum sim_d10v_regs) rn) { case SIM_D10V_R0_REGNUM: case SIM_D10V_R1_REGNUM: case SIM_D10V_R2_REGNUM: case SIM_D10V_R3_REGNUM: case SIM_D10V_R4_REGNUM: case SIM_D10V_R5_REGNUM: case SIM_D10V_R6_REGNUM: case SIM_D10V_R7_REGNUM: case SIM_D10V_R8_REGNUM: case SIM_D10V_R9_REGNUM: case SIM_D10V_R10_REGNUM: case SIM_D10V_R11_REGNUM: case SIM_D10V_R12_REGNUM: case SIM_D10V_R13_REGNUM: case SIM_D10V_R14_REGNUM: case SIM_D10V_R15_REGNUM: WRITE_16 (memory, GPR (rn - SIM_D10V_R0_REGNUM)); size = 2; break; case SIM_D10V_CR0_REGNUM: case SIM_D10V_CR1_REGNUM: case SIM_D10V_CR2_REGNUM: case SIM_D10V_CR3_REGNUM: case SIM_D10V_CR4_REGNUM: case SIM_D10V_CR5_REGNUM: case SIM_D10V_CR6_REGNUM: case SIM_D10V_CR7_REGNUM: case SIM_D10V_CR8_REGNUM: case SIM_D10V_CR9_REGNUM: case SIM_D10V_CR10_REGNUM: case SIM_D10V_CR11_REGNUM: case SIM_D10V_CR12_REGNUM: case SIM_D10V_CR13_REGNUM: case SIM_D10V_CR14_REGNUM: case SIM_D10V_CR15_REGNUM: WRITE_16 (memory, CREG (rn - SIM_D10V_CR0_REGNUM)); size = 2; break; case SIM_D10V_A0_REGNUM: case SIM_D10V_A1_REGNUM: WRITE_64 (memory, ACC (rn - SIM_D10V_A0_REGNUM)); size = 8; break; case SIM_D10V_SPI_REGNUM: /* PSW_SM indicates that the current SP is the USER stack-pointer. */ WRITE_16 (memory, spi_register ()); size = 2; break; case SIM_D10V_SPU_REGNUM: /* PSW_SM indicates that the current SP is the USER stack-pointer. */ WRITE_16 (memory, spu_register ()); size = 2; break; case SIM_D10V_IMAP0_REGNUM: case SIM_D10V_IMAP1_REGNUM: WRITE_16 (memory, imap_register (NULL, rn - SIM_D10V_IMAP0_REGNUM)); size = 2; break; case SIM_D10V_DMAP0_REGNUM: case SIM_D10V_DMAP1_REGNUM: case SIM_D10V_DMAP2_REGNUM: case SIM_D10V_DMAP3_REGNUM: WRITE_16 (memory, dmap_register (NULL, rn - SIM_D10V_DMAP0_REGNUM)); size = 2; break; case SIM_D10V_TS2_DMAP_REGNUM: size = 0; break; default: size = 0; break; } return size;} intsim_store_register (sd, rn, memory, length) SIM_DESC sd; int rn; unsigned char *memory; int length;{ int size; switch ((enum sim_d10v_regs) rn) { case SIM_D10V_R0_REGNUM: case SIM_D10V_R1_REGNUM: case SIM_D10V_R2_REGNUM: case SIM_D10V_R3_REGNUM: case SIM_D10V_R4_REGNUM: case SIM_D10V_R5_REGNUM: case SIM_D10V_R6_REGNUM: case SIM_D10V_R7_REGNUM: case SIM_D10V_R8_REGNUM: case SIM_D10V_R9_REGNUM: case SIM_D10V_R10_REGNUM: case SIM_D10V_R11_REGNUM: case SIM_D10V_R12_REGNUM: case SIM_D10V_R13_REGNUM: case SIM_D10V_R14_REGNUM: case SIM_D10V_R15_REGNUM: SET_GPR (rn - SIM_D10V_R0_REGNUM, READ_16 (memory)); size = 2; break; case SIM_D10V_CR0_REGNUM: case SIM_D10V_CR1_REGNUM: case SIM_D10V_CR2_REGNUM: case SIM_D10V_CR3_REGNUM: case SIM_D10V_CR4_REGNUM: case SIM_D10V_CR5_REGNUM: case SIM_D10V_CR6_REGNUM: case SIM_D10V_CR7_REGNUM: case SIM_D10V_CR8_REGNUM: case SIM_D10V_CR9_REGNUM: case SIM_D10V_CR10_REGNUM: case SIM_D10V_CR11_REGNUM: case SIM_D10V_CR12_REGNUM: case SIM_D10V_CR13_REGNUM: case SIM_D10V_CR14_REGNUM: case SIM_D10V_CR15_REGNUM: SET_CREG (rn - SIM_D10V_CR0_REGNUM, READ_16 (memory)); size = 2; break; case SIM_D10V_A0_REGNUM: case SIM_D10V_A1_REGNUM: SET_ACC (rn - SIM_D10V_A0_REGNUM, READ_64 (memory) & MASK40); size = 8; break; case SIM_D10V_SPI_REGNUM: /* PSW_SM indicates that the current SP is the USER stack-pointer. */ set_spi_register (READ_16 (memory)); size = 2; break; case SIM_D10V_SPU_REGNUM: set_spu_register (READ_16 (memory)); size = 2; break; case SIM_D10V_IMAP0_REGNUM: case SIM_D10V_IMAP1_REGNUM: set_imap_register (rn - SIM_D10V_IMAP0_REGNUM, READ_16(memory)); size = 2; break; case SIM_D10V_DMAP0_REGNUM: case SIM_D10V_DMAP1_REGNUM: case SIM_D10V_DMAP2_REGNUM: case SIM_D10V_DMAP3_REGNUM: set_dmap_register (rn - SIM_D10V_DMAP0_REGNUM, READ_16(memory)); size = 2; break; case SIM_D10V_TS2_DMAP_REGNUM: size = 0; break; default: size = 0; break; } SLOT_FLUSH (); return size;}voidsim_do_command (sd, cmd) SIM_DESC sd; char *cmd;{ (*d10v_callback->printf_filtered) (d10v_callback, "sim_do_command: %s\n",cmd);}SIM_RCsim_load (sd, prog, abfd, from_tty) SIM_DESC sd; char *prog; bfd *abfd; int from_tty;{ extern bfd *sim_load_file (); /* ??? Don't know where this should live. */ if (prog_bfd != NULL && prog_bfd_was_opened_p) { bfd_close (prog_bfd); prog_bfd_was_opened_p = 0; } prog_bfd = sim_load_file (sd, myname, d10v_callback, prog, abfd, sim_kind == SIM_OPEN_DEBUG, 1/*LMA*/, sim_write); if (prog_bfd == NULL) return SIM_RC_FAIL; prog_bfd_was_opened_p = abfd == NULL; return SIM_RC_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -