8a56cd975e5433778564adccdada09188bee5b62
13 sim_t::sim_t(int _nprocs
, htif_t
* _htif
)
19 // allocate target machine's memory, shrinking it as necessary
20 // until the allocation succeeds
22 size_t memsz0
= sizeof(size_t) == 8 ? 0x100000000ULL
: 0x70000000UL
;
23 size_t quantum
= std::max(PGSIZE
, (reg_t
)sysconf(_SC_PAGESIZE
));
24 memsz0
= memsz0
/quantum
*quantum
;
27 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
31 while(mem
== MAP_FAILED
&& (memsz
= memsz
*10/11/quantum
*quantum
))
32 mem
= (char*)mmap(NULL
, memsz
, PROT_WRITE
, MAP_PRIVATE
|MAP_ANON
, -1, 0);
33 assert(mem
!= MAP_FAILED
);
34 fprintf(stderr
, "warning: only got %lu bytes of target mem (wanted %lu)\n",
35 (unsigned long)memsz
, (unsigned long)memsz0
);
38 mmu
= new mmu_t(mem
, memsz
);
40 for(size_t i
= 0; i
< num_cores(); i
++)
41 procs
[i
] = new processor_t(this, new mmu_t(mem
, memsz
), i
);
48 for(size_t i
= 0; i
< num_cores(); i
++)
50 mmu_t
* pmmu
= &procs
[i
]->mmu
;
58 void sim_t::send_ipi(reg_t who
)
61 procs
[who
]->deliver_ipi();
64 void sim_t::run(bool debug
)
66 // word 0 of memory contains the memory capacity in MB
67 mmu
->store_uint32(0, memsz
>> 20);
68 // word 1 of memory contains the core count
69 mmu
->store_uint32(4, num_cores());
71 htif
->wait_for_start();
73 for(running
= true; running
; )
76 step_all(10000, 100, false);
82 void sim_t::step_all(size_t n
, size_t interleave
, bool noisy
)
84 for(size_t j
= 0; j
< n
; j
+=interleave
)
86 if (steps
% 16384 + interleave
>= 16384)
87 htif
->wait_for_packet();
89 for(int i
= 0; i
< (int)num_cores(); i
++)
90 procs
[i
]->step(interleave
,noisy
);