9 sim_t::sim_t(int _nprocs
, htif_t
* _htif
)
14 // allocate target machine's memory, shrinking it as necessary
15 // until the allocation succeeds
17 size_t memsz0
= sizeof(size_t) == 8 ? 0x100000000ULL
: 0x70000000UL
;
18 size_t quantum
= std::max(PGSIZE
, (reg_t
)sysconf(_SC_PAGESIZE
));
19 memsz0
= memsz0
/quantum
*quantum
;
22 mem
= (char*)mmap64(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
26 while(mem
== MAP_FAILED
&& (memsz
= memsz
*10/11/quantum
*quantum
))
27 mem
= (char*)mmap64(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
28 assert(mem
!= MAP_FAILED
);
29 fprintf(stderr
, "warning: only got %lu bytes of target mem (wanted %lu)\n",
30 (unsigned long)memsz
, (unsigned long)memsz0
);
33 mmu
= new mmu_t(mem
, memsz
);
35 for(size_t i
= 0; i
< num_cores(); i
++)
36 procs
[i
] = new processor_t(this, new mmu_t(mem
, memsz
), i
);
43 for(size_t i
= 0; i
< num_cores(); i
++)
45 mmu_t
* pmmu
= &procs
[i
]->mmu
;
53 void sim_t::set_tohost(reg_t val
)
59 reg_t
sim_t::get_fromhost()
61 htif
->wait_for_fromhost_write();
65 void sim_t::send_ipi(reg_t who
)
68 procs
[who
]->deliver_ipi();
71 void sim_t::run(bool debug
)
73 htif
->wait_for_start();
78 for(running
= true; running
; )
81 step_all(100,100,false);
87 void sim_t::step_all(size_t n
, size_t interleave
, bool noisy
)
89 for(size_t j
= 0; j
< n
; j
+=interleave
)
90 for(int i
= 0; i
< (int)num_cores(); i
++)
91 procs
[i
]->step(interleave
,noisy
);