From patchwork Mon Apr 28 11:29:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 343346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 757AD1400E4 for ; Mon, 28 Apr 2014 21:32:23 +1000 (EST) Received: from localhost ([::1]:43127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WejnI-0007BN-Qt for incoming@patchwork.ozlabs.org; Mon, 28 Apr 2014 07:32:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wejl3-0002uM-R3 for qemu-devel@nongnu.org; Mon, 28 Apr 2014 07:30:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wejkn-0003ty-RX for qemu-devel@nongnu.org; Mon, 28 Apr 2014 07:30:01 -0400 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:50487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wejkn-0003tq-HT for qemu-devel@nongnu.org; Mon, 28 Apr 2014 07:29:45 -0400 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Apr 2014 12:29:44 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp18.uk.ibm.com (192.168.101.148) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 Apr 2014 12:29:43 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 825D4219005E; Mon, 28 Apr 2014 12:29:35 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s3SBThAH4325786; Mon, 28 Apr 2014 11:29:43 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s3SBTgmC006622; Mon, 28 Apr 2014 05:29:42 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s3SBTgUG006617; Mon, 28 Apr 2014 05:29:42 -0600 Received: from bahia.lab.toulouse-stg.fr.ibm.com (bahia.lab.toulouse-stg.fr.ibm.com [9.101.4.41]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 69637210FF5; Mon, 28 Apr 2014 13:29:42 +0200 (CEST) To: agraf@suse.de From: Greg Kurz Date: Mon, 28 Apr 2014 13:29:42 +0200 Message-ID: <20140428112942.26464.82895.stgit@bahia.lab.toulouse-stg.fr.ibm.com> In-Reply-To: <20140428112931.26464.6763.stgit@bahia.lab.toulouse-stg.fr.ibm.com> References: <20140428112931.26464.6763.stgit@bahia.lab.toulouse-stg.fr.ibm.com> User-Agent: StGit/0.16 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14042811-6892-0000-0000-000008999021 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.114 Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, afaerber@suse.de, bharata@linux.ibm.com Subject: [Qemu-devel] [PATCH 2/4] ppc64-dump: Support dump for little endian ppc64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Bharata B Rao Fix ppc64 arch specific dump code to work correctly for little endian guests. Signed-off-by: Bharata B Rao [ rebased on top of current master branch, Greg Kurz ] Signed-off-by: Greg Kurz --- target-ppc/arch_dump.c | 62 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/target-ppc/arch_dump.c b/target-ppc/arch_dump.c index 9dccf1a..a85c872 100644 --- a/target-ppc/arch_dump.c +++ b/target-ppc/arch_dump.c @@ -80,93 +80,95 @@ typedef struct noteStruct { } QEMU_PACKED Note; -static void ppc64_write_elf64_prstatus(Note *note, PowerPCCPU *cpu) +static void ppc64_write_elf64_prstatus(Note *note, PowerPCCPU *cpu, int endian) { int i; uint64_t cr; struct PPC64ElfPrstatus *prstatus; struct PPC64UserRegStruct *reg; - note->hdr.n_type = cpu_to_be32(NT_PRSTATUS); + note->hdr.n_type = cpu_convert_to_target32(NT_PRSTATUS, endian); prstatus = ¬e->contents.prstatus; memset(prstatus, 0, sizeof(*prstatus)); reg = &prstatus->pr_reg; for (i = 0; i < 32; i++) { - reg->gpr[i] = cpu_to_be64(cpu->env.gpr[i]); + reg->gpr[i] = cpu_convert_to_target64(cpu->env.gpr[i], endian); } - reg->nip = cpu_to_be64(cpu->env.nip); - reg->msr = cpu_to_be64(cpu->env.msr); - reg->ctr = cpu_to_be64(cpu->env.ctr); - reg->link = cpu_to_be64(cpu->env.lr); - reg->xer = cpu_to_be64(cpu_read_xer(&cpu->env)); + reg->nip = cpu_convert_to_target64(cpu->env.nip, endian); + reg->msr = cpu_convert_to_target64(cpu->env.msr, endian); + reg->ctr = cpu_convert_to_target64(cpu->env.ctr, endian); + reg->link = cpu_convert_to_target64(cpu->env.lr, endian); + reg->xer = cpu_convert_to_target64(cpu_read_xer(&cpu->env), endian); cr = 0; for (i = 0; i < 8; i++) { cr |= (cpu->env.crf[i] & 15) << (4 * (7 - i)); } - reg->ccr = cpu_to_be64(cr); + reg->ccr = cpu_convert_to_target64(cr, endian); } -static void ppc64_write_elf64_fpregset(Note *note, PowerPCCPU *cpu) +static void ppc64_write_elf64_fpregset(Note *note, PowerPCCPU *cpu, int endian) { int i; struct PPC64ElfFpregset *fpregset; - note->hdr.n_type = cpu_to_be32(NT_PRFPREG); + note->hdr.n_type = cpu_convert_to_target32(NT_PRFPREG, endian); fpregset = ¬e->contents.fpregset; memset(fpregset, 0, sizeof(*fpregset)); for (i = 0; i < 32; i++) { - fpregset->fpr[i] = cpu_to_be64(cpu->env.fpr[i]); + fpregset->fpr[i] = cpu_convert_to_target64(cpu->env.fpr[i], endian); } - fpregset->fpscr = cpu_to_be64(cpu->env.fpscr); + fpregset->fpscr = cpu_convert_to_target64(cpu->env.fpscr, endian); } -static void ppc64_write_elf64_vmxregset(Note *note, PowerPCCPU *cpu) +static void ppc64_write_elf64_vmxregset(Note *note, PowerPCCPU *cpu, int endian) { int i; struct PPC64ElfVmxregset *vmxregset; - note->hdr.n_type = cpu_to_be32(NT_PPC_VMX); + note->hdr.n_type = cpu_convert_to_target32(NT_PPC_VMX, endian); vmxregset = ¬e->contents.vmxregset; memset(vmxregset, 0, sizeof(*vmxregset)); for (i = 0; i < 32; i++) { - vmxregset->avr[i].u64[0] = cpu_to_be64(cpu->env.avr[i].u64[0]); - vmxregset->avr[i].u64[1] = cpu_to_be64(cpu->env.avr[i].u64[1]); + vmxregset->avr[i].u64[0] = + cpu_convert_to_target64(cpu->env.avr[i].u64[0], endian); + vmxregset->avr[i].u64[1] = + cpu_convert_to_target64(cpu->env.avr[i].u64[1], endian); } - vmxregset->vscr.u32[3] = cpu_to_be32(cpu->env.vscr); + vmxregset->vscr.u32[3] = cpu_convert_to_target32(cpu->env.vscr, endian); } -static void ppc64_write_elf64_vsxregset(Note *note, PowerPCCPU *cpu) +static void ppc64_write_elf64_vsxregset(Note *note, PowerPCCPU *cpu, int endian) { int i; struct PPC64ElfVsxregset *vsxregset; - note->hdr.n_type = cpu_to_be32(NT_PPC_VSX); + note->hdr.n_type = cpu_convert_to_target32(NT_PPC_VSX, endian); vsxregset = ¬e->contents.vsxregset; memset(vsxregset, 0, sizeof(*vsxregset)); for (i = 0; i < 32; i++) { - vsxregset->vsr[i] = cpu_to_be64(cpu->env.vsr[i]); + vsxregset->vsr[i] = cpu_convert_to_target64(cpu->env.vsr[i], endian); } } -static void ppc64_write_elf64_speregset(Note *note, PowerPCCPU *cpu) +static void ppc64_write_elf64_speregset(Note *note, PowerPCCPU *cpu, int endian) { struct PPC64ElfSperegset *speregset; - note->hdr.n_type = cpu_to_be32(NT_PPC_SPE); + note->hdr.n_type = cpu_convert_to_target32(NT_PPC_SPE, endian); speregset = ¬e->contents.speregset; memset(speregset, 0, sizeof(*speregset)); - speregset->spe_acc = cpu_to_be64(cpu->env.spe_acc); - speregset->spe_fscr = cpu_to_be32(cpu->env.spe_fscr); + speregset->spe_acc = cpu_convert_to_target64(cpu->env.spe_acc, endian); + speregset->spe_fscr = cpu_convert_to_target32(cpu->env.spe_fscr, endian); } static const struct NoteFuncDescStruct { int contents_size; - void (*note_contents_func)(Note *note, PowerPCCPU *cpu); + void (*note_contents_func)(Note *note, PowerPCCPU *cpu, int endian); } note_func[] = { {sizeof(((Note *)0)->contents.prstatus), ppc64_write_elf64_prstatus}, {sizeof(((Note *)0)->contents.fpregset), ppc64_write_elf64_fpregset}, @@ -222,13 +224,15 @@ static int ppc64_write_all_elf64_notes(const char *note_name, int ret = -1; int note_size; const NoteFuncDesc *nf; + DumpState *s = opaque; + int endian = s->dump_info.d_endian; for (nf = note_func; nf->note_contents_func; nf++) { - note.hdr.n_namesz = cpu_to_be32(sizeof(note.name)); - note.hdr.n_descsz = cpu_to_be32(nf->contents_size); + note.hdr.n_namesz = cpu_convert_to_target32(sizeof(note.name), endian); + note.hdr.n_descsz = cpu_convert_to_target32(nf->contents_size, endian); strncpy(note.name, note_name, sizeof(note.name)); - (*nf->note_contents_func)(¬e, cpu); + (*nf->note_contents_func)(¬e, cpu, endian); note_size = sizeof(note) - sizeof(note.contents) + nf->contents_size; ret = f(¬e, note_size, opaque);