From nobody Sun Sep 28 15:24:16 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=1758892951; cv=none; d=zohomail.com; s=zohoarc; b=KDsxwdjTSD+upfCBna3srtQNLX6iZPBh2UIgPYp9BjdsnONv3WPDrYabD5BiAvKrWQmP37uuRDYcf0ax8+znikV3xmzcG1aWP3YLpifK8n2pUmz4SzdXB6hz1Jrr6Zw4MQp4qCd2cpNbwRtBWFM4wwSzkRH6ImWEORJCZaENBt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758892951; h=Content-Type: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=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=DCfWPiIjFu7I8OiJ5aAw8r/V5y2ELj3tRWep1NLzKmaLmrwck//rwVUSd+y8NOKTenaicI84VmD075evkaNTxKmkR5L0YVn9y++/0SQ6cFtJbmbJJ9IhUycM7K4DP7ZzidmAsH9lGKiTbjqXHp8d+CF+ASGse5rRSMu3ZuYt5Iw= 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 1758892951737644.6529284158369; Fri, 26 Sep 2025 06:22:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v28LI-00084c-Ea; Fri, 26 Sep 2025 09:18:32 -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 1v28LG-00082R-LJ for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:30 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v28Ks-00042j-T2 for qemu-devel@nongnu.org; Fri, 26 Sep 2025 09:18:26 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3ee15505cdeso1808685f8f.0 for ; Fri, 26 Sep 2025 06:17:55 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fb89fb19fsm7203035f8f.21.2025.09.26.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Sep 2025 06:17:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 321A75F8BD; Fri, 26 Sep 2025 14:17:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758892672; x=1759497472; 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=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=UuL8QjIN6HJEZrzeHcFvf2Hd4qNLsWGZBNfpWavjNg/5/bHTZ3qUT/xjxjW1riFrO1 MnH0rvg6YwIMVwkysyV51FNzcjaPeQEbDUy4vpxpnIrBywuHPXNTcuOYtWH8p7//+cd7 v0ZO4UEH6YYzCe8vFB1ymUb/B9KljkGXSZL4TR53h2xBa7Kxr3uLBdbWgxXqPLCxi65/ 4P/qgVTM1iX7d3/fn35WjOX36twhcaJM71vRarhVy2DXcsNV70yIUIn+doLOrB9Glqri AebJ8Ztu3TSzjD4IKbEuHX2yAmkqzYT3vx78HoIrk7Xnu+Gf2vX1w3z/li9Za7cYdtUp GcCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758892672; x=1759497472; 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=PT5ys6VW+Xb6TbLCy138ABnHFrZi9OZshK4P6osFvUA=; b=O8/kt+bNSF/quC6XbcnJCWqJVdYJ1cvZT/XaT2KjuIvaNFTFQ6oqa7QWxHt8brspMr CyhAMJZ5FsikGtooGOKcLjkFolZen9Vcb4S1F206PJ7D4gud8ehA9k9taHQkJho7Altm bDRrSx/6AZXIb81YKlemfCCtONrM6dQpHLsSnjEn7khaIiwSFN7qriL0eouyHoTSLGkA loZxMFRXqj+DGrUtjbk9eQqHv0pc1qtEcIU41gfCWZjEIQYi4eHlYfT9QhIVKLJCDyTX igIoQmdTzGUa4ER+rFuvC/wGMgvrAuZeEjK+K8mZC8iKsTVOEtUke7UD7F+cfW6lplBY 932w== X-Gm-Message-State: AOJu0Yxw3P7eVU4kei3hWRl7Q+jqaUCaO23/U6duRZdT86O/pqqp0ul/ 03QKKFbFPd03fHArqmtHNrOrwcaeqz6VGsnm2MN6rZ9CR3YA7U2+OpdO0n3omSCiSIGE18fDdzg 5qXLu2WQ= X-Gm-Gg: ASbGnctP5pKF7g8fr8hkVC5UdQgVTesLGSL4MJHBM3df6qqlGVw/8q1JcWKpBmq2PhS G33ySa2iqvIEt2VpXnW961xPyCtrYmiNDRaX8043tLE6dao+yriKW0itFTRLCQdxLs0pgjhEUPB ZOOd8LfC0y8h+Drj2MKz3xoVDO6jAq6XEEBaLudf3Owd9IdcgMqWF7tqUHHXcYwqLMkbjMzMvKM zUlzu1QHrzgyo0NW1Oc53TMQ6SJUHX1cn30V/WsDgEhPHu5/2dob/mIHlr5R+GNpqohsfpgFlW/ xiLntkYlHXJf/cmgd+nnt+MrTpD9kmi+PN/dHkCFEaWoCtspurbu7OYUjfJw6ux7OK4iVhumLlX R/Hks8mPnSNcZ7PIR7t3gYSs= X-Google-Smtp-Source: AGHT+IFf62eKmnb99Ql2AppSqUCSmIlUINfeJUej6wDmXORVXuCqVzerfj65VhA4qG+UvJbsOXX8ZQ== X-Received: by 2002:a5d:588b:0:b0:401:2cbf:ccad with SMTP id ffacd0b85a97d-40f65ac6671mr5939799f8f.17.1758892671942; Fri, 26 Sep 2025 06:17:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 05/24] semihosting/guestfd: compile once for system/user Date: Fri, 26 Sep 2025 14:17:24 +0100 Message-ID: <20250926131744.432185-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250926131744.432185-1-alex.bennee@linaro.org> References: <20250926131744.432185-1-alex.bennee@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=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1758892952422116600 From: Pierrick Bouvier 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 Message-ID: <20250822150058.18692-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-ID: <20250922093711.2768983-7-alex.bennee@linaro.org> 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 64ddc749bf8..a239cfc5a9d 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.3