From patchwork Thu Oct 26 00:13:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 738185 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp552247wrq; Wed, 25 Oct 2023 17:17:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCA7SRPspQ2CCa9uz3Oozp4hPHM/d42TSOkOpMQYs4x01nhwGMuPO7cQfSjcBr4YYGCpcg X-Received: by 2002:a5d:5746:0:b0:32d:62e7:8ff9 with SMTP id q6-20020a5d5746000000b0032d62e78ff9mr11564433wrw.34.1698279467842; Wed, 25 Oct 2023 17:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698279467; cv=none; d=google.com; s=arc-20160816; b=vUptmMShemIXLms8CyyeBYCU3IPfD30vqo+M+VF/9qPHWqBEP/uJQMazlwb2vMk1jh hnB1sXJ4WwmG+Faugqm4OHZqixFeGbXfwbitgsvPNH76G/VK3rsoUfqyVIJ8ywRkNqBa Nu7xBnGj6WU5KtJjd5hb3RrtSLzLvbqL+7S8hiZ6QfJksdhUll2qM5cmGl0fARQV3quz V4NlGXohBfAtr/db8Z2WuZuI5uuH4yKqUnaCoDmtRuOCZdBLmoTYuHJ8mWhReFWzUG1B GiEq1TnNFHLHqdRI1FDN9p4p0Xe5Iy+Q9+RxHqradmlT2dEdiyKMAxXhNX7ZtcP0hVwd Mrtg== 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=gYhvKxqYq5JV9In/R2ATIQpLZ14hQa9hieJVJfsIFqc=; fh=rYI8DiHAAFX3O5g969KmOAQ7d45Sb8OxQX1+DywGDk4=; b=DRF5/+JROuTx0y+8hfJN4A2R/CiCenHmRpLLEPnlymgzVia1uwiw84pZFiDgaTuJ2a pl4GR486BdeJ+AhoChT5C+hVEQl9E8H2HUeU8e+SYWBY/nbv7sfQV26G/iXz/rjuWkEO 8O0MkDzXmg0kvbkYtoNQnvUaRQw+pHeYsOQ+oMFxyutZ5IUyRM/MmrqsklZBO6zw2v7I pU8qIlrm1Bm/R/kPasRZf4fGG3ZF/pTkQSSxCfLTXg8iPenVZtrCwk4Vp+EY77vF61sd HX6Vz2n6o176z5HcD3JmY7dvpif672SlMFn3c/YfeZyPpvlVNlXmQXV9EcbYYAUWbZe0 FIyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c27mi1B5; 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 o5-20020a5d6845000000b0032ddc890ba8si7938963wrw.19.2023.10.25.17.17.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 17:17:47 -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=c27mi1B5; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvo2n-00072Q-TW; Wed, 25 Oct 2023 20:16:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvo2S-0006y1-AZ for qemu-devel@nongnu.org; Wed, 25 Oct 2023 20:16:06 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvo2N-0004pO-SD for qemu-devel@nongnu.org; Wed, 25 Oct 2023 20:15:50 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c77449a6daso2334705ad.0 for ; Wed, 25 Oct 2023 17:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698279346; x=1698884146; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gYhvKxqYq5JV9In/R2ATIQpLZ14hQa9hieJVJfsIFqc=; b=c27mi1B5pvgTHcLemzGBuoJG9gf0taDvwrhe1Xj7FEoQ36hKnHP+EdbhJOlYVHbY8L F8kSipKrMaXihxM4B+3SQLB9B8/5sFAcT/c5JZSjyaRfEb96LAh19+vrnSG9f2eWfMtU /Tw23MAkLh2JeeIJAXnwEcLRbWbXTrbvgHWbbL+ehXo56eBddA0KzkV/jBlT8sR0zzYx e1CQ/U9EGtoFpKylxVr/pNM6kwo7gwfl56wr8BBv1bMfOlOmVpsS15iC9GRevfbVihvK 6sHJlB5NwGTL1Fetxi+QdQjzhnrZcx/0vGvfryh6WAUf87arhH+6a9t70JxatHy6iVaQ E0MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698279346; x=1698884146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gYhvKxqYq5JV9In/R2ATIQpLZ14hQa9hieJVJfsIFqc=; b=tiAARDDXpFNALCrCxBaWXCOi1EOvH+pR+sHDKQiBPoT5BlZsR+yyWhwWEgePlKxp2J YEdTL0cybhlWVFyl3NdC/+UlhVka+7jJXYPE+5SjTD0q1f6TBYGEa0h0XdwbN0OH5pqE FETUmPeflBC1uOA0QraMBSAgs6zbgFP15xroVpfa862iddciCGOShyQOAtnjPB2rWcId EkQOvI0sXxCBFac6DKGS5hLQqvNsGE/ocj83w6NkSUOCl9BZen77brxY9ezWiULqv+E6 vlIgj6uB4Tdx5sy+GXM0wBgUoOy+WZmmUyK06DXFi+hfCOnoSlJNmWfGrrH+mQ8zItOJ XN5w== X-Gm-Message-State: AOJu0YwcaK1y3Zx8fcrMw40tJ6Gw2Unj536keFk5IpaoKEQZLHiY/mGa s++mLImTZXLfPJQV5aInuH3jF9+5SFdB3NKAtT0= X-Received: by 2002:a17:902:ce8d:b0:1c7:4ab6:b3cc with SMTP id f13-20020a170902ce8d00b001c74ab6b3ccmr20340206plg.54.1698279346537; Wed, 25 Oct 2023 17:15:46 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id ij23-20020a170902ab5700b001c582de968dsm10038433plb.72.2023.10.25.17.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 17:15:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland Subject: [PULL 02/94] target/sparc: Implement check_align inline Date: Wed, 25 Oct 2023 17:13:42 -0700 Message-Id: <20231026001542.1141412-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026001542.1141412-1-richard.henderson@linaro.org> References: <20231026001542.1141412-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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 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-bounces+patch=linaro.org@nongnu.org Emit the exception at the end of the translation block, so that the non-exception case can fall through. Tested-by: Mark Cave-Ayland Acked-by: Mark Cave-Ayland Signed-off-by: Richard Henderson --- target/sparc/helper.h | 1 - target/sparc/ldst_helper.c | 7 ++-- target/sparc/translate.c | 68 +++++++++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/target/sparc/helper.h b/target/sparc/helper.h index b8f1e78c75..b116ddcb29 100644 --- a/target/sparc/helper.h +++ b/target/sparc/helper.h @@ -24,7 +24,6 @@ DEF_HELPER_FLAGS_2(tick_set_count, TCG_CALL_NO_RWG, void, ptr, i64) DEF_HELPER_FLAGS_3(tick_get_count, TCG_CALL_NO_WG, i64, env, ptr, int) DEF_HELPER_FLAGS_2(tick_set_limit, TCG_CALL_NO_RWG, void, ptr, i64) #endif -DEF_HELPER_FLAGS_3(check_align, TCG_CALL_NO_WG, void, env, tl, i32) DEF_HELPER_1(debug, void, env) DEF_HELPER_1(save, void, env) DEF_HELPER_1(restore, void, env) diff --git a/target/sparc/ldst_helper.c b/target/sparc/ldst_helper.c index 78b03308ae..246de86c98 100644 --- a/target/sparc/ldst_helper.c +++ b/target/sparc/ldst_helper.c @@ -360,6 +360,7 @@ static inline void do_check_asi(CPUSPARCState *env, int asi, uintptr_t ra) #endif /* !CONFIG_USER_ONLY */ #endif +#if defined(TARGET_SPARC64) || !defined(CONFIG_USER_ONLY) static void do_check_align(CPUSPARCState *env, target_ulong addr, uint32_t align, uintptr_t ra) { @@ -367,11 +368,7 @@ static void do_check_align(CPUSPARCState *env, target_ulong addr, cpu_raise_exception_ra(env, TT_UNALIGNED, ra); } } - -void helper_check_align(CPUSPARCState *env, target_ulong addr, uint32_t align) -{ - do_check_align(env, addr, align, GETPC()); -} +#endif #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) && \ defined(DEBUG_MXCC) diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 8fabed28fd..8f6fd453e7 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -68,6 +68,15 @@ static TCGv cpu_wim; /* Floating point registers */ static TCGv_i64 cpu_fpr[TARGET_DPREGS]; +typedef struct DisasDelayException { + struct DisasDelayException *next; + TCGLabel *lab; + TCGv_i32 excp; + /* Saved state at parent insn. */ + target_ulong pc; + target_ulong npc; +} DisasDelayException; + typedef struct DisasContext { DisasContextBase base; target_ulong pc; /* current Program Counter: integer or DYNAMIC_PC */ @@ -89,6 +98,7 @@ typedef struct DisasContext { int fprs_dirty; int asi; #endif + DisasDelayException *delay_excp_list; } DisasContext; typedef struct { @@ -984,9 +994,38 @@ static void gen_exception(DisasContext *dc, int which) dc->base.is_jmp = DISAS_NORETURN; } -static void gen_check_align(TCGv addr, int mask) +static TCGLabel *delay_exceptionv(DisasContext *dc, TCGv_i32 excp) { - gen_helper_check_align(tcg_env, addr, tcg_constant_i32(mask)); + DisasDelayException *e = g_new0(DisasDelayException, 1); + + e->next = dc->delay_excp_list; + dc->delay_excp_list = e; + + e->lab = gen_new_label(); + e->excp = excp; + e->pc = dc->pc; + /* Caller must have used flush_cond before branch. */ + assert(e->npc != JUMP_PC); + e->npc = dc->npc; + + return e->lab; +} + +static TCGLabel *delay_exception(DisasContext *dc, int excp) +{ + return delay_exceptionv(dc, tcg_constant_i32(excp)); +} + +static void gen_check_align(DisasContext *dc, TCGv addr, int mask) +{ + TCGv t = tcg_temp_new(); + TCGLabel *lab; + + tcg_gen_andi_tl(t, addr, mask); + + flush_cond(dc); + lab = delay_exception(dc, TT_UNALIGNED); + tcg_gen_brcondi_tl(TCG_COND_NE, t, 0, lab); } static void gen_mov_pc_npc(DisasContext *dc) @@ -5019,9 +5058,9 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn) tcg_gen_mov_tl(cpu_tmp0, cpu_src1); } } + gen_check_align(dc, cpu_tmp0, 3); gen_helper_restore(tcg_env); gen_mov_pc_npc(dc); - gen_check_align(cpu_tmp0, 3); tcg_gen_mov_tl(cpu_npc, cpu_tmp0); dc->npc = DYNAMIC_PC_LOOKUP; goto jmp_insn; @@ -5044,12 +5083,9 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn) switch (xop) { case 0x38: /* jmpl */ { - TCGv t = gen_dest_gpr(dc, rd); - tcg_gen_movi_tl(t, dc->pc); - gen_store_gpr(dc, rd, t); - + gen_check_align(dc, cpu_tmp0, 3); + gen_store_gpr(dc, rd, tcg_constant_tl(dc->pc)); gen_mov_pc_npc(dc); - gen_check_align(cpu_tmp0, 3); gen_address_mask(dc, cpu_tmp0); tcg_gen_mov_tl(cpu_npc, cpu_tmp0); dc->npc = DYNAMIC_PC_LOOKUP; @@ -5060,8 +5096,8 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn) { if (!supervisor(dc)) goto priv_insn; + gen_check_align(dc, cpu_tmp0, 3); gen_mov_pc_npc(dc); - gen_check_align(cpu_tmp0, 3); tcg_gen_mov_tl(cpu_npc, cpu_tmp0); dc->npc = DYNAMIC_PC; gen_helper_rett(tcg_env); @@ -5643,6 +5679,7 @@ static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) { DisasContext *dc = container_of(dcbase, DisasContext, base); + DisasDelayException *e, *e_next; bool may_lookup; switch (dc->base.is_jmp) { @@ -5704,6 +5741,19 @@ static void sparc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) default: g_assert_not_reached(); } + + for (e = dc->delay_excp_list; e ; e = e_next) { + gen_set_label(e->lab); + + tcg_gen_movi_tl(cpu_pc, e->pc); + if (e->npc % 4 == 0) { + tcg_gen_movi_tl(cpu_npc, e->npc); + } + gen_helper_raise_exception(tcg_env, e->excp); + + e_next = e->next; + g_free(e); + } } static void sparc_tr_disas_log(const DisasContextBase *dcbase,