13 sim_t::sim_t(int _nprocs
, htif_t
* _htif
)
18 // allocate target machine's memory, shrinking it as necessary
19 // until the allocation succeeds
21 size_t memsz0
= sizeof(size_t) == 8 ? 0x100000000ULL
: 0x70000000UL
;
22 size_t quantum
= std::max(PGSIZE
, (reg_t
)sysconf(_SC_PAGESIZE
));
23 memsz0
= memsz0
/quantum
*quantum
;
26 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
30 while(mem
== MAP_FAILED
&& (memsz
= memsz
*10/11/quantum
*quantum
))
31 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
32 assert(mem
!= MAP_FAILED
);
33 fprintf(stderr
, "warning: only got %lu bytes of target mem (wanted %lu)\n",
34 (unsigned long)memsz
, (unsigned long)memsz0
);
37 mmu
= new mmu_t(mem
, memsz
);
39 for(size_t i
= 0; i
< num_cores(); i
++)
40 procs
[i
] = new processor_t(this, new mmu_t(mem
, memsz
), i
);
47 for(size_t i
= 0; i
< num_cores(); i
++)
49 mmu_t
* pmmu
= &procs
[i
]->mmu
;
57 void sim_t::set_tohost(reg_t val
)
61 htif
->wait_for_tohost_write();
64 reg_t
sim_t::get_fromhost()
66 htif
->wait_for_fromhost_write();
70 void sim_t::send_ipi(reg_t who
)
73 procs
[who
]->deliver_ipi();
76 void sim_t::run(bool debug
)
78 htif
->wait_for_start();
80 // word 0 of memory contains the memory capacity in MB
81 mmu
->store_uint32(0, memsz
>> 20);
82 // word 1 of memory contains the core count
83 mmu
->store_uint32(4, num_cores());
88 for(running
= true; running
; )
91 step_all(100,100,false);
97 void sim_t::step_all(size_t n
, size_t interleave
, bool noisy
)
99 for(size_t j
= 0; j
< n
; j
+=interleave
)
100 for(int i
= 0; i
< (int)num_cores(); i
++)
101 procs
[i
]->step(interleave
,noisy
);