qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] single-binary: compile once semihosting
@ 2025-07-30 22:06 Pierrick Bouvier
  2025-07-30 22:06 ` [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode Pierrick Bouvier
                   ` (9 more replies)
  0 siblings, 10 replies; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

This series compiles once semihosting files in system mode.
The most complicated file was semihosting/arm-compat-semi.c, which was carefully
cleaned in easy to understand steps.

Pierrick Bouvier (10):
  semihosting/syscalls: compile once in system and per target for user
    mode
  semihosting/guestfd: compile once for system/user
  semihosting/arm-compat-semi: remove common_semi_sys_exit_extended
  target/{arm,riscv}/common-semi-target: eradicate target_ulong
  include/semihosting/common-semi: extract common_semi API
  semihosting/arm-compat-semi: eradicate sizeof(target_ulong)
  semihosting/arm-compat-semi: replace target_ulong with uint64_t
  semihosting/arm-compat-semi: replace target_long with int64_t
  semihosting/arm-compat-semi: remove dependency on cpu.h
  semihosting/arm-compat-semi: compile once in system and per target for
    user mode

 include/semihosting/common-semi.h             |  5 ++
 include/semihosting/guestfd.h                 |  7 --
 include/semihosting/semihost.h                |  2 +
 include/semihosting/syscalls.h                | 29 +++---
 semihosting/arm-compat-semi-stub.c            | 19 ++++
 semihosting/arm-compat-semi.c                 | 61 +++++++++----
 semihosting/guestfd.c                         | 26 ++----
 semihosting/syscalls.c                        | 89 +++++++++----------
 ...mon-semi-target.h => common-semi-target.c} | 23 ++---
 ...mon-semi-target.h => common-semi-target.c} | 22 ++---
 semihosting/meson.build                       | 18 ++--
 target/arm/meson.build                        |  4 +
 target/riscv/meson.build                      |  4 +
 13 files changed, 168 insertions(+), 141 deletions(-)
 create mode 100644 semihosting/arm-compat-semi-stub.c
 rename target/arm/{common-semi-target.h => common-semi-target.c} (58%)
 rename target/riscv/{common-semi-target.h => common-semi-target.c} (52%)

-- 
2.47.2



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:13   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 02/10] semihosting/guestfd: compile once for system/user Pierrick Bouvier
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

We replace target_ulong mechanically by uint64_t.
We can't compile (easily) this code once for user, as it relies on
various target/function types, so leave it in specific_ss for user mode.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 include/semihosting/syscalls.h | 29 ++++++-----
 semihosting/arm-compat-semi.c  |  1 +
 semihosting/syscalls.c         | 89 +++++++++++++++++-----------------
 semihosting/meson.build        |  4 +-
 4 files changed, 62 insertions(+), 61 deletions(-)

diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h
index 6627c45fb28..abee23294fb 100644
--- a/include/semihosting/syscalls.h
+++ b/include/semihosting/syscalls.h
@@ -9,7 +9,6 @@
 #ifndef SEMIHOSTING_SYSCALLS_H
 #define SEMIHOSTING_SYSCALLS_H
 
-#include "exec/cpu-defs.h"
 #include "gdbstub/syscalls.h"
 
 /*
@@ -24,23 +23,23 @@
 typedef struct GuestFD GuestFD;
 
 void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong fname, target_ulong fname_len,
+                       uint64_t fname, uint64_t fname_len,
                        int gdb_flags, int mode);
 
 void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete,
                         int fd);
 
 void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                       int fd, target_ulong buf, target_ulong len);
+                       int fd, uint64_t buf, uint64_t len);
 
 void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete,
-                          GuestFD *gf, target_ulong buf, target_ulong len);
+                          GuestFD *gf, uint64_t buf, uint64_t len);
 
 void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete,
-                        int fd, target_ulong buf, target_ulong len);
+                        int fd, uint64_t buf, uint64_t len);
 
 void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete,
-                           GuestFD *gf, target_ulong buf, target_ulong len);
+                           GuestFD *gf, uint64_t buf, uint64_t len);
 
 void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
                         int fd, int64_t off, int gdb_whence);
@@ -50,27 +49,27 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
 
 void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb,
                        gdb_syscall_complete_cb flen_cb,
-                       int fd, target_ulong fstat_addr);
+                       int fd, uint64_t fstat_addr);
 
 void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
-                        int fd, target_ulong addr);
+                        int fd, uint64_t addr);
 
 void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong fname, target_ulong fname_len,
-                       target_ulong addr);
+                       uint64_t fname, uint64_t fname_len,
+                       uint64_t addr);
 
 void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong fname, target_ulong fname_len);
+                         uint64_t fname, uint64_t fname_len);
 
 void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong oname, target_ulong oname_len,
-                         target_ulong nname, target_ulong nname_len);
+                         uint64_t oname, uint64_t oname_len,
+                         uint64_t nname, uint64_t nname_len);
 
 void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong cmd, target_ulong cmd_len);
+                         uint64_t cmd, uint64_t cmd_len);
 
 void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
-                               target_ulong tv_addr, target_ulong tz_addr);
+                               uint64_t tv_addr, uint64_t tz_addr);
 
 void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
                            int fd, GIOCondition cond, int timeout);
diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index 86e5260e504..40dc778529d 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -34,6 +34,7 @@
 #include "qemu/osdep.h"
 #include "qemu/timer.h"
 #include "exec/gdbstub.h"
+#include "cpu.h"
 #include "gdbstub/syscalls.h"
 #include "semihosting/semihost.h"
 #include "semihosting/console.h"
diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c
index f6451d9bb0e..9799a5b08c1 100644
--- a/semihosting/syscalls.c
+++ b/semihosting/syscalls.c
@@ -8,7 +8,6 @@
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
-#include "cpu.h"
 #include "gdbstub/syscalls.h"
 #include "semihosting/guestfd.h"
 #include "semihosting/syscalls.h"
@@ -23,7 +22,7 @@
 /*
  * Validate or compute the length of the string (including terminator).
  */
