+static std::vector<std::pair<reg_t, mem_t*>> make_mems(const char* arg)
+{
+ // handle legacy mem argument
+ char* p;
+ auto mb = strtoull(arg, &p, 0);
+ if (*p == 0) {
+ reg_t size = reg_t(mb) << 20;
+ return std::vector<std::pair<reg_t, mem_t*>>(1, std::make_pair(reg_t(DRAM_BASE), new mem_t(size)));
+ }
+
+ // handle base/size tuples
+ std::vector<std::pair<reg_t, mem_t*>> res;
+ while (true) {
+ auto base = strtoull(arg, &p, 0);
+ if (!*p || *p != ':')
+ help();
+ auto size = strtoull(p + 1, &p, 0);
+ if ((size | base) % PGSIZE != 0)
+ help();
+ res.push_back(std::make_pair(reg_t(base), new mem_t(size)));
+ if (!*p)
+ break;
+ if (*p != ',')
+ help();
+ arg = p + 1;
+ }
+ return res;
+#if 0
+ // allocate target machine's memory, shrinking it as necessary
+ // until the allocation succeeds
+ size_t memsz0 = (size_t)mem_mb << 20;
+ size_t quantum = 1L << 20;
+ if (memsz0 == 0)
+ memsz0 = (size_t)2048 << 20;
+
+ memsz = memsz0;
+ while ((mem = (char*)calloc(1, memsz)) == NULL)
+ memsz = (size_t)(memsz*0.9)/quantum*quantum;
+
+ if (memsz != memsz0)
+ fprintf(stderr, "warning: only got %zu bytes of target mem (wanted %zu)\n",
+ memsz, memsz0);
+#endif
+}
+