From patchwork Mon Mar 21 11:33:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 8631891 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 966399F36E for ; Mon, 21 Mar 2016 11:33:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE711202C8 for ; Mon, 21 Mar 2016 11:33:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6375202E5 for ; Mon, 21 Mar 2016 11:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755190AbcCULdv (ORCPT ); Mon, 21 Mar 2016 07:33:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755164AbcCULdu (ORCPT ); Mon, 21 Mar 2016 07:33:50 -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 B2B878F2EC; Mon, 21 Mar 2016 11:33:49 +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 u2LBXeLi024562; Mon, 21 Mar 2016 07:33:47 -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 2/5] powerpc: add test to check invalid instruction trap Date: Mon, 21 Mar 2016 12:33:31 +0100 Message-Id: <1458560014-28862-3-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 Signed-off-by: Laurent Vivier Reviewed-by: Thomas Huth Reviewed-by: David Gibson --- v2: check program check type (invalid instruction) add "-v" parameter to display invalid instruction address powerpc/Makefile.common | 5 +++- powerpc/emulator.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 +++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 powerpc/emulator.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index ab2caf6..257e3fb 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -7,7 +7,8 @@ tests-common = \ $(TEST_DIR)/selftest.elf \ $(TEST_DIR)/spapr_hcall.elf \ - $(TEST_DIR)/rtas.elf + $(TEST_DIR)/rtas.elf \ + $(TEST_DIR)/emulator.elf all: $(TEST_DIR)/boot_rom.bin test_cases @@ -70,3 +71,5 @@ $(TEST_DIR)/selftest.elf: $(cstart.o) $(reloc.o) $(TEST_DIR)/selftest.o $(TEST_DIR)/spapr_hcall.elf: $(cstart.o) $(reloc.o) $(TEST_DIR)/spapr_hcall.o $(TEST_DIR)/rtas.elf: $(cstart.o) $(reloc.o) $(TEST_DIR)/rtas.o + +$(TEST_DIR)/emulator.elf: $(cstart.o) $(reloc.o) $(TEST_DIR)/emulator.o diff --git a/powerpc/emulator.c b/powerpc/emulator.c new file mode 100644 index 0000000..1d4f164 --- /dev/null +++ b/powerpc/emulator.c @@ -0,0 +1,65 @@ +/* + * Test some powerpc instructions + */ + +#include +#include + +static int verbose; +static int volatile is_invalid; + +static void program_check_handler(struct pt_regs *regs, void *opaque) +{ + int *data = opaque; + + if (verbose) { + printf("Detected invalid instruction 0x%016lx: %08x\n", + regs->nip, *(uint32_t*)regs->nip); + } + + /* the result is bit 16 to 19 of SRR1 + * bit 0: SRR0 contains the address of the next instruction + * bit 1: Trap + * bit 2: Privileged instruction + * bit 3: Illegal instruction + * bit 4: FP enabled exception type + */ + + *data = regs->msr >> 16; + + regs->nip += 4; +} + +static void test_illegal(void) +{ + report_prefix_push("invalid"); + + is_invalid = 0; + + asm volatile (".long 0"); + + report("exception", is_invalid == 8); /* illegal instruction */ + + report_prefix_pop(); +} + +int main(int argc, char **argv) +{ + int i; + + handle_exception(0x700, program_check_handler, (void *)&is_invalid); + + for (i = 0; i < argc; i++) { + if (strcmp(argv[i], "-v") == 0) { + verbose = 1; + } + } + + report_prefix_push("emulator"); + + test_illegal(); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 02b21c7..ed4fdbe 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -47,3 +47,6 @@ file = rtas.elf extra_params = -append "set-time-of-day" timeout = 5 groups = rtas + +[emulator] +file = emulator.elf