Received: from eggs.gnu.org ([208.118.235.92]:48926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXtgI-00030c-6t for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXtg4-0004Z8-Kx for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:18 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46624 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXtg4-0004Wn-18 for qemu-devel@nongnu.org; Thu, 02 May 2013 09:36:04 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 2 May 2013 15:35:43 +0200 Message-Id: <1367501755-32272-18-git-send-email-afaerber@suse.de> In-Reply-To: <1367501755-32272-1-git-send-email-afaerber@suse.de> References: <1367501755-32272-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 17/29] cpu: Move cpu_write_elfXX_note() functions to CPUState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jens Freimann , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Jens Freimann Convert cpu_write_elfXX_note() functions to CPUClass methods and pass CPUState as argument. Update target-i386 accordingly. Signed-off-by: Jens Freimann [AF: Retain stubs as CPUClass' default method implementation; style chang= es] Signed-off-by: Andreas F=C3=A4rber --- dump-stub.c | 28 ---------------------- dump.c | 8 +++---- include/qom/cpu.h | 49 ++++++++++++++++++++++++++++++++++++++ include/sysemu/dump.h | 9 ------- qom/cpu.c | 63 +++++++++++++++++++++++++++++++++++++++++++= ++++++ target-i386/arch_dump.c | 38 ++++++++++++++++------------- target-i386/cpu-qom.h | 9 +++++++ target-i386/cpu.c | 6 +++++ 8 files changed, 153 insertions(+), 57 deletions(-) diff --git a/dump-stub.c b/dump-stub.c index a9d0b3c..b3f42cb 100644 --- a/dump-stub.c +++ b/dump-stub.c @@ -24,34 +24,6 @@ void qmp_dump_guest_memory(bool paging, const char *fi= le, bool has_begin, error_set(errp, QERR_UNSUPPORTED); } =20 -int cpu_write_elf64_note(write_core_dump_function f, - CPUArchState *env, int cpuid, - void *opaque) -{ - return -1; -} - -int cpu_write_elf32_note(write_core_dump_function f, - CPUArchState *env, int cpuid, - void *opaque) -{ - return -1; -} - -int cpu_write_elf64_qemunote(write_core_dump_function f, - CPUArchState *env, - void *opaque) -{ - return -1; -} - -int cpu_write_elf32_qemunote(write_core_dump_function f, - CPUArchState *env, - void *opaque) -{ - return -1; -} - int cpu_get_dump_info(ArchDumpInfo *info) { return -1; diff --git a/dump.c b/dump.c index b34f143..c0d3da5 100644 --- a/dump.c +++ b/dump.c @@ -282,7 +282,7 @@ static int write_elf64_notes(DumpState *s) for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { cpu =3D ENV_GET_CPU(env); id =3D cpu_index(cpu); - ret =3D cpu_write_elf64_note(fd_write_vmcore, env, id, s); + ret =3D cpu_write_elf64_note(fd_write_vmcore, cpu, id, s); if (ret < 0) { dump_error(s, "dump: failed to write elf notes.\n"); return -1; @@ -290,7 +290,7 @@ static int write_elf64_notes(DumpState *s) } =20 for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - ret =3D cpu_write_elf64_qemunote(fd_write_vmcore, env, s); + ret =3D cpu_write_elf64_qemunote(fd_write_vmcore, cpu, s); if (ret < 0) { dump_error(s, "dump: failed to write CPU status.\n"); return -1; @@ -334,7 +334,7 @@ static int write_elf32_notes(DumpState *s) for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { cpu =3D ENV_GET_CPU(env); id =3D cpu_index(cpu); - ret =3D cpu_write_elf32_note(fd_write_vmcore, env, id, s); + ret =3D cpu_write_elf32_note(fd_write_vmcore, cpu, id, s); if (ret < 0) { dump_error(s, "dump: failed to write elf notes.\n"); return -1; @@ -342,7 +342,7 @@ static int write_elf32_notes(DumpState *s) } =20 for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - ret =3D cpu_write_elf32_qemunote(fd_write_vmcore, env, s); + ret =3D cpu_write_elf32_qemunote(fd_write_vmcore, cpu, s); if (ret < 0) { dump_error(s, "dump: failed to write CPU status.\n"); return -1; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index e54579b..7cd9442 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -24,6 +24,8 @@ #include "hw/qdev-core.h" #include "qemu/thread.h" =20 +typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaqu= e); + /** * SECTION:cpu * @section_id: QEMU-cpu @@ -62,6 +64,14 @@ typedef struct CPUClass { int64_t (*get_arch_id)(CPUState *cpu); =20 const struct VMStateDescription *vmsd; + int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); + int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); + int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); + int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); } CPUClass; =20 struct KVMState; @@ -127,6 +137,45 @@ struct CPUState { uint32_t halted; /* used by alpha, cris, ppc TCG */ }; =20 +/** + * cpu_write_elf64_note: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); + +/** + * cpu_write_elf64_qemunote: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); + +/** + * cpu_write_elf32_note: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); + +/** + * cpu_write_elf32_qemunote: + * @f: pointer to a function that writes memory to a file + * @cpu: The CPU whose memory is to be dumped + * @cpuid: ID number of the CPU + * @opaque: pointer to the CPUState struct + */ +int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); =20 /** * cpu_reset: diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index e25b7cf..b8c770f 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -20,15 +20,6 @@ typedef struct ArchDumpInfo { int d_class; /* ELFCLASS32 or ELFCLASS64 */ } ArchDumpInfo; =20 -typedef int (*write_core_dump_function)(void *buf, size_t size, void *op= aque); -int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaqu= e); -int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaqu= e); -int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *e= nv, - void *opaque); -int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *e= nv, - void *opaque); int cpu_get_dump_info(ArchDumpInfo *info); ssize_t cpu_get_note_size(int class, int machine, int nr_cpus); =20 diff --git a/qom/cpu.c b/qom/cpu.c index 3dc8208..04aefbb 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -64,6 +64,65 @@ void cpu_reset_interrupt(CPUState *cpu, int mask) cpu->interrupt_request &=3D ~mask; } =20 +int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + return (*cc->write_elf32_qemunote)(f, cpu, opaque); +} + +static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f, + CPUState *cpu, void *opaque) +{ + return -1; +} + +int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + return (*cc->write_elf32_note)(f, cpu, cpuid, opaque); +} + +static int cpu_common_write_elf32_note(WriteCoreDumpFunction f, + CPUState *cpu, int cpuid, + void *opaque) +{ + return -1; +} + +int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + return (*cc->write_elf64_qemunote)(f, cpu, opaque); +} + +static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f, + CPUState *cpu, void *opaque) +{ + return -1; +} + +int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + return (*cc->write_elf64_note)(f, cpu, cpuid, opaque); +} + +static int cpu_common_write_elf64_note(WriteCoreDumpFunction f, + CPUState *cpu, int cpuid, + void *opaque) +{ + return -1; +} + + void cpu_reset(CPUState *cpu) { CPUClass *klass =3D CPU_GET_CLASS(cpu); @@ -117,6 +176,10 @@ static void cpu_class_init(ObjectClass *klass, void = *data) k->class_by_name =3D cpu_common_class_by_name; k->reset =3D cpu_common_reset; k->get_arch_id =3D cpu_common_get_arch_id; + k->write_elf32_qemunote =3D cpu_common_write_elf32_qemunote; + k->write_elf32_note =3D cpu_common_write_elf32_note; + k->write_elf64_qemunote =3D cpu_common_write_elf64_qemunote; + k->write_elf64_note =3D cpu_common_write_elf64_note; dc->realize =3D cpu_common_realizefn; dc->no_user =3D 1; } diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c index 2cd2f7f..83898cd 100644 --- a/target-i386/arch_dump.c +++ b/target-i386/arch_dump.c @@ -34,7 +34,7 @@ typedef struct { char pad3[8]; } x86_64_elf_prstatus; =20 -static int x86_64_write_elf64_note(write_core_dump_function f, +static int x86_64_write_elf64_note(WriteCoreDumpFunction f, CPUArchState *env, int id, void *opaque) { @@ -144,7 +144,7 @@ static void x86_fill_elf_prstatus(x86_elf_prstatus *p= rstatus, CPUArchState *env, prstatus->pid =3D id; } =20 -static int x86_write_elf64_note(write_core_dump_function f, CPUArchState= *env, +static int x86_write_elf64_note(WriteCoreDumpFunction f, CPUArchState *e= nv, int id, void *opaque) { x86_elf_prstatus prstatus; @@ -179,18 +179,19 @@ static int x86_write_elf64_note(write_core_dump_fun= ction f, CPUArchState *env, return 0; } =20 -int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaque) +int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, + int cpuid, void *opaque) { + X86CPU *cpu =3D X86_CPU(cs); int ret; #ifdef TARGET_X86_64 bool lma =3D !!(first_cpu->hflags & HF_LMA_MASK); =20 if (lma) { - ret =3D x86_64_write_elf64_note(f, env, cpuid, opaque); + ret =3D x86_64_write_elf64_note(f, &cpu->env, cpuid, opaque); } else { #endif - ret =3D x86_write_elf64_note(f, env, cpuid, opaque); + ret =3D x86_write_elf64_note(f, &cpu->env, cpuid, opaque); #ifdef TARGET_X86_64 } #endif @@ -198,9 +199,10 @@ int cpu_write_elf64_note(write_core_dump_function f,= CPUArchState *env, return ret; } =20 -int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env, - int cpuid, void *opaque) +int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, + int cpuid, void *opaque) { + X86CPU *cpu =3D X86_CPU(cs); x86_elf_prstatus prstatus; Elf32_Nhdr *note; char *buf; @@ -208,7 +210,7 @@ int cpu_write_elf32_note(write_core_dump_function f, = CPUArchState *env, const char *name =3D "CORE"; int ret; =20 - x86_fill_elf_prstatus(&prstatus, env, cpuid); + x86_fill_elf_prstatus(&prstatus, &cpu->env, cpuid); descsz =3D sizeof(x86_elf_prstatus); note_size =3D ((sizeof(Elf32_Nhdr) + 3) / 4 + (name_size + 3) / 4 + (descsz + 3) / 4) * 4; @@ -317,7 +319,7 @@ static void qemu_get_cpustate(QEMUCPUState *s, CPUArc= hState *env) s->cr[4] =3D env->cr[4]; } =20 -static inline int cpu_write_qemu_note(write_core_dump_function f, +static inline int cpu_write_qemu_note(WriteCoreDumpFunction f, CPUArchState *env, void *opaque, int type) @@ -370,16 +372,20 @@ static inline int cpu_write_qemu_note(write_core_du= mp_function f, return 0; } =20 -int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *e= nv, - void *opaque) +int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cs, + void *opaque) { - return cpu_write_qemu_note(f, env, opaque, 1); + X86CPU *cpu =3D X86_CPU(cs); + + return cpu_write_qemu_note(f, &cpu->env, opaque, 1); } =20 -int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *e= nv, - void *opaque) +int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cs, + void *opaque) { - return cpu_write_qemu_note(f, env, opaque, 0); + X86CPU *cpu =3D X86_CPU(cs); + + return cpu_write_qemu_note(f, &cpu->env, opaque, 0); } =20 int cpu_get_dump_info(ArchDumpInfo *info) diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 08f9eb6..f890f1c 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -86,4 +86,13 @@ extern const struct VMStateDescription vmstate_x86_cpu= ; */ void x86_cpu_do_interrupt(CPUState *cpu); =20 +int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); +int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, + int cpuid, void *opaque); +int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); +int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, + void *opaque); + #endif diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 0d9493d..40d51be 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2351,6 +2351,12 @@ static void x86_cpu_common_class_init(ObjectClass = *oc, void *data) cc->reset =3D x86_cpu_reset; =20 cc->do_interrupt =3D x86_cpu_do_interrupt; +#ifndef CONFIG_USER_ONLY + cc->write_elf64_note =3D x86_cpu_write_elf64_note; + cc->write_elf64_qemunote =3D x86_cpu_write_elf64_qemunote; + cc->write_elf32_note =3D x86_cpu_write_elf32_note; + cc->write_elf32_qemunote =3D x86_cpu_write_elf32_qemunote; +#endif cpu_class_set_vmsd(cc, &vmstate_x86_cpu); =20 cc->get_arch_id =3D x86_cpu_get_arch_id; --=20 1.8.1.4