From 8d457d5148d57361f31e41ceb2e46e6a1c22d741 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Tue, 26 Apr 2016 08:29:17 -0700 Subject: [PATCH] Fix store to clear debug interrupt. --- riscv/debug_module.cc | 13 +++++++++++-- riscv/debug_module.h | 1 + riscv/gdbserver.cc | 7 +++++++ riscv/gdbserver.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index b31c4a6..75bb335 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -35,8 +35,8 @@ bool debug_module_t::store(reg_t addr, size_t len, const uint8_t* bytes) memcpy(raw_page + addr - DEBUG_START, bytes, len); return true; } else if (len == 4 && addr == DEBUG_CLEARDEBINT) { - clear_interrupt(bytes[4] | (bytes[5] << 8) | - (bytes[6] << 16) | (bytes[7] << 24)); + clear_interrupt(bytes[0] | (bytes[1] << 8) | + (bytes[2] << 16) | (bytes[3] << 24)); return true; } @@ -54,6 +54,15 @@ void debug_module_t::ram_write32(unsigned int index, uint32_t value) base[3] = (value >> 24) & 0xff; } +uint32_t debug_module_t::ram_read32(unsigned int index) +{ + char* base = raw_page + DEBUG_RAM_START - DEBUG_START + index * 4; + return base[0] | + (base[1] << 8) | + (base[2] << 16) | + (base[3] << 24); +} + char* debug_module_t::page(reg_t paddr) { fprintf(stderr, "dm::page(0x%lx)\n", paddr); diff --git a/riscv/debug_module.h b/riscv/debug_module.h index 10554a8..040ad1b 100644 --- a/riscv/debug_module.h +++ b/riscv/debug_module.h @@ -16,6 +16,7 @@ class debug_module_t : public abstract_device_t char* page(reg_t paddr); void ram_write32(unsigned int index, uint32_t value); + uint32_t ram_read32(unsigned int index); void set_interrupt(uint32_t hartid) { interrupt.insert(hartid); diff --git a/riscv/gdbserver.cc b/riscv/gdbserver.cc index 6840cb7..738556c 100644 --- a/riscv/gdbserver.cc +++ b/riscv/gdbserver.cc @@ -167,6 +167,11 @@ void gdbserver_t::write_debug_ram(unsigned int index, uint32_t value) sim->debug_module.ram_write32(index, value); } +uint32_t gdbserver_t::read_debug_ram(unsigned int index) +{ + return sim->debug_module.ram_read32(index); +} + void gdbserver_t::halt() { processor_t *p = sim->get_core(0); @@ -763,6 +768,8 @@ void gdbserver_t::handle() if (state == STATE_HALTING && sim->debug_module.get_interrupt(p->id) == 0) { // gdb requested a halt and now it's done. send_packet("T05"); + fprintf(stderr, "DPC: 0x%x\n", read_debug_ram(0)); + fprintf(stderr, "DCSR: 0x%x\n", read_debug_ram(2)); state = STATE_HALTED; } diff --git a/riscv/gdbserver.h b/riscv/gdbserver.h index 7ac8823..5a7a102 100644 --- a/riscv/gdbserver.h +++ b/riscv/gdbserver.h @@ -126,6 +126,7 @@ private: // Write value to the index'th word in Debug RAM. void write_debug_ram(unsigned int index, uint32_t value); + uint32_t read_debug_ram(unsigned int index); }; #endif -- 2.30.2