From patchwork Wed Aug 28 16:53:02 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: 172403 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1026080ily; Wed, 28 Aug 2019 10:02:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYZzH4ofzSQhbBUlz3NpWuycKYyFE5mgiIeg2yKTTOOmOy5pJFtHBCG2u2cTzJmG/Y61QS X-Received: by 2002:aa7:db0a:: with SMTP id t10mr5089184eds.17.1567011752496; Wed, 28 Aug 2019 10:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567011752; cv=none; d=google.com; s=arc-20160816; b=rKSmwszkN6+MJpzSJO9GOcKtgaR5BNwiHt6fNl5m7GjM+ypZAd+9dAAwx2HKlyhX8I FlqSM1NwdMPgYeEIquvf3fV9bINdWg0Z/7/8LSSJ64p2PJqB4QZElUW+Tm+0GE0OiOzf 06HrE4PdGYDSMjjmcgt1cABt6WchUUQQUPTIMIqG8CqRAVD5MIrcvFEVBhm5NmESHogE 9EpuMFgcJFS9G/sMHsq4avZLWxs9JkLiAyUamLcjilVB36DO9MZGVVoE+RY0egQWSCo7 eCUGj3XGZj7ZUqeYRWO4JFnpHNv73uxAParasaKWXosW6zMpcjtwb5pphoJaGOVDT454 d4TA== 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=IKUnc62WPCnJEius0PuJ3RtShM/DcMqSkoHnSUf3aGs=; b=dM+L+vNReLI05d/vgADwA/clcOv3OC/7kQAsPELYdMdp6eZ5wv0fvUwfvqDB+p1xMM yV7ZN+0uleUPACkhlF+YFYHzlk85IXGw3uUb28VAxDocte2JWf4KJ3CyXxQ/7stsi5Xs 1ql2Gc67V/k4pEkGuC+W322J1U5QFDuYqZdb6DYIQI9HGZtKuk7CfkOuglWjDEB4Xr5x u5ZHgPBhPyEtraQAXg/ESF+RFLkN2W/0OYmhMbNm+DRF4VAA1y0vdZw6pkgXeF5sWuTe Plgwo53XVKzMwaFiviwvQl4KBKo2rbNx7I4eUliXBYS94iBKsOI208UPkRr+rW0asE/2 CcGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OkI8cpgy; 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 o16si126976ejr.190.2019.08.28.10.02.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Aug 2019 10:02:32 -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=OkI8cpgy; 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]:38814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i31L4-0007M1-Ls for patch@linaro.org; Wed, 28 Aug 2019 13:02:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42502) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i31CH-0007mO-RW for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i31CE-000108-0K for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:23 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:38548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i31CA-0000sK-3O for qemu-devel@nongnu.org; Wed, 28 Aug 2019 12:53:20 -0400 Received: by mail-wr1-x443.google.com with SMTP id e16so526336wro.5 for ; Wed, 28 Aug 2019 09:53:13 -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=IKUnc62WPCnJEius0PuJ3RtShM/DcMqSkoHnSUf3aGs=; b=OkI8cpgyQWYVIcR1qSNOPUNK2TnHo5UYwOiNCuJs6A8w//3e/P8iOnC3lWUYadpNnG xT5nhOZ/Ig/pg/SiEkAUwvh+lta2PVPcseAgCPIAGM509Gok/gLqr41iSznXfJxQNvoJ bjE+1iC0c+CuSUJgS+E40YD8deF9CbY6obeyQJY0PrF68/E1JpW7imdC6+8SPHGkRPiu +2Fp4GMawkC3E06GC7y0fIkYQvT0zvP1IM2drX781ED2qxPQGq4QEiK7bxSnIRw5KAZo QoQ+zCXdIyMOiggvG6dspkKm8aM2L8oadBFgl0MnBcPFDdvNPBJGhEimbhvdxFCim8SP mptQ== 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=IKUnc62WPCnJEius0PuJ3RtShM/DcMqSkoHnSUf3aGs=; b=l+JcnGtqYky3V8roms1oYCMbZsdehn5VmcYonqT733ppLCYnUct0PWBX9+s+xB5aLt GtVE3jGq23E7jp8QOzX5cLNH+f4c03g5ZybcsaksIByUT03dmUAG/Zn6zk+/GRTS+HkS vEz0OBgenMZmRpKY2Z17dlPnwl8M8oGxpK84JUSAVh3hNrm5KYgFRepq+cO+a6GZjvIS XhSoYQLHaMYAN0jyj/XHWtCB7DIK+qG4RpdW99Ji/ZIsdags3aM0Gw+TrkQASlCkGPnT 1c316ic6gZ+e/EMd3aQDDuUSLXq3C5+twJoFq65XR4pWVPKI2xKDMW7lfsjrEpQLFNAZ T2jQ== X-Gm-Message-State: APjAAAWO+0Pakn7UxqwJnEKY06/OlJwA2cz4tJjKAAfyolQwFO5YMBUu hUV/yPS8d6n/S2vcCod0/QOPiA== X-Received: by 2002:a5d:658b:: with SMTP id q11mr5538897wru.211.1567011192599; Wed, 28 Aug 2019 09:53:12 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o2sm3717448wmh.9.2019.08.28.09.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 09:53:10 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B7F2F1FF91; Wed, 28 Aug 2019 17:53:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 28 Aug 2019 17:53:02 +0100 Message-Id: <20190828165307.18321-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190828165307.18321-1-alex.bennee@linaro.org> References: <20190828165307.18321-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::443 Subject: [Qemu-devel] [PATCH v1 4/9] 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 , "open list:ARM TCG CPUs" , =?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 v5 - move CONFIG_TCG ifdefs --- target/arm/helper.c | 96 +++++++++++---------------------------------- 1 file changed, 22 insertions(+), 74 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/target/arm/helper.c b/target/arm/helper.c index 7e0d5398ab8..c54d4768e1d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8262,88 +8262,32 @@ 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. + */ #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 = 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 } +#endif /* Handle a CPU exception for A and R profile CPUs. * Do any appropriate logging, handle PSCI calls, and then hand off @@ -8374,13 +8318,17 @@ 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)) { +#ifdef CONFIG_TCG + if (cs->exception_index == EXCP_SEMIHOST) { + handle_semihosting(cs); return; } +#endif /* Hooks may change global state so BQL should be held, also the * BQL needs to be held for any modification of