From patchwork Fri Aug 9 07:00:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rusty Russell X-Patchwork-Id: 265894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C070D2C00CF for ; Fri, 9 Aug 2013 17:01:31 +1000 (EST) Received: from localhost ([::1]:53231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7ghV-0001pL-N9 for incoming@patchwork.ozlabs.org; Fri, 09 Aug 2013 03:01:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7ghE-0001p5-75 for qemu-devel@nongnu.org; Fri, 09 Aug 2013 03:01:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7gh9-0001oo-Os for qemu-devel@nongnu.org; Fri, 09 Aug 2013 03:01:12 -0400 Received: from ozlabs.org ([203.10.76.45]:50831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7gh9-0001oh-Ch for qemu-devel@nongnu.org; Fri, 09 Aug 2013 03:01:07 -0400 Received: by ozlabs.org (Postfix, from userid 1011) id 0BBF62C009F; Fri, 9 Aug 2013 17:01:04 +1000 (EST) From: Rusty Russell To: Andreas =?utf-8?Q?F=C3=A4rber?= , Anthony Liguori In-Reply-To: <5203AB19.9070505@suse.de> References: <1375938949-22622-1-git-send-email-rusty@rustcorp.com.au> <1375938949-22622-2-git-send-email-rusty@rustcorp.com.au> <87li4cgvh1.fsf@codemonkey.ws> <5203AB19.9070505@suse.de> User-Agent: Notmuch/0.15.2+81~gd2c8818 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Fri, 09 Aug 2013 16:30:38 +0930 Message-ID: <87li4bnyax.fsf@rustcorp.com.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 203.10.76.45 Cc: qemu-devel@nongnu.org, anton@samba.org Subject: Re: [Qemu-devel] [PATCH 1/7] virtio: allow byte swapping for vring and config access 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 Andreas Färber writes: > Am 08.08.2013 15:31, schrieb Anthony Liguori: >> Rusty Russell writes: >> We have a mechanism to do weak functions via stubs/. I think it would >> be better to do cpu_get_byteswap() as a stub function and then overload >> it in the ppc64 code. > > If this as your name indicates is a per-CPU function then it should go > into CPUClass. Interesting question is, what is virtio supposed to do if > we have two ppc CPUs, one is Big Endian, the other is Little Endian. > We'd need to check current_cpu then, which for Xen is always NULL. Below is the minimal solution, which is sufficient for virtio. If Anton wants per-cpu endianness for gdb, he'll need something more sophisticated. Feedback welcome! Rusty. Subject: cpu_get_byteswap: function for endian-ambivalent targets. Signed-off-by: Rusty Russell diff --git a/include/qom/cpu.h b/include/qom/cpu.h index a5bb515..ed84267 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -357,4 +357,13 @@ void cpu_reset_interrupt(CPUState *cpu, int mask); */ void cpu_resume(CPUState *cpu); +/** + * cpu_get_byteswap: + * + * Is (any) CPU running in byteswapped mode: normally false. This + * doesn't take a cpu argument, because we don't support heterogeneous + * endianness. + */ +bool cpu_get_byteswap(void); + #endif diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 9b701b4..d4af94a 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -25,3 +25,4 @@ stub-obj-y += vm-stop.o stub-obj-y += vmstate.o stub-obj-$(CONFIG_WIN32) += fd-register.o stub-obj-y += cpus.o +stub-obj-y += cpu_byteswap.o diff --git a/stubs/cpu_byteswap.c b/stubs/cpu_byteswap.c new file mode 100644 index 0000000..b3b669f --- /dev/null +++ b/stubs/cpu_byteswap.c @@ -0,0 +1,6 @@ +#include "qom/cpu.h" + +bool cpu_get_byteswap(void) +{ + return false; +} Subject: target-ppc: ppc64 targets can be either endian. In this case, we just query the first cpu. Signed-off-by: Rusty Russell diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c index 616aab6..0a508eb 100644 --- a/target-ppc/misc_helper.c +++ b/target-ppc/misc_helper.c @@ -116,3 +116,8 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value) { hreg_store_msr(env, value, 0); } + +bool cpu_get_byteswap(void) +{ + return first_cpu->hflags & (1 << MSR_LE); +}