From nobody Wed Nov 12 03:40:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1567596406; cv=none; d=zoho.com; s=zohoarc; b=dfVDTNhfkQtyjFEC3/2IqGI1juEAfXnBzY2YLinvuvZFYhVECGNXRYGYXXnTceCw10HoGvrpC3uQhOMqOAbBb4Tmaixl3hBdIIr96AcgRm8sgJoH+QoUf15hF4gcjxzkOK+kn3SrohEeUUw8b2akvzoLxEqM1XnLgwPOcp81PKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567596406; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zlpCkLPxW/plsVCAFKM/m8fldNY7IYpuz4hZ7EfXmKg=; b=CoPMQzVoFKpS+rEDl+IqDjmOIKO+OYztvEU8DySWPaX4aiUa+UmkwCbxaAXKYMU/uT5oU7YVGlYulwpeo7PDWBcLKQMUL9PsdPDeFbHABhHtiG38VbUMJQPw8KCEdjXYFKPQrS5RQopqhD4OrRcHz1zJQxbMTN5L/ESYn/TZBQs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567596406133223.48138418223675; Wed, 4 Sep 2019 04:26:46 -0700 (PDT) Received: from localhost ([::1]:56312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5TQz-00049x-4A for importer@patchew.org; Wed, 04 Sep 2019 07:26:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36598) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5TLm-0007AG-5v for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5TLf-0007Gq-Fr for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:20 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46286) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5TLe-0007F9-SL for qemu-devel@nongnu.org; Wed, 04 Sep 2019 07:21:15 -0400 Received: by mail-wr1-x442.google.com with SMTP id h7so19500881wrt.13 for ; Wed, 04 Sep 2019 04:21:14 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y72sm5097353wmc.26.2019.09.04.04.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 04:21:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6781E1FF91; Wed, 4 Sep 2019 12:21:09 +0100 (BST) 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=zlpCkLPxW/plsVCAFKM/m8fldNY7IYpuz4hZ7EfXmKg=; b=eeOTZqfhp+fZCWHGhlEfoezZW0+2kDDeDLOAbfbYc0qJYMPscW29iQViYkH0GukIFl q1pq0YOX74QJSER1AyzBmI/oHm8/KPigWaei/6huZzIHFoiuh4nwJkOhArcREpVw+47U iXcuIiR2jHvEDEvr745+tNY+sfmCoEmt4DwRewgWM17oKfR61+SU6BU9WUXNtPULeVCI RI/WSkXhSA8Gj8i65fpIfGHBxe2saZ4UYX5AD7vR9ELd7EPClEDDoKJ2Dob6nwF7ALSV RMFMl8KpZazAbiDsnRjqWrKNL1n0oeJdhujyJwURMxQLfVfO8sRdDEBkkWmzNvLTysev 4dJw== 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=zlpCkLPxW/plsVCAFKM/m8fldNY7IYpuz4hZ7EfXmKg=; b=pwceHJmbscCRulKwuAXn9CSi5x2G2RxsZ9qQEcPaBTcghrGwAkOwQoe5yL6ScXs9/5 IHvD6P3BIQPRbuF3gCazHCst29En21aoypSmKnWPSrkYfuyKlnL0vbvSlcjMWVz6dK8T Ekc6oQ+z/Niz1f8QMPF+SVCYEanPsWcTVQsH1unrRWcNZbC2rAIL2wGppWt//BgMOnzF TXdv/kwzMfsbobRyhtt6pDE2KSJuBruio93/HZd94+dQ1fcSBCM7+5q5c0l+7x2GJaRI EQCOnxEr6aug1qIyyLpqb+PpqaQi7ookxtQreZQiiH3aQojhlJLa3ja07sG1ZilYFQAP UHpA== X-Gm-Message-State: APjAAAWw+iRopJWq6Jh3dNGGcXlDITX6tIKSK8jRmPKFkFQXVVsedBon PfIEca+j+teoZVW5HRC77gDDAA== X-Google-Smtp-Source: APXvYqwQVjoH8hI29Q33t64FvtyLFiDXcfbgxQ5GiHUAYsBYriWU42Hcb27Ul6ZOYQ8+oHbJMnZrgA== X-Received: by 2002:adf:a350:: with SMTP id d16mr31194562wrb.326.1567596073675; Wed, 04 Sep 2019 04:21:13 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 4 Sep 2019 12:21:07 +0100 Message-Id: <20190904112108.2341-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190904112108.2341-1-alex.bennee@linaro.org> References: <20190904112108.2341-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v2 4/5] target/arm: remove run time semihosting checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Now we do all our checking and use a common EXCP_SEMIHOST for semihosting operations we can make helper code a lot simpler. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- v2 - fix re-base conflicts - hoist EXCP_SEMIHOST check - comment cleanups v5 - move CONFIG_TCG ifdefs --- target/arm/helper.c | 96 +++++++++++---------------------------------- 1 file changed, 22 insertions(+), 74 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 507026c9154..a87ae6d46a1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8339,88 +8339,32 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *= cs) new_el, env->pc, pstate_read(env)); } =20 -static inline bool check_for_semihosting(CPUState *cs) -{ +/* + * Do semihosting call and set the appropriate return value. All the + * permission and validity checks have been done at translate time. + * + * We only see semihosting exceptions in TCG only as they are not + * trapped to the hypervisor in KVM. + */ #ifdef CONFIG_TCG - /* Check whether this exception is a semihosting call; if so - * then handle it and return true; otherwise return false. - */ +static void handle_semihosting(CPUState *cs) +{ ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; =20 if (is_a64(env)) { - if (cs->exception_index =3D=3D EXCP_SEMIHOST) { - /* This is always the 64-bit semihosting exception. - * The "is this usermode" and "is semihosting enabled" - * checks have been done at translate time. - */ - qemu_log_mask(CPU_LOG_INT, - "...handling as semihosting call 0x%" PRIx64 "\n= ", - env->xregs[0]); - env->xregs[0] =3D do_arm_semihosting(env); - return true; - } - return false; + qemu_log_mask(CPU_LOG_INT, + "...handling as semihosting call 0x%" PRIx64 "\n", + env->xregs[0]); + env->xregs[0] =3D do_arm_semihosting(env); } else { - uint32_t imm; - - /* Only intercept calls from privileged modes, to provide some - * semblance of security. - */ - if (cs->exception_index !=3D EXCP_SEMIHOST && - (!semihosting_enabled() || - ((env->uncached_cpsr & CPSR_M) =3D=3D ARM_CPU_MODE_USR))) { - return false; - } - - switch (cs->exception_index) { - case EXCP_SEMIHOST: - /* This is always a semihosting call; the "is this usermode" - * and "is semihosting enabled" checks have been done at - * translate time. - */ - break; - case EXCP_SWI: - /* Check for semihosting interrupt. */ - if (env->thumb) { - imm =3D arm_lduw_code(env, env->regs[15] - 2, arm_sctlr_b(= env)) - & 0xff; - if (imm =3D=3D 0xab) { - break; - } - } else { - imm =3D arm_ldl_code(env, env->regs[15] - 4, arm_sctlr_b(e= nv)) - & 0xffffff; - if (imm =3D=3D 0x123456) { - break; - } - } - return false; - case EXCP_BKPT: - /* See if this is a semihosting syscall. */ - if (env->thumb) { - imm =3D arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) - & 0xff; - if (imm =3D=3D 0xab) { - env->regs[15] +=3D 2; - break; - } - } - return false; - default: - return false; - } - qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); env->regs[0] =3D do_arm_semihosting(env); - return true; } -#else - return false; -#endif } +#endif =20 /* Handle a CPU exception for A and R profile CPUs. * Do any appropriate logging, handle PSCI calls, and then hand off @@ -8451,13 +8395,17 @@ void arm_cpu_do_interrupt(CPUState *cs) return; } =20 - /* Semihosting semantics depend on the register width of the - * code that caused the exception, not the target exception level, - * so must be handled here. + /* + * Semihosting semantics depend on the register width of the code + * that caused the exception, not the target exception level, so + * must be handled here. */ - if (check_for_semihosting(cs)) { +#ifdef CONFIG_TCG + if (cs->exception_index =3D=3D EXCP_SEMIHOST) { + handle_semihosting(cs); return; } +#endif =20 /* Hooks may change global state so BQL should be held, also the * BQL needs to be held for any modification of --=20 2.20.1