Add PowerPC 32-bit guest memory dump support
This patch extends support for the `dump-guest-memory` command to the 32-bit PowerPC architecture. It relies on the assumption that a 64-bit guest will not dump a 32-bit core file (and vice versa). [dwg: I suspect this patch won't cover all cases, in particular a 32-bit machine type on a 64-bit qemu build. However, it does strictly more than what we had before, so might as well apply as a starting point] Signed-off-by: Mike Nawrocki <michael.nawrocki@gtri.gatech.edu> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
8e4fba203e
commit
356bb70ed1
@ -2,8 +2,8 @@ obj-y += cpu-models.o
|
|||||||
obj-y += cpu.o
|
obj-y += cpu.o
|
||||||
obj-y += translate.o
|
obj-y += translate.o
|
||||||
ifeq ($(CONFIG_SOFTMMU),y)
|
ifeq ($(CONFIG_SOFTMMU),y)
|
||||||
obj-y += machine.o mmu_helper.o mmu-hash32.o monitor.o
|
obj-y += machine.o mmu_helper.o mmu-hash32.o monitor.o arch_dump.o
|
||||||
obj-$(TARGET_PPC64) += mmu-hash64.o arch_dump.o compat.o
|
obj-$(TARGET_PPC64) += mmu-hash64.o compat.o
|
||||||
endif
|
endif
|
||||||
obj-$(CONFIG_KVM) += kvm.o
|
obj-$(CONFIG_KVM) += kvm.o
|
||||||
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
|
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* writing ELF notes for ppc64 arch
|
* writing ELF notes for ppc{64,} arch
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Copyright IBM, Corp. 2013
|
* Copyright IBM, Corp. 2013
|
||||||
@ -19,36 +19,48 @@
|
|||||||
#include "sysemu/dump.h"
|
#include "sysemu/dump.h"
|
||||||
#include "sysemu/kvm.h"
|
#include "sysemu/kvm.h"
|
||||||
|
|
||||||
struct PPC64UserRegStruct {
|
#ifdef TARGET_PPC64
|
||||||
uint64_t gpr[32];
|
#define ELFCLASS ELFCLASS64
|
||||||
uint64_t nip;
|
#define cpu_to_dump_reg cpu_to_dump64
|
||||||
uint64_t msr;
|
typedef uint64_t reg_t;
|
||||||
uint64_t orig_gpr3;
|
typedef Elf64_Nhdr Elf_Nhdr;
|
||||||
uint64_t ctr;
|
#else
|
||||||
uint64_t link;
|
#define ELFCLASS ELFCLASS32
|
||||||
uint64_t xer;
|
#define cpu_to_dump_reg cpu_to_dump32
|
||||||
uint64_t ccr;
|
typedef uint32_t reg_t;
|
||||||
uint64_t softe;
|
typedef Elf32_Nhdr Elf_Nhdr;
|
||||||
uint64_t trap;
|
#endif /* TARGET_PPC64 */
|
||||||
uint64_t dar;
|
|
||||||
uint64_t dsisr;
|
struct PPCUserRegStruct {
|
||||||
uint64_t result;
|
reg_t gpr[32];
|
||||||
|
reg_t nip;
|
||||||
|
reg_t msr;
|
||||||
|
reg_t orig_gpr3;
|
||||||
|
reg_t ctr;
|
||||||
|
reg_t link;
|
||||||
|
reg_t xer;
|
||||||
|
reg_t ccr;
|
||||||
|
reg_t softe;
|
||||||
|
reg_t trap;
|
||||||
|
reg_t dar;
|
||||||
|
reg_t dsisr;
|
||||||
|
reg_t result;
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
struct PPC64ElfPrstatus {
|
struct PPCElfPrstatus {
|
||||||
char pad1[112];
|
char pad1[112];
|
||||||
struct PPC64UserRegStruct pr_reg;
|
struct PPCUserRegStruct pr_reg;
|
||||||
uint64_t pad2[4];
|
reg_t pad2[4];
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
|
|
||||||
struct PPC64ElfFpregset {
|
struct PPCElfFpregset {
|
||||||
uint64_t fpr[32];
|
uint64_t fpr[32];
|
||||||
uint64_t fpscr;
|
reg_t fpscr;
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
|
|
||||||
struct PPC64ElfVmxregset {
|
struct PPCElfVmxregset {
|
||||||
ppc_avr_t avr[32];
|
ppc_avr_t avr[32];
|
||||||
ppc_avr_t vscr;
|
ppc_avr_t vscr;
|
||||||
union {
|
union {
|
||||||
@ -57,26 +69,26 @@ struct PPC64ElfVmxregset {
|
|||||||
} vrsave;
|
} vrsave;
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
struct PPC64ElfVsxregset {
|
struct PPCElfVsxregset {
|
||||||
uint64_t vsr[32];
|
uint64_t vsr[32];
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
struct PPC64ElfSperegset {
|
struct PPCElfSperegset {
|
||||||
uint32_t evr[32];
|
uint32_t evr[32];
|
||||||
uint64_t spe_acc;
|
uint64_t spe_acc;
|
||||||
uint32_t spe_fscr;
|
uint32_t spe_fscr;
|
||||||
} QEMU_PACKED;
|
} QEMU_PACKED;
|
||||||
|
|
||||||
typedef struct noteStruct {
|
typedef struct noteStruct {
|
||||||
Elf64_Nhdr hdr;
|
Elf_Nhdr hdr;
|
||||||
char name[5];
|
char name[5];
|
||||||
char pad3[3];
|
char pad3[3];
|
||||||
union {
|
union {
|
||||||
struct PPC64ElfPrstatus prstatus;
|
struct PPCElfPrstatus prstatus;
|
||||||
struct PPC64ElfFpregset fpregset;
|
struct PPCElfFpregset fpregset;
|
||||||
struct PPC64ElfVmxregset vmxregset;
|
struct PPCElfVmxregset vmxregset;
|
||||||
struct PPC64ElfVsxregset vsxregset;
|
struct PPCElfVsxregset vsxregset;
|
||||||
struct PPC64ElfSperegset speregset;
|
struct PPCElfSperegset speregset;
|
||||||
} contents;
|
} contents;
|
||||||
} QEMU_PACKED Note;
|
} QEMU_PACKED Note;
|
||||||
|
|
||||||
@ -85,12 +97,12 @@ typedef struct NoteFuncArg {
|
|||||||
DumpState *state;
|
DumpState *state;
|
||||||
} NoteFuncArg;
|
} NoteFuncArg;
|
||||||
|
|
||||||
static void ppc64_write_elf64_prstatus(NoteFuncArg *arg, PowerPCCPU *cpu)
|
static void ppc_write_elf_prstatus(NoteFuncArg *arg, PowerPCCPU *cpu)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint64_t cr;
|
reg_t cr;
|
||||||
struct PPC64ElfPrstatus *prstatus;
|
struct PPCElfPrstatus *prstatus;
|
||||||
struct PPC64UserRegStruct *reg;
|
struct PPCUserRegStruct *reg;
|
||||||
Note *note = &arg->note;
|
Note *note = &arg->note;
|
||||||
DumpState *s = arg->state;
|
DumpState *s = arg->state;
|
||||||
|
|
||||||
@ -101,25 +113,25 @@ static void ppc64_write_elf64_prstatus(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|||||||
reg = &prstatus->pr_reg;
|
reg = &prstatus->pr_reg;
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
reg->gpr[i] = cpu_to_dump64(s, cpu->env.gpr[i]);
|
reg->gpr[i] = cpu_to_dump_reg(s, cpu->env.gpr[i]);
|
||||||
}
|
}
|
||||||
reg->nip = cpu_to_dump64(s, cpu->env.nip);
|
reg->nip = cpu_to_dump_reg(s, cpu->env.nip);
|
||||||
reg->msr = cpu_to_dump64(s, cpu->env.msr);
|
reg->msr = cpu_to_dump_reg(s, cpu->env.msr);
|
||||||
reg->ctr = cpu_to_dump64(s, cpu->env.ctr);
|
reg->ctr = cpu_to_dump_reg(s, cpu->env.ctr);
|
||||||
reg->link = cpu_to_dump64(s, cpu->env.lr);
|
reg->link = cpu_to_dump_reg(s, cpu->env.lr);
|
||||||
reg->xer = cpu_to_dump64(s, cpu_read_xer(&cpu->env));
|
reg->xer = cpu_to_dump_reg(s, cpu_read_xer(&cpu->env));
|
||||||
|
|
||||||
cr = 0;
|
cr = 0;
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
cr |= (cpu->env.crf[i] & 15) << (4 * (7 - i));
|
cr |= (cpu->env.crf[i] & 15) << (4 * (7 - i));
|
||||||
}
|
}
|
||||||
reg->ccr = cpu_to_dump64(s, cr);
|
reg->ccr = cpu_to_dump_reg(s, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ppc64_write_elf64_fpregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
static void ppc_write_elf_fpregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct PPC64ElfFpregset *fpregset;
|
struct PPCElfFpregset *fpregset;
|
||||||
Note *note = &arg->note;
|
Note *note = &arg->note;
|
||||||
DumpState *s = arg->state;
|
DumpState *s = arg->state;
|
||||||
|
|
||||||
@ -131,13 +143,13 @@ static void ppc64_write_elf64_fpregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
fpregset->fpr[i] = cpu_to_dump64(s, cpu->env.fpr[i]);
|
fpregset->fpr[i] = cpu_to_dump64(s, cpu->env.fpr[i]);
|
||||||
}
|
}
|
||||||
fpregset->fpscr = cpu_to_dump64(s, cpu->env.fpscr);
|
fpregset->fpscr = cpu_to_dump_reg(s, cpu->env.fpscr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ppc64_write_elf64_vmxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
static void ppc_write_elf_vmxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct PPC64ElfVmxregset *vmxregset;
|
struct PPCElfVmxregset *vmxregset;
|
||||||
Note *note = &arg->note;
|
Note *note = &arg->note;
|
||||||
DumpState *s = arg->state;
|
DumpState *s = arg->state;
|
||||||
|
|
||||||
@ -164,10 +176,11 @@ static void ppc64_write_elf64_vmxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|||||||
}
|
}
|
||||||
vmxregset->vscr.u32[3] = cpu_to_dump32(s, cpu->env.vscr);
|
vmxregset->vscr.u32[3] = cpu_to_dump32(s, cpu->env.vscr);
|
||||||
}
|
}
|
||||||
static void ppc64_write_elf64_vsxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|
||||||
|
static void ppc_write_elf_vsxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct PPC64ElfVsxregset *vsxregset;
|
struct PPCElfVsxregset *vsxregset;
|
||||||
Note *note = &arg->note;
|
Note *note = &arg->note;
|
||||||
DumpState *s = arg->state;
|
DumpState *s = arg->state;
|
||||||
|
|
||||||
@ -179,9 +192,10 @@ static void ppc64_write_elf64_vsxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|||||||
vsxregset->vsr[i] = cpu_to_dump64(s, cpu->env.vsr[i]);
|
vsxregset->vsr[i] = cpu_to_dump64(s, cpu->env.vsr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void ppc64_write_elf64_speregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
|
||||||
|
static void ppc_write_elf_speregset(NoteFuncArg *arg, PowerPCCPU *cpu)
|
||||||
{
|
{
|
||||||
struct PPC64ElfSperegset *speregset;
|
struct PPCElfSperegset *speregset;
|
||||||
Note *note = &arg->note;
|
Note *note = &arg->note;
|
||||||
DumpState *s = arg->state;
|
DumpState *s = arg->state;
|
||||||
|
|
||||||
@ -197,11 +211,11 @@ static const struct NoteFuncDescStruct {
|
|||||||
int contents_size;
|
int contents_size;
|
||||||
void (*note_contents_func)(NoteFuncArg *arg, PowerPCCPU *cpu);
|
void (*note_contents_func)(NoteFuncArg *arg, PowerPCCPU *cpu);
|
||||||
} note_func[] = {
|
} note_func[] = {
|
||||||
{sizeof(((Note *)0)->contents.prstatus), ppc64_write_elf64_prstatus},
|
{sizeof(((Note *)0)->contents.prstatus), ppc_write_elf_prstatus},
|
||||||
{sizeof(((Note *)0)->contents.fpregset), ppc64_write_elf64_fpregset},
|
{sizeof(((Note *)0)->contents.fpregset), ppc_write_elf_fpregset},
|
||||||
{sizeof(((Note *)0)->contents.vmxregset), ppc64_write_elf64_vmxregset},
|
{sizeof(((Note *)0)->contents.vmxregset), ppc_write_elf_vmxregset},
|
||||||
{sizeof(((Note *)0)->contents.vsxregset), ppc64_write_elf64_vsxregset},
|
{sizeof(((Note *)0)->contents.vsxregset), ppc_write_elf_vsxregset},
|
||||||
{sizeof(((Note *)0)->contents.speregset), ppc64_write_elf64_speregset},
|
{sizeof(((Note *)0)->contents.speregset), ppc_write_elf_speregset},
|
||||||
{ 0, NULL}
|
{ 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,8 +227,9 @@ int cpu_get_dump_info(ArchDumpInfo *info,
|
|||||||
PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
|
PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
|
||||||
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
|
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
|
||||||
|
|
||||||
info->d_machine = EM_PPC64;
|
info->d_machine = PPC_ELF_MACHINE;
|
||||||
info->d_class = ELFCLASS64;
|
info->d_class = ELFCLASS;
|
||||||
|
|
||||||
if ((*pcc->interrupts_big_endian)(cpu)) {
|
if ((*pcc->interrupts_big_endian)(cpu)) {
|
||||||
info->d_endian = ELFDATA2MSB;
|
info->d_endian = ELFDATA2MSB;
|
||||||
} else {
|
} else {
|
||||||
@ -236,25 +251,19 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
|
|||||||
int note_head_size;
|
int note_head_size;
|
||||||
const NoteFuncDesc *nf;
|
const NoteFuncDesc *nf;
|
||||||
|
|
||||||
if (class != ELFCLASS64) {
|
note_head_size = sizeof(Elf_Nhdr);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
assert(machine == EM_PPC64);
|
|
||||||
|
|
||||||
note_head_size = sizeof(Elf64_Nhdr);
|
|
||||||
|
|
||||||
for (nf = note_func; nf->note_contents_func; nf++) {
|
for (nf = note_func; nf->note_contents_func; nf++) {
|
||||||
elf_note_size = elf_note_size + note_head_size + name_size +
|
elf_note_size = elf_note_size + note_head_size + name_size +
|
||||||
nf->contents_size;
|
nf->contents_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (elf_note_size) * nr_cpus;
|
return (elf_note_size) * nr_cpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ppc64_write_all_elf64_notes(const char *note_name,
|
static int ppc_write_all_elf_notes(const char *note_name,
|
||||||
WriteCoreDumpFunction f,
|
WriteCoreDumpFunction f,
|
||||||
PowerPCCPU *cpu, int id,
|
PowerPCCPU *cpu, int id,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
NoteFuncArg arg = { .state = opaque };
|
NoteFuncArg arg = { .state = opaque };
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -282,5 +291,12 @@ int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
|
|||||||
int cpuid, void *opaque)
|
int cpuid, void *opaque)
|
||||||
{
|
{
|
||||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||||
return ppc64_write_all_elf64_notes("CORE", f, cpu, cpuid, opaque);
|
return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, opaque);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
|
||||||
|
int cpuid, void *opaque)
|
||||||
|
{
|
||||||
|
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||||
|
return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, opaque);
|
||||||
}
|
}
|
||||||
|
@ -1241,6 +1241,8 @@ int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
|
|||||||
int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg);
|
int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg);
|
||||||
int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
|
int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
|
||||||
int cpuid, void *opaque);
|
int cpuid, void *opaque);
|
||||||
|
int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
|
||||||
|
int cpuid, void *opaque);
|
||||||
#ifndef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
void ppc_cpu_do_system_reset(CPUState *cs);
|
void ppc_cpu_do_system_reset(CPUState *cs);
|
||||||
extern const struct VMStateDescription vmstate_ppc_cpu;
|
extern const struct VMStateDescription vmstate_ppc_cpu;
|
||||||
|
@ -10497,11 +10497,12 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
|
|||||||
#else
|
#else
|
||||||
cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug;
|
cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug;
|
||||||
cc->vmsd = &vmstate_ppc_cpu;
|
cc->vmsd = &vmstate_ppc_cpu;
|
||||||
#if defined(TARGET_PPC64)
|
|
||||||
cc->write_elf64_note = ppc64_cpu_write_elf64_note;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
cc->cpu_exec_enter = ppc_cpu_exec_enter;
|
cc->cpu_exec_enter = ppc_cpu_exec_enter;
|
||||||
|
#if defined(CONFIG_SOFTMMU)
|
||||||
|
cc->write_elf64_note = ppc64_cpu_write_elf64_note;
|
||||||
|
cc->write_elf32_note = ppc32_cpu_write_elf32_note;
|
||||||
|
#endif
|
||||||
|
|
||||||
cc->gdb_num_core_regs = 71;
|
cc->gdb_num_core_regs = 71;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user