-static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tlen)
+static int validate_strlen(CPUState *cs, uint64_t str, uint64_t tlen)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char c;
@@ -52,7 +51,7 @@ static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tlen)
 }
 
 static int validate_lock_user_string(char **pstr, CPUState *cs,
-                                     target_ulong tstr, target_ulong tlen)
+                                     uint64_t tstr, uint64_t tlen)
 {
     int ret = validate_strlen(cs, tstr, tlen);
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
@@ -72,7 +71,7 @@ static int validate_lock_user_string(char **pstr, CPUState *cs,
  * big-endian.  Until we do something with gdb, also produce the
  * same big-endian result from the host.
  */
-static int copy_stat_to_user(CPUState *cs, target_ulong addr,
+static int copy_stat_to_user(CPUState *cs, uint64_t addr,
                              const struct stat *s)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
@@ -129,7 +128,7 @@ static void gdb_open_cb(CPUState *cs, uint64_t ret, int err)
 }
 
 static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete,
-                     target_ulong fname, target_ulong fname_len,
+                     uint64_t fname, uint64_t fname_len,
                      int gdb_flags, int mode)
 {
     int len = validate_strlen(cs, fname, fname_len);
@@ -151,14 +150,14 @@ static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                     GuestFD *gf, target_ulong buf, target_ulong len)
+                     GuestFD *gf, uint64_t buf, uint64_t len)
 {
     gdb_do_syscall(complete, "read,%x,%lx,%lx",
                    (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
 }
 
 static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete,
-                      GuestFD *gf, target_ulong buf, target_ulong len)
+                      GuestFD *gf, uint64_t buf, uint64_t len)
 {
     gdb_do_syscall(complete, "write,%x,%lx,%lx",
                    (uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
@@ -178,15 +177,15 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
-                      GuestFD *gf, target_ulong addr)
+                      GuestFD *gf, uint64_t addr)
 {
     gdb_do_syscall(complete, "fstat,%x,%lx",
                    (uint32_t)gf->hostfd, (uint64_t)addr);
 }
 
 static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
-                     target_ulong fname, target_ulong fname_len,
-                     target_ulong addr)
+                     uint64_t fname, uint64_t fname_len,
+                     uint64_t addr)
 {
     int len = validate_strlen(cs, fname, fname_len);
     if (len < 0) {
@@ -199,7 +198,7 @@ static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong fname, target_ulong fname_len)
+                       uint64_t fname, uint64_t fname_len)
 {
     int len = validate_strlen(cs, fname, fname_len);
     if (len < 0) {
@@ -211,8 +210,8 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong oname, target_ulong oname_len,
-                       target_ulong nname, target_ulong nname_len)
+                       uint64_t oname, uint64_t oname_len,
+                       uint64_t nname, uint64_t nname_len)
 {
     int olen, nlen;
 
@@ -233,7 +232,7 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong cmd, target_ulong cmd_len)
+                       uint64_t cmd, uint64_t cmd_len)
 {
     int len = validate_strlen(cs, cmd, cmd_len);
     if (len < 0) {
@@ -245,7 +244,7 @@ static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
-                             target_ulong tv_addr, target_ulong tz_addr)
+                             uint64_t tv_addr, uint64_t tz_addr)
 {
     gdb_do_syscall(complete, "gettimeofday,%lx,%lx",
                    (uint64_t)tv_addr, (uint64_t)tz_addr);
@@ -256,7 +255,7 @@ static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
  */
 
 static void host_open(CPUState *cs, gdb_syscall_complete_cb complete,
-                      target_ulong fname, target_ulong fname_len,
+                      uint64_t fname, uint64_t fname_len,
                       int gdb_flags, int mode)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
@@ -316,7 +315,7 @@ static void host_close(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                      GuestFD *gf, target_ulong buf, target_ulong len)
+                      GuestFD *gf, uint64_t buf, uint64_t len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     void *ptr = lock_user(VERIFY_WRITE, buf, len, 0);
@@ -337,7 +336,7 @@ static void host_read(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_write(CPUState *cs, gdb_syscall_complete_cb complete,
-                       GuestFD *gf, target_ulong buf, target_ulong len)
+                       GuestFD *gf, uint64_t buf, uint64_t len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     void *ptr = lock_user(VERIFY_READ, buf, len, 1);
@@ -395,7 +394,7 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
-                       GuestFD *gf, target_ulong addr)
+                       GuestFD *gf, uint64_t addr)
 {
     struct stat buf;
     int ret;
@@ -410,8 +409,8 @@ static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete,
-                      target_ulong fname, target_ulong fname_len,
-                      target_ulong addr)
+                      uint64_t fname, uint64_t fname_len,
+                      uint64_t addr)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     struct stat buf;
@@ -440,7 +439,7 @@ static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete,
-                        target_ulong fname, target_ulong fname_len)
+                        uint64_t fname, uint64_t fname_len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char *p;
@@ -458,8 +457,8 @@ static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete,
-                        target_ulong oname, target_ulong oname_len,
-                        target_ulong nname, target_ulong nname_len)
+                        uint64_t oname, uint64_t oname_len,
+                        uint64_t nname, uint64_t nname_len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char *ostr, *nstr;
@@ -484,7 +483,7 @@ static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_system(CPUState *cs, gdb_syscall_complete_cb complete,
-                        target_ulong cmd, target_ulong cmd_len)
+                        uint64_t cmd, uint64_t cmd_len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char *p;
@@ -502,7 +501,7 @@ static void host_system(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
-                              target_ulong tv_addr, target_ulong tz_addr)
+                              uint64_t tv_addr, uint64_t tz_addr)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     struct gdb_timeval *p;
@@ -547,10 +546,10 @@ static void host_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
  */
 
 static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                            GuestFD *gf, target_ulong buf, target_ulong len)
