[PATCH v3 1/1] target: Add system emulation aiming to target any architecture

2024-02-15 Thread Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé 

Add the 'any'-architecture target.

- Only consider 64-bit targets
- Do not use any hardware accelerator (except qtest)
- For architecture constants, use:
  . max of supported targets phys/virt address space
  . max of supported targets MMU modes
  . min of supported targets variable page bits

Build as:

  $ ../configure --target-list=any-softmmu \
 --disable-hvf \
 --disable-kvm \
 --disable-nvmm \
 --disable-tcg \
 --disable-whpx \
 --disable-xen

Test as:

  $ qemu-system-any -M none,accel=qtest -monitor stdio
  QEMU 6.2.50 monitor - type 'help' for more information
  (qemu) info mtree
  address-space: I/O
- (prio 0, i/o): io

  address-space: memory
- (prio 0, i/o): system

  (qemu) info qom-tree
  /machine (none-machine)
/peripheral (container)
/peripheral-anon (container)
/unattached (container)
  /io[0] (memory-region)
  /sysbus (System)
  /system[0] (memory-region)
  (qemu) info qtree
  bus: main-system-bus
type System
  (qemu) info cpus
  (qemu)

Signed-off-by: Philippe Mathieu-Daudé 
---
 configs/devices/any-softmmu/default.mak |  9 +
 configs/targets/any-softmmu.mak |  3 +++
 meson.build |  6 --
 qapi/machine.json   |  2 +-
 include/sysemu/arch_init.h  |  1 +
 target/any/cpu-param.h  | 13 +
 target/any/cpu-qom.h| 12 
 target/any/cpu.h| 24 
 .gitlab-ci.d/buildtest.yml  | 20 
 hw/any/meson.build  |  5 +
 hw/meson.build  |  1 +
 target/Kconfig  |  1 +
 target/any/Kconfig  |  4 
 target/any/meson.build  |  7 +++
 target/meson.build  |  1 +
 15 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 configs/devices/any-softmmu/default.mak
 create mode 100644 configs/targets/any-softmmu.mak
 create mode 100644 target/any/cpu-param.h
 create mode 100644 target/any/cpu-qom.h
 create mode 100644 target/any/cpu.h
 create mode 100644 hw/any/meson.build
 create mode 100644 target/any/Kconfig
 create mode 100644 target/any/meson.build

diff --git a/configs/devices/any-softmmu/default.mak 
b/configs/devices/any-softmmu/default.mak
new file mode 100644
index 00..dab0ce770e
--- /dev/null
+++ b/configs/devices/any-softmmu/default.mak
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+CONFIG_ISA_BUS=y
+CONFIG_PCI=y
+CONFIG_PCI_DEVICES=y
+CONFIG_I2C=y
+CONFIG_TPM=y
+CONFIG_NUBUS=y
+CONFIG_VIRTIO=y
diff --git a/configs/targets/any-softmmu.mak b/configs/targets/any-softmmu.mak
new file mode 100644
index 00..2c6cf1edd4
--- /dev/null
+++ b/configs/targets/any-softmmu.mak
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+TARGET_ARCH=any
diff --git a/meson.build b/meson.build
index c1dc83e4c0..f6aee8218b 100644
--- a/meson.build
+++ b/meson.build
@@ -46,7 +46,7 @@ qapi_trace_events = []
 bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 
'darwin']
 supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 
'sunos', 'linux']
 supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 
'x86_64',
-  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
+  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'any']
 
 cpu = host_machine.cpu_family()
 
@@ -3043,7 +3043,9 @@ foreach target : target_dirs
 if default_targets
   continue
 endif
-error('No accelerator available for target @0@'.format(target))
+if 'any-softmmu' not in target_dirs
+  error('No accelerator available for target @0@'.format(target))
+endif
   endif
 
   actual_target_dirs += target
diff --git a/qapi/machine.json b/qapi/machine.json
index d816c5c02e..8d3dcd5fb4 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -36,7 +36,7 @@
  'mips64el', 'mipsel', 'nios2', 'or1k', 'ppc',
  'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
  'sh4eb', 'sparc', 'sparc64', 'tricore',
- 'x86_64', 'xtensa', 'xtensaeb' ] }
+ 'x86_64', 'xtensa', 'xtensaeb', 'any' ] }
 
 ##
 # @CpuS390State:
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 8850cb1a14..49bee75610 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -4,6 +4,7 @@
 
 enum {
 QEMU_ARCH_ALL = -1,
+QEMU_ARCH_ANY = -1,
 QEMU_ARCH_ALPHA = (1 << 0),
 QEMU_ARCH_ARM = (1 << 1),
 QEMU_ARCH_CRIS = (1 << 2),
diff --git a/target/any/cpu-param.h b/target/any/cpu-param.h
new file mode 100644
index 00..42e38ae991
--- /dev/null
+++ b/target/any/cpu-param.h
@@ -0,0 

Re: [PATCH v3 1/1] target: Add system emulation aiming to target any architecture

2024-02-15 Thread Manos Pitsidianakis

On Thu, 15 Feb 2024 10:46, Philippe Mathieu-Daudé  wrote:

From: Philippe Mathieu-Daudé 

Add the 'any'-architecture target.

- Only consider 64-bit targets
- Do not use any hardware accelerator (except qtest)
- For architecture constants, use:
 . max of supported targets phys/virt address space
 . max of supported targets MMU modes
 . min of supported targets variable page bits

Build as:

 $ ../configure --target-list=any-softmmu \
--disable-hvf \
--disable-kvm \
--disable-nvmm \
--disable-tcg \
--disable-whpx \
--disable-xen

Test as:

 $ qemu-system-any -M none,accel=qtest -monitor stdio
 QEMU 6.2.50 monitor - type 'help' for more information


6.2.50? :)


 (qemu) info mtree
 address-space: I/O
   - (prio 0, i/o): io

 address-space: memory
   - (prio 0, i/o): system

 (qemu) info qom-tree
 /machine (none-machine)
   /peripheral (container)
   /peripheral-anon (container)
   /unattached (container)
 /io[0] (memory-region)
 /sysbus (System)
 /system[0] (memory-region)
 (qemu) info qtree
 bus: main-system-bus
   type System
 (qemu) info cpus
 (qemu)

