From patchwork Wed May 9 17:54:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135342 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp64702lji; Wed, 9 May 2018 11:12:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpAWzgAVRJe8ntyHs90Z6TILxRRZGpeG+djjVhbmCzVk0SFfZIPJu2wWbwlJqldGs8ifa3j X-Received: by 2002:ac8:18ad:: with SMTP id s42-v6mr43872439qtj.184.1525889545633; Wed, 09 May 2018 11:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525889545; cv=none; d=google.com; s=arc-20160816; b=RQ4057MkjHG0VEYIJE/OVvrt/qrHRAV4fo2RhMpYPy8Tu3Kq72s8XsNVxQGhE/hrC2 LKMjq14xVqcOVUw3dgz/irPVrbkQaUz61RF9AIunH+v7vtFXFlAcVSEjgAlY+IXJlCBB bJlhAyvjVx+9yXwTGq83UsnzY0BjaX8ner9TNibBMyHBkXM/TI6IDj9f5FmO87LbeAMX iovVqdHyIyENDtP1DB0nn2dceoCnAOX0YZjDfLvxb/Hq5WZ972R7SuILTPo7SfJ6WfM0 uho3qq6VnyeHCRyk6d7F5oPIIZnr+rAZCROMFzIm84fjzq0CWX1SYohKi9+Kkc/FSdY5 Wd2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=RrzxbadUz70+EV3BNNYMqG1CCzYhhDuJBMQPCSousZ4=; b=rw8AhEPgPncd9Ngmiot8AUcFQK+1S+ku2E1L/mGhBmpo+J7z7+lswuN6Z0H4Rz2D9P iJarya0YWfJPFWN9T1uEf7uiS2cDlCL/PyB9aY5o8iPyNa/pfs+UDcxW2CEKLgQXbtpJ 8XrF4rDFpLiMw7bFBSEcQ9NJdNgyDmKSQR/ipyBRLYzNOzAm7QZjMauFw1vDfNCkUR4r tYSO6C29qiuO2necmSpdB0+y3epzwJwsz5TY3MNuBdwWYl+wGrn+2+h7W66nQCLRXH49 VF0cymSCZlQtyq6b3a7N+WhgYY+Sg7LY1hA2S36jK4aWXKPQjPs30ioB4i4c0hsyHpsG CA+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XdgjC0eK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g4si4391857qkm.163.2018.05.09.11.12.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 May 2018 11:12:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XdgjC0eK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTZh-0006RX-2L for patch@linaro.org; Wed, 09 May 2018 14:12:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJr-0005pf-Eh for qemu-devel@nongnu.org; Wed, 09 May 2018 13:56:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTJf-0006Oq-3P for qemu-devel@nongnu.org; Wed, 09 May 2018 13:56:03 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:43432) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTJe-0006NP-PQ for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:50 -0400 Received: by mail-pg0-x241.google.com with SMTP id k11-v6so21887871pgo.10 for ; Wed, 09 May 2018 10:55:50 -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=RrzxbadUz70+EV3BNNYMqG1CCzYhhDuJBMQPCSousZ4=; b=XdgjC0eKqqMsc+Xf3nb9qTMCMhpBhlQT+WNYFXRWRMxs3yBcB+ynWdZbuEaivOs55Z zeTmoNVKaJjMqnAEF8WhbxOzh36i1+Qw5SQf6t6KZ4BjqsoLi+yhSVeU27clslxEiWQ+ O3zJEyLiKg5zN8tWGR7WAiRjp5p68eXPgvgsU= 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=RrzxbadUz70+EV3BNNYMqG1CCzYhhDuJBMQPCSousZ4=; b=VocWa3bLANi8ylWz94xJrG7RscCkdksrLUTpi1tFaNDv8EArlvGrkvXCcO8TX/Jfm2 Piyd9RtSQ8IIewqBS66afWy/I9XdEZwkOUDBHQtDQNBCL/ez15fkEwPndXWat7hOAFOw s+r+aZIiIXvd09jMClol0wsLcabk9ekzxmAGmamOZi1jzEFv9u9p3PpIMufcV/PqyTM8 cd3PfoIkT6MFe/0z6Nw6ul4I3Z73RyKfYH0z5c/NIpFg0/Bn4piz29uIB5f5d/4uR9nU ZvdC7NGbOrje01gj9DritgXMAPi/zrIiE7sdl91peLhBNvuBa6hAR5Rv50wwQtAy7z4Q 5kbg== X-Gm-Message-State: ALKqPwdmwZyTgmsz9aN4BQNkJCXvtecCQHmjiaOGA4aqBTq0KKdFaAls rcR723rmiy8ChCUfimklADJm4bu/tyo= X-Received: by 2002:a63:755a:: with SMTP id f26-v6mr1871985pgn.30.1525888549357; Wed, 09 May 2018 10:55:49 -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.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:58 -0700 Message-Id: <20180509175458.15642-29-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:c05::241 Subject: [Qemu-devel] [PULL 28/28] target/riscv: 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: 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Reviewed-by: Richard Henderson Reviewed-by: 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 | 148 ++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 73 deletions(-) -- 2.17.0 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 68979abfd7..1788668c6f 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1837,78 +1837,71 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx) } } -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) +static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) { - CPURISCVState *env = cs->env_ptr; - DisasContext ctx; - target_ulong page_start; - int num_insns; - int max_insns; + DisasContext *ctx = container_of(dcbase, DisasContext, base); - ctx.base.pc_first = tb->pc; - ctx.base.pc_next = ctx.base.pc_first; - /* once we have GDB, the rest of the translate.c implementation should be - ready for singlestep */ - ctx.base.singlestep_enabled = cs->singlestep_enabled; - ctx.base.tb = tb; - ctx.base.is_jmp = DISAS_NEXT; + ctx->pc_succ_insn = ctx->base.pc_first; + ctx->flags = ctx->base.tb->flags; + ctx->mem_idx = ctx->base.tb->flags & TB_FLAGS_MMU_MASK; + ctx->frm = -1; /* unknown rounding mode */ +} - page_start = ctx.base.pc_first & TARGET_PAGE_MASK; - ctx.pc_succ_insn = ctx.base.pc_first; - ctx.flags = tb->flags; - ctx.mem_idx = tb->flags & TB_FLAGS_MMU_MASK; - ctx.frm = -1; /* unknown rounding mode */ +static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) +{ +} - num_insns = 0; - max_insns = tb_cflags(ctx.base.tb) & CF_COUNT_MASK; - if (max_insns == 0) { - max_insns = CF_COUNT_MASK; - } - if (max_insns > TCG_MAX_INSNS) { - max_insns = TCG_MAX_INSNS; - } - gen_tb_start(tb); +static void riscv_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) +{ + DisasContext *ctx = container_of(dcbase, DisasContext, base); - while (ctx.base.is_jmp == DISAS_NEXT) { - tcg_gen_insn_start(ctx.base.pc_next); - num_insns++; + tcg_gen_insn_start(ctx->base.pc_next); +} - if (unlikely(cpu_breakpoint_test(cs, ctx.base.pc_next, BP_ANY))) { - tcg_gen_movi_tl(cpu_pc, ctx.base.pc_next); - ctx.base.is_jmp = 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 - properly cleared -- thus we increment the PC here so that - the logic setting tb->size below does the right thing. */ - ctx.base.pc_next += 4; - goto done_generating; - } +static bool riscv_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, + const CPUBreakpoint *bp) +{ + DisasContext *ctx = container_of(dcbase, DisasContext, base); - if (num_insns == max_insns && (tb_cflags(ctx.base.tb) & CF_LAST_IO)) { - gen_io_start(); - } + tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); + ctx->base.is_jmp = 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 + properly cleared -- thus we increment the PC here so that + the logic setting tb->size below does the right thing. */ + ctx->base.pc_next += 4; + return true; +} - ctx.opcode = cpu_ldl_code(env, ctx.base.pc_next); - decode_opc(env, &ctx); - ctx.base.pc_next = ctx.pc_succ_insn; - if (ctx.base.is_jmp == DISAS_NEXT && - (cs->singlestep_enabled || - ctx.base.pc_next - page_start >= TARGET_PAGE_SIZE || - tcg_op_buf_full() || - num_insns >= max_insns || - singlestep)) { - ctx.base.is_jmp = DISAS_TOO_MANY; +static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +{ + DisasContext *ctx = container_of(dcbase, DisasContext, base); + CPURISCVState *env = cpu->env_ptr; + + ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); + decode_opc(env, ctx); + ctx->base.pc_next = ctx->pc_succ_insn; + + if (ctx->base.is_jmp == DISAS_NEXT) { + target_ulong page_start; + + page_start = ctx->base.pc_first & TARGET_PAGE_MASK; + if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE) { + ctx->base.is_jmp = DISAS_TOO_MANY; } } - if (tb_cflags(ctx.base.tb) & CF_LAST_IO) { - gen_io_end(); - } - switch (ctx.base.is_jmp) { +} + +static void riscv_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) +{ + DisasContext *ctx = container_of(dcbase, DisasContext, base); + + switch (ctx->base.is_jmp) { case DISAS_TOO_MANY: - tcg_gen_movi_tl(cpu_pc, ctx.base.pc_next); - if (cs->singlestep_enabled) { + tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); + if (ctx->base.singlestep_enabled) { gen_exception_debug(); } else { tcg_gen_exit_tb(0); @@ -1919,20 +1912,29 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) default: g_assert_not_reached(); } -done_generating: - gen_tb_end(tb, num_insns); - tb->size = ctx.base.pc_next - ctx.base.pc_first; - tb->icount = num_insns; +} -#ifdef DEBUG_DISAS - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) - && qemu_log_in_addr_range(ctx.base.pc_first)) { - qemu_log("IN: %s\n", lookup_symbol(ctx.base.pc_first)); - log_target_disas(cs, ctx.base.pc_first, - ctx.base.pc_next - ctx.base.pc_first); - qemu_log("\n"); - } -#endif +static void riscv_tr_disas_log(const DisasContextBase *dcbase, CPUState *cpu) +{ + qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first)); + log_target_disas(cpu, dcbase->pc_first, dcbase->tb->size); +} + +static const TranslatorOps riscv_tr_ops = { + .init_disas_context = riscv_tr_init_disas_context, + .tb_start = riscv_tr_tb_start, + .insn_start = riscv_tr_insn_start, + .breakpoint_check = riscv_tr_breakpoint_check, + .translate_insn = riscv_tr_translate_insn, + .tb_stop = riscv_tr_tb_stop, + .disas_log = riscv_tr_disas_log, +}; + +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) +{ + DisasContext ctx; + + translator_loop(&riscv_tr_ops, &ctx.base, cs, tb); } void riscv_translate_init(void)