+                            GuestFD *gf, uint64_t buf, uint64_t len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
-    target_ulong rest = gf->staticfile.len - gf->staticfile.off;
+    uint64_t rest = gf->staticfile.len - gf->staticfile.off;
     void *ptr;
 
     if (len > rest) {
@@ -605,7 +604,7 @@ static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete,
  */
 
 static void console_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                         GuestFD *gf, target_ulong buf, target_ulong len)
+                         GuestFD *gf, uint64_t buf, uint64_t len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char *ptr;
@@ -622,7 +621,7 @@ static void console_read(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void console_write(CPUState *cs, gdb_syscall_complete_cb complete,
-                          GuestFD *gf, target_ulong buf, target_ulong len)
+                          GuestFD *gf, uint64_t buf, uint64_t len)
 {
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
     char *ptr = lock_user(VERIFY_READ, buf, len, 1);
@@ -638,7 +637,7 @@ static void console_write(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
-                          GuestFD *gf, target_ulong addr)
+                          GuestFD *gf, uint64_t addr)
 {
     static const struct stat tty_buf = {
         .st_mode = 020666,  /* S_IFCHR, ugo+rw */
@@ -683,7 +682,7 @@ static void console_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
  */
 
 void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong fname, target_ulong fname_len,
+                       uint64_t fname, uint64_t fname_len,
                        int gdb_flags, int mode)
 {
     if (use_gdb_syscalls()) {
@@ -719,7 +718,7 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd)
 }
 
 void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete,
-                          GuestFD *gf, target_ulong buf, target_ulong len)
+                          GuestFD *gf, uint64_t buf, uint64_t len)
 {
     /*
      * Bound length for 64-bit guests on 32-bit hosts, not overflowing ssize_t.
@@ -748,7 +747,7 @@ void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete,
-                       int fd, target_ulong buf, target_ulong len)
+                       int fd, uint64_t buf, uint64_t len)
 {
     GuestFD *gf = get_guestfd(fd);
 
@@ -760,7 +759,7 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete,
-                           GuestFD *gf, target_ulong buf, target_ulong len)
+                           GuestFD *gf, uint64_t buf, uint64_t len)
 {
     /*
      * Bound length for 64-bit guests on 32-bit hosts, not overflowing ssize_t.
@@ -790,7 +789,7 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete,
-                        int fd, target_ulong buf, target_ulong len)
+                        int fd, uint64_t buf, uint64_t len)
 {
     GuestFD *gf = get_guestfd(fd);
 
@@ -856,7 +855,7 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd)
 
 void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb,
                        gdb_syscall_complete_cb flen_cb, int fd,
-                       target_ulong fstat_addr)
+                       uint64_t fstat_addr)
 {
     GuestFD *gf = get_guestfd(fd);
 
@@ -881,7 +880,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb,
 }
 
 void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
-                        int fd, target_ulong addr)
+                        int fd, uint64_t addr)
 {
     GuestFD *gf = get_guestfd(fd);
 
@@ -906,8 +905,8 @@ void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete,
-                       target_ulong fname, target_ulong fname_len,
-                       target_ulong addr)
+                       uint64_t fname, uint64_t fname_len,
+                       uint64_t addr)
 {
     if (use_gdb_syscalls()) {
         gdb_stat(cs, complete, fname, fname_len, addr);
@@ -917,7 +916,7 @@ void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong fname, target_ulong fname_len)
+                         uint64_t fname, uint64_t fname_len)
 {
     if (use_gdb_syscalls()) {
         gdb_remove(cs, complete, fname, fname_len);
@@ -927,8 +926,8 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong oname, target_ulong oname_len,
-                         target_ulong nname, target_ulong nname_len)
+                         uint64_t oname, uint64_t oname_len,
+                         uint64_t nname, uint64_t nname_len)
 {
     if (use_gdb_syscalls()) {
         gdb_rename(cs, complete, oname, oname_len, nname, nname_len);
@@ -938,7 +937,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete,
-                         target_ulong cmd, target_ulong cmd_len)
+                         uint64_t cmd, uint64_t cmd_len)
 {
     if (use_gdb_syscalls()) {
         gdb_system(cs, complete, cmd, cmd_len);
@@ -948,7 +947,7 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete,
 }
 
 void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
-                               target_ulong tv_addr, target_ulong tz_addr)
+                               uint64_t tv_addr, uint64_t tz_addr)
 {
     if (use_gdb_syscalls()) {
         gdb_gettimeofday(cs, complete, tv_addr, tz_addr);
diff --git a/semihosting/meson.build b/semihosting/meson.build
index b1ab2506c6e..77200a7f27b 100644
--- a/semihosting/meson.build
+++ b/semihosting/meson.build
@@ -1,6 +1,5 @@
 specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
   'guestfd.c',
-  'syscalls.c',
 ))
 
 common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c'))
@@ -9,9 +8,12 @@ system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
   'config.c',
   'console.c',
   'uaccess.c',
+  'syscalls.c',
 ), if_false: files(
   'stubs-system.c',
 ))
 
+specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'],
+                if_true: files('syscalls.c'))
 specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'],
 		if_true: files('arm-compat-semi.c'))
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/10] semihosting/guestfd: compile once for system/user
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
  2025-07-30 22:06 ` [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:15   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended Pierrick Bouvier
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

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 <pierrick.bouvier@linaro.org>
---
 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;
 
-/*
- * 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);
 
 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-semi-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 <glib.h>
+
+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] = {
     GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND,
 };
 
+/*
+ * 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
 
 /**
@@ -353,6 +360,25 @@ static const uint8_t featurefile_data[] = {
     SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */
 };
 
