fclose(f);
}
-static void load(const char arg[]) {
+static void load(const char arg[], uint8_t *ram) {
char name[PATH_MAX];
const char *ptr = strchr(arg, ':');
const unsigned len = ftell(f);
rewind(f);
- // TODO copy it up
+ if (addr + len >= RAMSIZE) {
+ printf("Tried to use too much RAM\n");
+ exit(1);
+ }
+
+ if (fread(&ram[addr], len, 1, f) != 1)
+ abort();
fclose(f);
}
uint8_t *ram, *progmem;
const char *binpath;
+ // Yes, we're frugal
+ if (posix_memalign((void **) &ram, 64 * 1024, RAMSIZE))
+ abort();
+ memset(ram, 0, RAMSIZE);
+
memset(®s, 0, sizeof(struct kvm_regs));
memset(&fpregs, 0, sizeof(struct kvm_fpu));
parsesprs(optarg, ®s);
break;
case 'l':
- load(optarg);
+ load(optarg, ram);
break;
case 'd':
if (num_dumps >= MAXDUMPS) {
help(argv[0]);
}
- // Yes, we're frugal
- if (posix_memalign((void **) &ram, 64 * 1024, RAMSIZE))
- abort();
- memset(ram, 0, RAMSIZE);
-
fseek(binary, 0, SEEK_END);
const unsigned binlen = ftell(binary);
rewind(binary);