From patchwork Thu Jun 2 01:33:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 578081 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp106664max; Wed, 1 Jun 2022 18:41:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKr2l5djjnv86M49BTdFvwad8TrBt3gaD7f6odfBKHXrh3u0607eTxeKl+cN98i6trCwAH X-Received: by 2002:a05:622a:1747:b0:304:b5c7:887f with SMTP id l7-20020a05622a174700b00304b5c7887fmr2138084qtk.628.1654134076097; Wed, 01 Jun 2022 18:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654134076; cv=none; d=google.com; s=arc-20160816; b=ps89Wp+eHz2eFR1WFz8phfysTq3Pduc0ew3lWAK3lTrEM5vyIHPwurTe0prhD2geSS KC9ky+z6vkpsdKLxVQH5ZDsq0F+rZWioZtUP8nH2U7AF367mfMHJ6DAw5lA9qYSkcL3z Jt1Xg9FhVF8MC8nSoHu3Q0vp1m2Kk2aT975/3rquSj21FlLLO+CGZd2nzw0lbngcc3q0 ly978Jcc/NG7CuSJnA71Q2VJ6xOOFJTD29bQWqaIVXGsPh93as6SuNPID0pI8H026l1T HPJlMu+h5ienZf8X/jvLJuwiXorFX94g/ShHJCqedzIi3b+tJq+GSJVhO+tJvvF7DhDU WZDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=Ec0dbY3Lo89Y5jy2prv7uGoDI+hJWJ+BkmpUFqfWdho=; b=GvOGoHdCX/7CjNUvwrsjQPOqbKPi6X5OZW9XViS6vyGxrbaPN9mXlPXKrouJv58Q8l PtqrK6MCTvknkb5fB2D5a6HiHUy2h63XeqAbc6iwm35EgRkcROcT8mouWFYY+TRNo9Or 8p3ioxADUvaRi9/WIiPqdLCAekmxFkFIw4GF4G2wAEzQjjOAx2mqReKMjj5PZKquddE/ sPAZCiVLz7i4jJs6kPprs0zazJn2730/kAV9UCoWc/kwzzjKBlto0wwLncLdDZikdQUv 5oYZ4AbeiybyQQHsYw0v0devzoMl2ORcOufMnNdU+cAOq85aBoyZnK9GnXKQW/rY7TIx z0Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y68fsTxs; 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 s131-20020a37a989000000b006a631b3d865si1651446qke.171.2022.06.01.18.41.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Jun 2022 18:41:16 -0700 (PDT) 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=y68fsTxs; 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]:58530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwZpr-0000bH-Ki for patch@linaro.org; Wed, 01 Jun 2022 21:41:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwZjN-0002jz-1p for qemu-devel@nongnu.org; Wed, 01 Jun 2022 21:34:33 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:36457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwZjJ-0005I9-RJ for qemu-devel@nongnu.org; Wed, 01 Jun 2022 21:34:32 -0400 Received: by mail-pj1-x1035.google.com with SMTP id u12-20020a17090a1d4c00b001df78c7c209so7975388pju.1 for ; Wed, 01 Jun 2022 18:34:22 -0700 (PDT) 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=Ec0dbY3Lo89Y5jy2prv7uGoDI+hJWJ+BkmpUFqfWdho=; b=y68fsTxszpmTWBuZ1q4Vt43XPX2n+F+Y5PVMLT9hdgrZIbdKBKTJTh3EOu+glZ4BvE SDVtKMf9eIO8N6KJaAW/vJN4UlbDiiD57yOhwC30v9UiT8seFdUEBeXik5rXX1GtkRtj XP0uQxlr9PJSQ/Emyni4jYTFk3QZlGW6lgAfRHw8mFiNuE7+9myrXpiFEJydxdnpcTC6 CK6Mt6nKKONw0q4Y79tVFKuocqG9Zh4GfF2THEBdBgFB+nSBSevO7zZA6FXhKORJvoyg gdA7uwWlI94U0uUZDVAEu/BtFdHjXEEsUeQzEZ3u5LW/9CF23d02gzWBRgSEkvkDU65E hNRw== 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=Ec0dbY3Lo89Y5jy2prv7uGoDI+hJWJ+BkmpUFqfWdho=; b=i0tzuwxs0hIJrXJTcvDtMMn/yr5o0ZbjXxvuikmP8vLhsx9WdT0kRvU/zKxfH/RjKK G2fHFkY/z/pk2YP3lLfGHiNWfjgs/KNeTZUlGkQsKTEW8l2yszbBm4fPKpkMJ32vaujW hhQmfJ03j4QgSw+vPIvuV629z4n1tmoyBsp9t95Q5WwYfqmTixUp+FLqW03tO4BBKEss mWaa8O6VdWIND1hQh5jfE+FHR41TEcBQb0zoWuPN+Ba/AsgQTrK8KDFxNs8qFcsvPnCX tOYkkhAjJZb4lCChRKB6RT+S+drbrPbAMvFpUf/YPjBi0mCk7SczvdA+ccsO1zRbm0Vw eR5g== X-Gm-Message-State: AOAM531C94HaVCV5fmSEb3pELXKkpIKd22cM53SC4ghiJECGFEA1wxrA zUmCN5evEBxuFXvmT7bhqgJFoB/kebreyQ== X-Received: by 2002:a17:90a:5c84:b0:1dc:9b42:f2cf with SMTP id r4-20020a17090a5c8400b001dc9b42f2cfmr37258335pji.123.1654133661361; Wed, 01 Jun 2022 18:34:21 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:1eca:8ee3:9269:e00c]) by smtp.gmail.com with ESMTPSA id l191-20020a6391c8000000b003fc5b1db26fsm1962875pge.52.2022.06.01.18.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 18:34:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH v6 14/17] tests/tcg/m68k: Add trap.c Date: Wed, 1 Jun 2022 18:33:58 -0700 Message-Id: <20220602013401.303699-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220602013401.303699-1-richard.henderson@linaro.org> References: <20220602013401.303699-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , 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. Reviewed-by: Laurent Vivier 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..96cac18d4d --- /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_ILLTRP; + 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