From patchwork Wed May 9 17:54:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135339 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp61494lji; Wed, 9 May 2018 11:09:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqlXx9KkAG1z9U6gffCOpW3kDR3yp8w2MywHSx/ep75MT5gqs2GYvyzi8ic8x0gTMc9sygA X-Received: by 10.55.18.155 with SMTP id 27mr37756662qks.96.1525889345196; Wed, 09 May 2018 11:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525889345; cv=none; d=google.com; s=arc-20160816; b=bmbfyyoZs7raXDnADLNTDhMoSMKr8yOQhyuXwZC/pEOLJTJ55jHFbVNVDDTEtvm0vN ZziWrfR1Z9w51fsNOEeSoxjUJrzzzeKshb7vOJ/gmCucLMeu+qD7pIePbb/1OuXBEARC ZTM9ezwyk0Bzz3P3Of1uWOP9vpfdqet8QCjKIaKK1rWbkWaKbHzIhiedI5bIgazvTUU0 0zCPbKLz0f2aSTXbe4UEqspSUDDGiMl1xHE2bLITfvSOlZ4xJM4XRqfrbJ5ZQJj+BOEA rB8jSrgFDwt67u/0/mrLXjn8Qu8ncale3wTBnha0/rbFWX7oy9y7aI8vzs6+YG/o8ftl QRqw== 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=oPERtIhZZZR4Xkb8MwvjjFgqIkTsmJoGkV3z4hVPZ+M=; b=JPA+6n1kyYg+6qy1UCw076CXHU9Wx+Hw9HOqch9gf4xxdty+eskTBiiM1vbbesqelb DkOug8Am9+Kq22tfOPhFDnWe3ao/+XU1yfZTgYMwtpO4GBHDyNGo6TecOHLwLfngS5xY 1tvnO2pfU/1YcUd3+wZpF1eQcgDJm39GlSmbwHHb/sHGqXxqShTLUJ0ypgZZxwI7dnkY tatR9cdJSKDshJvwwkjtivl3HHSWoKbuQinjpwxTgMZsji79LhRhnpVX+F9XJ2f4Bzev QglycvHoQpqXB3S93PqNgxkG8WgDZ24HW9jqwmxikxbWrgkU5wisUwjYZrsMpbyMx+pp WyBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C+5CGlYp; 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 56-v6si14355827qvs.107.2018.05.09.11.09.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 May 2018 11:09:05 -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=C+5CGlYp; 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]:58193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTWS-0002WL-It for patch@linaro.org; Wed, 09 May 2018 14:09:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJf-0005bZ-AA for qemu-devel@nongnu.org; Wed, 09 May 2018 13:56:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTJW-0006C2-Mg for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:51 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:40512) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTJW-00069v-BS for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:42 -0400 Received: by mail-pg0-x243.google.com with SMTP id l2-v6so23000121pgc.7 for ; Wed, 09 May 2018 10:55:41 -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=oPERtIhZZZR4Xkb8MwvjjFgqIkTsmJoGkV3z4hVPZ+M=; b=C+5CGlYpLIq3Os3wkcwkXMfjasE8G7i2yCkEm30tUnxB6//4QiJXJSP7zE4V5HrlN8 DjA272gxnV4QZFwSsYBbsjUY3n4T/2dVDwXCL/n4ligqLNJ7M2dRlW9FE4PAyCjhbHDE oQAIXN5IDBhEOtjImPS5OiBZ2Okj7YTp10mt0= 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=oPERtIhZZZR4Xkb8MwvjjFgqIkTsmJoGkV3z4hVPZ+M=; b=Y2iqRQRDbuAJmJ1ZLwVWHBlk05dPsHtJ66xOiekevn4cyU0XBAjMl5bK7heBs+MKUe vQJcWrXQWfuh7fh+TuGNDEs6BxCH+T1DF4uHoJ4ZQ1XfwAYzHJjxY+ubSev9uviv+wY/ jmghoeckYr0dmiskB+Suw1Gqj/u0YH0Xcg1kdWZ1Z0lsmhxp0oGSbynadjmPnKSy9KmR TP2uprl5q2g9c0OfORIPTl0P8mUBmnSV/YDVFZxRXPsjVfVm5+49nqBF4Kh1GAxByd1G j97fLajqrKVvBf+9NS7nuak08BDtq6L6fGdH3gKuAW0CR5YPOPl/oMm5n51ZEIBPptVV WmlA== X-Gm-Message-State: ALQs6tD7ocNBTVEkSp74h/aXp/JRed/iUkY/4+9hswhFcPsLG0GcYhZm oXkp0Mij/YNiKy64NYCka4vw4dBRVwg= X-Received: by 2002:a63:7d47:: with SMTP id m7-v6mr30135335pgn.443.1525888540721; Wed, 09 May 2018 10:55:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:53 -0700 Message-Id: <20180509175458.15642-24-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::243 Subject: [Qemu-devel] [PULL 23/28] target/s390x: 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" Note: I looked into dropping dc->do_debug. However, I don't see an easy way to do it given that TOO_MANY is also valid when we just translate more than max_insns. Thus, the check for do_debug in "case DISAS_PC_CC_UPDATED" would still need additional state to know whether or not we came from breakpoint_check. Acked-by: Cornelia Huck Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson Tested-by: David Hildenbrand Cc: David Hildenbrand Cc: Cornelia Huck Cc: Alexander Graf Cc: qemu-s390x@nongnu.org Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- target/s390x/translate.c | 178 +++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 90 deletions(-) -- 2.17.0 diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 5094128e9c..82309faa11 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -64,6 +64,7 @@ struct DisasContext { uint64_t pc_tmp; uint32_t ilen; enum cc_op cc_op; + bool do_debug; }; /* Information carried about a condition to be evaluated. */ @@ -6158,98 +6159,87 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s) return ret; } -void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) +static void s390x_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); + + /* 31-bit mode */ + if (!(dc->base.tb->flags & FLAG_MASK_64)) { + dc->base.pc_first &= 0x7fffffff; + dc->base.pc_next = dc->base.pc_first; + } + + dc->cc_op = CC_OP_DYNAMIC; + dc->ex_value = dc->base.tb->cs_base; + dc->do_debug = dc->base.singlestep_enabled; +} + +static void s390x_tr_tb_start(DisasContextBase *db, CPUState *cs) +{ +} + +static void s390x_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); + + tcg_gen_insn_start(dc->base.pc_next, dc->cc_op); +} + +static bool s390x_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, + const CPUBreakpoint *bp) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); + + dc->base.is_jmp = DISAS_PC_STALE; + dc->do_debug = true; + /* 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 does the right thing. */ + dc->base.pc_next += 2; + return true; +} + +static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { CPUS390XState *env = cs->env_ptr; - DisasContext dc; - uint64_t page_start; - int num_insns, max_insns; - DisasJumpType status; - bool do_debug; + DisasContext *dc = container_of(dcbase, DisasContext, base); - dc.base.pc_first = tb->pc; - /* 31-bit mode */ - if (!(tb->flags & FLAG_MASK_64)) { - dc.base.pc_first &= 0x7fffffff; - } - dc.base.pc_next = dc.base.pc_first; - dc.base.tb = tb; - dc.base.singlestep_enabled = cs->singlestep_enabled; + dc->base.is_jmp = translate_one(env, dc); + if (dc->base.is_jmp == DISAS_NEXT) { + uint64_t page_start; - dc.cc_op = CC_OP_DYNAMIC; - dc.ex_value = dc.base.tb->cs_base; - do_debug = cs->singlestep_enabled; - - page_start = dc.base.pc_first & TARGET_PAGE_MASK; - - num_insns = 0; - max_insns = tb_cflags(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); - - do { - tcg_gen_insn_start(dc.base.pc_next, dc.cc_op); - num_insns++; - - if (unlikely(cpu_breakpoint_test(cs, dc.base.pc_next, BP_ANY))) { - status = DISAS_PC_STALE; - do_debug = true; - /* 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 += 2; - break; + page_start = dc->base.pc_first & TARGET_PAGE_MASK; + if (dc->base.pc_next - page_start >= TARGET_PAGE_SIZE || dc->ex_value) { + dc->base.is_jmp = DISAS_TOO_MANY; } - - if (num_insns == max_insns && (tb_cflags(tb) & CF_LAST_IO)) { - gen_io_start(); - } - - status = translate_one(env, &dc); - - /* If we reach a page boundary, are single stepping, - or exhaust instruction count, stop generation. */ - if (status == DISAS_NEXT - && (dc.base.pc_next - page_start >= TARGET_PAGE_SIZE - || tcg_op_buf_full() - || num_insns >= max_insns - || singlestep - || dc.base.singlestep_enabled - || dc.ex_value)) { - status = DISAS_TOO_MANY; - } - } while (status == DISAS_NEXT); - - if (tb_cflags(tb) & CF_LAST_IO) { - gen_io_end(); } +} - switch (status) { +static void s390x_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); + + switch (dc->base.is_jmp) { case DISAS_GOTO_TB: case DISAS_NORETURN: break; case DISAS_TOO_MANY: case DISAS_PC_STALE: case DISAS_PC_STALE_NOCHAIN: - update_psw_addr(&dc); + update_psw_addr(dc); /* FALLTHRU */ case DISAS_PC_UPDATED: /* Next TB starts off with CC_OP_DYNAMIC, so make sure the cc op type is in env */ - update_cc_op(&dc); + update_cc_op(dc); /* FALLTHRU */ case DISAS_PC_CC_UPDATED: /* Exit the TB, either by raising a debug exception or by return. */ - if (do_debug) { + if (dc->do_debug) { gen_exception(EXCP_DEBUG); - } else if (use_exit_tb(&dc) || status == DISAS_PC_STALE_NOCHAIN) { + } else if (use_exit_tb(dc) || + dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) { tcg_gen_exit_tb(0); } else { tcg_gen_lookup_and_goto_ptr(); @@ -6258,28 +6248,36 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) default: g_assert_not_reached(); } +} - gen_tb_end(tb, num_insns); +static void s390x_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs) +{ + DisasContext *dc = container_of(dcbase, DisasContext, base); - tb->size = dc.base.pc_next - dc.base.pc_first; - tb->icount = num_insns; - -#if defined(S390X_DEBUG_DISAS) - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) - && qemu_log_in_addr_range(dc.base.pc_first)) { - qemu_log_lock(); - if (unlikely(dc.ex_value)) { - /* ??? Unfortunately log_target_disas can't use host memory. */ - qemu_log("IN: EXECUTE %016" PRIx64 "\n", dc.ex_value); - } else { - qemu_log("IN: %s\n", lookup_symbol(dc.base.pc_first)); - log_target_disas(cs, dc.base.pc_first, - dc.base.pc_next - dc.base.pc_first); - qemu_log("\n"); - } - qemu_log_unlock(); + if (unlikely(dc->ex_value)) { + /* ??? Unfortunately log_target_disas can't use host memory. */ + qemu_log("IN: EXECUTE %016" PRIx64, dc->ex_value); + } else { + qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first)); + log_target_disas(cs, dc->base.pc_first, dc->base.tb->size); } -#endif +} + +static const TranslatorOps s390x_tr_ops = { + .init_disas_context = s390x_tr_init_disas_context, + .tb_start = s390x_tr_tb_start, + .insn_start = s390x_tr_insn_start, + .breakpoint_check = s390x_tr_breakpoint_check, + .translate_insn = s390x_tr_translate_insn, + .tb_stop = s390x_tr_tb_stop, + .disas_log = s390x_tr_disas_log, +}; + +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) +{ + DisasContext dc; + + translator_loop(&s390x_tr_ops, &dc.base, cs, tb); } void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb,