From patchwork Fri Apr 27 20:27:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10369821 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 215B26038F for ; Fri, 27 Apr 2018 20:28:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 103A929260 for ; Fri, 27 Apr 2018 20:28:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0148429265; Fri, 27 Apr 2018 20:28:21 +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=-7.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI, 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 8D1EA29260 for ; Fri, 27 Apr 2018 20:28:21 +0000 (UTC) Received: from localhost ([::1]:49830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fC9yc-0004Ji-Hs for patchwork-qemu-devel@patchwork.kernel.org; Fri, 27 Apr 2018 16:28:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fC9xy-00040O-Gf for qemu-devel@nongnu.org; Fri, 27 Apr 2018 16:27:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fC9xx-0007EK-KJ for qemu-devel@nongnu.org; Fri, 27 Apr 2018 16:27:38 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:39901) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fC9xx-0007Db-CO for qemu-devel@nongnu.org; Fri, 27 Apr 2018 16:27:37 -0400 Received: by mail-lf0-x241.google.com with SMTP id j193-v6so4410938lfg.6 for ; Fri, 27 Apr 2018 13:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=aG0mladM2aCqDPcOI5jxBoX6cGePg8Z8Dxj1qWZU0Vo=; b=GDTmp3+9pAvOrZ+6HYPr1kcLLsJYk8T/FkObKDGFnb3M7+c5mAKdr2Apx9TiWLKQlZ bucIp+l6ZZM6jtwTodjcY+TAtrP7DUzF3Ff4vwD1mod/DBXfaovDs04j/M7aYUTwPOpM FltjMCcsZBNJuMh0GeviHvvx4Ay0gDtx2vuBp/00Xo3LA7F4vRx+7T0CS5PxPumiosIz +4XwJG/8O+dm2X+L580S5AqX3l2x+X0IJe4kzqgbBysbzUeZsCZ4hWYXPwQkxTQSRv89 YvCKmIHGa6nX9SUxPWHlFRPZyss6G/sKigvqqxobFBXD2wfU8G04ySFJPVf9yPFB64MH p4Ng== 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; bh=aG0mladM2aCqDPcOI5jxBoX6cGePg8Z8Dxj1qWZU0Vo=; b=K2bFBx7rHRNSPq5Trmhli9Lam3kHXovSTHQUQaEUl9OOOohbS2+9l6Pa3kAaB8WJun jMbZE8aN+ZzoOvc9VzDyW5c1TrW6uRMrx96risQx2gHy06PMO1ldQd7nH8uzQGMfthM+ 5HVxo6qbFjjcAp8Pb4PDYjwve+RfwUdiB9s7FANMZo//QMgZEry7ILY+UMUMsmcYaMCO lx5OOG4PXFb609+UGnkfdH7yMnA8lts3DoV80x609ltiaWb4doDtZjYYtedp5AtPwk6S YI4G8SWaDjjm08Q+nvX+mxt6GcYZkF8t4hDw3ZZpBljccBcmU3Ry2MS02QUSXizhRwos 0cZQ== X-Gm-Message-State: ALQs6tDmddRlgnPLbdsDzHpzvw7Ty4TNFn2iUnDZcGvKHc1yJ32EJkbd zDRjAtF8c0Smj7AsGpn2iLybfg== X-Google-Smtp-Source: AB8JxZp//tR3mzH2b6qrnvf0BPh9No9E9hxYHyYN180YDu5V9JcdUL/6+i3g/92swtH+U6z/Dp4HQg== X-Received: by 2002:a2e:4dd6:: with SMTP id c83-v6mr2486223ljd.126.1524860855528; Fri, 27 Apr 2018 13:27:35 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id f22-v6sm390801ljc.50.2018.04.27.13.27.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 13:27:34 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 27 Apr 2018 13:27:23 -0700 Message-Id: <20180427202723.16137-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH] target/xtensa: check zero overhead loop alignment 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: Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP ISA book documents that the first instruction of zero overhead loop must fit completely into naturally aligned region of an instruction fetch unit size. Check that condition and log a message if it's violated. Signed-off-by: Max Filippov --- target/xtensa/cpu.h | 1 + target/xtensa/overlay_tool.h | 1 + target/xtensa/translate.c | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index e9d2e109f790..51b455146494 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -369,6 +369,7 @@ struct XtensaConfig { unsigned nareg; int excm_level; int ndepc; + unsigned inst_fetch_width; uint32_t vecbase; uint32_t exception_vector[EXC_MAX]; unsigned ninterrupt; diff --git a/target/xtensa/overlay_tool.h b/target/xtensa/overlay_tool.h index b24ad11fec1c..ee37a04a176c 100644 --- a/target/xtensa/overlay_tool.h +++ b/target/xtensa/overlay_tool.h @@ -456,6 +456,7 @@ .options = XTENSA_OPTIONS, \ .nareg = XCHAL_NUM_AREGS, \ .ndepc = (XCHAL_XEA_VERSION >= 2), \ + .inst_fetch_width = XCHAL_INST_FETCH_WIDTH, \ EXCEPTIONS_SECTION, \ INTERRUPTS_SECTION, \ TLB_SECTION, \ diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 4f6d03059feb..f8331f7104dc 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -970,6 +970,13 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) } dc->next_pc = dc->pc + len; + if (xtensa_option_enabled(dc->config, XTENSA_OPTION_LOOP) && + dc->lbeg == dc->pc && + ((dc->pc ^ (dc->next_pc - 1)) & -dc->config->inst_fetch_width)) { + qemu_log_mask(LOG_GUEST_ERROR, + "unaligned first instruction of a loop (pc = %08x)\n", + dc->pc); + } for (i = 1; i < len; ++i) { b[i] = cpu_ldub_code(env, dc->pc + i); }