From patchwork Thu Dec 2 20:48:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 519767 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp1173294imb; Thu, 2 Dec 2021 12:59:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1gCvjeYRL2iAY7ekRpwl/T4sXuIz8HXTDL7LlZYsIt3jZEOekaYLyS0ZjH1tVblZZHE2f X-Received: by 2002:ac8:5745:: with SMTP id 5mr16434910qtx.85.1638478743674; Thu, 02 Dec 2021 12:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638478743; cv=none; d=google.com; s=arc-20160816; b=TS4n6vI2eRf7+gfGR1mMnjC46dd7jv+pKAylnsTcoeHH1p2Uh40UMhXXCfv0H3/ote iAiCv6dQ4BwQMlHLVx5he9CtVrKZ37di910ta0G2ogO8RNrrGyq/0eq5IvWncghYHbg8 GXupZgPQ9qb8S/9odMU/UjD6E+GRJUakKE9fSQ9BRwEyM2SGQxZiygruUjSTM6slUa5I INhjtf7RFgqmp7VyetkhhbcOsEzxtM6g7qpJlAD9h2J06jRCKIAxtVDfAQFEjoVHMwQh LJsNs8Lj/9pYpvhI/S5GNecb0iPrtdvZIDiFrltr6jqO72gwDkkpwpf8R5nVGpNJqRA2 lldg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=1iKqCq5gnBEuV7yETH5boxm9MvdrrB2fADfIX32vfoE=; b=l9TmaLEdJGqC71HVprQIellO2efniln8QkI2SVp273+3bdRZI43q0f+J+bUEB+n0Uu wQfHGXXCbfrV0oJ4kGT+qAIiRQ9QqQiBadprMuyuJu3/bb4TNjfa4J8IMmCscS32/Xlr ERi/vQ7dq5vt3e0aFyK8xySM7p4GPbJ2tkgqX3+mmOLzP/BOtwun97Ru9f6s0ClTL0aF M+Ha7BLZ1dQYRz/Ph4J9GwiURxFtkPz+A56pXNuzsaBGMSxjVsSriZpjFPzZeuMNFPEs 2NVjzhw0jx+9jHV2KSbY1zWvDPG1yulEMPMOWGZsRCfT/O5dM36ZEYyawy18mWgrmEHD CULw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B46Qilzq; 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=pass (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 h9si1103471qtk.504.2021.12.02.12.59.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Dec 2021 12:59:03 -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=pass header.i=@linaro.org header.s=google header.b=B46Qilzq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mstAV-0002sI-3W for patch@linaro.org; Thu, 02 Dec 2021 15:59:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mst0z-00009L-Nn for qemu-devel@nongnu.org; Thu, 02 Dec 2021 15:49:14 -0500 Received: from [2607:f8b0:4864:20::436] (port=34799 helo=mail-pf1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mst0x-0005Vy-S2 for qemu-devel@nongnu.org; Thu, 02 Dec 2021 15:49:13 -0500 Received: by mail-pf1-x436.google.com with SMTP id r130so750088pfc.1 for ; Thu, 02 Dec 2021 12:49:11 -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=1iKqCq5gnBEuV7yETH5boxm9MvdrrB2fADfIX32vfoE=; b=B46QilzquCUJMPkOEwVfv6LN32acyFT987HJOEAb4tmKeVNbrORiB2WLtZ1NKoi4eb duf/B3C9lvrZ8GBKJLuYmDnglvSGkm2Jzqvad7Y2mN7P9OME5MLrBJZd7157xl4mS6TD w9eEwYTZl8VXQ0xdHSp/Uc1iBVUtfNy1a/NBGejt2me1MloNNerom+EoY4tHQreXAqaq GfeDrpnQFvlUySKDQDSQpVB99Zu+GfClBiKN1rdeAZ/IjPI2jPvdqQUWpm7c3CozPQW2 hKxUhPoPKyF1TjFRfpVDtiZiP0CygtGLNz9T8b0RLuyb0Z29M2fDzbont4A1/62+pb27 99tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1iKqCq5gnBEuV7yETH5boxm9MvdrrB2fADfIX32vfoE=; b=QnpTatsKR8utID+H2pSVMTgPniTUh4D5tXyis5grxviGA7egx+3oR50puseDs7xTE7 onDZ6kEPztW7MMHKL0JVV6+wZh9s6vRL9AhXH2Bz1QwMdDpjmsf0lp1J1w0snJoUSOAY fry7g62Jnxsly0d84EjGy9DvBIcC9NcHfqciFQHD8r0GW2OBBeUFrydXe38njeZwd/Hg yxd5aN8yPJf0pfTIQHI+9+60qkFrcfU2k5FoviDQ6QYASES4hvwYaspKmr435/70IGU1 Zeq6hijHTqaP0VoNCBHMKn96Segj0l1cUfxdaSSnbZ22MdNpUfVwdxJu0tVOdx+1gbLT ecOA== X-Gm-Message-State: AOAM533o/DJBxf641xP34AIc4wW3FAM9IokAC2HV6D6liOw5U26noVPT UY1/+t24hh8U4B49Xh+3nCet3x1bSJXNFA== X-Received: by 2002:aa7:8e52:0:b0:4a1:5820:d9cc with SMTP id d18-20020aa78e52000000b004a15820d9ccmr15118425pfr.49.1638478150607; Thu, 02 Dec 2021 12:49:10 -0800 (PST) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id pi17sm3721391pjb.34.2021.12.02.12.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 12:49:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/15] tests/tcg/m68k: Add trap.c Date: Thu, 2 Dec 2021 12:48:58 -0800 Message-Id: <20211202204900.50973-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211202204900.50973-1-richard.henderson@linaro.org> References: <20211202204900.50973-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::436 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Test various trap instructions: chk, div, trap, trapv, trapcc, ftrapcc, and the signals and addresses that we expect from them. Signed-off-by: Richard Henderson --- tests/tcg/m68k/trap.c | 129 +++++++++++++++++++++++++++++++++ tests/tcg/m68k/Makefile.target | 3 + 2 files changed, 132 insertions(+) create mode 100644 tests/tcg/m68k/trap.c diff --git a/tests/tcg/m68k/trap.c b/tests/tcg/m68k/trap.c new file mode 100644 index 0000000000..08ab56b2ca --- /dev/null +++ b/tests/tcg/m68k/trap.c @@ -0,0 +1,129 @@ +/* + * Test m68k trap addresses. + */ + +#define _GNU_SOURCE 1 +#include +#include +#include + +static int expect_sig; +static int expect_si_code; +static void *expect_si_addr; +static greg_t expect_mc_pc; +static volatile int got_signal; + +static void sig_handler(int sig, siginfo_t *si, void *puc) +{ + ucontext_t *uc = puc; + mcontext_t *mc = &uc->uc_mcontext; + + assert(sig == expect_sig); + assert(si->si_code == expect_si_code); + assert(si->si_addr == expect_si_addr); + assert(mc->gregs[R_PC] == expect_mc_pc); + + got_signal = 1; +} + +#define FMT_INS [ad] "a"(&expect_si_addr), [pc] "a"(&expect_mc_pc) +#define FMT0_STR(S) \ + "move.l #1f, (%[ad])\n\tmove.l #1f, (%[pc])\n" S "\n1:\n" +#define FMT2_STR(S) \ + "move.l #0f, (%[ad])\n\tmove.l #1f, (%[pc])\n" S "\n1:\n" + +#define CHECK_SIG do { assert(got_signal); got_signal = 0; } while (0) + +int main(int argc, char **argv) +{ + struct sigaction act = { + .sa_sigaction = sig_handler, + .sa_flags = SA_SIGINFO + }; + int t0, t1; + + sigaction(SIGILL, &act, NULL); + sigaction(SIGTRAP, &act, NULL); + sigaction(SIGFPE, &act, NULL); + + expect_sig = SIGFPE; + expect_si_code = FPE_INTOVF; + asm volatile(FMT2_STR("0:\tchk %0, %1") : : "d"(0), "d"(-1), FMT_INS); + CHECK_SIG; + +#if 0 + /* FIXME: chk2 not correctly translated. */ + int bounds[2] = { 0, 1 }; + asm volatile(FMT2_STR("0:\tchk2.l %0, %1") + : : "m"(bounds), "d"(2), FMT_INS); + CHECK_SIG; +#endif + + asm volatile(FMT2_STR("cmp.l %0, %1\n0:\ttrapv") + : : "d"(INT_MIN), "d"(1), FMT_INS); + CHECK_SIG; + + asm volatile(FMT2_STR("cmp.l %0, %0\n0:\ttrapeq") + : : "d"(0), FMT_INS); + CHECK_SIG; + + asm volatile(FMT2_STR("cmp.l %0, %0\n0:\ttrapeq.w #0x1234") + : : "d"(0), FMT_INS); + CHECK_SIG; + + asm volatile(FMT2_STR("cmp.l %0, %0\n0:\ttrapeq.l #0x12345678") + : : "d"(0), FMT_INS); + CHECK_SIG; + + asm volatile(FMT2_STR("fcmp.x %0, %0\n0:\tftrapeq") + : : "f"(0.0L), FMT_INS); + CHECK_SIG; + + expect_si_code = FPE_INTDIV; + + asm volatile(FMT2_STR("0:\tdivs.w %1, %0") + : "=d"(t0) : "d"(0), "0"(1), FMT_INS); + CHECK_SIG; + + asm volatile(FMT2_STR("0:\tdivsl.l %2, %1:%0") + : "=d"(t0), "=d"(t1) : "d"(0), "0"(1), FMT_INS); + CHECK_SIG; + + expect_sig = SIGILL; + expect_si_code = ILL_ILLOPN; + asm volatile(FMT0_STR("trap #1") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #2") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #3") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #4") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #5") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #6") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #7") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #8") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #9") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #10") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #11") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #12") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #13") : : FMT_INS); + CHECK_SIG; + asm volatile(FMT0_STR("trap #14") : : FMT_INS); + CHECK_SIG; + + expect_sig = SIGTRAP; + expect_si_code = TRAP_BRKPT; + asm volatile(FMT0_STR("trap #15") : : FMT_INS); + CHECK_SIG; + + return 0; +} diff --git a/tests/tcg/m68k/Makefile.target b/tests/tcg/m68k/Makefile.target index 62f109eef4..1163c7ef03 100644 --- a/tests/tcg/m68k/Makefile.target +++ b/tests/tcg/m68k/Makefile.target @@ -3,5 +3,8 @@ # m68k specific tweaks - specifically masking out broken tests # +VPATH += $(SRC_PATH)/tests/tcg/m68k +TESTS += trap + # On m68k Linux supports 4k and 8k pages (but 8k is currently broken) EXTRA_RUNS+=run-test-mmap-4096 # run-test-mmap-8192