///////////////////////// 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};
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()
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;
}
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;
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);
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];
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)
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)
{
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
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");
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);
}
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) {
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) {