From nobody Thu Dec 18 13:19:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1624995450; cv=none; d=zohomail.com; s=zohoarc; b=QtG3cKzi3FB6yFktTIagfMhnTmD1VCdaZHc0SOdMiojA5hG3p9PEbLJeLW6jRlQTzqIQdGZq5glTPx2pBVbBPNPaTXnJCAmAHfA0ORkn5Y0m4BGTM33fF5fY1yDcTdfycve3SUomMXEwXpuxw7u7o+msMqAqrvg0GAnZFfSbJXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624995450; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xmxrOHZpSFj7JKNDeodYwqrJCJWQuRYw5m+Zqx3aVjs=; b=ht6WHcb6nngat3x834kS/xh0ceHyvfy7N+tGX9JpRJA+sHSyDyWb8t8VrW9ruTGKtK8kt7PFb6NAasXRzoNN55h2b9XC39wjwp8vukvksXmRDTTi+XBlBn2ctvcNKhlC7t0mqbj2vznfqW8fJZWaw0vPkTlP0F5JP06BdBD1FzA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1624995450748890.6389145619237; Tue, 29 Jun 2021 12:37:30 -0700 (PDT) Received: from localhost ([::1]:46782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyJY1-0001FM-Pe for importer@patchew.org; Tue, 29 Jun 2021 15:37:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyItA-0007zQ-CQ for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:55:16 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:41747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyIsu-0000r4-LT for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:55:11 -0400 Received: by mail-pf1-x436.google.com with SMTP id c5so90057pfv.8 for ; Tue, 29 Jun 2021 11:54:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id j2sm18811253pfb.53.2021.06.29.11.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:54:58 -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=xmxrOHZpSFj7JKNDeodYwqrJCJWQuRYw5m+Zqx3aVjs=; b=yac47MRFCKHKskEwMeKBvakn9qRM0Orp7ZqDBMCz6pN6ANph1hBcDdep/OpwnRyKGU 8bHCnRBjbyb0JLMEzI3Ni7+Mgp0cKfRUTf8siWsyGIjVV8rsmtzsG4+XzWHyLsVysZ+O Cs5YSSsRYKJa+ue09kPRvzMUXorZYmHuf6Q2sipCP/nul24htT6bp9Sz6kVPPqJcmFBv voeRW/Jppv4fUdqftNRsuhka/r6U4SjzLqdsYsU4E+QGuChSCl3mcLlsSGbCL9fQ23uS e4QyZV0FQA5B85b21BgEXFEZ5xD99GolVA+fv4kzRKRGnYhn1Uf9U4mWrFZif7jj4aid FFXw== 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:mime-version:content-transfer-encoding; bh=xmxrOHZpSFj7JKNDeodYwqrJCJWQuRYw5m+Zqx3aVjs=; b=pSCAqp00TNecC0cQZHWmNytnCxYPUd8hoZTLoszsVudpRxXbG5kU0zu2ZbjHaE94rH Hv8klSS0GY/feZhguvh1D796NoIjNbMR1IA8IGvf+mjVpLLBxo9VaxX6BXPhN/4ftRgH zmReU9sVi3++dZNzg5y+Nd8EWTlcjdhPvui2eGYgb6x1vIk1WRs2sMe13uU8mvSrtDkY +K2QrXd5jFSUcZYHOCR6smXNBSOO0OqTcz1t2f9VLkojXPYhM/GVTm8Yqwg6OFXBdT4r xdfkGRB/3/5aWzVxhIePYpQLI7KLu88bHoCLRKJi8qgUX1c9nzzSvoyQB7TAewqJZDGs 2arg== X-Gm-Message-State: AOAM531HpYzgS+MQ7wi0B+oy0RaIRS09KbIfQDxuGMPu0ExC6/xo2Y/y hbj+kIJ5UyPqM5OYFxy/CdhxKXQrcPsNMQ== X-Google-Smtp-Source: ABdhPJw8+kgCJb59f6p8pL77AAyWTASZidLHJCv0m2li+bptev+oUFTuUxkD70YttGR87Lgae2u4Kg== X-Received: by 2002:a65:41c6:: with SMTP id b6mr29807514pgq.206.1624992899013; Tue, 29 Jun 2021 11:54:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 05/63] target/nios2: Convert to TranslatorOps Date: Tue, 29 Jun 2021 11:53:57 -0700 Message-Id: <20210629185455.3131172-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210629185455.3131172-1-richard.henderson@linaro.org> References: <20210629185455.3131172-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/nios2/translate.c | 128 ++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 64cba02230..66f4c25b06 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -803,74 +803,69 @@ static void gen_exception(DisasContext *dc, uint32_t = excp) } =20 /* generate intermediate code for basic block 'tb'. */ -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_ins= ns) +static void nios2_tr_init_disas_context(DisasContextBase *dcbase, CPUState= *cs) { + DisasContext *dc =3D container_of(dcbase, DisasContext, base); CPUNios2State *env =3D cs->env_ptr; - DisasContext dc1, *dc =3D &dc1; - int num_insns; - - /* Initialize DC */ - - dc->base.tb =3D tb; - dc->base.singlestep_enabled =3D cs->singlestep_enabled; - dc->base.is_jmp =3D DISAS_NEXT; - dc->base.pc_first =3D tb->pc; - dc->base.pc_next =3D tb->pc; + int page_insns; =20 dc->mem_idx =3D cpu_mmu_index(env, false); =20 - /* Set up instruction counts */ - num_insns =3D 0; - if (max_insns > 1) { - int page_insns =3D (TARGET_PAGE_SIZE - (tb->pc & ~TARGET_PAGE_MASK= )) / 4; - if (max_insns > page_insns) { - max_insns =3D page_insns; - } - } + /* Bound the number of insns to execute to those left on the page. */ + page_insns =3D -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; + dc->base.max_insns =3D MIN(page_insns, dc->base.max_insns); +} =20 - gen_tb_start(tb); - do { - tcg_gen_insn_start(dc->base.pc_next); - num_insns++; +static void nios2_tr_tb_start(DisasContextBase *db, CPUState *cs) +{ +} =20 - if (unlikely(cpu_breakpoint_test(cs, dc->base.pc_next, BP_ANY))) { - gen_exception(dc, EXCP_DEBUG); - /* 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->pc +=3D 4; - break; - } +static void nios2_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) +{ + tcg_gen_insn_start(dcbase->pc_next); +} =20 - if (num_insns =3D=3D max_insns && (tb_cflags(tb) & CF_LAST_IO)) { - gen_io_start(); - } +static bool nios2_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *= cs, + const CPUBreakpoint *bp) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); =20 - dc->pc =3D dc->base.pc_next; - dc->base.pc_next +=3D 4; + gen_exception(dc, EXCP_DEBUG); + /* + * 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; +} =20 - /* Decode an instruction */ - handle_instruction(dc, env); +static void nios2_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); + CPUNios2State *env =3D cs->env_ptr; =20 - /* Translation stops when a conditional branch is encountered. - * Otherwise the subsequent code could get translated several time= s. - * Also stop translation when a page boundary is reached. This - * ensures prefetch aborts occur at the right place. */ - } while (!dc->base.is_jmp && - !tcg_op_buf_full() && - num_insns < max_insns); + dc->pc =3D dc->base.pc_next; + dc->base.pc_next +=3D 4; + + /* Decode an instruction */ + handle_instruction(dc, env); +} + +static void nios2_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc =3D container_of(dcbase, DisasContext, base); =20 /* Indicate where the next block should start */ switch (dc->base.is_jmp) { - case DISAS_NEXT: + case DISAS_TOO_MANY: case DISAS_UPDATE: /* Save the current PC back into the CPU register */ tcg_gen_movi_tl(cpu_R[R_PC], dc->base.pc_next); tcg_gen_exit_tb(NULL, 0); break; =20 - default: case DISAS_JUMP: /* The jump will already have updated the PC register */ tcg_gen_exit_tb(NULL, 0); @@ -879,25 +874,32 @@ void gen_intermediate_code(CPUState *cs, TranslationB= lock *tb, int max_insns) case DISAS_NORETURN: /* nothing more to generate */ break; + + default: + g_assert_not_reached(); } +} =20 - /* End off the block */ - gen_tb_end(tb, num_insns); +static void nios2_tr_disas_log(const DisasContextBase *dcbase, CPUState *c= pu) +{ + qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first)); + log_target_disas(cpu, dcbase->pc_first, dcbase->tb->size); +} =20 - /* Mark instruction starts for the final generated instruction */ - tb->size =3D dc->base.pc_next - dc->base.pc_first; - tb->icount =3D num_insns; +static const TranslatorOps nios2_tr_ops =3D { + .init_disas_context =3D nios2_tr_init_disas_context, + .tb_start =3D nios2_tr_tb_start, + .insn_start =3D nios2_tr_insn_start, + .breakpoint_check =3D nios2_tr_breakpoint_check, + .translate_insn =3D nios2_tr_translate_insn, + .tb_stop =3D nios2_tr_tb_stop, + .disas_log =3D nios2_tr_disas_log, +}; =20 -#ifdef DEBUG_DISAS - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) - && qemu_log_in_addr_range(dc->base.pc_first)) { - FILE *logfile =3D qemu_log_lock(); - qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first)); - log_target_disas(cs, tb->pc, tb->size); - qemu_log("\n"); - qemu_log_unlock(logfile); - } -#endif +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_ins= ns) +{ + DisasContext dc; + translator_loop(&nios2_tr_ops, &dc.base, cs, tb, max_insns); } =20 void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags) --=20 2.25.1