From: Laurent Vivier <lvivier@redhat.com>
To: Andrew Jones <drjones@redhat.com>
Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, thuth@redhat.com,
dgibson@redhat.com, agraf@suse.de, pbonzini@redhat.com
Subject: Re: [kvm-unit-tests PATCH v3 2/2] powerpc: select endianness
Date: Tue, 01 Mar 2016 08:12:19 +0000 [thread overview]
Message-ID: <56D54EE3.407@redhat.com> (raw)
In-Reply-To: <20160229194435.7bj42ap6fzfqgikd@hawk.localdomain>
On 29/02/2016 20:44, Andrew Jones wrote:
> On Mon, Feb 29, 2016 at 06:49:06PM +0100, Laurent Vivier wrote:
>> 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 <lvivier@redhat.com>
>> ---
>> 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
>
> redundant 'exit 1', usage() already has one in it
OK
>
>> + 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 <asm-generic/io.h>
>> #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%6 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
>
> We can avoid the #if.
>
> LOAD_REG_IMMEDIATE(r9, RTAS_MSR_MASK)
> and r11, r11, r9
>
> Right now we'll define RTAS_MSR_MASK to the boring value of
> 0xfffffffffffffffe, but presumably that'll change some day.
OK
>> + mtsrr0 r10
>> + mtsrr1 r11
>> + rfid
>> + b .
>> +
>> +rtas_return_loc:
>> + FIXUP_ENDIAN
>> ld r0, 16(r1)
>> mtlr r0
>> blr
>> --
>> 2.5.0
>
> Thanks,
> drew
>
Thanks,
Laurent
next prev parent reply other threads:[~2016-03-01 8:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 17:49 [kvm-unit-tests PATCH v3 0/2] powerpc: add little-endian support Laurent Vivier
2016-02-29 17:49 ` [kvm-unit-tests PATCH v3 1/2] powerpc: add asm/ppc_asm.h Laurent Vivier
2016-02-29 18:56 ` Andrew Jones
2016-03-01 8:30 ` Thomas Huth
2016-02-29 17:49 ` [kvm-unit-tests PATCH v3 2/2] powerpc: select endianness Laurent Vivier
2016-02-29 19:44 ` Andrew Jones
2016-03-01 8:12 ` Laurent Vivier [this message]
2016-03-01 8:40 ` Thomas Huth
2016-03-01 8:54 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56D54EE3.407@redhat.com \
--to=lvivier@redhat.com \
--cc=agraf@suse.de \
--cc=dgibson@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox