Skip to contentSkip to conversation

semihosting: Restrict to TCG

PATCH Applied Philippe Mathieu-Daudé 2 participants 10 messages Jul 17, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover semihosting: Restrict to TCG

v4: Address Paolo's comment
v3: Address Anton's comment
v2: Address Paolo's comment

Semihosting currently uses the TCG probe_access API, so it is pointless to have it in the binary when TCG isn't.

It could be implemented for other accelerators, but work need to be done. Meanwhile, do not enable it unless TCG is available.

Philippe Mathieu-Daudé (8):
semihosting: Include missing 'gdbstub/syscalls.h' header target/m68k: Add semihosting stub
target/mips: Add semihosting stub
target/m68k: Restrict semihosting to TCG target/mips: Restrict semihosting to TCG target/riscv: Restrict semihosting to TCG target/xtensa: Restrict semihosting to TCG
semihosting: Restrict to TCG

 include/semihosting/syscalls.h            |  2 ++
 target/m68k/semihosting-stub.c            | 15 +++++++++++++++
 target/mips/tcg/sysemu/semihosting-stub.c | 15 +++++++++++++++
 semihosting/Kconfig                       |  1 +
 target/m68k/Kconfig                       |  2 +-
 target/m68k/meson.build                   |  5 ++++-
 target/mips/Kconfig                       |  2 +-
 target/mips/tcg/sysemu/meson.build        |  6 ++++--
 target/riscv/Kconfig                      |  4 ++--
 target/xtensa/Kconfig                     |  2 +-
 10 files changed, 46 insertions(+), 8 deletions(-)
 create mode 100644 target/m68k/semihosting-stub.c
 create mode 100644 target/mips/tcg/sysemu/semihosting-stub.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH v4 1/8 semihosting: Include missing 'gdbstub/syscalls.h' header

"semihosting/syscalls.h" requires definitions from "gdbstub/syscalls.h", include it in order to avoid:

include/semihosting/syscalls.h:23:38: error: unknown type name 'gdb_syscall_complete_cb' void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete,

                                       ^
---
 include/semihosting/syscalls.h | 2 ++
 1 file changed, 2 insertions(+)
include/semihosting/syscalls.h +2 -0
index 3a5ec229eb..b5937c619a 100644
@@ -9,6 +9,8 @@
 #ifndef SEMIHOSTING_SYSCALLS_H
 #define SEMIHOSTING_SYSCALLS_H
 
