On 10/9/2026 5:52 PM, Pierrick Bouvier wrote:
This allows a specific target to declare its implementation of
semihosting.

Signed-off-by: Pierrick Bouvier <[email protected]>
---

Reviewed-by: Brian Cain <[email protected]>


  include/hw/core/cpu.h             |  6 ++++++
  include/semihosting/common-semi.h | 17 +++++++++++++++++
  2 files changed, 23 insertions(+)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 8160a301978..8432c66906d 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -98,6 +98,9 @@ struct AccelCPUClass;
  /* see sysemu-cpu-ops.h */
  struct SysemuCPUOps;
+/* see semihosting/common-semi.h */
+struct SemihostingCPUOps;
+
  /**
   * CPUClass:
   * @class_by_name: Callback to map -cpu command line model name to an
@@ -186,6 +189,9 @@ struct CPUClass {
  #ifdef CONFIG_TCG
      /* when TCG is not available, this pointer is NULL */
      const TCGCPUOps *tcg_ops;
+
+    /* when target does not implement semihosting, this pointer is NULL */
+    const struct SemihostingCPUOps *semi_ops;
  #endif
/*
diff --git a/include/semihosting/common-semi.h 
b/include/semihosting/common-semi.h
index 1e7699d7bbd..618f60f76e7 100644
--- a/include/semihosting/common-semi.h
+++ b/include/semihosting/common-semi.h
@@ -34,6 +34,23 @@
  #ifndef COMMON_SEMI_H
  #define COMMON_SEMI_H
+typedef struct SemihostingCPUOps {
+    /* Return argument @argno */
+    uint64_t (*arg)(CPUState *cs, int argno);
+    /* Set return value for semihosting call */
+    void (*set_ret)(CPUState *cs, uint64_t ret);
+    /* Set an error for a semihosting call */
+    void (*set_err)(CPUState *cs, int err);
+    /* True if the guest is using the 64-bit semihosting ABI */
+    bool (*is_64bit)(CPUState *cs);
+    /* True if SYS_EXIT takes an extended parameter block */
+    bool (*sys_exit_is_extended)(CPUState *cs);
+    /* Return lowest address until which stack can grow */
+    uint64_t (*stack_bottom)(CPUState *cs);
+    /* True if SYS_SYNCCACHE is implemented */
+    bool (*has_synccache)(CPUState *cs);
+} SemihostingCPUOps;
+
  void common_semi_cb(CPUState *cs, uint64_t ret, int err);
  void do_common_semihosting(CPUState *cs);
  uint64_t common_semi_arg(CPUState *cs, int argno);

Reply via email to