From nobody Sat May 4 21:05:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576692195; cv=none; d=zohomail.com; s=zohoarc; b=eepa8siTgtor6M4wYU2FeYxstb/cl9biGSjFga/QOeoERzqTOxtQxwujx/CT5gDIsolNhnLyrb792WAuYkCs5TnGuokGtdlKPK3BD0Wm0IIuifnGddXyh8bwKuBKZ3oO5YuXvQeWbBVg2Rj5zy4R5Y7vyE8xnwffNt0N7wtXnTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576692195; 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; bh=1imCrcgM5GABSpEnuVHZaVNMhwJCUodjjwEZVVhX2x8=; b=JrU9/UQFjT8RBFu5d4rkrDwTuTv1iIVNRhCXcKT1B2zgJeLjIWUF+yONRYkMAROU4+ZSGirPA3p9HeziuSKpMJeFg8vz29d3RPH4eqJi7VhriWlpP+WBkftLMmNIohClG32GUF0ww0PLrsITmrUX7h2oPzc/oEp8LiP1sGGcZkI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1576692195558751.526851444726; Wed, 18 Dec 2019 10:03:15 -0800 (PST) Received: from localhost ([::1]:58708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdfF-0006ld-PX for importer@patchew.org; Wed, 18 Dec 2019 13:03:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60019) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdcj-0004q1-0V for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihdcg-0002Pj-HU for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:36 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihdcg-0002Kr-7N for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:34 -0500 Received: by mail-wm1-x341.google.com with SMTP id m24so2786339wmc.3 for ; Wed, 18 Dec 2019 10:00:34 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v83sm3304469wmg.16.2019.12.18.10.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 10:00:30 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0EEB91FF8C; Wed, 18 Dec 2019 18:00:30 +0000 (GMT) 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=1imCrcgM5GABSpEnuVHZaVNMhwJCUodjjwEZVVhX2x8=; b=EMOwENtq4MXI8hlYodzhel4IydXy+3VrYIiKguE0ZYOdK5eGZVWd4OjcvNtVo++KBp Ea0bRmKkrMQipAjILsWMWK70CG863YL60cwDCRHd2QwemXcuD0THWS4HxkfTP823BzSo AXlKKqqXGp8/oeWFsnTr3/V8BtwNfOVz9BSoBfgdN6/ow365mytg64I1qxyZbsNzpAAh wZBNxhhy4IZM12gT9z5PFgEyQ+gEGCh1ofUqVjLAbvEjkxHCxGw59SvUNjyPQ1qWKq/n YbNNNB8+Xq3qjFF0Ys8pzYAwK9tvA5NE85+Uv2LxXcZ25t+/jrav9Y3yBNfTwZE35Nk6 OU5Q== 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=1imCrcgM5GABSpEnuVHZaVNMhwJCUodjjwEZVVhX2x8=; b=UI9HQJKo6UsT5by3LcQw6krVqO8vm/nuIytDxavTvTsrMDlj8LhNrDnJv7ajin2lqt jH9pNZWba5+fm98QbBcefJEkV1py8c6XAZOEFuntRq9JM/yaeKVjKEbh4Xg5W9Zdt7S6 TvBU04CcY2tlLzhLaBuhd/pILnPr7Nr0Q6oE1m5ZEJRqqpm0SFX8yWA3AEY8pY9CxY1x epl0sReJTuxvXS6UyZm4WEcYjvcBNoFFnFbI3PHDPUYx7QZTv6aOvVbBVwgA80sIHdmV ZXRaT62zDSJGxj4wFeZM5mag12B0z5dbLXIdePg091fwrt1cEDozAHLGlG9A2ZlbMkVZ 09GQ== X-Gm-Message-State: APjAAAUTxQfVfogWbWUXHutlTuPTTEtJ5wjonOZWRQP7ZFQloP6wUWGj IUR5HlC44Q1QvY4/lIBvWgSgV1wddmQ= X-Google-Smtp-Source: APXvYqyB2e7O6uLViS9FZKWHLP1SIBzw+sueD6XYHlO+8LzW4Edt2dNwpJH5YxNXHN6I7J7SKDVd2A== X-Received: by 2002:a1c:9e58:: with SMTP id h85mr4811878wme.77.1576692033082; Wed, 18 Dec 2019 10:00:33 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/4] target/arm: remove unused EXCP_SEMIHOST leg Date: Wed, 18 Dec 2019 18:00:26 +0000 Message-Id: <20191218180029.6744-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191218180029.6744-1-alex.bennee@linaro.org> References: <20191218180029.6744-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::341 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: pbonzini@redhat.com, keithp@keithp.com, "open list:ARM TCG CPUs" , =?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) All semihosting exceptions are dealt with earlier in the common code so we should never get here. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Keith Packard Reviewed-by: Richard Henderson Tested-by: Keith Packard --- target/arm/helper.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 5074b5f69ca..b4dc2274c8b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8554,12 +8554,6 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *c= s) case EXCP_VFIQ: addr +=3D 0x100; break; - case EXCP_SEMIHOST: - 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; default: cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index); } --=20 2.20.1 From nobody Sat May 4 21:05:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576692355; cv=none; d=zohomail.com; s=zohoarc; b=kGVtXg3GkkQYe20iR4UmYhH6rBYpDHebJa4HtpYHAf+sQdB2j3IVoCkU+XHkPBlSST9/HCclewD+W7GzEmClLE7mari8JVrAjaJ0KN3+/UDx5piGRq6lW5MIJ6Bn2/fnROpHkgIwEbLbmG7QF4yO0SZFXGdXp4zugR7o9/ROWaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576692355; 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; bh=OJ0FWXyVgln1qSkZCWjjhNl0S2nBbp6lHjR8Gp2aWVw=; b=M6YO5UI/dqOMlMA6rYflC5+UfiByDswipe/WLpeslcFZ8Dvmsk6hhKn9iRBY6HNiA2CuMIZRjIwvQw/Rv2WACJWRYL+/1w97dm2GQxbbXlCSCYANQHLYtrx0X6w5IObIkjJkxOHkPk0TOmUS7SLyW5gmy5PuPv2sNTl3bFl+RVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1576692355918911.8325513323539; Wed, 18 Dec 2019 10:05:55 -0800 (PST) Received: from localhost ([::1]:58778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdhq-0001cz-07 for importer@patchew.org; Wed, 18 Dec 2019 13:05:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60249) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdcs-0004ss-9O for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihdck-0002X7-QK for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:44 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:37442) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihdci-0002Qb-Vg for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:38 -0500 Received: by mail-wm1-x341.google.com with SMTP id f129so2931998wmf.2 for ; Wed, 18 Dec 2019 10:00:35 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k13sm3391284wrx.59.2019.12.18.10.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 10:00:33 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4D33E1FF8F; Wed, 18 Dec 2019 18:00:30 +0000 (GMT) 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=OJ0FWXyVgln1qSkZCWjjhNl0S2nBbp6lHjR8Gp2aWVw=; b=DmtBHwawVEeNJgubLkaQbh2rFgv8NVyg+uGpxb5hWGcn4HIEMSMhwwbJN/BACYx6ny 9iXAnybbzx1em2J/g9jp9OGiDz7VG9FeQMiZn9EgGKRvV055JZwrgqfd6NLWhCNwLn+s iKTSLq6W5iKjsfy4IYGcfk/nVvlBe1+uPCKAvAJ6SJkT3CxFE1WAI5buLgRxMMn6woQs FyLGjcTugTK6XJvmH/D1nELbCPCDEQuJF2eaLPB7/yS6e/nlVYMHCzkVz8meAYY6Z1VT X98ZIJ3Yprn6xRF8Hz9RJLwR9b1CT3KAJGRwyI47lbyOlDk+0bUbxp9ZljdUfUYDin7e 7ozA== 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=OJ0FWXyVgln1qSkZCWjjhNl0S2nBbp6lHjR8Gp2aWVw=; b=alhYi4AIBVWTSCI8DzJJeJaZSpvsfcF07dWHZpiFCwa9uTBak1qdk7JejcjCd/du9O 0w54+BxhOOHRId0fZfG7P/IqTv33jfdkl/tHeOkyfi0WW9NZClxuX+Hd5ms0pUcCLQ8V /KSLES9k7YH+QknVh4NusPmfoyLlZ5KGJgqCVIYtBd28jW/TCVJObrUPj7LO3cdFBw2Y 7YtyCSDa0jKpE/2E9GGHJly82ufPRmI5btTCEBdHSUSwQ5eUMkib2RULfwHojeEbFWW1 RT8nFkZn/wSJY3En+YvtQlo1arJ1CIKe6eO6qrfk7IyrgUFzKo0GNfYaipP81ODBv5u8 Bg1Q== X-Gm-Message-State: APjAAAWlSJvMHr1heTAJJlb+eB6H/QZ/78T4FDuttIG2SUVirxB/3ks7 0yXgYd34Qy2jIUlagZfZ+yXNvQ== X-Google-Smtp-Source: APXvYqwAaJtrW7vvxjim3Mq/1fo3QKUsJw6jhZFf6oMrKmgGnX0gPEm2KsPPG7FpmnkQTQ+ij1pGJg== X-Received: by 2002:a1c:4008:: with SMTP id n8mr4441035wma.121.1576692034227; Wed, 18 Dec 2019 10:00:34 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 2/4] target/arm: only update pc after semihosting completes Date: Wed, 18 Dec 2019 18:00:27 +0000 Message-Id: <20191218180029.6744-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191218180029.6744-1-alex.bennee@linaro.org> References: <20191218180029.6744-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::341 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 , keithp@keithp.com, Riku Voipio , Laurent Vivier , "open list:ARM TCG CPUs" , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Before we introduce blocking semihosting calls we need to ensure we can restart the system on semi hosting exception. To be able to do this the EXCP_SEMIHOST operation should be idempotent until it finally completes. Practically this means ensureing we only update the pc after the semihosting call has completed. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Keith Packard Reviewed-by: Richard Henderson Tested-by: Keith Packard --- linux-user/aarch64/cpu_loop.c | 1 + linux-user/arm/cpu_loop.c | 1 + target/arm/helper.c | 2 ++ target/arm/m_helper.c | 1 + target/arm/translate-a64.c | 2 +- target/arm/translate.c | 6 +++--- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 31c845a70d4..bbe9fefca81 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -130,6 +130,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_SEMIHOST: env->xregs[0] =3D do_arm_semihosting(env); + env->pc +=3D 4; break; case EXCP_YIELD: /* nothing to do here for user-mode, just resume guest code */ diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index 7be40717518..1fae90c6dfc 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -377,6 +377,7 @@ void cpu_loop(CPUARMState *env) break; case EXCP_SEMIHOST: env->regs[0] =3D do_arm_semihosting(env); + env->regs[15] +=3D env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ diff --git a/target/arm/helper.c b/target/arm/helper.c index b4dc2274c8b..088e2693df8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8602,11 +8602,13 @@ static void handle_semihosting(CPUState *cs) "...handling as semihosting call 0x%" PRIx64 "\n", env->xregs[0]); env->xregs[0] =3D do_arm_semihosting(env); + env->pc +=3D 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); env->regs[0] =3D do_arm_semihosting(env); + env->regs[15] +=3D env->thumb ? 2 : 4; } } #endif diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index 76de317e6af..33d414a684b 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2185,6 +2185,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) "...handling as semihosting call 0x%x\n", env->regs[0]); env->regs[0] =3D do_arm_semihosting(env); + env->regs[15] +=3D env->thumb ? 2 : 4; return; case EXCP_BKPT: armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index d4bebbe6295..972c28c3c95 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1937,7 +1937,7 @@ static void disas_exc(DisasContext *s, uint32_t insn) break; } #endif - gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST); + gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { unsupported_encoding(s, insn); } diff --git a/target/arm/translate.c b/target/arm/translate.c index 2b6c1f91bf9..5185e08641b 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -1124,7 +1124,7 @@ static inline void gen_hlt(DisasContext *s, int imm) s->current_el !=3D 0 && #endif (imm =3D=3D (s->thumb ? 0x3c : 0xf000))) { - gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST); + gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); return; } =20 @@ -8457,7 +8457,7 @@ static bool trans_BKPT(DisasContext *s, arg_BKPT *a) !IS_USER(s) && #endif (a->imm =3D=3D 0xab)) { - gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST); + gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { gen_exception_bkpt_insn(s, syn_aa32_bkpt(a->imm, false)); } @@ -10266,7 +10266,7 @@ static bool trans_SVC(DisasContext *s, arg_SVC *a) !IS_USER(s) && #endif (a->imm =3D=3D semihost_imm)) { - gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST); + gen_exception_internal_insn(s, s->pc_curr, EXCP_SEMIHOST); } else { gen_set_pc_im(s, s->base.pc_next); s->svc_imm =3D a->imm; --=20 2.20.1 From nobody Sat May 4 21:05:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576692194; cv=none; d=zohomail.com; s=zohoarc; b=HgvcigM4+KhDLFgTS00/KD9Vf+N3wc+l8eKekTwipXXqJGvoNDkMRP142gL201OOOxVXJekeFfnwNnRPyvEs5fO4hN1IWkSeKWMqidiWPp1FI/LnNVT0Goqo7c3Z2TMfInsxJT3u5lJS/mMB7PxSF8MHX5QSuJWC8GLzSlJ/f+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576692194; 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; bh=K2qAxDrW+aua7Zn4Y1Pq7im44DbrmZJggtzu3kQGHxk=; b=mji5lbpnbnR3mqCuMmuGRGjZmtXp/Ngf0yAsD3l+cwC/f6kdml1NrKxcg1vK0KvJMKvs86cejg90SA92qbC5dHwrb6LFm3QZ0EixwfdOA5uRANjWO0JbKnPXRexOZBPWhrG+Q9lhAVSV9FGNOqjqopdfk13wrI9dk9k9n0mSU/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1576692194130411.0152857002138; Wed, 18 Dec 2019 10:03:14 -0800 (PST) Received: from localhost ([::1]:58704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdfF-0006cQ-19 for importer@patchew.org; Wed, 18 Dec 2019 13:03:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60245) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdcs-0004sr-9Q for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihdck-0002Xk-UH for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:44 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihdck-0002TC-GX for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:38 -0500 Received: by mail-wr1-x443.google.com with SMTP id q10so3268434wrm.11 for ; Wed, 18 Dec 2019 10:00:36 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u24sm3220966wml.10.2019.12.18.10.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 10:00:33 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9B1EE1FF90; Wed, 18 Dec 2019 18:00:30 +0000 (GMT) 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=K2qAxDrW+aua7Zn4Y1Pq7im44DbrmZJggtzu3kQGHxk=; b=Af5ZQp5dL+xw61wJ2WOmX8XBMF6+IrVphNieNGwZGrb4Mxb4VcU8G5QGjnRhuDZJ94 nNZ9u0wxeMF/g2TtuS41Jb25uZF/iLLG5ukDqr4c7yj/W4FxgIws5PvJmD6e6NPJZ949 f0/6A0Hy0+186IGyLfIG/gX3ZL6B88nkB606nPX2/apdT+Bn8H1VNJwK5OLYdHXtqTcR pfjtBgggsBkcmlePDHZNl8JjJsqrXzyKt9H6JK8WS7YPL2o8GnNhcX9Z9pVE5FIhxbYB dbCbwcMenzdbhSvVw5C9R1lkWymYHyLf97ZnvVOAtUagoKWfiSbI3jVgy5GRP6hMZMQf yiFg== 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=K2qAxDrW+aua7Zn4Y1Pq7im44DbrmZJggtzu3kQGHxk=; b=tsfIui+Vp8TDLCrnyhRsKPU3XiW0EcUE9nO8vxOu40OdWX9TO0iGfM51kNSZ+MPkhJ Gv/nVbuFm0qGBRqJrZoH1eDzDHdbfqXXQkmljfEdf6bXPwhe0ofJ8sEVEBR16/pwwWsd 2WcX9H1iBRTvcMHNv7UFERCL2u4v3ex/4EseEAOKfqObWMz9MGdzOLMGqFXmt2D8inh3 qpM1ya5doKodrVFBxOHCSeNkGavS/+SbSKcOo5maBNLuVbiIYLt8CXbXVJthBsfq+1sI 8G6OAWNI9qBqrTCphVPgzG7sl40Ryyabyb/G3RnYiIiPEy4IjvE2FBNph1ayeY/Mxpdq +New== X-Gm-Message-State: APjAAAXnJ6XloJLPxJcDRJdgEO15an4WoR7urotuGcyKPfnXyx4B6cTA D+sZ2frVKcp1WunY9ESa+sTq0Q== X-Google-Smtp-Source: APXvYqy/tikRT44obMDAn/SxkSSCf1W9iwYo2Pt0cK/5NfeF3M7XZQ2KbBC26dw6k2M4x3UiHJtsWA== X-Received: by 2002:a5d:5592:: with SMTP id i18mr3996523wrv.55.1576692035373; Wed, 18 Dec 2019 10:00:35 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/4] semihosting: add qemu_semihosting_console_inc for SYS_READC Date: Wed, 18 Dec 2019 18:00:28 +0000 Message-Id: <20191218180029.6744-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191218180029.6744-1-alex.bennee@linaro.org> References: <20191218180029.6744-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::443 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 , keithp@keithp.com, Riku Voipio , Laurent Vivier , "open list:ARM TCG CPUs" , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Keith Packard Provides a blocking call to read a character from the console using semihosting.chardev, if specified. This takes some careful command line options to use stdio successfully as the serial ports, monitor and semihost all want to use stdio. Here's a sample set of command line options which share stdio betwen semihost, monitor and serial ports: qemu \ -chardev stdio,mux=3Don,id=3Dstdio0 \ -serial chardev:stdio0 \ -semihosting-config enable=3Don,chardev=3Dstdio0 \ -mon chardev=3Dstdio0,mode=3Dreadline This creates a chardev hooked to stdio and then connects all of the subsystems to it. A shorter mechanism would be good to hear about. Signed-off-by: Keith Packard Message-Id: <20191104204230.12249-1-keithp@keithp.com> [AJB: fixed up deadlock, minor commit title reword] Signed-off-by: Alex Benn=C3=A9e Cc: Paolo Bonzini Reviewed-by: Keith Packard Tested-by: Keith Packard --- v7 - reword commit title - remove mutexs, halt CPU until data available - document cpu_loop_exit behavior in function API --- include/hw/semihosting/console.h | 16 +++++++ include/hw/semihosting/semihost.h | 4 ++ hw/semihosting/console.c | 78 +++++++++++++++++++++++++++++++ linux-user/arm/semihost.c | 23 +++++++++ stubs/semihost.c | 4 ++ target/arm/arm-semi.c | 3 +- vl.c | 3 ++ 7 files changed, 129 insertions(+), 2 deletions(-) diff --git a/include/hw/semihosting/console.h b/include/hw/semihosting/cons= ole.h index 9be9754bcdf..a3bd6ca2419 100644 --- a/include/hw/semihosting/console.h +++ b/include/hw/semihosting/console.h @@ -37,6 +37,22 @@ int qemu_semihosting_console_outs(CPUArchState *env, tar= get_ulong s); */ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); =20 +/** + * qemu_semihosting_console_inc: + * @env: CPUArchState + * + * Receive single character from debug console. This may be the remote + * gdb session if a softmmu guest is currently being debugged. As this + * call may block if no data is available we suspend the CPU and will + * rexecute the instruction when data is there. Therefor two + * conditions must be met: + * - CPUState is syncronised before callinging this function + * - pc is only updated once the character is succesfully returned + * + * Returns: character read OR cpu_loop_exit! + */ +target_ulong qemu_semihosting_console_inc(CPUArchState *env); + /** * qemu_semihosting_log_out: * @s: pointer to string diff --git a/include/hw/semihosting/semihost.h b/include/hw/semihosting/sem= ihost.h index 60fc42d851e..b8ce5117ae0 100644 --- a/include/hw/semihosting/semihost.h +++ b/include/hw/semihosting/semihost.h @@ -56,6 +56,9 @@ static inline Chardev *semihosting_get_chardev(void) { return NULL; } +static inline void qemu_semihosting_console_init(void) +{ +} #else /* !CONFIG_USER_ONLY */ bool semihosting_enabled(void); SemihostingTarget semihosting_get_target(void); @@ -68,6 +71,7 @@ Chardev *semihosting_get_chardev(void); void qemu_semihosting_enable(void); int qemu_semihosting_config_options(const char *opt); void qemu_semihosting_connect_chardevs(void); +void qemu_semihosting_console_init(void); #endif /* CONFIG_USER_ONLY */ =20 #endif /* SEMIHOST_H */ diff --git a/hw/semihosting/console.c b/hw/semihosting/console.c index b4b17c8afbc..6180f33ef21 100644 --- a/hw/semihosting/console.c +++ b/hw/semihosting/console.c @@ -20,8 +20,15 @@ #include "hw/semihosting/semihost.h" #include "hw/semihosting/console.h" #include "exec/gdbstub.h" +#include "exec/exec-all.h" #include "qemu/log.h" #include "chardev/char.h" +#include +#include "chardev/char-fe.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qapi/error.h" +#include "qemu/fifo8.h" =20 int qemu_semihosting_log_out(const char *s, int len) { @@ -98,3 +105,74 @@ void qemu_semihosting_console_outc(CPUArchState *env, t= arget_ulong addr) __func__, addr); } } + +#define FIFO_SIZE 1024 + +typedef struct SemihostingConsole { + CharBackend backend; + GSList *sleeping_cpus; + bool got; + Fifo8 fifo; +} SemihostingConsole; + +static SemihostingConsole console; + +static int console_can_read(void *opaque) +{ + SemihostingConsole *c =3D opaque; + int ret; + g_assert(qemu_mutex_iothread_locked()); + ret =3D (int) fifo8_num_free(&c->fifo); + return ret; +} + +static void console_wake_up(gpointer data, gpointer user_data) +{ + CPUState *cs =3D (CPUState *) data; + /* cpu_handle_halt won't know we have work so just unbung here */ + cs->halted =3D 0; + qemu_cpu_kick(cs); +} + +static void console_read(void *opaque, const uint8_t *buf, int size) +{ + SemihostingConsole *c =3D opaque; + g_assert(qemu_mutex_iothread_locked()); + while (size-- && !fifo8_is_full(&c->fifo)) { + fifo8_push(&c->fifo, *buf++); + } + g_slist_foreach(c->sleeping_cpus, console_wake_up, NULL); +} + +target_ulong qemu_semihosting_console_inc(CPUArchState *env) +{ + uint8_t ch; + SemihostingConsole *c =3D &console; + g_assert(qemu_mutex_iothread_locked()); + g_assert(current_cpu); + if (fifo8_is_empty(&c->fifo)) { + c->sleeping_cpus =3D g_slist_prepend(c->sleeping_cpus, current_cpu= ); + current_cpu->halted =3D 1; + current_cpu->exception_index =3D EXCP_HALTED; + cpu_loop_exit(current_cpu); + /* never returns */ + } + c->sleeping_cpus =3D g_slist_remove_all(c->sleeping_cpus, current_cpu); + ch =3D fifo8_pop(&c->fifo); + return (target_ulong) ch; +} + +void qemu_semihosting_console_init(void) +{ + Chardev *chr =3D semihosting_get_chardev(); + + if (chr) { + fifo8_create(&console.fifo, FIFO_SIZE); + qemu_chr_fe_init(&console.backend, chr, &error_abort); + qemu_chr_fe_set_handlers(&console.backend, + console_can_read, + console_read, + NULL, NULL, &console, + NULL, true); + } +} diff --git a/linux-user/arm/semihost.c b/linux-user/arm/semihost.c index a16b525eec0..4f998d62201 100644 --- a/linux-user/arm/semihost.c +++ b/linux-user/arm/semihost.c @@ -14,6 +14,7 @@ #include "cpu.h" #include "hw/semihosting/console.h" #include "qemu.h" +#include =20 int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) { @@ -47,3 +48,25 @@ void qemu_semihosting_console_outc(CPUArchState *env, ta= rget_ulong addr) } } } + +target_ulong qemu_semihosting_console_inc(CPUArchState *env) +{ + uint8_t c; + struct pollfd pollfd =3D { + .fd =3D STDIN_FILENO, + .events =3D POLLIN + }; + + if (poll(&pollfd, 1, -1) !=3D 1) { + qemu_log_mask(LOG_UNIMP, "%s: unexpected read from stdin failure", + __func__); + return (target_ulong) -1; + } + + if (read(STDIN_FILENO, &c, 1) !=3D 1) { + qemu_log_mask(LOG_UNIMP, "%s: unexpected read from stdin failure", + __func__); + return (target_ulong) -1; + } + return (target_ulong) c; +} diff --git a/stubs/semihost.c b/stubs/semihost.c index f90589259c0..1d8b37f7b2f 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -69,3 +69,7 @@ void semihosting_arg_fallback(const char *file, const cha= r *cmd) void qemu_semihosting_connect_chardevs(void) { } + +void qemu_semihosting_console_init(void) +{ +} diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 6f7b6d801bf..47d61f6fe1f 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -802,8 +802,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) =20 return guestfd_fns[gf->type].readfn(cpu, gf, arg1, len); case TARGET_SYS_READC: - qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__= ); - return 0; + return qemu_semihosting_console_inc(env); case TARGET_SYS_ISTTY: GET_ARG(0); =20 diff --git a/vl.c b/vl.c index 94508300c3c..1912f87822b 100644 --- a/vl.c +++ b/vl.c @@ -4142,6 +4142,9 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, &error_fatal); =20 + /* connect semihosting console input if requested */ + qemu_semihosting_console_init(); + if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) exit(1); if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) --=20 2.20.1 From nobody Sat May 4 21:05:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1576692191; cv=none; d=zohomail.com; s=zohoarc; b=Fjsj23LKNs7Am9pankG9N5N0xgOo2IRIii+ToAabw4Hs0cq7w6hCwyXCHq5899V1P5jT3uIb/ci0SDcbGsUGd+JHqISPkGCv8bKxm0cc1y4wB446QSrNT1CHZMUbwSPfwOO/ZnkoUuQTzAfcSDrugAFlvYjOtT1CV2fQsdGM5Ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576692191; 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; bh=/fziV75QNz3yxBKb+2AS+Ep/ueUtdymBYxSkJU+JtSY=; b=fei7EVlYcbfJUogUrg6Yt/U84SKE5LUo+PF+GfXLruZw5Ze+OHihz+6UmOqDUYaOrzldgwYBsc3DzsBSrCKFsZBCmjx7+y1F602L2Xt/33Udkss0PDs9CpezKPSXL35C12r1YkytzxhR6PYhASarePsgWpKoorivuMW26meFHmk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 15766921914181002.0686413451845; Wed, 18 Dec 2019 10:03:11 -0800 (PST) Received: from localhost ([::1]:58700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdfA-0006aL-NM for importer@patchew.org; Wed, 18 Dec 2019 13:03:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60342) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihdct-0004t3-RL for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihdcq-0002cJ-Fn for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:46 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46914) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihdck-0002Uz-QH for qemu-devel@nongnu.org; Wed, 18 Dec 2019 13:00:38 -0500 Received: by mail-wr1-x443.google.com with SMTP id z7so3243396wrl.13 for ; Wed, 18 Dec 2019 10:00:37 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q19sm3164111wmc.12.2019.12.18.10.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 10:00:33 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CB2F41FF91; Wed, 18 Dec 2019 18:00:30 +0000 (GMT) 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=/fziV75QNz3yxBKb+2AS+Ep/ueUtdymBYxSkJU+JtSY=; b=t1/rW/JEf3QKkVLVHg/gMsC+Ct+fbSOVTMHB6e3lPTf8+mVzhJNsJicHkXGdsSuXGm v2HjumhoPfj+8dgr3Jn5ygkIPsvtEj/VtgMSQ2rMdVXJXF51FwDRkkxJOiDmmuzk/toR cwDd33Si5xtF5J1Ss8konCvEY/g6yNuWxOZBHwIB36G3pd242Gis0QblrX4ZIjlyoZPF 5MNkwic/du7t/sp7sRWnRrIKmkpJ7e+AB4UxPtJkUzorX8/0mWfWSJmiqo/wXDP8VrF4 q9q3yuWWd+87zXz1GhkNFJoIh2q2RWu6bbWyyWjJr9qcTDS+5VjuC3OeuimccTHKibAl Bk6Q== 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=/fziV75QNz3yxBKb+2AS+Ep/ueUtdymBYxSkJU+JtSY=; b=YMziV8xLjROqNj3A+7XO7aXoeqieNuCnTEWKmnk4lSH7fPW7nFGphyyriiv9zSsVzU rdKssng7lb0ChcDkrjuZfE3DHpUCGjrYCLl8THmBqCV3eDkDqtQPEsj6SQ0raA9SFMVt N6ReY9wRYiPxcV/wTvrvS452HO2EEzFygUgMpLzg/KossSj/i40h3wEKHG5d1gIhPQkj +fqic3rcemSk3yI27bqxLqMH1joKGxgQorJlf4O1yc+wyFQinfnWN5BIGJGKKyVT/uRw q7ikRafJag9eP6woiuyHeKdqwLvrQDEkdILq4KwIeoUV1KqOL1RrRKR7qdiEY2vhO27D ISMA== X-Gm-Message-State: APjAAAVmEWiJO2IMELYm4OHNKCSDH/TDwXZsTaXvJCe3SImcXCWxMSkA E8n8+4CiFeIbTVtgHt05cER79w== X-Google-Smtp-Source: APXvYqxORnpNvCZ1TWKw5pjTA2FxMC7ZCXLs9w3zhiQZoxiNteuM6bF9kbEMVWkL/M3E8N9Y7wF8ag== X-Received: by 2002:adf:e812:: with SMTP id o18mr4105823wrm.127.1576692036528; Wed, 18 Dec 2019 10:00:36 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 4/4] tests/tcg: add a dumb-as-bricks semihosting console test Date: Wed, 18 Dec 2019 18:00:29 +0000 Message-Id: <20191218180029.6744-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191218180029.6744-1-alex.bennee@linaro.org> References: <20191218180029.6744-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::443 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: pbonzini@redhat.com, keithp@keithp.com, "open list:ARM TCG CPUs" , =?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) We don't run this during check-tcg as we would need to check stuff is echoed back. However we can still build the binary so people can test it manually. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Keith Packard Reviewed-by: Richard Henderson Tested-by: Keith Packard --- tests/tcg/aarch64/system/semiconsole.c | 36 +++++++++++++++++++++++ tests/tcg/aarch64/Makefile.softmmu-target | 9 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/system/semiconsole.c diff --git a/tests/tcg/aarch64/system/semiconsole.c b/tests/tcg/aarch64/sys= tem/semiconsole.c new file mode 100644 index 00000000000..636537fbe4b --- /dev/null +++ b/tests/tcg/aarch64/system/semiconsole.c @@ -0,0 +1,36 @@ +/* + * Semihosting Console Test + * + * Copyright (c) 2019 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#define SYS_READC 0x7 + +uintptr_t __semi_call(uintptr_t type, uintptr_t arg0) +{ + register uintptr_t t asm("x0") =3D type; + register uintptr_t a0 asm("x1") =3D arg0; + asm("hlt 0xf000" + : "=3Dr" (t) + : "r" (t), "r" (a0)); +} + +int main(void) +{ + char c; + + ml_printf("Semihosting Console Test\n"); + ml_printf("hit X to exit:"); + + do { + c =3D __semi_call(SYS_READC, 0); + __sys_outc(c); + } while (c !=3D 'X'); + + return 0; +} diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/= Makefile.softmmu-target index 950dbb4bac2..9bdcfd9e7e4 100644 --- a/tests/tcg/aarch64/Makefile.softmmu-target +++ b/tests/tcg/aarch64/Makefile.softmmu-target @@ -31,7 +31,14 @@ LDFLAGS+=3D-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS)= -lgcc memory: CFLAGS+=3D-DCHECK_UNALIGNED=3D1 =20 # Running -QEMU_OPTS+=3D-M virt -cpu max -display none -semihosting-config enable=3Do= n,target=3Dnative,chardev=3Doutput -kernel +QEMU_BASE_MACHINE=3D-M virt -cpu max -display none +QEMU_OPTS+=3D$(QEMU_BASE_MACHINE) -semihosting-config enable=3Don,target= =3Dnative,chardev=3Doutput -kernel + +# console test is manual only +QEMU_SEMIHOST=3D-chardev stdio,mux=3Don,id=3Dstdio0 -semihosting-config en= able=3Don,chardev=3Dstdio0 -mon chardev=3Dstdio0,mode=3Dreadline +run-semiconsole: QEMU_OPTS=3D$(QEMU_BASE_MACHINE) $(QEMU_SEMIHOST) -kernel +run-semiconsole: semiconsole + $(call skip-test, $<, "MANUAL ONLY") =20 # Simple Record/Replay Test .PHONY: memory-record --=20 2.20.1