+#include "gdbstub/syscalls.h"
+
 /*
  * Argument loading from the guest is performed by the caller;
  * results are returned via the 'complete' callback.
Signature · 1 line
2.41.0
#2 lore raw

PATCH v4 2/8 target/m68k: Add semihosting stub

In reply to Philippe Mathieu-Daudé

Since the SEMIHOSTING feature is optional, we need a stub to link when it is disabled.

---
 target/m68k/semihosting-stub.c | 15 +++++++++++++++
 target/m68k/meson.build        |  5 ++++-
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 target/m68k/semihosting-stub.c
target/m68k/semihosting-stub.c new file +15 -0
new file mode 100644
index 0000000000..d6a5965e29
@@ -0,0 +1,15 @@
+/*
+ *  m68k/ColdFire semihosting stub
+ *
+ * SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]>
+ * SPDX-FileCopyrightText: 2024 Linaro Ltd.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+
+void do_m68k_semihosting(CPUM68KState *env, int nr)
+{
+    g_assert_not_reached();
+}
target/m68k/meson.build +4 -1
index 8d3f9ce288..4d213daaf6 100644
@@ -11,9 +11,12 @@ m68k_ss.add(files(
 
 m68k_system_ss = ss.source_set()
 m68k_system_ss.add(files(
-  'm68k-semi.c',
   'monitor.c'
 ))
+m68k_system_ss.add(when: ['CONFIG_SEMIHOSTING'],
+  if_true: files('m68k-semi.c'),
+  if_false: files('semihosting-stub.c')
+)
 
 target_arch += {'m68k': m68k_ss}
 target_system_arch += {'m68k': m68k_system_ss}
Signature · 1 line
2.41.0
#3 lore raw

PATCH v4 3/8 target/mips: Add semihosting stub

In reply to Philippe Mathieu-Daudé

Since the SEMIHOSTING feature is optional, we need a stub to link when it is disabled.

---
 target/mips/tcg/sysemu/semihosting-stub.c | 15 +++++++++++++++
 target/mips/tcg/sysemu/meson.build        |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 target/mips/tcg/sysemu/semihosting-stub.c
target/mips/tcg/sysemu/semihosting-stub.c new file +15 -0
new file mode 100644
index 0000000000..7ae27d746f
@@ -0,0 +1,15 @@
+/*
+ *  MIPS semihosting stub
+ *
+ * SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]>
+ * SPDX-FileCopyrightText: 2024 Linaro Ltd.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "internal.h"
+
+void mips_semihosting(CPUMIPSState *env)
+{
+    g_assert_not_reached();
+}
target/mips/tcg/sysemu/meson.build +4 -2
index ec665a4b1e..911341ac37 100644
@@ -1,10 +1,12 @@
 mips_system_ss.add(files(
   'cp0_helper.c',
-  'mips-semi.c',
   'special_helper.c',
   'tlb_helper.c',
 ))
-
+mips_system_ss.add(when: ['CONFIG_SEMIHOSTING'],
+  if_true: files('mips-semi.c'),
+  if_false: files('semihosting-stub.c')
+)
 mips_system_ss.add(when: 'TARGET_MIPS64', if_true: files(
   'lcsr_helper.c',
 ))
Signature · 1 line
2.41.0
#4 lore raw

PATCH v4 4/8 target/m68k: Restrict semihosting to TCG

In reply to Philippe Mathieu-Daudé

The semihosting feature depends on TCG (due to the probe_access API access). Although TCG is the single accelerator currently available for the m68k target, use the Kconfig "imply" directive which is more correct (if we were to support a different accel).

---
 target/m68k/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/m68k/Kconfig +1 -1
index 9eae71486f..23aae24ebe 100644
@@ -1,3 +1,3 @@
 config M68K
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
Signature · 1 line
2.41.0
#5 lore raw

PATCH v4 5/8 target/mips: Restrict semihosting to TCG

In reply to Philippe Mathieu-Daudé

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

---
 target/mips/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/mips/Kconfig +1 -1
index eb19c94c7d..876048b150 100644
@@ -1,6 +1,6 @@
 config MIPS
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
 
 config MIPS64
     bool
Signature · 1 line
2.41.0
#6 lore raw

PATCH v4 6/8 target/riscv: Restrict semihosting to TCG

In reply to Philippe Mathieu-Daudé

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

---
 target/riscv/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/Kconfig +2 -2
index 5f30df22f2..c332616d36 100644
@@ -1,9 +1,9 @@
 config RISCV32
     bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
     select DEVICE_TREE # needed by boot.c
 
 config RISCV64
     bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
     select DEVICE_TREE # needed by boot.c
Signature · 1 line
2.41.0
#7 lore raw

PATCH v4 7/8 target/xtensa: Restrict semihosting to TCG

In reply to Philippe Mathieu-Daudé

The semihosting feature depends on TCG (due to the probe_access API access). Although TCG is the single accelerator currently available for the xtensa target, use the Kconfig "imply" directive which is more correct (if we were to support a different accel).

---
 target/xtensa/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/xtensa/Kconfig +1 -1
index 5e46049262..e8c2598c4d 100644
@@ -1,3 +1,3 @@
 config XTENSA
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
Signature · 1 line
2.41.0
#8 lore raw

PATCH v4 8/8 semihosting: Restrict to TCG

In reply to Philippe Mathieu-Daudé

Semihosting currently uses the TCG probe_access API. It is pointless to have it in the binary when TCG isn't.

---
 semihosting/Kconfig | 1 +
 1 file changed, 1 insertion(+)
semihosting/Kconfig +1 -0
index eaf3a20ef5..fbe6ac87f9 100644
@@ -1,6 +1,7 @@
 
 config SEMIHOSTING
        bool
+       depends on TCG
 
 config ARM_COMPATIBLE_SEMIHOSTING
        bool
Signature · 1 line
2.41.0
Applied
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

v4: Address Paolo's comment
v3: Address Anton's comment
v2: Address Paolo's comment

Semihosting currently uses the TCG probe_access API, so it is pointless to have it in the binary when TCG isn't.

It could be implemented for other accelerators, but work need to be done. Meanwhile, do not enable it unless TCG is available.

Queued to semihosting/next, thanks.
<snip>

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro