From patchwork Mon Feb 29 17:49:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 8456831 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AAA319F2F0 for ; Mon, 29 Feb 2016 17:49:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3D9F20115 for ; Mon, 29 Feb 2016 17:49:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92E4B2011B for ; Mon, 29 Feb 2016 17:49:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753508AbcB2RtY (ORCPT ); Mon, 29 Feb 2016 12:49:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42986 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753258AbcB2RtW (ORCPT ); Mon, 29 Feb 2016 12:49:22 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 95538AA7; Mon, 29 Feb 2016 17:49:21 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-40.ams2.redhat.com [10.36.112.40]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1THn9vg010574; Mon, 29 Feb 2016 12:49:18 -0500 From: Laurent Vivier To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: drjones@redhat.com, thuth@redhat.com, dgibson@redhat.com, agraf@suse.de, pbonzini@redhat.com, Laurent Vivier Subject: [kvm-unit-tests PATCH v3 2/2] powerpc: select endianness Date: Mon, 29 Feb 2016 18:49:06 +0100 Message-Id: <1456768146-10136-3-git-send-email-lvivier@redhat.com> In-Reply-To: <1456768146-10136-1-git-send-email-lvivier@redhat.com> References: <1456768146-10136-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows to build tests for ppc64 little endian target (ppc64le) on big and little endian hosts. We add a new parameter to configure to select the endianness of the tests (--endian=little or --endian=big). I have built and tested big and little endian tests on a little endian host, a big endian host, with kvm_hv and kvm_pr, and on x86_64 with ppc64 as a TCG target. Signed-off-by: Laurent Vivier --- configure | 11 +++++++++++ lib/powerpc/asm/ppc_asm.h | 19 +++++++++++++++++++ lib/ppc64/asm/io.h | 8 ++++++++ powerpc/Makefile.common | 3 ++- powerpc/Makefile.ppc64 | 9 +++++++-- powerpc/cstart64.S | 20 ++++++++++++++++---- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/configure b/configure index a685cca..90e39d4 100755 --- a/configure +++ b/configure @@ -10,6 +10,7 @@ ar=ar arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` host=$arch cross_prefix= +endian="" usage() { cat <<-EOF @@ -23,6 +24,7 @@ usage() { --ld=LD ld linker to use ($ld) --prefix=PREFIX where to install things ($prefix) --kerneldir=DIR kernel build directory for kvm.h ($kerneldir) + --endian=ENDIAN endianness to compile for (little or big, ppc64 only) EOF exit 1 } @@ -50,6 +52,9 @@ while [[ "$1" = -* ]]; do --cross-prefix) cross_prefix="$arg" ;; + --endian) + endian="$arg" + ;; --cc) cc="$arg" ;; @@ -84,6 +89,11 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then elif [ "$arch" = "ppc64" ]; then testdir=powerpc firmware="$testdir/boot_rom.bin" + if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then + echo "You must provide endianness (big or little)!" + usage + exit 1 + fi else testdir=$arch fi @@ -139,4 +149,5 @@ AR=$cross_prefix$ar API=$api TEST_DIR=$testdir FIRMWARE=$firmware +ENDIAN=$endian EOF diff --git a/lib/powerpc/asm/ppc_asm.h b/lib/powerpc/asm/ppc_asm.h index f63bb72..f18100e 100644 --- a/lib/powerpc/asm/ppc_asm.h +++ b/lib/powerpc/asm/ppc_asm.h @@ -11,4 +11,23 @@ #define LOAD_REG_ADDR(reg,name) \ ld reg,name@got(r2) +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + +#define FIXUP_ENDIAN + +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + +#define FIXUP_ENDIAN \ + .long 0x05000048; /* bl . + 4 */ \ + .long 0xa602487d; /* mflr r10 */ \ + .long 0x20004a39; /* addi r10,r10,32 */ \ + .long 0xa600607d; /* mfmsr r11 */ \ + .long 0x01006b69; /* xori r11,r11,1 */ \ + .long 0xa6035a7d; /* mtsrr0 r10 */ \ + .long 0xa6037b7d; /* mtsrr1 r11 */ \ + .long 0x2400004c; /* rfid */ \ + .long 0x00000048; /* b . */ \ + +#endif /* __BYTE_ORDER__ */ + #endif /* _ASMPOWERPC_PPC_ASM_H */ diff --git a/lib/ppc64/asm/io.h b/lib/ppc64/asm/io.h index c0801d4..4f2c31b 100644 --- a/lib/ppc64/asm/io.h +++ b/lib/ppc64/asm/io.h @@ -1,5 +1,13 @@ #ifndef _ASMPPC64_IO_H_ #define _ASMPPC64_IO_H_ + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define __cpu_is_be() (0) +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define __cpu_is_be() (1) +#else +#error Undefined byte order +#endif + #include #endif diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index cc27ac8..b526668 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -11,7 +11,6 @@ all: $(TEST_DIR)/boot_rom.bin test_cases ################################################################## -CFLAGS += $(arch_CFLAGS) CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -Wextra @@ -32,6 +31,7 @@ cflatobjs += lib/powerpc/setup.o cflatobjs += lib/powerpc/rtas.o FLATLIBS = $(libcflat) $(LIBFDT_archive) +%.elf: CFLAGS += $(arch_CFLAGS) %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(LD) $(LDFLAGS) -o $@ \ @@ -48,6 +48,7 @@ $(TEST_DIR)/boot_rom.bin: $(TEST_DIR)/boot_rom.elf dd if=/dev/zero of=$@ bs=256 count=1 $(OBJCOPY) -O binary $^ >(cat - >>$@) +$(TEST_DIR)/boot_rom.elf: CFLAGS = -mbig-endian $(TEST_DIR)/boot_rom.elf: $(TEST_DIR)/boot_rom.o $(LD) -EB -nostdlib -Ttext=0x100 --entry=start --build-id=none -o $@ $< diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index 2df44d4..3da3a83 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -5,8 +5,13 @@ # bits = 64 -arch_CFLAGS = -mbig-endian -arch_LDFLAGS = -EB +ifeq ($(ENDIAN),little) + arch_CFLAGS = -mlittle-endian + arch_LDFLAGS = -EL +else + arch_CFLAGS = -mbig-endian + arch_LDFLAGS = -EB +endif cstart.o = $(TEST_DIR)/cstart64.o reloc.o = $(TEST_DIR)/reloc64.o diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 6072597..62078a4 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -16,6 +16,7 @@ */ .globl start start: + FIXUP_ENDIAN /* * We were loaded at QEMU's kernel load address, but we're not * allowed to link there due to how QEMU deals with linker VMAs, @@ -84,12 +85,23 @@ halt: enter_rtas: mflr r0 std r0, 16(r1) + + LOAD_REG_ADDR(r10, rtas_return_loc) + mtlr r10 LOAD_REG_ADDR(r11, rtas_entry) ld r10, 0(r11) -//FIXME: change this bctrl to an rtas-prep, rfid, rtas-return sequence - mtctr r10 - nop - bctrl + + mfmsr r11 +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + xori r11,r11,1 +#endif + mtsrr0 r10 + mtsrr1 r11 + rfid + b . + +rtas_return_loc: + FIXUP_ENDIAN ld r0, 16(r1) mtlr r0 blr