From nobody Thu Oct 16 04:50:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1755875142; cv=none; d=zohomail.com; s=zohoarc; b=dmOw0VkDv/VhHhXgA3+Z1zZX7IAX6yvpWKM9t1mV7vURKThrgTEEOusf8Ts999LfZiLPkaE1aNgjJjkZ4kIHYm9NWLjJiT3qNd1e732WxzgPS14o9Hf6Y9h6I2MW4lXldxzp5U/tNjLmz0HhZ740PvCleZNkvePedOf3Wia9neE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755875142; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=M9U0/wZZ+X7jDvuQEIrxHKhigwEtRJDRddgS55lpDeU=; b=KJQ3yqL0QcGaDGrPvoX19322iu8TCHWoG8v9rIz4DAVAbR7kbKIURczFr/iiCak7yb9XkBg4m+N8O1xuJ3l4isS22zoJwhulYbYpb/dp7kD9zHiipihBL5660qofTV4VgVdLe0htWoj3tGDFJkE4vAIx9JkXnVzXqB7d6qAYLL8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755875142537535.6847057422387; Fri, 22 Aug 2025 08:05:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1upTHJ-000236-MO; Fri, 22 Aug 2025 11:02:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1upTGk-0001l4-6y for qemu-devel@nongnu.org; Fri, 22 Aug 2025 11:01:31 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1upTGT-0004zg-KR for qemu-devel@nongnu.org; Fri, 22 Aug 2025 11:01:29 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2445824dc27so21201195ad.3 for ; Fri, 22 Aug 2025 08:01:11 -0700 (PDT) Received: from pc.taild8403c.ts.net ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-245ed5406e4sm85929495ad.165.2025.08.22.08.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Aug 2025 08:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755874869; x=1756479669; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M9U0/wZZ+X7jDvuQEIrxHKhigwEtRJDRddgS55lpDeU=; b=h3yZabb/4uOkN1rgSBr9dD6ZProPnPmCJtLhFHVTJZpojbi6Uh681aJR8NyQlWfZjA Q5Vrniud4/qvypGDysyD7YISB3pErmWUlEFzxYLtlZUCdNMuxwPMf39fGxxtw2hWQyZ9 ACTSLsb4qrFTpMTjvFK2KBYG2jF52XG18g18evq8zefUUOueL/xfB1gjhAzP3ciqPnhe 1LTjdG9PW+e4zkNAQqURRv6/67aHEVORadylbZIcyn0pHrSHy1vaQC8B/siytcCfdpB0 nRys1d46D2n1uN9vGt78vumMsuew4ke63Ii40QPgz8AqvPtPyARGRNVGBUVP2pcLryYt VsTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755874869; x=1756479669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M9U0/wZZ+X7jDvuQEIrxHKhigwEtRJDRddgS55lpDeU=; b=LP1P6gwe3wIyLP2TEtw8A3QBgDhQJOvAh5y8gzNHrgQZhz4RyKWYluISAapN+rNRYQ Omv6AInyNAWETyyCTJuQqEp61gURCAwBcJ4TNHkdsndiU/OwSjXnO+YxxcKkNh2EbpeQ +c9YnQ6J3d7Pbw0VWEGvv5zOa/ZSiZvZYGJa4B0RXLfEc6tcpIthK5X01OnAyItasAKI WVBf19iHIdi9B5p5mpvOfrqUIC/DkOGogU+8si8pCtrZk5zqIptEo5XItGarBvrpZTrQ VODEGJusiyJdFX8kWUciU/7jacmqCEO8qe8+CsC7FSOlP7t0toeQDh5Jfn9Fd14pAWS5 mGNg== X-Gm-Message-State: AOJu0YyZ/OuwLMGHzH3BuMCV3CSvjoS2W+/qeQr9G/OB3ECI1QfpYQ2z CV+f1EteHAqrJVJhHOWuiEpxQu2/jFHOsW6+3DOolTPECwLg8inTPbIYT4crGvDcEYzNVgfWCTj iDGYTtWITaQ== X-Gm-Gg: ASbGnctZp6dwG1vqU4toCs27FZtkGUgv8gFw4zNPa/D82qhU5SkhHc2jftBehcOR5Pt aZaeQlP03yL4YrCO3XD1vTnrvIPfUYdOglomDbDTBktfdbC24MXEWBy29KhMhfldXyNIp8VJ3fb 1EztIbJmbzHYFxKCFg/hb4c0TFErCE81b2RL7EjXW/8wdKewb3AcbNYODAQcyI3RI7kEaqrrm24 U89fiqSrqhmNKDrqmDtiFpfzThgp86mC2ItJXUcGhHYnKOOXhRPlyqifdsyaHL+dZU4kRZmPAJi iWRUppMCWnIYSaHRlRapxWqk9n4OqRftfl1xP0c44ejsQDGAe8Vn1QrKfgZmx1/1GH4aif5DxLV EHT6KtFrlLZyz+EOIjI7LHstUukvLR+BjySUEnHx/BUc= X-Google-Smtp-Source: AGHT+IF3toQpmj8h5tsWhOPCnEZzd3TnPsKwHOqHIF5l5vvq8fl4lmOXdwgv16NfyWulMLZ9dldmew== X-Received: by 2002:a17:902:e84e:b0:240:1831:eede with SMTP id d9443c01a7336-2462ef4cc1amr39835165ad.32.1755874868698; Fri, 22 Aug 2025 08:01:08 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , Weiwei Li , Palmer Dabbelt , qemu-riscv@nongnu.org, richard.henderson@linaro.org, Daniel Henrique Barboza , philmd@linaro.org, Liu Zhiwei , Peter Maydell , Pierrick Bouvier Subject: [PATCH v4 03/12] semihosting/guestfd: compile once for system/user Date: Fri, 22 Aug 2025 08:00:49 -0700 Message-ID: <20250822150058.18692-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250822150058.18692-1-pierrick.bouvier@linaro.org> References: <20250822150058.18692-1-pierrick.bouvier@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=pierrick.bouvier@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 autolearn=unavailable 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1755875143976116600 Content-Type: text/plain; charset="utf-8" We move relevant code to semihosting/arm-compat-semi.c, and add functions to query CONFIG_ARM_COMPATIBLE_SEMIHOSTING at runtime. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/semihosting/guestfd.h | 7 ------- include/semihosting/semihost.h | 2 ++ semihosting/arm-compat-semi-stub.c | 19 +++++++++++++++++++ semihosting/arm-compat-semi.c | 26 ++++++++++++++++++++++++++ semihosting/guestfd.c | 26 +++++--------------------- semihosting/meson.build | 11 ++++++----- 6 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 semihosting/arm-compat-semi-stub.c diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 3d426fedab3..a7ea1041ea0 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -35,13 +35,6 @@ typedef struct GuestFD { }; } GuestFD; =20 -/* - * For ARM semihosting, we have a separate structure for routing - * data for the console which is outside the guest fd address space. - */ -extern GuestFD console_in_gf; -extern GuestFD console_out_gf; - /** * alloc_guestfd: * diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index b03e6375787..231dc890395 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -33,6 +33,8 @@ typedef enum SemihostingTarget { * Return true if guest code is allowed to make semihosting calls. */ bool semihosting_enabled(bool is_user); +bool semihosting_arm_compatible(void); +void semihosting_arm_compatible_init(void); =20 SemihostingTarget semihosting_get_target(void); const char *semihosting_get_arg(int i); diff --git a/semihosting/arm-compat-semi-stub.c b/semihosting/arm-compat-se= mi-stub.c new file mode 100644 index 00000000000..bfa3681e267 --- /dev/null +++ b/semihosting/arm-compat-semi-stub.c @@ -0,0 +1,19 @@ +/* + * Stubs for platforms different from ARM + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "semihosting/semihost.h" +#include + +bool semihosting_arm_compatible(void) +{ + return false; +} + +void semihosting_arm_compatible_init(void) +{ + g_assert_not_reached(); +} diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 40dc778529d..3f653c6e7a9 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -101,6 +101,13 @@ static int gdb_open_modeflags[12] =3D { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, }; =20 +/* + * For ARM semihosting, we have a separate structure for routing + * data for the console which is outside the guest fd address space. + */ +static GuestFD console_in_gf; +static GuestFD console_out_gf; + #ifndef CONFIG_USER_ONLY =20 /** @@ -353,6 +360,25 @@ static const uint8_t featurefile_data[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 +bool semihosting_arm_compatible(void) +{ + return true; +} + +void semihosting_arm_compatible_init(void) +{ + /* For ARM-compat, the console is in a separate namespace. */ + if (use_gdb_syscalls()) { + console_in_gf.type =3D GuestFDGDB; + console_in_gf.hostfd =3D 0; + console_out_gf.type =3D GuestFDGDB; + console_out_gf.hostfd =3D 2; + } else { + console_in_gf.type =3D GuestFDConsole; + console_out_gf.type =3D GuestFDConsole; + } +} + /* * Do a semihosting call. * diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index d3241434c51..e8f236c690c 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -12,35 +12,20 @@ #include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/guestfd.h" -#ifndef CONFIG_USER_ONLY -#include CONFIG_DEVICES -#endif =20 static GArray *guestfd_array; =20 -#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING -GuestFD console_in_gf; -GuestFD console_out_gf; -#endif - void qemu_semihosting_guestfd_init(void) { /* New entries zero-initialized, i.e. type GuestFDUnused */ guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); =20 -#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING - /* For ARM-compat, the console is in a separate namespace. */ - if (use_gdb_syscalls()) { - console_in_gf.type =3D GuestFDGDB; - console_in_gf.hostfd =3D 0; - console_out_gf.type =3D GuestFDGDB; - console_out_gf.hostfd =3D 2; - } else { - console_in_gf.type =3D GuestFDConsole; - console_out_gf.type =3D GuestFDConsole; + if (semihosting_arm_compatible()) { + semihosting_arm_compatible_init(); + return; } -#else - /* Otherwise, the stdio file descriptors apply. */ + + /* Out of ARM, the stdio file descriptors apply. */ guestfd_array =3D g_array_set_size(guestfd_array, 3); #ifndef CONFIG_USER_ONLY if (!use_gdb_syscalls()) { @@ -54,7 +39,6 @@ void qemu_semihosting_guestfd_init(void) associate_guestfd(0, 0); associate_guestfd(1, 1); associate_guestfd(2, 2); -#endif } =20 /* diff --git a/semihosting/meson.build b/semihosting/meson.build index 77200a7f27b..bb0db323937 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,17 +1,18 @@ -specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( - 'guestfd.c', -)) - common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c')) -user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c')) +user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'user.c', + 'guestfd.c')) system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'config.c', 'console.c', + 'guestfd.c', 'uaccess.c', 'syscalls.c', ), if_false: files( 'stubs-system.c', )) +system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_false: files('arm-compat-semi-stub.c')) =20 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'], if_true: files('syscalls.c')) --=20 2.47.2