From patchwork Fri May 27 16:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 576511 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8607:0:0:0:0 with SMTP id bb7csp807010mab; Fri, 27 May 2022 09:53:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwud8cgFP/OpOorCE1wxC6Bz9Lk1wEd5RpTf1RkkKUwihs60av0B9Kzf+3/j7zbjMXMS5m4 X-Received: by 2002:ac8:5a43:0:b0:2f9:3533:9995 with SMTP id o3-20020ac85a43000000b002f935339995mr21636150qta.619.1653670412139; Fri, 27 May 2022 09:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653670412; cv=none; d=google.com; s=arc-20160816; b=f4evK+xCpZGYELKCp6z+tqRwcnvfDnJFWquyGj9dcEGLBNZhzE2imHC3zpRfd7lBBZ SzMwMpHz8Thtnfvb4tD3TckkvShAY9r+KCyPf17plfoz98GfbmzatrvhvCk9Ibwd1TsM Z8PZColf8eRAhson7n+N7AQAwCiROM7d3TfivYWCQKWd+mzCxiTOrxlksj8VDwgSXTYd bMavJXsWdcGQV8rgPe6uB+YE2kgCevKlDU2u+AG6eU/4uGsZnq++7P/6sKpnAfSkGuK+ 00FNCYZdS9hs/vzaXpcQ1DkdmPimJ8MMI/sgv0JDXBFu1kTdkJrN3il1SF5ek2LAuqw9 vgBw== 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=KyWq1SP5mJS//TtONTeiMPT3+Dc2kCMkrVruGMXnAYM=; b=wP09RhTzAqcuRfdBR7CQZigPEfdazMoV1y5pMKSXOrN+J3pffQsDbSKLVPTlXZEPut QxL0j2KMJpBx84GLIWL1DkJKg0DJYxfeDaKJY+ibnhoMtMamZnWRNa/Qz68LvjHZP8OB XjQRlnRlKnMYMcxsSW1MNDJwmfLHSRWaVWjRP1oZRtRVD9YJjubscwjWv9RRO0USS8+v aeCNvYJ9XZcQpBKnmFxOvC9jDG1pNOuWRJfrCkHDbfD93Bw+zzmbeRkWBcXB+GNma+t7 1ugN4AjER1Kz4bzYNZbmThaJDBVmt5BRZVmLPTCzJWeFzspZlzeW3z62yivWojSIQ47T AQHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QKzG4W7P; 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 f2-20020a05620a280200b006a5ea58f26esi997638qkp.758.2022.05.27.09.53.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 May 2022 09:53:32 -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=QKzG4W7P; 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]:46232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nudDP-0006AV-LX for patch@linaro.org; Fri, 27 May 2022 12:53:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nud8P-0001aR-Nz for qemu-devel@nongnu.org; Fri, 27 May 2022 12:48:21 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:52841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nud8N-0005P2-Uc for qemu-devel@nongnu.org; Fri, 27 May 2022 12:48:21 -0400 Received: by mail-pj1-x1031.google.com with SMTP id gz24so5082372pjb.2 for ; Fri, 27 May 2022 09:48:19 -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=KyWq1SP5mJS//TtONTeiMPT3+Dc2kCMkrVruGMXnAYM=; b=QKzG4W7P00g32mM+xXM2lPHztptqflVhhOHa9vdkBTs9nQJWg28DWkTHgidt0hrNea nodJ3cGK9DacCdJ/Ks1qS6MJbJcAISgFTOhKyg40ZeyASfPaZzHvaFFKrXFIRN0OTOHB 5bJ2y6Tnnb6xm4XmUAKhW50XbNNdYNrqUy2mboA2xqqIy5VlwPtqLFWt8OHUSrpQ7HHJ G/cu80QU8qwP5xo+NzdpTIsHcI5UAaJSuOEnJ0TfoWRQ2Ei0eK1fwwrIvUHxRlnle9+C p3g/8S0De8S8PUYz25hNuA8RMWJW4ZZ9u+Hf6+Rn8rVR2/PsVYxo81AP1W3rLoV1o/eT GQnA== 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=KyWq1SP5mJS//TtONTeiMPT3+Dc2kCMkrVruGMXnAYM=; b=c+2NZygux6NlS/JvtDo3Zhws5DajvXT7q/ScF4XUxTWIwo4R9Y3ikIOypaf/ylcZbQ LW9+s5P71DFjBMQLa6xbFxZDCa5/98bqY55rjZmiW03xiKA1Gbw6j0eV0VVzcJuCQ1lZ 05sHgP6xwSOKCMnWAXupZE5cSTc00M1mnpS38pgz/BS9KSV8/+3caPCNK4jtLIsMy8sL yx1QWV9ooSX8thjf+Lq8S+ByihUv5ypRu9Q0Y1YA8O8JqIODwxm2yF4vWx8ROt9V/nGf lQ5iYrRwq+41Xs4C72XggmjuC3yirDfI8f819+SCVXgJwAlT7TWRLGQByjgjv62PE4GK Ahew== X-Gm-Message-State: AOAM533X1lnH+jnnKrMfbE4RfsvkxONOQAjI8E7JVsKKcvB/k07wOKPB rhzGmlUH80M0E1AlydiIyiMabn8VJx2Pzg== X-Received: by 2002:a17:90a:d01:b0:1e0:2e32:8650 with SMTP id t1-20020a17090a0d0100b001e02e328650mr9271907pja.156.1653670098634; Fri, 27 May 2022 09:48:18 -0700 (PDT) Received: from stoup.. (174-21-71-225.tukw.qwest.net. [174.21.71.225]) by smtp.gmail.com with ESMTPSA id j11-20020aa7928b000000b0050dc7628133sm3861420pfa.13.2022.05.27.09.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 09:48:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH v5 10/17] target/m68k: Implement TRAPcc Date: Fri, 27 May 2022 09:48:00 -0700 Message-Id: <20220527164807.135038-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220527164807.135038-1-richard.henderson@linaro.org> References: <20220527164807.135038-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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" Resolves: https://gitlab.com/qemu-project/qemu/-/issues/754 Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/m68k/cpu.h | 2 ++ linux-user/m68k/cpu_loop.c | 1 + target/m68k/cpu.c | 1 + target/m68k/op_helper.c | 6 +---- target/m68k/translate.c | 49 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index 558c3c67d6..4d8f48e8c7 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -534,6 +534,8 @@ enum m68k_features { M68K_FEATURE_MOVEC, /* Unaligned data accesses (680[2346]0) */ M68K_FEATURE_UNALIGNED_DATA, + /* TRAPcc insn. (680[2346]0, and CPU32) */ + M68K_FEATURE_TRAPCC, }; static inline int m68k_feature(CPUM68KState *env, int feature) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index fcf9220552..3d3033155f 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -47,6 +47,7 @@ void cpu_loop(CPUM68KState *env) force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc); break; case EXCP_CHK: + case EXCP_TRAPCC: force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTOVF, env->mmu.ar); break; case EXCP_DIV0: diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index c7aeb7da9c..5f778773d1 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -162,6 +162,7 @@ static void m68020_cpu_initfn(Object *obj) m68k_set_feature(env, M68K_FEATURE_CHK2); m68k_set_feature(env, M68K_FEATURE_MSP); m68k_set_feature(env, M68K_FEATURE_UNALIGNED_DATA); + m68k_set_feature(env, M68K_FEATURE_TRAPCC); } /* diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index aa62158eb9..61948d92bb 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -399,14 +399,10 @@ static void m68k_interrupt_all(CPUM68KState *env, int is_hw) do_stack_frame(env, &sp, 2, oldsr, 0, env->pc); break; - case EXCP_TRAPCC: - /* FIXME: addr is not only env->pc */ - do_stack_frame(env, &sp, 2, oldsr, env->pc, env->pc); - break; - case EXCP_CHK: case EXCP_DIV0: case EXCP_TRACE: + case EXCP_TRAPCC: do_stack_frame(env, &sp, 2, oldsr, env->mmu.ar, env->pc); break; diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 399d9232e4..c4fe8abc03 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -4879,6 +4879,54 @@ DISAS_INSN(trap) gen_exception(s, s->pc, EXCP_TRAP0 + (insn & 0xf)); } +static void do_trapcc(DisasContext *s, DisasCompare *c) +{ + if (c->tcond != TCG_COND_NEVER) { + TCGLabel *over = NULL; + + update_cc_op(s); + + if (c->tcond != TCG_COND_ALWAYS) { + /* Jump over if !c. */ + over = gen_new_label(); + tcg_gen_brcond_i32(tcg_invert_cond(c->tcond), c->v1, c->v2, over); + } + + tcg_gen_movi_i32(QREG_PC, s->pc); + gen_raise_exception_format2(s, EXCP_TRAPCC, s->base.pc_next); + + if (over != NULL) { + gen_set_label(over); + s->base.is_jmp = DISAS_NEXT; + } + } + free_cond(c); +} + +DISAS_INSN(trapcc) +{ + DisasCompare c; + + /* Consume and discard the immediate operand. */ + switch (extract32(insn, 0, 3)) { + case 2: /* trapcc.w */ + (void)read_im16(env, s); + break; + case 3: /* trapcc.l */ + (void)read_im32(env, s); + break; + case 4: /* trapcc (no operand) */ + break; + default: + /* Illegal insn */ + disas_undef(env, s, insn); + return; + } + + gen_cc_cond(&c, s, extract32(insn, 8, 4)); + do_trapcc(s, &c); +} + static void gen_load_fcr(DisasContext *s, TCGv res, int reg) { switch (reg) { @@ -6050,6 +6098,7 @@ void register_m68k_insns (CPUM68KState *env) INSN(scc, 50c0, f0f8, CF_ISA_A); /* Scc.B Dx */ INSN(scc, 50c0, f0c0, M68000); /* Scc.B */ INSN(dbcc, 50c8, f0f8, M68000); + INSN(trapcc, 50f8, f0f8, TRAPCC); INSN(tpf, 51f8, fff8, CF_ISA_A); /* Branch instructions. */