From patchwork Tue Jun 28 04:53:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585558 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp542670mab; Tue, 28 Jun 2022 01:20:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfHRjsr35H8s+CQdnxu9ki3SOAnNJcXo01ybXoydZr+WEv0w0cNzM7iq9ZKBmlFzFzYvnp X-Received: by 2002:a05:620a:790:b0:6af:6859:ff9f with SMTP id 16-20020a05620a079000b006af6859ff9fmr130489qka.252.1656404417066; Tue, 28 Jun 2022 01:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404417; cv=none; d=google.com; s=arc-20160816; b=stzhPNNrVq/3frcQEmizvY5nDJ5eQXg4KNT6/7+snuXx9vQXSlLLP4LUe33C4XHeu1 N3C/jZoJTQYoPw5zA7VSXzqfV2GuoA9Gv6LKy22s8JMKggFuBNxhDBORWdKSy+Tl4Pna KVfyxFPhivs6gv4Yqpi4cB6UBeW6PWHenyh0jhR0k5vFEl7NpdR0PL+IFMmAWU3VShVG /PuMIJP85wRwza7wbVfUbmJpBpE9at/BI2tTExMQVurgpGTiNFKdwI7SVxJhqLSKrga2 fKuJrF63XInrbVzvDKhpnABoVbYeVGslwOV1LGBdV6/rSOZLMXQaJjZf98GiDYpJ8NlS gjIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=dvGEwia2LqXULvjK9x7SGCFtetADqVhqrMHOvvd+KrlFN9yY46SPCBXZHSe2a2iJl+ /IB7b3CWWLrxZR02fRY7dB9d+PvZp3gFN5iVI81yWIqZadDAw0rm9l72Jshafw3Pr8iN otgiEW8J5Sr4i1isW4m4YbRml+4Ay37lgMaYnCeUEWOeew73Hv5XdxdYYhzu1XC2dNe/ zgFQZMMn/r3Io6wLD2RWB47GVKuF06nQFKWOBlOy2scL0x4Ugc7ehRCZTJYYnTZxHPz4 ZVdXXm2Q0ZdVV/rVcqn+unaOnyK7m0tK1tuYcO1lkfW7JlSQ2U7rugxRWwfcu48I3h1M kizA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y+8Dn+aa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u21-20020a05620a0c5500b006a6c8a03307si8191913qki.88.2022.06.28.01.20.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y+8Dn+aa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66SG-0000SH-K2 for patch@linaro.org; Tue, 28 Jun 2022 04:20:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Je-000225-4Z for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:11 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:38562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jc-0000Wu-AF for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:09 -0400 Received: by mail-pl1-x633.google.com with SMTP id m14so10041998plg.5 for ; Mon, 27 Jun 2022 21:59: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=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=y+8Dn+aa7QQPwv08UEhLc2w3gkwzn1ur98cRK5MdLtldEaEEcNjZoVcC66T6moET+/ aavLWDihOjqHv1CfnvHwrmBNvY5ARq8mXVE/wjiBuxHAeskJ4mQipFxRWfQHiC8YIJRp 01v0HbM1VuDmaOoFVS2nv648CgEqan+YoAJzbcp0spi8JO9Eq25mBWWnZ6nWup07LzDf FLbSZtgk6agW3B7mcl6gS9kYCo9vPWyaWtnthhRtLomJ3c3HXakvs5YAzEg6Gon6KP/0 xMShIa/iu53RBYTGNRumacp4tsjf2vcTxgHOYk4AhtXwpwLGm0QDJHIK105QapgxJw7c Q1Mg== 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=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=n1NoqHvNGbOAy0USXDUS6W2rCwM4P/w6fTNsLub7wXJyf0/KwkQj0EWcn9McM3V7BI +4kY/WhWy1NNfj0IAq8Xc8Qh/UP+qj5XgvI0AyUbyLWeANcxSaYf4QoWDlmNEIIj6Euh enpYuiqjRThfBsXJYmWpKSifJAW/KRamD4Sz0cxixthHHtPy4kJpRqHjgmLxfiLrkmOZ Xh7JQ5JUuZeD94MVJozWDry2zgym5hc8y7htucV4iSon4tAA0aO8c/UuwsV7zTndqDBe PvrFL5XNgZF444cgaZSniqNV0/aVp0Q1GZCP2ULJlASjtVjSYUZzDjrakL6x1iC232Jt pEgg== X-Gm-Message-State: AJIora8PzefVjzU36SrdFOlVsAJOoPzQy93rnOQF5g2cQ1elb37JAKuo ++HwrIiHGg7G1F+fLMcGaUuyUH7FXSe1kA== X-Received: by 2002:a17:903:1cc:b0:16a:73fd:3c87 with SMTP id e12-20020a17090301cc00b0016a73fd3c87mr1783853plh.41.1656392346832; Mon, 27 Jun 2022 21:59:06 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 47/60] semihosting: Create qemu_semihosting_guestfd_init Date: Tue, 28 Jun 2022 10:23:50 +0530 Message-Id: <20220628045403.508716-48-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For arm-compat, initialize console_{in,out}_gf; otherwise, initialize stdio file descriptors. This will go some way to cleaning up arm-compat, and will allow other semihosting to use normal stdio. Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 +++++ include/semihosting/semihost.h | 1 + linux-user/main.c | 9 ++++++ semihosting/console.c | 2 ++ semihosting/guestfd.c | 52 +++++++++++++++++++++++++++------- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index a7ea1041ea..3d426fedab 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -35,6 +35,13 @@ typedef struct GuestFD { }; } GuestFD; +/* + * For ARM semihosting, we have a separate structure for routing + * data for the console which is outside the guest fd address space. + */ +extern GuestFD console_in_gf; +extern GuestFD console_out_gf; + /** * alloc_guestfd: * diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 5b36a76f08..93a3c21b44 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -64,5 +64,6 @@ int qemu_semihosting_config_options(const char *opt); void qemu_semihosting_chardev_init(void); void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ +void qemu_semihosting_guestfd_init(void); #endif /* SEMIHOST_H */ diff --git a/linux-user/main.c b/linux-user/main.c index 651e32f5f2..e44bdb17b8 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -54,6 +54,10 @@ #include "loader.h" #include "user-mmap.h" +#ifdef CONFIG_SEMIHOSTING +#include "semihosting/semihost.h" +#endif + #ifndef AT_FLAGS_PRESERVE_ARGV0 #define AT_FLAGS_PRESERVE_ARGV0_BIT 0 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) @@ -906,6 +910,11 @@ int main(int argc, char **argv, char **envp) } gdb_handlesig(cpu, 0); } + +#ifdef CONFIG_SEMIHOSTING + qemu_semihosting_guestfd_init(); +#endif + cpu_loop(env); /* never exits */ return 0; diff --git a/semihosting/console.c b/semihosting/console.c index 540aa0cd4b..955880514e 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -190,4 +190,6 @@ void qemu_semihosting_console_init(Chardev *chr) NULL, NULL, &console, NULL, true); } + + qemu_semihosting_guestfd_init(); } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e3122ebba9..b05c52f26f 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -10,15 +10,56 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "semihosting/semihost.h" #include "semihosting/guestfd.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" #else #include "semihosting/softmmu-uaccess.h" +#include CONFIG_DEVICES #endif static GArray *guestfd_array; +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING +GuestFD console_in_gf; +GuestFD console_out_gf; +#endif + +void qemu_semihosting_guestfd_init(void) +{ + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING + /* For ARM-compat, the console is in a separate namespace. */ + if (use_gdb_syscalls()) { + console_in_gf.type = GuestFDGDB; + console_in_gf.hostfd = 0; + console_out_gf.type = GuestFDGDB; + console_out_gf.hostfd = 2; + } else { + console_in_gf.type = GuestFDConsole; + console_out_gf.type = GuestFDConsole; + } +#else + /* Otherwise, the stdio file descriptors apply. */ + guestfd_array = g_array_set_size(guestfd_array, 3); +#ifndef CONFIG_USER_ONLY + if (!use_gdb_syscalls()) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, 0); + gf[0].type = GuestFDConsole; + gf[1].type = GuestFDConsole; + gf[2].type = GuestFDConsole; + return; + } +#endif + associate_guestfd(0, 0); + associate_guestfd(1, 1); + associate_guestfd(2, 2); +#endif +} + /* * Allocate a new guest file descriptor and return it; if we * couldn't allocate a new fd then return -1. @@ -30,11 +71,6 @@ int alloc_guestfd(void) { guint i; - if (!guestfd_array) { - /* New entries zero-initialized, i.e. type GuestFDUnused */ - guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); - } - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ for (i = 1; i < guestfd_array->len; i++) { GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); @@ -61,11 +97,7 @@ static void do_dealloc_guestfd(GuestFD *gf) */ static GuestFD *do_get_guestfd(int guestfd) { - if (!guestfd_array) { - return NULL; - } - - if (guestfd <= 0 || guestfd >= guestfd_array->len) { + if (guestfd < 0 || guestfd >= guestfd_array->len) { return NULL; }