From: Lauri Kasanen Date: Fri, 28 May 2021 08:40:27 +0000 (+0300) Subject: Add dumping X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=090d2b2305d37c6b3af16318fbf3251aae7f1a3e;p=kvm-minippc.git Add dumping --- diff --git a/main.c b/main.c index 5012602..d3d1e97 100644 --- a/main.c +++ b/main.c @@ -197,6 +197,43 @@ static void load(const char arg[], uint8_t *ram) { fclose(f); } +static void dump(const char src[], const uint8_t ram[]) { + const char *ptr = strchr(src, ':'); + if (!ptr) { + printf("Invalid dump\n"); + exit(1); + } + + char name[PATH_MAX]; + memcpy(name, src, ptr - src); + name[ptr - src] = '\0'; + + ptr++; + const uint32_t addr = strtol(ptr, NULL, 0); + + ptr = strchr(ptr, ':'); + if (!ptr) { + printf("Invalid dump\n"); + exit(1); + } + + ptr++; + const uint32_t len = strtol(ptr, NULL, 0); + + //printf("Saving to %s, from %x, len %u\n", name, addr, len); + + FILE *f = fopen(name, "w"); + if (!f) { + printf("Can't open %s\n", name); + exit(1); + } + + if (fwrite(&ram[addr], len, 1, f) != 1) + abort(); + + fclose(f); +} + static void setfpregs(const int vcpu, struct kvm_fpu *fpregs) { // KVM_[SG]ET_FPU isn't supported on PPC, we have to move individual regs... unsigned i; @@ -407,6 +444,11 @@ int main(int argc, char **argv) { printf("Exited because %u\n", run->exit_reason); } + unsigned i; + for (i = 0; i < num_dumps; i++) { + dump(dumps[i], ram); + } + close(kvm); free(progmem); free(ram);