From nobody Thu Oct 16 04:53:33 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=1753913319; cv=none; d=zohomail.com; s=zohoarc; b=Jie9bHmvaMe+8JuJBgq6/kfUovOlJDNR5BWAU4bWS23Qavz+H/0NvuTIW0LqpQCnC6qjiTEt1XZN5ZHjTrqjogjQEz6u2lLK/9CZbgRk2vee1ZSnUHz35rGTV3q6RY5FNljjlHDi/jByaVQQ7Zdsjr/kjsgKskD2XlGurALMlF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753913319; 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=BFKbQ//LgI79f1zxRYycYxEHuzsaGiAZjs584Y89tXI=; b=RGMRdsIZTwK7XvrWHsx3cnhKcaAM3LSo81W6yVWMDOKco822ADAl9XNagDlbrAQ+cTFSQOuGCQqqaJXVik7/s5uhCtCoyRklfz84WdCZt+NyK6hq9zEFOhPNYeYtzadr+1sbS7+VJEhuBRsuhHIU0wZ1ezntXApADrtGLwcsAFE= 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 1753913319716887.4898792078399; Wed, 30 Jul 2025 15:08:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uhEyE-0006Cj-Sy; Wed, 30 Jul 2025 18:08:22 -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 1uhEwW-0001Dn-S0 for qemu-devel@nongnu.org; Wed, 30 Jul 2025 18:06:37 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uhEwR-0002Z1-Bu for qemu-devel@nongnu.org; Wed, 30 Jul 2025 18:06:35 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2403c13cac3so11907385ad.0 for ; Wed, 30 Jul 2025 15:06:30 -0700 (PDT) Received: from pc.. ([38.41.223.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241e899d272sm981535ad.135.2025.07.30.15.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jul 2025 15:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1753913190; x=1754517990; 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=BFKbQ//LgI79f1zxRYycYxEHuzsaGiAZjs584Y89tXI=; b=TERUefhssIQU2adeKZZgxDshEFwxQz1ax9DkiC0kgOcVCawT66vI394+a+EA9DAqo4 rX4FStYU+6LaQfMlAlra4VvUCtydJhwNB6l6C4cseEtVUvedlXKC/YUjvU0DcBQuPbR1 /ff0NLdWOsXsbi5z/BeLlKZ7eMQbGenE0GkGaFtiY6D2RtC64foeUm+W3Ctyp0lr6chE dZviMpXm+jIDrJEfeTinvoPtuW09QwaXtkQkqemJzSim04EQownPHmhJ8612ap9pEcnL YzKyOFcTDhNsRW2vPItP2cMl4V38bnBzv4w5UP99X/rbjSSNO3NV7lqnRddi7lV659yT 3Idg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753913190; x=1754517990; 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=BFKbQ//LgI79f1zxRYycYxEHuzsaGiAZjs584Y89tXI=; b=lB+69lGqNLtKGH167Q3Z8WHGU93tUhNNKzSUO/OP5hAzDaJ7PGzhI7DMIBysMkzsW5 k1tm1o9tG1JUQkECPJU/kzw+jVdSlWzC98pD/nvnOufdJqTUR4nr1wxaM7UUzcJomE4t ZiCPVfmgdgiz/7ZiN3cSkj12ftE74q5Qgj0/SscNY1KDGNBiyEXQ2OQYRm1luZ0xDjXA VBpaU/nbRVcXuOVUsmnT4JEOiMe24UBiqF8HCUE/wCLrT0o3e4ygkDTpix72rchXdzzX cbpMc6oE25oC0Z6jn9H3oUTUSsRCVxe49TjNkbbs+Mpkzl6Pz2hGuiw98aJZAU0YT/dk 7ebQ== X-Gm-Message-State: AOJu0YxzaFpmodv5/Z6kfeU4Am4+cmpV06ZuT1rlv4QiqTFdLMxpx8KU ouq5FoVC3qH9CDqZECEIpm0c0nAiqC1egQXRZMOHRjl1/Os1F1C5Wef2tyhNCec4PYdHK2CsvAC UidHh X-Gm-Gg: ASbGnctPZnojOzEfTWV4V3f+8HRaoTdhXmOZmdThCQkolNmEI3OEdGOVU12AiF2KC1O gMduCtSR8dCVHjfFSLynozyzonxukZDGLJgKDP9c8wLyEBpXwGdtliE7sfQyqvDFXxGuPvu7S22 wtDuQbScx/nAWNlTixvE3KCgsvFdSEue4dMus6azBa/DnjLPYDGRKT4Va/lEBgA7/A3xPKsyS9c u//ronIp+HSxu8QhH9HEmjZ2aHtXael4Itq64gqYAK5JXDVAPZvR9ycvkA0SoU3cnqo4yQ8Fjgi bruIRZd4zPiHYFjXqlKvBJoUuWsFzr0JKGN7GiT8nf1nZyp1dm/P7+Y2EaqJlj+EoWRb96H5bou 8bMZa3/4r9FglA6Z6WwB3EA== X-Google-Smtp-Source: AGHT+IGZ1yYndVG9K2s8R/mLJl7MuT4SvFdUntXEkA/Q3Ye5zDqHpH0ZPp6sQY0Ctr+3x7XGeEL/JQ== X-Received: by 2002:a17:903:90c:b0:231:9817:6ec1 with SMTP id d9443c01a7336-2409689f466mr71269985ad.17.1753913189930; Wed, 30 Jul 2025 15:06:29 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Weiwei Li , philmd@linaro.org, Liu Zhiwei , Palmer Dabbelt , richard.henderson@linaro.org, qemu-riscv@nongnu.org, Alistair Francis , Pierrick Bouvier Subject: [PATCH 02/10] semihosting/guestfd: compile once for system/user Date: Wed, 30 Jul 2025 15:06:13 -0700 Message-ID: <20250730220621.1142496-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250730220621.1142496-1-pierrick.bouvier@linaro.org> References: <20250730220621.1142496-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::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.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: 1753913321641116600 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. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- 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..33614108094 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. + */ +GuestFD console_in_gf; +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