From patchwork Sat Apr 30 17:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568160 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7379014map; Sat, 30 Apr 2022 11:12:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA3js35aP+BvJIQfUEVg2AUPp8W9yRnnbPEDSnsoQv/CmWgKGwKsK0QWuOxrhxQxLVt9+x X-Received: by 2002:a37:6906:0:b0:69f:5a68:c2cd with SMTP id e6-20020a376906000000b0069f5a68c2cdmr3403642qkc.298.1651342351549; Sat, 30 Apr 2022 11:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651342351; cv=none; d=google.com; s=arc-20160816; b=MOEGza/RD+UN+/YD022cKWqPW/66eQvKwns1ZjMMPybko1183Of8lk79vzhKAKkfc9 ljJ82mme3M6MOiX8Z2dya7PeJ3BjMchhXo3UI24HzXIZ9uItezSpekxiGW6s+U+0mlqL PkoJjZVkErw9fb0osND4BIgkntdtfVppH9m5FJRT+TlkCulmaL2oX1EE7PaUTID3gXaW 5fRn/yewdqz6K7tWNquMacWMG3mytr99L4CU76euHFmSQ8NOZFqGFQPHvqrkNJlJuJ39 uFhEOrWV52kb+Q8B/Z/Kpx1iS+2Swt/pIAmLC7qZlPHMUmEPGx0mxdYZPep9ryJ8+WOx vJwQ== 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=oS4SpFhfIqgKlDgeO+bhyHZ/w+64dvw7Bn99nQxMQ8M=; b=UwUYdAazRejjZiqks1EMLheL1TXVNzqEnimxyj1uCLcuwmgQTqLBJQx2z0OirlNsi3 RZSl/LDsKR2AiZ0wfjcC8q3RKMqVwbh3fBUk4kpuyH3YPgc1Ld4jippRZvRy+gJ4viq2 B74gwvl33yIs7/H1MVAB1tNzm4xfj+xFpIr4GpAruanJySlPy1FfwHm/QshXlY80rla9 rRft8aum/0h0uUnXLtiGPvr8zMtYrZoXY4KjjUNvG71gxGU0OtFW/7Pe7BiVYbdUqfV2 dFpda7FJm1bQNxo6B9UJCeF4D2/Lc8dX+rjwsW24/TE2q+zmpjMIV0IB0n23AAn0CoHj ScqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sSQ+qxw4; 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 n19-20020ac85b53000000b002f38cfdf8c0si2992414qtw.681.2022.04.30.11.12.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 11:12:31 -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=sSQ+qxw4; 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]:43352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkra2-000568-Ks for patch@linaro.org; Sat, 30 Apr 2022 14:12:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nkrI8-0004ju-Pt for qemu-devel@nongnu.org; Sat, 30 Apr 2022 13:54:01 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:50988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nkrI6-00083x-0l for qemu-devel@nongnu.org; Sat, 30 Apr 2022 13:53:59 -0400 Received: by mail-pj1-x1036.google.com with SMTP id iq10so9630259pjb.0 for ; Sat, 30 Apr 2022 10:53:57 -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=oS4SpFhfIqgKlDgeO+bhyHZ/w+64dvw7Bn99nQxMQ8M=; b=sSQ+qxw4sxR4Tq4xNrN+yDVF70mhF4yfFSx2hrNb5lY406SF1632DP0Q9eTVWjdLCv tyXIYSP4l4V3Xj1Q5MbR+wFUzquaYxr1Wz2IdZ0e66Qi0RU5gT19kWuVyI1rvI5UPjPB T6GEGoy4S8jrPs8nReKuYXXjjfYEgKjYpAHzTkN1A8bW1HP6dhu8MKkTt/u23CWt/sLz vXGCYTsDkGI4D7lw2p82dMluwPOP78+C9HIN3VStlsN9QnjZIRjxArBafIg3CuEHJD2G RetBZnMr/0Csd7pGfK6U9tPxSJbH4ZZ9eH6SKJSM1XAB31KZXnGyllnIvGYImwAyrUdj tuBw== 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=oS4SpFhfIqgKlDgeO+bhyHZ/w+64dvw7Bn99nQxMQ8M=; b=qvsoT3fQF0AMvJ4yz0ide1CbvJSrFVU6OkSkTRcYUw0hPWuaO+3nLywvsgfU7yngXR 2quqGTmZBJ6nlQjDi/rEGnBFfwMXdzzKoXdQggtH9VNECl3DkdIfdl/YwdAQIiTD7/bq ux3UrbMQtLXOR99+qYsBz39DMaKTO6aessdYelzLtYsgpmh+B1Gmvb1dLKOZE1cmbf5U CxJVbWzv5MBNB6FOD80jPJQg1c0ecZcni1mUKCGH3/mR3/CHuqWhTcwNU5O8AOoxdW7i EY0eA1dVnTsSmSUJQ/o8KiR+KBqX7Hx7F2s6DQAS0fJdmnvgwG4tiOAAaiMs5XphGWLC /EiQ== X-Gm-Message-State: AOAM53282KpYmhf/Hu9byIS8sssf/vwkRmG6GsNtw/1/sFW9y2RAgyOe NNQPt1J88s3KLzgsz2JjRYBaOmR5MD2gcg== X-Received: by 2002:a17:902:d5ce:b0:158:48db:9719 with SMTP id g14-20020a170902d5ce00b0015848db9719mr4713419plh.7.1651341236742; Sat, 30 Apr 2022 10:53:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c20500b0015e8d4eb282sm1740910pll.204.2022.04.30.10.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 10:53:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 14/17] tests/tcg/m68k: Add trap.c Date: Sat, 30 Apr 2022 10:53:39 -0700 Message-Id: <20220430175342.370628-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430175342.370628-1-richard.henderson@linaro.org> References: <20220430175342.370628-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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: , 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 Reviewed-by: Laurent Vivier --- 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