From nobody Wed Oct 29 22:58:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15258904163311009.5586481615171; Wed, 9 May 2018 11:26:56 -0700 (PDT) Received: from localhost ([::1]:58355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTnj-0005vG-GH for importer@patchew.org; Wed, 09 May 2018 14:26:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJj-0005gb-G2 for qemu-devel@nongnu.org; Wed, 09 May 2018 13:56:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTJb-0006J2-LQ for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:55 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33535) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTJb-0006Ht-9q for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:47 -0400 Received: by mail-pf0-x241.google.com with SMTP id f20so17212800pfn.0 for ; Wed, 09 May 2018 10:55:47 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id l90sm60332813pfb.149.2018.05.09.10.55.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:44 -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; bh=t4NcYNVG4UP78FKUh+aSUCQTAEqf5H9XW1VYn6rvHFE=; b=BHV4HCp1ApnD/NCWoBPmU5nUyAl46b3A2F5R+3Bj0EjUPPEGcmb/MQXaN+y6jeQdRt GszTvJG/zP0bIUXkJHi1wLC5gm72VYyyJWJWBqEFIRo36KCPxoPcP5+SqJ9w145rnu7m rPmeTDFFRDPO2ky1wcWQqqmj4IFrTC2m5CeSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t4NcYNVG4UP78FKUh+aSUCQTAEqf5H9XW1VYn6rvHFE=; b=M3J2JEURos/xgspoTfoea26DLCcnMufzidanLWlUmLeKY9/UQo1z304rgTosGe2brp AegHONak0KG/S+NTDmru7r9hwHxtUkcsV/h3VkfQd4BUYh4aDUFWYPCr+b0dLyJRjE2v z/Ga+xNLsf328ixhV9VxRPov6nV4Ezd2mvHCNxJLwIfxU8f2s8pF/Wmp1sx06h1cvItG OTsIVYETvdFittfOHCRlryDnK5xSH/V7UG2ihRbUwLmISEWiSvg1JumXPtikLcvXr9Aq S07Eyu6S0OiuJP0YVE1vZH5dSFKN7I57Z0uTkxXefVctgUO8ZDyF+Htdlzbxfu6h8mB9 x8XQ== X-Gm-Message-State: ALQs6tBkz+sb03zzrWry4Y2ZfMTdKdYng9yvTt/Caenj9VvO5nJGsjQI 11KFNwJ+a9ULxl4W40j22UjFET2e+1s= X-Google-Smtp-Source: AB8JxZoe16851rQxZN4I13smvN3iIEfeANKJ9HjIQ1m+MJhw0OpldX5UVAyFyBtzosKHmn1olhFLAw== X-Received: by 10.98.34.24 with SMTP id i24mr28279947pfi.53.1525888545908; Wed, 09 May 2018 10:55:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:56 -0700 Message-Id: <20180509175458.15642-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509175458.15642-1-richard.henderson@linaro.org> References: <20180509175458.15642-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PULL 26/28] target/riscv: convert to DisasJumpType X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Sagar Karandikar , David Hildenbrand , Palmer Dabbelt , Mark Cave-Ayland , Max Filippov , Michael Clark , "Edgar E. Iglesias" , Guan Xuetao , Yongbok Kim , Alexander Graf , "Emilio G. Cota" , Richard Henderson , Artyom Tarasenko , Eduardo Habkost , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Stafford Horne , David Gibson , Peter Crosthwaite , Bastian Koppelmann , Cornelia Huck , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Reviewed-by: Bastian Koppelmann Reviewed-by: Richard Henderson Cc: Michael Clark Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- target/riscv/translate.c | 72 ++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a98033ca77..1fee5b51dc 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -26,6 +26,7 @@ #include "exec/helper-proto.h" #include "exec/helper-gen.h" =20 +#include "exec/translator.h" #include "exec/log.h" =20 #include "instmap.h" @@ -46,7 +47,7 @@ typedef struct DisasContext { uint32_t flags; uint32_t mem_idx; int singlestep_enabled; - int bstate; + DisasJumpType is_jmp; /* Remember the rounding mode encoded in the previous fp instruction, which we have already installed into env->fp_status. Or -1 for no previous fp instruction. Note that we exit the TB when writing @@ -55,13 +56,6 @@ typedef struct DisasContext { int frm; } DisasContext; =20 -enum { - BS_NONE =3D 0, /* When seen outside of translation while loop, ind= icates - need to exit tb due to end of page. */ - BS_STOP =3D 1, /* Need to exit tb for syscall, sret, etc. */ - BS_BRANCH =3D 2, /* Need to exit tb for branch, jal, etc. */ -}; - /* convert riscv funct3 to qemu memop for load/store */ static const int tcg_memop_lookup[8] =3D { [0 ... 7] =3D -1, @@ -88,7 +82,7 @@ static void generate_exception(DisasContext *ctx, int exc= p) TCGv_i32 helper_tmp =3D tcg_const_i32(excp); gen_helper_raise_exception(cpu_env, helper_tmp); tcg_temp_free_i32(helper_tmp); - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } =20 static void generate_exception_mbadaddr(DisasContext *ctx, int excp) @@ -98,7 +92,7 @@ static void generate_exception_mbadaddr(DisasContext *ctx= , int excp) TCGv_i32 helper_tmp =3D tcg_const_i32(excp); gen_helper_raise_exception(cpu_env, helper_tmp); tcg_temp_free_i32(helper_tmp); - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } =20 static void gen_exception_debug(void) @@ -531,7 +525,7 @@ static void gen_jal(CPURISCVState *env, DisasContext *c= tx, int rd, } =20 gen_goto_tb(ctx, 0, ctx->pc + imm); /* must use this for safety */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } =20 static void gen_jalr(CPURISCVState *env, DisasContext *ctx, uint32_t opc, @@ -562,7 +556,7 @@ static void gen_jalr(CPURISCVState *env, DisasContext *= ctx, uint32_t opc, gen_set_label(misaligned); gen_exception_inst_addr_mis(ctx); } - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; break; =20 default: @@ -616,7 +610,7 @@ static void gen_branch(CPURISCVState *env, DisasContext= *ctx, uint32_t opc, } else { gen_goto_tb(ctx, 0, ctx->pc + bimm); } - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } =20 static void gen_load(DisasContext *ctx, uint32_t opc, int rd, int rs1, @@ -1344,12 +1338,12 @@ static void gen_system(CPURISCVState *env, DisasCon= text *ctx, uint32_t opc, /* always generates U-level ECALL, fixed in do_interrupt handl= er */ generate_exception(ctx, RISCV_EXCP_U_ECALL); tcg_gen_exit_tb(0); /* no chaining */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; break; case 0x1: /* EBREAK */ generate_exception(ctx, RISCV_EXCP_BREAKPOINT); tcg_gen_exit_tb(0); /* no chaining */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; break; #ifndef CONFIG_USER_ONLY case 0x002: /* URET */ @@ -1359,7 +1353,7 @@ static void gen_system(CPURISCVState *env, DisasConte= xt *ctx, uint32_t opc, if (riscv_has_ext(env, RVS)) { gen_helper_sret(cpu_pc, cpu_env, cpu_pc); tcg_gen_exit_tb(0); /* no chaining */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } else { gen_exception_illegal(ctx); } @@ -1370,7 +1364,7 @@ static void gen_system(CPURISCVState *env, DisasConte= xt *ctx, uint32_t opc, case 0x302: /* MRET */ gen_helper_mret(cpu_pc, cpu_env, cpu_pc); tcg_gen_exit_tb(0); /* no chaining */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; break; case 0x7b2: /* DRET */ gen_exception_illegal(ctx); @@ -1419,7 +1413,7 @@ static void gen_system(CPURISCVState *env, DisasConte= xt *ctx, uint32_t opc, /* end tb since we may be changing priv modes, to get mmu_index ri= ght */ tcg_gen_movi_tl(cpu_pc, ctx->next_pc); tcg_gen_exit_tb(0); /* no chaining */ - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; break; } tcg_temp_free(source1); @@ -1812,7 +1806,7 @@ static void decode_RV32_64G(CPURISCVState *env, Disas= Context *ctx) * however we need to end the translation block */ tcg_gen_movi_tl(cpu_pc, ctx->next_pc); tcg_gen_exit_tb(0); - ctx->bstate =3D BS_BRANCH; + ctx->is_jmp =3D DISAS_NORETURN; } else { /* FENCE is a full memory barrier. */ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC); @@ -1862,7 +1856,7 @@ void gen_intermediate_code(CPUState *cs, TranslationB= lock *tb) ctx.singlestep_enabled =3D cs->singlestep_enabled; =20 ctx.tb =3D tb; - ctx.bstate =3D BS_NONE; + ctx.is_jmp =3D DISAS_NEXT; ctx.flags =3D tb->flags; ctx.mem_idx =3D tb->flags & TB_FLAGS_MMU_MASK; ctx.frm =3D -1; /* unknown rounding mode */ @@ -1877,13 +1871,13 @@ void gen_intermediate_code(CPUState *cs, Translatio= nBlock *tb) } gen_tb_start(tb); =20 - while (ctx.bstate =3D=3D BS_NONE) { + while (ctx.is_jmp =3D=3D DISAS_NEXT) { tcg_gen_insn_start(ctx.pc); num_insns++; =20 if (unlikely(cpu_breakpoint_test(cs, ctx.pc, BP_ANY))) { tcg_gen_movi_tl(cpu_pc, ctx.pc); - ctx.bstate =3D BS_BRANCH; + ctx.is_jmp =3D DISAS_NORETURN; gen_exception_debug(); /* The address covered by the breakpoint must be included in [tb->pc, tb->pc + tb->size) in order to for it to be @@ -1901,31 +1895,20 @@ void gen_intermediate_code(CPUState *cs, Translatio= nBlock *tb) decode_opc(env, &ctx); ctx.pc =3D ctx.next_pc; =20 - if (cs->singlestep_enabled) { - break; + if (ctx.is_jmp =3D=3D DISAS_NEXT && + (cs->singlestep_enabled || + ctx.pc - page_start >=3D TARGET_PAGE_SIZE || + tcg_op_buf_full() || + num_insns >=3D max_insns || + singlestep)) { + ctx.is_jmp =3D DISAS_TOO_MANY; } - if (ctx.pc - page_start >=3D TARGET_PAGE_SIZE) { - break; - } - if (tcg_op_buf_full()) { - break; - } - if (num_insns >=3D max_insns) { - break; - } - if (singlestep) { - break; - } - } if (tb->cflags & CF_LAST_IO) { gen_io_end(); } - switch (ctx.bstate) { - case BS_STOP: - gen_goto_tb(&ctx, 0, ctx.pc); - break; - case BS_NONE: /* handle end of page - DO NOT CHAIN. See gen_goto_tb. */ + switch (ctx.is_jmp) { + case DISAS_TOO_MANY: tcg_gen_movi_tl(cpu_pc, ctx.pc); if (cs->singlestep_enabled) { gen_exception_debug(); @@ -1933,9 +1916,10 @@ void gen_intermediate_code(CPUState *cs, Translation= Block *tb) tcg_gen_exit_tb(0); } break; - case BS_BRANCH: /* ops using BS_BRANCH generate own exit seq */ - default: + case DISAS_NORETURN: break; + default: + g_assert_not_reached(); } done_generating: gen_tb_end(tb, num_insns); --=20 2.17.0