From nobody Mon May 6 19:53:24 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=1576848449; cv=none; d=zohomail.com; s=zohoarc; b=SLQIkq3z8FmorsQz1KUnY/a0QhqMLQ8CYkrY9cf2+10TB50TihZhRSVV3Iu1jj7HAWo8l5RVZthlrqEshbkQeCzmweCG2AxMAy8QAFg0NR8sWw/qKG261SxzlWQBsaFkFlaE3fRxaTyHH4lfya4q17pdDbS62sg1GCH26c9/siM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576848449; 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=tq4uTuTrF1sjaAQeE45sTsyrBhoioBCJJ0MxAc2jFgg=; b=WIp6WiGXUsE/7j8ZLklkRO0ueALVOc9FqmC8ITa9DAM7FtCJkm865LbWB649Yerl8+JmYJ5xpSiKUvP8bLD0L2K2VN8Ld36x7gipNt7V3XFwIt6OcoMbhcPET0pc2Y8xgstaA/4Jyz8JhBe1XcXxp7vSMaqTzICTI2jaiqHq7fI= 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 1576848449210122.90853021073588; Fri, 20 Dec 2019 05:27:29 -0800 (PST) Received: from localhost ([::1]:55454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIJT-0004uW-8g for importer@patchew.org; Fri, 20 Dec 2019 08:27:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42556) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIF3-0007S4-Vm for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIF2-0005Rt-52 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:53 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:36620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiIF1-0005NG-Nb for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:51 -0500 Received: by mail-wm1-x344.google.com with SMTP id p17so9236065wma.1 for ; Fri, 20 Dec 2019 05:22:51 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t1sm9763073wma.43.2019.12.20.05.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 05:22:47 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ABC081FF8C; Fri, 20 Dec 2019 13:22:46 +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=tq4uTuTrF1sjaAQeE45sTsyrBhoioBCJJ0MxAc2jFgg=; b=n2+bLZoXUIjpILnemC+nImUg3xPzAb+dJGK3kwH6yv2Pw7+0XsroNA+cITIssOScdH 5fO9iilbZSj+ygSANDaLmWhOKGTmzyvqJMKRWzHrzyeNZVwUdWY1drgWc5ZAe+F08qyc uu1w+bQecM3O7j2y50K/aQ8OMbs1aE2PhJ3X9tSE3PSh+khjbuv/oOcoZwrDtY6b2BpQ v7RtUSQ3ktfSOtNb1vE5ybW/OA8TFC+Fr12uJR9EEq4Jqv/JKV4qr2CJZmpFj9e0oZE+ Kzg1RFbyL1tvX3qjq+tODsNyIWB7DIYFPA4SOl/P+OUWpbI9aWyepAWBDwRLsobbSN8M nD/A== 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=tq4uTuTrF1sjaAQeE45sTsyrBhoioBCJJ0MxAc2jFgg=; b=teDwcNTEGYTwwVFK9txon/4KdonXOZbsVSazteNQc0liNE2hlHQW+K+diFC0DmIkhp aAb7XKdF5EkAgB+mPowpxvJbl4Ma3E4tQIlfF1QNHRDj5po/mMPGajknj4/63rodcqRd 7fAx0g7NiK3RtuMFAHogNESLAjKsUNo+aitdu/LdwFndQBxAP/nXRhapNU61+kJHw+uV uaj95TAm99nuyhn1nBirC/4ixH/YzWtVoS6Irer3SjJu5iP+pOGC/7o2Wkz6J9qsniCn fY0B5RBYAU46tF/GH8MCLBOHHtvdOYHG651T9+g7hEYH29afwynEVsOLNvK4CSSHiQir C+Nw== X-Gm-Message-State: APjAAAVBNeSokk3p5tQbdDdji2UYW6G7/8aYGiALEMe6fkAi2gqcZvJh +5YJTcz7PKHJGqWYfdhbRMI4Ng== X-Google-Smtp-Source: APXvYqwPPRuJrhjFoxxUPR7D/zHH4ZkVaEVPFnI2YqCqBv6g/C/ERIkCv9Gp7rQ8wcBFiSK8lueBlg== X-Received: by 2002:a7b:c216:: with SMTP id x22mr15708176wmi.51.1576848170053; Fri, 20 Dec 2019 05:22:50 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] target/arm: remove unused EXCP_SEMIHOST leg Date: Fri, 20 Dec 2019 13:22:42 +0000 Message-Id: <20191220132246.6759-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220132246.6759-1-alex.bennee@linaro.org> References: <20191220132246.6759-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::344 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 , 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: Richard Henderson Reviewed-by: Keith Packard 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 Mon May 6 19:53:24 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=1576848276; cv=none; d=zohomail.com; s=zohoarc; b=IEhXOpEfP17hvyzzcNIaJyIvY3lrW7PmfEcZGUL0dNLK80EnM81CDNFxo0PR0Xyu6Ftb1Wob8FLFbUddZsfYgNrhTg9dJO3U/4iZjRoCn4M5xyKc0NLiJFieG5OCiiHlkopvwAqsyFGbEp+aaXsnJzN/h3NTMevisjqdC2bc3aI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576848276; 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=ovdoYf7CDyOfpwifeooI731QUTwDX4W14EjWn1WUyGo=; b=Azehy1WMACFByaxvqh8leHQx07bK56IUoWEktyiY6HLl5t8O6uYKZxTBX3EypLhaDm5rHknOi8YUY4C83TnqcDyZvdelbNFXBWeLV6IfScq8/AXeOmN37GSke4F6tFSEhggpvay1VB5u++lgmej4/hsH/wuaj+OIpkMGUcnl/vM= 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 1576848276208411.7260927267456; Fri, 20 Dec 2019 05:24:36 -0800 (PST) Received: from localhost ([::1]:55396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIGg-00018x-BC for importer@patchew.org; Fri, 20 Dec 2019 08:24:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42412) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIF2-0007Rv-TB for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIF1-0005P3-1d for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:52 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:38760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiIF0-0005Jc-Iy for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:50 -0500 Received: by mail-wm1-x342.google.com with SMTP id u2so9218093wmc.3 for ; Fri, 20 Dec 2019 05:22:50 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id i11sm9852109wrs.10.2019.12.20.05.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 05:22:47 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C85C41FF8F; Fri, 20 Dec 2019 13:22:46 +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=ovdoYf7CDyOfpwifeooI731QUTwDX4W14EjWn1WUyGo=; b=nUE6pb+O2XFAC6oAOxFwExUDYou7LIo786nSmjUlddRcNzddNEYeFFxianF5IawxwU 9IuUsKaA5o9JPQ64aTV0rR6Ldko71fXr7D/+Wq26rgG9JxhJr6hFScLjRqxPWYJjHavX YlEZkWkK4MGwfroFzlBD/XXxYt85CeZ5/UhSm1JUJthnFDPoosS0drSS72CaOs/tCndz vkUb14CtQ57a+YljskAKWVmgn+6QiNzUSFy1/Gzjk3/KRohoxb7YNrrgvcUa2ZDXWCqR jlqb0HKyBBBoZOC+Km6IIHViLDgHRV1HVY7tzLgnZLgdJGlmoejgt6diU/S/4+PBK/7U OL3Q== 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=ovdoYf7CDyOfpwifeooI731QUTwDX4W14EjWn1WUyGo=; b=dWpE28FmJKjI72xWjMaVmMwjhq6Ev/ecTzkKS+fiYayOAGQX8y7yderqLG4WymVjee BNwAuNy1AlkN2Rx5pzsVkcRE1dxPdhujdfyw7WchPb5cTJVhsFHXtqkcKX2lcxT2AFd/ 60uv7hdHHMuqlAyub1Wi1sUbqILy35kBns9aCopMEESyztzfbW8GaMHSETn3seVH/Z24 Ukc/NU0e3gDvXErGzflzh0cowe+GHD9h2pulmYunNycXrwnKAL4qTXouVzEGiX0iYIkF CwI3m7LLEr3kAYDuSsXlQg9BUFXavFrkzzm20xaaMSo2Y9+MWR542FxcD1oBqKC0n0Ro ccDQ== X-Gm-Message-State: APjAAAVNFRJl6XPhhen7N0W9usqJ9FRaI+fPfn7aZFPhuFZDZ3zGtGPh B5q6GL1B/WOyGOsybO2+FXGebQ== X-Google-Smtp-Source: APXvYqzgEsLHk7u7rRHF4JlGBj4Qdgiz96dtsKDRxiOtOOz/g6qS2KIFeSl6ZXvWBwXYQ+bJ4Caj7A== X-Received: by 2002:a05:600c:1:: with SMTP id g1mr15717810wmc.131.1576848168910; Fri, 20 Dec 2019 05:22:48 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/5] target/arm: only update pc after semihosting completes Date: Fri, 20 Dec 2019 13:22:43 +0000 Message-Id: <20191220132246.6759-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220132246.6759-1-alex.bennee@linaro.org> References: <20191220132246.6759-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::342 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 , Richard Henderson , Laurent Vivier , "open list:ARM TCG CPUs" , =?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: Richard Henderson Reviewed-by: Keith Packard 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 Mon May 6 19:53:24 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=1576848514; cv=none; d=zohomail.com; s=zohoarc; b=Qrwy78bQy2Qju4qluF1rOb42nsPzuAx9y0Nhrgzdo/gc+VX8CIQXc9tyeFmXuJLyocVX85kOq0/p/8hk0MQJ+9usQs1OFUXKQPbHWqJ6sIbPe6aZplAwkJmGj9XawBSpQkXzig/lgm/WKwZN/QLtFi0OCY/fZ2qvDCFpR+90/BQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576848514; 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=hcqHu7KDcCniaxK/ApCQCt8iC+h5jHtgiGByxeELqFg=; b=HG2YcTQc8p03/+EEizsic4zbKIMRnailIDOBi2dsmOpM45LYfMVhxibR+kKlqFq3W5r0hvBGVkIUh/WMfBf/TB6u4Bt3TNY64aCHiTL9pRmkF/T9BI/rr7PaR3uEBuEnx72ZobUi73hX8rFLualDCbDhs66KX/9OFJNGLseCZ0g= 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 1576848514563937.2964284916037; Fri, 20 Dec 2019 05:28:34 -0800 (PST) Received: from localhost ([::1]:55530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIKW-0006TB-Rs for importer@patchew.org; Fri, 20 Dec 2019 08:28:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42865) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIF6-0007Uo-7t for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIF4-0005Yd-As for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:56 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36854) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiIF3-0005V5-Rj for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:54 -0500 Received: by mail-wr1-x443.google.com with SMTP id z3so9423437wru.3 for ; Fri, 20 Dec 2019 05:22:53 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 25sm9240360wmi.32.2019.12.20.05.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 05:22:47 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E8DB51FF90; Fri, 20 Dec 2019 13:22:46 +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=hcqHu7KDcCniaxK/ApCQCt8iC+h5jHtgiGByxeELqFg=; b=f5v+1xGr4FBueJFTCDKKxXapZ2QxRklVXyYs6w5KH7F4tMYnf9tSQTq2cTw+aUozv9 DZmQ9oV7mWaniO8Mn0DebpPisqwYWmu+x8W7Jd7vuchP6uuMG3to1RP6cl4nNkn2ix5/ XTM/thSTKS0AY3NVJz1JoCl3ANKpLGGlT+dwKrbMrid4bMMqE9AYFCQB+nv78a2y6XHP qLxcaCKZUtDjiX3zwDwNPLLTuZMpJiwIOTxiqB4kZhr/H37cNtM9D38tGYJWsjreiTxD 0Xzt9Tesjt6SzyEHIUPdVErt/N9yv56EaktqnAejYDQ6U6IvMQcr4kBJbP14a8aipNk0 746g== 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=hcqHu7KDcCniaxK/ApCQCt8iC+h5jHtgiGByxeELqFg=; b=B/me0ieFBVGGXD5jBWKHFonhQC4RjJRLYLMdjHKvjWXe9jPAldJU06HprLDy2V495m 6v01HmnR+w5EdhYPI3y7oSNyx6slH1JV4qdmO1p6x5/yEc5NWID9tE587nBKRZ3dnYAu 51V6ELZqRl+hiRpR7dl7xRU3w4MIMvU2yKTIYXwMkbUDo5mXF24Kpr8emQnDEvs0xDKg qGuxqzPhis5Mn7Jxe2oZLT4r+fw7y3HOcnO/bTKSGOgZcPVgLW8wZ2z5mXaOx+KJRyYT qxCjG9yB3qO6jyKfPsUUQAmQe5CGsNX1Z8AKnc57Q4W5GYhVOLw2ADcNE+4CHvXjISL0 kJcw== X-Gm-Message-State: APjAAAXrFGixUWfaH1NXTct79AV3Woscot6wwQ04gTxv3QYeuRdOfNGC se6YLbKbTKyBz32PDScU6abMDA== X-Google-Smtp-Source: APXvYqzuAZWcvG4klfykSoXsgbBsdiDzg4FmbhTHT8UHzQUwjDTjupgb384O4iSUsZbJVVUmVsTpvw== X-Received: by 2002:a5d:6692:: with SMTP id l18mr16289208wru.382.1576848172572; Fri, 20 Dec 2019 05:22:52 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] semihosting: add qemu_semihosting_console_inc for SYS_READC Date: Fri, 20 Dec 2019 13:22:44 +0000 Message-Id: <20191220132246.6759-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220132246.6759-1-alex.bennee@linaro.org> References: <20191220132246.6759-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" , Paolo Bonzini , =?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 between 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 Reviewed-by: Richard Henderson --- v8 - allow linux-user to block using unbuffered IO - spelling and wording fixes v7 - reword commit title - remove mutexs, halt CPU until data available - document cpu_loop_exit behavior in function API squash! semihosting: add qemu_semihosting_console_inc for SYS_READC --- include/hw/semihosting/console.h | 16 +++++++ include/hw/semihosting/semihost.h | 4 ++ hw/semihosting/console.c | 79 +++++++++++++++++++++++++++++++ linux-user/arm/semihost.c | 27 +++++++++++ stubs/semihost.c | 4 ++ target/arm/arm-semi.c | 3 +- vl.c | 3 ++ 7 files changed, 134 insertions(+), 2 deletions(-) diff --git a/include/hw/semihosting/console.h b/include/hw/semihosting/cons= ole.h index 9be9754bcdf..0238f540f4b 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 + * re-execute the instruction when data is there. Therefore two + * conditions must be met: + * - CPUState is synchronized before calling this function + * - pc is only updated once the character is successfully 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..6346bd7f506 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,75 @@ void qemu_semihosting_console_outc(CPUArchState *env, t= arget_ulong addr) __func__, addr); } } + +#define FIFO_SIZE 1024 + +/* Access to this structure is protected by the BQL */ +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); + c->sleeping_cpus =3D 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 */ + } + 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..a1f0f6050ea 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,29 @@ void qemu_semihosting_console_outc(CPUArchState *env, ta= rget_ulong addr) } } } + +/* + * For linux-user we can safely block. However as we want to return as + * soon as a character is read we need to tweak the termio to disable + * line buffering. We restore the old mode afterwards in case the + * program is expecting more normal behaviour. This is slow but + * nothing using semihosting console reading is expecting to be fast. + */ +target_ulong qemu_semihosting_console_inc(CPUArchState *env) +{ + uint8_t c; + struct termios old_tio, new_tio; + + /* Disable line-buffering and echo */ + tcgetattr(STDIN_FILENO, &old_tio); + new_tio =3D old_tio; + new_tio.c_lflag &=3D (~ICANON & ~ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &new_tio); + + c =3D getchar(); + + /* restore config */ + tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); + + 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 Mon May 6 19:53:24 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=1576848620; cv=none; d=zohomail.com; s=zohoarc; b=M0hTONBcnSQaE3WDS3H2tc9hY4TR1Pc/meQOC8DNhH7dBaZm9WFcsAXIud0A22hiZOwbYHcRZMCyE8ZxW9DisJA27LdhvUnLH/jbvpGKRniMIqjBaikGXFjAxKytCSmzO9k+eHPhducyLDVTbZopuyg0Tts1VB+DoysV7EMMSv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576848620; 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=tWCHuSggB5szQdLA+HidJI7cGodm3lgcmToLZIxmHFk=; b=Eph5HlYXbbAzlfFTYH/ZtQME9E7A2jr87w5VULAqtKz4PEgfYf6LLkL7n2xzb02N/emxZqDwkr30rZgaBE7pFa7HeJXtC3xdKOEClw44bSKbLb9KMq8iA1tWfIlkgFBORuTvoWH2iQP4uEGg91ViJV9bx8nAY9RQKuxiSb4SE9A= 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 1576848620195837.9871195368398; Fri, 20 Dec 2019 05:30:20 -0800 (PST) Received: from localhost ([::1]:55676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIME-0000B8-M2 for importer@patchew.org; Fri, 20 Dec 2019 08:30:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42995) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIF7-0007Wz-2w for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIF5-0005dH-Hx for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:56 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiIF5-0005Yf-58 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:55 -0500 Received: by mail-wr1-x442.google.com with SMTP id z7so9361041wrl.13 for ; Fri, 20 Dec 2019 05:22:55 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n16sm9986070wro.88.2019.12.20.05.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 05:22:47 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0C7811FF91; Fri, 20 Dec 2019 13:22:47 +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=tWCHuSggB5szQdLA+HidJI7cGodm3lgcmToLZIxmHFk=; b=V3ktwIJCtO2n9oJK7KwaYijwukdLxDfE24R88UvTsU3NDWkbMn/So8kJg0gq3Q0fMD /QN4lV9GaKWwd5Z8h5qR3gZ2Qr8xGQVDHRXIMKbomug9YfrwqP+YVy8a1O3plJYTTxZL 9PPf3cfWhxH2VLSq6g171VNZSK7ZzXSD5CNvM60CN4vVc05sLiHgrT7j9ri7GKklgY0p xM4p51wo1VwTpLKxluqGfIrPcVbTYLWuwFjnV2RiOf5ZX+0EFSl/lSfKRKIEHdFpfzso B0rPP95jSvsZDi22kfoQdTXjmEU4K7Fq3uKsMG3F+TVvx4ZwtQoWfPLRg+G4b/6a15JF Obaw== 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=tWCHuSggB5szQdLA+HidJI7cGodm3lgcmToLZIxmHFk=; b=m9sApvWawVKWCo0taqzbW3ceiYBinSZ/Sg0W8++OKj6CyyoJKc28ujagxwybKWGXav wC8YvJmqRWo8gSqC3Tv9GtucKpoENBJ1vY8HMc+U3sl9MQVvKUX6eeIz4XfZ/Mu3JJTK 2Kdn4ipCVszW92pNpBdZ7lzhpabmsxjeO7PgYHDjDsNwUstz/ACACFmz4zltfYo+aN7R 0r05zS7wp4ZqZM9mqQ1m7HngftfGT58u2HLIMwzao0T+nF7Vn5aIHtpe7Y/oHpmS+Jy+ OGpYMqBy6U37mS4nx2hfK8DEqI1B/isPunuJbz+t4EU3z88etpjGsIs9Ubp7CICTQ+W7 659Q== X-Gm-Message-State: APjAAAUq5BxAYcVVmoHKha0bcxyjzbd/9rZFVqXMKxE4zSmy8bqh6LtP UD6RBr2q9Kl9fCAlb1n7nDxVwQ== X-Google-Smtp-Source: APXvYqxUKjMRQFj6C9Oe7b6xQzSLyDeyPE3MHbkZsmx/Km5T19B17j9M9tRSMYwDSYGXH68I2gMXbg== X-Received: by 2002:a5d:5091:: with SMTP id a17mr15166170wrt.362.1576848173831; Fri, 20 Dec 2019 05:22:53 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 4/5] tests/tcg: add a dumb-as-bricks semihosting console test Date: Fri, 20 Dec 2019 13:22:45 +0000 Message-Id: <20191220132246.6759-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220132246.6759-1-alex.bennee@linaro.org> References: <20191220132246.6759-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 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 , 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: Richard Henderson --- v8 - actually return the result! --- tests/tcg/aarch64/system/semiconsole.c | 38 +++++++++++++++++++++++ tests/tcg/aarch64/Makefile.softmmu-target | 9 +++++- 2 files changed, 46 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..bfe7c9e26b4 --- /dev/null +++ b/tests/tcg/aarch64/system/semiconsole.c @@ -0,0 +1,38 @@ +/* + * 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)); + + return t; +} + +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 From nobody Mon May 6 19:53:24 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=1576848300; cv=none; d=zohomail.com; s=zohoarc; b=EhWOCIS9WDol1oof9e+SANsORcTQMbBGjiXPc0dP3wL7aWny6C2eF4o3HWAy6M/DmCIsxbU79Mp5OspnGOSHhCnQCIJhm82aeOtMd/3hRmRjpaiJLK56doK4JtS+PBZK/8x8UfUptoGYOT8GFa2S4NUqraVpM8yOYBYRBIgmWj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576848300; 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=06XcrWFNlcIoXvMNfQG79LGFIvgNsdfFUwprXyUXHHk=; b=d0uF58hKeHiBIVpnW+MrSz0M4s2z5uHsMU39HEk06wy4RHd3Jr4Ur044RzrdH/5NVjcHuTDjeJF9sJ1yQkp0cK/+/UsXqmyulkY/3BvWpFGajNr3zo2MU5W3G3kWXLWp+AJlWyDBExDvOgTfM2F7DKXH5htwtQYRovN1MuFmATQ= 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 1576848300617697.9326128775666; Fri, 20 Dec 2019 05:25:00 -0800 (PST) Received: from localhost ([::1]:55404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIH5-0001mQ-4e for importer@patchew.org; Fri, 20 Dec 2019 08:24:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43245) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiIF8-0007aP-O4 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiIF7-0005jj-EP for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:58 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:51079) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiIF6-0005fe-Ta for qemu-devel@nongnu.org; Fri, 20 Dec 2019 08:22:57 -0500 Received: by mail-wm1-x332.google.com with SMTP id a5so8924090wmb.0 for ; Fri, 20 Dec 2019 05:22:56 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x132sm13756583wmg.0.2019.12.20.05.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 05:22:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 259591FF92; Fri, 20 Dec 2019 13:22:47 +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=06XcrWFNlcIoXvMNfQG79LGFIvgNsdfFUwprXyUXHHk=; b=BJZ6TIXhZiMuci54F//kmtNJyI9a8Qfq7aXKUYE2HiTdFLJ5SQyge6LGDKSo76ka/I +gyflGd0LltpF4bcNJ4YAAOcliYbDN+JytvtbNFy/MlcfhgQ+g0f+yLYzqwdH7YWinC8 1sqN3hJ6MmWWgP5OKItYdamq8eOq2MhUIttW5x9yJ8QEIwqxGbHOWnj9jJIE/vugj93+ fWW7BqSSYgfu62Ube+TKCr2LnsdICrIUypUOsCX05j9XptDJtn74NKGko+fY5Q500lvd Ar7BP5ZeTtIc5aHdnh18+0Jx6SGWMfT2VVoSc4CNjzAlMFpHfVYtVA5Pl6rAwRODJ1A/ mtjQ== 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=06XcrWFNlcIoXvMNfQG79LGFIvgNsdfFUwprXyUXHHk=; b=KomLBhV0X+AuqZqyjx4Okm9rAPe8Yajq5LdGTRHZ3T8KN1gHauzc9EYZGyC/gH0sn/ dFrMZNuqHMYdZ8oE6Ju5BQRIF5cczVCb2iUAn27LrVzs3/Xvfd/2PbX6oEVayt6nFzR+ lJNtNHpFThyP2X1yRmrS7Hy6V3SPFb4QfJeQonMDT1/gEarxFPWF4DRRjTzsowkpGsnP 61vqvrL2SCDY2jBteEBG80+2TDw/FWd2vB92CTywaZma40Ff+lL8OVe5HaSaNRVuWl3P c9dXAo6aeJhXM0YXxIQkuU+7qeffErfwObRs6mC4Kx3W3xckZ0/SLfnf+YjMCGwiWcAh P2Yw== X-Gm-Message-State: APjAAAWuB3afo2LgWg7Jvk4ac4IoJ6kxfkCBVXlEYnJMBwU5NtJ5gSGN s8aw2AR9w5NWgE7y2x4rZlW6fA== X-Google-Smtp-Source: APXvYqy+imwWgoxl3NSahuYuepF+nQFzo3osPvHv/D3n6Kviu43fMGBRDuHPwFxE7PBMUNXvZNC7FA== X-Received: by 2002:a7b:c001:: with SMTP id c1mr16623663wmb.96.1576848175612; Fri, 20 Dec 2019 05:22:55 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 5/5] tests/tcg: add user version of dumb-as-bricks semiconsole test Date: Fri, 20 Dec 2019 13:22:46 +0000 Message-Id: <20191220132246.6759-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220132246.6759-1-alex.bennee@linaro.org> References: <20191220132246.6759-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::332 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, "open list:ARM TCG CPUs" , =?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) There are linux-user users of semihosting so we'd better check things work for them as well. Signed-off-by: Alex Benn=C3=A9e --- tests/tcg/arm/semiconsole.c | 47 +++++++++++++++++++++++++++++++++++ tests/tcg/arm/Makefile.target | 7 ++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/tcg/arm/semiconsole.c diff --git a/tests/tcg/arm/semiconsole.c b/tests/tcg/arm/semiconsole.c new file mode 100644 index 00000000000..cc9266b87df --- /dev/null +++ b/tests/tcg/arm/semiconsole.c @@ -0,0 +1,47 @@ +/* + * linux-user semihosting console + * + * Copyright (c) 2019 + * Written by Alex Benn=C3=A9e + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include + +#define SYS_READC 0x7 + +uintptr_t __semi_call(uintptr_t type, uintptr_t arg0) +{ +#if defined(__arm__) + register uintptr_t t asm("r0") =3D type; + register uintptr_t a0 asm("r1") =3D arg0; + asm("svc 0xab" + : "=3Dr" (t) + : "r" (t), "r" (a0)); +#else + 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)); +#endif + + return t; +} + +int main(void) +{ + char c; + + printf("Semihosting Console Test\n"); + printf("hit X to exit:"); + + do { + c =3D __semi_call(SYS_READC, 0); + printf("got '%c'\n", c); + } while (c !=3D 'X'); + + return 0; +} diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target index 0765f37ff04..997e6e78ed9 100644 --- a/tests/tcg/arm/Makefile.target +++ b/tests/tcg/arm/Makefile.target @@ -40,6 +40,13 @@ run-plugin-semihosting-with-%: $(call strip-plugin,$<) 2> $<.err, \ "$< on $(TARGET_NAME) with $*") =20 +ARM_TESTS +=3D semiconsole +run-semiconsole: semiconsole + $(call skip-test, $<, "MANUAL ONLY") + +run-semiconsole-with-%: + $(call skip-test, $<, "MANUAL ONLY") + TESTS +=3D $(ARM_TESTS) =20 # On ARM Linux only supports 4k pages --=20 2.20.1