From patchwork Thu Feb 28 20:25:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 159445 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp1096844jad; Thu, 28 Feb 2019 12:38:31 -0800 (PST) X-Google-Smtp-Source: APXvYqyB+l5d+gskaZKiCZvJpfKySwLCRCivwgaLVBZq/+O4ScZkuKU7mgWyr/SgMpIxX33dQWe8 X-Received: by 2002:a25:3482:: with SMTP id b124mr1220410yba.23.1551386311243; Thu, 28 Feb 2019 12:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551386311; cv=none; d=google.com; s=arc-20160816; b=0MPiQFrIn203LO9T5KoowjEsZEqfBodLwtpgOCf2SiYOKb/3OT4sKoi505hujRy9V4 8oPPf8LcVRSRda2H3/sJ2dHrc55zwfCsdRZViHyor1o0FbFBkrpofqegczQe/KxxK/mj UglaWivZJEnaj4pDhiwpooiiIR1mkkddjs4fcq28KG0kFtTzk6zx4B4lgltSWlcXp6gW QWxMPDL4DZPCUH74oeOginze0Feoq2PMUHlXFmJSXIj8Iu1DRzM5GoKutU8q151b91Ej Jw/UMQ/MAFJU9EyaixQbP2MzaMgWXOldVCdP9BBIke8rmqiLP//sFqEHvY9Cdj9CQT2H ImjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=LOsSu8Eq6x2dR75aHJwrZ0rC0QsKzLcjJP/Aa5vKmvA=; b=DyOeoEFQeCOv/k5w4AWbiYrUQXdiIB85fNS4w96DJBTUPWx3SMNQ6LZVX3elfI9z0a wMYA0fWAxQgW/fDaD70wf+JJ9to1g/eWYpAT/AKooPL3oNcbv6OsS5uq3GaIlAntjSpl HqiON3DNpNVBFX9cqhVfRwFiuLXa+YLfzrMalvx1RRYgmANzXZ9b/2uwQsPmbmsL1amQ J5D+RChf2oM1CoII2U8ti+NuWfZiSjkrBtdVnQxJEO7fP8dia+F2MUKWo5+7XCh328pz JFewqy08DkcjWzL5a66b0uUonPNv675qglEFQhYlMe6vBbxG1K15y5qWB9wOMnnH/voQ UriQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VDw+NH4i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f68si10822076yba.424.2019.02.28.12.38.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 12:38:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VDw+NH4i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:46151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzSRq-00013R-NK for patch@linaro.org; Thu, 28 Feb 2019 15:38:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzSFY-0000Rf-6U for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzSFW-0007Ml-Uo for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:48 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:54225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzSFW-0007M3-LY for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:46 -0500 Received: by mail-wm1-x344.google.com with SMTP id e74so10415384wmg.3 for ; Thu, 28 Feb 2019 12:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LOsSu8Eq6x2dR75aHJwrZ0rC0QsKzLcjJP/Aa5vKmvA=; b=VDw+NH4ic/19NGaqLC8VDVdOSp56nRzTKAuabRUq3uz0EWhSJvOTGzw86nilzBaEpi U6cgYxFmRSeQGOOAF8ke7q215bWJAvYEDDcFy26AYfjmS/qL2H4k7Q3PAHrVYECbjKO5 LS5VI2fjDWRAUPVpAXRZVMROAC2REcVIJmPzu6cknTaqfJYm1ns40QdLyPvNmPMGct3Z vEStKmIJ7Q6oo4JMtHuVNczfooXUkTNTOXLCIy7Daabel9Q80di1YPPFqYz0D7Lk3brt aVOP7LvVjii3dxIoGy0frzZgl27gxlcbxgyMsGMpKAmz6l0SjvVImdL1BY7wd5WCNwLA pqQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LOsSu8Eq6x2dR75aHJwrZ0rC0QsKzLcjJP/Aa5vKmvA=; b=biShVnftfLWRzLBvzj1W2nhqbRwoWlBIRr8PtxGfVlXjT3aoOs4S2C3x9cJcPm7Nwl 3i1bDxlbHJ5JcFuAw9Vh4n8XanetjkOEKgcIRymqIXgyN5sf6p8hqRJyVlaLdsLAE40K EgjnpPyULCKB+hUWQbX2V0PA+TtoDGg/uVnPdsls6nazGPtsDVKEQoHG2Hpw2jDqiC/F Wa7+TYsiY8YTOB516xVeDY9KWsBgue4nlJVy8QDwgwzprLC2m8G2xUfxDzWjCg1JXP/M sF7QAQBHIThTZLFdbFK5be2Rzen2alPBvlawT2DgPhHfNxorL0Tu7qXK9ZX2+1GR9F0O iKkg== X-Gm-Message-State: AHQUAubAtGPAyHoGGAswM1+dv3ioS5s4resel1JfU8zO+JBmxuf707UK kl8LQVKWFfrOef0f1aUOKkEqpg== X-Received: by 2002:a1c:2545:: with SMTP id l66mr883568wml.96.1551385545545; Thu, 28 Feb 2019 12:25:45 -0800 (PST) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c18sm5162234wre.88.2019.02.28.12.25.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 12:25:41 -0800 (PST) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C17881FF8B; Thu, 28 Feb 2019 20:25:37 +0000 (UTC) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2019 20:25:29 +0000 Message-Id: <20190228202537.4638-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228202537.4638-1-alex.bennee@linaro.org> References: <20190228202537.4638-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PATCH v2 08/16] tests/tcg/arm: add ARMv6-M UNDEFINED 32-bit instruction test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: edgar.iglesias@gmail.com, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , Stefan Hajnoczi , jcmvbkbc@gmail.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Stefan Hajnoczi Test that 32-bit instructions declared UNDEFINED in the ARMv6-M Reference Manual really do raise an exception. Also test that the 6 32-bit instructions defined in the ARMv6-M Reference Manual do not raise an exception. Based-on: <20181029194519.15628-1-stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi Message-Id: <20181129185113.30353-1-stefanha@redhat.com> [AJB: integrated into system tests] Signed-off-by: Alex Bennée --- v2 - added to series - used softmmu-target Makefile with single compile/link step - launches with -kernel - drop .hex file --- tests/tcg/arm/Makefile.softmmu-target | 29 +++++ tests/tcg/arm/test-armv6m-undef.S | 154 ++++++++++++++++++++++++++ tests/tcg/arm/test-armv6m-undef.ld | 21 ++++ 3 files changed, 204 insertions(+) create mode 100644 tests/tcg/arm/Makefile.softmmu-target create mode 100644 tests/tcg/arm/test-armv6m-undef.S create mode 100644 tests/tcg/arm/test-armv6m-undef.ld -- 2.20.1 diff --git a/tests/tcg/arm/Makefile.softmmu-target b/tests/tcg/arm/Makefile.softmmu-target new file mode 100644 index 0000000000..49d48d8a1c --- /dev/null +++ b/tests/tcg/arm/Makefile.softmmu-target @@ -0,0 +1,29 @@ +# -*- Mode: makefile -*- +# +# ARM SoftMMU tests - included from tests/tcg/Makefile +# + +ifeq ($(TARGET_ABI_DIR),arm) + +ARM_SRC=$(SRC_PATH)/tests/tcg/arm + +# Set search path for all sources +VPATH += $(ARM_SRC) + +ARM_TESTS=test-armv6m-undef + +TESTS += $(ARM_TESTS) + +CFLAGS+=-Wl,--build-id=none -x assembler-with-cpp +LDFLAGS+=-nostdlib -N -static + +%: %.S %.ld + $(CC) $(CFLAGS) $(ASFLAGS) $< -o $@ $(LDFLAGS) -T $(ARM_SRC)/$@.ld + +# Specific Test Rules + +test-armv6m-undef: EXTRA_CFLAGS+=-mcpu=cortex-m0 + +run-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel + +endif diff --git a/tests/tcg/arm/test-armv6m-undef.S b/tests/tcg/arm/test-armv6m-undef.S new file mode 100644 index 0000000000..d18ca56b4a --- /dev/null +++ b/tests/tcg/arm/test-armv6m-undef.S @@ -0,0 +1,154 @@ +/* + * Test ARMv6-M UNDEFINED 32-bit instructions + * + * Copyright 2018 Red Hat Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 + * or later. See the COPYING file in the top-level directory. + */ + +/* + * Test that UNDEFINED 32-bit instructions fault as expected. This is an + * interesting test because ARMv6-M shares code with its more fully-featured + * siblings and it's necessary to verify that its limited instruction set is + * emulated correctly. + * + * The emulator must be invoked with -semihosting so that the test case can + * terminate with exit code 0 on success or 1 on failure. + * + * Failures can be debugged with -d in_asm,int,exec,cpu and the + * gdbstub (-S -s). + */ + +.syntax unified +.cpu cortex-m0 +.thumb + +/* + * Memory map + */ +#define SRAM_BASE 0x20000000 +#define SRAM_SIZE (16 * 1024) + +/* + * Semihosting interface on ARM T32 + * See "Semihosting for AArch32 and AArch64 Version 2.0 Documentation" by ARM + */ +#define semihosting_call bkpt 0xab +#define SYS_EXIT 0x18 + +vector_table: + .word SRAM_BASE + SRAM_SIZE /* 0. SP_main */ + .word exc_reset_thumb /* 1. Reset */ + .word 0 /* 2. NMI */ + .word exc_hard_fault_thumb /* 3. HardFault */ + .rept 7 + .word 0 /* 4-10. Reserved */ + .endr + .word 0 /* 11. SVCall */ + .word 0 /* 12. Reserved */ + .word 0 /* 13. Reserved */ + .word 0 /* 14. PendSV */ + .word 0 /* 15. SysTick */ + .rept 32 + .word 0 /* 16-47. External Interrupts */ + .endr + +exc_reset: +.equ exc_reset_thumb, exc_reset + 1 +.global exc_reset_thumb + /* The following 32-bit UNDEFINED instructions are tested by executing + * them. The HardFault exception handler should execute and return to + * the next test case. If no exception is raised the test fails. + */ + + /* Table A5-9 32-bit Thumb encoding */ + .short 0b1110100000000000 + .short 0b0000000000000000 + b not_reached + .short 0b1110100000000000 + .short 0b1000000000000000 + b not_reached + .short 0b1111100000000000 + .short 0b0000000000000000 + b not_reached + .short 0b1111100000000000 + .short 0b1000000000000000 + b not_reached + .short 0b1111000000000000 + .short 0b0000000000000000 + b not_reached + + /* Table A5-10 Branch and miscellaneous control instructions */ + .short 0b1111011111110000 + .short 0b1010000000000000 + b not_reached + + /* The following are valid 32-bit instructions that must not raise a + * HardFault. + */ + + /* B4.2.3 Move to Special Register (moves to IPSR are ignored) */ + msr ipsr, r0 + b 1f + b not_reached +1: + /* B4.2.2 Move from Special Register */ + mrs r0, ipsr + b 1f + b not_reached +1: + /* A6.7.13 Branch with Link (immediate) */ + bl 1f +1: + b 1f + b not_reached +1: + /* A6.7.21 Data Memory Barrier */ + dmb + b 1f + b not_reached +1: + /* A6.7.22 Data Synchronization Barrier */ + dsb + b 1f + b not_reached +1: + /* A6.7.24 Instruction Memory Barrier */ + isb + b 1f + b not_reached +1: + + /* Success! */ + movs r0, 1 + b exit + +not_reached: /* Failure :( */ + movs r0, 0 + b exit + +/* When a HardFault occurs, return to pc+6 (test cases are 3 halfwords long) */ +exc_hard_fault: +.equ exc_hard_fault_thumb, exc_hard_fault + 1 +.global exc_hard_fault_thumb + ldr r0, [sp, 0x18] + adds r0, 6 + str r0, [sp, 0x18] + bx lr + +/* + * exit: Terminate emulator + * @r0: 0 - failure, 1 - success + */ +exit: + movs r1, 0 + cmp r0, 1 + bne 1f + ldr r1, ADP_Stopped_ApplicationExit +1: + movs r0, SYS_EXIT + semihosting_call +.align 2 +ADP_Stopped_ApplicationExit: + .word 0x20026 diff --git a/tests/tcg/arm/test-armv6m-undef.ld b/tests/tcg/arm/test-armv6m-undef.ld new file mode 100644 index 0000000000..43dbbf17d5 --- /dev/null +++ b/tests/tcg/arm/test-armv6m-undef.ld @@ -0,0 +1,21 @@ +ENTRY(exc_reset_thumb) + +SECTIONS +{ + . = 0x0; + .text : { + *(.text) + } + .data : { + *(.data) + } + .rodata : { + *(.rodata) + } + .bss : { + *(.bss) + } + /DISCARD/ : { + *(.ARM.attributes) + } +}