X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=riscv%2Fdebug_module.cc;h=d828b72ff1a7da53df762143a53871c7f1d23695;hb=4f8b6a69484bd901f213d9a73ea29d26c8022dfd;hp=533b959b9d3cf487b70910189f60482229185acc;hpb=51a8a43d747c8e182dbcb63f602c6e27df30c276;p=riscv-isa-sim.git diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index 533b959..d828b72 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -39,7 +39,7 @@ debug_module_t::debug_module_t(sim_t *sim) : sim(sim) jal(ZERO, debug_abstract_start - DEBUG_ROM_WHERETO)); memset(debug_abstract, 0, sizeof(debug_abstract)); - + } void debug_module_t::reset() @@ -96,7 +96,7 @@ bool debug_module_t::load(reg_t addr, size_t len, uint8_t* bytes) memcpy(bytes, dmdata + addr - debug_data_start, len); return true; } - + if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + sizeof(program_buffer)))) { memcpy(bytes, program_buffer + addr - debug_progbuf_start, len); return true; @@ -119,16 +119,16 @@ bool debug_module_t::store(reg_t addr, size_t len, const uint8_t* bytes) } addr = DEBUG_START + addr; - + if (addr >= debug_data_start && (addr + len) <= (debug_data_start + sizeof(dmdata))) { memcpy(dmdata + addr - debug_data_start, bytes, len); return true; } - + if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + sizeof(program_buffer)))) { fprintf(stderr, "Successful write to program buffer %d bytes at %x\n", (int) len, (int) addr); memcpy(program_buffer + addr - debug_progbuf_start, bytes, len); - + return true; } @@ -206,18 +206,26 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) if (address >= DMI_DATA0 && address < DMI_DATA0 + abstractcs.datacount) { unsigned i = address - DMI_DATA0; result = read32(dmdata, i); + if (abstractcs.busy) { + result = -1; + fprintf(stderr, "\ndmi_read(0x%02x (data[%d]) -> -1 because abstractcs.busy==true\n", address, i); + } if (abstractcs.busy && abstractcs.cmderr == CMDERR_NONE) { abstractcs.cmderr = CMDERR_BUSY; } - if ((abstractauto.autoexecdata >> i) & 1){ + if (!abstractcs.busy && ((abstractauto.autoexecdata >> i) & 1)) { perform_abstract_command(); } } else if (address >= DMI_PROGBUF0 && address < DMI_PROGBUF0 + progsize) { unsigned i = address - DMI_PROGBUF0; result = read32(program_buffer, i); - if ((abstractauto.autoexecprogbuf >> i) & 1) { + if (abstractcs.busy) { + result = -1; + fprintf(stderr, "\ndmi_read(0x%02x (progbuf[%d]) -> -1 because abstractcs.busy==true\n", address, i); + } + if (!abstractcs.busy && ((abstractauto.autoexecprogbuf >> i) & 1)) { perform_abstract_command(); } @@ -268,7 +276,7 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) } else { dmstatus.allresumeack = false; } - + result = set_field(result, DMI_DMSTATUS_ALLNONEXISTENT, dmstatus.allnonexistant); result = set_field(result, DMI_DMSTATUS_ALLUNAVAIL, dmstatus.allunavail); result = set_field(result, DMI_DMSTATUS_ALLRUNNING, dmstatus.allrunning); @@ -373,7 +381,7 @@ bool debug_module_t::perform_abstract_command() //NOP write32(debug_abstract, 0, addi(ZERO, ZERO, 0)); } - + if (get_field(command, AC_ACCESS_REGISTER_POSTEXEC)) { // Since the next instruction is what we will use, just use nother NOP // to get there. @@ -383,7 +391,7 @@ bool debug_module_t::perform_abstract_command() } debug_rom_flags[dmcontrol.hartsel] |= 1 << DEBUG_ROM_FLAG_GO; - + abstractcs.busy = true; } else { abstractcs.cmderr = CMDERR_NOTSUP; @@ -396,27 +404,29 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) D(fprintf(stderr, "dmi_write(0x%x, 0x%x)\n", address, value)); if (address >= DMI_DATA0 && address < DMI_DATA0 + abstractcs.datacount) { unsigned i = address - DMI_DATA0; - write32(dmdata, address - DMI_DATA0, value); + if (!abstractcs.busy) + write32(dmdata, address - DMI_DATA0, value); if (abstractcs.busy && abstractcs.cmderr == CMDERR_NONE) { abstractcs.cmderr = CMDERR_BUSY; } - if ((abstractauto.autoexecdata >> i) & 1) { + if (!abstractcs.busy && ((abstractauto.autoexecdata >> i) & 1)) { perform_abstract_command(); } return true; } else if (address >= DMI_PROGBUF0 && address < DMI_PROGBUF0 + progsize) { unsigned i = address - DMI_PROGBUF0; - - write32(program_buffer, i, value); - if ((abstractauto.autoexecprogbuf >> i) & 1) { + if (!abstractcs.busy) + write32(program_buffer, i, value); + + if (!abstractcs.busy && ((abstractauto.autoexecprogbuf >> i) & 1)) { perform_abstract_command(); } return true; - + } else { switch (address) { case DMI_DMCONTROL: @@ -437,6 +447,9 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) debug_rom_flags[dmcontrol.hartsel] |= (1 << DEBUG_ROM_FLAG_RESUME); resumeack[dmcontrol.hartsel] = false; } + if (dmcontrol.ndmreset) { + proc->reset(); + } } } return true; @@ -450,9 +463,11 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) return true; case DMI_ABSTRACTAUTO: - abstractauto.autoexecprogbuf = get_field(value, DMI_ABSTRACTAUTO_AUTOEXECPROGBUF); - abstractauto.autoexecdata = get_field(value, DMI_ABSTRACTAUTO_AUTOEXECDATA); - break; + abstractauto.autoexecprogbuf = get_field(value, + DMI_ABSTRACTAUTO_AUTOEXECPROGBUF); + abstractauto.autoexecdata = get_field(value, + DMI_ABSTRACTAUTO_AUTOEXECDATA); + return true; } } return false;