From 3fc9b9e41b5dff4d7d9dfc8ad0d8118d491b3620 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Thu, 27 May 2021 15:39:17 +0300 Subject: [PATCH] Apply regs --- main.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index a5ed3fa..99c1041 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,10 @@ #define RAMSIZE (64 * 1024 * 1024) #define PROGSTART 0x20000000 +enum { + SPR_LR, +}; + static void nukenewline(char buf[]) { unsigned i; for (i = 0; buf[i]; i++) { @@ -64,7 +68,8 @@ static void help(const char argv0[]) { exit(0); } -static void parseregs(const char name[], const uint8_t gpr) { +static void parseregs(const char name[], const uint8_t gpr, struct kvm_regs *regs, + struct kvm_fpu *fpregs) { FILE *f = fopen(name, "r"); if (!f) { @@ -88,16 +93,18 @@ static void parseregs(const char name[], const uint8_t gpr) { const uint64_t val = strtol(ptr, NULL, 0); - // TODO apply reg + // apply reg if (gpr) { + regs->gpr[reg] = val; } else { + fpregs->fpr[reg] = val; } } fclose(f); } -static void parsesprs(const char name[]) { +static void parsesprs(const char name[], struct kvm_regs *regs) { FILE *f = fopen(name, "r"); if (!f) { @@ -117,7 +124,7 @@ static void parsesprs(const char name[]) { #define check(a) if (!strncasecmp(buf, a, sizeof(a) - 1)) check("LR:") { - // TODO reg = ; + reg = SPR_LR; } #undef check @@ -136,7 +143,12 @@ static void parsesprs(const char name[]) { const uint64_t val = strtol(ptr, NULL, 0); - // TODO apply reg + // apply reg + switch (reg) { + case SPR_LR: + regs->lr = val; + break; + } } fclose(f); @@ -191,6 +203,7 @@ int main(int argc, char **argv) { struct kvm_run *run; struct kvm_regs regs; struct kvm_sregs sregs; + struct kvm_fpu fpregs; int kvm, vmfd, vcpu; FILE *binary = NULL, *trace = NULL; char dumps[MAXDUMPS][PATH_MAX]; @@ -198,6 +211,12 @@ int main(int argc, char **argv) { uint8_t *ram, *progmem; const char *binpath; + memset(®s, 0, sizeof(struct kvm_regs)); + memset(&fpregs, 0, sizeof(struct kvm_fpu)); + + regs.lr = -1; + regs.pc = PROGSTART; + while (1) { const int c = getopt_long(argc, argv, opts, longopts, NULL); if (c == -1) @@ -219,13 +238,13 @@ int main(int argc, char **argv) { binpath = strdup(optarg); break; case 'g': - parseregs(optarg, 1); + parseregs(optarg, 1, ®s, &fpregs); break; case 'f': - parseregs(optarg, 0); + parseregs(optarg, 0, ®s, &fpregs); break; case 's': - parsesprs(optarg); + parsesprs(optarg, ®s); break; case 'l': load(optarg); @@ -272,7 +291,7 @@ int main(int argc, char **argv) { const unsigned binlen = ftell(binary); rewind(binary); - printf("Loading binary %u bytes\n", binlen); // TODO + printf("Loading binary %u bytes\n", binlen); if (posix_memalign((void **) &progmem, 64 * 1024, binlen)) abort(); -- 2.30.2