From patchwork Sat Apr 30 13:28:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568100 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7207552map; Sat, 30 Apr 2022 06:33:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT26sNKx00k9aFZCARErY1GK9jW0JK17YTMWAM4Z1nQxc3a8lsVsGlKn9f4J/UL6EFTNYX X-Received: by 2002:a05:620a:1a06:b0:69f:b536:af3c with SMTP id bk6-20020a05620a1a0600b0069fb536af3cmr2681259qkb.772.1651325639099; Sat, 30 Apr 2022 06:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325639; cv=none; d=google.com; s=arc-20160816; b=I9FBHhIwYYeTAKCs0DSFP6nBs2TOAxXK5KbtRJYuaErp+XWwUos5JWRmeizEdepBH+ y2dqPijlzps7Y79hkGBtJZokvvvUTmw/fiESSnhl8HI8gQJHpNLN23iTJ4gdUdaLe1nT v463oHi91621QW6vEEi0fS1DwkFg7nFOSqMRw4vl9cPd3PIqh4sUb7layWEVmPnPVatp r9fX/XiStYCYG8EUczjk4eD21D7P2FSNOf5y5UuoiV//S8oPIQ1FRQWfsc62bqvlpb03 e5vCM7sCe9+JOivYjzoPRiyMXKeyO+w1X3M2Sbi+7N3XDtpBhcIUgXPeNU/uoUqkaXR0 kf9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=Vkyvh/9eEF7wsQhckIumgCZ3iV/8MgN2W/jUBK0kP59Bds/7OpXBww27Iuym6BSuR9 Mb2gOmsQDwPvsoQFavNkOtOAdExu+24Xqe+D2JKXEUg1A/+1nt61fbqFARATgDMbnb11 amvs2O1LvI6k2aCihn/DYUUcHdxvE0/GxhLPUYaODlQfqeoEhp+w2z+a4rTfRLU7JWRr hjlone274ODHHMIMKsz6Fe/RSzPpOFgl7v8Sa55J9IB3sVbHWrI4BLusza2Ap0fuUiFI 7lOX5yCcyldP9vaNIlHz/FpnHE2AzZQ1L6ybT0DApbyp1ZyRTszdjwWbqwFuh+ssLWRH P37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Y2X0oNMt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gy6-20020a056214242600b0045494a02d75si681025qvb.252.2022.04.30.06.33.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Y2X0oNMt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknEU-0002OL-LX for patch@linaro.org; Sat, 30 Apr 2022 09:33:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAI-0004eF-W5 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:39 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:42634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAH-0006CU-5o for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:38 -0400 Received: by mail-pg1-x52a.google.com with SMTP id bg9so8493306pgb.9 for ; Sat, 30 Apr 2022 06:29: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=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=Y2X0oNMtOoWplti87uXxcjno/x4sZmMulwUCrLdlAiCNMEMpfBxt4KPGA+fPrn2N/+ kPJUOyZxuHa/vQETYsnTgMz/3cExIg7VK3UeXW67v873+2cb7aS81404diaCYWzRMaBS Y2GclQTXDryLaWVhrKNKcH/ySJ/wEgLYoanvzDNZ2dAtejwCcoyqXP4KfZjhgOp/Tuoe QKjINdd3eiUt6Aonbs7gHDsJbP8+toP88eeChepEIAAIXOXVpXrFucrgi+fJZ8FPGQd/ o9HUKpA2gFse5DWKXA+LPz798ZmCv8LoIgYGc7VonMz62zWF8X5IhoI/WUqPZI882QDu VRzQ== 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=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=k9L5nerQAn8O4K9fuUwmnZsHhI1BwIkmwkr3LNkyJLCoA50cL8OR2f7XD3YnTcxCf+ CYCGaLmEBPBwrHmKWq4jbih0UO7furU8yXLBwHDWrV99Pyn8nlOc1ZH24ZVbCk0Ma1uz KYYP1DG/jEMqEDX/vNz2E6xvFUnfC2Ymb8hnhbqic7TRxoHG1iBVYqBh9hdLHL6p/JX3 ypRCpay4a+Dxgr8wkG3g6nV5PgzvFNXvbpyxPDvZa8/cJYfWkam76u1h6JQasdmpvJjG u5Zq5WSE2Cd8obCDHfybJXXWdsCQNbktzWFdry+D7xNE6AvUhjMmX2nTmOO4p/PEOqXb 0NTg== X-Gm-Message-State: AOAM530aWPkjK2t1xzvp8gL1k6vDjFzFlU5zuCf/qjGXF8rcRGW86qdg q3StvMEThhrUhp9n08ZMJ+ctfUzB+NK3Tg== X-Received: by 2002:a63:1b5e:0:b0:3aa:593c:9392 with SMTP id b30-20020a631b5e000000b003aa593c9392mr3146605pgm.470.1651325375256; Sat, 30 Apr 2022 06:29:35 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/43] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h Date: Sat, 30 Apr 2022 06:28:50 -0700 Message-Id: <20220430132932.324018-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We have a subdirectory for semihosting; move this file out of exec. Rename to emphasize the contents are a replacement for the functions in linux-user/bsd-user uaccess.c. Signed-off-by: Richard Henderson --- .../{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} | 6 +++--- semihosting/arm-compat-semi.c | 2 +- target/m68k/m68k-semi.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 2 +- target/nios2/nios2-semi.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename include/{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} (95%) diff --git a/include/exec/softmmu-semi.h b/include/semihosting/softmmu-uaccess.h similarity index 95% rename from include/exec/softmmu-semi.h rename to include/semihosting/softmmu-uaccess.h index fbcae88f4b..e69e3c8548 100644 --- a/include/exec/softmmu-semi.h +++ b/include/semihosting/softmmu-uaccess.h @@ -7,8 +7,8 @@ * This code is licensed under the GPL */ -#ifndef SOFTMMU_SEMI_H -#define SOFTMMU_SEMI_H +#ifndef SEMIHOSTING_SOFTMMU_UACCESS_H +#define SEMIHOSTING_SOFTMMU_UACCESS_H #include "cpu.h" @@ -98,4 +98,4 @@ static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, } #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) -#endif +#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7a51fd0737..dbef280b87 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -370,7 +370,7 @@ static GuestFD *get_guestfd(int guestfd) #ifndef CONFIG_USER_ONLY static target_ulong syscall_err; -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37343d47e2..a31db38fc3 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -25,7 +25,7 @@ #include "qemu.h" #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #endif #include "qemu/log.h" diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index b4a383ae90..6d6296e709 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "qemu/log.h" #include "exec/helper-proto.h" -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index ec88474a73..373e6b9436 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -28,7 +28,7 @@ #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif #include "qemu/log.h" From patchwork Sat Apr 30 13:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568098 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7206230map; Sat, 30 Apr 2022 06:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG72z/fiW16g59pxyCrlhy/VCbzWt4KXJoLRHT2I+GR9JBuFAKJdJy4T39x8L6P53EKWkU X-Received: by 2002:a05:620a:372a:b0:69f:61e6:f981 with SMTP id de42-20020a05620a372a00b0069f61e6f981mr2669534qkb.767.1651325507581; Sat, 30 Apr 2022 06:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325507; cv=none; d=google.com; s=arc-20160816; b=JVr7SzMXmws3GjkirGGO1QbTwQrxyVdlm08G5qF/MNSsK3WyZUXtkjxe6jMCTimXZx q8WnDZ+7C4HsL+bxVtDmqutlWvUML+ExdTUNXHJqF5D9TZu0wSOTvyXaQM3a4nr/10OE 93J1Mq33zCUoKt2BLtBsGtUs3sdARgJlvqA1Y24pOepmib/k5vNvDudClM13PIg+zulr V9myPplZk5urL9vpHNcwOYtWeZPEgfZJcYnbmuVDuYwW72YFJpTTBG5L+E1rHxysKxPv zrEmhsyYTx9NpfU3U+dFpIrjgsMBKXb8fGJbyXxo1P1VySHvQqW5iXqtuyftCWmWBbQ6 RCAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=Gh6EF2V6If0rZbXM2ZxtUCv+FmIR4n8YxWnpZWzEwQJfMc0/iMukCmFXvIcYIDZfRj tUgpI/Qq7oxDoWCZCYSpsw/yXEVmeKmlyMBVuGTNVIGmO1vJarJDAZ9in06ID0XxVwKD JojVEX3XROG8uqCtqsRbcpD+voMuGViuDpz4GiqCKmDCJMBtKHhx6RfyUfJzeSh/Usgr X/uhlbNC5vTo5B+7RknXDzj4XznkvqAAP+a8rmkoqZm8g252y5uShlHHFScbaKpUA6x1 F83IYuEdri4deq9gQjAR/y2sd0dni07ycWfQbsm6G42+bPNk3AlJihlJh/KL9Vb8vFxO /xtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kBnKVmAj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q20-20020a05622a031400b002f393178e58si1930188qtw.588.2022.04.30.06.31.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kBnKVmAj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknCN-0004ue-3F for patch@linaro.org; Sat, 30 Apr 2022 09:31:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAJ-0004ed-Ga for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:41 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:45813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAH-0006Ce-MK for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:39 -0400 Received: by mail-pf1-x433.google.com with SMTP id h1so9040906pfv.12 for ; Sat, 30 Apr 2022 06:29: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=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=kBnKVmAjRWL5vHTwNr624dsY6j0QUulBXnynUJyFOxGUeh1hxOL08iXiTTke4cL/AP eBEQ3A5JQtWjkHR5MHCUMAn5oQfuSeMBjKcJahlwTpwViEgOtwHP+stf2Ns7Uhq48eJt r4KxvJmKde712/2MFP8xkA0Q8tfnwzfp6Hn5S0Hpo7x6dPtiZjFKb6W+JfZ7IW0FbHMv nwXt5p6NaHB3OhI0Jqt5LriTQjhMD2Yt3g2p8+BdF5y1W2Ts2bN/P4gu8hlTj9AG77rH mRkMm2LNnsZB/BxXCCz5hHqbJ+RH8Q8O3Ak9OT6+EjoWO/ILm6WLPdBHF+NHmyuqLriw rI2w== 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=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=sg0bTWyKZsUvLfPQxrIfq/9UUyp3KuvY8geZvk1kCM6FQSB+aFx6Mol4MrLBREq4v+ 1vahQxLhtKf0iNrcVJiLlgj5eOLA2w1GvoWT0Q+n2hTXEzyBIBgm6ONzcR5CbhncpPeo GzUV3cqbENN9ZuzeSCcKI77ITWj4KAKGz9WrP8XMunaUnsTpIyaDPHgbZ+1mh6p50F8Y AzISWd3qa0GWdQLUS//IPhe5y4WwMxdKzJxcAz3Qp6Hh7nwis/euiJVrvdBlMTNyMQ// 34DzpBqVfuTOrBBQjpSxZxtldDHOe8ZN9DV2ceBGizbeU9OSSRyKJV0THKKm2738m0tJ b6wA== X-Gm-Message-State: AOAM5334rlpRZI9ajMPddOtXCWaKD1+NqCWBfavHekCtjjJuS5y569aT FY/mrgAW7JKZqBf8Nsxj/8dcKSSI0VjQ6g== X-Received: by 2002:a63:fb56:0:b0:3aa:cec:6b6f with SMTP id w22-20020a63fb56000000b003aa0cec6b6fmr3165406pgj.409.1651325376263; Sat, 30 Apr 2022 06:29:36 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 02/43] semihosting: Return failure from softmmu-uaccess.h functions Date: Sat, 30 Apr 2022 06:28:51 -0700 Message-Id: <20220430132932.324018-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We were reporting unconditional success for these functions; pass on any failure from cpu_memory_rw_debug. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 91 ++++++++++++--------------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index e69e3c8548..5246a91570 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -12,82 +12,69 @@ #include "cpu.h" -static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) -{ - uint64_t val; +#define get_user_u64(val, addr) \ + ({ uint64_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap64(val_); ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 0); - return tswap64(val); -} +#define get_user_u32(val, addr) \ + ({ uint32_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap32(val_); ret_; }) -static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr) -{ - uint32_t val; +#define get_user_u8(val, addr) \ + ({ uint8_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = val_; ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 0); - return tswap32(val); -} - -static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr) -{ - uint8_t val; - - cpu_memory_rw_debug(env_cpu(env), addr, &val, 1, 0); - return val; -} - -#define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; }) -#define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; }) -#define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; }) #define get_user_ual(arg, p) get_user_u32(arg, p) -static inline void softmmu_tput64(CPUArchState *env, - target_ulong addr, uint64_t val) -{ - val = tswap64(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1); -} +#define put_user_u64(val, addr) \ + ({ uint64_t val_ = tswap64(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) + +#define put_user_u32(val, addr) \ + ({ uint32_t val_ = tswap32(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) -static inline void softmmu_tput32(CPUArchState *env, - target_ulong addr, uint32_t val) -{ - val = tswap32(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 1); -} -#define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; }) -#define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; }) #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, - target_ulong addr, target_ulong len, int copy) +static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) { - uint8_t *p; - /* TODO: Make this something that isn't fixed size. */ - p = malloc(len); + void *p = malloc(len); if (p && copy) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0); + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } } return p; } #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) + static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - char *p; - char *s; - uint8_t c; /* TODO: Make this something that isn't fixed size. */ - s = p = malloc(1024); + char *s = malloc(1024); + size_t len = 0; + if (!s) { return NULL; } do { - cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0); - addr++; - *(p++) = c; - } while (c); + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); return s; } #define lock_user_string(p) softmmu_lock_user_string(env, p) + static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len) { From patchwork Sat Apr 30 13:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568103 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7209083map; Sat, 30 Apr 2022 06:36:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt13XjZrH83lI3btwZYTNxh127FDeeRgRwQv4S4fKBQ9gL4wz0xKm8BJWRJw+7UYm9W7+Y X-Received: by 2002:a05:6214:248d:b0:456:2c42:415e with SMTP id gi13-20020a056214248d00b004562c42415emr2993424qvb.116.1651325792899; Sat, 30 Apr 2022 06:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325792; cv=none; d=google.com; s=arc-20160816; b=eK9NjQBvFqO+cV+O2i/KVkk2VtZCPX2rlUA2HpnQ7eoXBm5o4gf03YiqLNhD3jWJz7 07zto8Y8gwOk0ROKC++nTRGZgn+FWxa55jtwqKOW8eokEA8JHpnA2DhcEz1GXyUNdeck 1kfpTfPvlcyyBIzC5zs0Hk/9tcSy0jzXjV8xD1HOPKjighzGIA0I1XVWUobIM+zQFyr4 +p1Y7oWCBX8pApPJCGWqISWc1FiG8UsRbGuCj0pbybIuHnaiigNUnVWVO+Ep+uz7qL+Z G98YoqI6IHrlpnTwouKquGXbM2MgLyoFSzS2m70KjOom91ART+sGP3D7431xNR68mqp3 uH4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=fEl2nnvBlVuP80RGeb+8snab9oIJu1STiNQyoLsyA7fs7gtXVkrB6gBm3GY+DhtTqS dtp1icV6hsfsWI9Ev379a03fBmR3tT0LFlS+Ha0DwxEXm1VuzpjgYgJjDc20PWfqoGtU I0528xunI6wuWkMkmf2tvfLNINrrPSsho7gdHEPGd2/cnGevfYZbuiA/8gaZIUYsz7fQ bhNTCuOS+gZIWnYb0/kV3rzko2NvzM5jSI3j46N5LowMx5dRwK1FbkiEiX4ze1Xo6AMG TfXHAms8O0fTW6Y4mRQ3B7ta9zm3v7+UsQ5q1fvGu3Ycwc8kFKXQ8UG9o9t/2H1EdYRh UeUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Imyz5dgC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c6-20020ac85a86000000b002f381192da1si3976763qtc.572.2022.04.30.06.36.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:36:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Imyz5dgC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknGy-0007dc-FH for patch@linaro.org; Sat, 30 Apr 2022 09:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAL-0004gK-Cq for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:43 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:34477) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAI-0006Cs-J2 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:39 -0400 Received: by mail-pf1-x433.google.com with SMTP id a11so9074853pff.1 for ; Sat, 30 Apr 2022 06:29: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=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=Imyz5dgCKPDXsQAaNisYgo38+kyyK/4XqFm0ucezEGCxTw2ZbS05dLfppOQAzcDr0D 3iWych4dyUvrHx8IP/UlKoPppqpHiPnpc5KbBajTdEuKeUxa7K3T8bjb4WcdIaW336sP RqRiJ7Ou/H4iHO613N7pBfZEve4R7F/Agp59ShSk2Es5hqoLpWUAjhjKqzC+9XcwiDzA 8rXd222IJmJlL1jvUsu6n99Fj9P4DK1GCbTQExMFnPCWhqTS7/9DPlHoQ98p3XysBjHb mjv6CP4+0mr27GPkQdcK3MuyZpMfdfkEr1lokDSc1R1oQpeNkIogDP1T2iHybTKXURdI 5WbA== 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=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=gkDqtlxAXWb0wCCpAILN9d+YBzApku/z8JO7F49vdossW3bz1EJ6+pOH8e8+M7z3gI FnK5y6ehjRy6AvnUrpzPEyERnuwoYhoXQ1YdkzPNYWpYjerHlsLSv9s031YxbBIAR/tb 4m671vtMNJ0gfyRBZtFm+XkbkacWGdRnqh01vIbLXSNnIqa+gxqxwVg0fVkCH7jupoDl UYl8z+e/gki8BAuQTntLhNssU6uImIsQ9XC5WyiDTvGgWS8F+kXp34LgkFCeSCdAatyu 6Qo27DrpL9nnuZ5heX2oOwXctnzcFfSnJE3UXMxX8sVDIX8zjploBKpoNxp9IuI9g1oS 4htQ== X-Gm-Message-State: AOAM531SSr9lkx3+0Bp8PSa1sMXzxrl4+9nNxZ2d1ZCxPDMDPrmYm2Tm YTqlsC73mW9GyjDOyVMqTgdR8j6P6CWfog== X-Received: by 2002:a05:6a00:2403:b0:4fd:e84a:4563 with SMTP id z3-20020a056a00240300b004fde84a4563mr3833726pfh.60.1651325377248; Sat, 30 Apr 2022 06:29:37 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/43] semihosting: Improve condition for config.c and console.c Date: Sat, 30 Apr 2022 06:28:52 -0700 Message-Id: <20220430132932.324018-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While CONFIG_SEMIHOSTING is currently only set for softmmu, this will not continue to be true. Signed-off-by: Richard Henderson --- semihosting/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/meson.build b/semihosting/meson.build index ea8090abe3..4344e43fb9 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,4 +1,4 @@ -specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( +specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', )) From patchwork Sat Apr 30 13:28:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568097 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7206221map; Sat, 30 Apr 2022 06:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBTTDzn8bKnRXe7ycx8sJY7Lu1xo7lhTzmkvTisF34ah/JbqAsh2VZCrr6cJG6+8HD6tke X-Received: by 2002:a05:6214:3017:b0:45a:6c33:2ae9 with SMTP id ke23-20020a056214301700b0045a6c332ae9mr3051008qvb.108.1651325507117; Sat, 30 Apr 2022 06:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325507; cv=none; d=google.com; s=arc-20160816; b=GQI6cSIJRNFkO/vwW6ugR+al4P71Ymr2qRRNgZM3UV1sxUUc4oi+Wugt0dPBIaJsfG RKB7x1YP2rAITcw2PhgM+AHuDSkJ1tOMos8CUZlWd012wZbE21vApRJmQuIsXLjSbD3z GJPwQjp98+F+b4IhxFj1VYGKEOssUfqMbhSbW+x4SKDNqe7cjrzsWbKV9kc8lQy+9y4/ hLvwQyIRNvzfpE/rmHwy/IfF03ikyjlZz6E+dMytxJiemYY7FiYn2Rz6uu9LFnXlsCOU WD/kW5p1xt/dL1xdjUorFvvZ4xL27xTLSrSzQOtpU0sDUTanWvq8LdwmbB3veAF6YKOF XECQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=pOYDXUg4+fsulOxpIbgQ5gb27gDai5+jRdA9jnxk4nqh+B8mZLfMmU2KNM058x2W7S c74Cy7858jOq3naZ0k0Iavf7E1cgvPdJ8sLLNOBrAhWghO+epNGp76YrsqpbOpcnbKhM m6yu0nXyYytIvIqsRBtzaTbH//P8twoh/pHLNKodj2ZRruE85KI53vlVV8MwCWb/JfG6 dplxp82JznA2UjFoI+MAZBhEtZptSKC7VwSq+fx5MJ1fOeed4phWVidWr7yLS7t2u++i Nj83SFHtYY/61mfv99B893RIDMRhcclNO1f5ElbHTA43dNBeeSkM5gXCBk1AIHiDDiZD 2hrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PHR6CAiP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a17-20020a05622a065100b002f1faea49d4si3932677qtb.656.2022.04.30.06.31.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PHR6CAiP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknCM-0004m7-Gv for patch@linaro.org; Sat, 30 Apr 2022 09:31:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAN-0004gP-0k for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:43 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAL-0006D4-4Z for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:42 -0400 Received: by mail-pj1-x1036.google.com with SMTP id cx11-20020a17090afd8b00b001d9fe5965b3so10813378pjb.3 for ; Sat, 30 Apr 2022 06:29: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=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=PHR6CAiPt4gWta5B4Sg3UU7KLvMxEQMWB9HS/c4NZh6LDvzlpqfDzmWp22ponf8Pjo Cfl859Bvb9TxocU+rmhUcwj1pV8Og5SQrxpQwGGCrfh6VUmL4cFYap7tql5NHM7/hEdU bHtWw+gODtn4FstY9KFm7IXt5MH3Hf0rB6Ohu/24p+oui0fKkus1KGYvXdxdDMJ7todH ZrMUh1saaGwoCKcXSE9ScZUhmc0+yZtCzCL5h+/5LT64zyg8ai1G4lkd+cWHzU+X+uak Pa7DEhWITHhJd1VUkinj9iOvo33txd8c4ivaUH4t4FquwIporabUI+RBnfMSDATyj7vI JMjA== 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=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=792OZE/R1Mw0x8NfMgi21AxGOmwustseVIDo3dEoe+cgX/ANPnBzdvl/brnybL7vxJ Y8EoFdhlagQsiw/TZAu1IVCw3NazicH7PeyUSjnRieNy6lBhxoQOJ5H4fMZ6d3r8+Uu/ GJ5kvXXs6zO/FgAAWosipvQkdc2Yrw5jU60guVl4gYVFQUQn8hLL9nSAYjrh6PHqTiv0 TcunjGbQAaFS1GuNeHQQFe7DShuxakLkRrjqfgGNNo69/dV/vF8a1gFQC7uF54TmrLU8 StGt1DISymDsaXEc9f3H7xV+5Xwwmehnel8JyfYJfgH9j3w27l4lBO/1vgBz5PYZiUfB qmbA== X-Gm-Message-State: AOAM531c8LydSyxAYEK6hW1e+nBCEIekqRhAsWXEykW2QFMMtC3zrSg0 vpciMV3e5KfuoCcUhlcQHu6O9SshKub/gA== X-Received: by 2002:a17:902:edc5:b0:158:4065:a5ce with SMTP id q5-20020a170902edc500b001584065a5cemr4019540plk.55.1651325378263; Sat, 30 Apr 2022 06:29:38 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 04/43] semihosting: Move softmmu-uaccess functions out of line Date: Sat, 30 Apr 2022 06:28:53 -0700 Message-Id: <20220430132932.324018-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather that static (and not even inline) functions within a header, move the functions to semihosting/uaccess.c. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 42 +++------------------- semihosting/uaccess.c | 51 +++++++++++++++++++++++++++ semihosting/meson.build | 1 + 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 semihosting/uaccess.c diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 5246a91570..03300376d3 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -42,47 +42,15 @@ #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, - target_ulong len, bool copy) -{ - void *p = malloc(len); - if (p && copy) { - if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); - p = NULL; - } - } - return p; -} +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy); #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) -static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) -{ - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { - return NULL; - } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; -} +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr); #define lock_user_string(p) softmmu_lock_user_string(env, p) -static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, - target_ulong len) -{ - if (len) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); - } - free(p); -} +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c new file mode 100644 index 0000000000..0d3b32b75d --- /dev/null +++ b/semihosting/uaccess.c @@ -0,0 +1,51 @@ +/* + * Helper routines to provide target memory access for semihosting + * syscalls in system emulation mode. + * + * Copyright (c) 2007 CodeSourcery. + * + * This code is licensed under the GPL + */ + +#include "qemu/osdep.h" +#include "semihosting/softmmu-uaccess.h" + +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) +{ + void *p = malloc(len); + if (p && copy) { + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } + } + return p; +} + +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) +{ + /* TODO: Make this something that isn't fixed size. */ + char *s = malloc(1024); + size_t len = 0; + + if (!s) { + return NULL; + } + do { + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); + return s; +} + +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len) +{ + if (len) { + cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); + } + free(p); +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 4344e43fb9..10b3b99921 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,6 +1,7 @@ specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', + 'uaccess.c', )) specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], From patchwork Sat Apr 30 13:28:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568099 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7207483map; Sat, 30 Apr 2022 06:33:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtze5zxnDl0GBG6A3WUkj3R4lrne/vkiL2SE9gVWGVmVNCRHSAdvlNhrDvQsEjj3a4lcHi X-Received: by 2002:a05:6214:2409:b0:432:bf34:362f with SMTP id fv9-20020a056214240900b00432bf34362fmr3004890qvb.66.1651325631949; Sat, 30 Apr 2022 06:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325631; cv=none; d=google.com; s=arc-20160816; b=PQMIzvS21kiYJatOjOV7u8Ku5Txxguwth+a1rRfz7aiMfH7lo3hUt4QQS3e1YFQmgb 00LERYY2vKuhfL/+LVtN2OE0UO0W68JlZRegjSBBUjYVZ2psgg8hRvbi1QmJJMXEPkhP vcp/lF3oTUB4FIUK+qNjeAFcADu3VwEZQjZECScqVfNM5pI5K9qW70FdZI0LNDKOUX8/ 4IyL3jD6KDLi6ua4AkuaWiUyf1AD5an4SEgWD/F3ZNtTWQqudeqpR6wL3mHkYoBSgYU4 o8aeRZZR23OrMVp9XVGpkAjTxkaRrSeqLU/BKA6Y9G6PQB40pp4VfhUDaLf0FeYi1dk9 wkYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=mN75AmwrCvt+yYxIFc6TYm94zl+4XDCyA/khwzneKqaRWvyssr5M3Rmk+kwwfBTfkr ulG+i6UFLUZH33h74H2LAhFKT2MKNucojtvOtgrf846P2ACgs0TGuw4gBsbdBoZpvmi1 C1x7HJ0quGBG4Lxvaj2Z91KLItPwk4dXg3Uaiq6js1T//yk7YTpahSFl9SN5dopfU5fC vkBFz6oKmZx2Z8VZ8If9xS/Qdv8hoAG1LaeWVwrdeTy2x9hrcLIh1eMOLDjcw+WyD184 yd7rGkbCfwZA9Fa2Egn9+wCLUQ9rQyIqmTrVUOgBo6p4ACFpg3k0OWHwyv4YYGN7TnNA Q4tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kmEhznUx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j12-20020a05620a410c00b0069fc00e7afcsi1360281qko.191.2022.04.30.06.33.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kmEhznUx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknEN-00020x-IH for patch@linaro.org; Sat, 30 Apr 2022 09:33:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAN-0004gO-0p for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:43 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:39918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAL-0006DO-4m for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:42 -0400 Received: by mail-pl1-x62f.google.com with SMTP id u9so8681924plf.6 for ; Sat, 30 Apr 2022 06:29: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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=kmEhznUx1qC6YTEblmAa94kOTM4FxvPsXHGg9HENz3fIT7+sts9actE21e2Iw3UBCd vrvr1DfdmZDGKt6W0hgzce6Cs3UqSaLkGtFogZGQa82EuvCvv9cq8xik1+MPNIoq06fP Znb7vUF/fh+HlSmWwD5+uU7D1QEYjfTuMoSZPcgguDvQtR/dsUA2J+mmRfkxA/jRIzsc GiOLbS2jNmr+67wIIeB5QhvVpb11wAdvcmb5UftTblJd98tzbGPW1yWqL0OyMAFQ8m/r tzbTihoxgAHNCHIQySr0k67lPKpG1RoHchl2n21INvhMrU9VXIESYi8ptn+5hXmMNS7g VKEg== 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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=VoyIRVr4NDe9WVF8+EQa5oiZgsK2qy4rAdGIHv2/UitDXJNqK8Xm5uATOWrl0TBFyb inMvhpt1lrQqzUQpERZ9/8L648QV0gInNmgppy1Jv0sr88RlM4/q1WYsmdOB2f+dpqvC kqLCUa9ym61JWD5KFm6MJ7BdnCeZw/L2QZCjUTkw8Elnez1bzdGvmwPzhdbsqrNxI6A1 PtItl8AOFl6a3ffTacaoFl1cIG7t1M0M0ueCh7k+bUyucu164L35qKsUq1d3ttetn3eC vV3Wwyu5anQs7VaxqGy+cuqLJ25y/V2xorC74kBBmM/9DxZJN3ObbMjSZpNb8E3m5GXX Ws9Q== X-Gm-Message-State: AOAM533j1u/rZsdcXDqJcU4/zkFiNXC4gmlAQmknhYGGl0tLE0Hu83oK PwlNbR+hpNy3TYawK+15WCbk7pm8QcLkmQ== X-Received: by 2002:a17:90b:1d0e:b0:1c9:b74e:494 with SMTP id on14-20020a17090b1d0e00b001c9b74e0494mr4229293pjb.238.1651325379127; Sat, 30 Apr 2022 06:29:39 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 05/43] semihosting: Add target_strlen for softmmu-uaccess.h Date: Sat, 30 Apr 2022 06:28:54 -0700 Message-Id: <20220430132932.324018-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Mirror the user-only function of the same name. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 3 +++ semihosting/uaccess.c | 29 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 03300376d3..4f08dfc098 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -53,4 +53,7 @@ void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr); +#define target_strlen(p) softmmu_strlen_user(env, p) + #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 0d3b32b75d..3cd809122c 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -23,6 +23,35 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + char buf[256]; + size_t len = 0; + + while (1) { + size_t chunk; + char *p; + + chunk = -(addr | TARGET_PAGE_MASK); + chunk = MIN(chunk, sizeof(buf)); + + if (cpu_memory_rw_debug(env_cpu(env), addr, buf, chunk, 0)) { + return -1; + } + p = memchr(buf, 0, chunk); + if (p) { + len += p - buf; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + + len += chunk; + addr += chunk; + if (len > INT32_MAX) { + return -1; + } + } +} + char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { /* TODO: Make this something that isn't fixed size. */ From patchwork Sat Apr 30 13:28:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568104 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7209178map; Sat, 30 Apr 2022 06:36:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+OZuj6rdcyvJoJaqHxzZhkMRIo8Eug4p7yUdKFPE9KIifbSXHoRSY/6UXfD2/CcZLaITS X-Received: by 2002:a05:622a:2c8:b0:2f3:9c9f:a59e with SMTP id a8-20020a05622a02c800b002f39c9fa59emr1963796qtx.565.1651325801261; Sat, 30 Apr 2022 06:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325801; cv=none; d=google.com; s=arc-20160816; b=fXRyJBdmwswOqRDmCNSnU3Pp1NwZkzuufDl/twAA++1XFWQO6/IUz3eUsZVhwRdweD tpavUbQ6BJaQ/O54N0cma6HGhSAmvWf5Y9JfngicwFe1UU0qo8iw8STl1TDEXbt5CSv1 /pxJF+FIPZuM+WYsiLzkEiU9qRo2cAYjFV7RmXCmiWB9V3GZyygt/89FbraOKsj5mOj6 8QrGHwEjl05j87ufa+/2hZmkvCm6/GM5JmqzxlgbFkveZnnGFqDMDkjOVE/Q6BgT+0T3 ZuuZCaI+I6qvsjOJAXvSduSJL1ANZJwUuFj68xYQnJudrifUNgjbHJNOn9YcBwW+wsHI muFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=yB1EadBAFuE3Ve3LZrDUS7c8GHoKal0KeAUD5Okw18IARfXTDYtisg9zvbriwRgrZf r5FGCBrfRJM01Q0A659POE2jGTFc5aO9D95E8xXBohuepIiF3RISQBd/qva5KkfDI7AT NPRbwKy7NGE8ld8Tfj62mj2TiGLp0+dcFeVZOokb9UE7m9qsIEAdpCZMMInmBJvlks1k PRR50JTZdOa7wjSorcsSlO3y/jN+dAJFmF1puesb0UWb1l0w9PqjmlAPnvKwQYbs7lcb pvmxPzDLfKi6BguBbUopd6MJQbkQxouKHwaj8gW3UeJzbC0w9OxB7RoPJSkLiXvd/ryG b6ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=s13WSI+K; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z206-20020a3765d7000000b0069fbc0a454dsi1344762qkb.127.2022.04.30.06.36.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:36:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=s13WSI+K; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknH6-00085r-Rn for patch@linaro.org; Sat, 30 Apr 2022 09:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAN-0004iI-T5 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:43 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:46911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAL-0006DW-6N for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:43 -0400 Received: by mail-pl1-x62e.google.com with SMTP id u7so9278379plg.13 for ; Sat, 30 Apr 2022 06:29: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=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=s13WSI+KvEFkskHyX/H8xj7dr8zb35D/ejGRS5qpBUOccLPaWrGKsgQYvU3BDwNUSn dYOVPCijTZTN9z1oi7hb2z9nYVbh3Y6LVqBTVeO27HAvuc+hELQ9PX0aRdQXAYw7Rgdn n6fXVmiqs2SQqdvJqWqRqrcea0My+nn51NvDOWojkw5sx7cyfLNHrV3asdNSfhGnDqB2 FUKDDI+nwNGxExrKIYPDBLbe87UvI8zvivNLZySG5Cy8Agj8bCMQPc66lB2XpJb/Ss+v TMkTtn9Ma62OKt/m9LNJ+G2JmUvUd+J0CbU26aMnnHEZYeJsMOuO9qq8UsatecxGOVog hKeA== 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=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=f8N8BJgTeTgw8M/psSg4MDEf9zxuKZ3gZwedFvQSQkNyEQ2tMEAbYMZ95B1gdrrtBe HFCX7ZMJLr2iJK82ItsjIoK+6iFm0xSg6nAVeTMg0/CXInjQ2JmkJjVZqLimlN7/IyXX BJxTSFAQ36hLl0oeSpBcOBQo7c/EefiYpTL2G+CxSZEBUQERLjg08NQmGGig+ZtqhPpk 19KrAndlNiPEuEbscM9RnuSPSKzbexni0AuOjBRqhBVTj7JZ/XTUZ1t3NDcg9NxCP0Eq IviVEsjuGgLxFxa7cd8UOSOLpcRHoW8bvm538FSzQ6Y1N2bZ83B9vHBhi3EgJxjXQcBd HLig== X-Gm-Message-State: AOAM532iyHCtB3OwfFbI2Ic428pnM8e8lAfd8NlONJThPKWa511gJwjd QBomnreo3EBOKzh9ns+MMaQNmOj7hf0k6Q== X-Received: by 2002:a17:903:14a:b0:15c:f657:62cd with SMTP id r10-20020a170903014a00b0015cf65762cdmr3941363plc.36.1651325379855; Sat, 30 Apr 2022 06:29:39 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 06/43] semihosting: Simplify softmmu_lock_user_string Date: Sat, 30 Apr 2022 06:28:55 -0700 Message-Id: <20220430132932.324018-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We are not currently bounding the search to the 1024 bytes that we allocated, possibly overrunning the buffer. Use softmmu_strlen_user to find the length and allocate the correct size from the beginning. 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 3cd809122c..f5fc94c401 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -54,20 +54,11 @@ ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { + ssize_t len = softmmu_strlen_user(env, addr); + if (len < 0) { return NULL; } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; + return softmmu_lock_user(env, addr, len + 1, true); } void softmmu_unlock_user(CPUArchState *env, void *p, From patchwork Sat Apr 30 13:28:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568109 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7210646map; Sat, 30 Apr 2022 06:39:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb39evengqZTLMDVQELUI69OFUgk1EkukYmsrWx9g/gFg4UqC4628SRD6huYNH0VXWkjPv X-Received: by 2002:a05:6214:2683:b0:456:3877:ab39 with SMTP id gm3-20020a056214268300b004563877ab39mr3212745qvb.36.1651325953845; Sat, 30 Apr 2022 06:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325953; cv=none; d=google.com; s=arc-20160816; b=Q3mlGAG909HRmdG0BOw3z+l/ef/ffUV/ACXTwQgbogta0j4aUeN58A9PkwROAQGqXP GML0qKP+kVu4jxkJzMbFK5eSsai8H3VEPuNs7dgPDSC9EzyjCBJ0qYt9rlcaQGDwXKs0 pN+A35lzzXk8VeUcPpzAm0cEe7/2frWup2vh302IQdLBd/xVi7USdratkUUgoVLWNi9o pcKIszr+JndWMv9Xun4ujqlKBYtFOkbwCRhCrfwyYLGPC8eA8Ae3cHj38QPuH8elIl1z hyp6pY+57ziGpeiBv76kyMu/Wsg0hKlmVZPgzPZgk+nZquWIDOg8L4UX8Ii6zfAB6Ttj j0zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=o+dFS91YM59wA2TMXjYApLzQTx0/+WJi+oPOwEg+MIcdwy5+Zt455hxHUFV/gjl4Ym jAF7AZFfkbnwq6fzyGiEaLYUt0myKOJQ7GmejoYGZZmk10IvKcxMH65ilDsYezyYdIxz 8S5XVPqfSOHFvlB9atKZ8GQJ9MP/NX89oUp4XY+jB1HJnNlI9AdDLPUuIK7Xy0r0zh/L 47x8POXdITWJhClNhqIFu22xFJ3aKuV4U17lnfPxysDgWwmUusWh6UNSgAQcxWWeA/F9 B9O5nNyu/i7V001iDL8qvsTpTzWYy95PdQ4bcv7m+5QSIkAqJj4MCi4IXVrRxNWrO7Mm KTtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UbYwSH+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u10-20020a05620a0c4a00b0069f85eb5d9csi4461752qki.608.2022.04.30.06.39.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:39:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UbYwSH+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknJZ-0005RQ-Ca for patch@linaro.org; Sat, 30 Apr 2022 09:39:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAP-0004kR-1z for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:46 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:40913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAM-0006Em-B3 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:44 -0400 Received: by mail-pl1-x634.google.com with SMTP id i1so3161867plg.7 for ; Sat, 30 Apr 2022 06:29: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=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=UbYwSH+3h2tYp/maT18I1+a370+oynq1py+RYjq7ltMbysknG+3U8oXTEsTg5LAfLc IlJV6u+ChoZmYr0IRQrAR/TYraerQiQFQ3Rpfrmvd+Tj6bLgJ/H6gC7HiMfb8U9Tf1DS nFwHZL8v4BiWFU1luLOu6+QKlNTtiXlT1rO7AcE7DC7+3XKWSHq/cn5EdIzHx6SknUxC doGrrAdQw15soXfb3igD/uRikMC9KuNBGJqQRwn8Ofp72H1YO19L9qCaR1hsYhu2py9z 34ZadOlHGPdaiSXwJCTyNsMcyFVD98iSJs0nC2fDRLROwDNwPkx6pHK/72O5U8631Wk7 fWww== 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=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=yqUM8HDKqSJ5xF064XdoYpLPCvKU5UMRShqADSl6YUW5fkVNpVIuwzL30jAHAnclpl SGFu6VbqjlccI3pZUiTtigFBNTEVkXvcPohjMuHLIAEq8Fa0j2zzAIh9hrhw19QvSZeu wN5AiELjvqHS5DLah3/v73CN44lFgZQUixEwGOefWUu3NxvxPePE0n4/SWSQxAtUWnAP lvP0vq8NWSyl18Sf60DTUYvf1H8ViEd7ED7BMYGf8A48WiCFYwHmm6S8jMsPtM9VQD+v VYFc95sKCthCZweCnt5uyyWv2e+Q1upIAftGo+A49wlIgbjIqFoeT8HsJJ8flH2+slsX 7vFw== X-Gm-Message-State: AOAM532aZeu/nFPV65U14eYS4+Ur5lPfM6ZUIMsPF6zRNQadW7Y85fP9 VURydT9jW1yyGHWXbgcn9gmvXBvbm6D0xw== X-Received: by 2002:a17:90b:4acb:b0:1dc:32dd:d51e with SMTP id mh11-20020a17090b4acb00b001dc32ddd51emr1725548pjb.5.1651325380944; Sat, 30 Apr 2022 06:29:40 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 07/43] semihosting: Split out guestfd.c Date: Sat, 30 Apr 2022 06:28:56 -0700 Message-Id: <20220430132932.324018-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" In arm-compat-semi.c, we have more advanced treatment of guest file descriptors than we do in other implementations. Split out GuestFD and related functions to a new file so that they can be shared. 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 | 40 +++++++ semihosting/arm-compat-semi.c | 125 +--------------------- semihosting/guestfd.c | 116 ++++++++++++++++++++ semihosting/meson.build | 4 + 10 files changed, 168 insertions(+), 123 deletions(-) create mode 100644 include/semihosting/guestfd.h create mode 100644 semihosting/guestfd.c diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch64-linux-user.mak index d0c603c54e..db552f1839 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aarch64_be-linux-user.mak index 7794424745..dc78044fb1 100644 --- a/configs/targets/aarch64_be-linux-user.mak +++ b/configs/targets/aarch64_be-linux-user.mak @@ -3,4 +3,5 @@ TARGET_BASE_ARCH=arm TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/arm-linux-user.mak b/configs/targets/arm-linux-user.mak index 3e10d6b15d..7f5d65794c 100644 --- a/configs/targets/arm-linux-user.mak +++ b/configs/targets/arm-linux-user.mak @@ -3,4 +3,5 @@ TARGET_SYSTBL_ABI=common,oabi TARGET_SYSTBL=syscall.tbl TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/armeb-linux-user.mak b/configs/targets/armeb-linux-user.mak index a249cc2e29..943d0d87bf 100644 --- a/configs/targets/armeb-linux-user.mak +++ b/configs/targets/armeb-linux-user.mak @@ -4,4 +4,5 @@ TARGET_SYSTBL=syscall.tbl TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv32-linux-user.mak b/configs/targets/riscv32-linux-user.mak index bd2f1fd497..9761618e67 100644 --- a/configs/targets/riscv32-linux-user.mak +++ b/configs/targets/riscv32-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv32 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv64-linux-user.mak b/configs/targets/riscv64-linux-user.mak index 4aca7662ce..cfd1fd382f 100644 --- a/configs/targets/riscv64-linux-user.mak +++ b/configs/targets/riscv64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv64 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h new file mode 100644 index 0000000000..5d6e744305 --- /dev/null +++ b/include/semihosting/guestfd.h @@ -0,0 +1,40 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_GUESTFD_H +#define SEMIHOSTING_GUESTFD_H + +typedef enum GuestFDType { + GuestFDUnused = 0, + GuestFDHost = 1, + GuestFDGDB = 2, + GuestFDFeatureFile = 3, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + union { + int hostfd; + unsigned featurefile_offset; + }; +} GuestFD; + +int alloc_guestfd(void); +void dealloc_guestfd(int guestfd); +GuestFD *get_guestfd(int guestfd); + +void associate_guestfd(int guestfd, int hostfd); +void init_featurefile_guestfd(int guestfd); + +#endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index dbef280b87..c092138031 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -32,12 +32,13 @@ */ #include "qemu/osdep.h" - #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" +#include "semihosting/guestfd.h" #include "qemu/timer.h" #include "exec/gdbstub.h" + #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -123,27 +124,6 @@ static int open_modeflags[12] = { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; -typedef enum GuestFDType { - GuestFDUnused = 0, - GuestFDHost = 1, - GuestFDGDB = 2, - GuestFDFeatureFile = 3, -} GuestFDType; - -/* - * Guest file descriptors are integer indexes into an array of - * these structures (we will dynamically resize as necessary). - */ -typedef struct GuestFD { - GuestFDType type; - union { - int hostfd; - target_ulong featurefile_offset; - }; -} GuestFD; - -static GArray *guestfd_array; - #ifndef CONFIG_USER_ONLY /** @@ -268,98 +248,6 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) #endif -/* - * Allocate a new guest file descriptor and return it; if we - * couldn't allocate a new fd then return -1. - * This is a fairly simplistic implementation because we don't - * expect that most semihosting guest programs will make very - * heavy use of opening and closing fds. - */ -static int alloc_guestfd(void) -{ - guint i; - - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ - for (i = 1; i < guestfd_array->len; i++) { - GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); - - if (gf->type == GuestFDUnused) { - return i; - } - } - - /* All elements already in use: expand the array */ - g_array_set_size(guestfd_array, i + 1); - return i; -} - -/* - * Look up the guestfd in the data structure; return NULL - * for out of bounds, but don't check whether the slot is unused. - * This is used internally by the other guestfd functions. - */ -static GuestFD *do_get_guestfd(int guestfd) -{ - if (!guestfd_array) { - return NULL; - } - - if (guestfd <= 0 || guestfd >= guestfd_array->len) { - return NULL; - } - - return &g_array_index(guestfd_array, GuestFD, guestfd); -} - -/* - * Associate the specified guest fd (which must have been - * allocated via alloc_fd() and not previously used) with - * the specified host/gdb fd. - */ -static void associate_guestfd(int guestfd, int hostfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; - gf->hostfd = hostfd; -} - -/* - * Deallocate the specified guest file descriptor. This doesn't - * close the host fd, it merely undoes the work of alloc_fd(). - */ -static void dealloc_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = GuestFDUnused; -} - -/* - * Given a guest file descriptor, get the associated struct. - * If the fd is not valid, return NULL. This is the function - * used by the various semihosting calls to validate a handle - * from the guest. - * Note: calling alloc_guestfd() or dealloc_guestfd() will - * invalidate any GuestFD* obtained by calling this function. - */ -static GuestFD *get_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - if (!gf || gf->type == GuestFDUnused) { - return NULL; - } - return gf; -} - /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -665,15 +553,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void init_featurefile_guestfd(int guestfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = GuestFDFeatureFile; - gf->featurefile_offset = 0; -} - static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c new file mode 100644 index 0000000000..e77265db0f --- /dev/null +++ b/semihosting/guestfd.c @@ -0,0 +1,116 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" + +static GArray *guestfd_array; + +/* + * Allocate a new guest file descriptor and return it; if we + * couldn't allocate a new fd then return -1. + * This is a fairly simplistic implementation because we don't + * expect that most semihosting guest programs will make very + * heavy use of opening and closing fds. + */ +int alloc_guestfd(void) +{ + guint i; + + if (!guestfd_array) { + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ + for (i = 1; i < guestfd_array->len; i++) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type == GuestFDUnused) { + return i; + } + } + + /* All elements already in use: expand the array */ + g_array_set_size(guestfd_array, i + 1); + return i; +} + +/* + * Look up the guestfd in the data structure; return NULL + * for out of bounds, but don't check whether the slot is unused. + * This is used internally by the other guestfd functions. + */ +static GuestFD *do_get_guestfd(int guestfd) +{ + if (!guestfd_array) { + return NULL; + } + + if (guestfd <= 0 || guestfd >= guestfd_array->len) { + return NULL; + } + + return &g_array_index(guestfd_array, GuestFD, guestfd); +} + +/* + * Given a guest file descriptor, get the associated struct. + * If the fd is not valid, return NULL. This is the function + * used by the various semihosting calls to validate a handle + * from the guest. + * Note: calling alloc_guestfd() or dealloc_guestfd() will + * invalidate any GuestFD* obtained by calling this function. + */ +GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + if (!gf || gf->type == GuestFDUnused) { + return NULL; + } + return gf; +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host/gdb fd. + */ +void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; + gf->hostfd = hostfd; +} + +void init_featurefile_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDFeatureFile; + gf->featurefile_offset = 0; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +void dealloc_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDUnused; +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 10b3b99921..d2c1c37bfd 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,3 +1,7 @@ +specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'guestfd.c', +)) + specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', From patchwork Sat Apr 30 13:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568101 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7207561map; Sat, 30 Apr 2022 06:34:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzfXjSsC7umMTnYQjNL18OvmhCQ9UtEjF5dM5f1acWVYHFKhfRtz+7MT5isHOplJlqy695 X-Received: by 2002:a37:b181:0:b0:69e:afa9:8350 with SMTP id a123-20020a37b181000000b0069eafa98350mr2779017qkf.698.1651325640008; Sat, 30 Apr 2022 06:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325640; cv=none; d=google.com; s=arc-20160816; b=nbtBV28P9Voi5+yQX2kI2r7cN/uxFd5RFqO2/vPhCYTCB4GDW9mvm3IYMMKehY9GSE djKR8SqksbwTCsfFJswCUqfy9cMU84ih9bR7YGElPhJCHt/c/xKFsOoxtGBSiE/tC0Vc DQvFnPZbNa88Z41CgcUXO8+6XsGBGq6XCRkkry36gag9FOCDOu90bL+4g9EfFCH16YA9 naEO4+WY0oSlQicervkyaKRE3yg2EjhAEzNczbx3MEjKnJhuKiZT9S6Bs+aMVyveWx/Q jR0ccnUHRa58ccsfCtBH3wzye004yKy3y+PGiStXcogv9l96rR3t0hQ+nTL5qT+prkU7 l1ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=0xMgYUduHVz5pqDZoO/M875LiJuT4m76nOFLBFOOv0vYLiJ4/bZLPbOT0Wq+ot8xbB epNBaxpwOcbviBn5dj0T1VLyW0QtVzf2VLA+WMXXJ4hrarYGe6nSfawHJ0qudzcN+tOI 0LXY/jW6sx1Id+ekx29UQ7R2V90KNm8JSuit1vnfUNAmIGWRrqbUKApQFb/kcNN717dM 7E9mxq1Cr4cQh/cYOIK5QvfyL+lxG0laFLs2GT9ZHfjsBwLpTywpFwzSSWCMLeD621c+ IQtfzd7+2QbGD7egkhJoy3CKuB8B2d+yZovMTMLxHFbaYx1fnqYuJc4axrwvedtyC3mf 5cMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gVFBtkpu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g20-20020ac87f54000000b002f34f162ccfsi3907791qtk.403.2022.04.30.06.33.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gVFBtkpu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknEV-0002Sc-J2 for patch@linaro.org; Sat, 30 Apr 2022 09:33:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAP-0004kT-2n for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:46 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:37658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAN-0006Ew-2k for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:44 -0400 Received: by mail-pl1-x62e.google.com with SMTP id k1so704096pll.4 for ; Sat, 30 Apr 2022 06:29: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=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=gVFBtkpurULAf4lJ9r1ofupYOo+fPfxx0kueNiwD6DQ9xOXrfgcQPbzmwuNyaccDqZ NcMswjn7j3xYA9Cue1vJLdpn2t+w0rritSeYOj4A56QptaTXOK1gIxa8GFaQV/5iAx6K hXCsBho66eChHTOq8U7I7R5m2qDcnBMgWrIjOBYifYhOeRuM6joPBG9gFDLju5oqC4+V H6jQBtittYB1mM6dEXuSu6SQGVSubcY8MgEuGOLer30H1p/2HvFjjI+uPc/+9AhhH0ay +hQ0vXFfbzN6dSYUMj8PmkJWtCinauM34uNDk2Ap4w+ufeFLgYpRu/bwMBVZ2NDAI022 gNzA== 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=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=xyGXaWFuF1OR5kGL9fBYuq7QCMSicXIScroNt9/Mitt03YXsZfJxpwh25/9EyYkTUy wXq34KjsiXncfUtVBJfNA6xmHMTZ+v6M8WuG+JwVenSZ5P1x95FdBhyVZvza7vsBWroD VvreeWgrGIIukLmRVv1C6xDhMEGLg24hp/rICptrkzWxOdMDehS0aElt7iW9tSpRjIyj hBbKDciZprI7sO0TbwC1rMADCfLdcVw940u293CvuKvEnuDxEUgv+i4sqEDNYMzx7r3s //d3Fdi7/u2UfDcfud0NuCBdx/n6DpQaSL/pw1iO7UIxplv+dAYq/tRqsY3XZFg6owwI fJwg== X-Gm-Message-State: AOAM531weQWf7MSir66cSDeGZy+/recpMLD6bWgP/zakTmuBlsuB5ugS eNm6wqwma19m3KbD9wow0fkF/zNYpXIR2w== X-Received: by 2002:a17:90b:4f92:b0:1cd:3a73:3a46 with SMTP id qe18-20020a17090b4f9200b001cd3a733a46mr4307896pjb.66.1651325381786; Sat, 30 Apr 2022 06:29:41 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 08/43] semihosting: Generalize GuestFDFeatureFile Date: Sat, 30 Apr 2022 06:28:57 -0700 Message-Id: <20220430132932.324018-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather than hard-coding the buffer from which we deliver data, pass it in on initialization. This decouples the feature from ARM semihosting. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 10 ++++++--- semihosting/arm-compat-semi.c | 39 ++++++++++++++++++----------------- semihosting/guestfd.c | 8 ++++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 5d6e744305..5aa2722cb2 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -15,7 +15,7 @@ typedef enum GuestFDType { GuestFDUnused = 0, GuestFDHost = 1, GuestFDGDB = 2, - GuestFDFeatureFile = 3, + GuestFDStatic = 3, } GuestFDType; /* @@ -26,7 +26,11 @@ typedef struct GuestFD { GuestFDType type; union { int hostfd; - unsigned featurefile_offset; + struct { + const uint8_t *data; + size_t len; + size_t off; + } staticfile; }; } GuestFD; @@ -35,6 +39,6 @@ void dealloc_guestfd(int guestfd); GuestFD *get_guestfd(int guestfd); void associate_guestfd(int guestfd, int hostfd); -void init_featurefile_guestfd(int guestfd); +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 c092138031..c6bfd4d1ba 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -553,13 +553,13 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } -static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ @@ -568,7 +568,7 @@ static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, return set_swi_errno(cs, -1); } -static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; @@ -582,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, } for (i = 0; i < len; i++) { - if (gf->featurefile_offset >= sizeof(featurefile_data)) { + if (gf->staticfile.off >= gf->staticfile.len) { break; } - s[i] = featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } unlock_user(s, buf, len); @@ -595,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, return len - i; } -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset = offset; + gf->staticfile.off = offset; return 0; } -static uint32_t featurefile_flenfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return sizeof(featurefile_data); + return gf->staticfile.len; } typedef struct GuestFDFunctions { @@ -638,13 +638,13 @@ static const GuestFDFunctions guestfd_fns[] = { .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, - [GuestFDFeatureFile] = { - .closefn = featurefile_closefn, - .writefn = featurefile_writefn, - .readfn = featurefile_readfn, - .isattyfn = featurefile_isattyfn, - .seekfn = featurefile_seekfn, - .flenfn = featurefile_flenfn, + [GuestFDStatic] = { + .closefn = staticfile_closefn, + .writefn = staticfile_writefn, + .readfn = staticfile_readfn, + .isattyfn = staticfile_isattyfn, + .seekfn = staticfile_seekfn, + .flenfn = staticfile_flenfn, }, }; @@ -765,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno = EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e77265db0f..b6405f5663 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -94,13 +94,15 @@ void associate_guestfd(int guestfd, int hostfd) gf->hostfd = hostfd; } -void init_featurefile_guestfd(int guestfd) +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) { GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDFeatureFile; - gf->featurefile_offset = 0; + gf->type = GuestFDStatic; + gf->staticfile.data = data; + gf->staticfile.len = len; + gf->staticfile.off = 0; } /* From patchwork Sat Apr 30 13:28:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568117 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7214006map; Sat, 30 Apr 2022 06:44:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4Ybc6wG9YKssKJ2jn2EHTN8xk70mdNoQeWWCL0Ow0cWC92q5/PfpeNTqkZbNwUaqAR3Tp X-Received: by 2002:a0c:b2d3:0:b0:45a:8430:1735 with SMTP id d19-20020a0cb2d3000000b0045a84301735mr48725qvf.110.1651326291526; Sat, 30 Apr 2022 06:44:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326291; cv=none; d=google.com; s=arc-20160816; b=xLme+wQlmzDTI9TnJHKX/dd7MqV3Mi6iwHb8XdS3mTmklH1bFG/xSawmrfioVQXe1Y 8Ewp1Hisr9TVCU07dxgUeQ7Rxy502TzI1f5ppJ2BjVS6Bty4zhPa8Jfh/sfEzD7/AFDT xzViM0QLxRArcDGiX0OFO0iVtdZjL+n6owoQmOPcAlc76krCmXWksLppjyVvEUiQGVS7 Tp11TGSM8INqT9ATCDEKoT6+ZH4hMTPGogOV8OfAAdtm+GUwlVLIJvlfACgoiviw4o2l TWNx+/NatlEyYrg94CD9Ser5VM0I8NwLZ+i1tcfNunZqmTgjmbl8wxVwPE2u3XUVzYGT 6u4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=lOqNzv31mq2KqN+zCyGjRxjuholC5hnUkfTDwKVT+OI=; b=N8phOOvruyHpEIgyZ7tYz9abK6a1D4oGYlYd7fmtzL8Dd+S413CmcwM2tJH1H/zLSJ jc1xcsFhfYES4e/xEPvJIoSsrLv1UYJgjtvBNY2zR5FpVA2mEnyERnCeOSXCn8Yx2HYa B58vBbC7XhtsTxRa7VbDnpUdNCZTpPq18Vwo0R1NfIe8zdMxeZRDn0hvpHgY0KQKYHLt YaZSL3Rav6cwnIhPGtC1Fapz60n7cxxlMUBlFjUURojYxl8x09NJ70pYvNujlBVdDzX2 Ab3kzaM+6MZZkLHIekR4ckVB0zKGLNDTr/lSAkHt7HWhpcNo9Y0GQthZGSureVkHUmWX JdBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KPLaciiU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c2-20020a056214224200b0045a5d04539dsi1303904qvc.99.2022.04.30.06.44.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:44:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KPLaciiU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknP1-0000H0-13 for patch@linaro.org; Sat, 30 Apr 2022 09:44:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAS-0004lp-RY for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:51 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:38424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAO-0006FG-IZ for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:48 -0400 Received: by mail-pl1-x636.google.com with SMTP id n18so9306418plg.5 for ; Sat, 30 Apr 2022 06:29: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=lOqNzv31mq2KqN+zCyGjRxjuholC5hnUkfTDwKVT+OI=; b=KPLaciiU+8VwUO1jdxQtHQ2n9SSYCINHcYzHkIJ+/5eaClbDO4/5C4eRgjho53IZ9S 7Ou7BV6wdEhzcIXsb+h+9FypHWh0phiu55aXzyggZzXjnZdfxugxUfWBrZyRMxyFhNSN 51AlUvVJpRckY+gcZioOvyughCr3NEN4NBLhBu9XCECs4W+bq7+3M58VGOQ9rYq+FDyL l5GMCw0SZg2sp2601o2ePJ/mOkj+pwk980swOVuQm5YqiehKurX4oUzpYSQxKYWi2uIo mN2YSatHrKWBQZ7rldjwjuNwabw4RL0grytVXpgaZWRzIys+H+yZeGIlsxzkbMfibdhS vQ1w== 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=lOqNzv31mq2KqN+zCyGjRxjuholC5hnUkfTDwKVT+OI=; b=pWbZlTpLa9dwywqHJ0Kj52oORxVjnVySSuWlxaN/FotF8B0he5UWOJoiOPTBZVNZze w7Xs43oCT7CY5lk3APLDS1n12w8wx45MbkIwN3PPQdh50mklDxlIMJ2KtwXURnlpe24z /Ra6jbB0m0HSP/Aq1y+cPxydzsqDRV9sWHTuTJIuu1undLc350PXika/xplEb+cF8pcx OIxMvuJccxIlP3Jkn/Q0HSG5ar5GtEGncpYzDKKsIQW+GqvI7522WyuRQcJ0K67OSIlf HH1mzzbTPHUgZv5ZgqMsj/QwmK4IET2KKv/Fj5veJ5n4DcBMXqCmpOrO+ArhrnYhpUKY uHEw== X-Gm-Message-State: AOAM530rvSMKzwHbncmwp6cAhluPappNU5Pqaqo/uL5mIOhrhv/lnN8R NmuQFoUs+VnzyDL4EnXS3IdcxbGJvkdZ/Q== X-Received: by 2002:a17:90a:408f:b0:1d1:d1ba:2abb with SMTP id l15-20020a17090a408f00b001d1d1ba2abbmr9127840pjg.152.1651325382807; Sat, 30 Apr 2022 06:29:42 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/43] semihosting: Return void from do_common_semihosting Date: Sat, 30 Apr 2022 06:28:58 -0700 Message-Id: <20220430132932.324018-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Perform the cleanup in the FIXME comment in common_semi_gdb_syscall. Do not modify guest registers until the syscall is complete, which in the gdbstub case is asynchronous. In the synchronous non-gdbstub case, use common_semi_set_ret to set the result. Merge set_swi_errno into common_semi_cb. Rely on the latter for combined return value / errno setting. Signed-off-by: Richard Henderson --- semihosting/common-semi.h | 2 +- linux-user/aarch64/cpu_loop.c | 2 +- linux-user/arm/cpu_loop.c | 2 +- linux-user/riscv/cpu_loop.c | 2 +- semihosting/arm-compat-semi.c | 571 ++++++++++++++++------------------ target/arm/helper.c | 4 +- target/arm/m_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- 8 files changed, 278 insertions(+), 309 deletions(-) diff --git a/semihosting/common-semi.h b/semihosting/common-semi.h index 0bfab1c669..0a91db7c41 100644 --- a/semihosting/common-semi.h +++ b/semihosting/common-semi.h @@ -34,6 +34,6 @@ #ifndef COMMON_SEMI_H #define COMMON_SEMI_H -target_ulong do_common_semihosting(CPUState *cs); +void do_common_semihosting(CPUState *cs); #endif /* COMMON_SEMI_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 3b273f6299..f7ef36cd9f 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -154,7 +154,7 @@ void cpu_loop(CPUARMState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case EXCP_SEMIHOST: - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; case EXCP_YIELD: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index d950409d5b..c0790f3246 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -449,7 +449,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SEMIHOST: - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 29084c1421..bffca7db12 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -81,7 +81,7 @@ void cpu_loop(CPURISCVState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case RISCV_EXCP_SEMIHOST: - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; default: diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index c6bfd4d1ba..7030dfd587 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -261,20 +261,6 @@ static target_ulong syscall_err; #include "semihosting/softmmu-uaccess.h" #endif -static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) -{ - if (code == (uint32_t)-1) { -#ifdef CONFIG_USER_ONLY - TaskState *ts = cs->opaque; - - ts->swi_errno = errno; -#else - syscall_err = errno; -#endif - } - return code; -} - static inline uint32_t get_swi_errno(CPUState *cs) { #ifdef CONFIG_USER_ONLY @@ -290,28 +276,29 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - target_ulong reg0 = common_semi_arg(cs, 0); - if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); - reg0 = ret; +#ifdef CONFIG_USER_ONLY + TaskState *ts = cs->opaque; + ts->swi_errno = err; +#else + syscall_err = err; +#endif } else { /* Fixup syscalls that use nonstardard return conventions. */ + target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 = common_semi_syscall_len - ret; + ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: - reg0 = 0; + ret = 0; break; default: - reg0 = ret; break; } } - common_semi_set_ret(cs, reg0); + common_semi_set_ret(cs, ret); } static target_ulong common_semi_flen_buf(CPUState *cs) @@ -351,9 +338,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, (uint8_t *)&size, 4, 0); size = be32_to_cpu(size); + common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); - errno = err; - set_swi_errno(cs, -1); } static int common_semi_open_guestfd; @@ -362,64 +348,32 @@ static void common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); dealloc_guestfd(common_semi_open_guestfd); } else { associate_guestfd(common_semi_open_guestfd, ret); ret = common_semi_open_guestfd; } - common_semi_set_ret(cs, ret); -} - -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); + common_semi_cb(cs, ret, err); } /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all - * do the work and return the required return value for the guest, - * setting the guest errno if appropriate. + * do the work and return the required return value to the guest + * via common_semi_cb. */ -typedef uint32_t sys_closefn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset); -typedef uint32_t sys_flenfn(CPUState *cs, GuestFD *gf); +typedef void sys_closefn(CPUState *cs, GuestFD *gf); +typedef void sys_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); +typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); +typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static uint32_t host_closefn(CPUState *cs, GuestFD *gf) +static void host_closefn(CPUState *cs, GuestFD *gf) { + int ret; /* * Only close the underlying host fd if it's one we opened on behalf * of the guest in SYS_OPEN. @@ -427,113 +381,106 @@ static uint32_t host_closefn(CPUState *cs, GuestFD *gf) if (gf->hostfd == STDIN_FILENO || gf->hostfd == STDOUT_FILENO || gf->hostfd == STDERR_FILENO) { - return 0; + ret = 0; + } else { + ret = close(gf->hostfd); } - return set_swi_errno(cs, close(gf->hostfd)); + common_semi_cb(cs, ret, ret ? errno : 0); } -static uint32_t host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_READ, buf, len, 1); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* Return bytes not written on error */ - return len; + if (s) { + ret = write(gf->hostfd, s, len); + unlock_user(s, buf, 0); + if (ret == (uint32_t)-1) { + ret = 0; + } } - ret = set_swi_errno(cs, write(gf->hostfd, s, len)); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not written */ - return len - ret; + /* Return bytes not written, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_WRITE, buf, len, 0); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* return bytes not read */ - return len; + if (s) { + do { + ret = read(gf->hostfd, s, len); + } while (ret == -1 && errno == EINTR); + unlock_user(s, buf, len); + if (ret == (uint32_t)-1) { + ret = 0; + } } - do { - ret = set_swi_errno(cs, read(gf->hostfd, s, len)); - } while (ret == -1 && errno == EINTR); - unlock_user(s, buf, len); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not read */ - return len - ret; + /* Return bytes not read, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_isattyfn(CPUState *cs, GuestFD *gf) +static void host_isattyfn(CPUState *cs, GuestFD *gf) { - return isatty(gf->hostfd); + common_semi_cb(cs, isatty(gf->hostfd), 0); } -static uint32_t host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - uint32_t ret = set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)); - if (ret == (uint32_t)-1) { - return -1; - } - return 0; + off_t ret = lseek(gf->hostfd, offset, SEEK_SET); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); } -static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) +static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; - uint32_t ret = set_swi_errno(cs, fstat(gf->hostfd, &buf)); - if (ret == (uint32_t)-1) { - return -1; + + if (fstat(gf->hostfd, &buf)) { + common_semi_cb(cs, -1, errno); + } else { + common_semi_cb(cs, buf.st_size, 0); } - return buf.st_size; } -static uint32_t gdb_closefn(CPUState *cs, GuestFD *gf) +static void gdb_closefn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "close,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); } -static uint32_t gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "write,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "read,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_isattyfn(CPUState *cs, GuestFD *gf) +static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "isatty,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static uint32_t gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - return common_semi_gdb_syscall(cs, common_semi_cb, "lseek,%x,%x,0", - gf->hostfd, offset); + gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); } -static uint32_t gdb_flenfn(CPUState *cs, GuestFD *gf) +static void gdb_flenfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); + gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, common_semi_flen_buf(cs)); } #define SHFB_MAGIC_0 0x53 @@ -553,63 +500,57 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) +static void staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ - - errno = EBADF; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EBADF); } -static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t i; + uint32_t i = 0; char *s; (void) env; /* Used in arm softmmu lock_user implicitly */ s = lock_user(VERIFY_WRITE, buf, len, 0); - if (!s) { - return len; - } - - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; + if (s) { + for (i = 0; i < len; i++) { + if (gf->staticfile.off >= gf->staticfile.len) { + break; + } + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; + unlock_user(s, buf, len); } - unlock_user(s, buf, len); - /* Return number of bytes not read */ - return len - i; + common_semi_cb(cs, len - i, 0); } -static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) +static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset) +static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { gf->staticfile.off = offset; - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) +static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return gf->staticfile.len; + common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { @@ -668,13 +609,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ } \ } \ } while (0) @@ -694,7 +635,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env) * leave the register unchanged. We use 0xdeadbeef as the return value * when there isn't a defined return value for the call. */ -target_ulong do_common_semihosting(CPUState *cs) +void do_common_semihosting(CPUState *cs) { CPUArchState *env = cs->env_ptr; target_ulong args; @@ -714,32 +655,23 @@ target_ulong do_common_semihosting(CPUState *cs) switch (nr) { case TARGET_SYS_OPEN: { - int guestfd; + int ret, err = 0; + int hostfd; GET_ARG(0); GET_ARG(1); GET_ARG(2); s = lock_user_string(arg0); if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } if (arg1 >= 12) { unlock_user(s, arg0, 0); - errno = EINVAL; - return set_swi_errno(cs, -1); - } - - guestfd = alloc_guestfd(); - if (guestfd < 0) { - unlock_user(s, arg0, 0); - errno = EMFILE; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EINVAL); + break; } if (strcmp(s, ":tt") == 0) { - int result_fileno; - /* * We implement SH_EXT_STDOUT_STDERR, so: * open for read == stdin @@ -747,63 +679,67 @@ target_ulong do_common_semihosting(CPUState *cs) * open for append == stderr */ if (arg1 < 4) { - result_fileno = STDIN_FILENO; + hostfd = STDIN_FILENO; } else if (arg1 < 8) { - result_fileno = STDOUT_FILENO; + hostfd = STDOUT_FILENO; } else { - result_fileno = STDERR_FILENO; + hostfd = STDERR_FILENO; } - associate_guestfd(guestfd, result_fileno); - unlock_user(s, arg0, 0); - return guestfd; - } - if (strcmp(s, ":semihosting-features") == 0) { - unlock_user(s, arg0, 0); + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); + } else if (strcmp(s, ":semihosting-features") == 0) { /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */ if (arg1 != 0 && arg1 != 1) { - dealloc_guestfd(guestfd); - errno = EACCES; - return set_swi_errno(cs, -1); - } - staticfile_guestfd(guestfd, featurefile_data, - sizeof(featurefile_data)); - return guestfd; - } - - if (use_gdb_syscalls()) { - common_semi_open_guestfd = guestfd; - ret = common_semi_gdb_syscall(cs, common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - } else { - ret = set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); - if (ret == (uint32_t)-1) { - dealloc_guestfd(guestfd); + ret = -1; + err = EACCES; } else { - associate_guestfd(guestfd, ret); - ret = guestfd; + ret = alloc_guestfd(); + staticfile_guestfd(ret, featurefile_data, + sizeof(featurefile_data)); + } + } else if (use_gdb_syscalls()) { + unlock_user(s, arg0, 0); + common_semi_open_guestfd = alloc_guestfd(); + gdb_do_syscall(common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg2 + 1, + gdb_open_modeflags[arg1]); + break; + } else { + hostfd = open(s, open_modeflags[arg1], 0644); + if (hostfd < 0) { + ret = -1; + err = errno; + } else { + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); } } unlock_user(s, arg0, 0); - return ret; + common_semi_cb(cs, ret, err); + break; } + case TARGET_SYS_CLOSE: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } - - ret = guestfd_fns[gf->type].closefn(cs, gf); + guestfd_fns[gf->type].closefn(cs, gf); dealloc_guestfd(arg0); - return ret; + break; + case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(cs->env_ptr, args); - return 0xdeadbeef; + common_semi_set_ret(cs, 0xdeadbeef); + break; + case TARGET_SYS_WRITE0: - return qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(cs->env_ptr, args); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); @@ -812,11 +748,11 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].writefn(cs, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); @@ -825,129 +761,150 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(cs->env_ptr); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_ISERROR: GET_ARG(0); - return (target_long) arg0 < 0 ? 1 : 0; + common_semi_set_ret(cs, (target_long)arg0 < 0); + break; + case TARGET_SYS_ISTTY: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].isattyfn(cs, gf); + break; - return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].seekfn(cs, gf, arg1); + break; - return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].flenfn(cs, gf); + break; - return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: + { + int len; + char *p; + GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), - (int) (arg1 & 0xff)) < 0) { - return -1; - } - ul_ret = (target_ulong) -1; - + len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff); /* Make sure there's enough space in the buffer */ - if (strlen(s) < arg2) { - char *output = lock_user(VERIFY_WRITE, arg0, arg2, 0); - strcpy(output, s); - unlock_user(output, arg0, arg2); - ul_ret = 0; + if (len < 0 || len >= arg2) { + common_semi_set_ret(cs, -1); + break; } + p = lock_user(VERIFY_WRITE, arg0, len, 0); + if (!p) { + goto do_fault; + } + memcpy(p, s, len + 1); + unlock_user(p, arg0, len); free(s); - return ul_ret; + common_semi_set_ret(cs, 0); + break; + } + case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - ret = common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, remove(s)); - unlock_user(s, arg0, 0); + gdb_do_syscall(common_semi_cb, "unlink,%s", + arg0, (int)arg1 + 1); + break; } - return ret; + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = remove(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); + break; + case TARGET_SYS_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, - (int)arg3 + 1); + gdb_do_syscall(common_semi_cb, "rename,%s,%s", + arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); } else { char *s2; + s = lock_user_string(arg0); - s2 = lock_user_string(arg2); - if (!s || !s2) { - errno = EFAULT; - ret = set_swi_errno(cs, -1); - } else { - ret = set_swi_errno(cs, rename(s, s2)); + if (!s) { + goto do_fault; } - if (s2) - unlock_user(s2, arg2, 0); - if (s) + s2 = lock_user_string(arg2); + if (!s2) { unlock_user(s, arg0, 0); - return ret; + goto do_fault; + } + ret = rename(s, s2); + unlock_user(s2, arg2, 0); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); } + break; + case TARGET_SYS_CLOCK: - return clock() / (CLOCKS_PER_SEC / 100); + common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100)); + break; + case TARGET_SYS_TIME: - return set_swi_errno(cs, time(NULL)); + ul_ret = time(NULL); + common_semi_cb(cs, ul_ret, ul_ret == -1 ? errno : 0); + break; + case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "system,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, system(s)); - unlock_user(s, arg0, 0); - return ret; + gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); + break; } + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = system(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); + break; + case TARGET_SYS_ERRNO: - return get_swi_errno(cs); + common_semi_set_ret(cs, get_swi_errno(cs)); + break; + case TARGET_SYS_GET_CMDLINE: { /* Build a command-line from the original argv. @@ -998,22 +955,20 @@ target_ulong do_common_semihosting(CPUState *cs) if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - errno = E2BIG; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, E2BIG); + break; } /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Lock the buffer on the ARM side. */ output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); if (!output_buffer) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Copy the command-line arguments. */ @@ -1028,9 +983,8 @@ target_ulong do_common_semihosting(CPUState *cs) if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - errno = EFAULT; - status = set_swi_errno(cs, -1); - goto out; + unlock_user(output_buffer, arg0, 0); + goto do_fault; } /* Separate arguments by white spaces. */ @@ -1043,9 +997,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]; @@ -1102,12 +1057,13 @@ target_ulong do_common_semihosting(CPUState *cs) if (fail) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } } - return 0; + common_semi_set_ret(cs, 0); } + break; + case TARGET_SYS_EXIT: case TARGET_SYS_EXIT_EXTENDED: if (common_semi_sys_exit_extended(cs, nr)) { @@ -1137,6 +1093,7 @@ target_ulong do_common_semihosting(CPUState *cs) } gdb_exit(ret); exit(ret); + case TARGET_SYS_ELAPSED: elapsed = get_clock() - clock_start; if (sizeof(target_ulong) == 8) { @@ -1145,10 +1102,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 @@ -1157,16 +1118,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 63397bbac1..748bb843e5 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10195,13 +10195,13 @@ static void handle_semihosting(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%" PRIx64 "\n", env->xregs[0]); - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; } } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index a740c3e160..308610f6b4 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2373,7 +2373,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) "...handling as semihosting call 0x%x\n", env->regs[0]); #ifdef CONFIG_TCG - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); #else g_assert_not_reached(); #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e1aa4f2097..55105cb0cc 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1345,7 +1345,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (cause == RISCV_EXCP_SEMIHOST) { if (env->priv >= PRV_S) { - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; return; } From patchwork Sat Apr 30 13:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568113 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7212309map; Sat, 30 Apr 2022 06:42:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzltNTgDjX9gfNXiduKaDKHKGRD4hR8cLwPr/EpY3tX5ERK/K8zrQz84djhBCVunZwwaqd/ X-Received: by 2002:a05:620a:2886:b0:699:bab7:ae78 with SMTP id j6-20020a05620a288600b00699bab7ae78mr2697796qkp.618.1651326124572; Sat, 30 Apr 2022 06:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326124; cv=none; d=google.com; s=arc-20160816; b=MD0fe+bAdzSDoZQhHJj50xUA0TtoMT2EKHWOyY88wT2WiLH3c0zQmGeMjLXqKkONdp tC1Hl2fBY0OmJDMI0yuwOJ9vA3y57abPu2wcrE9b006SFRGXrk8HFBxJHcaY3VJ0/K/z UuudS832zm84hHq1+hJybDwLpH2hqJepc71n+YCeEhEWr/MrfnqYtY33W6ezeyLTtSO+ 660AMsm7f9+WUR/QOihKSSIPA3miUvE1KpE7wc/n/2F6Dsxg8Kzu5l1D8+2sLicnTj3W VEf99LJQ4NZZnamYEt0gkt4HMhO0M1PPFDVdK+nGC0FD7gusLy6l4zcOaGwVZY+59rlC fndw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=N0GDL08w1rW3vQh6aFiM93TfqRB/5oBCbPaVJUzJGP/vg68ksCub5hg4107ttOxkXt HlXcPj+P0E7sf8tg5A75ZH8n/g2G9nwJ/vKbLlbtLVizyGpvhhu+FKTBRRbpypb1DQv+ T7DJZrTPKGnopp5ua02PmcRlxyR7bEUIVHkxB66PIbCbzZjpncgL1OUYz8E+SNYqVIWW tQldxoVzyD+9sdp/J5ry2Pqqjs2z/Z3fM5NJEMhviCHw8rj9CQrY1xZsk9+Ya6kKEZlV z+XCbFu4R8Un3UvPmAq0QPSbgZrTBAIv2jq/tHOBUsYMjMX9AiunjzuMJHFG5zH7QNCV lZkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lw3NyF6I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g6-20020ac87f46000000b002ed4ce50c88si4219877qtk.744.2022.04.30.06.42.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lw3NyF6I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMK-0002xk-2l for patch@linaro.org; Sat, 30 Apr 2022 09:42:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAQ-0004kt-NF for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:48 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:36633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAP-0006FT-7y for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:46 -0400 Received: by mail-pf1-x436.google.com with SMTP id z16so9064062pfh.3 for ; Sat, 30 Apr 2022 06:29: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=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=lw3NyF6Inbo1gdkr9ggQWtGFKq2paJ9og67ZfLZtuqvhyAlw7Fm1+vPwZSCwTlnUBr Nawh5+jJzZFO637zWxDoVUbHK3adaTIuWd7uj9zhQQAu/A7qW+LWFvPmEY9bT5gm+Kx2 OUVmY4ZgH1KzO4uG8+3cFAsFYdQmACT8xfau1QEEJVdoK1wV/x79Vkjo4zNb6hHoMU6B ybpapnsYeLHygDM4X2srnsErd1Ut7ghK58J7yio+S5h+X49eRsIxp93RciWZnrYO61HF KsDcZHZOR/RQ39hml1/Y+8EBwmkywUEgUPGiF+0D22vyRPBbFq7Hw5XNZ5+KS7zsRz/h yUDQ== 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=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=NDoIHr1cawHI/MZoJFeRUUj2Fh6xBAsYX6WQlE4nD+S9X4JnYQufHt7olTQtCHn0A+ RwTwp86MuOUTEnw01/wTF2Z7WLHSMC/RbMz6wQjNWCXjNmoQWtpOa/5MwnXHS6VmRgAA azV02OTEqpQyu4+vcSYEYm5VC2Y1+LQHItbcjOhOqZWoMYBzy8ViTd2HewF+jHCY5547 QeI4uf3NAsvcGBQLczmpX4ltvRZ4uemsGmSksTPYn3OId+1xxpbrwex0HXSf46Gs9cc6 yqb67azDu/zZQO7tDVOj1tX5s5mkn9NKPQfYPHCdmSn7tO7/eIuN4eroIr53IKTElKdq QZmw== X-Gm-Message-State: AOAM531YM/CVMXj46Rl2b4c2VMLlmyKyQukrzg/FHevKfC0W0ox3n4YJ 9DwHfsQk+JWSzjWsKOyYKs5YR/cnSmdDGA== X-Received: by 2002:a63:2305:0:b0:39d:1299:29c9 with SMTP id j5-20020a632305000000b0039d129929c9mr3173032pgj.244.1651325384006; Sat, 30 Apr 2022 06:29:44 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 10/43] semihosting: Adjust error checking in common_semi_cb Date: Sat, 30 Apr 2022 06:28:59 -0700 Message-Id: <20220430132932.324018-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The err parameter is non-zero if and only if an error occured. Use this instead of ret == -1 for determining if we need to update the saved errno. This fixes the errno setting of SYS_ISTTY, which returns 0 on error, not -1. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7030dfd587..18664b1c47 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -276,7 +276,7 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - if (ret == (target_ulong)-1) { + if (err) { #ifdef CONFIG_USER_ONLY TaskState *ts = cs->opaque; ts->swi_errno = err; From patchwork Sat Apr 30 13:29:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568105 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7209186map; Sat, 30 Apr 2022 06:36:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT/Ag9hMNxZhSXPBgEEfyoCFcMAv4sYwRtB6QMsO2cOw+VgIqyBUDzDq5zlykyJOIZB4yf X-Received: by 2002:a05:620a:2a08:b0:69e:e79a:16b1 with SMTP id o8-20020a05620a2a0800b0069ee79a16b1mr2824377qkp.784.1651325801883; Sat, 30 Apr 2022 06:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325801; cv=none; d=google.com; s=arc-20160816; b=G77ZZI7fAzXRSontGR6kt57YoYEcAhUYsvfj8lB8s11W3tZL7JwRTsD+qL+VwxSict hYmGRa6c18sQaxPYehWVuX20/Gm3UdGtIs+wfb5GVsfXRy3R/WwiqJqOcEzndDAqrLOU xRXpUVHVKGD5vzIG8MsTml5KjqKfMXYHKnCHiFvBvDU5RevFKB8pYWXBQPvIYqygLkBr BqFzj2C51oRc6S7+QoIGmtvUBmacuLl15iDUAH2elOUypyS8AIPi+vlXChgNAfC0gvma RCUrzCXQFgJnPBwMl8/pHfqsx5iTXpQNck1VSwO+0ORzHkvR/pRQFc8jHC1mxkvoJyHc lPgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=M/7PWCA6lh4exK4u993PNvEM3xwc1Fq0u1frcI5X2ue7m8YgkAE48tD52VFumIEO45 YltEW2xTqT5SZcb6WApa7/ba/h4HJ9/9Cg5bu88LDrIG6jssccA2Fybtk9bwTIhPogy+ dER37nc3SeIq3jSbQAEGM9UfxL8S0mQahCci/LwsNFmz9UQlui0sF9ApQ1Lao/gAjp4A io6LkmL8UZj8QjCMjI8c0jd0AbMMrtnusJgKOGIkjieAWBJite/ySy/TUqauB5opfTjp j/eDMPTja0/AyokZPxoAqN/i8twczpuYpRO4FNOqrme8eOiir+D/eh2pUb5Ly+9EAIv2 Ipsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HAx+YPki; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y29-20020a0ca91d000000b004564dae347dsi3679208qva.222.2022.04.30.06.36.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:36:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HAx+YPki; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknH7-0008A6-GN for patch@linaro.org; Sat, 30 Apr 2022 09:36:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAS-0004lG-Kp for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:50 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:44551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAQ-0006Fg-EU for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:47 -0400 Received: by mail-pl1-x635.google.com with SMTP id j8so9281337pll.11 for ; Sat, 30 Apr 2022 06:29:45 -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=HAx+YPkiYyRIhAAqjYCxbpCV7g7KVy9FXEEbboCUJhcrIENrwnHNYb0SgP7GTn0iB3 yj2F87v6NfR9LR3kBGMJ5t7ogGFktUd7VHozzjmrYEySynnaiRqvdZYmldlGPFlH1Kb7 88lT6axf+8XAbvUOLOHwdWQQaRIGCbSK8XtHGqyV1CGGpdTP6xDZZejuU/ubvQ0jMLYd pk+gidvQLX3nUP9G/IC2BKZuDyt1cq4PpWW+gYd8QITm4RVrweUkDIr+27imLv7XFgin jFy0TkHuDe2ePeZqi/wB0VsnQM5BbzUZTJqePA0+7rg7iqUE4RRNBFqF+esgekq4V8Ls wq8Q== 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=LJMOVz03pmNWW1QMRhYMUDiQEpcq2P6hN+Ag4ecMtvdnbKvkK5FjYerjlZI4dY25Kb Tj6/dQbgnDZLxMjrgtawOTtMtwrruEztq3QmHfnrA08Oo8nvwiyKZzcaWYi3/zex0aco txLtF3wf+LglYR/5PVw+sxAw2GiExQN8xjz7ZBFQ0j+eslGcJYHW6MNQnVzsCBF1fJ7I 95QQLOpM2hXmypoHJGiqVd3ogOpMNeTaEEcKM81ounOu3WZ1tE68/aQ9v/964rwbzaKz lxQD4z3NEIaO6OvOROR3nllj3rBOPVP6Q5GQEbhfmIeh5EY8RiseDDezi2261lNIgewi WwRQ== X-Gm-Message-State: AOAM531cmJ2DVxhxM5XsJY/T/klv3uLiIw6aH8erfu6E25XdmKPcEjLH NtwaxP/JJj62ggEa+qD9Vt9wYBp6bGSR+w== X-Received: by 2002:a17:902:ecd1:b0:15e:850b:c2d with SMTP id a17-20020a170902ecd100b0015e850b0c2dmr3904863plh.75.1651325385043; Sat, 30 Apr 2022 06:29:45 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/43] semihosting: Move common-semi.h to include/semihosting/ Date: Sat, 30 Apr 2022 06:29:00 -0700 Message-Id: <20220430132932.324018-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This header is not private to the top-level semihosting directory, so place it in the public include directory. Signed-off-by: Richard Henderson --- {semihosting => include/semihosting}/common-semi.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {semihosting => include/semihosting}/common-semi.h (100%) diff --git a/semihosting/common-semi.h b/include/semihosting/common-semi.h similarity index 100% rename from semihosting/common-semi.h rename to include/semihosting/common-semi.h From patchwork Sat Apr 30 13:29:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568102 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7207580map; Sat, 30 Apr 2022 06:34:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL/oQXFnU+kLy4jgfrK3El0lvL+kpoLOlfZ6YgnN8UJKrgpBchq22sfNK/HhPBVUnrpXT+ X-Received: by 2002:a05:620a:4148:b0:69f:8e5e:1aa6 with SMTP id k8-20020a05620a414800b0069f8e5e1aa6mr2701595qko.145.1651325641444; Sat, 30 Apr 2022 06:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325641; cv=none; d=google.com; s=arc-20160816; b=J1HDNO7WRBr4KpRbk8FrQ30LMgbnwfdDGqe3CIicyBgvqDdTe8lr1NuFko/j2LiewD 9MqpkIrMYEkg5lOq0P4FwAgg5Xh1VX+YT5WmzlxQa2bnL7KvsrdP8SMJF6EGUbIHcWIk PKRM+xs6ASE3HlET9ECTYwHYHW3jQwD8EcFumSlaTSeGJKrd2CfuTcg2jtlyjDSGZJix NB28SEtZkz7wUNEJydqKiKIqtreEJMBLDvNzlGWCZ7wOsCdDt/9IE8Dxf93DD9rRFBgM bfA3lLvlRaqLoPmlXkvlxXy8/OkJ2DRiCP1TznaA8vQdv36+BmvBuRkWO1vxbsf/bq9s DQSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=sno2cpXAEPBRKluY2liaXmd/zMSe7Lnx0VLgdgqmo8MFHbFayRGBI+ylxiDtNS/9Dc rk2OdSbVkgAgRbeXOQhIPItbeOmEzvbdRWeNYWSt0xwJ4RQjkbi0qweEsIlj6dGMhEb0 j6rjpFDQDe5VkGjxlcGdkk7j7gy82gugh2A0w0FHI1Ek2b18iI4Cfuuccl1XkxmThLP4 jiTEHee4zj+5OW51xstXbf6Rm9MGIn5LqHi6DisqJ7mkBlv4DY+nq+U0L5WXCglCcgMH nynCme+IWs9tguZyxuy25NmBMvAhshR1RPCXmu4CsVU0x1BQHxq8MIHzQOvBzv+XBFJb waFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RfzRtCxs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f19-20020a05622a105300b002f3a096b445si72480qte.582.2022.04.30.06.34.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RfzRtCxs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknEX-0002WP-16 for patch@linaro.org; Sat, 30 Apr 2022 09:34:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAV-0004lz-PV for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:56 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:40844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAS-0006Fs-Cw for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:50 -0400 Received: by mail-pg1-x536.google.com with SMTP id x12so8498853pgj.7 for ; Sat, 30 Apr 2022 06:29: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=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=RfzRtCxsH4IeaViGLfCWF0KTgOoEuxAP7jHVJjcXz4dUV3sxHB33M427pKAzwQfSqU jWgkq+fO4hYsOkOld6pMdes03z1ZtdRZXPsNwPGcnnoFhgOvu29/U2gmCeujCassedda f+Cmp2QZ3Hps5hKZjYXC+TpN9ZwnM7+LSLnoA8f7uhavNKXGobDmkiwUZAtOoglUDd8Q rhCqa9OqoX+rkrguEXZaf4Y1O0r8+EZBH21BC7Bn0n+AJR4//uPa5ZJSHmQ3aOWgGTGB SsX8DMlN4hUuxn7JBXj92A1fOV56K8wgHfeE6jXfe69/Yi6Sd2h1ykbOqtvQf2EkiCyi uRgA== 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=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=Gt6v3GkJ3LLwZIScbxuEwlFs168U96XUPql+ltKS4KrHvI+YsvHZ9kd5wl2RtoNIIE W1VRCduqsZjo2B2yb9fDAPTsiHN8xthBE+JMsCrENr/DPNVgW6qUouSHC7Gbvq4rkSWz toQ7idR5S+JLcBP2HhuDYSXknsKEDhDBo1TEwEhAq0Lmgr8Jgt+P6zns/RGUfLtheuJc inFToKIQ1eVyGK6djLku7n8BKyFPSHOlBc+g3c9s7fOlf6Igx2HPWRgKNb8xMPpih5nz r8L7+UcIVSIF3mwk33OgTl8kopDNOnQ29kfN119RgOCNGrmOuYFP6iPqnT44LNYxYBKY +p5A== X-Gm-Message-State: AOAM530qZFcKxb+6Q27Gfq4qCmbybHPrIivJtd4nvyoSEDEsqBiVbxsz W63YG1YQkb44EqwPg2VkSHDiPuI8EyDBsw== X-Received: by 2002:a63:2b45:0:b0:3ab:971b:be5e with SMTP id r66-20020a632b45000000b003ab971bbe5emr3074271pgr.265.1651325386172; Sat, 30 Apr 2022 06:29:46 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 12/43] include/exec: Move gdb open flags to gdbstub.h Date: Sat, 30 Apr 2022 06:29:01 -0700 Message-Id: <20220430132932.324018-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There were 3 copies of these flags. Place them in the file with gdb_do_syscall, with which they belong. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 10 ++++++++++ semihosting/arm-compat-semi.c | 8 -------- target/m68k/m68k-semi.c | 8 -------- target/nios2/nios2-semi.c | 8 -------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c35d7334b4..2aaba9c723 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,16 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 +/* For gdb file i/o remote protocol open flags. */ +#define GDB_O_BINARY 0 +#define GDB_O_RDONLY 0 +#define GDB_O_WRONLY 1 +#define GDB_O_RDWR 2 +#define GDB_O_APPEND 8 +#define GDB_O_CREAT 0x200 +#define GDB_O_TRUNC 0x400 +#define GDB_O_EXCL 0x800 + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 18664b1c47..a1fc4ea039 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -86,14 +86,6 @@ #define O_BINARY 0 #endif -#define GDB_O_RDONLY 0x000 -#define GDB_O_WRONLY 0x001 -#define GDB_O_RDWR 0x002 -#define GDB_O_APPEND 0x008 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_BINARY 0 - static int gdb_open_modeflags[12] = { GDB_O_RDONLY, GDB_O_RDONLY | GDB_O_BINARY, diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index a31db38fc3..475a6b13b7 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -69,14 +69,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 373e6b9436..0eec1f9a1c 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -71,14 +71,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; From patchwork Sat Apr 30 13:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568112 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7212296map; Sat, 30 Apr 2022 06:42:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG9izHxN389zWyg537Cu7Jj8Zxx2e/a7mS46Oon5N1clOsoOzDL+8RAYStwp2cfx0P/7M5 X-Received: by 2002:ac8:5c50:0:b0:2f3:9def:5978 with SMTP id j16-20020ac85c50000000b002f39def5978mr1445498qtj.545.1651326123122; Sat, 30 Apr 2022 06:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326123; cv=none; d=google.com; s=arc-20160816; b=I7SWmaI0NA0YS4JhMTBh+v0mAMsnyTjoi0OQxADq7iR38eI4lQJhGQr7thtGBp4jmh F1MK64w/FEfrzVu7tQxoB488nmG22tpeCFblOA4NLeF5JeQYLgQqfu82GGZrlzPvGJbU iOBb6PxXvPTk1ELD4Msq1JUQzy7qyEzp6F+iRGB3XqjZWJNhY3uvvLG9uNpeukyWHlhi JQObuY++9KCTx4qqSJfnpbeMwxDWt/sSuWF4XDz1LCGbHVEZ+divT/26aBVWq2tukOOR yhv89588xnZ0Vr8h7dI09AEjLsfWc8XTDvS86I2wZ2zHXr0ycH0CsULd2RAbn2s51+9E fVUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=j4d/BMY45uBjpf3pge1UNt4X/SqhbAkZOsjy8rPqWiaKodNyB0l0P3mUPfxUrf2aU0 FjokS43jcpd4WJuNPhhNlSGOXs37d6D7Ara9JKk9EtJEum3KchwWh/zEafZ1TZccma3P Brz+q/Sw2+2NThlrt2mmAIafCeuDoiV4B968oXYmrfyNy3/Vb0354OGA0LLvU04eFsFv QPqGzstTpmF7mhBaTPhR4cLj1Re/VMBYMLNF8yWAil+F8/E0UlhPUQuwjMIanBPsOL3y Sweip3lRmT8cZ3Kht9UJ60p66rEWtu2nHppoVPRw84tGknFVpIDUGkPD5dEACuxmzy24 j9pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T7CoM01Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l28-20020a37f91c000000b0069ec0403643si3861018qkj.328.2022.04.30.06.42.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T7CoM01Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMI-0002qo-Ho for patch@linaro.org; Sat, 30 Apr 2022 09:42:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAV-0004ly-PM for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:56 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:39926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAS-0006Fz-K3 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:50 -0400 Received: by mail-pf1-x432.google.com with SMTP id y38so9057443pfa.6 for ; Sat, 30 Apr 2022 06:29: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=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=T7CoM01YNVS77MrHESTFuiw4aqmwC0ymAhMNvJ8+i0tbXf+K3pA8f0ePAKMceb86d9 2Mf4HrAytn2+htYPN10wWdEmIUyU12eDVCCim6DBt9e1JAfI32t15E3/Q/xbWC+aHWI5 2PVvZx6aX2lWfY7GVjK/QsOccg8TI8T+L9FjUjfNP/Qf8xOdhKVG34lXffc3zEsrOtEU 7jgNwujOeyHBZY93h9IrmrR6zoRXrD4eUEtnEHhlXzQE6ionDekajiqhOn1izKk6EGIq g0v25IuVblCCSSmgUEH1GHQ/LgHtZw3FI+QXvUV6NEhHLF+vp3Cx1CU5BWUnRjOR1e+K gtlg== 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=7v1dAOnr6NGo+WNIUFw6tZYrzu3EsixUOldUXwWBJTGPI3bnxH+nOjZ/I44R5ffNoB 6YesrwRnd3JpvQNBYf/iKlkpVEdfvG9bIjHngz9Dz3r53hCEn7YEYgR6mDXv/FXX3unj tFqQ5q/TVW+inOAzQKXwwlcirqF8yiSgf3ky6ddYArn9vjdkYINos8dhLnt9dUAyMhBk Py4GAdcwQu9Cp9r2nUlZHlukQjO4HIMzRT6sCEm2DmAm13XmL1pOi5sHxn3rZNa1YuY1 gHyF1gm7fwt6GkXeWv3lc1NJuIww452ez3hpUUbqk21wvaT2Rc9ijEomLKlqDrOjQ12F UJoQ== X-Gm-Message-State: AOAM532DXc1DtxPderP03ak5VXOVJokI+ztFl+nrJFI5uzobgp6EARrH f72UvgzHdKF9Ak6kR6hB1fyyFPewGALdzQ== X-Received: by 2002:a63:4d64:0:b0:39d:5e6e:242d with SMTP id n36-20020a634d64000000b0039d5e6e242dmr3193529pgl.32.1651325387237; Sat, 30 Apr 2022 06:29:47 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 13/43] include/exec: Move gdb_stat and gdb_timeval to gdbstub.h Date: Sat, 30 Apr 2022 06:29:02 -0700 Message-Id: <20220430132932.324018-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We have two copies of these structures, and require them in semihosting/ going forward. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 25 +++++++++++++++++++++++++ target/m68k/m68k-semi.c | 30 +++--------------------------- target/nios2/nios2-semi.c | 30 +++--------------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 2aaba9c723..33a262a5a3 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,31 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o stat/fstat. */ +typedef uint32_t gdb_mode_t; +typedef uint32_t gdb_time_t; + +struct gdb_stat { + uint32_t gdb_st_dev; /* device */ + uint32_t gdb_st_ino; /* inode */ + gdb_mode_t gdb_st_mode; /* protection */ + uint32_t gdb_st_nlink; /* number of hard links */ + uint32_t gdb_st_uid; /* user ID of owner */ + uint32_t gdb_st_gid; /* group ID of owner */ + uint32_t gdb_st_rdev; /* device type (if inode device) */ + uint64_t gdb_st_size; /* total size, in bytes */ + uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ + uint64_t gdb_st_blocks; /* number of blocks allocated */ + gdb_time_t gdb_st_atime; /* time of last access */ + gdb_time_t gdb_st_mtime; /* time of last modification */ + gdb_time_t gdb_st_ctime; /* time of last change */ +} QEMU_PACKED; + +struct gdb_timeval { + gdb_time_t tv_sec; /* second */ + uint64_t tv_usec; /* microsecond */ +} QEMU_PACKED; + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 475a6b13b7..da0186f3ef 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -45,30 +45,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct m68k_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -90,9 +66,9 @@ static int translate_openflags(int flags) static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) { - struct m68k_gdb_stat *p; + struct gdb_stat *p; - if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat), 0))) + if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) /* FIXME - should this return an error code? */ return; p->gdb_st_dev = cpu_to_be32(s->st_dev); @@ -114,7 +90,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); } static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 0eec1f9a1c..3e504a6c5f 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -47,30 +47,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct nios2_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -102,9 +78,9 @@ static int translate_openflags(int flags) static bool translate_stat(CPUNios2State *env, target_ulong addr, struct stat *s) { - struct nios2_gdb_stat *p; + struct gdb_stat *p; - p = lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0); + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); if (!p) { return false; @@ -128,7 +104,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct nios2_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); return true; } From patchwork Sat Apr 30 13:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568116 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7213972map; Sat, 30 Apr 2022 06:44:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8dd//Y69vvufy3iIZugPRyfOxV5IyZ6Jtw7DUsAORgKb6p8beK8Ytr0A5OMvsuUriQK+y X-Received: by 2002:a05:620a:2443:b0:69f:534:4a31 with SMTP id h3-20020a05620a244300b0069f05344a31mr2645570qkn.295.1651326287094; Sat, 30 Apr 2022 06:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326287; cv=none; d=google.com; s=arc-20160816; b=sKherrriEbnuOsFGygJiDwTKp3bdmlN3ppHIai75m5ruUhTkYDjbjZur9AupgFc0rc Xsrnk82atWocdPs9OSyGd0ReSN2D9iGpjucgirMgUqcHDzKpAPzFMxcKyc3GbW/eMb3G T+CH/X1UXKtOQ93V7NF50RxouHEpt8EIn8YVe3+yHoMxfozdTaA/uR30DkPjd6n44QNF 7vU5tFs0pozQJm4hFdnRivbPqrhzDfkBRliF8bPPOJjyEWHINLjuChLjtF+s3tuL4xkx h3HxhC1neA/VvwpZTue/peadIrcbIb+7PiAHYjwtnymc2hV9vWhwM3ZipqTWk+HVt+e1 iLJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=a9heLp7ebpydozyDipCEvgBTmD/ZEpv2/tEWVKMBkO0JiiMQ9bRCgblKDOWmUG8NF/ ZdfQkCiTs6sL9R9q1OXwcsra6OHYJWMan+K2zXdy06VPpzv6oofZLsSUbWp7aPkvccdC E/5U5lWVeeCu6MZVaTdAifwpK0gbO1zTYf2XPCuNalI2+EghPv3q/l0f0wht3ZO19Ges LqrYB7BerC9l3UkhThYwOWXiAzTY7DJAKY4/rvHcqrTyzrQrdlRatWE15hnDwX5dz4E+ Q9RNo9T/vg3O5x2jWan7SXKDt1GQF4ylfa74Qm+NsDcRfXWQWbLTbSjE1ej6MaqCdCDp TPRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ChK5vr3e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t21-20020a05620a451500b0069e5e06b268si4360637qkp.741.2022.04.30.06.44.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:44:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ChK5vr3e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknOw-0000Gd-KQ for patch@linaro.org; Sat, 30 Apr 2022 09:44:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAW-0004m1-Vq for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:56 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:56238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAU-0006GH-En for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:52 -0400 Received: by mail-pj1-x1032.google.com with SMTP id r9so9268316pjo.5 for ; Sat, 30 Apr 2022 06:29: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=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=ChK5vr3eOHg5pU/YPOL3rFg1JTC15gLm9KeQPS/myyU8REUWbhnS8WDWP8Ti6tYKXm PRfUtKpRftLaevTnosYCSDdZBsqJlQ+hv10ny6hzECh00NgMFGkDM+aDcqhlvfCsLZ9W C4Y98GOK/RxQ14L+Q7ILlHCv6h/tJ5lf4O4jADfr27MCUHLcZ4nW735Qton143QQugf8 /tBLKTqeqQ8XexfUr/e0cEdTX6cgc+LtVSR1sKVE/l+MHV4DXDIl9MSPm1OPV4n6gqZY +8F44MBYbqd/WsxElj+FEV/fdDgGqSVR6BVrkBoihaGtsv+csYGTPc7PBFGq5H9W9MfQ QOxw== 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=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=eMlFfoGjIpYWY/Ign/UNNqjZ6Ys7g3iS0elUuF7yQYCLR++O4WKnxXLtHnlqDdm1qw f1wZGHMJniZk9AY7p7cWW3ewDh0cfMsbgwAwWDAWwkLlZG02/ZPXkcWPLKMU1oL0KaPH 0H2Ja4CPNSUV5ugEKYZKLnBumXUfz+oMjQXnkNNCVVELbXjx+mRZEKUqWhP6xlKr5nch h0QogpNAofEyksblA1Kjsjn/1UXcUW/Xx+MszYF0P4+CKhahBDo7WANVYkHq8tyWZy8m wkz+QmRVlDqdGziSfWKAuFJe/3vCFidrbRsM5BjEwcX+WaP49QBDi8MF/26PPydP3FL9 +xFQ== X-Gm-Message-State: AOAM530uRzfMOw6zGrBMzi0+3GuUT6eYt1Z4FtaNJO3VmNe+mxe4pYzh hZ0GadyyXEPgttUpCtpUo4UMFjRE2Ak7TQ== X-Received: by 2002:a17:902:bb8d:b0:156:51a1:3f5a with SMTP id m13-20020a170902bb8d00b0015651a13f5amr3702184pls.65.1651325388263; Sat, 30 Apr 2022 06:29:48 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 14/43] semihosting: Use struct gdb_stat in common_semi_flen_cb Date: Sat, 30 Apr 2022 06:29:03 -0700 Message-Id: <20220430132932.324018-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use offsetof instead of an integer constant. Load the entire 64-bit size while we're at it. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index a1fc4ea039..a6c6e5baf6 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -324,12 +324,12 @@ static target_ulong common_semi_flen_buf(CPUState *cs) static void common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { - /* The size is always stored in big-endian order, extract - the value. We assume the size always fit in 32 bits. */ - uint32_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, - (uint8_t *)&size, 4, 0); - size = be32_to_cpu(size); + /* The size is always stored in big-endian order, extract the value. */ + uint64_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0); + size = be64_to_cpu(size); common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); } From patchwork Sat Apr 30 13:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568107 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7210570map; Sat, 30 Apr 2022 06:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+pJF2udyHbC08PhDVn4RlyAad5d8LReCsYUjelzwCBrhIfiJxSxJEASi+BSXacJiRsno4 X-Received: by 2002:a05:622a:1305:b0:2e1:e697:31e7 with SMTP id v5-20020a05622a130500b002e1e69731e7mr3412720qtk.97.1651325947271; Sat, 30 Apr 2022 06:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325947; cv=none; d=google.com; s=arc-20160816; b=RmZm0kr3oIew4+Qdu7Q2PqJDCP0TLYptJOZpm3PiW5qoKVPsNivW8GgHtBKoJ3vw/A bpngvIk4sYFEKFI7P1EZc5SgfCiIVJXObqeIyOG8/1/1yOWn6oOmXa407t6GjUP8mkdT f7L5VNPMvzWaaa7rJBe+5KP4p6YP1vBQGAIW3HOFkxz6j8eZXkhayJJ6j5Xcs2MAg9/k C2Wj0u4MMjWvui++N0X8VH/K14ArIm+PErZIfkVE9sUpwr+8RhWvL18tMWRZoPsFSRuI SQtxRxWTY1S2VrImvGuLhclaoVjZWLCvYELA5YshoiPyBIIOu2G/sP5tXCIdmXgwgMj/ 4rqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=rX9EKBeJ1FMchdvrqzihCHE2hSeH6cz/njv7XbIUPLtWGfYPyW51grEw1bIsUk1vg0 ETW5u+Sa4EG1awT4Np5SBjnMzISJs7cqsVfwRYk+Jr6ttTtajhH4iAgDQucfFXRtmTyP Jde0D3W9DHE93FI5/d7vGjuEI2RmTHKHkTikCmSj62JRrLdZiP7K32LkcBUHbWds7+2Y 2kJur3LLnJPfAePv9jL0FCiXA7Q+iOkmMwDgSRjVAGfC576WJ4wfUIQlCsLjNWE0rI5n GGdtFV34CvLrqTeqm9fevBBwgzEO7nRQ22tOazG3MvXW9cwJvyEZxQ3dLRPMFso7A8D4 Mrdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MYaCNupZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bn6-20020a056214148600b004444158f514si3341021qvb.80.2022.04.30.06.39.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MYaCNupZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknJS-0004zO-NR for patch@linaro.org; Sat, 30 Apr 2022 09:39:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAY-0004mB-Fl for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:46969) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAV-0006GP-IF for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:53 -0400 Received: by mail-pj1-x1031.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso4074301pjb.5 for ; Sat, 30 Apr 2022 06:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=MYaCNupZQcz9zdXBtHousQTz09lzKoi2dZ1ko0Snmyp28RtEpgk5d51uCvWhkykBMu f/55TT/wZpORgIk5nheoXb6iA3wFSvzfEkqAy8A+yiK+DlHb88L2r7QYj3ofh1hwMEwX ElwSQDiLBrpbgPHlZqQ5NWeSDn4J7ln/VvWlhQ0bcUKnVuZye4pSaHUQt4DjMeZ+fuE9 8/c82Mf12/dwfGUkrtcWVjXmBSgmteGRaFoxMKpRn9HPv7B8bRI4xAc88v3Nqmcjblg/ Lo3lZxJD+6/u1RvLpPLOzqzkLgPrz9EBfsXm3058ZJvOwgrQfRoD45v97bSlkihbVe0v QR3A== 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=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=n09o7FiLn+1rg0GNOZOq5CkpXbb+M9eQHxeK7ki35gq2uEs07RJQpqyzV45KjLtZ8L vlMnVamp984fj1+zog1q6lSjdY5HJc5/r5Y7NQpPzvzF5kLZZ0jKxJlR//MBETYvUrdJ tM+8p6HmMb+3RS0GmRYtfBi30ZhpSJ3/6N1QyuL8v4D8os9DZEoFx+s41V2uXEg2FUWw B23Wa7CSbCR46n0QEFXvhmeo4zvpnOfToL6ioqh0E+2ULhI5nQwaRnLM3Div3P/OgcUl kJMRk6cCggf6CJ2YksJpO+PkWBykEzFMD/KN6JLI/dbsnofOjHzA7qWaRn+4nfHxlq62 k9JQ== X-Gm-Message-State: AOAM533J0RonkSmWDM2yDSZd+WFym9oR7IXeZp07V0w5ahZ9/jW3jE3G ARby5Xd8UH2gJhhst919na4rNfM92g2uFA== X-Received: by 2002:a17:903:230f:b0:15e:6e55:3230 with SMTP id d15-20020a170903230f00b0015e6e553230mr3877760plh.35.1651325389346; Sat, 30 Apr 2022 06:29:49 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 15/43] semihosting: Split is_64bit_semihosting per target Date: Sat, 30 Apr 2022 06:29:04 -0700 Message-Id: <20220430132932.324018-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split the function into multiple implementations per arch. Signed-off-by: Richard Henderson --- 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 a6c6e5baf6..7fc60e223a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -213,6 +213,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -238,6 +242,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} #endif /* @@ -586,17 +594,6 @@ static const GuestFDFunctions guestfd_fns[] = { * call if the memory read fails. Eventually we could use a generic * CPUState helper function here. */ -static inline bool is_64bit_semihosting(CPUArchState *env) -{ -#if defined(TARGET_ARM) - return is_a64(env); -#elif defined(TARGET_RISCV) - return riscv_cpu_mxl(env) != MXL_RV32; -#else -#error un-handled architecture -#endif -} - #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ From patchwork Sat Apr 30 13:29:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568111 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7212237map; Sat, 30 Apr 2022 06:41:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7dlREBx5W7v6U9s6I4/6aYtlsoOWzKUvQwtT8er6I8v4z+VpJalkpaFy2ooJRHbDHObeI X-Received: by 2002:ac8:5c55:0:b0:2f3:72db:be46 with SMTP id j21-20020ac85c55000000b002f372dbbe46mr3373144qtj.669.1651326116555; Sat, 30 Apr 2022 06:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326116; cv=none; d=google.com; s=arc-20160816; b=zb4n06TrUrLUjXwsDED4Q6EPcEooNI3/VGOf3ad+Rp3JiN4ibKQwi6zYQucQDTJtJW 18CsblTjjQ5p1CjQ5cWUT79AAGuEu199I3veii+v87VgrUqObRKup07B9JGNSNAA5RTk TfnXM3evlW7cC7wHe7aUD4mzd4fCDAbP86Ugb70ffSPvH4eCs1Seb2b1wX9xhKdQ448r GNAE0oo8TapTyaA9qved6vh4BJ2XBxK325cqtDteYmS3ifU0v3Wzx9tyLE5zFHjR4E85 JGcWsczQpbgvcx3AAxqVAZSTLTLhoMO9GO8tBj6rce8L3MPcw2mok9iGW/DCBH3eLYKa ArEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=WyDfwF6Y1GBO/R/GkAlX4fnxnwz4v+KWu0hpL/+jD1x04/EtoW3gbPScnEPYyw4+XJ UJ14lhtNfN/oXe5CQ+jE/xJm2S7QUZbfQOroREtKfgj9Vsj3jqY46NDk+B9V0FOw2WB0 irt5tl/l67PbQxztRXq0BEYn+HQNoL/u69mkiX3z1bYJSJ/q+PZfyWoZ6W/X2r+cFDI4 jxTLPBDCTYoCxpQ9tfBdzWxzzIOLB16y5WRkSlkXcX/BbYr3JCkLr0jDPKUDP87g7l/+ Pt6BqoC5uVBPVZa4zJWEwsWxQM5p+5D7P5Hz8PbfOlcqiAjDgJLTNm7lapC2ZKIkOuW+ cEVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vKTw6K1p; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o14-20020a05622a008e00b002f39228d583si2277856qtw.490.2022.04.30.06.41.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vKTw6K1p; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMC-0002RP-3s for patch@linaro.org; Sat, 30 Apr 2022 09:41:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAY-0004mD-H3 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:40588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAV-0006GV-Ik for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:53 -0400 Received: by mail-pj1-x1032.google.com with SMTP id iq2-20020a17090afb4200b001d93cf33ae9so12729370pjb.5 for ; Sat, 30 Apr 2022 06:29: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=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=vKTw6K1pyFSug4fM4A/3IyP/LXCWnY1JVdPKc4B05vaZvr51SjTmv1l83Ej+KvrcRn mWycv+LB8rPMXPBZFZDHvYfsV0Iq36gyJ4EGn8gQXrEyyyizkcO5UTKhNJmV95JynyJY mrt7EXo98+g4y6QtF6NFuiyNEUvcSJLeAQ67YojzH1bRgwwiydBmE+s2ru1Zgoxc5kLo NuEcso9UCJACBsQi0a/+uDLS+EDFRmkbZhDACNwDrICSibx8/yv6xPOxconEPis5tNQH T8uNHeBzi6DDU3ngzhrz7cvevSvYzc5fO6xehlCWPmB7JWBUpeefzlA6vvXdZfKCncoI sqiw== 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=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=AOswZDJSl4GUxJV19n98ARbtOm4RuIjSp4XTtnw9tGdH0H5wdXGsoucL9bFnS7xwbo OUGznlHWozvbTPWfECAiiDRyZOKSIE4F9lfik97/H4SF5VFbbvKGSJyYMDy47NVQg9wZ 05ZF0ti2e2QhfkFOC7p87aRT3YwUhNJ40Zv2YA2A1MZ/OvK6CfUpG0xaVcWb1DGwXiWD zbw0qbei+944KUa9ryTT972iqkwPYfOaDcjQP5BwR+bXup1a3/uDoP8VdNoglT2ZnOUV dQl47QhNDg72tqoO02juJteNfWg4NE8Ply4EfCgaZeD0mBXjNkwMa3LSjhUjBVlsDa+o TjiA== X-Gm-Message-State: AOAM530/fEwdhBatztC67wWvGZdykStW8jT4HKk2+8WlOFDQLfpoDwJH aFmuV4TPOPyaI9wGPFiaQHt8jFk8pxDJdg== X-Received: by 2002:a17:902:8698:b0:158:99d4:6256 with SMTP id g24-20020a170902869800b0015899d46256mr3982498plo.104.1651325390340; Sat, 30 Apr 2022 06:29:50 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 16/43] semihosting: Split common_semi_flen_buf per target Date: Sat, 30 Apr 2022 06:29:05 -0700 Message-Id: <20220430132932.324018-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split out common_semi_stack_bottom per target. Signed-off-by: Richard Henderson --- 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 7fc60e223a..b2816e9f66 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -217,6 +217,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return is_a64(env); } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -246,6 +253,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return riscv_cpu_mxl(env) != MXL_RV32; } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} #endif /* @@ -301,31 +315,15 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * Return an address in target memory of 64 bytes where the remote + * gdb should write its stat struct. (The format of this structure + * is defined by GDB's remote protocol and is not target-specific.) + * We put this on the guest's stack just below SP. + */ static target_ulong common_semi_flen_buf(CPUState *cs) { - target_ulong sp; -#ifdef TARGET_ARM - /* Return an address in target memory of 64 bytes where the remote - * gdb should write its stat struct. (The format of this structure - * is defined by GDB's remote protocol and is not target-specific.) - * We put this on the guest's stack just below SP. - */ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - - if (is_a64(env)) { - sp = env->xregs[31]; - } else { - sp = env->regs[13]; - } -#endif -#ifdef TARGET_RISCV - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - - sp = env->gpr[xSP]; -#endif - + target_ulong sp = common_semi_stack_bottom(cs); return sp - 64; } From patchwork Sat Apr 30 13:29:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568108 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7210636map; Sat, 30 Apr 2022 06:39:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5BTKSQoibWYWcw3rItYPW7W0r4Kd3KtnN+PbHfK15IvEtU+jN3CJsAMgZBRK3kCiqNwAy X-Received: by 2002:a05:6214:2266:b0:456:2c5a:b45f with SMTP id gs6-20020a056214226600b004562c5ab45fmr3162445qvb.24.1651325952881; Sat, 30 Apr 2022 06:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325952; cv=none; d=google.com; s=arc-20160816; b=mhzfF0wkfufR9zDeUqY4gIMyR7wYzy/2wvfWy6mi6rZSQ9Tg0xAwLx8jpV66qOqBuA 3/NoCAleoIF3p0zlPM3kpawn8krUFAt/FK4zGWUG4hmBeWYMvPaYnwS8C6URG+hxvP6u s5aXvGFusb26TJmRBXZ5lgI5OFdFtBHf5aY9fZrMbUekisqrQwT05qBtlA3JzmLbALKZ yNE13HiuMB5FhlU056rqAhWBQoRNM5yCpZW14jjN5Ctx+w6A2OBz0mvl8xdiQpZIpl/D Xh+xLo5LSxi8i0KkASj9ZuhxwVUOa3eqxCL7xJ4AsyTEGkIIaFSFfURvpSfVmtu9AICv PLxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=ibzPMDAxlYcmcfls75AdW5zlM2A+inTat6nBzUlcStcYbOpRaL+jKTsDfMZKESgHf4 jBrZH6T6ysgIh/V6DN7U5D+hKZg28ruVDSdBRfrDKT3CHlfO5+jHItFSOnDNdsAzOUfl OOxwFNfKOwyRB9aWGIpDElnhox4+MFlpubiDAdmTH7Ld5bimpHV9pfmU1Mq+vtedDrgb R5iF9+1BDwtTuDOrB2HlCiFtJZuCdKvbtmRhrahryoFmtRCeC2RIBfNphRbtoFY/Ou8A kijfiLDiCPoP2oiWp1/l6/tsF0AtsiC0w9otUcbGa6tr3HyMxss3qLRvYoMWqK1kDJOs mUnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gJV4mWnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z14-20020ac87f8e000000b002ed58584346si3681002qtj.441.2022.04.30.06.39.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:39:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gJV4mWnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknJY-0005Sg-Fb for patch@linaro.org; Sat, 30 Apr 2022 09:39:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAY-0004mC-GV for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:41970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAW-0006Gi-N8 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:54 -0400 Received: by mail-pg1-x52f.google.com with SMTP id t13so8493245pgn.8 for ; Sat, 30 Apr 2022 06:29: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=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=gJV4mWnk6zBJnSDgFpEUX8RfgjE82mp9ZhyZpKMekEkgso9t7oa53yC/c+6wOjr2QU aEqInOIJ5rnkwk8H9CD1mJlOabcapLwXThl6Z9UFo5J41uYl/dq071wH97Rtd46tMzez s63ctcCtRaCpAHkwz8o5r1a/J0KSxE8NJNXb1p5TW3d5MvKQ6/Cw+N/FJonqzuzs5gqx VeocVoGD1mQ/ky5STgWxeV0bMkmDKu1rycTm36NlKuU7bHiQ9QMaDf1/j610DpTwoka5 pa0gpd3znPv+/YnwaPyZsT/9/ak0A79NSmpEFHSz9hBz2FUCuG6tilDhZwMZKjaeZQiT NcBw== 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=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=kCPi4IXtb87uBV0RRhAq18bFFBQv1MTU41+Ceib9Il5+1esYiD4h4bEHBOAajgSe77 FUjS7ATE47hUl6bcU2DXWNeCJktyETmhSX+5GKuZU7Jsb7h8ts6DxX+u4SREfFjUbwWC OM43DwCCF56gi3YSAgGa5O9Nx6UeF9u2knwqF9N3l47y05vNzfH+/NIRpnDHq0WmHSXA ZcshRBtcmDRDOD2YA68CjUSpHYYRjspRSMT6HaXX3vNsVS1wkd8K51rDInjNjiAbpIf1 PgS+u3LtMWLqcRd91e1/MIUuuzqqb8lfkGcciTyVqa21wvB0Zk8CTXkW77dBpa5uD6C8 5lIA== X-Gm-Message-State: AOAM531f6CSnlB1GId/ZzaM4Qbo+hsiaPCHuWoiBIeyfcaMPSceZ0QZr K/0zz/+veVyoos+5qR0y66shSEL4m6WeTA== X-Received: by 2002:a63:101:0:b0:3aa:b7e9:6708 with SMTP id 1-20020a630101000000b003aab7e96708mr3151682pgb.111.1651325391394; Sat, 30 Apr 2022 06:29:51 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 17/43] semihosting: Split out common_semi_has_synccache Date: Sat, 30 Apr 2022 06:29:06 -0700 Message-Id: <20220430132932.324018-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We already have some larger ifdef blocks for ARM and RISCV; split out a boolean test for SYS_SYNCCACHE. 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 b2816e9f66..6149be404f 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -224,6 +224,12 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPUARMState *env = &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32. */ + return !is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -260,6 +266,11 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPURISCVState *env = &cpu->env; return env->gpr[xSP]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} #endif /* @@ -1103,16 +1114,11 @@ void do_common_semihosting(CPUState *cs) * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */ -#ifdef TARGET_ARM - if (is_a64(cs->env_ptr)) { + if (common_semi_has_synccache(env)) { common_semi_set_ret(cs, 0); break; } -#endif -#ifdef TARGET_RISCV - common_semi_set_ret(cs, 0); -#endif - /* fall through -- invalid for A32/T32 */ + /* fall through */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, 0); From patchwork Sat Apr 30 13:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568106 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7209197map; Sat, 30 Apr 2022 06:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytuEX889qKxFl/STdSwdX8DRk0y8Q0IJCDb9cic58fetv8QvaXtvyREKW4oib1zzRCbo6J X-Received: by 2002:a05:620a:408a:b0:69e:b4e9:cb93 with SMTP id f10-20020a05620a408a00b0069eb4e9cb93mr2633696qko.777.1651325803127; Sat, 30 Apr 2022 06:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325803; cv=none; d=google.com; s=arc-20160816; b=h3pMH1ciGvPeKP4a1L/M14yHO7R/5HTorFpf2D8QcbzpsU428BbI4qIcZe3WepaC5i /QG+fb7NQOJ4HRQWqT2EudJ+uvUux6nemf5gMSX7+bVe+g72JVam85deA+FYS/+ETb9h hScbbzxyzJIVJKk3CfoxMLvmWMk0XFdMZP5KJ91rfhOkA4zhQf4xx7UzRgk3bG3IOuGW g2dX3lIhfgHt4P1FlEV42llaaCs7x8v130SQ8NF4/f+x0qwwPfcVyTgpDs0le60gzIYh 0VHOsIHxD4UEBg/N2cfoCH9TVrKOiHlzoXPX9w0rMC9cmsMb3HXJTz4823vHtmLLTCg6 xptg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=kDWNhGsQuAmrpPR6i950ZCasrdBDMuM8EAgPSV9LsTG4IQHQLI1z9+nJz01QdfAjGb Ffaa+IUfD6FUutOisSrCuwHeO40OMailEGuwd9ehCwc+uZvDVVvQEpsYyZz4eahb6arn d27NevnBOL0BFkJwknlwgZAnpKTxhdZnjMZFxlVZmHuY5xiWJPGTWlsL3r6r07bs80Ze /7ctxZCY7HM4BwTBtA4pRc5PAhu7YtQboVUgQ8J9aGglZ5PTm0XZ7NrDl1FTZnBf/s+J MOoQoH6gPAaUBC7ejmYtW5WRbhR4g332rzo8SjRygwGwdAX1tDU2rjhcP0+YCwu6zyRm Um9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=F3vbFVC5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fi20-20020a0562141a5400b004565186dea2si3983238qvb.12.2022.04.30.06.36.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=F3vbFVC5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknH8-0008Dy-Mh for patch@linaro.org; Sat, 30 Apr 2022 09:36:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAa-0004mF-6M for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:42804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAY-0006Gy-7N for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:55 -0400 Received: by mail-pj1-x1033.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so9466323pjm.1 for ; Sat, 30 Apr 2022 06:29: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=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=F3vbFVC5jiJID6ZnZtleBggIsZkOAk97VYgmI7WRcSxYz6zoWtfFmZRmLM4RF2myaC LtI3QiQNTDN/aNs85QweUwYSr9DrwFbQmMbUFm4Au95aHdEOOINGdXDUR9nVtQIXAI4U neGb+bBSe3g6muTAo9OuQNIM7juaIyle9sG5PMmKbwqnMBjC1rYlsyYev6ssMCuzu0gM DoSCGxTipcvsF3AI8DLjn784EUSuzpY7a5SUK79JI2QT/dTwQMdHTvG7m9drVtYU4sXB MWYb8r1r1tSRc2OP6U1S1+4vZgLahpLrrKl7Z4M7fk+aUo8l1fTLr9D0QRtHcXhRpLav Pi9g== 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=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=6A27JrDXqfHDUmjkUDNJlTYf8MKzXYdf+TV0t9wSAIYC+00mcgalEwIUWVO3/AmDMq K74ralA8/dDsjCZorS3dXhqLaiZXLG3jqVp1UsuBFvUYYH9wowCgVTdJl8souPpiXo+c 9gSRWPeUUg1KHLGEEkVfguyyzKAQ+gZO1zEJbgPLtqtnpxr3TA3z6RNLYcA6k/s7UMCf KIBxg21yLSAccsnnvfVDIkt7yjZAUxaVYgWHY7499umAKShNRMzp2cFaDHn0YV10g6oj GrTthGBKhD8AJ8F3RGEgZzhT4v4uZKMaFc6eCNuxMBoB7EiOkDC8fDm87sZjAowcHcKQ gebg== X-Gm-Message-State: AOAM531mkaUNJss5eVQik0qGlEipJHbtNxfQF0gXtumIQ6VBg3ufkoJw 8Gb2sasnJSqythTmMtQx9D7WhYfmJbWDOg== X-Received: by 2002:a17:902:b789:b0:15b:5d52:7542 with SMTP id e9-20020a170902b78900b0015b5d527542mr3991538pls.26.1651325392410; Sat, 30 Apr 2022 06:29:52 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 18/43] semihosting: Use env more often in do_common_semihosting Date: Sat, 30 Apr 2022 06:29:07 -0700 Message-Id: <20220430132932.324018-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We've already loaded cs->env_ptr into a local variable; use it. Since env is unconditionally used, we don't need a dummy use. Signed-off-by: Richard Henderson --- target/arm/common-semi-target.h | 62 ++++++++++++++++++ target/riscv/common-semi-target.h | 50 +++++++++++++++ semihosting/arm-compat-semi.c | 101 ++---------------------------- 3 files changed, 116 insertions(+), 97 deletions(-) create mode 100644 target/arm/common-semi-target.h create mode 100644 target/riscv/common-semi-target.h diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.h new file mode 100644 index 0000000000..c20e1cca76 --- /dev/null +++ b/target/arm/common-semi-target.h @@ -0,0 +1,62 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H +#define TARGET_ARM_COMMON_SEMI_TARGET_H + +#ifndef CONFIG_USER_ONLY +#include "hw/arm/boot.h" +#endif + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + return env->xregs[argno]; + } else { + return env->regs[argno]; + } +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + env->xregs[0] = ret; + } else { + env->regs[0] = ret; + } +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32 */ + return !is_a64(env); +} + +#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.h new file mode 100644 index 0000000000..7c8a59e0cc --- /dev/null +++ b/target/riscv/common-semi-target.h @@ -0,0 +1,50 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H +#define TARGET_RISCV_COMMON_SEMI_TARGET_H + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + env->gpr[xA0] = ret; +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} + +#endif diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 6149be404f..3a740482f9 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -46,9 +46,6 @@ #else #include "qemu/cutils.h" #include "hw/loader.h" -#ifdef TARGET_ARM -#include "hw/arm/boot.h" -#endif #include "hw/boards.h" #endif @@ -182,96 +179,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #endif -#ifdef TARGET_ARM -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - return env->xregs[argno]; - } else { - return env->regs[argno]; - } -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - env->xregs[0] = ret; - } else { - env->regs[0] = ret; - } -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return is_a64(env); -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - return is_a64(env) ? env->xregs[31] : env->regs[13]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - /* Invalid for A32/T32. */ - return !is_a64(env); -} -#endif /* TARGET_ARM */ - -#ifdef TARGET_RISCV -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xA0 + argno]; -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - env->gpr[xA0] = ret; -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return riscv_cpu_mxl(env) != MXL_RV32; -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xSP]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - return true; -} -#endif +#include "common-semi-target.h" /* * The semihosting API has no concept of its errno being thread-safe, @@ -646,7 +554,6 @@ void do_common_semihosting(CPUState *cs) GuestFD *gf; int64_t elapsed; - (void) env; /* Used implicitly by arm lock_user macro */ nr = common_semi_arg(cs, 0) & 0xffffffffU; args = common_semi_arg(cs, 1); @@ -729,12 +636,12 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(cs->env_ptr, args); + qemu_semihosting_console_outc(env, args); common_semi_set_ret(cs, 0xdeadbeef); break; case TARGET_SYS_WRITE0: - ret = qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(env, args); common_semi_set_ret(cs, ret); break; @@ -765,7 +672,7 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(env); common_semi_set_ret(cs, ret); break; From patchwork Sat Apr 30 13:29:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568120 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7216406map; Sat, 30 Apr 2022 06:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmeT60RYiQufcsj8avWxEeliez5R5J5Ukq+OSnsGQGCXhQl82or2LoGWBahn0xh1NKOpG2 X-Received: by 2002:ac8:5e4e:0:b0:2f3:5df5:5b3f with SMTP id i14-20020ac85e4e000000b002f35df55b3fmr3412198qtx.295.1651326536988; Sat, 30 Apr 2022 06:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326536; cv=none; d=google.com; s=arc-20160816; b=oMjI8CiJyDg3/KXhc0GqwRdBKVCSvD+pWRCXT2wnx86jAaTSZwGWNkQln/sOz0toIf LLrOmdF65JJFQMxWNzkGhbvJDSp2LSt9+a6UVvsBjMJtDI0xu7zPtlQXpPntk7jQf9Xk UVmlza5YXrTWI6cwVB2O9HABtIjMJoy5Gxjb6i7VufliAwTUiuHfqjeJgIk6q4hm7Q3N tHZV1JlZTnx9APR3DQIWDYPWaEnK3/2JVNqcl/L/gGTQGVqt/MNAWV4TqW6Z3TXIieqw XoZGKeQLWNIFl81I8qp/N4qPCmGrOo3nKUmv9iufk1DHvmkTMRzbBcWKnJMtmT3l7TNL 1OuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=rXeJ/BQkZueAc3n3INRyD18YsYnT5yTYZ4uC43YTrsfTJ5ZFGUYcqqkXO/eaAfekCk 10wWUCGPT4YbFfvJCvlst7wVKobVMBEDXYIGchpzpTBz5rMAHYs6TAD0wymruE5iFo2M rRjpm8UM04XkP2Y36GnZ+hmhq/Op8Pd6QJ6sw419cvjy17n8IHljIyP1LzWDK7PDWYDR mcwEiofnGJVS+pcd5QsWaOQdzVR9S3TqLr0Kin5oVgIvaKQpP9Y2wXLVYngI1uA0CDEt O67iE9J9rhPr4Fv21CAux33rYfoJ/zq+HkvHJ3/wKtTDxH52P2xO+ozDtWp6F8q4ze8z KQ3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hyrtmvin; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w12-20020ac857cc000000b002f1fa6644e7si231492qta.272.2022.04.30.06.48.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:48:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hyrtmvin; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknSy-0005zJ-Id for patch@linaro.org; Sat, 30 Apr 2022 09:48:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAc-0004nG-Ho for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:00 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:43852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAZ-0006H8-Oh for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: by mail-pf1-x42c.google.com with SMTP id y14so9047461pfe.10 for ; Sat, 30 Apr 2022 06:29: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=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=hyrtmvin031FUKrTZeDG3DueHkuGPEWTzfyLAtBztqAUsUF3bMq2YqkJRBZ2iXQhBE ALywlPDHnJCy5ROE7AvcmcZVhIVjyxIjiWM2HGAkANVhiV4ZMLvkoyO/Od63zL/Q/KoX mNAdQdJqugNT9usARzpghLlO9bmPCEZiasrUSceU/+kjqUIS52yHAhXZZyvHuEoVUKnu JvdVDs2X98PKjosvHJZPgRIuXjS3sWep8EGYfsR7N+6ZFe10Yx1W5/0mWONSBaw0tl3B FYkulNCcPEMcPbu4eFMfdvdTReJlakG+pesbVGL/pT3non4s9sLphDONDYYVnp8SWWZl dV1Q== 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=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=NrhEO/Sh8GX7SKGWCNFz2nrXw3G/Ns0X8HrLcSSCtleQfjSMzcGJtdm4snUm0pAJLy kLjgSRFYt3yb5fVIRYctIAOuKHtFq3XM+Tt9549Yel3HUBRBwiIOQ0kn0sXGVyqHLxfB 1V79eaALK2Bqq/AIj/JV73R7zyWziQ9Bs/ioQf2u90V4pAwNx6/348G9vEpDEFKbZ/CS T9L2iw+nizD1FGJa2md+fmByx7F4jqDTjlbGw5sffkbsX2PMIUWmTH9bwkfaapHloVsn rFSxUwleDgo2t/Et2bVaISU92I/Nb1sE+ueDY52MCgVjBDWQxHtIBiDKyta0A+BGbT1Y +/nQ== X-Gm-Message-State: AOAM530WPCe+0+SKpNT8HENvaaHesyj6JCLgOb9Wk1Rqudnx4XNt24wC RPlUQtjcdMwBWGfSfZiWG/GDSAiyVo7mvA== X-Received: by 2002:a05:6a00:1897:b0:50d:baaf:4163 with SMTP id x23-20020a056a00189700b0050dbaaf4163mr3624854pfh.26.1651325393406; Sat, 30 Apr 2022 06:29:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 19/43] semihosting: Move GET_ARG/SET_ARG earlier in the file Date: Sat, 30 Apr 2022 06:29:08 -0700 Message-Id: <20220430132932.324018-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Moving this to be useful for another function besides do_common_semihosting. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3a740482f9..49f976cbc5 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -181,6 +181,32 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #include "common-semi-target.h" +/* + * Read the input value from the argument block; fail the semihosting + * call if the memory read fails. Eventually we could use a generic + * CPUState helper function here. + */ + +#define GET_ARG(n) do { \ + if (is_64bit_semihosting(env)) { \ + if (get_user_u64(arg ## n, args + (n) * 8)) { \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ + } \ + } else { \ + if (get_user_u32(arg ## n, args + (n) * 4)) { \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ + } \ + } \ +} 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 @@ -506,32 +532,6 @@ static const GuestFDFunctions guestfd_fns[] = { }, }; -/* - * Read the input value from the argument block; fail the semihosting - * call if the memory read fails. Eventually we could use a generic - * CPUState helper function here. - */ - -#define GET_ARG(n) do { \ - if (is_64bit_semihosting(env)) { \ - if (get_user_u64(arg ## n, args + (n) * 8)) { \ - common_semi_cb(cs, -1, EFAULT); \ - return; \ - } \ - } else { \ - if (get_user_u32(arg ## n, args + (n) * 4)) { \ - common_semi_cb(cs, -1, EFAULT); \ - return; \ - } \ - } \ -} while (0) - -#define SET_ARG(n, val) \ - (is_64bit_semihosting(env) ? \ - put_user_u64(val, args + (n) * 8) : \ - put_user_u32(val, args + (n) * 4)) - - /* * Do a semihosting call. * From patchwork Sat Apr 30 13:29:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568115 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7213898map; Sat, 30 Apr 2022 06:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqQ8lFuEURGGR//9L1x4DwaWmNgAWfNSta30UzRrLpplzhSBT/oTFQ2TW4xRUwmUCnFk9d X-Received: by 2002:a0c:ea26:0:b0:456:393d:ec72 with SMTP id t6-20020a0cea26000000b00456393dec72mr2992134qvp.6.1651326278924; Sat, 30 Apr 2022 06:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326278; cv=none; d=google.com; s=arc-20160816; b=RrTsZYPsaiYGemeSSs9WPlhXygtutML1wfvshRHw3pGQPEEs0R+/0jcUiaWTchf5TT wEBVRNfNhed+4RyCXxkO0rgmFX7ir9tLc65YqT8VUty0q2vrr3Tfo631dWfFFjMPVmRK NNSY48wBfFGKLPpPDzpjt6o/DGDkpz8JbizyRFDKSGZeMePDjHLsgAzif4z8B12yOROa wZLaX44BOC3gIJ42Y06oNGBA8aTo64b1vgqGHTDDce/mmIKZ986QuYfjpq/yHmBMdyGA daNgFmTkitwzhyewJeGekhclhBdCWBLavGeUQEmAG807MjA+xAkL5dEqVH+Tdgcnsf8p OcWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=aKzXDiDuIzeMYnJqEAFUYGAGzPJrOV+1efeY8aXLxdY=; b=EoJUlye9J7hKB2/tQRuDF54xT19f9ltaziDFV30gWg86eT6lIS0NuMkyXvN9HyEAJ/ 3PqV8PCnQvn6Ztzxtdi0skipLPmorQwqIqpUcOMFS4ilX/2n6yuPEqDjyds9eFPIzC3R fCo9+hlUzAL89ajtmmB9IOcX5BZ7o777CGo8m/O3OZVAfIXdX+tJhTt9Ky3He6mRHaQQ GH/y52M1MuNPv2qj2ZUACNOgY7yz7QDSuauHbUbWxOtu6Zz/4UOCtykEWzoBPUss7bQv qepUasteq1+a1PprXVs0RqSO4mR1tAtO+Nty/PGdJ02OZ7eH+V9kVW6F25tsYDozk6Fr 8uFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="UFBpsZ/S"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ce8-20020a05621403c800b004444ce38924si3446692qvb.268.2022.04.30.06.44.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:44:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="UFBpsZ/S"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknOo-0008Bb-GP for patch@linaro.org; Sat, 30 Apr 2022 09:44:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAc-0004nA-Hn for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:00 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:42817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAZ-0006HO-Om for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:57 -0400 Received: by mail-pf1-x42a.google.com with SMTP id x23so3772680pff.9 for ; Sat, 30 Apr 2022 06:29: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=aKzXDiDuIzeMYnJqEAFUYGAGzPJrOV+1efeY8aXLxdY=; b=UFBpsZ/SnypcXOFl7I8V7aiqLkhW0lYt9rfbJjOGsuiPTaVal+6EC7fKbEYqdeQOW4 UCP114/mtBGJphEzcIPp4zKneQpn1WE+2W6pYo2LZLoJmzLCx88VxpOqTYNDrYwTNVRq 3zezPLtdbxoue4sOUaa11X0eiW2g/f0+gzg67rU7azmRhBIfyTA65zri9IsmPsYRpzdL cvXVgITzVo6tkjkTrx6uBoEd14J/yp0zQeed/NB0J6DwMfCRzozcgoEemfe2cLz2UXQK Wb9eFm0dCeq+WyLFy0ZHmiBdItfO31KGfbB+PQUA6kYEH1b0zO2vO1fJ3UEbLg5LT7c8 1YVQ== 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=aKzXDiDuIzeMYnJqEAFUYGAGzPJrOV+1efeY8aXLxdY=; b=n4AfNxbtvlBKdr6NBxBIgIxpjIovqILt6GDH8J1490KkhMyQ4SAZidGNvWqXRDaMW1 3nGerss05HYcLtiHRbb38+j/cTHzVqoJ1+1veca1fFf1vZGdlJip/dke8T/BheFBMRy7 1YaXlFekaGg7t2CT4CbYBxbHZgpsLxgEYACUO3TWZDB/ycFYuOS7zblVhiUKb3qwF4Rb D5XcD1D5J/VLWZLGtzvO+8Biyu6SORCDlfgkLPsUeQqiYXZE9eHWrSut0f9ZzFhqQBLQ IhYd9dpK2VEsLSnUguU/cjP5excjieEGIMCc4C/bWbFjWydZcxCWb07MiYzQe3RhUami s+xw== X-Gm-Message-State: AOAM531vUfRSbaUOLdZeTOe8Benl6JnEH/tRYzyqN5ULGST+9o8uQ1CE jMc1qNLtjDx+FiDibLPiDZi06A5N6g2u+w== X-Received: by 2002:aa7:9d0d:0:b0:50d:4fcc:7cb1 with SMTP id k13-20020aa79d0d000000b0050d4fcc7cb1mr3816602pfp.41.1651325394444; Sat, 30 Apr 2022 06:29:54 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 20/43] semihosting: Split out semihost_sys_open Date: Sat, 30 Apr 2022 06:29:09 -0700 Message-Id: <20220430132932.324018-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_OPEN to a reusable function. This handles gdb and host file i/o. Add helpers to validate the length of the filename string. Prepare for usage by other semihosting by allowing the filename length parameter to be 0, and calling strlen. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 13 ++++ semihosting/arm-compat-semi.c | 49 +----------- semihosting/guestfd.c | 135 ++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 45 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 5aa2722cb2..275b91b73a 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -41,4 +41,17 @@ GuestFD *get_guestfd(int guestfd); void associate_guestfd(int guestfd, int hostfd); void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len); +/* + * Syscall implementations for semi-hosting. 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_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 49f976cbc5..e2decd54e4 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -35,9 +35,9 @@ #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" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -98,21 +98,6 @@ static int gdb_open_modeflags[12] = { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY }; -static int open_modeflags[12] = { - O_RDONLY, - O_RDONLY | O_BINARY, - O_RDWR, - O_RDWR | O_BINARY, - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, - O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, - O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY -}; - #ifndef CONFIG_USER_ONLY /** @@ -285,20 +270,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, size); } -static int common_semi_open_guestfd; - -static void -common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) -{ - if (ret == (target_ulong)-1) { - dealloc_guestfd(common_semi_open_guestfd); - } else { - associate_guestfd(common_semi_open_guestfd, ret); - ret = common_semi_open_guestfd; - } - common_semi_cb(cs, ret, err); -} - /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all @@ -602,22 +573,10 @@ void do_common_semihosting(CPUState *cs) staticfile_guestfd(ret, featurefile_data, sizeof(featurefile_data)); } - } else if (use_gdb_syscalls()) { - unlock_user(s, arg0, 0); - common_semi_open_guestfd = alloc_guestfd(); - gdb_do_syscall(common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - break; } else { - hostfd = open(s, open_modeflags[arg1], 0644); - if (hostfd < 0) { - ret = -1; - err = errno; - } else { - ret = alloc_guestfd(); - associate_guestfd(ret, hostfd); - } + semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, + gdb_open_modeflags[arg1], 0644); + break; } unlock_user(s, arg0, 0); common_semi_cb(cs, ret, err); diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index b6405f5663..1393279333 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -11,6 +11,11 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" #include "semihosting/guestfd.h" +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +#else +#include "semihosting/softmmu-uaccess.h" +#endif static GArray *guestfd_array; @@ -116,3 +121,133 @@ void dealloc_guestfd(int guestfd) assert(gf); gf->type = GuestFDUnused; } + +/* + * Validate or compute the length of the string (including terminator). + */ +static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tlen) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char c; + + if (tlen == 0) { + ssize_t slen = target_strlen(str); + + if (slen < 0) { + return -EFAULT; + } + if (slen >= INT32_MAX) { + return -ENAMETOOLONG; + } + return slen + 1; + } + if (tlen > INT32_MAX) { + return -ENAMETOOLONG; + } + if (get_user_u8(c, str + tlen - 1)) { + return -EFAULT; + } + if (c != 0) { + return -EINVAL; + } + return tlen; +} + +static int validate_lock_user_string(char **pstr, CPUState *cs, + target_ulong tstr, target_ulong tlen) +{ + int ret = validate_strlen(cs, tstr, tlen); + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *str = NULL; + + if (ret > 0) { + str = lock_user(VERIFY_READ, tstr, ret, true); + ret = str ? 0 : -EFAULT; + } + *pstr = str; + return ret; +} + +/* + * File-related semihosting syscall implementations. + */ + +static gdb_syscall_complete_cb gdb_open_complete; + +static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + if (!err) { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + ret = guestfd; + } + gdb_open_complete(cs, ret, err); +} + +static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_open_complete = complete; + gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x", + fname, len, (target_ulong)gdb_flags, (target_ulong)mode); +} + +static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret, host_flags; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + if (gdb_flags & GDB_O_WRONLY) { + host_flags = O_WRONLY; + } else if (gdb_flags & GDB_O_RDWR) { + host_flags = O_RDWR; + } else { + host_flags = O_RDONLY; + } + if (gdb_flags & GDB_O_CREAT) { + host_flags |= O_CREAT; + } + if (gdb_flags & GDB_O_TRUNC) { + host_flags |= O_TRUNC; + } + if (gdb_flags & GDB_O_EXCL) { + host_flags |= O_EXCL; + } + + ret = open(p, host_flags, mode); + if (ret < 0) { + complete(cs, -1, errno); + } else { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + complete(cs, guestfd, 0); + } + unlock_user(p, fname, 0); +} + +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); + } +} From patchwork Sat Apr 30 13:29:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568122 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7216465map; Sat, 30 Apr 2022 06:49:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYBWum+eZkVPqvUrc+tzghlTM9rzdH5lqvYobt/hkGN5YntjtBrSMnWeC2ev9DFfi8EA6N X-Received: by 2002:ac8:5f48:0:b0:2f3:818c:7b95 with SMTP id y8-20020ac85f48000000b002f3818c7b95mr3513812qta.454.1651326543834; Sat, 30 Apr 2022 06:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326543; cv=none; d=google.com; s=arc-20160816; b=eAy3ad5Puam21Rv/s2B/440qOJVBTq7q41Ctm/Eax8VCgCQ2lFn2TmYWh7/Nx5chNt qdNiRZKuEOvJyW2XBo77bV+YvUjk6W3s2hbMOMJNODw04N+VuFf8XSOMcbTlNB7CuNnb JyVe/fRLpMiTAWJmsvwyuR8l+zewtRiTus8wwCqbuHG9zEKzAr1HXJf9K2QujVNhd2BS ZsIUIX6pwu51TcheTb5D2UIo35EtC+fRGVPUO+K0K3eeK/6mty47gj9RY8Kr2QoHIw/L mFgSuwmGcInZJrH4K7W0GKObR0Jeukta2aClPCveGwhBefEHX5mCK3DV/PAqvwO1cRkh KQFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ifeWU+//WzY4yqP3RZk+9v7785I7G9eMl5ZAoLqQLT4=; b=EehwIME9UtuTSkMaPn3uMhH1FtRCYXK4e2HDYQYfjNDcdj2kM1fAbVwjIramf0DHc+ 1u1Pb4/LE6Sldq/Yi6V+Xj2gSfeUHEjYp1uefH4E60kWXxQy8ZMyqxh6xAWagjPJUKdY 3O7mW639BCoM0vh3QMlN2Hm/4jHJDc+A03zVIwM+tfREjVtHPmsahRajVHN7ISrXZFDj 6djUMyrywHcIQgxKrnbzzWywy1PPnscq2NekAN31IvixYTHxoZJJ4olm6BczkkWiu4+K tIk238ULy1DG+HNfwQAc1+ze7RI8w7oNBZ1Pkh5AE0+FT42lcZbF1w3ha9oZ+x4t+EuH BxAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="pEh7y/5M"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ke24-20020a056214301800b0044612b45b55si261221qvb.168.2022.04.30.06.49.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="pEh7y/5M"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknT5-0006HP-7w for patch@linaro.org; Sat, 30 Apr 2022 09:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAe-0004qn-0B for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:00 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:52888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAc-0006HT-8R for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:29:59 -0400 Received: by mail-pj1-x102c.google.com with SMTP id e24so9298501pjt.2 for ; Sat, 30 Apr 2022 06:29: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=ifeWU+//WzY4yqP3RZk+9v7785I7G9eMl5ZAoLqQLT4=; b=pEh7y/5MVkas+1F1UrF93yju2Efwn4zAwDxVIBk/33g/v57H/6Ig0WSx9yvxk3SxPb kPeBwlGz/CYzA7uto7EHgP0uD8rrzinkEkSC4ARGztaEWpz3Pdf9dQ1e34Ecd/YbtJ6t rWiRh9T9fSSSA4Z1zX+oc6JzKt3AaMKxx2A7vnLziGnJG0jxSSKhHKEGdcI19dniGloX KcwIFmPAgMbTC3OJs5JXtrXY3DETa97iBAe0v5Uc19D1P09TwUOR/blC81zHasbbMh3/ mO2QkyZC+L36mYp9ygSBQ659KKTYHkrf/82VTxDwOKx+gSrUNcIqcHSfK5NG1js0iK2g 41QA== 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=ifeWU+//WzY4yqP3RZk+9v7785I7G9eMl5ZAoLqQLT4=; b=W5ovEr5e16U18gXb96k2qladyTut5VHj5RQVRW75BluSjtTJVbn1iClBSda0SiiQ+z MnZcbo80XxSzjXBP3apRjmrsXh0uKh74wPzHYglh3pEpd8HryMJWGJj6nULh9gK6zYjQ TnwIl7laKn/l6oqfrzDDCtCnHqgcXWX9le8b7h31kBUma8Ke0KhMaO9YOkTmyf+kZshp UBKvRMPHO0Ml/Mi+rDaQZ/g1IvSH5oEjojPlambikt6uN4/Yd84xjfSgWfT/g18w+O6U f1L1wJpzuoKsFLwh1dcnviLGB1vHuu8YAiLC6tMl6Gp+XTo+gafZdg3D5rwJUMELE9Se 8IcA== X-Gm-Message-State: AOAM5300URe7eqHa8XDwXl5zbOdi418HK9OqU6e7sqDw7Jc9o6Ooi5sx xtRj0y6Va1mCOQZA9b8Giw+ckKWjksHZaA== X-Received: by 2002:a17:90b:4d0d:b0:1ce:ef5d:f1ef with SMTP id mw13-20020a17090b4d0d00b001ceef5df1efmr8909660pjb.91.1651325395215; Sat, 30 Apr 2022 06:29:55 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 21/43] semihosting: Split out semihost_sys_close Date: Sat, 30 Apr 2022 06:29:10 -0700 Message-Id: <20220430132932.324018-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_CLOSE to a reusable function. This handles all GuestFD. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 2 ++ semihosting/arm-compat-semi.c | 41 +------------------------- semihosting/guestfd.c | 54 ++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 275b91b73a..c38b1d3657 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -54,4 +54,6 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, int gdb_flags, int mode); +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index e2decd54e4..f20e84c4f0 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -276,7 +276,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_closefn(CPUState *cs, GuestFD *gf); typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); typedef void sys_readfn(CPUState *cs, GuestFD *gf, @@ -285,23 +284,6 @@ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_closefn(CPUState *cs, GuestFD *gf) -{ - int ret; - /* - * Only close the underlying host fd if it's one we opened on behalf - * of the guest in SYS_OPEN. - */ - if (gf->hostfd == STDIN_FILENO || - gf->hostfd == STDOUT_FILENO || - gf->hostfd == STDERR_FILENO) { - ret = 0; - } else { - ret = close(gf->hostfd); - } - common_semi_cb(cs, ret, ret ? errno : 0); -} - static void host_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -362,11 +344,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_closefn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); -} - static void gdb_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -414,12 +391,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_closefn(CPUState *cs, GuestFD *gf) -{ - /* Nothing to do */ - common_semi_cb(cs, 0, 0); -} - static void staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -468,7 +439,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -478,7 +448,6 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .closefn = host_closefn, .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, @@ -486,7 +455,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = host_flenfn, }, [GuestFDGDB] = { - .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, @@ -494,7 +462,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .closefn = staticfile_closefn, .writefn = staticfile_writefn, .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, @@ -585,13 +552,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_CLOSE: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].closefn(cs, gf); - dealloc_guestfd(arg0); + semihost_sys_close(cs, common_semi_cb, arg0); break; case TARGET_SYS_WRITEC: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 1393279333..c26b1c677e 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -49,6 +49,11 @@ int alloc_guestfd(void) return i; } +static void do_dealloc_guestfd(GuestFD *gf) +{ + gf->type = GuestFDUnused; +} + /* * Look up the guestfd in the data structure; return NULL * for out of bounds, but don't check whether the slot is unused. @@ -119,7 +124,7 @@ void dealloc_guestfd(int guestfd) GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDUnused; + do_dealloc_guestfd(gf); } /* @@ -251,3 +256,50 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, host_open(cs, complete, fname, fname_len, gdb_flags, mode); } } + +static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); +} + +static void host_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + /* + * Only close the underlying host fd if it's one we opened on behalf + * of the guest in SYS_OPEN. + */ + if (gf->hostfd != STDIN_FILENO && + gf->hostfd != STDOUT_FILENO && + gf->hostfd != STDERR_FILENO && + close(gf->hostfd) < 0) { + complete(cs, -1, errno); + } else { + complete(cs, 0, 0); + } +} + +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, 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(); + } + do_dealloc_guestfd(gf); +} From patchwork Sat Apr 30 13:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568110 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7210673map; Sat, 30 Apr 2022 06:39:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc1jXs0nqNh2bRwglFA2prWEHev73zgxTbCpYxyQ+iizMHU0x60EPAXV5ku6XjWJDrRnVA X-Received: by 2002:a05:620a:3189:b0:69f:421e:ba00 with SMTP id bi9-20020a05620a318900b0069f421eba00mr2754176qkb.485.1651325956656; Sat, 30 Apr 2022 06:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325956; cv=none; d=google.com; s=arc-20160816; b=yOcCcjAmAVA4LaAa3RQB4aD5MqFs1/14aHan+dVUJG9M9YpzPPMFccVdYdwz4rVIff G83biuiOSjcYvabfhzTJp1DtiimN8Se6RsO39MuFIx2d++SpPPFerCSqDbY15OJUwDET CdDtjfLClQyuXJsi/TDvSob3i1lWqn/27+WR+ZMGO44TrXsp1GmlXxEwjrlLuIrKYNmS BtO5k7TD6h9WM4wQvS1as1hw3LlVUbJsbhca9RXGrzwHt61eS0pMiGFgIlWpSgwX1jf1 ohzOTKyOR+aKxwCcdHIhf8qVbfcp2LSeN/toDp7ER8xcdFYtCpy+Hlu5hdZXwdVGZ2Ws zxug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mPei3RSwc5/UahcC23WarvGjq8ZHMU2cCnmAH40UDUM=; b=qsuIuZ+LjxkypTIzlp04TDtY+QRpWGJWq9bUoUyuNOMEpd0A51c3W+4OxUCechDuX4 W5jE70j+jQuyZdn6qOHdJdNWpNzk5hgi/cnWdmbWOXLtW2ILL4hJbwpEKrzx/5EUXrEs 3aGmxr/V9BpOf5qhPRa9chmcYaOIhndOvBP6ggeSOAQWnaPfrV1IYzUBaGTXLRcGrNJU rid+agpHcLB6/g2dw6crQK00j/YajmSQbTMFohgn0DVQNksRj2xbkoMKoL8tohZhIth5 WO6f0wlbxJa65OXzrkVDUuZwdoTnvf+9fTfr1/0sR5yPsMSEl+EgX8fONWbjaQx5qco1 mAGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XfhKaZh9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t4-20020a05622a01c400b002f201fd8239si3904327qtw.128.2022.04.30.06.39.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:39:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XfhKaZh9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknJc-0005fQ-5R for patch@linaro.org; Sat, 30 Apr 2022 09:39:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAe-0004rG-JB for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:00 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:41975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAc-0006Hd-87 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:00 -0400 Received: by mail-pg1-x534.google.com with SMTP id t13so8493338pgn.8 for ; Sat, 30 Apr 2022 06:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mPei3RSwc5/UahcC23WarvGjq8ZHMU2cCnmAH40UDUM=; b=XfhKaZh9QAF+6HdJBQM4FARMfB5R8DZmaJwdyFeUnUz5TS8H47WZ+UuHfOd2FCEnZd x4flW2e7Sz+UbTsFr6AS5EEwSFdQlNvvrd0xLoBlnPjKTkJUw9scS5VOoOzMsEOrq1BM uxQogz+bhCQ0rIOCKtnf232bKzHtoL/mTBm0yCfPby9/rTppMkih6dsWlodyU+0XWOoz gfViThqaBJKbewKmNVzCAjRFWHJfZp0yvQDLlZP0qMIjD7F8oPDiIbKVTd2+zBFobn1V aWLY8um9O6HeMrzJh5y+8f9DluDgPpa214o1OEd5nG5m0Ft6YP7z1WRTdTtfHcZEURVC B7Ug== 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=mPei3RSwc5/UahcC23WarvGjq8ZHMU2cCnmAH40UDUM=; b=bL3dOOVEDtmNoEpNgRZIVV3rA5ycsELKBHv0YxOz/Lp8rrBByPedJOEvilSIf6DgNG EbSL2Fi5fyi/S2rViUYDP4VC6maPiAsB2RxfO2x1lKhTf8NIjfsu11TC7KUwAh8DXkE5 rRTl8T5bBBYZJV+m7f+nhOqw2rlqfDpSo1EzKG4MX3CWRvzU5w/Rr15XbEfvETMXEMB0 ypG3F4MFnOsXm0a39gXvbQigpUgy+LoAt3EPBJB5LCe3RUo0HoDhbFtahVlLOCyuJjsq OxzYgYOzO0bZ3wJ7JHxGyLlilZp8MNSAWL7BIG3YQ8yWI71WS/UOJmLzt+EQQ0i/AiMk s0Aw== X-Gm-Message-State: AOAM532WDaXncML/f/BpVv1aQkmOeWP5lKbDAre0VxQW2CIzemA+8vpS wLDmVRpZRmIh9snwuyr3xkvVOsV2Jeq5ZA== X-Received: by 2002:a05:6a00:2295:b0:50d:d290:338c with SMTP id f21-20020a056a00229500b0050dd290338cmr1745333pfe.30.1651325396337; Sat, 30 Apr 2022 06:29:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 22/43] semihosting: Split out semihost_sys_read Date: Sat, 30 Apr 2022 06:29:11 -0700 Message-Id: <20220430132932.324018-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_READ to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_rw_cb. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 ++ semihosting/arm-compat-semi.c | 84 ++++++++--------------------------- semihosting/guestfd.c | 75 +++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 65 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index c38b1d3657..568d55fd32 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -56,4 +56,7 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f20e84c4f0..2c6c2dd0d0 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -232,7 +232,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: - case TARGET_SYS_READ: ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: @@ -245,6 +244,24 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * SYS_READ and SYS_WRITE always return the number of bytes not read/written. + * There is no error condition, other than returning the original length. + */ +static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + /* Recover the original length from the third argument. */ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong args = common_semi_arg(cs, 1); + target_ulong arg2; + GET_ARG(2); + + if (err) { + ret = 0; /* error: no bytes transmitted */ + } + common_semi_set_ret(cs, arg2 - ret); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -278,8 +295,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) */ typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef void sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); @@ -302,26 +317,6 @@ static void host_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, len - ret, 0); } -static void host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_WRITE, buf, len, 0); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - do { - ret = read(gf->hostfd, s, len); - } while (ret == -1 && errno == EINTR); - unlock_user(s, buf, len); - if (ret == (uint32_t)-1) { - ret = 0; - } - } - /* Return bytes not read, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -351,13 +346,6 @@ static void gdb_writefn(CPUState *cs, GuestFD *gf, gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static void gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -398,30 +386,6 @@ static void staticfile_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, -1, EBADF); } -static void staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t i = 0; - char *s; - - (void) env; /* Used in arm softmmu lock_user implicitly */ - s = lock_user(VERIFY_WRITE, buf, len, 0); - if (s) { - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; - } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; - } - unlock_user(s, buf, len); - } - - /* Return number of bytes not read */ - common_semi_cb(cs, len - i, 0); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -440,7 +404,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_writefn *writefn; - sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -449,21 +412,18 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .writefn = host_writefn, - .readfn = host_readfn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .writefn = gdb_writefn, - .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .writefn = staticfile_writefn, - .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -582,13 +542,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READC: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index c26b1c677e..057e384d65 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -303,3 +303,78 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) } do_dealloc_guestfd(gf); } + +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); +} + +static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_WRITE, buf, len, 0); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + do { + ret = read(gf->hostfd, ptr, len); + } while (ret == -1 && errno == EINTR); + if (ret == -1) { + complete(cs, -1, errno); + unlock_user(ptr, buf, 0); + } else { + complete(cs, ret, 0); + unlock_user(ptr, buf, ret); + } +} + +static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong rest = gf->staticfile.len - gf->staticfile.off; + void *ptr; + + if (len > rest) { + len = rest; + } + ptr = lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + memcpy(ptr, gf->staticfile.data + gf->staticfile.off, len); + gf->staticfile.off += len; + complete(cs, len, 0); + unlock_user(ptr, buf, len); +} + +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + 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(); + } +} From patchwork Sat Apr 30 13:29:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568119 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7216339map; Sat, 30 Apr 2022 06:48:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy72wJANSRuL49kizjgId6IMtogr929Kq5SMWUbrNXLf8D5/K1Mt1WMP2jKKllCxqgBKOhT X-Received: by 2002:ac8:5983:0:b0:2f3:5e03:42ee with SMTP id e3-20020ac85983000000b002f35e0342eemr3513319qte.6.1651326527814; Sat, 30 Apr 2022 06:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326527; cv=none; d=google.com; s=arc-20160816; b=0h8I2pL8C6tETUyMfXSIshVyDdSSDDCWOvyoTyfAfNP22ghFsd9/QKftDl13Bq4Y9q NHYibVA1HLju34Yzhlw0FcNhyqnS80Gm5N6erADhx09acNsWX4LkU4E5AghjKzd/G+7x AupyWs2LXti5LhSEExixJ6YVQxY8KeSg6RzAxGp6DCH6SsBiGOGnQYNIp/xIQA6gD7hO AfSn5THdm7/472JKfUfR6DyD3ixjyShF0e0C/nqNdlmBx6YGEqJgJJwiQ0eNQRwDUwxS bss3jaFafY/TAMg/fvCBV7mP3l60yfDmoJF/MaykBokH4b/w7xPGbZGgpq0Zvxtsi9fd xmUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=D+i1/p52cnWoq/UdGJsdummOLTJVfBA8piubLoll8HQ=; b=Gn7kvLBDGR+UGsCONRaxKGsjHt9+jR06WmOQEwjlnvBaVUk+WI1j8gvugtdUzb6EB7 kK1jrj3Z+SRQx8Edhcpvt2NZ/g7PsxOojAbF5Vm5X2q2GKb17muVZJuNywkc8efiQmwX dCAKtj0yhdAbMZsETsLRFLn6Oa7ULefJWfGsK9SnO6lZxClMceIDxOcW5qjk9FXi/xmE chKiTpsU+QDrhJ1HxT5YNihGPIB3Tcu2M+FQ3vHkfA7eilvsSLK0cg3jxIfQe9ttoMDD 5ADBWJorOss6Lnr25a9jKptIUZOZmOQDz8LJorAYF+eo3Y2Bsna4iEKsN1jxQkt+gt5z mAvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xAg3Zu0Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z3-20020a05622a028300b002ebc603bef8si3832797qtw.755.2022.04.30.06.48.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:48:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xAg3Zu0Y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknSp-0005aY-1I for patch@linaro.org; Sat, 30 Apr 2022 09:48:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAf-0004sn-Kn for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:40843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAc-0006Hi-EM for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:01 -0400 Received: by mail-pg1-x534.google.com with SMTP id x12so8499074pgj.7 for ; Sat, 30 Apr 2022 06:29:58 -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=D+i1/p52cnWoq/UdGJsdummOLTJVfBA8piubLoll8HQ=; b=xAg3Zu0Y+C4SL4aPl/a9Eih/E7n2FcE9x1xMfbD++QUS78VDIoEByFbl7IfDVi9QNd nJILhGR0ejxwR5ADwJPJeLcza4FtPmWfDbPNUZUyuT/rUlSZIBbczw59Tk4UxpUZfADr 7vhlYGFejUPzdH8ul5Wz5bFiM9+TQhGE9P/gXUUPmdTsZPkCLlSKBcSDKIfHHOWPzHQT DJtEz6svdv1WdB8/zom/B0LUk1iMwbwg8F7kaqgMqNYPxxiBzoq2snc/V4NxuNu1oOx0 4hlbSVwZrOj6btOwKAS6bs49F83PFxBb0rlYEH56mH6ZEe/W8AwaU3/1AhMdLibSl0KE ooVw== 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=D+i1/p52cnWoq/UdGJsdummOLTJVfBA8piubLoll8HQ=; b=4toK753E2i73Wb8of35Sn1ldUfBoLhuYPnNOltddqRXn81888vnVTybHJsg305eX9h O+Bs1Jdt8V/0zoC4lJ3cbqBejp5ofXqPgsIvj9U27BGfPauQaQucmn2PlQ6JCCYhGDAO ulDoMAijWz1+s+v9VHXYhbUsFtTUnFD0gHZMDtzXiBahE9VH1LdorS5prV7BWkn9tFwt u4tSlBU/vMfEe8IDgUxvK9w4vr/qAFQbf3h6U76Pn+8uhJ0vaSRrIyPhV9mvicyIkkXT 2dU1++yJJ04Kdixkv1VSgXcO0U8rDq4Js8o9QJ+SGwKzSTknO4mwJfO2cz6ITxGJPGLa UYig== X-Gm-Message-State: AOAM5326/ErK1Fxs2K3mE/+F7YIFU+ye4+l3QHGcxeUcMh8Qqgj3PQLm Ec051XZjsLMOZkDCQg5ReCDtUHdy9qKAXA== X-Received: by 2002:a05:6a00:16cd:b0:4e1:366:7ee8 with SMTP id l13-20020a056a0016cd00b004e103667ee8mr3449824pfc.9.1651325397098; Sat, 30 Apr 2022 06:29:57 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 23/43] semihosting: Split out semihost_sys_write Date: Sat, 30 Apr 2022 06:29:12 -0700 Message-Id: <20220430132932.324018-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_WRITE to a reusable function. This handles all GuestFD. This removes the last use of common_semi_syscall_len. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 ++ semihosting/arm-compat-semi.c | 52 +---------------------------------- semihosting/guestfd.c | 48 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 568d55fd32..5780ea2f13 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -59,4 +59,7 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, int fd, target_ulong buf, target_ulong len); +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 2c6c2dd0d0..6568d205eb 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -216,8 +216,6 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static target_ulong common_semi_syscall_len; - static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (err) { @@ -231,9 +229,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) /* Fixup syscalls that use nonstardard return conventions. */ target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { - case TARGET_SYS_WRITE: - ret = common_semi_syscall_len - ret; - break; case TARGET_SYS_SEEK: ret = 0; break; @@ -293,30 +288,10 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_READ, buf, len, 1); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - ret = write(gf->hostfd, s, len); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - } - /* Return bytes not written, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -339,13 +314,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -379,13 +347,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - /* This fd can never be open for writing */ - common_semi_cb(cs, -1, EBADF); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -403,7 +364,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_writefn *writefn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -411,19 +371,16 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .writefn = host_writefn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .writefn = gdb_writefn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .writefn = staticfile_writefn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -448,7 +405,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - uint32_t len; GuestFD *gf; int64_t elapsed; @@ -529,13 +485,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READ: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 057e384d65..42efd2c558 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -378,3 +378,51 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +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); +} + +static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_READ, buf, len, 1); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = write(gf->hostfd, ptr, len); + complete(cs, ret, ret == -1 ? errno : 0); + unlock_user(ptr, buf, 0); +} + +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + goto ebadf; + } + 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: + ebadf: + /* Static files are never open for writing: EBADF. */ + complete(cs, -1, EBADF); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat Apr 30 13:29:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568114 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7212322map; Sat, 30 Apr 2022 06:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAeiUkrPAvM2aJay/ouLNC/AdsA0SVouk7gNLprAPacZl+uBw0EMAB6chgdTul6OP2xr1B X-Received: by 2002:a37:e102:0:b0:69f:8463:cbdd with SMTP id c2-20020a37e102000000b0069f8463cbddmr2695051qkm.766.1651326126360; Sat, 30 Apr 2022 06:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326126; cv=none; d=google.com; s=arc-20160816; b=D4dYOIaQXmN0ibzPOTNaiWyvqS31jGOcvq9KxYRaXhsJHsNG1qQVYwsnurG52vIYN4 PDrX4f4w7rsw/CTd2wssjW75dLVFN3YrHzp+HVs1W2WnUk/pnAYu6itWZLZWlTHM3+kZ srAD7WdAxihZnKSYVcM/UksDDcrLm3oNLWq7/XNiTmtpXbzw/e6JJNwUIEQ8QYdLlNOk ShYg5amaUWbOwq/oPaVTxUNOJUofxogz1GAvB/vfDYERQwiwK+7bHrPOg7rjHYdCUuxj cM+5qknUl/4w5D0TfWypUi0m5PlEjIvnWgA/sid7MduHXpu4tY0rVJvBu6tvdCR3WfiL AO3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Y2rWbJS1eJALSwnl02x5AThCIttXRwsa/33AtoYRv2g=; b=qtm3Mxnc209ccJKhIQxBi4s5dZdW0RTrYDJ41Z5kSHC7r+bz4urYAq8KKXw4VYhb5y Hqa9ZJ1lWQz0QhWIbkUgLHG7MtlpkIScYLJzIMz6ZpfqL/7g8ayc6UHzD2BrlpUONpAt diD/3Yd0VeEIXhT3mVeBjb+oNgg8ggRxIbkshneYSLIi+rNZVmtwV2fLUC0legKJnt6I ik0HgzfUwagMsC3urHGfSinalP0d16BbWsNJU8u3aWuGUF5Lz1jWPw1+SZsGcwYCRWqo aiellMXji8fYpeLsEock9yr8+KsGo/MvpqB55PonYFxAP/8SbUQinLfLbiiRT5y8kTpX 7wTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dFCsCoqG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a21-20020a05622a02d500b002f393ac8bd7si1848896qtx.267.2022.04.30.06.42.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dFCsCoqG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknML-0003AK-Vt for patch@linaro.org; Sat, 30 Apr 2022 09:42:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAf-0004sm-Dx for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:40583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAd-0006I4-9c for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:01 -0400 Received: by mail-pj1-x102c.google.com with SMTP id iq2-20020a17090afb4200b001d93cf33ae9so12729520pjb.5 for ; Sat, 30 Apr 2022 06:29:58 -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=Y2rWbJS1eJALSwnl02x5AThCIttXRwsa/33AtoYRv2g=; b=dFCsCoqG/pMjDsLspf8/5J0Uw2z3zxHb/S0QL0zKeV67IkYT6MszvC1y36lQFr7LyT vKfksOqm5rBvaUnrgEwTegeqCqU1KzlYKKQv8wLz43U5MkWsjLS0EmEn5lYxXzOevQ9C GP4uE+UhZF/IQhMI24dtQlYR0eyLnbeGYYfRHw8I2aDDJfYb3ds8s6G2f6mteky1/ZWO VC0BSRdQPTfOTunevbax0+mmQByRkfoGNK8hjBOKWKQ+8jP7jnoy7b19kZtvZ/ozjMkq Y1PnNY8dJ7p71p8ZcGe6/sRGDpsJadiNElQHbm5ws/gyZHL1ySm8IiExHh1sv9EZCt/G Gu+w== 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=Y2rWbJS1eJALSwnl02x5AThCIttXRwsa/33AtoYRv2g=; b=BoTPEg8ymSgdcj8Hvz/upAS/6KPA9zILA2LzJuOwmGRNosySUM60KCSn03TrXcc520 vw2PzVnICQ4v5L0YP2e2KXfqKMPA4sa2G0aMjpz5ymUZVIk6D6IAD9s9BiVcan3a4Hpb 9jwgBDebGWMkIYPxeltNjWyzurUg7XvLHZrrW1O2+7FnUGzN8rXNokYUCWlwF46j/Vje Q2gz5kBPV4rLkKjPg+VfkVCncFAoK8H9jPsdY5quZcEmQIwWM0NDwQK3NdzFyygmvgG6 1e2E6B5yQ6A2vJ0UPQod5lvdKRUdioMTJEYr3yeUaQ4ZoFc9b4f6U2qnlZOTQksoL+QY SCeg== X-Gm-Message-State: AOAM533lQqz34NIOYqz2tf4iXkVKylKEpsCVzoU1UL8bxqf3j6Mj9Tkr 69BpzEHOAYmi1mfrJWj/t0MsakpU6OL0mA== X-Received: by 2002:a17:902:a710:b0:156:5650:f94a with SMTP id w16-20020a170902a71000b001565650f94amr3857158plq.86.1651325398141; Sat, 30 Apr 2022 06:29:58 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 24/43] semihosting: Bound length for semihost_sys_{read, write} Date: Sat, 30 Apr 2022 06:29:13 -0700 Message-Id: <20220430132932.324018-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Fixes a minor bug in which a 64-bit guest on a 32-bit host could truncate the length. This would only ever cause a problem if there were no bits set in the low 32, so that it truncates to 0. Signed-off-by: Richard Henderson --- semihosting/guestfd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 42efd2c558..356b87453c 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -364,6 +364,14 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, EBADF); return; } + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_read(cs, complete, gf, buf, len); @@ -410,6 +418,14 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, if (!gf) { goto ebadf; } + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_write(cs, complete, gf, buf, len); From patchwork Sat Apr 30 13:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568125 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7218942map; Sat, 30 Apr 2022 06:52:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKoasQocNOD7THSFjFkhyxnKAE3vNKKqCJJcCV5CA0iMNHUrG86UkuD2iU1liHlLyR8ez8 X-Received: by 2002:ac8:5fd0:0:b0:2f3:6495:64c1 with SMTP id k16-20020ac85fd0000000b002f3649564c1mr3555296qta.34.1651326777622; Sat, 30 Apr 2022 06:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326777; cv=none; d=google.com; s=arc-20160816; b=dgkgjYCwemO+u2QhNutG48lSYa5lG5ZKMI0lwbaadABIGHjRC4Ka9ynACeWbS33hke t3mrqYAotIBRp60ZhshOIIgYjzHbhr+s3XFd19aMGZf9kbIzXE2TURmpLikis5BBMY/j vL/XLkbvtGxwfKq0VIdGJ63NwtX6vNmMr43CabgFieqQilC7dZ4P9UtGOoVO4c6XFLAU dUuDJHYWKpCWN/DMXoJ3YAdXgbRehqawZNXyFSnpIqIN14cOCJgiWOaX2Ikq8pCct7dD QmNLNZv4DxA5gTr5nTzWTV87mGxsc+pu1G6Cj/Jpccr7yLvJaMATVHRGEGPfLcccHgjn Yn4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=daJgBRI1f4WcTuGoTO5bJfZcH8leBw7G8vdt6nAxSJg=; b=yq05FtM+8IIWEITQ11q8e0qaVv7NbZkG89+EuzgkxhmrZN88XSwe8Qvzp7tgo3aJEI cXvvqXNOw/7KNXxvDU8AeHLKZQWKVaqVDluNh6bRfLqvdP6F2aZsMxvZf6jx3LWq4Wkn trl7RSWR+w51X3U90bn5sOvr9Zo+IZbJBA1nuUkeiVECCImxAfjK0P8Dj8AISGt03urr DcCyPDEFMoMqwp/F5xdRh+ex7IeBSd2dHd/wy2+b6lopNyuwtyjg+LUwDWUzRb7dpTCV EgfeVWsIXlaRx1UZQvZEUJWE84aJw5sl6/kcJfL1WdPBxSlWRIJ5T6e9F/Er2iypG8G6 e8eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LrdmpaK2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h9-20020ac85e09000000b002ebc917850bsi4174455qtx.161.2022.04.30.06.52.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:52:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LrdmpaK2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknWr-0004El-69 for patch@linaro.org; Sat, 30 Apr 2022 09:52:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAg-0004u5-G1 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:44545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAe-0006IA-E6 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: by mail-pl1-x62e.google.com with SMTP id j8so9281569pll.11 for ; Sat, 30 Apr 2022 06:30:00 -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=daJgBRI1f4WcTuGoTO5bJfZcH8leBw7G8vdt6nAxSJg=; b=LrdmpaK2moDb/Z866j92nppfoDe+v9CCgXynFMAZ7/MAADx7F0jVlsWqntDnos2Aj2 Qgf2LSvPrhg4T8V3D1eBuEi8YMC+/CViOBdxJezFoT+3CemKvf8miZQv0a25fC+iTdVO yMg7bgaTKqZMk/JaqdcXp20W9YM8T3FjUD1CGGRKfvsFcYmbjU9TFhDINThi3YlLstAj e8GXGjKXAM326mznikmdF3U3Bv2Bqlgxlulj0otg0ZLp/7fKhixCJCjX4XPrRGyt4/XT QN+n/7mNunzlyWh5ogPRoHJSUhdgkjF5uwHQI31v1jIhsbSMnAjnk0XzSVhupXyBZ8P/ KVag== 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=daJgBRI1f4WcTuGoTO5bJfZcH8leBw7G8vdt6nAxSJg=; b=w2uiNxHLpDOgsHbjsODwADZkkNjVRAAvVt1zyuP2HbfyXXWUJr1CLMWgyORpF82O0i 5YWAGH5Vme1JA7HsW/NSUvYCDuVYw9o+FcBT6xIfXWMQ2LGS4KJlFj/5p/9apfQsZrv1 Q71i4FyPY+C34GgBx3PuNyUzn4eJaK2+R++ggZFzl0U7oClDLlzkPU8e0v3xvaM/SdBs ZoCWy1YWgHvy2i4YjMtr2l7tzFmF5cYWQNPaGCn6q3dtffXlNpxPtbyPUR3RIUelYg9n bzN7dBkiSw3xi9F/VgqcZ9f9Ql5oW0BPZdKL6UZVDqWJOfh+LoG8NrcYGuUEV9wUb6C2 r4zw== X-Gm-Message-State: AOAM530ZAE/9TOtldCM6JkU4qzCt/pggv6lKNMG1RpK74A6HH16ckpAT 6UNh8Ur6MYITTwqLByHeW6j3mzleJlwtBg== X-Received: by 2002:a17:903:300b:b0:15c:b49b:6647 with SMTP id o11-20020a170903300b00b0015cb49b6647mr3749724pla.90.1651325399154; Sat, 30 Apr 2022 06:29:59 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 25/43] semihosting: Split out semihost_sys_lseek Date: Sat, 30 Apr 2022 06:29:14 -0700 Message-Id: <20220430132932.324018-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_SEEK to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_seek_cb. Expand the internal type of the offset to int64_t, and provide the whence argument, which will be required by m68k and nios2 semihosting. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 5 +++ include/semihosting/guestfd.h | 3 ++ semihosting/arm-compat-semi.c | 51 ++++++---------------- semihosting/guestfd.c | 81 +++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 33a262a5a3..a7d3bfd5d4 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,11 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* 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/guestfd.h b/include/semihosting/guestfd.h index 5780ea2f13..9c6967ac53 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -62,4 +62,7 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, int fd, target_ulong buf, target_ulong len); +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 6568d205eb..0cab721a50 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -225,16 +225,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) #else syscall_err = err; #endif - } else { - /* Fixup syscalls that use nonstardard return conventions. */ - target_ulong reg0 = common_semi_arg(cs, 0); - switch (reg0) { - case TARGET_SYS_SEEK: - ret = 0; - break; - default: - break; - } } common_semi_set_ret(cs, ret); } @@ -257,6 +247,18 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } +/* + * SYS_SEEK returns 0 on success, not the resulting offset. + */ +static void common_semi_seek_cb(CPUState *cs, target_ulong ret, + target_ulong err) +{ + if (!err) { + ret = 0; + } + common_semi_cb(cs, ret, err); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -289,7 +291,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * via common_semi_cb. */ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); static void host_isattyfn(CPUState *cs, GuestFD *gf) @@ -297,12 +298,6 @@ static void host_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, isatty(gf->hostfd), 0); } -static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - off_t ret = lseek(gf->hostfd, offset, SEEK_SET); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -319,11 +314,6 @@ static void gdb_isattyfn(CPUState *cs, GuestFD *gf) gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -352,12 +342,6 @@ static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, 0, 0); } -static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gf->staticfile.off = offset; - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); @@ -365,24 +349,20 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_isattyfn *isattyfn; - sys_seekfn *seekfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .isattyfn = host_isattyfn, - .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .isattyfn = gdb_isattyfn, - .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .isattyfn = staticfile_isattyfn, - .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, }, }; @@ -518,12 +498,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].seekfn(cs, gf, arg1); + semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_SET); break; case TARGET_SYS_FLEN: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 356b87453c..e33d226534 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -442,3 +442,84 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +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); +} + +static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int whence) +{ + /* So far, all hosts use the same values. */ + QEMU_BUILD_BUG_ON(GDB_SEEK_SET != SEEK_SET); + QEMU_BUILD_BUG_ON(GDB_SEEK_CUR != SEEK_CUR); + QEMU_BUILD_BUG_ON(GDB_SEEK_END != SEEK_END); + + off_t ret = off; + int err = 0; + + if (ret == off) { + ret = lseek(gf->hostfd, ret, whence); + if (ret == -1) { + err = errno; + } + } else { + ret = -1; + err = EOVERFLOW; + } + complete(cs, ret, err); +} + +static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int gdb_whence) +{ + int64_t ret; + + switch (gdb_whence) { + case GDB_SEEK_SET: + ret = off; + break; + case GDB_SEEK_CUR: + ret = gf->staticfile.off + off; + break; + case GDB_SEEK_END: + ret = gf->staticfile.len - off; + break; + default: + ret = -1; + break; + } + if (ret >= 0 && ret <= gf->staticfile.len) { + gf->staticfile.off = ret; + complete(cs, ret, 0); + } else { + complete(cs, -1, EINVAL); + } +} + +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_lseek(cs, complete, gf, off, gdb_whence); + return; + case GuestFDHost: + host_lseek(cs, complete, gf, off, gdb_whence); + break; + case GuestFDStatic: + staticfile_lseek(cs, complete, gf, off, gdb_whence); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat Apr 30 13:29:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568118 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7214019map; Sat, 30 Apr 2022 06:44:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzTNbFNwKGfLV1HZoVlydU9+RZRGc6TXtPZIM3XaoytHNvdNUArd2dU4sTcSqfHEEGaQKF X-Received: by 2002:a05:620a:2915:b0:69f:1574:ea14 with SMTP id m21-20020a05620a291500b0069f1574ea14mr2876995qkp.200.1651326292696; Sat, 30 Apr 2022 06:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326292; cv=none; d=google.com; s=arc-20160816; b=SdmjZ0ahxR3HZQJ/mZ0d18jfUUQi0tPjZeAOGXiF8x1CInmjmAcO+7oH7tZ1rYD6z5 P5HzwLsdL3U2BPE7pQsTnFP2kEhVUPEQYcKlMtGIGCHt2kebUzsEdn96pDQElG8BX7l2 wNtN3aF2lrk1UWo5EyuiaPHTf7bFPHqMNG358akjiOIN7VFkIjLDD2eOPlFdDCZ7FNJK Pv+6phc/t0nzJcvAqyfE0VAOXL4XDvj5Xz8JQu4XyfS3MAlD/Egh/9rj1HS6SI/XpH0a Xuwhav7yc73V9NgKSS8ZNTiB7a7wHLnzuC1hqx+hWzRx9axJEvl05VMsOr5m6VsI0wCf wlXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=lqsGPuaCUPcJSOTUaNA4JwqOyqO5kgM0V/wVLGD2Hkdbx0kZRFQFh6RxQFPtfS1tgG zJjhFt7XwlYr4M/zudnuj7yeoMPacLrFIQi08p5w0toAt+ZhYcxgUVf1lV3vin18GnVq p3V4NXL059rHdZMcqtkjTN2Y/z9YbRtXTmI3P7pUM3ntQlYQIQGWhEceKDR60n5/Bj6s xmywQ8voJoFEoeapJZkMuusH1mK7fv6XdhyoyPo+4dNFxbXI54+EtiCIxlLtnCLtCk96 c/0VOSZQfnaAN/yM+jV97cnTe8RmkU9/yFSHiVpF1u/W/9fEm+xGU3NsnchZGnD2alX8 kWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bZNKDHVX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay12-20020a05620a178c00b0069f0febeb6fsi3891196qkb.434.2022.04.30.06.44.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bZNKDHVX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknP2-0000Sv-8U for patch@linaro.org; Sat, 30 Apr 2022 09:44:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAh-0004xT-Bc for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:06 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:33268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAf-0006IR-Ho for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: by mail-pj1-x1031.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so9749554pjb.0 for ; Sat, 30 Apr 2022 06:30:01 -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=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=bZNKDHVXJgAPpJoex5Y0STc+m70+YGhWkLQfC1HTWM0BYt+NCsDWyw8dChT62TEQPk 6N+uhfb8Fl8hD4eF5Bw/YR3N0ADiOjoUETeFn8IWvdPNgB3sF6UyABnnhDUoNcayozez q50Cl0hd5+yGqSuN78N9lkZXrBxTvTcBj6p1KpW/KfhiL5A2I2luiMik/CRpXgzxZZMS EAZlcVvauqjG1p3w+RI+yaoCZCeXyNsNYRLnSqLQa1f2tfkO55nu2IQMHZzI8dICVeGf I+Vynq1UldJkgOv/PtMb1gBoxI7VhIYiSr3VcFcfn1koAdD9lTesMq8SiByDSroggScH 1Gfw== 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=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=28NYCuJJNPvk41NqNboOQ2lkM8wZKmGQ3nnsSTta07snuv38NUmgESP+V1LHWF45h0 1N9VG82f315PSvDspA1xf/7vMiFbzFAhaZaczsSSJX7W2/snOiIXBni9Ht+ZhrUUV3g/ 6pqVnI9kijaUl7pzAkACyjDYu3l/kp+FaDtkw1N/M3ODBvv5MgscD/7Bo/ssnKHuP4n+ KNffFKYoiGKSoK4sALaSMNjfGbn7kCFeLuUAR078FapqrlsYxcu+1u3NzsrkpF6HdxLJ OWyPjx/qGmLYr4hGCDqNzEksSFApzF+buFaqxuzWBcfQBaZ1bYx1L/32Aij9y8HZwNEt m7FA== X-Gm-Message-State: AOAM530dilRo4QIGCpzp82iQA5UIB6EacDcAce4ZHvn956mhdOuy0HJQ S246+ONjBgvRA3Zmf512zK1quwM9jp0NNg== X-Received: by 2002:a17:902:82c9:b0:15d:2e43:a0e5 with SMTP id u9-20020a17090282c900b0015d2e43a0e5mr3804083plz.64.1651325400231; Sat, 30 Apr 2022 06:30:00 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 26/43] semihosting: Split out semihost_sys_isatty Date: Sat, 30 Apr 2022 06:29:15 -0700 Message-Id: <20220430132932.324018-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_ISTTY to a reusable function. This handles all GuestFD. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 +++ semihosting/arm-compat-semi.c | 27 +----------------------- semihosting/guestfd.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 9c6967ac53..d3dd081e81 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -65,4 +65,7 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 0cab721a50..3844d0e376 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,14 +290,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, isatty(gf->hostfd), 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -309,11 +303,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_isattyfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -337,32 +326,23 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { - sys_isattyfn *isattyfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .isattyfn = host_isattyfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .isattyfn = gdb_isattyfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .isattyfn = staticfile_isattyfn, .flenfn = staticfile_flenfn, }, }; @@ -487,12 +467,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_ISTTY: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].isattyfn(cs, gf); + semihost_sys_isatty(cs, common_semi_cb, arg0); break; case TARGET_SYS_SEEK: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e33d226534..6ed4a9162d 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -523,3 +523,42 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); +} + +static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + if (isatty(gf->hostfd)) { + complete(cs, 1, 0); + } else { + complete(cs, 0, errno); + } +} + +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, 0, 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, ENOTTY); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat Apr 30 13:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568123 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7218798map; Sat, 30 Apr 2022 06:52:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzII9WoJrpBMI6aFCBLY15wipCyQ17O2oPqrFo0SZiUE0Guc7v+hBlaNK4yHWH0o6KzsGWf X-Received: by 2002:a05:620a:4690:b0:69f:beb0:4e06 with SMTP id bq16-20020a05620a469000b0069fbeb04e06mr2801595qkb.591.1651326763929; Sat, 30 Apr 2022 06:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326763; cv=none; d=google.com; s=arc-20160816; b=ri8Kh3AVsVTbw+yoXPmQx/QTSXV60m8PfZBc3PnOORI0dax/UniTyl9KKstTiusqHK ciNyPaMdHrvcAZITpxjI2S/jnGwwNMxjWAvMP4rnXnpKHqwtSXHnff9q/dgLdE5s8s7O Fii5ITghXBj7/gDKfYohxr8ShzAJhXq0bVrL8mlU7jJ5PqoobOZzH4wFsWH1UMiRlmVo GkC+qG2b7tanwquuvZTcgJafOFwPNCZ/I3icHzdov7qUZAUauQ5k/yhhzArFkCf6SmJh RWbxU2HQ8Ujkf9E4mGVhMdol/9A6ViVtcwHGNnM57EPT9tpc3aQnFOoXZJuN9/rXhyTE MJfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=/V/5ek2/sTpAJkdwhvVli5OsV2nxpbp/oo1KwpsxAiw=; b=nmM+yNJN9Wnuaun66v535V7S/WcU1+/VrzyInx0jB88mB/HPK7vePBX9aVxyBEzSDm kbmj7dfE8lEJSEUlc4MACiJJI29qdAfn77ytFY9v7hMFpmnHKh/YS2r0m6weo26xhTab b3DzJzmX/eSC41lVbvOaFLp8EcANUjLdLe2j9UWuPhiofnJGosBg4h+09upTC7dT8pMp eRC+ZDibtexqe7HhzVPAyNuQgycxxBPqBpWVqyjgE2Q/GK1gu/H2Kecnmm0VfCh2eGXn jQZ3V0xrnVMmi5TnyUcAqMD+0ktnHS0nt41Hf8StVbrXah33dSu/w2kd9xITrRh661t3 c+BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KvWVZIAU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o14-20020ad45c8e000000b00440e46a7cb3si3928821qvh.337.2022.04.30.06.52.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:52:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KvWVZIAU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknWd-0003xs-Et for patch@linaro.org; Sat, 30 Apr 2022 09:52:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAj-0004yK-Ez for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:06 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:42824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAg-0006JT-H7 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:04 -0400 Received: by mail-pf1-x431.google.com with SMTP id x23so3772818pff.9 for ; Sat, 30 Apr 2022 06:30:02 -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=/V/5ek2/sTpAJkdwhvVli5OsV2nxpbp/oo1KwpsxAiw=; b=KvWVZIAU8RdLIvkgyGatvsVJtUsvXIyjxP+8ZgBKWA/EgDuf/jOv6xhvME0knEQa7k S8W+B55NCSMykiasRXDwTTKzrdnqzjSJeq/lM/opl82Qyzi3ym/AmP9xTLrxYLsz9C0/ /ieRLstx05Y4bsi8VFVUjcvrC8I9tXXpZoCbS309mJeNPnOO9iOG/vNltFccHIkYCAHe LqIPJSKdAi0KZQMFlN8xGWInXHEzrGNtztOAkCwBJUx1l441W7LaCHKcIc3QvwCmZ7Db s6lMCgZXSNKubwBP2uOrDTJRMwFl8Y8zwdYgC5XRlyi5X2F9GdHz8Sjr8NK/fGg0WpOt aNZg== 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=/V/5ek2/sTpAJkdwhvVli5OsV2nxpbp/oo1KwpsxAiw=; b=u2piZwSaYQJ6ED6B6v1zDnBjA2yyzT7HqOu5X12obcg+RqW3SzLc4kT74/uObCERQY NrhERleji477H8pEsDACP6xFUtRXXYvolABlP1Wpl6eR6BsHzd50L7tNpuaXoIJX43HN qNEQuLteAWcISjh91oYOqBmCKYPvgmwyu4HeStnGLYFWvT0tTgfaorTl6gWH6HZl5KYW PLFmzQMeTlpo58ShHtgTUALUlGVyb6qbc9NoaVUCA3iuqW1K7LzbJ/nTOy8pNevWZMfE 81B5ZvNmLBzDX8boxYRAqmc9bue29XZOeAa+ykXDfqKznolRnU8I36zCfHTPha5c0+xK K5WA== X-Gm-Message-State: AOAM530XTw2x0ihcoT4+LfzdvzASvSxuHFipbLd90OEqn25pgfrU7WuO dSfT0fZpHoT+PF7evwSHWYXcFpK+7GELLQ== X-Received: by 2002:a05:6a00:130e:b0:4f3:9654:266d with SMTP id j14-20020a056a00130e00b004f39654266dmr3678662pfu.59.1651325401192; Sat, 30 Apr 2022 06:30:01 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 27/43] semihosting: Split out semihost_sys_flen Date: Sat, 30 Apr 2022 06:29:16 -0700 Message-Id: <20220430132932.324018-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The ARM-specific SYS_FLEN isn't really something that can be reused by other semihosting apis, but moving the implementation to guestfd.c means that we can keep the GuestFD stuff together. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 4 ++ semihosting/arm-compat-semi.c | 83 ++++++++--------------------------- semihosting/guestfd.c | 55 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 64 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index d3dd081e81..d362b7ccf0 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -68,4 +68,8 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, + int fd, target_ulong fstat_addr); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3844d0e376..f9938ac879 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -272,41 +272,25 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) { - /* The size is always stored in big-endian order, extract the value. */ - uint64_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + - offsetof(struct gdb_stat, gdb_st_size), - &size, 8, 0); - size = be64_to_cpu(size); - common_semi_cb(cs, -1, err); - common_semi_set_ret(cs, size); -} - -/* - * 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); + if (!err) { + /* The size is always stored in big-endian order, extract the value. */ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + uint64_t size; + if (get_user_u64(size, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size))) { + ret = -1, err = EFAULT; + } else { + /* Undo the tswap from get_user_u64, then swap from BE. */ + size = be64_to_cpu(tswap64(size)); + ret = size; + if (ret != size) { + ret = -1, err = EOVERFLOW; + } + } } -} - -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)); + common_semi_cb(cs, ret, err); } #define SHFB_MAGIC_0 0x53 @@ -326,27 +310,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_flenfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, gf->staticfile.len, 0); -} - -typedef struct GuestFDFunctions { - sys_flenfn *flenfn; -} GuestFDFunctions; - -static const GuestFDFunctions guestfd_fns[] = { - [GuestFDHost] = { - .flenfn = host_flenfn, - }, - [GuestFDGDB] = { - .flenfn = gdb_flenfn, - }, - [GuestFDStatic] = { - .flenfn = staticfile_flenfn, - }, -}; - /* * Do a semihosting call. * @@ -365,7 +328,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - GuestFD *gf; int64_t elapsed; nr = common_semi_arg(cs, 0) & 0xffffffffU; @@ -478,12 +440,8 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_FLEN: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].flenfn(cs, gf); + semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb, + arg0, common_semi_flen_buf(cs)); break; case TARGET_SYS_TMPNAM: @@ -805,9 +763,6 @@ void do_common_semihosting(CPUState *cs) cpu_dump_state(cs, stderr, 0); abort(); - do_badf: - common_semi_cb(cs, -1, EBADF); - break; do_fault: common_semi_cb(cs, -1, EFAULT); break; diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 6ed4a9162d..3a2100585d 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -562,3 +562,58 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) g_assert_not_reached(); } } + +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); +} + +static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + struct stat buf; + target_ulong ret; + + if (fstat(gf->hostfd, &buf) < 0) { + complete(cs, -1, errno); + } else { + ret = buf.st_size; + if (ret != buf.st_size) { + complete(cs, -1, EOVERFLOW); + } else { + complete(cs, ret, 0); + } + } +} + +static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + complete(cs, gf->staticfile.len, 0); +} + +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, int fd, + target_ulong fstat_addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + flen_cb(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_fstat(cs, fstat_cb, gf, fstat_addr); + break; + case GuestFDHost: + host_flen(cs, flen_cb, gf); + break; + case GuestFDStatic: + staticfile_flen(cs, flen_cb, gf); + break; + default: + g_assert_not_reached(); + } +} From patchwork Sat Apr 30 13:29:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568126 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7219250map; Sat, 30 Apr 2022 06:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiRTUM9YWl9fwpo3l65/j6pSGuRO3b9tBtfKH5xJQHF5pQNQ/K0/AVdEDFgz40qWi/sVCP X-Received: by 2002:a05:620a:c86:b0:69f:c7cb:935a with SMTP id q6-20020a05620a0c8600b0069fc7cb935amr983365qki.229.1651326807572; Sat, 30 Apr 2022 06:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326807; cv=none; d=google.com; s=arc-20160816; b=MZBQP8sIxu1UrHezuOdNF47JUYH7viVKst2FC26zlQ0blItY5UawaUK3lxTcYy6VQl Xg+9teyYFLzBB2FxDE+JiBp/rwAt/0Z+So8yu34qswL4heE9tgdlPz3ND13RrjWbLC0j iyegYB4qSoV5NK2+okKdS3/eeRUMP8gyymlZ+a/khSyZkqSHS8hFj63jNkJzZL5g1TyZ G/L1vbTimaiSfEG98oBanpa/D80eN3N+WsTPDBorlpwDH3xC5wJ0ydv0l2Xtnjs68x2S Dwz4zOPWy+vdQAa8rQRF3O0qmCh3WITYCT5oUQ0ht61YXyNVDO4u5UPpiUD4mzTpoozM UBBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wjsjJKro/B7ogDkOsPzqR4XAGlS7j/Ldrx/QhnOdC5E=; b=JVOBequJLjhvNIDEhzS3OpcYVJerzw+h18hi0KQNPJ4N2qMVefDT/oCO1td6NJk7yY XmFlFWjMQvuomttVpHpBR41YIkTcOfnkIxapmZrcdGDn69bm1+LmFtQp6t+/BvPi9csW Pd1ZokwBqcW83edz4q0/CX96FoOS68fdjoKrgQTChXMxDh9BC7RUEOkojW/oc6XhUooK pVzqEIyodALYfNk4iXjlJBRX4ACX9xIsPuY/SFZTnw6yayUF6YhnNmFfVNHbkf+ZBAJs BUBsxUz+xHdsVkaWsv30f5uW2tdaQXQ1/YNT8BNdaBIhgMbhY0R6WRVR7HnRilXElYrJ lU6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OfRzmxNe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bs35-20020a05620a472300b0069f4031e6a7si2346869qkb.469.2022.04.30.06.53.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OfRzmxNe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknXL-0005X2-55 for patch@linaro.org; Sat, 30 Apr 2022 09:53:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAk-0004yR-5q for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:06 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:36539) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAh-0006K5-Gy for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:05 -0400 Received: by mail-pj1-x102b.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso12765622pjb.1 for ; Sat, 30 Apr 2022 06:30: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=wjsjJKro/B7ogDkOsPzqR4XAGlS7j/Ldrx/QhnOdC5E=; b=OfRzmxNe++0g76nMhh5aeBaag0Qsr39zIWssjobQpJYWcI1nxHfO0+t8YvY+sE0aj4 cmKAuWx/eI9rp//Ey+GpFz7eJjm0b6OyVinz7Wcx8kpGAhLdWnbT/pwQBXEu5OoyTes2 NH5RHYTl/N0/4LFGAC5iaTbOekmDA8INU+NjCD6t7FYHFjPe+w+VJzyUGSanapu7H5BY fpJAXT5TaDU2SfGduvGQFkKL3/UidOo0hPhOU7AkErM69eR49zaXUEA0ilFcu5Uqzu0i qYzNQGyCCJn+TKEESaSvNb5d3D/MSP031ICGgcduR9vasiCNGkownlwCSp4wrELvzD7A 2X+g== 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=wjsjJKro/B7ogDkOsPzqR4XAGlS7j/Ldrx/QhnOdC5E=; b=q/AkXoHtt37xApB1TC8gGcKjnnKuPZpRzLJ9g3YHircDEIfcnSkRPCdj2YkqeybnQN yCNY9ULPt+htTm8/uXAR0zqatbt58FsechcIPsAOKhxBRuABHFrRCKDVCGtIobzJbhGK MvoTiy0YoyJaZctfcWwAp3jt3sb6+o6rsmxcjNwLrNXuDKZYMGkoLTl4JPIXagyjAviK 45q6e7QIwLPqiw/EX2WVsRcTPuxS0DIVH0oULznQeUNRnD3FZlwHHkCgPjswMRHpMdDB yhz3ZuBXmFrwfj+J7YoYaFrebgur4JLvbEcVtL5pnHpodyRPXTbyCjz8andORESnwydk umcA== X-Gm-Message-State: AOAM530Bbt1iFyUowtkS7m3fj/gY5n+Y51ROq+Xv+KguGNn9HmGQKZzN jcDf0bixtJ7RKVtBPQJ/3uM4QYjsT7n8/w== X-Received: by 2002:a17:903:241:b0:15c:ee52:cbf2 with SMTP id j1-20020a170903024100b0015cee52cbf2mr3908919plh.10.1651325402248; Sat, 30 Apr 2022 06:30:02 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 28/43] semihosting: Split out semihost_sys_remove Date: Sat, 30 Apr 2022 06:29:17 -0700 Message-Id: <20220430132932.324018-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_REMOVE to a reusable function. This doesn't use GuestFD, but it does reuse validate_strlen() from semihost_sys_open. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 +++ semihosting/arm-compat-semi.c | 13 +----------- semihosting/guestfd.c | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index d362b7ccf0..c31a48598a 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -72,4 +72,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f9938ac879..d460754ea0 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -472,18 +472,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = remove(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); + semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_RENAME: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 3a2100585d..17d43e83d3 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -617,3 +617,43 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, g_assert_not_reached(); } } + +static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "unlink,%s", fname, len); +} + +static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = remove(p); + complete(cs, ret, ret ? errno : 0); + unlock_user(p, fname, 0); +} + +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + if (use_gdb_syscalls()) { + gdb_remove(cs, complete, fname, fname_len); + } else { + host_remove(cs, complete, fname, fname_len); + } +} From patchwork Sat Apr 30 13:29:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568129 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7220642map; Sat, 30 Apr 2022 06:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK7DvSZozZb479QJHbyuEbn6/jggKNCJJoHT/Kqv8O/gAVNuuhe9+UUAbzPfFY7gpMbXiM X-Received: by 2002:a05:6214:ace:b0:458:1336:4d3 with SMTP id g14-20020a0562140ace00b00458133604d3mr3197218qvi.69.1651326959734; Sat, 30 Apr 2022 06:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326959; cv=none; d=google.com; s=arc-20160816; b=jqWJrrg3moLtEZWTujkEjfkNpdSR3qK9r6gqjoR7jMuW4k96ueY5VJ2zYIS343onOn smKu4miYzr5RQcUOqtKLQCmE6fiXgZsi11pTqT+EnMg9QPkhLJeEKqIoqG/TW3ZrNuSG G3pQGSCTIK6FOZZknFL5ktylFgSBPQMUGSgzuCh5J/19EIq396ZeCFQfBDGDDejIGMsi 43d0HYbv2JoMsDWED8JLQs1dRqfCUm/5H0pWr+XFoKGe6CSIRrFoMeJGzaNoH87/EL0R bYFd7SBOX4GcIgqCxbPt0bU5Rt3z85XlEteddoyc/7K5HTxIPJwziUh/DYhjF6Ffp24p JA/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=yzC4mN9oeKC/XWEC5pXoNeqO+GLlfES9F20aR2uyY3vVpmBI9Mlmxbm3rx6UxbNfpt aI9fLq0FReHpOu1YyiWCJz3u6RNl15IeeNzyUSF1zqE1HbAZREOgTLGXr/+57SUtJHLY 584gMbSio5y/t0ZwHe2z3wgD3zbDo29BAKQzn65jP8RzqwuSXF8K7wXLWGGWlRms9FLr 5RbgyXynkv2og5ZeStWqHiAHBKZyVGzEIgdX+ZQNjquPAZnolOhE5cTR/UJKm5J2CDfG 87LxgszLs/mIxy+59o9gyMvKQ0NTDDRrdYmwuOmQvM5XLBInsrd+he+cWiBzJdR19YwR fNKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mPh9mY9L; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y13-20020a05620a44cd00b0069a14682517si4188342qkp.586.2022.04.30.06.55.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:55:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mPh9mY9L; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknZn-0001Ya-9i for patch@linaro.org; Sat, 30 Apr 2022 09:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAl-0004yz-Jo for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:08 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:40949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAj-0006L0-FX for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:07 -0400 Received: by mail-pf1-x42b.google.com with SMTP id i24so9053287pfa.7 for ; Sat, 30 Apr 2022 06:30: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=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=mPh9mY9L3eJP8WP8gDAI7ZVxpjFgvM3bxaU4wAeXpnGakUlzfFMgwRp5S/9CzPXVpx LqM1nRe5KrI4VeYBcHFJyj0tn6+ubj7y1uuGqgoXwbBSqjXCdsN/SNxBRoyBdr4kNWFF 49JhCEH1cvFyb02je6jCJCcrPpgUykAOQHBEdLWnL1fo5OsWmVMjiOu5/4tI1EUgFt0V bSOANX0dMqFWlM2DaxrYdJcPv6QqPFGSr9Ym14yF6VEV65Oof5ErrX/5T2lKp0OtOVyP 6zupC6Blt264sMG3DrOiRdrpes+09BT8lqqePL78jE0qEt8kOKaRYK67Lg4WCoy1Y9pH LG1A== 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=thg/qH430ddCqrwkV3ZntRtLEhaKDDdaC5slwVCyxTw=; b=5SRy/oveA69EtTCzsv6f0wuXTBOLL8UZALlXxwTrpcjtoexte6XHEQrIM9QL2qw5+M dVbJPW7Wtl7N7TQoShZXf3KHyj6NAnepbvSmzLs0TCJw2hQ+pYIGuIQbK7N3lkvUtchG y+OJ2MumsCBLr2n66iXq2DQGpYHXS1aNJS0L3iyU7EimLs6GeqU/J5RuQt7uA3SfupSl 0PugpOJ8wf/3UgQRYYf/NgYl8RnsvqW1LZcnnN1BMr+yPfp7SQayd2MQe0g5CmTAFtqj 3WFpq72iNgJ51TFTl0+U96vD4WtS57LkNi8vYYeND/5e1e7uL/AX3KmB5FI0itbfVagq HnAw== X-Gm-Message-State: AOAM531odTU/OzcBYr1FKXsr/W6mx4A+/DP4M7NHmU5XiYAJSf8FM3Dd xm+CAUZ7ZpDZJ+wsqsDCLxm0PYBFBUWITg== X-Received: by 2002:a63:1d5f:0:b0:39d:b5e4:ae24 with SMTP id d31-20020a631d5f000000b0039db5e4ae24mr3067945pgm.502.1651325403077; Sat, 30 Apr 2022 06:30:03 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 29/43] semihosting: Split out semihost_sys_rename Date: Sat, 30 Apr 2022 06:29:18 -0700 Message-Id: <20220430132932.324018-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. This doesn't use GuestFD, but it does reuse validate_strlen() from semihost_sys_open. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 4 +++ semihosting/arm-compat-semi.c | 21 +------------ semihosting/guestfd.c | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index c31a48598a..2bdf02429b 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -75,4 +75,8 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index d460754ea0..143c8689f5 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -480,26 +480,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); - } else { - char *s2; - - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 = lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret = rename(s, s2); - unlock_user(s2, arg2, 0); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); - } + semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1); break; case TARGET_SYS_CLOCK: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 17d43e83d3..03e516535a 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -657,3 +657,60 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, host_remove(cs, complete, fname, fname_len); } } + +static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + int olen, nlen; + + olen = validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen = validate_strlen(cs, nname, nname_len); + if (nlen < 0) { + complete(cs, -1, -nlen); + return; + } + + gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); +} + +static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret = validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret = validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret = rename(ostr, nstr); + complete(cs, ret, ret ? errno : 0); + unlock_user(ostr, oname, 0); + unlock_user(nstr, nname, 0); +} + +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + if (use_gdb_syscalls()) { + gdb_rename(cs, complete, oname, oname_len, nname, nname_len); + } else { + host_rename(cs, complete, oname, oname_len, nname, nname_len); + } +} From patchwork Sat Apr 30 13:29:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568132 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7222546map; Sat, 30 Apr 2022 06:59:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmQm5kGCFeG4TG0skE0oHEQOJrHTGgHFa5bfEO63Rm8/BiL9FBK4RVuiSX8ge/BZRn5UDc X-Received: by 2002:ae9:e887:0:b0:69f:9a9d:aa04 with SMTP id a129-20020ae9e887000000b0069f9a9daa04mr2805714qkg.31.1651327183569; Sat, 30 Apr 2022 06:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327183; cv=none; d=google.com; s=arc-20160816; b=VYCYEtM0mL6LQ/9d8UGFKnA4UX1wWhIjhPZv//EwVVOmZboPUOXcJAXgvIcc3/vxWX Ucjt1ZpGLwhNorqK67OicGwZ+F2WR4SKdcb13LLXbvmn2+1HnnQIOlIeC1Amnyf4sSCz SlkHIk4Wo+litOSvF/wvv6/kiS6oB9kj7Vq+NCGwLLco8qOUgnrMMuV0fA6gmtA6JHKl tkSBBvj5SLomhTknzrd0PIAlluReejXRH5b9u/GKvAuiJhnSghwqYAX+b1QNrkXtyqgP AtUaq+0uBzq2CWsPt5L1IPu3McR31lZHn5WnehpdXrLo/4SURrFnQki1fXGWsFc8IE+P rpvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=qA/dc39lMp/qfah2YhoKmuHzdA4VCD/D6LCwwGwyU4A=; b=df2YnG2mjkpf6QS7DR5bkklzLvIdD3Sv4NXSflCiXLtTMaM+vKJ9dTuDArex6xANpz a/Y2XlRLWSyOj0r3qZe/45IyTV/XRo3JvJY7RwYjjyp/pn+x/C9ulLulEAGZpYWB4qhp q3ub7bfezRjOljO6xHqe56mW2rqgPBnuEfcIg7EtM6PmBPrzIdQ9p5DvADNJ7a8B7uBi TvfFj/RFju8cQ3x2E9pUvPimwnxjhx97Ncp7Vz79qps02jQ3yCXpDJPusaPEzrFWfeBb 8TXUvex+PApIO2PyDtSeWavlyfZFXUmCekd+QlJMoTeaB0zfErlyvZmkvbaBrOzbyrpr uZKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aAsXhpdQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z14-20020ac87f8e000000b002ed58584346si3699182qtj.441.2022.04.30.06.59.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:59:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aAsXhpdQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkndP-0007UH-7H for patch@linaro.org; Sat, 30 Apr 2022 09:59:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAl-0004yy-J0 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:08 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:45970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAj-0006NX-Fc for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:07 -0400 Received: by mail-pl1-x631.google.com with SMTP id h12so9282238plf.12 for ; Sat, 30 Apr 2022 06:30: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=qA/dc39lMp/qfah2YhoKmuHzdA4VCD/D6LCwwGwyU4A=; b=aAsXhpdQg4Whxe9rVEPdPbpXlBwznzjH1tOm4GlVEIs0kP+gIburoRnF/K4me7YMVD Xq6GkQxwpLYbRAFV29tjy9QtdqY+YAmkBdnsbKbth5+TA7V8q1qRsnSqAJsZiYZ6OqEP 3nBy5IhUSdIxjkmoSpN20O9cwfi/D6i/RTlNNptv1A7FcMLhY7XG+tkY3e4LGSGPUKhw PTQxvSkX/nrNk6PNJf2UFzAKuVsTNAybysJalmpgKU+CyBKgEUEy1o8h8WGYUYpSEDQD En3VCt3CXoPpKDQtpOoimrHlBEUpkYEESJP6PZQLO/z0FftYz3/zU/67D9UtwZkC0JP+ 2/ig== 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=qA/dc39lMp/qfah2YhoKmuHzdA4VCD/D6LCwwGwyU4A=; b=KCjUzSUUMeNt49hEZuwCykapSVYOiqRri3lWqy1B6BVvasVz9/Clyfab1xNvR5wGIF kTFLNN+NtcFPPLjazcKCLhWpDcQuPHnSe7/TZGLkFmn6q2GSdw5Tn565BokXYQOw9rvY 7kBlXtCpVefymW+vQTkLQy5JywIvHMoHOFx3RrR8XjSdYlERtmQGqcXcdWZH6SIk9set wQU0F1jKcuOpki99jIZ+BLDPv7opkXRjRhw8OmiAEow1OsnysfL2jFUtHghsdVdoQ6xs +1pPYqjPyDiGs9P9dYYs9VxYJI0dKbNVuc/76jeEvSPZH0Nei5shHpe+KAHiluIxctIV QMLg== X-Gm-Message-State: AOAM533RYUQBHlBZCoB2MDvuyc5X8wbrsSvbKqOg51DFO2LFcwBbL+fg 5HX8/FXyHwwDRABgf2uw51rDnaKhwzqung== X-Received: by 2002:a17:90a:e641:b0:1da:43b8:95b7 with SMTP id ep1-20020a17090ae64100b001da43b895b7mr4213760pjb.180.1651325403858; Sat, 30 Apr 2022 06:30:03 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 30/43] semihosting: Split out semihost_sys_system Date: Sat, 30 Apr 2022 06:29:19 -0700 Message-Id: <20220430132932.324018-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out the non-ARM specific portions of SYS_SYSTEM to a reusable function. This doesn't use GuestFD, but it does reuse validate_strlen() from semihost_sys_open. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 +++ semihosting/arm-compat-semi.c | 12 +---------- semihosting/guestfd.c | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 2bdf02429b..a6d34e8141 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -79,4 +79,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong oname, target_ulong oname_len, target_ulong nname, target_ulong nname_len); +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 143c8689f5..61e8dede8d 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -495,17 +495,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_ERRNO: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 03e516535a..9176ddd301 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -714,3 +714,43 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, host_rename(cs, complete, oname, oname_len, nname, nname_len); } } + +static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + int len = validate_strlen(cs, cmd, cmd_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "system,%s", cmd, len); +} + +static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = system(p); + complete(cs, ret, ret == -1 ? errno : 0); + unlock_user(p, cmd, 0); +} + +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + if (use_gdb_syscalls()) { + gdb_system(cs, complete, cmd, cmd_len); + } else { + host_system(cs, complete, cmd, cmd_len); + } +} From patchwork Sat Apr 30 13:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568121 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7216429map; Sat, 30 Apr 2022 06:48:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4CPIXIkGuemp9aBniheGYH5prILG91Lp+pzlIYV9N1ceJlVLg/JX4mJeJMMEe8jzOD8Ph X-Received: by 2002:a05:620a:4502:b0:69f:9970:b7b2 with SMTP id t2-20020a05620a450200b0069f9970b7b2mr2798366qkp.92.1651326539263; Sat, 30 Apr 2022 06:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326539; cv=none; d=google.com; s=arc-20160816; b=y7Lw1BjhTY05gqlshSo4r4pnOm8ILdHsZG44NnbNw6fFp6VGcDavBri9uMIT/XzKhi a5SnPQJ/lIDP1xvgvhlgR0Do+4FFLtij51Q4fBoNnCGerUjPVykGfLjQ/3n/IG9nJWSU Yxy/1ps7BjCJPShkCVMiG7Gxfceo/NrulNKmEMXnPsJ4PbOL2+KEvfa1SAZd7bpz77HH EtkfpiYDbyqLqlww4IggJ69XOSql46nIWPcQttJ8A5x2AZIcQFeArq/SDnYlnhH3MfQc XEjE258xk+nTzmgT11N6cIYfI25OKoG6WAfajK9yvBbRBAJRkj78p3l9lCmmWZBEaNCg y69Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KzhRI9ZBMDbSjvbxlK4evTeTziJ0fFpirvhUh0Y9F/o=; b=PMXP/m9oKq2UYlfI/hn/Tvvv1cb8Ln5fE80sJ2YMp1cqnx3fRjKWZLmHexvxObakRb cYYA0f/VU5lv/pIHb1X97j+zqij6hqanbkfbe9MsXQKJVUTWKuScuLMey7jgbGhOxSLl ndKeroy8k4EAAIHZGLRLyg6X+V5BdWIitqHCr7qpJ7IxY0rRx18XZPsjrAF9qOQPDxlY ZZWWzZU+/b1iXI83n3rU8NlDgTnjHLrxZFKXyxzfTnxKfTbnNggPklIa3bYkTvSch6LA o2Ul1sn1RGrcqvnujaF6uEWufCyjyKK56xsnyx7x1XmwZD4k5Rxu4CjFVY7xlxzfo8IO qPYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xUQXwGJO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bk11-20020a05620a1a0b00b0067e4be23890si4283235qkb.213.2022.04.30.06.48.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:48:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xUQXwGJO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknT0-0006Cu-NK for patch@linaro.org; Sat, 30 Apr 2022 09:48:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAl-0004z0-QC for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:08 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:34694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAk-0006VJ-0E for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:07 -0400 Received: by mail-pg1-x52d.google.com with SMTP id z21so8514575pgj.1 for ; Sat, 30 Apr 2022 06:30: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=KzhRI9ZBMDbSjvbxlK4evTeTziJ0fFpirvhUh0Y9F/o=; b=xUQXwGJOmwyCFP9VQvwle5SAyxVEzVvT5jy7ReNbeQdilaqYY8EzhH6xTfMWoLk6cG k5aqtfKQItefka1WwZaCihavADzj3DfX3/zlKeyk1dU6ybpustq348nHAMHDRMvA+Ica A369e9N6Ur72ou4iogafQ3Lwd13eCNx1J5jBHQRdftYSsNPox3iRpRq3TGM0enPzfLSS 3rLClbVRhhe1R2Znky3pZsqY/STr0Pmo37XHd+IuzNrlCuVU8sTCMIjNorsY71q+nFvH 7ZR6fWcdblTxsv5o5qd/ChFc1XlUbTdUmN/g6agXn49TKe+XohbfwkDOHkqCgsFtDIE6 v83Q== 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=KzhRI9ZBMDbSjvbxlK4evTeTziJ0fFpirvhUh0Y9F/o=; b=az+iTPIrnCNXkOTkzPDwAtOzcYtkUnvifnaC3mTD/s02iJabVFzWQxuDcqpzZch07Y oqz8SHN3S6wGiJU+odjCi0FOBIRt7tezDqv348onN6Zs//z0x4w6DJo1V0JHt1z8dvB+ +sfn0Vd5skVbDCES0Z3mw7VYmgpK2qYs6gfKyS5V/4KpxefFfpl9BPoRdIrzTSHQ/rMC UgdjerYPEb2y2VbJkTHadi0/KaRht8F9OgIaBoDHJrd/EXT64a5Z1p8TLIyhSXqUN8l5 2JsFuud0ypyFr3rw/Mvr/ufvrKkGYa5w3fGqkrhO61h/6WchkDI/n9o5E/pxOtUxGLuk ILqw== X-Gm-Message-State: AOAM531UsIa2nZWKNHq7I+tlrbdXMZjmBNKIbdHftiQWn5Y88j75lacz FwkISS2LykIygemVI3jZvksAvhzzWabKxQ== X-Received: by 2002:a63:500a:0:b0:3c1:afc5:1213 with SMTP id e10-20020a63500a000000b003c1afc51213mr3199257pgb.148.1651325404721; Sat, 30 Apr 2022 06:30:04 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 31/43] semihosting: Create semihost_sys_{stat,fstat} Date: Sat, 30 Apr 2022 06:29:20 -0700 Message-Id: <20220430132932.324018-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These syscalls will be used by m68k and nios2 semihosting. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 ++ semihosting/guestfd.c | 137 ++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index a6d34e8141..315cac1c44 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -82,4 +82,11 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong cmd, target_ulong cmd_len); +void semihost_sys_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); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 9176ddd301..c182d5b7e6 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -563,12 +563,95 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) } } +/* + * TODO: Note that gdb always stores the stat structure big-endian. + * So far, that's ok, as the only two targets using this are also + * big-endian. Until we do something with gdb, also produce the + * same big-endian result from the host. + */ +static int copy_stat_to_user(CPUState *cs, target_ulong addr, + const struct stat *s) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_stat *p; + + if (s->st_dev != (uint32_t)s->st_dev || + s->st_ino != (uint32_t)s->st_ino) { + return -EOVERFLOW; + } + + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -EFAULT; + } + + p->gdb_st_dev = cpu_to_be32(s->st_dev); + p->gdb_st_ino = cpu_to_be32(s->st_ino); + p->gdb_st_mode = cpu_to_be32(s->st_mode); + p->gdb_st_nlink = cpu_to_be32(s->st_nlink); + p->gdb_st_uid = cpu_to_be32(s->st_uid); + p->gdb_st_gid = cpu_to_be32(s->st_gid); + p->gdb_st_rdev = cpu_to_be32(s->st_rdev); + p->gdb_st_size = cpu_to_be64(s->st_size); +#ifdef _WIN32 + /* Windows stat is missing some fields. */ + p->gdb_st_blksize = 0; + p->gdb_st_blocks = 0; +#else + p->gdb_st_blksize = cpu_to_be64(s->st_blksize); + p->gdb_st_blocks = cpu_to_be64(s->st_blocks); +#endif + p->gdb_st_atime = cpu_to_be32(s->st_atime); + p->gdb_st_mtime = cpu_to_be32(s->st_mtime); + p->gdb_st_ctime = cpu_to_be32(s->st_ctime); + + unlock_user(p, addr, sizeof(struct gdb_stat)); + return 0; +} + 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); } +static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + struct stat buf; + int ret; + + ret = fstat(gf->hostfd, &buf); + if (ret) { + complete(cs, -1, errno); + return; + } + ret = copy_stat_to_user(cs, addr, &buf); + complete(cs, ret ? -1 : 0, ret ? -ret : 0); +} + +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, 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(); + } +} + static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf) { @@ -754,3 +837,57 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, host_system(cs, complete, cmd, cmd_len); } } + +static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr); +} + +static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct stat buf; + char *name; + int ret, err; + + ret = validate_lock_user_string(&name, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = stat(name, &buf); + if (ret) { + err = errno; + } else { + ret = copy_stat_to_user(cs, addr, &buf); + err = 0; + if (ret < 0) { + err = -ret; + ret = -1; + } + } + complete(cs, ret, err); + unlock_user(name, fname, 0); +} + +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); + } +} From patchwork Sat Apr 30 13:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568135 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7228117map; Sat, 30 Apr 2022 07:06:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWSs08VpG1oqejZNBiLPV6/zMaS3dEGeZJaFXUTTwb2xPL/0JG2tKuns/DihCVtOy6CIhx X-Received: by 2002:a37:48e:0:b0:69f:9bc8:720d with SMTP id 136-20020a37048e000000b0069f9bc8720dmr2796579qke.268.1651327561710; Sat, 30 Apr 2022 07:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327561; cv=none; d=google.com; s=arc-20160816; b=sSwcNnhqJzhRj9XvJ9h53FgQCMKotLHOIZ/ZVjrquxYvHC/qc+P+JImedzQQSOQmMD NmGqYGn5XR0XMbq2AJYbLMOg0ta1JHEQ59KcdUuEo17uZKWkgrl776/cJ3GEI+nZ/U6o IzYPV8gNnmrFFS6VYfYrakZRILR3UJRDc1MJd1CT4YRPXjwk1eaR0LL9D7etLu0ZbLHz nBUSY7FZe/uRSAXnNgR2PJLjo5WGqERy7eXKHFpjqHG2tqiqU8hft0mevJ6wXqfOwsnm j0FcB+TgkrsDspw6A3drKRxmTi1HwAWSLusT3QbGjd4TO5pUCGfganE3D60naL6T77As HNMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=6GpLQ8ipNBATQfL4tdhE0DDcTIbaXhK4bLfdN035pIc=; b=WNYzpxUnaTOWMuNUOSje7BcZn7OVI5JzoTZWQTzf7WkF0SCwDL1KVLyOUGgGDE5kfB LWymtjGFFTdGtQf0dUYjXrN5DVsIC1eA43y98o5kG5YQ61I31YCBaZY4cvOvDdPH5vjt uOW+yPtqPhsXFYaEcQcuMlzWL1hwAsTN2N9UKdlBBUpF+ipUXx/mxjEbjju6NhEIeD2D s63TRNIEQGaw4eo1fn0u4QTfYkUe55B1mt32hHgWKSOfYoeq5Y6Dce+/jsSP9RD+XJlh ZzjrHIjwfyuFMAb0BqtibxhLt0dne+/z07kVZjw4nXD+FAmvaKI1lDjJBjdGqCOyaXns iAlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WthsuyDj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d22-20020a0caa16000000b0045644c232b4si3359083qvb.576.2022.04.30.07.06.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WthsuyDj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknjV-00057p-9G for patch@linaro.org; Sat, 30 Apr 2022 10:06:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAn-00050E-2W for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:10 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:39927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAl-0006VW-9g for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:08 -0400 Received: by mail-pf1-x432.google.com with SMTP id y38so9057812pfa.6 for ; Sat, 30 Apr 2022 06:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6GpLQ8ipNBATQfL4tdhE0DDcTIbaXhK4bLfdN035pIc=; b=WthsuyDjOyrZl9sL8Vz2XFwgflAVbWZcMmE2MtiiyEb39Rac9uJ+SL/W9SSL7dCNp1 Zdo3WORuM6k9u8cXpBdevEGeb9ebWUw0m+wZrjKVMwsZAFM/3C3Aq7E9E5f52kTXp1kz 6522H7kFbsXPT0fqqx+u1+q3Fg/DNP2/dy8+t5VbO/EfJST718vjOOn9PMg4zYZU8vax qkGpVD1IDxdgELVvGHLkgsMb/OUY2HkXSqnW1JCFXrPHh+dZadwHWW4TYgXbNdV6lZZT SHakTKbRcOr3Cysv1OI4q4lgb9n6mDPYdSp6CVM1nRbR43xbQGiWyTCbyPDBPORFhkfx VSQw== 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=6GpLQ8ipNBATQfL4tdhE0DDcTIbaXhK4bLfdN035pIc=; b=jLeRRaNq8j6rTLhtk3Qb901M+oekU9kiPXVrKc7gBZS/Klw0MWZJcF3uya6xrtim2a bpXZSd+uwl2BzPEPcFkpr92zL2EF2EUXwfB3SXnE6MQT6HjyU6zvfuc3RxhFoMmOQFby h6I5o5WMR2qGnOt09fD0YP1I4+743x4USNR2xjXdK/otZx3elgcrWrrilmCWK+PlhWKp T3salYgce5HIRM+6jHzqPIYqK3aNbJjroxO1g9WwoFjKAhwB8RKKAoyoVJIjmltFwYpk tZcMKKt7ipSgfkvQ+JJBGCXNiJSAe1LQzJGVxVsDshbyg1jHH2GWvkHc8xLMNEwshIB7 1jpQ== X-Gm-Message-State: AOAM533UlzB/DJly02cflgHJ26SOcPCtR9S5hHPjGzDPzuTvhrVVZqtA c32d1y9hsEXjWpgyU1jEGIjeyzsM+7HEoA== X-Received: by 2002:a63:7702:0:b0:3ab:4d62:b68b with SMTP id s2-20020a637702000000b003ab4d62b68bmr3248383pgc.452.1651325405516; Sat, 30 Apr 2022 06:30:05 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 32/43] semihosting: Create semihost_sys_gettimeofday Date: Sat, 30 Apr 2022 06:29:21 -0700 Message-Id: <20220430132932.324018-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This syscall will be used by m68k and nios2 semihosting. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 +++ semihosting/guestfd.c | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 315cac1c44..5b0ed1b472 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -89,4 +89,7 @@ void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, target_ulong addr); +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr); + #endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index c182d5b7e6..cb9eab9587 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -891,3 +891,45 @@ void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, host_stat(cs, complete, fname, fname_len, addr); } } + +static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + gdb_do_syscall(complete, "gettimeofday,%s,%x", tv_addr, tz_addr); +} + +static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_timeval *p; + int64_t rt; + + /* GDB fails on non-null TZ, so be consistent. */ + if (tz_addr != 0) { + complete(cs, -1, EINVAL); + return; + } + + p = lock_user(VERIFY_WRITE, tv_addr, sizeof(struct gdb_timeval), 0); + if (!p) { + complete(cs, -1, EFAULT); + return; + } + + /* TODO: Like stat, gdb always produces big-endian results; match it. */ + rt = g_get_real_time(); + p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); + p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); + unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); +} + +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + if (use_gdb_syscalls()) { + gdb_gettimeofday(cs, complete, tv_addr, tz_addr); + } else { + host_gettimeofday(cs, complete, tv_addr, tz_addr); + } +} From patchwork Sat Apr 30 13:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568124 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7218902map; Sat, 30 Apr 2022 06:52:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvO0a+5oJFWoWO/07KfvttwsMHK8Z6M5dwH+kIHtqUSQ8gakCU8x+hzCcpcb/dpNbYRe7Q X-Received: by 2002:a37:6902:0:b0:606:853:fe50 with SMTP id e2-20020a376902000000b006060853fe50mr2747193qkc.751.1651326773132; Sat, 30 Apr 2022 06:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326773; cv=none; d=google.com; s=arc-20160816; b=n3PaG0X2SUR1ZKY0o8jjGZ7Nv3mf1FvnTGjQuc6auM2CbzYEWsgHO1aBOJ+JuyqPXX n4EOIp5BYzW8ZwJ3XazdBcte08KGONwpiCBh5EqnRxjYCrZQDkOn1vpRzOv1dlemU/Xr sObtWU5Tn+zMVEsaLwDBM/VZtnDyCsiKqOQ5yxcs4ngGOTpX7JEjLGpYsMRXeWkbBVJh f82QcysNAesscQ4FbRwqBSgMfp3TjDdDEEo3/EMJNkUbfBm2mjYiiZhwgCvyz17/jrbs D1AH9n6qGJYgiAYLXoS8XTxsLpwHiuOwaBPhiOS2Vx1fhHR2/Go91+ARIMzT587ZgJN5 4vqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=tSJK3mS4bOjkLh53cDYFX3XNRh44hRQ7vDXtW3G1P34=; b=z4tGVQTrmJkrxKq9CGThpZkKadVmHz2nqtpSKuaKg8r68rfCqQqoUQ/5pk9uTitqyK 2M1h9vcvNAUxBdcntlbpNaOBM6KUBAkIdPHYVYjMBAKMsWGRF3Iiw/Zyr4XjdQ9MRQeX SjemMoLUu4wI777T2wu2i8lwzI0hw5wft8kxvAZDfP7rRN19AgPVACQZwQ0iYn2gP5t7 NXJ0qShBtavSR32ksqYaK3zvdjeOuMnCEac4H3XFggDPpdfGsvDFBdmuM2EvCjYMchUW QJpVWt7iQh7dEIOkqTDkGYGAZQqIm21dp6Nsb0URkvSNIIAMnvcODZxjifIZ1TPKbxWt P65g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tvvn4E23; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u21-20020a05620a0c5500b0069c35f3b191si4305062qki.598.2022.04.30.06.52.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:52:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tvvn4E23; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknWm-00049l-Jx for patch@linaro.org; Sat, 30 Apr 2022 09:52:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAo-000511-Mu for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:10 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:42644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAl-0006Vq-Qk for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:10 -0400 Received: by mail-pg1-x532.google.com with SMTP id bg9so8493891pgb.9 for ; Sat, 30 Apr 2022 06:30: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=tSJK3mS4bOjkLh53cDYFX3XNRh44hRQ7vDXtW3G1P34=; b=tvvn4E23OxaJmGtQqlIGdSK46W6Le8Lz8VADY3KMfreXn71o0RD3AgBfjvx0Os34YE 9nOmqEsDQCClYw6slIs4Lf7eWNOEUaAdUKTLSDtDMC5zEhGz3kNw2x/dGmxwme8yTGG1 CQojwGJKIzsKvjeRbRotxk+aSq1Ky+kjqLW9kiX+zzv1uoiGdrAlAJmDI2Joh+t3/gnY fJdekva5L/OgePMaemI59W5JA7cNVi5xtKw/T6moViB+Ny9p4e5U0i+1lDUvdtTNNnaG MNqA/KZeVTtBjCcODkx3zkLhzk/rVZqkLp8+QKQxMYw7oSgABO/cDGrriQaleyWTffaa bGlg== 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=tSJK3mS4bOjkLh53cDYFX3XNRh44hRQ7vDXtW3G1P34=; b=RDpUip4BwuWISaHMMXUKckiRyT3iDNK8c5HRKvfvh5x+aHuP1Bvr/ARSV08vvu9dC4 UKlRjZ54yorqDE707T/F8Lf+pLuefw6jap7lonBhg+6ybWBNfnubJO8HQEopnJu8u8/6 U9M7K9BInaFAnXt/Rbmw2a2wAPZV7uWQZ7M2Ds7JriIKILoCmsdljxjVocX+Uk/C5UVl 37tXKYTFqoq3OyTXCMbMuU5uC4LeGefLEw5oOHpY3Y+xRh4p9TW1LfjQJbBozpigH9ki Xz/jwk+aPU4iuhg4DJrvBUh9bqMLUnLsvPzwE2r9lfj/HplsZLZ1srcEjRSKFSlYNpZT fBLQ== X-Gm-Message-State: AOAM530/+p3uEwI7bAtXW8n+VA35kvz1YNuhQUl1eobxi+uETJrbDUQc iuCF+6BUbKCT77r5bcEHZtVlY42kpC1EKg== X-Received: by 2002:a63:f954:0:b0:3a8:2153:78fb with SMTP id q20-20020a63f954000000b003a8215378fbmr3149883pgk.8.1651325406539; Sat, 30 Apr 2022 06:30:06 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 33/43] gdbstub: Widen gdb_syscall_complete_cb return value Date: Sat, 30 Apr 2022 06:29:22 -0700 Message-Id: <20220430132932.324018-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Always pass a uint64_t. This resolves a FIXME in the m68k and nios2 semihosting that we've lost data. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 3 +-- gdbstub.c | 7 ++++--- semihosting/arm-compat-semi.c | 9 ++++----- semihosting/console.c | 7 +++---- semihosting/guestfd.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 a7d3bfd5d4..22b386ff65 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -53,8 +53,7 @@ struct gdb_timeval { #ifdef NEED_CPU_H #include "cpu.h" -typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, - target_ulong ret, target_ulong err); +typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err); /** * gdb_do_syscall: diff --git a/gdbstub.c b/gdbstub.c index a3ff8702ce..5286253f8a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1870,11 +1870,12 @@ static void handle_read_all_regs(GArray *params, void *user_ctx) static void handle_file_io(GArray *params, void *user_ctx) { if (params->len >= 1 && gdbserver_state.current_syscall_cb) { - target_ulong ret, err; + uint64_t ret; + int err; - ret = (target_ulong)get_param(params, 0)->val_ull; + ret = get_param(params, 0)->val_ull; if (params->len >= 2) { - err = (target_ulong)get_param(params, 1)->val_ull; + err = get_param(params, 1)->val_ull; } else { err = 0; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 61e8dede8d..ad0df6eabf 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -216,7 +216,7 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_cb(CPUState *cs, uint64_t ret, int err) { if (err) { #ifdef CONFIG_USER_ONLY @@ -233,7 +233,7 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) * SYS_READ and SYS_WRITE always return the number of bytes not read/written. * There is no error condition, other than returning the original length. */ -static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err) { /* Recover the original length from the third argument. */ CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; @@ -250,8 +250,7 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) /* * SYS_SEEK returns 0 on success, not the resulting offset. */ -static void common_semi_seek_cb(CPUState *cs, target_ulong ret, - target_ulong err) +static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { ret = 0; @@ -272,7 +271,7 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { /* The size is always stored in big-endian order, extract the value. */ diff --git a/semihosting/console.c b/semihosting/console.c index ef6958d844..3dd0ac60e2 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -64,11 +64,10 @@ static GString *copy_user_string(CPUArchState *env, target_ulong addr) return s; } -static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void semihosting_cb(CPUState *cs, uint64_t ret, int err) { - if (ret == (target_ulong) -1) { - qemu_log("%s: gdb console output failed ("TARGET_FMT_ld")", - __func__, err); + if (err) { + qemu_log("%s: gdb console output failed (%d)", __func__, err); } } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index cb9eab9587..341113f939 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -179,7 +179,7 @@ static int validate_lock_user_string(char **pstr, CPUState *cs, static gdb_syscall_complete_cb gdb_open_complete; -static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void gdb_open_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { int guestfd = alloc_guestfd(); diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index da0186f3ef..94deebf09e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,7 +93,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) +static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || @@ -108,7 +108,7 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) +static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || @@ -122,16 +122,12 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) static int m68k_semi_is_fseek; -static void m68k_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; if (m68k_semi_is_fseek) { - /* - * FIXME: We've already lost the high bits of the fseek - * return value. - */ m68k_semi_return_u64(env, ret, err); m68k_semi_is_fseek = 0; } else { diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 3e504a6c5f..4d02789d26 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,8 +108,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, return true; } -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, - uint32_t err) +static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret, args) || @@ -124,8 +123,7 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, } } -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, - uint32_t err) +static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret >> 32, args) || @@ -139,7 +137,7 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, static int nios2_semi_is_lseek; -static void nios2_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; From patchwork Sat Apr 30 13:29:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568128 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7220559map; Sat, 30 Apr 2022 06:55:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOZt3Cs0bTz72qfWdQC44BHqhPUgJDKKdyiA5zEjg/qkrA0mjCwXKgMTDbr9Pv2f7D2BAl X-Received: by 2002:ac8:7d10:0:b0:2f2:2a7:41ff with SMTP id g16-20020ac87d10000000b002f202a741ffmr3430002qtb.566.1651326948619; Sat, 30 Apr 2022 06:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326948; cv=none; d=google.com; s=arc-20160816; b=ORS1OAqrvesfsx1GqHv+0jraJIUItU+W1uly+AZY8Hv1M4/ELgFRrSTsnHq3iarbrP rQ0rsh0NV2Ts3jam956dhlDw19zDH7iVJo0QVOodU+PH7cX2/XoD4cenQHJLrwQIvCWs 3jWT7ed7+jTnbkpvCzk2dlSYQWDw9Y2HZeVseeUk20KeUu+tQtjAMNZREdBFeqWJ4KDN VUkZHanjuoF1KD32YDm3arjscSoi59BAiJRqm9z2N1/xsLRJeav0i2E5M7JieUSLpdrn RTGEEn62i4El4QelFAUOcrhmRhBTZ3nqPbgLlH4WsRQgVxjj9bzHHYlpXSPqoW25mzCB aPCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=WQZlHIkj4guY1fe81bPK+C+z0QSBc+oYPvv48Zt6reM3vYyflwaIO2az65qooTNNZk Rcq/GdHruKyVJ7AwaS9EAa50ZRAGpFbFuoL/YcZ5hVpt7CCVm8abKlnMGWq9KYSf2ilW hXRR0URonsd6X0uMRH/F5iS+w8xYObAyKtuDs23srq+ct5Ng9HLDOwnvtqpODgmnWXLT 8TkPJLTiG9O5HJXseJ8HX+GDKsiBVbBQqZE1hmdB3cHHgB4sDBE+a22tGyxaRa/yqzir /nRphG1rILMxEepM7wY5eadP0tHkY4UXT24Izex0hvV696ebiAwzdepUJt0pQOPkqca0 7tKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sKpzkJIs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r13-20020a05622a034d00b002f344779826si3973058qtw.550.2022.04.30.06.55.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sKpzkJIs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknZc-0001PO-43 for patch@linaro.org; Sat, 30 Apr 2022 09:55:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAo-00051N-S7 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:11 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:38854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAm-0006WH-TQ for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:10 -0400 Received: by mail-pj1-x102f.google.com with SMTP id cx11-20020a17090afd8b00b001d9fe5965b3so10814015pjb.3 for ; Sat, 30 Apr 2022 06:30: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=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=sKpzkJIsDOfc/h2PsKLyg7O2eVGSwEhwrukpLzUilXgcRV4n3fMkTAgA5LG+dJyzKf rS0OHXHHDxaLR4Wq6GZ8d3cJGjPDrKDXj3DuHlw9kD1dovBSS05Mfu13G+A4nerP2+wY DWOzgOBbIsYY2uh+c7LD+lmaN1ExlUnuH0MAIT9GuOMXxwxkBiX5N1L0bUjoly/Gy4bB u/8mNTUHbXMWEzpT9ZjTgn644JiJiCdjqlWdQaZ63SWAjcknsJqF/rRb1tU7tRd5Jfv6 UcLdqFJhAmhwWda7Fq4cRMTEHx0R3PoDtp9ABzGIs7rCr05YiCGaDxajtNx6VLhnx5j0 oM3w== 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=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=1eq0qTt6BGP/T6GpRB1BtKKmScGyq/daG3f65cyIl8aYnu0U5skBVeFuBCWXoXS8hr y6Ofui+XLj/hwwq6Tr9D3Ly2kS99QlV5rJyAQ6G4f6RvGA9EfpYZQ19iUjPM0jU0Smi2 Eb9Fx4IxIDcsl3/LGs/Gh4MOomAaKEYC7Q2AHsB1CkF9t9riu/QEZtSYyNg7fb1FmnkG JWsAXNOh2C9Hpeg6JwUOFAsE5yAy9pps7wS97RR3d364F5cgUJtXyaE7Dnps7hqouXvv gvDsjXpW70ZDDAsO4anSVYy6HQiDH+RZKB6bHrfpxU9nB5WX3Tehx3Czpd6HqL2mgb8w UojA== X-Gm-Message-State: AOAM5324LHcNlnoBQ5rO+w1JN+9qEWPj4McHkzQm0K738CQSju7SNIdl WoPDLpFOjGUTJftQvv1b7YfneYwhPaq97A== X-Received: by 2002:a17:90b:3901:b0:1db:f2a7:c881 with SMTP id ob1-20020a17090b390100b001dbf2a7c881mr9182781pjb.229.1651325407563; Sat, 30 Apr 2022 06:30:07 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 34/43] target/m68k: Eliminate m68k_semi_is_fseek Date: Sat, 30 Apr 2022 06:29:23 -0700 Message-Id: <20220430132932.324018-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg m68k_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 55 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 94deebf09e..5b4c51957e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,8 +93,11 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) +static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || put_user_u32(err, args + 4)) { @@ -108,8 +111,11 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) +static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || @@ -120,21 +126,6 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) } } -static int m68k_semi_is_fseek; - -static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - M68kCPU *cpu = M68K_CPU(cs); - CPUM68KState *env = &cpu->env; - - if (m68k_semi_is_fseek) { - m68k_semi_return_u64(env, ret, err); - m68k_semi_is_fseek = 0; - } else { - m68k_semi_return_u32(env, ret, err); - } -} - /* * Read the input value from the argument block; fail the semihosting * call if the memory read fails. @@ -149,6 +140,7 @@ static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) void do_m68k_semihosting(CPUM68KState *env, int nr) { + CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; void *p; @@ -167,7 +159,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, + gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, arg2, arg3); return; } else { @@ -188,7 +180,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) int fd = arg0; if (fd > 2) { if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "close,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); return; } else { result = close(fd); @@ -204,7 +196,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", arg0, arg1, len); return; } else { @@ -224,7 +216,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", arg0, arg1, len); return; } else { @@ -247,12 +239,11 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(3); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - m68k_semi_is_fseek = 1; - gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x", + gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - m68k_semi_return_u64(env, off, errno); + m68k_semi_u64_cb(cs, off, errno); } return; } @@ -262,7 +253,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "rename,%s,%s", + gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", arg0, (int)arg1, arg2, (int)arg3); return; } else { @@ -282,7 +273,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "unlink,%s", + gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", arg0, (int)arg1); return; } else { @@ -301,7 +292,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(1); GET_ARG(2); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "stat,%s,%x", + gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", arg0, (int)arg1, arg2); return; } else { @@ -323,7 +314,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", arg0, arg1); return; } else { @@ -338,7 +329,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", arg0, arg1); return; } else { @@ -359,7 +350,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) case HOSTED_ISATTY: GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "isatty,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); return; } else { result = isatty(arg0); @@ -369,7 +360,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "system,%s", + gdb_do_syscall(m68k_semi_u32_cb, "system,%s", arg0, (int)arg1); return; } else { @@ -427,5 +418,5 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) result = 0; } failed: - m68k_semi_return_u32(env, result, errno); + m68k_semi_u32_cb(cs, result, errno); } From patchwork Sat Apr 30 13:29:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568130 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7220905map; Sat, 30 Apr 2022 06:56:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1WcALkjEp+s46RY7bTR4is+0Tc3m8i7smxYextY7/G/r2ttByIY5LGv++2ujyGBTedKS6 X-Received: by 2002:a37:9c8b:0:b0:69f:8793:f2ef with SMTP id f133-20020a379c8b000000b0069f8793f2efmr2852027qke.300.1651326982299; Sat, 30 Apr 2022 06:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326982; cv=none; d=google.com; s=arc-20160816; b=Hbi/59uV8hOpqlOTTc0BYP2cN5WfDU2WCzQwkY32D04W8oGfyWbbODDoYX79aSNEGv ObTFq9c87vhR2IzLd2ld5YkC9hzBttjuyV3moCHhuLfOlfFf/Z8mLr7lKZtuHxGii7Tz vFkLdlPJBjNSraPFTE91BshntSmSv9xRwxzFJsqjnA0nmse4U7yuHjlXOs21Z28ZgE2+ pMtJ9uauFJMw2Wzpz5xnjqYCw7G70rPniUDWNM58lrePO/FOei2xfm1t4DiosyJFWufo RGUSpIYfrlgURkm9GmfwsZvzy7465+ID2lfPWhcItc3V4Po8E1KCKYg7k7VF5a3Gzqlr HJ8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=sm+922Zo/K18dpvDpeZInH18VMveXoRUZCNnLvwXjQc4CUN9QCpyvn/5mikYsVy6z6 7E/5uqWjVkIXvHdF7cbHI8iXfaylFvh/nKTX14GOHvLo5bfp3wLJ2Gqzaxstdwa4snfZ ERZ7l485l8kTIZ1TGOpwTMMrHIJtl92pTfeNMyvqpl2Kmn4WD+qiwDbM/dmFsuq+V20v g8bhXpFGCy/HJuYH2kY5+2do2zui7GOpiAueF6FrZUEGAu1WWxRKeGxqIdU+e4/xV8Xh hSO7VoIrOdw76vskd1YXBVfFYL7dci0k42UZ6QdinbIWTqHqpbavTA7O6qjadARA7Qyt l+kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RUOK++L1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o63-20020a0c9045000000b004443bfb70f4si3882534qvo.397.2022.04.30.06.56.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:56:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RUOK++L1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkna9-0002hq-QE for patch@linaro.org; Sat, 30 Apr 2022 09:56:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAp-00052G-GK for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:12 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:42788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAn-0006Wd-SA for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:11 -0400 Received: by mail-pl1-x62f.google.com with SMTP id p6so9292421plf.9 for ; Sat, 30 Apr 2022 06:30: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=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=RUOK++L1aSRINe+5iBfBfh8Lpq02+5rb8zr4OIQOw1ySFrrOUChrB7f0T+BY5eBtk7 GXwBoCXE8YfqaQzyM2uaDJyyKffee/+Aim/Hx8wt4EbMvvTE8IkYhfaBhnivo0kQB7U3 gNILVed/vNTJ0obBzOFEq38exqL8rwfUw57SV9aF4YkPzB2+lGWmLzMuVw9ByRYg164D t+YIFmfv1GJhk7Y4hafsZluYgkw/fUKlARTJOzFbDl1Mw4fn6b9SFi22C7kKmBWTsf/h DRud+b3drAdbvkYjHE9CNLztP63Rc9ELy+31s689Eg+gOp2uua0+aHVSxw/qzpCJfdEZ nbDA== 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=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=Nochwi5QtQbxXUCg8+9n5TetjQ6pR9YcTHcFWPxQw87BxhZW0ZCM9rq19qTJS6qAmx eh2/EyLViPKHD8gKiVKjYmHXuGVSGrgQwELvX32ZLXf2h9zK32KlZrngb9wWxaNeQjem GBi/XtwnhfNlZG2bfvunUUBz1vxsP9KWps/2DdW83pAakDP/4QNlKK3Rc79os/ISmRDB omMqe5qsuO+HrI7Yu8kCKHBDNAXnUTLJcqMWVl/5R89j/fPrA6joL7ATzcYHq3RCPfUj bpBfO6ALcqWG4dtWVd4WZrcbjFG2wi1g72hy6gz85O0+9MN5hW7SmDFuIw8Nb8rF13Jh T2Fg== X-Gm-Message-State: AOAM530xB829eq4+xo/N4t+owdeypcjb0pvsYyAdbvBiwUrLBw30EFW6 npMuQxiFPV3xD/Jvw8t4TtvJEgcj9ICpEQ== X-Received: by 2002:a17:90b:17c3:b0:1dc:3f12:1dbc with SMTP id me3-20020a17090b17c300b001dc3f121dbcmr515562pjb.169.1651325408568; Sat, 30 Apr 2022 06:30:08 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 35/43] target/m68k: Make semihosting system only Date: Sat, 30 Apr 2022 06:29:24 -0700 Message-Id: <20220430132932.324018-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While we had a call to do_m68k_semihosting in linux-user, it wasn't actually reachable. We don't include DISAS_INSN(halt) as an instruction unless system mode. Signed-off-by: Richard Henderson --- linux-user/m68k/cpu_loop.c | 5 ----- target/m68k/m68k-semi.c | 37 +------------------------------------ target/m68k/meson.build | 6 ++++-- 3 files changed, 5 insertions(+), 43 deletions(-) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index d1bf8548b7..fa6aa112cb 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -36,11 +36,6 @@ void cpu_loop(CPUM68KState *env) process_queued_cpu_work(cs); switch(trapnr) { - case EXCP_HALT_INSN: - /* Semihosing syscall. */ - env->pc += 4; - do_m68k_semihosting(env, env->dregs[0]); - break; case EXCP_ILLEGAL: case EXCP_LINEA: case EXCP_LINEF: diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 5b4c51957e..4b5621a101 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,13 +21,9 @@ #include "cpu.h" #include "exec/gdbstub.h" -#if defined(CONFIG_USER_ONLY) -#include "qemu.h" -#define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) -#else +#include "semihosting/guestfd.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" -#endif #include "qemu/log.h" #define HOSTED_EXIT 0 @@ -375,43 +371,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) } break; case HOSTED_INIT_SIM: -#if defined(CONFIG_USER_ONLY) - { - CPUState *cs = env_cpu(env); - TaskState *ts = cs->opaque; - /* Allocate the heap using sbrk. */ - if (!ts->heap_limit) { - abi_ulong ret; - uint32_t size; - uint32_t base; - - base = do_brk(0); - size = SEMIHOSTING_HEAP_SIZE; - /* Try a big heap, and reduce the size if that fails. */ - for (;;) { - ret = do_brk(base + size); - if (ret >= (base + size)) { - break; - } - size >>= 1; - } - ts->heap_limit = base + size; - } - /* - * This call may happen before we have writable memory, so return - * values directly in registers. - */ - env->dregs[1] = ts->heap_limit; - env->aregs[7] = ts->stack_base; - } -#else /* * FIXME: This is wrong for boards where RAM does not start at * address zero. */ env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; -#endif return; default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); diff --git a/target/m68k/meson.build b/target/m68k/meson.build index 05cd9fbd1e..27d2d7ba87 100644 --- a/target/m68k/meson.build +++ b/target/m68k/meson.build @@ -4,14 +4,16 @@ m68k_ss.add(files( 'fpu_helper.c', 'gdbstub.c', 'helper.c', - 'm68k-semi.c', 'op_helper.c', 'softfloat.c', 'translate.c', )) m68k_softmmu_ss = ss.source_set() -m68k_softmmu_ss.add(files('monitor.c')) +m68k_softmmu_ss.add(files( + 'm68k-semi.c', + 'monitor.c' +)) target_arch += {'m68k': m68k_ss} target_softmmu_arch += {'m68k': m68k_softmmu_ss} From patchwork Sat Apr 30 13:29:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568133 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7223027map; Sat, 30 Apr 2022 07:00:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwse2XVqhyYMW+V/D0LQLG7dEk/+9HGfZbn6y1mk1WLCDxz3Kzmdc+8IopVa2kEy0aTQrSZ X-Received: by 2002:a0c:d6c6:0:b0:456:4e6a:b875 with SMTP id l6-20020a0cd6c6000000b004564e6ab875mr3106109qvi.34.1651327226568; Sat, 30 Apr 2022 07:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327226; cv=none; d=google.com; s=arc-20160816; b=ojyNB9oZae63EQhIuO48Wz94DdWgzXZcwJoAU4x3CyrqbmMcRknqabAR0TZLG2/Nau /OHrO/3fQ/TZo3P0SQ0DO17hQEf312kVRqghJzN7mXnPMMJ0GaYV8+mIilG2qHtKtIGx AdyAUFA3ah3QzY0RylHK2ssQ7u0ECNLqz+NQqkaUQbC0nK5q3XqhTgySq+ohxyVd6Dxr 1fMUWSPtA8NxfWEA10Q10B/pgVRY+/FjxtoP6eBCEXqNsNcca45dPcNYJZfBTJcb+dkb 66wNErdKyjhD48+CV86CKbFJt1ljmFSnFS5GuWYA06JHuklog33uFdVBTJvA+pC79cYh KWVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=czSsEZZDTFOG9l5oT6lzPjAvLl9xr0/LWEJ8z08lpog=; b=yIenk3JU/SxvzjlKiERJZHxZ3ZXa3CYx3lyyI5NGJkHtXFaHD+KquGWeM4vlrtvW53 UsutLsvGtspQqsMc/Zg4i9iJfum7snbx7T7ldk9zPqDCFP0X28Wqpks2T9Hb8Quu8IFX dvv14JHhPNyWwSSSFw+emCrBHctTuDxDt/p1gvzval5cKkA8DtKqRl0oCp6jTzdfhn/Q LL/WAZ4jwhplPocmHoIgAyy1qH5vkYjTDkQ31uKoSd8UMQw+++b3TUZBq2l5Qe2RXT6Y sPkLKE9hFuqamyvPMu+IMYdAJG5nyWpXFW0DGiTGvNENqhByr1TqOG0mpYqUXFda6JEw v4lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gH5DrY8v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u10-20020ac858ca000000b002f1d31814e5si3780230qta.688.2022.04.30.07.00.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:00:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gH5DrY8v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkne6-0000Ei-3F for patch@linaro.org; Sat, 30 Apr 2022 10:00:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAr-000546-1W for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:14 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:35654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAp-0006Wv-1J for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:12 -0400 Received: by mail-pl1-x636.google.com with SMTP id d15so9319017plh.2 for ; Sat, 30 Apr 2022 06:30: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=czSsEZZDTFOG9l5oT6lzPjAvLl9xr0/LWEJ8z08lpog=; b=gH5DrY8vz7Vr+P1SWcR7hfaynb7860cqHP+7HWjDJRPUkAFSfCq6QFcS9oEIIOydXU hitBa5tkYND5ICneXiAEHj+PGa6qdSiU/LBJVZQ/EUMMnpyznxYNuNMNS2UX9WhEcwE0 dKN/a/XbBZBX6eYd6Bt86PE1sXMpEsioYjpekNb9QNJ3vHS2ooG3fQaK5p2wskY1hcCG Yy9bHXkhPVJjtTpYitV+KO9fOuHDIYwGNIis3uaOhEiBDnu2IRoNiYYHASJDsIfpOx7I 6VbCjVr/Koo3vrhWsWaJhvvj9kqGNiVMdWe9h20byqrog+3/lrAfEy0+70Zu9ydyExWc U/Ew== 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=czSsEZZDTFOG9l5oT6lzPjAvLl9xr0/LWEJ8z08lpog=; b=1sKzYO5sGhIf6GvC8KRzxJ12xjGjPP5FM0J67SDL/fN0CdFNHEyaoJt9HmcDNQmnP8 tuSFgRwcJ+7rgG6KkBskSo77lI91b5Ni582xCr2gzgcWlS5ZI3Da/EIBqjqmLrY1gJih ZijlNIpG44VXRuSTc+2EYDJYDG238A/XTgp6O/jM2P0Qc5Q7hk+RUGu0uvrmp38I/MZX jkV5zPjCEzTlqTtTJ/iktqiAXY1AUAvCa1kbyMjS6KUyGhbgNBTo5tKuRbeSHsfndv2n iBRTCfbtvF3S9qS5ozMXlpzOGjxJcCPEwTQak7ZWgwV6gu1e/W9i3NXMBPxB4jZuF7L1 xq8A== X-Gm-Message-State: AOAM5326s6fJudlq6uGS2hT4wL5mQJYaNlNx0QoUq9PohC4w2f6BF3an XuzdvF0u3sX+1xrVg+du3Tzg7MoTo47F3g== X-Received: by 2002:a17:902:b941:b0:14d:af72:3f23 with SMTP id h1-20020a170902b94100b0014daf723f23mr3793229pls.6.1651325409713; Sat, 30 Apr 2022 06:30:09 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 36/43] target/m68k: Use guestfd.h to implement syscalls. Date: Sat, 30 Apr 2022 06:29:25 -0700 Message-Id: <20220430132932.324018-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 268 ++++++---------------------------------- 1 file changed, 38 insertions(+), 230 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 4b5621a101..71f9d42e6c 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -41,54 +41,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) - hf = O_WRONLY; - else if (flags & GDB_O_RDWR) - hf = O_RDWR; - else - hf = O_RDONLY; - - if (flags & GDB_O_APPEND) hf |= O_APPEND; - if (flags & GDB_O_CREAT) hf |= O_CREAT; - if (flags & GDB_O_TRUNC) hf |= O_TRUNC; - if (flags & GDB_O_EXCL) hf |= O_EXCL; - - return hf; -} - -static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) -{ - struct gdb_stat *p; - - if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) - /* FIXME - should this return an error code? */ - return; - p->gdb_st_dev = cpu_to_be32(s->st_dev); - p->gdb_st_ino = cpu_to_be32(s->st_ino); - p->gdb_st_mode = cpu_to_be32(s->st_mode); - p->gdb_st_nlink = cpu_to_be32(s->st_nlink); - p->gdb_st_uid = cpu_to_be32(s->st_uid); - p->gdb_st_gid = cpu_to_be32(s->st_gid); - p->gdb_st_rdev = cpu_to_be32(s->st_rdev); - p->gdb_st_size = cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize = 0; - p->gdb_st_blocks = 0; -#else - p->gdb_st_blksize = cpu_to_be64(s->st_blksize); - p->gdb_st_blocks = cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime = cpu_to_be32(s->st_atime); - p->gdb_st_mtime = cpu_to_be32(s->st_mtime); - p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); -} - static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); @@ -128,8 +80,6 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) @@ -139,237 +89,93 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: gdb_exit(env->dregs[0]); exit(env->dregs[0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, m68k_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - m68k_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + GET_ARG(3); + semihost_sys_lseek(cs, m68k_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - /* FIXME - check error code? */ - result = -1; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0) { - translate_stat(env, arg2, &s); - } - } + semihost_sys_stat(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0) { - translate_stat(env, arg1, &s); - } - } + semihost_sys_fstat(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", - arg0, arg1); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = 0; - p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, arg0, sizeof(struct gdb_timeval)); - } - } + semihost_sys_gettimeofday(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, m68k_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_INIT_SIM: /* * FIXME: This is wrong for boards where RAM does not start at @@ -378,10 +184,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; return; + default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); - result = 0; + + failed: + m68k_semi_u32_cb(cs, -1, EFAULT); + break; } -failed: - m68k_semi_u32_cb(cs, result, errno); } From patchwork Sat Apr 30 13:29:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568137 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7231497map; Sat, 30 Apr 2022 07:10:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3UrBsWExln9xVDI9jA1oW7fOOIWMbeveNrDdXYzTgVkcUyXyaTmxvG160wXSicUQwsaUW X-Received: by 2002:a37:5805:0:b0:69f:c640:f5e8 with SMTP id m5-20020a375805000000b0069fc640f5e8mr1246716qkb.586.1651327816692; Sat, 30 Apr 2022 07:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327816; cv=none; d=google.com; s=arc-20160816; b=j4DZfzv09dQoOARWywEjuOjwaPIo/wF3mu++tNaqF3Ve87O/nfR4flK5uxW1zFIOGD Ep57qQHr9GQzclxxq95ZOzKd6cjm8R162pTcjYrPXLMa/30jjDl6/JCbqSdEauCeB4aQ ega/yImjcdroounEBviXLF/gR+Z73VWBejKP06pvR1F8rICOMtx5h01TGX9Vk/tiVr5l L0s5Lt2RPJciAEwBFtjiFvVEEHhDCiM8MEXt3gdD3vqX7U+rtfDnkC3/vemoE6xPkwz1 vu73qS2fgM9ioT1aR12x3T5beHHmb1cY9PCyXsBdDN3MRDKKu8CpDn1jeVFY08y5H7LR nILw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=becak9z+s8Wl/AMp2phsDYooGn27jELaYNop0f5bhwc=; b=SHmW3cUej34fXKCcpdB7t++N9YK8l3dicAgAMAQv4Gw6be9+it5GpyATFpK1bo7UVm zM7AaciKdzqjqKW5FT9EVB/VM7MOECqgHjWoIQtgbgkJUWxtJSnuHDpYfgaoiTAWZYtC aY0CeBbe1n7sjXn5uakDezwF41ItFtfR07G7uEG/+c/OzTU9kC19qeCX19qbnJTllFWZ sPJ7ud1iE/+hB58TmBe3+rplfmVg+U6BXYFxlE6FwhpeCsEqM88b5Ai1f6RwqM47T8mp oZ6KOx7AzUpHfcb81h8/CxvYGfOgZ8pZ36w+goaIPzBufol2M4ZYMRDDSDwmix1x+DZn DRbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RpHe61vt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u7-20020a05620a454700b0069eca9c911fsi4341563qkp.50.2022.04.30.07.10.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:10:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RpHe61vt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknnZ-0002k3-D4 for patch@linaro.org; Sat, 30 Apr 2022 10:10:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAr-000548-GY for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:15 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:41881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAp-0006XA-OX for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:13 -0400 Received: by mail-pl1-x634.google.com with SMTP id s14so9299393plk.8 for ; Sat, 30 Apr 2022 06:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=becak9z+s8Wl/AMp2phsDYooGn27jELaYNop0f5bhwc=; b=RpHe61vtkA1xkVBzhXpYkzaFRXSzHKmu2dNXbIONQtdCRoO36oT1lclOFv6Zj3elLX bD5v6Gsf64YCDo7vnt64KUoeXH4rtV8V0zqVMws462+X5agVanHGRFlj6XNFLq/ZpSn0 pJ3YHq8zDd/HFkQ5XB4ovmBUIZ5segco8Vj9rh9Hzlq1sTsSrnf9loDa6AyZmktW2Lnw wGyaMXBXiD/obLoA6CgfJeg3D/PNMjKnPNnuvby/5EqxPPaOAiUs0xROg1KUTQ+Q7qqF GIdZT1uvuo/kZbxeYZCOTdzKMKXgHmLppiasNnXgp8Pwc61ueQSE1nmyFWcRubBY6qBC dPtQ== 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=becak9z+s8Wl/AMp2phsDYooGn27jELaYNop0f5bhwc=; b=DI6TyPUg0CeILw3Bv9PLl+qinRZMDIxiTf2GGfxd5teragFbOzU/ZTU2ClA7z+ChqO brgBiDHKJkETdebfPUW670zx6tPnkhaWI4JkXnICbfR9/HQCRB4USog4wdQsF1FBzAi5 0WTNGqLfQN6p8dDR7PeWsdmbJxtZKIhpZVA78vA16+yVVEMqe3FYHsSk97DFrVgO/FwM 2jTwlggRA8xk5SbR6sYFSe44uHc7O9PV//GtGbbxYeEXGfOVEXqDL5BxKWXF2RQzOYqe xYCHxCf2KysfhJBvHn1fUMeOjLBQe3WiVWC0dRiZWtFOiC6txOCgUbidIkWVcXMJZYLW 8AMw== X-Gm-Message-State: AOAM530rfuAmE+agYLn5rzT6IKsBcJ1cojlF7WjEVETzqlSnG6NTadBQ w+QramE4eSkZTQ4twMnjpi5p4viygiPL5A== X-Received: by 2002:a17:90b:124c:b0:1bc:369b:7db5 with SMTP id gx12-20020a17090b124c00b001bc369b7db5mr9012706pjb.179.1651325410474; Sat, 30 Apr 2022 06:30:10 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 37/43] target/m68k: Do semihosting call as a normal helper Date: Sat, 30 Apr 2022 06:29:26 -0700 Message-Id: <20220430132932.324018-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There's no need to raise an exception; just call the helper function directly. The test for the required surrounding insns is easier as well. Move the load of nr inside the helper. Signed-off-by: Richard Henderson --- target/m68k/cpu.h | 2 -- target/m68k/helper.h | 1 + target/m68k/m68k-semi.c | 6 ++++-- target/m68k/op_helper.c | 10 ---------- target/m68k/translate.c | 26 +++++++++++++++++++++++++- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index 9b3bf7a448..60f88e6bc9 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -456,8 +456,6 @@ typedef enum { void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector); void m68k_switch_sp(CPUM68KState *env); -void do_m68k_semihosting(CPUM68KState *env, int nr); - /* * The 68000 family is defined in six main CPU classes, the 680[012346]0. * Generally each successive CPU adds enhanced data/stack/instructions. diff --git a/target/m68k/helper.h b/target/m68k/helper.h index 0a6b4146f6..0e27c27810 100644 --- a/target/m68k/helper.h +++ b/target/m68k/helper.h @@ -128,4 +128,5 @@ DEF_HELPER_4(chk2, void, env, s32, s32, s32) DEF_HELPER_3(ptest, void, env, i32, i32) DEF_HELPER_3(pflush, void, env, i32, i32) DEF_HELPER_FLAGS_1(reset, TCG_CALL_NO_RWG, void, env) +DEF_HELPER_1(semihosting, void, env) #endif diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 71f9d42e6c..1a36c1158d 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -25,6 +25,7 @@ #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #include "qemu/log.h" +#include "exec/helper-proto.h" #define HOSTED_EXIT 0 #define HOSTED_INIT_SIM 1 @@ -84,12 +85,13 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) } \ } while (0) -void do_m68k_semihosting(CPUM68KState *env, int nr) +void HELPER(semihosting)(CPUM68KState *env) { CPUState *cs = env_cpu(env); - uint32_t args; + uint32_t args, nr; target_ulong arg0, arg1, arg2, arg3; + nr = env->dregs[0]; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index 8decc61240..a345245612 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -22,7 +22,6 @@ #include "exec/helper-proto.h" #include "exec/exec-all.h" #include "exec/cpu_ldst.h" -#include "semihosting/semihost.h" #if !defined(CONFIG_USER_ONLY) @@ -203,15 +202,6 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw) cf_rte(env); return; case EXCP_HALT_INSN: - if (semihosting_enabled() - && (env->sr & SR_S) != 0 - && (env->pc & 3) == 0 - && cpu_lduw_code(env, env->pc - 4) == 0x4e71 - && cpu_ldl_code(env, env->pc) == 0x4e7bf000) { - env->pc += 4; - do_m68k_semihosting(env, env->dregs[0]); - return; - } cs->halted = 1; cs->exception_index = EXCP_HLT; cpu_loop_exit(cs); diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 4026572ed8..b7adc8f53d 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -33,6 +33,9 @@ #include "exec/log.h" #include "fpu/softfloat.h" +#ifndef CONFIG_USER_ONLY +#include "semihosting/semihost.h" +#endif //#define DEBUG_DISPATCH 1 @@ -313,6 +316,25 @@ static inline void gen_addr_fault(DisasContext *s) gen_exception(s, s->base.pc_next, EXCP_ADDRESS); } +#ifndef CONFIG_USER_ONLY +static bool maybe_semihosting(DisasContext *s) +{ + /* + * The semihosting insn (halt or bkpt) is preceeded by an aligned NOP + * and followed by an invalid sentinel insn (movec %sp,0). + */ + if (semihosting_enabled() + && (s->pc & 3) == 2 + && cpu_lduw_code(s->env, s->pc - 2) == 0x4e71 + && cpu_ldl_code(s->env, s->pc + 4) == 0x4e7bf000) { + gen_helper_semihosting(cpu_env); + s->pc += 4; + return true; + } + return false; +} +#endif + /* * Generate a load from the specified address. Narrow values are * sign extended to full register width. @@ -4702,7 +4724,9 @@ DISAS_INSN(halt) gen_exception(s, s->base.pc_next, EXCP_PRIVILEGE); return; } - + if (maybe_semihosting(s)) { + return; + } gen_exception(s, s->pc, EXCP_HALT_INSN); } From patchwork Sat Apr 30 13:29:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568136 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7228798map; Sat, 30 Apr 2022 07:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfn81H5/jDEbYrX39skPL5HWYGk+2m21cW4jqqMe0oDA6rocRv+dqvfzJKXQVHWwbTmbFf X-Received: by 2002:a37:b95:0:b0:69f:b96d:ff4e with SMTP id 143-20020a370b95000000b0069fb96dff4emr2842099qkl.373.1651327607758; Sat, 30 Apr 2022 07:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327607; cv=none; d=google.com; s=arc-20160816; b=TwnUyMlKhLDh9WCCP1pg42daEajgTWysUNj9nBp4pmVQ3NsC0se6bimHW2UBr5GugA jVKo9KFgd5iiOhj6xLl5H2QowzcG7ymbsZ9NkoIF6zNVCfmUIxFofzycdFUEQsVof3j4 b3KiQTsSVasJfVaZDuf+sAveAWIOA62/I56C3FDmE+xUrH0ESEZDCLDQgpp4mylcPYd9 nGsdx+VZQH1SyN7mPbBp26yJ8PsLSx7AZNxZ9jtkQtTjwppsupkSEOccfNeookNow+bZ Tt7jueQGHpyLB1rGmKVQ6QSyk/KObh2fNu+01z+IKdKb0SUzOYWZn0LwGA97H7j0Z5mB MVtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=/27qRMF/7/SVCIffe/0N75Mp/N/kT0yltHM3qggU1zM=; b=zgr+qY6SsDy7/UbNKLW5Py/w2gCS40vmsSSY3MCnhXcQna5bwlxTW+I4jzvG/lhcY3 D3LGXmozeGP9sGXbweFYwhUTaWwQ/bvLDtWnVuw0mWZw0C1VVjJ+fsVqpyAj6D5nLt/6 vl7uLT/BINuH/26BFQb37SghfsArySnUfkXVVrJ0Uj9aeshmJbjFoFV/uTwY84wPCROb 7RCWQ/5A/QFQXPdmixcTeqZmf+6yFgKJqoVqls/7KquGEJNYY86dzwa/FF33rQRZSwRE PX9e+2hQd4W0QNmFBCtl1crWLaN8r+Riov2teZPa4Qjx1i99H6R55smLZucXQXaZWUe7 lgGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="yQ/fel4m"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g13-20020a0562140acd00b004563337c5absi4270479qvi.196.2022.04.30.07.06.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="yQ/fel4m"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknkF-0006KX-BU for patch@linaro.org; Sat, 30 Apr 2022 10:06:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAr-00055A-Vb for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:15 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:52892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAq-0006XJ-He for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:13 -0400 Received: by mail-pj1-x102f.google.com with SMTP id e24so9298872pjt.2 for ; Sat, 30 Apr 2022 06:30: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=/27qRMF/7/SVCIffe/0N75Mp/N/kT0yltHM3qggU1zM=; b=yQ/fel4m6s85ma0A3x/cRZwAJELQoIY1IJmGo7Ibtr1JyESfIxFHOmKYOjUFtRM7fj B1OsfgSVLloxJ73FrUkQfJ/oNzwY1DYtTNmxiAxVP6fzwiVVxMS0/N9bsMhaWAOHZg5N rx3HT8KNqAyMX6qqpDN28bdsnhOh8GBd6qYq1o/4VcOGXdN+zy0wk4+yqDPZ0LsS5pcs reRwtPmYXoMnR6TabcD4YfQmrF97d4INqvcw7eQZdrWxOnfUZA/SrmUoQV0iJp+aQ5k8 fvvUnL5n7kD1IoJdnGsPqxWM7oEZcI9l2EpFiM3qIpYlSdgvotIYQXTeT9JHd2foxBsx 23SA== 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=/27qRMF/7/SVCIffe/0N75Mp/N/kT0yltHM3qggU1zM=; b=6GC7aA1LKs/AX+1sHk5vcF2TSFeNK5Lwx/u5tDrxbVPtwYmfjYFXJszgY1zSn+3+jx OB6nhZIrBLnjZm/Tckd51upnq2my5K4mcbWXt9etz86QTS5dmHDcx5vx+inST7ISUJ06 o7pJK3HLNnypEcOHrZ5PFP/TU8RpFZ2tLitT3ALTWv7kK2iDgaiTOhpiGNSGsqdBs0P+ Nl86wde8XBWJzPMBvJjmctnj/jBSKRKpMRSz1M6bifKtsIkyx9vKs9Yjgji5J7AMER/z IDV25iYMlF5WSviIJ/rF7HTzQHW7Byzt9AMS2gWs48fZXSei1cwBxbF844qx6WXYqB0W cqhA== X-Gm-Message-State: AOAM531NHPUPd3xZetXz12E1JM7Gb99CzhAw7Bn7yg6zCja0Q7YJmIRf wEavJkcbrvrojiwPrq9cCqc3lXnaRSqKzw== X-Received: by 2002:a17:902:8644:b0:15a:3b4a:538a with SMTP id y4-20020a170902864400b0015a3b4a538amr3729895plt.146.1651325411272; Sat, 30 Apr 2022 06:30:11 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 38/43] target/m68k: Enable semihosting for non-coldfire Date: Sat, 30 Apr 2022 06:29:27 -0700 Message-Id: <20220430132932.324018-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The libgloss m68k-semi.txt spec says that bkpt #0 may be used when the halt insn is not available. While halt is available for 68060, continue to support bkpt #0 for all m68k processors. Signed-off-by: Richard Henderson --- target/m68k/translate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index b7adc8f53d..51c546f26f 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -2775,6 +2775,15 @@ DISAS_INSN(swap) DISAS_INSN(bkpt) { +#ifndef CONFIG_USER_ONLY + /* The non-ColdFire semihosting insn is bkpt #0. */ + if (!m68k_feature(s->env, M68K_FEATURE_CF_ISA_A) + && !IS_USER(s) + && (insn & 7) == 0 + && maybe_semihosting(s)) { + return; + } +#endif gen_exception(s, s->base.pc_next, EXCP_DEBUG); } From patchwork Sat Apr 30 13:29:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568138 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7232283map; Sat, 30 Apr 2022 07:11:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYxR1R5WGMD0n/+Kz8xWB+4Jp4ifaVa+h6nsRrz97FYRkfosvWQxVvERJS2TllMM2wwZeA X-Received: by 2002:a37:9e49:0:b0:69f:cdbd:a1e with SMTP id h70-20020a379e49000000b0069fcdbd0a1emr232315qke.349.1651327876921; Sat, 30 Apr 2022 07:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327876; cv=none; d=google.com; s=arc-20160816; b=hrJvNx5i7z/spSOPCWxzDiIr7QsQ9FiDt6UrJ3Q6uhQ0Gh24qIx+Wtf/rJaq13FOAB hWMvJ5m+iEvzJP/p1Dnb1b5IFNY/8QFwZZDCgyZkclYZFT+midP8wXymT//VkMsKCgtO 28EfOUtlQZFFqOpaJYfDTyhu8P4uV70VwvjgJDee2LxP3Y+7llWVXeMNUqP+karM9KLK CZ34tSKHwp2xr8GZljyMBysz5outMfQYEVIZAHFL/YYQdBdGhRPlWgb0u0hig8sbuoB7 iH7eNSvHWswcmjg+yiXZHlRD//g5Z0Ys/KlyqCOL56VKVMibme6zvfsJElCGRnx0Jj5p NFpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=vyI9atIKZgVrQgHTzauV1Q/z1myJDzCa5CWllyH6//o=; b=BZ4Sa1KCETpyqUwRfeecdvP2WP9yAB9D2ElJF01cdZQeu9Y4Y/tBipDB6lKdCCDKzC yL/RzFkLdi0hikn4wZZdmWJTmmzmQvDcPGEmFizkPnYy5IHHCTGLvawSiRVbkeHhjcGL /uzmYIi8r418rmjn4ZNG4cP2lg4FQY0dE2II4bSsOeRv9eRuXyqnN7G046b2gBnZWNJ6 ij/+LkuFxs78Y9wqeCo1w7Cr8ePcpfKdIGTqYlVdaeYU+uHBVoz20HWwkjEdoopmEk9o dHR6o+JO2QJSTTvT7R2U+Z5a8sxO41c8ESkh/BPTYAyUOSSKKo/RnB4A1iUkStNgXfKT W9yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="i/chQaAD"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s126-20020ae9de84000000b0069f9086a1b9si3755947qkf.144.2022.04.30.07.11.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:11:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="i/chQaAD"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknoa-0003u4-FQ for patch@linaro.org; Sat, 30 Apr 2022 10:11:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAs-00057K-SZ for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:15 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:42791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAr-0006XR-BX for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:14 -0400 Received: by mail-pl1-x632.google.com with SMTP id p6so9292494plf.9 for ; Sat, 30 Apr 2022 06:30: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=vyI9atIKZgVrQgHTzauV1Q/z1myJDzCa5CWllyH6//o=; b=i/chQaADAoksE27Ep83yDkoNrfhd5H4DbyXhCV8UeoFlWaIumaZ70kbAaDl8mXiM8s lgu6AwaUzNueHGQYhqtURTQtUIr3gXY0aelxQCNCZ6cX8rW7rDqmVF+yBUr76k7RxRL2 Z/+l1Uuacw5rHr+bpF+aDgV9IB2CTTVAS6nwwy0uYF8OV/TCx/cUNkuAvxMFsSLaWF2m wNi6j6ok3j5jOqJgeLrnRI1DzNtaWWj6L9r6uK0gC5ZRK9DAZDhkizdK/hKIUMTR+TCI rg7DVqkjdt5xyxR4kS7PATABMKGwRfl1poR90FXVtSMV4ocqqLM9elY2u7bJXBrP3QGD W4Ew== 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=vyI9atIKZgVrQgHTzauV1Q/z1myJDzCa5CWllyH6//o=; b=1GFoW4wxXD6X7izkuWppOc2zpCTkY+gU39BjSq5cDvti/gPWudn8BvoTFzeQQgcAzV kwuNX0xP3xthgO1k6AqXQdjaNmwO57/I6n7xlOwRMhTK8wRjB19GPPceuyPnhUCH/0qt Bvbq8NV9rjCzZqE0wkBiA+cc60ypxoTDcbabtehNsVQKE2yh8rigtbEkMMBQ8XtiY9kp WYotjKh3ceifu5JBQbJ4j0uu1uTp3hG6zzaHah+FYnxF8rlnIcUv3pZ+tip6q6o1RKvL eMCsIWP0IEu0Ab6QZXCClRUkETZDj6LIRe7oqwzZjWIztREJQdkBiCDTtPAdQ+5F+h4y Agxw== X-Gm-Message-State: AOAM530P92FlK/BDyCegvvmogzoof18r98/Z8mXHjsFXK6JSJ/Et3L/J xevKfEbLBuUw9i/nSTXgmkjkzAdAPoyBEQ== X-Received: by 2002:a17:90b:4d08:b0:1ce:8d09:1c58 with SMTP id mw8-20020a17090b4d0800b001ce8d091c58mr4270641pjb.168.1651325412068; Sat, 30 Apr 2022 06:30:12 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:30:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 39/43] target/m68k: Remove EXCP_HALT_INSN Date: Sat, 30 Apr 2022 06:29:28 -0700 Message-Id: <20220430132932.324018-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Now that semihosting is not attached to EXCP_HALT_INSN, we can use EXCP_HLT. Signed-off-by: Richard Henderson --- target/m68k/cpu.h | 1 - target/m68k/op_helper.c | 5 ----- target/m68k/translate.c | 3 ++- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index 60f88e6bc9..f10554318b 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -66,7 +66,6 @@ #define EXCP_MMU_ACCESS 58 /* MMU Access Level Violation Error */ #define EXCP_RTE 0x100 -#define EXCP_HALT_INSN 0x101 #define M68K_DTTR0 0 #define M68K_DTTR1 1 diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c index a345245612..6218ac791b 100644 --- a/target/m68k/op_helper.c +++ b/target/m68k/op_helper.c @@ -201,11 +201,6 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw) /* Return from an exception. */ cf_rte(env); return; - case EXCP_HALT_INSN: - cs->halted = 1; - cs->exception_index = EXCP_HLT; - cpu_loop_exit(cs); - return; } if (cs->exception_index >= EXCP_TRAP0 && cs->exception_index <= EXCP_TRAP15) { diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 51c546f26f..354a127e1a 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -4736,7 +4736,8 @@ DISAS_INSN(halt) if (maybe_semihosting(s)) { return; } - gen_exception(s, s->pc, EXCP_HALT_INSN); + tcg_gen_movi_i32(cpu_halted, 1); + gen_exception(s, s->pc, EXCP_HLT); } DISAS_INSN(stop) From patchwork Sat Apr 30 13:29:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568134 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7223614map; Sat, 30 Apr 2022 07:00:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGn4ir0b105a/OYcaK9CF/mWkLc4EHEMQ8Oxcxwh7uIIrIt/F0o8GZTtETZWvHaBnxedz8 X-Received: by 2002:ad4:5dce:0:b0:446:74be:a494 with SMTP id m14-20020ad45dce000000b0044674bea494mr3301689qvh.84.1651327259134; Sat, 30 Apr 2022 07:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327259; cv=none; d=google.com; s=arc-20160816; b=x1wFhjIef3KTCM5DkUZ7eCuX7V2DUkRy+CDbTiTG8Hgx46hFgg/H/fbi4v93r11Xws 3Htbp1LLVZ/WNIj6fx1UVHjnPpgNNszLQaUwCoDqb9P133QTBUS0XN+Ao39+UZojXIMg erf164xGOuVHRQ4soESTkENuylKlM2MBHFTXK4ijy28PEzXXiACDTcs9xh2Pn9dfe3kw 6H49uGL2Mg3LBYYGpKoE+IrtUFvDGtmXB8ZFBlqGhWWxdPqdVdU5Xmkgh3/Y9PEUFxWO 0y1B/SLJRMXItCCaFviG1SxjhapqVkPEPjlNyZBR085Vy1sLnS4A9WmrOie22ddYfafz FVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=cFvraHVz7l3Zb9ciiKLFc98Cr0B62hVzoeype7x/lniLTUT0TSaB+BprqWbpb5PCu/ C7ezi4nxjUG3w82NejUd466kPCv7uSv6d7xocZC2smuBVwO703PxddgB+9AR/nnhMMBO xqTLnpnBoNjxYD1W2zoPTlD2Lhgt36pRNwl9Ppeatgufhocu6ANu+8sxzvDPjX4F1zns SUgZjIfwTT2SE8W9NRlNKMRS/Peu4f3kTn1XMlOtCbfkzQJXXCnt5ZqOnRjhCRM6oZEO agB1vKYWeRZequuQHrAagobNhTALW+m5pM51M8fnmMwt4THVO1DZ8MVJidgJJdwlYubk ubzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KfFoPboF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d9-20020ac85ac9000000b002f3a0c08689si55675qtd.541.2022.04.30.07.00.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KfFoPboF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknec-00015m-HL for patch@linaro.org; Sat, 30 Apr 2022 10:00:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknDp-0003Ns-U1 for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:18 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:37675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknDn-0006tk-3J for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:17 -0400 Received: by mail-pl1-x631.google.com with SMTP id k1so708253pll.4 for ; Sat, 30 Apr 2022 06:33: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=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=KfFoPboFa1WP0Jl/lOG8a++N9Pcj+zxnG9hg2+OHdpYrUd9rDTjZ4NsPhNPl1mHHNZ qTSJaecZw61WJzc1Exk4rv2OsW+YMoT4eHtrl3Bv1Oyqm7vFv+HvTlBgoxagzZI16yPG vMQRx7gfYBrivrBNcbWkg9NCCU3eAtCwJNOjSF9eixeZv8DFy/cIFKlj6AMC7fDbQZO/ bnP4/gZI8hWbUFDNw11qRTx8M6I4u1XDgfPzDQ0fOr9LsPSf7tr0eAxvK2pn3eiHiRGn 0xRpcL8ch3eCuyp2CBZkK+kPypRmNla0UHNS9CKCenG9UV0q7uBryfo4kCknFier9VCT X/Xg== 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=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=fkbKq5K/QuwKDjFsHYrRbeFwB7qn/zRsFhRyoIrO6ooqVr4e0xZUW7UGpQRweqUOHv Msdo9mQor51aKjMWYJqarYzVGCLlAkRMUJ2vDrTh0YWc+O5WSfm6lpgl4jHGpYvlF+ym +qKTc1wvCxaHpUL74Y3D45cbcwPAtXwbHXgk+ufunmZOpSQziXGwq9nKt7y81IZXFH/2 wVkf+6DM1xXQMUtMRr5zfggB2MOqqG3CkvnclDqwHI8X+RDTQzfqKb7iTADDi3bwCdMY 01wmAHvJN+hiO1wZd0I5noKjIGUbfdzzZY6jgBJHrjb8B3frF1tunJoe7/y8uHtm6dQd 6VRw== X-Gm-Message-State: AOAM533UPv+mSssIAvQOkFFMIQ4iX4vgovKmObCt1biG4RIEe7d+xDGg HUMweyuIaoTqjRS2gO5IGU2CKvB7xAo5OQ== X-Received: by 2002:a17:902:b597:b0:158:1aee:1b59 with SMTP id a23-20020a170902b59700b001581aee1b59mr3694135pls.33.1651325593532; Sat, 30 Apr 2022 06:33:13 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id c136-20020a63358e000000b003c14af5063bsm8517840pga.83.2022.04.30.06.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:33:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 40/43] target/nios2: Eliminate nios2_semi_is_lseek Date: Sat, 30 Apr 2022 06:29:29 -0700 Message-Id: <20220430132932.324018-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg nios2_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 59 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 4d02789d26..bdf8849689 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,9 +108,12 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, return true; } -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) +static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu = NIOS2_CPU(cs); + CPUNios2State *env = &cpu->env; target_ulong args = env->regs[R_ARG1]; + if (put_user_u32(ret, args) || put_user_u32(err, args + 4)) { /* @@ -123,9 +126,12 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) } } -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) +static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu = NIOS2_CPU(cs); + CPUNios2State *env = &cpu->env; target_ulong args = env->regs[R_ARG1]; + if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || put_user_u32(err, args + 8)) { @@ -135,25 +141,6 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) } } -static int nios2_semi_is_lseek; - -static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - Nios2CPU *cpu = NIOS2_CPU(cs); - CPUNios2State *env = &cpu->env; - - if (nios2_semi_is_lseek) { - /* - * FIXME: We've already lost the high bits of the lseek - * return value. - */ - nios2_semi_return_u64(env, ret, err); - nios2_semi_is_lseek = 0; - } else { - nios2_semi_return_u32(env, ret, err); - } -} - /* * Read the input value from the argument block; fail the semihosting * call if the memory read fails. @@ -168,6 +155,7 @@ static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) void do_nios2_semihosting(CPUNios2State *env) { + CPUState *cs = env_cpu(env); int nr; uint32_t args; target_ulong arg0, arg1, arg2, arg3; @@ -188,7 +176,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, + gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, arg2, arg3); return; } else { @@ -209,7 +197,7 @@ void do_nios2_semihosting(CPUNios2State *env) int fd = arg0; if (fd > 2) { if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "close,%x", arg0); + gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); return; } else { result = close(fd); @@ -225,7 +213,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "read,%x,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", arg0, arg1, len); return; } else { @@ -245,7 +233,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "write,%x,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", arg0, arg1, len); return; } else { @@ -268,12 +256,11 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(3); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - nios2_semi_is_lseek = 1; - gdb_do_syscall(nios2_semi_cb, "lseek,%x,%lx,%x", + gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x", arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - nios2_semi_return_u64(env, off, errno); + nios2_semi_u64_cb(cs, off, errno); } return; } @@ -283,7 +270,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "rename,%s,%s", + gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s", arg0, (int)arg1, arg2, (int)arg3); return; } else { @@ -303,7 +290,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "unlink,%s", + gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s", arg0, (int)arg1); return; } else { @@ -322,7 +309,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(1); GET_ARG(2); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "stat,%s,%x", + gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x", arg0, (int)arg1, arg2); return; } else { @@ -345,7 +332,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "fstat,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x", arg0, arg1); return; } else { @@ -361,7 +348,7 @@ void do_nios2_semihosting(CPUNios2State *env) /* Only the tv parameter is used. tz is assumed NULL. */ GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "gettimeofday,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x", arg0, 0); return; } else { @@ -382,7 +369,7 @@ void do_nios2_semihosting(CPUNios2State *env) case HOSTED_ISATTY: GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "isatty,%x", arg0); + gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0); return; } else { result = isatty(arg0); @@ -392,7 +379,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "system,%s", + gdb_do_syscall(nios2_semi_u32_cb, "system,%s", arg0, (int)arg1); return; } else { @@ -412,5 +399,5 @@ void do_nios2_semihosting(CPUNios2State *env) result = 0; } failed: - nios2_semi_return_u32(env, result, errno); + nios2_semi_u32_cb(cs, result, errno); } From patchwork Sat Apr 30 13:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568139 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7234846map; Sat, 30 Apr 2022 07:14:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7uapiwG3qxa364n2X8CcrXcGWaTo5r8ahKwUW7iKoC8+rhVlaEH6dXElFGbN5IB1FieZO X-Received: by 2002:a37:c84:0:b0:69f:c94a:a8ca with SMTP id 126-20020a370c84000000b0069fc94aa8camr937470qkm.167.1651328078223; Sat, 30 Apr 2022 07:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651328078; cv=none; d=google.com; s=arc-20160816; b=qJen3fBEH61ZOq2rzbIkcYlFQhpL+pwo+4Z9XPUc3M6J5nwEbcxV+cHUGZY3re2C62 Plqs2w5FcYINSegpRFicL0J3pn0ev4/2oWbNcPMWidnsHN+hvDa5LKlMxMJM3iHSGhfP T0E2IRvRKybq51NiLVQPblOXqD4hTb2Y0xWYH6KZyJ3pH97+7Z35ZRoIh2bNK9PZdmh5 GD5xORRbAZ6RyZid8p9xfxiEMgbOvdKRFgpfCiyJH8rSfHp9lO1pUvoaU4PppXX42Vsq oMCSTIBVk7ehMFgrbRez4SWQ7oz46lrwpwSonyuP6ccm35/nOmdllk0kANh/x0qqFZVt 7xlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=soUcv/NVaic7rpIoQ3EoUGWbMozulS/V4BtUmAyldra3nonlDKezjddnwYsYiKieqV cZpUFTiI2YqBROn2jixjnZIJoRvhxsJESmMPMZSUga3UOIzpDWOs3SzRbsJBoSEnEcyo ZFWxHVOcmzGKYPhW3ubr9ejTA3P+EryN4sMPpxIPAEpowOvIZ+Z+zW0awq4wW6+m1to+ 4yesZQZzLt0PjQ8PtG+6pf+N6/YgcavJStURa/4ijOA3s1GhvPypsDZoZ7RwksorBFkB 11O5owb3i8nvhZTXh/JwUFPL7UPXDXxIr0vSxTks1KtIzGJcz45Z45m6aBAmgVHVJbO7 EJAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="jBJs/XAN"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h12-20020ac8584c000000b002f20281d237si3813765qth.459.2022.04.30.07.14.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 07:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="jBJs/XAN"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknrp-0001JG-QQ for patch@linaro.org; Sat, 30 Apr 2022 10:14:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknDp-0003Nr-SS for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:18 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:44644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknDo-0006tr-Ao for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:17 -0400 Received: by mail-pj1-x102e.google.com with SMTP id m14-20020a17090a34ce00b001d5fe250e23so9460696pjf.3 for ; Sat, 30 Apr 2022 06:33: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=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=jBJs/XANkUP64bue39bEqQ5SUGi9rf6vxzwezGUh01B7QoReOk4opKzHX6akv8Zr9O xw2s1t2EG+5CluMr2ZnBAiOIJ/QQhJf1l5FVTfsqKqFAAQgSvwwHWRO7dxady/nEfTs2 82dcY/TwCi4McqsBwKoAWIrjkQ13/eTu9LkWX8gaRRTDsuwxw+5ASqstTgvFJZlGJyrj /Ykyk4spb3KTNr3mHMm4n6YJEtrUMhDOAbdJZISw+yXzqS21eClVYg3/r/lBodhq5pgD KFMEtp7uBkFnUFNXv1kqP+mzCLJr26jIzpVeMOJvBdehJNfP2MElpvDyALuPEnn8vdOM dXNw== 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=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=nQS4ovb1KtA1bFHQBABnWnwQ5GoZxlKlaYNPRt7X4+XJs5PQhGhW0I4rXYkwczdV4L ilm6X8AQjKpcrGzoVhvbX4dxmyXTBfAL6AZG4tMa/hGJWmJAWjelktgcEbzHw8cj6lMx sMlF3DToGdWnAAqn2NTU8tWQdMHkKKfIHVnJSLBciE3BGjOeEpz+/DF1CSrwhEglAtCV UfP6xNMNtJfNKGvxPv5a1IbGnYpFHIbwNGmu4d100UJEr0t60noDtzU7GlHlOkw4uVYg wZD8G94aID9ZX4hR0urNGYFREj+AgkBd6WvWm7UG3078T+B3p12V4PrP/ohoeNyXF369 wQ2w== X-Gm-Message-State: AOAM5336vfhPv5VtE4cCOnm2iuOOLZQYZ5ZTYOa25yzhgBA1zyX4EmSv 77+qxUz0sAACY3j05FMAIwE0uMlgm9wI0Q== X-Received: by 2002:a17:902:ab55:b0:15c:ecb:81ad with SMTP id ij21-20020a170902ab5500b0015c0ecb81admr4064898plb.50.1651325594554; Sat, 30 Apr 2022 06:33:14 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id c136-20020a63358e000000b003c14af5063bsm8517840pga.83.2022.04.30.06.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:33:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 41/43] target/nios2: Move nios2-semi.c to nios2_softmmu_ss Date: Sat, 30 Apr 2022 06:29:30 -0700 Message-Id: <20220430132932.324018-42-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Semihosting is not enabled for nios2-linux-user. Signed-off-by: Richard Henderson --- target/nios2/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/nios2/meson.build b/target/nios2/meson.build index 2bd60ba306..c6e2243cc3 100644 --- a/target/nios2/meson.build +++ b/target/nios2/meson.build @@ -1,7 +1,6 @@ nios2_ss = ss.source_set() nios2_ss.add(files( 'cpu.c', - 'nios2-semi.c', 'op_helper.c', 'translate.c', )) @@ -10,7 +9,8 @@ nios2_softmmu_ss = ss.source_set() nios2_softmmu_ss.add(files( 'helper.c', 'monitor.c', - 'mmu.c' + 'mmu.c', + 'nios2-semi.c', )) target_arch += {'nios2': nios2_ss} From patchwork Sat Apr 30 13:29:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568127 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7220521map; Sat, 30 Apr 2022 06:55:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVdGonDvH89sm2j8O3lUVeHU7EE+fNLrr9bZXSEtS3ECwBVGn7kpxWpGQ0D/x+F8W1eztV X-Received: by 2002:ac8:4707:0:b0:2ed:b56:5531 with SMTP id f7-20020ac84707000000b002ed0b565531mr3476421qtp.148.1651326944687; Sat, 30 Apr 2022 06:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326944; cv=none; d=google.com; s=arc-20160816; b=M+uPGgfkvC3wSMXdo6oNx/tdvPMPz2KJlZVWXkG3Q/nLjZVk4oFM7k9cpVDsGORONh sWpVb+QeSDy0bRaAbNZoUih2no29moHO5yUDvToCbl+hTbIwfeMpGv3hgsIWqm6lbLPJ KG43CeSyDqgbaGolTi9AigOngS4xbHAZoHkpLeWGwFmFJym0ULMf10HK0CQRc/2f0oNN HLnWeUOeATWdXxgrRS6yVdw8UhV7Owhzp5vz+7f8TkPehVAe/GDYSrSJ+jjO+cQkxv2Y MK0yYM3NjBjgZlVfNopAb3vsp4QHK77nQxf1i7uckvKxG2fSpZypIRt/Fev6oJ53HEcU ewuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=O00AgyFrOx6VT5cHkpUCMbRE4gEXAb+bzYu/d7WzwIk=; b=IczhuoNxBIBcumCCKbc5w/a2MFILhJAzhc6xUcB5pRO6yBtP9lM6YOfSMHSb/UPvV4 EfK2T+4a46AnU/OI75smjFbI/7O7ffwmAPz/NoPu4c9UCEtBBrEQv8dwsHt2N11AIjrR NlXlIuTv8YiD0+78cghkmHCRFqpVKQhirkoVs9tx3+0VhSPK1YvkIWACTiRqJH7GFgEF tpRThg4eOTNQ+ZosfrkovqA/djpekOnz052YIseIBY37tG3rfEHvufQ8vf7rkeKoHFPf 1KjABGO/ktUeCzCwtVu0Qg3KaAEZR5F0IxhkphXqo4YqEYaorpx/PC9ZpWUR322SD+fP gAHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dog+oZq8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l23-20020a37f917000000b0069f0c98d582si3928046qkj.466.2022.04.30.06.55.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dog+oZq8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknZY-0001Hx-8c for patch@linaro.org; Sat, 30 Apr 2022 09:55:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknDr-0003P5-2V for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:20 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:42835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknDp-0006uC-2E for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:18 -0400 Received: by mail-pf1-x42f.google.com with SMTP id x23so3777116pff.9 for ; Sat, 30 Apr 2022 06:33: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=O00AgyFrOx6VT5cHkpUCMbRE4gEXAb+bzYu/d7WzwIk=; b=Dog+oZq8mQym3y0dPttbZLYuNlHR7as9+Uur7LXTrUTRvvJmAgPicmFkwOoJCQlhiK JBYdkbNtVsJLXuHjwfAWo99ExQddFi6i9HwHxza+i63msyp1cxfWL0yKiBOAU1SiYqVG 90LK/zKXW6XOsfmTb/Eley9Q/7tCYoArrDoB+O57XJsx1JzCaEZE2Y2XLCxcJP19Ltx0 jKluPhtCoWW9YP3jfEH3AUZNKghf517xyEVkhgv+cgMQ/7v/LTJ8R6h0bZO0kSN8Zqjy vZJhTADzzcNaim+NFjHQ78Ox6kCT8ogJOHwe9uvcaE6s6yl4EhaCviuiFgATL30IbE8j RTMw== 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=O00AgyFrOx6VT5cHkpUCMbRE4gEXAb+bzYu/d7WzwIk=; b=uVXma2dPf9NLuGlcfYsK6fYizu5c9rwQqK+99iFuyhEXD8FfMUGmch7huPUW1Oww6n /TNQ8E5UPhbedBJrtd3J9NO6xizyWi0e9y2TdBH17bUbqAEhDjq1RTZ7ILI3wfZ2SZqt CS455GqkzKZwOU00v4Uv/FiIS1iwWRmpJXmqqFAsF5ISxTaKviVTa2kXHvzReQt/I5G9 nFajj1g9mUFrRcfmLTYhE1KaDHF22xhdBu6cS+eENyAOZ4c53dRI28QMYV1/6l5Ww+Th VUv0Ifpy7yxcUqE7GGDyBv6rLNXp/4UN3fLTE96sSpqE5rVRbsWXl0YHxTtj9msvaMIJ Smjw== X-Gm-Message-State: AOAM5334apj+lsBkz1epATSdpl4Jg/qMTrUm3TfwWyLEtTWb1O+cR08T UNyCkWbplSwD/B5pgSx6fnVbwE2NXqdh6w== X-Received: by 2002:a63:914b:0:b0:3ab:48:8a16 with SMTP id l72-20020a63914b000000b003ab00488a16mr3172025pge.617.1651325595686; Sat, 30 Apr 2022 06:33:15 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id c136-20020a63358e000000b003c14af5063bsm8517840pga.83.2022.04.30.06.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:33:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 42/43] target/nios2: Use guestfd.h to implement syscalls. Date: Sat, 30 Apr 2022 06:29:31 -0700 Message-Id: <20220430132932.324018-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 287 ++++++-------------------------------- 1 file changed, 41 insertions(+), 246 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index bdf8849689..3dad72d1f6 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -25,6 +25,7 @@ #include "cpu.h" #include "exec/gdbstub.h" +#include "semihosting/guestfd.h" #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else @@ -47,67 +48,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) { - hf = O_WRONLY; - } else if (flags & GDB_O_RDWR) { - hf = O_RDWR; - } else { - hf = O_RDONLY; - } - - if (flags & GDB_O_APPEND) { - hf |= O_APPEND; - } - if (flags & GDB_O_CREAT) { - hf |= O_CREAT; - } - if (flags & GDB_O_TRUNC) { - hf |= O_TRUNC; - } - if (flags & GDB_O_EXCL) { - hf |= O_EXCL; - } - - return hf; -} - -static bool translate_stat(CPUNios2State *env, target_ulong addr, - struct stat *s) -{ - struct gdb_stat *p; - - p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - - if (!p) { - return false; - } - p->gdb_st_dev = cpu_to_be32(s->st_dev); - p->gdb_st_ino = cpu_to_be32(s->st_ino); - p->gdb_st_mode = cpu_to_be32(s->st_mode); - p->gdb_st_nlink = cpu_to_be32(s->st_nlink); - p->gdb_st_uid = cpu_to_be32(s->st_uid); - p->gdb_st_gid = cpu_to_be32(s->st_gid); - p->gdb_st_rdev = cpu_to_be32(s->st_rdev); - p->gdb_st_size = cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize = 0; - p->gdb_st_blocks = 0; -#else - p->gdb_st_blksize = cpu_to_be64(s->st_blksize); - p->gdb_st_blocks = cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime = cpu_to_be32(s->st_atime); - p->gdb_st_mtime = cpu_to_be32(s->st_mtime); - p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); - return true; -} - static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); @@ -147,8 +87,6 @@ static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) @@ -159,10 +97,6 @@ void do_nios2_semihosting(CPUNios2State *env) int nr; uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; nr = env->regs[R_ARG0]; args = env->regs[R_ARG1]; @@ -170,234 +104,95 @@ void do_nios2_semihosting(CPUNios2State *env) case HOSTED_EXIT: gdb_exit(env->regs[R_ARG0]); exit(env->regs[R_ARG0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, nios2_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - nios2_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + GET_ARG(3); + semihost_sys_lseek(cs, nios2_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - result = -1; - errno = EFAULT; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0 && !translate_stat(env, arg2, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_stat(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0 && !translate_stat(env, arg1, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_fstat(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: - /* Only the tv parameter is used. tz is assumed NULL. */ GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x", - arg0, 0); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = 0; - p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, arg0, sizeof(struct gdb_timeval)); - } - } + GET_ARG(1); + semihost_sys_gettimeofday(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, nios2_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, nios2_semi_u32_cb, arg0, arg1); break; + default: qemu_log_mask(LOG_GUEST_ERROR, "nios2-semihosting: unsupported " "semihosting syscall %d\n", nr); - result = 0; + nios2_semi_u32_cb(cs, -1, ENOSYS); + break; + + failed: + nios2_semi_u32_cb(cs, -1, EFAULT); + break; } -failed: - nios2_semi_u32_cb(cs, result, errno); } From patchwork Sat Apr 30 13:29:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568131 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7222489map; Sat, 30 Apr 2022 06:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkUhggTL3AjhUYHkUMkA5/J3aolvFrp3D2cEh0ydv/2Fbc+LZXfi+fWJqJxbF/1rZv9/MW X-Received: by 2002:a05:620a:14b2:b0:69f:9cc3:a6df with SMTP id x18-20020a05620a14b200b0069f9cc3a6dfmr2782883qkj.406.1651327174961; Sat, 30 Apr 2022 06:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651327174; cv=none; d=google.com; s=arc-20160816; b=DLczyniHGtZwxbdfdQ5awHtANcr/GoFXs4tDeS0jm6YItwbQ77mxbefB4MUdkSVEvV crM85gs17zwp9SmQOTauuE43b43sxat1fY55iYA/qx1vjDKBU8vj5MrAolT2wCSHgWLa UuuhvBDA2Ixm7dsBX70gd/r5RHyu1xYCxC5WLi1n5KumQhTLnDQOJG2+Do9s9J+NVSOL JuO6uC/AXRRngxsfxqjym0KZmAbtS5mKMKfJ3UobW/NAPenmuM2A0zzqI97gCLKEY09A HNGCRQ41brCpT9dnvgJqcSaWY/cbdrExSyYtY0Iy+SBXlYMD6yS6BUwhVTasLVtrM/Cu OWQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UdtjLtols2yqTud00vK3rG7dIDZOc8n/MVdagQPOyIc=; b=fjrz6SoGe4lf14mANWnmkSNIvGukFDo4OxpWkATQvA4JbDXwwGeeYUvb4UiOs5/q2Y RmIehH2kr5T/+/Wc8t7RzjvD9S8NCmZBXo8ImWIWzNb4INnTxTe6CopxNSLtwYZBl4ll VhbHfJoHchCnLH/lmQMTStAnV475ZbC5Uc4mQPiypujrxUry5VHFz8lMki3ii+5yeQkW TDBmx88QnNHnp54WIXnBK6f86wDTI2kCMJIWMNfQodAoOIFqiPwtTnhNgRvyNssHN9sv ivC1RnDkKpgvekuh0hmXIEXc7dhyqQGtahrXT73uh6R7kqPAyQu7OFMFncAgdqxbbEoU ifyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="R5/ljiZ0"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n17-20020a0ce551000000b00440e46a7d34si3594125qvm.466.2022.04.30.06.59.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="R5/ljiZ0"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkndG-0007Am-IX for patch@linaro.org; Sat, 30 Apr 2022 09:59:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknDs-0003Pp-CK for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:20 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:46983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknDq-0006uM-6R for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:33:19 -0400 Received: by mail-pj1-x1035.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso4078387pjb.5 for ; Sat, 30 Apr 2022 06:33: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=UdtjLtols2yqTud00vK3rG7dIDZOc8n/MVdagQPOyIc=; b=R5/ljiZ0GIpQjZne/EEGJXQiblXl+KuEzFDWZLp3eECeJ2WmOGnxSgtHUyH5cBK7W7 Dgv7NRcmE7fDdvOrY4WMQ6BXN+sbH5+47IbmEE8zmV74ReNipUPvChwfMmFJUvy8zZPp NfK9xuSI5SpEYZ3H4GZ6OtmyxvFM7AL3kx8HTuzktoH4hSSAKdv+WDjXHWkLc5rs40TC 4aw3yr7Bva2c8OBR57pkZ3KXryqB344eJb8L7KaIVVeYX7SgaeGawBPzknLxCiuqCYyd FLX4T7I91DFQKDDsyQRJnS9opDvTDM/LpMewjHEqH1SzSEX14crJo8bG1k8fYCqLrDKo bjKQ== 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=UdtjLtols2yqTud00vK3rG7dIDZOc8n/MVdagQPOyIc=; b=M11/pf3Q6ol63CM2eX0KX/mBi9zHHPIEY10aLEwxfWqORCpRUHzqLVEbJyxe8Agcjt MSJAAMNCUWDTDnG+mPumvplrklOW7gW7K/LBGk/dzGmvovQONSOMekDicE0fHbgjZDMJ DqjE6Xch+zRt3z0D/6Gv9ZX23NnVHFk64hCYEOKTYl3jzzH56HaKHm/pfRPaUUN8ULfQ fNWhRVfo9gACSKJdw8yFymSGAZWW987gCZaoKiKQW+e6suuRAWmsNdE8Xrv9acU0zZVE 8xzSuaVMY5bkW/UcaPE0CTeKIH84prZy7fxRhRZUgsQyPByP8Dyj9GBTG7NBLPJCW/Yx mdcw== X-Gm-Message-State: AOAM531wjpN/DYB/3Bu0ZVspJ0TbzYTVM9hV7qwTukAiJ3hXfvKwAo5A kGh31+a8nCEZLUezKW8PES92lbGJy8hsxQ== X-Received: by 2002:a17:903:24f:b0:15c:e3b8:a640 with SMTP id j15-20020a170903024f00b0015ce3b8a640mr3656771plh.5.1651325596803; Sat, 30 Apr 2022 06:33:16 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id c136-20020a63358e000000b003c14af5063bsm8517840pga.83.2022.04.30.06.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:33:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 43/43] target/nios2: Do semihosting call as a normal helper Date: Sat, 30 Apr 2022 06:29:32 -0700 Message-Id: <20220430132932.324018-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There's no need to raise an exception; just call the helper function directly. Signed-off-by: Richard Henderson --- target/nios2/cpu.h | 3 --- target/nios2/helper.h | 1 + target/nios2/helper.c | 7 ------- target/nios2/nios2-semi.c | 3 ++- target/nios2/translate.c | 2 +- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index f85581ee56..75a111a25e 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -164,7 +164,6 @@ FIELD(CR_TLBMISC, EE, 24, 1) /* Exceptions */ #define EXCP_BREAK 0x1000 -#define EXCP_SEMIHOST 0x1001 #define EXCP_RESET 0 #define EXCP_PRESET 1 #define EXCP_IRQ 2 @@ -269,8 +268,6 @@ G_NORETURN void nios2_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, G_NORETURN void nios2_cpu_loop_exit_advance(CPUNios2State *env, uintptr_t retaddr); -void do_nios2_semihosting(CPUNios2State *env); - #define CPU_RESOLVING_TYPE TYPE_NIOS2_CPU #define cpu_gen_code cpu_nios2_gen_code diff --git a/target/nios2/helper.h b/target/nios2/helper.h index 1648d76ade..51ec2b35a0 100644 --- a/target/nios2/helper.h +++ b/target/nios2/helper.h @@ -29,4 +29,5 @@ DEF_HELPER_3(wrprs, void, env, i32, i32) DEF_HELPER_2(mmu_write_tlbacc, void, env, i32) DEF_HELPER_2(mmu_write_tlbmisc, void, env, i32) DEF_HELPER_2(mmu_write_pteaddr, void, env, i32) +DEF_HELPER_1(semihosting, void, env) #endif diff --git a/target/nios2/helper.c b/target/nios2/helper.c index bb3b09e5a7..491cbd486f 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -173,9 +173,6 @@ void nios2_cpu_do_interrupt(CPUState *cs) case EXCP_BREAK: name = "BREAK insn"; break; - case EXCP_SEMIHOST: - name = "SEMIHOST insn"; - break; } if (name) { qemu_log("%s at pc=0x%08x\n", name, env->pc); @@ -250,10 +247,6 @@ void nios2_cpu_do_interrupt(CPUState *cs) do_exception(cpu, cpu->exception_addr, 0, true); break; - case EXCP_SEMIHOST: - do_nios2_semihosting(env); - break; - default: cpu_abort(cs, "unhandled exception type=%d\n", cs->exception_index); } diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 3dad72d1f6..9648030d37 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -32,6 +32,7 @@ #include "semihosting/softmmu-uaccess.h" #endif #include "qemu/log.h" +#include "exec/helper-proto.h" #define HOSTED_EXIT 0 #define HOSTED_INIT_SIM 1 @@ -91,7 +92,7 @@ static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) } \ } while (0) -void do_nios2_semihosting(CPUNios2State *env) +void HELPER(semihosting)(CPUNios2State *env) { CPUState *cs = env_cpu(env); int nr; diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 3a037a68cc..f245fd7d0a 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -819,7 +819,7 @@ static void gen_break(DisasContext *dc, uint32_t code, uint32_t flags) /* The semihosting instruction is "break 1". */ R_TYPE(instr, code); if (semihosting_enabled() && instr.imm5 == 1) { - t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); + gen_helper_semihosting(cpu_env); return; } #endif