From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325677351771.5875512223948; Sat, 30 Apr 2022 06:34:37 -0700 (PDT) Received: from localhost ([::1]:52162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknF6-00053x-6o for importer@patchew.org; Sat, 30 Apr 2022 09:34:36 -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) 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) 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-Google-Smtp-Source: ABdhPJzz4tT2nNjhZR0GLRsrBXpwntjGhIScFqIznjOPpcA3HefYjwRn6nJ8GUYXH0eJJx2QbAJI3Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325679198100001 Content-Type: text/plain; charset="utf-8" We have a subdirectory for semihosting; move this file out of exec. Rename to emphasize the contents are a replacement for the functions in linux-user/bsd-user uaccess.c. Signed-off-by: Richard Henderson --- .../{exec/softmmu-semi.h =3D> semihosting/softmmu-uaccess.h} | 6 +++--- semihosting/arm-compat-semi.c | 2 +- target/m68k/m68k-semi.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 2 +- target/nios2/nios2-semi.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename include/{exec/softmmu-semi.h =3D> semihosting/softmmu-uaccess.h} (9= 5%) diff --git a/include/exec/softmmu-semi.h b/include/semihosting/softmmu-uacc= ess.h similarity index 95% rename from include/exec/softmmu-semi.h rename to include/semihosting/softmmu-uaccess.h index fbcae88f4b..e69e3c8548 100644 --- a/include/exec/softmmu-semi.h +++ b/include/semihosting/softmmu-uaccess.h @@ -7,8 +7,8 @@ * This code is licensed under the GPL */ =20 -#ifndef SOFTMMU_SEMI_H -#define SOFTMMU_SEMI_H +#ifndef SEMIHOSTING_SOFTMMU_UACCESS_H +#define SEMIHOSTING_SOFTMMU_UACCESS_H =20 #include "cpu.h" =20 @@ -98,4 +98,4 @@ static void softmmu_unlock_user(CPUArchState *env, void *= p, target_ulong addr, } #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) =20 -#endif +#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7a51fd0737..dbef280b87 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -370,7 +370,7 @@ static GuestFD *get_guestfd(int guestfd) #ifndef CONFIG_USER_ONLY static target_ulong syscall_err; =20 -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif =20 static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37343d47e2..a31db38fc3 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -25,7 +25,7 @@ #include "qemu.h" #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #endif #include "qemu/log.h" diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mi= ps-semi.c index b4a383ae90..6d6296e709 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "qemu/log.h" #include "exec/helper-proto.h" -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" =20 diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index ec88474a73..373e6b9436 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -28,7 +28,7 @@ #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif #include "qemu/log.h" =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325540502103.12923905105333; Sat, 30 Apr 2022 06:32:20 -0700 (PDT) Received: from localhost ([::1]:43762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknCt-0007vh-Bf for importer@patchew.org; Sat, 30 Apr 2022 09:32:19 -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) 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) 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-Google-Smtp-Source: ABdhPJzs2LXhJuHJQ5+20dNqwg0JkVSuDlPlk7pEvK/LpHfHLjL8VVS2OuZK3/CudfuQJjce9PEzhQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325542436100005 Content-Type: text/plain; charset="utf-8" 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/so= ftmmu-uaccess.h index e69e3c8548..5246a91570 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -12,82 +12,69 @@ =20 #include "cpu.h" =20 -static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) -{ - uint64_t val; +#define get_user_u64(val, addr) \ + ({ uint64_t val_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D tswap64(val_); ret_; }) =20 - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 0); - return tswap64(val); -} +#define get_user_u32(val, addr) \ + ({ uint32_t val_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D tswap32(val_); ret_; }) =20 -static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr) -{ - uint32_t val; +#define get_user_u8(val, addr) \ + ({ uint8_t val_ =3D 0; \ + int ret_ =3D cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) =3D val_; ret_; }) =20 - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 0); - return tswap32(val); -} - -static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr) -{ - uint8_t val; - - cpu_memory_rw_debug(env_cpu(env), addr, &val, 1, 0); - return val; -} - -#define get_user_u64(arg, p) ({ arg =3D softmmu_tget64(env, p); 0; }) -#define get_user_u32(arg, p) ({ arg =3D softmmu_tget32(env, p) ; 0; }) -#define get_user_u8(arg, p) ({ arg =3D softmmu_tget8(env, p) ; 0; }) #define get_user_ual(arg, p) get_user_u32(arg, p) =20 -static inline void softmmu_tput64(CPUArchState *env, - target_ulong addr, uint64_t val) -{ - val =3D tswap64(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1); -} +#define put_user_u64(val, addr) \ + ({ uint64_t val_ =3D tswap64(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); = }) + +#define put_user_u32(val, addr) \ + ({ uint32_t val_ =3D tswap32(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); = }) =20 -static inline void softmmu_tput32(CPUArchState *env, - target_ulong addr, uint32_t val) -{ - val =3D tswap32(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 1); -} -#define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; }) -#define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; }) #define put_user_ual(arg, p) put_user_u32(arg, p) =20 -static void *softmmu_lock_user(CPUArchState *env, - target_ulong addr, target_ulong len, int co= py) +static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) { - uint8_t *p; - /* TODO: Make this something that isn't fixed size. */ - p =3D malloc(len); + void *p =3D malloc(len); if (p && copy) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0); + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p =3D NULL; + } } return p; } #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) + static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - char *p; - char *s; - uint8_t c; /* TODO: Make this something that isn't fixed size. */ - s =3D p =3D malloc(1024); + char *s =3D malloc(1024); + size_t len =3D 0; + if (!s) { return NULL; } do { - cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0); - addr++; - *(p++) =3D c; - } while (c); + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); return s; } #define lock_user_string(p) softmmu_lock_user_string(env, p) + static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong a= ddr, target_ulong len) { --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325818675355.014343556345; Sat, 30 Apr 2022 06:36:58 -0700 (PDT) Received: from localhost ([::1]:60098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknHN-0001z1-Cn for importer@patchew.org; Sat, 30 Apr 2022 09:36:57 -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) 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) 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-Google-Smtp-Source: ABdhPJweC17YhaCdFBjS33va1wNkP7pBfYJ8+bRF0QV7zl/O/PYbGd1LetMAlYzhyFiyIpFYt2d3FA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325819771100001 Content-Type: text/plain; charset="utf-8" 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: f= iles( 'config.c', 'console.c', )) --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325539786262.5700510519164; Sat, 30 Apr 2022 06:32:19 -0700 (PDT) Received: from localhost ([::1]:43712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknCs-0007ty-FK for importer@patchew.org; Sat, 30 Apr 2022 09:32:18 -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) 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) 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-Google-Smtp-Source: ABdhPJzEBkxkXAa3nriIPQhsRCIemlqJvyH+tCWnr2FWSN5wCovP9gnr/7AfU1Ou5jEgaF/YsvlZ1Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325540811100001 Content-Type: text/plain; charset="utf-8" Rather that static (and not even inline) functions within a header, move the functions to semihosting/uaccess.c. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 42 +++------------------- semihosting/uaccess.c | 51 +++++++++++++++++++++++++++ semihosting/meson.build | 1 + 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 semihosting/uaccess.c diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/so= ftmmu-uaccess.h index 5246a91570..03300376d3 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -42,47 +42,15 @@ =20 #define put_user_ual(arg, p) put_user_u32(arg, p) =20 -static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, - target_ulong len, bool copy) -{ - void *p =3D malloc(len); - if (p && copy) { - if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); - p =3D NULL; - } - } - return p; -} +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy); #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) =20 -static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) -{ - /* TODO: Make this something that isn't fixed size. */ - char *s =3D malloc(1024); - size_t len =3D 0; - - if (!s) { - return NULL; - } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; -} +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr); #define lock_user_string(p) softmmu_lock_user_string(env, p) =20 -static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong a= ddr, - target_ulong len) -{ - if (len) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); - } - free(p); -} +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) =20 #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c new file mode 100644 index 0000000000..0d3b32b75d --- /dev/null +++ b/semihosting/uaccess.c @@ -0,0 +1,51 @@ +/* + * Helper routines to provide target memory access for semihosting + * syscalls in system emulation mode. + * + * Copyright (c) 2007 CodeSourcery. + * + * This code is licensed under the GPL + */ + +#include "qemu/osdep.h" +#include "semihosting/softmmu-uaccess.h" + +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) +{ + void *p =3D malloc(len); + if (p && copy) { + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p =3D NULL; + } + } + return p; +} + +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) +{ + /* TODO: Make this something that isn't fixed size. */ + char *s =3D malloc(1024); + size_t len =3D 0; + + if (!s) { + return NULL; + } + do { + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); + return s; +} + +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len) +{ + if (len) { + cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); + } + free(p); +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 4344e43fb9..10b3b99921 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,6 +1,7 @@ specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: f= iles( 'config.c', 'console.c', + 'uaccess.c', )) =20 specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325666118579.8086649152331; Sat, 30 Apr 2022 06:34:26 -0700 (PDT) Received: from localhost ([::1]:51594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknEu-0004gr-B9 for importer@patchew.org; Sat, 30 Apr 2022 09:34:24 -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) 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) 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-Google-Smtp-Source: ABdhPJyh6NfVG1782gUd4SNz6TGwwthJnVlxhoKxmgF8TykosrYSVqiKtWKVEqOeymR2oJlc84En6A== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325667026100001 Content-Type: text/plain; charset="utf-8" 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/so= ftmmu-uaccess.h index 03300376d3..4f08dfc098 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -53,4 +53,7 @@ void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) =20 +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr); +#define target_strlen(p) softmmu_strlen_user(env, p) + #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 0d3b32b75d..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; } =20 +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + char buf[256]; + size_t len =3D 0; + + while (1) { + size_t chunk; + char *p; + + chunk =3D -(addr | TARGET_PAGE_MASK); + chunk =3D MIN(chunk, sizeof(buf)); + + if (cpu_memory_rw_debug(env_cpu(env), addr, buf, chunk, 0)) { + return -1; + } + p =3D memchr(buf, 0, chunk); + if (p) { + len +=3D p - buf; + return len <=3D INT32_MAX ? (ssize_t)len : -1; + } + + len +=3D chunk; + addr +=3D 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. */ --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325825904807.6332235733395; Sat, 30 Apr 2022 06:37:05 -0700 (PDT) Received: from localhost ([::1]:60736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknHU-0002QF-TJ for importer@patchew.org; Sat, 30 Apr 2022 09:37:04 -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) 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) 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-Google-Smtp-Source: ABdhPJxZ3WP9Fe707OiT3OC7ovMl8QGAPO5WXUnUDK5iedJaSRf44KAQGeGLbEeTaWZHWp7kn3m1rg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325827806100002 Content-Type: text/plain; charset="utf-8" We are not currently bounding the search to the 1024 bytes that we allocated, possibly overrunning the buffer. Use softmmu_strlen_user to find the length and allocate the correct size from the beginning. 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_u= long addr) =20 char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - /* TODO: Make this something that isn't fixed size. */ - char *s =3D malloc(1024); - size_t len =3D 0; - - if (!s) { + ssize_t len =3D softmmu_strlen_user(env, addr); + if (len < 0) { return NULL; } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; + return softmmu_lock_user(env, addr, len + 1, true); } =20 void softmmu_unlock_user(CPUArchState *env, void *p, --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325989592372.83275786199385; Sat, 30 Apr 2022 06:39:49 -0700 (PDT) Received: from localhost ([::1]:41152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknK4-0008Lr-88 for importer@patchew.org; Sat, 30 Apr 2022 09:39:44 -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) 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) 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-Google-Smtp-Source: ABdhPJxtJSAoUtE5lrmVog7bWMS+AO8RBhhgeIrjL7pVRYwVVJgY0c3tvtOdnoiN/pdT5c/6QU2pQg== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325990636100001 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/aarch= 64-linux-user.mak index d0c603c54e..db552f1839 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=3Daarch64 TARGET_BASE_ARCH=3Darm TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aa= rch64_be-linux-user.mak index 7794424745..dc78044fb1 100644 --- a/configs/targets/aarch64_be-linux-user.mak +++ b/configs/targets/aarch64_be-linux-user.mak @@ -3,4 +3,5 @@ TARGET_BASE_ARCH=3Darm TARGET_BIG_ENDIAN=3Dy TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/arm-linux-user.mak b/configs/targets/arm-linux= -user.mak index 3e10d6b15d..7f5d65794c 100644 --- a/configs/targets/arm-linux-user.mak +++ b/configs/targets/arm-linux-user.mak @@ -3,4 +3,5 @@ TARGET_SYSTBL_ABI=3Dcommon,oabi TARGET_SYSTBL=3Dsyscall.tbl TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-v= fp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-prof= ile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/armeb-linux-user.mak b/configs/targets/armeb-l= inux-user.mak index a249cc2e29..943d0d87bf 100644 --- a/configs/targets/armeb-linux-user.mak +++ b/configs/targets/armeb-linux-user.mak @@ -4,4 +4,5 @@ TARGET_SYSTBL=3Dsyscall.tbl TARGET_BIG_ENDIAN=3Dy TARGET_XML_FILES=3D gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-v= fp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-prof= ile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=3Dy +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/riscv32-linux-user.mak b/configs/targets/riscv= 32-linux-user.mak index bd2f1fd497..9761618e67 100644 --- a/configs/targets/riscv32-linux-user.mak +++ b/configs/targets/riscv32-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=3Driscv32 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-virtual.xml +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/configs/targets/riscv64-linux-user.mak b/configs/targets/riscv= 64-linux-user.mak index 4aca7662ce..cfd1fd382f 100644 --- a/configs/targets/riscv64-linux-user.mak +++ b/configs/targets/riscv64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=3Driscv64 TARGET_BASE_ARCH=3Driscv TARGET_ABI_DIR=3Driscv TARGET_XML_FILES=3D gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xm= l gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml +CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h new file mode 100644 index 0000000000..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 =C2=A9 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_GUESTFD_H +#define SEMIHOSTING_GUESTFD_H + +typedef enum GuestFDType { + GuestFDUnused =3D 0, + GuestFDHost =3D 1, + GuestFDGDB =3D 2, + GuestFDFeatureFile =3D 3, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + union { + int hostfd; + 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 @@ */ =20 #include "qemu/osdep.h" - #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" +#include "semihosting/guestfd.h" #include "qemu/timer.h" #include "exec/gdbstub.h" + #ifdef CONFIG_USER_ONLY #include "qemu.h" =20 @@ -123,27 +124,6 @@ static int open_modeflags[12] =3D { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; =20 -typedef enum GuestFDType { - GuestFDUnused =3D 0, - GuestFDHost =3D 1, - GuestFDGDB =3D 2, - GuestFDFeatureFile =3D 3, -} GuestFDType; - -/* - * Guest file descriptors are integer indexes into an array of - * these structures (we will dynamically resize as necessary). - */ -typedef struct GuestFD { - GuestFDType type; - union { - int hostfd; - target_ulong featurefile_offset; - }; -} GuestFD; - -static GArray *guestfd_array; - #ifndef CONFIG_USER_ONLY =20 /** @@ -268,98 +248,6 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) =20 #endif =20 -/* - * Allocate a new guest file descriptor and return it; if we - * couldn't allocate a new fd then return -1. - * This is a fairly simplistic implementation because we don't - * expect that most semihosting guest programs will make very - * heavy use of opening and closing fds. - */ -static int alloc_guestfd(void) -{ - guint i; - - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - - /* SYS_OPEN should return nonzero handle on success. Start guestfd fro= m 1 */ - for (i =3D 1; i < guestfd_array->len; i++) { - GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, i); - - if (gf->type =3D=3D GuestFDUnused) { - return i; - } - } - - /* All elements already in use: expand the array */ - g_array_set_size(guestfd_array, i + 1); - return i; -} - -/* - * Look up the guestfd in the data structure; return NULL - * for out of bounds, but don't check whether the slot is unused. - * This is used internally by the other guestfd functions. - */ -static GuestFD *do_get_guestfd(int guestfd) -{ - if (!guestfd_array) { - return NULL; - } - - if (guestfd <=3D 0 || guestfd >=3D guestfd_array->len) { - return NULL; - } - - return &g_array_index(guestfd_array, GuestFD, guestfd); -} - -/* - * Associate the specified guest fd (which must have been - * allocated via alloc_fd() and not previously used) with - * the specified host/gdb fd. - */ -static void associate_guestfd(int guestfd, int hostfd) -{ - GuestFD *gf =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; - gf->hostfd =3D hostfd; -} - -/* - * Deallocate the specified guest file descriptor. This doesn't - * close the host fd, it merely undoes the work of alloc_fd(). - */ -static void dealloc_guestfd(int guestfd) -{ - GuestFD *gf =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D GuestFDUnused; -} - -/* - * Given a guest file descriptor, get the associated struct. - * If the fd is not valid, return NULL. This is the function - * used by the various semihosting calls to validate a handle - * from the guest. - * Note: calling alloc_guestfd() or dealloc_guestfd() will - * invalidate any GuestFD* obtained by calling this function. - */ -static GuestFD *get_guestfd(int guestfd) -{ - GuestFD *gf =3D do_get_guestfd(guestfd); - - if (!gf || gf->type =3D=3D GuestFDUnused) { - return NULL; - } - return gf; -} - /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -665,15 +553,6 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void init_featurefile_guestfd(int guestfd) -{ - GuestFD *gf =3D do_get_guestfd(guestfd); - - assert(gf); - gf->type =3D GuestFDFeatureFile; - gf->featurefile_offset =3D 0; -} - static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) { /* 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 =C2=A9 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" + +static GArray *guestfd_array; + +/* + * Allocate a new guest file descriptor and return it; if we + * couldn't allocate a new fd then return -1. + * This is a fairly simplistic implementation because we don't + * expect that most semihosting guest programs will make very + * heavy use of opening and closing fds. + */ +int alloc_guestfd(void) +{ + guint i; + + if (!guestfd_array) { + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + /* SYS_OPEN should return nonzero handle on success. Start guestfd fro= m 1 */ + for (i =3D 1; i < guestfd_array->len; i++) { + GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type =3D=3D GuestFDUnused) { + return i; + } + } + + /* All elements already in use: expand the array */ + g_array_set_size(guestfd_array, i + 1); + return i; +} + +/* + * Look up the guestfd in the data structure; return NULL + * for out of bounds, but don't check whether the slot is unused. + * This is used internally by the other guestfd functions. + */ +static GuestFD *do_get_guestfd(int guestfd) +{ + if (!guestfd_array) { + return NULL; + } + + if (guestfd <=3D 0 || guestfd >=3D guestfd_array->len) { + return NULL; + } + + return &g_array_index(guestfd_array, GuestFD, guestfd); +} + +/* + * Given a guest file descriptor, get the associated struct. + * If the fd is not valid, return NULL. This is the function + * used by the various semihosting calls to validate a handle + * from the guest. + * Note: calling alloc_guestfd() or dealloc_guestfd() will + * invalidate any GuestFD* obtained by calling this function. + */ +GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + if (!gf || gf->type =3D=3D GuestFDUnused) { + return NULL; + } + return gf; +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host/gdb fd. + */ +void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; + gf->hostfd =3D hostfd; +} + +void init_featurefile_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDFeatureFile; + gf->featurefile_offset =3D 0; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +void dealloc_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDUnused; +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 10b3b99921..d2c1c37bfd 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,3 +1,7 @@ +specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'guestfd.c', +)) + specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: f= iles( 'config.c', 'console.c', --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165132567904512.12640230269676; Sat, 30 Apr 2022 06:34:39 -0700 (PDT) Received: from localhost ([::1]:52256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknF7-00057k-Is for importer@patchew.org; Sat, 30 Apr 2022 09:34:37 -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) 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) 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-Google-Smtp-Source: ABdhPJyCm8+5toy8b8esfI9OE3dzFrNHMEcB84UCMtZAvcLo5aAlvDhykKFRpZZHolhvQduxvkYb/g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325681233100004 Content-Type: text/plain; charset="utf-8" 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 =3D 0, GuestFDHost =3D 1, GuestFDGDB =3D 2, - GuestFDFeatureFile =3D 3, + GuestFDStatic =3D 3, } GuestFDType; =20 /* @@ -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; =20 @@ -35,6 +39,6 @@ void dealloc_guestfd(int guestfd); GuestFD *get_guestfd(int guestfd); =20 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); =20 #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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } =20 -static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ @@ -568,7 +568,7 @@ static uint32_t featurefile_writefn(CPUState *cs, Guest= FD *gf, return set_swi_errno(cs, -1); } =20 -static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { CPUArchState *env =3D cs->env_ptr; @@ -582,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, } =20 for (i =3D 0; i < len; i++) { - if (gf->featurefile_offset >=3D sizeof(featurefile_data)) { + if (gf->staticfile.off >=3D gf->staticfile.len) { break; } - s[i] =3D featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] =3D gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } =20 unlock_user(s, buf, len); @@ -595,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, return len - i; } =20 -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } =20 -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset =3D offset; + gf->staticfile.off =3D offset; return 0; } =20 -static uint32_t featurefile_flenfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return sizeof(featurefile_data); + return gf->staticfile.len; } =20 typedef struct GuestFDFunctions { @@ -638,13 +638,13 @@ static const GuestFDFunctions guestfd_fns[] =3D { .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, - [GuestFDFeatureFile] =3D { - .closefn =3D featurefile_closefn, - .writefn =3D featurefile_writefn, - .readfn =3D featurefile_readfn, - .isattyfn =3D featurefile_isattyfn, - .seekfn =3D featurefile_seekfn, - .flenfn =3D featurefile_flenfn, + [GuestFDStatic] =3D { + .closefn =3D staticfile_closefn, + .writefn =3D staticfile_writefn, + .readfn =3D staticfile_readfn, + .isattyfn =3D staticfile_isattyfn, + .seekfn =3D staticfile_seekfn, + .flenfn =3D staticfile_flenfn, }, }; =20 @@ -765,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno =3D EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } =20 diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c 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 =3D hostfd; } =20 -void init_featurefile_guestfd(int guestfd) +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) { GuestFD *gf =3D do_get_guestfd(guestfd); =20 assert(gf); - gf->type =3D GuestFDFeatureFile; - gf->featurefile_offset =3D 0; + gf->type =3D GuestFDStatic; + gf->staticfile.data =3D data; + gf->staticfile.len =3D len; + gf->staticfile.off =3D 0; } =20 /* --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326351176198.2202681555026; Sat, 30 Apr 2022 06:45:51 -0700 (PDT) Received: from localhost ([::1]:58142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknPx-000305-Md for importer@patchew.org; Sat, 30 Apr 2022 09:45:49 -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) 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) 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-Google-Smtp-Source: ABdhPJxAoEHHkBGo3pzcjz9+lOr5WJH1UNA9iOjHssJRGV71E9Kff7N38LKTyLMAZ1L4jBSrfUsq3g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326352235100001 Content-Type: text/plain; charset="utf-8" Perform the cleanup in the FIXME comment in common_semi_gdb_syscall. Do not modify guest registers until the syscall is complete, which in the gdbstub case is asynchronous. In the synchronous non-gdbstub case, use common_semi_set_ret to set the result. Merge set_swi_errno into common_semi_cb. Rely on the latter for combined return value / errno setting. Signed-off-by: Richard Henderson --- semihosting/common-semi.h | 2 +- linux-user/aarch64/cpu_loop.c | 2 +- linux-user/arm/cpu_loop.c | 2 +- linux-user/riscv/cpu_loop.c | 2 +- semihosting/arm-compat-semi.c | 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 =20 -target_ulong do_common_semihosting(CPUState *cs); +void do_common_semihosting(CPUState *cs); =20 #endif /* COMMON_SEMI_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 3b273f6299..f7ef36cd9f 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -154,7 +154,7 @@ void cpu_loop(CPUARMState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case EXCP_SEMIHOST: - env->xregs[0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; break; case EXCP_YIELD: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index d950409d5b..c0790f3246 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -449,7 +449,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SEMIHOST: - env->regs[0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] +=3D env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 29084c1421..bffca7db12 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -81,7 +81,7 @@ void cpu_loop(CPURISCVState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case RISCV_EXCP_SEMIHOST: - env->gpr[xA0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; break; default: diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 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 =20 -static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) -{ - if (code =3D=3D (uint32_t)-1) { -#ifdef CONFIG_USER_ONLY - TaskState *ts =3D cs->opaque; - - ts->swi_errno =3D errno; -#else - syscall_err =3D errno; -#endif - } - return code; -} - static inline uint32_t get_swi_errno(CPUState *cs) { #ifdef CONFIG_USER_ONLY @@ -290,28 +276,29 @@ static target_ulong common_semi_syscall_len; =20 static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { - target_ulong reg0 =3D common_semi_arg(cs, 0); - if (ret =3D=3D (target_ulong)-1) { - errno =3D err; - set_swi_errno(cs, -1); - reg0 =3D ret; +#ifdef CONFIG_USER_ONLY + TaskState *ts =3D cs->opaque; + ts->swi_errno =3D err; +#else + syscall_err =3D err; +#endif } else { /* Fixup syscalls that use nonstardard return conventions. */ + target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 =3D common_semi_syscall_len - ret; + ret =3D common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: - reg0 =3D 0; + ret =3D 0; break; default: - reg0 =3D ret; break; } } - common_semi_set_ret(cs, reg0); + common_semi_set_ret(cs, ret); } =20 static target_ulong common_semi_flen_buf(CPUState *cs) @@ -351,9 +338,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, tar= get_ulong err) cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, (uint8_t *)&size, 4, 0); size =3D be32_to_cpu(size); + common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); - errno =3D err; - set_swi_errno(cs, -1); } =20 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 =3D=3D (target_ulong)-1) { - errno =3D err; - set_swi_errno(cs, -1); dealloc_guestfd(common_semi_open_guestfd); } else { associate_guestfd(common_semi_open_guestfd, ret); ret =3D common_semi_open_guestfd; } - common_semi_set_ret(cs, ret); -} - -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); } =20 /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all - * do the work and return the required return value for the guest, - * setting the guest errno if appropriate. + * do the work and return the required return value to the guest + * via common_semi_cb. */ -typedef uint32_t sys_closefn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset); -typedef uint32_t sys_flenfn(CPUState *cs, GuestFD *gf); +typedef void sys_closefn(CPUState *cs, GuestFD *gf); +typedef void sys_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); +typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); +typedef void sys_flenfn(CPUState *cs, GuestFD *gf); =20 -static uint32_t host_closefn(CPUState *cs, GuestFD *gf) +static void host_closefn(CPUState *cs, GuestFD *gf) { + int ret; /* * Only close the underlying host fd if it's one we opened on behalf * of the guest in SYS_OPEN. @@ -427,113 +381,106 @@ static uint32_t host_closefn(CPUState *cs, GuestFD = *gf) if (gf->hostfd =3D=3D STDIN_FILENO || gf->hostfd =3D=3D STDOUT_FILENO || gf->hostfd =3D=3D STDERR_FILENO) { - return 0; + ret =3D 0; + } else { + ret =3D close(gf->hostfd); } - return set_swi_errno(cs, close(gf->hostfd)); + common_semi_cb(cs, ret, ret ? errno : 0); } =20 -static uint32_t host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env =3D cs->env_ptr; - uint32_t ret; + uint32_t ret =3D 0; char *s =3D lock_user(VERIFY_READ, buf, len, 1); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* Return bytes not written on error */ - return len; + if (s) { + ret =3D write(gf->hostfd, s, len); + unlock_user(s, buf, 0); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } } - ret =3D set_swi_errno(cs, write(gf->hostfd, s, len)); - unlock_user(s, buf, 0); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not written */ - return len - ret; + /* Return bytes not written, on error as well. */ + common_semi_cb(cs, len - ret, 0); } =20 -static uint32_t host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env =3D cs->env_ptr; - uint32_t ret; + uint32_t ret =3D 0; char *s =3D lock_user(VERIFY_WRITE, buf, len, 0); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* return bytes not read */ - return len; + if (s) { + do { + ret =3D read(gf->hostfd, s, len); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + unlock_user(s, buf, len); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } } - do { - ret =3D set_swi_errno(cs, read(gf->hostfd, s, len)); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); - unlock_user(s, buf, len); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not read */ - return len - ret; + /* Return bytes not read, on error as well. */ + common_semi_cb(cs, len - ret, 0); } =20 -static uint32_t host_isattyfn(CPUState *cs, GuestFD *gf) +static void host_isattyfn(CPUState *cs, GuestFD *gf) { - return isatty(gf->hostfd); + common_semi_cb(cs, isatty(gf->hostfd), 0); } =20 -static uint32_t host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - uint32_t ret =3D set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)= ); - if (ret =3D=3D (uint32_t)-1) { - return -1; - } - return 0; + off_t ret =3D lseek(gf->hostfd, offset, SEEK_SET); + common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); } =20 -static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) +static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; - uint32_t ret =3D set_swi_errno(cs, fstat(gf->hostfd, &buf)); - if (ret =3D=3D (uint32_t)-1) { - return -1; + + if (fstat(gf->hostfd, &buf)) { + common_semi_cb(cs, -1, errno); + } else { + common_semi_cb(cs, buf.st_size, 0); } - return buf.st_size; } =20 -static uint32_t gdb_closefn(CPUState *cs, GuestFD *gf) +static void gdb_closefn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "close,%x", gf->hos= tfd); + gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); } =20 -static uint32_t gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len =3D len; - return common_semi_gdb_syscall(cs, common_semi_cb, "write,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } =20 -static uint32_t gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len =3D len; - return common_semi_gdb_syscall(cs, common_semi_cb, "read,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); } =20 -static uint32_t gdb_isattyfn(CPUState *cs, GuestFD *gf) +static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "isatty,%x", gf->ho= stfd); + gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } =20 -static uint32_t gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - return common_semi_gdb_syscall(cs, common_semi_cb, "lseek,%x,%x,0", - gf->hostfd, offset); + gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); } =20 -static uint32_t gdb_flenfn(CPUState *cs, GuestFD *gf) +static void gdb_flenfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); + gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, common_semi_flen_buf(cs)); } =20 #define SHFB_MAGIC_0 0x53 @@ -553,63 +500,57 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) +static void staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ - return 0; + common_semi_cb(cs, 0, 0); } =20 -static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ - - errno =3D EBADF; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EBADF); } =20 -static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env =3D cs->env_ptr; - uint32_t i; + uint32_t i =3D 0; char *s; =20 (void) env; /* Used in arm softmmu lock_user implicitly */ s =3D lock_user(VERIFY_WRITE, buf, len, 0); - if (!s) { - return len; - } - - for (i =3D 0; i < len; i++) { - if (gf->staticfile.off >=3D gf->staticfile.len) { - break; + if (s) { + for (i =3D 0; i < len; i++) { + if (gf->staticfile.off >=3D gf->staticfile.len) { + break; + } + s[i] =3D gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } - s[i] =3D gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; + unlock_user(s, buf, len); } =20 - unlock_user(s, buf, len); - /* Return number of bytes not read */ - return len - i; + common_semi_cb(cs, len - i, 0); } =20 -static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) +static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { - return 0; + common_semi_cb(cs, 0, 0); } =20 -static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset) +static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offs= et) { gf->staticfile.off =3D offset; - return 0; + common_semi_cb(cs, 0, 0); } =20 -static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) +static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return gf->staticfile.len; + common_semi_cb(cs, gf->staticfile.len, 0); } =20 typedef struct GuestFDFunctions { @@ -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 =3D 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 =3D 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 *e= nv) * leave the register unchanged. We use 0xdeadbeef as the return value * when there isn't a defined return value for the call. */ -target_ulong do_common_semihosting(CPUState *cs) +void do_common_semihosting(CPUState *cs) { CPUArchState *env =3D cs->env_ptr; target_ulong args; @@ -714,32 +655,23 @@ target_ulong do_common_semihosting(CPUState *cs) switch (nr) { case TARGET_SYS_OPEN: { - int guestfd; + int ret, err =3D 0; + int hostfd; =20 GET_ARG(0); GET_ARG(1); GET_ARG(2); s =3D lock_user_string(arg0); if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } if (arg1 >=3D 12) { unlock_user(s, arg0, 0); - errno =3D EINVAL; - return set_swi_errno(cs, -1); - } - - guestfd =3D alloc_guestfd(); - if (guestfd < 0) { - unlock_user(s, arg0, 0); - errno =3D EMFILE; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EINVAL); + break; } =20 if (strcmp(s, ":tt") =3D=3D 0) { - int result_fileno; - /* * We implement SH_EXT_STDOUT_STDERR, so: * open for read =3D=3D stdin @@ -747,63 +679,67 @@ target_ulong do_common_semihosting(CPUState *cs) * open for append =3D=3D stderr */ if (arg1 < 4) { - result_fileno =3D STDIN_FILENO; + hostfd =3D STDIN_FILENO; } else if (arg1 < 8) { - result_fileno =3D STDOUT_FILENO; + hostfd =3D STDOUT_FILENO; } else { - result_fileno =3D STDERR_FILENO; + hostfd =3D STDERR_FILENO; } - associate_guestfd(guestfd, result_fileno); - unlock_user(s, arg0, 0); - return guestfd; - } - if (strcmp(s, ":semihosting-features") =3D=3D 0) { - unlock_user(s, arg0, 0); + ret =3D alloc_guestfd(); + associate_guestfd(ret, hostfd); + } else if (strcmp(s, ":semihosting-features") =3D=3D 0) { /* We must fail opens for modes other than 0 ('r') or 1 ('rb')= */ if (arg1 !=3D 0 && arg1 !=3D 1) { - dealloc_guestfd(guestfd); - errno =3D EACCES; - return set_swi_errno(cs, -1); - } - staticfile_guestfd(guestfd, featurefile_data, - sizeof(featurefile_data)); - return guestfd; - } - - if (use_gdb_syscalls()) { - common_semi_open_guestfd =3D guestfd; - ret =3D common_semi_gdb_syscall(cs, common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg= 2 + 1, - gdb_open_modeflags[arg1]); - } else { - ret =3D set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); - if (ret =3D=3D (uint32_t)-1) { - dealloc_guestfd(guestfd); + ret =3D -1; + err =3D EACCES; } else { - associate_guestfd(guestfd, ret); - ret =3D guestfd; + ret =3D alloc_guestfd(); + staticfile_guestfd(ret, featurefile_data, + sizeof(featurefile_data)); + } + } else if (use_gdb_syscalls()) { + unlock_user(s, arg0, 0); + common_semi_open_guestfd =3D alloc_guestfd(); + gdb_do_syscall(common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg2 + 1, + gdb_open_modeflags[arg1]); + break; + } else { + hostfd =3D open(s, open_modeflags[arg1], 0644); + if (hostfd < 0) { + ret =3D -1; + err =3D errno; + } else { + ret =3D alloc_guestfd(); + associate_guestfd(ret, hostfd); } } unlock_user(s, arg0, 0); - return ret; + common_semi_cb(cs, ret, err); + break; } + case TARGET_SYS_CLOSE: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } - - ret =3D guestfd_fns[gf->type].closefn(cs, gf); + guestfd_fns[gf->type].closefn(cs, gf); dealloc_guestfd(arg0); - return ret; + break; + case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(cs->env_ptr, args); - return 0xdeadbeef; + common_semi_set_ret(cs, 0xdeadbeef); + break; + case TARGET_SYS_WRITE0: - return qemu_semihosting_console_outs(cs->env_ptr, args); + ret =3D qemu_semihosting_console_outs(cs->env_ptr, args); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); @@ -812,11 +748,11 @@ target_ulong do_common_semihosting(CPUState *cs) =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + break; =20 - return guestfd_fns[gf->type].writefn(cs, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); @@ -825,129 +761,150 @@ target_ulong do_common_semihosting(CPUState *cs) =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + break; =20 - return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(cs->env_ptr); + ret =3D qemu_semihosting_console_inc(cs->env_ptr); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_ISERROR: GET_ARG(0); - return (target_long) arg0 < 0 ? 1 : 0; + common_semi_set_ret(cs, (target_long)arg0 < 0); + break; + case TARGET_SYS_ISTTY: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].isattyfn(cs, gf); + break; =20 - return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].seekfn(cs, gf, arg1); + break; =20 - return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); =20 gf =3D get_guestfd(arg0); if (!gf) { - errno =3D EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].flenfn(cs, gf); + break; =20 - return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: + { + int len; + char *p; + GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), - (int) (arg1 & 0xff)) < 0) { - return -1; - } - ul_ret =3D (target_ulong) -1; - + len =3D asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xf= f); /* Make sure there's enough space in the buffer */ - if (strlen(s) < arg2) { - char *output =3D lock_user(VERIFY_WRITE, arg0, arg2, 0); - strcpy(output, s); - unlock_user(output, arg0, arg2); - ul_ret =3D 0; + if (len < 0 || len >=3D arg2) { + common_semi_set_ret(cs, -1); + break; } + p =3D lock_user(VERIFY_WRITE, arg0, len, 0); + if (!p) { + goto do_fault; + } + memcpy(p, s, len + 1); + unlock_user(p, arg0, len); free(s); - return ul_ret; + common_semi_set_ret(cs, 0); + break; + } + case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - ret =3D common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s= ", - arg0, (int)arg1 + 1); - } else { - s =3D lock_user_string(arg0); - if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); - } - ret =3D set_swi_errno(cs, remove(s)); - unlock_user(s, arg0, 0); + gdb_do_syscall(common_semi_cb, "unlink,%s", + arg0, (int)arg1 + 1); + break; } - return ret; + s =3D lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret =3D remove(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); + break; + case TARGET_SYS_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "rename,%s,= %s", - arg0, (int)arg1 + 1, arg2, - (int)arg3 + 1); + gdb_do_syscall(common_semi_cb, "rename,%s,%s", + arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); } else { char *s2; + s =3D lock_user_string(arg0); - s2 =3D lock_user_string(arg2); - if (!s || !s2) { - errno =3D EFAULT; - ret =3D set_swi_errno(cs, -1); - } else { - ret =3D set_swi_errno(cs, rename(s, s2)); + if (!s) { + goto do_fault; } - if (s2) - unlock_user(s2, arg2, 0); - if (s) + s2 =3D lock_user_string(arg2); + if (!s2) { unlock_user(s, arg0, 0); - return ret; + goto do_fault; + } + ret =3D rename(s, s2); + unlock_user(s2, arg2, 0); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); } + break; + case TARGET_SYS_CLOCK: - return clock() / (CLOCKS_PER_SEC / 100); + common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100)); + break; + case TARGET_SYS_TIME: - return set_swi_errno(cs, time(NULL)); + ul_ret =3D time(NULL); + common_semi_cb(cs, ul_ret, ul_ret =3D=3D -1 ? errno : 0); + break; + case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "system,%s", - arg0, (int)arg1 + 1); - } else { - s =3D lock_user_string(arg0); - if (!s) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); - } - ret =3D set_swi_errno(cs, system(s)); - unlock_user(s, arg0, 0); - return ret; + gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + = 1); + break; } + s =3D lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret =3D system(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); + break; + case TARGET_SYS_ERRNO: - return get_swi_errno(cs); + common_semi_set_ret(cs, get_swi_errno(cs)); + break; + case TARGET_SYS_GET_CMDLINE: { /* Build a command-line from the original argv. @@ -998,22 +955,20 @@ target_ulong do_common_semihosting(CPUState *cs) =20 if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - errno =3D E2BIG; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, E2BIG); + break; } =20 /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } =20 /* Lock the buffer on the ARM side. */ output_buffer =3D lock_user(VERIFY_WRITE, arg0, output_size, 0= ); if (!output_buffer) { - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } =20 /* Copy the command-line arguments. */ @@ -1028,9 +983,8 @@ target_ulong do_common_semihosting(CPUState *cs) =20 if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - errno =3D EFAULT; - status =3D set_swi_errno(cs, -1); - goto out; + unlock_user(output_buffer, arg0, 0); + goto do_fault; } =20 /* Separate arguments by white spaces. */ @@ -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) =20 if (fail) { /* Couldn't write back to argument block */ - errno =3D EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } } - return 0; + common_semi_set_ret(cs, 0); } + break; + case TARGET_SYS_EXIT: case TARGET_SYS_EXIT_EXTENDED: if (common_semi_sys_exit_extended(cs, nr)) { @@ -1137,6 +1093,7 @@ target_ulong do_common_semihosting(CPUState *cs) } gdb_exit(ret); exit(ret); + case TARGET_SYS_ELAPSED: elapsed =3D get_clock() - clock_start; if (sizeof(target_ulong) =3D=3D 8) { @@ -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] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] +=3D env->thumb ? 2 : 4; } } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index a740c3e160..308610f6b4 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2373,7 +2373,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) "...handling as semihosting call 0x%x\n", env->regs[0]); #ifdef CONFIG_TCG - env->regs[0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); #else g_assert_not_reached(); #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e1aa4f2097..55105cb0cc 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1345,7 +1345,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) =20 if (cause =3D=3D RISCV_EXCP_SEMIHOST) { if (env->priv >=3D PRV_S) { - env->gpr[xA0] =3D do_common_semihosting(cs); + do_common_semihosting(cs); env->pc +=3D 4; return; } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326158485477.85346551425346; Sat, 30 Apr 2022 06:42:38 -0700 (PDT) Received: from localhost ([::1]:49692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMr-0005iN-Ae for importer@patchew.org; Sat, 30 Apr 2022 09:42:37 -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) 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) 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-Google-Smtp-Source: ABdhPJxilH77nG9UQQj+bTi7NFDKf4fIxHDQbESDGe4COX3DETvpbB2pUUo0Y+Xq86Q9lKfsw648JA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326159525100001 Content-Type: text/plain; charset="utf-8" The err parameter is non-zero if and only if an error occured. Use this instead of ret =3D=3D -1 for determining if we need to update the saved errno. This fixes the errno setting of SYS_ISTTY, which returns 0 on error, not -1. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 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; =20 static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { - if (ret =3D=3D (target_ulong)-1) { + if (err) { #ifdef CONFIG_USER_ONLY TaskState *ts =3D cs->opaque; ts->swi_errno =3D err; --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651325825882102.55142346778075; Sat, 30 Apr 2022 06:37:05 -0700 (PDT) Received: from localhost ([::1]:60828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknHU-0002Tb-U2 for importer@patchew.org; Sat, 30 Apr 2022 09:37:04 -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) 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) 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-Google-Smtp-Source: ABdhPJy1RCTzgNRQrNC5mId7aQS0cbrYo4m+Ae1F01ULvJpE02JTlisQJvA9deajL9AYlM1HV8Fjvw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325827803100001 Content-Type: text/plain; charset="utf-8" This header is not private to the top-level semihosting directory, so place it in the public include directory. Signed-off-by: Richard Henderson --- {semihosting =3D> include/semihosting}/common-semi.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {semihosting =3D> include/semihosting}/common-semi.h (100%) diff --git a/semihosting/common-semi.h b/include/semihosting/common-semi.h similarity index 100% rename from semihosting/common-semi.h rename to include/semihosting/common-semi.h --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165132567955525.572306720036522; Sat, 30 Apr 2022 06:34:39 -0700 (PDT) Received: from localhost ([::1]:52416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknF8-0005Dz-GU for importer@patchew.org; Sat, 30 Apr 2022 09:34:38 -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) 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) 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-Google-Smtp-Source: ABdhPJwnCdm81vpwZ53kPx3WzpaXxY87f+NWWvoSsmweXNFAJvvUJ3XKW17duuZHQmyaQAynCUWzTg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325681221100003 Content-Type: text/plain; charset="utf-8" There were 3 copies of these flags. Place them in the file with gdb_do_syscall, with which they belong. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 10 ++++++++++ semihosting/arm-compat-semi.c | 8 -------- target/m68k/m68k-semi.c | 8 -------- target/nios2/nios2-semi.c | 8 -------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c35d7334b4..2aaba9c723 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,16 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 =20 +/* For gdb file i/o remote protocol open flags. */ +#define GDB_O_BINARY 0 +#define GDB_O_RDONLY 0 +#define GDB_O_WRONLY 1 +#define GDB_O_RDWR 2 +#define GDB_O_APPEND 8 +#define GDB_O_CREAT 0x200 +#define GDB_O_TRUNC 0x400 +#define GDB_O_EXCL 0x800 + #ifdef NEED_CPU_H #include "cpu.h" =20 diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 18664b1c47..a1fc4ea039 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -86,14 +86,6 @@ #define O_BINARY 0 #endif =20 -#define GDB_O_RDONLY 0x000 -#define GDB_O_WRONLY 0x001 -#define GDB_O_RDWR 0x002 -#define GDB_O_APPEND 0x008 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_BINARY 0 - static int gdb_open_modeflags[12] =3D { GDB_O_RDONLY, GDB_O_RDONLY | GDB_O_BINARY, diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index a31db38fc3..475a6b13b7 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -69,14 +69,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; =20 -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 373e6b9436..0eec1f9a1c 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -71,14 +71,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; =20 -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326157566331.7541528610036; Sat, 30 Apr 2022 06:42:37 -0700 (PDT) Received: from localhost ([::1]:49560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMq-0005dI-Gu for importer@patchew.org; Sat, 30 Apr 2022 09:42:36 -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) 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) 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-Google-Smtp-Source: ABdhPJw8XrTz0WYu6KN2ji+J/+Bvx6MxE39IM5LqfFKN17RAXjbXX+w3cO9KTGIjtr6LZH+hOHNbtA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326159546100002 Content-Type: text/plain; charset="utf-8" We have two copies of these structures, and require them in semihosting/ going forward. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 25 +++++++++++++++++++++++++ target/m68k/m68k-semi.c | 30 +++--------------------------- target/nios2/nios2-semi.c | 30 +++--------------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 2aaba9c723..33a262a5a3 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,31 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 =20 +/* For gdb file i/o stat/fstat. */ +typedef uint32_t gdb_mode_t; +typedef uint32_t gdb_time_t; + +struct gdb_stat { + uint32_t gdb_st_dev; /* device */ + uint32_t gdb_st_ino; /* inode */ + gdb_mode_t gdb_st_mode; /* protection */ + uint32_t gdb_st_nlink; /* number of hard links */ + uint32_t gdb_st_uid; /* user ID of owner */ + uint32_t gdb_st_gid; /* group ID of owner */ + uint32_t gdb_st_rdev; /* device type (if inode device) */ + uint64_t gdb_st_size; /* total size, in bytes */ + uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ + uint64_t gdb_st_blocks; /* number of blocks allocated */ + gdb_time_t gdb_st_atime; /* time of last access */ + gdb_time_t gdb_st_mtime; /* time of last modification */ + gdb_time_t gdb_st_ctime; /* time of last change */ +} QEMU_PACKED; + +struct gdb_timeval { + gdb_time_t tv_sec; /* second */ + uint64_t tv_usec; /* microsecond */ +} QEMU_PACKED; + #ifdef NEED_CPU_H #include "cpu.h" =20 diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 475a6b13b7..da0186f3ef 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -45,30 +45,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 =20 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct m68k_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -90,9 +66,9 @@ static int translate_openflags(int flags) =20 static void translate_stat(CPUM68KState *env, target_ulong addr, struct st= at *s) { - struct m68k_gdb_stat *p; + struct gdb_stat *p; =20 - if (!(p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat)= , 0))) + if (!(p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) /* FIXME - should this return an error code? */ return; p->gdb_st_dev =3D cpu_to_be32(s->st_dev); @@ -114,7 +90,7 @@ static void translate_stat(CPUM68KState *env, target_ulo= ng addr, struct stat *s) p->gdb_st_atime =3D cpu_to_be32(s->st_atime); p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); } =20 static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t= err) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 0eec1f9a1c..3e504a6c5f 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -47,30 +47,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 =20 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct nios2_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -102,9 +78,9 @@ static int translate_openflags(int flags) static bool translate_stat(CPUNios2State *env, target_ulong addr, struct stat *s) { - struct nios2_gdb_stat *p; + struct gdb_stat *p; =20 - p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0); + p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); =20 if (!p) { return false; @@ -128,7 +104,7 @@ static bool translate_stat(CPUNios2State *env, target_u= long addr, p->gdb_st_atime =3D cpu_to_be32(s->st_atime); p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct nios2_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); return true; } =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326329534676.9589348732139; Sat, 30 Apr 2022 06:45:29 -0700 (PDT) Received: from localhost ([::1]:57972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknPc-0002tR-GA for importer@patchew.org; Sat, 30 Apr 2022 09:45:28 -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) 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) 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-Google-Smtp-Source: ABdhPJzlFgsGUEeZBHLAH5926m6SxRh0jgyKma9GG3oyTNwcthqvkmXPeZD7gDvSYD+gVDlTJwn+MQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326330019100001 Content-Type: text/plain; charset="utf-8" Use offsetof instead of an integer constant. Load the entire 64-bit size while we're at it. Signed-off-by: Richard Henderson --- 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 =3D 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 =3D be64_to_cpu(size); common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165132597364647.70943014512363; Sat, 30 Apr 2022 06:39:33 -0700 (PDT) Received: from localhost ([::1]:40424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknJs-0007sO-65 for importer@patchew.org; Sat, 30 Apr 2022 09:39:32 -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) 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) 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-Google-Smtp-Source: ABdhPJzE+p3pQ02Mqlc+zvjJxQaeTAtJVgThqGguHS4aiuhX2vFtvW0DYMmXBuxJW0VlVATQfSZo3g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325974554100001 Content-Type: text/plain; charset="utf-8" We already have some larger ifdef blocks for ARM and RISCV; split the function into multiple implementations per arch. 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 =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); } =20 +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} #endif /* TARGET_ARM */ =20 #ifdef TARGET_RISCV @@ -238,6 +242,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); } =20 +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) !=3D MXL_RV32; +} #endif =20 /* @@ -586,17 +594,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { * call if the memory read fails. Eventually we could use a generic * CPUState helper function here. */ -static inline bool is_64bit_semihosting(CPUArchState *env) -{ -#if defined(TARGET_ARM) - return is_a64(env); -#elif defined(TARGET_RISCV) - return riscv_cpu_mxl(env) !=3D MXL_RV32; -#else -#error un-handled architecture -#endif -} - =20 #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326150267702.86165524818; Sat, 30 Apr 2022 06:42:30 -0700 (PDT) Received: from localhost ([::1]:48948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMj-0005E0-5h for importer@patchew.org; Sat, 30 Apr 2022 09:42:29 -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) 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) 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-Google-Smtp-Source: ABdhPJy2J3d0oMz14U+GLF6MGbejsMVwTw7iqY42jv6rQnZcQpRV7fkUuKuncKP3sBQxu3WBg45rOw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326151565100001 Content-Type: text/plain; charset="utf-8" We already have some larger ifdef blocks for ARM and RISCV; split out common_semi_stack_bottom per target. 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 =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} #endif /* TARGET_ARM */ =20 #ifdef TARGET_RISCV @@ -246,6 +253,13 @@ static inline bool is_64bit_semihosting(CPUArchState *= env) { return riscv_cpu_mxl(env) !=3D MXL_RV32; } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xSP]; +} #endif =20 /* @@ -301,31 +315,15 @@ static void common_semi_cb(CPUState *cs, target_ulong= ret, target_ulong err) common_semi_set_ret(cs, ret); } =20 +/* + * Return an address in target memory of 64 bytes where the remote + * gdb should write its stat struct. (The format of this structure + * is defined by GDB's remote protocol and is not target-specific.) + * We put this on the guest's stack just below SP. + */ static target_ulong common_semi_flen_buf(CPUState *cs) { - target_ulong sp; -#ifdef TARGET_ARM - /* Return an address in target memory of 64 bytes where the remote - * gdb should write its stat struct. (The format of this structure - * is defined by GDB's remote protocol and is not target-specific.) - * We put this on the guest's stack just below SP. - */ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - - if (is_a64(env)) { - sp =3D env->xregs[31]; - } else { - sp =3D env->regs[13]; - } -#endif -#ifdef TARGET_RISCV - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - - sp =3D env->gpr[xSP]; -#endif - + target_ulong sp =3D common_semi_stack_bottom(cs); return sp - 64; } =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165132598251821.79115685685747; Sat, 30 Apr 2022 06:39:42 -0700 (PDT) Received: from localhost ([::1]:41046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknK0-0008Hq-Hb for importer@patchew.org; Sat, 30 Apr 2022 09:39:41 -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) 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) 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-Google-Smtp-Source: ABdhPJwC6i2+NALuyega/I0il81TbQHrRxKhdQNilWkJsNu2RNv1TzbXKPAyJYFMIIM/8a3RiJKE9Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325984707100001 Content-Type: text/plain; charset="utf-8" We already have some larger ifdef blocks for ARM and RISCV; split out a boolean test for SYS_SYNCCACHE. 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(CP= UState *cs) CPUARMState *env =3D &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32. */ + return !is_a64(env); +} #endif /* TARGET_ARM */ =20 #ifdef TARGET_RISCV @@ -260,6 +266,11 @@ static inline target_ulong common_semi_stack_bottom(CP= UState *cs) CPURISCVState *env =3D &cpu->env; return env->gpr[xSP]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} #endif =20 /* @@ -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); --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165132582881730.703593331173693; Sat, 30 Apr 2022 06:37:08 -0700 (PDT) Received: from localhost ([::1]:60938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknHX-0002Xk-AA for importer@patchew.org; Sat, 30 Apr 2022 09:37:07 -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) 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) 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-Google-Smtp-Source: ABdhPJypec9mcCVRHWusTVl9DrEJci7zANFjvZws9M1Gb9I96BNqjsb0RjvvNtMJ4WPX6vgTgaw6cA== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325829900100001 We've already loaded cs->env_ptr into a local variable; use it. Since env is unconditionally used, we don't need a dummy use. Signed-off-by: Richard Henderson --- target/arm/common-semi-target.h | 62 ++++++++++++++++++ target/riscv/common-semi-target.h | 50 +++++++++++++++ semihosting/arm-compat-semi.c | 101 ++---------------------------- 3 files changed, 116 insertions(+), 97 deletions(-) create mode 100644 target/arm/common-semi-target.h create mode 100644 target/riscv/common-semi-target.h diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-targe= t.h new file mode 100644 index 0000000000..c20e1cca76 --- /dev/null +++ b/target/arm/common-semi-target.h @@ -0,0 +1,62 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H +#define TARGET_ARM_COMMON_SEMI_TARGET_H + +#ifndef CONFIG_USER_ONLY +#include "hw/arm/boot.h" +#endif + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + if (is_a64(env)) { + return env->xregs[argno]; + } else { + return env->regs[argno]; + } +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + if (is_a64(env)) { + env->xregs[0] =3D ret; + } else { + env->regs[0] =3D ret; + } +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Invalid for A32/T32 */ + return !is_a64(env); +} + +#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-t= arget.h new file mode 100644 index 0000000000..7c8a59e0cc --- /dev/null +++ b/target/riscv/common-semi-target.h @@ -0,0 +1,50 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * Copyright =C2=A9 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H +#define TARGET_RISCV_COMMON_SEMI_TARGET_H + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + env->gpr[xA0] =3D ret; +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) !=3D MXL_RV32; +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu =3D RISCV_CPU(cs); + CPURISCVState *env =3D &cpu->env; + return env->gpr[xSP]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} + +#endif diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 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 =20 @@ -182,96 +179,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) =20 #endif =20 -#ifdef TARGET_ARM -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - if (is_a64(env)) { - return env->xregs[argno]; - } else { - return env->regs[argno]; - } -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - if (is_a64(env)) { - env->xregs[0] =3D ret; - } else { - env->regs[0] =3D ret; - } -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return is_a64(env); -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - ARMCPU *cpu =3D ARM_CPU(cs); - CPUARMState *env =3D &cpu->env; - return is_a64(env) ? env->xregs[31] : env->regs[13]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - /* Invalid for A32/T32. */ - return !is_a64(env); -} -#endif /* TARGET_ARM */ - -#ifdef TARGET_RISCV -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - return env->gpr[xA0 + argno]; -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - env->gpr[xA0] =3D ret; -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) =3D= =3D 8); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return riscv_cpu_mxl(env) !=3D MXL_RV32; -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - RISCVCPU *cpu =3D RISCV_CPU(cs); - CPURISCVState *env =3D &cpu->env; - return env->gpr[xSP]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - return true; -} -#endif +#include "common-semi-target.h" =20 /* * The semihosting API has no concept of its errno being thread-safe, @@ -646,7 +554,6 @@ void do_common_semihosting(CPUState *cs) GuestFD *gf; int64_t elapsed; =20 - (void) env; /* Used implicitly by arm lock_user macro */ nr =3D common_semi_arg(cs, 0) & 0xffffffffU; args =3D common_semi_arg(cs, 1); =20 @@ -729,12 +636,12 @@ void do_common_semihosting(CPUState *cs) break; =20 case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(cs->env_ptr, args); + qemu_semihosting_console_outc(env, args); common_semi_set_ret(cs, 0xdeadbeef); break; =20 case TARGET_SYS_WRITE0: - ret =3D qemu_semihosting_console_outs(cs->env_ptr, args); + ret =3D qemu_semihosting_console_outs(env, args); common_semi_set_ret(cs, ret); break; =20 @@ -765,7 +672,7 @@ void do_common_semihosting(CPUState *cs) break; =20 case TARGET_SYS_READC: - ret =3D qemu_semihosting_console_inc(cs->env_ptr); + ret =3D qemu_semihosting_console_inc(env); common_semi_set_ret(cs, ret); break; =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326580473264.2756236455259; Sat, 30 Apr 2022 06:49:40 -0700 (PDT) Received: from localhost ([::1]:38052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknTf-0000Y8-CI for importer@patchew.org; Sat, 30 Apr 2022 09:49:39 -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) 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) 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-Google-Smtp-Source: ABdhPJzqz2fzvWvi9qo7lzi9pZNotkLWzCdVl3j8JF0Ml661kATp3kX+IpNujjEsq1tGyl59LIdTiA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326581180100001 Content-Type: text/plain; charset="utf-8" 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) =20 #include "common-semi-target.h" =20 +/* + * Read the input value from the argument block; fail the semihosting + * call if the memory read fails. Eventually we could use a generic + * CPUState helper function here. + */ + +#define GET_ARG(n) do { \ + if (is_64bit_semihosting(env)) { \ + if (get_user_u64(arg ## n, args + (n) * 8)) { \ + 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[] =3D { }, }; =20 -/* - * Read the input value from the argument block; fail the semihosting - * call if the memory read fails. Eventually we could use a generic - * CPUState helper function here. - */ - -#define GET_ARG(n) do { \ - if (is_64bit_semihosting(env)) { \ - if (get_user_u64(arg ## n, args + (n) * 8)) { \ - 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. * --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326320591167.5913984164332; Sat, 30 Apr 2022 06:45:20 -0700 (PDT) Received: from localhost ([::1]:57322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknPS-0002Sg-Mb for importer@patchew.org; Sat, 30 Apr 2022 09:45:18 -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) 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) 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-Google-Smtp-Source: ABdhPJwmE+tlCv9VsKbvslxn+cB/ZPDOTD7cS1KyvtYDZEDsO9NKoDHNchfDrKDbmFQP1oq0Ybhd0Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326322138100001 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_OPEN to a reusable function. This handles gdb and host file i/o. Add helpers to validate the length of the filename string. Prepare for usage by other semihosting by allowing the filename length parameter to be 0, and calling strlen. Signed-off-by: Richard Henderson --- include/semihosting/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); =20 +/* + * 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" =20 #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -98,21 +98,6 @@ static int gdb_open_modeflags[12] =3D { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY }; =20 -static int open_modeflags[12] =3D { - O_RDONLY, - O_RDONLY | O_BINARY, - O_RDWR, - O_RDWR | O_BINARY, - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, - O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, - O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY -}; - #ifndef CONFIG_USER_ONLY =20 /** @@ -285,20 +270,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, ta= rget_ulong err) common_semi_set_ret(cs, size); } =20 -static int common_semi_open_guestfd; - -static void -common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) -{ - if (ret =3D=3D (target_ulong)-1) { - dealloc_guestfd(common_semi_open_guestfd); - } else { - associate_guestfd(common_semi_open_guestfd, ret); - ret =3D common_semi_open_guestfd; - } - common_semi_cb(cs, ret, err); -} - /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all @@ -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 =3D alloc_guestfd(); - gdb_do_syscall(common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - break; } else { - hostfd =3D open(s, open_modeflags[arg1], 0644); - if (hostfd < 0) { - ret =3D -1; - err =3D errno; - } else { - ret =3D alloc_guestfd(); - associate_guestfd(ret, hostfd); - } + semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, + gdb_open_modeflags[arg1], 0644); + break; } unlock_user(s, arg0, 0); common_semi_cb(cs, ret, err); diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index b6405f5663..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 =20 static GArray *guestfd_array; =20 @@ -116,3 +121,133 @@ void dealloc_guestfd(int guestfd) assert(gf); gf->type =3D GuestFDUnused; } + +/* + * Validate or compute the length of the string (including terminator). + */ +static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tl= en) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char c; + + if (tlen =3D=3D 0) { + ssize_t slen =3D target_strlen(str); + + if (slen < 0) { + return -EFAULT; + } + if (slen >=3D 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 !=3D 0) { + return -EINVAL; + } + return tlen; +} + +static int validate_lock_user_string(char **pstr, CPUState *cs, + target_ulong tstr, target_ulong tlen) +{ + int ret =3D validate_strlen(cs, tstr, tlen); + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *str =3D NULL; + + if (ret > 0) { + str =3D lock_user(VERIFY_READ, tstr, ret, true); + ret =3D str ? 0 : -EFAULT; + } + *pstr =3D 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 =3D alloc_guestfd(); + associate_guestfd(guestfd, ret); + ret =3D guestfd; + } + gdb_open_complete(cs, ret, err); +} + +static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + int len =3D validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_open_complete =3D complete; + gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x", + fname, len, (target_ulong)gdb_flags, (target_ulong)mode= ); +} + +static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *p; + int ret, host_flags; + + ret =3D validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + if (gdb_flags & GDB_O_WRONLY) { + host_flags =3D O_WRONLY; + } else if (gdb_flags & GDB_O_RDWR) { + host_flags =3D O_RDWR; + } else { + host_flags =3D O_RDONLY; + } + if (gdb_flags & GDB_O_CREAT) { + host_flags |=3D O_CREAT; + } + if (gdb_flags & GDB_O_TRUNC) { + host_flags |=3D O_TRUNC; + } + if (gdb_flags & GDB_O_EXCL) { + host_flags |=3D O_EXCL; + } + + ret =3D open(p, host_flags, mode); + if (ret < 0) { + complete(cs, -1, errno); + } else { + int guestfd =3D 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); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326583057432.52943323265254; Sat, 30 Apr 2022 06:49:43 -0700 (PDT) Received: from localhost ([::1]:38416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknTi-0000qu-13 for importer@patchew.org; Sat, 30 Apr 2022 09:49:42 -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) 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) 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-Google-Smtp-Source: ABdhPJytl30wMyhuIOUNRTqBj8yOaVy9BYWaaeTPFpsdSY+iBv0Kj4fyjr++HePDa3dxFELAJz8BGA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326585138100007 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_CLOSE to a reusable function. This handles all GuestFD. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/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); =20 +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, in= t 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, tar= get_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_closefn(CPUState *cs, GuestFD *gf); typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); typedef void sys_readfn(CPUState *cs, GuestFD *gf, @@ -285,23 +284,6 @@ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); =20 -static void host_closefn(CPUState *cs, GuestFD *gf) -{ - int ret; - /* - * Only close the underlying host fd if it's one we opened on behalf - * of the guest in SYS_OPEN. - */ - if (gf->hostfd =3D=3D STDIN_FILENO || - gf->hostfd =3D=3D STDOUT_FILENO || - gf->hostfd =3D=3D STDERR_FILENO) { - ret =3D 0; - } else { - ret =3D close(gf->hostfd); - } - common_semi_cb(cs, ret, ret ? errno : 0); -} - static void host_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -362,11 +344,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } =20 -static void gdb_closefn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); -} - static void gdb_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -414,12 +391,6 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void staticfile_closefn(CPUState *cs, GuestFD *gf) -{ - /* Nothing to do */ - common_semi_cb(cs, 0, 0); -} - static void staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -468,7 +439,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } =20 typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -478,7 +448,6 @@ typedef struct GuestFDFunctions { =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .closefn =3D host_closefn, .writefn =3D host_writefn, .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, @@ -486,7 +455,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .closefn =3D gdb_closefn, .writefn =3D gdb_writefn, .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, @@ -494,7 +462,6 @@ static const GuestFDFunctions guestfd_fns[] =3D { .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .closefn =3D staticfile_closefn, .writefn =3D staticfile_writefn, .readfn =3D staticfile_readfn, .isattyfn =3D staticfile_isattyfn, @@ -585,13 +552,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_CLOSE: GET_ARG(0); - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].closefn(cs, gf); - dealloc_guestfd(arg0); + semihost_sys_close(cs, common_semi_cb, arg0); break; =20 case TARGET_SYS_WRITEC: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 1393279333..c26b1c677e 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -49,6 +49,11 @@ int alloc_guestfd(void) return i; } =20 +static void do_dealloc_guestfd(GuestFD *gf) +{ + gf->type =3D GuestFDUnused; +} + /* * Look up the guestfd in the data structure; return NULL * for out of bounds, but don't check whether the slot is unused. @@ -119,7 +124,7 @@ void dealloc_guestfd(int guestfd) GuestFD *gf =3D do_get_guestfd(guestfd); =20 assert(gf); - gf->type =3D GuestFDUnused; + do_dealloc_guestfd(gf); } =20 /* @@ -251,3 +256,50 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_compl= ete_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 !=3D STDIN_FILENO && + gf->hostfd !=3D STDOUT_FILENO && + gf->hostfd !=3D 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, in= t fd) +{ + GuestFD *gf =3D 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); +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16513259946571005.2850685246938; Sat, 30 Apr 2022 06:39:54 -0700 (PDT) Received: from localhost ([::1]:41374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknKC-0008VE-9C for importer@patchew.org; Sat, 30 Apr 2022 09:39:52 -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) 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) 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-Google-Smtp-Source: ABdhPJxPKAwCqJ2w3crz7P/4s43N+gST9atswpwrY/G1O5RuT7S/ADDAkhXmNgJnE8iempQOHt5c2Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651325996649100003 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_READ to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_rw_cb. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/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, =20 void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, in= t fd); =20 +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 r= et, target_ulong err) target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: - case TARGET_SYS_READ: ret =3D common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: @@ -245,6 +244,24 @@ static void common_semi_cb(CPUState *cs, target_ulong = ret, target_ulong err) common_semi_set_ret(cs, ret); } =20 +/* + * SYS_READ and SYS_WRITE always return the number of bytes not read/writt= en. + * There is no error condition, other than returning the original length. + */ +static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong= err) +{ + /* Recover the original length from the third argument. */ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + target_ulong args =3D common_semi_arg(cs, 1); + target_ulong arg2; + GET_ARG(2); + + if (err) { + ret =3D 0; /* error: no bytes transmitted */ + } + common_semi_set_ret(cs, arg2 - ret); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -278,8 +295,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, tar= get_ulong err) */ typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef void sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); @@ -302,26 +317,6 @@ static void host_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, len - ret, 0); } =20 -static void host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t ret =3D 0; - char *s =3D lock_user(VERIFY_WRITE, buf, len, 0); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - do { - ret =3D read(gf->hostfd, s, len); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); - unlock_user(s, buf, len); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - } - /* Return bytes not read, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -351,13 +346,6 @@ static void gdb_writefn(CPUState *cs, GuestFD *gf, gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } =20 -static void gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len =3D len; - gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -398,30 +386,6 @@ static void staticfile_writefn(CPUState *cs, GuestFD *= gf, common_semi_cb(cs, -1, EBADF); } =20 -static void staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t i =3D 0; - char *s; - - (void) env; /* Used in arm softmmu lock_user implicitly */ - s =3D lock_user(VERIFY_WRITE, buf, len, 0); - if (s) { - for (i =3D 0; i < len; i++) { - if (gf->staticfile.off >=3D gf->staticfile.len) { - break; - } - s[i] =3D gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; - } - unlock_user(s, buf, len); - } - - /* Return number of bytes not read */ - common_semi_cb(cs, len - i, 0); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -440,7 +404,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) =20 typedef struct GuestFDFunctions { sys_writefn *writefn; - sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -449,21 +412,18 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { .writefn =3D host_writefn, - .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { .writefn =3D gdb_writefn, - .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { .writefn =3D staticfile_writefn, - .readfn =3D staticfile_readfn, .isattyfn =3D staticfile_isattyfn, .seekfn =3D staticfile_seekfn, .flenfn =3D staticfile_flenfn, @@ -582,13 +542,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len =3D arg2; - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2); break; =20 case TARGET_SYS_READC: diff --git a/semihosting/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_comp= lete_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 =3D cs->env_ptr; + void *ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + do { + ret =3D read(gf->hostfd, ptr, len); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + if (ret =3D=3D -1) { + complete(cs, -1, errno); + 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 le= n) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + target_ulong rest =3D gf->staticfile.len - gf->staticfile.off; + void *ptr; + + if (len > rest) { + len =3D rest; + } + ptr =3D lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + memcpy(ptr, gf->staticfile.data + gf->staticfile.off, len); + gf->staticfile.off +=3D len; + complete(cs, len, 0); + unlock_user(ptr, buf, len); +} + +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf =3D get_guestfd(fd); + + if (!gf) { + 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(); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326569970439.36816033750813; Sat, 30 Apr 2022 06:49:29 -0700 (PDT) Received: from localhost ([::1]:37408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknTU-0008NS-W6 for importer@patchew.org; Sat, 30 Apr 2022 09:49:29 -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) 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) 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-Google-Smtp-Source: ABdhPJzcGaQa2Ej+5oNulaOI5aLk1SILHN21NOksgO1wDaV91etVi5wtWl/dZhes2eLEt4imWV5uFw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326571078100001 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_WRITE to a reusable function. This handles all GuestFD. This removes the last use of common_semi_syscall_len. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/semihosting/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_complet= e_cb complete, int fd); void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, int fd, target_ulong buf, target_ulong len); =20 +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + #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 } =20 -static target_ulong common_semi_syscall_len; - static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) { if (err) { @@ -231,9 +229,6 @@ static void common_semi_cb(CPUState *cs, target_ulong r= et, target_ulong err) /* Fixup syscalls that use nonstardard return conventions. */ target_ulong reg0 =3D common_semi_arg(cs, 0); switch (reg0) { - case TARGET_SYS_WRITE: - ret =3D common_semi_syscall_len - ret; - break; case TARGET_SYS_SEEK: ret =3D 0; break; @@ -293,30 +288,10 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, t= arget_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); =20 -static void host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env =3D cs->env_ptr; - uint32_t ret =3D 0; - char *s =3D lock_user(VERIFY_READ, buf, len, 1); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - ret =3D write(gf->hostfd, s, len); - unlock_user(s, buf, 0); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - } - /* Return bytes not written, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -339,13 +314,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } =20 -static void gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len =3D len; - gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -379,13 +347,6 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - /* This fd can never be open for writing */ - common_semi_cb(cs, -1, EBADF); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -403,7 +364,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } =20 typedef struct GuestFDFunctions { - sys_writefn *writefn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -411,19 +371,16 @@ typedef struct GuestFDFunctions { =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .writefn =3D host_writefn, .isattyfn =3D host_isattyfn, .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .writefn =3D gdb_writefn, .isattyfn =3D gdb_isattyfn, .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .writefn =3D staticfile_writefn, .isattyfn =3D staticfile_isattyfn, .seekfn =3D staticfile_seekfn, .flenfn =3D staticfile_flenfn, @@ -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; =20 @@ -529,13 +485,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len =3D arg2; - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2); break; =20 case TARGET_SYS_READ: diff --git a/semihosting/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_compl= ete_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 =3D cs->env_ptr; + void *ptr =3D lock_user(VERIFY_READ, buf, len, 1); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret =3D write(gf->hostfd, ptr, len); + complete(cs, ret, ret =3D=3D -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 =3D 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(); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326160454964.7883167538076; Sat, 30 Apr 2022 06:42:40 -0700 (PDT) Received: from localhost ([::1]:49944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknMt-0005sr-Dk for importer@patchew.org; Sat, 30 Apr 2022 09:42:39 -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) 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) 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-Google-Smtp-Source: ABdhPJyzCHtimAujhiJ0FOelo92m3wkVNzU0n5JrFpzRlaYADZvsV2Iit6+JcyIwIar5OW5XUXRw5g== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326161284100005 Content-Type: text/plain; charset="utf-8" Fixes a minor bug in which a 64-bit guest on a 32-bit host could truncate the length. This would only ever cause a problem if there were no bits set in the low 32, so that it truncates to 0. Signed-off-by: Richard Henderson --- semihosting/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_compl= ete_cb complete, complete(cs, -1, EBADF); return; } + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssiz= e_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len =3D INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_read(cs, complete, gf, buf, len); @@ -410,6 +418,14 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_comp= lete_cb complete, if (!gf) { goto ebadf; } + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssiz= e_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len =3D INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_write(cs, complete, gf, buf, len); --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326813588515.4006436067607; Sat, 30 Apr 2022 06:53:33 -0700 (PDT) Received: from localhost ([::1]:46784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknXQ-0006uh-CJ for importer@patchew.org; Sat, 30 Apr 2022 09:53:32 -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) 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) 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-Google-Smtp-Source: ABdhPJwI6nqLJqsuL4uA+s+x2Sii3goSwz1bK7Bv5nEGHsoVGp30cgMGHZPZXqpcjFyaRYvzb//Zsg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326814560100001 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_SEEK to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_seek_cb. Expand the internal type of the offset to int64_t, and provide the whence argument, which will be required by m68k and nios2 semihosting. Note that gdb_do_syscall %x reads target_ulong, not int. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 5 +++ include/semihosting/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 =20 +/* For gdb file i/o remote protocol lseek whence. */ +#define GDB_SEEK_SET 0 +#define GDB_SEEK_CUR 1 +#define GDB_SEEK_END 2 + /* For gdb file i/o stat/fstat. */ typedef uint32_t gdb_mode_t; typedef uint32_t gdb_time_t; diff --git a/include/semihosting/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); =20 +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 =3D err; #endif - } else { - /* Fixup syscalls that use nonstardard return conventions. */ - target_ulong reg0 =3D common_semi_arg(cs, 0); - switch (reg0) { - case TARGET_SYS_SEEK: - ret =3D 0; - break; - default: - break; - } } common_semi_set_ret(cs, ret); } @@ -257,6 +247,18 @@ static void common_semi_rw_cb(CPUState *cs, target_ulo= ng ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } =20 +/* + * SYS_SEEK returns 0 on success, not the resulting offset. + */ +static void common_semi_seek_cb(CPUState *cs, target_ulong ret, + target_ulong err) +{ + if (!err) { + ret =3D 0; + } + common_semi_cb(cs, ret, err); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -289,7 +291,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, tar= get_ulong err) * via common_semi_cb. */ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); =20 static void host_isattyfn(CPUState *cs, GuestFD *gf) @@ -297,12 +298,6 @@ static void host_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, isatty(gf->hostfd), 0); } =20 -static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - off_t ret =3D lseek(gf->hostfd, offset, SEEK_SET); - common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -319,11 +314,6 @@ static void gdb_isattyfn(CPUState *cs, GuestFD *gf) gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } =20 -static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -352,12 +342,6 @@ static void staticfile_isattyfn(CPUState *cs, GuestFD = *gf) common_semi_cb(cs, 0, 0); } =20 -static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offs= et) -{ - gf->staticfile.off =3D offset; - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); @@ -365,24 +349,20 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *= gf) =20 typedef struct GuestFDFunctions { sys_isattyfn *isattyfn; - sys_seekfn *seekfn; sys_flenfn *flenfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { .isattyfn =3D host_isattyfn, - .seekfn =3D host_seekfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { .isattyfn =3D gdb_isattyfn, - .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { .isattyfn =3D staticfile_isattyfn, - .seekfn =3D staticfile_seekfn, .flenfn =3D staticfile_flenfn, }, }; @@ -518,12 +498,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].seekfn(cs, gf, arg1); + semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_S= ET); break; =20 case TARGET_SYS_FLEN: diff --git a/semihosting/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_comp= lete_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 !=3D SEEK_SET); + QEMU_BUILD_BUG_ON(GDB_SEEK_CUR !=3D SEEK_CUR); + QEMU_BUILD_BUG_ON(GDB_SEEK_END !=3D SEEK_END); + + off_t ret =3D off; + int err =3D 0; + + if (ret =3D=3D off) { + ret =3D lseek(gf->hostfd, ret, whence); + if (ret =3D=3D -1) { + err =3D errno; + } + } else { + ret =3D -1; + err =3D EOVERFLOW; + } + complete(cs, ret, err); +} + +static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complet= e, + GuestFD *gf, int64_t off, int gdb_whence) +{ + int64_t ret; + + switch (gdb_whence) { + case GDB_SEEK_SET: + ret =3D off; + break; + case GDB_SEEK_CUR: + ret =3D gf->staticfile.off + off; + break; + case GDB_SEEK_END: + ret =3D gf->staticfile.len - off; + break; + default: + ret =3D -1; + break; + } + if (ret >=3D 0 && ret <=3D gf->staticfile.len) { + gf->staticfile.off =3D ret; + complete(cs, ret, 0); + } else { + complete(cs, -1, EINVAL); + } +} + +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence) +{ + GuestFD *gf =3D get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_lseek(cs, complete, gf, off, gdb_whence); + return; + case GuestFDHost: + host_lseek(cs, complete, gf, off, gdb_whence); + break; + case GuestFDStatic: + staticfile_lseek(cs, complete, gf, off, gdb_whence); + break; + default: + g_assert_not_reached(); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326356143497.0726898463711; Sat, 30 Apr 2022 06:45:56 -0700 (PDT) Received: from localhost ([::1]:58284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknPz-00035f-IO for importer@patchew.org; Sat, 30 Apr 2022 09:45:53 -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) 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) 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-Google-Smtp-Source: ABdhPJwU+v/8+Iawq/IHBBni15tpkSj/pV3j/KOuvN2n7RAdwAiEsZYUWfhSVQqF7N6ylAS9+nXmMw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326358461100001 Content-Type: text/plain; charset="utf-8" Split out the non-ARM specific portions of SYS_ISTTY to a reusable function. This handles all GuestFD. Signed-off-by: Richard Henderson --- include/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_complet= e_cb complete, void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); =20 +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_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, ta= rget_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); =20 -static void host_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, isatty(gf->hostfd), 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -309,11 +303,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } =20 -static void gdb_isattyfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -337,32 +326,23 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); } =20 typedef struct GuestFDFunctions { - sys_isattyfn *isattyfn; sys_flenfn *flenfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { - .isattyfn =3D host_isattyfn, .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { - .isattyfn =3D gdb_isattyfn, .flenfn =3D gdb_flenfn, }, [GuestFDStatic] =3D { - .isattyfn =3D staticfile_isattyfn, .flenfn =3D staticfile_flenfn, }, }; @@ -487,12 +467,7 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_ISTTY: GET_ARG(0); - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].isattyfn(cs, gf); + semihost_sys_isatty(cs, common_semi_cb, arg0); break; =20 case TARGET_SYS_SEEK: diff --git a/semihosting/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_comp= lete_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, i= nt fd) +{ + GuestFD *gf =3D 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(); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16513268077531019.3052809896622; Sat, 30 Apr 2022 06:53:27 -0700 (PDT) Received: from localhost ([::1]:46402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknXK-0006fJ-Lr for importer@patchew.org; Sat, 30 Apr 2022 09:53:26 -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) 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) 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-Google-Smtp-Source: ABdhPJxVxrv6VZXQPp2x7CBpxXRRunAHlta1P/fIvh770Pi3pzmWfd/KAK+6YA1qhwyNaO/Ydc5Ykw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326808131100001 Content-Type: text/plain; charset="utf-8" The ARM-specific SYS_FLEN isn't really something that can be reused by other semihosting apis, but 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_complet= e_cb complete, void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd); =20 +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, + int fd, target_ulong fstat_addr); + #endif /* SEMIHOSTING_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) } =20 static void -common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) { - /* 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 =3D 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 valu= e. */ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + uint64_t size; + if (get_user_u64(size, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size))) { + ret =3D -1, err =3D EFAULT; + } else { + /* Undo the tswap from get_user_u64, then swap from BE. */ + size =3D be64_to_cpu(tswap64(size)); + ret =3D size; + if (ret !=3D size) { + ret =3D -1, err =3D 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); } =20 #define SHFB_MAGIC_0 0x53 @@ -326,27 +310,6 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static void staticfile_flenfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, gf->staticfile.len, 0); -} - -typedef struct GuestFDFunctions { - sys_flenfn *flenfn; -} GuestFDFunctions; - -static const GuestFDFunctions guestfd_fns[] =3D { - [GuestFDHost] =3D { - .flenfn =3D host_flenfn, - }, - [GuestFDGDB] =3D { - .flenfn =3D gdb_flenfn, - }, - [GuestFDStatic] =3D { - .flenfn =3D staticfile_flenfn, - }, -}; - /* * Do a semihosting call. * @@ -365,7 +328,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - GuestFD *gf; int64_t elapsed; =20 nr =3D common_semi_arg(cs, 0) & 0xffffffffU; @@ -478,12 +440,8 @@ void do_common_semihosting(CPUState *cs) =20 case TARGET_SYS_FLEN: GET_ARG(0); - - gf =3D get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].flenfn(cs, gf); + semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb, + arg0, common_semi_flen_buf(cs)); break; =20 case TARGET_SYS_TMPNAM: @@ -805,9 +763,6 @@ void do_common_semihosting(CPUState *cs) cpu_dump_state(cs, stderr, 0); abort(); =20 - do_badf: - common_semi_cb(cs, -1, EBADF); - break; do_fault: common_semi_cb(cs, -1, EFAULT); break; diff --git a/semihosting/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_com= plete_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 =3D buf.st_size; + if (ret !=3D 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 =3D 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(); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326842317761.966582989955; Sat, 30 Apr 2022 06:54:02 -0700 (PDT) Received: from localhost ([::1]:48652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknXt-00088g-A8 for importer@patchew.org; Sat, 30 Apr 2022 09:54:01 -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) 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) 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-Google-Smtp-Source: ABdhPJwFsawUcwN0TMlRLutC7MqvDwPiM87ku42mz/Jpg1ApW9qCK8Zux7XsQeKO2XBfLnRD2f8Ttg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326844286100001 Content-Type: text/plain; charset="utf-8" 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); =20 +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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret =3D remove(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); + semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); break; =20 case TARGET_SYS_RENAME: diff --git a/semihosting/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_compl= ete_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 =3D 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 =3D cs->env_ptr; + char *p; + int ret; + + ret =3D validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D remove(p); + complete(cs, ret, ret ? errno : 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); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326998015950.4928569806144; Sat, 30 Apr 2022 06:56:38 -0700 (PDT) Received: from localhost ([::1]:55510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknaO-0004Pn-JZ for importer@patchew.org; Sat, 30 Apr 2022 09:56:37 -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) 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) 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-Google-Smtp-Source: ABdhPJw9I6gEAuJNQ11Grmzbjaesk4mXjW03ZDn5ZTmupi3QkaEQXEzPt7VwJi1s2ySR862ymlkdPg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326999446100001 Content-Type: text/plain; charset="utf-8" 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); =20 +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len); + #endif /* SEMIHOSTING_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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 =3D lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret =3D rename(s, s2); - unlock_user(s2, arg2, 0); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); - } + semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3= + 1); break; =20 case TARGET_SYS_CLOCK: diff --git a/semihosting/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_com= plete_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 =3D validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen =3D validate_strlen(cs, nname, nname_len); + if (nlen < 0) { + complete(cs, -1, -nlen); + return; + } + + gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); +} + +static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret =3D validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret =3D validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret =3D rename(ostr, nstr); + complete(cs, ret, ret ? errno : 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); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327237270682.9796319697865; Sat, 30 Apr 2022 07:00:37 -0700 (PDT) Received: from localhost ([::1]:35814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkneF-0001yO-4w for importer@patchew.org; Sat, 30 Apr 2022 10:00:35 -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) 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) 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-Google-Smtp-Source: ABdhPJyTa9FSJ1VtjRbiSuemsRejFz4Gs9EAKqCcfuq48PyFLr4bEpdyFvP17Vehep4aSlZMV/ZK/w== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327238540100001 Content-Type: text/plain; charset="utf-8" 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_comple= te_cb complete, target_ulong oname, target_ulong oname_len, target_ulong nname, target_ulong nname_len); =20 +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len); + #endif /* SEMIHOSTING_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 =3D lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret =3D system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret =3D=3D -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; =20 case TARGET_SYS_ERRNO: diff --git a/semihosting/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_com= plete_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 =3D 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 =3D cs->env_ptr; + char *p; + int ret; + + ret =3D validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D system(p); + complete(cs, ret, ret =3D=3D -1 ? errno : 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); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326582302462.34177274479975; Sat, 30 Apr 2022 06:49:42 -0700 (PDT) Received: from localhost ([::1]:38304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknTh-0000mJ-4U for importer@patchew.org; Sat, 30 Apr 2022 09:49:41 -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) 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) 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-Google-Smtp-Source: ABdhPJz6ikL93NRqiCuAhYEbooq7dAHCoV+y5wre2Gz06JyQEZs1HoukDldOjGdkIgcO+oRmMaPJXg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326583086100003 Content-Type: text/plain; charset="utf-8" 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_compl= ete_cb complete, void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong cmd, target_ulong cmd_len); =20 +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr); + +void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr); + #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_co= mplete_cb complete, int fd) } } =20 +/* + * TODO: Note that gdb always stores the stat structure big-endian. + * So far, that's ok, as the only two targets using this are also + * big-endian. Until we do something with gdb, also produce the + * same big-endian result from the host. + */ +static int copy_stat_to_user(CPUState *cs, target_ulong addr, + const struct stat *s) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + struct gdb_stat *p; + + if (s->st_dev !=3D (uint32_t)s->st_dev || + s->st_ino !=3D (uint32_t)s->st_ino) { + return -EOVERFLOW; + } + + p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -EFAULT; + } + + p->gdb_st_dev =3D cpu_to_be32(s->st_dev); + p->gdb_st_ino =3D cpu_to_be32(s->st_ino); + p->gdb_st_mode =3D cpu_to_be32(s->st_mode); + p->gdb_st_nlink =3D cpu_to_be32(s->st_nlink); + p->gdb_st_uid =3D cpu_to_be32(s->st_uid); + p->gdb_st_gid =3D cpu_to_be32(s->st_gid); + p->gdb_st_rdev =3D cpu_to_be32(s->st_rdev); + p->gdb_st_size =3D cpu_to_be64(s->st_size); +#ifdef _WIN32 + /* Windows stat is missing some fields. */ + p->gdb_st_blksize =3D 0; + p->gdb_st_blocks =3D 0; +#else + p->gdb_st_blksize =3D cpu_to_be64(s->st_blksize); + p->gdb_st_blocks =3D cpu_to_be64(s->st_blocks); +#endif + p->gdb_st_atime =3D cpu_to_be32(s->st_atime); + p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); + p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); + + unlock_user(p, addr, sizeof(struct gdb_stat)); + return 0; +} + 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= ); } =20 +static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + struct stat buf; + int ret; + + ret =3D fstat(gf->hostfd, &buf); + if (ret) { + complete(cs, -1, errno); + return; + } + ret =3D 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 =3D 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_com= plete_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 =3D validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr); +} + +static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + struct stat buf; + char *name; + int ret, err; + + ret =3D validate_lock_user_string(&name, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret =3D stat(name, &buf); + if (ret) { + err =3D errno; + } else { + ret =3D copy_stat_to_user(cs, addr, &buf); + err =3D 0; + if (ret < 0) { + err =3D -ret; + ret =3D -1; + } + } + complete(cs, ret, err); + unlock_user(name, fname, 0); +} + +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); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327614722948.9630569464324; Sat, 30 Apr 2022 07:06:54 -0700 (PDT) Received: from localhost ([::1]:44252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknkL-0007zE-CF for importer@patchew.org; Sat, 30 Apr 2022 10:06:53 -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) 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) 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-Google-Smtp-Source: ABdhPJzoT4Jt8mcEdYHwzoRCWX/78nsT3ZuLq5gVmFxXajbQ8sMHkDtS5pwJyTw/8JqQoWGCd5SU0A== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327616714100001 Content-Type: text/plain; charset="utf-8" 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); =20 +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, + 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_compl= ete_cb complete, host_stat(cs, complete, fname, fname_len, addr); } } + +static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complet= e, + target_ulong tv_addr, target_ulong tz_addr) +{ + gdb_do_syscall(complete, "gettimeofday,%s,%x", tv_addr, tz_addr); +} + +static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb comple= te, + target_ulong tv_addr, target_ulong tz_addr) +{ + CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; + struct gdb_timeval *p; + int64_t rt; + + /* GDB fails on non-null TZ, so be consistent. */ + if (tz_addr !=3D 0) { + complete(cs, -1, EINVAL); + return; + } + + p =3D 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 =3D g_get_real_time(); + p->tv_sec =3D cpu_to_be32(rt / G_USEC_PER_SEC); + p->tv_usec =3D cpu_to_be64(rt % G_USEC_PER_SEC); + unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); +} + +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb compl= ete, + target_ulong tv_addr, target_ulong tz_addr) +{ + if (use_gdb_syscalls()) { + gdb_gettimeofday(cs, complete, tv_addr, tz_addr); + } else { + host_gettimeofday(cs, complete, tv_addr, tz_addr); + } +} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326811195753.1318089663667; Sat, 30 Apr 2022 06:53:31 -0700 (PDT) Received: from localhost ([::1]:46656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknXO-0006pd-2d for importer@patchew.org; Sat, 30 Apr 2022 09:53:30 -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) 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) 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-Google-Smtp-Source: ABdhPJwmDCZmAJ/ogRmL6quBbKpDCIQF3fyXUCmSylBgCKgimdQkb9wMSkQit6e8ZnAtipWVWupfHA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326812259100001 Content-Type: text/plain; charset="utf-8" Always pass a uint64_t. This resolves a FIXME in the m68k and nios2 semihosting that we've lost data. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 3 +-- gdbstub.c | 7 ++++--- semihosting/arm-compat-semi.c | 9 ++++----- semihosting/console.c | 7 +++---- semihosting/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" =20 -typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, - target_ulong ret, target_ulong err= ); +typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int e= rr); =20 /** * gdb_do_syscall: diff --git a/gdbstub.c b/gdbstub.c index a3ff8702ce..5286253f8a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1870,11 +1870,12 @@ static void handle_read_all_regs(GArray *params, vo= id *user_ctx) static void handle_file_io(GArray *params, void *user_ctx) { if (params->len >=3D 1 && gdbserver_state.current_syscall_cb) { - target_ulong ret, err; + uint64_t ret; + int err; =20 - ret =3D (target_ulong)get_param(params, 0)->val_ull; + ret =3D get_param(params, 0)->val_ull; if (params->len >=3D 2) { - err =3D (target_ulong)get_param(params, 1)->val_ull; + err =3D get_param(params, 1)->val_ull; } else { err =3D 0; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 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 } =20 -static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong er= r) +static void common_semi_cb(CPUState *cs, uint64_t ret, int err) { if (err) { #ifdef CONFIG_USER_ONLY @@ -233,7 +233,7 @@ static void common_semi_cb(CPUState *cs, target_ulong r= et, target_ulong err) * SYS_READ and SYS_WRITE always return the number of bytes not read/writt= en. * There is no error condition, other than returning the original length. */ -static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong= err) +static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err) { /* Recover the original length from the third argument. */ CPUArchState *env G_GNUC_UNUSED =3D cs->env_ptr; @@ -250,8 +250,7 @@ static void common_semi_rw_cb(CPUState *cs, target_ulon= g ret, target_ulong err) /* * SYS_SEEK returns 0 on success, not the resulting offset. */ -static void common_semi_seek_cb(CPUState *cs, target_ulong ret, - target_ulong err) +static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { ret =3D 0; @@ -272,7 +271,7 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } =20 static void -common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { /* The size is always stored in big-endian order, extract the valu= e. */ diff --git a/semihosting/console.c b/semihosting/console.c index ef6958d844..3dd0ac60e2 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -64,11 +64,10 @@ static GString *copy_user_string(CPUArchState *env, tar= get_ulong addr) return s; } =20 -static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong er= r) +static void semihosting_cb(CPUState *cs, uint64_t ret, int err) { - if (ret =3D=3D (target_ulong) -1) { - qemu_log("%s: gdb console output failed ("TARGET_FMT_ld")", - __func__, err); + if (err) { + qemu_log("%s: gdb console output failed (%d)", __func__, err); } } =20 diff --git a/semihosting/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, CPUSt= ate *cs, =20 static gdb_syscall_complete_cb gdb_open_complete; =20 -static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void gdb_open_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { int guestfd =3D alloc_guestfd(); diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index da0186f3ef..94deebf09e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,7 +93,7 @@ static void translate_stat(CPUM68KState *env, target_ulon= g addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } =20 -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t= err) +static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) { target_ulong args =3D env->dregs[1]; if (put_user_u32(ret, args) || @@ -108,7 +108,7 @@ static void m68k_semi_return_u32(CPUM68KState *env, uin= t32_t ret, uint32_t err) } } =20 -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t= err) +static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) { target_ulong args =3D env->dregs[1]; if (put_user_u32(ret >> 32, args) || @@ -122,16 +122,12 @@ static void m68k_semi_return_u64(CPUM68KState *env, u= int64_t ret, uint32_t err) =20 static int m68k_semi_is_fseek; =20 -static void m68k_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu =3D M68K_CPU(cs); CPUM68KState *env =3D &cpu->env; =20 if (m68k_semi_is_fseek) { - /* - * FIXME: We've already lost the high bits of the fseek - * return value. - */ m68k_semi_return_u64(env, ret, err); m68k_semi_is_fseek =3D 0; } else { diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 3e504a6c5f..4d02789d26 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,8 +108,7 @@ static bool translate_stat(CPUNios2State *env, target_u= long addr, return true; } =20 -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, - uint32_t err) +static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int er= r) { target_ulong args =3D env->regs[R_ARG1]; if (put_user_u32(ret, args) || @@ -124,8 +123,7 @@ static void nios2_semi_return_u32(CPUNios2State *env, u= int32_t ret, } } =20 -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, - uint32_t err) +static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int er= r) { target_ulong args =3D env->regs[R_ARG1]; if (put_user_u32(ret >> 32, args) || @@ -139,7 +137,7 @@ static void nios2_semi_return_u64(CPUNios2State *env, u= int64_t ret, =20 static int nios2_semi_is_lseek; =20 -static void nios2_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu =3D NIOS2_CPU(cs); CPUNios2State *env =3D &cpu->env; --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326986014336.091267726482; Sat, 30 Apr 2022 06:56:26 -0700 (PDT) Received: from localhost ([::1]:55248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknaC-0004FS-Kz for importer@patchew.org; Sat, 30 Apr 2022 09:56:24 -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) 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) 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-Google-Smtp-Source: ABdhPJyUGInzd8emdo5byqAhbp+/rlhBFNdbdj++6DmGFa/cFkR6kn2XUxOMJzmDgdtugQmDwiz0cA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326987066100003 Content-Type: text/plain; charset="utf-8" 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_ulo= ng addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } =20 -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 =3D M68K_CPU(cs); + CPUM68KState *env =3D &cpu->env; + target_ulong args =3D 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, ui= nt32_t ret, int err) } } =20 -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 =3D M68K_CPU(cs); + CPUM68KState *env =3D &cpu->env; + target_ulong args =3D 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, ui= nt64_t ret, int err) } } =20 -static int m68k_semi_is_fseek; - -static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - M68kCPU *cpu =3D M68K_CPU(cs); - CPUM68KState *env =3D &cpu->env; - - if (m68k_semi_is_fseek) { - m68k_semi_return_u64(env, ret, err); - m68k_semi_is_fseek =3D 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, in= t err) =20 void do_m68k_semihosting(CPUM68KState *env, int nr) { + CPUState *cs =3D 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)a= rg1, arg2, arg3); return; } else { @@ -188,7 +180,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) int fd =3D 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 =3D close(fd); @@ -204,7 +196,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len =3D 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 =3D 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 =3D (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - m68k_semi_is_fseek =3D 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 =3D 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 =3D 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 =3D 0; } failed: - m68k_semi_return_u32(env, result, errno); + m68k_semi_u32_cb(cs, result, errno); } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327039629368.49985135127633; Sat, 30 Apr 2022 06:57:19 -0700 (PDT) Received: from localhost ([::1]:57200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknb4-0005XT-IK for importer@patchew.org; Sat, 30 Apr 2022 09:57:18 -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) 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) 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-Google-Smtp-Source: ABdhPJx7erLiMC8LIQPMvTIuSRSZj9R0b62sGiH5XQVL2v0niw5KZa+DVSGmtiBt/QBHzjGaL7aIRQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327041363100001 Content-Type: text/plain; charset="utf-8" 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); =20 switch(trapnr) { - case EXCP_HALT_INSN: - /* Semihosing syscall. */ - env->pc +=3D 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 @@ =20 #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" =20 #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 =3D env_cpu(env); - TaskState *ts =3D cs->opaque; - /* Allocate the heap using sbrk. */ - if (!ts->heap_limit) { - abi_ulong ret; - uint32_t size; - uint32_t base; - - base =3D do_brk(0); - size =3D SEMIHOSTING_HEAP_SIZE; - /* Try a big heap, and reduce the size if that fails. */ - for (;;) { - ret =3D do_brk(base + size); - if (ret >=3D (base + size)) { - break; - } - size >>=3D 1; - } - ts->heap_limit =3D base + size; - } - /* - * This call may happen before we have writable memory, so return - * values directly in registers. - */ - env->dregs[1] =3D ts->heap_limit; - env->aregs[7] =3D ts->stack_base; - } -#else /* * FIXME: This is wrong for boards where RAM does not start at * address zero. */ env->dregs[1] =3D current_machine->ram_size; env->aregs[7] =3D 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', )) =20 m68k_softmmu_ss =3D ss.source_set() -m68k_softmmu_ss.add(files('monitor.c')) +m68k_softmmu_ss.add(files( + 'm68k-semi.c', + 'monitor.c' +)) =20 target_arch +=3D {'m68k': m68k_ss} target_softmmu_arch +=3D {'m68k': m68k_softmmu_ss} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327363058839.239762111487; Sat, 30 Apr 2022 07:02:43 -0700 (PDT) Received: from localhost ([::1]:37520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkngH-0003BV-SB for importer@patchew.org; Sat, 30 Apr 2022 10:02:41 -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) 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) 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-Google-Smtp-Source: ABdhPJyy0zDJuKMJSBu15Mg9w2coNxpRpgF7Zrh3j4xoi1JHniAHmmRKEGJBFpVaYVw07SQRehc0+w== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327365348100001 Content-Type: text/plain; charset="utf-8" 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 =20 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) - hf =3D O_WRONLY; - else if (flags & GDB_O_RDWR) - hf =3D O_RDWR; - else - hf =3D O_RDONLY; - - if (flags & GDB_O_APPEND) hf |=3D O_APPEND; - if (flags & GDB_O_CREAT) hf |=3D O_CREAT; - if (flags & GDB_O_TRUNC) hf |=3D O_TRUNC; - if (flags & GDB_O_EXCL) hf |=3D O_EXCL; - - return hf; -} - -static void translate_stat(CPUM68KState *env, target_ulong addr, struct st= at *s) -{ - struct gdb_stat *p; - - if (!(p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) - /* FIXME - should this return an error code? */ - return; - p->gdb_st_dev =3D cpu_to_be32(s->st_dev); - p->gdb_st_ino =3D cpu_to_be32(s->st_ino); - p->gdb_st_mode =3D cpu_to_be32(s->st_mode); - p->gdb_st_nlink =3D cpu_to_be32(s->st_nlink); - p->gdb_st_uid =3D cpu_to_be32(s->st_uid); - p->gdb_st_gid =3D cpu_to_be32(s->st_gid); - p->gdb_st_rdev =3D cpu_to_be32(s->st_rdev); - p->gdb_st_size =3D cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize =3D 0; - p->gdb_st_blocks =3D 0; -#else - p->gdb_st_blksize =3D cpu_to_be64(s->st_blksize); - p->gdb_st_blocks =3D cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime =3D cpu_to_be32(s->st_atime); - p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); - p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); -} - static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu =3D 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 =3D -1; \ - errno =3D EFAULT; \ goto failed; \ } \ } while (0) @@ -139,237 +89,93 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) CPUState *cs =3D env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; =20 args =3D 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)a= rg1, - arg2, arg3); - return; - } else { - p =3D lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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 =3D arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); - return; - } else { - result =3D close(fd); - } - } else { - result =3D 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 =3D arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p =3D lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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 =3D arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p =3D lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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 =3D (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 =3D 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 =3D lock_user_string(arg0); - q =3D lock_user_string(arg2); - if (!p || !q) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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 =3D lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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 =3D lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result =3D=3D 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 =3D fstat(arg0, &s); - if (result =3D=3D 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 =3D g_get_real_time(); - p =3D lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval)= , 0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 0; - p->tv_sec =3D cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec =3D cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, 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 =3D 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 =3D lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result =3D -1; - } else { - result =3D 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] =3D current_machine->ram_size; env->aregs[7] =3D current_machine->ram_size; return; + default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr= ); - result =3D 0; + + failed: + m68k_semi_u32_cb(cs, -1, EFAULT); + break; } -failed: - m68k_semi_u32_cb(cs, result, errno); } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327893395222.00607063219957; Sat, 30 Apr 2022 07:11:33 -0700 (PDT) Received: from localhost ([::1]:53020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknoq-0005cR-AT for importer@patchew.org; Sat, 30 Apr 2022 10:11:32 -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) 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) 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-Google-Smtp-Source: ABdhPJxcTb1BH0bqSi6S8uzF5eFhJJcUNAAjcTxD6G9qDrE2oD9wEvMPi8fP20wIF5cPsejHj2vTOw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327893996100001 Content-Type: text/plain; charset="utf-8" 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); =20 -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" =20 #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) =20 -void do_m68k_semihosting(CPUM68KState *env, int nr) +void HELPER(semihosting)(CPUM68KState *env) { CPUState *cs =3D env_cpu(env); - uint32_t args; + uint32_t args, nr; target_ulong arg0, arg1, arg2, arg3; =20 + nr =3D env->dregs[0]; args =3D 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" =20 #if !defined(CONFIG_USER_ONLY) =20 @@ -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) !=3D 0 - && (env->pc & 3) =3D=3D 0 - && cpu_lduw_code(env, env->pc - 4) =3D=3D 0x4e71 - && cpu_ldl_code(env, env->pc) =3D=3D 0x4e7bf000) { - env->pc +=3D 4; - do_m68k_semihosting(env, env->dregs[0]); - return; - } cs->halted =3D 1; cs->exception_index =3D 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 @@ =20 #include "exec/log.h" #include "fpu/softfloat.h" +#ifndef CONFIG_USER_ONLY +#include "semihosting/semihost.h" +#endif =20 =20 //#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); } =20 +#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) =3D=3D 2 + && cpu_lduw_code(s->env, s->pc - 2) =3D=3D 0x4e71 + && cpu_ldl_code(s->env, s->pc + 4) =3D=3D 0x4e7bf000) { + gen_helper_semihosting(cpu_env); + s->pc +=3D 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); } =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327653683638.0644988465294; Sat, 30 Apr 2022 07:07:33 -0700 (PDT) Received: from localhost ([::1]:46054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknky-0000mv-Ev for importer@patchew.org; Sat, 30 Apr 2022 10:07:32 -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) 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) 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-Google-Smtp-Source: ABdhPJwPaObPWNVccq+J6KfWrkoHOGH/8hj2hwMr0rwSxdPj7ndYBjDo+HgBhyRM4M2Ev7AW0IhH6Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327654715100001 Content-Type: text/plain; charset="utf-8" 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) =20 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) =3D=3D 0 + && maybe_semihosting(s)) { + return; + } +#endif gen_exception(s, s->base.pc_next, EXCP_DEBUG); } =20 --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327972906967.6192821065978; Sat, 30 Apr 2022 07:12:52 -0700 (PDT) Received: from localhost ([::1]:54662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknq7-0006j4-Mq for importer@patchew.org; Sat, 30 Apr 2022 10:12:51 -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) 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) 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-Google-Smtp-Source: ABdhPJzzzUX8MLHa6J+jx0m1Jq/8En8nv6/cbNgIr9uYPanyVEDtdsccY+XPN458+9wGPx+kQrNZFA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327974452100001 Content-Type: text/plain; charset="utf-8" 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 */ =20 #define EXCP_RTE 0x100 -#define EXCP_HALT_INSN 0x101 =20 #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 =3D 1; - cs->exception_index =3D EXCP_HLT; - cpu_loop_exit(cs); - return; } if (cs->exception_index >=3D EXCP_TRAP0 && cs->exception_index <=3D 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); } =20 DISAS_INSN(stop) --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327399410439.6511240014447; Sat, 30 Apr 2022 07:03:19 -0700 (PDT) Received: from localhost ([::1]:38614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkngr-0003yY-Vg for importer@patchew.org; Sat, 30 Apr 2022 10:03:18 -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) 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) 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-Google-Smtp-Source: ABdhPJycUAbG1ZNxZgE7QMmpVXYNTv7PbKGICdXgV58UIRRd1JRfHq2qpKEGOae8sFIHaGr7kzJ9xw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327401626100001 Content-Type: text/plain; charset="utf-8" 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; } =20 -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int er= r) +static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu =3D NIOS2_CPU(cs); + CPUNios2State *env =3D &cpu->env; target_ulong args =3D 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) } } =20 -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int er= r) +static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu =3D NIOS2_CPU(cs); + CPUNios2State *env =3D &cpu->env; target_ulong args =3D 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) } } =20 -static int nios2_semi_is_lseek; - -static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - Nios2CPU *cpu =3D NIOS2_CPU(cs); - CPUNios2State *env =3D &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 =3D 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, i= nt err) =20 void do_nios2_semihosting(CPUNios2State *env) { + CPUState *cs =3D 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 =3D 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 =3D close(fd); @@ -225,7 +213,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); len =3D 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 =3D 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 =3D (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - nios2_semi_is_lseek =3D 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 =3D 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 =3D 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 =3D 0; } failed: - nios2_semi_return_u32(env, result, errno); + nios2_semi_u32_cb(cs, result, errno); } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651328134699415.2954337887114; Sat, 30 Apr 2022 07:15:34 -0700 (PDT) Received: from localhost ([::1]:34892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknsj-0003wk-IE for importer@patchew.org; Sat, 30 Apr 2022 10:15:33 -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) 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) 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-Google-Smtp-Source: ABdhPJxASLESuVMDOfuPu1MX60xlwKjwBLWvjP7HXYNrSyEQxQ/vwtTujCB9bYkp+0UU+WxhlAPqgg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651328135461100001 Content-Type: text/plain; charset="utf-8" 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 =3D ss.source_set() nios2_ss.add(files( 'cpu.c', - 'nios2-semi.c', 'op_helper.c', 'translate.c', )) @@ -10,7 +9,8 @@ nios2_softmmu_ss =3D ss.source_set() nios2_softmmu_ss.add(files( 'helper.c', 'monitor.c', - 'mmu.c' + 'mmu.c', + 'nios2-semi.c', )) =20 target_arch +=3D {'nios2': nios2_ss} --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651326983422136.8526081897163; Sat, 30 Apr 2022 06:56:23 -0700 (PDT) Received: from localhost ([::1]:55044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkna9-00047R-Ll for importer@patchew.org; Sat, 30 Apr 2022 09:56:21 -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) 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) 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-Google-Smtp-Source: ABdhPJx9l2kyTOa26SaRoH9s6Pc/yfXC2REX+XCvfXicpQB6+TkQwy2WBApbOrSc7df9XS/xG+aMqw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651326985348100001 Content-Type: text/plain; charset="utf-8" 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 @@ =20 #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 =20 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) { - hf =3D O_WRONLY; - } else if (flags & GDB_O_RDWR) { - hf =3D O_RDWR; - } else { - hf =3D O_RDONLY; - } - - if (flags & GDB_O_APPEND) { - hf |=3D O_APPEND; - } - if (flags & GDB_O_CREAT) { - hf |=3D O_CREAT; - } - if (flags & GDB_O_TRUNC) { - hf |=3D O_TRUNC; - } - if (flags & GDB_O_EXCL) { - hf |=3D O_EXCL; - } - - return hf; -} - -static bool translate_stat(CPUNios2State *env, target_ulong addr, - struct stat *s) -{ - struct gdb_stat *p; - - p =3D lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - - if (!p) { - return false; - } - p->gdb_st_dev =3D cpu_to_be32(s->st_dev); - p->gdb_st_ino =3D cpu_to_be32(s->st_ino); - p->gdb_st_mode =3D cpu_to_be32(s->st_mode); - p->gdb_st_nlink =3D cpu_to_be32(s->st_nlink); - p->gdb_st_uid =3D cpu_to_be32(s->st_uid); - p->gdb_st_gid =3D cpu_to_be32(s->st_gid); - p->gdb_st_rdev =3D cpu_to_be32(s->st_rdev); - p->gdb_st_size =3D cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize =3D 0; - p->gdb_st_blocks =3D 0; -#else - p->gdb_st_blksize =3D cpu_to_be64(s->st_blksize); - p->gdb_st_blocks =3D cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime =3D cpu_to_be32(s->st_atime); - p->gdb_st_mtime =3D cpu_to_be32(s->st_mtime); - p->gdb_st_ctime =3D cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); - return true; -} - static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu =3D 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 =3D -1; \ - errno =3D 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; =20 nr =3D env->regs[R_ARG0]; args =3D 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 =3D lock_user_string(arg0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); - return; - } else { - result =3D close(fd); - } - } else { - result =3D 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 =3D arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p =3D lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p =3D lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D (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 =3D 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 =3D lock_user_string(arg0); - q =3D lock_user_string(arg2); - if (!p || !q) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D lock_user_string(arg0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D lock_user_string(arg0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result =3D=3D 0 && !translate_stat(env, arg2, &s)) { - result =3D -1; - errno =3D 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 =3D fstat(arg0, &s); - if (result =3D=3D 0 && !translate_stat(env, arg1, &s)) { - result =3D -1; - errno =3D 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 =3D g_get_real_time(); - p =3D lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval)= , 0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 0; - p->tv_sec =3D cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec =3D cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, 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 =3D 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 =3D lock_user_string(arg0); - if (!p) { - result =3D -1; - errno =3D EFAULT; - } else { - result =3D 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 =3D 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); } --=20 2.34.1 From nobody Sat May 18 09:22:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651327229369183.39294841842855; Sat, 30 Apr 2022 07:00:29 -0700 (PDT) Received: from localhost ([::1]:35358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nkne8-0001eE-8C for importer@patchew.org; Sat, 30 Apr 2022 10:00:28 -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) 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) 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-Google-Smtp-Source: ABdhPJy4wsdeQLLgfmGJLJfhaHOFA2qpcmAltnWG+7b6vjdMcYt/wk+axysETEgzJSe9WD6LvO3E5Q== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1651327230401100001 Content-Type: text/plain; charset="utf-8" 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) =20 /* 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); =20 -void do_nios2_semihosting(CPUNios2State *env); - #define CPU_RESOLVING_TYPE TYPE_NIOS2_CPU =20 #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 =3D "BREAK insn"; break; - case EXCP_SEMIHOST: - name =3D "SEMIHOST insn"; - break; } if (name) { qemu_log("%s at pc=3D0x%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; =20 - case EXCP_SEMIHOST: - do_nios2_semihosting(env); - break; - default: cpu_abort(cs, "unhandled exception type=3D%d\n", cs->exception_ind= ex); } 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" =20 #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) =20 -void do_nios2_semihosting(CPUNios2State *env) +void HELPER(semihosting)(CPUNios2State *env) { CPUState *cs =3D 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 =3D=3D 1) { - t_gen_helper_raise_exception(dc, EXCP_SEMIHOST); + gen_helper_semihosting(cpu_env); return; } #endif --=20 2.34.1