From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091725; cv=none; d=zohomail.com; s=zohoarc; b=gQ2b9zbFfGcn7EHWK4r2Sw0cQ5Zp7ScU5zaJjcN+mYZ2/OU8X+CIRy8aMXYFYH2zTkWiSsdkdQqWsTFksgtInP8MtviF2xgu3scjbxpw3AE7WqyEX+fqlXUAIK/YlNVALHbtqV8A6H5H7SRbCdu55P7NI8kSYyN53D4sRZ7OV64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091725; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8nTEBA0ibtyn59fqrnvMD1vJ/OB33r4Ox7u7QZwpM0M=; b=WZGkxLVzbZR+pmy50DR+36RN46OsaYR4YgdnpeJPCiwkyMOB671w4Ob8MiDHFk9g5uO69UI7Fhdtv4QXWhbqNkF2IC3ZRJNQeGSb5Z0F93Z9WY7CcRy0Mt93d0TGudLZlwFl6T2qmi/x8+5hi4+viu3LrjT3WJLi9c0NgBb1UdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091725703317.3227799942588; Fri, 20 May 2022 17:08:45 -0700 (PDT) Received: from localhost ([::1]:57846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCfj-0002hy-E0 for importer2@patchew.org; Fri, 20 May 2022 20:08:43 -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) 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) 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-Google-Smtp-Source: ABdhPJzdgXYPVxGNt60fcLySJBjfl+8eG6AC34zDb1Do9KNnvgMyxo8npaqqObWWL+f/KTW1hUy3/A== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091726396100001 Content-Type: text/plain; charset="utf-8" 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 =3D> 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 =3D> semihosting/softmmu-uaccess.h} (9= 5%) diff --git a/include/exec/softmmu-semi.h b/include/semihosting/softmmu-uacc= ess.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 */ =20 -#ifndef SOFTMMU_SEMI_H -#define SOFTMMU_SEMI_H +#ifndef SEMIHOSTING_SOFTMMU_UACCESS_H +#define SEMIHOSTING_SOFTMMU_UACCESS_H =20 #include "cpu.h" =20 @@ -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) =20 -#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; =20 -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif =20 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/mi= ps-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" =20 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" =20 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091728; cv=none; d=zohomail.com; s=zohoarc; b=enFX6v+O59RKS8e31X1J9ZTW6f1ob6NQCPiYbf6xd9toRu0ngl/ZfnNlFw1jsfHSk04HfGLa5DuD4u8/5opYK+jcLQdUtGjhSPLdbDnkAPftk5aGQcqMeMVFzRmvDJth32hKZbI3ytR2IVxxxLwdgk9HViCL2sqTKe+RNdI6rWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091728; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=AfiXnq95Q2vy2EDzQlVPpi7haBiGsSlp1RW0N+MuAvi1bb9UTCdsY7zi+TGy9oKdtjPzJcX1RF7y083Il1Xo11yLk8S0qqaaXiwt6boV2PiVDlCXZeWTqjCaw5lNTEuxUuNJoVHVTsjolM13BAcuVmh/kUOV2xwqCqoOpSWSWcU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091728477439.25177128450343; Fri, 20 May 2022 17:08:48 -0700 (PDT) Received: from localhost ([::1]:58038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCfn-0002oB-Fs for importer2@patchew.org; Fri, 20 May 2022 20:08:47 -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) 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) 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-Google-Smtp-Source: ABdhPJwspM81pl6JvvKhdLs+6zGRuMK2SW4fGFwvJFDnePSFa1b00cnRmdp7JL5faSnjULYO98x5UA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091730092100001 Content-Type: text/plain; charset="utf-8" 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/so= ftmmu-uaccess.h index e69e3c8548..5246a91570 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -12,82 +12,69 @@ =20 #include "cpu.h" =20 -static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) -{ - uint64_t val; +#define get_user_u64(val, addr) \ + ({ uint64_t val_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D tswap64(val_); ret_; }) =20 - 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_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D tswap32(val_); ret_; }) =20 -static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr) -{ - uint32_t val; +#define get_user_u8(val, addr) \ + ({ uint8_t val_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D val_; ret_; }) =20 - 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 =3D softmmu_tget64(env, p); 0; }) -#define get_user_u32(arg, p) ({ arg =3D softmmu_tget32(env, p) ; 0; }) -#define get_user_u8(arg, p) ({ arg =3D softmmu_tget8(env, p) ; 0; }) #define get_user_ual(arg, p) get_user_u32(arg, p) =20 -static inline void softmmu_tput64(CPUArchState *env, - target_ulong addr, uint64_t val) -{ - val =3D tswap64(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1); -} +#define put_user_u64(val, addr) \ + ({ uint64_t val_ =3D tswap64(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); = }) + +#define put_user_u32(val, addr) \ + ({ uint32_t val_ =3D tswap32(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); = }) =20 -static inline void softmmu_tput32(CPUArchState *env, - target_ulong addr, uint32_t val) -{ - val =3D 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) =20 -static void *softmmu_lock_user(CPUArchState *env, - target_ulong addr, target_ulong len, int co= py) +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 =3D malloc(len); + void *p =3D 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 =3D 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 =3D p =3D malloc(1024); + char *s =3D malloc(1024); + size_t len =3D 0; + if (!s) { return NULL; } do { - cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0); - addr++; - *(p++) =3D 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 a= ddr, target_ulong len) { --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091901; cv=none; d=zohomail.com; s=zohoarc; b=e43N4LmEYtWS6HYvj+qeUCnFAu2MQVa7nG160MQrRNwovtCneM+Zyzj2jUYF2wYH6gGTA9LXgO6Tak8gRFOIHjgS0bo5itUVUDJXhhgz33T2NOdRSKUAsgWtNmTLO9xI/vT+RaK/0K+s4I8M+uCNn10DiFmD2DLdBc4wvWldznI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091901; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=hIK7MqnAI4KBK1l63Mq/AAUuF7fcqSNJzwHl06Y9YY/V99ynP7bNAsTbrcfOXFQY4u+OHQOllgg6XIPXYHIDdy3Q+qLhm+AuybB7Tixwe0BV87NynsBkS40GH5CD2pgWyY4fiZiGf4FQ61pkOU2DFI2v2xA0ajtVapTZzyX3kQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091901367334.46556074438547; Fri, 20 May 2022 17:11:41 -0700 (PDT) Received: from localhost ([::1]:38342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCia-0000PR-B5 for importer2@patchew.org; Fri, 20 May 2022 20:11:40 -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) 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) 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-Google-Smtp-Source: ABdhPJwrz/o1vcREE6G9h8f5q/6TFgBazp2Y6YB0P48YFXzMR8Dx7lFwbQZqYIDIIJAg8xcpzmUxNg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091903166100001 Content-Type: text/plain; charset="utf-8" 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: f= iles( 'config.c', 'console.c', )) --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091903; cv=none; d=zohomail.com; s=zohoarc; b=MZSx7iyAuqWBZvo+FF/LF62tIsotBDDY/4csDbvPTKbmjWLuzZ88T/qj98w4fXoiqV5GjE/jyJNfwZu1iBFz1TUCov6OnEwtFI5R6FkeeEpZ3SbW+xCtIILD/G+XLzUAgHA/kWwaN1PKY6WGNnn1KoMgLLVsI0l8dfO9VsJRL4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091903; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=at7qIqFZwmmPPtnD0khGIRUCfNp84egGZu7NC9lpOEYLxdbNQRzSs3nJNBBwQJAHatiWUhftYmFslbu33XQfl8s41PLfhXj6IO6A5Sa1/xvf1gcSJ/x8nJSGBJy069xrIGpwjaSvNPUeklVS4PCsaV0t1l6Kd9jMH205D2RzV/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091903484365.1787715554083; Fri, 20 May 2022 17:11:43 -0700 (PDT) Received: from localhost ([::1]:38598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCic-0000ZB-2i for importer2@patchew.org; Fri, 20 May 2022 20:11:42 -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) 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) 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-Google-Smtp-Source: ABdhPJya1fsZugCiTy9RnkSRw4NWAnhREq8tlA4duO6d4L6EjsCa2b1GELRoFyTpd5bNft/FvRQfiQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091905159100005 Content-Type: text/plain; charset="utf-8" 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/so= ftmmu-uaccess.h index 5246a91570..03300376d3 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -42,47 +42,15 @@ =20 #define put_user_ual(arg, p) put_user_u32(arg, p) =20 -static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, - target_ulong len, bool copy) -{ - void *p =3D malloc(len); - if (p && copy) { - if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); - p =3D 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) =20 -static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) -{ - /* TODO: Make this something that isn't fixed size. */ - char *s =3D malloc(1024); - size_t len =3D 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) =20 -static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong a= ddr, - 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) =20 #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 =3D malloc(len); + if (p && copy) { + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p =3D NULL; + } + } + return p; +} + +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) +{ + /* TODO: Make this something that isn't fixed size. */ + char *s =3D malloc(1024); + size_t len =3D 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: f= iles( 'config.c', 'console.c', + 'uaccess.c', )) =20 specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091732; cv=none; d=zohomail.com; s=zohoarc; b=MieX8xyoDCwJ6UP0gD+6d/tj8U3N7o7zFmL87K8o6bMeQxWJhKf1WnBrK9fN7TbG9bgogXiWOlKpWUN+EYwPUGj4jeTFLPKgC+6XcChjWbvWMLyAm1uTVdLby8FbKZyXEg36Obx5yb4j14TrsTlbVIfYnpsMuDg2zVo53Pf1ZKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091732; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2OyP2Wnw9umWfxtpbUetMIm1XRFLbapKewV58Lgr8fc=; b=LDAVopZSCJxApd4ol7Wb+PfmuOIUiszhhqTHTRpB0557moo2QS67I+6J69Jz4Xd32R9bDf2iAnRuuui7g0y5TIVBKHSqakC8M9/kBUs53oikHKq+1JtvKg/pRD/nJeLkvViP0bscnXlDtEPXrSMNAASm9umzvgzP8sUEY45stUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091732712350.29172562691554; Fri, 20 May 2022 17:08:52 -0700 (PDT) Received: from localhost ([::1]:57984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCfp-0002mb-TE for importer2@patchew.org; Fri, 20 May 2022 20:08:49 -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) 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) 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-Google-Smtp-Source: ABdhPJzB6gVq463DOmcWC06vjYcw/y4qlye6RnVe8nLFqNw33ElSVHl+XRF8wFvMgrdE3+EMULYwmQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091734149100001 Content-Type: text/plain; charset="utf-8" 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/so= ftmmu-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) =20 +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 @@ */ =20 #include "qemu/osdep.h" +#include "exec/exec-all.h" #include "semihosting/softmmu-uaccess.h" =20 void *softmmu_lock_user(CPUArchState *env, target_ulong addr, @@ -23,6 +24,54 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong = addr, return p; } =20 +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + int mmu_idx =3D cpu_mmu_index(env, false); + size_t len =3D 0; + + while (1) { + size_t left_in_page; + int flags; + void *h; + + /* Find the number of bytes remaining in the page. */ + left_in_page =3D -(addr | TARGET_PAGE_MASK); + + flags =3D 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 =3D=3D 0) { + return len; + } + addr++; + len++; + if (len > INT32_MAX) { + return -1; + } + } while (--left_in_page !=3D 0); + } else { + char *p =3D memchr(h, 0, left_in_page); + if (p) { + len +=3D p - (char *)h; + return len <=3D INT32_MAX ? (ssize_t)len : -1; + } + addr +=3D left_in_page; + len +=3D 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. */ --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092034; cv=none; d=zohomail.com; s=zohoarc; b=T6QHVUDr2uvqGci9JzE8r64SVoh+Ur112Z1cad6s5qSx7McqGgF7sV+6iggpCABbtiJz5xrZAm6HXAsgpkwwY36oR+AsTcyk8rhOKAT8ABhzImB6Iv9i6ZDzrsbqFjDIZXzf/Ra7JdXhyVstLqNgeuIBAk+L1Ml9CMBX9g3r6Uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092034; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2UWwm+1enZhNATgFL33PYQ1DN6Mmw/PBhL6/pzVSSaU=; b=dbIIjvuL/4cVybGtyyuw+sXB4zK3wtiNL/PG/wpBXLFh0ePnzpNtuDtH+QcquMy0yUh85cSjL3YsQBlOQkbjaCClLT5tVOSf3TpFYCElOxUZZCXKLTVpFblJ5SRR9d6QEpH8hCyA3MiAyZzWN3ZezwnebxZWi/DPjqVlfjHWG5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092034333957.6004333754804; Fri, 20 May 2022 17:13:54 -0700 (PDT) Received: from localhost ([::1]:47072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCkj-0006Bo-32 for importer2@patchew.org; Fri, 20 May 2022 20:13:53 -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) 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) 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-Google-Smtp-Source: ABdhPJxu44nZvWi22IGrNblmW7qaAO6O0n41xZwOCjxFejBZkJDIK2uC/FjIRwRX13XLqdv/+WIBnQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092035719100001 Content-Type: text/plain; charset="utf-8" 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_u= long addr) =20 char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - /* TODO: Make this something that isn't fixed size. */ - char *s =3D malloc(1024); - size_t len =3D 0; - - if (!s) { + ssize_t len =3D 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); } =20 void softmmu_unlock_user(CPUArchState *env, void *p, --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092038; cv=none; d=zohomail.com; s=zohoarc; b=oB64psogMml6/38wmvVuwDdBo42J1inMpjXjiKaGNahj6gxRU7TgghlmyoL+/FqhdqlrRXE0okf6GjCAO5lL2vBD1z2BsYQuQGatpDOZtMORNfsY4PhfZXn+EwVpYDt2S1atEuvADiWDal2veJRASZRd/e4uXSqFwsougEXE47s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092038; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=99JGUMI2r4BW2Q/ohOps3LgiQ8LQqv9048VXv1Twk64=; b=mpWPqCd+llvoRfbd1SeqK+y4KAiTTH4YaxDP9xgj7sKtznTZdme37AceDTXmFKBfduufdnAumyJbPXE+8Y0v+n/DLqc2Hy6KwabTVj0vcdVxmHnC3Thpau5PG3wxSR+gKPFrEpoIKwcreEWMH30FPpGuSEyKXK9rR2lOBNsF3+A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092038184332.25091987873714; Fri, 20 May 2022 17:13:58 -0700 (PDT) Received: from localhost ([::1]:47020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCkm-00069u-Ll for importer2@patchew.org; Fri, 20 May 2022 20:13:56 -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) 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) 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-Google-Smtp-Source: ABdhPJyDD691Spz3/gc3AzuJ41OBmcNbTWKKD4S/5gZC57PyIvvgJ8JlzqmXLv5E3ar0m7cfqy+t6Q== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092039805100001 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/aarch= 64-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=3Daarch64 TARGET_BASE_ARCH=3Darm TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aa= rch64_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=3Darm TARGET_BIG_ENDIAN=3Dy TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy 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=3Dcommon,oabi TARGET_SYSTBL=3Dsyscall.tbl TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-v= fp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-prof= ile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/armeb-linux-user.mak b/configs/targets/armeb-l= inux-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=3Dsyscall.tbl TARGET_BIG_ENDIAN=3Dy TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-v= fp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-prof= ile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/riscv32-linux-user.mak b/configs/targets/riscv= 32-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=3Driscv32 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-virtual.xml +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/riscv64-linux-user.mak b/configs/targets/riscv= 64-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=3Driscv64 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy 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 =C2=A9 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_GUESTFD_H +#define SEMIHOSTING_GUESTFD_H + +typedef enum GuestFDType { + GuestFDUnused =3D 0, + GuestFDHost =3D 1, + GuestFDGDB =3D 2, + GuestFDStatic =3D 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 @@ */ =20 #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" =20 @@ -123,27 +124,6 @@ static int open_modeflags[12] =3D { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; =20 -typedef enum GuestFDType { - GuestFDUnused =3D 0, - GuestFDHost =3D 1, - GuestFDGDB =3D 2, - GuestFDFeatureFile =3D 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 =20 /** @@ -268,98 +248,6 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) =20 #endif =20 -/* - * 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 =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - - /* SYS_OPEN should return nonzero handle on success. Start guestfd fro= m 1 */ - for (i =3D 1; i < guestfd_array->len; i++) { - GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, i); - - if (gf->type =3D=3D 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 <=3D 0 || guestfd >=3D 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 =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; - gf->hostfd =3D 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 =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D 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 =3D do_get_guestfd(guestfd); - - if (!gf || gf->type =3D=3D 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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void init_featurefile_guestfd(int guestfd) -{ - GuestFD *gf =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D GuestFDFeatureFile; - gf->featurefile_offset =3D 0; -} - -static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } =20 -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, Guest= FD *gf, return set_swi_errno(cs, -1); } =20 -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 =3D cs->env_ptr; @@ -703,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, } =20 for (i =3D 0; i < len; i++) { - if (gf->featurefile_offset >=3D sizeof(featurefile_data)) { + if (gf->staticfile.off >=3D gf->staticfile.len) { break; } - s[i] =3D featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] =3D gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } =20 unlock_user(s, buf, len); @@ -716,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, return len - i; } =20 -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } =20 -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset =3D offset; + gf->staticfile.off =3D offset; return 0; } =20 -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; } =20 typedef struct GuestFDFunctions { @@ -759,13 +638,13 @@ static const GuestFDFunctions guestfd_fns[] =3D { .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, - [GuestFDFeatureFile] =3D { - .closefn =3D featurefile_closefn, - .writefn =3D featurefile_writefn, - .readfn =3D featurefile_readfn, - .isattyfn =3D featurefile_isattyfn, - .seekfn =3D featurefile_seekfn, - .flenfn =3D featurefile_flenfn, + [GuestFDStatic] =3D { + .closefn =3D staticfile_closefn, + .writefn =3D staticfile_writefn, + .readfn =3D staticfile_readfn, + .isattyfn =3D staticfile_isattyfn, + .seekfn =3D staticfile_seekfn, + .flenfn =3D staticfile_flenfn, }, }; =20 @@ -886,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno =3D EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } =20 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 =C2=A9 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 =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + /* SYS_OPEN should return nonzero handle on success. Start guestfd fro= m 1 */ + for (i =3D 1; i < guestfd_array->len; i++) { + GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type =3D=3D 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 <=3D 0 || guestfd >=3D 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 =3D do_get_guestfd(guestfd); + + if (!gf || gf->type =3D=3D 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 =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; + gf->hostfd =3D hostfd; +} + +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDStatic; + gf->staticfile.data =3D data; + gf->staticfile.len =3D len; + gf->staticfile.off =3D 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 =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D 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: f= iles( 'config.c', 'console.c', --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092022; cv=none; d=zohomail.com; s=zohoarc; b=RIS0paQ1lG9L2Mjy/rxLW3VpG60Dfa3wpC4t3qz5SiYC6sy36xQF6COCLz36Oj10D5JeoA7S7lBWaptXRECAofdL/WiS7sRBWOjpu4Q9XkFRsqDd/BmgaaJYTNlTgDiK5dr36Wx7ab6oB0RPupcHVqvJzkLnKVE2sb8GW7y0JwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092022; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LqMX+PYoPOvCfsrBf9LDk+x8oxX5ugoY/7ce6aNzp7o=; b=KsVTgPe+r1X+nru6dwr+fvLXzgB0oNfaGNg5kGp4uO/g3qGFYYLbvcet2mNCUw9IpQ3XFrBuXI2RGATmt2Hhg31unwCffcz4PPEMiI15aZ2+l4ZqG/QFtpJp1lJif/ZCfxMbLTsZXd2SHfrYY/nqRRAAKvmrUq99/Ij4oqX2HdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092022233361.75716868053075; Fri, 20 May 2022 17:13:42 -0700 (PDT) Received: from localhost ([::1]:46916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCkX-00065l-25 for importer2@patchew.org; Fri, 20 May 2022 20:13:41 -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) 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) 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-Google-Smtp-Source: ABdhPJws0x73K9yax4RseENN5YNTJfNOVhgvEDR7ntD/ZMPDKPENQGnsGn+UGg3uVCIdk3y0+e6bYg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092023776100001 Content-Type: text/plain; charset="utf-8" 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; =20 static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { - target_ulong reg0 =3D common_semi_arg(cs, 0); - if (ret =3D=3D (target_ulong)-1) { - errno =3D err; - set_swi_errno(cs, -1); - reg0 =3D ret; +#ifdef CONFIG_USER_ONLY + TaskState *ts =3D cs->opaque; + ts->swi_errno =3D err; +#else + syscall_err =3D err; +#endif } else { /* Fixup syscalls that use nonstardard return conventions. */ + target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 =3D common_semi_syscall_len - ret; + ret =3D common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: - reg0 =3D 0; + ret =3D 0; break; default: - reg0 =3D ret; break; } } - common_semi_set_ret(cs, reg0); + common_semi_set_ret(cs, ret); } =20 static target_ulong common_semi_flen_buf(CPUState *cs) --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092278; cv=none; d=zohomail.com; s=zohoarc; b=KGqjYLA03iOmYWDcHdrPkHhCoN4hOBEaPrFMaO2oXWqEHKx95oESoz+aglHAC9WiBTqLWx0yL+9FrT1Q2Vob5gogTPocnrujmCK2fHs8CakSA8A/hrxaAUxQkORMfAlG96bb4sRVbK2++avQvFiFFhIFzEZyYhnlV1UdpEyqmPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092278; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iO8bYt33Tjxv9WbhuJst+fUaLLVWutotkQNg/qYeZ+o=; b=RuOuabNv/i07Ps6o1Lzyfhs9yjdoc7wOfyzx6mMDtbNH6S5mtvbQqeNhQRmV4St+76JH34TcsPAdgOxBD0b6cFTyk9TbPInPTRL5NJUNju1oNAERa2piL/ZFsvFbzscuJwQLnNyELMsbgmaxbkctxR1l+0+V1kL0h3Y3PocnUmU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092278495409.1060056776596; Fri, 20 May 2022 17:17:58 -0700 (PDT) Received: from localhost ([::1]:55588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCof-0003aO-0G for importer2@patchew.org; Fri, 20 May 2022 20:17:57 -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) 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) 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-Google-Smtp-Source: ABdhPJws5HLnGCQxi7aCw4nF8jZjJMdD2H8CRD8H32UwlIEJ/SJCoT4/v+8Q+c8tp8rRdvS404jhyw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092278964100001 Content-Type: text/plain; charset="utf-8" The err parameter is non-zero if and only if an error occured. Use this instead of ret =3D=3D -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; =20 static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { - if (ret =3D=3D (target_ulong)-1) { + if (err) { #ifdef CONFIG_USER_ONLY TaskState *ts =3D cs->opaque; ts->swi_errno =3D err; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091902; cv=none; d=zohomail.com; s=zohoarc; b=LhJb4U4V51AwkXUsCRppnMKO8u20oqwAXs/8fRszOAkbV/t7YJPG/EWkiON+nc9WpKvGz7yY5FneJs4++fySjN6zN08002E5nhP+PEvcNPxxZ3OfXF5x5U7x1lN1qqwI1suHacTFlYA1toNdRBybIN7uDi/BSexKWtXAAnmPFZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091902; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kCDHy7lpceuAK2eVJ1Y4445ZF33BxGk4+3bwHnJ8e7o=; b=UvBUZMvPnFvrce0zbvkC4Zt1PSR09Wi3ZczjBlXDnKm20S6+qH64KiqhnIy/ZABhe2yc/OzyObSpkNUxB1tCgqGeDAXMBCREOKNgU6jXSxpsonPgjK7489q3LRu7Ze41zcCQNF5zTh9Q/dvM60GZhYfxUQYHbomOhgNYC1RnyZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091902659370.65539060095887; Fri, 20 May 2022 17:11:42 -0700 (PDT) Received: from localhost ([::1]:38422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCib-0000SV-L7 for importer2@patchew.org; Fri, 20 May 2022 20:11:41 -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) 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) 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-Google-Smtp-Source: ABdhPJzqTsDwjRUa//ZWVF/KXqWYnbYI7+9xrCRX1mJAN02knfB5o025m6hrA1gk6LCxZnEF84D+Tg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091903169100002 Content-Type: text/plain; charset="utf-8" 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=C3=A9e --- 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 =3D be32_to_cpu(size); - common_semi_set_ret(cs, size); - errno =3D 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 =3D be32_to_cpu(size); + } + common_semi_cb(cs, ret, err); } =20 static int common_semi_open_guestfd; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092491; cv=none; d=zohomail.com; s=zohoarc; b=A+6yG3GIOlwX/SIVMJMZM7RtpaS7V+gSpzyN34ME/4IbH9rewg/wSEXe3sbB59k9iqqx8sb7Lls/mVeawDFR+MO0oTIKvyndITl2seOyycLAoJQQ/a99yFxvmY61sbEk86KYY0fiB88/3yfOI/qg9koo5zageMJsITrgL0U32+k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092491; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CwJJmiinTbs3pTu81N0JRGdiNyaikTYskuQZDhXBbfU=; b=LiYqC3O340/QSLe5sIuWmUC+9YUnR8AZe1EcDCX+AD08kcs3Au6DRUHaDVp8tn+dxHyXRdRBe7oxMmxgVcVG4yFU92dJTscnPn7WEarDr7qvsTHrhP1fHi6ply0O7AHYyMHULA+vswOz0FfqFyl1+Q2evst/82g/XVyAJMcSGuA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092491416859.61858482131; Fri, 20 May 2022 17:21:31 -0700 (PDT) Received: from localhost ([::1]:35786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCs6-000120-E1 for importer2@patchew.org; Fri, 20 May 2022 20:21:30 -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) 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) 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-Google-Smtp-Source: ABdhPJw4E6pzejTUh8f6F2NZRwGlD8iiXUxQnM82htqtlF9dJ6qGH/LNqarV/FxnZdN330xbz1Vrpg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092492721100001 Content-Type: text/plain; charset="utf-8" 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=C3=A9e --- 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 =3D=3D (target_ulong)-1) { - errno =3D err; - set_swi_errno(cs, -1); + if (err) { dealloc_guestfd(common_semi_open_guestfd); } else { associate_guestfd(common_semi_open_guestfd, ret); ret =3D common_semi_open_guestfd; } - common_semi_set_ret(cs, ret); + common_semi_cb(cs, ret, err); } =20 static target_ulong --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092904; cv=none; d=zohomail.com; s=zohoarc; b=oIrb3bRA9XyNC25r0eUtc0A7d8NSg0dtuB2uN/X/9uGlGs80Z803UPXTvymCJhkZYgFd7B6G1UbSz0m6kyhCZcXjRQIIj4qqSxb2g3Lg8oUfx+AhK2p1h9w+tG+A2p5l+fkWoRtP3dt5eQNhSIvc0lG/zHnipkJKwms+NIr5RMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092904; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Ft7CVbGog1TUu0kU/zq3jjXX/+B4Wi5S7h2gXyMVQw=; b=OGtzeblfo5vdBBFOVU7UxW1btKIUfq392IX4+BuJZGbgnoQrLTQxGZny2rlgt3r6C9tu39WiX3aigRlwOYgVPGjykLOFAnCoyVJFYtkTJ3cJKsH8MjLTUjPPI2Y8hoyVMfiCvBm5SgeOGBToJbN83KiWQGAfHD26LC6BH0hgZeg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092904107858.701685467863; Fri, 20 May 2022 17:28:24 -0700 (PDT) Received: from localhost ([::1]:52250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCyk-0004GC-Ur for importer2@patchew.org; Fri, 20 May 2022 20:28:22 -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) 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) 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-Google-Smtp-Source: ABdhPJyD8I05cLlAqbr4NrI6IZOEL3g7kSglJuQjIvuX9/AYlErQIcPnQW4J6Qx9n+l1GbIJ5mGNSQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092904790100001 Content-Type: text/plain; charset="utf-8" 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 =20 -target_ulong do_common_semihosting(CPUState *cs); +void do_common_semihosting(CPUState *cs); =20 #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] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 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] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] +=3D 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] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 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 =20 -static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) -{ - if (code =3D=3D (uint32_t)-1) { -#ifdef CONFIG_USER_ONLY - TaskState *ts =3D cs->opaque; - - ts->swi_errno =3D errno; -#else - syscall_err =3D 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, t= arget_ulong err) common_semi_cb(cs, ret, err); } =20 -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); =20 -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 =3D=3D STDIN_FILENO || gf->hostfd =3D=3D STDOUT_FILENO || gf->hostfd =3D=3D STDERR_FILENO) { - return 0; + ret =3D 0; + } else { + ret =3D close(gf->hostfd); } - return set_swi_errno(cs, close(gf->hostfd)); + common_semi_cb(cs, ret, ret ? errno : 0); } =20 -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 =3D cs->env_ptr; - uint32_t ret; + uint32_t ret =3D 0; char *s =3D 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 =3D write(gf->hostfd, s, len); + unlock_user(s, buf, 0); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } } - ret =3D set_swi_errno(cs, write(gf->hostfd, s, len)); - unlock_user(s, buf, 0); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not written */ - return len - ret; + /* Return bytes not written, on error as well. */ + common_semi_cb(cs, len - ret, 0); } =20 -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 =3D cs->env_ptr; - uint32_t ret; + uint32_t ret =3D 0; char *s =3D 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 =3D read(gf->hostfd, s, len); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + unlock_user(s, buf, len); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } } - do { - ret =3D set_swi_errno(cs, read(gf->hostfd, s, len)); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); - unlock_user(s, buf, len); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not read */ - return len - ret; + /* Return bytes not read, on error as well. */ + common_semi_cb(cs, len - ret, 0); } =20 -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); } =20 -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 =3D set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)= ); - if (ret =3D=3D (uint32_t)-1) { - return -1; - } - return 0; + off_t ret =3D lseek(gf->hostfd, offset, SEEK_SET); + common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); } =20 -static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) +static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; - uint32_t ret =3D set_swi_errno(cs, fstat(gf->hostfd, &buf)); - if (ret =3D=3D (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; } =20 -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->hos= tfd); + gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); } =20 -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 =3D 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); } =20 -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 =3D 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); } =20 -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->ho= stfd); + gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } =20 -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); } =20 -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)); } =20 #define SHFB_MAGIC_0 0x53 @@ -554,63 +503,57 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -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); } =20 -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 =3D EBADF; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EBADF); } =20 -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 =3D cs->env_ptr; - uint32_t i; + uint32_t i =3D 0; char *s; =20 (void) env; /* Used in arm softmmu lock_user implicitly */ s =3D lock_user(VERIFY_WRITE, buf, len, 0); - if (!s) { - return len; - } - - for (i =3D 0; i < len; i++) { - if (gf->staticfile.off >=3D gf->staticfile.len) { - break; + if (s) { + for (i =3D 0; i < len; i++) { + if (gf->staticfile.off >=3D gf->staticfile.len) { + break; + } + s[i] =3D gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } - s[i] =3D gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; + unlock_user(s, buf, len); } =20 - unlock_user(s, buf, len); - /* Return number of bytes not read */ - return len - i; + common_semi_cb(cs, len - i, 0); } =20 -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); } =20 -static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset) +static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offs= et) { gf->staticfile.off =3D offset; - return 0; + common_semi_cb(cs, 0, 0); } =20 -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); } =20 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 =3D EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - errno =3D EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } \ } while (0) @@ -695,7 +636,7 @@ static inline bool is_64bit_semihosting(CPUArchState *e= nv) * 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 =3D 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 =3D 0; + int hostfd; =20 GET_ARG(0); GET_ARG(1); GET_ARG(2); s =3D lock_user_string(arg0); if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } if (arg1 >=3D 12) { unlock_user(s, arg0, 0); - errno =3D EINVAL; - return set_swi_errno(cs, -1); - } - - guestfd =3D alloc_guestfd(); - if (guestfd < 0) { - unlock_user(s, arg0, 0); - errno =3D EMFILE; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EINVAL); + break; } =20 if (strcmp(s, ":tt") =3D=3D 0) { - int result_fileno; - /* * We implement SH_EXT_STDOUT_STDERR, so: * open for read =3D=3D stdin @@ -748,63 +680,67 @@ target_ulong do_common_semihosting(CPUState *cs) * open for append =3D=3D stderr */ if (arg1 < 4) { - result_fileno =3D STDIN_FILENO; + hostfd =3D STDIN_FILENO; } else if (arg1 < 8) { - result_fileno =3D STDOUT_FILENO; + hostfd =3D STDOUT_FILENO; } else { - result_fileno =3D STDERR_FILENO; + hostfd =3D STDERR_FILENO; } - associate_guestfd(guestfd, result_fileno); - unlock_user(s, arg0, 0); - return guestfd; - } - if (strcmp(s, ":semihosting-features") =3D=3D 0) { - unlock_user(s, arg0, 0); + ret =3D alloc_guestfd(); + associate_guestfd(ret, hostfd); + } else if (strcmp(s, ":semihosting-features") =3D=3D 0) { /* We must fail opens for modes other than 0 ('r') or 1 ('rb')= */ if (arg1 !=3D 0 && arg1 !=3D 1) { - dealloc_guestfd(guestfd); - errno =3D 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 =3D guestfd; - ret =3D common_semi_gdb_syscall(cs, common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg= 2 + 1, - gdb_open_modeflags[arg1]); - } else { - ret =3D set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); - if (ret =3D=3D (uint32_t)-1) { - dealloc_guestfd(guestfd); + ret =3D -1; + err =3D EACCES; } else { - associate_guestfd(guestfd, ret); - ret =3D guestfd; + ret =3D alloc_guestfd(); + staticfile_guestfd(ret, featurefile_data, + sizeof(featurefile_data)); + } + } else if (use_gdb_syscalls()) { + unlock_user(s, arg0, 0); + common_semi_open_guestfd =3D alloc_guestfd(); + gdb_do_syscall(common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg2 + 1, + gdb_open_modeflags[arg1]); + break; + } else { + hostfd =3D open(s, open_modeflags[arg1], 0644); + if (hostfd < 0) { + ret =3D -1; + err =3D errno; + } else { + ret =3D 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); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } - - ret =3D 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 =3D 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) =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + break; =20 - 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) =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + break; =20 - return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(cs->env_ptr); + ret =3D 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); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].isattyfn(cs, gf); + break; =20 - return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].seekfn(cs, gf, arg1); + break; =20 - return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].flenfn(cs, gf); + break; =20 - 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 =3D (target_ulong) -1; - + len =3D asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xf= f); /* Make sure there's enough space in the buffer */ - if (strlen(s) < arg2) { - char *output =3D lock_user(VERIFY_WRITE, arg0, arg2, 0); - strcpy(output, s); - unlock_user(output, arg0, arg2); - ul_ret =3D 0; + if (len < 0 || len >=3D arg2) { + common_semi_set_ret(cs, -1); + break; } + p =3D 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 =3D common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s= ", - arg0, (int)arg1 + 1); - } else { - s =3D lock_user_string(arg0); - if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); - } - ret =3D 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 =3D lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret =3D 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 =3D lock_user_string(arg0); - s2 =3D lock_user_string(arg2); - if (!s || !s2) { - errno =3D EFAULT; - ret =3D set_swi_errno(cs, -1); - } else { - ret =3D set_swi_errno(cs, rename(s, s2)); + if (!s) { + goto do_fault; } - if (s2) - unlock_user(s2, arg2, 0); - if (s) + s2 =3D lock_user_string(arg2); + if (!s2) { unlock_user(s, arg0, 0); - return ret; + goto do_fault; + } + ret =3D 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 =3D time(NULL); + common_semi_cb(cs, ul_ret, ul_ret =3D=3D -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 =3D lock_user_string(arg0); - if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); - } - ret =3D 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 =3D lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret =3D system(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret =3D=3D -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) =20 if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - errno =3D E2BIG; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, E2BIG); + break; } =20 /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } =20 /* Lock the buffer on the ARM side. */ output_buffer =3D lock_user(VERIFY_WRITE, arg0, output_size, 0= ); if (!output_buffer) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } =20 /* Copy the command-line arguments. */ @@ -1029,9 +984,8 @@ target_ulong do_common_semihosting(CPUState *cs) =20 if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - errno =3D EFAULT; - status =3D set_swi_errno(cs, -1); - goto out; + unlock_user(output_buffer, arg0, 0); + goto do_fault; } =20 /* 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) =20 if (fail) { /* Couldn't write back to argument block */ - errno =3D 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 =3D get_clock() - clock_start; if (sizeof(target_ulong) =3D=3D 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] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] +=3D 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] =3D 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) =20 if (cause =3D=3D RISCV_EXCP_SEMIHOST) { if (env->priv >=3D PRV_S) { - env->gpr[xA0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; return; } --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092277; cv=none; d=zohomail.com; s=zohoarc; b=XW4Q7YmsUAjjeB/T5CkLlbpqF/3Ei8+xmgAHizb3rSEwIR0FUAKD4qM96XdlwBMLMTsAnt6Omj3giyGPMgxusXflNRObOXNrdtotvD8G5ZMo9s5i+bc6GcDBwywd5scqtL85Jm247TDzpewA7GjE/RAA8kUHkuW9rVZnSvmZEnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092277; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=bgu+g6Eqkk9tvASEkws3/V6witfLAealhSXWe78Fqb40++qL9buH+r4450eN1Zq31yXOJpyXKqKUA6Cdvq30gK7n5OM48vLZZAo+C/vzIMZ49CrwZYyMejhCNQ95ZwEHvW2dTldXsOpJYE7A9oLZyl8wr4IREc7NXvJnLUjscX8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092277573249.90057602449997; Fri, 20 May 2022 17:17:57 -0700 (PDT) Received: from localhost ([::1]:55622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCoe-0003bZ-1O for importer2@patchew.org; Fri, 20 May 2022 20:17:56 -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) 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) 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-Google-Smtp-Source: ABdhPJybaVfOmVnzMUqn6bHR4BTEhIMNZ3EC4mzgmN9832Y9R5w9N59vOfLxA91HAW6koj49/9SlLQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092279033100003 Content-Type: text/plain; charset="utf-8" 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 =3D> include/semihosting}/common-semi.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {semihosting =3D> 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 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094618; cv=none; d=zohomail.com; s=zohoarc; b=Zz9KCxtCd0mb1jA04A/QBH7//xpMvSSly6vzyotjW4/jzP4s6mMK2QbasacKYQMGkIFdBz7m5aUyQhZ86v8W8uVE5KGgede4C5ArURkxSXW26voZKmMdGLOmWjm22TiD9r8WM7tMlsGemYbEvgFTznNTu8nHfKMHjOHnc7YRkYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094618; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6dWKfH8zSLvUN3M0oH8qZ8MqlB5qlfA1EdENsRW07Xc=; b=acEhLLNS4Vyins6hxUafqV8gkmA0wYj91xerobHbgbYLAk9CHTvNw4fwBieH50D3CKU0KkMU/38fYQxKpNC+xaZicRzrY4Jn7VwJzhW37xnmXKBPjTjnEnREZFFz40fiipFEH6ZS5mg7b9fs25SHRaB2l60K88+6VlgIbv9ykzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094618652534.3602469798248; Fri, 20 May 2022 17:56:58 -0700 (PDT) Received: from localhost ([::1]:39002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDQP-00018T-8s for importer2@patchew.org; Fri, 20 May 2022 20:56:57 -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) 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) 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-Google-Smtp-Source: ABdhPJwiODPxdTxvnVKavL3N7qOLUmUFwwJ046nxMSENy2MYx6Nj0TPZRGHyClhcxU1/uVz0isuAbA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094620239100001 Content-Type: text/plain; charset="utf-8" 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: Alex Benn=C3=A9e Reviewed-by: Peter Maydell --- 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 =20 +/* 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" =20 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 =20 -#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] =3D { 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; =20 -#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; =20 -#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; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094504; cv=none; d=zohomail.com; s=zohoarc; b=OoZEDUwLqB/uEyt/hX2ToaVgcp2nDnjxakKFBS/mTZtVxwbf/75042y4fV93hiHJjE9/9Kd3PuQqkoPDPkgZ3sxV/yd27lGHWcIekHJ+J9OTzmzWbPhq10q5eYLbMR24CFxpKcJk5JDHWnRZ0jg0fTYEfc5o7ycjn1WUBMfGZiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094504; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=Y/aGLx0P6PViXF7H/ipsGpiuf5us1bP+qZf0WvwIRCgAOvW1azXfnnY8RSro5w3bVCB5Tx5C0r2+B3NyPcza8x0kUAxzChzaHjyMRIND/XoP6+yT/seap+HedEfxEnMxyxQ2k3K3AbbThq0g0uHIuS5C047wkPKZQzjWwlragQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094504329897.8614089573315; Fri, 20 May 2022 17:55:04 -0700 (PDT) Received: from localhost ([::1]:36772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDOZ-0007xU-BH for importer2@patchew.org; Fri, 20 May 2022 20:55:03 -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) 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) 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-Google-Smtp-Source: ABdhPJx+gRxTsf9CqjN3L7IZbU0dfMH3ag3qpeZO+vAzz22oIz/ACdCGwf6NUIOj8rogvEpl9y7b4g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094505733100001 Content-Type: text/plain; charset="utf-8" We have two copies of these structures, and require them in semihosting/ going forward. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Peter Maydell --- 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 =20 +/* 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" =20 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 =20 -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) =20 static void translate_stat(CPUM68KState *env, target_ulong addr, struct st= at *s) { - struct m68k_gdb_stat *p; + struct gdb_stat *p; =20 - if (!(p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat)= , 0))) + if (!(p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) /* FIXME - should this return an error code? */ return; p->gdb_st_dev =3D cpu_to_be32(s->st_dev); @@ -114,7 +90,7 @@ static void translate_stat(CPUM68KState *env, target_ulo= ng addr, struct stat *s) p->gdb_st_atime =3D cpu_to_be32(s->st_atime); p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); } =20 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 =20 -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; =20 - p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0); + p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); =20 if (!p) { return false; @@ -128,7 +104,7 @@ static bool translate_stat(CPUNios2State *env, target_u= long addr, p->gdb_st_atime =3D cpu_to_be32(s->st_atime); p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); p->gdb_st_ctime =3D 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; } =20 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092668; cv=none; d=zohomail.com; s=zohoarc; b=ZeVhbRmaauqebr5ZiS7gW/zs5pmAsl/bgzXfeWMSPWz+qH+t5s8b+AjpjRXzl9UzRqeO02tzyTIxOglpchl0K4Bi13Xmg1YGCOMVl9mW9uXsdndIJh8m+XOiryUlsT8lzzukuSqcqMhQHn7/lCy4M7b3HRMdvSb6QMsGuAxc3pA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092668; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=WMxwKC3k3Et2xrqjxlIwuAKOgaRbu2qDK/80W+yIcCyiqgokPq/bgJ57FNkrd6CdSgoFA0J1QnjAAbpCeLQD+937c1yQNTpvkxtOdbkt0MzdVf5RidYOjUrzfoO7R8eUl+6GPeoTUsueO3v1cmLk/EXZZEhg0uF6K01GXPudDGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092668645753.7185511994767; Fri, 20 May 2022 17:24:28 -0700 (PDT) Received: from localhost ([::1]:43912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCux-0006om-24 for importer2@patchew.org; Fri, 20 May 2022 20:24:27 -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) 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) 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-Google-Smtp-Source: ABdhPJxDdwZhDcH5157a/EUtRaZlbYHqv40gC6aj5rw6a0hmHvHKAlzP65ZCLtBpoZSFiDYU8gRWhw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092669488100001 Content-Type: text/plain; charset="utf-8" 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 =20 +/* 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; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092264; cv=none; d=zohomail.com; s=zohoarc; b=O1863cU59D6xE5hR3UweqvWGtmF9ip74At5V2VHTw7qy/72SsOS/C+Q1MMGqzAxhbNn/Yf9MESLrOH9UyDgyH3x5XJg3fI5y+Xu51ifaLU2QJFhcxOUHc0TGmiTZZbdA0IIdoTQSxMCFZagULOfRyj59IfvX4xhdH0s1Z24SGXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092264; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t4HrU8aBsDXJmwDfJHBNtFc0i86kohNVifRpodC+Hr4=; b=Xwnumz5azwXEP6ENIgAB/gHL2XU40rsCgV4Tk+bu4GRxO8+TrfcrEFJR7BRkUIGiE1ssp+J0K3TvFuViCbWspw6Wj08KOALGVW/nijOrdGNCtpyLOLXFYF322p3ZToqq/dRUKBnwxW1qpR6fRB0cEAVamkyGNfzVNgXlb41/v8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165309226446729.207015973363582; Fri, 20 May 2022 17:17:44 -0700 (PDT) Received: from localhost ([::1]:55338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCoP-0003Na-UO for importer2@patchew.org; Fri, 20 May 2022 20:17:41 -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) 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) 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-Google-Smtp-Source: ABdhPJwcyuHR8aCxQTkJkNnT6J/s4GSCfGP8alWCMmPQhh2pV6ggc6u5EoCYq/jkcw6nTWmgrnyhBg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092264897100001 Content-Type: text/plain; charset="utf-8" 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 =3D be32_to_cpu(size); + /* The size is always stored in big-endian order, extract the valu= e. */ + uint64_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0); + ret =3D be64_to_cpu(size); } common_semi_cb(cs, ret, err); } --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093188; cv=none; d=zohomail.com; s=zohoarc; b=E+hl1k8CwBxIjxnMdinck3dt8T0Oo5b4Sl9ou2w2luOeRz765TAMEfyTVIIXF7hUiqqlOJ0F25aKdXSiDNRJPJ/HANGR2aJMbmRR3k3F55ECTa/am1V8XUWmC9xVHrROIBJPgF2ofTU8snzj292uyCrl5dhqxkHENKfTJtYkW3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093188; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ksJwiBOmhFBw0ef1995REJKMRag6w/MQtxaor/JS6fU=; b=EmQTXGGPIzLfw6gU45yP4ICxTtV6o7njL3MHonQsYPQrq/uVrc+5bx9nVrDTmGybumB3O4/z5YwyUntNHx3f6llxOYVfwi8ta51uc3RNQxEXV3tNmc2T+iZSh1BHaqeaBxCb5U4wRoBPvKrVNsYhqp18Zsvlg3kBScgz3Q6h3go= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165309318822673.95108795044541; Fri, 20 May 2022 17:33:08 -0700 (PDT) Received: from localhost ([::1]:60722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD3K-0001oj-Oi for importer2@patchew.org; Fri, 20 May 2022 20:33:06 -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) 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) 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-Google-Smtp-Source: ABdhPJyMlCGZRK7UqjzHcxtk+n8pqPK48vgKSAJ/OeaFF4Rw16FFmnsXjTbG/qcNpD9P85DFe3K15g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093188451100002 Content-Type: text/plain; charset="utf-8" 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 =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); } =20 +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} #endif /* TARGET_ARM */ =20 #ifdef TARGET_RISCV @@ -238,6 +242,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); } =20 +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) !=3D MXL_RV32; +} #endif =20 /* @@ -587,17 +595,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { * 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) !=3D MXL_RV32; -#else -#error un-handled architecture -#endif -} - =20 #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093462; cv=none; d=zohomail.com; s=zohoarc; b=a4eYSjyo7zB5sr7P5OwskfFEUyZfrsa9sWLIhzNZKZ4e0Q7Q97eaaspET0FZ9/zeNjtAPUl9jqHs8iq0e+91afdUjb7jBQHXB0tBQ3FVXO5ESNZ3HdpnH8SjW2S3TaG4LEcE6PEWA//50UKQ0Q8FemI5VNwx8mpRBGFvVeXALQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093462; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FOXW0QBVRQzvdj2/5WlXeWhliAMlds8KPficEgm5rdo=; b=KM0jGKWv6xXH2RxXD7F3hC2ZJ7hYKp3v4ZeAPhcJ0uiSvmCQgKhc1mZ3RmJ2gRfuBuemCRnTije3Mlc30dYOfWiRK4UXzD2WY6oPp0RKcd9804qezcx24kN9GrMazMawtlAQTr7KMyG00EjrxC0oWRHWbFS5PEE8IRcXzvldmXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093462684827.3635856803503; Fri, 20 May 2022 17:37:42 -0700 (PDT) Received: from localhost ([::1]:40536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD7k-0007Ry-Ik for importer2@patchew.org; Fri, 20 May 2022 20:37:40 -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) 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) 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-Google-Smtp-Source: ABdhPJyF3Bd8mcQNsI3lI/ybaCCX41u1r5ygyMyK1wa2piFexlE11b+GgqjwlDDn3ys3dbMh0Nnngw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093463568100001 Content-Type: text/plain; charset="utf-8" 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 =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} #endif /* TARGET_ARM */ =20 #ifdef TARGET_RISCV @@ -246,6 +253,13 @@ static inline bool is_64bit_semihosting(CPUArchState *= env) { return riscv_cpu_mxl(env) !=3D MXL_RV32; } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xSP]; +} #endif =20 /* @@ -301,31 +315,15 @@ static void common_semi_cb(CPUState *cs, target_ulong= ret, target_ulong err) common_semi_set_ret(cs, ret); } =20 +/* + * 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 =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - - if (is_a64(env)) { - sp =3D env->xregs[31]; - } else { - sp =3D env->regs[13]; - } -#endif -#ifdef TARGET_RISCV - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - - sp =3D env->gpr[xSP]; -#endif - + target_ulong sp =3D common_semi_stack_bottom(cs); return sp - 64; } =20 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093154; cv=none; d=zohomail.com; s=zohoarc; b=bQCCHnG/aJD1/94+kV0+51+C5o5ICDLxPnylWuKBATId0IvslgsMxQCj5VW7ORsbILYPeq4EybXaAxbLo4uRLly5BBP5vpGPxjukzFWiO+5aXQ6/gosUzzOontCIx2S3kRd1YRNLep3XpXRnqvcYuuFYE4ttbT6vcgnciCgwhlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WQ9CMUu8S8KNltjSwi0JIKZ7rxutJhSFkeyYpNk7QeY=; b=PnA36XAcPFhJfYkTFJz9CqfLFaProVXloVLMYAYgSZ19PJ7leoqAUBjxy4ILd5doVkJXjiOJxm7uGDVIGsfmIcjDKMa4FxDv7C2QpuCL/rmcFZy+kr+Zm9e+rcGdKbtpoX8KUsJf9oBWV6geRzYjSXnUgg4CH50GCuCuXmBrGTA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093154862634.6288257653324; Fri, 20 May 2022 17:32:34 -0700 (PDT) Received: from localhost ([::1]:60038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD2m-0001Kl-C4 for importer2@patchew.org; Fri, 20 May 2022 20:32:32 -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) 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) 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-Google-Smtp-Source: ABdhPJzbrKdwBYzJ5xmtemZAMIzJbpdWPUjZ9JEYfVPdc2aESBur5+w8xoru4YlTb4tSNqYJbP+auw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093156367100001 Content-Type: text/plain; charset="utf-8" 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(CP= UState *cs) CPUARMState *env =3D &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 */ =20 #ifdef TARGET_RISCV @@ -260,6 +266,11 @@ static inline target_ulong common_semi_stack_bottom(CP= UState *cs) CPURISCVState *env =3D &cpu->env; return env->gpr[xSP]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} #endif =20 /* @@ -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); --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093923; cv=none; d=zohomail.com; s=zohoarc; b=CvPptl8J74DDB+xuiQdej73JaEUVyXwL3ASzPakBhrHCcQn+/pUCQ9ltLcm4Q4Db/tSgXxYTLaqlm74DCwNpjC4ry1A36K9gBtg70z2XyEeo5Hew927YgNaEX3XDLQQAeejShID6eSqf7yW/96SEekcEG5dzsTqr0kMe4VtW46w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093923; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fG9arG1tn4b444K5zf/g1JuzGuQmuRsUj+aiYfge+3E=; b=h+DPhrmdGc5cD+JNm18E8YWUbvmVPpUWpAVom0I/BRmATz69b9OEI1LliLpkOqhk21TZvsG3SQC07mwvbbiDO+nV6RMjKOyZuKXRPtr4oZcbx0OeJ58ZX5bzn2cuBXBEjHPegX32hTNb4BsER37o9UZltSV2tKI2gz9mxaasE1I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093923116558.1766000242341; Fri, 20 May 2022 17:45:23 -0700 (PDT) Received: from localhost ([::1]:50560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDFC-00060O-3X for importer2@patchew.org; Fri, 20 May 2022 20:45:22 -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) 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) 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-Google-Smtp-Source: ABdhPJxMdmB92/j1yrlVXY8CBcPW8KZtKAgeuiR7GQjw9HPKD+Rnng+Ocgy/sGoWIydJHHDL9d01vg== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093923755100001 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-targe= t.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 =3D ARM_CPU(cs); + CPUARMState *env =3D &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 =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + if (is_a64(env)) { + env->xregs[0] =3D ret; + } else { + env->regs[0] =3D ret; + } +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D 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 =3D ARM_CPU(cs); + CPUARMState *env =3D &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-t= arget.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 =C2=A9 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 =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + env->gpr[xA0] =3D ret; +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) !=3D MXL_RV32; +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &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 =20 @@ -182,96 +179,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) =20 #endif =20 -#ifdef TARGET_ARM -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &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 =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - if (is_a64(env)) { - env->xregs[0] =3D ret; - } else { - env->regs[0] =3D ret; - } -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr =3D=3D 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 =3D ARM_CPU(cs); - CPUARMState *env =3D &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 =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - return env->gpr[xA0 + argno]; -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - env->gpr[xA0] =3D ret; -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return riscv_cpu_mxl(env) !=3D MXL_RV32; -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - return env->gpr[xSP]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - return true; -} -#endif +#include "common-semi-target.h" =20 /* * 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; =20 - (void) env; /* Used implicitly by arm lock_user macro */ nr =3D common_semi_arg(cs, 0) & 0xffffffffU; args =3D common_semi_arg(cs, 1); =20 @@ -728,12 +635,12 @@ void do_common_semihosting(CPUState *cs) break; =20 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; =20 case TARGET_SYS_WRITE0: - ret =3D qemu_semihosting_console_outs(cs->env_ptr, args); + ret =3D qemu_semihosting_console_outs(env, args); common_semi_set_ret(cs, ret); break; =20 @@ -764,7 +671,7 @@ void do_common_semihosting(CPUState *cs) break; =20 case TARGET_SYS_READC: - ret =3D qemu_semihosting_console_inc(cs->env_ptr); + ret =3D qemu_semihosting_console_inc(env); common_semi_set_ret(cs, ret); break; =20 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094083; cv=none; d=zohomail.com; s=zohoarc; b=G1/qSKx1nX8ffEb4U8+5PqQPOixTY/h1L4yEzUQnTu9p2DZFQ/fiygS1QMDvKlJjhTvTbzMIeXtCGNgfbvG88OF3ysrfZ2/wetFK473QE3gdLS+rfnf3FcJrP9BAAqoEo7OO27ByvnC5cUWYFMGUV6Yqw1BdPFEPsykEuIRwy6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Am6ZQ75YNAJ1iQQvd/m4L79xzkPVsPgjLxYKlB9VWSI=; b=kkxcGzAQoOxE+gbRCx7+0rrFlhy69BM52+/gnsH7jIvPZz2LSpfVhuFdXBy2pvcbh6nS+SBMYp9D415wxQu42cxjezHMUouFXVWLo/ivoRxl6g7+METy7aE9WvvczU98/OiWWfVoVNqE79+8U7ha7LbET5et1N4mc7dEz56pjDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094083970595.4549724693401; Fri, 20 May 2022 17:48:03 -0700 (PDT) Received: from localhost ([::1]:55880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDHm-0001W8-Su for importer2@patchew.org; Fri, 20 May 2022 20:48:02 -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) 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) 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-Google-Smtp-Source: ABdhPJxDgSItzVY9cJUBB2q8+Os5Kz1ZyfHHcwfxFRhDwLPMdS1WThl0VakhpvQ0ugISMN2GeOFQyw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094084589100001 Content-Type: text/plain; charset="utf-8" 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) =20 #include "common-semi-target.h" =20 +/* + * 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[] =3D { }, }; =20 -/* - * 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. * --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092093; cv=none; d=zohomail.com; s=zohoarc; b=Ybiij2T/T6gY3a/iOdDNKus13yRMdVlh29wqWciw5rCSCqFkvzkx5ISvWz/Wav/YQtmF/9Xcg8UOYND4esoeFOaXp33dbfTo5JsbnQOUHG9UvKjI51YFBSnUzN1ck9yLnk5nhfAX1QFBNfCnRUYAsr/ykYhK9s1AerXwuZQOQ9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092093; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6hAoVCK1sUE0dO/zjjldEsyPEFjDE5oCQFS4JmN/6DY=; b=UrdC7KxLV+UmPsnYjOjTQr4L7VT3s3P95OeSaUJbRKkxa83PFmo2xSszbRSYMOC2ml6hGQE/eb80lIA1h35A2FibdLSdjKhE0yh99359Yb4hifItf4lE0UdMRcB4bQ00O08WkQRDdEh6f9R6x05n5L2kH7tavTC2ygULy81WkE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092093136708.2509447132153; Fri, 20 May 2022 17:14:53 -0700 (PDT) Received: from localhost ([::1]:49856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsClg-00084Z-35 for importer2@patchew.org; Fri, 20 May 2022 20:14:52 -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) 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) 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-Google-Smtp-Source: ABdhPJxZ4D7LNjxznGz2oZjW21+tPsBt7mYwAp7169HUwnd3UV0OPfB9Cz6Nnxj/hzJILQbZei9CqQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092094086100001 Content-Type: text/plain; charset="utf-8" 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" =20 #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -98,21 +99,6 @@ static int gdb_open_modeflags[12] =3D { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY }; =20 -static int open_modeflags[12] =3D { - 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 =20 /** @@ -284,20 +270,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, ta= rget_ulong err) common_semi_cb(cs, ret, err); } =20 -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 =3D 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 =3D alloc_guestfd(); - gdb_do_syscall(common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - break; } else { - hostfd =3D open(s, open_modeflags[arg1], 0644); - if (hostfd < 0) { - ret =3D -1; - err =3D errno; - } else { - ret =3D 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 =20 static GArray *guestfd_array; =20 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 tl= en) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char c; + + if (tlen =3D=3D 0) { + ssize_t slen =3D target_strlen(str); + + if (slen < 0) { + return -GDB_EFAULT; + } + if (slen >=3D 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 !=3D 0) { + return -GDB_EINVAL; + } + return tlen; +} + +static int validate_lock_user_string(char **pstr, CPUState *cs, + target_ulong tstr, target_ulong tlen) +{ + int ret =3D validate_strlen(cs, tstr, tlen); + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *str =3D NULL; + + if (ret > 0) { + str =3D lock_user(VERIFY_READ, tstr, ret, true); + ret =3D str ? 0 : -GDB_EFAULT; + } + *pstr =3D 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 =3D alloc_guestfd(); + associate_guestfd(guestfd, ret); + ret =3D 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 =3D validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_open_complete =3D 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 =3D cs->env_ptr; + char *p; + int ret, host_flags; + + ret =3D 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 =3D O_WRONLY; + } else if (gdb_flags & GDB_O_RDWR) { + host_flags =3D O_RDWR; + } else { + host_flags =3D O_RDONLY; + } + if (gdb_flags & GDB_O_CREAT) { + host_flags |=3D O_CREAT; + } + if (gdb_flags & GDB_O_TRUNC) { + host_flags |=3D O_TRUNC; + } + if (gdb_flags & GDB_O_EXCL) { + host_flags |=3D O_EXCL; + } + + ret =3D open(p, host_flags, mode); + if (ret < 0) { + complete(cs, -1, errno_for_gdb()); + } else { + int guestfd =3D 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', )) =20 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: f= iles( --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093604; cv=none; d=zohomail.com; s=zohoarc; b=LzX5FhFd7OgpewZ0AwEQW/UAAbBxitisogBlNVrKg5tFdxausbtEY4Td1ZKF+pxGsDF2ucBGh8qdgYcBRPY0VZjvcKtCNAADcvsOtpgEEe41QziTcQYsLZafYgEonT12Lwy29nagLAj8lrTXzJbEJYN5yLSAncym3DljwHxaZW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093604; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Ent/aGrN0lvBHhuu6zgeU6QjQbHaFQoY2hP0wODKxw=; b=WkVD9g2B2xCbQ+JDi7DEw+QeKhsynokhmJxJS7BdqrU8/lvR61LKjSxXcAfLNj9xba/Qau0E0ENRbsWoif0N0jHx5fCGvMHsrHkRUEfhncm2jN5n50w5LnFxsm7wVu7Tb66aqlOfUMg1TF0dyfOQUs0d6DOKkYican/+/ovz1JU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093603999712.144562452294; Fri, 20 May 2022 17:40:03 -0700 (PDT) Received: from localhost ([::1]:46152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDA2-0002rE-W0 for importer2@patchew.org; Fri, 20 May 2022 20:40:03 -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) 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) 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-Google-Smtp-Source: ABdhPJyc0BIEB5raRlXBTcQ+zVhwjxXh4DsmbapkwUaFMnglejbV44DmW0ycbOEphYVlduqmYb9q7w== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093606141100001 Content-Type: text/plain; charset="utf-8" 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); =20 +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, tar= get_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); =20 -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 =3D=3D STDIN_FILENO || - gf->hostfd =3D=3D STDOUT_FILENO || - gf->hostfd =3D=3D STDERR_FILENO) { - ret =3D 0; - } else { - ret =3D 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) } } =20 -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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -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) } =20 typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -478,7 +448,6 @@ typedef struct GuestFDFunctions { =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .closefn =3D host_closefn, .writefn =3D host_writefn, .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, @@ -486,7 +455,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .closefn =3D gdb_closefn, .writefn =3D gdb_writefn, .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, @@ -494,7 +462,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .closefn =3D staticfile_closefn, .writefn =3D staticfile_writefn, .readfn =3D staticfile_readfn, .isattyfn =3D staticfile_isattyfn, @@ -585,13 +552,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_CLOSE: GET_ARG(0); - - gf =3D 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; =20 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; } =20 +static void do_dealloc_guestfd(GuestFD *gf) +{ + gf->type =3D 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 =3D do_get_guestfd(guestfd); =20 assert(gf); - gf->type =3D 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_complet= e_cb complete, fname, len, (target_ulong)gdb_flags, (target_ulong)mode= ); } =20 +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_comple= te_cb complete, unlock_user(p, fname, 0); } =20 +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 !=3D STDIN_FILENO && + gf->hostfd !=3D STDOUT_FILENO && + gf->hostfd !=3D 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_compl= ete_cb complete, host_open(cs, complete, fname, fname_len, gdb_flags, mode); } } + +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, in= t fd) +{ + GuestFD *gf =3D 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); +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092483; cv=none; d=zohomail.com; s=zohoarc; b=CLwglS2cqsRnb+Nuss987sbGeaGYsKGmstP+RjIgnjzhaA+8Vxcpnf5rJwo9kfWdDISgVyEfbWU8y4eP2LRhVH4UqdaNhWT3C1mC6TYOiAwO8k40MdH/88ZIR4zqxE3cvPJt91t81mO8CdLRBX/riKt9TfFHht9q037zYiaYmAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092483; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ei4oX9gqsxpF/TVtJUIb1bHkWuBeEJNDM94QCzd9LJ4=; b=nZj9m9Ua5/s+RS9P6C3ITzUvWtW8+2GTwIm4ulCoFN8fBktT8vuSMiMGN4pvPNIpe5fzzWpWPHVGeef1wCakSxpOg5EXEKNW1Y8v17upaKQXKv4AuHOhbT1C0e0m2Cx5ryPw1WHen6AxE1xCAayqqqOgbY4Yg2Gn+VSLIq0I9g8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092483213426.72349850541514; Fri, 20 May 2022 17:21:23 -0700 (PDT) Received: from localhost ([::1]:35448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCry-0000nw-5J for importer2@patchew.org; Fri, 20 May 2022 20:21:22 -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) 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) 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-Google-Smtp-Source: ABdhPJzUxZBOS17vkz146oBeObUDvQ6Qu4s0vaf2aUnJi1GEFdIfH/Bxo9lcMV/6F60k5AQeZ3H/MQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092484752100001 Content-Type: text/plain; charset="utf-8" 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). */ =20 +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_complet= e_cb complete, void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); =20 +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 r= et, target_ulong err) target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: - case TARGET_SYS_READ: ret =3D 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); } =20 +/* + * SYS_READ and SYS_WRITE always return the number of bytes not read/writt= en. + * 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 =3D cs->env_ptr; + target_ulong args =3D common_semi_arg(cs, 1); + target_ulong arg2; + GET_ARG(2); + + if (err) { + do_fault: + ret =3D 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, tar= get_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); } =20 -static void host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t ret =3D 0; - char *s =3D lock_user(VERIFY_WRITE, buf, len, 0); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - do { - ret =3D read(gf->hostfd, s, len); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); - unlock_user(s, buf, len); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 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); } =20 -static void gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len =3D 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); } =20 -static void staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t i =3D 0; - char *s; - - (void) env; /* Used in arm softmmu lock_user implicitly */ - s =3D lock_user(VERIFY_WRITE, buf, len, 0); - if (s) { - for (i =3D 0; i < len; i++) { - if (gf->staticfile.off >=3D gf->staticfile.len) { - break; - } - s[i] =3D 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) =20 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[] =3D { [GuestFDHost] =3D { .writefn =3D host_writefn, - .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { .writefn =3D gdb_writefn, - .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { .writefn =3D staticfile_writefn, - .readfn =3D staticfile_readfn, .isattyfn =3D staticfile_isattyfn, .seekfn =3D staticfile_seekfn, .flenfn =3D staticfile_flenfn, @@ -582,13 +543,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len =3D arg2; - - gf =3D 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; =20 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_comple= te_cb complete, gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); } =20 +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_compl= ete_cb complete, } } =20 +static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + void *ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, GDB_EFAULT); + return; + } + do { + ret =3D read(gf->hostfd, ptr, len); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + if (ret =3D=3D -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 le= n) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + target_ulong rest =3D gf->staticfile.len - gf->staticfile.off; + void *ptr; + + if (len > rest) { + len =3D rest; + } + ptr =3D 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 +=3D 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_comp= lete_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 =3D get_guestfd(fd); + + if (gf) { + semihost_sys_read_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, GDB_EBADF); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653091936; cv=none; d=zohomail.com; s=zohoarc; b=W8HOpLARh80Lz06s46AQEPrj5Q1ptRWZGuQHsxCfyTSVQaZ1LNHDTOTzWKlqnOhehu5cxjKcDeed5zHTuraDDxp91rzPYX3rEQJ42VaqWgEusiDg0A5oZ8avFXajytDYPXs2gTaHQx5FUTzgMBRjDp9Xe/w2bQcrpy40Jg9eZvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653091936; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tgVRADqR9B5grnNVu8mA4b/Up+ANot4pk44Zo7iuCRQ=; b=bRzrr5cWzYFP9E5VBO2BuDxgYpkuCXNhLr2tSMPsjHMTC6PocDya/9esY8IgLxNV/cPwa2AtjLZalu2gr2VuE2w954hrtmuML5rlPTnpaJDC+kGHVu09YbZAnw3JbT+VkwD/bQIQFQ/gndnAcRuduYHnnCL6UjhCmmcl6tswq30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653091936817337.9841520817507; Fri, 20 May 2022 17:12:16 -0700 (PDT) Received: from localhost ([::1]:41296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCj9-0002Lv-O3 for importer2@patchew.org; Fri, 20 May 2022 20:12:15 -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) 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) 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-Google-Smtp-Source: ABdhPJxoe5+EG8HWB4omjZ/fkC2IIbFqn8l3jXjTLdrpsa+gQCA1C0QNm7rwkW8nxt5hloeeSbcYIA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653091937339100001 Content-Type: text/plain; charset="utf-8" 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_complet= e_cb complete, void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len); =20 +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 } =20 -static target_ulong common_semi_syscall_len; - static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { if (err) { @@ -230,9 +228,6 @@ static void common_semi_cb(CPUState *cs, target_ulong r= et, target_ulong err) /* Fixup syscalls that use nonstardard return conventions. */ target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { - case TARGET_SYS_WRITE: - ret =3D common_semi_syscall_len - ret; - break; case TARGET_SYS_SEEK: ret =3D 0; break; @@ -294,30 +289,10 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, t= arget_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); =20 -static void host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t ret =3D 0; - char *s =3D lock_user(VERIFY_READ, buf, len, 1); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - ret =3D write(gf->hostfd, s, len); - unlock_user(s, buf, 0); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 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) } } =20 -static void gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len =3D 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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -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) } =20 typedef struct GuestFDFunctions { - sys_writefn *writefn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -412,19 +372,16 @@ typedef struct GuestFDFunctions { =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .writefn =3D host_writefn, .isattyfn =3D host_isattyfn, .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .writefn =3D gdb_writefn, .isattyfn =3D gdb_isattyfn, .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .writefn =3D staticfile_writefn, .isattyfn =3D staticfile_isattyfn, .seekfn =3D staticfile_seekfn, .flenfn =3D 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; =20 @@ -530,13 +486,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len =3D arg2; - - gf =3D 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; =20 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_complet= e_cb complete, (target_ulong)gf->hostfd, buf, len); } =20 +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_comple= te_cb complete, } } =20 +static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + void *ptr =3D lock_user(VERIFY_READ, buf, len, 1); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, GDB_EFAULT); + return; + } + ret =3D write(gf->hostfd, ptr, len); + complete(cs, ret, ret =3D=3D -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_compl= ete_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 =3D get_guestfd(fd); + + if (gf) { + semihost_sys_write_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, GDB_EBADF); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092348644555.0646877361194; Fri, 20 May 2022 17:19:08 -0700 (PDT) Received: from localhost ([::1]:58406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCpn-0005Xn-7B for importer2@patchew.org; Fri, 20 May 2022 20:19:07 -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) 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) 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-Google-Smtp-Source: ABdhPJxEee9ozPoKfjl2XMmLv5Bjkyt3YVVzHITXGxnnckF2T+MYTA+9juYNRcvd/9SuK0N9I7CoGA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1653092350639100001 Content-Type: text/plain; charset="utf-8" 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_comp= lete_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 ssiz= e_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 =3D 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_compl= ete_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 ssiz= e_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 =3D INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_write(cs, complete, gf, buf, len); --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092491; cv=none; d=zohomail.com; s=zohoarc; b=JGfk0R6RZRAtmnqQ+tUcrCQClzS9kZz65O8kjHrhQpIQhluc/w5Y6XLAFhjdEbYtsF9ooPNtIJoYU307WO+aL+98bOHHhEzH7+L0NVPFnBE96Gx2n9nqRa3sr3Vj5AfU24LMjTWBWF5NM6X0M7hvtZQ3bxEGJym/1e3wyGKFgPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092491; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ISYOLSXdDLADD2AwvTBEZ0VMRY6JVLGtKafBn7ec4+s=; b=fG2uw+kMvtCfGiTMny5usSQzOJnINpMPW4ar2HSubXVaB3tdWstRpRh0AFM0SPXKigZjhaIs86BYPSR1ayuRkUth9+onf3j8X2RQSLZcHohr9fDgC9X7d1g8y4EW0l1dLA0YsYYhDjvijTiPGMUJXpZaQSr5+OxJ+Tdgp4r1zzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092491668308.25549281899885; Fri, 20 May 2022 17:21:31 -0700 (PDT) Received: from localhost ([::1]:35648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCs1-0000ve-Ms for importer2@patchew.org; Fri, 20 May 2022 20:21:26 -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) 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) 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-Google-Smtp-Source: ABdhPJw3pcCEU/gdRxaoN7QyK/6rgdNYx/AjJ2cvZg23kZuUkflQfwpqNl5XvWt+kKFbfkD/CVQumw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092492755100002 Content-Type: text/plain; charset="utf-8" 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 =20 +/* 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_complet= e_cb complete, void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len= ); =20 +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 =3D err; #endif - } else { - /* Fixup syscalls that use nonstardard return conventions. */ - target_ulong reg0 =3D common_semi_arg(cs, 0); - switch (reg0) { - case TARGET_SYS_SEEK: - ret =3D 0; - break; - default: - break; - } } common_semi_set_ret(cs, ret); } @@ -257,6 +247,18 @@ static void common_semi_rw_cb(CPUState *cs, target_ulo= ng ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } =20 +/* + * 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 =3D 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, tar= get_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); =20 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); } =20 -static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - off_t ret =3D lseek(gf->hostfd, offset, SEEK_SET); - common_semi_cb(cs, ret, ret =3D=3D -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); } =20 -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); } =20 -static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offs= et) -{ - gf->staticfile.off =3D 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) =20 typedef struct GuestFDFunctions { sys_isattyfn *isattyfn; - sys_seekfn *seekfn; sys_flenfn *flenfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { .isattyfn =3D host_isattyfn, - .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { .isattyfn =3D gdb_isattyfn, - .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { .isattyfn =3D staticfile_isattyfn, - .seekfn =3D staticfile_seekfn, .flenfn =3D staticfile_flenfn, }, }; @@ -519,12 +499,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); - - gf =3D 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_S= ET); break; =20 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_comple= te_cb complete, (target_ulong)gf->hostfd, buf, len); } =20 +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_compl= ete_cb complete, unlock_user(ptr, buf, 0); } =20 +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 !=3D SEEK_SET); + QEMU_BUILD_BUG_ON(GDB_SEEK_CUR !=3D SEEK_CUR); + QEMU_BUILD_BUG_ON(GDB_SEEK_END !=3D SEEK_END); + + off_t ret =3D off; + int err =3D 0; + + if (ret =3D=3D off) { + ret =3D lseek(gf->hostfd, ret, whence); + if (ret =3D=3D -1) { + err =3D errno_for_gdb(); + } + } else { + ret =3D -1; + err =3D 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); } =20 +static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complet= e, + GuestFD *gf, int64_t off, int gdb_whence) +{ + int64_t ret; + + switch (gdb_whence) { + case GDB_SEEK_SET: + ret =3D off; + break; + case GDB_SEEK_CUR: + ret =3D gf->staticfile.off + off; + break; + case GDB_SEEK_END: + ret =3D gf->staticfile.len - off; + break; + default: + ret =3D -1; + break; + } + if (ret >=3D 0 && ret <=3D gf->staticfile.len) { + gf->staticfile.off =3D 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_comp= lete_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 =3D 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(); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653095084; cv=none; d=zohomail.com; s=zohoarc; b=EsjN8dd2j8bWC6/vwaGG3yld2OYyJnjcfqS+TxRSderXRVOBvChh6Qf81pJ5rl+ElRPo5w0VRaXtJpn77QnEr6t3/HTN5E+8JFqLvf6x9cP7BTEHTCG5kyYm6JIXqBRrlnyBwkK0HeaCcTxuLz35tj1tTof08252325M+QEtbeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653095084; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iVi2WL9LYbp1NIow410Rcdf8IJcyVNGeWO58E9XwFhI=; b=eJ7OX8DlxMIEOMQZyik6jObbXcAW9UPcYHkc0MF3y/7J1opR581sfe9HRYFrRfNo+VG8xCb/m76OEDewXC4gpbfUFcfPYFQo4YeHyLMRyr5frxFs9LxveambhmmGCadKRFUFDk1OGEMfdSoFLoHZ7SHgYR5j+7uttBGJ5vU7MtI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653095084172688.9339892314019; Fri, 20 May 2022 18:04:44 -0700 (PDT) Received: from localhost ([::1]:47718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDXv-0007Of-6z for importer2@patchew.org; Fri, 20 May 2022 21:04:43 -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) 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) 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-Google-Smtp-Source: ABdhPJwyNbkg3jl3RWzjilnvlhLYYJ6jKP/Sqam1YayCWCTyLxSmSSq/gYulh+jzvxwycqKaYnXLyA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653095085803100001 Content-Type: text/plain; charset="utf-8" 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 =20 /* 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_comp= lete_cb complete, void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); =20 +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, ta= rget_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); =20 -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) } } =20 -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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -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); } =20 typedef struct GuestFDFunctions { - sys_isattyfn *isattyfn; sys_flenfn *flenfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .isattyfn =3D host_isattyfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .isattyfn =3D gdb_isattyfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .isattyfn =3D staticfile_isattyfn, .flenfn =3D staticfile_flenfn, }, }; @@ -488,12 +468,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_ISTTY: GET_ARG(0); - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].isattyfn(cs, gf); + semihost_sys_isatty(cs, common_semi_cb, arg0); break; =20 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_comple= te_cb complete, (target_ulong)gf->hostfd, off, (target_ulong)gdb_whence= ); } =20 +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_compl= ete_cb complete, complete(cs, ret, err); } =20 +static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + int ret =3D 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_comp= lete_cb complete, g_assert_not_reached(); } } + +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, i= nt fd) +{ + GuestFD *gf =3D 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(); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094708; cv=none; d=zohomail.com; s=zohoarc; b=nFej/3YXDqEYeB0vqlR8BhRA7Zj3i87K7fXHj1v1ysnfwGM35xpfFO7VC8+swOIbaKXMwoa+Oflln4IZ+IivyFFXfDudqy9PB/JH0I39rCzJa24ezzpg8CkOLnkCXylD1QF9dOSY7nOlL5C5U2bn5xaihT2NwxFciNJBxLt0kjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094708; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TzUwl9qms3llKSXLrofbP99q2dV9evxhKXHM3ias5fg=; b=CzEnbc6xuYAkLijSVDzm07hubWU+yGMOfkaQPngfsSJW2eT7fhXr2S9iI9rCPZM39iDHmxJq+0pUBSXdR8gW9arzao79hPVXV18p1XJz6GC4sFMGUDdzpAZOkz83JArkFMGddL2sT28Oy4uMQyi1CO0JVV0Q0DXgwArFDE/ITzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094708148396.13228035663303; Fri, 20 May 2022 17:58:28 -0700 (PDT) Received: from localhost ([::1]:41108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDRr-0002c2-2f for importer2@patchew.org; Fri, 20 May 2022 20:58:27 -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) 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) 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-Google-Smtp-Source: ABdhPJxO/URDVxpNwLK4jHiF7pAcTt7O1Qek7WLUCWoF8njnI875kjKHk5FOaqGWnS05YbJAL1Tc2A== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094708479100001 Content-Type: text/plain; charset="utf-8" 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 =20 /* 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_complet= e_cb complete, void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd); =20 +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) } =20 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 valu= e. */ uint64_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + - offsetof(struct gdb_stat, gdb_st_size), - &size, 8, 0); - ret =3D 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 =3D -1, err =3D GDB_EFAULT; + } else { + size =3D be64_to_cpu(size); + if (ret !=3D size) { + ret =3D -1, err =3D GDB_EOVERFLOW; + } + } } common_semi_cb(cs, ret, err); } =20 -/* - * 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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -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[] =3D { - [GuestFDHost] =3D { - .flenfn =3D host_flenfn, - }, - [GuestFDGDB] =3D { - .flenfn =3D gdb_flenfn, - }, - [GuestFDStatic] =3D { - .flenfn =3D 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; =20 nr =3D common_semi_arg(cs, 0) & 0xffffffffU; @@ -479,12 +438,8 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_FLEN: GET_ARG(0); - - gf =3D 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; =20 case TARGET_SYS_TMPNAM: @@ -806,9 +761,6 @@ void do_common_semihosting(CPUState *cs) cpu_dump_state(cs, stderr, 0); abort(); =20 - 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_compl= ete_cb complete, gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); } =20 +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_comp= lete_cb complete, complete(cs, ret, ret ? 0 : errno_for_gdb()); } =20 +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, } } =20 +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_com= plete_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 =3D 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(); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653095172; cv=none; d=zohomail.com; s=zohoarc; b=fCbTRl2fJnMpGX+H0pwEh0kj6HfbVRJ6j4qrJdpIS5rhnSMYnMAlcyoh75gXt9u/PWM4yy9pvF5k0vDVJkYkjjCkdxUrwWlEKiY5PlZZSBCAf+S14mv8i9uWh3R+Z4BOhdw2tIqKJ8orjDZUIJaYy72DESl0nZHXZApOReDXJvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653095172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LN6XpMNK1B7AUGbjroKLaQGdSs8x64FTUaroN/g+tus=; b=Z4bAzW1RMxZHbztDNYE3uq0y93aJK3L5HHcO3N92uEGdMWdNURFRteYxgJTTmDGSSXqk4SAKrYREQbVh+jSD7C8dUPXOcJf3r1cJQac7uMQIuApieC9qq9v5afKM6P2rmN1EJUBnrP0Tiu30g27M1CP3CjRRXXsVJUYEdeW61IQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653095172598128.01618688984365; Fri, 20 May 2022 18:06:12 -0700 (PDT) Received: from localhost ([::1]:49952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDZL-0000em-FH for importer2@patchew.org; Fri, 20 May 2022 21:06:11 -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) 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) 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-Google-Smtp-Source: ABdhPJxdFSi08P/ifQ/qDxVOsLm+4JHpWqWcDmuhRJRj3RsaPMACqDgpzOhw3jXahdCZbIDmTIDtzw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653095174211100001 Content-Type: text/plain; charset="utf-8" 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); =20 +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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret =3D 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; =20 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_comple= te_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr= ); } =20 +static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + int len =3D 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_comple= te_cb complete, } } =20 +static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *p; + int ret; + + ret =3D validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D 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_compl= ete_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); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092562; cv=none; d=zohomail.com; s=zohoarc; b=DLqmjFoRt8ctgNO4m30nwBqhvPlASc9pFvxW3tnqSrGb1V+yI87wULYRPXqdPkLxqDO0LV0kieM31EN1bdyMs4j8J5tRZKhS0B1YM4HhncGCjmYcIlmdrgY5X6XcmJ2DeBeXnI3VtSoMTltC1JIswmqFv/etzBlzo7KHqWUpCDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092562; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=enxou4yoMT/vOpcisCbCyqvDmHRkcHgrMJIOlZ4t5Wk=; b=cYqhzJ9btIoeD631QwEgHeRO1Sb6rmqyVja0hyQcRw95811xQxWv7APr9ejV3LGzpkR+h8sYwcFRn2LxL5E1ssIMwNOd2+yYwSASXnZszXEMcD4e0znK+5hcRle/vn6MuQUpbLFNC8rdD/Ko82vmrnfOjq6plZ/vBztoJN5CBL4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092562852464.2579475817729; Fri, 20 May 2022 17:22:42 -0700 (PDT) Received: from localhost ([::1]:38366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCtF-0002tF-PC for importer2@patchew.org; Fri, 20 May 2022 20:22:41 -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) 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) 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-Google-Smtp-Source: ABdhPJxvZC96zAvy60Qq22DmHEtVXEJBGVdQv//d0dxzFFbe7bfpyXSIgKvrjYgUpQ/A5lAfVI/gFA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092564958100001 Content-Type: text/plain; charset="utf-8" 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); =20 +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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 =3D lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret =3D 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; =20 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_compl= ete_cb complete, gdb_do_syscall(complete, "unlink,%s", fname, len); } =20 +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 =3D validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen =3D 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_comp= lete_cb complete, unlock_user(p, fname, 0); } =20 +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 =3D cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret =3D validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret =3D validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret =3D 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_com= plete_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); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094406; cv=none; d=zohomail.com; s=zohoarc; b=J/xLYj1ggZTc6H41mzKFotfmAIMSuKSiyrT5IdhgOeRD5/pua7Xahq6BMx+MggIwpVVVPo+KY50O/hoZ65XkfuUbmXURIXOcoZ2Iio6ysAzY4NM7tbzzGjVzwAK36wYbGSBLv4MqmxWLEoAC1RqSt38WMcCygqT3p+fKG8k+i5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094406; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y40sF2c9DbUtXmV2ndKv/KtYmK5ILHYoXK/oAxIJpeU=; b=LgHh/jhVE4TvrkiKXbN4spDatd6G/fWf0DnmsdSbNg614t3jUEEtYYEZboiGMMQEajtDEnN1aMDaH+vnfnGAz3NMmwSEFAoxnGy42JpFDffVE6jNQtDOPPrDzuvDaIglJm46gUnRJURl7d7cni9k+gqBynLSVOl4EcWmACkn1S4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094406210868.1412503844891; Fri, 20 May 2022 17:53:26 -0700 (PDT) Received: from localhost ([::1]:34586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDMz-0006QE-6I for importer2@patchew.org; Fri, 20 May 2022 20:53:25 -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) 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) 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-Google-Smtp-Source: ABdhPJxexglpYGimk9fvX41NRcNN5WMikggNzXmZ088/n2skEbCOssKZHU6lbbBfTRN+SQKd9Ww6Pw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094407428100001 Content-Type: text/plain; charset="utf-8" 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_comple= te_cb complete, target_ulong oname, target_ulong oname_len, target_ulong nname, target_ulong nname_len); =20 +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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret =3D system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; =20 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_compl= ete_cb complete, gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); } =20 +static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + int len =3D 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_comp= lete_cb complete, unlock_user(nstr, nname, 0); } =20 +static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *p; + int ret; + + ret =3D validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D system(p); + complete(cs, ret, ret =3D=3D -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_com= plete_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); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092775; cv=none; d=zohomail.com; s=zohoarc; b=c4tRhM1k4uQwxf/Q5zzR6pxBPkEKEXfYEuFC7v0JshEeIQ306egM743gx0h4lkdIIUgJcECb+lI1dW959HzohK789i2HsBQ5nQxHS4MsH0ZKByoROG2QatvZoboKYwBuAnZLzLtWMswgwGMrDnfyWc7U/nz8TYxU1xxNOXyRhJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092775; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=fIVAmz+K1PrAOJddo0HGHEsU4pac2w783p7Xcj1N+mYrlWz2YddIw9CSK2xcyFsGmX94o9hbH8xyK/8h3h4SfJnmukkGvOMCB5tz0ez2LJvBi8gh8PLFjtF2zNNxHxbWROUO1Yrazpak6OjiHdzo5LTckbl95GKxfNlSlGMa+NU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092774945533.4310649673912; Fri, 20 May 2022 17:26:14 -0700 (PDT) Received: from localhost ([::1]:46624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCwf-0000HS-Lw for importer2@patchew.org; Fri, 20 May 2022 20:26:13 -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) 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) 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-Google-Smtp-Source: ABdhPJwLm3iT1rAfdW0j9ZxuKTnieDokU7L0fsQaa9oxhuwk5l+GvHedPxf9z/7dySFycVme532tkA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092776284100001 Content-Type: text/plain; charset="utf-8" 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_complet= e_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); =20 +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); =20 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 } =20 +/* + * 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 =3D cs->env_ptr; + struct gdb_stat *p; + + if (s->st_dev !=3D (uint32_t)s->st_dev || + s->st_ino !=3D (uint32_t)s->st_ino) { + return -GDB_EOVERFLOW; + } + + p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -GDB_EFAULT; + } + + p->gdb_st_dev =3D cpu_to_be32(s->st_dev); + p->gdb_st_ino =3D cpu_to_be32(s->st_ino); + p->gdb_st_mode =3D cpu_to_be32(s->st_mode); + p->gdb_st_nlink =3D cpu_to_be32(s->st_nlink); + p->gdb_st_uid =3D cpu_to_be32(s->st_uid); + p->gdb_st_gid =3D cpu_to_be32(s->st_gid); + p->gdb_st_rdev =3D cpu_to_be32(s->st_rdev); + p->gdb_st_size =3D cpu_to_be64(s->st_size); +#ifdef _WIN32 + /* Windows stat is missing some fields. */ + p->gdb_st_blksize =3D 0; + p->gdb_st_blocks =3D 0; +#else + p->gdb_st_blksize =3D cpu_to_be64(s->st_blksize); + p->gdb_st_blocks =3D cpu_to_be64(s->st_blocks); +#endif + p->gdb_st_atime =3D cpu_to_be32(s->st_atime); + p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); + p->gdb_st_ctime =3D 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_comple= te_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr= ); } =20 +static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + int len =3D 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_comple= te_cb complete, } } =20 +static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + struct stat buf; + int ret; + + ret =3D fstat(gf->hostfd, &buf); + if (ret) { + complete(cs, -1, errno_for_gdb()); + return; + } + ret =3D 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 =3D cs->env_ptr; + struct stat buf; + char *name; + int ret, err; + + ret =3D validate_lock_user_string(&name, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D stat(name, &buf); + if (ret) { + err =3D errno_for_gdb(); + } else { + ret =3D copy_stat_to_user(cs, addr, &buf); + err =3D 0; + if (ret < 0) { + err =3D -ret; + ret =3D -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_compl= ete_cb fstat_cb, } } =20 +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr) +{ + GuestFD *gf =3D 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) { --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094797; cv=none; d=zohomail.com; s=zohoarc; b=nLxN174Mu+6+3YEaommcIimVv4bSDShtPejamz7FNN/d4qBLbLYQeHmFPMN0ZqnnhPxXPcMddRjbJF+IGCq+zx4K6fjSHK73w9pTr/jwFUnUPUfh9hWC/9e3AXTvz4eEpHD4yCqjpEKzlVCYJYlHmXKjhhfC+X5jrVwIMtwGe9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094797; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=PxKd66HxVM60HgJSdIlq63q7M9BdZhBC0k8zIAKbML59ZOc9XYoBxl6yr0HiDkPmvBC2ZSMGJ104S+vlnLieBAeD+se/sqUTHPHbfpvL7RgzuRVGe+eAUOGzQ2ynFLGYie5VxO15Icaj6Q3ezVGTDTZI0xt1uxBa2Wbx63E3Qxk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094797362250.64939771591025; Fri, 20 May 2022 17:59:57 -0700 (PDT) Received: from localhost ([::1]:43214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDTI-00045M-5Z for importer2@patchew.org; Fri, 20 May 2022 20:59:56 -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) 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) 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-Google-Smtp-Source: ABdhPJwmjilcanHDyxerhqbVQQac9R8yWNlveoCEPrcNUZwVHHYqHrWVCb66MwPxmkGLS1rmQKcJOw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094798976100001 Content-Type: text/plain; charset="utf-8" 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_comple= te_cb complete, void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong cmd, target_ulong cmd_len); =20 +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, + 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_compl= ete_cb complete, gdb_do_syscall(complete, "system,%s", cmd, len); } =20 +static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complet= e, + 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_comp= lete_cb complete, unlock_user(p, cmd, 0); } =20 +static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb comple= te, + target_ulong tv_addr, target_ulong tz_addr) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + struct gdb_timeval *p; + int64_t rt; + + /* GDB fails on non-null TZ, so be consistent. */ + if (tz_addr !=3D 0) { + complete(cs, -1, GDB_EINVAL); + return; + } + + p =3D 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 =3D g_get_real_time(); + p->tv_sec =3D cpu_to_be32(rt / G_USEC_PER_SEC); + p->tv_usec =3D 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_com= plete_cb complete, host_system(cs, complete, cmd, cmd_len); } } + +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, + 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); + } +} --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092891; cv=none; d=zohomail.com; s=zohoarc; b=OJ2evFDW4PGaeCJFublf75Zx78RdxbPeNa5zgjld1dMYcPajSUbAuRWn5iJL6DK4FBuDNH+ixNsBMzHco/la/9Qo9ANzgVPxkEL8cvBh+9SyHTfhwesYLD3mPHFpilbY4sGy3Ylsa3qAzqjFhuFkCPTtHB6B3kLugUCSm6f2mho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092891; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=R8LmH4e+PMnsi9Af9Onv9SkMhAoC/ASzAF/xHgzRWGA=; b=kKVP1IqXEmAcb4Bi+lcYetop6ju5gk9iRhuq6uU4OvUf6n0wDGt1/9TbdsNUPj3Ece4wfPxNtN2miMtlvUcru+mtWV+Pq0n38j37oHCAJtUoFN7wFDJ7Bfx642ndzWDakjmLeGKg01fqdRxmX0F7LINS1d0sjFNe8P4qXwMcmOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092891888204.3655407942897; Fri, 20 May 2022 17:28:11 -0700 (PDT) Received: from localhost ([::1]:51874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCyY-00040V-SW for importer2@patchew.org; Fri, 20 May 2022 20:28:10 -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) 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) 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-Google-Smtp-Source: ABdhPJzUbvVWOYcGoXqLuW2E9EiHEdUFhh+OBSOF40NoPRSFo+5lFb1cXAormm9048csFNtxhlwbLA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092892798100001 Content-Type: text/plain; charset="utf-8" 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" =20 -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 e= rr); =20 /** * 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, vo= id *user_ctx) static void handle_file_io(GArray *params, void *user_ctx) { if (params->len >=3D 1 && gdbserver_state.current_syscall_cb) { - target_ulong ret, err; + uint64_t ret; + int err; =20 - ret =3D (target_ulong)get_param(params, 0)->val_ull; + ret =3D get_param(params, 0)->val_ull; if (params->len >=3D 2) { - err =3D (target_ulong)get_param(params, 1)->val_ull; + err =3D get_param(params, 1)->val_ull; } else { err =3D 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 } =20 -static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) +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 r= et, target_ulong err) * SYS_READ and SYS_WRITE always return the number of bytes not read/writt= en. * 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 =3D cs->env_ptr; @@ -250,8 +250,7 @@ static void common_semi_rw_cb(CPUState *cs, target_ulon= g 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 =3D 0; @@ -272,7 +271,7 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } =20 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 valu= e. */ 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, tar= get_ulong addr) return s; } =20 -static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong er= r) +static void semihosting_cb(CPUState *cs, uint64_t ret, int err) { - if (ret =3D=3D (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); } } =20 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, =20 static gdb_syscall_complete_cb gdb_open_complete; =20 -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 =3D 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_ulon= g addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } =20 -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 =3D env->dregs[1]; if (put_user_u32(ret, args) || @@ -108,7 +108,7 @@ static void m68k_semi_return_u32(CPUM68KState *env, uin= t32_t ret, uint32_t err) } } =20 -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 =3D env->dregs[1]; if (put_user_u32(ret >> 32, args) || @@ -122,16 +122,12 @@ static void m68k_semi_return_u64(CPUM68KState *env, u= int64_t ret, uint32_t err) =20 static int m68k_semi_is_fseek; =20 -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 =3D M68K_CPU(cs); CPUM68KState *env =3D &cpu->env; =20 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 =3D 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_u= long addr, return true; } =20 -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 er= r) { target_ulong args =3D env->regs[R_ARG1]; if (put_user_u32(ret, args) || @@ -124,8 +123,7 @@ static void nios2_semi_return_u32(CPUNios2State *env, u= int32_t ret, } } =20 -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 er= r) { target_ulong args =3D env->regs[R_ARG1]; if (put_user_u32(ret >> 32, args) || @@ -139,7 +137,7 @@ static void nios2_semi_return_u64(CPUNios2State *env, u= int64_t ret, =20 static int nios2_semi_is_lseek; =20 -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 =3D NIOS2_CPU(cs); CPUNios2State *env =3D &cpu->env; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094947; cv=none; d=zohomail.com; s=zohoarc; b=RNbPIfKSNhCV3mAE0/1mGknrr459vikgWornVFK5X9J2M0FBR7lD1+QWMB8+rRZbQXdGDPQZS2dxCk9b5/FIWYyQOpvBs1TNMze8qQ63FKzL5OaBv8royJkOz1GXso9wjSzB1WzKrm39/3i+SQfEtUxlTJENcT5TDd9Rkl2hjvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094947; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=nKVrfsfcx1+QPEdVywlfN0dkpLPHjmWol4URm31W5gnxOvGq1b4hOvhyc66V1j2K33fb2/OiE1yjDyfkRVDk40BZQdhHB1O1DV07rZs5k428MIE6wPaFYAlOjJE701FCm27fKn/oNZ9QHwH+UrpFjVZo+FhkZgt2iAC1rNA/iRs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094947666692.8676702418924; Fri, 20 May 2022 18:02:27 -0700 (PDT) Received: from localhost ([::1]:45376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDVi-0005hq-J1 for importer2@patchew.org; Fri, 20 May 2022 21:02:26 -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) 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) 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-Google-Smtp-Source: ABdhPJxWV7GbxOdJgyCU8Dmm0k2oH4PSG2esZnRBQiN1IFH8vqZj1jyoxg2F1lZLmTFylJO4YZWe2g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094949069100001 Content-Type: text/plain; charset="utf-8" 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, t= arget_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 * --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094212; cv=none; d=zohomail.com; s=zohoarc; b=DRnoPvLarlPVO6LkorvnbvOP7/oyVmytVkt98IV9D45TTJc7ROnUX0DTWYd+EU3e5/nep0acWe9TMGb5cOzs+5O6EWFGneJ89MfodIId/D+2NWYIf38w9MXkKFKZ2F9np0KXvTSplS2Y62DhmqniLqo+wBH7mVGgkRLUTIJWRZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094212; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NkYDWZD4Kl/AmjNy/kSwweyafB44BYvhT/zKiCaM700=; b=MgwKJjt22dmiy8Cf30L3E0xr5DCB7o4pyPGvj4VguIAkOJADkcU13USa+qXoS+dyy6nXtUdVj1izuMCFYULRfLg6vkAoJ8QaSuMACwCo1ic8H7k6Ia9OoI9DPVYerIEDMRKjw2aPzVrr8660CuHVpy27AT5Saj5An5TVrkfOMUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165309421283816.005630006790057; Fri, 20 May 2022 17:50:12 -0700 (PDT) Received: from localhost ([::1]:60096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDJr-0004Nx-OK for importer2@patchew.org; Fri, 20 May 2022 20:50:11 -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) 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) 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-Google-Smtp-Source: ABdhPJzwAl96d+3W1/6D9EC4/usCKYov7Z5RPC/9Le5sJmWCJox09TLDJn8X48JgH8Xtpi3+V0vQ5A== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094214671100001 Content-Type: text/plain; charset="utf-8" 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, tar= get_ulong c); =20 /** * 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, tar= get_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); =20 /** * 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, tar= get_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; =20 case TARGET_SYS_READC: - ret =3D qemu_semihosting_console_inc(env); + ret =3D qemu_semihosting_console_inc(cs); common_semi_set_ret(cs, ret); break; =20 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 =3D NULL; } =20 -target_ulong qemu_semihosting_console_inc(CPUArchState *env) +target_ulong qemu_semihosting_console_inc(CPUState *cs) { uint8_t ch; SemihostingConsole *c =3D &console; + g_assert(qemu_mutex_iothread_locked()); - g_assert(current_cpu); if (fifo8_is_empty(&c->fifo)) { - c->sleeping_cpus =3D g_slist_prepend(c->sleeping_cpus, current_cpu= ); - current_cpu->halted =3D 1; - current_cpu->exception_index =3D EXCP_HALTED; - cpu_loop_exit(current_cpu); + c->sleeping_cpus =3D g_slist_prepend(c->sleeping_cpus, cs); + cs->halted =3D 1; + cs->exception_index =3D EXCP_HALTED; + cpu_loop_exit(cs); /* never returns */ } ch =3D fifo8_pop(&c->fifo); --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092649; cv=none; d=zohomail.com; s=zohoarc; b=EN/Og0YBnuQJRVNA965rrrwf6MxjP0SUNOX3DAt0Dl5+eInxxFbJ/Ntbjj5jPeFXqB2wVUol0gEAyGXdgSiDfTipZ3lG46XoKehc1j545m+sD0ek0DvI+VWFdbKJ0EYC/O+tIESuOQLa1As5S1kDhxIKyQnCAqeXOj7nwIqyH40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092649; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jZGKSwAg+QGOS7FPNjoYkg7xUN0QcDGNw7JjeaNbJgo=; b=MLT92UYI/BtwITAUcLvf16sdvbhkBE+UrGdAC6dkQDJIoTf2olRjATAOFYhBck/2LCSbj/a8KCWUWpndNK/ZI8kz6wIIBo2qNG2HaV6ShCo7jOj0uCYiCfElXQhsIk2UNy8222G6v1JKu+KGygv5P7EDG+hhGREIkLZaDlQGD88= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092649307524.491391071243; Fri, 20 May 2022 17:24:09 -0700 (PDT) Received: from localhost ([::1]:43698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCud-0006eb-42 for importer2@patchew.org; Fri, 20 May 2022 20:24:08 -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) 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) 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-Google-Smtp-Source: ABdhPJxHi9GBuwl9LQr29n6AEzB6Nwwbj8mskdU3Bx7qZe5lYOgPvdL7RV+cYC7TNER/MwrdO6ZcUQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092651385100001 Content-Type: text/plain; charset="utf-8" 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, ta= rget_ulong s); void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); =20 /** - * 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); =20 /** * 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, t= arget_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; =20 /* Disable line-buffering and echo */ tcgetattr(STDIN_FILENO, &old_tio); new_tio =3D old_tio; new_tio.c_lflag &=3D (~ICANON & ~ECHO); + new_tio.c_cc[VMIN] =3D 1; + new_tio.c_cc[VTIME] =3D 0; tcsetattr(STDIN_FILENO, TCSANOW, &new_tio); =20 - c =3D getchar(); + ret =3D fread(buf, 1, len, stdin); =20 /* restore config */ tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); =20 - 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; =20 case TARGET_SYS_READC: - ret =3D qemu_semihosting_console_inc(cs); - common_semi_set_ret(cs, ret); + { + uint8_t ch; + int ret =3D qemu_semihosting_console_read(cs, &ch, 1); + if (ret =3D=3D 1) { + common_semi_cb(cs, ch, 0); + } else { + common_semi_cb(cs, -1, EIO); + } + } break; =20 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 =3D NULL; } =20 -target_ulong qemu_semihosting_console_inc(CPUState *cs) +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) { - uint8_t ch; SemihostingConsole *c =3D &console; + int ret =3D 0; =20 g_assert(qemu_mutex_iothread_locked()); + + /* Block if the fifo is completely empty. */ if (fifo8_is_empty(&c->fifo)) { c->sleeping_cpus =3D g_slist_prepend(c->sleeping_cpus, cs); cs->halted =3D 1; @@ -157,8 +159,14 @@ target_ulong qemu_semihosting_console_inc(CPUState *cs) cpu_loop_exit(cs); /* never returns */ } - ch =3D fifo8_pop(&c->fifo); - return (target_ulong) ch; + + /* Read until buffer full or fifo exhausted. */ + do { + *(char *)(buf + ret) =3D fifo8_pop(&c->fifo); + ret++; + } while (ret < len && !fifo8_is_empty(&c->fifo)); + + return ret; } =20 void qemu_semihosting_console_init(void) --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093542; cv=none; d=zohomail.com; s=zohoarc; b=JgUTGnxuPhL5rTLNeOtZCkc2jjkW93NMPXCccpaFcYy9Nmlb5bt0wNm8/vg3rjVXctoTryBMWWhfaqrz7UFAf6Jc65c2pBvBTP9RLSXPNL+ZVR2JAUJ5KJhMTaWVbV1NcQnt1go15a1MbKM28CcXg/8bLpsXivt3dMyeU+D/CcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093542; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E+fPmq/gIqgkSE063dcs/6u6fyml6PThxo/MDWH5lGI=; b=YIVuNwwje96RfE5MRfuTz04KzlUMkQ47+ZUNyS7FCANa1ujH9T5WkYQZV0XwKOelpsX0cGWG3IsfMJP1UCr0b/0bovNOn3la+VYMMbjnoVnEHulAg/ncwLX4XXNvWbYzgY3LjBc0Vrs07VFujSEzgTc6Q7AbY9l26iQe/toLOas= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165309354250174.58856615117315; Fri, 20 May 2022 17:39:02 -0700 (PDT) Received: from localhost ([::1]:44330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD93-0001du-DO for importer2@patchew.org; Fri, 20 May 2022 20:39:01 -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) 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) 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-Google-Smtp-Source: ABdhPJzLqwM6MmgxWtYXwEF6xzIwdER6dZ7oOBuwY3Fyn96tFx503x4RSZyTS6dvzxpnxCRgrmsYfw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093543865100001 Content-Type: text/plain; charset="utf-8" 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 */ =20 #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 =3D { 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) } } =20 -Chardev *semihosting_get_chardev(void) -{ - return semihosting.chardev; -} - void qemu_semihosting_enable(void) { semihosting.enabled =3D true; @@ -171,16 +165,19 @@ int qemu_semihosting_config_options(const char *optar= g) return 0; } =20 -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 =3D NULL; + if (semihost_chardev) { - Chardev *chr =3D qemu_chr_find(semihost_chardev); + chr =3D qemu_chr_find(semihost_chardev); if (chr =3D=3D NULL) { error_report("semihosting chardev '%s' not found", semihost_chardev); exit(1); } - semihosting.chardev =3D 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" =20 +/* 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 =3D 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) =20 #define FIFO_SIZE 1024 =20 -/* Access to this structure is protected by the BQL */ -typedef struct SemihostingConsole { - CharBackend backend; - GSList *sleeping_cpus; - bool got; - Fifo8 fifo; -} SemihostingConsole; - -static SemihostingConsole console; - static int console_can_read(void *opaque) { SemihostingConsole *c =3D opaque; @@ -169,10 +169,9 @@ int qemu_semihosting_console_read(CPUState *cs, void *= buf, int len) return ret; } =20 -void qemu_semihosting_console_init(void) +void qemu_semihosting_console_init(Chardev *chr) { - Chardev *chr =3D semihosting_get_chardev(); - + console.chr =3D 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); =20 /* now chardevs have been created we may have semihosting to connect */ - qemu_semihosting_connect_chardevs(); - qemu_semihosting_console_init(); + qemu_semihosting_chardev_init(); } =20 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 ch= ar *cmd) { } =20 -void qemu_semihosting_connect_chardevs(void) -{ -} - -void qemu_semihosting_console_init(void) +void qemu_semihosting_chardev_init(void) { } --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653095299; cv=none; d=zohomail.com; s=zohoarc; b=Ch7n4pkptkuLgp8ftCjbUl8rY72j4loUUQT5ng+aCN2dxjZh3YkeJ4COD9UZ7pVN7lP9eeGBzxNYlGTooqQfCinHmL9EhaOPpKGG9ywBI0TlDPK0a0wKLOeDXij36LKtmY6HTGDNR5J70xD9wtJebhs6gOECa7hWfxh0ed19Y3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653095299; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=FU3CZRbGGmHq1hLnznzr0xBCkYSJWUTnxvvgpku11HiixwyB1NrsAA3x9G0Dhn//wS0rMBCUZog0woM5ZU6FhTGyAioQIgioF9lNPnzAxv3fq2GREapwk96c1OxSSRG4qLa7vjsrVLpLqFLHWxV/PFu96aW4ft0FS2DD31At10U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653095299486590.2520502445387; Fri, 20 May 2022 18:08:19 -0700 (PDT) Received: from localhost ([::1]:52098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDbO-0002Dt-Hi for importer2@patchew.org; Fri, 20 May 2022 21:08:18 -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) 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) 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-Google-Smtp-Source: ABdhPJwpmpwRAF9RTCu3EpkTAGHHP5SyeLkfm+BO0W65yZl0xcSXksrsIWlHxUa2XFr2YMapnXAvnA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653095300911100001 Content-Type: text/plain; charset="utf-8" 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, ta= rget_ulong c); */ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); =20 +/** + * 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) =20 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; } =20 +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 =3D chr; --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653095378; cv=none; d=zohomail.com; s=zohoarc; b=MBsURvoEYcHhO6DeX+9W23fwT48I0wN2eM9McnjSbbFXlsH8iS3q5XddY0cWmnUTVWfBHx6aNCpPXnfvG+CkEIj1TtObPvekKQ7qKhU3MDmpn3SLzhnCGwOUP1slB/isYKijYdTbE6aQQ8kFl7d+d1mndCR4/2a0Sws5oU7MtF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653095378; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/j2cw52lTOWH/atsAabzvb2VUFPtyq5zVPafxci6jYk=; b=eAeMS5v/UwZtU3wYD3eOheYwUEOmduTx3+obOz6y0wEwsStXXqL8Ml77GykPuhlezojYkGsigQSLW3f3ctLXOl7vxXCo+4g7+oGXZe/mfnFDdCXrdC2d+BFp/gpVMl8Mrg9/c9fwJABZA68WFxE03lKKoT42ptnAuW+36ly9v3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653095378386863.8808804875736; Fri, 20 May 2022 18:09:38 -0700 (PDT) Received: from localhost ([::1]:54226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDcf-0003gH-0E for importer2@patchew.org; Fri, 20 May 2022 21:09:37 -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) 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) 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-Google-Smtp-Source: ABdhPJwXyOtjUgSEtrDGbjAluekEI8F94Cgg3/3dzntDKBVvz1O3Sb3QclBnNBSvtnzhHq6XQwRp5g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653095379199100001 Content-Type: text/plain; charset="utf-8" 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 @@ =20 typedef enum GuestFDType { GuestFDUnused =3D 0, - GuestFDHost =3D 1, - GuestFDGDB =3D 2, - GuestFDStatic =3D 3, + GuestFDHost, + GuestFDGDB, + GuestFDStatic, + GuestFDConsole, } GuestFDType; =20 /* 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); } =20 +/* + * 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 =3D cs->env_ptr; + char *ptr; + int ret; + + ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret =3D 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 =3D cs->env_ptr; + char *ptr =3D lock_user(VERIFY_READ, buf, len, 1); + int ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret =3D 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 =3D { + .st_mode =3D 020666, /* S_IFCHR, ugo+rw */ + .st_rdev =3D 5, /* makedev(5, 0) -- linux /dev/tty */ + }; + int ret; + + ret =3D 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_compl= ete_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_com= plete_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_co= mplete_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_compl= ete_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_comp= lete_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_comple= te_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_compl= ete_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(); --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093758; cv=none; d=zohomail.com; s=zohoarc; b=WeSJ359dPY+4APKcDKPBC7jmw5Kpfiga8e5xDbvcPI5pq33AA3HIhNNvtRTxK04fvROf5sbdYOZTWhEEfBPIPU6ULR0I6BZMMgskK7VYFqBELbzsQ8ofArZ59NKO/em/ytw7dZvHkGqtpnol62pyMFRJOrISQ8F7fyl61GwEDMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093758; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ptZSGC/FODqEi0rLC9tfcDztwNdHfO1v+1vhlJ7WWkE=; b=dSrwJJB2t0E8L/+K6r9jA6TSyyIq7B4do6MuGDGeLah759RsJYuwVC+jbD9BPyYciqUZKKD3i2121TLXZEYQooDUCh0rQ1IsCohvNNspZaEfcqqeFN5vJjiDK60bI2t1uXPL+XdCWzQpWaRT3XfX8c3ypHugm/T2mVI9gb8CSZ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093758275908.2712544710123; Fri, 20 May 2022 17:42:38 -0700 (PDT) Received: from localhost ([::1]:48716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDCX-0004jt-7P for importer2@patchew.org; Fri, 20 May 2022 20:42:37 -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) 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) 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-Google-Smtp-Source: ABdhPJwIrV8Li6++E34/YyI8kQBvUkjLUMN03G4wqKtHFcpRWVMM19WJa2KLxYp11NF/SVSYnyxAhg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093759072100001 Content-Type: text/plain; charset="utf-8" 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; =20 +/* + * 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); =20 #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" =20 +#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 @@ =20 #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 =20 static GArray *guestfd_array; =20 +#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 =3D 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 =3D GuestFDGDB; + console_in_gf.hostfd =3D 0; + console_out_gf.type =3D GuestFDGDB; + console_out_gf.hostfd =3D 2; + } else { + console_in_gf.type =3D GuestFDConsole; + console_out_gf.type =3D GuestFDConsole; + } +#else + /* Otherwise, the stdio file descriptors apply. */ + guestfd_array =3D g_array_set_size(guestfd_array, 3); +#ifndef CONFIG_USER_ONLY + if (!use_gdb_syscalls()) { + GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, 0); + gf[0].type =3D GuestFDConsole; + gf[1].type =3D GuestFDConsole; + gf[2].type =3D 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; =20 - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - /* SYS_OPEN should return nonzero handle on success. Start guestfd fro= m 1 */ for (i =3D 1; i < guestfd_array->len; i++) { GuestFD *gf =3D &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 <=3D 0 || guestfd >=3D guestfd_array->len) { + if (guestfd < 0 || guestfd >=3D guestfd_array->len) { return NULL; } =20 --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092652; cv=none; d=zohomail.com; s=zohoarc; b=c6Lvvae4pCNnaHqbsBcVursy0YbP1bT/d5W3eut8iKkyQRo54/AmyMd85hKGAZkne6/Se8eAWkV6Jc62LqK5DEw9o07ZiSfaz6dLLw2bVb2MwuoaBGphR5dk1lmkG37c+rZ7Sx9JzHLFI3DghlLjACdaM4xuIwm4ldluOWi8UGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092652; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q7p7TZN47ATIiQ3A5Y3xH06vJfjCq2B+xHIDC9Ub+lo=; b=FtqRWBd9GxWnesT8t7u7kdEw2HXvIf2EPhQ4RLEYWb4wl6TFfGbDip5iIudzvpZLUcWawwnRjAiuLBT3IXpHSfPQNFAHZpQjZGXLcgBkauHF3v0sN2TK/kBb2KWjPcTOUSfFHiH5KF3DoEOB6pjihxvplv4EBZyVdWH4CE6JPqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092652440278.29087950984547; Fri, 20 May 2022 17:24:12 -0700 (PDT) Received: from localhost ([::1]:43720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCuh-0006fc-8p for importer2@patchew.org; Fri, 20 May 2022 20:24:11 -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) 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) 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-Google-Smtp-Source: ABdhPJwObgXbkU+wXFusA5QU4cAvD2RdShOW23vW8zTtWtNGDMBWlP5Z9od04k9l3Up6AN7B6fGclQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092653356100003 Content-Type: text/plain; charset="utf-8" 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); } =20 +static void +common_semi_readc_cb(CPUState *cs, uint64_t ret, int err) +{ + if (!err) { + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + uint8_t ch; + + if (get_user_u8(ch, common_semi_stack_bottom(cs) - 1)) { + ret =3D -1, err =3D EFAULT; + } else { + ret =3D 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; =20 case TARGET_SYS_READC: - { - uint8_t ch; - int ret =3D qemu_semihosting_console_read(cs, &ch, 1); - if (ret =3D=3D 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; =20 case TARGET_SYS_ISERROR: --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653092893; cv=none; d=zohomail.com; s=zohoarc; b=EmPx4a6yA6A/tgnrEnvXnXkp5O8++eQ67ilfKeVEp6fQWNwXxasKkzbDFYxEcZaXZkxJeNvOnv0u+sJzi3cyueE8dsDEdkq764LrnAK5c7azLaD6AZ3mGmoTW/aik8gbHTtKPFzXoL/k8JSI8icxlESIU2Jc+PUw4I5ywT/XFhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653092893; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z1XEM4ETfmeGaHs0P/KqaWrAu876hNlLRNnzFnqql6I=; b=oC9ntU+YzEm5kb2QSvX/bFKKAllGv6eOlNcrTFRuZFVBbomCDTr3oCas6jUYBrb6nz0vPQakk058rni1bDaZbt4pZbfBuHsW3O0th1nVbqzYuVSmpI289SDqLmdSRTH1tpgShfamOeK6FcnD6h8nkPHBvttxTr5DWzjvScm+R7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653092893698526.7596629235337; Fri, 20 May 2022 17:28:13 -0700 (PDT) Received: from localhost ([::1]:51902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsCya-00041n-8b for importer2@patchew.org; Fri, 20 May 2022 20:28:12 -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) 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) 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-Google-Smtp-Source: ABdhPJxYUyM6O7FpGYWrVZpLtj8LQ9UVIe5o9WthwpXB+gLuu1c4o+Kbk3TBDNmTSaI/amsYJmMrDQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653092894697100003 Content-Type: text/plain; charset="utf-8" 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); } =20 +/* + * 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/writt= en. * There is no error condition, other than returning the original length. @@ -329,8 +338,7 @@ static const uint8_t featurefile_data[] =3D { * 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; =20 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; =20 case TARGET_SYS_WRITE0: --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093186; cv=none; d=zohomail.com; s=zohoarc; b=nNqzMsZeQXth4aQPh9rh6vICDph0TqBhg41RYWrd9sARrKsOBEYGYlYLK77xhIu/Onm9aK1PDUOXTbz9aoKAlm9avFGUeigDxIIhLQRclL9VpAjp1M3F+PuAOZGQmQ/uBl8p+yImOsmDj2B6BSOkUbp6rESIaahJhxRm0Kxx0zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093186; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=eFKwv6iQY6W6ovnp7Q8EQyqmOJEmYd83bjNxjOlMsJ+IyTcZu9I4lBYnU4JIAc0DtGr4AziRpzjFRbjY218qp/+hi89T+wvGNdoMbV1F1Yi3zabv92dFouBOEOEBmUEr1o+/CbcJopdcBPFOLRHNcAfKYed+OyTG2cgLJGe3ye8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093186783456.87311630734223; Fri, 20 May 2022 17:33:06 -0700 (PDT) Received: from localhost ([::1]:60682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD3J-0001na-O7 for importer2@patchew.org; Fri, 20 May 2022 20:33:05 -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) 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) 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-Google-Smtp-Source: ABdhPJzKE1an2tbYXWQ7mV/1sWju3ynkUhTwDJNA3rsCRaW9rIFVoaQxGMY+5UHrPOYwhz/Hr426/Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093188427100001 Content-Type: text/plain; charset="utf-8" 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); =20 -/** - * 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, tar= get_ulong addr) return len; } =20 -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) !=3D 1) { - qemu_log_mask(LOG_UNIMP, "%s: unexpected write to stdout failu= re", - __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, tar= get_ulong addr) return out; } =20 -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) -{ - CPUState *cpu =3D env_cpu(env); - uint8_t c; - - if (cpu_memory_rw_debug(cpu, addr, &c, 1, 0) =3D=3D 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 =20 static int console_can_read(void *opaque) --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094036; cv=none; d=zohomail.com; s=zohoarc; b=FgkoTS3ENcmdDB36Q1GNuUw+o+bW2Gs6fBAMycmtvZy07qen9JBjNb5WRzguN7ac7quUUQqyLvLVQclHDaSzqvcaYB259RW0xT7hMzMBpM44N3/LgYblZ1ACNSIAgTOi71EsFbqu7OV853KOEm4DJbQOnjHw5MY4W1A2LGOUCbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094036; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xw5S8AgSS2kdVT0yNtWxbG47quJl+p2/OpzczA7b8dk=; b=H6pBPtoiefyICuqSXqdmQPvbpGSFsXpmvvEvvccMCFuoThIR70LI3FkLHV6lfOj4cHI9sgmQpIvr1MUKdKlG/z981jZspwqbLBP4l7YwcTTI3l4bT2H37xM7emBA9jxKQWPwhn/LI9XBQRCk8KBBh/4KzpZ9BPhj+fnoczM9shM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094036474865.118905934673; Fri, 20 May 2022 17:47:16 -0700 (PDT) Received: from localhost ([::1]:53550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDH1-0008G6-CP for importer2@patchew.org; Fri, 20 May 2022 20:47:15 -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) 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) 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-Google-Smtp-Source: ABdhPJx0UzE+brqYN9IOkZpMdeCDapBuS+fQpavpqV54YQbmAnoi6mH8+tyDjqjsHrzuJQT9UJVDxg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094038271100001 Content-Type: text/plain; charset="utf-8" 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; =20 case TARGET_SYS_WRITE0: - ret =3D qemu_semihosting_console_outs(env, args); - common_semi_set_ret(cs, ret); + { + ssize_t len =3D 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; =20 case TARGET_SYS_WRITE: --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653094155; cv=none; d=zohomail.com; s=zohoarc; b=mN/UeiN8eVKIbABgfeX2eLIKU4IOXPwg8BavUGAJKwPSog1Vc66YigjkbUyUz6tdr2DltjDagYE92BexVhvL3pfoJG2BbQwfLphKDt8njbnRqyP2jhQj7zVA2YMRXlbUr1zeGZQz43JCzyjbOPo6sggvJXCllf1EliS1/6VCV5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653094155; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=bKHUU2NkqE9rgE+ije26Kwb50WdCb0iQlRt2Z6iAjJ/QPlLt6j0HE/TRKsFft/mNX3yVweqluXt6RdqZTHOroXGSvfCr8Wcj2GdUlLOhTTpMUzJwnmT9+WU5JVruW0ba8uz5lVJFVNtjvv9qV2pjx7HNSiygf9+vOfeezCWjrZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653094155915570.3284594734339; Fri, 20 May 2022 17:49:15 -0700 (PDT) Received: from localhost ([::1]:58306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDIw-0003A3-LI for importer2@patchew.org; Fri, 20 May 2022 20:49:14 -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) 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) 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-Google-Smtp-Source: ABdhPJwWrRUGjxfd4PhADa3SF8oqBXf+miI7O/EQzHzzQcDCh/tDArqVsnd41FTjRh5Vsf25lZi7eg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653094156803100001 Content-Type: text/plain; charset="utf-8" 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 @@ =20 #include "cpu.h" =20 -/** - * 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 =20 -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) -{ - int len =3D 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 =3D lock_user(VERIFY_READ, addr, (long)(len + 1), 1); - g_assert(s); /* target_strlen has already verified this will work */ - len =3D 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) } } =20 -/* - * 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 =3D env_cpu(env); - GString *s =3D g_string_sized_new(128); - uint8_t c; - - do { - if (cpu_memory_rw_debug(cpu, addr++, &c, 1, 0) =3D=3D 0) { - if (c) { - s =3D 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!=3D0); - - 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 =3D copy_user_string(env, addr); - int out =3D s->len; - - if (use_gdb_syscalls()) { - gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, s->len); - } else { - out =3D qemu_semihosting_log_out(s->str, s->len); - } - - g_string_free(s, true); - return out; -} - #define FIFO_SIZE 1024 =20 static int console_can_read(void *opaque) --=20 2.34.1 From nobody Tue Apr 23 08:16:06 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1653093456; cv=none; d=zohomail.com; s=zohoarc; b=hbgoGWE1uGGHhN1MJfyBwzvtOPsb3qvcoAnzXlBhRLAKm8qsUHqLZkaGY3xEa/tVa68NVBC8/mZLBNOE0iB6ryLqe3opxUIaEBqOqm52OrR2xqeAiuuOpKQMHbz48two6GZ70zVXXUCZIpfhcVNv+598vz7Hla4gv0anznWkyOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653093456; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=ffzEKY4iHRrlVI/QUxECmS6oQe9Mmu3IM7QXCBQIq3PuQ7urEAgpqdS/FD45Flqz0Xuln7LCzTdRSD/cu+j4LUJbiWebx1UmfpFKVIfpWaeEw1Ko8Lq/uEy43uhvDP3J1+p7B4tMm+tBCnZIosGw7gzZW6h2tDNMfR94qMZGQEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653093456018420.65342736776404; Fri, 20 May 2022 17:37:36 -0700 (PDT) Received: from localhost ([::1]:40348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsD7e-0007Js-FQ for importer2@patchew.org; Fri, 20 May 2022 20:37:34 -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) 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) 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-Google-Smtp-Source: ABdhPJxpsBEbddukhM+8WMZ8gu9IaTDM4ixoHJGmNleroeOpw+z/3EYRfjLPyhswMVsJs1zPfs8Phg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1653093457615100001 Content-Type: text/plain; charset="utf-8" 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); =20 +/* + * 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_comple= te_cb complete, void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, target_ulong tv_addr, target_ulong tz_addr); =20 +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 *b= uf, int size) c->sleeping_cpus =3D NULL; } =20 -int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +bool qemu_semihosting_console_ready(void) +{ + SemihostingConsole *c =3D &console; + + g_assert(qemu_mutex_iothread_locked()); + return !fifo8_is_empty(&c->fifo); +} + +void qemu_semihosting_console_block_until_ready(CPUState *cs) { SemihostingConsole *c =3D &console; - int ret =3D 0; =20 g_assert(qemu_mutex_iothread_locked()); =20 @@ -92,6 +99,14 @@ int qemu_semihosting_console_read(CPUState *cs, void *bu= f, int len) cpu_loop_exit(cs); /* never returns */ } +} + +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +{ + SemihostingConsole *c =3D &console; + int ret =3D 0; + + qemu_semihosting_console_block_until_ready(cs); =20 /* 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_syscal= l_complete_cb complete, unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); } =20 +#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_co= mplete_cb complete, complete(cs, ret ? -1 : 0, ret ? -ret : 0); } =20 +#ifndef CONFIG_USER_ONLY +static void console_poll_one(CPUState *cs, gdb_syscall_complete_cb complet= e, + GuestFD *gf, GIOCondition cond, int timeout) +{ + /* The semihosting console does not support urgent data or errors. */ + cond &=3D 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 =3D=3D 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 &=3D ~G_IO_IN; + } + + complete(cs, cond, 0); +} +#endif + /* * Syscall entry points. */ @@ -936,3 +979,30 @@ void semihost_sys_gettimeofday(CPUState *cs, gdb_sysca= ll_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 =3D 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 --=20 2.34.1