From patchwork Thu Jun 2 20:07:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9151163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8A3960221 for ; Thu, 2 Jun 2016 20:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 998252656B for ; Thu, 2 Jun 2016 20:23:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DA6B28328; Thu, 2 Jun 2016 20:23:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D03852656B for ; Thu, 2 Jun 2016 20:23:43 +0000 (UTC) Received: from localhost ([::1]:50185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Z9b-0004JI-0O for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 16:23:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Yts-0006Js-Js for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Ytp-0003nb-Tp for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:27 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Ytp-0003nS-5w for qemu-devel@nongnu.org; Thu, 02 Jun 2016 16:07:25 -0400 Received: by mail-wm0-x243.google.com with SMTP id a20so7043024wma.3 for ; Thu, 02 Jun 2016 13:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qBvIy92daQIKGuKPMA6CvFxGDX1RmpWcdwh6+4PQHK8=; b=YNAw82inD4aGCwyKtBa806DdJWthQFcOc1VodBo2DWyAaJO02eJbKu9y3QDBavLr0x dlWwQeFz605vi1FvhNoOzAFGtIK6FD4HDlA3i9eY5o+JTk+1Ne+9jC4aiQsHMdwDRjHQ 2oEjClisc3LS4q3tx4zxRwySY7Iz2F74GdymK0Oo1XIkTXdakHfGHt0dX1Orv50GGFu+ UiBjDCVTQeRkyNHyqYNNjXWT3MUpdYnuKaB6DqRxd+uuJoXWOYQGI777QGfvRe06843E 611NatSLlA0XgflUZmU7DkYldYyuTpEBYMjKaTuwk7qZltO92YvgPPyxqZVFZFjMJzEL KdAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qBvIy92daQIKGuKPMA6CvFxGDX1RmpWcdwh6+4PQHK8=; b=eiUxZDkf6MT/alcOU5bArOCuZvs722qMmqXZ7gMHiS7KqUtHvopL8cvcD4zSFBrVpT t3bR/6zJJlQmxBoOlCO15+cwVduXKn+iFkYSk1pzoT3YhcDwsMmoPDxFGW8qYHFPGPQN L95epK7KwMxL1kaefni76Fof4pamORNbPWte1Fb9VRCUesN2MbUefdgzohuhdMG2vJvH C14xVxpw1ch/pFqsyRka7wMGp2nQvJPfTy6AGodo8o35TUJp/ogX/vWUHwfuLF2B1kth HWD+RZlrpR54qpLOZRHaBoH1bE033vFPw7WaQ4I2trlkFDROxib3lsXcYWjr4PeLvWuZ x/Zg== X-Gm-Message-State: ALyK8tLOtC+Oa3OvqCrh8zG4zGRQbPouG16bSNkExHCD0BkEI3ebNn9J44+Gdp4gm0gQjw== X-Received: by 10.28.184.83 with SMTP id i80mr29197005wmf.66.1464898044564; Thu, 02 Jun 2016 13:07:24 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([94.230.86.227]) by smtp.gmail.com with ESMTPSA id i4sm2127090wjj.49.2016.06.02.13.07.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:07:24 -0700 (PDT) From: Michael Rolnik X-Google-Original-From: Michael Rolnik To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 23:07:01 +0300 Message-Id: <1464898022-97990-9-git-send-email-rolnik@amazon.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1464898022-97990-1-git-send-email-rolnik@amazon.com> References: <1464898022-97990-1-git-send-email-rolnik@amazon.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 09/10] target-avr: updating translate.c to use instructions translation 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: Michael Rolnik , Michael Rolnik Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Michael Rolnik --- target-avr/Makefile.objs | 4 +- target-avr/translate.c | 148 ++++++++++++++++++++++------------------------- 2 files changed, 72 insertions(+), 80 deletions(-) diff --git a/target-avr/Makefile.objs b/target-avr/Makefile.objs index c503546..8d06d54 100644 --- a/target-avr/Makefile.objs +++ b/target-avr/Makefile.objs @@ -1,3 +1,5 @@ -obj-y += translate.o cpu.o helper.o +obj-y += translate.o helper.o cpu.o translate-inst.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o + +obj-y += decode.o diff --git a/target-avr/translate.c b/target-avr/translate.c index e98aaef..0df0184 100644 --- a/target-avr/translate.c +++ b/target-avr/translate.c @@ -18,60 +18,31 @@ * */ -#include "qemu/osdep.h" - -#include "cpu.h" -#include "exec/exec-all.h" -#include "disas/disas.h" -#include "tcg-op.h" -#include "exec/cpu_ldst.h" - -#include "exec/helper-proto.h" -#include "exec/helper-gen.h" -#include "exec/log.h" - -typedef struct DisasContext DisasContext; -typedef struct InstInfo InstInfo; - -/*This is the state at translation time. */ -struct DisasContext { - struct TranslationBlock *tb; - - /*Routine used to access memory */ - int memidx; - int bstate; - int singlestep; -}; - -enum { - BS_NONE = 0, /* Nothing special (none of the below */ - BS_STOP = 1, /* We want to stop translation for any reason */ - BS_BRANCH = 2, /* A branch condition is reached */ - BS_EXCP = 3, /* An exception condition is reached */ -}; - -static TCGv_env cpu_env; - -static TCGv cpu_pc; - -static TCGv cpu_Cf; -static TCGv cpu_Zf; -static TCGv cpu_Nf; -static TCGv cpu_Vf; -static TCGv cpu_Sf; -static TCGv cpu_Hf; -static TCGv cpu_Tf; -static TCGv cpu_If; - -static TCGv cpu_rampD; -static TCGv cpu_rampX; -static TCGv cpu_rampY; -static TCGv cpu_rampZ; - -static TCGv cpu_io[64]; -static TCGv cpu_r[32]; -static TCGv cpu_eind; -static TCGv cpu_sp; +#include "translate.h" + + +TCGv_env cpu_env; + +TCGv cpu_pc; + +TCGv cpu_Cf; +TCGv cpu_Zf; +TCGv cpu_Nf; +TCGv cpu_Vf; +TCGv cpu_Sf; +TCGv cpu_Hf; +TCGv cpu_Tf; +TCGv cpu_If; + +TCGv cpu_rampD; +TCGv cpu_rampX; +TCGv cpu_rampY; +TCGv cpu_rampZ; + +TCGv cpu_io[64]; +TCGv cpu_r[32]; +TCGv cpu_eind; +TCGv cpu_sp; #include "exec/gen-icount.h" #define REG(x) (cpu_r[x]) @@ -120,30 +91,42 @@ void avr_translate_init(void) done_init = 1; } -static inline void gen_goto_tb(CPUAVRState *env, - DisasContext *ctx, - int n, - target_ulong dest) +static void decode_opc( + AVRCPU *cpu, + DisasContext *ctx, + InstInfo *inst) { - TranslationBlock *tb; + CPUAVRState *env = &cpu->env; - tb = ctx->tb; + inst->opcode = cpu_ldl_code(env, inst->cpc * 2); /* pc points to words */ + inst->length = 16; + inst->translate = NULL; - if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) - && (ctx->singlestep == 0)) { - tcg_gen_goto_tb(n); - tcg_gen_movi_i32(cpu_pc, dest); - tcg_gen_exit_tb((uintptr_t)tb + n); - } else { - tcg_gen_movi_i32(cpu_pc, dest); + /* the following function looks onto the opcode as a string of bytes */ + avr_decode(inst->cpc, &inst->length, inst->opcode, &inst->translate); - if (ctx->singlestep) { - gen_helper_debug(cpu_env); - } - tcg_gen_exit_tb(0); + if (inst->length == 16) { + inst->npc = inst->cpc + 1; + /* get opcode as 16bit value */ + inst->opcode = inst->opcode & 0x0000ffff; + } + if (inst->length == 32) { + inst->npc = inst->cpc + 2; + /* get opcode as 32bit value */ + inst->opcode = (inst->opcode << 16) + | (inst->opcode >> 16); } } +uint32_t get_opcode( + uint8_t const *code, + unsigned bitBase, + unsigned bitSize) +{ + return *(uint16_t *)code; +} + + /*generate intermediate code for basic block 'tb'. */ void gen_intermediate_code( CPUAVRState *env, @@ -176,18 +159,21 @@ void gen_intermediate_code( gen_tb_start(tb); /* decode first instruction */ - cpc = pc_start; - npc = cpc + 1; + ctx.inst[0].cpc = pc_start; + decode_opc(cpu, &ctx, &ctx.inst[0]); do { - /* translate current instruction */ + /* set curr/next PCs */ + cpc = ctx.inst[0].cpc; + npc = ctx.inst[0].npc; + + /* decode next instruction */ + ctx.inst[1].cpc = ctx.inst[0].npc; + decode_opc(cpu, &ctx, &ctx.inst[1]); + + /* translate current instruction */ tcg_gen_insn_start(cpc); num_insns++; - /* just skip to next instruction */ - cpc++; - npc++; - ctx.bstate = BS_NONE; - if (unlikely(cpu_breakpoint_test(cs, cpc * 2, BP_ANY))) { tcg_gen_movi_i32(cpu_pc, cpc); gen_helper_debug(cpu_env); @@ -199,6 +185,8 @@ void gen_intermediate_code( goto done_generating; } + ctx.bstate = ctx.inst[0].translate(env, &ctx, ctx.inst[0].opcode); + if (num_insns >= max_insns) { break; /* max translated instructions limit reached */ } @@ -208,6 +196,8 @@ void gen_intermediate_code( if ((cpc & (TARGET_PAGE_SIZE - 1)) == 0) { break; /* page boundary */ } + + ctx.inst[0] = ctx.inst[1]; /* make next inst curr */ } while (ctx.bstate == BS_NONE && !tcg_op_buf_full()); if (tb->cflags & CF_LAST_IO) {