+// See LICENSE for license details.
+
#include "sim.h"
#include "htif.h"
#include <sys/mman.h>
#include <iostream>
#include <climits>
#include <assert.h>
+#include <unistd.h>
#ifdef __linux__
# define mmap mmap64
#endif
-sim_t::sim_t(int _nprocs, htif_t* _htif)
- : htif(_htif),
- procs(_nprocs),
- running(false)
+sim_t::sim_t(int _nprocs, int mem_mb, const std::vector<std::string>& args)
+ : htif(new htif_isasim_t(this, args)),
+ procs(_nprocs)
{
// allocate target machine's memory, shrinking it as necessary
// until the allocation succeeds
+ size_t memsz0 = (size_t)mem_mb << 20;
+ if (memsz0 == 0)
+ memsz0 = 1L << (sizeof(size_t) == 8 ? 32 : 30);
- size_t memsz0 = sizeof(size_t) == 8 ? 0x100000000ULL : 0x70000000UL;
size_t quantum = std::max(PGSIZE, (reg_t)sysconf(_SC_PAGESIZE));
memsz0 = memsz0/quantum*quantum;
for(size_t i = 0; i < num_cores(); i++)
procs[i] = new processor_t(this, new mmu_t(mem, memsz), i);
-
- htif->init(this);
}
sim_t::~sim_t()
munmap(mem, memsz);
}
-void sim_t::set_tohost(reg_t val)
-{
- fromhost = 0;
- tohost = val;
-}
-
-reg_t sim_t::get_fromhost()
-{
- htif->wait_for_fromhost_write();
- return fromhost;
-}
-
void sim_t::send_ipi(reg_t who)
{
if(who < num_cores())
procs[who]->deliver_ipi();
}
-void sim_t::run(bool debug)
+reg_t sim_t::get_scr(int which)
{
- htif->wait_for_start();
-
- // start core 0
- send_ipi(0);
+ switch (which)
+ {
+ case 0: return num_cores();
+ case 1: return memsz >> 20;
+ default: return -1;
+ }
+}
- for(running = true; running; )
+void sim_t::run(bool debug)
+{
+ while (!htif->done())
{
if(!debug)
- step_all(100,100,false);
+ step_all(10000, 1000, false);
else
interactive();
}
void sim_t::step_all(size_t n, size_t interleave, bool noisy)
{
+ htif->tick();
for(size_t j = 0; j < n; j+=interleave)
+ {
for(int i = 0; i < (int)num_cores(); i++)
procs[i]->step(interleave,noisy);
+ }
}