From: Palmer Dabbelt Date: Tue, 16 May 2017 16:33:40 +0000 (-0700) Subject: Merge remote-tracking branch 'origin/debug-0.13' into priv-1.10 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a1f754b2f0ec5fe72c86d6916d7c603e7727e68e;p=riscv-isa-sim.git Merge remote-tracking branch 'origin/debug-0.13' into priv-1.10 --- a1f754b2f0ec5fe72c86d6916d7c603e7727e68e diff --cc riscv/sim.cc index edf0819,a44ced6..42d60a1 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@@ -23,19 -23,28 +23,19 @@@ static void handle_signal(int sig signal(sig, &handle_signal); } -sim_t::sim_t(const char* isa, size_t nprocs, size_t mem_mb, bool halted, +sim_t::sim_t(const char* isa, size_t nprocs, bool halted, reg_t start_pc, + std::vector> mems, const std::vector& args) - : htif_t(args), mems(mems), procs(std::max(nprocs, size_t(1))), - : htif_t(args), debug_module(this), procs(std::max(nprocs, size_t(1))), ++ : htif_t(args), debug_module(this), mems(mems), procs(std::max(nprocs, size_t(1))), + start_pc(start_pc), - current_step(0), current_proc(0), debug(false), gdbserver(NULL) + current_step(0), current_proc(0), debug(false), remote_bitbang(NULL) { signal(SIGINT, &handle_signal); - // allocate target machine's memory, shrinking it as necessary - // until the allocation succeeds - size_t memsz0 = (size_t)mem_mb << 20; - size_t quantum = 1L << 20; - if (memsz0 == 0) - memsz0 = (size_t)2048 << 20; - memsz = memsz0; - while ((mem = (char*)calloc(1, memsz)) == NULL) - memsz = (size_t)(memsz*0.9)/quantum*quantum; - - if (memsz != memsz0) - fprintf(stderr, "warning: only got %zu bytes of target mem (wanted %zu)\n", - memsz, memsz0); + for (auto& x : mems) + bus.add_device(x.first, x.second); - bus.add_device(DEBUG_START, &debug_module); + debug_module.add_device(&bus); debug_mmu = new mmu_t(this, NULL); diff --cc riscv/sim.h index 421f5c2,d3353a1..9372cc1 --- a/riscv/sim.h +++ b/riscv/sim.h @@@ -30,15 -29,20 +30,20 @@@ public void set_log(bool value); void set_histogram(bool value); void set_procs_debug(bool value); - void set_gdbserver(gdbserver_t* gdbserver) { this->gdbserver = gdbserver; } + void set_remote_bitbang(remote_bitbang_t* remote_bitbang) { + this->remote_bitbang = remote_bitbang; + } - const char* get_dts() { return dts.c_str(); } + const char* get_dts() { if (dts.empty()) reset(); return dts.c_str(); } processor_t* get_core(size_t i) { return procs.at(i); } + unsigned nprocs() const { return procs.size(); } + + debug_module_t debug_module; private: - char* mem; // main memory - size_t memsz; // memory size in bytes + std::vector> mems; mmu_t* debug_mmu; // debug port into main memory std::vector procs; + reg_t start_pc; std::string dts; std::unique_ptr boot_rom; std::unique_ptr clint; @@@ -55,10 -58,14 +59,10 @@@ bool debug; bool log; bool histogram_enabled; // provide a histogram of PCs - gdbserver_t* gdbserver; + remote_bitbang_t* remote_bitbang; // memory-mapped I/O routines - bool addr_is_mem(reg_t addr) { - return addr >= DRAM_BASE && addr < DRAM_BASE + memsz; - } - char* addr_to_mem(reg_t addr) { return mem + addr - DRAM_BASE; } - reg_t mem_to_addr(char* x) { return x - mem + DRAM_BASE; } + char* addr_to_mem(reg_t addr); bool mmio_load(reg_t addr, size_t len, uint8_t* bytes); bool mmio_store(reg_t addr, size_t len, const uint8_t* bytes); void make_dtb(); diff --cc spike_main/spike.cc index d69d4bc,38529b2..23f8e49 --- a/spike_main/spike.cc +++ b/spike_main/spike.cc @@@ -91,11 -59,10 +92,11 @@@ int main(int argc, char** argv parser.option('g', 0, 0, [&](const char* s){histogram = true;}); parser.option('l', 0, 0, [&](const char* s){log = true;}); parser.option('p', 0, 1, [&](const char* s){nprocs = atoi(s);}); - parser.option('m', 0, 1, [&](const char* s){mem_mb = atoi(s);}); + parser.option('m', 0, 1, [&](const char* s){mems = make_mems(s);}); // I wanted to use --halted, but for some reason that doesn't work. parser.option('H', 0, 0, [&](const char* s){halted = true;}); - parser.option(0, "gdb-port", 1, [&](const char* s){gdb_port = atoi(s);}); + parser.option(0, "rbb-port", 1, [&](const char* s){use_rbb = true; rbb_port = atoi(s);}); + parser.option(0, "pc", 1, [&](const char* s){start_pc = strtoull(s, 0, 0);}); parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));}); parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));}); parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));}); @@@ -112,14 -79,12 +113,15 @@@ auto argv1 = parser.parse(argv); std::vector htif_args(argv1, (const char*const*)argv + argc); - sim_t s(isa, nprocs, mem_mb, halted, htif_args); - std::unique_ptr jtag_dtm(new jtag_dtm_t(&s.debug_module)); + if (mems.empty()) + mems = make_mems("2048"); + + sim_t s(isa, nprocs, halted, start_pc, mems, htif_args); - std::unique_ptr gdbserver; - if (gdb_port) { - gdbserver = std::unique_ptr(new gdbserver_t(gdb_port, &s)); - s.set_gdbserver(&(*gdbserver)); + std::unique_ptr remote_bitbang((remote_bitbang_t *) NULL); ++ std::unique_ptr jtag_dtm(new jtag_dtm_t(&s.debug_module)); + if (use_rbb) { + remote_bitbang.reset(new remote_bitbang_t(rbb_port, &(*jtag_dtm))); + s.set_remote_bitbang(&(*remote_bitbang)); } if (dump_dts) {