From patchwork Wed Jul 31 16:06:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 170145 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4215546ile; Wed, 31 Jul 2019 09:10:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUXX0E/jNtbQ0UA9DlY9h9DgenJDz0C/mONB00AVCVhRMIXsAAStHA/9SS/fQa9ef82y3C X-Received: by 2002:a17:906:c785:: with SMTP id cw5mr48595758ejb.215.1564589433175; Wed, 31 Jul 2019 09:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564589433; cv=none; d=google.com; s=arc-20160816; b=ZknA0fJO1GFQ5ZrtOAV3J/ts9g/z8pStjPAjZumVBgzat7nqJKUYY6Uy2xO1xWGqGH B7NAWzWtnOSld4IZ2cJq0AzC3nfkuUREru1AECfroLOc4XlIp5aWvxerpk5uK6dwCCz9 nYl4kYvExV4xLfxDjR9ZY7zh0MSrxq9ZY5ylZhMgivhE/vaPGHLpFTST3DTx9YXkqFDp /ck6h5qy5FhVgYTrrEJm0AV3OXvxzuxtCmsAxaGzgTlEdmModIDQ4WDMLiFWkDgqfDj1 ih0BS+qN8K3KzdyLIPvw4IQy49I+mqCXvIgcsIOdkyMX7aQ9UfG8l2GwT8O23Dpm6xgg 7dJQ== 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; bh=SWna9UxNFjHgSxxpvUscIhoIHkEj4BqQ4tH+9BGOa3A=; b=dtiLT8cQcder3dBbxPiCHJTiGJ+xRvNRtzse+mCyJW4GnE8+28ICv8/GJ1ZprX0bEG z0t2VkK0Pu3AeyZF5rZvt02VsdRmEAKwVlHBdAZovmsTsrXoAnJl0H2cBELlPdexjKFa S9gRFLreYHtv8oOih+a/mspK3j59O5gAETquajlepyBnr5SfWM07+msNnfHthfgD2LTY 5Ypqg+W1/v1CzJiFxHjez7cPRL+Q4wSdna/UahwO5tNOfop0OBcxcU3iIrzjw05s3I19 0U2oXhSWrqEkeZbyvLzX51GRiSsMao+v7CA4pBUuyTJz5CInOTNWCqHHvDnGXmqk5Tdp XaZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UO5G9+rc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id c42si22823816eda.70.2019.07.31.09.10.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2019 09:10:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UO5G9+rc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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]:42350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrBQ-0005kL-3N for patch@linaro.org; Wed, 31 Jul 2019 12:10:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40242) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8U-00022M-2w for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8O-0000dZ-QZ for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:29 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46242) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8O-0000cL-C2 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:24 -0400 Received: by mail-wr1-x444.google.com with SMTP id z1so70279133wru.13 for ; Wed, 31 Jul 2019 09:07:23 -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=SWna9UxNFjHgSxxpvUscIhoIHkEj4BqQ4tH+9BGOa3A=; b=UO5G9+rcGZ5XmAXAxpryg7fOu5CohkrhcC0NWHWk2zbNSnedwbSgdSedzKdZVklKl3 vWts0bzK+80fVS8FzhiGS5SzOpL3c9IQ2/5vEdFA0wzY+hChEG2X+5rRflelaUIr2zPN zj9vfXyr7pLNjuuI7FDnOXawx2GKxh2jASiU0eO4V1gMCsrvAp9/jdF51zV8tqiqPtM2 hXTsDDeCkH9yytBhQqgJfaTAV5kDSMjk4ySksDcEdj33N80+yx0mc23gNnTDw4yLN9KA fEASMzsiKAmKK6DDNjbfVZ/VR2Uf3NLUF1lsXTaKCffcNAAT5Hp54JJslX0A7djoM+wP rY2A== 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=SWna9UxNFjHgSxxpvUscIhoIHkEj4BqQ4tH+9BGOa3A=; b=B3iP3KQ3ufyGTtK3Ttm+PAUhbhO+AkCZjeLnbuIF/QkGtVbb9JOgfonh7nFxxxpTEh m3T2Uuql4fLLNNUWy7mukzlKCJc211bje1AnMA7ws2m7fJ+skWqsQxR49IcQWzW7Nufe WHeCa4R8wds7F3FAxA/VqEyncAmmSYM+YPr9JF2bw9JY4QioCorVfQa02VNhk+Hp3qIW TF2Up2aXR2ddYLjC6GBm/84o1+Ij1DJQBeBU/EzTf+S7lnDiVwl0Up6pkOoHKLYqOtZt 6Kft5KzIayUN5xzwNENJLDy/jKezPguI8B+KIRaZTz9oRWixU/UfwqwppQD9TMFFhxNc ZrIw== X-Gm-Message-State: APjAAAWf6M8IXPZwuB3R818VA+hVqGJdCmMp60UsH7AiMGqXG4hsAB/z Ib6+OeVdgVrMBkAaikM9lnAPgw== X-Received: by 2002:adf:cd04:: with SMTP id w4mr86500409wrm.230.1564589242963; Wed, 31 Jul 2019 09:07:22 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p10sm2143203wmk.2.2019.07.31.09.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:20 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C8BD71FF91; Wed, 31 Jul 2019 17:07:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:29 +0100 Message-Id: <20190731160719.11396-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v4 04/54] 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: Peter Maydell , aaron@os.amperecomputing.com, cota@braap.org, "open list:ARM TCG CPUs" , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée --- v2 - fix re-base conflicts - hoist EXCP_SEMIHOST check - comment cleanups --- target/arm/helper.c | 90 +++++++++------------------------------------ 1 file changed, 18 insertions(+), 72 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index b74c23a9bc0..c5b90a83d36 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8259,86 +8259,30 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) new_el, env->pc, pstate_read(env)); } -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. + */ +static void handle_semihosting(CPUState *cs) { #ifdef CONFIG_TCG - /* Check whether this exception is a semihosting call; if so - * then handle it and return true; otherwise return false. - */ ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; if (is_a64(env)) { - if (cs->exception_index == 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] = 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] = do_arm_semihosting(env); } else { - uint32_t imm; - - /* Only intercept calls from privileged modes, to provide some - * semblance of security. - */ - if (cs->exception_index != EXCP_SEMIHOST && - (!semihosting_enabled() || - ((env->uncached_cpsr & CPSR_M) == 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 = arm_lduw_code(env, env->regs[15] - 2, arm_sctlr_b(env)) - & 0xff; - if (imm == 0xab) { - break; - } - } else { - imm = arm_ldl_code(env, env->regs[15] - 4, arm_sctlr_b(env)) - & 0xffffff; - if (imm == 0x123456) { - break; - } - } - return false; - case EXCP_BKPT: - /* See if this is a semihosting syscall. */ - if (env->thumb) { - imm = arm_lduw_code(env, env->regs[15], arm_sctlr_b(env)) - & 0xff; - if (imm == 0xab) { - env->regs[15] += 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] = do_arm_semihosting(env); - return true; } -#else - return false; #endif } @@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs) return; } - /* 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)) { + if (cs->exception_index == EXCP_SEMIHOST) { + handle_semihosting(cs); return; }