Signed-off-by: Philippe Mathieu-Daudé 
---
configs/devices/any-softmmu/default.mak |  9 +
configs/targets/any-softmmu.mak |  3 +++
meson.build |  6 --
qapi/machine.json   |  2 +-
include/sysemu/arch_init.h  |  1 +
target/any/cpu-param.h  | 13 +
target/any/cpu-qom.h| 12 
target/any/cpu.h| 24 
.gitlab-ci.d/buildtest.yml  | 20 
hw/any/meson.build  |  5 +
hw/meson.build  |  1 +
target/Kconfig  |  1 +
target/any/Kconfig  |  4 
target/any/meson.build  |  7 +++
target/meson.build  |  1 +
15 files changed, 106 insertions(+), 3 deletions(-)
create mode 100644 configs/devices/any-softmmu/default.mak
create mode 100644 configs/targets/any-softmmu.mak
create mode 100644 target/any/cpu-param.h
create mode 100644 target/any/cpu-qom.h
create mode 100644 target/any/cpu.h
create mode 100644 hw/any/meson.build
create mode 100644 target/any/Kconfig
create mode 100644 target/any/meson.build

diff --git a/configs/devices/any-softmmu/default.mak 
b/configs/devices/any-softmmu/default.mak
new file mode 100644
index 00..dab0ce770e
--- /dev/null
+++ b/configs/devices/any-softmmu/default.mak
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+CONFIG_ISA_BUS=y
+CONFIG_PCI=y
+CONFIG_PCI_DEVICES=y
+CONFIG_I2C=y
+CONFIG_TPM=y
+CONFIG_NUBUS=y
+CONFIG_VIRTIO=y
diff --git a/configs/targets/any-softmmu.mak b/configs/targets/any-softmmu.mak
new file mode 100644
index 00..2c6cf1edd4
--- /dev/null
+++ b/configs/targets/any-softmmu.mak
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+TARGET_ARCH=any
diff --git a/meson.build b/meson.build
index c1dc83e4c0..f6aee8218b 100644
--- a/meson.build
+++ b/meson.build
@@ -46,7 +46,7 @@ qapi_trace_events = []
bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 
'darwin']
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 
'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 
'x86_64',
-  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
+  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'any']

cpu = host_machine.cpu_family()

@@ -3043,7 +3043,9 @@ foreach target : target_dirs
if default_targets
  continue
endif
-error('No accelerator available for target @0@'.format(target))
+if 'any-softmmu' not in target_dirs
+  error('No accelerator available for target @0@'.format(target))
+endif
  endif

  actual_target_dirs += target
diff --git a/qapi/machine.json b/qapi/machine.json
index d816c5c02e..8d3dcd5fb4 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -36,7 +36,7 @@
 'mips64el', 'mipsel', 'nios2', 'or1k', 'ppc',
 'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
 'sh4eb', 'sparc', 'sparc64', 'tricore',
- 'x86_64', 'xtensa', 'xtensaeb' ] }
+ 'x86_64', 'xtensa', 'xtensaeb', 'any' ] }


This array looks alphabetically sorted (before the `any`), might that be 
on purpose?




##
# @CpuS390State:
diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 8850cb1a14..49bee75610 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -4,6 +4,7 @@

enum {
QEMU_ARCH_ALL = -1,
+QEMU_ARCH_ANY = -1,
QEMU_ARCH_ALPHA = (1 << 0),
QEMU_ARCH_ARM = (1 << 1),
QEMU_ARCH_CRIS = (1 << 2),
diff --git a/target/any/cpu-param.h b/target/any/cpu-param.h
new file mode

Re: [PATCH v3 1/1] target: Add system emulation aiming to target any architecture

2024-02-15 Thread Philippe Mathieu-Daudé

On 15/2/24 14:02, Manos Pitsidianakis wrote:
On Thu, 15 Feb 2024 10:46, Philippe Mathieu-Daudé  
wrote:

From: Philippe Mathieu-Daudé 

Add the 'any'-architecture target.

- Only consider 64-bit targets
- Do not use any hardware accelerator (except qtest)
- For architecture constants, use:
 . max of supported targets phys/virt address space
 . max of supported targets MMU modes
 . min of supported targets variable page bits

Build as:

 $ ../configure --target-list=any-softmmu \
    --disable-hvf \
    --disable-kvm \
    --disable-nvmm \
    --disable-tcg \
    --disable-whpx \
    --disable-xen

Test as:

 $ qemu-system-any -M none,accel=qtest -monitor stdio
 QEMU 6.2.50 monitor - type 'help' for more information


6.2.50? :)


Time passed...

LGTM in general overall. In case this wasn't discussed already, would it 
be a good idea to name the target x-any if it ends up in a stable release?


This will end in stable releases. Do you mean distribution releases?
They don't include qemu-system-all and we don't use x-all. Why would
a distrib want to include a pointless binary? :)


Regardless of my inlined style comments:

Reviewed-by: Manos Pitsidianakis 


Thanks!