1
0
Fork 0

Add "-memsize" flag to emulator

- Allow user to set memory size (in MiB) used by emulator.
   - if memory is exhausted, warn user about memory shortage.

Close #3
This commit is contained in:
Iori YONEJI 2015-02-14 01:56:54 +09:00 committed by Christopher Celio
parent b55765f597
commit 0ac6172525
1 changed files with 13 additions and 1 deletions

View File

@ -27,12 +27,15 @@ int main(int argc, char** argv)
FILE *vcdfile = NULL;
bool dramsim2 = false;
bool log = false;
uint64_t memsz_mb = MEM_SIZE / (1024*1024);
for (int i = 1; i < argc; i++)
{
std::string arg = argv[i];
if (arg.substr(0, 2) == "-v")
vcd = argv[i]+2;
else if (arg.substr(0, 9) == "+memsize=")
memsz_mb = atoll(argv[i]+9);
else if (arg.substr(0, 2) == "-s")
random_seed = atoi(argv[i]+2);
else if (arg == "+dramsim")
@ -65,7 +68,16 @@ int main(int argc, char** argv)
// Instantiate and initialize main memory
mm_t* mm = dramsim2 ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
mm->init(MEM_SIZE, tile.Top__io_mem_resp_bits_data.width()/8, LINE_SIZE);
try {
mm->init(memsz_mb*1024*1024, tile.Top__io_mem_resp_bits_data.width()/8, LINE_SIZE);
}
catch (const std::bad_alloc& e) {
fprintf(stderr,
"Failed to allocate %ld bytes (%ld MiB) of memory\n"
"Set smaller amount of memory using +memsize=<N> (in MiB)\n" , memsz_mb*1024*1024, memsz_mb
);
exit(-1);
}
if (loadmem)
load_mem(mm->get_data(), loadmem);