From nobody Mon Feb 9 18:31:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508609452632710.8648233022501; Sat, 21 Oct 2017 11:10:52 -0700 (PDT) Received: from localhost ([::1]:58705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5yEI-00015u-Mg for importer@patchew.org; Sat, 21 Oct 2017 14:10:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5yDP-0000fs-8q for qemu-devel@nongnu.org; Sat, 21 Oct 2017 14:09:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5yDO-0004a8-0x for qemu-devel@nongnu.org; Sat, 21 Oct 2017 14:09:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:51708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5yDJ-0004Vm-7r; Sat, 21 Oct 2017 14:09:37 -0400 Received: from [10.0.0.56] (c-24-130-70-9.hsd1.ca.comcast.net [24.130.70.9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B0382191E; Sat, 21 Oct 2017 18:09:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B0382191E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=sstabellini@kernel.org Date: Sat, 21 Oct 2017 11:09:33 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: peter.maydell@linaro.org Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PATCH v2] fix WFI/WFE length in syndrome register 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: qemu-arm@nongnu.org, sstabellini@kernel.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: TEXT/PLAIN; charset="utf-8" WFI/E are often, but not always, 4 bytes long. When they are, we need to set ARM_EL_IL_SHIFT in the syndrome register. Pass the instruction length to HELPER(wfi), use it to decrement pc appropriately and to pass an is_16bit flag to syn_wfx, which sets ARM_EL_IL_SHIFT if needed. Signed-off-by: Stefano Stabellini diff --git a/target/arm/helper.h b/target/arm/helper.h index 2cf6f74..439d228 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -48,7 +48,7 @@ DEF_HELPER_FLAGS_3(sel_flags, TCG_CALL_NO_RWG_SE, DEF_HELPER_2(exception_internal, void, env, i32) DEF_HELPER_4(exception_with_syndrome, void, env, i32, i32, i32) DEF_HELPER_1(setend, void, env) -DEF_HELPER_1(wfi, void, env) +DEF_HELPER_2(wfi, void, env, i32) DEF_HELPER_1(wfe, void, env) DEF_HELPER_1(yield, void, env) DEF_HELPER_1(pre_hvc, void, env) diff --git a/target/arm/internals.h b/target/arm/internals.h index 5a5af38..6792df2 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -428,9 +428,10 @@ static inline uint32_t syn_breakpoint(int same_el) | ARM_EL_IL | 0x22; } =20 -static inline uint32_t syn_wfx(int cv, int cond, int ti) +static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit) { return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) | + (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) | (cv << 24) | (cond << 20) | ti; } =20 diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c index 045c312..30039c5 100644 --- a/target/arm/op_helper.c +++ b/target/arm/op_helper.c @@ -463,7 +463,7 @@ static inline int check_wfx_trap(CPUARMState *env, bool= is_wfe) return 0; } =20 -void HELPER(wfi)(CPUARMState *env) +void HELPER(wfi)(CPUARMState *env, uint32_t insn_len) { CPUState *cs =3D CPU(arm_env_get_cpu(env)); int target_el =3D check_wfx_trap(env, false); @@ -476,8 +476,9 @@ void HELPER(wfi)(CPUARMState *env) } =20 if (target_el) { - env->pc -=3D 4; - raise_exception(env, EXCP_UDEF, syn_wfx(1, 0xe, 0), target_el); + env->pc -=3D insn_len; + raise_exception(env, EXCP_UDEF, syn_wfx(1, 0xe, 0, insn_len =3D=3D= 2), + target_el); } =20 cs->exception_index =3D EXCP_HLT; diff --git a/target/arm/psci.c b/target/arm/psci.c index fc34b26..eb7b88e 100644 --- a/target/arm/psci.c +++ b/target/arm/psci.c @@ -189,7 +189,7 @@ void arm_handle_psci_call(ARMCPU *cpu) } else { env->regs[0] =3D 0; } - helper_wfi(env); + helper_wfi(env, 4); break; case QEMU_PSCI_0_1_FN_MIGRATE: case QEMU_PSCI_0_2_FN_MIGRATE: diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index a39b9d3..6f74589 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11380,17 +11380,20 @@ static void aarch64_tr_tb_stop(DisasContextBase *= dcbase, CPUState *cpu) gen_helper_yield(cpu_env); break; case DISAS_WFI: + { + TCGv_i32 tmp =3D tcg_const_i32((dc->insn & (1U << 31)) ? 4 : 2= ); /* This is a special case because we don't want to just halt t= he CPU * if trying to debug across a WFI. */ gen_a64_set_pc_im(dc->pc); - gen_helper_wfi(cpu_env); + gen_helper_wfi(cpu_env, tmp); /* The helper doesn't necessarily throw an exception, but we * must go back to the main loop to check for interrupts anywa= y. */ tcg_gen_exit_tb(0); break; } + } } =20 /* Functions above can change dc->pc, so re-align db->pc_next */ diff --git a/target/arm/translate.c b/target/arm/translate.c index 4da1a4c..a89518f 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -12325,12 +12325,15 @@ static void arm_tr_tb_stop(DisasContextBase *dcba= se, CPUState *cpu) /* nothing more to generate */ break; case DISAS_WFI: - gen_helper_wfi(cpu_env); + { + TCGv_i32 tmp =3D tcg_const_i32((dc->insn & (1U << 31)) ? 4 : 2= ); + gen_helper_wfi(cpu_env, tmp); /* The helper doesn't necessarily throw an exception, but we * must go back to the main loop to check for interrupts anywa= y. */ tcg_gen_exit_tb(0); break; + } case DISAS_WFE: gen_helper_wfe(cpu_env); break;