From patchwork Sat May 21 00:03:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574755 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2659860mab; Fri, 20 May 2022 17:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjgcuNu0EOst1vFF7Dk0U71CIxKjZ4zNwQ/9A8LPyiAvuAMO67151Xy/Gej0hNi4alf7C3 X-Received: by 2002:ac8:7d46:0:b0:2f3:dd89:5557 with SMTP id h6-20020ac87d46000000b002f3dd895557mr9499206qtb.567.1653091665206; Fri, 20 May 2022 17:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091665; cv=none; d=google.com; s=arc-20160816; b=T1zLdE+PY47/rAoMpodmjqPpRRU0O2N9CG9mRpyhG5t9hFsNME4FBjp70ShHz8eGLu q33oj+T1b/3ipFHrlef0WrGqaIoKoQwbT5/L8VxA5DZlMc59mrlAQXGzxgw40w7DdhTT z6KTFgkslHZXUr7Ry8jZTAG6dfxL8PF414vtjnqsB4+NXVNCNNkALdPZJJz+gxLtyqJ7 YS+4FasZvmEKXJGu0y480N84FP4ga4UTX66Et5B59cEIqcMZPSMouymywodVyLRa2wSY 1p56hzFuMWy/7F6Ry1BCL2AZxagNEs3xThxXwWTIyggcGJjvu1mgYvNKnEnIjEKLQo5N jmsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8nTEBA0ibtyn59fqrnvMD1vJ/OB33r4Ox7u7QZwpM0M=; b=bRptT9/0XfsUV7OZZZDhz6RE4bbQgRi7WrCMel/8dlGODhSVx8Xnb5/DpOHcdlPrBg QzxE56YlH6KqIIezlTPSvTwaoDZgSOJf7Lr5G5WUMB4bTIa6IzxdRS2KXYQzb5KSA0Sj putMhqf0CMPituh3pyZ6bqroMS2qBv17gBehy9xBEPwlnB4uzmrcH6DwxyUSEt+gp4Qm BK3/QCfBuGQkyMHUOPEuh6ZL+4SOK4FZoBSD9Trv4C0XutDXtgMfmYlAvwnv5Amqe3PZ lGNJQIqWaU//2PP1fw7M6M2p23oEFOjudQJv7Nqhw2eRGwMLaUP6D+1pjlHiIe2fzGgd OSNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="okgZTs/g"; 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=pass (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 k9-20020a05622a03c900b002f917d2d3casi392573qtx.615.2022.05.20.17.07.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:07:45 -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=pass header.i=@linaro.org header.s=google header.b="okgZTs/g"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCem-00080s-OH for patch@linaro.org; Fri, 20 May 2022 20:07:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbK-0007zt-82 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:41741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbG-0003y9-4P for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:07 -0400 Received: by mail-pg1-x535.google.com with SMTP id 31so8967887pgp.8 for ; Fri, 20 May 2022 17:04:05 -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=8nTEBA0ibtyn59fqrnvMD1vJ/OB33r4Ox7u7QZwpM0M=; b=okgZTs/gWshfiWF9hJ9WQg6ZmZB64+y4B+as/FChp6kjAjj7rkMIJcWVqSZtCrPK1+ tNaAiA9pRp5ITZGfoBr0XO5oE4iFv/1g3sAZaWaLaexZKCBo7615Gh4ztZwC9nQejxNj FjxO93m4cgghF+cL7KxydpmdK0TE1jiK7mPhgv9An13YEfVw5RiljzjO6D5VqD44qmjy 0T8HG/uBYA0DOjRIRLTii06zo49OMeeNp+erbxY+xQcAPJojDoDS9dt3Ix5kMM2ebq7R DnRZvLTuEbukeTrj6g/nSVOzv/FOaz4Lku1iFBFscTQa2B1sQpe/TyQayQAGgsT2yCdt Fsog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8nTEBA0ibtyn59fqrnvMD1vJ/OB33r4Ox7u7QZwpM0M=; b=dDye6mR2SmmeYYrecU4faPsjVhqFG+1WVlXdxn2G5H29PkTC5caZT8Bf3nLi8cfIGF 8Ei8pbqbftAyoR0/6he+hnVzdavrmwvIi+blD36P9KaoRn1o6fDTSk95H/xUoudNe/7O ODHZ142Qt0iRUmKaoGAIX4dwMi0I7ha/ZQsMH/JCqmeFJcmHIfWMhYtb+HFGbaMlA/cu 92CttAq09mzBQVxKixh/MmeJJkOi1l3xhptKYtuI9EESAiv2/4f3giPmwEQyXMrOEmq1 FHjy5o3fZ5fVppfzVQXK1zic1j/TzStq/2c4A9t3/DFyJ4kf11ZA5vLpaIyyeBbRfoVp w4nA== X-Gm-Message-State: AOAM532Hc11UvrvFqh2BZtEUKbzwnSY+q2f7AN/x5M0XleA1HeWq9Bou MUtxGevsCfupHWA++mdK1/AGkt2blwCqVA== X-Received: by 2002:a63:fc5e:0:b0:3db:5804:f3b with SMTP id r30-20020a63fc5e000000b003db58040f3bmr10746366pgk.126.1653091444415; Fri, 20 May 2022 17:04:04 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 01/49] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h Date: Fri, 20 May 2022 17:03:12 -0700 Message-Id: <20220521000400.454525-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We have a subdirectory for semihosting; move this file out of exec. Rename to emphasize the contents are a replacement for the functions in linux-user/bsd-user uaccess.c. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- .../{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} | 6 +++--- semihosting/arm-compat-semi.c | 2 +- target/m68k/m68k-semi.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 2 +- target/nios2/nios2-semi.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename include/{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} (95%) diff --git a/include/exec/softmmu-semi.h b/include/semihosting/softmmu-uaccess.h similarity index 95% rename from include/exec/softmmu-semi.h rename to include/semihosting/softmmu-uaccess.h index fbcae88f4b..e69e3c8548 100644 --- a/include/exec/softmmu-semi.h +++ b/include/semihosting/softmmu-uaccess.h @@ -7,8 +7,8 @@ * This code is licensed under the GPL */ -#ifndef SOFTMMU_SEMI_H -#define SOFTMMU_SEMI_H +#ifndef SEMIHOSTING_SOFTMMU_UACCESS_H +#define SEMIHOSTING_SOFTMMU_UACCESS_H #include "cpu.h" @@ -98,4 +98,4 @@ static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, } #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) -#endif +#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7a51fd0737..dbef280b87 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -370,7 +370,7 @@ static GuestFD *get_guestfd(int guestfd) #ifndef CONFIG_USER_ONLY static target_ulong syscall_err; -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37343d47e2..a31db38fc3 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -25,7 +25,7 @@ #include "qemu.h" #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #endif #include "qemu/log.h" diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index b4a383ae90..6d6296e709 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "qemu/log.h" #include "exec/helper-proto.h" -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index ec88474a73..373e6b9436 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -28,7 +28,7 @@ #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif #include "qemu/log.h" From patchwork Sat May 21 00:03:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574778 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2659870mab; Fri, 20 May 2022 17:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLtHUwCuKH8gAt5sxDkSnI7trMNs4xHrOp3MoYEqdDm0CrNyU5iOYKEaetM0gCxVMznoD6 X-Received: by 2002:a05:6214:c42:b0:45a:d3e9:5797 with SMTP id r2-20020a0562140c4200b0045ad3e95797mr9768132qvj.103.1653091665589; Fri, 20 May 2022 17:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091665; cv=none; d=google.com; s=arc-20160816; b=uLrnJsTocnQ98YGPi7201kMFoE5N41gwdqzSC0YxkaEF5GNBT7HpCEKvN5pzo6gBk4 PHaiRiCo7NzHlwuGz28z3xiZz5W+E9PUB7K+wApgTzBwupN8I9CoeVyvcGwxJR0Ff2jZ 4jz1Jy9XvR+KN15hH8Nlr7twEov0sM0viNU14xgjkipcOy9d71jSOlrYb2jEExWT+Z3Q aiak6cdk9ZWTEsVmUZrXZKEbHi9QTtzm8LW76usz8EYPfFz3cfhmLCArdHJ+1yOo8Bky CyM18bGjb4l8OGpRCHMpgj72JyUaK1uWUOu+qIMv9satGzLp6l4M4++j5ZjViLs8P/bq mb9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=Iyfjo4fDsgUmXbnryh3zL1JuGz4rP0UHE28a+YUDAWgf2foXLiWjM4IBfUuh33gDr1 Od67M6PcT9PyjI+uAxKywsDC8VKdMTCN37dcXv6dhwjHXO920ARAeEodVpTQwP23uKCf WHOgVa7mrf3bkrI6lyzgeDRUJcVoemOX560zoFqPxfC/EZoFpiINtR+Nr8BHPe1Z2Apx OeOsOBUvSCseh7sJLdKwf8UarxSIl3W6GlCRkUnGoZ4bdW15Vo1nwdfkaK9YmmSs26zk zEot4tOP1g8JrfjnkY62GxVvjwv4cZQE9EZTzPeNpuGpnnasMwRo+v3m52FkHZ8J5wV4 ZuQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dodTOc6C; 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=pass (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 p15-20020a0cc3cf000000b0044153b237f0si261041qvi.407.2022.05.20.17.07.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:07:45 -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=pass header.i=@linaro.org header.s=google header.b=dodTOc6C; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCen-00084t-2T for patch@linaro.org; Fri, 20 May 2022 20:07:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbK-0007zu-49 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:46640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbG-0003yF-W7 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:09 -0400 Received: by mail-pl1-x636.google.com with SMTP id w3so1941669plp.13 for ; Fri, 20 May 2022 17:04:06 -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=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=dodTOc6Ct/PwUXdaEm/d3h2jhXMGGlOLDOVbSvNWEiz1f2W+4QdaljtFx7ofmM+QJ8 snhZc3hnwSEZ7zqYaTCP74dz/j5TN/DWM8qOLBF/ci44Hn1+L7mXBaIP95vXp8d/iXii kf7x7swwf4f6Ho/9Mt4VGHYMYxVm9gqb8cfrtR7g9/zChcQqmOIpsLfs0FzwO91UZZuB OHw2ELRA9zYd286ILlEEcU96pXPW2mffNhytiSRhrh58bEm1Qgpt2hGvixEL1IsMBgMi Fvl2KNCtgMTDr2HC0uAgvGpjGgnKt+ykRayF7YwomLc2od8ihTQhc2e89LNJNEnbVz9U O5pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=twzs5ZyS4eX5sHhj0rkcJzR8unvlZYbr/zAh0Y+GY2HCs491hz1swq7TGsXXP4QinQ QLlIviS+iSWmN/Q1lsSnVMSjA7Sw1/uM5thD5lSLzoEo43W8JuX/2CTXZSSu4NXPHi1W 4fCRhSATVA+6Pem3ujaCNyNba8Zsy+mn6i/zF9aW8jlLX/NribhmsEEq+7Jvm/P5kpcK B1e+ER+Hl67q+9NTgDmoJt4OuG2ISXlYHLoWRk82V3hG9UJufn/tzWuxe7wVoyHbS4gN ClPGKghy30F4jrhZEU0IkUymspG9oEmewKMjq4sxt+FI1YIrmGYFNcqs2LThFBtjjCHl ByHA== X-Gm-Message-State: AOAM530/9zzp5Zrg9AqNqJJT1cTuWKtXR+au9HcoRnuPKqkQm0zHktYL pV4CMXM/K6Uay2mcmxopbFTd387abFQFYA== X-Received: by 2002:a17:90b:1a8a:b0:1dc:ea29:f6a9 with SMTP id ng10-20020a17090b1a8a00b001dcea29f6a9mr14383883pjb.108.1653091445460; Fri, 20 May 2022 17:04:05 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 02/49] semihosting: Return failure from softmmu-uaccess.h functions Date: Fri, 20 May 2022 17:03:13 -0700 Message-Id: <20220521000400.454525-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We were reporting unconditional success for these functions; pass on any failure from cpu_memory_rw_debug. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 91 ++++++++++++--------------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index e69e3c8548..5246a91570 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -12,82 +12,69 @@ #include "cpu.h" -static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) -{ - uint64_t val; +#define get_user_u64(val, addr) \ + ({ uint64_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap64(val_); ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 0); - return tswap64(val); -} +#define get_user_u32(val, addr) \ + ({ uint32_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap32(val_); ret_; }) -static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr) -{ - uint32_t val; +#define get_user_u8(val, addr) \ + ({ uint8_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = val_; ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 0); - return tswap32(val); -} - -static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr) -{ - uint8_t val; - - cpu_memory_rw_debug(env_cpu(env), addr, &val, 1, 0); - return val; -} - -#define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; }) -#define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; }) -#define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; }) #define get_user_ual(arg, p) get_user_u32(arg, p) -static inline void softmmu_tput64(CPUArchState *env, - target_ulong addr, uint64_t val) -{ - val = tswap64(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1); -} +#define put_user_u64(val, addr) \ + ({ uint64_t val_ = tswap64(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) + +#define put_user_u32(val, addr) \ + ({ uint32_t val_ = tswap32(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) -static inline void softmmu_tput32(CPUArchState *env, - target_ulong addr, uint32_t val) -{ - val = tswap32(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 1); -} -#define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; }) -#define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; }) #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, - target_ulong addr, target_ulong len, int copy) +static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) { - uint8_t *p; - /* TODO: Make this something that isn't fixed size. */ - p = malloc(len); + void *p = malloc(len); if (p && copy) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0); + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } } return p; } #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) + static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - char *p; - char *s; - uint8_t c; /* TODO: Make this something that isn't fixed size. */ - s = p = malloc(1024); + char *s = malloc(1024); + size_t len = 0; + if (!s) { return NULL; } do { - cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0); - addr++; - *(p++) = c; - } while (c); + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); return s; } #define lock_user_string(p) softmmu_lock_user_string(env, p) + static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len) { From patchwork Sat May 21 00:03:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574899 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2661560mab; Fri, 20 May 2022 17:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQZFExCfMTNFzk48DXfRtm4b0VkzeYwYY3WRORrrUz+8TZHcJ4rW/BhxNkS/PteTzoO0gf X-Received: by 2002:ac8:5a53:0:b0:2f3:c6bc:b66d with SMTP id o19-20020ac85a53000000b002f3c6bcb66dmr9622336qta.477.1653091863434; Fri, 20 May 2022 17:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091863; cv=none; d=google.com; s=arc-20160816; b=I0xvEA8I4gYHqQl0Dh4R1130Jk7r3W4efg24aGsUk6RZ4nbNB1OyRtcxGSSnN3kGEJ zLqBZ2oh3PQDplrEDkJZshdd8bIxNOg3gYCDKDqIWwUbWcfFexgKyodBHHsQYV16Akij BK+v44bE/H1Wu87hIfovjIF7vyC52YqCHupOy61FQtmI/iQFcy78el1aYFNrKcgXBVTI v4AEQTDo1hX8i80uyU398WaDVb4HeFF6BCo1MNBU2VBYJAgTPKkDNeCiwtj2zIi1ghth KPkBlzFSMAbx0TM8M0Rx75Gdb190ppvni2B/F1KNsYeow0fevkOG9XMHkUxkMP0r+BWq BhMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=Dg0+8I9LzBozZVczj6+CIQ8Xwn5LGCqlQMcLLx9vxsVgRhgGesks3mu7M1hYAVxjQq dCjA1WGWBGA0KkoOI5Aus418zCf//QpOsik4+tcJcuDwh/EJ0RrjAfo9/H8m/xLhByYw YesWWG18mH8ne58fA3ysRrF9ps1pYVKaysWOUZcAqEEq2PoOH+tdXtXml9q+HQM8JVYN Sg2airl/2fvLN+xORGHh7m03/BH9TxhlgX3IqqYsx0dTOjLMN5oTAkEfAgpGR2EXNpiB rkq3I9ZtNn/xZ+cxXjgyQEmPMdCpVvDLJXdOKih1KKdz2sjhtjM/uaAWRD/4cmhmXDM+ twPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MUNBlr7H; 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=pass (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 s125-20020a37a983000000b006a2e3f2ba53si348624qke.534.2022.05.20.17.11.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:11:03 -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=pass header.i=@linaro.org header.s=google header.b=MUNBlr7H; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsChy-00066j-Up for patch@linaro.org; Fri, 20 May 2022 20:11:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbL-0007zv-9O for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:45846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbJ-0003yJ-OQ for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: by mail-pl1-x633.google.com with SMTP id q18so8553151pln.12 for ; Fri, 20 May 2022 17:04:07 -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=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=MUNBlr7H6MFyk2Ky/KpfGeRE1qKyJQqE6r0ZhBFuhvvGRMV0yfGhUlTINLBLmund0u DSf00Ur2t5KvB5sLJPd7BsWDh6pAYdMYpV+aQN2jX+Vx3huZj3168XIcJaYt0uzjUmUR 9wEFh+Cg0ombwJrBR32npC8+nxMGYnVd5JcshuxACRAKdX++aYpJBKi4C1LjOo/A6jI8 Apai37L/cE96AshiWrRIMMFV5tn15ESaeNUGKeuYNC+0mzWmuLpBixoE8YPdwEVWwfUW bt62cKehddpWWjdWEMkt6EKdi80vboqqNd5wcBn/MIttmW1EdlgyCLCIGprA2zPUVHAO MMNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=CG5F8YY00pS9uPoI/dxojamerdsaHMsI4kVgQSZOgSi1/MjMaUTTgNqoi1xpNAuiMW ENcchxf7leOlZ/oolpl8MZXofd9j8v9/q0g2EiGWry+VIpONJ9tmov3X7lpR4XdKbwJU hGxZigMMrhPBiPn6YM87lmk2Kra2GwGm8RACuf748NgB7OXv6URn7Oux8YUW3rPwPL5X 9WK7uhKAGrTUJTF8/+a8GEANIeyRM3/2GbarR3sz0G156bTnDB2sV+M92W3tKK/DJ+OH N9oBCcJt/heUwuU+JYNH4YqmLUEUd2lJZyf3JDDmBusUTqRy9a4EnGq3fxEsA5jExOSq YfKA== X-Gm-Message-State: AOAM532tVy4M1/J/yr0pldnZNm/020l2/qLzfVzUE1iD3zYicrfkXsBn gvL8Ci3RYMuNsddycLbYzrDhEBeZNtQjuA== X-Received: by 2002:a17:90b:3a85:b0:1df:f22e:cd9 with SMTP id om5-20020a17090b3a8500b001dff22e0cd9mr7530803pjb.206.1653091446561; Fri, 20 May 2022 17:04:06 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 03/49] semihosting: Improve condition for config.c and console.c Date: Fri, 20 May 2022 17:03:14 -0700 Message-Id: <20220521000400.454525-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While CONFIG_SEMIHOSTING is currently only set for softmmu, this will not continue to be true. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/meson.build b/semihosting/meson.build index ea8090abe3..4344e43fb9 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,4 +1,4 @@ -specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( +specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', )) From patchwork Sat May 21 00:03:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574901 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2661596mab; Fri, 20 May 2022 17:11:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5FkwCbRrKzj2G4jzrIpGS9CHeFTD/g/k3Fw6zzJ8VsxfS/y0N3Q4QHIkwNrxlOjcv30uU X-Received: by 2002:ac8:5b56:0:b0:2f3:eb25:910e with SMTP id n22-20020ac85b56000000b002f3eb25910emr9350026qtw.616.1653091866216; Fri, 20 May 2022 17:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091866; cv=none; d=google.com; s=arc-20160816; b=ShQvu1S9RgDyWTj64iOxj84HRK05bNoBr07UOw2RDe5HR7lmhUasp44w5YOZlKc+CM b6Y9y8PVYeUzx/eLTve1LKZCao4roXKWmO54j7+cD+Qnt8QH+06MweyadTJt72jXyfeQ Vq8nI6fmFdui5pU0TXoQX0FwZem7ujT5DFO+W1w4KsE6BBP+6Sjx1Rh5lxAPX6QIZpST D7pPqn1aXtMfBmzxVzGTtasBGKAMSZ/FrNkmK6WvNbrKbnKNK1WxxnRfs8zMEFvjhVR3 3fnAgv0XkJd9KPjW5Q8jEh/jw1FC2ArlXMyb7yg7KHhF1XrRD4A0gVue7G5Hz4PEUU15 to9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=hLfiv7aKi07cDCWOO+Spd+grIbAda+N2fBoSISXZ2ArCjkl8roKZtU+MiSGzBLZu3c a13BynuHqYCmewNJLzZKyLZXDnukHeGE25X8HDdUMLEBzj93TOyQMuJG+xBsD7EUBTtb yzIom41RtZQgP/f5vYRYwRLofXL5IqunpuxlxYu0o50qdlDNpNLetHFnqZCg//JsY/lW VniCGHkm0XLukVib5aniHwZyrAVTqRumrlZYKRCU3LF9rv0E3LtqmrbmZvSWcvbOAByc ZsAFJAZiZanAV1q1OD9SVMPSA7TKEp/9syEOBe9nv9v95Bx68s10fg//CSIAfI4qkUU0 xTAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="skWA/feg"; 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=pass (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 c1-20020a05622a024100b002f3e14f872fsi360514qtx.357.2022.05.20.17.11.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:11:06 -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=pass header.i=@linaro.org header.s=google header.b="skWA/feg"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCi1-00069I-QJ for patch@linaro.org; Fri, 20 May 2022 20:11:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbL-0007zz-F7 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbJ-0003yQ-R7 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:11 -0400 Received: by mail-pl1-x630.google.com with SMTP id c2so8576739plh.2 for ; Fri, 20 May 2022 17:04:08 -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=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=skWA/feguyRr+bfxNc8QFtwOqU9g9w8Qn2gJr9WI+VKNcp+sjposldyXF0bGLUsq9p l6CYWKlYa/G8xRbyCbJIiGaZfkiBeyELgd7PP3zVxLUyk4ZOC1pRBdLdxyHVWCG73HT4 B4LUEMEShoaKkNrO2woQ31alCjmbM4jxdJKldr4FYFRftscRuUjJPC+8JqJuaMFrWuJO K5eR2U3Dm2taGYYz/r4HOQ68TEzIggXk61Fg+x0DXMoVhybKBNJL0+vJL3Lb3NAhQ1et U3YGj0g7h6WvYXkcR0gY2iu+JNL3+gfzg8x1mAuQ0NZfEdq/1Ek7IrBt0JjUBASPxlit ocfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=GMCA4JD9dLA/2SbM5+yRJfzQvMqm3dVmaCDVj++EljnVFfxqAV+t1bbp1zcvW20qf/ vjI6ncIy3d3Ku9ggkn7gsnbwG3s+jVwr/5G8ZHzQTFCNZv3h9gcRPhsbHTQVzaJale2I ay9tvtBtLzIAMMyh4ChdA2SkNUunJrh+vlnnqZH2Nt3UapCN9HG6+JHt+ZVyZIb8OBNB bjLIGmqqOWmlvHp8vaIyMEeTK937JEEBJfq66YQadj+Qoou6IBp2QVOUPrdDOAovw7uM KPF9tNy5rVK5GcqjZxlNu01oqCD91BF2aEhpTCjF7/5UlWPwKbQ7vS3vVtwEgD+MQLID oVRg== X-Gm-Message-State: AOAM530DEIH09V5r7WWDZxqwYZHEw7guhYla9/xy5VOYJ10/13CuzCha ZlDzrT1QLhkwtsNB2PIpA1yaZU0CIJYDXg== X-Received: by 2002:a17:903:44e:b0:161:58c6:77e5 with SMTP id iw14-20020a170903044e00b0016158c677e5mr12283860plb.81.1653091447806; Fri, 20 May 2022 17:04:07 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 04/49] semihosting: Move softmmu-uaccess.h functions out of line Date: Fri, 20 May 2022 17:03:15 -0700 Message-Id: <20220521000400.454525-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather that static (and not even inline) functions within a header, move the functions to semihosting/uaccess.c. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 42 +++------------------- semihosting/uaccess.c | 51 +++++++++++++++++++++++++++ semihosting/meson.build | 1 + 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 semihosting/uaccess.c diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 5246a91570..03300376d3 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -42,47 +42,15 @@ #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, - target_ulong len, bool copy) -{ - void *p = malloc(len); - if (p && copy) { - if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); - p = NULL; - } - } - return p; -} +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy); #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) -static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) -{ - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { - return NULL; - } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; -} +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr); #define lock_user_string(p) softmmu_lock_user_string(env, p) -static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, - target_ulong len) -{ - if (len) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); - } - free(p); -} +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c new file mode 100644 index 0000000000..0d3b32b75d --- /dev/null +++ b/semihosting/uaccess.c @@ -0,0 +1,51 @@ +/* + * Helper routines to provide target memory access for semihosting + * syscalls in system emulation mode. + * + * Copyright (c) 2007 CodeSourcery. + * + * This code is licensed under the GPL + */ + +#include "qemu/osdep.h" +#include "semihosting/softmmu-uaccess.h" + +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) +{ + void *p = malloc(len); + if (p && copy) { + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } + } + return p; +} + +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) +{ + /* TODO: Make this something that isn't fixed size. */ + char *s = malloc(1024); + size_t len = 0; + + if (!s) { + return NULL; + } + do { + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); + return s; +} + +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len) +{ + if (len) { + cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); + } + free(p); +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 4344e43fb9..10b3b99921 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,6 +1,7 @@ specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', + 'uaccess.c', )) specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], From patchwork Sat May 21 00:03:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574779 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2659882mab; Fri, 20 May 2022 17:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynfE6ddquwtCbc8wQjQKAMhu/4oztFh1skKNHKxuDW3DBGb9iICo/k/8UaJvkNgqbc/LuL X-Received: by 2002:a05:620a:4506:b0:6a0:8003:99d0 with SMTP id t6-20020a05620a450600b006a0800399d0mr8064228qkp.728.1653091667260; Fri, 20 May 2022 17:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091667; cv=none; d=google.com; s=arc-20160816; b=mUCqPmosjNkJEoo6MDAvUTyg4CB3fttH96pY8gnhMq9pgKXXkzK3JNDM5SH7IEpvHs //trMFfH28Zz7dKB0CBn6GjgHknVnOyz3MpexBUeoCb9xSPc+h8NBbAkF19X5bZLWuFg Om4aB4GwtuciGPq1Kn3KI34REV2WO0HIP0lqS1jkJoKUbIZuJloDLMUJzXR4FmVy4rrE cR30vTb0aImSesmpTzqVdddTxL4Q2i2Gp54LhMdAZXP+03guPlgLTCOEHWy2j2z9X21O lZCa74UhBVzlOPffJ/ocl8n0MFMdZljnhQwhc6Jv59m0HtdiBGK7P3SrdTcln9PGACx3 pPLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=ppe/I69FO69c8GFMtkmxfZRVYY/jB7FHKg3SsW0ItTMeBAmRNKKgxIgO6XgL1ZmA+w 3uXHkGVA8QVwt4V/OXydZVKp8Q99yr0F8zLvu9Y29VJwzQ2veirqIc5M/y94q6Bwezl0 gm93ViopbKzqYM+cwXVtP2Wjc+9L2P9VEbVozAj8Bp6x9yN/uCoE7LQ14pXH2pc7r2Ha xvsMybZj6ZZXalYyMXz3wPc+EWUG0SVNydN1Dx6bl1xf7vAz1e43Z3fMkX1YMqlq4yfu BuIB8IEqQ/CmZoVqqj9VvgzZ6woEVxdx/J2zoBinmoVM2zxGCpKNm9dy8bIT/f2XSy4S /GMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vl7I20wH; 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=pass (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 h7-20020a0562140da700b0045667133e6bsi410825qvh.400.2022.05.20.17.07.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:07:47 -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=pass header.i=@linaro.org header.s=google header.b=Vl7I20wH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCeo-00084z-SL for patch@linaro.org; Fri, 20 May 2022 20:07:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbN-00080X-Mq for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:14 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:44659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbK-0003yV-9P for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:12 -0400 Received: by mail-pl1-x633.google.com with SMTP id q4so8553498plr.11 for ; Fri, 20 May 2022 17:04:09 -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=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=Vl7I20wHocej6ezd+GOhft8MprLJBf9xVnw8ipS9GDYNOuoT+MHgc+N247SsfEqbxP Q1ZIkyYZUJt6DPPjlz+rEWUJwNgF9FNgp7kKe4eFJ4RV41T1/Uz8wqttXA6LQw5GiHvY j7c6k+KtcDnUtS8KEDVPoZAXrXciR05F7mWaOio3VLIG+ccDLieB5TJyXhamRXlnReYc JDAHpdBhe64aJVLX4GO4l0m5toGLm7r+upvS0rkneXJssuOndMhjoQf+t/FjoMfSVm23 rjDQRWMZArEmzoRkdXWFf5kUQmWJ8zV/kFKaxqyDX72JKY2s+Dr7S2Mwt0TQNkBU75AC lMPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=opOrmB3m6WrWP+N+G18m3BHfYhbbleNxv42Hk7ZsqUN4Pk7LC8bQ+pZqv6rfRAqHgZ 2h7leq8EIjCKvpQGL3IKgq8PNIIf7Xh+A987mVa1DbYvgRthaWcert8M+qFVdpYwAXZd uRI/Zp/WZu2gx5I4qtHcY+2oXnD+iTaGBt6V8KiB6vLk/v45apR6SDRGd1JYZEAzHL3v lqBNFLzfzvP7LFPrQ9QR/sUKoBAzjANacWUhXB2sUZx8jW6Mk89zpqJzg/Nne/DbB6bO EmGYlbwQd2aJpi0lWm5ho4NBnRFRepbZUtg0gccC2Pr0F/6zLs4My6E8kgM88L9T2Pu7 aBpQ== X-Gm-Message-State: AOAM532Cv/stYndlvSK4Y9/ygDXT9cAFzmtDhGPdwYCwgq5lNZD81ErK mpKhJIigoszE4Q2574gHBkhHaQmB19Jhkg== X-Received: by 2002:a17:902:a387:b0:15e:f63f:237f with SMTP id x7-20020a170902a38700b0015ef63f237fmr12010647pla.32.1653091448990; Fri, 20 May 2022 17:04:08 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 05/49] semihosting: Add target_strlen for softmmu-uaccess.h Date: Fri, 20 May 2022 17:03:16 -0700 Message-Id: <20220521000400.454525-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Mirror the interface of the user-only function of the same name. Use probe_access_flags for the common case of ram, and cpu_memory_rw_debug for the uncommon case of mmio. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v3: Use probe_access_flags (pmm) --- include/semihosting/softmmu-uaccess.h | 3 ++ semihosting/uaccess.c | 49 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 03300376d3..4f08dfc098 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -53,4 +53,7 @@ void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr); +#define target_strlen(p) softmmu_strlen_user(env, p) + #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 0d3b32b75d..51019b79ff 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -8,6 +8,7 @@ */ #include "qemu/osdep.h" +#include "exec/exec-all.h" #include "semihosting/softmmu-uaccess.h" void *softmmu_lock_user(CPUArchState *env, target_ulong addr, @@ -23,6 +24,54 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + int mmu_idx = cpu_mmu_index(env, false); + size_t len = 0; + + while (1) { + size_t left_in_page; + int flags; + void *h; + + /* Find the number of bytes remaining in the page. */ + left_in_page = -(addr | TARGET_PAGE_MASK); + + flags = probe_access_flags(env, addr, MMU_DATA_LOAD, + mmu_idx, true, &h, 0); + if (flags & TLB_INVALID_MASK) { + return -1; + } + if (flags & TLB_MMIO) { + do { + uint8_t c; + if (cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0)) { + return -1; + } + if (c == 0) { + return len; + } + addr++; + len++; + if (len > INT32_MAX) { + return -1; + } + } while (--left_in_page != 0); + } else { + char *p = memchr(h, 0, left_in_page); + if (p) { + len += p - (char *)h; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + addr += left_in_page; + len += left_in_page; + if (len > INT32_MAX) { + return -1; + } + } + } +} + char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { /* TODO: Make this something that isn't fixed size. */ From patchwork Sat May 21 00:03:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574905 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2662706mab; Fri, 20 May 2022 17:13:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjnVnNC7d1wNQDEdaBYSRyNzPWiWMS9mXu4VgflnePTsmgxrBXSCsOTPlVWuOkXCPtSSJp X-Received: by 2002:a05:622a:155:b0:2f9:11a1:85c7 with SMTP id v21-20020a05622a015500b002f911a185c7mr7660706qtw.543.1653091987687; Fri, 20 May 2022 17:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091987; cv=none; d=google.com; s=arc-20160816; b=X0/7H5ssX0IQReD9uAEThIzX0lvqkENIHPCuyBl39TEdxW5NHjlpDa8j6NraPggv9K SgjafCuxSQCNgpKvOsV5RuLoaicV8jGDUSK50A/TVs6FrT32Wzd4kmXy2lfIdyCnLLqi OQWN1pmRNbIWD0/x9l3Y1V+1DYgSGlbMGypNQEF1y9T3QPVliywIC6uax89LhA6JEDLa p/Wnp4cObONgb/CRl4HJL6iChUrIauM0N3MR8DNXn8ZuVmfoiJO0NsJUftDUktyspaFj ji6ntjD5k+3Gn7YMUltGEorcJ/vPdNxcH8mQdAFTheXq7PnVunnuvpenBpNXh519+C0l xWng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2UWwm+1enZhNATgFL33PYQ1DN6Mmw/PBhL6/pzVSSaU=; b=j8TzL394QUgRCQLFWfWP92UlSEnPWhCpZA62U+Z52VvH56yEKg36wd9Cnexo2+S7gd MeO5MgJA0pEcnxFoPu8vZhk8NPLz3OLKnluz//RgjSK4oNeAyZRYwU2OKKk++L5+o06D xsd00Ml/pJ5zoGw/O5jA9rx5ujlOZRW9KVhhNwVlQw5BvEknbEI1uNrVJ9hlHMz/xbcb oHt+BYhlqj/BezEzfFchHV51PyTbQxGmp7wGO5oIOVqn/QiyChqcTuzLcxn9wWCgoN5B J4XdLxRajJJyIlECJ9+VaF2Sq2x6O/UvcRkO4Xcsx3IkEmTS75MYT6wyIFWIJqu6XoPG 9ckw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fgu3qTbk; 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=pass (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 d17-20020a05622a15d100b002f3b7c023afsi368659qty.522.2022.05.20.17.13.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:13:07 -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=pass header.i=@linaro.org header.s=google header.b=Fgu3qTbk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCjz-0003WF-7b for patch@linaro.org; Fri, 20 May 2022 20:13:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbN-00080Y-Nn for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:14 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:45837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbL-0003ym-RE for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:13 -0400 Received: by mail-pl1-x629.google.com with SMTP id q18so8553221pln.12 for ; Fri, 20 May 2022 17:04:11 -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=2UWwm+1enZhNATgFL33PYQ1DN6Mmw/PBhL6/pzVSSaU=; b=Fgu3qTbk2lWuWYI4rssD4eziEK2qZP5OTJdBnQUacie1mPi8z38I0R1i9IyaLtMOMR F3r89ZKIOS1U4+4w1KO5oHRQZY8kqucoOrsyc1bQwIKq+BuLpD2qUsHO4bYUUb+ZgOH/ 3r2Rv9PuBKE+xUuK8ab7zShR3mp95Wtbc6TuVxxYw4/cXBvg9O4QwPlZ7WG253F8fLrr 71zxZbCzc2ISiq64fz1Ns5KDlgNBrTN/7dhNZ4AD6jLRIS1L+TiAQbeLaekisoHiTjYJ Hyd2SI6EfJYwwAknBGEFxC12ZzVzZMevbbTI7yUCYfb5BRbhNI8xRKzV8UX0sCGfoOuL g3Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2UWwm+1enZhNATgFL33PYQ1DN6Mmw/PBhL6/pzVSSaU=; b=qY2D2pGiVrM09PGUyHotHg7axNPwWYe/rV+IS/JNBBWWYz0FCYnWNJ5z677bIOolpK /IhsZGnTC0yUkVwWl65F5lzYy3UfD1LpBPSmA6dSUgonOc985uoWAWO2FFsjJ1YohI39 caWP3gxHej6jrsAR+uPgsdk/kLN6gCZuj2xjKoBmArHtXssKe9WHH82hPCL589PeFZkf 5en9OEHvV1IN42pQ3yD7x+gzBBZKU7xZqV/0LcvjG9S90rDGJbal7JEkolafq++Pvizv TJzhvqtpPqtuATvqjuM6ptmBvPayHnEDa0L1x7fyCtYlrv9XHHuRw9/ERGacyOJeS/uJ chWg== X-Gm-Message-State: AOAM533hLiZGf8/BytP8w2UO0HWo7zTmfdNYr6myXjHwWkUpEPRALVW6 7PfkX5qdjZOwdkGvj9p3d8W/9kgUKQrPiw== X-Received: by 2002:a17:902:700b:b0:15f:a51a:cdeb with SMTP id y11-20020a170902700b00b0015fa51acdebmr11680558plk.137.1653091450309; Fri, 20 May 2022 17:04:10 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 06/49] semihosting: Simplify softmmu_lock_user_string Date: Fri, 20 May 2022 17:03:17 -0700 Message-Id: <20220521000400.454525-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We are not currently bounding the search to the 1024 bytes that we allocated, possibly overrunning the buffer. Use softmmu_strlen_user to find the length and allocate the correct size from the beginning. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/uaccess.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 51019b79ff..9894f40feb 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -74,20 +74,11 @@ ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { + ssize_t len = softmmu_strlen_user(env, addr); + if (len < 0) { return NULL; } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; + return softmmu_lock_user(env, addr, len + 1, true); } void softmmu_unlock_user(CPUArchState *env, void *p, From patchwork Sat May 21 00:03:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574904 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2662690mab; Fri, 20 May 2022 17:13:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjZYu0KtvcWpFCdeJeuZV+21YHpHmcq77y2rJ6IyTLkr5Ea7P8u/EfAeZPXzECjdgRDwSE X-Received: by 2002:ad4:5bc4:0:b0:45b:13a:f3ef with SMTP id t4-20020ad45bc4000000b0045b013af3efmr10122610qvt.10.1653091986233; Fri, 20 May 2022 17:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091986; cv=none; d=google.com; s=arc-20160816; b=Kgp3sc3C3xadrggmPVh3vhJT2KReHdru2jMTRRz9XArgxPa5G0SB5QbwXVr5Ro1kqk TioRdA1R7T28yrbLpJ9gJp6898MLVEPilMjOz/W8mox9cZZx3RmErwhu3LHb+Lw3KbgX UtXKbwg6UWi5id7S5/IcY2Jqbusv7lYJWBCWvOfiqudwJU18pCn4twG5eabOmWiU0AaP 7FICo2+2bsHOasiQRCV7i5eV29hqGuL+E7wCVDlrEa69+5ZEgL9+h49Qh/n3OlsaWtfH NeB2VLSm5cm9sBnhEVHoU82tPrlsNZBdP9rQmZ7HTCark6rPLUH0dFQMMu++j41KPWhM OdiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=99JGUMI2r4BW2Q/ohOps3LgiQ8LQqv9048VXv1Twk64=; b=cist5FTd/ipHT64aXYtGp/03ramuuy87MeGUDwbmADrWXttXbEsxIEqqaKqTm544ky cBLmglu5WyxNGB5oyfgORL12ehzNUax83x4M0164m4jQ8lte1Q4uz5PaWAoW3Jl3J4ME OgTVuV8A/Us2vnCxOw55OR9fwqdqLveMmYtmARXjSPnf5OG8Rj/2dpezP3uf7VxdXVmg S4MouvkUT6+sj38VoeH9XCacZR2upOQr0hI8/AXCogZbv9ujwCZkHxhSul8pJOa00qQP jGQwwZGyjEKOIXm2xWOxkLjDL+peh0wn9uKeiFzo/pOK8o4/5+MSvRw+1EXTui/X88FZ u+pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=if+YmgMt; 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=pass (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 w20-20020a05620a445400b0069eeb761da6si455861qkp.156.2022.05.20.17.13.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:13:06 -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=pass header.i=@linaro.org header.s=google header.b=if+YmgMt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCjx-0003Sd-QV for patch@linaro.org; Fri, 20 May 2022 20:13:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbQ-00082F-Sq for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:25 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:46592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbN-0003z2-FW for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:15 -0400 Received: by mail-pg1-x529.google.com with SMTP id j21so8768982pga.13 for ; Fri, 20 May 2022 17:04:12 -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=99JGUMI2r4BW2Q/ohOps3LgiQ8LQqv9048VXv1Twk64=; b=if+YmgMtd5OzlT2K3j63k1lu5BD5UN68C9ie1ryPXedHui7jfVACMUJg+Ao+5AWlo2 B1nMMcAVUiZXl2AyW/XclH8N+aosn2oBrjD24QXx8GMBIh/5BUwlASQqMDvTZWwQuhNv rRzKWORf1F26b8185Oji+/4/wX8FlJNmHKmK8GV56M0oAhQMFPLnPitSNvE7SgE0FnjY DYsR+o+nIMFUiWvBSSLoz3yX76zVF/IoKuszwvMMQ4BTvmrZ4BxkBEp3pdH48Z6s0iQB VSKZuGlsidQaWsEg4R02eXNw++KZEmdFyw9h+jItu9jhsqEbCA6lzz8yCdYgyV/abbcE n+oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=99JGUMI2r4BW2Q/ohOps3LgiQ8LQqv9048VXv1Twk64=; b=NL3XWMSZDgDyg8O4HXZAGVVWEUo1S3y54APxv2XIrRjsyAVZUd4GKfS1urNb6GWS9x Jrv1lUasevXRX1vMvCCRzft+5d4LQtbYCE32D+l+xSvjyrUhU05UCFLzktB/RSPHVeQv iltn/V22VHbK4g1OU/Tec+It8bNJhUDpvovvK3T9kCbGkJwM8pgIkAYE8rphXDmWcgBM FAMDBFeExC23bMtIuKCJBMLPhgAq/Q+0yVYAsBFVj9N5DjoOnUdIBmgJy28pyFISlfWw oo3PYFUdrm1i8/D05AFV0uvHJ+4v/fU7WHuVySPV9qsxnpbvQYhWWsLi0UyKb767Fihc hVJg== X-Gm-Message-State: AOAM532STpCDfsj8gUQVgFwUkP0FJZUsiHUNZNTnPgck4gLgYvTS2lm+ lZrBMuUUbhsacw+ZtXXiGQF3z/ftzg3N0A== X-Received: by 2002:a63:7450:0:b0:3c6:234f:e70a with SMTP id e16-20020a637450000000b003c6234fe70amr10687296pgn.619.1653091451582; Fri, 20 May 2022 17:04:11 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 07/49] semihosting: Split out guestfd.c Date: Fri, 20 May 2022 17:03:18 -0700 Message-Id: <20220521000400.454525-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In arm-compat-semi.c, we have more advanced treatment of guest file descriptors than we do in other implementations. Split out GuestFD and related functions to a new file so that they can be shared. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- configs/targets/aarch64-linux-user.mak | 1 + configs/targets/aarch64_be-linux-user.mak | 1 + configs/targets/arm-linux-user.mak | 1 + configs/targets/armeb-linux-user.mak | 1 + configs/targets/riscv32-linux-user.mak | 1 + configs/targets/riscv64-linux-user.mak | 1 + include/semihosting/guestfd.h | 83 +++++++++++ semihosting/arm-compat-semi.c | 164 +++------------------- semihosting/guestfd.c | 118 ++++++++++++++++ semihosting/meson.build | 4 + 10 files changed, 233 insertions(+), 142 deletions(-) create mode 100644 include/semihosting/guestfd.h create mode 100644 semihosting/guestfd.c diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch64-linux-user.mak index d0c603c54e..db552f1839 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aarch64_be-linux-user.mak index 7794424745..dc78044fb1 100644 --- a/configs/targets/aarch64_be-linux-user.mak +++ b/configs/targets/aarch64_be-linux-user.mak @@ -3,4 +3,5 @@ TARGET_BASE_ARCH=arm TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/arm-linux-user.mak b/configs/targets/arm-linux-user.mak index 3e10d6b15d..7f5d65794c 100644 --- a/configs/targets/arm-linux-user.mak +++ b/configs/targets/arm-linux-user.mak @@ -3,4 +3,5 @@ TARGET_SYSTBL_ABI=common,oabi TARGET_SYSTBL=syscall.tbl TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/armeb-linux-user.mak b/configs/targets/armeb-linux-user.mak index a249cc2e29..943d0d87bf 100644 --- a/configs/targets/armeb-linux-user.mak +++ b/configs/targets/armeb-linux-user.mak @@ -4,4 +4,5 @@ TARGET_SYSTBL=syscall.tbl TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv32-linux-user.mak b/configs/targets/riscv32-linux-user.mak index bd2f1fd497..9761618e67 100644 --- a/configs/targets/riscv32-linux-user.mak +++ b/configs/targets/riscv32-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv32 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv64-linux-user.mak b/configs/targets/riscv64-linux-user.mak index 4aca7662ce..cfd1fd382f 100644 --- a/configs/targets/riscv64-linux-user.mak +++ b/configs/targets/riscv64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv64 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h new file mode 100644 index 0000000000..ef268abe85 --- /dev/null +++ b/include/semihosting/guestfd.h @@ -0,0 +1,83 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_GUESTFD_H +#define SEMIHOSTING_GUESTFD_H + +typedef enum GuestFDType { + GuestFDUnused = 0, + GuestFDHost = 1, + GuestFDGDB = 2, + GuestFDStatic = 3, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + union { + int hostfd; + struct { + const uint8_t *data; + size_t len; + size_t off; + } staticfile; + }; +} GuestFD; + +/** + * alloc_guestfd: + * + * Allocate an unused GuestFD index. The associated guestfd index + * will still be GuestFDUnused until it is initialized. + */ +int alloc_guestfd(void); + +/** + * dealloc_guestfd: + * @guestfd: GuestFD index + * + * Deallocate a GuestFD index. The associated GuestFD structure + * will be recycled for a subsequent allocation. + */ +void dealloc_guestfd(int guestfd); + +/** + * get_guestfd: + * @guestfd: GuestFD index + * + * Return the GuestFD structure associated with an initialized @guestfd, + * or NULL if it has not been allocated, or hasn't been initialized. + */ +GuestFD *get_guestfd(int guestfd); + +/** + * associate_guestfd: + * @guestfd: GuestFD index + * @hostfd: host file descriptor + * + * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd. + */ +void associate_guestfd(int guestfd, int hostfd); + +/** + * staticfile_guestfd: + * @guestfd: GuestFD index + * @data: data to be read + * @len: length of @data + * + * Initialize the GuestFD for @guestfd to GuestFDStatic. + * The @len bytes at @data will be returned to the guest on reads. + */ +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len); + +#endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index dbef280b87..c6bfd4d1ba 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -32,12 +32,13 @@ */ #include "qemu/osdep.h" - #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" +#include "semihosting/guestfd.h" #include "qemu/timer.h" #include "exec/gdbstub.h" + #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -123,27 +124,6 @@ static int open_modeflags[12] = { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; -typedef enum GuestFDType { - GuestFDUnused = 0, - GuestFDHost = 1, - GuestFDGDB = 2, - GuestFDFeatureFile = 3, -} GuestFDType; - -/* - * Guest file descriptors are integer indexes into an array of - * these structures (we will dynamically resize as necessary). - */ -typedef struct GuestFD { - GuestFDType type; - union { - int hostfd; - target_ulong featurefile_offset; - }; -} GuestFD; - -static GArray *guestfd_array; - #ifndef CONFIG_USER_ONLY /** @@ -268,98 +248,6 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) #endif -/* - * Allocate a new guest file descriptor and return it; if we - * couldn't allocate a new fd then return -1. - * This is a fairly simplistic implementation because we don't - * expect that most semihosting guest programs will make very - * heavy use of opening and closing fds. - */ -static int alloc_guestfd(void) -{ - guint i; - - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ - for (i = 1; i < guestfd_array->len; i++) { - GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); - - if (gf->type == GuestFDUnused) { - return i; - } - } - - /* All elements already in use: expand the array */ - g_array_set_size(guestfd_array, i + 1); - return i; -} - -/* - * Look up the guestfd in the data structure; return NULL - * for out of bounds, but don't check whether the slot is unused. - * This is used internally by the other guestfd functions. - */ -static GuestFD *do_get_guestfd(int guestfd) -{ - if (!guestfd_array) { - return NULL; - } - - if (guestfd <= 0 || guestfd >= guestfd_array->len) { - return NULL; - } - - return &g_array_index(guestfd_array, GuestFD, guestfd); -} - -/* - * Associate the specified guest fd (which must have been - * allocated via alloc_fd() and not previously used) with - * the specified host/gdb fd. - */ -static void associate_guestfd(int guestfd, int hostfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; - gf->hostfd = hostfd; -} - -/* - * Deallocate the specified guest file descriptor. This doesn't - * close the host fd, it merely undoes the work of alloc_fd(). - */ -static void dealloc_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = GuestFDUnused; -} - -/* - * Given a guest file descriptor, get the associated struct. - * If the fd is not valid, return NULL. This is the function - * used by the various semihosting calls to validate a handle - * from the guest. - * Note: calling alloc_guestfd() or dealloc_guestfd() will - * invalidate any GuestFD* obtained by calling this function. - */ -static GuestFD *get_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - if (!gf || gf->type == GuestFDUnused) { - return NULL; - } - return gf; -} - /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -665,22 +553,13 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void init_featurefile_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = GuestFDFeatureFile; - gf->featurefile_offset = 0; -} - -static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } -static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ @@ -689,7 +568,7 @@ static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, return set_swi_errno(cs, -1); } -static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; @@ -703,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, } for (i = 0; i < len; i++) { - if (gf->featurefile_offset >= sizeof(featurefile_data)) { + if (gf->staticfile.off >= gf->staticfile.len) { break; } - s[i] = featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } unlock_user(s, buf, len); @@ -716,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, return len - i; } -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset = offset; + gf->staticfile.off = offset; return 0; } -static uint32_t featurefile_flenfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return sizeof(featurefile_data); + return gf->staticfile.len; } typedef struct GuestFDFunctions { @@ -759,13 +638,13 @@ static const GuestFDFunctions guestfd_fns[] = { .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, - [GuestFDFeatureFile] = { - .closefn = featurefile_closefn, - .writefn = featurefile_writefn, - .readfn = featurefile_readfn, - .isattyfn = featurefile_isattyfn, - .seekfn = featurefile_seekfn, - .flenfn = featurefile_flenfn, + [GuestFDStatic] = { + .closefn = staticfile_closefn, + .writefn = staticfile_writefn, + .readfn = staticfile_readfn, + .isattyfn = staticfile_isattyfn, + .seekfn = staticfile_seekfn, + .flenfn = staticfile_flenfn, }, }; @@ -886,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno = EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c new file mode 100644 index 0000000000..b6405f5663 --- /dev/null +++ b/semihosting/guestfd.c @@ -0,0 +1,118 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" + +static GArray *guestfd_array; + +/* + * Allocate a new guest file descriptor and return it; if we + * couldn't allocate a new fd then return -1. + * This is a fairly simplistic implementation because we don't + * expect that most semihosting guest programs will make very + * heavy use of opening and closing fds. + */ +int alloc_guestfd(void) +{ + guint i; + + if (!guestfd_array) { + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ + for (i = 1; i < guestfd_array->len; i++) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type == GuestFDUnused) { + return i; + } + } + + /* All elements already in use: expand the array */ + g_array_set_size(guestfd_array, i + 1); + return i; +} + +/* + * Look up the guestfd in the data structure; return NULL + * for out of bounds, but don't check whether the slot is unused. + * This is used internally by the other guestfd functions. + */ +static GuestFD *do_get_guestfd(int guestfd) +{ + if (!guestfd_array) { + return NULL; + } + + if (guestfd <= 0 || guestfd >= guestfd_array->len) { + return NULL; + } + + return &g_array_index(guestfd_array, GuestFD, guestfd); +} + +/* + * Given a guest file descriptor, get the associated struct. + * If the fd is not valid, return NULL. This is the function + * used by the various semihosting calls to validate a handle + * from the guest. + * Note: calling alloc_guestfd() or dealloc_guestfd() will + * invalidate any GuestFD* obtained by calling this function. + */ +GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + if (!gf || gf->type == GuestFDUnused) { + return NULL; + } + return gf; +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host/gdb fd. + */ +void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; + gf->hostfd = hostfd; +} + +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDStatic; + gf->staticfile.data = data; + gf->staticfile.len = len; + gf->staticfile.off = 0; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +void dealloc_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDUnused; +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 10b3b99921..d2c1c37bfd 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,3 +1,7 @@ +specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'guestfd.c', +)) + specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', From patchwork Sat May 21 00:03:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574903 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2662647mab; Fri, 20 May 2022 17:13:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrTJfpaenyXCdo9jnAEZCIuxvOgMq6paTiUBpNJ3sccUe1gXJQkoT+7T+xGXzHobcJUv2u X-Received: by 2002:a05:620a:2a08:b0:6a3:2c43:f526 with SMTP id o8-20020a05620a2a0800b006a32c43f526mr7789079qkp.414.1653091982874; Fri, 20 May 2022 17:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091982; cv=none; d=google.com; s=arc-20160816; b=S9psjI1Y1D+e56pUwM0V+6W//h2P/znBohH1hTHGl7Sl55zeekaY9NdyBYBY409znr CHVORbCdFNXUgNrv0ZKgGtj6g0zpLcycaJHNaL+8AGpUmOyKw8df2Cq88UTkv9WbudPH zs35649g0sYt+GZKcbUvDksgN4KPusdUHsKxirkMYOsVb8680EULz3nXH738KQZEdKfC uXbOycMpoxK88fQCvMep9Yp8wH4pUH6jyR1uO6jVqsLtWyIWeBgW5p8t6cmKamkRovMn hin3hmdcQWPESXY114NRmUX5p+MGgBGujsAzz4Xg0DnUyrvg01NtGGM5VCDCiEkPOFPF M65Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LqMX+PYoPOvCfsrBf9LDk+x8oxX5ugoY/7ce6aNzp7o=; b=kbkbOMRP3peGRsDTbvcq/1mJ6i2fbXDzaUgJ+OJ+gn6Lo3rPLrVsGkCcJsqZRbd8hk yOo2YNv4hfpfbydEcSMVpbxCe0HY6AYXjf0MN0ufBYjSIbM72Z44boCLoN+XgaMneL8J CsIuJAG5G7vu7asi3qc0a9RiGETfUucBSYMUUpQmVd/4SDcxuVG3aTi2jFBYH8+/g22v S4OE2ZxG6GI6MF9qVebirprfxlAg9GYKk9CmbujKXoKCCjGruIauyCiVoqVauP/wQJ7T GfwxFqghlshvBVZsj/HLc3uKnYT7yVxlMerX2qGZFjwMJnWtv0E2HIEKjafR8vdJ72HA R/Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i9+1U34T; 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=pass (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 g14-20020ac8580e000000b002f3c52360efsi403934qtg.80.2022.05.20.17.13.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:13:02 -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=pass header.i=@linaro.org header.s=google header.b=i9+1U34T; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCju-0003RE-ED for patch@linaro.org; Fri, 20 May 2022 20:13:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbP-00080t-TE for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:23 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:43873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbO-0003z7-4F for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:15 -0400 Received: by mail-pg1-x52b.google.com with SMTP id q76so8965608pgq.10 for ; Fri, 20 May 2022 17:04: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=LqMX+PYoPOvCfsrBf9LDk+x8oxX5ugoY/7ce6aNzp7o=; b=i9+1U34T9xd/bX6kw9dlFyDDOBIC7gL/Fj6msV5r+9FTA8bgcMozuTRa16UKlJSaNV w3jzZ4eHS+flNw97DZrO2+Bj02KW5YHuRhMv1CAQNKcHDVj8ort1SCLpsZHGYjbLFNOy 1YUfkzESNzuK4cTJnRHPjT0VecV5YtGNhMmjyQmghKOQ/xD2CsCRksviX+4L+ode7qxh V+bVFICiMEK0z57SEI3tOcotHWtPr+0u8E39s/ZeVqthVgZ4F4fFza4jYvq3WSOrMz4K 61MMwbyZ+YiyrS6zJPSsfto1UhUbHi7wWnpXFlC/Bmh/YgQOrWd2eMi5yN0eIm2+Avsg 6tag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LqMX+PYoPOvCfsrBf9LDk+x8oxX5ugoY/7ce6aNzp7o=; b=FP9LqbVpheBbFzWBm4AfsMjzaUrOeKABzB/LXNCJEh+Vdjz5SPBelZRRs1Wg7tAnkH rp3kFOOSZlnTeWxQafCfDGK/EMsqp+AOaN1D9WeLgYtmwclTuuEeDTtNmaEipILqggO2 rJi8xMViaC/xGoB39YLuc6Oqs/B0crpfmcKWprDlcZsAkxEqmbVC8Jod0uzdAQHONgnN rocH+4STA+xqFqDlkMqHTiBuuHOjGuaPftqH+jZu23DFuOjnSdOjRD1YPDN+OioqLaLa 7dPIprcVPgCdnF9zdaE3fEGZ+16eAotlU6lOhi/o9WJkjXh4Zk4GvijjN+G8OupnwyU4 UnVQ== X-Gm-Message-State: AOAM5327rbMqiMJox/6dJ4dsPBGjvxfyR2GDGJcW1pgQkJfhmrz4uB/2 8NKIa7Z+bhw+K/NQU+31AXV1v1hgFycc+g== X-Received: by 2002:a63:85c8:0:b0:3f9:e8c4:1eb1 with SMTP id u191-20020a6385c8000000b003f9e8c41eb1mr1019262pgd.203.1653091452774; Fri, 20 May 2022 17:04:12 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 08/49] semihosting: Inline set_swi_errno into common_semi_cb Date: Fri, 20 May 2022 17:03:19 -0700 Message-Id: <20220521000400.454525-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not store 'err' into errno only to read it back immediately. Use 'ret' for the return value, not 'reg0'. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/arm-compat-semi.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index c6bfd4d1ba..b00ed2c6d1 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,28 +290,29 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - target_ulong reg0 = common_semi_arg(cs, 0); - if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); - reg0 = ret; +#ifdef CONFIG_USER_ONLY + TaskState *ts = cs->opaque; + ts->swi_errno = err; +#else + syscall_err = err; +#endif } else { /* Fixup syscalls that use nonstardard return conventions. */ + target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 = common_semi_syscall_len - ret; + ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: - reg0 = 0; + ret = 0; break; default: - reg0 = ret; break; } } - common_semi_set_ret(cs, reg0); + common_semi_set_ret(cs, ret); } static target_ulong common_semi_flen_buf(CPUState *cs) From patchwork Sat May 21 00:03:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574908 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2664028mab; Fri, 20 May 2022 17:16:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa5rQq6OGEs3xFDnAsox8YPVAVOcv62gmvVPaW1cYd04g2uQWALF4dECwnh3CTXT3tC1bU X-Received: by 2002:ac8:5c8b:0:b0:2f3:dd2f:b512 with SMTP id r11-20020ac85c8b000000b002f3dd2fb512mr9702115qta.625.1653092161140; Fri, 20 May 2022 17:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092161; cv=none; d=google.com; s=arc-20160816; b=SNh0BiDxKo08wxfSnMiXFjy1YSDmz+csrWEmKjGkXR9ZN1P2ulx0IhvtejBshN97tk ZsJqlvd7/36w9WnN3n4ntfsQ4d1eg7De6aqT1X+iutVZJrE/DIm+FjyTmLCtRGafqmD2 MON0mhIAS1civxDEHAd0dcU8nXF3atss4t0hYQmjSjlrzn3g8agQGY2/DJ3QAHafu3oX 6W++pqPzbHpGRlRAVTGSw8BmP+2IBTk7ZNBI5OzvcpzT2IUvm9xdWYYYnF8YkMllG1Ax NbKgViJvVg24BU6JNYmnuqkuCfPcM5UXTqJ8++Gkb9tEucxFVg21ViAaC0u2JQ7jcCQb l9ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iO8bYt33Tjxv9WbhuJst+fUaLLVWutotkQNg/qYeZ+o=; b=KNKJ+lgtu0u83OjE+zL5Mj6fMx+bq2w1eiCvBffvL2IllCuqdmgSAAOZIBMTTHDw62 vkoGxyFjv9Zl12wjwKmmF8qACuIn/V5GijzyYvfoso0ItZysmhejKL8gKyuSj6aBveG4 0zWLxvvSHlABogeM4Npvncnb8TRQQTtXZG9UkvntnLiYe9Otkfv07HCom5t3yPsUQf5o 5EkK4T2TnZiPLRYdeofq2IhK4h4kpmuk8szdQ1lnuk66dxmbsUF1x2bcFxVEirdX+E9K PPlQ/iTQRISjQ7QNKrR1t1x2uUcZc9GriH6SSCJjuyGgU7ZV+IeCsb4NeNMR9h28OHGU Rwrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zOgAcsH6; 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=pass (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 w4-20020ac87e84000000b002f3dc9a429fsi414740qtj.105.2022.05.20.17.16.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:16:01 -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=pass header.i=@linaro.org header.s=google header.b=zOgAcsH6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCmm-0000ru-Ki for patch@linaro.org; Fri, 20 May 2022 20:16:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbT-00082K-Ba for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:25 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:52022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbP-0003zO-2f for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:16 -0400 Received: by mail-pj1-x102c.google.com with SMTP id gg20so9309381pjb.1 for ; Fri, 20 May 2022 17:04:14 -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=iO8bYt33Tjxv9WbhuJst+fUaLLVWutotkQNg/qYeZ+o=; b=zOgAcsH65e8tEgDT1U3HYry9Ssa+0RFHW+Ml5JEbaTmywW9n5tLfuwblJ/MSddLXv/ Q/lZVVnl6tyD0ndIGhckJ6A6WwDP+Jj9wIQLjVpIZKL1WIRq6Lgg1LoKd+tc8Osg2CNq IqQGwo243pqUmRC3slp4pmg0FtpLMhxiV7QcmCvgR8y5dKuFBtXxtBft+WLk6Tm3C/iZ bn1Ccj0806BUDt8+46X5xKrkG9cua8skO3xNyqyvQJw6uclOaAJJ4NN3+Rt0Q7c9RYAW elLJVNTNIdP2WAg4ZGC4gx7j3faMea82SouzwKfx67GDHJGinEx73Q08y3pvNLskVOt9 0z9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iO8bYt33Tjxv9WbhuJst+fUaLLVWutotkQNg/qYeZ+o=; b=BIi7Plebs0gRlop9hZY+lYpFJgfIi+q7hMPjjvpJ0zUcDS9pZOuzdlbnSU2RGUZa9R vrHdabUzwWxakM6m/DJN/99YJDl5f904TmamegNfGQuFtDlHtZ7lOXlJp24eig3eb21m jyHE53k61/TglswPi9kWfQBMLWvzbAvTWHmBg2rhxP3+YPfU6RhkLtijqDuUXdYtaQEO x27RGw/V/WyV5HVogWPxT4tUMwHOcbFoLcqJMgNdFuOCP9UBGt//SSjWk6horu77jC4v CZh2uPjk1IaU0nTHnk/Fsm2anrOYhmlmt5zP/pvtAffgnAZ59fzw+GxQ6fCMdNV2fHwY TzLQ== X-Gm-Message-State: AOAM533T4IdyRS1Af+lnCVXiacMf1cj3vTPLCCkTcODZY163kxoAQEw1 MCPUD3vTAoGNX5raaSjkbdDPDXH9jrcbvw== X-Received: by 2002:a17:90a:149:b0:1df:3da1:3549 with SMTP id z9-20020a17090a014900b001df3da13549mr13398787pje.90.1653091453882; Fri, 20 May 2022 17:04:13 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 09/49] semihosting: Adjust error checking in common_semi_cb Date: Fri, 20 May 2022 17:03:20 -0700 Message-Id: <20220521000400.454525-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The err parameter is non-zero if and only if an error occured. Use this instead of ret == -1 for determining if we need to update the saved errno. This fixes the errno setting of SYS_ISTTY, which returns 0 on error, not -1. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index b00ed2c6d1..88e1c286ba 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,7 +290,7 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - if (ret == (target_ulong)-1) { + if (err) { #ifdef CONFIG_USER_ONLY TaskState *ts = cs->opaque; ts->swi_errno = err; From patchwork Sat May 21 00:03:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574900 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2661592mab; Fri, 20 May 2022 17:11:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSwxR/uvzSvLBo7+VivWiWG4ZCq8f7qJ5PgGH1mJZRnBauAxyMg7LeyrU1uPSSvoJn2iVR X-Received: by 2002:a05:6214:c41:b0:45f:380d:2f6a with SMTP id r1-20020a0562140c4100b0045f380d2f6amr9825733qvj.54.1653091865971; Fri, 20 May 2022 17:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091865; cv=none; d=google.com; s=arc-20160816; b=ouzApuoBNjG+yvr2XaD9D8xI6t+qm5SrgQ0XMAJJezn0FfbZitWmUCl8qYdLHd/Jqb XvJ9zDQGLN5nT6FcGeqCfrcwJD6Jy5KjUQp4hHDmluW3WKL2VIK8tnGeh215poT7qC3/ UHSYyOlNQeCUD8T2nShV5tYMCoKRQ6HI40u4hK88ObYIVEvS8wGd+Lb3+o0BNVytJL/s gCN8AH8g/u3ylDdudGQiYouHLgHuy/ssL5a8vG+pwlMkV+gCYB2TH2hl3Ag0DDUeIfSu 5jF32JU9h8QJrgEen/9EOYXeXUXekG32tTOwpKRisEMWIRKyfWCQdFS9b/GbVWtG8H+y noOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kCDHy7lpceuAK2eVJ1Y4445ZF33BxGk4+3bwHnJ8e7o=; b=Aa1iGsOB7ziLpPx/9zJaaigJkyHkfPF6Q2rtqnhHheLW+6oIJ4EskaUKq0n1oi8Lvx 0Hf5CuPhGuXxk0bN3/Yajn5L5p8zhjd+mzhrYH7reyFiiqYN05gSGCQTS674/nJRWPK8 FEAoEJYUauanbtBqz0QZODFyFGbW7DbuEkwiLU26N+LvD1ovU8MxcTQ84GiPVC7AgvBb YtUxwGcf7rqmsQv/VvmR9m7sssXES0qwQXNcQfJPh4vin2x649dRBZcG78q3s5U1tfub bFm3jIjwTSkausfJYdxynPUGT/0ZywGQc5IZ0VPTeMcjOEp/4gOemJBjo1qM9h3UnS3o 5JLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RfC5JEDD; 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=pass (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 bs10-20020a05620a470a00b006a35aec5febsi397036qkb.302.2022.05.20.17.11.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:11:05 -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=pass header.i=@linaro.org header.s=google header.b=RfC5JEDD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCi1-00068K-I9 for patch@linaro.org; Fri, 20 May 2022 20:11:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbT-00082L-E3 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:25 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:36763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbQ-0003zT-KN for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:17 -0400 Received: by mail-pg1-x52e.google.com with SMTP id h186so8978566pgc.3 for ; Fri, 20 May 2022 17:04:15 -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=kCDHy7lpceuAK2eVJ1Y4445ZF33BxGk4+3bwHnJ8e7o=; b=RfC5JEDDnCstDE1FKe79gc7KvW1iIO0/gU0ng4P9TPCdmxbsRYFtHYbcZvaLQXSERD kKREE09StcBztZtgaMJUKHRFqLBtcWH5cJQPup2vSyHhkf44V5dIyLphY0Yt0+K0jXOS pOtgp+d9zmMogOiHEjArozZ1Nx7kMlNhl4jG99Zb1b16lY5WoWb1ktp+42vywg3tSURJ i541OWZ9ghKmaaBS9IUMbnmJmiDAKe7JOxpY0tQatbQ1Ec0JWJhYd6uBar1tnG7c4UAj y96Fr4sI43PRm33xzpqkE8AB8SxxyHlITrlBmAjBqazj4U2tha3bbBUJ7IpD5U30AucZ U7kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kCDHy7lpceuAK2eVJ1Y4445ZF33BxGk4+3bwHnJ8e7o=; b=Br3E7kpr+uXEs8xQAjWSmBeisWevrMa585p17R2bq9Ky3XEe8yVH1dG2kmvkkTP/mK B9goLaWp0y29l9lxKoD8e0sY5L0C21Gyipi9AC/eV5FgrFtwLeDXJmRedMsjaa6lETUZ sqyeY/jHBSLz7kBS7SjHS43AFPYRTgVh8Au4XLsLvXkLsDqzPM5UZVHNh85Vezm5ot7S c5JxabSau1ybB+alfLQDlWw2Ua6mMqCDYdl+hZ8ws66Hid8GWUGEjbXP4E3NL3buB8jp lJ0LBPrBuK+J3+wjrZ6DPkcJEofiv8v1Q9/B8aCmm7opawh/4ORhRuSAQI0HvPnXGwsF /Kqg== X-Gm-Message-State: AOAM531JpGigaPGDRb10+ctblVMofNLn9atzHwyrvDl0JvDj0FqQlpIq VPxaZQaDF5T4eK1kUllTOJJu6UOcPbQS5A== X-Received: by 2002:a63:1d5f:0:b0:3c6:e822:2eb1 with SMTP id d31-20020a631d5f000000b003c6e8222eb1mr10566233pgm.99.1653091454946; Fri, 20 May 2022 17:04:14 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 10/49] semihosting: Clean up common_semi_flen_cb Date: Fri, 20 May 2022 17:03:21 -0700 Message-Id: <20220521000400.454525-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not read from the gdb struct stat buffer if the callback is reporting an error. Use common_semi_cb to finish returning results. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- semihosting/arm-compat-semi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 88e1c286ba..8792180974 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -346,15 +346,17 @@ static target_ulong common_semi_flen_buf(CPUState *cs) static void common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { - /* The size is always stored in big-endian order, extract - the value. We assume the size always fit in 32 bits. */ - uint32_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, - (uint8_t *)&size, 4, 0); - size = be32_to_cpu(size); - common_semi_set_ret(cs, size); - errno = err; - set_swi_errno(cs, -1); + if (!err) { + /* + * The size is always stored in big-endian order, extract + * the value. We assume the size always fit in 32 bits. + */ + uint32_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, + (uint8_t *)&size, 4, 0); + ret = be32_to_cpu(size); + } + common_semi_cb(cs, ret, err); } static int common_semi_open_guestfd; From patchwork Sat May 21 00:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574912 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2665813mab; Fri, 20 May 2022 17:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykvUPuLA2F/xiFGtkv1ah8DkY10iSP0WFKFmopxw3H4ZslHmI7VgiXfkELqDAawf9I5jFl X-Received: by 2002:a05:6214:c29:b0:45a:fedd:7315 with SMTP id a9-20020a0562140c2900b0045afedd7315mr9708436qvd.59.1653092432704; Fri, 20 May 2022 17:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092432; cv=none; d=google.com; s=arc-20160816; b=URizbrZtnN5UHLG7o2mDcs8Adaqw3Gwq0b1X8zFrfyOpACaaZ7VSla6yqK6xsBkoz9 8FgYj2Y4693Njkpi2xXgjPHoroZ/d9ctvqgXYXEEjbN7niWpL2q90xR9eVPBaOlvdX2I uypQ+dQIIHmYcRBeCJlNQZ/mHTfiE+OG50BwaQ83867vyOMf7YrhaAxrWEDbcRfrpZQt wQSQpnxBaSmszLaG9wHzT+aKZa8aFf1Ko8ZxIcpcWX1li5E/gNY+KRIDQ5LlwDFHzUIB GT94Lr9VKjgrFovKDhcaRiLG2MX2lxVnTEDDYbScRTxKstVkH5E/NKUJbN7ZtyVIXP0M /lBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CwJJmiinTbs3pTu81N0JRGdiNyaikTYskuQZDhXBbfU=; b=YEca2FSrSDKrePzWL8kguTVB+Xssxs4Y7LbwuKCptm7Fj48HsMjclxJco4ZiZgIHUJ 3GMxgCxx7tTWmJ9fufbLuVxJZWUOVo6w9hLnJx28eJUKpJ4xKQLu6/gBXq0yqjG1/F6V sBCE4rSPTm4d46X2QWB9Gr1Aj2nbnZ0QWUoBw3MZgQJ6zxXbr6NIftupChIqlp6B1XNZ ChPNMzY/9ko80ONJoi+07cBF/W9KtAV01dcr8HgaEjamtWyXJKSId3zFdusc5Ck+caoI QPbPXcy71Ij5eWHcf984U83J3z5CvTKYXIjHgglKIcAym2/YdYDvUgM40K/ZwZ3egZ9A 1L/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MwCIJoEx; 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=pass (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 q1-20020a05620a024100b006a340d3f663si359360qkn.206.2022.05.20.17.20.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:20: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=pass header.i=@linaro.org header.s=google header.b=MwCIJoEx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCrA-0006jX-8k for patch@linaro.org; Fri, 20 May 2022 20:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbi-00086l-4l for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:35 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:35817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbT-0003zf-3f for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:33 -0400 Received: by mail-pf1-x434.google.com with SMTP id c14so8985287pfn.2 for ; Fri, 20 May 2022 17:04:16 -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=CwJJmiinTbs3pTu81N0JRGdiNyaikTYskuQZDhXBbfU=; b=MwCIJoExiFT0E+mxTP4UhEmXRjrt3CM9wAs+IeKQInA3MasXzaggODnMn3ZOEDxN4U FjBlQUTk3c1FdSkubWKoLFaB7JnuFlp3doZLxcFXBI0Zt+SvccrVn00EkPxUqKDuvy0C ry5EFj8GRsE+9aLUAW4eugbKOR2kI+W0qFJ518CdHUtn8HXXlR+zYg6b1QHx2yVUaYxv Rjx8TBpwEDUOM+W/s5tCjEG7U6rzhJ8W+gBnje+vGAED9WsXiJavKak+wspkY6NdNaS/ aJt3mRQ5Zd3aW7ouRC5nmUH0KLalzJVJ2FSzQyhAJ9AWbBkfYwsnw6QTHuqGj/ZMZAyi m7Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CwJJmiinTbs3pTu81N0JRGdiNyaikTYskuQZDhXBbfU=; b=YfbtVo/GDRYRn3/32jMbtY/R48ye488r2Z+ssF+L3Hrt4/Lt4c8vinCu0dwaN93JiB AY43Aztt20uXVOhqBROpirR2Y5FyTUiJivYDQvTXSbZoWgE3INKM5drNVAVVTDqdELy4 y7kh6vSNhfOxBvil+s/49g8GrpPpydCD2VVZSYT2trmKVt1WTDwdvz3yRGMGl3VEcigT 9FRRbGkCGFfe9w/tsGXz0YQgoiS9OuJt/zwIVWbs1PRlfBuE+0EcTffhWYGbOsJFSntd /rv/q8ey2ng5OzQvHakbdSuPKiM1e78UaCqS18baxGCVVvgz59WOiU+5f45sJGKkfIsl t7Ew== X-Gm-Message-State: AOAM530bfcGTNxaRgvsp+YabMzbsh5K00+r0mFgCuUDhpRgr8yB/4RU3 uexLeHhZdxwC1zbspMv5CCfznrwjlcP4CA== X-Received: by 2002:a63:4d02:0:b0:3f5:db92:60b7 with SMTP id a2-20020a634d02000000b003f5db9260b7mr10817807pgb.580.1653091455938; Fri, 20 May 2022 17:04:15 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 11/49] semihosting: Clean up common_semi_open_cb Date: Fri, 20 May 2022 17:03:22 -0700 Message-Id: <20220521000400.454525-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use common_semi_cb to return results instead of calling set_swi_errno and common_semi_set_ret directly. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- semihosting/arm-compat-semi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 8792180974..1f1c5b4c9e 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -364,15 +364,13 @@ static int common_semi_open_guestfd; static void common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) { - if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); + if (err) { dealloc_guestfd(common_semi_open_guestfd); } else { associate_guestfd(common_semi_open_guestfd, ret); ret = common_semi_open_guestfd; } - common_semi_set_ret(cs, ret); + common_semi_cb(cs, ret, err); } static target_ulong From patchwork Sat May 21 00:03:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574921 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2668313mab; Fri, 20 May 2022 17:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHgm7nAKj7Mr6NZAi3aYGhg8n67U7uckQcKr9fRVQtmS/XorJoLODjUEhSaPBvAcGVBU6W X-Received: by 2002:a05:6214:3001:b0:443:bb87:7f9a with SMTP id ke1-20020a056214300100b00443bb877f9amr9886586qvb.13.1653092828964; Fri, 20 May 2022 17:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092828; cv=none; d=google.com; s=arc-20160816; b=wTyh644lriPLRx7zI0KItn2aTucSadY618rPeH1PRPXuBvfYOx5cOcYE3AKmfuFbl5 CUYYt55oMF8HtMbR6rMWHkAs/Yk0yb+GRHXZ0KcZk2Fxypxy1MhYUlWr6N82PxZA6acK Pdnw2fLT0m5h6uVLxDnkSkLIxlmvMKXG2lah1UZhVQtHF9NexG8UYcJui28yF+ahIj+s fteB57UWQLrRjh1tUbK/DWsOm4mHyToPT69OnqUqjtiij4rhfkUfmB1v/EWXAs+8aQLn p2cewj3cH1l0ASk+fHt8MlXxKzhyENe81d1HFCw2iMOehIqf5+EkqQVuQFx2eEn5Skai AbhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7Ft7CVbGog1TUu0kU/zq3jjXX/+B4Wi5S7h2gXyMVQw=; b=AQ+8K3gxCYTmhk17qlICBP0mfPil3c6qi0JfB74r9LjCzf+1wWFqiVXiSnqTNhHxF3 yFq9S/Jrig1Y7Gyg97DtJalFd0gogqGZ2hTXD4Sovac4dKe7Gw2C85zq+HZN50+gEy5F M1QskgAO2142G0tA0+ScdbQUhaMq1fduBMWuDNVyvAhlFpPKwqmRIVYTY15gHj6lQidG 6IHmdk2wkKHfakZpeK11+/7c3HLIy09uxGy1/0YT6RwPbFTJaG0klX0VT6HZcVdlo44H 5AU01Ze3CYHHr7qufENbXXnM1nziIllNSX2w0dacW4UpBBmpROCCj8tZlsZ4OuNkudHW b+Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=InJAiLnT; 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=pass (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 o13-20020a05620a2a0d00b0069fca9ffca6si401753qkp.631.2022.05.20.17.27.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:27:08 -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=pass header.i=@linaro.org header.s=google header.b=InJAiLnT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCxY-0001UG-Ga for patch@linaro.org; Fri, 20 May 2022 20:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbu-0008B3-Ua for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:47 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:34756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbT-0003zo-3x for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:38 -0400 Received: by mail-pg1-x531.google.com with SMTP id g184so8989004pgc.1 for ; Fri, 20 May 2022 17:04:18 -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=7Ft7CVbGog1TUu0kU/zq3jjXX/+B4Wi5S7h2gXyMVQw=; b=InJAiLnT02x2OcNZyBfA4Wu2QFk6Ie5HOq7MGUtX/G7snzgOmqvgsaAPxTKd6lDXyj qYqt8UVscLQAoFFf8+5la6jFPaCywQ6NleT2rbF6DexmXF1Pfs99iQEvHR2eNW7icpdf chUmZr+HDPd0FSm3CH4lCzbrqdVVwIKGwUvcoHhrf0/zn90sLFzb9n+13OPRqQBYpx1l hSFDxTX0s5agxu2acQznMh82pcA8zM0+p/k62jO8SoPzOXo+PGD0zIM2KXFCgLNVrqOk iw/Q9zjAGuhbY1ojUMLJY5lBTyRgEDSJ6TlkuvgvixoMqm2FUIUbI/VszucRLXox0+gf D5jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Ft7CVbGog1TUu0kU/zq3jjXX/+B4Wi5S7h2gXyMVQw=; b=hRcRdF6+pfHF45a4ZNt5dS2KJJvev+JFzTUW/gmndVkXsj41RLSiBmXcPvXGr8BL/4 Je8L1FC9yzgZKm3qvNeBXcBOf5n28yuBW522GL6Tz/YPHC0WqC9fR6ODKyYo9zRDO1cH sLYZ/igpGfXZHBc2Ix82f4tp3rV4uMPsLLIIPO33ChhfW5LHL0iX65w3onwG6KAqtOZj 2nEex0Faih9Kg7O67NGfYZ55C30mQq3w6M9gADu0s417VuFiDjqFKKttWY33Caf5OWrb cSL5E9hS3VAYosUSUr4x/NoLn9nIiz/swu1n/QMLyEDfhKu+AKQ1sQ2t67YvbqjpuQFq Eydg== X-Gm-Message-State: AOAM533h3c/WC9vIUaQ9iLqwKEoYHKNu5WTkuxd3nH4kUakjMh70Wips AbXX/DNakHgIvSMLnZgK7LH5ecyHGQT/TQ== X-Received: by 2002:a63:f151:0:b0:3f6:1c2b:e678 with SMTP id o17-20020a63f151000000b003f61c2be678mr10759512pgk.403.1653091457041; Fri, 20 May 2022 17:04:17 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 12/49] semihosting: Return void from do_common_semihosting Date: Fri, 20 May 2022 17:03:23 -0700 Message-Id: <20220521000400.454525-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Perform the cleanup in the FIXME comment in common_semi_gdb_syscall. Do not modify guest registers until the syscall is complete, which in the gdbstub case is asynchronous. In the synchronous non-gdbstub case, use common_semi_set_ret to set the result. Merge set_swi_errno into common_semi_cb. Rely on the latter for combined return value / errno setting. Signed-off-by: Richard Henderson --- semihosting/common-semi.h | 2 +- linux-user/aarch64/cpu_loop.c | 2 +- linux-user/arm/cpu_loop.c | 2 +- linux-user/riscv/cpu_loop.c | 2 +- semihosting/arm-compat-semi.c | 543 ++++++++++++++++------------------ target/arm/helper.c | 4 +- target/arm/m_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- 8 files changed, 264 insertions(+), 295 deletions(-) diff --git a/semihosting/common-semi.h b/semihosting/common-semi.h index 0bfab1c669..0a91db7c41 100644 --- a/semihosting/common-semi.h +++ b/semihosting/common-semi.h @@ -34,6 +34,6 @@ #ifndef COMMON_SEMI_H #define COMMON_SEMI_H -target_ulong do_common_semihosting(CPUState *cs); +void do_common_semihosting(CPUState *cs); #endif /* COMMON_SEMI_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 3b273f6299..f7ef36cd9f 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -154,7 +154,7 @@ void cpu_loop(CPUARMState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case EXCP_SEMIHOST: - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; case EXCP_YIELD: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index d950409d5b..c0790f3246 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -449,7 +449,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SEMIHOST: - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 29084c1421..bffca7db12 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -81,7 +81,7 @@ void cpu_loop(CPURISCVState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case RISCV_EXCP_SEMIHOST: - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; default: diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 1f1c5b4c9e..7b56bae7db 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -261,20 +261,6 @@ static target_ulong syscall_err; #include "semihosting/softmmu-uaccess.h" #endif -static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) -{ - if (code == (uint32_t)-1) { -#ifdef CONFIG_USER_ONLY - TaskState *ts = cs->opaque; - - ts->swi_errno = errno; -#else - syscall_err = errno; -#endif - } - return code; -} - static inline uint32_t get_swi_errno(CPUState *cs) { #ifdef CONFIG_USER_ONLY @@ -373,54 +359,24 @@ common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_cb(cs, ret, err); } -static target_ulong -common_semi_gdb_syscall(CPUState *cs, gdb_syscall_complete_cb cb, - const char *fmt, ...) -{ - va_list va; - - va_start(va, fmt); - gdb_do_syscallv(cb, fmt, va); - va_end(va); - - /* - * FIXME: in softmmu mode, the gdbstub will schedule our callback - * to occur, but will not actually call it to complete the syscall - * until after this function has returned and we are back in the - * CPU main loop. Therefore callers to this function must not - * do anything with its return value, because it is not necessarily - * the result of the syscall, but could just be the old value of X0. - * The only thing safe to do with this is that the callers of - * do_common_semihosting() will write it straight back into X0. - * (In linux-user mode, the callback will have happened before - * gdb_do_syscallv() returns.) - * - * We should tidy this up so neither this function nor - * do_common_semihosting() return a value, so the mistake of - * doing something with the return value is not possible to make. - */ - - return common_semi_arg(cs, 0); -} - /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all - * do the work and return the required return value for the guest, - * setting the guest errno if appropriate. + * do the work and return the required return value to the guest + * via common_semi_cb. */ -typedef uint32_t sys_closefn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset); -typedef uint32_t sys_flenfn(CPUState *cs, GuestFD *gf); +typedef void sys_closefn(CPUState *cs, GuestFD *gf); +typedef void sys_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); +typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); +typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static uint32_t host_closefn(CPUState *cs, GuestFD *gf) +static void host_closefn(CPUState *cs, GuestFD *gf) { + int ret; /* * Only close the underlying host fd if it's one we opened on behalf * of the guest in SYS_OPEN. @@ -428,113 +384,106 @@ static uint32_t host_closefn(CPUState *cs, GuestFD *gf) if (gf->hostfd == STDIN_FILENO || gf->hostfd == STDOUT_FILENO || gf->hostfd == STDERR_FILENO) { - return 0; + ret = 0; + } else { + ret = close(gf->hostfd); } - return set_swi_errno(cs, close(gf->hostfd)); + common_semi_cb(cs, ret, ret ? errno : 0); } -static uint32_t host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_READ, buf, len, 1); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* Return bytes not written on error */ - return len; + if (s) { + ret = write(gf->hostfd, s, len); + unlock_user(s, buf, 0); + if (ret == (uint32_t)-1) { + ret = 0; + } } - ret = set_swi_errno(cs, write(gf->hostfd, s, len)); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not written */ - return len - ret; + /* Return bytes not written, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_WRITE, buf, len, 0); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* return bytes not read */ - return len; + if (s) { + do { + ret = read(gf->hostfd, s, len); + } while (ret == -1 && errno == EINTR); + unlock_user(s, buf, len); + if (ret == (uint32_t)-1) { + ret = 0; + } } - do { - ret = set_swi_errno(cs, read(gf->hostfd, s, len)); - } while (ret == -1 && errno == EINTR); - unlock_user(s, buf, len); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not read */ - return len - ret; + /* Return bytes not read, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_isattyfn(CPUState *cs, GuestFD *gf) +static void host_isattyfn(CPUState *cs, GuestFD *gf) { - return isatty(gf->hostfd); + common_semi_cb(cs, isatty(gf->hostfd), 0); } -static uint32_t host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - uint32_t ret = set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)); - if (ret == (uint32_t)-1) { - return -1; - } - return 0; + off_t ret = lseek(gf->hostfd, offset, SEEK_SET); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); } -static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) +static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; - uint32_t ret = set_swi_errno(cs, fstat(gf->hostfd, &buf)); - if (ret == (uint32_t)-1) { - return -1; + + if (fstat(gf->hostfd, &buf)) { + common_semi_cb(cs, -1, errno); + } else { + common_semi_cb(cs, buf.st_size, 0); } - return buf.st_size; } -static uint32_t gdb_closefn(CPUState *cs, GuestFD *gf) +static void gdb_closefn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "close,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); } -static uint32_t gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "write,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "read,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_isattyfn(CPUState *cs, GuestFD *gf) +static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "isatty,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static uint32_t gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - return common_semi_gdb_syscall(cs, common_semi_cb, "lseek,%x,%x,0", - gf->hostfd, offset); + gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); } -static uint32_t gdb_flenfn(CPUState *cs, GuestFD *gf) +static void gdb_flenfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); + gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, common_semi_flen_buf(cs)); } #define SHFB_MAGIC_0 0x53 @@ -554,63 +503,57 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) +static void staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ - - errno = EBADF; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EBADF); } -static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t i; + uint32_t i = 0; char *s; (void) env; /* Used in arm softmmu lock_user implicitly */ s = lock_user(VERIFY_WRITE, buf, len, 0); - if (!s) { - return len; - } - - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; + if (s) { + for (i = 0; i < len; i++) { + if (gf->staticfile.off >= gf->staticfile.len) { + break; + } + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; + unlock_user(s, buf, len); } - unlock_user(s, buf, len); - /* Return number of bytes not read */ - return len - i; + common_semi_cb(cs, len - i, 0); } -static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) +static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset) +static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { gf->staticfile.off = offset; - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) +static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return gf->staticfile.len; + common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { @@ -669,13 +612,11 @@ static inline bool is_64bit_semihosting(CPUArchState *env) #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } \ } while (0) @@ -695,7 +636,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env) * leave the register unchanged. We use 0xdeadbeef as the return value * when there isn't a defined return value for the call. */ -target_ulong do_common_semihosting(CPUState *cs) +void do_common_semihosting(CPUState *cs) { CPUArchState *env = cs->env_ptr; target_ulong args; @@ -715,32 +656,23 @@ target_ulong do_common_semihosting(CPUState *cs) switch (nr) { case TARGET_SYS_OPEN: { - int guestfd; + int ret, err = 0; + int hostfd; GET_ARG(0); GET_ARG(1); GET_ARG(2); s = lock_user_string(arg0); if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } if (arg1 >= 12) { unlock_user(s, arg0, 0); - errno = EINVAL; - return set_swi_errno(cs, -1); - } - - guestfd = alloc_guestfd(); - if (guestfd < 0) { - unlock_user(s, arg0, 0); - errno = EMFILE; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EINVAL); + break; } if (strcmp(s, ":tt") == 0) { - int result_fileno; - /* * We implement SH_EXT_STDOUT_STDERR, so: * open for read == stdin @@ -748,63 +680,67 @@ target_ulong do_common_semihosting(CPUState *cs) * open for append == stderr */ if (arg1 < 4) { - result_fileno = STDIN_FILENO; + hostfd = STDIN_FILENO; } else if (arg1 < 8) { - result_fileno = STDOUT_FILENO; + hostfd = STDOUT_FILENO; } else { - result_fileno = STDERR_FILENO; + hostfd = STDERR_FILENO; } - associate_guestfd(guestfd, result_fileno); - unlock_user(s, arg0, 0); - return guestfd; - } - if (strcmp(s, ":semihosting-features") == 0) { - unlock_user(s, arg0, 0); + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); + } else if (strcmp(s, ":semihosting-features") == 0) { /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */ if (arg1 != 0 && arg1 != 1) { - dealloc_guestfd(guestfd); - errno = EACCES; - return set_swi_errno(cs, -1); - } - staticfile_guestfd(guestfd, featurefile_data, - sizeof(featurefile_data)); - return guestfd; - } - - if (use_gdb_syscalls()) { - common_semi_open_guestfd = guestfd; - ret = common_semi_gdb_syscall(cs, common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - } else { - ret = set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); - if (ret == (uint32_t)-1) { - dealloc_guestfd(guestfd); + ret = -1; + err = EACCES; } else { - associate_guestfd(guestfd, ret); - ret = guestfd; + ret = alloc_guestfd(); + staticfile_guestfd(ret, featurefile_data, + sizeof(featurefile_data)); + } + } else if (use_gdb_syscalls()) { + unlock_user(s, arg0, 0); + common_semi_open_guestfd = alloc_guestfd(); + gdb_do_syscall(common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg2 + 1, + gdb_open_modeflags[arg1]); + break; + } else { + hostfd = open(s, open_modeflags[arg1], 0644); + if (hostfd < 0) { + ret = -1; + err = errno; + } else { + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); } } unlock_user(s, arg0, 0); - return ret; + common_semi_cb(cs, ret, err); + break; } + case TARGET_SYS_CLOSE: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } - - ret = guestfd_fns[gf->type].closefn(cs, gf); + guestfd_fns[gf->type].closefn(cs, gf); dealloc_guestfd(arg0); - return ret; + break; + case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(cs->env_ptr, args); - return 0xdeadbeef; + common_semi_set_ret(cs, 0xdeadbeef); + break; + case TARGET_SYS_WRITE0: - return qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(cs->env_ptr, args); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); @@ -813,11 +749,11 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].writefn(cs, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); @@ -826,129 +762,150 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(cs->env_ptr); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_ISERROR: GET_ARG(0); - return (target_long) arg0 < 0 ? 1 : 0; + common_semi_set_ret(cs, (target_long)arg0 < 0); + break; + case TARGET_SYS_ISTTY: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].isattyfn(cs, gf); + break; - return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].seekfn(cs, gf, arg1); + break; - return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].flenfn(cs, gf); + break; - return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: + { + int len; + char *p; + GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), - (int) (arg1 & 0xff)) < 0) { - return -1; - } - ul_ret = (target_ulong) -1; - + len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff); /* Make sure there's enough space in the buffer */ - if (strlen(s) < arg2) { - char *output = lock_user(VERIFY_WRITE, arg0, arg2, 0); - strcpy(output, s); - unlock_user(output, arg0, arg2); - ul_ret = 0; + if (len < 0 || len >= arg2) { + common_semi_set_ret(cs, -1); + break; } + p = lock_user(VERIFY_WRITE, arg0, len, 0); + if (!p) { + goto do_fault; + } + memcpy(p, s, len + 1); + unlock_user(p, arg0, len); free(s); - return ul_ret; + common_semi_set_ret(cs, 0); + break; + } + case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - ret = common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, remove(s)); - unlock_user(s, arg0, 0); + gdb_do_syscall(common_semi_cb, "unlink,%s", + arg0, (int)arg1 + 1); + break; } - return ret; + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = remove(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); + break; + case TARGET_SYS_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, - (int)arg3 + 1); + gdb_do_syscall(common_semi_cb, "rename,%s,%s", + arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); } else { char *s2; + s = lock_user_string(arg0); - s2 = lock_user_string(arg2); - if (!s || !s2) { - errno = EFAULT; - ret = set_swi_errno(cs, -1); - } else { - ret = set_swi_errno(cs, rename(s, s2)); + if (!s) { + goto do_fault; } - if (s2) - unlock_user(s2, arg2, 0); - if (s) + s2 = lock_user_string(arg2); + if (!s2) { unlock_user(s, arg0, 0); - return ret; + goto do_fault; + } + ret = rename(s, s2); + unlock_user(s2, arg2, 0); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); } + break; + case TARGET_SYS_CLOCK: - return clock() / (CLOCKS_PER_SEC / 100); + common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100)); + break; + case TARGET_SYS_TIME: - return set_swi_errno(cs, time(NULL)); + ul_ret = time(NULL); + common_semi_cb(cs, ul_ret, ul_ret == -1 ? errno : 0); + break; + case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "system,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, system(s)); - unlock_user(s, arg0, 0); - return ret; + gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); + break; } + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = system(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); + break; + case TARGET_SYS_ERRNO: - return get_swi_errno(cs); + common_semi_set_ret(cs, get_swi_errno(cs)); + break; + case TARGET_SYS_GET_CMDLINE: { /* Build a command-line from the original argv. @@ -999,22 +956,20 @@ target_ulong do_common_semihosting(CPUState *cs) if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - errno = E2BIG; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, E2BIG); + break; } /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Lock the buffer on the ARM side. */ output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); if (!output_buffer) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Copy the command-line arguments. */ @@ -1029,9 +984,8 @@ target_ulong do_common_semihosting(CPUState *cs) if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - errno = EFAULT; - status = set_swi_errno(cs, -1); - goto out; + unlock_user(output_buffer, arg0, 0); + goto do_fault; } /* Separate arguments by white spaces. */ @@ -1044,9 +998,10 @@ target_ulong do_common_semihosting(CPUState *cs) #endif /* Unlock the buffer on the ARM side. */ unlock_user(output_buffer, arg0, output_size); - - return status; + common_semi_cb(cs, status, 0); } + break; + case TARGET_SYS_HEAPINFO: { target_ulong retvals[4]; @@ -1103,12 +1058,13 @@ target_ulong do_common_semihosting(CPUState *cs) if (fail) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } } - return 0; + common_semi_set_ret(cs, 0); } + break; + case TARGET_SYS_EXIT: case TARGET_SYS_EXIT_EXTENDED: if (common_semi_sys_exit_extended(cs, nr)) { @@ -1138,6 +1094,7 @@ target_ulong do_common_semihosting(CPUState *cs) } gdb_exit(ret); exit(ret); + case TARGET_SYS_ELAPSED: elapsed = get_clock() - clock_start; if (sizeof(target_ulong) == 8) { @@ -1146,10 +1103,14 @@ target_ulong do_common_semihosting(CPUState *cs) SET_ARG(0, (uint32_t) elapsed); SET_ARG(1, (uint32_t) (elapsed >> 32)); } - return 0; + common_semi_set_ret(cs, 0); + break; + case TARGET_SYS_TICKFREQ: /* qemu always uses nsec */ - return 1000000000; + common_semi_set_ret(cs, 1000000000); + break; + case TARGET_SYS_SYNCCACHE: /* * Clean the D-cache and invalidate the I-cache for the specified @@ -1158,16 +1119,24 @@ target_ulong do_common_semihosting(CPUState *cs) */ #ifdef TARGET_ARM if (is_a64(cs->env_ptr)) { - return 0; + common_semi_set_ret(cs, 0); + break; } #endif #ifdef TARGET_RISCV - return 0; + common_semi_set_ret(cs, 0); #endif /* fall through -- invalid for A32/T32 */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, 0); abort(); + + do_badf: + common_semi_cb(cs, -1, EBADF); + break; + do_fault: + common_semi_cb(cs, -1, EFAULT); + break; } } diff --git a/target/arm/helper.c b/target/arm/helper.c index 40da63913c..902abe67cf 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10313,13 +10313,13 @@ static void handle_semihosting(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%" PRIx64 "\n", env->xregs[0]); - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; } } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index a740c3e160..308610f6b4 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2373,7 +2373,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) "...handling as semihosting call 0x%x\n", env->regs[0]); #ifdef CONFIG_TCG - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); #else g_assert_not_reached(); #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e1aa4f2097..55105cb0cc 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1345,7 +1345,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (cause == RISCV_EXCP_SEMIHOST) { if (env->priv >= PRV_S) { - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; return; } From patchwork Sat May 21 00:03:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574909 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2664072mab; Fri, 20 May 2022 17:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo6U8kbzaCbGZi5J6tdP34shCycFm1oAQ1k3VE1ly71CxMfJQ8MNDo4016OO2WfzICsluj X-Received: by 2002:a05:622a:13ce:b0:2f3:cd7b:d684 with SMTP id p14-20020a05622a13ce00b002f3cd7bd684mr9646054qtk.497.1653092164835; Fri, 20 May 2022 17:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092164; cv=none; d=google.com; s=arc-20160816; b=Iw+vda3vI4hkTBZzZnI9VflFE7UlPjKjCf6o4C7Kak1NefVzUNiIiJTUDbbzKY7Ix1 UVvb7OYUSA7UO1CPUrXC+kSifFEc3K1kLcvPy045P1bev6MWUiR1lCFNloioMsf2NSMs Mr90MO7QftkLN55lEwGa5GUoVIIrJKOx6VMX+1/UqEP9tB8pS7iJHXg7PhvcCIq3ivGr hV0zdZTee4IOtc9IVbj8jCQTJJz4D4uc5KQB4/OuexpgxWe2ww3A05Adl0lEDxxG6/Xi P7dSSexQHT907BA0H6m0/MHjsvYPzT/S7TUCeHBzrSQGLLM9UPMRlieufNeY2L0HD30A U0xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=AT3ROv3xmjjMdnMSslVi7zr4gG1h9UcUPAOfQSU6Fyfkod8bnEXgokXMI75/qe9WfD QQRpgP4Mt3VZpElfqjB27sdja4MOZIT8TXwZiDScr7Ia4+KO/HaTaSUgSCd8Fm+qsTha 0IzO65RzCU9WEJspYiCrF8lIOT+z7H2TtlUL5FAqfwlI+Wdl1nP5Ramu37DGd8HEUo7B hDJAQMmEXJOqd1oYPLsYD/wwrcbtZV26S/tp+XzZE3Vsw8fgnq5eoS87x54381HdIZai +xluy+8b9rMIxMEXVmIfGZU8SNuf7VI6tfYpa+HW0tYYCszxTWecdyyItZE8TkrizWG7 tofw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GU/lbfN9"; 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=pass (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 b16-20020ac87fd0000000b002f39b98a284si336318qtk.710.2022.05.20.17.16.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:16:04 -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=pass header.i=@linaro.org header.s=google header.b="GU/lbfN9"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCmp-0000mu-JW for patch@linaro.org; Fri, 20 May 2022 20:16:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbu-0008B1-UB for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:46 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:54142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbX-0003zs-Gf for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:39 -0400 Received: by mail-pj1-x102f.google.com with SMTP id f10so9289113pjs.3 for ; Fri, 20 May 2022 17:04:19 -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=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=GU/lbfN9x+xzTekgN+OiO0SqHqcZnaW9dcvxzGvULP+FF+hrsy4O9e0HlvxK95RZLx +eLT+kVA8WdzYymv1EQn93SSBBbVZbsk0tACVVTPAsdRbj8kVyMShJ3fAnctAKjluuz4 /WH7+RoQE8Vx1gEGB5iRZZGtDPm/Nto3511pCJ6r0/L7x+ONtGTSNtsaJwPvWBlCacLT CaPTpRKrYj0OO0RFGzZTBkumtY9f8tlVwJHmiYqRD32AR/c/5OxLDp85kqcgaRGVl9Ja mRYzKm7OYjyo0LaiUJTJ9FSDEwkldjFSoKLmj4CFW569sQCIrs8LkDKx/rQv+MczOdME WkYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=IPCMLZlkeiAlqTxalBGnIrE02g4ps0brHa7ZuFGtQMgyw1xRhK8VnPSczOt2Yfxt69 RDcRBTTVBHIqN3aIRBEfaDFJVeMp+rFBb/5iBkQRShqmV+O5V3RXeExPrxvw+H7ZK+Au UlD3fWHwc2GcKoG1Q1LFjNjt9XBDdLH2X62PS/4SRkmzv+HDasSve97sXMGnxwMz5Cu1 efMstwQEhOQ4Fm8rlP/eNwUtPuriEtF20MaSIMcxI003NCzpMHJS8sCFoj8j5T2+pthc sYz33fd3mQSZv4jTecQRfQRn5pPHO2T3PAefsBZBHxbO2PDMehabgXVDMVzi/MyAw9go Uu4Q== X-Gm-Message-State: AOAM530jF5SR6rhis+w+WypIRqQ8NCj4tnrQypdo2ySxsAyVTlkGqyti qkV5zkd5njaD2NSC0F/2gBwmN8+iRIQAyw== X-Received: by 2002:a17:902:8504:b0:15d:2c7c:ceac with SMTP id bj4-20020a170902850400b0015d2c7cceacmr12345284plb.130.1653091458109; Fri, 20 May 2022 17:04:18 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 13/49] semihosting: Move common-semi.h to include/semihosting/ Date: Fri, 20 May 2022 17:03:24 -0700 Message-Id: <20220521000400.454525-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This header is not private to the top-level semihosting directory, so place it in the public include directory. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- {semihosting => include/semihosting}/common-semi.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {semihosting => include/semihosting}/common-semi.h (100%) diff --git a/semihosting/common-semi.h b/include/semihosting/common-semi.h similarity index 100% rename from semihosting/common-semi.h rename to include/semihosting/common-semi.h From patchwork Sat May 21 00:03:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574937 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2680269mab; Fri, 20 May 2022 17:56:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7TIGsa9u1OaUgUomAflxNe17I0oABsJOdo4mFyCQ4/y5dwkCbYxJssZMs7PG77aiY00Qn X-Received: by 2002:a05:6214:194e:b0:45a:d8e3:2d3f with SMTP id q14-20020a056214194e00b0045ad8e32d3fmr10108522qvk.59.1653094568293; Fri, 20 May 2022 17:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094568; cv=none; d=google.com; s=arc-20160816; b=l1h57yqjWjhk4aYHr2+D1jvlXCgVuxtD9ztScHNOOTIqKf2teNaHT0zXq8GjZQqBor 2FYQZMSrYFv8CtQEuizSmUTRmIpoSYytN8MVmKAgh7LesEKa7CtDj7npRdSWy5XUYYmy 5A1Om7d9eGHGL5ljy+wyUduaKwez4xJYfhjF+m8deHYw/GG4MSVwVUj6DaZDJorl0L1E MldR6WhBh5WvSA2l6azuKEvDBUs4xgLIZ6AFF6ViZrtCbET2XxsqBQXNH1YiOA4yWq7F H5b0xALtt1FdoQK3DQ3MgddAUbCJCNC9JT7Qu3uLEzMXInMHtuFvh6l3MbkBiiM0TjIb eiCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6dWKfH8zSLvUN3M0oH8qZ8MqlB5qlfA1EdENsRW07Xc=; b=InSvGp5XDleKD9kB+LaKrbQq+bGqDPTONMeDLJhv/hPsnVAU0Ty3GB97ho56MQ+xfJ 4y3v7Ldrh1CZtd2LuyZCi+rZ/Eb1clY/BtTFeaJ7qJ+RYOHSdpy+l6a96dsHWZgdf95F 0thKFU+t2gnlBA4XaIMy6RQBT+d7JKDNW+Ae6hd2ZfrU0vGJxuTKmCPiNhO1+YP7UK17 eKcU0ZmmG/vvcob9R6OgzRwJyBgWsjJh6e2pA1r4f3BCV8vBMXaXH/f1+dqR/LUAFRys kgT/WActveIAuWBLokxVJ1XZHnmv8dpz4Xxm6uu8nGCMdfkA05Sc4mrt70+A1R2Z7Kcp hVug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lq3A4/Qe"; 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=pass (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 2-20020ac85902000000b002f3f067e8ebsi344388qty.747.2022.05.20.17.56.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:56:08 -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=pass header.i=@linaro.org header.s=google header.b="Lq3A4/Qe"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDPb-0000LP-TY for patch@linaro.org; Fri, 20 May 2022 20:56:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bc-5O for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:33587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbX-000404-Gj for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:45 -0400 Received: by mail-pg1-x536.google.com with SMTP id r71so9015625pgr.0 for ; Fri, 20 May 2022 17:04:20 -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=6dWKfH8zSLvUN3M0oH8qZ8MqlB5qlfA1EdENsRW07Xc=; b=Lq3A4/Qea0Y/E2qZy4Y4sz9PnWUBch6iJ5XMAP5aGt6KAeXccYgeY0Y1n04KMXFybt 7qXTL9ZHhTqB6wRJ1w0+EFRc1d/x+K+JZSCg19ZVCOImC5G+MgoLMhtPV6yQ9bWFxHpk 4icY1UUNvU869A37rcIZPxLxkg2yyw8mThlmODvYw3GYOGkdj4xKZW+zjWCh7La1N/Ts +0Z97GFDyeE/0EVpJ7ihW1iF1XxmGRjqP1GMhUDIV8/VBRRFTqnSzz/ibQ6Vl2vIc5Sb SEAAUiXCJIwNhqAdReyNnouQHAm0HzqP9kpjkoPeyyn/YwJZsERjaxZSRbT93seURcNp 1WgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6dWKfH8zSLvUN3M0oH8qZ8MqlB5qlfA1EdENsRW07Xc=; b=H2ISrSFfAXOr2vd3+CrOMl1fyPHcpdIfZJLvRWwQIrKQPZd/DAS1HBZTnErtxyTHPs 1XeYhqGpfKfvTDdfdt/dClwh5KPVyddnUXaOCj3cc/LGn58T4VuMntTO19XLk2PmNLHK m8ww9UWbC+niojsiuozL1hgypFBQB0XTAMNpe2JSS+CokELYYNPXmjx+Zeswg4Lt/dt6 17gWJ4KaQU4QDuJxdNIqw4dymhvhChneH0MwWdkk4bk/PLJl53geZL8j3EhHuViJlybi ShnUXkwUzj4SPPEZ2++CiCMzZMjmcuLXbSE+FVr21MWJIruBPyjjPnqXopaa8En9UisM WHEw== X-Gm-Message-State: AOAM533/GYzDHi/TiS767a4tFwGHwSolT6RS0VaiYX6ycRoGqeDl0QHL /LTbafn0yzTcJjDhkhyRATvNYmePk10RAQ== X-Received: by 2002:a63:d908:0:b0:3c1:f140:c1a4 with SMTP id r8-20020a63d908000000b003c1f140c1a4mr10458498pgg.393.1653091459272; Fri, 20 May 2022 17:04:19 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 14/49] include/exec: Move gdb open flags to gdbstub.h Date: Fri, 20 May 2022 17:03:25 -0700 Message-Id: <20220521000400.454525-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There were 3 copies of these flags. Place them in the file with gdb_do_syscall, with which they belong. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Alex Bennée --- include/exec/gdbstub.h | 10 ++++++++++ semihosting/arm-compat-semi.c | 8 -------- target/m68k/m68k-semi.c | 8 -------- target/nios2/nios2-semi.c | 8 -------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c35d7334b4..2aaba9c723 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,16 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 +/* For gdb file i/o remote protocol open flags. */ +#define GDB_O_BINARY 0 +#define GDB_O_RDONLY 0 +#define GDB_O_WRONLY 1 +#define GDB_O_RDWR 2 +#define GDB_O_APPEND 8 +#define GDB_O_CREAT 0x200 +#define GDB_O_TRUNC 0x400 +#define GDB_O_EXCL 0x800 + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7b56bae7db..2e0e7febb1 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -86,14 +86,6 @@ #define O_BINARY 0 #endif -#define GDB_O_RDONLY 0x000 -#define GDB_O_WRONLY 0x001 -#define GDB_O_RDWR 0x002 -#define GDB_O_APPEND 0x008 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_BINARY 0 - static int gdb_open_modeflags[12] = { GDB_O_RDONLY, GDB_O_RDONLY | GDB_O_BINARY, diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index a31db38fc3..475a6b13b7 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -69,14 +69,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 373e6b9436..0eec1f9a1c 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -71,14 +71,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; From patchwork Sat May 21 00:03:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574936 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2679630mab; Fri, 20 May 2022 17:54:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeAlNTX7B55cx0++obyTKzCve26st3vn6Y85Y6/+5artGw6voXkBlu/l2RluHLcQra1Efl X-Received: by 2002:a0c:ee2c:0:b0:461:d4bd:39ff with SMTP id l12-20020a0cee2c000000b00461d4bd39ffmr9979810qvs.109.1653094476483; Fri, 20 May 2022 17:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094476; cv=none; d=google.com; s=arc-20160816; b=jv/zE/Lz/AOz59W6B7Px0y0SMz/84YbJqldUO25aopVESpr7y6ZHpKot+Jt7D1FA39 jxcF/OmcPN246nPO3rRobP5RADZq9UrrMQkKcA8pfOE3pGewLkBvDPItSzR6XgQUjp8L g3kIHHWyC0ofQfr9v+QhwnSxtG2vHgcV8E9uEadtyL4P12mZjCXljncSdJ4YblYSwQ3L vQ4WxazMxOxHbbN69fJEgvo0owzzUftnzeMTGt3nZ9kc7b8sBmhZDtw76ihlSvzdChoq LlAMew9fsCDVyXwUy7b+5BP/EvTPaWfXIlr3l/2t7ZlqtPsHz0vxtu/SckXZ+5QL4fz+ h37w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=R1cWCAX6T1IhCXzfFldyArcKJBjdH5O3Whiq+4Ivo+nqalrJoniQAc4Zj8VskrSZMJ 5DdjGpjDbotlYoaF2BiDFtczw/RphNsJqwvQxjWPUHtAAFAWzvm5J7AknaaA8B35B77s bY9XAPd8ICwVxv0w0ho73CrL0rvBI8ZsenRf2DC4yk8wq5JNQit3n6rL4wE5qYObKZrk ro4rjINJKjr+uSoX/QSKE+ck+pJ/tt0r3AT9UsgwNa3BB7yU56ayVKTg4pKU3ybjRenb 5X/1sJ3ocEe4EoNcIh2NwTaUGz/jAUHEiVWXECNChdDrtgYozo2p1wyB00WSOVgjf6W5 Ip5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cNUHDmDN; 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=pass (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 u17-20020a05620a431100b006a012a715edsi400047qko.78.2022.05.20.17.54.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:54:36 -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=pass header.i=@linaro.org header.s=google header.b=cNUHDmDN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDO8-0007Ft-03 for patch@linaro.org; Fri, 20 May 2022 20:54:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CA-Ct for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:43761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbY-000408-E0 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:48 -0400 Received: by mail-pj1-x102b.google.com with SMTP id l7-20020a17090aaa8700b001dd1a5b9965so9051593pjq.2 for ; Fri, 20 May 2022 17:04:21 -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=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=cNUHDmDNyq+Ai9EELn3N5NwNo+tJRt6FtwsKwSpJHHrWz96WETSqad8TWgt30bmTfN 8AsjlPzQIv0SFtW7EYJ2DXJr4tn2c3w2Cy6lqLISsUJ7b7gkfxqZNGfl9rZFUQ7JiM6Y AiOdbDSG7jV7Cd4jE4t2kvhpQJYTW6bya7/w4f/2HGYLe5jkIsNjZpPaW3eM1Y4c7u2K NS2YuJcGDBpLQtJye95oiKC0r4f8o+4+pQrh1pOYpki1hrFHhVMFpg6Ode0lmUlTv8WF QK68950tH2TViVw1zh9qs0mZOUO0ocwRCjYnsgkUmrjXxrDDZT8q9pCVk9wjB9vnnFQ6 UdkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=1QrMHbqNS/HNl3rblYVO3Pbq+CTC1CL44hojux0l8jKm3tIHaBAD0G/PWpycKbi1ey oNc9TwSY6xgnMJvQJUjji/Zd3wjug79lLUaxGzonDvOIhnU7126ubZmYp5498fqshmOc UhmQKyFXGXYz21NvJ0KyuRmuQ0XnVaeDD6Rysm10hHlRDv+a/whChJy6WYjBuzia4m18 V6dTEO6YUtFQTFzJo6ePWwziHEXRWs+fLCNQLsWBhb9jQ+wPacCv/iRvYY6jqVBgGnnL 8OOcEP9ZzZY/6O7HJObSf80HJEMF9qkC3WYsYGaTsyMFJMH0+JezMafCPaIcPP7+H7ZW hRlA== X-Gm-Message-State: AOAM530ckQOlZOZ4JdfHUIWUTCvqKEOv4Mf0PXQ4nMd1B7itPxNOyI6Y Rby+Pu+xhQekVoEI3WHyN36XZ77scmck3w== X-Received: by 2002:a17:902:ea0a:b0:161:fb2f:ef9b with SMTP id s10-20020a170902ea0a00b00161fb2fef9bmr3301166plg.22.1653091460357; Fri, 20 May 2022 17:04:20 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 15/49] include/exec: Move gdb_stat and gdb_timeval to gdbstub.h Date: Fri, 20 May 2022 17:03:26 -0700 Message-Id: <20220521000400.454525-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We have two copies of these structures, and require them in semihosting/ going forward. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Alex Bennée --- include/exec/gdbstub.h | 25 +++++++++++++++++++++++++ target/m68k/m68k-semi.c | 30 +++--------------------------- target/nios2/nios2-semi.c | 30 +++--------------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 2aaba9c723..33a262a5a3 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,31 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o stat/fstat. */ +typedef uint32_t gdb_mode_t; +typedef uint32_t gdb_time_t; + +struct gdb_stat { + uint32_t gdb_st_dev; /* device */ + uint32_t gdb_st_ino; /* inode */ + gdb_mode_t gdb_st_mode; /* protection */ + uint32_t gdb_st_nlink; /* number of hard links */ + uint32_t gdb_st_uid; /* user ID of owner */ + uint32_t gdb_st_gid; /* group ID of owner */ + uint32_t gdb_st_rdev; /* device type (if inode device) */ + uint64_t gdb_st_size; /* total size, in bytes */ + uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ + uint64_t gdb_st_blocks; /* number of blocks allocated */ + gdb_time_t gdb_st_atime; /* time of last access */ + gdb_time_t gdb_st_mtime; /* time of last modification */ + gdb_time_t gdb_st_ctime; /* time of last change */ +} QEMU_PACKED; + +struct gdb_timeval { + gdb_time_t tv_sec; /* second */ + uint64_t tv_usec; /* microsecond */ +} QEMU_PACKED; + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 475a6b13b7..da0186f3ef 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -45,30 +45,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct m68k_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -90,9 +66,9 @@ static int translate_openflags(int flags) static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) { - struct m68k_gdb_stat *p; + struct gdb_stat *p; - if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat), 0))) + if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) /* FIXME - should this return an error code? */ return; p->gdb_st_dev = cpu_to_be32(s->st_dev); @@ -114,7 +90,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); } static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 0eec1f9a1c..3e504a6c5f 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -47,30 +47,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct nios2_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -102,9 +78,9 @@ static int translate_openflags(int flags) static bool translate_stat(CPUNios2State *env, target_ulong addr, struct stat *s) { - struct nios2_gdb_stat *p; + struct gdb_stat *p; - p = lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0); + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); if (!p) { return false; @@ -128,7 +104,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct nios2_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); return true; } From patchwork Sat May 21 00:03:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574917 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2666803mab; Fri, 20 May 2022 17:23:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvjBOumOEN0bCjdQxVQBdHhZjJ3ns3DfodXdSXmPgKogxs9slVFWmgdhs2GYmCWNcqOud4 X-Received: by 2002:a05:6214:224f:b0:43f:cd6a:1d6b with SMTP id c15-20020a056214224f00b0043fcd6a1d6bmr10123902qvc.12.1653092599778; Fri, 20 May 2022 17:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092599; cv=none; d=google.com; s=arc-20160816; b=qujmBvdGL7mw380PbL3kj23KAtfdMAdX1MvIrYhWHDAxjyLZRbaGsBABLq5s9OHyjC lqvkNMNQoOixDtOOtNMZThGDdmSPLe2vAe8McGK8tQzjDqDp8QtcIeV1byoJ8GmKsmDg cCKvuiiCk9EH9WUwuWD+10P1AuhTbZUNRguqIozmM7tyQQttZnm1SYjytIhjhenqFs+s wfFcRNddkC+uNW99m8rJ1oDj0JUMJ9pIVVJU231kR/C8lfkDafQdy5wccM95SYr4raU6 zXptUs0XqrdGa6YPzHMZGCEiq6Bh0YCgjaqNekLOeS9DEqXLgYK03V4ERdHz6IwtqE5f 5vcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=WRPXWYNyl42yaiIaCbx5msMkGa7CNlVRaxilNSNB6Rh+5MpT09jo2GAPViJ/rx/nxX o5ISpSvoTTejIPtQB3LdS1c7quGRl/JBeC4ffJVTu8a2GReVsRRCjv4KXULPCAhghq9n dKcjkj+S8NLy9BlsN1KGZ2Psg+TgCmDS6RzyWKb0wyCoC8HN7fjwkVeA9+mfO6nLPpvb /R7iDYrw3ZG7E6Ucj7NtLbFJ+9HvN9Rkp38Z59GRIUsb8yaUZi4urwXB7OADLbA3OPXI BCefXNE59b/SbLu6Artqi6+VKoGraOZDnGoVi8thcXLOfmc68Dd2fAeLAkjQmHyN2v9h OBiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j3mwiRnW; 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=pass (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 hf11-20020a0562140e8b00b00461ec636eebsi368194qvb.372.2022.05.20.17.23.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:23:19 -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=pass header.i=@linaro.org header.s=google header.b=j3mwiRnW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCtr-00045h-B7 for patch@linaro.org; Fri, 20 May 2022 20:23:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbu-0008B0-Ua for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:46 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:44659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbZ-0003yV-5M for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:39 -0400 Received: by mail-pl1-x633.google.com with SMTP id q4so8553498plr.11 for ; Fri, 20 May 2022 17:04:21 -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=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=j3mwiRnWOm6xJO4niiOTKABBso0CB+lFjaSPON/oN71B7gjLR/+9ACd+HpY8FppmLI zW91gN8az12Y1HzChyG6SWVVKKq+rzWmC8PafJWDIX/HVG7l+iU6cOXFBMv5yrANCkwM 3j7Jl2MN1hpcYQ8i9ktLk9tsnphyykBoZCpyvyY/04dnxGllrgC9LL89wdFIjyGsP/UV 1wfpSlyeo/8d/g4J9A2VP8HUv594mnaM3WTkfOzneb2hQW5nBtN5a28saGo1yRlnxUVs EZfHwlVQ18WyrkUOOghUJmYMV5fGmeCCU8ONf7pH55OT458zt+12KrU1qaWdWafzPqKV IGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=MTq7PbamAgn6YBKjnTdOfHCs+PdFh2+6hs3WLZ4vUSYunqBP/IXNeoSOzhs3necZNR 9pGLaEHn7nRS+pEuTP+gxTGW+6bhTaHkSIFlQn507ellQc7jDE/7EBqHjE+utWd6s4rA r37n+2ijNYWAGF+QIDh3BZHA4xXh06awYhiHXu1YoYwm4yuj6Zu5KJ1d+uBO0/1+Adff qMwq4eMU5aiDbU6BNUVIW9iAOappsmxdhgb/7aRro+k1gpr0T+EAFeTxgbWdYW0gb5+/ iCbevAXuR4nonCSg/rC2oF5Kvoo1e0xGlr6NS64qOQSupIK6elvm9BgTGszBK9viSVpO ANKg== X-Gm-Message-State: AOAM530HvaWo0Lu4LprJyfu6JzQKb9b6W0jQ8a+ZSNvhNopp7cROKRoy /h4AhYB1Ix/V7Jc69MbqfOhN9Cf/NKwtOA== X-Received: by 2002:a17:902:ef45:b0:156:1858:71fc with SMTP id e5-20020a170902ef4500b00156185871fcmr11692853plx.23.1653091461501; Fri, 20 May 2022 17:04:21 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 16/49] include/exec: Define errno values in gdbstub.h Date: Fri, 20 May 2022 17:03:27 -0700 Message-Id: <20220521000400.454525-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Define constants for the errno values defined by the gdb remote fileio protocol. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/gdbstub.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 33a262a5a3..0a6e0d6eeb 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,28 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o remove protocol errno values */ +#define GDB_EPERM 1 +#define GDB_ENOENT 2 +#define GDB_EINTR 4 +#define GDB_EBADF 9 +#define GDB_EACCES 13 +#define GDB_EFAULT 14 +#define GDB_EBUSY 16 +#define GDB_EEXIST 17 +#define GDB_ENODEV 19 +#define GDB_ENOTDIR 20 +#define GDB_EISDIR 21 +#define GDB_EINVAL 22 +#define GDB_ENFILE 23 +#define GDB_EMFILE 24 +#define GDB_EFBIG 27 +#define GDB_ENOSPC 28 +#define GDB_ESPIPE 29 +#define GDB_EROFS 30 +#define GDB_ENAMETOOLONG 91 +#define GDB_EUNKNOWN 9999 + /* For gdb file i/o stat/fstat. */ typedef uint32_t gdb_mode_t; typedef uint32_t gdb_time_t; From patchwork Sat May 21 00:03:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574907 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2663956mab; Fri, 20 May 2022 17:15:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6/aUZJEBNTNgUUuxC4/D2u/WcOmfD2g9eKnhsyvMURWM0wseYup/O+e1ALmfHJfagGdnR X-Received: by 2002:a05:620a:2493:b0:6a0:2c2e:9937 with SMTP id i19-20020a05620a249300b006a02c2e9937mr7967604qkn.546.1653092151869; Fri, 20 May 2022 17:15:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092151; cv=none; d=google.com; s=arc-20160816; b=etfDQdLDF/wHh4b3iTZUTfe6MAhaxm9FWCWdxszLjAPMYHLBRORrQ3KBoeDZZCkSse IyUUSb1F3qLCzfWJ22/0ktN7pVBjZx4PWvYI6jkH2F2DcbX0UlumQn2GEnFQ0mdpb5Bx jszz4IBE/Dbo8HiKketxrdyoz9Gj+rLaK89LBdWEsAF+aeq52/DOT/9wc0SvEbGO9wDt YioRWxryHqmj2R6dc9xE0eYcckm7Kic46fiV0120FonKFRnIWNMVfdVLCzOBLksRejiW kEiSLY0D+XJXQ5b8nCMnyipp5GsVP5ubgIy7oqRb5eyqg6AqPpD6dY9ZDDPftVTTHmCn 1RRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t4HrU8aBsDXJmwDfJHBNtFc0i86kohNVifRpodC+Hr4=; b=G/NsBfMVPzSOM5zcQ3BT9nqbGzs43ungjf+EfL9WnPnvfYANGOGHbY/SZZGRagM8MU oh/xkIbi8qIWUOeswDh0Id2Xqf1FRH5IoEx0oLkroNS9YaoHFKbw2o3X8L7Stoi48agf KV3x6BmnTvuudZR/oDo2yby7xTgAFi1Xcv63/BpfYOQSWnFfnOaH4sT0CgiXWn3zccFe Gwwb7vmW3ehHhCbEj90XpgJW6vH3Chn5OKnI6jMqBVCamIyhWzU3oX32gx9IQrH9u1ij NY8saFuiAFDGsURt9vdSpcohUXLpW6kDu7gslRVI5YNx8A1Mwi2AZ7cRlhJl0sOHwYeU 01ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QVHAOnOS; 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=pass (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 de5-20020a05620a370500b0069ee712efc8si382008qkb.86.2022.05.20.17.15.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:15:51 -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=pass header.i=@linaro.org header.s=google header.b=QVHAOnOS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCmd-0000e0-Ef for patch@linaro.org; Fri, 20 May 2022 20:15:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbv-0008BA-2z for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:47 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:39765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbZ-00040E-6b for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:40 -0400 Received: by mail-pl1-x631.google.com with SMTP id bh5so8560203plb.6 for ; Fri, 20 May 2022 17:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t4HrU8aBsDXJmwDfJHBNtFc0i86kohNVifRpodC+Hr4=; b=QVHAOnOS0+4w2Gfmp0mHDxMMxWQgSrM7S0AyNrqBTB1E5Tvle/EJCsBOFWGOhQ7LE6 3eMYmmtAVsh3t4t3U3PeZu9bDkQwf5gPrF1hz9nxK/5EglVlmG5Psu74QbQAW5ptonOK 3Gf7NVhm8TdmByXw3P+36IBOokItIHkeEftQAwn8AqZ16vTv85GNenyS1XuBGjMCavXb xyOSYZnYmui8KQa3o9MIIowuvioDN3tjIqe6xcnTkLXTzeLJevPalm4boQ8hMtVumaUd rnnH2cNheS/EQrUpDW9f3vUj1thZ7tipbeLfAn8jWgyjt3fGaKzPf1YHjuxtreLdSueQ cZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t4HrU8aBsDXJmwDfJHBNtFc0i86kohNVifRpodC+Hr4=; b=U3gieeTtuOPXdgxDeLLqVFh5ESvrgJ0+2CO5/shfJkv0dvCBv1lkTD6he+NZVb6zQO zZokB7Wv5Mh30WxWaqlgnwykcKV5LgAcblW8pMUwtlKuf++0lpjsy3m5bcE/ygQ6QRo9 niCzyd9syTzTpDiHOFixHMf2CD+EsErHK85t0t4c090kwLmM5DQbTTCTHI7dyoOHEo32 BnYwiXU5Epx0q17TNr6KODbnn/iz31g6nMaVbXQhW59Ycvq215LamfrdKAuY4i4lUkZy jI5hr/9NevlMw1fxlqL6SyDX2MRELFMor2YOvYm3qVHhbAdDd5+Q+x1o5xkdGg+kafgZ Rl1Q== X-Gm-Message-State: AOAM532jzWym8YL+yjKZrrSWvLzovaKsCrT6OFOdnVq+B1xe6kQ/f1kG TFbn/mdBuP8D9eT1moPyB6b6s805ZMecMQ== X-Received: by 2002:a17:902:8303:b0:15f:86f:70a with SMTP id bd3-20020a170902830300b0015f086f070amr12216102plb.5.1653091462701; Fri, 20 May 2022 17:04:22 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 17/49] semihosting: Use struct gdb_stat in common_semi_flen_cb Date: Fri, 20 May 2022 17:03:28 -0700 Message-Id: <20220521000400.454525-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use offsetof instead of an integer constant. Load the entire 64-bit size while we're at it. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/arm-compat-semi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 2e0e7febb1..7becc14a81 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -325,14 +325,12 @@ static void common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (!err) { - /* - * The size is always stored in big-endian order, extract - * the value. We assume the size always fit in 32 bits. - */ - uint32_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, - (uint8_t *)&size, 4, 0); - ret = be32_to_cpu(size); + /* The size is always stored in big-endian order, extract the value. */ + uint64_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0); + ret = be64_to_cpu(size); } common_semi_cb(cs, ret, err); } From patchwork Sat May 21 00:03:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574923 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2670078mab; Fri, 20 May 2022 17:31:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy679AXJn3A1SzBdDA26c7mA9Sd1kOSHDrn0zG6WI13rUd29O/OBq8fHV9kME/Hr40zBFSn X-Received: by 2002:a05:620a:c43:b0:67d:f048:f5e9 with SMTP id u3-20020a05620a0c4300b0067df048f5e9mr7838878qki.281.1653093072541; Fri, 20 May 2022 17:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093072; cv=none; d=google.com; s=arc-20160816; b=GsVtqMwtn5CqClshyOVpO72qYlF24E1tPb41uk4sVLRLvEAErnjSGVcoqVkpFBjnBz QNb/UMwhYfn2rR8hCkw14GzcZXkxOQc6qrDgBK0g1KTLhf80je6fYURkl1UuNB+S51lQ 2+IiBid6M5nUg9A0hRfNI7TAZh3d/mnkr1Dvnimp/+Hcmk512iJO8lxebM+oMv5sie8Z AAHVoZ5ReDpuHpBBgaWkc70KMJTWVQE3vWNeAli3vO3oRzhoSSw/B6L0yDy9OVmI1oTg rx9m6aCS610rvRN3wsqPtRxLimBmKaADnWezFRYISG/HDMI+95TiNJyLGMHRhq4jHECj cgog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ksJwiBOmhFBw0ef1995REJKMRag6w/MQtxaor/JS6fU=; b=kYrJDBkeVDoieUfHQLlE0t7eIMRcZI4rln3JqPXoka4mw3Tj5oU2gnGMl8PLPtQJVf /CB8GAqYV256Lcz8lBpO1vww2WwaGHB2jqNoFgbtryLPP3PcLYBKqy9bu7M5hZd55jQH cbII9FqF7oC8xGjSYkbN2rzSGfhI/qcHF7Iw7zvxBXtN824Zgqvy2B2RXmIB4bmTolHh 3F1AMPXap8+oQtSjXwO7HHzmMsMqrBy9kGED1u9o/fos3hQA8vGscJp8x+CER/++KxRf k2dkoe4OsHDhIW5bu4FQMEC0PpUpwHItDLV1NEV81lDx4woXeZJsfTeM/BxsSRoyAanM LYAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZUY1Mdno; 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=pass (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 f1-20020a05622a104100b002f91745eca0si419880qte.94.2022.05.20.17.31.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:31:12 -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=pass header.i=@linaro.org header.s=google header.b=ZUY1Mdno; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD1U-0007Oe-2F for patch@linaro.org; Fri, 20 May 2022 20:31:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbv-0008B7-1o for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:47 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:33547) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbZ-00040I-AY for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:41 -0400 Received: by mail-pl1-x62c.google.com with SMTP id 10so5129623plj.0 for ; Fri, 20 May 2022 17:04:24 -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=ksJwiBOmhFBw0ef1995REJKMRag6w/MQtxaor/JS6fU=; b=ZUY1MdnoCWZ04waslyjRyDuZh5vxgvbxF/HBlcJ168IGfPNT7CnWww5F9N7pLP3fjU NgzhICCtEC6qmcPpEUVBXC9QlZO+cX5Wmqk8R+r4DLSDwf+s7tmuuAAfN/tIuPalh/GL DVEeYhK4Eo+Z1/L4A9C68cSZjoF3HapPpClpQwtauVz7hX93dkn/ite5rwOY2xDj/A/z 7XPPeDDY5LP4TdxWh3Mnmz2qp+B5sFZb0PKqc2FA6441c2uiTYdov7k2joTHWWJYYO1U 97EpH3joQa6fG57ceAIqm/wuEFGIynxV5U7YamGTygf82+xR1lBoF2R4SdwPGP3nx4Dv IL/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ksJwiBOmhFBw0ef1995REJKMRag6w/MQtxaor/JS6fU=; b=Mjv6XSuheeRbOA3kcWRWceWc4r2/LsxvdhpfD2cMLV3oAC0y2Gde4u53YLOUj6WA5p Vif/137MOUqgPKXjpvvKx135oBZwaqbIpiWbHtU5A3lfgOUVT4MrAiiIhrICdZD13GbG cgrFn33wAXnuqeBGthfp6kmv5lJsqXRDJWY3VpWZlNrEzhtkus3hC326KL84T8LDyk03 w4bCy4ZvQjL1YuH76Zx7St0J+UWs1ejmnMAefCjBO/6RkB48m8HdQ5J2hyMOmwqO4BN/ PnP+gyK6JyyxOsH5ptd+ltrl9U+NRREblUojp7KfKjIMLMaSDcJ1u8kpPHSg+ck14aPf yjFA== X-Gm-Message-State: AOAM533FPujrILaYAO3KHCrpBNVCEgynvxi4G0T91JE3Eqaxs1/Tqi1k DXR2oUvIHh3zCxsfMHxxi6vCzB1JM5lrRA== X-Received: by 2002:a17:902:7593:b0:15e:fe5d:58e1 with SMTP id j19-20020a170902759300b0015efe5d58e1mr11798894pll.102.1653091463660; Fri, 20 May 2022 17:04:23 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, Alistair Francis Subject: [PATCH v3 18/49] semihosting: Split is_64bit_semihosting per target Date: Fri, 20 May 2022 17:03:29 -0700 Message-Id: <20220521000400.454525-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split the function into multiple implementations per arch. Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/arm-compat-semi.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7becc14a81..99a1809f27 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -213,6 +213,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -238,6 +242,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} #endif /* @@ -587,17 +595,6 @@ static const GuestFDFunctions guestfd_fns[] = { * call if the memory read fails. Eventually we could use a generic * CPUState helper function here. */ -static inline bool is_64bit_semihosting(CPUArchState *env) -{ -#if defined(TARGET_ARM) - return is_a64(env); -#elif defined(TARGET_RISCV) - return riscv_cpu_mxl(env) != MXL_RV32; -#else -#error un-handled architecture -#endif -} - #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ From patchwork Sat May 21 00:03:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574926 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2672437mab; Fri, 20 May 2022 17:35:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXv4DU9fwBoUFD3mDq2wxgPI6Aj9JX7dUixoF3uagCXL50zLe5Ubgar3OPC+g1TPsPepC+ X-Received: by 2002:a37:a102:0:b0:6a3:5d5e:2706 with SMTP id k2-20020a37a102000000b006a35d5e2706mr2051528qke.251.1653093352755; Fri, 20 May 2022 17:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093352; cv=none; d=google.com; s=arc-20160816; b=uhxWY1niTQe6eJI39sossKlvVE0q88iyWvcP5mZEyhr58iTjU0W873gG32IUvwKhpC Hu/5CfV5j++33INxdHxYKCoqTnkMYz8+igxXHD/vAEE6biOVIIjoyDJbR4zP2bE9naeb x9XWICW/2DEP8m/aDVZavyACQPdGSJKqb/6yCZ4HYy1wXNGxOElk7WtyrsuQmDaSBCOv V5p/Dx84ew6WvJnj4xG6FdezvVJJwnlUfwXVlwPeSdRQtrW8LfivowBJlf0HXGx7qt0B r8EJRH1MGeZFYk4G7t3UwXT5VicbXl3QSBv9oSVnRB58H9UMaJ4YvGQThgAAqttIe149 6HOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FOXW0QBVRQzvdj2/5WlXeWhliAMlds8KPficEgm5rdo=; b=h7igzJtEwWlj3wXzYcZkGLlXaxOBiJtQDj4DBI5NKwpySuMNhE3O51zb2QU267IKo9 KaGynymzP6T8ue+tafHn7NyAjUsinOz2ee6Wx7Olyx8/CCEfpU3TN/fRuvYN5NBZ0iJU +II1s9RQPYLXSa0fY5d+ubWWS/wmQUOO9/lG9+AkhKvvCvcEbwTzn0VGsJBTi3NmIRvk F15SzWgUmqkPh1iMpswzspg8d1W0l0R0wIOPPCeQOYMC77xMZttS56yjUEVOzKMSlQE9 VDsDValba8iG0rssFm4s9MXW8Y+5/9OYw1ThXDx4et5GWS3fkwoxUsuvef1rzCjgjhdK Q2/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OviK12BR; 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=pass (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 q1-20020a05620a024100b006a340d3f663si368096qkn.206.2022.05.20.17.35.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:35:52 -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=pass header.i=@linaro.org header.s=google header.b=OviK12BR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD60-0004wU-Ci for patch@linaro.org; Fri, 20 May 2022 20:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbv-0008BY-MS for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:42780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbZ-00040P-Td for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:41 -0400 Received: by mail-pj1-x102e.google.com with SMTP id a23-20020a17090acb9700b001df4e9f4870so9062695pju.1 for ; Fri, 20 May 2022 17:04:25 -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=FOXW0QBVRQzvdj2/5WlXeWhliAMlds8KPficEgm5rdo=; b=OviK12BRLMDBD+B/+T12TZ6u4AHeAQgmDflErLQUohruXLe9bykv//fazu1on3jUvK POkME46q3kW046Bkhy9uZAr+n1ctyphseVEMdojmbJ1jqONfKAyVyeRO84rgcLmKrd08 yniVdCbY5+A8R/Q0vEXLxA2LumECI2pUrnZ+CgsKK+9DNVmbuLFxdJNPh056Jiv7aTDe Fguk1JKRh7H8gIpldM1jaOMCZIeWn8wpFb4wY2xClEDwS0r+Rh6QJy+gdnOmT5pM6T2w 7m+k41t9P+DfxXNSbviNwdeeZ1yyvzgRIjtubn2rD/Wg7PgA2Lf5kyZL5EtQlpa61F+C NCJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FOXW0QBVRQzvdj2/5WlXeWhliAMlds8KPficEgm5rdo=; b=HUSSgvLiYE9K+K5bsKslopfldi4WwjVeWSna4OQx9JSIbLyWVF9RRgMaSjsvfQiFQ9 1S4sXhORGCfp7/qPUaIn2dmm+RyvPvkvgfRi6WV49obwdp5ap3e+Thfp+eHeDcIsHvSC aXKixsBDXjItMFi+e5/aWaPn+PtbaNIveyEqFRhnZN28XF0XPcKhtqZK+nMbVns3RTcq cWyvKWYqnAi0ciAdDsMy99ju09MGPbKdBXBrTjKn4a9ifpjfc1mRMU9tTA7Rot6dvvij TdknDfDaVBnT7aGAjZdfCfp/bYhiJivJJf7+BWLbv+0gO9SIyKcEmpb7OuObDWWPjkeb NrNw== X-Gm-Message-State: AOAM531iAVmPOJQi1KleHvk6LftYDgVdCj3CpQzWrYanHyRmds4Koz87 5UPexWf0IU6XpvIgRfqYnr0m+ZEn0WiAXQ== X-Received: by 2002:a17:902:d550:b0:161:fdb8:3d9d with SMTP id z16-20020a170902d55000b00161fdb83d9dmr2864151plf.42.1653091464556; Fri, 20 May 2022 17:04:24 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, Alistair Francis Subject: [PATCH v3 19/49] semihosting: Split common_semi_flen_buf per target Date: Fri, 20 May 2022 17:03:30 -0700 Message-Id: <20220521000400.454525-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split out common_semi_stack_bottom per target. Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/arm-compat-semi.c | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 99a1809f27..9ea985beee 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -217,6 +217,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return is_a64(env); } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -246,6 +253,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return riscv_cpu_mxl(env) != MXL_RV32; } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} #endif /* @@ -301,31 +315,15 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * Return an address in target memory of 64 bytes where the remote + * gdb should write its stat struct. (The format of this structure + * is defined by GDB's remote protocol and is not target-specific.) + * We put this on the guest's stack just below SP. + */ static target_ulong common_semi_flen_buf(CPUState *cs) { - target_ulong sp; -#ifdef TARGET_ARM - /* Return an address in target memory of 64 bytes where the remote - * gdb should write its stat struct. (The format of this structure - * is defined by GDB's remote protocol and is not target-specific.) - * We put this on the guest's stack just below SP. - */ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - - if (is_a64(env)) { - sp = env->xregs[31]; - } else { - sp = env->regs[13]; - } -#endif -#ifdef TARGET_RISCV - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - - sp = env->gpr[xSP]; -#endif - + target_ulong sp = common_semi_stack_bottom(cs); return sp - 64; } From patchwork Sat May 21 00:03:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574922 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2669943mab; Fri, 20 May 2022 17:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztt6EMy4oSz92K9mfy42p00JiT31VnghZEcVJQHCU2ynw2D3Nw4UQaaPEwKU2V0eoLVo6Z X-Received: by 2002:a05:622a:54f:b0:2f3:d566:e22c with SMTP id m15-20020a05622a054f00b002f3d566e22cmr9615181qtx.466.1653093059282; Fri, 20 May 2022 17:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093059; cv=none; d=google.com; s=arc-20160816; b=IuWbOZG4T3CZB3DmRjlCYZRrmWoaN8UCplIn4qhzah5IxQJUa/HM+vA08p3dbf4j1r MawkMQZRcNfdGWAUrj2Jm5tJ7uktqcsrEKJxbue5njO3LNx9H4zwNN+c4P1EufaYqRcW oy4FHeJRD2B201kU9h5mDYSo92d37eks/rOlP67QUwwR8pCKGcXE1YK+urMcAEEfc8Xs mXysdC77C0C1WEJrgzmtbO7RxPMrkZeltTaY6gee2Cy3kMyjF5b3nSoA2xA8aSqiCnG/ yAU74/uDf4L1DO/TO6GLnUTB7QdIXXbd8n/WGN5dafn1q6Wf9a2UbkTIYrpAEUMezJRT PLFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WQ9CMUu8S8KNltjSwi0JIKZ7rxutJhSFkeyYpNk7QeY=; b=EW+NCnVIIPiNoP73JOLRrUY+WAvRmasNVzrLzIhk3Hvc2RCw6sZxQc40dncKelZdZe IUyhiBFN1d6HQpXqKef13WV97psKW759nYOu5xsI1J+/i4VTMmrdNe0GOuImMvmqqwDk BMl0Dp+6SJnx9H4msPdAqaRqJdRtR9S6quLpFZfAfYXS2NhiXW0B7yhrSt+sOjSxRpi1 5DPmLpMxHV1CWPvksQ/jU2jZZFv9ssjFNaKABdEuThOs1Py4Lsn3GDAj1PwIlL9Oj3+w ZgvDC05Razsthf1c3mafmSCtEzmuTbB9qbtt8++YFfEIDT4oMtwsXsOUbk2Mh5MZUb9H uf1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LG2D176y; 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=pass (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 g10-20020ac8580a000000b002ed11a6a4acsi401695qtg.535.2022.05.20.17.30.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:30:59 -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=pass header.i=@linaro.org header.s=google header.b=LG2D176y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD1G-0006vU-Rc for patch@linaro.org; Fri, 20 May 2022 20:30:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbv-0008BZ-Mb for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:46944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbb-00040Y-J9 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:42 -0400 Received: by mail-pj1-x1031.google.com with SMTP id v5-20020a17090a7c0500b001df84fa82f8so9030201pjf.5 for ; Fri, 20 May 2022 17:04:26 -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=WQ9CMUu8S8KNltjSwi0JIKZ7rxutJhSFkeyYpNk7QeY=; b=LG2D176y156pfG/9ukFMhFrZHI8qLyIwh5/SC7axsY/fRpcZtYLXUGPHjZKscW/Hxm xlLICNZTMTYwjwNbb3RzgAX2g9dkhkU7aQRh9JXxgPoXF4O/HpJCWfyfDe+RDSK+8KQY cHp4sO1tvIW376dZcG7I62nSJbdqsbe9YpfVaP4E9/xuJzhUQPpbbEdjoqQ7YRox4Avq tJTyOT8yoeLkVNCVaDXKqIvdqk2CGIRvrHeWoSxtjFFwKSGzGPa2Kmbg7jKSM87RPow0 I82suR5WnNwWNWXP0/IPdaaHLQYWsC1ZPHd999k0Q1nJuVq2dKqXetyF0e436Qw2FfbA pG8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WQ9CMUu8S8KNltjSwi0JIKZ7rxutJhSFkeyYpNk7QeY=; b=SmKq8deTH/AKq7Q+ZFOHuSOOa83aTpVWNzTywJ9vAFsBeLPwvW5d3rz5ATeyvXTMHF o0kKrNmlIi+vpBj6vyGY+17G1J+NknMKYLt1EvQ5qIpIKFEF1QSGthAj71mZChCVhdqX P7EFjPSXfq9JCZJ4tDPX2E9rBvTo8EPW6R6Uv+Cnpt+GGaSqd1EkG1c6xNXvfJreLqob G5hp12BPDY0Jgw4Tu9rCGuGoM7LlWn5e3uHfdVJHzB5zQmbEvB+DqG8B8ttCupmq3H/Z nbwI6LppJU/t4psAsnc4CLHDyFYzDOKozryQjZMLXZXB+qpvOY2putSIGQnWBOyXgD5l 6o4A== X-Gm-Message-State: AOAM53290s5sFb6yWjbZ9X23g1ZgckrlaHTK2XyzJXi2j8ujpTVUQKeq wr6IGF71dXqWTjxgQZ8IcoHkOhBJZMOPNQ== X-Received: by 2002:a17:902:7597:b0:15e:b5d3:267d with SMTP id j23-20020a170902759700b0015eb5d3267dmr12209017pll.55.1653091465614; Fri, 20 May 2022 17:04:25 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, Alistair Francis Subject: [PATCH v3 20/49] semihosting: Split out common_semi_has_synccache Date: Fri, 20 May 2022 17:03:31 -0700 Message-Id: <20220521000400.454525-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split out a boolean test for SYS_SYNCCACHE. Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9ea985beee..c53cb1891f 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -224,6 +224,12 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPUARMState *env = &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32. */ + return !is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -260,6 +266,11 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPURISCVState *env = &cpu->env; return env->gpr[xSP]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} #endif /* @@ -1102,16 +1113,11 @@ void do_common_semihosting(CPUState *cs) * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */ -#ifdef TARGET_ARM - if (is_a64(cs->env_ptr)) { + if (common_semi_has_synccache(env)) { common_semi_set_ret(cs, 0); break; } -#endif -#ifdef TARGET_RISCV - common_semi_set_ret(cs, 0); -#endif - /* fall through -- invalid for A32/T32 */ + /* fall through */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, 0); From patchwork Sat May 21 00:03:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574930 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2675274mab; Fri, 20 May 2022 17:42:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx4D2sAdgzGIiwREhGeaoiegi2bJwroiG71EGD8p8vDA/A6H//xjhIHTebP+WMDCTL+TXX X-Received: by 2002:a05:620a:1662:b0:6a3:5692:636 with SMTP id d2-20020a05620a166200b006a356920636mr2419795qko.311.1653093761623; Fri, 20 May 2022 17:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093761; cv=none; d=google.com; s=arc-20160816; b=Wkad0OrIsE22kDPGBMWp5WsCGtTnygS4Iu9ZmdELMfMp6MTbnjfy+qJAcknUYGasNT 0uSzF5+MIMLs201KoSFuObxeovlt1vYWzKuN+UDYSi/d4le/wZCbuly3vaN3v5Q+6B3+ jMLRYZ3WDOa/2qGiRSkJUxpEPGT/3kYZiOaLv17upzrR4aKh/C2bi25wVVF8ERDIpJhP RtD6EG0eJ0ZlcbcbgHAJ1xSWEIf38bGHLtpYk1LLenbY6MTAgjso+XPZQ2noPjaEQSx/ DcOeBBQK0085e39BkuVCTZzN5v/7JMO40pdGhn1PbZwOnPgHcFVBb95jCUJT9ClSo700 bp/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fG9arG1tn4b444K5zf/g1JuzGuQmuRsUj+aiYfge+3E=; b=BT21GM7gGH3vV38ZFLoVn5LO3Xt+i9xMp0SYmYOkl/DJ77yfj7o4zG0HNjFCofkhO2 REnyOr56LuBrro9Ah7SKC+tFjlXLCY6Yy4X7oXDCoHaVxu9uOCxTaO+8rjoKmsRgDBYt BlYBqm6rMZ6pSOmhf2fCsX6BZICBWgoMScDpA4XtZhfnAEYuXUnUz+lrkPFiDX1MC7eB 5TsWkDiB1pvVFVa4GWR5lWQSeTANbdgTTTZMaTF6fMdQw/yBHhMyqlgzj/ItWOfj10jD Ebkpn92al1z8DQ+41Ej5CEGI19tOAwiK5ErMdc+k+DJnHsicUF2WI2TocMqDNSAgnFrf dCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y4fNrW4m; 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=pass (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 s14-20020a05620a254e00b006a339d370bbsi438012qko.338.2022.05.20.17.42.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:42:41 -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=pass header.i=@linaro.org header.s=google header.b=y4fNrW4m; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDCb-0004ab-1Y for patch@linaro.org; Fri, 20 May 2022 20:42:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Be-5r for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:54145) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbc-00040c-1p for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:43 -0400 Received: by mail-pj1-x1031.google.com with SMTP id f10so9289302pjs.3 for ; Fri, 20 May 2022 17:04:27 -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=fG9arG1tn4b444K5zf/g1JuzGuQmuRsUj+aiYfge+3E=; b=y4fNrW4mV30VJPIhWQcFoEZ6CNjNEhkQvJKPlw096guIJ6XndmFCod03U8J+mOWE9j 2m0kJ8jRTELGs/Ydev5vrbI1UBjSKOltsDKF/OCkk457C/mbdc3y22XOjOezQTl0nToe 76Q1o/XptqA9F7KQfYBybysTlvsdq77gRFfdwZy1FTACc9OiAQMXqnPN3rXW2+YLB2M+ zZs4+CHCmQHZWjC5s3M6rFmHDKacBpncU/Ib7zMyJACj73aV4p9URTEUauxy9WqG1Em9 F5+0jksT8dhW5qTmYKMXCo7VsU0sbjUniwF1oZY8YLcVd751A1UZ6+hjLJLaOps0d4dv twkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fG9arG1tn4b444K5zf/g1JuzGuQmuRsUj+aiYfge+3E=; b=ItACFJHVSDZtpoE1F7qaSyvJ3l4mNty3DGQ6ORQhct3+7y0buyOfrBxSODhCOqlhEX cXEDoLvDtWvkvtdDA5oqqOnVWmTJI2N5yNzGWzmFRb9luWwwwXO8H3PAv/DKnjwcEoA+ NTPgU3ZQcEUKCWTQS4EhUDdC26knaQLORkgtq9PdR+P5mv5lV6F3/59I4gSE3sx2qlc7 VUjhqzbxs1pEvHLYKKUJ9Vldqix/lwjHFOYC9kKh0UDQB93tSYrY8G5WDr0yQjhF4N6O JXQzRwi8LQto2IE8jTulByQCoyGgorFOcw85BNjwgRs1ehJ0od1X7NTjO65zdH24zU97 TIlA== X-Gm-Message-State: AOAM531tkcfuCHRu62uZJz5Vd+89ZLJZvU+7097/uwdOOOd87ac1bQq1 firlUKIXar7UUFde+WLkbqnONd57a94/sw== X-Received: by 2002:a17:902:e484:b0:161:6657:dc5b with SMTP id i4-20020a170902e48400b001616657dc5bmr12268974ple.2.1653091466679; Fri, 20 May 2022 17:04:26 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 21/49] semihosting: Use env more often in do_common_semihosting Date: Fri, 20 May 2022 17:03:32 -0700 Message-Id: <20220521000400.454525-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We've already loaded cs->env_ptr into a local variable; use it. Since env is unconditionally used, we don't need a dummy use. Signed-off-by: Richard Henderson --- target/arm/common-semi-target.h | 62 ++++++++++++++++++ target/riscv/common-semi-target.h | 50 +++++++++++++++ semihosting/arm-compat-semi.c | 101 ++---------------------------- 3 files changed, 116 insertions(+), 97 deletions(-) create mode 100644 target/arm/common-semi-target.h create mode 100644 target/riscv/common-semi-target.h diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.h new file mode 100644 index 0000000000..c20e1cca76 --- /dev/null +++ b/target/arm/common-semi-target.h @@ -0,0 +1,62 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H +#define TARGET_ARM_COMMON_SEMI_TARGET_H + +#ifndef CONFIG_USER_ONLY +#include "hw/arm/boot.h" +#endif + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + return env->xregs[argno]; + } else { + return env->regs[argno]; + } +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + env->xregs[0] = ret; + } else { + env->regs[0] = ret; + } +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32 */ + return !is_a64(env); +} + +#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.h new file mode 100644 index 0000000000..7c8a59e0cc --- /dev/null +++ b/target/riscv/common-semi-target.h @@ -0,0 +1,50 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H +#define TARGET_RISCV_COMMON_SEMI_TARGET_H + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + env->gpr[xA0] = ret; +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} + +#endif diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index c53cb1891f..9c6fe7ffd7 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -46,9 +46,6 @@ #else #include "qemu/cutils.h" #include "hw/loader.h" -#ifdef TARGET_ARM -#include "hw/arm/boot.h" -#endif #include "hw/boards.h" #endif @@ -182,96 +179,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #endif -#ifdef TARGET_ARM -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - return env->xregs[argno]; - } else { - return env->regs[argno]; - } -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - env->xregs[0] = ret; - } else { - env->regs[0] = ret; - } -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return is_a64(env); -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - return is_a64(env) ? env->xregs[31] : env->regs[13]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - /* Invalid for A32/T32. */ - return !is_a64(env); -} -#endif /* TARGET_ARM */ - -#ifdef TARGET_RISCV -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xA0 + argno]; -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - env->gpr[xA0] = ret; -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return riscv_cpu_mxl(env) != MXL_RV32; -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xSP]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - return true; -} -#endif +#include "common-semi-target.h" /* * The semihosting API has no concept of its errno being thread-safe, @@ -645,7 +553,6 @@ void do_common_semihosting(CPUState *cs) GuestFD *gf; int64_t elapsed; - (void) env; /* Used implicitly by arm lock_user macro */ nr = common_semi_arg(cs, 0) & 0xffffffffU; args = common_semi_arg(cs, 1); @@ -728,12 +635,12 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(cs->env_ptr, args); + qemu_semihosting_console_outc(env, args); common_semi_set_ret(cs, 0xdeadbeef); break; case TARGET_SYS_WRITE0: - ret = qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(env, args); common_semi_set_ret(cs, ret); break; @@ -764,7 +671,7 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(env); common_semi_set_ret(cs, ret); break; From patchwork Sat May 21 00:03:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574932 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2676808mab; Fri, 20 May 2022 17:47:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMvXqbfqC1uqtPaM0/2mPBET8iLUweebYchDydTwMEuHMYklAwyfGaFvFR1txq2OOL6phs X-Received: by 2002:a05:622a:44a:b0:2f3:b5b5:d42c with SMTP id o10-20020a05622a044a00b002f3b5b5d42cmr9602618qtx.30.1653094041580; Fri, 20 May 2022 17:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094041; cv=none; d=google.com; s=arc-20160816; b=C5HaUIP1j4PMyT/lF74o6t709ozQGilwFfQu9EeRssfngdz4gCTGS39bcXl1q6Ann2 zy6DKun5pmbuSCk4H3BvB3tDHRdAbLe6vzUlWL/ckf0RTS1nA7rU3Z/xhtsQ3geK1mUK Buy+kulFsvyCbFcIKq3Vmo29HSbEfIClaLC0dJQpYCXRNDE4XRLPBGnrFZrd2tixsf96 mVjtufPeE8jKJRl1cIrOIsFPTm7OF5fchKkkzxo2K9twzFOsRZaZFpf/SnRc/19ugpfq /RObI6ZkT/i03o12yjLvcaYlD6T5K+weyzmCZfP8cTBU5w1N/JKc7h0Xrn6xGfm2nN9/ D6wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Am6ZQ75YNAJ1iQQvd/m4L79xzkPVsPgjLxYKlB9VWSI=; b=TAF9WS7MEQGsaWSVgJ5FN/3Or/aERD4XDOFPdyRqFfn80reSFNPLcx8/JJwYkBG5Zu qazVErvAJB49Vd3xoQh7Hi1Nr/qJccQcUT7xbBybzLeRHuG+OYf9ICeA4LEn6QSXUpij meHrAXoQ94JTDDOJtMrPZwwR/EHmB0FWClaTc/9pfZBLPXLUeelp7WG+pNqB5OghazW/ KxxJ77RVlh1lycaN4/A6jFvzWNkXy52A45ssr/NSk0Zw7Cx1Nv4L522vCw7QGKgb6TPh qYSmx1vLNFpg92vn6KWdQdo2cvyB2Q4fMY0rdOJ39DQJ2CRVHWv63hAjEHq39MmNMU2V 415Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pM0NEPnq; 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=pass (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 e10-20020ac85dca000000b002f3db6df0dbsi336977qtx.595.2022.05.20.17.47.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:47:21 -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=pass header.i=@linaro.org header.s=google header.b=pM0NEPnq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDH7-00087e-5z for patch@linaro.org; Fri, 20 May 2022 20:47:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bd-5x for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:35814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbd-00040g-Mc for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:43 -0400 Received: by mail-pf1-x430.google.com with SMTP id c14so8985529pfn.2 for ; Fri, 20 May 2022 17:04:28 -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=Am6ZQ75YNAJ1iQQvd/m4L79xzkPVsPgjLxYKlB9VWSI=; b=pM0NEPnqVlRIMiHOsUggQ1EB89PmjqoQXvu4WzrCAGC6zcnef/odKzYWkJCjK5AL4W ojr8kXbxsWcAM8NurjLWmDUjW6yGgxsWBY9xySIbc/1lr9HuJOllL5WkI0j/r6vINPoK o1H/DFiAjgfCTByDLUKRVc8VlaVu2vF1QRdMqj07tZBMDJEhxBLBygtniT4vVCZ4vQ1j NpPjWkiMUbo4n7KzTkUCiRpjBmBhlFAImPj/qh0QslTfrCQgyilcbdxdVj3keUHC6gsJ CnNcCs/rpir83PNOuUpIke9L+OcJumi9tKptQxr5YCl82bRGiI3utTzn01caihcKjiBt 1v7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Am6ZQ75YNAJ1iQQvd/m4L79xzkPVsPgjLxYKlB9VWSI=; b=00TR/ysyfHFV80M9CcD8nfvyo728UN47dQt3kskRKbVQB0cSFCEss20HNo5SluE8A0 ncxoms5KT9blaDQJQYYHztk8HdYK/yDOLmhEXtR4MN2qetK/WNI2O5VUXF/9EVR6EAyp 0QX/F+hJLRsuun1IZCJLtoYKtXEPg3l9u+HHBVmCqGQyISPgVGIQn208nz9yaERi4mMy utGq9RKUjgWXEN7yf1VLYEkdMN0xB2eW5HTSTb334/oeEgb+JgI/4KZvL4Xq2tjL+W8L QD2z85QjN7xpG9WxBYh1xqV9yPI7nMq5UgSsI7CAdTP/eFu0XHwH2EenZuGU20e+HUFE gBvA== X-Gm-Message-State: AOAM532jXmgZMv1EeaTj8jdX6CReeBsA0zx/wXTBtKaQegyc11cuUHiL 4xCvXNjHdOsPebM2KVdRkUHCTJ8acniUeg== X-Received: by 2002:a05:6a00:1501:b0:510:7ab8:71c8 with SMTP id q1-20020a056a00150100b005107ab871c8mr12381316pfu.63.1653091467792; Fri, 20 May 2022 17:04:27 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 22/49] semihosting: Move GET_ARG/SET_ARG earlier in the file Date: Fri, 20 May 2022 17:03:33 -0700 Message-Id: <20220521000400.454525-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Moving this to be useful for another function besides do_common_semihosting. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/arm-compat-semi.c | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9c6fe7ffd7..7a7468799f 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -181,6 +181,30 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #include "common-semi-target.h" +/* + * Read the input value from the argument block; fail the semihosting + * call if the memory read fails. Eventually we could use a generic + * CPUState helper function here. + */ + +#define GET_ARG(n) do { \ + if (is_64bit_semihosting(env)) { \ + if (get_user_u64(arg ## n, args + (n) * 8)) { \ + goto do_fault; \ + } \ + } else { \ + if (get_user_u32(arg ## n, args + (n) * 4)) { \ + goto do_fault; \ + } \ + } \ +} while (0) + +#define SET_ARG(n, val) \ + (is_64bit_semihosting(env) ? \ + put_user_u64(val, args + (n) * 8) : \ + put_user_u32(val, args + (n) * 4)) + + /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -507,30 +531,6 @@ static const GuestFDFunctions guestfd_fns[] = { }, }; -/* - * Read the input value from the argument block; fail the semihosting - * call if the memory read fails. Eventually we could use a generic - * CPUState helper function here. - */ - -#define GET_ARG(n) do { \ - if (is_64bit_semihosting(env)) { \ - if (get_user_u64(arg ## n, args + (n) * 8)) { \ - goto do_fault; \ - } \ - } else { \ - if (get_user_u32(arg ## n, args + (n) * 4)) { \ - goto do_fault; \ - } \ - } \ -} while (0) - -#define SET_ARG(n, val) \ - (is_64bit_semihosting(env) ? \ - put_user_u64(val, args + (n) * 8) : \ - put_user_u32(val, args + (n) * 4)) - - /* * Do a semihosting call. * From patchwork Sat May 21 00:03:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574906 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2663020mab; Fri, 20 May 2022 17:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlbnCIS8XYGtF+8IQzWPw/3ifHOjAJ5ajMlOGcr3Ut9VA4O8hzS+aMwNeEoIXn13BZymbJ X-Received: by 2002:a05:6214:f26:b0:462:844:b06e with SMTP id iw6-20020a0562140f2600b004620844b06emr6792211qvb.34.1653092023906; Fri, 20 May 2022 17:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092023; cv=none; d=google.com; s=arc-20160816; b=zmbYiEwpCSA/QU1fgmhwGJcs8uTYqxttP2IZ0knhXpXHtrAOZw1LC+9OTGjlG90xVg E0XDPQzBei3IGiun2bNjkQxZJzrQyOXg7lpirVk/BrpDAiMHyq7yL2VQb9rMd36/YJJX rfWXPQfkxTcZUtenPLTwqIggZSUWsaJvqeVs5+VVHpyeAHEjv2P/TBqdq3DVlkdDhGpH WYuD52S6+Eog3h5pB/yjxVespOy/JMF5kKZ/ZMKi/CoYdz4GVwB6F/lGJmzvUUm97+0F lPpeh3ObwYucUDjp8wxeXQHLdMbBJYkvGnpbO68UXjXBgXp9bV/0cqFqhJ4ERn7MZBWU zgPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6hAoVCK1sUE0dO/zjjldEsyPEFjDE5oCQFS4JmN/6DY=; b=juOd+rZ+DdC9tciXopnwd3dXtGxApEge0An4J18CRTeq/VCqHL6ED8eCUtWHQfdzjB O6wxTmUixa1EF61rhvZICOWqo0BxnSARJVrTx4xuTcxKIbmFJ9xa0zbCJTEVqbPZ8/rP V21aXfbw8NoB9gX6ON79l501cCnatFgUEywK47sy/Sn1s6wQsHP/kMgR776+eozYY1m8 VR/KunQYygk2eRrzBYVWw8ytZrmFutRiFxOiJTgOOl14hPyi/wuBnUmQaHSI8lOE6rXi LnxHr1JiiNhdCbrY04SIdYd03Oc4+bHbvtksPDpu5Fnpv0ZMk9gzmngONtkJyD24Zj/H WrVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v+69l2cC; 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=pass (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 m2-20020a05620a24c200b0069fa2cc5332si425637qkn.167.2022.05.20.17.13.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:13:43 -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=pass header.i=@linaro.org header.s=google header.b=v+69l2cC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCkZ-0005NE-Ft for patch@linaro.org; Fri, 20 May 2022 20:13:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bg-6P for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:39846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbf-00040p-3F for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:44 -0400 Received: by mail-pf1-x435.google.com with SMTP id v11so8962912pff.6 for ; Fri, 20 May 2022 17:04:29 -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=6hAoVCK1sUE0dO/zjjldEsyPEFjDE5oCQFS4JmN/6DY=; b=v+69l2cCvQAdfDX/R1yN+n9+taTcMaMSYmNqQ5nXxi8uLGj6GeZMeLvsVfcgmaujB+ bFrlm2HciosurEuX1QP6Sud/7rgH0gwk+irO54rAkreLRCPPJp8mzv3qrn/yQfxEB468 whEyHf2f05OKOlKPRzdvd3fh7b9/ukN1h2mWWKNXMGwu160zfDyFICrZK4IcehsoGCF4 k4zwLP4PtPFgatuunp0Hw1rKkSNmTGaVcKpR0xuewe53A/AHbGMRR6OIUrrHvPdwhr2G LvZ0N4rojfrcmBrwbyTmNWblrwMAWOHU0CdVACbEQpvcQFFO3SCzHaSYgaa72P1YkAAB IAcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6hAoVCK1sUE0dO/zjjldEsyPEFjDE5oCQFS4JmN/6DY=; b=Z3quV50fcy0Cogf6HRljmZfhC/36eb1fakI2BEpw+pU30CYazqfOoSEbS9Dd0ttwmH o5ktpvo1noJvx9JEHgMpj+CP1GxpcfywBE3QItXpNBcCM+cYZvc99gbzBvt+ozKokqI9 vtRIrkZcFd18PM160AiiVKj8qYirpIy3cSICBvgt4s7FIeKCVxyhVWOWTHaV+G0jog8P miQoFjVBquY/xw2fKm4TiSZpOQoKzz31l95yTdK0MuY07AyKDgpaeR6m2A0gUIBDNL57 IpAoekB9q+HxU7x6T/6R7/y4bPsha5qFQ9vdYKZBoenaImtwr3sCDVlRIqDWko2zCDJG r0vg== X-Gm-Message-State: AOAM531sZ52YHf50C9Ac8DRQj0mYSp6StausJ9u2Ors6OZZCfsH19uBU yzQsBeWzRbwNvGIsICDkLyj2oSAxcbzUVg== X-Received: by 2002:a05:6a00:2188:b0:50d:b093:12a2 with SMTP id h8-20020a056a00218800b0050db09312a2mr12557298pfi.84.1653091468902; Fri, 20 May 2022 17:04:28 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 23/49] semihosting: Split out semihost_sys_open Date: Fri, 20 May 2022 17:03:34 -0700 Message-Id: <20220521000400.454525-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_OPEN to a reusable function. This handles gdb and host file i/o. Add helpers to validate the length of the filename string. Prepare for usage by other semihosting by allowing the filename length parameter to be 0, and calling strlen. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 25 +++++ semihosting/arm-compat-semi.c | 50 +-------- semihosting/guestfd.c | 5 + semihosting/syscalls.c | 186 +++++++++++++++++++++++++++++++++ semihosting/meson.build | 1 + 5 files changed, 222 insertions(+), 45 deletions(-) create mode 100644 include/semihosting/syscalls.h create mode 100644 semihosting/syscalls.c diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h new file mode 100644 index 0000000000..991658bf79 --- /dev/null +++ b/include/semihosting/syscalls.h @@ -0,0 +1,25 @@ +/* + * Syscall implementations for semihosting. + * + * Copyright (c) 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_SYSCALLS_H +#define SEMIHOSTING_SYSCALLS_H + +/* + * Argument loading from the guest is performed by the caller; + * results are returned via the 'complete' callback. + * + * String operands are in address/len pairs. The len argument may be 0 + * (when the semihosting abi does not already provide the length), + * or non-zero (where it should include the terminating zero). + */ + +void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode); + +#endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7a7468799f..cc008d0338 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -35,9 +35,10 @@ #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" -#include "semihosting/guestfd.h" #include "qemu/timer.h" #include "exec/gdbstub.h" +#include "semihosting/guestfd.h" +#include "semihosting/syscalls.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -98,21 +99,6 @@ static int gdb_open_modeflags[12] = { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY }; -static int open_modeflags[12] = { - O_RDONLY, - O_RDONLY | O_BINARY, - O_RDWR, - O_RDWR | O_BINARY, - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, - O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, - O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY -}; - #ifndef CONFIG_USER_ONLY /** @@ -284,20 +270,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_cb(cs, ret, err); } -static int common_semi_open_guestfd; - -static void -common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) -{ - if (err) { - dealloc_guestfd(common_semi_open_guestfd); - } else { - associate_guestfd(common_semi_open_guestfd, ret); - ret = common_semi_open_guestfd; - } - common_semi_cb(cs, ret, err); -} - /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all @@ -601,22 +573,10 @@ void do_common_semihosting(CPUState *cs) staticfile_guestfd(ret, featurefile_data, sizeof(featurefile_data)); } - } else if (use_gdb_syscalls()) { - unlock_user(s, arg0, 0); - common_semi_open_guestfd = alloc_guestfd(); - gdb_do_syscall(common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - break; } else { - hostfd = open(s, open_modeflags[arg1], 0644); - if (hostfd < 0) { - ret = -1; - err = errno; - } else { - ret = alloc_guestfd(); - associate_guestfd(ret, hostfd); - } + semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, + gdb_open_modeflags[arg1], 0644); + break; } unlock_user(s, arg0, 0); common_semi_cb(cs, ret, err); diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index b6405f5663..7ac2e147a8 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -11,6 +11,11 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" #include "semihosting/guestfd.h" +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +#else +#include "semihosting/softmmu-uaccess.h" +#endif static GArray *guestfd_array; diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c new file mode 100644 index 0000000000..a44d5cbae2 --- /dev/null +++ b/semihosting/syscalls.c @@ -0,0 +1,186 @@ +/* + * Syscall implementations for semihosting. + * + * Copyright (c) 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" +#include "semihosting/syscalls.h" +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +#else +#include "semihosting/softmmu-uaccess.h" +#endif + + +/* + * Validate or compute the length of the string (including terminator). + */ +static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tlen) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char c; + + if (tlen == 0) { + ssize_t slen = target_strlen(str); + + if (slen < 0) { + return -GDB_EFAULT; + } + if (slen >= INT32_MAX) { + return -GDB_ENAMETOOLONG; + } + return slen + 1; + } + if (tlen > INT32_MAX) { + return -GDB_ENAMETOOLONG; + } + if (get_user_u8(c, str + tlen - 1)) { + return -GDB_EFAULT; + } + if (c != 0) { + return -GDB_EINVAL; + } + return tlen; +} + +static int validate_lock_user_string(char **pstr, CPUState *cs, + target_ulong tstr, target_ulong tlen) +{ + int ret = validate_strlen(cs, tstr, tlen); + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *str = NULL; + + if (ret > 0) { + str = lock_user(VERIFY_READ, tstr, ret, true); + ret = str ? 0 : -GDB_EFAULT; + } + *pstr = str; + return ret; +} + +static int errno_for_gdb(void) +{ +#define E(N) case E##N: return GDB_E##N + + switch (errno) { + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(ACCES); + E(FAULT); + E(BUSY); + E(EXIST); + E(NODEV); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + } + return GDB_EUNKNOWN; + +#undef E +} + +/* + * GDB semihosting syscall implementations. + */ + +static gdb_syscall_complete_cb gdb_open_complete; + +static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + if (!err) { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + ret = guestfd; + } + gdb_open_complete(cs, ret, err); +} + +static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_open_complete = complete; + gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x", + fname, len, (target_ulong)gdb_flags, (target_ulong)mode); +} + +/* + * Host semihosting syscall implementations. + */ + +static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret, host_flags; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + if (gdb_flags & GDB_O_WRONLY) { + host_flags = O_WRONLY; + } else if (gdb_flags & GDB_O_RDWR) { + host_flags = O_RDWR; + } else { + host_flags = O_RDONLY; + } + if (gdb_flags & GDB_O_CREAT) { + host_flags |= O_CREAT; + } + if (gdb_flags & GDB_O_TRUNC) { + host_flags |= O_TRUNC; + } + if (gdb_flags & GDB_O_EXCL) { + host_flags |= O_EXCL; + } + + ret = open(p, host_flags, mode); + if (ret < 0) { + complete(cs, -1, errno_for_gdb()); + } else { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + complete(cs, guestfd, 0); + } + unlock_user(p, fname, 0); +} + +/* + * Syscall entry points. + */ + +void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + if (use_gdb_syscalls()) { + gdb_open(cs, complete, fname, fname_len, gdb_flags, mode); + } else { + host_open(cs, complete, fname, fname_len, gdb_flags, mode); + } +} diff --git a/semihosting/meson.build b/semihosting/meson.build index d2c1c37bfd..8057db5494 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,5 +1,6 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'guestfd.c', + 'syscalls.c', )) specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( From patchwork Sat May 21 00:03:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574928 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2673690mab; Fri, 20 May 2022 17:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1r0Oc7HdmKt0InfWZdG4L4KYZvaxhU3x2LWDsMBFYhBCX0kpzJQ1xwOOERdBvgfraphqO X-Received: by 2002:a05:6214:c49:b0:461:dace:171f with SMTP id r9-20020a0562140c4900b00461dace171fmr10041458qvj.98.1653093547213; Fri, 20 May 2022 17:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093547; cv=none; d=google.com; s=arc-20160816; b=f9topHlDP1qiSx0zZI8/coAsZz+fiISznSb2cfoCE72xI+O0++cZQwItfXFBdpTvR5 AD3zIvxjP0lXMAMV/sdA31CobbHcfeU3OthKhjT0tzTU7/BWX30BWJZNhjsBVes5PJSp TSL+JJHu+Mo+I3xBhA+S4xrKy+wi1MVOsP7lw4OJKvoCzNhGfIC0rMoVTboccIjxDFqF aVsdqe04ANXjJdNbjuVpWgA8uzQ6bnY0E1fuVT++XX2vNF/xAtITrLrBFkOnuSm6Y1Xe TXUZUcb8n5wjy+YublOmusYXjg3j6P+vLGqxyG9SgicqJLhEO7JB5DWKq45UIbaqhC8E iexg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7Ent/aGrN0lvBHhuu6zgeU6QjQbHaFQoY2hP0wODKxw=; b=HIv9b7zYBlR5ggsdKO0KtbBFTkF63yVLSh+0KiOd4Fm4zMSBAcFqOZ5Z7LoH4FYTRT 6guCPeNvmkKD+/SDReG6jrzoTELyPCDkEGP9lRjPafAgOSKNevFHRk8sgpRhP8oZcLCG cKbeJ6olseccFSF5PT/5qc5VLNsUJj7RwIxlysOhb/o3bkroD53OBqZQqMsa11O+w2w+ KiBCf4omsOcTuKheUErgPk3LwCk2Bz89UnawzHP2+IY4RS7d5A1U/K5oRgDFhx7IxRFg BlfxUJSiD2FYxiHyJa40FepjYqRUHb2Z4oYbLQHkXK+OAT0XVggcYPlsxTBw5Jz+VVeX HCEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CzQvSZ+B; 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=pass (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 s21-20020a05620a0bd500b0069c41fad5d0si440310qki.290.2022.05.20.17.39.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:39:07 -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=pass header.i=@linaro.org header.s=google header.b=CzQvSZ+B; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD98-0001R6-Rd for patch@linaro.org; Fri, 20 May 2022 20:39:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bf-6K for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:57 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:35563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbf-00041H-DZ for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:45 -0400 Received: by mail-pg1-x52a.google.com with SMTP id c22so8996744pgu.2 for ; Fri, 20 May 2022 17:04:31 -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=7Ent/aGrN0lvBHhuu6zgeU6QjQbHaFQoY2hP0wODKxw=; b=CzQvSZ+B6ttbnIcVRnOJTxfxWy7nxbtBLyYH2JAXZB40nNQ0paBc+V1je1fyJuC54L ukf+XXT4WNPbncgKcUfyEdjRVemfcAL7x0cq6zK0h662LMHroP6TTf4i2BGm0Af562x7 WC39T4152Ob+NtLT2mleZH2ko+D1klJNzEjKM7g6ynZYpvRlFeDMEDF1LF96yqTmFDgU hb+IXTSxip/mjJrG0WvQ6nZEgJtLh5CS9TDZXZjvEyIFBuSLLg3rYcKjzY6QSp5ybWOn 9IvJH7uSAHhrkEXeUCoLkw2sQwJpxYh3XAzzTL30pA6Yx4SuCDCnZtgTeBYhckeRGnR0 05yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Ent/aGrN0lvBHhuu6zgeU6QjQbHaFQoY2hP0wODKxw=; b=GLFrmGta97m39pb55FU6psQyEipg9D5YCyZBBCEzKCFv/a+3DLuOXaGWHN3kbf3DaN S2VG6JINv2puE9q3M5aD7ZItw6LEYTiSkTWA4A5dRdkEvRoFDVSIqjfxgeuhXvRz0pvF oJpKjjQ+96cbw8cYeg0t9OOj1RxdY4dK19X63dPT3CjxXeC256zZHCDrtorZMeWPUmNV jsLVL+y7kS9QHZiGXsS+R+y9OFr15afFEYnwmV8s6VJkbb9hbTPokFKelV9kKHWAPPRc VzepcDIWzM0GAKMgSAjo1oLviMJIpCy1cmmGqNlruA+Iem9hzPjC0gnZ+nkE6VHGF1tH yPKA== X-Gm-Message-State: AOAM531NI30Oodcv7WIdxMeyFPreQf8pSRyCXWEBRPiw9QpTrVC2x23F ehxIa02mHMXEm9ko8GKEUxztUXan5y672Q== X-Received: by 2002:a63:dd09:0:b0:3f2:804a:cf11 with SMTP id t9-20020a63dd09000000b003f2804acf11mr10517982pgg.621.1653091469891; Fri, 20 May 2022 17:04:29 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 24/49] semihosting: Split out semihost_sys_close Date: Fri, 20 May 2022 17:03:35 -0700 Message-Id: <20220521000400.454525-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_CLOSE to a reusable function. This handles all GuestFD. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 41 +---------------------------- semihosting/guestfd.c | 7 ++++- semihosting/syscalls.c | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 991658bf79..00e718f11d 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -22,4 +22,7 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, int gdb_flags, int mode); +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index cc008d0338..9bb80c3286 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -276,7 +276,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_closefn(CPUState *cs, GuestFD *gf); typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); typedef void sys_readfn(CPUState *cs, GuestFD *gf, @@ -285,23 +284,6 @@ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_closefn(CPUState *cs, GuestFD *gf) -{ - int ret; - /* - * Only close the underlying host fd if it's one we opened on behalf - * of the guest in SYS_OPEN. - */ - if (gf->hostfd == STDIN_FILENO || - gf->hostfd == STDOUT_FILENO || - gf->hostfd == STDERR_FILENO) { - ret = 0; - } else { - ret = close(gf->hostfd); - } - common_semi_cb(cs, ret, ret ? errno : 0); -} - static void host_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -362,11 +344,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_closefn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); -} - static void gdb_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -414,12 +391,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_closefn(CPUState *cs, GuestFD *gf) -{ - /* Nothing to do */ - common_semi_cb(cs, 0, 0); -} - static void staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -468,7 +439,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -478,7 +448,6 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .closefn = host_closefn, .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, @@ -486,7 +455,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = host_flenfn, }, [GuestFDGDB] = { - .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, @@ -494,7 +462,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .closefn = staticfile_closefn, .writefn = staticfile_writefn, .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, @@ -585,13 +552,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_CLOSE: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].closefn(cs, gf); - dealloc_guestfd(arg0); + semihost_sys_close(cs, common_semi_cb, arg0); break; case TARGET_SYS_WRITEC: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 7ac2e147a8..e3122ebba9 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -49,6 +49,11 @@ int alloc_guestfd(void) return i; } +static void do_dealloc_guestfd(GuestFD *gf) +{ + gf->type = GuestFDUnused; +} + /* * Look up the guestfd in the data structure; return NULL * for out of bounds, but don't check whether the slot is unused. @@ -119,5 +124,5 @@ void dealloc_guestfd(int guestfd) GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDUnused; + do_dealloc_guestfd(gf); } diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index a44d5cbae2..9c4b635317 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -124,6 +124,12 @@ static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, fname, len, (target_ulong)gdb_flags, (target_ulong)mode); } +static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); +} + /* * Host semihosting syscall implementations. */ @@ -170,6 +176,23 @@ static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, fname, 0); } +static void host_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + /* + * Only close the underlying host fd if it's one we opened on behalf + * of the guest in SYS_OPEN. + */ + if (gf->hostfd != STDIN_FILENO && + gf->hostfd != STDOUT_FILENO && + gf->hostfd != STDERR_FILENO && + close(gf->hostfd) < 0) { + complete(cs, -1, errno_for_gdb()); + } else { + complete(cs, 0, 0); + } +} + /* * Syscall entry points. */ @@ -184,3 +207,27 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, host_open(cs, complete, fname, fname_len, gdb_flags, mode); } } + +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, GDB_EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_close(cs, complete, gf); + break; + case GuestFDHost: + host_close(cs, complete, gf); + break; + case GuestFDStatic: + complete(cs, 0, 0); + break; + default: + g_assert_not_reached(); + } + dealloc_guestfd(fd); +} From patchwork Sat May 21 00:03:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574911 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2665633mab; Fri, 20 May 2022 17:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKWyKbVFPVs1fQNiHgGbNvn9K1hrNt1p2m3DgIbjBIgghTLCGTEBP0z6DnHppLeo7bsx2S X-Received: by 2002:a05:6214:29c2:b0:461:ca26:7ecd with SMTP id gh2-20020a05621429c200b00461ca267ecdmr9970455qvb.32.1653092405415; Fri, 20 May 2022 17:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092405; cv=none; d=google.com; s=arc-20160816; b=soHe9jG1TpCnZZbcN6Ouods9TbFwnaGhXMwyYHwOXFX1rohpmAidW7PNSV9P1P++WX 8+rZiZmkpk6rE8G3tapF2z2d/4m0AyKWJHT8HLnd0NctLj758w0RbyISRKyYsCiYjGJ0 OyD5suRNAf/YgplawaRRgP3ApSOS7WGfkqPyP6ZyOz6xgF/6bTnbLrqTg5MYRSYBf3FV goLovs6jaGsihxqeMjRkfw1eQP2BznAUiZgOPGeVewVoZ+fNJkG4exI/KPQTCkGJDkRZ 1Scvyfobo3ooytjAfel+42LzUVRpJ6RLKCF+9hh+NdJT3IN/dPwE9WFQJyAy5BsYNa1j upIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ei4oX9gqsxpF/TVtJUIb1bHkWuBeEJNDM94QCzd9LJ4=; b=XYukohlicTpHYU2oyCZCKXGRH/LwpscBRyIGOorMYxUnapZQwySLPhobpbPW8Y/Bnl vSPnwaH4LuXhQCFvZrN2bDcz/zSJrkRJWbRs2aKVPfOaHmGx9OS1BFHHEe8vzpGiRqtf AJs0u/2N5RLhF22IA059FuT44ILpzoMtoVTcmB3M61gSPtGDH+jU0xls7/W8yVKSKBHA mDRi7Y6FhhubcvD6JBOQcqoySYzbWlyacTwwpLZRhQoviTvv/V0uMLAqeCEBgWX8KC1B MXuPWIQi5wGri56edywmsI8aH3VU3EgEy2wdtT4enl/qnL2P6ZVwyRx6Sze/BLa9p7M5 f/wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Eag+0nVB; 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=pass (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 g14-20020a05620a40ce00b0069f23ff9055si468624qko.14.2022.05.20.17.20.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:20:05 -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=pass header.i=@linaro.org header.s=google header.b=Eag+0nVB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCqi-0006WO-VC for patch@linaro.org; Fri, 20 May 2022 20:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bk-HR for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:58 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:39835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbg-00041U-Qn for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:46 -0400 Received: by mail-pf1-x429.google.com with SMTP id v11so8962963pff.6 for ; Fri, 20 May 2022 17:04:31 -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=ei4oX9gqsxpF/TVtJUIb1bHkWuBeEJNDM94QCzd9LJ4=; b=Eag+0nVBHWwCz8ZDdVr7CyeE5pzFjAuorcxO4kplDryH/a0Gq7ecLSTZoau88ZCJxO ARl1eiSbejANUv/EzASkwR2zHn2CaRNENCwIhbS91PK+jCYAAA9KIu+3nVTWqrzNE/sa sRKXxtlVQXcZe+5ot44qoMy56PvnYCh9NUDcCrkDYsGCRiLXQoQ6RIlvTs/DFRJmds8Z +OWfcDE9FmVTuA3nnbEb6BdeO+rBRZ+IoqDd9yY8wCsLHPZrHM/wY3p+2i+TRLvnehtt 8pfc6SlrOufPW5S/RIhb3wGi403KjazSnYP1xb8g8bdH1WsB5E1wXdCPk6MNG1nx6TTl cSOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ei4oX9gqsxpF/TVtJUIb1bHkWuBeEJNDM94QCzd9LJ4=; b=P1IomwjgyFM3G/FzEYl9acyp8vXeABpnmqYD30KjREF0WnNEfw8cxD8gVE4L2jLSw3 3v44ygWA96uvCR4WPp8hrWBXcODG919eEwfKqQszpRkv5hOoi8BmgnmmxHvLj3VZtlFj t6i1HzCoTODFo+SX2xiNVupQlvUgLJVFmSsLZeLeAhE+gFH0u4QjQBZKz3aEHBs/TUAA pmkwo1rRP1xKHd7gXCvckZTSshjeiBvcDFPuj++GKMkX39gTKZ42es6I8RIgDxjGfv+M 9EC3jlZcx9zH6JMV/ha5V7X9su8yzM3xFcFZeNXjkRkdHqH22TPvkjGjafCWUQnbUH+T cHSw== X-Gm-Message-State: AOAM530GpWnzrkb5Eu8BfkBDKK+4h3xmw6UGVdGLEpvmpc7N89Om7Mne dSihWDKCQ0dzC4GBweYkkCJ0JnKgMxRq8w== X-Received: by 2002:a05:6a00:23ce:b0:50d:823f:981 with SMTP id g14-20020a056a0023ce00b0050d823f0981mr12858909pfc.10.1653091470765; Fri, 20 May 2022 17:04:30 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 25/49] semihosting: Split out semihost_sys_read Date: Fri, 20 May 2022 17:03:36 -0700 Message-Id: <20220521000400.454525-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_READ to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_rw_cb. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 8 ++++ semihosting/arm-compat-semi.c | 85 ++++++++-------------------------- semihosting/syscalls.c | 85 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 65 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 00e718f11d..20da8138b0 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -18,6 +18,8 @@ * or non-zero (where it should include the terminating zero). */ +typedef struct GuestFD GuestFD; + void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, int gdb_flags, int mode); @@ -25,4 +27,10 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + +void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9bb80c3286..5e4101c6a7 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -231,7 +231,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: - case TARGET_SYS_READ: ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: @@ -244,6 +243,25 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * SYS_READ and SYS_WRITE always return the number of bytes not read/written. + * There is no error condition, other than returning the original length. + */ +static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + /* Recover the original length from the third argument. */ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong args = common_semi_arg(cs, 1); + target_ulong arg2; + GET_ARG(2); + + if (err) { + do_fault: + ret = 0; /* error: no bytes transmitted */ + } + common_semi_set_ret(cs, arg2 - ret); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -278,8 +296,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) */ typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef void sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); @@ -302,26 +318,6 @@ static void host_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, len - ret, 0); } -static void host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_WRITE, buf, len, 0); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - do { - ret = read(gf->hostfd, s, len); - } while (ret == -1 && errno == EINTR); - unlock_user(s, buf, len); - if (ret == (uint32_t)-1) { - ret = 0; - } - } - /* Return bytes not read, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -351,13 +347,6 @@ static void gdb_writefn(CPUState *cs, GuestFD *gf, gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static void gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -398,30 +387,6 @@ static void staticfile_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, -1, EBADF); } -static void staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t i = 0; - char *s; - - (void) env; /* Used in arm softmmu lock_user implicitly */ - s = lock_user(VERIFY_WRITE, buf, len, 0); - if (s) { - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; - } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; - } - unlock_user(s, buf, len); - } - - /* Return number of bytes not read */ - common_semi_cb(cs, len - i, 0); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -440,7 +405,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_writefn *writefn; - sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -449,21 +413,18 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .writefn = host_writefn, - .readfn = host_readfn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .writefn = gdb_writefn, - .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .writefn = staticfile_writefn, - .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -582,13 +543,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READC: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 9c4b635317..7c18f77898 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -130,6 +130,13 @@ static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); } +static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + gdb_do_syscall(complete, "read,%x,%x,%x", + (target_ulong)gf->hostfd, buf, len); +} + /* * Host semihosting syscall implementations. */ @@ -193,6 +200,54 @@ static void host_close(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_WRITE, buf, len, 0); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, GDB_EFAULT); + return; + } + do { + ret = read(gf->hostfd, ptr, len); + } while (ret == -1 && errno == EINTR); + if (ret == -1) { + complete(cs, -1, errno_for_gdb()); + unlock_user(ptr, buf, 0); + } else { + complete(cs, ret, 0); + unlock_user(ptr, buf, ret); + } +} + +/* + * Static file semihosting syscall implementations. + */ + +static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong rest = gf->staticfile.len - gf->staticfile.off; + void *ptr; + + if (len > rest) { + len = rest; + } + ptr = lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, GDB_EFAULT); + return; + } + memcpy(ptr, gf->staticfile.data + gf->staticfile.off, len); + gf->staticfile.off += len; + complete(cs, len, 0); + unlock_user(ptr, buf, len); +} + /* * Syscall entry points. */ @@ -231,3 +286,33 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) } dealloc_guestfd(fd); } + +void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + switch (gf->type) { + case GuestFDGDB: + gdb_read(cs, complete, gf, buf, len); + break; + case GuestFDHost: + host_read(cs, complete, gf, buf, len); + break; + case GuestFDStatic: + staticfile_read(cs, complete, gf, buf, len); + break; + default: + g_assert_not_reached(); + } +} + +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (gf) { + semihost_sys_read_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, GDB_EBADF); + } +} From patchwork Sat May 21 00:03:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574902 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2661921mab; Fri, 20 May 2022 17:11:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydlW3vMoLsLygPzAFyM9bX5Ans4EUB0s5y/fok2Q2KVLSifjdJzyKPaubLnq63K6hgrotL X-Received: by 2002:a05:622a:178a:b0:2f9:2257:69e3 with SMTP id s10-20020a05622a178a00b002f9225769e3mr2897868qtk.568.1653091898168; Fri, 20 May 2022 17:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653091898; cv=none; d=google.com; s=arc-20160816; b=eZ8sa+AX58Xc3JW7zOwqygkRuzbphX/v/H8puGle8NxglhwSumTu04t7ZOY2j3QvpX 4T8JC4UcajYSGRl0ZQ9cFzFGQAknODxLoavoZjkzQYnKRVF8Y6Om1qvNV6vh+1pbokuO 3hOBaMWLQlgIpFjJEvrvQ3l7TmhID2iL7LDj1H/nLVC0qUOZQhrV+Vh9d0BhMVCyB4Zc On0DfzHWGuo84l3zyC40rUicLAPJzvATomZ4JKu7uJti3UGUqumYUCF6je4nrYGx22cU A4F0O5n+P/B2GHW+Spk8s6PURA22TrzJq24yOvz6wBIWuayGvdJ4S0v50CivJAKtxU00 OuGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tgVRADqR9B5grnNVu8mA4b/Up+ANot4pk44Zo7iuCRQ=; b=JY03SYf45yF25r8SGrzjK4JsiLiChuVJJrpRa6nk0RvhwL2ipViwuivXFkfioR10/l O2Ir1L/GEZgeWFcSDSqQ2xUYUXJDk44TY6hbCuaEn2c06rPQRz77xEysDgzWdBSiC/Q3 GOHxAdw5c6ogkviV1pJtqmoV3wjPgDCvOqcMKd8ypjbmDvZBDKNU/DPv3vxT7k7glrfH oA6sn8cZYFSQuFc4V+2EaFfWQnlJhPIzN4F8xpLjU7QPacZ6zfuOAygIANvoI1bpqUsn VQJDNlkuAXhAD90dDgpwzgHYlm3eib8m8aYHzk01c/BuFxeiNQ/KLk2fYxQnZllq/x0S quUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TV6pjn+8; 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=pass (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 i13-20020a05620a248d00b0069f7490d35esi441004qkn.116.2022.05.20.17.11.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:11:38 -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=pass header.i=@linaro.org header.s=google header.b=TV6pjn+8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCiX-00087x-OV for patch@linaro.org; Fri, 20 May 2022 20:11:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCbw-0008Bj-GT for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:56 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:46592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbg-0003z2-RD for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:46 -0400 Received: by mail-pg1-x529.google.com with SMTP id j21so8768982pga.13 for ; Fri, 20 May 2022 17:04:32 -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=tgVRADqR9B5grnNVu8mA4b/Up+ANot4pk44Zo7iuCRQ=; b=TV6pjn+81ArueSqW6Xzf2F845lAzmHMJaHhlZTBRl1LxzOwBwys4Qx9Li4zX36Pk08 RrfN0S+i2bMtF4nAwq/pyA2gqlDWS12Sv/uJ4UQSM4guuvKI0qhrkP74fMPbxrzVhkr5 z9vh2DjiXtRRTYxDHc4uYgL7ud5Ywu9omQEJdiK1IEIm2Mxyr2vryD4HU5xI3JpcvaMd g1meOcQt7xx/Bo178J5OI3Tn2L16vIqzuTGTVkqGAdSm5cQUkPzSjQYqRfF9s7LSYk0g zdn1NRqkFTrZrdBgaIW5DmR1YuKMBBvILfb4Hax+opH5PXXIWuLllJnh/AX6MYMLYd1L /IUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tgVRADqR9B5grnNVu8mA4b/Up+ANot4pk44Zo7iuCRQ=; b=YlmgCxTFLeSqoqRuGth5TrlH0BbwcOEyueGtMbB4lpIrFInECYAuUfgmyrL08cDT+z +xYnJ9TWN3COwI6z3ZoYZ7p68xDERcV/gfVk9D7+gnB0TLBkpYMaZnBMWz5UjMURGbZU 2WsULXwIkH+fMdGMRDYMrHj1hxojvzOp06CmiONHhDrHqyqosyL+N0shwqd7G22uYTgq 8WM2KI5YeYnn+KQFfMy7TvaIVR8wH1q6rz2NpxB2Xv1WTGPBC8lT1MDwtfwkMZSWmYYp 0g1TgwKg5Li8AlYij5I4DQcOG+o4T23wkbobGsmxmM0oX5/Gyj/Zs8u3Ue9ij19/qam1 88XA== X-Gm-Message-State: AOAM5302uh0z6dIM84IS31ZuwxAKH4CTq7MK4Bn7jQUpZSRjU7mWCx4n k/YK0Up5RcF/79SPGoKyKWeuhupZTBBiug== X-Received: by 2002:aa7:92d2:0:b0:518:4929:e4cc with SMTP id k18-20020aa792d2000000b005184929e4ccmr9053431pfa.37.1653091471768; Fri, 20 May 2022 17:04:31 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 26/49] semihosting: Split out semihost_sys_write Date: Fri, 20 May 2022 17:03:37 -0700 Message-Id: <20220521000400.454525-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_WRITE to a reusable function. This handles all GuestFD. This removes the last use of common_semi_syscall_len. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 6 ++++ semihosting/arm-compat-semi.c | 52 +------------------------------- semihosting/syscalls.c | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 51 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 20da8138b0..2464467579 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -33,4 +33,10 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len); +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + +void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 5e4101c6a7..1238b81e0a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -215,8 +215,6 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static target_ulong common_semi_syscall_len; - static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (err) { @@ -230,9 +228,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) /* Fixup syscalls that use nonstardard return conventions. */ target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { - case TARGET_SYS_WRITE: - ret = common_semi_syscall_len - ret; - break; case TARGET_SYS_SEEK: ret = 0; break; @@ -294,30 +289,10 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_READ, buf, len, 1); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - ret = write(gf->hostfd, s, len); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - } - /* Return bytes not written, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -340,13 +315,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -380,13 +348,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - /* This fd can never be open for writing */ - common_semi_cb(cs, -1, EBADF); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -404,7 +365,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_writefn *writefn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -412,19 +372,16 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .writefn = host_writefn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .writefn = gdb_writefn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .writefn = staticfile_writefn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -449,7 +406,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - uint32_t len; GuestFD *gf; int64_t elapsed; @@ -530,13 +486,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READ: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 7c18f77898..db4561b798 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -137,6 +137,13 @@ static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, buf, len); } +static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + gdb_do_syscall(complete, "write,%x,%x,%x", + (target_ulong)gf->hostfd, buf, len); +} + /* * Host semihosting syscall implementations. */ @@ -223,6 +230,22 @@ static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_READ, buf, len, 1); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, GDB_EFAULT); + return; + } + ret = write(gf->hostfd, ptr, len); + complete(cs, ret, ret == -1 ? errno_for_gdb() : 0); + unlock_user(ptr, buf, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -316,3 +339,34 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, GDB_EBADF); } } + +void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + switch (gf->type) { + case GuestFDGDB: + gdb_write(cs, complete, gf, buf, len); + break; + case GuestFDHost: + host_write(cs, complete, gf, buf, len); + break; + case GuestFDStatic: + /* Static files are never open for writing: EBADF. */ + complete(cs, -1, GDB_EBADF); + break; + default: + g_assert_not_reached(); + } +} + +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (gf) { + semihost_sys_write_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, GDB_EBADF); + } +} From patchwork Sat May 21 00:03:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574910 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2664665mab; Fri, 20 May 2022 17:17:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvAnbH4+Xne9DFQ3iLEUi0RvP826w6RwsV+ttnYhxZuodJvL2zRgsQNGAwBAIgWvWOutNd X-Received: by 2002:ad4:5dcd:0:b0:461:d36b:500d with SMTP id m13-20020ad45dcd000000b00461d36b500dmr10063575qvh.106.1653092249085; Fri, 20 May 2022 17:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092249; cv=none; d=google.com; s=arc-20160816; b=wxO6tO3qn7++4t2mw3R4WO7Au2ztDEnaOSpWyBjby+TRbLbxxr7pRUeTkRhqvV9+xZ LzyHrlItQOxrkRE0nARtxk2cKZpsdSHp7ZZB81GIiImI7obda6afsmzr9eF4C4N149K1 toQDu2cVp+KdqcQ2tTU43AIpOg7myIvB8cxIBXRnz/2o5sNx1I+jj3L7H9YYwRrGHEvL ovuzd3Nt3Tfrv++unvDPXaLbW01jVSOQrbTg4bszAnoKBg/Rt4MwDc4thCH38uUQ72Ev luN89IjPHNuYlPzpjDGHb3E7PtzYgtDYFh4E8mmCabV3UyhBdoMnJpxmqt0U20YlI1FR pXwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=UeTcSG7NyZ5U+naZ6H+iiA59VeERiPu/Nsv5I8602QD4aJlraDJmDRRNJeSrKGuTR/ 9D7QDHUKdMh0Gw71jbhnvN2cHIeMfB4bPK2tw0pIqZ+dfS5I36fuX6CAdPCPHwoGkof7 AKEBQBu3ZZbT7l32keh+NEHSdDg2ofYxD4YmQOqqj2j9K0UVFebfAE0ETdGwweL0WDDN 4QQxN7kRuh7uQtxJUZEjKjUz0rHIz48o38iax/e8YX78VCvPUpEKj5iq4O1Ewkc9Xyyf l0c8BIENWBHUC3I28p5CkpW2Zc4/OWFsjF1pK/SW2+La2NgyYu7rXlTSYre3I8TO3E8m /RLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="s/NfPqqp"; 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 de40-20020a05620a372800b0069f58643a5fsi391177qkb.356.2022.05.20.17.17.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:17:29 -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="s/NfPqqp"; 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]:54442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCoA-0002k0-Vb for patch@linaro.org; Fri, 20 May 2022 20:17:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCby-0008Br-VW for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:58 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:40469) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbj-00041j-3F for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:47 -0400 Received: by mail-pj1-x102f.google.com with SMTP id nr2-20020a17090b240200b001df2b1bfc40so12734090pjb.5 for ; Fri, 20 May 2022 17:04:33 -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=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=s/NfPqqpeOn3O/J4L51i5NZGR4f6C6PYyojESAYY9uyaQVYt109ZOk4SCfUqN/sP0R JIorlGPVoDG7rii9XEBdLW7mCuf2VFN2Gm65qQbJninq00BL3ih5pIgjUZdRz7OtigHq LoTsqfvneID9o1N8Mwj742RK1e7S725zkO5j3UWrA5op/KwYzLsAvvHiFbz38pqg1opc iYsC/YSypTw82OxXDbJgcf0G79eXJpgVR5HmGxNw/J5/2/6ElHimfx/XgbBQKF/XZEgt R7HpkvJm6FLu+Y43LASgX55BCx0ATEuPe8kYlFj7KVCkZQ3nXXVWGmo5gndDzsDuvMkY I5gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=n96m8AXts9APaG9ZKqWSBq6eox4zyn4RahHhTg56zxfEyJbus8cEjNt4LXGqn5cVfY upNWsRB0wqhfeStTpJp0MkP1YU+yvrQkuSgK9IjZHUgWlURUR88TSqJkbnhxhWJoMLeL ElNUSSapwjXbMm49NgBRnVChBQmnJsFzqp/xTCVblrnTshwtKxKufsy/vrFj4XMB2Njt CCN3mOXCGqpISXrpW7JXqZ/P1gvb6W/h6Jr0MvHwmHd1tixDXhuDUxpz+MYKFmOu6K81 N+5luPXX2K9zcvWqIp3ejOKeDQhQfL7hg41LOlVnf2aa7nTNo5nLf2IyH1qyjOx52Bvm i/uQ== X-Gm-Message-State: AOAM533j3aUHJg6gBGMDcibWT8Ffs1O87fqRS8gMwLxoF4uV3Zv+yEm6 Wr8J3oEoVA8IZsP4MU7AWbOHTcJyzgq9wg== X-Received: by 2002:a17:90a:b001:b0:1dd:30b9:1a45 with SMTP id x1-20020a17090ab00100b001dd30b91a45mr14440067pjq.132.1653091472783; Fri, 20 May 2022 17:04:32 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 27/49] semihosting: Bound length for semihost_sys_{read, write} Date: Fri, 20 May 2022 17:03:38 -0700 Message-Id: <20220521000400.454525-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Fixes a minor bug in which a 64-bit guest on a 32-bit host could truncate the length. This would only ever cause a problem if there were no bits set in the low 32, so that it truncates to 0. Signed-off-by: Richard Henderson --- semihosting/syscalls.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index db4561b798..a5623ebf0f 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -313,6 +313,14 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len) { + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_read(cs, complete, gf, buf, len); @@ -343,6 +351,14 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len) { + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_write(cs, complete, gf, buf, len); From patchwork Sat May 21 00:03:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574913 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2665810mab; Fri, 20 May 2022 17:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuJG6Xvpf58piIfJsuNR13nZhEW+pFaLqdLg4HqF8vDWfF+CA5/biusYuTuvK1cAk6JSQw X-Received: by 2002:a05:620a:2681:b0:67e:95f2:7ce2 with SMTP id c1-20020a05620a268100b0067e95f27ce2mr7756589qkp.223.1653092432509; Fri, 20 May 2022 17:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092432; cv=none; d=google.com; s=arc-20160816; b=hSmKu3AdisoZaRa8CBM7rVudHlVajFijrXN+JCPVNhQnbRrd7MV7D55rdkhaMbUO1+ WBJHLmLstIHEeNE5iAR8MlcuJ+6g+MIYdf5dVPTekk435PJRXdasy/yKuObIHKH8CPlW yRkY99J+anpUCKhzZY7TEynVoukin2Zq4YKlSAOjA/Zop3XXg4jbPw7DahTylWvnGpry W9CXToq64ioYUD6pzN807aWnlKU3kAj8YZx9pWc9rsU6bKRtdGnSVhQPwkzt/I5yi0kD JkrjzTqlygqjQNId+DjgzCH2I9dwID6Q2955Qk7f1f17RnnHd+DNbQkz0oVUXcrq88vz lKEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ISYOLSXdDLADD2AwvTBEZ0VMRY6JVLGtKafBn7ec4+s=; b=UevS4zLUQLbn12IsuJMuwCtLZzuh2lji3DIijDNrBqSEgz2yB9R2jWsLq32cJamCYa Dxk4kZTRQjI9eimgtZJC1/UeEe/9ptbtG1ZJLWw04Z1iVJEW88ti0rx9M6rW4lw48f4i inh7r08c5Ez4oqIgRJZyzJHlZEd71uC47WpPDdJPO2Rz69MOlinx264xvWeH1xQ1vhVw pVI7bGEzZaofIVyjAbB424TTEwoV9LGye9Z24vjh8IFCv/6AnlTpr7aUawpzlthTY2Vz FFP9gUoUiDBtnME6ylJCFMksHw0RLK6xOdvPI5eZQ2+sB5qYwWk77u4FjG/V1T9yeJKi EKyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MNJ9QV4E; 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=pass (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 o127-20020a37be85000000b006a35ac129b7si332372qkf.527.2022.05.20.17.20.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:20: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=pass header.i=@linaro.org header.s=google header.b=MNJ9QV4E; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCrA-0006f1-2J for patch@linaro.org; Fri, 20 May 2022 20:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008C9-Du for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:46640) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbj-0003yF-Jq for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:48 -0400 Received: by mail-pl1-x636.google.com with SMTP id w3so1941669plp.13 for ; Fri, 20 May 2022 17:04:35 -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=ISYOLSXdDLADD2AwvTBEZ0VMRY6JVLGtKafBn7ec4+s=; b=MNJ9QV4EFeDH4tRwbtYbn9iGiPnDJ3M8GP4qsIlG/d1qRg4UOyu0dXAWwlO/t+bcnz ERoUAcYpHSyo4PkLEzxL8UFQTBrI2KE5eHzsayoTjtNTAyNc14j9Mj+hc4zyAF914whJ QwS3m+lTVN40+Gqi+/pO/vGDM8x2bs1OKIe85RXiYb+8xHKZnvKjhFhzS7AKZy06uo0b eOlmTfu95/14JBtPf7hk/lqrcjjmZ/JUlejLtLBNnImVkdMY0PxPtOh4Zt7qicrccWmm EZ4d2a0LaJwSIRckHoPzHequY91NecjrFqnr6fsaUMETVwzyQwQoIx5bT/PEAgXAyKuk ZAbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ISYOLSXdDLADD2AwvTBEZ0VMRY6JVLGtKafBn7ec4+s=; b=prtSAVa9jiQhNTWemra/HQEg2//FkePD05qqVavfuqWBZ61KcMk2colOgsAzKcJOq7 XcTi7Z8BMeHrgxy9tot97zmJbBeR3nSSwENYW4Y6xqzCWTDpJSZwpujHkGVAkwVtCALt XpBHvdM4diZhLt2okt5rlVvBY3nmOUrVwh25f6TvSAkIum7qlcE2SmJUnXo3O/oKscX1 yLxrIKSgvP1gC8ATKDgqclKG2gbXyAOOU2Wum02ti6rIfYohjixtk3LP7QXxxDHSMPO1 Tv4VtI1nmxmGbaJKy33LDts0VAftM1YO1TfvIK6agjPuNshOZStZoIYFWeRYIRmVLRlN h5vw== X-Gm-Message-State: AOAM533M2LC03SFIISYIS3pOmWXqpp1rwE4Mdjmy/tGRnDbWQ55q5bzt 0C5v0q0/gE5e1UfNIymVue48CN4BxRGoJQ== X-Received: by 2002:a17:90b:1c8e:b0:1dd:24f3:c6f6 with SMTP id oo14-20020a17090b1c8e00b001dd24f3c6f6mr14228123pjb.244.1653091473850; Fri, 20 May 2022 17:04:33 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 28/49] semihosting: Split out semihost_sys_lseek Date: Fri, 20 May 2022 17:03:39 -0700 Message-Id: <20220521000400.454525-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_SEEK to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_seek_cb. Expand the internal type of the offset to int64_t, and provide the whence argument, which will be required by m68k and nios2 semihosting. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 5 +++ include/semihosting/syscalls.h | 3 ++ semihosting/arm-compat-semi.c | 51 ++++++--------------- semihosting/syscalls.c | 81 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 0a6e0d6eeb..056db1a0d0 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -42,6 +42,11 @@ #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 +/* For gdb file i/o remote protocol lseek whence. */ +#define GDB_SEEK_SET 0 +#define GDB_SEEK_CUR 1 +#define GDB_SEEK_END 2 + /* For gdb file i/o stat/fstat. */ typedef uint32_t gdb_mode_t; typedef uint32_t gdb_time_t; diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 2464467579..841a93d25b 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -39,4 +39,7 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len); +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 1238b81e0a..e7e568a77e 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -224,16 +224,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) #else syscall_err = err; #endif - } else { - /* Fixup syscalls that use nonstardard return conventions. */ - target_ulong reg0 = common_semi_arg(cs, 0); - switch (reg0) { - case TARGET_SYS_SEEK: - ret = 0; - break; - default: - break; - } } common_semi_set_ret(cs, ret); } @@ -257,6 +247,18 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } +/* + * SYS_SEEK returns 0 on success, not the resulting offset. + */ +static void common_semi_seek_cb(CPUState *cs, target_ulong ret, + target_ulong err) +{ + if (!err) { + ret = 0; + } + common_semi_cb(cs, ret, err); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -290,7 +292,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * via common_semi_cb. */ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); static void host_isattyfn(CPUState *cs, GuestFD *gf) @@ -298,12 +299,6 @@ static void host_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, isatty(gf->hostfd), 0); } -static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - off_t ret = lseek(gf->hostfd, offset, SEEK_SET); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -320,11 +315,6 @@ static void gdb_isattyfn(CPUState *cs, GuestFD *gf) gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -353,12 +343,6 @@ static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, 0, 0); } -static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gf->staticfile.off = offset; - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); @@ -366,24 +350,20 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_isattyfn *isattyfn; - sys_seekfn *seekfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .isattyfn = host_isattyfn, - .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .isattyfn = gdb_isattyfn, - .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .isattyfn = staticfile_isattyfn, - .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, }, }; @@ -519,12 +499,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].seekfn(cs, gf, arg1); + semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_SET); break; case TARGET_SYS_FLEN: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index a5623ebf0f..db8891535b 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -144,6 +144,13 @@ static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, buf, len); } +static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int gdb_whence) +{ + gdb_do_syscall(complete, "lseek,%x,%lx,%x", + (target_ulong)gf->hostfd, off, (target_ulong)gdb_whence); +} + /* * Host semihosting syscall implementations. */ @@ -246,6 +253,29 @@ static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(ptr, buf, 0); } +static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int whence) +{ + /* So far, all hosts use the same values. */ + QEMU_BUILD_BUG_ON(GDB_SEEK_SET != SEEK_SET); + QEMU_BUILD_BUG_ON(GDB_SEEK_CUR != SEEK_CUR); + QEMU_BUILD_BUG_ON(GDB_SEEK_END != SEEK_END); + + off_t ret = off; + int err = 0; + + if (ret == off) { + ret = lseek(gf->hostfd, ret, whence); + if (ret == -1) { + err = errno_for_gdb(); + } + } else { + ret = -1; + err = GDB_EINVAL; + } + complete(cs, ret, err); +} + /* * Static file semihosting syscall implementations. */ @@ -271,6 +301,33 @@ static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(ptr, buf, len); } +static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int gdb_whence) +{ + int64_t ret; + + switch (gdb_whence) { + case GDB_SEEK_SET: + ret = off; + break; + case GDB_SEEK_CUR: + ret = gf->staticfile.off + off; + break; + case GDB_SEEK_END: + ret = gf->staticfile.len - off; + break; + default: + ret = -1; + break; + } + if (ret >= 0 && ret <= gf->staticfile.len) { + gf->staticfile.off = ret; + complete(cs, ret, 0); + } else { + complete(cs, -1, EINVAL); + } +} + /* * Syscall entry points. */ @@ -386,3 +443,27 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, GDB_EBADF); } } + +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, GDB_EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_lseek(cs, complete, gf, off, gdb_whence); + return; + case GuestFDHost: + host_lseek(cs, complete, gf, off, gdb_whence); + break; + case GuestFDStatic: + staticfile_lseek(cs, complete, gf, off, gdb_whence); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat May 21 00:03:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574941 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2683277mab; Fri, 20 May 2022 18:03:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxsuA713dHKfYoO5+ONVL1smfQvUdvniQpepIOO/cBc3agnAAMr3wldbcjY+EesNBMl3B4 X-Received: by 2002:a05:620a:1a96:b0:69f:4352:fdb0 with SMTP id bl22-20020a05620a1a9600b0069f4352fdb0mr8014952qkb.143.1653095002942; Fri, 20 May 2022 18:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653095002; cv=none; d=google.com; s=arc-20160816; b=IerrijuCSOttLvBcO/iS4CiYtSroOavEnr/dgYS1OTs/I2hZGI8B2KKega/BYOCzBg dLBVvLPRUZuZ/6vUalSIhBUPksmb7JvjOuWXJv0PTTKvKLU7vEWZeW/0xV2wNGsMLq3D Urc7oHNB5OMQYy7mXADOm6WxhOWtJPSF3oTtb/0dR2kDbq9PaZzbLyJJv1i3ChpHnmfv rTsDIIlg/d0hh/fpF7gJlaMXz+dtEyHdetvCF6qFcayWrb/EdA5wuqGN/MYr9ru6rpPe OOT/UCy4Z4OUYIlII1ktx+DBcNaH2GG0oZOowDZnPwxLJsBZ8rauwI6vrRmzDrFRXOH9 aCMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iVi2WL9LYbp1NIow410Rcdf8IJcyVNGeWO58E9XwFhI=; b=N7T+EH1Rhb1KWp6MYmdiqUPbBN0Unj/6t/6YjxSa/jXAX+xHSSTQ9xny5YWbbjJkyd Kh08lpLGHiAepts/KRnG1MAFXoGYyx6T+AXdyARSAW+z3RSEG3inHzK6sPiN4zwANoB5 cRYfR9M6tEgSln79KcV+K9iAq0P7X6+NsEk8nDkfJzwFM3pMq0R59fHO8yXWs6sQMibx YVOJG1g0+/evuBVCfuEeakvCkUc8kAtFy11N6XZQBCOmnYzjaI9wAltE3IfwN/QHbCdG O92gJAFZEKjOLf9wqmmSDsqSbMgB2QlMvF8zs9NVxkSO8Q002RS84dwOCl4Xg/bI36ZS rS8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zE6/YyLh"; 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=pass (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 m15-20020ac85b0f000000b002f36f143be1si388024qtw.687.2022.05.20.18.03.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:03:22 -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=pass header.i=@linaro.org header.s=google header.b="zE6/YyLh"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDWc-0006Zh-Hn for patch@linaro.org; Fri, 20 May 2022 21:03:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CE-Cp for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:38536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbl-000421-6Z for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:48 -0400 Received: by mail-pl1-x62d.google.com with SMTP id n18so8566303plg.5 for ; Fri, 20 May 2022 17:04:35 -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=iVi2WL9LYbp1NIow410Rcdf8IJcyVNGeWO58E9XwFhI=; b=zE6/YyLhILpXCuNNPPxSFbE/JYyKSntu7d2b4IJRa6sj2rFFKqZYX3WCDUWs42GWbe CiU4f7uKdfD+8yyLVpgZwtChx82o0cpcBV2CoAxqP6gYdiH0tzdFofcP1+u1F99EHQ2H Y3uq6pcb/6eaFe88oH3cN7vtATMz08e4oKR/bi0nkDlPwp6MY+wuecsadhyI/RUkYOn3 qy4O8Wp4uQJ5BRC0gsFFaDp2jYQ3q8xm+WKe38oFqhz3Jerfp8KcQuqxe1k6kDuZBrFD Fnbhhqn+xeHqhH0/cz+oaDEcsWQBqzIAymzjkijCWE7yxBpd7yWOrgxXlVC9oI7R9lcX kDkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iVi2WL9LYbp1NIow410Rcdf8IJcyVNGeWO58E9XwFhI=; b=1DvVWh5tTQ3VFtoUM+WM4w6iPkqOAEbQhbJE42paNJK3pG3ReR/whgadCkHOKE7omm +LD1S4t+TEDq33WbAmN/4vjDgxIPHNinFcrwqi2P3zrN7Mcp3eCWMit65+LaW/kdNvQs coQCBYv57vgYmFcdc9cVP8d9wlxI64kOZh/WJfVQ27n9/K7sKkOFVUqtz2HC8qri4eZ7 6jFFRpg1iqIxlCSvxCKGzcDJruu8Co3W3l54J6j+7VOpoSG/IdXaHyKKUH8X+7MlQ/da KO8xRQWZlIA2S2fvpich3kCWak1k7KsVPmaXzDjtsRkPV5PfKZG+JZsLUXwaBTnIx0iy RhTA== X-Gm-Message-State: AOAM531Y+lnpJt3N8c8T85PPc4U9WrORkWAN1RD63jTAzVP1pQZaUpUY NNAxNsf1Zn+9ZVzjJyM2N0OMbzVe/oWv0Q== X-Received: by 2002:a17:90b:4a43:b0:1df:d1e3:6fd4 with SMTP id lb3-20020a17090b4a4300b001dfd1e36fd4mr12601515pjb.30.1653091474893; Fri, 20 May 2022 17:04:34 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 29/49] semihosting: Split out semihost_sys_isatty Date: Fri, 20 May 2022 17:03:40 -0700 Message-Id: <20220521000400.454525-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_ISTTY to a reusable function. This handles all GuestFD. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 1 + include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 27 +------------------------ semihosting/syscalls.c | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 056db1a0d0..fd4bc4e937 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -41,6 +41,7 @@ #define GDB_EROFS 30 #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 +#define GDB_ENOTTY GDB_EUNKNOWN /* For gdb file i/o remote protocol lseek whence. */ #define GDB_SEEK_SET 0 diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 841a93d25b..c60ebafb85 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -42,4 +42,7 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index e7e568a77e..973b0a68ab 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -291,14 +291,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, isatty(gf->hostfd), 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -310,11 +304,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_isattyfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -338,32 +327,23 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { - sys_isattyfn *isattyfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .isattyfn = host_isattyfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .isattyfn = gdb_isattyfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .isattyfn = staticfile_isattyfn, .flenfn = staticfile_flenfn, }, }; @@ -488,12 +468,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_ISTTY: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].isattyfn(cs, gf); + semihost_sys_isatty(cs, common_semi_cb, arg0); break; case TARGET_SYS_SEEK: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index db8891535b..702541b270 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -151,6 +151,12 @@ static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, off, (target_ulong)gdb_whence); } +static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); +} + /* * Host semihosting syscall implementations. */ @@ -276,6 +282,13 @@ static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret, err); } +static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + int ret = isatty(gf->hostfd); + complete(cs, ret, ret ? 0 : errno_for_gdb()); +} + /* * Static file semihosting syscall implementations. */ @@ -467,3 +480,26 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, 0, GDB_EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_isatty(cs, complete, gf); + break; + case GuestFDHost: + host_isatty(cs, complete, gf); + break; + case GuestFDStatic: + complete(cs, 0, GDB_ENOTTY); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat May 21 00:03:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574938 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2680839mab; Fri, 20 May 2022 17:57:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBh+PK8ycovPO60sqO1GaA0G/6gCnnNhLvMydUbGcTFDVjLS45geDY19FWyCoDuEHVW7mD X-Received: by 2002:a05:620a:1a83:b0:6a0:993:6a9b with SMTP id bl3-20020a05620a1a8300b006a009936a9bmr8047989qkb.434.1653094671361; Fri, 20 May 2022 17:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094671; cv=none; d=google.com; s=arc-20160816; b=ugv/gsUAkbGXS431lMscMV0b2jPZaBFZE0Mu3Hu4k8/7CA2HhWozCIgKF8abEvSQH3 tb4qFUDDa/E2H1v3zcieH9gWXyKaCIjayaDGh9Vdt8glZRh8af5oY6EQfs5EJ49/2fir RLokYIG9b0+guKiqzsh/7SGWBr+S/1v4OCbQnEdZ4UwuByZD78JV0hN1EPW57idGrTW0 bL5aVoOeWcdquTr4mtoz0FXfJ9nRdiUDNZ3VNUyIqosF0g5/pl/PaymVCFhKH3ZoWjsL qJdbqyFV45S0qyhXJsHUaepmsizmSD4XFDGiIxOy2fkLCVlMerKKo9VFy9A/W/lvee8z ByXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TzUwl9qms3llKSXLrofbP99q2dV9evxhKXHM3ias5fg=; b=ZuAex19cp4P0rFirkl84VZwd2PyptlF173n1cIc9PyVPDDx0fEhSfZvwvhRcnxTFLZ OnGbvdCZ/eSwwGgycvUgnoL9rLTfI3N2JrzTJI1p3XKN0mqaZigzrhR3IrCaqt9t8wRE aLO6MNMSi5+q4wWWFC6LRw44XFb4X7wi8EAUODxsO5Hr5eGdPeiHBw/mPLx/c93Im7Nv met9aQbNM8LrGFcDIRTAw8XDPrv/sHWgI1cBeNECO8vtnjcJPzlRFda3kmfOxu6rJq8c 5Xar5wJ9AQHByt6AxHtKkK4ORRGcDUsg4wE+5jwGt4lQLcopTGIAYVIjky3c/MR6jdX2 7u9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xLTKpjl7; 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=pass (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 9-20020a0562140d6900b004443866e7fdsi471254qvs.77.2022.05.20.17.57.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:57:51 -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=pass header.i=@linaro.org header.s=google header.b=xLTKpjl7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDRG-0001uw-VZ for patch@linaro.org; Fri, 20 May 2022 20:57:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CC-Bi for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:34072) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbl-000429-CX for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:49 -0400 Received: by mail-pj1-x102c.google.com with SMTP id ob14-20020a17090b390e00b001dff2a43f8cso2445022pjb.1 for ; Fri, 20 May 2022 17:04:36 -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=TzUwl9qms3llKSXLrofbP99q2dV9evxhKXHM3ias5fg=; b=xLTKpjl7z/VKNrW0RL+BeVNnK5pkLHdeJqH/kBfk7HfpchqFSi2T9JNOfo4PAVWLAD SOAuJgmbDOfnzOxKe8EwBk+xBCblscU+EhMJ2wJpaWFaMMl+ATDlZr6u2Gp5FCzWHLrD BG0mylVkj7u/FzsnmEBJiPS3yd309wAJYZ6kfDYzPem1ML7+Oye/5zcLLGU+LlLZ0owQ 5Ph8LezMzLl6pebrsBiW4fHDknAyyRl2mlrTPHDIMI6GwR73ZHu5TnEeDKLYseODChHe 9vk17KiuV30Iw/awPSUp0WwJZV3cB6OGJvFjARNelJWqNSnmGBtmxeZxtPc6YVuhVfT7 +Tmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TzUwl9qms3llKSXLrofbP99q2dV9evxhKXHM3ias5fg=; b=AGTrbNslOPCf9oUMQ+RmkhZNwgvWBCT2jSeT2GPj3DZ7m2SSqIpUPCgX3X0HbeqJhn aBoeaQk4TZaQNLwbhGYAdnQNExqdhNK8QhbNiUfhbuOxWG4B63iTi2DRIbl3T35RHdia NfODtM1Y4GMeeRj4TYupFfGreofsrxpIYudIgGDsKDMrErkg9ODbfHaaJS9AU2POxhpg wnfskLzgROGJMkjUYVrN6Z/9gd5S4HpsaVPLPfQCJuADjGsBiCPy9rLREVzFOZDdDou4 oR7oSmtI6jETtNS5UeZRTONuOvK8pfd2qaKzeFScfbQ+US+lf+aAK+zOEvWKgWn0AlI8 HRUg== X-Gm-Message-State: AOAM533aTYwGEgJYNcS52qyDwU0dxLmBCFFAZJPrJ1iAaqhNt+elUpMJ VJ+mpqHY+HUgggJmgZCa2Md3N6jnG9sZ6g== X-Received: by 2002:a17:90b:3708:b0:1df:56ac:65c6 with SMTP id mg8-20020a17090b370800b001df56ac65c6mr14315066pjb.23.1653091476005; Fri, 20 May 2022 17:04:36 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 30/49] semihosting: Split out semihost_sys_flen Date: Fri, 20 May 2022 17:03:41 -0700 Message-Id: <20220521000400.454525-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The ARM-specific SYS_FLEN isn't really something that can be reused by other semihosting apis, but there are parts that can reused for the implementation of semihost_sys_fstat. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 1 + include/semihosting/syscalls.h | 4 ++ semihosting/arm-compat-semi.c | 74 ++++++---------------------------- semihosting/syscalls.c | 49 ++++++++++++++++++++++ 4 files changed, 67 insertions(+), 61 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index fd4bc4e937..8e9cdcb1c1 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -42,6 +42,7 @@ #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 #define GDB_ENOTTY GDB_EUNKNOWN +#define GDB_EOVERFLOW GDB_EUNKNOWN /* For gdb file i/o remote protocol lseek whence. */ #define GDB_SEEK_SET 0 diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index c60ebafb85..1ae5ba6716 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -45,4 +45,8 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, + int fd, target_ulong fstat_addr); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 973b0a68ab..5dd8c800cc 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -272,44 +272,25 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (!err) { /* The size is always stored in big-endian order, extract the value. */ uint64_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + - offsetof(struct gdb_stat, gdb_st_size), - &size, 8, 0); - ret = be64_to_cpu(size); + if (cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0)) { + ret = -1, err = GDB_EFAULT; + } else { + size = be64_to_cpu(size); + if (ret != size) { + ret = -1, err = GDB_EOVERFLOW; + } + } } common_semi_cb(cs, ret, err); } -/* - * Types for functions implementing various semihosting calls - * for specific types of guest file descriptor. These must all - * do the work and return the required return value to the guest - * via common_semi_cb. - */ -typedef void sys_flenfn(CPUState *cs, GuestFD *gf); - -static void host_flenfn(CPUState *cs, GuestFD *gf) -{ - struct stat buf; - - if (fstat(gf->hostfd, &buf)) { - common_semi_cb(cs, -1, errno); - } else { - common_semi_cb(cs, buf.st_size, 0); - } -} - -static void gdb_flenfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); -} - #define SHFB_MAGIC_0 0x53 #define SHFB_MAGIC_1 0x48 #define SHFB_MAGIC_2 0x46 @@ -327,27 +308,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_flenfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, gf->staticfile.len, 0); -} - -typedef struct GuestFDFunctions { - sys_flenfn *flenfn; -} GuestFDFunctions; - -static const GuestFDFunctions guestfd_fns[] = { - [GuestFDHost] = { - .flenfn = host_flenfn, - }, - [GuestFDGDB] = { - .flenfn = gdb_flenfn, - }, - [GuestFDStatic] = { - .flenfn = staticfile_flenfn, - }, -}; - /* * Do a semihosting call. * @@ -366,7 +326,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - GuestFD *gf; int64_t elapsed; nr = common_semi_arg(cs, 0) & 0xffffffffU; @@ -479,12 +438,8 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_FLEN: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].flenfn(cs, gf); + semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb, + arg0, common_semi_flen_buf(cs)); break; case TARGET_SYS_TMPNAM: @@ -806,9 +761,6 @@ void do_common_semihosting(CPUState *cs) cpu_dump_state(cs, stderr, 0); abort(); - do_badf: - common_semi_cb(cs, -1, EBADF); - break; do_fault: common_semi_cb(cs, -1, EFAULT); break; diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 702541b270..1425156bf6 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -157,6 +157,12 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); } +static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); +} + /* * Host semihosting syscall implementations. */ @@ -289,6 +295,18 @@ static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret, ret ? 0 : errno_for_gdb()); } +static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + struct stat buf; + + if (fstat(gf->hostfd, &buf) < 0) { + complete(cs, -1, errno_for_gdb()); + } else { + complete(cs, buf.st_size, 0); + } +} + /* * Static file semihosting syscall implementations. */ @@ -341,6 +359,12 @@ static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + complete(cs, gf->staticfile.len, 0); +} + /* * Syscall entry points. */ @@ -503,3 +527,28 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) g_assert_not_reached(); } } + +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, int fd, + target_ulong fstat_addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + flen_cb(cs, -1, GDB_EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_fstat(cs, fstat_cb, gf, fstat_addr); + break; + case GuestFDHost: + host_flen(cs, flen_cb, gf); + break; + case GuestFDStatic: + staticfile_flen(cs, flen_cb, gf); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat May 21 00:03:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574942 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2684239mab; Fri, 20 May 2022 18:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwScz8fKFyhqG/l2nhV6tMKUQQ8kyll3D+O3mwv/m06H0sAfJK+ERkyxzIBgG6hdODPssBm X-Received: by 2002:a05:6214:226f:b0:461:e91b:4fdd with SMTP id gs15-20020a056214226f00b00461e91b4fddmr9911518qvb.68.1653095130538; Fri, 20 May 2022 18:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653095130; cv=none; d=google.com; s=arc-20160816; b=qC5t1GFEx0qx9ZuVeB/DDkYgboV7mPtugo2waVrW1jMNwuM5ZaoGh6fm3WjOaS8vG1 w7S/4DdiB8EyPdQwTtXi4+xDTu7wgQ/By1X2Us7SJbj8IbUSPgmQcGWnx7ZQ73HyQ04k v0Ru5Baw50t6trxGo5TvFUCr5BBGSAfJftl8xWrGXp5tQiLvFnd953POR4qYb881x8Ba qid5nfhmQ82ggpj31ncfuoDO9AW9TOn55wG2KJQ0bYiT/bZ/jmgx8OZ6bO/G74C608a3 zwzDMv5BlLdcyVsSLkUPUr4wXnSGS4RDVgJA1OlUOKmu4dZcRi5zbtgz2L7hoyDB+rkT Wnzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=gcQRQEAIjWtS065egzPRPQ/peBfc0GWMjRGJk1oCJM2O3n/UY90MGemX9CxJ0/za1h L1vC6uGqHSfacZ4mDlbaLkJnlrs5l+5jie2AHW1YISvK7ETvIKawyVUEBmtjpHKq0fYH qicWNzVpiuHH/yYZKklYjAOqr0eUosLge4trISWX11LmHqqwg0Aist9Hxqew73DUI47S 7lHH7OTjSU5j1f6oKdaYLrxtxhQ/7j6z6ihsCH9nCbkQYjL3EvYAQFQYKp+l45fFKf0V pg8xbhEq4cH6K3VdkP5IIY4LbGV16YQJMiK/ei0tcaAwtM6nhM0eBKX2Qti2pbhCouvO UGYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aAfH0ZA/"; 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=pass (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 15-20020ad45baf000000b004621edca200si414904qvq.184.2022.05.20.18.05.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:05:30 -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=pass header.i=@linaro.org header.s=google header.b="aAfH0ZA/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDYg-0008Ny-1H for patch@linaro.org; Fri, 20 May 2022 21:05:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CK-WD for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:41561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbp-00042D-OB for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:50 -0400 Received: by mail-pl1-x635.google.com with SMTP id s14so8556604plk.8 for ; Fri, 20 May 2022 17:04:38 -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=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=aAfH0ZA/X9yVbGcmtAb4roHMq6C/zyYZBRaZ4/5ntSTdXT58Njth2UTwhct/5iGeVj LqqAez6GB1r28d5HOeCsb3EKKu4ipdWfwXOV7XocjQ52rm7Db00r6ZIzG4/zvpfLUz7r DL3txqX0gn2kigtJX2CDP83ddmc40KuNZ938fleTKc9lkZRjOHAL/GEvRznYLkiiFLY1 ZfjV8hfqOZn/v+T/nMR7XBZkXuVmEj+skob2jcfryrp8uNmM9ZaStHcbxdHDNyFoYUWL H45YRhCsYZpsTQ2z4JI90EkdVl210ZmRGszBSIyl4AWATdrwubQVtxPoSBib8mhS+t8M EVoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=EjCXGQV5VSVv4JGu4DW+a+70YfFKCB2wPQGPGmugh2rLuzU0KUGiRNn7FSm1+cK6ko YpjzNhLEBzxVMkKQ8de4sVKGfQ1EGDUKjqEPPb6fwkz6GOTnjsbpeEFKtF0ldOOo5ogU cSY4L8eedTte5cSApF8BelcD2qi62CXynUq/sGfPIZfQxtUVByocnfyZV5qs3UaYeuhM XX8Her/VpWRrRSXCr1SDCOadT/gVuVbLaILlfn11+V/S/D5tRxf12hDl88ZqzovElSgy MEYEMUQbya7DSwaFTrW53N+jTuGYyBs/oTVo4gBUmQZl9ivLaO8cumHbqPo0jdlmd06k YhWA== X-Gm-Message-State: AOAM532Unca39wVT/02Ta3t0TaZ2nVQvyWff9kKKHp5a5clOSnkOx7sw EAONpjoTxccstQUopfiz201+ID0m/8tmZw== X-Received: by 2002:a17:90b:3a89:b0:1de:bad4:b614 with SMTP id om9-20020a17090b3a8900b001debad4b614mr14181225pjb.139.1653091477058; Fri, 20 May 2022 17:04:37 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 31/49] semihosting: Split out semihost_sys_remove Date: Fri, 20 May 2022 17:03:42 -0700 Message-Id: <20220521000400.454525-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_REMOVE to a reusable function. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 13 +---------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 1ae5ba6716..748a4b5e47 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -49,4 +49,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 5dd8c800cc..b4320939a1 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -470,18 +470,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = remove(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); + semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_RENAME: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 1425156bf6..3464896281 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -163,6 +163,18 @@ static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); } +static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "unlink,%s", fname, len); +} + /* * Host semihosting syscall implementations. */ @@ -307,6 +319,24 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = remove(p); + complete(cs, ret, ret ? errno_for_gdb() : 0); + unlock_user(p, fname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -552,3 +582,13 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, g_assert_not_reached(); } } + +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + if (use_gdb_syscalls()) { + gdb_remove(cs, complete, fname, fname_len); + } else { + host_remove(cs, complete, fname, fname_len); + } +} From patchwork Sat May 21 00:03:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574914 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2666087mab; Fri, 20 May 2022 17:21:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+enJkbRlj2nrfTqqXzdOUwSdCaxCbfehvk59a+GbsjyHOhJUPVhCwx5ixQJQ5FI3KwYHE X-Received: by 2002:a05:620a:258b:b0:680:f66e:3381 with SMTP id x11-20020a05620a258b00b00680f66e3381mr7695066qko.291.1653092480164; Fri, 20 May 2022 17:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092480; cv=none; d=google.com; s=arc-20160816; b=fViz444bB7grCfAVpkBQkWu7RPO1nCLjfoUmmzSID4BKOmbFQr8mw9fVlVCy8b+nhz Ztnz63AKF91Nc1ej4Ms5jUPAT8TSgxTBYxsgDNxYw+8SyaFYHITszYQJDkDzx/0q/E7G aDxeL4NC0TQ9UqD1847Hc4exCYwfjxsJLZLsHvEmdjR4XJwE28dGuxHJKkFjxuVc6MLt WhnJcQj2mnRmW4zFi31vholsRTTCaz0XKS2Nf+HMFuk6HUM4cNI8CsMMciF7HfLTX5QG ievq5WO6s2tRe116kLExoYOT5oMgv967Mx4ogXD/Y5otvRVCXCvg7g9YHlXGsG3bqaLC 8M5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=enxou4yoMT/vOpcisCbCyqvDmHRkcHgrMJIOlZ4t5Wk=; b=YlmwghxbKbOtk0E5Pk06YAPeHt4h6vFdeoYsqo28AH4kZRl7X9elnfKAMzA6hfQZE8 qiJKQCif/JMYTBMka+VPlH5mXsI+EWoMtFld/WEZj+JvmK8+kRsOx+jFrAHzQtp2zGNu 8aF+JhjhViihaUIVj2HhxVDYr6az5/+MyxYYhGyFctwZGVO40tacIqfiLBx1GxnGwoq5 K1AFC0HkBBXkAEC2777IemDbbF92YX02LaufPgph/EcgjMOrtU7+lsbsac4lAEK0jl6v 0XLdoDkoP6Zt0jPer+UmBxbMx/K5XifR0dLIb1lXIbf5m630lqlc5Uz1WquHJLTOrxpT 5r/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UuUwACNE; 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=pass (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 t15-20020a05621421af00b00461b52e0c5dsi356660qvc.328.2022.05.20.17.21.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:21:20 -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=pass header.i=@linaro.org header.s=google header.b=UuUwACNE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCrv-00006u-LW for patch@linaro.org; Fri, 20 May 2022 20:21:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CD-Bd for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:37394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbq-00042L-1Q for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:49 -0400 Received: by mail-pl1-x629.google.com with SMTP id m12so8569854plb.4 for ; Fri, 20 May 2022 17:04:38 -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=enxou4yoMT/vOpcisCbCyqvDmHRkcHgrMJIOlZ4t5Wk=; b=UuUwACNEm16rttnhC6EIr4KP7EYN9j7Eete+HNg5BflWy4dEiEroa2UIfaI4hd5J9z ETkFGPg2FHD8ddJ3d3C134DB2weN9E0AVb0ymlJrSoAFkPGt1AhYfmTiBtJwe0zD+lXB oJuGyjCV40/TG08Hj5Y8yPLRA2wyGVdDWtaaRnXYW4hKBstrUZXYf56GWpeOCv9n67PH Wpv2nPqZjcvKz+ZaEtJGhKDhdrN6g36IQON6nndiYMVeqxZRsGJatdVxFvEyjwQUKQrF Vunr65cu0UerXfXR4cTgZgV1qla8wCj+pFSYneqsOw8yhDfhaZuEcii1EHhHP1+NDFBk a48w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=enxou4yoMT/vOpcisCbCyqvDmHRkcHgrMJIOlZ4t5Wk=; b=y1/qenJvJgqdmZuYYTB0jVSyNqDf4j31BYZtoi8xadvChzXEk1ZriZNU50DV00jE31 15pgT1fu0SZK7Owe8uExE+iycxjt2cQnubPQ2AYE8Hxp2fIx+YYfHPVZS1/eAMkpK1ky wKv2Xl9FK1TMoMn1XcBzE9N0pUIyuij2ZkVJJwLbI3NkQhVmZzKUzyYp7SbM45Npn4XW Gly2PozGq/QCEY+WMaFUm4RrJcXxdTxub/FdZY4/ABjtKlMwnD+o+XFNmT90AErbsXsM 3mXDs69JAcCcVYHEFL4/IAEL+d2RlfhCKO9271e44aLyKDmuEGgQtIbtoyOqqamkjIwP 4jPQ== X-Gm-Message-State: AOAM5338EJDU4pktsYnJ143Z14LNkDtmnYfOXhBk4Dd/Qbgu5Pgz/n/C o7htuRplPSzOxo9eY2EGeOTiJnaYkta6lQ== X-Received: by 2002:a17:902:8c8f:b0:15e:ab1c:591b with SMTP id t15-20020a1709028c8f00b0015eab1c591bmr12056861plo.171.1653091477954; Fri, 20 May 2022 17:04:37 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 32/49] semihosting: Split out semihost_sys_rename Date: Fri, 20 May 2022 17:03:43 -0700 Message-Id: <20220521000400.454525-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 4 +++ semihosting/arm-compat-semi.c | 21 +------------ semihosting/syscalls.c | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 748a4b5e47..21430aa0ef 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -52,4 +52,8 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index b4320939a1..f02131aebd 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -478,26 +478,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); - } else { - char *s2; - - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 = lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret = rename(s, s2); - unlock_user(s2, arg2, 0); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); - } + semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1); break; case TARGET_SYS_CLOCK: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 3464896281..96d823e8b3 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -175,6 +175,26 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "unlink,%s", fname, len); } +static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + int olen, nlen; + + olen = validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen = validate_strlen(cs, nname, nname_len); + if (nlen < 0) { + complete(cs, -1, -nlen); + return; + } + + gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); +} + /* * Host semihosting syscall implementations. */ @@ -337,6 +357,32 @@ static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, fname, 0); } +static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret = validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret = validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret = rename(ostr, nstr); + complete(cs, ret, ret ? errno_for_gdb() : 0); + unlock_user(ostr, oname, 0); + unlock_user(nstr, nname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -592,3 +638,14 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, host_remove(cs, complete, fname, fname_len); } } + +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + if (use_gdb_syscalls()) { + gdb_rename(cs, complete, oname, oname_len, nname, nname_len); + } else { + host_rename(cs, complete, oname, oname_len, nname, nname_len); + } +} From patchwork Sat May 21 00:03:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574935 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2678968mab; Fri, 20 May 2022 17:52:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Wv/rh2MyFTPJ1Sp7L7IW5zPH4PKYEw57jduJdrKm15FnPE3fhEqoUC48VEiYEvNT7f0X X-Received: by 2002:ac8:5bd0:0:b0:2f3:bb55:4612 with SMTP id b16-20020ac85bd0000000b002f3bb554612mr9643980qtb.391.1653094376965; Fri, 20 May 2022 17:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094376; cv=none; d=google.com; s=arc-20160816; b=prw6pWQug5BACt7FZ8ScRm+BJ7Aq9JxiK9056thMfns15CjyF8n2SoD1GJf3rbcUS3 sPwB5ZCisC9Bh3PyE1gw2hV1ffwBKIztbhuTq/4F8y2hez91If89qo723kbwSW+Vib96 05EFjHo5szdo7PgLSDsRTNdznZ6UbbxwQBCG3E0wWOCBLRWlSFaoTElaYUQFFVhG1OqR KcuOL+lw0iG/y2dvWPUScTX0o6YvrqvF68vW8UwRzP1QvhRyJhjS2mAgtIiKPy9PpNoo UJEnvLa8JuBRJb+tzeOEoueAazJXhw24EDSjS74Hz0M6wNhGfZqQQW6dPa/sz62oMMbH fOqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=YtyDpi2xczV6KFPTHBsh0DZJgp3eFWit8H9tbaAQZwm84191qvoT7FoX3o9yIMKw+f c9NdJWRWH9ZhYxmqRkE/jtFze6hUue+DcN0s1wFOustKLypAoKJvmL7ASzTGiTdgsiVt u9zSTKRESTqGqjfTuOQpC1p4ftSVkofRdm0eRlyk+SDKyM5DLBwtPvDdt/yQNyXjylNU 9pi5XzrNUfyZpdc1kTAnn7Z8qaaPGkW2XnOxGzfdSJy2caAvlV4ZD86DAwlZ8UMmATZA EwE7EGMP9RvRyGbeEN/pHGV7GcuD53gLzhOpEeytzqLm9H8ZmwBLCh8iralSztRkyNfe uVBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BqxuznKg; 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=pass (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 b20-20020a05620a0cd400b0069fce27ef20si335248qkj.397.2022.05.20.17.52.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:52:56 -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=pass header.i=@linaro.org header.s=google header.b=BqxuznKg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDMW-0005fT-Iv for patch@linaro.org; Fri, 20 May 2022 20:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc7-0008CM-32 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:45013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbt-00042P-HJ for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:53 -0400 Received: by mail-pf1-x431.google.com with SMTP id x143so8947462pfc.11 for ; Fri, 20 May 2022 17:04:39 -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=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=BqxuznKg/VbuPsfCIcm0NKZ85Z7QwCbuldtJ7bNQ2L4No5IWkrDpEBtB6R7D0I35Iy 341Mfu4ww6u3JE18zO9yWidk2180XWvEnpsFvYw+lE4Ir3SfkMKnG8EANKdbkL/vVyBM BxFkOmLLpTTPIxcpgQw3fayvWXdceQSXQaQSUK07VjrdM8UIMzW6dZ304J2yVwx/o6K7 EB/Oj9VgBIugcDyd9BIObv179CXrWkpWEGCk4jEZQRbkEDC31fsejaDSfjRyx4LNWQPQ uVZDSX7nsaLUjM5hlIXaSo1hPgrpMYdDvw5Y3ukMnl0It0b4kFGDANTztjQ6EvMtZ6ZV VbIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=33VQQESq1hP74O07+2MJn7eTV9EJHOlMmk0JhP6RLQolBQJPxeu7lnp9sQJTMs8BJH dI3QtiZ+aGBa/T6yX+u4/keP9Rh7z2Gdjnpg49FGtEni9+IIcZLtoZvVvrtFNYfAo7F4 fyiPshlLVNrS4NwneWJVrZeUDQLKaOPCAf9+8VgOmvJr5af8oRJBHaeASCuQQkRrJIdX Jkc4JpOflsIBx4OekxCxLQ0Oecw4b6V9urC18deyKz4e43fQ4eqfJwC1fnwTMXzS+59e UC7yWkqIfYjsMoELn1fggdz7nthWusQdWu1rUIw1KnDjO2vwv9uDX/0kN8m/GgYAPH2j 5ulQ== X-Gm-Message-State: AOAM532GJRuyjZqo7QYLrRaahJTZcIaWbiN10SkRavTZCu7e/6udYsJx 54dxxxrq3vHPjXOHOUqV+ffae6JH7mhQtw== X-Received: by 2002:a63:210f:0:b0:3f6:24e6:bec with SMTP id h15-20020a63210f000000b003f624e60becmr10667186pgh.400.1653091478870; Fri, 20 May 2022 17:04:38 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 33/49] semihosting: Split out semihost_sys_system Date: Fri, 20 May 2022 17:03:44 -0700 Message-Id: <20220521000400.454525-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_SYSTEM to a reusable function. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 12 +--------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 21430aa0ef..c9f9e66be1 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -56,4 +56,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong oname, target_ulong oname_len, target_ulong nname, target_ulong nname_len); +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f02131aebd..9cfa8a421c 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -493,17 +493,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_ERRNO: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 96d823e8b3..b6c395af22 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -195,6 +195,18 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); } +static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + int len = validate_strlen(cs, cmd, cmd_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "system,%s", cmd, len); +} + /* * Host semihosting syscall implementations. */ @@ -383,6 +395,24 @@ static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(nstr, nname, 0); } +static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = system(p); + complete(cs, ret, ret == -1 ? errno_for_gdb() : 0); + unlock_user(p, cmd, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -649,3 +679,13 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, host_rename(cs, complete, oname, oname_len, nname, nname_len); } } + +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + if (use_gdb_syscalls()) { + gdb_system(cs, complete, cmd, cmd_len); + } else { + host_system(cs, complete, cmd, cmd_len); + } +} From patchwork Sat May 21 00:03:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574918 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2667115mab; Fri, 20 May 2022 17:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1bnHTwiQKnyhBRXMCcWUtvKorHlNoo/EaqgtMipnNKVBkBDzMvsaxTXGxD2hamDNeTZxP X-Received: by 2002:a05:6214:2a8a:b0:45c:64df:5e14 with SMTP id jr10-20020a0562142a8a00b0045c64df5e14mr10049073qvb.13.1653092648700; Fri, 20 May 2022 17:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092648; cv=none; d=google.com; s=arc-20160816; b=yFa8SeTPV17HvB2NGwiiwsSMPUL0SpBBuqKuOgLFGGuOwEfscS683d4xS78ZiEpviq 3DINUcdHnk7K9dByFpTRZoq4Y9ycXWNRo/ri7bHsffTjS+/Dmf6UfAQjV4heJJ5gWZaS qELUhX9aZzDkaBai1LrwXibtsMR4B3pmEntQtRWNrWVHbt4LCkzOFMS4pbImkW2UbApV 7WXEJO60JyD3qzWzc8HRCH6EmBrZkGxuYQtbL511kh+tk8S68Lv8s+G4XmeaXAK2C1yI ywDA/wsz/LOvqGNpzqQS7iQYlUdeNOPNWl0422sBNtff13okXBuLZZ1LOp8GfAYoTMls ck/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=e1hILWBCkWfN4V7I7s8Fkzb25wwd+VphBm75H9eSXkh7GFFxy1kpO2Bqy1XhFxi72f HvoVTMJNqundlBx4S8um7UXhyU6IDuq3bGzQuZeMm75U8w421V7voJdE4VjNGmO22tgd XdV3yaFBdcRG5tnU/sBexmVB/7OCLSRtEGIBmx8JasA3jOTQUnOqtKwh83PQ5bDdfCE9 L/fOxMdaE4Q6NR1DyPPOGlqOUbq/oBuYYRxKPWQ7XGKk8Pabl/pkOezE+dfgZW2qIssB T+pQCiRFpjXETN67WLBruO2jXx7Z29lt/o5sOmf+4qyl676JVZef4F5gKR/gT9vv86Op b/NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="I1Fday/h"; 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=pass (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 i5-20020a375405000000b006a33f610788si384084qkb.234.2022.05.20.17.24.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:24:08 -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=pass header.i=@linaro.org header.s=google header.b="I1Fday/h"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCue-0005yC-8f for patch@linaro.org; Fri, 20 May 2022 20:24:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc8-0008D3-UM for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:11 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:33727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCc4-00042V-KB for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: by mail-pf1-x42b.google.com with SMTP id 202so1967984pfu.0 for ; Fri, 20 May 2022 17:04:40 -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=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=I1Fday/h2CjzF7iE7KlD0VKYrqwjHSF/tC1MHoH4Uo8HXWNqaRJ34rjq/09vEdOk21 C4ngkWP4s0q9qmm6KqeMAxtfWqcpsPmwwERPRInAXZadk/HNTy2kqgURCNeUHc+FJh2M s6g2lC6PJs9Ud1i6XK8iVZWD8O2faTfPGfWqeaU0jka2+Jt9Wf+9GiDSMSdECeuE6X4I BZTkgamUepE3Q++zhLhXLgTq572p81NrbQtZ11+FrGaiokZHtaOonkWIjTVeXFYrgxjR ZbZZfgnh3jNmH/g6mUxAF1TTDZllxsU6kG51HwvzKixJSBPI+8smVfGxl36kYFScMllw a97g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=rQWOqYwLBYQVufGE4oUi3nffz7fVzoeK1l1hL4mIzya3cpg1BCF+4Vr+T7RI86pavR iwZJBiX6MZcS6wiFAriPRpeoRiH1fRtEwA2DAHyiOCw2u/oHkStZLPM3/FTjrItksFmP HHHdzlCji5pqKTlC2iR/sRVdTDW2Ylv9VnXaUT1cR0Qhrm6m7gdNXU++c5SM9H0YKaqI J48fVokuYwrSItrHf7FEYpczg3KWSsbB4m2pgnGzHMk1EI7OKpl93M6Q5/pCpt2LgqAL SJLu/jXHNljfVTaJClAr+FGr/EBLCPgil0q6WpThWxD5ArVw6K29qBs/X99oVHDKV9zg PMdA== X-Gm-Message-State: AOAM532LwetWygAlx0jBARJikPs4AVOQxvww6SYh4/iF18TH68J/cX/N B0P6PtN376ZHYDQ6m7ym4l2UBJpx3+mhPA== X-Received: by 2002:a63:4204:0:b0:3f6:4a4f:5a96 with SMTP id p4-20020a634204000000b003f64a4f5a96mr8324751pga.10.1653091479844; Fri, 20 May 2022 17:04:39 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 34/49] semihosting: Create semihost_sys_{stat,fstat} Date: Fri, 20 May 2022 17:03:45 -0700 Message-Id: <20220521000400.454525-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These syscalls will be used by m68k and nios2 semihosting. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 7 ++ semihosting/syscalls.c | 137 +++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index c9f9e66be1..ecc97751a9 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -49,6 +49,13 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr); + +void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr); + void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index b6c395af22..7bc2640512 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -93,6 +93,52 @@ static int errno_for_gdb(void) #undef E } +/* + * TODO: Note that gdb always stores the stat structure big-endian. + * So far, that's ok, as the only two targets using this are also + * big-endian. Until we do something with gdb, also produce the + * same big-endian result from the host. + */ +static int copy_stat_to_user(CPUState *cs, target_ulong addr, + const struct stat *s) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_stat *p; + + if (s->st_dev != (uint32_t)s->st_dev || + s->st_ino != (uint32_t)s->st_ino) { + return -GDB_EOVERFLOW; + } + + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -GDB_EFAULT; + } + + p->gdb_st_dev = cpu_to_be32(s->st_dev); + p->gdb_st_ino = cpu_to_be32(s->st_ino); + p->gdb_st_mode = cpu_to_be32(s->st_mode); + p->gdb_st_nlink = cpu_to_be32(s->st_nlink); + p->gdb_st_uid = cpu_to_be32(s->st_uid); + p->gdb_st_gid = cpu_to_be32(s->st_gid); + p->gdb_st_rdev = cpu_to_be32(s->st_rdev); + p->gdb_st_size = cpu_to_be64(s->st_size); +#ifdef _WIN32 + /* Windows stat is missing some fields. */ + p->gdb_st_blksize = 0; + p->gdb_st_blocks = 0; +#else + p->gdb_st_blksize = cpu_to_be64(s->st_blksize); + p->gdb_st_blocks = cpu_to_be64(s->st_blocks); +#endif + p->gdb_st_atime = cpu_to_be32(s->st_atime); + p->gdb_st_mtime = cpu_to_be32(s->st_mtime); + p->gdb_st_ctime = cpu_to_be32(s->st_ctime); + + unlock_user(p, addr, sizeof(struct gdb_stat)); + return 0; +} + /* * GDB semihosting syscall implementations. */ @@ -163,6 +209,19 @@ static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); } +static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr); +} + static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { @@ -351,6 +410,51 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + struct stat buf; + int ret; + + ret = fstat(gf->hostfd, &buf); + if (ret) { + complete(cs, -1, errno_for_gdb()); + return; + } + ret = copy_stat_to_user(cs, addr, &buf); + complete(cs, ret ? -1 : 0, ret ? -ret : 0); +} + +static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct stat buf; + char *name; + int ret, err; + + ret = validate_lock_user_string(&name, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = stat(name, &buf); + if (ret) { + err = errno_for_gdb(); + } else { + ret = copy_stat_to_user(cs, addr, &buf); + err = 0; + if (ret < 0) { + err = -ret; + ret = -1; + } + } + complete(cs, ret, err); + unlock_user(name, fname, 0); +} + static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { @@ -659,6 +763,39 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, } } +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, GDB_EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_fstat(cs, complete, gf, addr); + break; + case GuestFDHost: + host_fstat(cs, complete, gf, addr); + break; + case GuestFDStatic: + default: + g_assert_not_reached(); + } +} + +void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + if (use_gdb_syscalls()) { + gdb_stat(cs, complete, fname, fname_len, addr); + } else { + host_stat(cs, complete, fname, fname_len, addr); + } +} + void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { From patchwork Sat May 21 00:03:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574939 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2681429mab; Fri, 20 May 2022 17:59:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOHE8WpW73fWkXdOm5U2SridcCa/DZdSoR+4d311VrHG83/S83TEXWFBaX+YXSy0daUMxT X-Received: by 2002:a05:620a:84b:b0:6a3:4895:d272 with SMTP id u11-20020a05620a084b00b006a34895d272mr5092783qku.338.1653094772255; Fri, 20 May 2022 17:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094772; cv=none; d=google.com; s=arc-20160816; b=GQ6hc0aaRenpGA4OJx5wwe3Qa6QQB5ETU2KoDZJChlx/dnIBry62K3aZE/1bwPi84C tTy1vINuOpl8fN2UC4f74mLWvGpfFmfuRQ8LF9IICBIUOgZj63j/HO+ZUSX/nRJ3SHS/ bkuZW6ixL29BTbtjfRuvXlG+FW/BzfkP0AlrTkQPvv1CRX8DxzhpxCYEKSTc8MciC+1Z Y4uJatV+KDu5pMoxLC3yXAFQ75RO0U8l7k2xPs2YjkekgZU+PNmiW7jh8ZAt+KDp67BE NlrbnX7aVZSlWyvfn+WryBRsuiE7/xr47Kq+G/+Q/FiXV3QogRVJT3UvC9ypcEFZjO+O OMLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=cZBPE9ZHKC8vyDYpkyAf8uiLhs+MH4BpKK1snvvJqauJHuyJ59B6pF5QiSFdWNhTlw KmwtpYlV+3C5nCkS2TIKi9jF5c9Kt0KytTPTAhwq1KYKbnfK51b4VCfxrPlEZji8TKTE pkaJmTTduWT32tUHU7invDdFKDrcGGUp0QBZsRjHKrJNtHusNP1Ht14CC7rMxJxDfM31 WaAkk19P207N7KXJWRWVO86zR+rnnQdMFq1MkcIFsgnNwFMUs3EBe6Hfo4hL4E821POr YIVbJhgH0YFETdyYNwEssJIPHqi3+ZaOI5glUIsHFzTcHgdbmdNVqKkr5IyFce9HC7fl WWpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tnBWdMIO; 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=pass (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 u31-20020a05622a199f00b002e1fbf3beeasi430674qtc.219.2022.05.20.17.59.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:59: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=pass header.i=@linaro.org header.s=google header.b=tnBWdMIO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDSt-0003Os-Sd for patch@linaro.org; Fri, 20 May 2022 20:59:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc8-0008Cf-BR for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:01 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:39766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCby-00042b-Na for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:58 -0400 Received: by mail-pl1-x631.google.com with SMTP id bh5so8560536plb.6 for ; Fri, 20 May 2022 17:04:41 -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=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=tnBWdMIOBpml/OZsk2CnHbv0WVbl+fOG+e4KlC1smReheAPN1bL1GPT11jmhnFCs3M IvDZQCoLIFW+LX6bGIbhY2AnzR2vpBJL5M8aLT5MbbRQquvHGDBGL9LEJEAJ+X8pXLK0 XkQUwFtcCa+Ppc8jgln5J3oEojolWSwyy2ETAo+GaMp+ph0OJCd14gewruKN4b0+wUVX Ztg2uywNBg5LrC+qV/yQ8WjMcBYgcVx6w+psxEMYZSHD34hQM3odNjyCQR5B74qnrLFR XYePugXlmj+EggMfC4t4w46SjkKJ6znl09DRykPIsjTWkHqsGVG6tMpQr0EBk5+bfAnJ afnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=noVwNCQw1Dz1qg4sg087hCfluQOnJEg/Dr3D7xhZsBTQBE64ymc2bfxdzqvYPXQz3t l2LDG1ukKmOVRRpnj8/AYzSF2snYmHXp6sPE7ftVs1eUgFZQUq7u3QNSHAUn/o+l+hrU /qLEBZkhxzxaypVE2s6FLMlpIWEk9dNiU6msessaTLtwvzgOLQ1ywEo5NlyexQs1XpFl Y7WgesqGAoCZVqSwHafSCisUzSJETTC42C7/6f0pRWog2dDkMVLXToTcVR1Ea+ZB68ts xZncAK+0gGpwVKcK6McODb12/bmtxe7M87xF8aoFXehF7uuzihqDEwagOLbfMHebD+WQ aprQ== X-Gm-Message-State: AOAM531pEg1o362Nyf0wjShrtLK7WJo2ff6WFt9FsU7zbPjjcNbDvymk fDlhT4f6cd0Dln9DkCN+srZjgbt2rCO1NA== X-Received: by 2002:a17:902:8c92:b0:161:e861:861f with SMTP id t18-20020a1709028c9200b00161e861861fmr7965542plo.33.1653091480761; Fri, 20 May 2022 17:04:40 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 35/49] semihosting: Create semihost_sys_gettimeofday Date: Fri, 20 May 2022 17:03:46 -0700 Message-Id: <20220521000400.454525-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This syscall will be used by m68k and nios2 semihosting. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/syscalls.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index ecc97751a9..347200cb9f 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -66,4 +66,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong cmd, target_ulong cmd_len); +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 7bc2640512..269f750d98 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -266,6 +266,12 @@ static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "system,%s", cmd, len); } +static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + gdb_do_syscall(complete, "gettimeofday,%x,%x", tv_addr, tz_addr); +} + /* * Host semihosting syscall implementations. */ @@ -517,6 +523,32 @@ static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, cmd, 0); } +static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_timeval *p; + int64_t rt; + + /* GDB fails on non-null TZ, so be consistent. */ + if (tz_addr != 0) { + complete(cs, -1, GDB_EINVAL); + return; + } + + p = lock_user(VERIFY_WRITE, tv_addr, sizeof(struct gdb_timeval), 0); + if (!p) { + complete(cs, -1, GDB_EFAULT); + return; + } + + /* TODO: Like stat, gdb always produces big-endian results; match it. */ + rt = g_get_real_time(); + p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); + p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); + unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); +} + /* * Static file semihosting syscall implementations. */ @@ -826,3 +858,13 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, host_system(cs, complete, cmd, cmd_len); } } + +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + if (use_gdb_syscalls()) { + gdb_gettimeofday(cs, complete, tv_addr, tz_addr); + } else { + host_gettimeofday(cs, complete, tv_addr, tz_addr); + } +} From patchwork Sat May 21 00:03:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574919 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2668265mab; Fri, 20 May 2022 17:27:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIEl6a4hg9+108M4/FxnSRjLfkCaMjFkvFC18TwRVl1IhzItooHAmqqgdUcu43DY340hqK X-Received: by 2002:ac8:5f83:0:b0:2f3:dc9e:bb43 with SMTP id j3-20020ac85f83000000b002f3dc9ebb43mr9760464qta.171.1653092823438; Fri, 20 May 2022 17:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092823; cv=none; d=google.com; s=arc-20160816; b=uzsHfraMpoh9K2AzpyWw48Kk1bFxsXNr2klCO1TczH+1Mx/BPK4v1mcPzcJKihIOix 9XABqpnxCgU3B8gN20OtIqCM+vFU7LwUruOtekdjeUuOmzBebA8TOUVNxgFVpYPElZYZ afxNtxFlVjiz7FREGKnqNPxMDNiX/W88XBLdUoaDJA9k6NVwqFfxyzmhl+6+8w8Q22pS 4/AVNQohi0ADZwFdfTX1nTREo9JCOb7U+UaugKSjB/JcZrixqO9j5ok1HT8uDk48oJUd 8GjH1dsAbjj/rweySZw9+Z/aUIuI8s814pOAe98VXQnNvxYkzpmQRLg9B9kf7mIVS5pb 51Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R8LmH4e+PMnsi9Af9Onv9SkMhAoC/ASzAF/xHgzRWGA=; b=pH5afeEpXuIjiiAlSK7/ej6Q69wcHHvnzj7YZtMOR0wKDBJAP/veSoehA5OMcTuJTo +3mBrQzI1aUAcoAmzAEgdPAQ9VSo2P6JHb5WPTnhDkEzJOkfFXbaVTuCSK1ywlP45EIp 0GRlPZTLKkbIvnKZbcYIacuo/Z7IQi6AwhX12AOmsNaB6HRJbtUJ0fCdH3Xw1IZPWvTv xFjYVLgVnmwn1PqssBy2H0AVt/lRsapaYNmMRltfvLw3RlVXFGVDERtjWQ8Bug3FbWQh CtFcdn+FYSFJXAYPoW+fxvmaaAM/UTxOjVk9l629ktxPhERn0+fiWl7LKtfAbn7/L+/P Nq7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L9gLfh23; 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=pass (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 d10-20020a05622a100a00b002f3b90d6d5asi383936qte.610.2022.05.20.17.27.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:27:03 -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=pass header.i=@linaro.org header.s=google header.b=L9gLfh23; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCxT-0001GH-12 for patch@linaro.org; Fri, 20 May 2022 20:27:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CJ-W0 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:37406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbv-00042g-U2 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:51 -0400 Received: by mail-pf1-x430.google.com with SMTP id bo5so8968752pfb.4 for ; Fri, 20 May 2022 17:04:42 -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=R8LmH4e+PMnsi9Af9Onv9SkMhAoC/ASzAF/xHgzRWGA=; b=L9gLfh23Y/TeJ/6DEL/KasykGOhuTZwjdsfMY18Ks6CS1AbjhGqMYZRYSrSi8/9ESp bfjvfa0rQd065AXsH/K0xLz2VCG6caMzFkfcphqIxRy3sqMR4BL7/U4q9TD/1jMe/U+L HS3Pejo0EyzxaAYGpcWKptHqf7pXPE00gqkQ9wfs3JXZKs9aTWDY3f6OlfEVt4YHOmMT kX899TgRVhikDvxnV9G/dxMtqxFUlhpkt6gsyELhk3Ix85IHtDDqwrUW1aSfyybPXI32 KA0i1LxsL8ktni9CE8VCg9TmYgVDrit9B5DgI/mWrlUwEc39lY8wibb5GLf6qCQL2Pbg SqrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R8LmH4e+PMnsi9Af9Onv9SkMhAoC/ASzAF/xHgzRWGA=; b=0Z64/Rd+Ae1iLkBYJzBh/ydf8kv8rsbwXpoKN1tVBAFBW9H7Nnx1kanOOWe4yRIw5o Bald0NuRcbQ/iwwOg6iereWPu3K3oR9dgSYVT7BPRLj063OsZxjvkFy4ls3FTq0ePytI ISV94ofyMJi7FaMYuV49ww0paHRG1wP32/DxAAXT+nGFqbX0EmRCM1jd9c0h2R70tg8/ r5RWWpM6eQFag/tsOQAbXiQ5RZmN4oKLzHyKKgRWkuo99XYKf7WOYf76clwynTWbfwSe tEC+9lanyn6YjtgqhZpeoZfE8xLjkDZYELxDeROFtlMthMewj+2qCmdN+e3vIGPWofIP HgEA== X-Gm-Message-State: AOAM531qyFWQD9akh1B6oyGqb21V05e/m7GBBUDdXe+7FI35Eg1BWmRK xheLkJEqyQEb8Z2aTzhH/6c8eifbmKOurA== X-Received: by 2002:a63:f057:0:b0:3db:8238:ed3d with SMTP id s23-20020a63f057000000b003db8238ed3dmr10624914pgj.345.1653091481889; Fri, 20 May 2022 17:04:41 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 36/49] gdbstub: Widen gdb_syscall_complete_cb return value Date: Fri, 20 May 2022 17:03:47 -0700 Message-Id: <20220521000400.454525-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Always pass a uint64_t. This resolves a FIXME in the m68k and nios2 semihosting that we've lost data. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 3 +-- gdbstub.c | 7 ++++--- semihosting/arm-compat-semi.c | 9 ++++----- semihosting/console.c | 7 +++---- semihosting/syscalls.c | 2 +- target/m68k/m68k-semi.c | 10 +++------- target/nios2/nios2-semi.c | 8 +++----- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 8e9cdcb1c1..63764a9766 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -77,8 +77,7 @@ struct gdb_timeval { #ifdef NEED_CPU_H #include "cpu.h" -typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, - target_ulong ret, target_ulong err); +typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err); /** * gdb_do_syscall: diff --git a/gdbstub.c b/gdbstub.c index a3ff8702ce..5286253f8a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1870,11 +1870,12 @@ static void handle_read_all_regs(GArray *params, void *user_ctx) static void handle_file_io(GArray *params, void *user_ctx) { if (params->len >= 1 && gdbserver_state.current_syscall_cb) { - target_ulong ret, err; + uint64_t ret; + int err; - ret = (target_ulong)get_param(params, 0)->val_ull; + ret = get_param(params, 0)->val_ull; if (params->len >= 2) { - err = (target_ulong)get_param(params, 1)->val_ull; + err = get_param(params, 1)->val_ull; } else { err = 0; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9cfa8a421c..3eb9d1c049 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -215,7 +215,7 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_cb(CPUState *cs, uint64_t ret, int err) { if (err) { #ifdef CONFIG_USER_ONLY @@ -232,7 +232,7 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) * SYS_READ and SYS_WRITE always return the number of bytes not read/written. * There is no error condition, other than returning the original length. */ -static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err) { /* Recover the original length from the third argument. */ CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; @@ -250,8 +250,7 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) /* * SYS_SEEK returns 0 on success, not the resulting offset. */ -static void common_semi_seek_cb(CPUState *cs, target_ulong ret, - target_ulong err) +static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { ret = 0; @@ -272,7 +271,7 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { /* The size is always stored in big-endian order, extract the value. */ diff --git a/semihosting/console.c b/semihosting/console.c index ef6958d844..3dd0ac60e2 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -64,11 +64,10 @@ static GString *copy_user_string(CPUArchState *env, target_ulong addr) return s; } -static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void semihosting_cb(CPUState *cs, uint64_t ret, int err) { - if (ret == (target_ulong) -1) { - qemu_log("%s: gdb console output failed ("TARGET_FMT_ld")", - __func__, err); + if (err) { + qemu_log("%s: gdb console output failed (%d)", __func__, err); } } diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 269f750d98..4c934654cd 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -145,7 +145,7 @@ static int copy_stat_to_user(CPUState *cs, target_ulong addr, static gdb_syscall_complete_cb gdb_open_complete; -static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void gdb_open_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { int guestfd = alloc_guestfd(); diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index da0186f3ef..94deebf09e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,7 +93,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) +static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || @@ -108,7 +108,7 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) +static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || @@ -122,16 +122,12 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) static int m68k_semi_is_fseek; -static void m68k_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; if (m68k_semi_is_fseek) { - /* - * FIXME: We've already lost the high bits of the fseek - * return value. - */ m68k_semi_return_u64(env, ret, err); m68k_semi_is_fseek = 0; } else { diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 3e504a6c5f..4d02789d26 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,8 +108,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, return true; } -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, - uint32_t err) +static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret, args) || @@ -124,8 +123,7 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, } } -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, - uint32_t err) +static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret >> 32, args) || @@ -139,7 +137,7 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, static int nios2_semi_is_lseek; -static void nios2_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; From patchwork Sat May 21 00:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574940 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2682333mab; Fri, 20 May 2022 18:01:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRyImtqEXUIF8MS8+Iyhua3O3vsn/35VYUZAW/V0Mw3930UhtEsNKxIRIWe8jNdB8MkeCX X-Received: by 2002:a05:6214:23c8:b0:45f:b582:346e with SMTP id hr8-20020a05621423c800b0045fb582346emr9792718qvb.109.1653094897064; Fri, 20 May 2022 18:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094897; cv=none; d=google.com; s=arc-20160816; b=IkRo65f20y8nZWTg+rTyM4FvdSPoqdym5Lql1vS4CjduWDHgpuTI+9svqvvoFMmCn1 zTBzXVWdc0CamoR9E1UgNCkMvvWphm6SoiEZOjrR7b/V8M4jZCcvhu+UQ/RpLTcoGsgJ xY51hUOXZFuzqmtnxnmUf5imcJNVl1PvpSHuOaQj7dg+xzLdIy3EHfjL7byVBtDF8mxj o1hJLcLbo4S1mQULL1KzBpt3O6/jEhIAjUqZqcGVsL6k3BDhBqexdure99ZIg2bdcEdJ ZEMv6LNbg8gtzd1WTP0VZpJPo9P2bqB0DpE6W3d59NdxWc0uj9sgNqYyxk6o4kVPSFyH BKew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=fzhIMLbx8y7mbsMeFHMCFoVvluWiKy+dYIdV9x9esMd3vx7CUTxxGfEaX8TP8LWzdV NYPZNNkG8mCZH7uBcLluDP6+IDmmp5yFNdVc4fmN4NH73trtayJ4pi9O6fJ1ZPtsut1T ghq6mSV7AMySHWqc8gjO6ZY7TEoRwl9KGhMfcYD0oeLJ27lQ4nBX87rrXrrpNDGjkepn xIq6hnTE5qM/o85ObNkD85azeQqgBXTUayLbY0I6+4bmML0cIF+CXQAcAcdNanI2zhaC GrfmSybUHcwlkEl9E0XM/w94DsZzK0dGRpppMH/NWUu3WXsyp/mn73R9OKu5hpWHRmri c9oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qZaGPRzD; 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=pass (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 ey6-20020a0562140b6600b00440e46a7b6asi511740qvb.8.2022.05.20.18.01.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:01:37 -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=pass header.i=@linaro.org header.s=google header.b=qZaGPRzD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDUu-0004r0-JE for patch@linaro.org; Fri, 20 May 2022 21:01:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc6-0008CB-BS for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:41867) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbv-00042m-FE for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:50 -0400 Received: by mail-pf1-x42d.google.com with SMTP id p8so8949934pfh.8 for ; Fri, 20 May 2022 17:04:44 -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=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=qZaGPRzD/idX/MG9PMfe4gX4E+cE6HujhAB3uSA5Pny4YwEH55kpFA2hgIw6OzNWZ8 E5i14n8Z1eaQUE+q3ssGoY7os9gDZfRcMJ4EY2mVHimuvnc/iJBbK+dQoGCi6lE4f3iX QCK650O5aJN+niYeKw7BFXh/zrlWl0l911le+BAU9OvO8vX+Q7H7Xv23Vk4CIN8gm3FB Jz9YNgsE1LPZHF8RVyjJbww1G0Tr1Mo3ZSZKJYTzgZP0mJmNQQB9I82JfmXmLvHY1Yr+ wKR81cZ5Qy5qN1kmJoO3iYiblK1lOBYbQdHsWggC9tXcLfgy1evggMezWn/6y8nu7fan eRQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=39WrIK0dtBnSJ9iloKeSzZAOWFzvdVBOQBPFrK/KpJyDzbcd53YBRXlKoh7lBkNqw3 x43dRHhmO4fDrg+De5uRhmsklcwy8RJqk8bvUT9IDCalYJdO8JoidjssdSJ/Ar5mnr0r rDDNn1Zqr1xoH54M0/sqaBm15F8rNTDdQancVkG7PiMRF1sAuSr7xcLsufOYr/Zee/u0 K3gA2EX0CNjB53DTcUQ6WgY3ZbcmSVRb/SxHFF7NVVxp0hECIskM9sfcKTEJJxxN/MnE rGU2BbuJn0jDlBHctzqGqYmtfIOr8jNcwZ8SkUu50gOoEO+WbF1ers8iRQQmNn/IpMlj buzw== X-Gm-Message-State: AOAM530DqdkACU276Dr+bFA17BCBxaQdWhXY+qYHzQyJRl/p0pS1Zif1 iRfDUs+EBWxssVEwR3DboZdg3F2/m/5m6g== X-Received: by 2002:a63:202:0:b0:3f2:75a7:cd28 with SMTP id 2-20020a630202000000b003f275a7cd28mr10621770pgc.537.1653091483019; Fri, 20 May 2022 17:04:43 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 37/49] semihosting: Fix docs comment for qemu_semihosting_console_inc Date: Fri, 20 May 2022 17:03:48 -0700 Message-Id: <20220521000400.454525-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The implementation of qemu_semihosting_console_inc does not defer to gdbstub, but only reads from the fifo in console.c. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 0238f540f4..4f6217bf10 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -41,11 +41,10 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); * 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: + * Receive single character from debug console. 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 * From patchwork Sat May 21 00:03:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574934 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2677531mab; Fri, 20 May 2022 17:49:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnKFCxs7EzZsqyqMeAxeijTixKKJSsQpcO8KI87JlKcKTcuXQ7hBJTEEuWz/oOjZMLYQzV X-Received: by 2002:ac8:7f43:0:b0:2f3:d55d:7296 with SMTP id g3-20020ac87f43000000b002f3d55d7296mr9637243qtk.635.1653094161176; Fri, 20 May 2022 17:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094161; cv=none; d=google.com; s=arc-20160816; b=H2hap42VWZqOANOM5S40rVinIZWdVB85cCyVZ8XI0Lj8a7h4R8hMTavnhAX3zjQHuD W7w7C9h4XkPhRbjXcfhVwqKUwGMtBEMvxBI0lIZieiSYLzqlc0dDVpXpc/mtBebAXpsk DUTVSAEsCbqSHa0BmLSNiHLqE5eF9uSpX+jw+/ahYewJE9OaiL0X7tfowKLLoqATZKet wCpC1wg/q1Jau7Zxte9LD12N2glQ7zuWtj0MC0HpH3OxaG41rXwV9KH4dG5nG00yZsq4 pxVjqtvyjhe3kel7ijKQb5rpClerwDwDhSMy4LfYk/STkP+Y8TsiO5GvwqCekFwC4r6B cjFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NkYDWZD4Kl/AmjNy/kSwweyafB44BYvhT/zKiCaM700=; b=y5qrpMz/uJueuVgD1uoN0xwUwYsUw9567dDRWmZF2jG9xcu36QEXuYbi/DdmquPv1X 2W/Opcjk+tpPnyFFMSk0Y0YXNvD4RA5w42xC13cHLg1vfmEYsCZDUXMZPhrRgDk2hB9O kkj/JCQeOPw/4amJBLARvtKh4I85mqbgJqkmhclYnd+SzDou/6lFLr9lRR94LhyoDES0 m5v83NrYeiDPFZeddmYvjwCwvUyiQ6n4iRSWj68fCLiFvrkS8IwJWYClnH8wHSL1g7RI RGvMteddFi7RqS4W1FNkCFOZPk4n7JK1nNCeeuCfnIA7nLnld3RI/aZd+xZYJ3UwhZ30 BXQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NF36B6op; 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=pass (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 h12-20020a05620a284c00b006a3224bfdb4si423932qkp.297.2022.05.20.17.49.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:49:21 -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=pass header.i=@linaro.org header.s=google header.b=NF36B6op; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDJ2-000334-RL for patch@linaro.org; Fri, 20 May 2022 20:49:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc7-0008CP-CN for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:50709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbw-00042v-94 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:57 -0400 Received: by mail-pj1-x1031.google.com with SMTP id ds11so9333068pjb.0 for ; Fri, 20 May 2022 17:04:44 -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=NkYDWZD4Kl/AmjNy/kSwweyafB44BYvhT/zKiCaM700=; b=NF36B6opwH1/yH8in3Gz8o1zhOVYxCJDM6o8+tMoKDSIkXYZeK1DwhY/sAbWXc24Lz FfWx01tddEH3skAkoQjPj2yRdhsPgQIwPQqUuXqez0HJzmKaXBliD2wXMivvn9txdK0l FYpTko7kMg3biIOcQu7bjCiteZTknxCOAFeXrTZYFuOcPk4zEOuJ0M4m6+rR/NM9gqbq PBg1kiK1QNDTvwX2Uu671NkAAYPclu9NoZe4K7Y7s4xYchfTRzaZ/TI1IHHeQ4O4agmp fuXC6Gij20DOCGMEmbnXpswdZoshLkFlYXBhJ5iIMDuDropAoq2Q74BOX1k68ZPJoike /s+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NkYDWZD4Kl/AmjNy/kSwweyafB44BYvhT/zKiCaM700=; b=mSvdjeFzEbNUsaTZMngyemI7EuxbO0wqPrUqxYqDykhf1BRxZk2WVXY1NrQxIHDBr+ znpbNVXGdkNvOzyQgZpOcJVH9noYeZGYrw/ab7gvbnD4zWjv1QR/hmREtpcDwD7RDyoe jH/p22M7m/2s2pBkmyR/mt5Z40NvJE5h8tVDipKqoeLSvt4WBo/NVs3wQzUxvGr40Vx3 inuHmHlrKv4tj0JTn/0Zw0R4oZDFziCHMJ6RRmFbQH1Rq5hr4WUHu25J0mOLXCw+I44g sUefkq4rCUmwFt1I5HsJb7odKF9A9pzw04sdzFGjAWMWAsgfdlJJ98CtkDhmfp63hmJV FmjA== X-Gm-Message-State: AOAM530xIdZRykE+rxGO6M/LbpaabA9R9wtDd0x1WN/smZgaB4risBmb boSgukysCcIncUc2TPKP5tEMdheZVkBbcQ== X-Received: by 2002:a17:90b:4a07:b0:1df:7c10:7d3e with SMTP id kk7-20020a17090b4a0700b001df7c107d3emr14371970pjb.109.1653091484088; Fri, 20 May 2022 17:04:44 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 38/49] semihosting: Pass CPUState to qemu_semihosting_console_inc Date: Fri, 20 May 2022 17:03:49 -0700 Message-Id: <20220521000400.454525-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We don't need CPUArchState, and we do want the CPUState of the thread performing the operation -- use this instead of current_cpu. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/semihosting/console.h | 4 ++-- linux-user/semihost.c | 2 +- semihosting/arm-compat-semi.c | 2 +- semihosting/console.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 4f6217bf10..afc961057c 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -39,7 +39,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); /** * qemu_semihosting_console_inc: - * @env: CPUArchState + * @: CPUState * * Receive single character from debug console. As this call may block * if no data is available we suspend the CPU and will re-execute the @@ -50,7 +50,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); * * Returns: character read OR cpu_loop_exit! */ -target_ulong qemu_semihosting_console_inc(CPUArchState *env); +target_ulong qemu_semihosting_console_inc(CPUState *cs); /** * qemu_semihosting_log_out: diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 17f074ac56..f14c6ae21d 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -56,7 +56,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) * 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) +target_ulong qemu_semihosting_console_inc(CPUState *cs) { uint8_t c; struct termios old_tio, new_tio; diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3eb9d1c049..5d10a2b932 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -415,7 +415,7 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(env); + ret = qemu_semihosting_console_inc(cs); common_semi_set_ret(cs, ret); break; diff --git a/semihosting/console.c b/semihosting/console.c index 3dd0ac60e2..7b896fe43b 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -144,17 +144,17 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -target_ulong qemu_semihosting_console_inc(CPUArchState *env) +target_ulong qemu_semihosting_console_inc(CPUState *cs) { uint8_t ch; SemihostingConsole *c = &console; + g_assert(qemu_mutex_iothread_locked()); - g_assert(current_cpu); if (fifo8_is_empty(&c->fifo)) { - c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, current_cpu); - current_cpu->halted = 1; - current_cpu->exception_index = EXCP_HALTED; - cpu_loop_exit(current_cpu); + c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, cs); + cs->halted = 1; + cs->exception_index = EXCP_HALTED; + cpu_loop_exit(cs); /* never returns */ } ch = fifo8_pop(&c->fifo); From patchwork Sat May 21 00:03:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574915 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2666783mab; Fri, 20 May 2022 17:23:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv48K08knOIjz5nR8Na0NTS429UqAq841eNM2xgTtpvGzDVusGv/WKOrcGg0gLWLTTvBO+ X-Received: by 2002:a05:622a:13d1:b0:2f3:ca31:2200 with SMTP id p17-20020a05622a13d100b002f3ca312200mr9691194qtk.348.1653092597251; Fri, 20 May 2022 17:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092597; cv=none; d=google.com; s=arc-20160816; b=LwU3DOT+0Ydn+/iiDdJUQzSlfh2Yq3eHvJ0UM7ZaNPMb8p5LpE/XTOO6q0hwdg0EuL xx/6S2PywLclnergLwHFbn91+aaPzyrXgE+xlR8kVRVlqTN+DCu8kk97z0b1MRGXD0vZ OJA8QfQypdyj9cPr6AnLCPq/D9qXdVYJy2k1zCG1M8osUKmRcIHIAS0Ygov9FQHSjVXK xjOPe2eV5R2BHyXlKCsrqPCWcpeve32NiGr8giCYYKoU5PJPQbtBMTT3KxEabfmeLJdk P9zdI5rLikBQa0EyaPhMSKvlTWH7z15yX/K6Gw0gnVhMXIRKqlm6pdKbd1gbfaq75uJ0 UooA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jZGKSwAg+QGOS7FPNjoYkg7xUN0QcDGNw7JjeaNbJgo=; b=v/T000uWtfpB3Xz25H+tYWV9DBUApNwovaMQn0hXUReSc4D6SnKNF3j134W/AylTW6 6ptsmm7p6F5OPdQItkWMpEITzR7PW/g5rHPOBOIJUlOf7K6hM5gEFVGZtvSRyltgtnCB i0NPEIIm5fRir77pDhma5nES23nzrt/LmFex76vBnI82udk6nrDilMwoNeNBjLB3UMd8 s9sJk/br1OjCeFs0twt0vMto0h6J5h4KtXSJPEySaCYg8CZfCseF7SC5h3/I2KBx6KYa mBxrGANU1dktjgZzpZgUcaOLAizPWm9n8DSG7HficfnPnd7jryiiAwQ7eS7djObdnAlG e3fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fv+JnyGZ; 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=pass (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 u7-20020ac858c7000000b002f7a6d0001bsi392981qta.704.2022.05.20.17.23.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:23:17 -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=pass header.i=@linaro.org header.s=google header.b=fv+JnyGZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCto-0003tl-Pv for patch@linaro.org; Fri, 20 May 2022 20:23:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc7-0008CN-3o for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:00 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:39768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCbw-000449-54 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:51 -0400 Received: by mail-pl1-x633.google.com with SMTP id bh5so8560640plb.6 for ; Fri, 20 May 2022 17:04:46 -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=jZGKSwAg+QGOS7FPNjoYkg7xUN0QcDGNw7JjeaNbJgo=; b=fv+JnyGZIpYDi4RziscQCTjJ4hOwQc0tcbMkLlBVtjm0Uev+L3RRb5FonAh5y8wzMa nH6N/JIqnkU+05iaAFkxlHSDsYYpzDoZPdArLvsDzgHzCIwufIBn+08rh+s7DgXb/0rf kBj6H3Eil2M87qO9+PMY6AGgY0S+Hn4gmxvrSJ8QOzcMVhG+hFutzZpvgTLNSwbM00bf /yqVNuSRdxnc+VB6fpNK9ZBvjGHtEm6gOwenTSQhbJcbRaO7hwx4EhGaBQotAfJUVzzn coQM7IOmB+AEyTvTR6trjlyf9orjreIqFKH1bjXPjXxSh8sUhTVRhRx1jvFrsBwgnh4q M74A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jZGKSwAg+QGOS7FPNjoYkg7xUN0QcDGNw7JjeaNbJgo=; b=uP4HGM9Gqj29u7XLZpKteH8J4j8cXcJbeNox4gPThXqN3/y+716zLEsu0bKLU/w+3V wPaNVEky/1uQjne+zX5TmYERFrfDl2NUI3NAp82kZq090B39e85ifrVAgYgkf9sgodvE V8/7ZaZnPkqdRzzg7+b/gsUIrpwZlgknDPQ8Naew3WPtVu6hmge+nVtcr6qOLk7G+rge RU6x+Ji0ZOrW1ClTNz45G3d687/EuxAjqMdnPxXBGI+E8L/mETGkU7+Rl18sYptomsx/ FZmPtNWPP4H6M/pEVhGblw8oG1qCamF34of7aY4+3X37OMy9dXMu3jCdS7b86h9n3OYw ApuQ== X-Gm-Message-State: AOAM532RV7zhMFdEj97vu5PZlXvrw2KGcGrrXQP8ZjL2cytqneOjTbJf OK4FpF45lt6Kr+Tbg52kjM/xKtSf9xBrmw== X-Received: by 2002:a17:90a:db95:b0:1df:37e7:6a28 with SMTP id h21-20020a17090adb9500b001df37e76a28mr14257375pjv.204.1653091485288; Fri, 20 May 2022 17:04:45 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 39/49] semihosting: Expand qemu_semihosting_console_inc to read Date: Fri, 20 May 2022 17:03:50 -0700 Message-Id: <20220521000400.454525-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Allow more than one character to be read at one time. Will be used by m68k and nios2 semihosting for stdio. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 14 ++++++++------ linux-user/semihost.c | 10 ++++++---- semihosting/arm-compat-semi.c | 11 +++++++++-- semihosting/console.c | 16 ++++++++++++---- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index afc961057c..39dbf1b062 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -38,19 +38,21 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); /** - * qemu_semihosting_console_inc: - * @: CPUState + * qemu_semihosting_console_read: + * @cs: CPUState + * @buf: host buffer + * @len: buffer size * - * Receive single character from debug console. As this call may block - * if no data is available we suspend the CPU and will re-execute the + * Receive at least one character from debug console. 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! + * Returns: number of characters read, OR cpu_loop_exit! */ -target_ulong qemu_semihosting_console_inc(CPUState *cs); +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); /** * qemu_semihosting_log_out: diff --git a/linux-user/semihost.c b/linux-user/semihost.c index f14c6ae21d..2029fb674c 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -56,21 +56,23 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) * 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(CPUState *cs) +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) { - uint8_t c; + int ret; struct termios old_tio, new_tio; /* Disable line-buffering and echo */ tcgetattr(STDIN_FILENO, &old_tio); new_tio = old_tio; new_tio.c_lflag &= (~ICANON & ~ECHO); + new_tio.c_cc[VMIN] = 1; + new_tio.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &new_tio); - c = getchar(); + ret = fread(buf, 1, len, stdin); /* restore config */ tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); - return (target_ulong) c; + return ret; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 5d10a2b932..20d97290ff 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -415,8 +415,15 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(cs); - common_semi_set_ret(cs, ret); + { + uint8_t ch; + int ret = qemu_semihosting_console_read(cs, &ch, 1); + if (ret == 1) { + common_semi_cb(cs, ch, 0); + } else { + common_semi_cb(cs, -1, EIO); + } + } break; case TARGET_SYS_ISERROR: diff --git a/semihosting/console.c b/semihosting/console.c index 7b896fe43b..df618a28a4 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -144,12 +144,14 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -target_ulong qemu_semihosting_console_inc(CPUState *cs) +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) { - uint8_t ch; SemihostingConsole *c = &console; + int ret = 0; g_assert(qemu_mutex_iothread_locked()); + + /* Block if the fifo is completely empty. */ if (fifo8_is_empty(&c->fifo)) { c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, cs); cs->halted = 1; @@ -157,8 +159,14 @@ target_ulong qemu_semihosting_console_inc(CPUState *cs) cpu_loop_exit(cs); /* never returns */ } - ch = fifo8_pop(&c->fifo); - return (target_ulong) ch; + + /* Read until buffer full or fifo exhausted. */ + do { + *(char *)(buf + ret) = fifo8_pop(&c->fifo); + ret++; + } while (ret < len && !fifo8_is_empty(&c->fifo)); + + return ret; } void qemu_semihosting_console_init(void) From patchwork Sat May 21 00:03:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574927 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2673292mab; Fri, 20 May 2022 17:38:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl1Zy7kVy8gqNBNQIpip2q7OuzuwusFvZaRBZbRjdxlcBSNx0gpns6nMhQqcnztKW3tSr1 X-Received: by 2002:ac8:5dcc:0:b0:2f3:d8d2:7cf with SMTP id e12-20020ac85dcc000000b002f3d8d207cfmr9714142qtx.464.1653093492089; Fri, 20 May 2022 17:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093492; cv=none; d=google.com; s=arc-20160816; b=Yk00Uof3y/Lai4rJFnQDP73frMA6KJzl/OraX3jqm1mCeoqaveE/mVMpq6o9vZFOCF 4DM3ORQ3ofJ9hoEW0v7yOWoLD2iyMYz2p8FFAHxpmRWztK7kdifrRfPLucIAjR0pVcYZ B8yLTQn59sIpvIbiO+R6rU00qL8pL8KnKADwXwLBGGr94yG38okRDbsaHvtZnuOMWA3J c7ZxQEULgN4esbshrEuXJtFbn13KcRLl+SMyOPkFeXc7RfLj/NN5ytT0xpc8uchLR3YV kLns71WVoMPL7Rr1mI0ncVgxlZV+MVZMzi24Sw8bn0PFVZnfZVE2WQs28wz+D9v1qoCw DKpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E+fPmq/gIqgkSE063dcs/6u6fyml6PThxo/MDWH5lGI=; b=0xKvuG4cugn6MJB421BYlO0FSSs+e7xP6qU3xwZRso+Uz2xP8JgVEMxvafi7tXUxmt Bfm9vDiEbVSPJBK73uhq4gSbg3rsmeSOACH0vX5i4jwT3ZxLjrAKPHji5/MZnjUu2g2A 7zUl1YCpwp+5vCURWFYsmJILY0YcZdpuaRNTE6MAzArLx5dBCAkKbB3M5ieeO3mxJ3fd eSfHgG3lEORaqRq9KeFlqQ/7vPPRPYEHHjK3WT0REVPvC4mTID1DZLUHQJrRD6B6pHl2 HzTIEImYyygF5lNqS+KY94BkwJu7N/e8Yp+tQBA2UH1WCKqqB5iNSsX1wDuLreWtTEkp TE1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hOEPrGxt; 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=pass (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 de26-20020a05620a371a00b006a331d7503fsi429184qkb.347.2022.05.20.17.38.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:38:12 -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=pass header.i=@linaro.org header.s=google header.b=hOEPrGxt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD8F-00087F-Lg for patch@linaro.org; Fri, 20 May 2022 20:38:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCes-0002tM-DY for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:50 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:54926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCeq-0004Yj-Hu for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:50 -0400 Received: by mail-pj1-x1032.google.com with SMTP id ev18so9300459pjb.4 for ; Fri, 20 May 2022 17:07:48 -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=E+fPmq/gIqgkSE063dcs/6u6fyml6PThxo/MDWH5lGI=; b=hOEPrGxtacFaN+AzjEVQCzXCZELJdHG6ZFr+u3ARnbTTyiVYjSoRZfJe8PouDs7m0F MkEBr1dpfwmjRBx5CbrQx5Ut+Ngl2U6jh3pqGviEkwue3UDeuBs7nT3sh/tf3bhi0+yz L6etia1cE6UAFXWxtTiDOmapqXbURMygpOcyICnatpbWK0at8dEk0IKxfKlbVPk6pvcS sspw/mDUwQKA3B5/PgTIVrHIkcFdVqFCLdrMYNfAQ9U9CHFKgF0a74zIRNp+1L6PUfIV Nblve+86ceYd2qFE3++Wy31e+92BdYIf5xr40QvTHW89FXvj7u4iD0XC81ZjzdGHn2H5 cbcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E+fPmq/gIqgkSE063dcs/6u6fyml6PThxo/MDWH5lGI=; b=rxUrRuI2ESj49lzVnbJXYjiON5X/DRBBOUNy/VgUFdIWrOAd5sNRyQt4+To8ZEsHgO 8vh6vTCL9x379MQwdXeXKp5DpKORUPy04sUfcRyrRpzkZnYUszrEztRJ/NMvoC7/10fe 13YHBXti/5lZAQpYCyCZWK2SRmxIFWmd9sZWUNIiUI/nJyQ5h3p8cisYXoUtXVdryjtz Ahr7bWsXn4itV2bWNvoUEL+ArcI5qrUm6Epxr2cdgBtNCrilEINKJATf2Dai2lxADo8C hvlmSaEpC4zIHOcgzpY+3U11SoDvO5hnKKqEFaMmf3B60fSb6EfzDOCO2MzI/k3DlSc8 UMAw== X-Gm-Message-State: AOAM533zLWmmqz25YHlDugomrdQPnZMvdzS1j2jTa5q73ZWRzoSTbHq8 irUI14dcc1yYPb4y71QZ9Z6ZgdsW4sOBIw== X-Received: by 2002:a17:902:6bc1:b0:15d:1e15:1a75 with SMTP id m1-20020a1709026bc100b0015d1e151a75mr12477013plt.114.1653091667016; Fri, 20 May 2022 17:07:47 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 40/49] semihosting: Cleanup chardev init Date: Fri, 20 May 2022 17:03:51 -0700 Message-Id: <20220521000400.454525-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename qemu_semihosting_connect_chardevs to qemu_semihosting_chardev_init; pass the result directly to qemu_semihosting_console_init. Store the chardev in SemihostingConsole instead of SemihostingConfig, which lets us drop semihosting_get_chardev. Signed-off-by: Richard Henderson --- include/semihosting/semihost.h | 13 ++----------- semihosting/config.c | 17 +++++++---------- semihosting/console.c | 31 +++++++++++++++---------------- softmmu/vl.c | 3 +-- stubs/semihost.c | 6 +----- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 0c55ade3ac..5b36a76f08 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -51,14 +51,6 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } - -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); @@ -66,12 +58,11 @@ const char *semihosting_get_arg(int i); int semihosting_get_argc(void); const char *semihosting_get_cmdline(void); void semihosting_arg_fallback(const char *file, const char *cmd); -Chardev *semihosting_get_chardev(void); /* for vl.c hooks */ 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); +void qemu_semihosting_chardev_init(void); +void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ #endif /* SEMIHOST_H */ diff --git a/semihosting/config.c b/semihosting/config.c index 50d82108e6..4bca769fad 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -50,7 +50,6 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; - Chardev *chardev; char **argv; int argc; const char *cmdline; /* concatenated argv */ @@ -121,11 +120,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) } } -Chardev *semihosting_get_chardev(void) -{ - return semihosting.chardev; -} - void qemu_semihosting_enable(void) { semihosting.enabled = true; @@ -171,16 +165,19 @@ int qemu_semihosting_config_options(const char *optarg) return 0; } -void qemu_semihosting_connect_chardevs(void) +/* We had to defer this until chardevs were created */ +void qemu_semihosting_chardev_init(void) { - /* We had to defer this until chardevs were created */ + Chardev *chr = NULL; + if (semihost_chardev) { - Chardev *chr = qemu_chr_find(semihost_chardev); + chr = qemu_chr_find(semihost_chardev); if (chr == NULL) { error_report("semihosting chardev '%s' not found", semihost_chardev); exit(1); } - semihosting.chardev = chr; } + + qemu_semihosting_console_init(chr); } diff --git a/semihosting/console.c b/semihosting/console.c index df618a28a4..4088192842 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -27,11 +27,21 @@ #include "qapi/error.h" #include "qemu/fifo8.h" +/* Access to this structure is protected by the BQL */ +typedef struct SemihostingConsole { + CharBackend backend; + Chardev *chr; + GSList *sleeping_cpus; + bool got; + Fifo8 fifo; +} SemihostingConsole; + +static SemihostingConsole console; + int qemu_semihosting_log_out(const char *s, int len) { - Chardev *chardev = semihosting_get_chardev(); - if (chardev) { - return qemu_chr_write_all(chardev, (uint8_t *) s, len); + if (console.chr) { + return qemu_chr_write_all(console.chr, (uint8_t *) s, len); } else { return write(STDERR_FILENO, s, len); } @@ -106,16 +116,6 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong 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 = opaque; @@ -169,10 +169,9 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } -void qemu_semihosting_console_init(void) +void qemu_semihosting_console_init(Chardev *chr) { - Chardev *chr = semihosting_get_chardev(); - + console.chr = chr; if (chr) { fifo8_create(&console.fifo, FIFO_SIZE); qemu_chr_fe_init(&console.backend, chr, &error_abort); diff --git a/softmmu/vl.c b/softmmu/vl.c index 84a31eba76..3395c877aa 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2041,8 +2041,7 @@ static void qemu_create_late_backends(void) exit(1); /* now chardevs have been created we may have semihosting to connect */ - qemu_semihosting_connect_chardevs(); - qemu_semihosting_console_init(); + qemu_semihosting_chardev_init(); } static void cxl_set_opts(void) diff --git a/stubs/semihost.c b/stubs/semihost.c index 4bf2cf71b9..f486651afb 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -65,10 +65,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) { } -void qemu_semihosting_connect_chardevs(void) -{ -} - -void qemu_semihosting_console_init(void) +void qemu_semihosting_chardev_init(void) { } From patchwork Sat May 21 00:03:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574943 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2685145mab; Fri, 20 May 2022 18:07:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysef192f7wN2uLmBuFqt9iD6IyqyLPyuqagzoS7av3mi7v1uWcydbpd0ROAKpbRBf8HMCr X-Received: by 2002:a05:6214:29ee:b0:461:ccb9:ba7e with SMTP id jv14-20020a05621429ee00b00461ccb9ba7emr10257272qvb.51.1653095251244; Fri, 20 May 2022 18:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653095251; cv=none; d=google.com; s=arc-20160816; b=K8aPLUNh6+nFWNCp71XYfvy2shXfHnDFLcKh3AYJf7CoPOzX7Whh4uGdCIAiPY/Lxg QBsAjuvcVKdX9I09DCkpNJHHl7G4RHWdkVW9Kj0AG+4ZuJXD3taeHFC9vYdQ8YIDYUYu GdLeHUDqcEcaWSWA3WshBrnasKX6Ucy6boceKEOqF8wc5s1P7kfFLpc5ZU9W3GyZiKFh J/OplEGkKa9gk5DIKK8BkFYhF6YA5Fe6bRkP5uhfG1Wl3ZcFZRioWs1mRBGjIhdLqW7l 0wxa7uF94LAYad74qPsCpCzcy74eJkv/tIYhzRkJwzuoUb4fv7dLX+95iI7oBb8V2Cp2 CEBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=DX1ZA9rtl0EHq7dPTCukR+xj03zA/Aw5VFSk2EHBHIlUJIaMrfPGsCiNvYVRh8nWg8 X0rtpAWmQSsRFK4mbV4ojaYxo0DBrEullLr6+uv/NB6VLupJZ7Y0lU6pmCFzM7g4ZJgm 30Ct1PCOtsbsI84GoMfsHBbxsSOL3G2/HerxkNCZBGRWuGBlBDhz2BaF0r+xUUTKemFD 2KBMuNOPzaQPzyOeGLrK9Hxk1Fi3y2GLyXzNkSvzTzCPESSvhcZsg1jwTtjoj+cIrtB2 LEhtsE8H1hVvHFzBoZHjLt9fpDswo71ZAccX7VFf/TFQINE0Fj9tSF7VyUHCqLbV1DIb ijPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TOTLMS4z; 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=pass (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 c2-20020a05622a024200b002f3d2710f2esi387378qtx.429.2022.05.20.18.07.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:07:31 -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=pass header.i=@linaro.org header.s=google header.b=TOTLMS4z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDac-0001WV-SN for patch@linaro.org; Fri, 20 May 2022 21:07:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCet-0002zY-Np for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:52 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:39778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCer-0004Yn-In for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:51 -0400 Received: by mail-pl1-x634.google.com with SMTP id bh5so8564145plb.6 for ; Fri, 20 May 2022 17:07:49 -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=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=TOTLMS4zCbkvyd9ZhNeJcXRZ+qsrMM8wOqFKLDIFC9e4cUwLzap9VudMeBYoAMOk/B Xw2D8Y+14AtYWZ9PP+CBLkAWI0p/ZVh+NMb5n6VFbv4WeJCe1fNd4pyrbZjhA/LtwXAD 1Vc+TKXcSaeDW8qYzjtwPUfBlXiZqR13+afLiaAG8UfCjhn6v6Wg7xUP5x6MGzT9iKT8 a+fAGkjYr5pz84Vn717XayKZevHn1v3kpTNi2DYUFwr/TSIDlu/GRkEw600xFARv1C/f q6mdT45E5NCySaxT07gLk3TcE2pVvGtKsjV4GCS8hz+ODzuVXPtm5T61TpmYh7RAreOn wHeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=Ieq0aMnO0rbpywfNHMTTb7BsMJCItxvmykHvwBj7e4Q8wGkQTcw6KPmuM1ikmLS4Jo fUeEnRnunwUyBMOllcnaNz7aJ290QOKEjFGVCMVL4poyjlk55tIy+0RCVXzBl6L4rnB+ Y7SN9ZMYcmcKCLAGymttD8ZyOheBVf/TtzmxPDoGJ+/Ehig3Kl5ENM3GdDdD+N1maHCB NRAkoVXdC7SfV4qvGcI0RfDEtF3w0yBVP73C9dYL39v+8f9JFnWjWJ/ufxo5crIpHKMr Tu2A4TvjIVKAF/4s+aXCRGNb/T43c0FDikQEmu6C+seP4iQV9BymaY54op0chjru58SB yL+Q== X-Gm-Message-State: AOAM530KWb13CSsVmvu/9te8fuKiSWa9qq535DSAyXt87b2T0DsdpzpA Oqn/Ok7qh1JpVkBM/O0QzC205JeIMoVl0g== X-Received: by 2002:a17:903:208:b0:162:284:3396 with SMTP id r8-20020a170903020800b0016202843396mr1651710plh.121.1653091668104; Fri, 20 May 2022 17:07:48 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 41/49] semihosting: Create qemu_semihosting_console_write Date: Fri, 20 May 2022 17:03:52 -0700 Message-Id: <20220521000400.454525-42-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Will replace qemu_semihosting_console_{outs,outc}, but we need more plumbing first. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 12 ++++++++++++ linux-user/semihost.c | 5 +++++ semihosting/console.c | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 39dbf1b062..6994f23c82 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -54,6 +54,18 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); */ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); +/** + * qemu_semihosting_console_write: + * @buf: host buffer + * @len: buffer size + * + * Write len bytes from buf to the debug console. + * + * Returns: number of bytes written -- this should only ever be short + * on some sort of i/o error. + */ +int qemu_semihosting_console_write(void *buf, int len); + /** * qemu_semihosting_log_out: * @s: pointer to string diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 2029fb674c..871edf993a 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -76,3 +76,8 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } + +int qemu_semihosting_console_write(void *buf, int len) +{ + return fwrite(buf, 1, len, stderr); +} diff --git a/semihosting/console.c b/semihosting/console.c index 4088192842..b6a342744d 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -169,6 +169,15 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } +int qemu_semihosting_console_write(void *buf, int len) +{ + if (console.chr) { + return qemu_chr_write_all(console.chr, (uint8_t *)buf, len); + } else { + return fwrite(buf, 1, len, stderr); + } +} + void qemu_semihosting_console_init(Chardev *chr) { console.chr = chr; From patchwork Sat May 21 00:03:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574944 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2685834mab; Fri, 20 May 2022 18:08:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5Z6UKLp9+dcGjH/PJu/ecV6wfIUNRvIxNT9zHY4iXFYiMfhL66dZ3M1us5BdbUw38ssls X-Received: by 2002:ae9:d8c4:0:b0:6a0:8f29:274f with SMTP id u187-20020ae9d8c4000000b006a08f29274fmr8182122qkf.584.1653095338241; Fri, 20 May 2022 18:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653095338; cv=none; d=google.com; s=arc-20160816; b=G1m8kq8pH+nakGZPZjZxHUEjJhbovgIfPYRGHEXi/eWObJ3bXhUzBo9XSkUaVqKpTg Zh5vWhMdnejpu1nnRPyZaCyQXphPeKxlKFGJnh2wX6cA6E39T86TEhL/q5kZ5EfxvAcu uZV2W/+4eCW03kxYotODEuCVC6c8dUgba/RYv4I9X/LyYaoS5yXwDYHdAusE289UUl8z 8ov2HcXnt7FfLZBRGB0ygInrLJKvV4sducCo1rl25j9anAJHTpkjxh63izCSZ17o+7zY kNf753T8fcXGv8diHxTi8zTc0AngCNgB1MGjfw0p+8p0/JCe4pcijOZKEZGFwbVK1KdD T9dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/j2cw52lTOWH/atsAabzvb2VUFPtyq5zVPafxci6jYk=; b=HwY5lQwVHhI0aqbLrSqwL9XfbucWQ0WKs8JoDNsr+828g1zBTgZDcPudupPwKNr1WO 6Rc3Sh/flE7APOaG4hGtaOwT+7XY82xvzT9/HE0mLWi3Q7BcjKxGpvZMVfX9YGzhBpaE i6A+wWbX9FmRDjloNbqC0SSO40zT4sRYMjcxqkUNJKTcE2Tr2cyYVVPQyQxusMQmJjhe al1Maj5nbq/kBVG9k0j9pCxBUjox8yKASO32Jk4QsIrrKIYSYY/oVJUgEh+l6QU7cVeJ k9OjzD6zVHKxXx773v85w3EFEOlGfWz76I9PdyV5DO4JNq0c1gLqLPU0+CClTMPZU6qI zQuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M8z/3zqD"; 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=pass (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 4-20020a0562140d0400b0045a85f98984si425538qvh.11.2022.05.20.18.08.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 18:08:58 -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=pass header.i=@linaro.org header.s=google header.b="M8z/3zqD"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDc1-00030z-Rw for patch@linaro.org; Fri, 20 May 2022 21:08:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCeu-00030M-I1 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:52 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:34089) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCes-0004Ys-KA for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:52 -0400 Received: by mail-pj1-x1035.google.com with SMTP id ob14-20020a17090b390e00b001dff2a43f8cso2448163pjb.1 for ; Fri, 20 May 2022 17:07:50 -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=/j2cw52lTOWH/atsAabzvb2VUFPtyq5zVPafxci6jYk=; b=M8z/3zqDdqn7ST5Du25y/V2ZkkZfNqe9spOmHajrFoLfBcL1Pub620ChrGI73T+EG9 tuhyLbDGtxTV4TN8KpH+Hy/B82z3FuOz6rly1hM2wbP0/i+Rv12o2cDzloIxflZBZQTJ p+l8gU11bZSuSUA95lFLzpOphb/SgTWctgb67rIwwF86DxafRh1MTq1NsVolJ5Xj4oTl uDP53fzy7ylivixL64HwQcvuPViqU/xcSm1j/WCrcCqresHuyV3ZY8KZSayk/mGmFe14 E0Af2Z7vbnbQZEC+FNfDaJ+opJp5g0FU74Qzc3CK3e7BXjl3qPQ/nIEI80+cnJSFQ/o/ 9fiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/j2cw52lTOWH/atsAabzvb2VUFPtyq5zVPafxci6jYk=; b=PLDdciXYmA/X2idnL+nSrmuxRu6zKmFWHqL6UdvjtMcXB7zyWhiUtMyMwL/1ofqyXm Pivm8cgTz1TFhseM/P2VNdbJrmctLe7JQ2YWunH7eZFZnlgqCeQdhrj0Es45UV+kg3Ov lucx5sEQN+9jtyhF0yGGUSD1V/HjfUlXuXHfp00y+iApI9OVQFAjU1gvQGctnPKDFiXR IGp/Xz9NYxlnmMDFEsMidoJd40w4x9yG0KklBpFMeCqKatnKGvjxsRjw2+VoeEoa4fv/ QmZ6DhOH2ZwJ513lcflflFM4bJ0//9PVQL0FKUWsZb4VlxUV16Iy6F+9JN8NEbb7nDgK f8zg== X-Gm-Message-State: AOAM530IKZf18lHmL+VTX9eJsOs+y4y478awEMkyAAybWvpwDnTtM90o KEhxmK08AGVc412HD0f6/8duOHKvvFigEA== X-Received: by 2002:a17:903:120a:b0:15f:99f:95bc with SMTP id l10-20020a170903120a00b0015f099f95bcmr12108436plh.48.1653091669222; Fri, 20 May 2022 17:07:49 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 42/49] semihosting: Add GuestFDConsole Date: Fri, 20 May 2022 17:03:53 -0700 Message-Id: <20220521000400.454525-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add a GuestFDType for connecting to the semihosting console. Hook up to read, write, isatty, and fstat syscalls. Note that the arm-specific syscall flen cannot be applied to the console, because the console is not a descriptor exposed to the guest. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 ++-- semihosting/syscalls.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index ef268abe85..a7ea1041ea 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -13,9 +13,10 @@ typedef enum GuestFDType { GuestFDUnused = 0, - GuestFDHost = 1, - GuestFDGDB = 2, - GuestFDStatic = 3, + GuestFDHost, + GuestFDGDB, + GuestFDStatic, + GuestFDConsole, } GuestFDType; /* diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 4c934654cd..aa4ee47649 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -10,6 +10,7 @@ #include "exec/gdbstub.h" #include "semihosting/guestfd.h" #include "semihosting/syscalls.h" +#include "semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" #else @@ -607,6 +608,56 @@ static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, gf->staticfile.len, 0); } +/* + * Console semihosting syscall implementations. + */ + +static void console_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ptr; + int ret; + + ptr = lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = qemu_semihosting_console_read(cs, ptr, len); + complete(cs, ret, 0); + unlock_user(ptr, buf, ret); +} + +static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ptr = lock_user(VERIFY_READ, buf, len, 1); + int ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = qemu_semihosting_console_write(ptr, len); + complete(cs, ret ? ret : -1, ret ? 0 : EIO); + unlock_user(ptr, buf, ret); +} + +static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + static const struct stat tty_buf = { + .st_mode = 020666, /* S_IFCHR, ugo+rw */ + .st_rdev = 5, /* makedev(5, 0) -- linux /dev/tty */ + }; + int ret; + + ret = copy_stat_to_user(cs, addr, &tty_buf); + complete(cs, ret ? -1 : 0, ret ? -ret : 0); +} + /* * Syscall entry points. */ @@ -638,6 +689,7 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) host_close(cs, complete, gf); break; case GuestFDStatic: + case GuestFDConsole: complete(cs, 0, 0); break; default: @@ -667,6 +719,9 @@ void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDStatic: staticfile_read(cs, complete, gf, buf, len); break; + case GuestFDConsole: + console_read(cs, complete, gf, buf, len); + break; default: g_assert_not_reached(); } @@ -702,6 +757,9 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDHost: host_write(cs, complete, gf, buf, len); break; + case GuestFDConsole: + console_write(cs, complete, gf, buf, len); + break; case GuestFDStatic: /* Static files are never open for writing: EBADF. */ complete(cs, -1, GDB_EBADF); @@ -742,6 +800,9 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDStatic: staticfile_lseek(cs, complete, gf, off, gdb_whence); break; + case GuestFDConsole: + complete(cs, -1, ESPIPE); + break; default: g_assert_not_reached(); } @@ -765,6 +826,9 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) case GuestFDStatic: complete(cs, 0, GDB_ENOTTY); break; + case GuestFDConsole: + complete(cs, 1, 0); + break; default: g_assert_not_reached(); } @@ -790,6 +854,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, case GuestFDStatic: staticfile_flen(cs, flen_cb, gf); break; + case GuestFDConsole: default: g_assert_not_reached(); } @@ -811,6 +876,9 @@ void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDHost: host_fstat(cs, complete, gf, addr); break; + case GuestFDConsole: + console_fstat(cs, complete, gf, addr); + break; case GuestFDStatic: default: g_assert_not_reached(); From patchwork Sat May 21 00:03:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574929 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2674836mab; Fri, 20 May 2022 17:41:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxD/JXC3xFCb/NQXsa3fLw/AjGt5GKx5BMdAvO15ybGxSd3/Wce7wMHEmwYeaY+SMsk33p X-Received: by 2002:a05:622a:13c7:b0:2f3:aff5:f58c with SMTP id p7-20020a05622a13c700b002f3aff5f58cmr9875570qtk.511.1653093684422; Fri, 20 May 2022 17:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093684; cv=none; d=google.com; s=arc-20160816; b=AsRGAWUvCXWhDYrhoSFturDRCTGxKPQJM7kF0OZPQ+D9JvuEyCnEihV1I2TZKLlJwx 0NLvNg8MUyyCp8btUxJoev7/tIor72ZSzACgmK1Q5EUiAnDf0Tf8Nd79TtXJTREYFpKj dPBxTzENuXdZCJDtYAa0CvFFVlYDiaY/gMBaiYAavl7aVbpBZ/GC+p/6ssDPCTg+jjao mOuuHQHeVINGGz2M/i7rEttUn64wRPf7fcAC+3sH4sz5ToocpRQsyMer4iO0bfJ7S1B0 uOH6Z7XgGsOFp/JyaMzGRWSgznAEWN6U+uVshCK96WdgIJxMM60UoQamRj+QpQyI1R+X wvdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ptZSGC/FODqEi0rLC9tfcDztwNdHfO1v+1vhlJ7WWkE=; b=0vk7DlgqtUAtYEHFz7GVFesPY2nloYqU3mobi0QgS1qDQOVuYWefzZli7HEl6aw74n pY/jis8F3STr7XfZZi+jSqJBDd1Cw21I7CZ7uvkyDqGqSR2yjEER6+9DgLgzv6ksf6gC +6+bZQAq0SMU9KqDdfT1wJ0aMhr4A2kFKe+onHy9eofOwY78NT7PG+2I7N9EXRr6Ppuc h2YmtSEzMlaZNDo9lucVFWawnt7RXOh28qQk8dry5YTn5IyBK4pwZBPu+OYZwpV9uyRC 7rXRufSYSdBTaAA3WwLQcRUZp6qP39CQhFER67WTTxde0Ka2+Sg3W6vP7yce5bqJ5PsE SGqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xwfx/tFA"; 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=pass (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 q13-20020a05620a0c8d00b006a33e08562bsi349079qki.439.2022.05.20.17.41.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:41:24 -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=pass header.i=@linaro.org header.s=google header.b="xwfx/tFA"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDBM-0003Dl-1i for patch@linaro.org; Fri, 20 May 2022 20:41:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCev-00033C-Pv for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:54 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:44697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCet-0004ZB-RI for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:53 -0400 Received: by mail-pj1-x1032.google.com with SMTP id pq9-20020a17090b3d8900b001df622bf81dso9047980pjb.3 for ; Fri, 20 May 2022 17:07:51 -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=ptZSGC/FODqEi0rLC9tfcDztwNdHfO1v+1vhlJ7WWkE=; b=xwfx/tFAozT2gC9ZlgijarS9gaQqbtw5e3K4aQBukELVqnKoZqG92r10eiClVHvb1F /LDTdHklEoAtzQzkJEak/SKaSmoPE6Ik2yzlUXWQDkfRCYK+Ee01K0VKJWvoUVKYcmxS Obj6mYBQukUMf+S+KDUlS3vSJrmGV7GnmFvavTgkQ1rCiqycejwKFTw1ysj0PFjIfbMG 4zxGKdenqCLeMQ+Hpy7/6s+oowU6ZdTpFQSumMSUtvA+0AFNTjgyE8mxfVaEHna5IWu5 c+sQ7XLC99BHPTcJWA7DfuQWvZnwgCI9djdxU2lh4FfA67jPQ9J5e/SJ943cwrNcZCU9 k1TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ptZSGC/FODqEi0rLC9tfcDztwNdHfO1v+1vhlJ7WWkE=; b=eOL8EWgyxUcInReaATNqlQbaab46qYJB30rJy1+a7GtWkGv0AX4YSyCv7gUczq/vA/ rU+HjbSQxhuKwvlNnfd4omvzGBYoy+2O9M2lNMbaYWJ73iuZANb0wf4Er0/cL1ZOjcQ0 4/qSOF4HJVf4DpOPhx24GzFNvVYPAHvdcNgLHAGgQmUil9UQIDyfkaVZ3/JSZcTzVzD7 A1fxqHNn+rYqrwjF8pPld+hmpfmO7GbhbcZRBAjhvbLyF6zm13W2f6/D3VmSNPJ71VwD TDft2N6+1D6pnUQn2YBS8roqTSUL6xfFAk6A73YalZUR7PR4D2wbU55Vi96PhIea6+QH 21eA== X-Gm-Message-State: AOAM53197WNDg6KwFUe/KmM5Zdzqn4LCKvdERZwUMG50K5Sa5ed2PVNH hJ66LnzduL40yFILPcbqn7qffXToc84STg== X-Received: by 2002:a17:902:ea46:b0:15d:dbc:34f2 with SMTP id r6-20020a170902ea4600b0015d0dbc34f2mr11934197plg.60.1653091670510; Fri, 20 May 2022 17:07:50 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 43/49] semihosting: Create qemu_semihosting_guestfd_init Date: Fri, 20 May 2022 17:03:54 -0700 Message-Id: <20220521000400.454525-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For arm-compat, initialize console_{in,out}_gf; otherwise, initialize stdio file descriptors. This will go some way to cleaning up arm-compat, and will allow other semihosting to use normal stdio. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 +++++ include/semihosting/semihost.h | 1 + linux-user/main.c | 9 ++++++ semihosting/console.c | 2 ++ semihosting/guestfd.c | 52 +++++++++++++++++++++++++++------- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index a7ea1041ea..3d426fedab 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -35,6 +35,13 @@ typedef struct GuestFD { }; } GuestFD; +/* + * For ARM semihosting, we have a separate structure for routing + * data for the console which is outside the guest fd address space. + */ +extern GuestFD console_in_gf; +extern GuestFD console_out_gf; + /** * alloc_guestfd: * diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 5b36a76f08..93a3c21b44 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -64,5 +64,6 @@ int qemu_semihosting_config_options(const char *opt); void qemu_semihosting_chardev_init(void); void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ +void qemu_semihosting_guestfd_init(void); #endif /* SEMIHOST_H */ diff --git a/linux-user/main.c b/linux-user/main.c index 7ca48664e4..7faf390df9 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -54,6 +54,10 @@ #include "loader.h" #include "user-mmap.h" +#ifdef CONFIG_SEMIHOSTING +#include "semihosting/semihost.h" +#endif + #ifndef AT_FLAGS_PRESERVE_ARGV0 #define AT_FLAGS_PRESERVE_ARGV0_BIT 0 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) @@ -906,6 +910,11 @@ int main(int argc, char **argv, char **envp) } gdb_handlesig(cpu, 0); } + +#ifdef CONFIG_SEMIHOSTING + qemu_semihosting_guestfd_init(); +#endif + cpu_loop(env); /* never exits */ return 0; diff --git a/semihosting/console.c b/semihosting/console.c index b6a342744d..677ec2b176 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -190,4 +190,6 @@ void qemu_semihosting_console_init(Chardev *chr) NULL, NULL, &console, NULL, true); } + + qemu_semihosting_guestfd_init(); } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e3122ebba9..b05c52f26f 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -10,15 +10,56 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "semihosting/semihost.h" #include "semihosting/guestfd.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" #else #include "semihosting/softmmu-uaccess.h" +#include CONFIG_DEVICES #endif static GArray *guestfd_array; +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING +GuestFD console_in_gf; +GuestFD console_out_gf; +#endif + +void qemu_semihosting_guestfd_init(void) +{ + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING + /* For ARM-compat, the console is in a separate namespace. */ + if (use_gdb_syscalls()) { + console_in_gf.type = GuestFDGDB; + console_in_gf.hostfd = 0; + console_out_gf.type = GuestFDGDB; + console_out_gf.hostfd = 2; + } else { + console_in_gf.type = GuestFDConsole; + console_out_gf.type = GuestFDConsole; + } +#else + /* Otherwise, the stdio file descriptors apply. */ + guestfd_array = g_array_set_size(guestfd_array, 3); +#ifndef CONFIG_USER_ONLY + if (!use_gdb_syscalls()) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, 0); + gf[0].type = GuestFDConsole; + gf[1].type = GuestFDConsole; + gf[2].type = GuestFDConsole; + return; + } +#endif + associate_guestfd(0, 0); + associate_guestfd(1, 1); + associate_guestfd(2, 2); +#endif +} + /* * Allocate a new guest file descriptor and return it; if we * couldn't allocate a new fd then return -1. @@ -30,11 +71,6 @@ int alloc_guestfd(void) { guint i; - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ for (i = 1; i < guestfd_array->len; i++) { GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); @@ -61,11 +97,7 @@ static void do_dealloc_guestfd(GuestFD *gf) */ static GuestFD *do_get_guestfd(int guestfd) { - if (!guestfd_array) { - return NULL; - } - - if (guestfd <= 0 || guestfd >= guestfd_array->len) { + if (guestfd < 0 || guestfd >= guestfd_array->len) { return NULL; } From patchwork Sat May 21 00:03:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574916 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2666793mab; Fri, 20 May 2022 17:23:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd+H7fbHX5Ft5zOFlDpsB/yKRBQEcbU4czLvAZHtX+t1fpLTAzWOxQXoNAlHHkmK4a9K5b X-Received: by 2002:ac8:5788:0:b0:2f9:1e0a:100a with SMTP id v8-20020ac85788000000b002f91e0a100amr3911331qta.659.1653092598564; Fri, 20 May 2022 17:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092598; cv=none; d=google.com; s=arc-20160816; b=eAgt+YjysTjCCmqJ1z7tvvNEe6jdTVJQjIrbOnz9rO+JgLGvZCrF6Q8Gk1uwi3iB+Z Tv61OTLPSghu5hyGDcXfsWXhcRf/pcRNJRs6d0c4u2hxvohiC0T57d6zSWSgT2VXpk6x 6+svrhNahPeL5jc7pTOOB87FrDRp9eqE9dig4hnSgLmQQSar7oI0mGNvBHPfU9CI7FKo cncHLMSRYeyV+VMJnwFR9IQuwvETUozJTe7yqT1Wx8ZtG/3TfxjcETUtub7aZz5PNILJ /KZuu4PWMGYtltZuHmuH2r91qkMiCk6mfs5Z11oLHw6XLCiQi7nbXSyYzxzTF0bjI+18 8zvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Q7p7TZN47ATIiQ3A5Y3xH06vJfjCq2B+xHIDC9Ub+lo=; b=Ka1QfakgvwuvFQJeohRY+/DlR/vMvOvyELSiV3lybU4wZaOYzoqAJXXd0FVipmJ8cM VKrJ8SzzZEVOcUpzavEqhgLDpBdVKNt3Nj6kslnWn8QfZwWQhoZbuIVeDCCEY8mlQptp wV+NnXglcOB7cIOlMi0RyjR6EjVV75+D9NRhOLisBVsZzNjLdU4A2b/yJSQ4QiBy7U/E qSSLaK63pcrE9TtZhIirvbjupy5Ws8ijqpT1EAvIoXzIl94K/8QL+Bqk7Umwroqop5X/ Nu/YcTlWQavp81XlszXb6wDLNQir+53NFV27SaFfWMgEImCFxuzdxpiRYxELFbu2IRkU M9WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I4836iqD; 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=pass (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 f11-20020a0562141d2b00b004621033ad31si325040qvd.573.2022.05.20.17.23.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:23:18 -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=pass header.i=@linaro.org header.s=google header.b=I4836iqD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCtq-00043V-5w for patch@linaro.org; Fri, 20 May 2022 20:23:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCew-00033d-8H for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:54 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:38849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCeu-0004ZL-OB for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:53 -0400 Received: by mail-pf1-x430.google.com with SMTP id h13so2692523pfq.5 for ; Fri, 20 May 2022 17:07:52 -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=Q7p7TZN47ATIiQ3A5Y3xH06vJfjCq2B+xHIDC9Ub+lo=; b=I4836iqDX6QoKoNTeY3XgYyWcZCv8IPJugK8o6wqtRs5gdKdT3xU1mCbymrn0dyEyh fWVt4MceeMaeiUllJk59/OunkltXn5p0HPjQ7Alhsp5cgOIz7fvE0FUDTz7TzFZAS6Qc PBC00/OHsasVF0VItTTBZce1L05YivtLd9ycQvFddjyufmp9zyt6YYn21QiAlPKaRxlL ordujAil4S2L8egD9/MN9+jZkQNWFaW5ZM5vlREiJo+R4Q1g2GNfjCtjiLY0mJfnd6ah 2F2HD0SeT2NUqIxLMIVVX/VYJPJZsXTsXpELUMUR5Ir/bdv15hzk5va0B5pJXE9G1gdr mC0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q7p7TZN47ATIiQ3A5Y3xH06vJfjCq2B+xHIDC9Ub+lo=; b=eprIZ8BQW+GCOx6ZTbW9ZScRSngzLtDqJN8KHZkLWoUYHT9llNi5UTa8u0Z7Bm2KTy r9ZAS9Dxjr+X8kT36YLJBxQkIp/+ie6ZpxDju5BbOjQPlAyjFE0lCfOxUDHTvtvZkvkj eVCuUM+QJtFWZm0wHgMkLVnBeNam8EpJ83FOmUZNRpqErClnHEolzRMeb9Gb7jIyGuVr Mtt/Uy+AsSH2m7zuUKvSIdxQuIJYgPzIRS0LFS9tcwMYGGULcQzV7ZKPzyK7SOw4/fay RZXrZ1gPgKX9z4XveBuSJYTmmaEVKqCIg4wXtINJUOzdUYrnWhDxWMT+1vsGfIMFMZsZ XVLw== X-Gm-Message-State: AOAM531ae3IYDizHzZpGWh82mvBLcoxod7baj+e+N2wP+5AVZGCLBxL2 62VVn+XBB8JqZ6LVmmHRkWuWdlycRnmnFQ== X-Received: by 2002:a05:6a00:1683:b0:4f7:e497:6a55 with SMTP id k3-20020a056a00168300b004f7e4976a55mr12546630pfc.21.1653091671443; Fri, 20 May 2022 17:07:51 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 44/49] semihosting: Use console_in_gf for SYS_READC Date: Fri, 20 May 2022 17:03:55 -0700 Message-Id: <20220521000400.454525-45-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 20d97290ff..9230c69ff2 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,6 +290,22 @@ common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) common_semi_cb(cs, ret, err); } +static void +common_semi_readc_cb(CPUState *cs, uint64_t ret, int err) +{ + if (!err) { + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + uint8_t ch; + + if (get_user_u8(ch, common_semi_stack_bottom(cs) - 1)) { + ret = -1, err = EFAULT; + } else { + ret = ch; + } + } + common_semi_cb(cs, ret, err); +} + #define SHFB_MAGIC_0 0x53 #define SHFB_MAGIC_1 0x48 #define SHFB_MAGIC_2 0x46 @@ -415,15 +431,8 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - { - uint8_t ch; - int ret = qemu_semihosting_console_read(cs, &ch, 1); - if (ret == 1) { - common_semi_cb(cs, ch, 0); - } else { - common_semi_cb(cs, -1, EIO); - } - } + semihost_sys_read_gf(cs, common_semi_readc_cb, &console_in_gf, + common_semi_stack_bottom(cs) - 1, 1); break; case TARGET_SYS_ISERROR: From patchwork Sat May 21 00:03:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574920 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2668268mab; Fri, 20 May 2022 17:27:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2/nOTfcVv00DbqKBgt05qktnb/C636wy9RTJv3DDIP8gW4fFYv9eEXuUnFWqTmAh6ooE5 X-Received: by 2002:a05:620a:40d6:b0:6a3:558f:a2c7 with SMTP id g22-20020a05620a40d600b006a3558fa2c7mr2575600qko.595.1653092823759; Fri, 20 May 2022 17:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653092823; cv=none; d=google.com; s=arc-20160816; b=knjuPnap7EsBdGEzlPZ29VA6yKCs4/GS2Ec0RemOiEpH1MWg7kcsKMQBBTwHoUPx5h E/cPLexDD/uKrqIBJCiP6tYafrdHpWQi8NxZz1JXsy7CUIpMd4pIT99t6WAtX3zZEBL9 1VIVHLI9SJNrvReqANAfgCbTPRgl+neigVfHrJ90N10Cb2jixudpBV7y2OH5beOm9BS4 jbI6eRwYrNeJCiIEzjwcTjz8Nb1ov9F5UlZFnMnA3T9UZhASNlClC+5j37X5joJhfnae 7XcGxzwObvEh2RpTpwg4U37raCQS5i0gSjoMcRXFQPbZ6GgwB0ngeQR96GDNePZ0oa4Q 8LPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z1XEM4ETfmeGaHs0P/KqaWrAu876hNlLRNnzFnqql6I=; b=Y9cRioOA/15ck0N6SXY16u5f+tgT05x5LlSisotOiKjCPiKnqSCgb7EpXcQX08aW/m A+/CsMRac5uFq/JWVjGPj3+7+MzwHJSmRTgSTIi9jrlx3UoTq+gDl10REmqEpOIOJnGG +WhWOUYAFebCp/kJku5qguskPglAmZckusZsP1KBkguLIGf1pxbE9te/8gaVQzyUXcC3 RXaGEbigTmGNKtXdX87KKBAM8NgmwNGYJIGT4Tn7wIKS5GRlRlZrBRqH99XWw9PVJvrP +pkw75474wvzKm6OMDjkCU0V21DTrb5TME6ERzU50hF6XXj3VFNJBOQPCNKnExOOfR4w EEeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vkMX3CZy; 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=pass (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 jl5-20020ad45e85000000b00461b52e0c53si338839qvb.91.2022.05.20.17.27.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:27:03 -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=pass header.i=@linaro.org header.s=google header.b=vkMX3CZy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCxT-0001Js-Bg for patch@linaro.org; Fri, 20 May 2022 20:27:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCex-000369-TN for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:58 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:44698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCev-0004Za-Vq for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:55 -0400 Received: by mail-pj1-x1033.google.com with SMTP id pq9-20020a17090b3d8900b001df622bf81dso9048010pjb.3 for ; Fri, 20 May 2022 17:07:53 -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=Z1XEM4ETfmeGaHs0P/KqaWrAu876hNlLRNnzFnqql6I=; b=vkMX3CZywVx5e+lYBJ62iPDc03yfKZklpLruhWQ1T0QRKZzi5JO8XtyfX+tsl/saYj 1AZhXSiYDmNvySR1JFbvpJT6aKKptgUlighQNGcqJZTXHA4sFi6ams74/s8ohV9uYFSE xxpHiM6JFfgwT2cexfISHrWdBM4+7nE5pUnDwkuewAiG8ONy3IqbyeMMajS9AYNP+Dts cEUIxcnRz0d7sHwuihmgs8QPA0yd08EL9u/BX4AAqDBheY1LHmnWFa+Bwnh63hwdaU9c 8CVBhDXif72H2RPs8tD6rDEqhuOt0yXoRnvszXuOO46EYYLD8+W9s0o5e1mY37dWDbS1 xdyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z1XEM4ETfmeGaHs0P/KqaWrAu876hNlLRNnzFnqql6I=; b=WkvzxvnnlPvzlr3gL9hCvsYc2yf4NZmkFgDVSyzifLMt/YchOlrc3mBWQzDpIzY+Wp fAtjc0qBZzyO5LACE3nT6541yNXvdP6Jfm+S4S4YtZB56qB1Q/0OZbQg0GeOYyC/Pcgs ixAXg/AV1ZicDprwNgBH0KuzSS0HtueJZmdv/8gBt0WMbSc8VNe/mYicLR/bwdjw9HVU y8ad4kYyIRElBZi1L/WZspbQg2wQmRtSgmqHJfbieGxqa247x1DClt/jxXpbXqgNQcNB 3ieriaUngDLByLJqDVJ4TvAcaxCIB3jZP1Klz9H6p8K506QyX4icXhm8JineI7lDrm0P R1GQ== X-Gm-Message-State: AOAM5326CTODJm/G8YHTn/xOC6Ca0R9jffZuDOLnxnvhJquEopq21AqI Wh9v5kEl2dynpWbEcoAO20ClTtxBkg82wA== X-Received: by 2002:a17:902:70c9:b0:15f:a78:fd15 with SMTP id l9-20020a17090270c900b0015f0a78fd15mr12099261plt.12.1653091672613; Fri, 20 May 2022 17:07:52 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 45/49] semihosting: Use console_out_gf for SYS_WRITEC Date: Fri, 20 May 2022 17:03:56 -0700 Message-Id: <20220521000400.454525-46-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9230c69ff2..e24e9284c2 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -228,6 +228,15 @@ static void common_semi_cb(CPUState *cs, uint64_t ret, int err) common_semi_set_ret(cs, ret); } +/* + * Use 0xdeadbeef as the return value when there isn't a defined + * return value for the call. + */ +static void common_semi_dead_cb(CPUState *cs, uint64_t ret, int err) +{ + common_semi_set_ret(cs, 0xdeadbeef); +} + /* * SYS_READ and SYS_WRITE always return the number of bytes not read/written. * There is no error condition, other than returning the original length. @@ -329,8 +338,7 @@ static const uint8_t featurefile_data[] = { * The specification always says that the "return register" either * returns a specific value or is corrupted, so we don't need to * report to our caller whether we are returning a value or trying to - * leave the register unchanged. We use 0xdeadbeef as the return value - * when there isn't a defined return value for the call. + * leave the register unchanged. */ void do_common_semihosting(CPUState *cs) { @@ -407,8 +415,12 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(env, args); - common_semi_set_ret(cs, 0xdeadbeef); + /* + * FIXME: the byte to be written is in a target_ulong slot, + * which means this is wrong for a big-endian guest. + */ + semihost_sys_write_gf(cs, common_semi_dead_cb, + &console_out_gf, args, 1); break; case TARGET_SYS_WRITE0: From patchwork Sat May 21 00:03:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574924 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2670086mab; Fri, 20 May 2022 17:31:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx686Uqi9+jCzQb1Yi8V/0RuNoEU6ORF5ItEyu8Ei9gz3NLHqjbxXYtqrZPhY0iez//iUfY X-Received: by 2002:a37:45cf:0:b0:6a3:2bb1:6c40 with SMTP id s198-20020a3745cf000000b006a32bb16c40mr8090327qka.481.1653093074270; Fri, 20 May 2022 17:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093074; cv=none; d=google.com; s=arc-20160816; b=qFoDIQerns5Jlt5IFH+2vJ81iu++65CJrGDlEu67oXDiZcFdhAvy0rYrnQLDIMOx3p 4AwJbBodpWmvoeqZ7PpLvROKKn1vSIZzC2eNKcWbt5/UsIE1415cSyEKgmiNGD4pBp3/ WgNOowI10IjdV50/Uj3fofUdmtkzmt3U/14LvHidGnBXkou7G4KTj3RndVvFWWvS3oIN HgFjsTISvoaGWKtoIOFp+H3mQojMzM45kiR1CN3vB78T0G9NOmx3kLEEM3An3N1I+4Z9 8ba3FjOaTXCJ//WrE+YeqbvnBIZ6pW4j01F7747qXdWli/9tsywosHnXOEPT8dz1rtbP ywrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=W59tomZXIRxqwrD21XbJcaTCFMWnQOBHgEqNXUbJdL3e7on5F1ILQT1d65GJOPFzD5 GObBDcGaOx1BrTj4tCaDs12C2L4fI5RtKviUmW/Gec/6xKxPByPTKPnOR1gd/riCy1lf LrmKtEl909BVMImqAheIDS3ztWg9an+hGgoUAWhOXn8kJhIeChB3DUPGMh6vkO6sE4sR qiKc+ONuz6iRKF9DcmgeeZFtr3UbykX+eCHo0RKMgp0ycxh9aHAKIqy9i02doYzwGroQ 5lfVZiIxLIkfkbh2bHFj4M9f31NWXmt2Wo7DC2f+w+v6buqiRtEM+hc1kVngG5hO5kCY LQPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dM4S8zJu; 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=pass (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 j2-20020a05620a410200b006a04fde76ccsi408610qko.600.2022.05.20.17.31.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:31:14 -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=pass header.i=@linaro.org header.s=google header.b=dM4S8zJu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD1V-0007Qb-SV for patch@linaro.org; Fri, 20 May 2022 20:31:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCf0-00036E-6I for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:58 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:33279) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCex-0004Zo-NM for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:57 -0400 Received: by mail-pj1-x102e.google.com with SMTP id fw21-20020a17090b129500b001df9f62edd6so7300144pjb.0 for ; Fri, 20 May 2022 17:07:54 -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=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=dM4S8zJujbi7Iz9EvhOuNYRzLUp86V9jeeUFkJBBxgMstO8j6cvrtQP5m/pH7MFzeb RDl0kOcQT57qAkze/Cih8ND7ULAUmazm9peisYi6bmaRXqz1GS0JEs0zc1kiu28SIlO0 ViG3kOqPT6eQy8B/zxYQMMwrE/D+9RPPXFV2eSYbdvu6ZTkomqOBsUTBFn8d/T5Vzoln N0ulOFxYsOlZuN+F8lTMXXs7LGli9fZCoP1jAcx4u66x8NU64WA6w5OYmZz12JMBcDKb aELKcg2CyzcHTUsQsmpgKkE8Ba0aRd5mLR3Vgv/AEjhBEojjGfeCk1St4Gzq9eSfxITI ylQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=DaRexlx6yFkIabfXnfjUSh+7kBeLKEestMg2/MyX/o5EA8YPRcONAS3gSknm/kVVPb vP90ezjm0/4w6tjGfnhwxsf18QASAyV65Cbg/h7fY6zYQ2OESXxN/EJv0qZ+cVuCrKKb utrz0zmWCyBjXAUrSJ+oi8EE/fAerDjjCAvLQ1T/5/Mey45KqkSTS4W9i7xEHyYAzBE/ FBynYsuk1rRlZu5ED/Hq7iocMyn6v8BUEsMR7gEAgXzOHCygcdB1Lam5rjxgO6L/6eMI VmBOjrFnzqtAvTlYy0NKCAMwCegUjPMn5PbRYygWJUoAt6T7ulkEEZJEIIOwB1/iJMFx jotg== X-Gm-Message-State: AOAM531rsAL7zubqfQZDnh/AykGUT9361a6Uxd1y0JtcfCLpOZHX2Wc9 QrOIEJfbzVP8EukNtoT9TG96FJIpjw0XSw== X-Received: by 2002:a17:902:f605:b0:154:aa89:bd13 with SMTP id n5-20020a170902f60500b00154aa89bd13mr12287828plg.112.1653091673658; Fri, 20 May 2022 17:07:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 46/49] semihosting: Remove qemu_semihosting_console_outc Date: Fri, 20 May 2022 17:03:57 -0700 Message-Id: <20220521000400.454525-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This function has been replaced by *_write. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 13 ------------- linux-user/semihost.c | 16 ---------------- semihosting/console.c | 18 ------------------ 3 files changed, 47 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 6994f23c82..d6c1cc58ab 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -24,19 +24,6 @@ */ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); -/** - * qemu_semihosting_console_outc: - * @env: CPUArchState - * @s: host address of null terminated guest string - * - * Send single character from guest memory to the debug console. This - * may be the remote gdb session if a softmmu guest is currently being - * debugged. - * - * Returns: nothing - */ -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); - /** * qemu_semihosting_console_read: * @cs: CPUState diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 871edf993a..f8bc8889f3 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -33,22 +33,6 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) return len; } -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) -{ - char c; - - if (get_user_u8(c, addr)) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - } else { - if (write(STDERR_FILENO, &c, 1) != 1) { - qemu_log_mask(LOG_UNIMP, "%s: unexpected write to stdout failure", - __func__); - } - } -} - /* * 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 diff --git a/semihosting/console.c b/semihosting/console.c index 677ec2b176..f6fab5933a 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -96,24 +96,6 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) return out; } -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) -{ - CPUState *cpu = env_cpu(env); - uint8_t c; - - if (cpu_memory_rw_debug(cpu, addr, &c, 1, 0) == 0) { - if (use_gdb_syscalls()) { - gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, 1); - } else { - qemu_semihosting_log_out((const char *) &c, 1); - } - } else { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - } -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Sat May 21 00:03:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574931 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2676458mab; Fri, 20 May 2022 17:46:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcQllN0SdjCLcekMYnf99XQS5HA/EkMokRnw+jh1h7f+QjHNLaZ/oNyT3PdVnKDaGTWbZo X-Received: by 2002:ac8:5bcc:0:b0:2f9:187b:3bcf with SMTP id b12-20020ac85bcc000000b002f9187b3bcfmr6143172qtb.435.1653093968815; Fri, 20 May 2022 17:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093968; cv=none; d=google.com; s=arc-20160816; b=OrmL965ms1rBB9aUqGjUoJO4eXpY6rdJf0F09A58qU7Fam1Tp0Fu2rXRoXYswTcGCh XHGupdiR9DaOOO3H7hQQDkOVx7juElSL+fyVq0znzx1Jx0uVM4dsWPpn9OtBnIUu24e6 TAC3sp1fAQNcXkb+9ZkMTQu9DVHSQLn9DPRtwgtYspxVHmTeD9vyipgI0EsR2Vr7kzX6 nIIlZq4+O03Y8CgdAr3YQ4rnv/yBxNUE7qBV/MyZBlRiJpYHqKoCNb1CsE5m0qka3/9p d6Oeg5UHOIDdLLAh4w8zbkp49Yo2KUgpYkJzIHPGfa2Q0qOg1f0perLItR/PYp8F3gNM avWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xw5S8AgSS2kdVT0yNtWxbG47quJl+p2/OpzczA7b8dk=; b=SOqPwZtozFA7sC2WqMhwtPC7bqafg9M1WoadBqXhF2gM2DEM7/TkOa8mS7OvpiysKw d0qIfcAUAYhuHnmMESIzzDh38h1llvUlkKiDD4qelwo2BKYf07LsXgoJSLmsQcTSLn4m NgUUgLIi080KlPCbMHNUAOI+1AFMp7DUM8H1hR6JONnie1tFp61VEhhYjXOPMRdDhQmf 597YhhHu1653Oik7imdSmjbkcNYYbSzTFwj2XVOBlTIVqa/BO7quyRvk+3EEY84hgiCr vMqILBohvHAftO69Asn5pfAD9Bocp56Cej6a4LcqdYDmP7HIXiD4lhb3/JwUNSv6kvpW 0ZkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BmQRxlsZ; 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=pass (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 q7-20020a05620a0d8700b006a0cdc7c97asi467936qkl.30.2022.05.20.17.46.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:46:08 -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=pass header.i=@linaro.org header.s=google header.b=BmQRxlsZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDFw-0006L4-DZ for patch@linaro.org; Fri, 20 May 2022 20:46:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCf0-00036D-4u for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:58 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:37456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCey-0004Zx-LW for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:57 -0400 Received: by mail-pj1-x1032.google.com with SMTP id oe17-20020a17090b395100b001df77d29587so12758063pjb.2 for ; Fri, 20 May 2022 17:07:55 -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=Xw5S8AgSS2kdVT0yNtWxbG47quJl+p2/OpzczA7b8dk=; b=BmQRxlsZhIuR8m12n1phxPEEOZfGP3j/r1vBCi99O7keHdMFNHlfbXcrR7lY170uFV ZlCkIgTpOk1aZx4469FinLrTMm3j+2xe7TwT0ADSv1aUNdMVahL22/SBn3tHIEQVAWR0 dOXkqS332gjuF6DyfAbaSEC7Z3TW5qrkiY0LCsoXv+n4SRlxF67nB2pVNWpABhpsMjf1 5C4qkaln/XtHFsZyLnBNeMBUToas/6U3tj0KBt+tjOZWKSK4EXtF5PWW3YtkMkNTZ0Mg RQrZElZ8ySmiAwofoQjY+l/7Y8yayyJygK3kQQMofwj6486Vkc94wvaBlW6frqotDkek IE9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xw5S8AgSS2kdVT0yNtWxbG47quJl+p2/OpzczA7b8dk=; b=q3Xwv3W9suojYlJGQJTA2W78fNOlDDA3pUuJXiwcu64nNN7hVL4ENfxBmexdZ3/XuI Q15NmgAalYL4wBo5AZwlTPnOZdtv/iirf9fuuMwS7OAHt6hNmF3C0oM4DWg/MP2G6Lti 6yIyM4XP3pE1OG5MOgSuAQlSur11DCHRiCakgIQBKDUS/NMdQ+5WLrDlyjKBejg3T6T4 yhFZ+e7EMT/0813rLgXgWzhMYib3m/jm1SzbfkNOrxTdZ/VFo4oGzDd5J+s3NmOsoJ4a LO2QaSGS/Jd3HjvyMCe69piWKThw2K7T/9b6zWbMDJHLFfdV8PtC0VjeTRaTVGjvjgj/ mLnQ== X-Gm-Message-State: AOAM532OJalMCtAcXsZ0fqVRM4gjnw3r4Id1EbgQIx7A5V0VX5DjhXzM nymyf+bbsiFNeycJR6Q1WHUBM3eEnzk3WA== X-Received: by 2002:a17:90b:38cc:b0:1e0:1c6f:d3e3 with SMTP id nn12-20020a17090b38cc00b001e01c6fd3e3mr74434pjb.86.1653091674938; Fri, 20 May 2022 17:07:54 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 47/49] semihosting: Use console_out_gf for SYS_WRITE0 Date: Fri, 20 May 2022 17:03:58 -0700 Message-Id: <20220521000400.454525-48-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index e24e9284c2..1e4c931327 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -424,8 +424,15 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITE0: - ret = qemu_semihosting_console_outs(env, args); - common_semi_set_ret(cs, ret); + { + ssize_t len = target_strlen(args); + if (len < 0) { + common_semi_dead_cb(cs, -1, EFAULT); + } else { + semihost_sys_write_gf(cs, common_semi_dead_cb, + &console_out_gf, args, len); + } + } break; case TARGET_SYS_WRITE: From patchwork Sat May 21 00:03:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574933 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2677235mab; Fri, 20 May 2022 17:48:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybqxPYizk/yWj0fhDMoB17/vzFzpx3WvXbCkmpHtWSKmlmWkZT2YRVoimP6L77fj3+JPQz X-Received: by 2002:a05:6214:1cc3:b0:456:56d:f2c5 with SMTP id g3-20020a0562141cc300b00456056df2c5mr9991732qvd.119.1653094115078; Fri, 20 May 2022 17:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094115; cv=none; d=google.com; s=arc-20160816; b=Sz1J6R3aTt5yPPtVbJr9bqp6HhOg77Jvm4FfaPdChYC9a0rXnFJ/SW1V9v98mEswXV QKd0+Ta4Z41q5c/B/CaudRhitFK5unCNw90H+zSZa2V5TxsO5G03xkAJvXFFOznCG9OK 42eXOwfZNI6ZpTspjm2kgb29x+xiAVRZpwkOMnVnTWxb6C93K7PF6FtX8mzaPnJG8TXR 2gSgpjoxIokb+Ba5+oXmgc+iwCGWg7BA4pxbsOLB+94cc7LChDcyS2EJa4yMqWOlttEh VosHsNsMFwsp9mq/4dD4Yl2OicqIG+UE3Wm2oUMHuyi1B0N+2ndQu6uYlUFsD6jAY+Su tY8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=FMNwuFd25Ybf70G1pcWTdJ+Q2nW/xoxtgxziUPpxsDlMG9BjHh8FPSWOOsXakFf85S pS5+XrbYuSv3Y0L+H/4Dm8afAjSr2fPa0u4MM0goXmKW3dQNMY1PfE8zVq/ynWtztWH2 FV7rzj3FNbW7AUEKmHSGeWC+zDl+ibIjPIJDv8ISjKvNZy3e3iJ8Y5fCw2qSpnBcdaq8 Ujjocn1yWK17ePQlvdntl0KBtRJAXMMzkCYAl1DzTpW7E29ZfjmExsbwYyI6mSqXRse6 ZkiMN2/BrfM9J6zsxalx+DfFcz5wKA23LboQFTF4RZmlFyt3UmRjUlNJfWNCEZBBhY85 XrKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n5p3Xz8Z; 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=pass (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 h12-20020a05622a170c00b002f92b8e6f49si258481qtk.467.2022.05.20.17.48.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:48:35 -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=pass header.i=@linaro.org header.s=google header.b=n5p3Xz8Z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDII-0001o8-Kk for patch@linaro.org; Fri, 20 May 2022 20:48:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCf2-00039W-HJ for qemu-devel@nongnu.org; Fri, 20 May 2022 20:08:00 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:38551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCez-0004aB-D5 for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:59 -0400 Received: by mail-pl1-x632.google.com with SMTP id n18so8570020plg.5 for ; Fri, 20 May 2022 17:07:57 -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=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=n5p3Xz8ZQjOeUQF0/vFCpuBIhLYUi1175k+CT4X7HylP5F/Cc0+YKJZZ7jPzCdggc+ ZkAJmDzt+QfpAH00crA/UAl3t2GCW+u0Y3rPdhuSyio7odoa0U+hB18i0LotMouBd7U+ +XHOjc3a+i7BoGpCNrJtnVUCJOZmVM/HCouKqllmI89OuoGUo3eEgDgluYEKdbwYrVpf 7441asGyuIwCd27bleeIUr/ofHT9cYhr94hvMmyE7mncF5f3BElMDW023HxFndAZsYM5 gyfz4jUTvRT6ExwJSxvQuvYt2Acfr72CpjlH3uInSdAmdrNHwZF1MD1DbFYlwotWv6OC waAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=510bOLYtYLPZ1NHtCXPqd9W7oTgHkw0CKdu7sRujXxLfC9maJ2e6XFBI3Nq5rcQkC0 H1eqXZKfIZ1HKeHoVj1jkxYfrnL2ngc9r2vW06dQvI2oh5N7yI0trb3yISv7L2+bW4Qf FwVAhhc0YWJb9SBx3N0KvPNdKf8NeBiF4f5XdLZ8ULS6o8HBYpadRcnZCJrpE0O5kLrQ BX8fRAoULITwksumT/cBe/tmCGfEi+F46P1SJxTiAl+4Qh+cJZp7luoQW4ybS24ln92q yrepw29PUp2flVjzAUYI2RsATjM2kTdgH7X+VjIZeUPy63DLcq4R4IBjaxLMJt/ZJ9lC E70g== X-Gm-Message-State: AOAM530fgC5Qbi+AxDV3U3bCt0cRe6Fz8E/60Evh2Zx0wQ4kcydHjAK2 Z6fp9huqPtq74GCVSVj7NnhMmMeTVr8qCg== X-Received: by 2002:a17:903:241:b0:15c:ee52:cbf2 with SMTP id j1-20020a170903024100b0015cee52cbf2mr11756664plh.10.1653091676019; Fri, 20 May 2022 17:07:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 48/49] semihosting: Remove qemu_semihosting_console_outs Date: Fri, 20 May 2022 17:03:59 -0700 Message-Id: <20220521000400.454525-49-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This function has been replaced by *_write. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 13 ---------- linux-user/semihost.c | 17 ------------ semihosting/console.c | 49 ----------------------------------- 3 files changed, 79 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index d6c1cc58ab..20c31d89d4 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -11,19 +11,6 @@ #include "cpu.h" -/** - * qemu_semihosting_console_outs: - * @env: CPUArchState - * @s: host address of null terminated guest string - * - * Send a null terminated guest string to the debug console. This may - * be the remote gdb session if a softmmu guest is currently being - * debugged. - * - * Returns: number of bytes written. - */ -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); - /** * qemu_semihosting_console_read: * @cs: CPUState diff --git a/linux-user/semihost.c b/linux-user/semihost.c index f8bc8889f3..cee62a365c 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -16,23 +16,6 @@ #include "user-internals.h" #include -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) -{ - int len = target_strlen(addr); - void *s; - if (len < 0){ - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - return 0; - } - s = lock_user(VERIFY_READ, addr, (long)(len + 1), 1); - g_assert(s); /* target_strlen has already verified this will work */ - len = write(STDERR_FILENO, s, len); - unlock_user(s, addr, 0); - return len; -} - /* * 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 diff --git a/semihosting/console.c b/semihosting/console.c index f6fab5933a..c84ab97ab6 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -47,55 +47,6 @@ int qemu_semihosting_log_out(const char *s, int len) } } -/* - * A re-implementation of lock_user_string that we can use locally - * instead of relying on softmmu-semi. Hopefully we can deprecate that - * in time. Copy string until we find a 0 or address error. - */ -static GString *copy_user_string(CPUArchState *env, target_ulong addr) -{ - CPUState *cpu = env_cpu(env); - GString *s = g_string_sized_new(128); - uint8_t c; - - do { - if (cpu_memory_rw_debug(cpu, addr++, &c, 1, 0) == 0) { - if (c) { - s = g_string_append_c(s, c); - } - } else { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - break; - } - } while (c!=0); - - return s; -} - -static void semihosting_cb(CPUState *cs, uint64_t ret, int err) -{ - if (err) { - qemu_log("%s: gdb console output failed (%d)", __func__, err); - } -} - -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) -{ - GString *s = copy_user_string(env, addr); - int out = s->len; - - if (use_gdb_syscalls()) { - gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, s->len); - } else { - out = qemu_semihosting_log_out(s->str, s->len); - } - - g_string_free(s, true); - return out; -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Sat May 21 00:04:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 574925 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2672421mab; Fri, 20 May 2022 17:35:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhJX0ym7u49zCdLTtQJu3tO35afmkzGfSFM4x7bQ8ncIp8oTJtNt4hLRF0AAwx8seK2sXg X-Received: by 2002:ac8:5891:0:b0:2f3:ba03:429 with SMTP id t17-20020ac85891000000b002f3ba030429mr9513438qta.13.1653093348982; Fri, 20 May 2022 17:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653093348; cv=none; d=google.com; s=arc-20160816; b=oIzBlCBVZQWL6442t5MLW3MzHV1gHSAryq7LPsho+XdB3j1ixciC+Bv0IrTkY6smPV cSK9x6HTWF3plxVZvd7fQ2F14G90CRfhteaAL/BiQpGQK+STFtXoivw7YzMnO0Zlznh4 c3l2eCf1eGm3cIgkNTHq8Sq9PwuBugFoSVTXuAY2EMV02+d5mVO2qOthdb+S/uwDj9qo hm67VlhD9QTZ9i0C6VXLIYmTETVY1yQFKSQ8s8L1zTgkxpBYUfPsRjB25qMaXouz5r6w Po9ENwujVn5FSxAYxe48tweYvaooy3zuoiCHzArWtgK3IZOEkLXGghrXA4XbnlkQ8Rk/ GaxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=zuCyHaoVbmeTO/1npYNfvus1qjIoIkX4THw80q8ncLn+n11yF5eASpI4u28vAqUy/j fjNVgZkH8HMOnt/MnfqN0jWSU63RmS7slPF93LxsHHGTnjF9wbtu5re8TW4NkUEPpYuP 2VDBPANKk6U77QGbMeKBqptE76EaA0lVmXSGErCV5Ouli7lacIbly+qCRQ9IQRMNGcQv IhnK5jaWlGASvzHriqjJ/iijiwt8hx1NJ51ZQdeHXE3Zo40vlKXr0cmKPzbJHVPHKwhu wkEWnJ2Oz74LTgWQJX+xk6me3LubzR1IPKh9xLGo47GddGQ1eS9f5d4vBf9x9FgWkPWU tY8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xsNJcIjx; 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=pass (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 iu3-20020ad45cc3000000b004564f8f5e9dsi368638qvb.454.2022.05.20.17.35.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:35:48 -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=pass header.i=@linaro.org header.s=google header.b=xsNJcIjx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD5w-0004ns-JG for patch@linaro.org; Fri, 20 May 2022 20:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCf2-00039X-Hh for qemu-devel@nongnu.org; Fri, 20 May 2022 20:08:00 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:35635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCf0-0004aH-9J for qemu-devel@nongnu.org; Fri, 20 May 2022 20:07:59 -0400 Received: by mail-pj1-x1031.google.com with SMTP id nk9-20020a17090b194900b001df2fcdc165so12804958pjb.0 for ; Fri, 20 May 2022 17:07:57 -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=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=xsNJcIjxRM8IcFuxnv1J3ocV9SpPogNjRsRIuIHQuMjH/HMOgstJjMM4Mht65QaMKN keZfxAvAlJTHwxOajGx0nIidNv2Bf1eaH6MKJn3Ffv4akMuMUdezow7/D2j0dQWA/kT4 TPpm3cSGagMDZNYcGXxie/w9xFz02ZBX72HFa2xPoboFBz4IWiav2z2NiSSaJoQM9ZBd TALnmjvFmTRdc5hMxvMaVeYpVtRWtQwSYmW31OYzza9kFl5ueXITNEk8GfP//3AfaFl4 2+ycdqt1BykI9/Tl0TiWART7BgDzOJbRl1G5L3QKefBCdG9XbpfXX97aO74CuJMq4J/2 8Leg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=ptR5aDSgYxiOFc/dJv21MDC74gN4KaQcv+NRE1XISYdbXTo6uLIGR35755fnfN8zcW 9+HhDIPqaMM1FAqk9h5bhdEtZ63ipyzpqAcgSugXxlCp3LMnDgzxGvrLxePztx1aDdND UnRt7ZqtTHO71+xzY1ytli7BscClaX2XM0d4j0kOu3Iz8uBOZAafkFONz39m+6O1rSt4 yg2KAtgrAuxfPrjvroDBhOY+JhhSXPGEPnvCSGzOi4PlAi058uLvvPgyygrSH/v9N0H/ IB2sbeyWlFvE3F4W6/+EcjIOS4OV37rcUfYcpNm7e9BXKNpq6j+rMV4NHGYf5PisUhHj bTfA== X-Gm-Message-State: AOAM533dE3NSGCJjFI2s1j9XEPd+aEhw5CiSYGohWxan64V5w1CZhxcW BjBcKQAG9+J5pJMnTzD/0nHJ4KApD4lD9Q== X-Received: by 2002:a17:90b:1b4b:b0:1de:d495:8bc3 with SMTP id nv11-20020a17090b1b4b00b001ded4958bc3mr14067976pjb.200.1653091676915; Fri, 20 May 2022 17:07:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0cc100b001d2bff34228sm2517703pjt.9.2022.05.20.17.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:07:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 49/49] semihosting: Create semihost_sys_poll_one Date: Fri, 20 May 2022 17:04:00 -0700 Message-Id: <20220521000400.454525-50-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This will be used for implementing the xtensa select_one system call. Choose "poll" over "select" so that we can reuse Glib's g_poll constants and to avoid struct timeval. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 16 ++++++++ include/semihosting/syscalls.h | 3 ++ semihosting/console.c | 19 ++++++++- semihosting/syscalls.c | 70 ++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 20c31d89d4..61b0cb3a94 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -53,4 +53,20 @@ int qemu_semihosting_console_write(void *buf, int len); */ int qemu_semihosting_log_out(const char *s, int len); +/* + * qemu_semihosting_console_block_until_ready: + * @cs: CPUState + * + * If no data is available we suspend the CPU and will re-execute the + * instruction when data is available. + */ +void qemu_semihosting_console_block_until_ready(CPUState *cs); + +/** + * qemu_semihosting_console_ready: + * + * Return true if characters are available for read; does not block. + */ +bool qemu_semihosting_console_ready(void); + #endif /* SEMIHOST_CONSOLE_H */ diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 347200cb9f..3a5ec229eb 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -69,4 +69,7 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong tv_addr, target_ulong tz_addr); +void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, GIOCondition cond, int timeout); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/console.c b/semihosting/console.c index c84ab97ab6..cda7cf1905 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -77,10 +77,17 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +bool qemu_semihosting_console_ready(void) +{ + SemihostingConsole *c = &console; + + g_assert(qemu_mutex_iothread_locked()); + return !fifo8_is_empty(&c->fifo); +} + +void qemu_semihosting_console_block_until_ready(CPUState *cs) { SemihostingConsole *c = &console; - int ret = 0; g_assert(qemu_mutex_iothread_locked()); @@ -92,6 +99,14 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) cpu_loop_exit(cs); /* never returns */ } +} + +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +{ + SemihostingConsole *c = &console; + int ret = 0; + + qemu_semihosting_console_block_until_ready(cs); /* Read until buffer full or fifo exhausted. */ do { diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index aa4ee47649..1b87c37437 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -550,6 +550,21 @@ static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); } +#ifndef CONFIG_USER_ONLY +static void host_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, GIOCondition cond, int timeout) +{ + /* + * Since this is only used by xtensa in system mode, and stdio is + * handled through GuestFDConsole, and there are no semihosting + * system calls for sockets and the like, that means this descriptor + * must be a normal file. Normal files never block and are thus + * always ready. + */ + complete(cs, cond & (G_IO_IN | G_IO_OUT), 0); +} +#endif + /* * Static file semihosting syscall implementations. */ @@ -658,6 +673,34 @@ static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret ? -1 : 0, ret ? -ret : 0); } +#ifndef CONFIG_USER_ONLY +static void console_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, GIOCondition cond, int timeout) +{ + /* The semihosting console does not support urgent data or errors. */ + cond &= G_IO_IN | G_IO_OUT; + + /* + * Since qemu_semihosting_console_write never blocks, we can + * consider output always ready -- leave G_IO_OUT alone. + * All that remains is to conditionally signal input ready. + * Since output ready causes an immediate return, only block + * for G_IO_IN alone. + * + * TODO: Implement proper timeout. For now, only support + * indefinite wait or immediate poll. + */ + if (cond == G_IO_IN && timeout < 0) { + qemu_semihosting_console_block_until_ready(cs); + /* We returned -- input must be ready. */ + } else if ((cond & G_IO_IN) && !qemu_semihosting_console_ready()) { + cond &= ~G_IO_IN; + } + + complete(cs, cond, 0); +} +#endif + /* * Syscall entry points. */ @@ -936,3 +979,30 @@ void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, host_gettimeofday(cs, complete, tv_addr, tz_addr); } } + +#ifndef CONFIG_USER_ONLY +void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, GIOCondition cond, int timeout) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, G_IO_NVAL, 1); + return; + } + switch (gf->type) { + case GuestFDGDB: + complete(cs, G_IO_NVAL, 1); + break; + case GuestFDHost: + host_poll_one(cs, complete, gf, cond, timeout); + break; + case GuestFDConsole: + console_poll_one(cs, complete, gf, cond, timeout); + break; + case GuestFDStatic: + default: + g_assert_not_reached(); + } +} +#endif