From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5BDDCAC592 for ; Mon, 22 Sep 2025 09:43:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0d0e-0003hh-LW; Mon, 22 Sep 2025 05:39:00 -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 1v0czL-0002Dk-31 for qemu-riscv@nongnu.org; Mon, 22 Sep 2025 05:37:42 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1v0cz5-0000dv-Jh for qemu-riscv@nongnu.org; Mon, 22 Sep 2025 05:37:38 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-45f2acb5f42so31194635e9.1 for ; Mon, 22 Sep 2025 02:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1758533839; x=1759138639; 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=S68QpsHReykX2B9M0K/3nvL5iS+xqDJkvSo3if0s2aI=; b=vsHsKGJkAXOMb4sNYH1hNwGMxUzlmntw3zgbQrq0p4MOnwdFJILHSnaWPKO9edMJQC u6m+OAG4IxN4ZAilJPUc9RfTm7W9o39VIR8/6j96BypKofS7S86wtbqgP/HEnwUNDsXz U5BX885a12/B5ImRlZiaQWdSBfFyjuAI4aKDwIAS5VDeXEsbksFUkmI/25rApeeRO6+k fVZoWSaY407LUKXur30DFxupmR+AlzHp5ZO7cFRkAWAUR8V543CNcvmmgX8npG75dEob vJfmX/Oij55dCuh9WHgGBXu8iokwnoVyUQy7dpXNipFDa0FRRGkITAg4e3q2MGdC3r9b hItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758533839; x=1759138639; 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=S68QpsHReykX2B9M0K/3nvL5iS+xqDJkvSo3if0s2aI=; b=LKQQjUEcKUg9YXbg9byEmb2PvsMNPzJbsKYSfA0EhZGRji0UCnIT2BpXx56NdMLq5/ aG505lIp4CF8WG7D7nLmzFDmIgmvOTPQjuFfodMhqiRVqza0TFZYs8KM5uaYR17zb85E cvYDwZaz7Yxlw6hDkGr8UZDrtekWEP3i3DviCHLiMnrTtA0+LuN2HTZSVtvCBtZwUvC4 4yBL3Q2xKSV6qSLSto97BQpq/z6Vm5jWH1m7AK+IluLfElXrsTQc9BS2udl+8RSlFzh4 gSrLlBjycHIy+rF+39Xhzel2G+eonWeHqApRBOkghTI5aM9/f0nVDn0XW9cpVQM5Utoh gmag== X-Forwarded-Encrypted: i=1; AJvYcCWQzzQ+wNPzjngUqvVXcHgXqGJPB85zFUyPK8rkhHwmAMM8BCviA4DijCDZZAjzPH+rfjaIwB1KBeom@nongnu.org X-Gm-Message-State: AOJu0YxfIXnTrcyiNwXxsm7TWf6bJNYIAn67rmCoLIThaxda1Lpy566R ERKZGiDRhlPmRaKG2ZlRg9Fx2UcpBL3pf3psm2MoE/khHue6AFxTg1soBAA1rxTkGEs= X-Gm-Gg: ASbGnctL2mEn5dZN5u5mn6M7Jgd6zOUCkQQdlFrNxVMNx6NrbEFt0/GIWbdFHEiuiOq zk7mGhOIf1SUwn2ldbPaFC3s2MjPSz3dDAFZNN93F5Owa0ABlOVN/Cyq3eKvmOxxHHLla5EJ9iV KcwM72sIJFcB5mgs6Dyn8hmqXbSH02EWiMpHOqyijsqKWh/UreBnKpAOpac+0r5qvPHiXBK/cnD CSfYWPwFeTATqPFJkGwp8fZjDz+o01jXSK1aWR5AgTmzepCVFk9HndAI40rvByrindxygVtIozy rjJ4/BmXw673gc+avSFmT78f05XMR1BspD5tBnoH/WhoWDqzbggpJpvdFLChSCAXFJxpuioWg0A BaqNTKkvlj0ncmX0x6SPff0mpoG/YSQL7pw== X-Google-Smtp-Source: AGHT+IFeOPrdmQ+WxCpZ0rgHiwmsA1CiCsZW8Euy1LaxjPRW6FsGah+A6P4UMQbCmou9rE1npfhClA== X-Received: by 2002:a05:600c:4ec9:b0:46e:1a60:c995 with SMTP id 5b1f17b1804b1-46e1a60cb3amr6265615e9.2.1758533839278; Mon, 22 Sep 2025 02:37:19 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3ee073f4f3csm18495792f8f.2.2025.09.22.02.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 02:37:17 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 865CF5FA02; Mon, 22 Sep 2025 10:37:12 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alexandre Iooss , Mahmoud Mandour , qemu-riscv@nongnu.org, Daniel Henrique Barboza , Thomas Huth , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alistair Francis , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Weiwei Li , Pierrick Bouvier , Liu Zhiwei , Richard Henderson Subject: [PATCH 10/25] include/semihosting/common-semi: extract common_semi API Date: Mon, 22 Sep 2025 10:36:55 +0100 Message-ID: <20250922093711.2768983-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922093711.2768983-1-alex.bennee@linaro.org> References: <20250922093711.2768983-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org From: Pierrick Bouvier We transform target/{arm,riscv}/common-semi-target.h headers to proper compilation units, and use them in arm-compat-semi.c. This way, we can include only the declaration header (which is target agnostic), and selectively link the appropriate implementation based on current target. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-ID: <20250822150058.18692-8-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- include/semihosting/common-semi.h | 6 ++++++ semihosting/arm-compat-semi.c | 3 +-- ...mon-semi-target.h => common-semi-target.c} | 20 +++++++++---------- ...mon-semi-target.h => common-semi-target.c} | 19 +++++++++--------- target/arm/meson.build | 4 ++++ target/riscv/meson.build | 4 ++++ 6 files changed, 33 insertions(+), 23 deletions(-) rename target/arm/{common-semi-target.h => common-semi-target.c} (64%) rename target/riscv/{common-semi-target.h => common-semi-target.c} (59%) diff --git a/include/semihosting/common-semi.h b/include/semihosting/common-semi.h index 0a91db7c414..aa511a46f42 100644 --- a/include/semihosting/common-semi.h +++ b/include/semihosting/common-semi.h @@ -35,5 +35,11 @@ #define COMMON_SEMI_H void do_common_semihosting(CPUState *cs); +uint64_t common_semi_arg(CPUState *cs, int argno); +void common_semi_set_ret(CPUState *cs, uint64_t ret); +bool is_64bit_semihosting(CPUArchState *env); +bool common_semi_sys_exit_is_extended(CPUState *cs); +uint64_t common_semi_stack_bottom(CPUState *cs); +bool common_semi_has_synccache(CPUArchState *env); #endif /* COMMON_SEMI_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 26263a06b7a..604a69e3646 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -174,8 +174,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #endif -#include "cpu.h" -#include "common-semi-target.h" +#include "semihosting/common-semi.h" /* * Read the input value from the argument block; fail the semihosting diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.c similarity index 64% rename from target/arm/common-semi-target.h rename to target/arm/common-semi-target.c index 6775a270aaa..2b77ce9c17b 100644 --- a/target/arm/common-semi-target.h +++ b/target/arm/common-semi-target.c @@ -7,12 +7,12 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H -#define TARGET_ARM_COMMON_SEMI_TARGET_H - +#include "qemu/osdep.h" +#include "cpu.h" +#include "semihosting/common-semi.h" #include "target/arm/cpu-qom.h" -static inline uint64_t common_semi_arg(CPUState *cs, int argno) +uint64_t common_semi_arg(CPUState *cs, int argno) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -23,7 +23,7 @@ static inline uint64_t common_semi_arg(CPUState *cs, int argno) } } -static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) +void common_semi_set_ret(CPUState *cs, uint64_t ret) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -34,27 +34,25 @@ static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) } } -static inline bool common_semi_sys_exit_is_extended(CPUState *cs) +bool common_semi_sys_exit_is_extended(CPUState *cs) { return is_a64(cpu_env(cs)); } -static inline bool is_64bit_semihosting(CPUArchState *env) +bool is_64bit_semihosting(CPUArchState *env) { return is_a64(env); } -static inline uint64_t common_semi_stack_bottom(CPUState *cs) +uint64_t common_semi_stack_bottom(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } -static inline bool common_semi_has_synccache(CPUArchState *env) +bool common_semi_has_synccache(CPUArchState *env) { /* Ok for A64, invalid for A32/T32 */ return is_a64(env); } - -#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.c similarity index 59% rename from target/riscv/common-semi-target.h rename to target/riscv/common-semi-target.c index 663dedfdad2..aeaeb88d536 100644 --- a/target/riscv/common-semi-target.h +++ b/target/riscv/common-semi-target.c @@ -8,43 +8,42 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H -#define TARGET_RISCV_COMMON_SEMI_TARGET_H +#include "qemu/osdep.h" +#include "cpu.h" +#include "semihosting/common-semi.h" -static inline uint64_t common_semi_arg(CPUState *cs, int argno) +uint64_t common_semi_arg(CPUState *cs, int argno) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; return env->gpr[xA0 + argno]; } -static inline void common_semi_set_ret(CPUState *cs, uint64_t ret) +void common_semi_set_ret(CPUState *cs, uint64_t ret) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; env->gpr[xA0] = ret; } -static inline bool is_64bit_semihosting(CPUArchState *env) +bool is_64bit_semihosting(CPUArchState *env) { return riscv_cpu_mxl(env) != MXL_RV32; } -static inline bool common_semi_sys_exit_is_extended(CPUState *cs) +bool common_semi_sys_exit_is_extended(CPUState *cs) { return is_64bit_semihosting(cpu_env(cs)); } -static inline uint64_t common_semi_stack_bottom(CPUState *cs) +uint64_t common_semi_stack_bottom(CPUState *cs) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; return env->gpr[xSP]; } -static inline bool common_semi_has_synccache(CPUArchState *env) +bool common_semi_has_synccache(CPUArchState *env) { return true; } - -#endif diff --git a/target/arm/meson.build b/target/arm/meson.build index 914f1498fc5..638ee62525f 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -28,12 +28,16 @@ arm_user_ss.add(files( 'vfp_fpscr.c', 'el2-stubs.c', )) +arm_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) arm_common_system_ss.add(files('cpu.c')) arm_common_system_ss.add(when: 'TARGET_AARCH64', if_false: files( 'cpu32-stubs.c')) arm_common_system_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) arm_common_system_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) +arm_common_system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) arm_common_system_ss.add(files( 'arch_dump.c', 'arm-powerctl.c', diff --git a/target/riscv/meson.build b/target/riscv/meson.build index a4bd61e52a9..fdefe88ccdd 100644 --- a/target/riscv/meson.build +++ b/target/riscv/meson.build @@ -8,6 +8,10 @@ gen = [ riscv_ss = ss.source_set() riscv_ss.add(gen) + +riscv_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', + if_true: files('common-semi-target.c')) + riscv_ss.add(files( 'cpu.c', 'cpu_helper.c', -- 2.47.3