13 sim_t::sim_t(int _nprocs
, htif_t
* _htif
)
20 // allocate target machine's memory, shrinking it as necessary
21 // until the allocation succeeds
23 size_t memsz0
= sizeof(size_t) == 8 ? 0x100000000ULL
: 0x70000000UL
;
24 size_t quantum
= std::max(PGSIZE
, (reg_t
)sysconf(_SC_PAGESIZE
));
25 memsz0
= memsz0
/quantum
*quantum
;
28 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
32 while(mem
== MAP_FAILED
&& (memsz
= memsz
*10/11/quantum
*quantum
))
33 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
34 assert(mem
!= MAP_FAILED
);
35 fprintf(stderr
, "warning: only got %lu bytes of target mem (wanted %lu)\n",
36 (unsigned long)memsz
, (unsigned long)memsz0
);
39 mmu
= new mmu_t(mem
, memsz
);
41 for(size_t i
= 0; i
< num_cores(); i
++)
42 procs
[i
] = new processor_t(this, new mmu_t(mem
, memsz
), i
);
49 for(size_t i
= 0; i
< num_cores(); i
++)
51 mmu_t
* pmmu
= &procs
[i
]->mmu
;
59 void sim_t::set_tohost(reg_t val
)
63 htif
->wait_for_tohost_write();
66 reg_t
sim_t::get_tohost()
71 reg_t
sim_t::get_fromhost()
73 htif
->wait_for_fromhost_write();
77 void sim_t::send_ipi(reg_t who
)
80 procs
[who
]->deliver_ipi();
83 void sim_t::run(bool debug
)
85 htif
->wait_for_start();
87 // word 0 of memory contains the memory capacity in MB
88 mmu
->store_uint32(0, memsz
>> 20);
89 // word 1 of memory contains the core count
90 mmu
->store_uint32(4, num_cores());
95 for(running
= true; running
; )
97 for (int i
= 0; i
< 1000; i
++)
100 step_all(100,100,false);
109 void sim_t::step_all(size_t n
, size_t interleave
, bool noisy
)
111 for(size_t j
= 0; j
< n
; j
+=interleave
)
112 for(int i
= 0; i
< (int)num_cores(); i
++)
113 procs
[i
]->step(interleave
,noisy
);