From nobody Tue Dec 16 05:38:18 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519945440857976.2841066447288; Thu, 1 Mar 2018 15:04:00 -0800 (PST) Received: from localhost ([::1]:59679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erXF1-0007jD-Tz for importer@patchew.org; Thu, 01 Mar 2018 18:03:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erX5T-0000Jb-UY for qemu-devel@nongnu.org; Thu, 01 Mar 2018 17:54:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erX5P-0004sb-2G for qemu-devel@nongnu.org; Thu, 01 Mar 2018 17:54:07 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:38465) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erX5O-0004re-PT for qemu-devel@nongnu.org; Thu, 01 Mar 2018 17:54:02 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4A55A20E18; Thu, 1 Mar 2018 17:54:02 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Thu, 01 Mar 2018 17:54:02 -0500 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id EE0CF7E12E; Thu, 1 Mar 2018 17:54:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=eTdBqk8B7fhwDB jkkjwG980xSdPLh5eiGGGz8JWctNU=; b=2rayMBRlh6hHeC/Hfqf/KNx9dICTJs zp7IECpHIZqy3QYrpVikXBXfEywQDvtGhtWnYCRmj1QuTurtQ6+NBHhU1oOoWyDv T+HlSjyN+N2p+HMBfYhLLYRyulQYLqMet03bYe4g3o7kMJ4o6tWmuRYG/RKOF2+t C+NI0OFoQYIMI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=eTdBqk8B7fhwDBjkkjwG980xSdPLh5eiGGGz8JWctNU=; b=DKpraowb qy2DYdM/2xBQ1cuWK7xf2oQG7bfwStWUVnZJuY3OUrcLxC8h63aetd1pRprpyw2F S7VBkaY+3OnrOq1nUSO7sRqnTLSUwEO4e1lv2HIv/yBGRaI39uQneJ5hsFFME9wL tUhnMVrWYpwhOnj+GXQpJ/h0dqLEweYQY+cVIXEQxLS5He9RFqDZktdhJ3cjgGQH CP6KY0+Gql2N6vzIVR7W5Dwwu3nj3tYON2TdFI2522uMGJ3/PBHlaipcL3Sj6PfR 5o/lT9Gu78NJ+BQxtWi6ub+BuDdfJ5uP5tCY7hJ7ll0gsohnlLRTVonNphDH9qC9 FEouF7quYr95kg== X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 17:53:58 -0500 Message-Id: <1519944838-12430-15-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519944838-12430-1-git-send-email-cota@braap.org> References: <1519944838-12430-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.29 Subject: [Qemu-devel] [PATCHv1 14/14] target/openrisc: convert to TranslatorOps 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: Stafford Horne , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Notes: - Changed the num_insns test in insn_start to check for dc->base.num_insns > 1, since when tb_start is first called in a TB, base.num_insns is already set to 1. - Removed DISAS_NEXT from the switch in tb_stop; use DISAS_TOO_MANY instead. - Added an assert_not_reached on tb_stop for DISAS_NEXT and the default case. - Merged the two separate log_target_disas calls into the disas_log op. Cc: Stafford Horne Signed-off-by: Emilio G. Cota --- target/openrisc/translate.c | 163 +++++++++++++++++++++-------------------= ---- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index b37414f..7cf29cd 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -1520,46 +1520,22 @@ static void disas_openrisc_insn(DisasContext *dc, O= penRISCCPU *cpu) } } =20 -void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) +static void openrisc_tr_init_disas_context(DisasContextBase *dcb, CPUState= *cs) { + DisasContext *dc =3D container_of(dcb, DisasContext, base); CPUOpenRISCState *env =3D cs->env_ptr; - OpenRISCCPU *cpu =3D openrisc_env_get_cpu(env); - struct DisasContext ctx, *dc =3D &ctx; - uint32_t pc_start; - uint32_t next_page_start; - int num_insns; - int max_insns; - - pc_start =3D tb->pc; - - dc->base.tb =3D tb; - dc->base.singlestep_enabled =3D cs->singlestep_enabled; - dc->base.pc_next =3D pc_start; - dc->base.is_jmp =3D DISAS_NEXT; + int bound; =20 - dc->mem_idx =3D cpu_mmu_index(&cpu->env, false); + dc->mem_idx =3D cpu_mmu_index(env, false); dc->tb_flags =3D dc->base.tb->flags; dc->delayed_branch =3D (dc->tb_flags & TB_FLAGS_DFLAG) !=3D 0; + bound =3D -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; + dc->base.max_insns =3D MIN(dc->base.max_insns, bound); +} =20 - next_page_start =3D (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; - num_insns =3D 0; - max_insns =3D tb_cflags(tb) & CF_COUNT_MASK; - - if (max_insns =3D=3D 0) { - max_insns =3D CF_COUNT_MASK; - } - if (max_insns > TCG_MAX_INSNS) { - max_insns =3D TCG_MAX_INSNS; - } - - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) - && qemu_log_in_addr_range(pc_start)) { - qemu_log_lock(); - qemu_log("----------------\n"); - qemu_log("IN: %s\n", lookup_symbol(pc_start)); - } - - gen_tb_start(tb); +static void openrisc_tr_tb_start(DisasContextBase *db, CPUState *cs) +{ + DisasContext *dc =3D container_of(db, DisasContext, base); =20 /* Allow the TCG optimizer to see that R0 =3D=3D 0, when it's true, which is the common case. */ @@ -1568,50 +1544,55 @@ void gen_intermediate_code(CPUState *cs, struct Tra= nslationBlock *tb) } else { cpu_R[0] =3D cpu_R0; } +} =20 - do { - tcg_gen_insn_start(dc->base.pc_next, (dc->delayed_branch ? 1 : 0) - | (num_insns ? 2 : 0)); - num_insns++; +static void openrisc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); =20 - if (unlikely(cpu_breakpoint_test(cs, dc->base.pc_next, BP_ANY))) { - tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); - gen_exception(dc, EXCP_DEBUG); - dc->base.is_jmp =3D DISAS_NORETURN; - /* The address covered by the breakpoint must be included in - [tb->pc, tb->pc + tb->size) in order to for it to be - properly cleared -- thus we increment the PC here so that - the logic setting tb->size below does the right thing. */ - dc->base.pc_next +=3D 4; - break; - } + tcg_gen_insn_start(dc->base.pc_next, (dc->delayed_branch ? 1 : 0) + | (dc->base.num_insns > 1 ? 2 : 0)); +} =20 - if (num_insns =3D=3D max_insns && (tb_cflags(tb) & CF_LAST_IO)) { - gen_io_start(); - } - disas_openrisc_insn(dc, cpu); - dc->base.pc_next +=3D 4; - - /* delay slot */ - if (dc->delayed_branch) { - dc->delayed_branch--; - if (!dc->delayed_branch) { - tcg_gen_mov_tl(cpu_pc, jmp_pc); - tcg_gen_discard_tl(jmp_pc); - dc->base.is_jmp =3D DISAS_UPDATE; - break; - } +static bool openrisc_tr_breakpoint_check(DisasContextBase *dcbase, CPUStat= e *cs, + const CPUBreakpoint *bp) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); + + tcg_gen_movi_tl(cpu_pc, dc->base.pc_next); + gen_exception(dc, EXCP_DEBUG); + dc->base.is_jmp =3D DISAS_NORETURN; + /* The address covered by the breakpoint must be included in + [tb->pc, tb->pc + tb->size) in order to for it to be + properly cleared -- thus we increment the PC here so that + the logic setting tb->size below does the right thing. */ + dc->base.pc_next +=3D 4; + return true; +} + +static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState = *cs) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); + OpenRISCCPU *cpu =3D OPENRISC_CPU(cs); + + disas_openrisc_insn(dc, cpu); + dc->base.pc_next +=3D 4; + + /* delay slot */ + if (dc->delayed_branch) { + dc->delayed_branch--; + if (!dc->delayed_branch) { + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_discard_tl(jmp_pc); + dc->base.is_jmp =3D DISAS_UPDATE; + return; } - } while (!dc->base.is_jmp - && !tcg_op_buf_full() - && !dc->base.singlestep_enabled - && !singlestep - && (dc->base.pc_next < next_page_start) - && num_insns < max_insns); - - if (tb_cflags(tb) & CF_LAST_IO) { - gen_io_end(); } +} + +static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); =20 if ((dc->tb_flags & TB_FLAGS_DFLAG ? 1 : 0) !=3D (dc->delayed_branch != =3D 0)) { tcg_gen_movi_i32(cpu_dflag, dc->delayed_branch !=3D 0); @@ -1626,10 +1607,9 @@ void gen_intermediate_code(CPUState *cs, struct Tran= slationBlock *tb) gen_exception(dc, EXCP_DEBUG); } else { switch (dc->base.is_jmp) { - case DISAS_NEXT: + case DISAS_TOO_MANY: gen_goto_tb(dc, 0, dc->base.pc_next); break; - default: case DISAS_NORETURN: case DISAS_JUMP: case DISAS_TB_JUMP: @@ -1639,20 +1619,35 @@ void gen_intermediate_code(CPUState *cs, struct Tra= nslationBlock *tb) to find the next TB */ tcg_gen_exit_tb(0); break; + default: + g_assert_not_reached(); } } +} =20 - gen_tb_end(tb, num_insns); +static void openrisc_tr_disas_log(const DisasContextBase *dcbase, CPUState= *cs) +{ + DisasContext *s =3D container_of(dcbase, DisasContext, base); =20 - tb->size =3D dc->base.pc_next - pc_start; - tb->icount =3D num_insns; + qemu_log("IN: %s\n", lookup_symbol(s->base.pc_first)); + log_target_disas(cs, s->base.pc_first, s->base.tb->size); +} =20 - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) - && qemu_log_in_addr_range(pc_start)) { - log_target_disas(cs, pc_start, tb->size); - qemu_log("\n"); - qemu_log_unlock(); - } +static const TranslatorOps openrisc_tr_ops =3D { + .init_disas_context =3D openrisc_tr_init_disas_context, + .tb_start =3D openrisc_tr_tb_start, + .insn_start =3D openrisc_tr_insn_start, + .breakpoint_check =3D openrisc_tr_breakpoint_check, + .translate_insn =3D openrisc_tr_translate_insn, + .tb_stop =3D openrisc_tr_tb_stop, + .disas_log =3D openrisc_tr_disas_log, +}; + +void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) +{ + DisasContext ctx; + + translator_loop(&openrisc_tr_ops, &ctx.base, cs, tb); } =20 void openrisc_cpu_dump_state(CPUState *cs, FILE *f, --=20 2.7.4