diff options
-rw-r--r-- | riscv/debug_module.cc | 20 | ||||
-rw-r--r-- | riscv/debug_module.h | 18 | ||||
-rw-r--r-- | riscv/execute.cc | 4 | ||||
-rw-r--r-- | riscv/sim.cc | 6 | ||||
-rw-r--r-- | riscv/sim.h | 3 | ||||
-rw-r--r-- | spike_main/spike.cc | 10 |
6 files changed, 42 insertions, 19 deletions
diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index 985cbbd..cbc8c48 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -16,7 +16,12 @@ ///////////////////////// debug_module_t -debug_module_t::debug_module_t(sim_t *sim) : sim(sim) +debug_module_t::debug_module_t(sim_t *sim, unsigned progsize) : + progsize(progsize), + program_buffer_bytes(4 + 4*progsize), + debug_progbuf_start(debug_data_start - program_buffer_bytes), + debug_abstract_start(debug_progbuf_start - debug_abstract_size*4), + sim(sim) { dmcontrol = {0}; @@ -29,17 +34,24 @@ debug_module_t::debug_module_t(sim_t *sim) : sim(sim) abstractauto = {0}; + program_buffer = new uint8_t[program_buffer_bytes]; + memset(halted, 0, sizeof(halted)); memset(debug_rom_flags, 0, sizeof(debug_rom_flags)); memset(resumeack, 0, sizeof(resumeack)); - memset(program_buffer, 0, sizeof(program_buffer)); + memset(program_buffer, 0, program_buffer_bytes); + program_buffer[progsize] = ebreak(); memset(dmdata, 0, sizeof(dmdata)); write32(debug_rom_whereto, 0, jal(ZERO, debug_abstract_start - DEBUG_ROM_WHERETO)); memset(debug_abstract, 0, sizeof(debug_abstract)); +} +debug_module_t::~debug_module_t() +{ + delete[] program_buffer; } void debug_module_t::reset() @@ -97,7 +109,7 @@ bool debug_module_t::load(reg_t addr, size_t len, uint8_t* bytes) return true; } - if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + sizeof(program_buffer)))) { + if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + program_buffer_bytes))) { memcpy(bytes, program_buffer + addr - debug_progbuf_start, len); return true; } @@ -138,7 +150,7 @@ bool debug_module_t::store(reg_t addr, size_t len, const uint8_t* bytes) return true; } - if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + sizeof(program_buffer)))) { + if (addr >= debug_progbuf_start && ((addr + len) <= (debug_progbuf_start + program_buffer_bytes))) { memcpy(program_buffer + addr - debug_progbuf_start, bytes, len); return true; diff --git a/riscv/debug_module.h b/riscv/debug_module.h index f0d2a47..8b209fb 100644 --- a/riscv/debug_module.h +++ b/riscv/debug_module.h @@ -59,7 +59,8 @@ typedef struct { class debug_module_t : public abstract_device_t { public: - debug_module_t(sim_t *sim); + debug_module_t(sim_t *sim, unsigned progsize); + ~debug_module_t(); void add_device(bus_t *bus); @@ -74,18 +75,23 @@ class debug_module_t : public abstract_device_t private: static const unsigned datasize = 2; - static const unsigned progsize = 16; + // Size of program_buffer in 32-bit words, as exposed to the rest of the + // world. + unsigned progsize; + // Actual size of the program buffer, which is 1 word bigger than we let on + // to implement the implicit ebreak at the end. + unsigned program_buffer_bytes; static const unsigned debug_data_start = 0x380; - static const unsigned debug_progbuf_start = debug_data_start - progsize*4; + unsigned debug_progbuf_start; static const unsigned debug_abstract_size = 2; - static const unsigned debug_abstract_start = debug_progbuf_start - debug_abstract_size*4; - + unsigned debug_abstract_start; + sim_t *sim; uint8_t debug_rom_whereto[4]; uint8_t debug_abstract[debug_abstract_size * 4]; - uint8_t program_buffer[progsize * 4]; + uint8_t *program_buffer; uint8_t dmdata[datasize * 4]; bool halted[1024]; diff --git a/riscv/execute.cc b/riscv/execute.cc index 25e9520..878893c 100644 --- a/riscv/execute.cc +++ b/riscv/execute.cc @@ -147,14 +147,12 @@ void processor_t::step(size_t n) break; } - if (unlikely(state.pc >= DEBUG_START && + if (unlikely(state.pc >= DEBUG_ROM_ENTRY && state.pc < DEBUG_END)) { // We're waiting for the debugger to tell us something. return; } - - } } else while (instret < n) diff --git a/riscv/sim.cc b/riscv/sim.cc index 793a2c8..81d1307 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -25,8 +25,10 @@ static void handle_signal(int sig) sim_t::sim_t(const char* isa, size_t nprocs, bool halted, reg_t start_pc, std::vector<std::pair<reg_t, mem_t*>> mems, - const std::vector<std::string>& args, std::vector<int> const hartids) - : htif_t(args), debug_module(this), mems(mems), procs(std::max(nprocs, size_t(1))), + const std::vector<std::string>& args, + std::vector<int> const hartids, unsigned progsize) + : htif_t(args), debug_module(this, progsize), mems(mems), + procs(std::max(nprocs, size_t(1))), start_pc(start_pc), current_step(0), current_proc(0), debug(false), remote_bitbang(NULL) { diff --git a/riscv/sim.h b/riscv/sim.h index b102a6b..ce5fe19 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -21,7 +21,8 @@ class sim_t : public htif_t public: sim_t(const char* isa, size_t _nprocs, bool halted, reg_t start_pc, std::vector<std::pair<reg_t, mem_t*>> mems, - const std::vector<std::string>& args, const std::vector<int> hartids); + const std::vector<std::string>& args, const std::vector<int> hartids, + unsigned progsize); ~sim_t(); // run the simulation to completion diff --git a/spike_main/spike.cc b/spike_main/spike.cc index 863ee81..1205965 100644 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@ -25,7 +25,7 @@ static void help() fprintf(stderr, " -g Track histogram of PCs\n"); fprintf(stderr, " -l Generate a log of execution\n"); fprintf(stderr, " -h Print this help message\n"); - fprintf(stderr, " -H Start halted, allowing a debugger to connect\n"); + fprintf(stderr, " -H Start halted, allowing a debugger to connect\n"); fprintf(stderr, " --isa=<name> RISC-V ISA string [default %s]\n", DEFAULT_ISA); fprintf(stderr, " --pc=<address> Override ELF entry point\n"); fprintf(stderr, " --hartids=<a,b,...> Explicitly specify hartids, default is 0,1,...\n"); @@ -35,7 +35,8 @@ static void help() fprintf(stderr, " --extension=<name> Specify RoCC Extension\n"); fprintf(stderr, " --extlib=<name> Shared library to load\n"); fprintf(stderr, " --rbb-port=<port> Listen on <port> for remote bitbang connection\n"); - fprintf(stderr, " --dump-dts Print device tree string and exit\n"); + fprintf(stderr, " --dump-dts Print device tree string and exit\n"); + fprintf(stderr, " --progsize=<words> progsize for the debug module [default 2]\n"); exit(1); } @@ -85,6 +86,7 @@ int main(int argc, char** argv) const char* isa = DEFAULT_ISA; uint16_t rbb_port = 0; bool use_rbb = false; + unsigned progsize = 2; std::vector<int> hartids; auto const hartids_parser = [&](const char *s) { @@ -125,13 +127,15 @@ int main(int argc, char** argv) exit(-1); } }); + parser.option(0, "progsize", 1, [&](const char* s){progsize = atoi(s);}); auto argv1 = parser.parse(argv); std::vector<std::string> htif_args(argv1, (const char*const*)argv + argc); if (mems.empty()) mems = make_mems("2048"); - sim_t s(isa, nprocs, halted, start_pc, mems, htif_args, std::move(hartids)); + sim_t s(isa, nprocs, halted, start_pc, mems, htif_args, std::move(hartids), + progsize); std::unique_ptr<remote_bitbang_t> remote_bitbang((remote_bitbang_t *) NULL); std::unique_ptr<jtag_dtm_t> jtag_dtm(new jtag_dtm_t(&s.debug_module)); if (use_rbb) { |