From patchwork Wed Sep 6 16:06:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111830 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1149789qge; Wed, 6 Sep 2017 09:30:38 -0700 (PDT) X-Received: by 10.55.12.133 with SMTP id 127mr4049075qkm.251.1504715438699; Wed, 06 Sep 2017 09:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504715438; cv=none; d=google.com; s=arc-20160816; b=V1mkJbSEbAkFmm0x9UZWog4cNGg9hdy6QZWk98+na/xdZT1oN2o4IP0UrX2ETFBMPP MGUx53RLFGHXB1gDCug6yXAij8JTBSd5U1WP71MkoGkj3QbfUAbcbaAcs+/bcLQUiaii huBPPDrAxX6iU3DOhk6BDn0Veiz8JhKnhwfqsHkWjbxHwsbkrCJSUfOuVzRC22l4URI3 HC7ZYPfy5jwaL6oU1ajKYhIrRuoULhnkap1eklvzuM4+57wmHdOF2/PPVE9zSebchBvJ fcitXFs9fCaYnhQSGiP+IGAiVrJXsM0uWnOYBxiFy6Zcq8Kzr4kszT6+IUYKwLuq9UGu dc9w== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Tmhd7lJTCptCpYf1L1lrkBjfQN41pZppSXIWh62yW1E=; b=JGwYB5I7kXQgLWRfP/yrbs7X8F9WzalnG4Y6MBjtlVr6jctjuvHidhYfhJlUNVT8z0 THvjl/UJ8Vq125HaGTzc9pQwTc/Qf57ARuEw8hDWa3DcHV0Y+ejavUTuKMnkw/aclTDW Fit0HwjrIV+Xoq0wJwWFUKm/Db7dcRud+PEBDeTjpD14mFKBmJ3kbB2Wuw7Hh5hq1Kby l+T7U1+9h8R0dH2Arwr47DcOBGLO+/ya8lSqcSLcB+c8X2tMCkqQZrLP2i8IvCO0wrsb b9a+897x9MnetRgykM8+vMAzkTUxzbV8qDFpzhytClX08T3dM319YSOPcbxtC8DwfBxv kbLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XCaqWd0/; 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 w20si244971qkb.172.2017.09.06.09.30.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 06 Sep 2017 09:30:38 -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=XCaqWd0/; 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]:37068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpdDo-0003qn-9L for patch@linaro.org; Wed, 06 Sep 2017 12:30:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcqn-0000MH-BZ for qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpcqk-0002fj-0s for qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:49 -0400 Received: from mail-pg0-x22d.google.com ([2607:f8b0:400e:c05::22d]:35580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpcqj-0002dc-Ml for qemu-devel@nongnu.org; Wed, 06 Sep 2017 12:06:45 -0400 Received: by mail-pg0-x22d.google.com with SMTP id 188so12738604pgb.2 for ; Wed, 06 Sep 2017 09:06:45 -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=Tmhd7lJTCptCpYf1L1lrkBjfQN41pZppSXIWh62yW1E=; b=XCaqWd0/hr5vjFWUqqmiVMsr9ot7IdCA+NTNNeHf/6Oo5WvqEd1bRxYraEVzf2wVOz EOj9XTa5ZlZKVLu1eDy1j5gxy+q2//O3Koxdh5hnZLVgG3QG3DrNZJH+C6/QC3nC2II3 3IJ1e+W9iYNl7rrUWmh4hU0jW3DHc0H+KklxM= 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=Tmhd7lJTCptCpYf1L1lrkBjfQN41pZppSXIWh62yW1E=; b=ljTnK1lF/py/drcXvuVLLgZ0e8yOORWyheqPpsdsgzlsvWX1XhEnTCGFRuyjBuJJaM FOGUobCDib1PHFyBc25sL6qSxjEEAdxfn/PVhqqhQEiKeqK5hBa9PHzM8Uypmsxxy4f5 ROylJQMxqDaKYl8VQZhB/7Hdb10ShqDPS71iNaBSkvr/zQ6mxy0IBZFwF2La4Wi89pWd NSegH9yqKzc9BppcJe+BXeWL9gHJi8GIL/6qVwI9kX/wKJf01AcP5uWZFs8Hzq+X8ehr vMBXP1lKgMvZMMcJ6Oj0eLzBCB8HSyIYrdiLDwmaCnu0ZVZmmw/0hauwFPMNEQ67i/3W WHpQ== X-Gm-Message-State: AHPjjUgqYgXsSW7AL2+tgYrEjFkEgY0F7vgA0nbwFTk5kJJ1OzL5488r f3WuyIJUYt1EQGLafv8yfw== X-Google-Smtp-Source: ADKCNb7tLq93Qz5aZWCd8RbFy9EJa6dJTf2LfOxrdUVMHoDwiUw3ifHE2p6EhjduMmkwSVFmd0Z9hA== X-Received: by 10.98.35.210 with SMTP id q79mr7817950pfj.340.1504714004230; Wed, 06 Sep 2017 09:06:44 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id t65sm262863pfk.59.2017.09.06.09.06.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Sep 2017 09:06:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 09:06:02 -0700 Message-Id: <20170906160612.22769-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170906160612.22769-1-richard.henderson@linaro.org> References: <20170906160612.22769-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22d Subject: [Qemu-devel] [PULL 22/32] target/arm: [tcg] Port to translate_insn 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, =?utf-8?q?Llu=C3=ADs_Vilanova?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Lluís Vilanova Incrementally paves the way towards using the generic instruction translation loop. Reviewed-by: Emilio G. Cota Signed-off-by: Lluís Vilanova Message-Id: <150002485863.22386.13949856269576226529.stgit@frigg.lan> [rth: Adjust for translate_insn interface change.] Signed-off-by: Richard Henderson --- target/arm/translate.h | 1 + target/arm/translate.c | 165 +++++++++++++++++++++++++++---------------------- 2 files changed, 91 insertions(+), 75 deletions(-) -- 2.13.5 diff --git a/target/arm/translate.h b/target/arm/translate.h index a804ff65ac..e8dcec51ac 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -9,6 +9,7 @@ typedef struct DisasContext { DisasContextBase base; target_ulong pc; + target_ulong next_page_start; uint32_t insn; /* Nonzero if this instruction has been conditionally skipped. */ int condjmp; diff --git a/target/arm/translate.c b/target/arm/translate.c index 2f5f65310d..5737299943 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -11880,6 +11880,8 @@ static int arm_tr_init_disas_context(DisasContextBase *dcbase, dc->is_ldex = false; dc->ss_same_el = false; /* Can't be true since EL_d must be AArch64 */ + dc->next_page_start = + (dc->base.pc_first & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; cpu_F0s = tcg_temp_new_i32(); cpu_F1s = tcg_temp_new_i32(); @@ -11973,14 +11975,93 @@ static bool arm_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, return true; } +static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); + CPUARMState *env = cpu->env_ptr; + +#ifdef CONFIG_USER_ONLY + /* Intercept jump to the magic kernel page. */ + if (dc->pc >= 0xffff0000) { + /* We always get here via a jump, so know we are not in a + conditional execution block. */ + gen_exception_internal(EXCP_KERNEL_TRAP); + dc->base.is_jmp = DISAS_NORETURN; + return; + } +#endif + + if (dc->ss_active && !dc->pstate_ss) { + /* Singlestep state is Active-pending. + * If we're in this state at the start of a TB then either + * a) we just took an exception to an EL which is being debugged + * and this is the first insn in the exception handler + * b) debug exceptions were masked and we just unmasked them + * without changing EL (eg by clearing PSTATE.D) + * In either case we're going to take a swstep exception in the + * "did not step an insn" case, and so the syndrome ISV and EX + * bits should be zero. + */ + assert(dc->base.num_insns == 1); + gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0), + default_exception_el(dc)); + dc->base.is_jmp = DISAS_NORETURN; + return; + } + + if (dc->thumb) { + disas_thumb_insn(env, dc); + if (dc->condexec_mask) { + dc->condexec_cond = (dc->condexec_cond & 0xe) + | ((dc->condexec_mask >> 4) & 1); + dc->condexec_mask = (dc->condexec_mask << 1) & 0x1f; + if (dc->condexec_mask == 0) { + dc->condexec_cond = 0; + } + } + } else { + unsigned int insn = arm_ldl_code(env, dc->pc, dc->sctlr_b); + dc->pc += 4; + disas_arm_insn(dc, insn); + } + + if (dc->condjmp && !dc->base.is_jmp) { + gen_set_label(dc->condlabel); + dc->condjmp = 0; + } + + if (dc->base.is_jmp == DISAS_NEXT) { + /* Translation stops when a conditional branch is encountered. + * Otherwise the subsequent code could get translated several times. + * Also stop translation when a page boundary is reached. This + * ensures prefetch aborts occur at the right place. */ + + if (is_singlestepping(dc)) { + dc->base.is_jmp = DISAS_TOO_MANY; + } else if ((dc->pc >= dc->next_page_start) || + ((dc->pc >= dc->next_page_start - 3) && + insn_crosses_page(env, dc))) { + /* We want to stop the TB if the next insn starts in a new page, + * or if it spans between this page and the next. This means that + * if we're looking at the last halfword in the page we need to + * see if it's a 16-bit Thumb insn (which will fit in this TB) + * or a 32-bit Thumb insn (which won't). + * This is to avoid generating a silly TB with a single 16-bit insn + * in it at the end of this page (which would execute correctly + * but isn't very efficient). + */ + dc->base.is_jmp = DISAS_TOO_MANY; + } + } + + dc->base.pc_next = dc->pc; +} + /* generate intermediate code for basic block 'tb'. */ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) { - CPUARMState *env = cs->env_ptr; DisasContext dc1, *dc = &dc1; - target_ulong next_page_start; int max_insns; - bool end_of_page; /* generate intermediate code */ @@ -11999,7 +12080,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) dc->base.num_insns = 0; dc->base.singlestep_enabled = cs->singlestep_enabled; - next_page_start = (dc->base.pc_first & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) { max_insns = CF_COUNT_MASK; @@ -12036,83 +12116,18 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) gen_io_start(); } -#ifdef CONFIG_USER_ONLY - /* Intercept jump to the magic kernel page. */ - if (dc->pc >= 0xffff0000) { - /* We always get here via a jump, so know we are not in a - conditional execution block. */ - gen_exception_internal(EXCP_KERNEL_TRAP); - dc->base.is_jmp = DISAS_NORETURN; - break; - } -#endif - - if (dc->ss_active && !dc->pstate_ss) { - /* Singlestep state is Active-pending. - * If we're in this state at the start of a TB then either - * a) we just took an exception to an EL which is being debugged - * and this is the first insn in the exception handler - * b) debug exceptions were masked and we just unmasked them - * without changing EL (eg by clearing PSTATE.D) - * In either case we're going to take a swstep exception in the - * "did not step an insn" case, and so the syndrome ISV and EX - * bits should be zero. - */ - assert(dc->base.num_insns == 1); - gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0), - default_exception_el(dc)); - dc->base.is_jmp = DISAS_NORETURN; - break; - } - - if (dc->thumb) { - disas_thumb_insn(env, dc); - if (dc->condexec_mask) { - dc->condexec_cond = (dc->condexec_cond & 0xe) - | ((dc->condexec_mask >> 4) & 1); - dc->condexec_mask = (dc->condexec_mask << 1) & 0x1f; - if (dc->condexec_mask == 0) { - dc->condexec_cond = 0; - } - } - } else { - unsigned int insn = arm_ldl_code(env, dc->pc, dc->sctlr_b); - dc->pc += 4; - disas_arm_insn(dc, insn); - } - - if (dc->condjmp && !dc->base.is_jmp) { - gen_set_label(dc->condlabel); - dc->condjmp = 0; - } + arm_tr_translate_insn(&dc->base, cs); if (tcg_check_temp_count()) { fprintf(stderr, "TCG temporary leak before "TARGET_FMT_lx"\n", dc->pc); } - /* Translation stops when a conditional branch is encountered. - * Otherwise the subsequent code could get translated several times. - * Also stop translation when a page boundary is reached. This - * ensures prefetch aborts occur at the right place. */ - - /* We want to stop the TB if the next insn starts in a new page, - * or if it spans between this page and the next. This means that - * if we're looking at the last halfword in the page we need to - * see if it's a 16-bit Thumb insn (which will fit in this TB) - * or a 32-bit Thumb insn (which won't). - * This is to avoid generating a silly TB with a single 16-bit insn - * in it at the end of this page (which would execute correctly - * but isn't very efficient). - */ - end_of_page = (dc->pc >= next_page_start) || - ((dc->pc >= next_page_start - 3) && insn_crosses_page(env, dc)); - - } while (!dc->base.is_jmp && !tcg_op_buf_full() && - !is_singlestepping(dc) && - !singlestep && - !end_of_page && - dc->base.num_insns < max_insns); + if (!dc->base.is_jmp && (tcg_op_buf_full() || singlestep || + dc->base.num_insns >= max_insns)) { + dc->base.is_jmp = DISAS_TOO_MANY; + } + } while (!dc->base.is_jmp); if (tb->cflags & CF_LAST_IO) { if (dc->condjmp) {