From patchwork Mon Mar 21 11:33:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 8631921 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 DE4DD9F36E for ; Mon, 21 Mar 2016 11:34:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 124FE202BE for ; Mon, 21 Mar 2016 11:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AA3920204 for ; Mon, 21 Mar 2016 11:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754959AbcCULd7 (ORCPT ); Mon, 21 Mar 2016 07:33:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53018 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755164AbcCULd6 (ORCPT ); Mon, 21 Mar 2016 07:33:58 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 07D78B8914; Mon, 21 Mar 2016 11:33:58 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-39.ams2.redhat.com [10.36.112.39]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2LBXeLl024562; Mon, 21 Mar 2016 07:33:55 -0400 From: Laurent Vivier To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: drjones@redhat.com, thuth@redhat.com, dgibson@redhat.com, pbonzini@redhat.com, Laurent Vivier Subject: [kvm-unit-tests PATCH v2 5/5] powerpc: Check lswx in little-endian mode. Date: Mon, 21 Mar 2016 12:33:34 +0100 Message-Id: <1458560014-28862-6-git-send-email-lvivier@redhat.com> In-Reply-To: <1458560014-28862-1-git-send-email-lvivier@redhat.com> References: <1458560014-28862-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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 For lswx in little-endian mode, an alignment interrupt occurs. Signed-off-by: Laurent Vivier Reviewed-by: Thomas Huth --- powerpc/emulator.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/powerpc/emulator.c b/powerpc/emulator.c index 8d0dde2..87ef4a9 100644 --- a/powerpc/emulator.c +++ b/powerpc/emulator.c @@ -7,6 +7,7 @@ static int verbose; static int volatile is_invalid; +static int volatile alignment; static void program_check_handler(struct pt_regs *regs, void *opaque) { @@ -30,6 +31,18 @@ static void program_check_handler(struct pt_regs *regs, void *opaque) regs->nip += 4; } +static void alignment_handler(struct pt_regs *regs, void *opaque) +{ + int *data = opaque; + + printf("Detected alignment exception 0x%016lx: %08x\n", + regs->nip, *(uint32_t*)regs->nip); + + *data = 1; + + regs->nip += 4; +} + static void test_illegal(void) { report_prefix_push("invalid"); @@ -73,6 +86,8 @@ static void test_64bit(void) * - RT <= RA or RB < RT + (n + 4) is invalid or result is undefined * - RT == RA == 0 is invalid * + * For lswx in little-endian mode, an alignment interrupt always occurs. + * */ static void test_lswx(void) @@ -90,6 +105,7 @@ static void test_lswx(void) /* check incomplete register filling */ + alignment = 0; asm volatile ("mtxer %[len];" "li r12,-1;" "mr r11, r12;" @@ -103,7 +119,12 @@ static void test_lswx(void) : "xer", "r11", "r12", "memory"); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + report("alignment", alignment); + return; +#else report("partial", regs[0] == 0x01020300 && regs[1] == (uint64_t)-1); +#endif /* check an old know bug: the number of bytes is used as * the number of registers, so try 32 bytes. @@ -200,6 +221,7 @@ int main(int argc, char **argv) int i; handle_exception(0x700, program_check_handler, (void *)&is_invalid); + handle_exception(0x600, alignment_handler, (void *)&alignment); for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-v") == 0) {