From nobody Thu Oct 16 04:49:00 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=1754335704; cv=none; d=zohomail.com; s=zohoarc; b=R2w6geQwVBTOu120BrAoa5E2dSIZpdbK5MKAsuUuDy7hZr8sc+gW2rjym8Rq0wqz/zO9aMjhIO0PdEl/J0eHYqfeaSTF9neBJtGx3Q7ysW323zabd0iMXhbdt7+EeMnnYzNRkCGL+9a7b9fE0LkArCjo5qNLpiBQQWOs/fciJ6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754335704; 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=QeYS37qpB1KPJ1YY/BodsVA5dGOBaJ82IxvGdn5Uav8etamSOr15TuL5Ca9J8iynFE6U5b2LxL4P4we88X7ppOXKEczPd8V4qraM++JZubBcAi58OAlNKIXTUTqAqSKtFP11bKwGV4AjU4ZwtmtlhF1+jP990Tob4JEEZhHUWv8= 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 1754335704163181.70218160181741; Mon, 4 Aug 2025 12:28:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uj0m7-0006Lt-Py; Mon, 04 Aug 2025 15:23:15 -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 1uj06R-00018U-2O for qemu-devel@nongnu.org; Mon, 04 Aug 2025 14:40:09 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uj06M-0000v4-2U for qemu-devel@nongnu.org; Mon, 04 Aug 2025 14:40:06 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-76bdc73f363so2879056b3a.3 for ; Mon, 04 Aug 2025 11:40:00 -0700 (PDT) Received: from pc.. ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76bd78875cesm9940171b3a.15.2025.08.04.11.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Aug 2025 11:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1754332799; x=1754937599; 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=v83gKcA1IO85y5HsdNA4rzZJ+jiKm2/AWkUq/cqjoxjUxdd6GtB6+oVK5GlO8UbDcz pPHVFxMmR5ZDIaJwN2YavOX8f8tozy+XvYQyLH31UeTAyuN0eehlOyM7A3uCFY9bU+GE DMtoKMKjDsSJz44E+OJMwSMPA5uQCM4GlfClbxzSU/yOt/6ffkS4g+RZV9NgYXMUCLpe EWGtI3s8y7gjoUvmVK6Q/XKNA6Zn6/0SqwbRWFHXXtJmHXr9b0Vd9hq1v1fMsEwxAfL6 WGrsJuxamGfEpGyGcFEzJ6Jzw7YWfEK1kwijRhMvskSRr0bnuv8G8pFFbCs8PvBDL6pj w53w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754332799; x=1754937599; 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=OusMg4MhoIrFOGsN4tUYqmq1T0MwfC+3y/nX2M6xXhuAGIkI5f+ZQlfMJP+RDM1CDQ 7hwqBFYNGgLBYecsjpAk8eZwFFzX0KJJw1IwiqU1MV0R9rd0/vK/EGxd+u4TxmSe05wL pa79TqlcvwJKIfKcOWYqNyRphMWC0uORM2oJJz37ALd3L/UsqpEfTw8qIh/wryBzNutO bVvs/xfImVBJkEOPLnTBxB0j5f2aNUZOp2TNSs7zHVFK7wMS2Bz/iIH/BCdGdi5EX/xu i0rab40LuTF6uZGQGABw/P7C1Ai43AWAXqerj9JQz29wIRAKb/M5p4dZndKvXbuWz4pQ +XAg== X-Gm-Message-State: AOJu0Yz9UyC4uFvUg/atNEjnkXMXaMLJZLzhufnsUIQN8z6RayknkdsS S5uugWYgi6I0wsAp4Af8b8tWwcHkQoarcmKQ10m6s7FbUYmi9uxglJgWa9XBsU0VuerM4o1zNxZ wSJBl X-Gm-Gg: ASbGncvM+MT7PW5Bd5/65gfLWSrDP8JJkbzpYCQvTBkMkzz3iL0gAoPudvnPooVU2wF 0mJnLnNJhfI9kfxk8NOZ0gfQk9zp+u/3EiplRZuCDx983wYBxb2AiOiqMclmEZn8J7WbtEl0Vau pqCNQpIyCEzkO9i0Fjw945aMkb0NrzphHhmVnmd6vNSg9LxJGnPUlQGFm+4DDKItJqV3Z1sokpv K2nCsOBzrDiUpqeALe86UcbifQouD58sgXOveOPcWQvenG6L8LxbpY8zmwNBzdtGGIVs5VLW/iT tV/E+Z5RWiCH7eLQfMBItk6IupLgSgjUGux17c8H9nvDNm4pG8yajn+S3p1Aw7rexP/+grQY1mU lC0/qkOMiQgZ9LqtxuZsecA== X-Google-Smtp-Source: AGHT+IGXv/toE0slkkXu0tzxMxIDZx1hCC4UlcjLD+Xw8v5mt+ojSlfeQMHFcqGK3tMy6M7PAimzOg== X-Received: by 2002:a05:6a00:4c97:b0:76b:f01c:ff08 with SMTP id d2e1a72fcca58-76bf01d0125mr11318107b3a.2.1754332799444; Mon, 04 Aug 2025 11:39:59 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, philmd@linaro.org, Weiwei Li , Palmer Dabbelt , richard.henderson@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Liu Zhiwei , qemu-arm@nongnu.org, Alistair Francis , Daniel Henrique Barboza , Pierrick Bouvier Subject: [PATCH v3 03/12] semihosting/guestfd: compile once for system/user Date: Mon, 4 Aug 2025 11:39:41 -0700 Message-ID: <20250804183950.3147154-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250804183950.3147154-1-pierrick.bouvier@linaro.org> References: <20250804183950.3147154-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::431; envelope-from=pierrick.bouvier@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 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: 1754335704943116600 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