+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 = GuestFDGDB;
+        console_in_gf.hostfd = 0;
+        console_out_gf.type = GuestFDGDB;
+        console_out_gf.hostfd = 2;
+    } else {
+        console_in_gf.type = GuestFDConsole;
+        console_out_gf.type = 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
 
 static GArray *guestfd_array;
 
-#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 = g_array_new(FALSE, TRUE, sizeof(GuestFD));
 
-#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING
-    /* For ARM-compat, the console is in a separate namespace. */
-    if (use_gdb_syscalls()) {
-        console_in_gf.type = GuestFDGDB;
-        console_in_gf.hostfd = 0;
-        console_out_gf.type = GuestFDGDB;
-        console_out_gf.hostfd = 2;
-    } else {
-        console_in_gf.type = GuestFDConsole;
-        console_out_gf.type = 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 = 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
 }
 
 /*
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'))
 
 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'],
                 if_true: files('syscalls.c'))
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
  2025-07-30 22:06 ` [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode Pierrick Bouvier
  2025-07-30 22:06 ` [PATCH 02/10] semihosting/guestfd: compile once for system/user Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:20   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 04/10] target/{arm, riscv}/common-semi-target: eradicate target_ulong Pierrick Bouvier
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

This allows to get rid of sizeof(target_ulong) for riscv, without
changing the semantic.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target/arm/common-semi-target.h   | 5 -----
 target/riscv/common-semi-target.h | 5 -----
 semihosting/arm-compat-semi.c     | 4 +++-
 3 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.h
index da51f2d7f54..7ebd2136d93 100644
--- a/target/arm/common-semi-target.h
+++ b/target/arm/common-semi-target.h
@@ -34,11 +34,6 @@ static inline void common_semi_set_ret(CPUState *cs, target_ulong ret)
     }
 }
 
-static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr)
-{
-    return nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cpu_env(cs));
-}
-
 static inline bool is_64bit_semihosting(CPUArchState *env)
 {
     return is_a64(env);
diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.h
index 7c8a59e0cc3..63bbcd2d5fa 100644
--- a/target/riscv/common-semi-target.h
+++ b/target/riscv/common-semi-target.h
@@ -25,11 +25,6 @@ static inline void common_semi_set_ret(CPUState *cs, target_ulong ret)
     env->gpr[xA0] = ret;
 }
 
-static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr)
-{
-    return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8);
-}
-
 static inline bool is_64bit_semihosting(CPUArchState *env)
 {
     return riscv_cpu_mxl(env) != MXL_RV32;
diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index 33614108094..1a3abd45c5b 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -755,7 +755,9 @@ void do_common_semihosting(CPUState *cs)
     {
         uint32_t ret;
 
-        if (common_semi_sys_exit_extended(cs, nr)) {
+        bool extended = (nr == TARGET_SYS_EXIT_EXTENDED ||
+                         is_64bit_semihosting(cpu_env(cs)));
+        if (extended) {
             /*
              * The A64 version of SYS_EXIT takes a parameter block,
              * so the application-exit type can return a subcode which
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/10] target/{arm, riscv}/common-semi-target: eradicate target_ulong
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (2 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:23   ` [PATCH 04/10] target/{arm,riscv}/common-semi-target: " Richard Henderson
  2025-07-30 22:06 ` [PATCH 05/10] include/semihosting/common-semi: extract common_semi API Pierrick Bouvier
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

We replace mechanically with uint64_t.
There is no semantic change, and allows us to extract a proper API from
this set of functions.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target/arm/common-semi-target.h   | 6 +++---
 target/riscv/common-semi-target.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.h
index 7ebd2136d93..b900121272c 100644
--- a/target/arm/common-semi-target.h
+++ b/target/arm/common-semi-target.h
@@ -12,7 +12,7 @@
 
 #include "target/arm/cpu-qom.h"
 
-static inline target_ulong common_semi_arg(CPUState *cs, int argno)
+static inline uint64_t common_semi_arg(CPUState *cs, int argno)
 {
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
@@ -23,7 +23,7 @@ static inline target_ulong common_semi_arg(CPUState *cs, int argno)
     }
 }
 
-static inline void common_semi_set_ret(CPUState *cs, target_ulong ret)
+static inline void common_semi_set_ret(CPUState *cs, uint64_t ret)
 {
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
@@ -39,7 +39,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env)
     return is_a64(env);
 }
 
-static inline target_ulong common_semi_stack_bottom(CPUState *cs)
+static inline uint64_t common_semi_stack_bottom(CPUState *cs)
 {
     ARMCPU *cpu = ARM_CPU(cs);
     CPUARMState *env = &cpu->env;
diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.h
index 63bbcd2d5fa..2e6d6a659a3 100644
--- a/target/riscv/common-semi-target.h
+++ b/target/riscv/common-semi-target.h
@@ -11,14 +11,14 @@
 #ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H
 #define TARGET_RISCV_COMMON_SEMI_TARGET_H
 
-static inline target_ulong common_semi_arg(CPUState *cs, int argno)
+static inline 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, target_ulong ret)
+static inline void common_semi_set_ret(CPUState *cs, uint64_t ret)
 {
     RISCVCPU *cpu = RISCV_CPU(cs);
     CPURISCVState *env = &cpu->env;
@@ -30,7 +30,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env)
     return riscv_cpu_mxl(env) != MXL_RV32;
 }
 
-static inline target_ulong common_semi_stack_bottom(CPUState *cs)
+static inline uint64_t common_semi_stack_bottom(CPUState *cs)
 {
     RISCVCPU *cpu = RISCV_CPU(cs);
     CPURISCVState *env = &cpu->env;
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/10] include/semihosting/common-semi: extract common_semi API
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (3 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 04/10] target/{arm, riscv}/common-semi-target: eradicate target_ulong Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:28   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong) Pierrick Bouvier
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, 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.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 include/semihosting/common-semi.h              |  5 +++++
 semihosting/arm-compat-semi.c                  |  3 +--
 ...mmon-semi-target.h => common-semi-target.c} | 18 ++++++++----------
 ...mmon-semi-target.h => common-semi-target.c} | 17 ++++++++---------
 target/arm/meson.build                         |  4 ++++
 target/riscv/meson.build                       |  4 ++++
 6 files changed, 30 insertions(+), 21 deletions(-)
 rename target/arm/{common-semi-target.h => common-semi-target.c} (66%)
 rename target/riscv/{common-semi-target.h => common-semi-target.c} (60%)

diff --git a/include/semihosting/common-semi.h b/include/semihosting/common-semi.h
index 0a91db7c414..9b8524dca13 100644
--- a/include/semihosting/common-semi.h
+++ b/include/semihosting/common-semi.h
@@ -35,5 +35,10 @@
 #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);
+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 1a3abd45c5b..5a04ce55ca9 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 66%
rename from target/arm/common-semi-target.h
rename to target/arm/common-semi-target.c
index b900121272c..bad33a711d7 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,22 +34,20 @@ static inline void common_semi_set_ret(CPUState *cs, uint64_t ret)
     }
 }
 
-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 60%
rename from target/riscv/common-semi-target.h
rename to target/riscv/common-semi-target.c
index 2e6d6a659a3..7ac8b9164ee 100644
--- a/target/riscv/common-semi-target.h
+++ b/target/riscv/common-semi-target.c
@@ -8,38 +8,37 @@
  * 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 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 07d9271aa4d..688b50a2e26 100644
--- a/target/arm/meson.build
+++ b/target/arm/meson.build
@@ -27,12 +27,16 @@ arm_user_ss.add(files(
   'helper.c',
   'vfp_fpscr.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.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong)
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (4 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 05/10] include/semihosting/common-semi: extract common_semi API Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:28   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t Pierrick Bouvier
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

No semantic change.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 semihosting/arm-compat-semi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index 5a04ce55ca9..e5a665d604b 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -787,7 +787,7 @@ void do_common_semihosting(CPUState *cs)
 
     case TARGET_SYS_ELAPSED:
         elapsed = get_clock() - clock_start;
-        if (sizeof(target_ulong) == 8) {
+        if (is_64bit_semihosting(env)) {
             if (SET_ARG(0, elapsed)) {
                 goto do_fault;
             }
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (5 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong) Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-07-31 23:33   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t Pierrick Bouvier
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 semihosting/arm-compat-semi.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index e5a665d604b..e3b520631b3 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -123,7 +123,7 @@ GuestFD console_out_gf;
  */
 
 typedef struct LayoutInfo {
-    target_ulong rambase;
+    uint64_t rambase;
     size_t ramsize;
     hwaddr heapbase;
     hwaddr heaplimit;
@@ -214,7 +214,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs)
  * global, and we assume that the guest takes care of avoiding any races.
  */
 #ifndef CONFIG_USER_ONLY
-static target_ulong syscall_err;
+static uint64_t syscall_err;
 
 #include "semihosting/uaccess.h"
 #endif
@@ -260,8 +260,8 @@ static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err)
 {
     /* Recover the original length from the third argument. */
     CPUArchState *env G_GNUC_UNUSED = cpu_env(cs);
-    target_ulong args = common_semi_arg(cs, 1);
-    target_ulong arg2;
+    uint64_t args = common_semi_arg(cs, 1);
+    uint64_t arg2;
     GET_ARG(2);
 
     if (err) {
@@ -300,9 +300,9 @@ static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err)
  * is defined by GDB's remote protocol and is not target-specific.)
  * We put this on the guest's stack just below SP.
  */
-static target_ulong common_semi_flen_buf(CPUState *cs)
+static uint64_t common_semi_flen_buf(CPUState *cs)
 {
-    target_ulong sp = common_semi_stack_bottom(cs);
+    uint64_t sp = common_semi_stack_bottom(cs);
     return sp - 64;
 }
 
@@ -389,9 +389,9 @@ void semihosting_arm_compatible_init(void)
 void do_common_semihosting(CPUState *cs)
 {
     CPUArchState *env = cpu_env(cs);
-    target_ulong args;
-    target_ulong arg0, arg1, arg2, arg3;
-    target_ulong ul_ret;
+    uint64_t args;
+    uint64_t arg0, arg1, arg2, arg3;
+    uint64_t ul_ret;
     char * s;
     int nr;
     int64_t elapsed;
@@ -462,7 +462,7 @@ void do_common_semihosting(CPUState *cs)
 
     case TARGET_SYS_WRITEC:
         /*
-         * FIXME: the byte to be written is in a target_ulong slot,
+         * FIXME: the byte to be written is in a uint64_t slot,
          * which means this is wrong for a big-endian guest.
          */
         semihost_sys_write_gf(cs, common_semi_dead_cb,
@@ -688,11 +688,11 @@ void do_common_semihosting(CPUState *cs)
 
     case TARGET_SYS_HEAPINFO:
         {
-            target_ulong retvals[4];
+            uint64_t retvals[4];
             int i;
 #ifdef CONFIG_USER_ONLY
             TaskState *ts = get_task_state(cs);
-            target_ulong limit;
+            uint64_t limit;
 #else
             LayoutInfo info = common_semi_find_bases(cs);
 #endif
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (6 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-08-01  1:25   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h Pierrick Bouvier
  2025-07-30 22:06 ` [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode Pierrick Bouvier
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 semihosting/arm-compat-semi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index e3b520631b3..715a22528ab 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -502,7 +502,7 @@ void do_common_semihosting(CPUState *cs)
 
     case TARGET_SYS_ISERROR:
         GET_ARG(0);
-        common_semi_set_ret(cs, (target_long)arg0 < 0);
+        common_semi_set_ret(cs, (int64_t)arg0 < 0);
         break;
 
     case TARGET_SYS_ISTTY:
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (7 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-08-01  1:26   ` Richard Henderson
  2025-07-30 22:06 ` [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode Pierrick Bouvier
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 semihosting/arm-compat-semi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index 715a22528ab..703db038a4e 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -34,7 +34,6 @@
 #include "qemu/osdep.h"
 #include "qemu/timer.h"
 #include "exec/gdbstub.h"
-#include "cpu.h"
 #include "gdbstub/syscalls.h"
 #include "semihosting/semihost.h"
 #include "semihosting/console.h"
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode
  2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
                   ` (8 preceding siblings ...)
  2025-07-30 22:06 ` [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h Pierrick Bouvier
@ 2025-07-30 22:06 ` Pierrick Bouvier
  2025-08-01  1:26   ` Richard Henderson
  9 siblings, 1 reply; 25+ messages in thread
From: Pierrick Bouvier @ 2025-07-30 22:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	richard.henderson, qemu-riscv, Alistair Francis, Pierrick Bouvier

We don't have any target dependency left in system mode, so we can
compile once.

User mode depends on qemu.h, which is duplicated between linux and bsd,
so we can't easily compile it once.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 semihosting/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/semihosting/meson.build b/semihosting/meson.build
index bb0db323937..99f10e2e2bb 100644
--- a/semihosting/meson.build
+++ b/semihosting/meson.build
@@ -12,9 +12,10 @@ system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
   'stubs-system.c',
 ))
 system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING',
+  if_true: files('arm-compat-semi.c'),
   if_false: files('arm-compat-semi-stub.c'))
 
 specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'],
                 if_true: files('syscalls.c'))
-specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'],
+specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING', 'CONFIG_USER_ONLY'],
 		if_true: files('arm-compat-semi.c'))
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode
  2025-07-30 22:06 ` [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode Pierrick Bouvier
@ 2025-07-31 23:13   ` Richard Henderson
  2025-08-01  1:42     ` Pierrick Bouvier
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:13 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> We replace target_ulong mechanically by uint64_t.
> We can't compile (easily) this code once for user, as it relies on
> various target/function types, so leave it in specific_ss for user mode.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   include/semihosting/syscalls.h | 29 ++++++-----
>   semihosting/arm-compat-semi.c  |  1 +
>   semihosting/syscalls.c         | 89 +++++++++++++++++-----------------
>   semihosting/meson.build        |  4 +-
>   4 files changed, 62 insertions(+), 61 deletions(-)

We can at least use vaddr for the pointers, like fname.

I see syscalls.c already uses uint64_t in many of those places, but that can be a separate 
cleanup -- we don't need to add more.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 02/10] semihosting/guestfd: compile once for system/user
  2025-07-30 22:06 ` [PATCH 02/10] semihosting/guestfd: compile once for system/user Pierrick Bouvier
@ 2025-07-31 23:15   ` Richard Henderson
  2025-08-01  1:41     ` Pierrick Bouvier
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:15 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> 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] = {
>       GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND,
>   };
>   
> +/*
> + * 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;

These can now be static.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended
  2025-07-30 22:06 ` [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended Pierrick Bouvier
@ 2025-07-31 23:20   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:20 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> This allows to get rid of sizeof(target_ulong) for riscv, without
> changing the semantic.
> 
> Signed-off-by: Pierrick Bouvier<pierrick.bouvier@linaro.org>
> ---
>   target/arm/common-semi-target.h   | 5 -----
>   target/riscv/common-semi-target.h | 5 -----
>   semihosting/arm-compat-semi.c     | 4 +++-
>   3 files changed, 3 insertions(+), 11 deletions(-)

I suspect riscv32 should have matched riscv64 in always supporting extended, and that this 
was blind copying of the aarch32/aarch64 code.  However, what's done is done.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 04/10] target/{arm,riscv}/common-semi-target: eradicate target_ulong
  2025-07-30 22:06 ` [PATCH 04/10] target/{arm, riscv}/common-semi-target: eradicate target_ulong Pierrick Bouvier
@ 2025-07-31 23:23   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:23 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> We replace mechanically with uint64_t.
> There is no semantic change, and allows us to extract a proper API from
> this set of functions.
> 
> Signed-off-by: Pierrick Bouvier<pierrick.bouvier@linaro.org>
> ---
>   target/arm/common-semi-target.h   | 6 +++---
>   target/riscv/common-semi-target.h | 6 +++---
>   2 files changed, 6 insertions(+), 6 deletions(-)


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/10] include/semihosting/common-semi: extract common_semi API
  2025-07-30 22:06 ` [PATCH 05/10] include/semihosting/common-semi: extract common_semi API Pierrick Bouvier
@ 2025-07-31 23:28   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:28 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> 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.
> 
> Signed-off-by: Pierrick Bouvier<pierrick.bouvier@linaro.org>
> ---
>   include/semihosting/common-semi.h              |  5 +++++
>   semihosting/arm-compat-semi.c                  |  3 +--
>   ...mmon-semi-target.h => common-semi-target.c} | 18 ++++++++----------
>   ...mmon-semi-target.h => common-semi-target.c} | 17 ++++++++---------
>   target/arm/meson.build                         |  4 ++++
>   target/riscv/meson.build                       |  4 ++++
>   6 files changed, 30 insertions(+), 21 deletions(-)
>   rename target/arm/{common-semi-target.h => common-semi-target.c} (66%)
>   rename target/riscv/{common-semi-target.h => common-semi-target.c} (60%)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong)
  2025-07-30 22:06 ` [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong) Pierrick Bouvier
@ 2025-07-31 23:28   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:28 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> No semantic change.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   semihosting/arm-compat-semi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index 5a04ce55ca9..e5a665d604b 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -787,7 +787,7 @@ void do_common_semihosting(CPUState *cs)
>   
>       case TARGET_SYS_ELAPSED:
>           elapsed = get_clock() - clock_start;
> -        if (sizeof(target_ulong) == 8) {
> +        if (is_64bit_semihosting(env)) {
>               if (SET_ARG(0, elapsed)) {
>                   goto do_fault;
>               }

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t
  2025-07-30 22:06 ` [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t Pierrick Bouvier
@ 2025-07-31 23:33   ` Richard Henderson
  2025-08-01  1:40     ` Pierrick Bouvier
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Henderson @ 2025-07-31 23:33 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   semihosting/arm-compat-semi.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index e5a665d604b..e3b520631b3 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -123,7 +123,7 @@ GuestFD console_out_gf;
>    */
>   
>   typedef struct LayoutInfo {
> -    target_ulong rambase;
> +    uint64_t rambase;

vaddr.


> @@ -300,9 +300,9 @@ static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err)
>    * is defined by GDB's remote protocol and is not target-specific.)
>    * We put this on the guest's stack just below SP.
>    */
> -static target_ulong common_semi_flen_buf(CPUState *cs)
> +static uint64_t common_semi_flen_buf(CPUState *cs)
>   {
> -    target_ulong sp = common_semi_stack_bottom(cs);
> +    uint64_t sp = common_semi_stack_bottom(cs);
>       return sp - 64;
>   }
>   

vaddr.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t
  2025-07-30 22:06 ` [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t Pierrick Bouvier
@ 2025-08-01  1:25   ` Richard Henderson
  2025-08-01  1:39     ` Pierrick Bouvier
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Henderson @ 2025-08-01  1:25 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   semihosting/arm-compat-semi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index e3b520631b3..715a22528ab 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -502,7 +502,7 @@ void do_common_semihosting(CPUState *cs)
>   
>       case TARGET_SYS_ISERROR:
>           GET_ARG(0);
> -        common_semi_set_ret(cs, (target_long)arg0 < 0);
> +        common_semi_set_ret(cs, (int64_t)arg0 < 0);
>           break;
>   
>       case TARGET_SYS_ISTTY:

Here we have a semantic change.  For 32-bit, we used get_user_u32, so this will always 
return false.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h
  2025-07-30 22:06 ` [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h Pierrick Bouvier
@ 2025-08-01  1:26   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-08-01  1:26 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   semihosting/arm-compat-semi.c | 1 -
>   1 file changed, 1 deletion(-)
> 
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index 715a22528ab..703db038a4e 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -34,7 +34,6 @@
>   #include "qemu/osdep.h"
>   #include "qemu/timer.h"
>   #include "exec/gdbstub.h"
> -#include "cpu.h"
>   #include "gdbstub/syscalls.h"
>   #include "semihosting/semihost.h"
>   #include "semihosting/console.h"

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode
  2025-07-30 22:06 ` [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode Pierrick Bouvier
@ 2025-08-01  1:26   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-08-01  1:26 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 08:06, Pierrick Bouvier wrote:
> We don't have any target dependency left in system mode, so we can
> compile once.
> 
> User mode depends on qemu.h, which is duplicated between linux and bsd,
> so we can't easily compile it once.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   semihosting/meson.build | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/semihosting/meson.build b/semihosting/meson.build
> index bb0db323937..99f10e2e2bb 100644
> --- a/semihosting/meson.build
> +++ b/semihosting/meson.build
> @@ -12,9 +12,10 @@ system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
>     'stubs-system.c',
>   ))
>   system_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING',
> +  if_true: files('arm-compat-semi.c'),
>     if_false: files('arm-compat-semi-stub.c'))
>   
>   specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_USER_ONLY'],
>                   if_true: files('syscalls.c'))
> -specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'],
> +specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING', 'CONFIG_USER_ONLY'],
>   		if_true: files('arm-compat-semi.c'))

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t
  2025-08-01  1:25   ` Richard Henderson
@ 2025-08-01  1:39     ` Pierrick Bouvier
  0 siblings, 0 replies; 25+ messages in thread
From: Pierrick Bouvier @ 2025-08-01  1:39 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 6:25 PM, Richard Henderson wrote:
> On 7/31/25 08:06, Pierrick Bouvier wrote:
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    semihosting/arm-compat-semi.c | 2 +-
>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
>> index e3b520631b3..715a22528ab 100644
>> --- a/semihosting/arm-compat-semi.c
>> +++ b/semihosting/arm-compat-semi.c
>> @@ -502,7 +502,7 @@ void do_common_semihosting(CPUState *cs)
>>    
>>        case TARGET_SYS_ISERROR:
>>            GET_ARG(0);
>> -        common_semi_set_ret(cs, (target_long)arg0 < 0);
>> +        common_semi_set_ret(cs, (int64_t)arg0 < 0);
>>            break;
>>    
>>        case TARGET_SYS_ISTTY:
> 
> Here we have a semantic change.  For 32-bit, we used get_user_u32, so this will always
> return false.
> 

Right... I'll add the intermediate missing cast based on 
is_64bit_semihosting(env).

Thanks,
Pierrick

> 
> r~



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t
  2025-07-31 23:33   ` Richard Henderson
@ 2025-08-01  1:40     ` Pierrick Bouvier
  0 siblings, 0 replies; 25+ messages in thread
From: Pierrick Bouvier @ 2025-08-01  1:40 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 4:33 PM, Richard Henderson wrote:
> On 7/31/25 08:06, Pierrick Bouvier wrote:
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    semihosting/arm-compat-semi.c | 24 ++++++++++++------------
>>    1 file changed, 12 insertions(+), 12 deletions(-)
>>
>> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
>> index e5a665d604b..e3b520631b3 100644
>> --- a/semihosting/arm-compat-semi.c
>> +++ b/semihosting/arm-compat-semi.c
>> @@ -123,7 +123,7 @@ GuestFD console_out_gf;
>>     */
>>    
>>    typedef struct LayoutInfo {
>> -    target_ulong rambase;
>> +    uint64_t rambase;
> 
> vaddr.
> 
> 
>> @@ -300,9 +300,9 @@ static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err)
>>     * is defined by GDB's remote protocol and is not target-specific.)
>>     * We put this on the guest's stack just below SP.
>>     */
>> -static target_ulong common_semi_flen_buf(CPUState *cs)
>> +static uint64_t common_semi_flen_buf(CPUState *cs)
>>    {
>> -    target_ulong sp = common_semi_stack_bottom(cs);
>> +    uint64_t sp = common_semi_stack_bottom(cs);
>>        return sp - 64;
>>    }
>>    
> 
> vaddr.
> 

Will change to it, thanks.

> Otherwise,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> r~



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 02/10] semihosting/guestfd: compile once for system/user
  2025-07-31 23:15   ` Richard Henderson
@ 2025-08-01  1:41     ` Pierrick Bouvier
  0 siblings, 0 replies; 25+ messages in thread
From: Pierrick Bouvier @ 2025-08-01  1:41 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 4:15 PM, Richard Henderson wrote:
> On 7/31/25 08:06, Pierrick Bouvier wrote:
>> 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] = {
>>        GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND,
>>    };
>>    
>> +/*
>> + * 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;
> 
> These can now be static.
>

Yes, I forgot to reapply that from my initial series when cleaning it 
up. Thanks.

> Otherwise,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> 
> r~



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode
  2025-07-31 23:13   ` Richard Henderson
@ 2025-08-01  1:42     ` Pierrick Bouvier
  0 siblings, 0 replies; 25+ messages in thread
From: Pierrick Bouvier @ 2025-08-01  1:42 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel
  Cc: Daniel Henrique Barboza, Peter Maydell, qemu-arm,
	Alex Bennée, Weiwei Li, philmd, Liu Zhiwei, Palmer Dabbelt,
	qemu-riscv, Alistair Francis

On 7/31/25 4:13 PM, Richard Henderson wrote:
> On 7/31/25 08:06, Pierrick Bouvier wrote:
>> We replace target_ulong mechanically by uint64_t.
>> We can't compile (easily) this code once for user, as it relies on
>> various target/function types, so leave it in specific_ss for user mode.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    include/semihosting/syscalls.h | 29 ++++++-----
>>    semihosting/arm-compat-semi.c  |  1 +
>>    semihosting/syscalls.c         | 89 +++++++++++++++++-----------------
>>    semihosting/meson.build        |  4 +-
>>    4 files changed, 62 insertions(+), 61 deletions(-)
> 
> We can at least use vaddr for the pointers, like fname.
> 
> I see syscalls.c already uses uint64_t in many of those places, but that can be a separate
> cleanup -- we don't need to add more.
>

I preferred to do a mechanical change, given where it's used. Anyway, 
I'll replace that using vaddr where appropriate.

> 
> r~



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2025-08-01  1:45 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 22:06 [PATCH 00/10] single-binary: compile once semihosting Pierrick Bouvier
2025-07-30 22:06 ` [PATCH 01/10] semihosting/syscalls: compile once in system and per target for user mode Pierrick Bouvier
2025-07-31 23:13   ` Richard Henderson
2025-08-01  1:42     ` Pierrick Bouvier
2025-07-30 22:06 ` [PATCH 02/10] semihosting/guestfd: compile once for system/user Pierrick Bouvier
2025-07-31 23:15   ` Richard Henderson
2025-08-01  1:41     ` Pierrick Bouvier
2025-07-30 22:06 ` [PATCH 03/10] semihosting/arm-compat-semi: remove common_semi_sys_exit_extended Pierrick Bouvier
2025-07-31 23:20   ` Richard Henderson
2025-07-30 22:06 ` [PATCH 04/10] target/{arm, riscv}/common-semi-target: eradicate target_ulong Pierrick Bouvier
2025-07-31 23:23   ` [PATCH 04/10] target/{arm,riscv}/common-semi-target: " Richard Henderson
2025-07-30 22:06 ` [PATCH 05/10] include/semihosting/common-semi: extract common_semi API Pierrick Bouvier
2025-07-31 23:28   ` Richard Henderson
2025-07-30 22:06 ` [PATCH 06/10] semihosting/arm-compat-semi: eradicate sizeof(target_ulong) Pierrick Bouvier
2025-07-31 23:28   ` Richard Henderson
2025-07-30 22:06 ` [PATCH 07/10] semihosting/arm-compat-semi: replace target_ulong with uint64_t Pierrick Bouvier
2025-07-31 23:33   ` Richard Henderson
2025-08-01  1:40     ` Pierrick Bouvier
2025-07-30 22:06 ` [PATCH 08/10] semihosting/arm-compat-semi: replace target_long with int64_t Pierrick Bouvier
2025-08-01  1:25   ` Richard Henderson
2025-08-01  1:39     ` Pierrick Bouvier
2025-07-30 22:06 ` [PATCH 09/10] semihosting/arm-compat-semi: remove dependency on cpu.h Pierrick Bouvier
2025-08-01  1:26   ` Richard Henderson
2025-07-30 22:06 ` [PATCH 10/10] semihosting/arm-compat-semi: compile once in system and per target for user mode Pierrick Bouvier
2025-08-01  1:26   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).