Skip to contentSkip to conversation

monitor: Remove need of per-target handlers

PATCH Superseded Philippe Mathieu-Daudé 4 participants 40 messages Apr 14 – Apr 27

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover monitor: Remove need of per-target handlers

Missing review: 1-3, 16, 18

Since v2:
- Addressed rth review comments

Changes needed for the single binary (and heterogeneous emulation).

Convert target_monitor_defs() and target_monitor_defs() to SysemuCPUOps fields, adapting the 4 targets using these 'legacy' code.

Instead of filtering the commands per target / device at build time, add a new field to HMPCommand to filter them at runtime, allowing to compile the command array once.

Philippe Mathieu-Daudé (27):
stubs: Rename monitor* -> qmp* files
monitor/meson: Use SPICE with migration HMP commands
monitor: Restrict monitor_set_cpu() method scope
monitor: Make 'info via' a generic command
monitor: Make Xen emulation commands generic ones
system: Expose 'arch_init.h' as 'qemu/base-arch-defs.h'
monitor: Introduce HMPCommand::arch_bitmask field hw/s390x: Reduce 'monitor/monitor.h' inclusions
monitor: Do not check TARGET_S390X to build s390x commands
monitor: Do not check TARGET_I386 to build target/i386/ commands
monitor: Do not check TARGET_I386 to build 'info sgx' command
monitor: Do not check TARGET_I386 to build 'info sev' command
monitor: Do not check TARGET_I386/RISCV to build 'info mem' command
monitor: Do not check multiple TARGET_* to build 'info tlb' command
cpus: Introduce SysemuCPUOps::monitor_get_register() hook target/riscv: Register target_get_monitor_def in SysemuCPUOps
monitor: Remove target_get_monitor_def()
monitor: Have MonitorDef::get_value() always return int64_t type
monitor: Reduce target-specific methods further
monitor: Remove 'monitor/hmp-target.h' header
monitor: Forward-declare the MonitorDef type
cpus: Introduce SysemuCPUOps::monitor_defs hook target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs target/sparc: Replace target_monitor_defs ->
SysemuCPUOps::monitor_defs
monitor: Remove target_monitor_defs()
monitor: Merge hmp-target.c code within hmp-cmds.c

 MAINTAINERS                                   |  14 ++-
 include/hw/core/sysemu-cpu-ops.h              |  14 +++
 include/hw/s390x/storage-attributes.h         |   4 -
 include/hw/s390x/storage-keys.h               |   3 -
 include/monitor/hmp-target.h                  |  46 -------
 include/monitor/hmp.h                         |  21 ++++
 include/monitor/monitor.h                     |   1 -
 .../qemu/base-arch-defs.h                     |  10 +-
 include/qemu/typedefs.h                       |   1 +
 monitor/monitor-internal.h                    |  13 +-
 target/riscv/internals.h                      |   3 +
 hw/i386/kvm/xen-stubs.c                       |  12 ++
 hw/i386/sgx-hmp-stub.c                        |  16 +++
 hw/i386/sgx-stub.c                            |   6 -
 hw/i386/sgx.c                                 |   1 -
 hw/misc/mos6522-stub.c                        |  16 +++
 hw/pci/pci.c                                  |   2 +-
 hw/s390x/s390-skeys.c                         |   2 +
 hw/s390x/s390-stattrib.c                      |   2 +
 monitor/hmp-cmds.c                            |  41 ++++++-
 monitor/hmp-target.c                          | 115 ------------------
 monitor/hmp.c                                 |  45 ++++++-
 stubs/hmp-cmd-info_mem.c                      |  12 ++
 stubs/hmp-cmd-info_sev.c                      |  16 +++
 stubs/hmp-cmd-info_tlb.c                      |  12 ++
 stubs/hmp-cmds-hw-s390x.c                     |  15 +++
 stubs/hmp-cmds-target-i386.c                  |  13 ++
 stubs/{monitor-arm-gic.c => qmp-arm-gic.c}    |   0
 ...or-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |   0
 .../{monitor-cpu-s390x.c => qmp-cpu-s390x.c}  |   0
 stubs/{monitor-cpu.c => qmp-cpu.c}            |   0
 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}  |   0
 stubs/{monitor-i386-sev.c => qmp-i386-sev.c}  |   0
 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}  |   0
 stubs/{monitor-i386-xen.c => qmp-i386-xen.c}  |   0
 stubs/target-get-monitor-def.c                |  29 -----
 stubs/target-monitor-defs.c                   |   7 --
 system/arch_init.c                            |   2 +-
 system/qdev-monitor.c                         |   2 +-
 system/vl.c                                   |   2 +-
 target/i386/cpu-apic.c                        |   1 -
 target/i386/cpu.c                             |  29 +++++
 target/i386/monitor.c                         |  26 ----
 target/i386/sev-system-stub.c                 |   6 -
 target/i386/sev.c                             |   1 -
 target/m68k/cpu.c                             |  18 +++
 target/m68k/monitor.c                         |  22 ----
 target/ppc/monitor.c                          |   2 -
 target/riscv/cpu.c                            |   1 +
 target/riscv/monitor.c                        |  12 +-
 target/sh4/monitor.c                          |   1 -
 target/sparc/cpu.c                            |  19 +++
 target/sparc/monitor.c                        |  19 ---
 target/xtensa/monitor.c                       |   1 -
 hmp-commands-info.hx                          |  26 ++--
 hmp-commands.hx                               |  13 +-
 hw/i386/meson.build                           |   1 +
 hw/misc/meson.build                           |   1 +
 migration/meson.build                         |   2 +-
 monitor/meson.build                           |   5 +-
 stubs/meson.build                             |  23 ++--
 61 files changed, 375 insertions(+), 352 deletions(-)
 delete mode 100644 include/monitor/hmp-target.h
 rename system/arch_init.h => include/qemu/base-arch-defs.h (92%)
 create mode 100644 hw/i386/sgx-hmp-stub.c
 create mode 100644 hw/misc/mos6522-stub.c
 delete mode 100644 monitor/hmp-target.c
 create mode 100644 stubs/hmp-cmd-info_mem.c
 create mode 100644 stubs/hmp-cmd-info_sev.c
 create mode 100644 stubs/hmp-cmd-info_tlb.c
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
 create mode 100644 stubs/hmp-cmds-target-i386.c
 rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%)
 rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%)
 rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%)
 rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
 rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%)
 rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%)
 rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%)
 rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)
 delete mode 100644 stubs/target-get-monitor-def.c
 delete mode 100644 stubs/target-monitor-defs.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/27 stubs: Rename monitor* -> qmp* files

We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'.

---
 MAINTAINERS                                      |  6 ++++++
 stubs/{monitor-arm-gic.c => qmp-arm-gic.c}       |  0
 ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |  0
 stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c}   |  0
 stubs/{monitor-cpu.c => qmp-cpu.c}               |  0
 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}     |  0
 stubs/{monitor-i386-sev.c => qmp-i386-sev.c}     |  0
 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}     |  0
 stubs/{monitor-i386-xen.c => qmp-i386-xen.c}     |  0
 stubs/meson.build                                | 16 ++++++++--------
 10 files changed, 14 insertions(+), 8 deletions(-)
 rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%)
 rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%)
 rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%)
 rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
 rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%)
 rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%)
 rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%)
 rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)
MAINTAINERS +6 -0
index 535d1d3398e..eb212c31ac2 100644
@@ -121,6 +121,7 @@ F: include/hw/s390x/
 F: include/hw/watchdog/wdt_diag288.h
 F: pc-bios/s390-ccw/
 F: pc-bios/s390-ccw.img
+F: stubs/qmp-cpu-s390x.c
 F: target/s390x/
 F: docs/system/target-s390x.rst
 F: docs/system/s390x/
@@ -496,6 +497,7 @@ M: Christian Borntraeger <[email protected]>
 R: Eric Farman <[email protected]>
 R: Matthew Rosato <[email protected]>
 S: Supported
+F: stubs/qmp-cpu-s390x-kvm.c
 F: target/s390x/kvm/
 F: target/s390x/machine.c
 F: target/s390x/sigp.c
@@ -510,6 +512,8 @@ L: [email protected]
 S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
+F: stubs/qmp-i386-sev.c
+F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
 F: target/i386/sev*
 F: scripts/kvm/vmxcap
@@ -522,6 +526,7 @@ S: Supported
 F: include/system/kvm_xen.h
 F: target/i386/kvm/xen*
 F: hw/i386/kvm/xen*
+F: stubs/qmp-i386-xen.c
 F: tests/functional/x86_64/test_kvm_xen.py
 
 Guest CPU Cores (other accelerators)
@@ -800,6 +805,7 @@ F: include/hw/timer/a9gtimer.h
 F: include/hw/timer/arm_mptimer.h
 F: include/hw/timer/armv7m_systick.h
 F: include/hw/misc/armv7m_ras.h
+F: stubs/qmp-arm-gic.c
 F: tests/qtest/test-arm-mptimer.c
 
 Bananapi M2U
stubs/qmp-arm-gic.c renamed from stubs/monitor-arm-gic.c +0 -0
similarity index 100%
rename from stubs/monitor-arm-gic.c
rename to stubs/qmp-arm-gic.c
stubs/qmp-cpu-s390x-kvm.c renamed from stubs/monitor-cpu-s390x-kvm.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu-s390x-kvm.c
rename to stubs/qmp-cpu-s390x-kvm.c
stubs/qmp-cpu-s390x.c renamed from stubs/monitor-cpu-s390x.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu-s390x.c
rename to stubs/qmp-cpu-s390x.c
stubs/qmp-cpu.c renamed from stubs/monitor-cpu.c +0 -0
similarity index 100%
rename from stubs/monitor-cpu.c
rename to stubs/qmp-cpu.c
stubs/qmp-i386-rtc.c renamed from stubs/monitor-i386-rtc.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-rtc.c
rename to stubs/qmp-i386-rtc.c
stubs/qmp-i386-sev.c renamed from stubs/monitor-i386-sev.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-sev.c
rename to stubs/qmp-i386-sev.c
stubs/qmp-i386-sgx.c renamed from stubs/monitor-i386-sgx.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-sgx.c
rename to stubs/qmp-i386-sgx.c
stubs/qmp-i386-xen.c renamed from stubs/monitor-i386-xen.c +0 -0
similarity index 100%
rename from stubs/monitor-i386-xen.c
rename to stubs/qmp-i386-xen.c
stubs/meson.build +8 -8
index 7189ff63ed5..2d334a5a8f3 100644
@@ -78,14 +78,14 @@ if have_system
   stub_ss.add(files('target-monitor-defs.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
-  stub_ss.add(files('monitor-arm-gic.c'))
-  stub_ss.add(files('monitor-i386-rtc.c'))
-  stub_ss.add(files('monitor-i386-sev.c'))
-  stub_ss.add(files('monitor-i386-sgx.c'))
-  stub_ss.add(files('monitor-i386-xen.c'))
-  stub_ss.add(files('monitor-cpu.c'))
-  stub_ss.add(files('monitor-cpu-s390x.c'))
-  stub_ss.add(files('monitor-cpu-s390x-kvm.c'))
+  stub_ss.add(files('qmp-arm-gic.c'))
+  stub_ss.add(files('qmp-i386-rtc.c'))
+  stub_ss.add(files('qmp-i386-sev.c'))
+  stub_ss.add(files('qmp-i386-sgx.c'))
+  stub_ss.add(files('qmp-i386-xen.c'))
+  stub_ss.add(files('qmp-cpu.c'))
+  stub_ss.add(files('qmp-cpu-s390x.c'))
+  stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
Reviewed-by on v3 1/27
#2 lore raw

Re: [PATCH v3 01/27] stubs: Rename monitor* -> qmp* files

Quoted 17 lines · Philippe Mathieu-Daudé

We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'.

---
  MAINTAINERS                                      |  6 ++++++
  stubs/{monitor-arm-gic.c => qmp-arm-gic.c}       |  0
  ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |  0
  stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c}   |  0
  stubs/{monitor-cpu.c => qmp-cpu.c}               |  0
  stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}     |  0
  stubs/{monitor-i386-sev.c => qmp-i386-sev.c}     |  0
  stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}     |  0
  stubs/{monitor-i386-xen.c => qmp-i386-xen.c}     |  0
  stubs/meson.build                                | 16 ++++++++--------
  10 files changed, 14 insertions(+), 8 deletions(-)
Quoted 8 lines

rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%) rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%) rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%) rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%) rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%) rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%) rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)

r~

Acked-by on v3 1/27
#3 lore raw

Re: [PATCH v3 01/27] stubs: Rename monitor* -> qmp* files

In reply to Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé

We use 'HMP' for Human monitor and 'QMP' for 'Machine protocol'. These files aren't about human monitor but QMP, so rename them for clarity using the 'qmp-' prefix instead of 'monitor-'.

---
 MAINTAINERS                                      |  6 ++++++
 stubs/{monitor-arm-gic.c => qmp-arm-gic.c}       |  0
 ...nitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} |  0
 stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c}   |  0
 stubs/{monitor-cpu.c => qmp-cpu.c}               |  0
 stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c}     |  0
 stubs/{monitor-i386-sev.c => qmp-i386-sev.c}     |  0
 stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c}     |  0
 stubs/{monitor-i386-xen.c => qmp-i386-xen.c}     |  0
 stubs/meson.build                                | 16 ++++++++--------
 10 files changed, 14 insertions(+), 8 deletions(-)
Quoted 8 lines
 rename stubs/{monitor-arm-gic.c => qmp-arm-gic.c} (100%)
 rename stubs/{monitor-cpu-s390x-kvm.c => qmp-cpu-s390x-kvm.c} (100%)
 rename stubs/{monitor-cpu-s390x.c => qmp-cpu-s390x.c} (100%)
 rename stubs/{monitor-cpu.c => qmp-cpu.c} (100%)
 rename stubs/{monitor-i386-rtc.c => qmp-i386-rtc.c} (100%)
 rename stubs/{monitor-i386-sev.c => qmp-i386-sev.c} (100%)
 rename stubs/{monitor-i386-sgx.c => qmp-i386-sgx.c} (100%)
 rename stubs/{monitor-i386-xen.c => qmp-i386-xen.c} (100%)
#4 lore raw

PATCH v3 2/27 monitor/meson: Use SPICE with migration HMP commands

In reply to Philippe Mathieu-Daudé

When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags.

---
 migration/meson.build | 2 +-
 monitor/meson.build   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
migration/meson.build +1 -1
index c9f0f5f9f21..e583822dec6 100644
@@ -23,7 +23,6 @@ system_ss.add(files(
   'fd.c',
   'file.c',
   'global_state.c',
-  'migration-hmp-cmds.c',
   'migration.c',
   'multifd.c',
   'multifd-device-state.c',
@@ -37,6 +36,7 @@ system_ss.add(files(
   'socket.c',
   'tls.c',
 ), gnutls, zlib)
+system_ss.add([spice_headers, files('migration-hmp-cmds.c'), spice])
 
 if get_option('replication').allowed()
   system_ss.add(files('colo-failover.c', 'colo.c', 'multifd-colo.c'))
monitor/meson.build +2 -2
index 2647100e04c..585251804e4 100644
@@ -5,8 +5,8 @@ system_ss.add(files(
   'hmp-cmds.c',
   'hmp.c',
   'qemu-config-qmp.c',
+  'qmp-cmds.c',
 ))
-system_ss.add([spice_headers, files('qmp-cmds.c')])
 
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
-                if_true: [files('hmp-target.c'), spice])
+                if_true: [files('hmp-target.c')])
Signature · 1 line
2.53.0
Reviewed-by on v3 2/27
#5 lore raw

Re: [PATCH v3 02/27] monitor/meson: Use SPICE with migration HMP commands

Quoted 9 lines · Philippe Mathieu-Daudé

When moving code around in commit 27be86351ec ("migration: Move the QMP command from monitor/ to migration/") we forgot to update the meson rule about SPICE pkg-config flags.

---
  migration/meson.build | 2 +-
  monitor/meson.build   | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)

r~

#6 lore raw

PATCH v3 3/27 monitor: Restrict monitor_set_cpu() method scope

In reply to Philippe Mathieu-Daudé

As mentioned in commit 755f196898e ("qapi: Convert the cpu command") 15 years ago, the monitor_set_cpu() method is a temporary bridge between QMP -> HMP and shouldn't be used elsewhere. Make its scope internal to monitor/.

---
 include/monitor/monitor.h  | 1 -
 monitor/monitor-internal.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/monitor/monitor.h +0 -1
index 296690e1f1c..55649a86641 100644
@@ -37,7 +37,6 @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 void monitor_printc(Monitor *mon, int ch);
 void monitor_flush(Monitor *mon);
-int monitor_set_cpu(Monitor *mon, int cpu_index);
 int monitor_get_cpu_index(Monitor *mon);
 
 int monitor_puts_locked(Monitor *mon, const char *str);
monitor/monitor-internal.h +1 -0
index feca111ae31..80b4a8150bf 100644
@@ -175,6 +175,7 @@ void monitor_data_destroy(Monitor *mon);
 int monitor_can_read(void *opaque);
 void monitor_list_append(Monitor *mon);
 void monitor_fdsets_cleanup(void);
+int monitor_set_cpu(Monitor *mon, int cpu_index);
 
 void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
 void monitor_data_destroy_qmp(MonitorQMP *mon);
Signature · 1 line
2.53.0
Reviewed-by on v3 3/27
#7 lore raw

Re: [PATCH v3 03/27] monitor: Restrict monitor_set_cpu() method scope

Quoted 10 lines · Philippe Mathieu-Daudé

As mentioned in commit 755f196898e ("qapi: Convert the cpu command") 15 years ago, the monitor_set_cpu() method is a temporary bridge between QMP -> HMP and shouldn't be used elsewhere. Make its scope internal to monitor/.

---
  include/monitor/monitor.h  | 1 -
  monitor/monitor-internal.h | 1 +
  2 files changed, 1 insertion(+), 1 deletion(-)

r~

#8 lore raw

PATCH v3 4/27 monitor: Make 'info via' a generic command

In reply to Philippe Mathieu-Daudé

In order to build hmp-commands-info.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the device is not available.

---
 MAINTAINERS            |  2 +-
 hw/misc/mos6522-stub.c | 16 ++++++++++++++++
 hmp-commands-info.hx   |  2 --
 hw/misc/meson.build    |  1 +
 4 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 hw/misc/mos6522-stub.c
MAINTAINERS +1 -1
index eb212c31ac2..cf462793a79 100644
@@ -1558,7 +1558,7 @@ F: hw/ppc/mac_newworld.c
 F: hw/pci-host/uninorth.c
 F: hw/pci-bridge/dec.[hc]
 F: hw/misc/macio/
-F: hw/misc/mos6522.c
+F: hw/misc/mos6522*.c
 F: hw/nvram/mac_nvram.c
 F: hw/ppc/fw_cfg.c
 F: hw/input/adb*
hw/misc/mos6522-stub.c new file +16 -0
new file mode 100644
index 00000000000..85eb0ee36ee
@@ -0,0 +1,16 @@
+/*
+ * QEMU MOS6522 VIA stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
+
+void hmp_info_via(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "MOS6522 VIA is not available in this QEMU\n");
+}
hmp-commands-info.hx +0 -2
index 74c741f80e2..463038c302a 100644
@@ -885,7 +885,6 @@ SRST
     Show intel SGX information.
 ERST
 
-#if defined(CONFIG_MOS6522)
     {
         .name         = "via",
         .args_type    = "",
@@ -893,7 +892,6 @@ ERST
         .help         = "show guest mos6522 VIA devices",
         .cmd          = hmp_info_via,
     },
-#endif
 
 SRST
   ``info via``
hw/misc/meson.build +1 -0
index cd084a19363..fa6a961ac9a 100644
@@ -20,6 +20,7 @@ system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c'))
 
 # Mac devices
 system_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c'))
+stub_ss.add(files('mos6522-stub.c'))
 system_ss.add(when: 'CONFIG_DJMEMC', if_true: files('djmemc.c'))
 system_ss.add(when: 'CONFIG_IOSB', if_true: files('iosb.c'))
 
Signature · 1 line
2.53.0
#9 lore raw

PATCH v3 5/27 monitor: Make Xen emulation commands generic ones

In reply to Philippe Mathieu-Daudé

In order to build hmp-commands.hx once we need to stop using device target-specific check. Use the generic pattern to make the command available on all targets, providing a stub with kind error message when the feature is not available.

---
 hw/i386/kvm/xen-stubs.c | 12 ++++++++++++
 hmp-commands.hx         |  2 --
 2 files changed, 12 insertions(+), 2 deletions(-)
hw/i386/kvm/xen-stubs.c +12 -0
index ce73119ee7a..bf6ac28bef4 100644
@@ -12,6 +12,8 @@
 #include "qemu/osdep.h"
 
 #include "qapi/error.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
 
 #include "xen_evtchn.h"
 #include "xen_primary_console.h"
@@ -37,3 +39,13 @@ void xen_primary_console_create(void)
 void xen_primary_console_set_be_port(uint16_t port)
 {
 }
+
+void hmp_xen_event_list(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "XEN emulation is not available in this QEMU\n");
+}
+
+void hmp_xen_event_inject(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "XEN emulation is not available in this QEMU\n");
+}
hmp-commands.hx +0 -2
index 5cc4788f12d..06d7b17bf25 100644
@@ -1839,7 +1839,6 @@ SRST
 ERST
 #endif
 
-#if defined(CONFIG_XEN_EMU)
     {
         .name       = "xen-event-inject",
         .args_type  = "port:i",
@@ -1866,4 +1865,3 @@ SRST
 ``xen-event-list``
   List event channels in the guest
 ERST
-#endif
Signature · 1 line
2.53.0
#10 lore raw

PATCH v3 6/27 system: Expose 'arch_init.h' as 'qemu/base-arch-defs.h'

In reply to Philippe Mathieu-Daudé

We already have a file unit outside of the local system' folder which include "system/arch_init.h". We want more files to use it, so make it official it is a generic header by moving it under include. Rename as "qemu/base-arch-defs.h" which is more descriptive.

---
 system/arch_init.h => include/qemu/base-arch-defs.h | 10 ++++++++--
 hw/pci/pci.c                                        |  2 +-
 system/arch_init.c                                  |  2 +-
 system/qdev-monitor.c                               |  2 +-
 system/vl.c                                         |  2 +-
 5 files changed, 12 insertions(+), 6 deletions(-)
 rename system/arch_init.h => include/qemu/base-arch-defs.h (92%)
include/qemu/base-arch-defs.h renamed from system/arch_init.h +8 -2
similarity index 92%
rename from system/arch_init.h
rename to include/qemu/base-arch-defs.h
index 0c2b1f3a5d0..f33465738c9 100644
@@ -1,5 +1,11 @@
-#ifndef QEMU_ARCH_INIT_H
-#define QEMU_ARCH_INIT_H
+/*
+ * QEMU base architecture bit definitions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_BASE_ARCH_DEFS_H
+#define QEMU_BASE_ARCH_DEFS_H
 
 #include "qapi/qapi-types-machine.h"
 
hw/pci/pci.c +1 -1
index 2c3657d00de..a38dffd4899 100644
@@ -36,7 +36,7 @@
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
 #include "net/net.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/numa.h"
 #include "system/runstate.h"
 #include "system/system.h"
system/arch_init.c +1 -1
index 604d5909ed0..1ad2f3d6f78 100644
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/bitops.h"
 #include "qemu/target-info-qapi.h"
 
system/qdev-monitor.c +1 -1
index 2ed95e83602..2e9dbb9b5c2 100644
@@ -23,7 +23,7 @@
 #include "monitor/hmp-completion.h"
 #include "monitor/monitor.h"
 #include "monitor/qdev.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/runstate.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-qdev.h"
system/vl.c +1 -1
index 0e1fc217b4f..c89fe8378c5 100644
@@ -112,7 +112,7 @@
 #include "trace/control.h"
 #include "qemu/plugin.h"
 #include "qemu/queue.h"
-#include "system/arch_init.h"
+#include "qemu/base-arch-defs.h"
 #include "system/confidential-guest-support.h"
 
 #include "ui/qemu-spice.h"
Signature · 1 line
2.53.0
#11 lore raw

PATCH v3 7/27 monitor: Introduce HMPCommand::arch_bitmask field

In reply to Philippe Mathieu-Daudé

Add the @arch_bitmask field to the HMPCommand structure, allowing to restrict a command to a set of target architectures (represented by the QEMU_ARCH_* enum constants).

---
 monitor/monitor-internal.h | 11 ++++++++++-
 monitor/hmp-target.c       |  1 +
 monitor/hmp.c              |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
monitor/monitor-internal.h +10 -1
index 80b4a8150bf..eaf9a607783 100644
@@ -82,7 +82,6 @@ typedef struct HMPCommand {
      * the formatted text.
      */
     HumanReadableText *(*cmd_info_hrt)(Error **errp);
-    bool coroutine;
     /*
      * @sub_table is a list of 2nd level of commands. If it does not exist,
      * cmd should be used. If it exists, sub_table[?].cmd should be
@@ -90,6 +89,16 @@ typedef struct HMPCommand {
      */
     struct HMPCommand *sub_table;
     void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
+
+    /* Keep non-pointer data at the end to minimize holes. */
+
+    /**
+     * @arch_bitmask: bitmask of QEMU_ARCH_* constants
+     *     Allow to restrict the command for a particular set of
+     *     target architectures.
+     */
+    uint32_t arch_bitmask;
+    bool coroutine;
 } HMPCommand;
 
 struct Monitor {
monitor/hmp-target.c +1 -0
index da7dd7f31f2..f6dce326cf5 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "monitor-internal.h"
 #include "monitor/qdev.h"
 #include "net/slirp.h"
monitor/hmp.c +4 -0
index 0e5913fabb1..e881c26c305 100644
@@ -36,6 +36,7 @@
 #include "qemu/cutils.h"
 #include "qemu/log.h"
 #include "qemu/option.h"
+#include "qemu/base-arch-defs.h"
 #include "qemu/target-info.h"
 #include "qemu/units.h"
 #include "exec/gdbstub.h"
@@ -219,6 +220,9 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)
 
 static bool cmd_available(const HMPCommand *cmd)
 {
+    if (cmd->arch_bitmask && !qemu_arch_available(cmd->arch_bitmask)) {
+        return false;
+    }
     return phase_check(PHASE_MACHINE_READY) || cmd_can_preconfig(cmd);
 }
 
Signature · 1 line
2.53.0
#12 lore raw

PATCH v3 8/27 hw/s390x: Reduce 'monitor/monitor.h' inclusions

In reply to Philippe Mathieu-Daudé

We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files.

---
 include/hw/s390x/storage-attributes.h | 4 ----
 include/hw/s390x/storage-keys.h       | 3 ---
 include/monitor/hmp.h                 | 5 +++++
 hw/s390x/s390-skeys.c                 | 2 ++
 hw/s390x/s390-stattrib.c              | 2 ++
 5 files changed, 9 insertions(+), 7 deletions(-)
include/hw/s390x/storage-attributes.h +0 -4
index 66716a97c05..0305873b019 100644
@@ -13,7 +13,6 @@
 #define S390_STORAGE_ATTRIBUTES_H
 
 #include "hw/core/qdev.h"
-#include "monitor/monitor.h"
 #include "qom/object.h"
 
 #define TYPE_S390_STATTRIB "s390-storage_attributes"
@@ -72,7 +71,4 @@ static inline Object *kvm_s390_stattrib_create(void)
 }
 #endif
 
-void hmp_info_cmma(Monitor *mon, const QDict *qdict);
-void hmp_migrationmode(Monitor *mon, const QDict *qdict);
-
 #endif /* S390_STORAGE_ATTRIBUTES_H */
include/hw/s390x/storage-keys.h +0 -3
index 2d02936c31c..666c05e2996 100644
@@ -13,7 +13,6 @@
 #define S390_STORAGE_KEYS_H
 
 #include "hw/core/qdev.h"
-#include "monitor/monitor.h"
 #include "qom/object.h"
 
 #define TYPE_S390_SKEYS "s390-skeys"
@@ -123,8 +122,6 @@ int s390_skeys_set(S390SKeysState *ks, uint64_t start_gfn,
 S390SKeysState *s390_get_skeys_device(void);
 
 void s390_qmp_dump_skeys(const char *filename, Error **errp);
-void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
-void hmp_info_skeys(Monitor *mon, const QDict *qdict);
 
 #define TYPE_DUMP_SKEYS_INTERFACE "dump-skeys-interface"
 
include/monitor/hmp.h +5 -0
index 9c2330205fc..d694bfdf768 100644
@@ -173,4 +173,9 @@ void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
 void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
 void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
 
+void hmp_dump_skeys(Monitor *mon, const QDict *qdict);
+void hmp_info_skeys(Monitor *mon, const QDict *qdict);
+void hmp_info_cmma(Monitor *mon, const QDict *qdict);
+void hmp_migrationmode(Monitor *mon, const QDict *qdict);
+
 #endif
hw/s390x/s390-skeys.c +2 -0
index d974d97b5e7..7dca67d6618 100644
@@ -24,6 +24,8 @@
 #include "system/kvm.h"
 #include "migration/qemu-file-types.h"
 #include "migration/register.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
 #include "trace.h"
 
 #define S390_SKEYS_BUFFER_SIZE (128 * KiB)  /* Room for 128k storage keys */
hw/s390x/s390-stattrib.c +2 -0
index 2e83aa211cd..74b23b0a995 100644
@@ -15,6 +15,8 @@
 #include "system/ram_addr.h"
 #include "migration/qemu-file.h"
 #include "migration/register.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/s390x/storage-attributes.h"
 #include "qemu/error-report.h"
Signature · 1 line
2.53.0
Reviewed-by on v3 8/27
#13 lore raw

Re: [PATCH v3 08/27] hw/s390x: Reduce 'monitor/monitor.h' inclusions

Quoted 7 lines · Philippe Mathieu-Daudé

We want to make the HMP commands available for all targets, move the declarations to "monitor/hmp.h" where all other are, and only include the monitor headers in the source files.

Quoted 7 lines
---
 include/hw/s390x/storage-attributes.h | 4 ----
 include/hw/s390x/storage-keys.h       | 3 ---
 include/monitor/hmp.h                 | 5 +++++
 hw/s390x/s390-skeys.c                 | 2 ++
 hw/s390x/s390-stattrib.c              | 2 ++
 5 files changed, 9 insertions(+), 7 deletions(-)
#14 lore raw

PATCH v3 9/27 monitor: Do not check TARGET_S390X to build s390x commands

In reply to Philippe Mathieu-Daudé

These commands are filtered at build-time for s390x binary. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since the methods are used inconditionally within hw/s390x/, define them in the same stub file.

---
 MAINTAINERS               |  1 +
 include/monitor/hmp.h     |  7 +++++++
 monitor/hmp-target.c      |  5 -----
 stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++
 hmp-commands-info.hx      |  6 ++----
 hmp-commands.hx           |  6 ++----
 stubs/meson.build         |  1 +
 7 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
MAINTAINERS +1 -0
index cf462793a79..306835ff678 100644
@@ -122,6 +122,7 @@ F: include/hw/watchdog/wdt_diag288.h
 F: pc-bios/s390-ccw/
 F: pc-bios/s390-ccw.img
 F: stubs/qmp-cpu-s390x.c
+F: stubs/hmp-cmds-hw-s390x.c
 F: target/s390x/
 F: docs/system/target-s390x.rst
 F: docs/system/s390x/
include/monitor/hmp.h +7 -0
index d694bfdf768..a29185741b8 100644
@@ -16,6 +16,13 @@
 
 #include "qemu/readline.h"
 #include "qapi/qapi-types-common.h"
+#include "monitor/monitor.h"
+
+#define HMP_STUB(cmd) \
+    void hmp_##cmd(Monitor *mon, const QDict *qdict) \
+    { \
+        g_assert_not_reached(); \
+    }
 
 bool hmp_handle_error(Monitor *mon, Error *err);
 void hmp_help_cmd(Monitor *mon, const char *name);
monitor/hmp-target.c +0 -5
index f6dce326cf5..a222fd4c96a 100644
@@ -36,11 +36,6 @@
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-machine.h"
 
-#if defined(TARGET_S390X)
-#include "hw/s390x/storage-keys.h"
-#include "hw/s390x/storage-attributes.h"
-#endif
-
 /* Make devices configuration available for use in hmp-commands*.hx templates */
 #include CONFIG_DEVICES
 
stubs/hmp-cmds-hw-s390x.c new file +15 -0
new file mode 100644
index 00000000000..2b4f4cac79f
@@ -0,0 +1,15 @@
+/*
+ * Human Monitor hw/s390x stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(dump_skeys)
+HMP_STUB(info_cmma)
+HMP_STUB(info_skeys)
+HMP_STUB(migrationmode)
hmp-commands-info.hx +2 -4
index 463038c302a..28dec25642d 100644
@@ -717,30 +717,28 @@ SRST
     Show rocker OF-DPA groups.
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "skeys",
         .args_type  = "addr:l",
         .params     = "address",
         .help       = "Display the value of a storage key",
         .cmd        = hmp_info_skeys,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
   ``info skeys`` *address*
     Display the value of a storage key (s390 only)
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "cmma",
         .args_type  = "addr:l,count:l?",
         .params     = "address [count]",
         .help       = "Display the values of the CMMA storage attributes for a range of pages",
         .cmd        = hmp_info_cmma,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
   ``info cmma`` *address*
hmp-commands.hx +2 -4
index 06d7b17bf25..ff65b39b454 100644
@@ -1125,30 +1125,28 @@ SRST
 
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "dump-skeys",
         .args_type  = "filename:F",
         .params     = "",
         .help       = "Save guest storage keys into file 'filename'.\n",
         .cmd        = hmp_dump_skeys,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
 ``dump-skeys`` *filename*
   Save guest storage keys to a file.
 ERST
 
-#if defined(TARGET_S390X)
     {
         .name       = "migration_mode",
         .args_type  = "mode:i",
         .params     = "mode",
         .help       = "Enables or disables migration mode\n",
         .cmd        = hmp_migrationmode,
+        .arch_bitmask = QEMU_ARCH_S390X,
     },
-#endif
 
 SRST
 ``migration_mode`` *mode*
stubs/meson.build +1 -0
index 2d334a5a8f3..32c16209543 100644
@@ -86,6 +86,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmds-hw-s390x.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
Reviewed-by on v3 9/27
#15 lore raw

Re: [PATCH v3 09/27] monitor: Do not check TARGET_S390X to build s390x commands

Quoted 6 lines · Philippe Mathieu-Daudé

These commands are filtered at build-time for s390x binary. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since the methods are used inconditionally within hw/s390x/,

unconditionally

Quoted 5 lines

define them in the same stub file.

Quoted 10 lines
---
 MAINTAINERS               |  1 +
 include/monitor/hmp.h     |  7 +++++++
 monitor/hmp-target.c      |  5 -----
 stubs/hmp-cmds-hw-s390x.c | 15 +++++++++++++++
 hmp-commands-info.hx      |  6 ++----
 hmp-commands.hx           |  6 ++----
 stubs/meson.build         |  1 +
 7 files changed, 28 insertions(+), 13 deletions(-)
 create mode 100644 stubs/hmp-cmds-hw-s390x.c
#16 lore raw

PATCH v3 10/27 monitor: Do not check TARGET_I386 to build target/i386/ commands

In reply to Philippe Mathieu-Daudé

These commands are filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands[-info].hx files once.

Since these methods are used inconditionally within target/i386/, define them in the same stub file.

---
 MAINTAINERS                  |  1 +
 stubs/hmp-cmds-target-i386.c | 13 +++++++++++++
 hmp-commands-info.hx         |  4 +---
 hmp-commands.hx              |  5 +----
 stubs/meson.build            |  1 +
 5 files changed, 17 insertions(+), 7 deletions(-)
 create mode 100644 stubs/hmp-cmds-target-i386.c
MAINTAINERS +1 -0
index 306835ff678..a0c8f484163 100644
@@ -148,6 +148,7 @@ F: configs/targets/i386-softmmu.mak
 F: configs/targets/x86_64-softmmu.mak
 F: docs/system/i386/
 F: docs/system/target-i386*
+F: stubs/hmp-cmds-target-i386.c
 F: target/i386/*.[ch]
 F: target/i386/Kconfig
 F: target/i386/meson.build
stubs/hmp-cmds-target-i386.c new file +13 -0
new file mode 100644
index 00000000000..43a167056d5
@@ -0,0 +1,13 @@
+/*
+ * Human Monitor x86 stubs
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_local_apic)
+HMP_STUB(mce)
hmp-commands-info.hx +1 -3
index 28dec25642d..b575e4ac993 100644
@@ -113,16 +113,14 @@ SRST
     Show the cpu registers.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "lapic",
         .args_type  = "apic-id:i?",
         .params     = "[apic-id]",
         .help       = "show local apic state (apic-id: local apic to read, default is which of current CPU)",
-
         .cmd        = hmp_info_local_apic,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info lapic``
hmp-commands.hx +1 -4
index ff65b39b454..cfd53bdc744 100644
@@ -1488,18 +1488,15 @@ SRST
   Stop the QEMU embedded NBD server.
 ERST
 
-
-#if defined(TARGET_I386)
-
     {
         .name       = "mce",
         .args_type  = "broadcast:-b,cpu_index:i,bank:i,status:l,mcg_status:l,addr:l,misc:l",
         .params     = "[-b] cpu bank status mcgstatus addr misc",
         .help       = "inject a MCE on the given CPU [and broadcast to other CPUs with -b option]",
         .cmd        = hmp_mce,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
 
-#endif
 SRST
 ``mce`` *cpu* *bank* *status* *mcgstatus* *addr* *misc*
   Inject an MCE on the given CPU (x86 only).
stubs/meson.build +1 -0
index 32c16209543..4d1a803c17c 100644
@@ -87,6 +87,7 @@ if have_system
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
+  stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
 
 if have_system or have_user
Signature · 1 line
2.53.0
#17 lore raw

PATCH v3 11/27 monitor: Do not check TARGET_I386 to build 'info sgx' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SGX definition, define it in its own stub file.

---
 MAINTAINERS            |  1 +
 hw/i386/sgx-hmp-stub.c | 16 ++++++++++++++++
 hw/i386/sgx-stub.c     |  5 -----
 hmp-commands-info.hx   |  3 +--
 hw/i386/meson.build    |  1 +
 5 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 hw/i386/sgx-hmp-stub.c
MAINTAINERS +1 -0
index a0c8f484163..16a3d71af02 100644
@@ -514,6 +514,7 @@ L: [email protected]
 S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
+F: hw/i386/sgx*
 F: stubs/qmp-i386-sev.c
 F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
hw/i386/sgx-hmp-stub.c new file +16 -0
new file mode 100644
index 00000000000..cf1d9a6344b
@@ -0,0 +1,16 @@
+/*
+ * Human Monitor 'info sgx' stub (CONFIG_SGX)
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+
+void hmp_info_sgx(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SGX is not available in this QEMU\n");
+}
hw/i386/sgx-stub.c +0 -5
index 1dd8d9afbfa..2b083c77bc1 100644
@@ -23,11 +23,6 @@ SgxInfo *qmp_query_sgx_capabilities(Error **errp)
     return NULL;
 }
 
-void hmp_info_sgx(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "SGX is not available in this QEMU\n");
-}
-
 void pc_machine_init_sgx_epc(PCMachineState *pcms)
 {
     memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState));
hmp-commands-info.hx +1 -2
index b575e4ac993..da9fdc0ab7b 100644
@@ -866,15 +866,14 @@ SRST
     Display the vcpu dirty page limit information.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "sgx",
         .args_type  = "",
         .params     = "",
         .help       = "show intel SGX information",
         .cmd        = hmp_info_sgx,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info sgx``
hw/i386/meson.build +1 -0
index 63ae57baa51..b611fbb5a7f 100644
@@ -24,6 +24,7 @@ i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c'))
 i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c'))
 i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'),
                                 if_false: files('sgx-stub.c'))
+stub_ss.add(files('sgx-hmp-stub.c'))
 
 i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c'))
 i386_ss.add(when: 'CONFIG_PC', if_true: files(
Signature · 1 line
2.53.0
#18 lore raw

PATCH v3 12/27 monitor: Do not check TARGET_I386 to build 'info sev' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on the CONFIG_SEV definition, define it in its own stub file.

---
 MAINTAINERS                   |  1 +
 stubs/hmp-cmd-info_sev.c      | 16 ++++++++++++++++
 target/i386/sev-system-stub.c |  5 -----
 hmp-commands-info.hx          |  3 +--
 stubs/meson.build             |  1 +
 5 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_sev.c
MAINTAINERS +1 -0
index 16a3d71af02..580a80ab254 100644
@@ -515,6 +515,7 @@ S: Supported
 F: docs/system/i386/amd-memory-encryption.rst
 F: docs/system/i386/sgx.rst
 F: hw/i386/sgx*
+F: stubs/hmp-cmd-info_sev.c
 F: stubs/qmp-i386-sev.c
 F: stubs/qmp-i386-sgx.c
 F: target/i386/kvm/
stubs/hmp-cmd-info_sev.c new file +16 -0
new file mode 100644
index 00000000000..f3624423a33
@@ -0,0 +1,16 @@
+/*
+ * Human Monitor 'info sev' stub (CONFIG_SEV)
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+
+void hmp_info_sev(Monitor *mon, const QDict *qdict)
+{
+    monitor_printf(mon, "SEV is not available in this QEMU\n");
+}
target/i386/sev-system-stub.c +0 -5
index fb84aee94d2..2ea85597cf9 100644
@@ -32,11 +32,6 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)
     g_assert_not_reached();
 }
 
-void hmp_info_sev(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "SEV is not available in this QEMU\n");
-}
-
 void pc_system_parse_sev_metadata(uint8_t *flash_ptr, size_t flash_size)
 {
 }
hmp-commands-info.hx +1 -2
index da9fdc0ab7b..336ab870a2c 100644
@@ -812,15 +812,14 @@ SRST
     enabled) memory in bytes.
 ERST
 
-#if defined(TARGET_I386)
     {
         .name       = "sev",
         .args_type  = "",
         .params     = "",
         .help       = "show SEV information",
         .cmd        = hmp_info_sev,
+        .arch_bitmask = QEMU_ARCH_I386,
     },
-#endif
 
 SRST
   ``info sev``
stubs/meson.build +1 -0
index 4d1a803c17c..4a1d687a111 100644
@@ -86,6 +86,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmd-info_sev.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
Signature · 1 line
2.53.0
#19 lore raw

PATCH v3 13/27 monitor: Do not check TARGET_I386/RISCV to build 'info mem' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for i386/x86_64 and riscv32/riscv64 binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter it at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

---
 stubs/hmp-cmd-info_mem.c | 12 ++++++++++++
 hmp-commands-info.hx     |  3 +--
 stubs/meson.build        |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_mem.c
stubs/hmp-cmd-info_mem.c new file +12 -0
new file mode 100644
index 00000000000..8a53e367a9f
@@ -0,0 +1,12 @@
+/*
+ * Human Monitor 'info mem' stub
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_mem)
hmp-commands-info.hx +1 -2
index 336ab870a2c..2d0a8f7d48f 100644
@@ -209,15 +209,14 @@ SRST
     Show virtual to physical memory mappings.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_RISCV)
     {
         .name       = "mem",
         .args_type  = "",
         .params     = "",
         .help       = "show the active virtual memory mappings",
         .cmd        = hmp_info_mem,
+        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_RISCV,
     },
-#endif
 
 SRST
   ``info mem``
stubs/meson.build +1 -0
index 4a1d687a111..9aaf80e6c1b 100644
@@ -86,6 +86,7 @@ if have_system
   stub_ss.add(files('qmp-cpu.c'))
   stub_ss.add(files('qmp-cpu-s390x.c'))
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
+  stub_ss.add(files('hmp-cmd-info_mem.c'))
   stub_ss.add(files('hmp-cmd-info_sev.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
Signature · 1 line
2.53.0
#20 lore raw

PATCH v3 14/27 monitor: Do not check multiple TARGET_* to build 'info tlb' command

In reply to Philippe Mathieu-Daudé

This command is filtered at build-time for a selection of binaries. By using the recently introduced HMPCommand::arch_bitmask flag we can filter them at runtime, making it possible to compile hmp-commands-info.hx once.

Since the method depends on a pair of distinct targets, define it in its own stub file.

---
 stubs/hmp-cmd-info_tlb.c | 12 ++++++++++++
 hmp-commands-info.hx     |  5 ++---
 stubs/meson.build        |  1 +
 3 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 stubs/hmp-cmd-info_tlb.c
stubs/hmp-cmd-info_tlb.c new file +12 -0
new file mode 100644
index 00000000000..a144e68c1c7
@@ -0,0 +1,12 @@
+/*
+ * Human Monitor 'info tlb' stub
+ *
+ * Copyright (c) Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/hmp.h"
+
+HMP_STUB(info_tlb)
hmp-commands-info.hx +2 -3
index 2d0a8f7d48f..0898221a486 100644
@@ -193,16 +193,15 @@ SRST
     Show PCI information.
 ERST
 
-#if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
-    defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K)
     {
         .name       = "tlb",
         .args_type  = "",
         .params     = "",
         .help       = "show virtual to physical memory mappings",
         .cmd        = hmp_info_tlb,
+        .arch_bitmask = QEMU_ARCH_I386 | QEMU_ARCH_SH4 | QEMU_ARCH_SPARC \
+                        | QEMU_ARCH_PPC | QEMU_ARCH_XTENSA | QEMU_ARCH_M68K,
     },
-#endif
 
 SRST
   ``info tlb``
stubs/meson.build +1 -0
index 9aaf80e6c1b..398822f47fa 100644
@@ -88,6 +88,7 @@ if have_system
   stub_ss.add(files('qmp-cpu-s390x-kvm.c'))
   stub_ss.add(files('hmp-cmd-info_mem.c'))
   stub_ss.add(files('hmp-cmd-info_sev.c'))
+  stub_ss.add(files('hmp-cmd-info_tlb.c'))
   stub_ss.add(files('hmp-cmds-hw-s390x.c'))
   stub_ss.add(files('hmp-cmds-target-i386.c'))
 endif
Signature · 1 line
2.53.0
#21 lore raw

PATCH v3 15/27 cpus: Introduce SysemuCPUOps::monitor_get_register() hook

In reply to Philippe Mathieu-Daudé

Allow targets to register their legacy target_get_monitor_def() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
 include/hw/core/sysemu-cpu-ops.h |  8 ++++++++
 monitor/hmp-target.c             | 11 ++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
include/hw/core/sysemu-cpu-ops.h +8 -0
index 7b2d2d2610f..5b831393cf4 100644
@@ -85,6 +85,14 @@ typedef struct SysemuCPUOps {
      */
     bool (*internal_is_big_endian)(CPUState *cpu);
 
+    /**
+     * @monitor_get_register: Callback to fill @pval with register @name value.
+     *                        This field is legacy, use @gdb_core_xml_file
+     *                        to dump registers instead.
+     * Returns: 0 on success or negative errno on failure.
+     */
+    int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval);
+
     /**
      * @legacy_vmsd: Legacy state for migration.
      *               Do not use in new targets, use #DeviceClass::vmsd instead.
monitor/hmp-target.c +8 -3
index a222fd4c96a..46ccbd14aec 100644
@@ -35,6 +35,7 @@
 #include "qapi/qapi-commands-control.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-machine.h"
+#include "hw/core/sysemu-cpu-ops.h"
 
 /* Make devices configuration available for use in hmp-commands*.hx templates */
 #include CONFIG_DEVICES
@@ -85,9 +86,13 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
         }
     }
 
-    ret = target_get_monitor_def(cs, name, &tmp);
-    if (!ret) {
-        *pval = (target_long) tmp;
+    if (cs->cc->sysemu_ops->monitor_get_register) {
+        ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
+    } else {
+        ret = target_get_monitor_def(cs, name, &tmp);
+        if (!ret) {
+            *pval = (target_long) tmp;
+        }
     }
 
     return ret;
Signature · 1 line
2.53.0
#22 lore raw

PATCH v3 16/27 target/riscv: Register target_get_monitor_def in SysemuCPUOps

In reply to Philippe Mathieu-Daudé

Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as SysemuCPUOps::monitor_get_register() handler. Take care to sign-extend values for 32-bit HARTs.

---
 target/riscv/internals.h |  3 +++
 target/riscv/cpu.c       |  1 +
 target/riscv/monitor.c   | 11 +++++++----
 3 files changed, 11 insertions(+), 4 deletions(-)
target/riscv/internals.h +3 -0
index 460346dd6de..28b61d25888 100644
@@ -245,4 +245,7 @@ static inline int insn_len(uint16_t first_word)
     return (first_word & 3) == 3 ? 4 : 2;
 }
 
+int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
+                                      int64_t *pval);
+
 #endif
target/riscv/cpu.c +1 -0
index 8ac935ac06e..dbd88fa6655 100644
@@ -2720,6 +2720,7 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
     .get_phys_page_debug = riscv_cpu_get_phys_page_debug,
     .write_elf64_note = riscv_cpu_write_elf64_note,
     .write_elf32_note = riscv_cpu_write_elf32_note,
+    .monitor_get_register = riscv_monitor_get_register_legacy,
     .legacy_vmsd = &vmstate_riscv_cpu,
 };
 #endif
target/riscv/monitor.c +7 -4
index a9d31114442..00a68c26abc 100644
@@ -27,6 +27,7 @@
 #include "monitor/hmp.h"
 #include "monitor/hmp-target.h"
 #include "system/memory.h"
+#include "internals.h"
 
 #ifdef TARGET_RISCV64
 #define PTE_HEADER_FIELDS       "vaddr            paddr            "\
@@ -311,16 +312,18 @@ static bool reg_is_vreg(const char *name)
     return false;
 }
 
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
+int riscv_monitor_get_register_legacy(CPUState *cs, const char *name,
+                                      int64_t *pval)
 {
-    CPURISCVState *env = &RISCV_CPU(cs)->env;
+    RISCVCPU *hart = RISCV_CPU(cs);
+    CPURISCVState *env = cpu_env(cs);
     target_ulong val = 0;
     uint64_t val64 = 0;
     int i;
 
     if (reg_is_ulong_integer(env, name, &val, false) ||
         reg_is_ulong_integer(env, name, &val, true)) {
-        *pval = val;
+        *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val;
         return 0;
     }
 
@@ -369,7 +372,7 @@ int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
          * to do the filtering of the registers that are present.
          */
         if (res == RISCV_EXCP_NONE) {
-            *pval = val;
+            *pval = riscv_cpu_is_32bit(hart) ? (int32_t)val : val;
             return 0;
         }
     }
Signature · 1 line
2.53.0
Reviewed-by on v3 16/27
#23 lore raw

Re: [PATCH v3 16/27] target/riscv: Register target_get_monitor_def in SysemuCPUOps

Quoted 10 lines · Philippe Mathieu-Daudé

Rename target_get_monitor_def() as riscv_monitor_get_register_legacy() and register it as SysemuCPUOps::monitor_get_register() handler. Take care to sign-extend values for 32-bit HARTs.

---
  target/riscv/internals.h |  3 +++
  target/riscv/cpu.c       |  1 +
  target/riscv/monitor.c   | 11 +++++++----
  3 files changed, 11 insertions(+), 4 deletions(-)

r~

#24 lore raw

PATCH v3 17/27 monitor: Remove target_get_monitor_def()

In reply to Philippe Mathieu-Daudé

target_get_monitor_def() is now only a dead stub. Remove as pointless.

---
 include/monitor/hmp-target.h   |  1 -
 monitor/hmp-target.c           | 14 +++-----------
 stubs/target-get-monitor-def.c | 29 -----------------------------
 stubs/meson.build              |  1 -
 4 files changed, 3 insertions(+), 42 deletions(-)
 delete mode 100644 stubs/target-get-monitor-def.c
include/monitor/hmp-target.h +0 -1
index ce0bb1983cc..008c1a6570c 100644
@@ -38,7 +38,6 @@ struct MonitorDef {
 #endif
 
 const MonitorDef *target_monitor_defs(void);
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
 
 CPUArchState *mon_get_cpu_env(Monitor *mon);
 CPUState *mon_get_cpu(Monitor *mon);
monitor/hmp-target.c +3 -11
index 46ccbd14aec..c2ddcd67e51 100644
@@ -66,8 +66,6 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
     const MonitorDef *md = target_monitor_defs();
     CPUState *cs = mon_get_cpu(mon);
     void *ptr;
-    uint64_t tmp = 0;
-    int ret;
 
     if (cs == NULL || md == NULL) {
         return -1;
@@ -86,16 +84,10 @@ int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
         }
     }
 
-    if (cs->cc->sysemu_ops->monitor_get_register) {
-        ret = cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
-    } else {
-        ret = target_get_monitor_def(cs, name, &tmp);
-        if (!ret) {
-            *pval = (target_long) tmp;
-        }
+    if (!cs->cc->sysemu_ops->monitor_get_register) {
+        return -1;
     }
-
-    return ret;
+    return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
 }
 
 static int
stubs/target-get-monitor-def.c deleted +0 -29
deleted file mode 100644
index 394e0f9a7d2..00000000000
@@ -1,29 +0,0 @@
-/*
- *  Stub for target_get_monitor_def.
- *
- *  Copyright IBM Corp., 2015
- *
- *  Author: Alexey Kardashevskiy <[email protected]>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License,
- *  or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "qemu/osdep.h"
-
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval);
-
-int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
-{
-    return -1;
-}
stubs/meson.build +0 -1
index 398822f47fa..2bf376e15e3 100644
@@ -74,7 +74,6 @@ if have_system
     stub_ss.add(files('igvm.c'))
   endif
   stub_ss.add(files('kvm.c'))
-  stub_ss.add(files('target-get-monitor-def.c'))
   stub_ss.add(files('target-monitor-defs.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
Signature · 1 line
2.53.0
#25 lore raw

PATCH v3 18/27 monitor: Have MonitorDef::get_value() always return int64_t type

In reply to Philippe Mathieu-Daudé

Simplify MonitorDef::get_value() handler by having it always return a int64_t type.

Let the single caller (x86 targets) sign-extend the returned value, directly handling 64-bit CPUs in 32-bit or 16-bit mode.

---
 include/monitor/hmp-target.h |  6 +-----
 target/i386/monitor.c        | 11 ++++++++---
 2 files changed, 9 insertions(+), 8 deletions(-)
include/monitor/hmp-target.h +1 -5
index 008c1a6570c..ae34ca65ded 100644
@@ -27,15 +27,11 @@
 
 typedef struct MonitorDef MonitorDef;
 
-#ifdef COMPILING_PER_TARGET
-#include "exec/target_long.h"
 struct MonitorDef {
     const char *name;
     int offset;
-    target_long (*get_value)(Monitor *mon, const struct MonitorDef *md,
-                             int val);
+    int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
 };
-#endif
 
 const MonitorDef *target_monitor_defs(void);
 
target/i386/monitor.c +8 -3
index 977f65fe16c..98df5c7fd12 100644
@@ -593,11 +593,16 @@ void hmp_mce(Monitor *mon, const QDict *qdict)
     }
 }
 
-static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
-                                  int val)
+static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
+                              int offset)
 {
     CPUArchState *env = mon_get_cpu_env(mon);
-    return env->eip + env->segs[R_CS].base;
+    int64_t ret = env->eip + env->segs[R_CS].base;
+
+    if (!(env->hflags & HF_CS64_MASK)) {
+        ret = (int32_t)ret;
+    }
+    return ret;
 }
 
 const MonitorDef monitor_defs[] = {
Signature · 1 line
2.53.0
Reviewed-by on v3 18/27
#26 lore raw

Re: [PATCH v3 18/27] monitor: Have MonitorDef::get_value() always return int64_t type

Quoted 6 lines · Philippe Mathieu-Daudé

SimplifyMonitorDef::get_value() handler by having it always return a int64_t type.

Let the single caller (x86 targets) sign-extend the returned value, directly handling 64-bit CPUs in 32-bit or 16-bit mode.

Quoted 6 lines
---
  include/monitor/hmp-target.h |  6 +-----
  target/i386/monitor.c        | 11 ++++++++---
  2 files changed, 9 insertions(+), 8 deletions(-)

r~

#27 lore raw

PATCH v3 19/27 monitor: Reduce target-specific methods further

In reply to Philippe Mathieu-Daudé

get_monitor_def() doesn't use any target-specific declaration anymore, move it to hmp.c to compile it once.

---
 monitor/monitor-internal.h |  1 -
 monitor/hmp-target.c       | 33 ---------------------------------
 monitor/hmp.c              | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 34 deletions(-)
monitor/monitor-internal.h +0 -1
index eaf9a607783..a5c4aba306e 100644
@@ -191,7 +191,6 @@ void monitor_data_destroy_qmp(MonitorQMP *mon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
-int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
 void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
 int hmp_compare_cmd(const char *name, const char *list);
 
monitor/hmp-target.c +0 -33
index c2ddcd67e51..550a7178052 100644
@@ -57,39 +57,6 @@ HMPCommand *hmp_cmds_for_target(bool info_command)
     return info_command ? hmp_info_cmds : hmp_cmds;
 }
 
-/*
- * Set @pval to the value in the register identified by @name.
- * return 0 if OK, -1 if not found
- */
-int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
-{
-    const MonitorDef *md = target_monitor_defs();
-    CPUState *cs = mon_get_cpu(mon);
-    void *ptr;
-
-    if (cs == NULL || md == NULL) {
-        return -1;
-    }
-
-    for(; md->name != NULL; md++) {
-        if (hmp_compare_cmd(name, md->name)) {
-            if (md->get_value) {
-                *pval = md->get_value(mon, md, md->offset);
-            } else {
-                CPUArchState *env = mon_get_cpu_env(mon);
-                ptr = (uint8_t *)env + md->offset;
-                *pval = *(int32_t *)ptr;
-            }
-            return 0;
-        }
-    }
-
-    if (!cs->cc->sysemu_ops->monitor_get_register) {
-        return -1;
-    }
-    return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
-}
-
 static int
 compare_mon_cmd(const void *a, const void *b)
 {
monitor/hmp.c +36 -0
index e881c26c305..618ded40207 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include <dirent.h>
 #include "hw/core/qdev.h"
+#include "hw/core/sysemu-cpu-ops.h"
 #include "monitor-internal.h"
 #include "monitor/hmp.h"
 #include "monitor/hmp-target.h"
@@ -359,6 +360,8 @@ static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
 static const char *pch;
 static sigjmp_buf expr_env;
 
+static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
+
 static G_NORETURN G_GNUC_PRINTF(2, 3)
 void expr_error(Monitor *mon, const char *fmt, ...)
 {
@@ -1599,3 +1602,36 @@ void monitor_register_hmp_info_hrt(const char *name,
     }
     g_assert_not_reached();
 }
+
+/*
+ * Set @pval to the value in the register identified by @name.
+ * return 0 if OK, -1 if not found
+ */
+static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
+{
+    const MonitorDef *md = target_monitor_defs();
+    CPUState *cs = mon_get_cpu(mon);
+    void *ptr;
+
+    if (cs == NULL || md == NULL) {
+        return -1;
+    }
+
+    for(; md->name != NULL; md++) {
+        if (hmp_compare_cmd(name, md->name)) {
+            if (md->get_value) {
+                *pval = md->get_value(mon, md, md->offset);
+            } else {
+                CPUArchState *env = mon_get_cpu_env(mon);
+                ptr = (uint8_t *)env + md->offset;
+                *pval = *(int32_t *)ptr;
+            }
+            return 0;
+        }
+    }
+
+    if (!cs->cc->sysemu_ops->monitor_get_register) {
+        return -1;
+    }
+    return cs->cc->sysemu_ops->monitor_get_register(cs, name, pval);
+}
Signature · 1 line
2.53.0
#28 lore raw

PATCH v3 20/27 monitor: Remove 'monitor/hmp-target.h' header

In reply to Philippe Mathieu-Daudé

The "monitor/hmp-target.h" header doesn't contain any target-specific declarations anymore. Merge it with "monitor/hmp.h", its target-agnostic counterpart.

---
 MAINTAINERS                   |  1 -
 include/monitor/hmp-target.h  | 41 -----------------------------------
 include/monitor/hmp.h         | 11 ++++++++++
 hw/i386/sgx-stub.c            |  1 -
 hw/i386/sgx.c                 |  1 -
 monitor/hmp-cmds.c            |  1 -
 monitor/hmp-target.c          |  1 -
 monitor/hmp.c                 |  1 -
 stubs/target-monitor-defs.c   |  2 +-
 target/i386/cpu-apic.c        |  1 -
 target/i386/monitor.c         |  1 -
 target/i386/sev-system-stub.c |  1 -
 target/i386/sev.c             |  1 -
 target/m68k/monitor.c         |  1 -
 target/ppc/monitor.c          |  2 --
 target/riscv/monitor.c        |  1 -
 target/sh4/monitor.c          |  1 -
 target/sparc/monitor.c        |  1 -
 target/xtensa/monitor.c       |  1 -
 19 files changed, 12 insertions(+), 59 deletions(-)
 delete mode 100644 include/monitor/hmp-target.h
MAINTAINERS +0 -1
index 580a80ab254..5dcd24a8a89 100644
@@ -3421,7 +3421,6 @@ F: hmp.h
 F: hmp-commands*.hx
 F: include/monitor/hmp.h
 F: include/monitor/hmp-completion.h
-F: include/monitor/hmp-target.h
 F: tests/qtest/test-hmp.c
 F: include/qemu/qemu-print.h
 F: util/qemu-print.c
include/monitor/hmp-target.h deleted +0 -41

41 lines not on this page · raw message

include/monitor/hmp.h +11 -0
index a29185741b8..8abe3168924 100644
@@ -24,6 +24,17 @@
         g_assert_not_reached(); \
     }
 
+typedef struct MonitorDef {
+    const char *name;
+    int offset;
+    int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset);
+} MonitorDef;
+
+const MonitorDef *target_monitor_defs(void);
+
+CPUArchState *mon_get_cpu_env(Monitor *mon);
+CPUState *mon_get_cpu(Monitor *mon);
+
 bool hmp_handle_error(Monitor *mon, Error *err);
 void hmp_help_cmd(Monitor *mon, const char *name);
 strList *hmp_split_at_comma(const char *str);
hw/i386/sgx-stub.c +0 -1
index 2b083c77bc1..59d58926311 100644
@@ -1,7 +1,6 @@
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "hw/i386/pc.h"
 #include "hw/i386/sgx-epc.h"
 #include "qapi/qapi-commands-misc-i386.h"
hw/i386/sgx.c +0 -1
index 5e792e8e6e9..7e4c509f5a4 100644
@@ -17,7 +17,6 @@
 #include "monitor/qdev.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-commands-misc-i386.h"
monitor/hmp-cmds.c +0 -1
index bc26b39d708..e81632f5551 100644
@@ -22,7 +22,6 @@
 #include "monitor/hmp.h"
 #include "qemu/help_option.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "monitor/monitor-internal.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-control.h"
monitor/hmp-target.c +0 -1
index 550a7178052..2739383607d 100644
@@ -28,7 +28,6 @@
 #include "monitor/qdev.h"
 #include "net/slirp.h"
 #include "system/device_tree.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
 #include "block/block-hmp-cmds.h"
monitor/hmp.c +0 -1
index 618ded40207..d7b2f731def 100644
@@ -28,7 +28,6 @@
 #include "hw/core/sysemu-cpu-ops.h"
 #include "monitor-internal.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qobject/qdict.h"
 #include "qobject/qnum.h"
 #include "qemu/bswap.h"
stubs/target-monitor-defs.c +1 -1
index 35a0a342772..0dd4cdb34f6 100644
@@ -1,5 +1,5 @@
 #include "qemu/osdep.h"
-#include "monitor/hmp-target.h"
+#include "monitor/hmp.h"
 
 const MonitorDef *target_monitor_defs(void)
 {
target/i386/cpu-apic.c +0 -1
index eaa10ad2a3d..5599a4675c5 100644
@@ -11,7 +11,6 @@
 #include "qapi/error.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "system/hw_accel.h"
 #include "system/kvm.h"
 #include "system/xen.h"
target/i386/monitor.c +0 -1
index 98df5c7fd12..1befb8ea824 100644
@@ -25,7 +25,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "qobject/qdict.h"
 #include "qapi/error.h"
target/i386/sev-system-stub.c +0 -1
index 2ea85597cf9..d97536cca1c 100644
@@ -14,7 +14,6 @@
 #include "qemu/osdep.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/error.h"
 #include "sev.h"
 
target/i386/sev.c +0 -1
index 261b6aaa37b..b44b5a1c2b9 100644
@@ -40,7 +40,6 @@
 #include "qom/object.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "qapi/qapi-commands-misc-i386.h"
 #include "confidential-guest.h"
 #include "hw/i386/pc.h"
target/m68k/monitor.c +0 -1
index 94bb12833af..be7411edca6 100644
@@ -8,7 +8,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "monitor/monitor.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
target/ppc/monitor.c +0 -2
index 776a76602ea..7c88e0e2bda 100644
@@ -7,9 +7,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/ctype.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 #include "cpu.h"
 
target/riscv/monitor.c +0 -1
index 00a68c26abc..a6250bcccca 100644
@@ -25,7 +25,6 @@
 #include "cpu_bits.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp.h"
-#include "monitor/hmp-target.h"
 #include "system/memory.h"
 #include "internals.h"
 
target/sh4/monitor.c +0 -1
index 2da6a5426eb..50324d3600c 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 static void print_tlb(Monitor *mon, int idx, tlb_t *tlb)
target/sparc/monitor.c +0 -1
index a60671a60a4..99abddbf1e0 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 
target/xtensa/monitor.c +0 -1
index fbf60d55530..2af84934f83 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "monitor/monitor.h"
-#include "monitor/hmp-target.h"
 #include "monitor/hmp.h"
 
 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
Signature · 1 line
2.53.0
#29 lore raw

PATCH v3 21/27 monitor: Forward-declare the MonitorDef type

In reply to Philippe Mathieu-Daudé

Rather than having core header forced to include "monitor/hmp.h" to get the MonitorDef type declaration, forward-declare it in "qemu/typedefs.h".

---
 include/monitor/hmp.h   | 6 +++---
 include/qemu/typedefs.h | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)
include/monitor/hmp.h +3 -3
index 8abe3168924..22784bd4c79 100644
@@ -24,11 +24,11 @@
         g_assert_not_reached(); \
     }
 
-typedef struct MonitorDef {
+struct MonitorDef {
     const char *name;
     int offset;
-    int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int offset);
-} MonitorDef;
+    int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
+};
 
 const MonitorDef *target_monitor_defs(void);
 
include/qemu/typedefs.h +1 -0
index 416a8c9acea..07f2ae7c9f1 100644
@@ -72,6 +72,7 @@ typedef struct MemoryRegionSection MemoryRegionSection;
 typedef struct MigrationIncomingState MigrationIncomingState;
 typedef struct MigrationState MigrationState;
 typedef struct Monitor Monitor;
+typedef struct MonitorDef MonitorDef;
 typedef struct MSIMessage MSIMessage;
 typedef struct NetClientState NetClientState;
 typedef struct NetFilterState NetFilterState;
Signature · 1 line
2.53.0
#30 lore raw

PATCH v3 22/27 cpus: Introduce SysemuCPUOps::monitor_defs hook

In reply to Philippe Mathieu-Daudé

Allow targets to register their legacy target_monitor_defs() in SysemuCPUOps; check it first in get_monitor_def() otherwise fall back to previous per-target helper.

---
 include/hw/core/sysemu-cpu-ops.h | 6 ++++++
 monitor/hmp.c                    | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
include/hw/core/sysemu-cpu-ops.h +6 -0
index 5b831393cf4..94e36ecdd18 100644
@@ -93,6 +93,12 @@ typedef struct SysemuCPUOps {
      */
     int (*monitor_get_register)(CPUState *cs, const char *name, int64_t *pval);
 
+    /**
+     * @monitor_defs: Array of MonitorDef entries. This field is legacy,
+     *                use @gdb_core_xml_file to dump registers instead.
+     */
+    const MonitorDef *monitor_defs;
+
     /**
      * @legacy_vmsd: Legacy state for migration.
      *               Do not use in new targets, use #DeviceClass::vmsd instead.
monitor/hmp.c +6 -2
index d7b2f731def..70e5e5c2367 100644
@@ -1608,11 +1608,15 @@ void monitor_register_hmp_info_hrt(const char *name,
  */
 static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
 {
-    const MonitorDef *md = target_monitor_defs();
     CPUState *cs = mon_get_cpu(mon);
+    const MonitorDef *md;
     void *ptr;
 
-    if (cs == NULL || md == NULL) {
+    if (cs == NULL) {
+        return -1;
+    }
+    md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs();
+    if (md == NULL) {
         return -1;
     }
 
Signature · 1 line
2.53.0
#31 lore raw

PATCH v3 23/27 target/i386: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict x86_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
 target/i386/cpu.c     | 29 +++++++++++++++++++++++++++++
 target/i386/monitor.c | 30 ------------------------------
 2 files changed, 29 insertions(+), 30 deletions(-)
target/i386/cpu.c +29 -0
index c6fd1dc00eb..4cb8c627295 100644
@@ -39,6 +39,7 @@
 #include "exec/watchpoint.h"
 #ifndef CONFIG_USER_ONLY
 #include "confidential-guest.h"
+#include "monitor/hmp.h"
 #include "system/reset.h"
 #include "qapi/qapi-commands-machine.h"
 #include "system/address-spaces.h"
@@ -10685,6 +10686,33 @@ static const Property x86_cpu_properties[] = {
 };
 
 #ifndef CONFIG_USER_ONLY
+
+static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
+                              int offset)
+{
+    CPUArchState *env = mon_get_cpu_env(mon);
+    int64_t ret = env->eip + env->segs[R_CS].base;
+
+    if (!(env->hflags & HF_CS64_MASK)) {
+        ret = (int32_t)ret;
+    }
+    return ret;
+}
+
+static const MonitorDef x86_monitor_defs[] = {
+#define SEG(name, seg) \
+    { name ".limit", offsetof(CPUX86State, segs[seg].limit) },
+    SEG("cs", R_CS)
+    SEG("ds", R_DS)
+    SEG("es", R_ES)
+    SEG("ss", R_SS)
+    SEG("fs", R_FS)
+    SEG("gs", R_GS)
+    { "pc", 0, monitor_get_pc, },
+    { NULL },
+#undef SEG
+};
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps i386_sysemu_ops = {
@@ -10698,6 +10726,7 @@ static const struct SysemuCPUOps i386_sysemu_ops = {
     .write_elf64_note = x86_cpu_write_elf64_note,
     .write_elf32_qemunote = x86_cpu_write_elf32_qemunote,
     .write_elf64_qemunote = x86_cpu_write_elf64_qemunote,
+    .monitor_defs = x86_monitor_defs,
     .legacy_vmsd = &vmstate_x86_cpu,
 };
 #endif
target/i386/monitor.c +0 -30
index 1befb8ea824..a536712c755 100644
@@ -591,33 +591,3 @@ void hmp_mce(Monitor *mon, const QDict *qdict)
                            flags);
     }
 }
-
-static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md,
-                              int offset)
-{
-    CPUArchState *env = mon_get_cpu_env(mon);
-    int64_t ret = env->eip + env->segs[R_CS].base;
-
-    if (!(env->hflags & HF_CS64_MASK)) {
-        ret = (int32_t)ret;
-    }
-    return ret;
-}
-
-const MonitorDef monitor_defs[] = {
-#define SEG(name, seg) \
-    { name ".limit", offsetof(CPUX86State, segs[seg].limit) },
-    SEG("cs", R_CS)
-    SEG("ds", R_DS)
-    SEG("es", R_ES)
-    SEG("ss", R_SS)
-    SEG("fs", R_FS)
-    SEG("gs", R_GS)
-    { "pc", 0, monitor_get_pc, },
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
#32 lore raw

PATCH v3 24/27 target/m68k: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict m68k_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook, allowing to remove the target_monitor_defs() method.

---
 target/m68k/cpu.c     | 18 ++++++++++++++++++
 target/m68k/monitor.c | 21 ---------------------
 2 files changed, 18 insertions(+), 21 deletions(-)
target/m68k/cpu.c +18 -0
index d849a4a90fc..f704a6af613 100644
@@ -25,6 +25,7 @@
 
 #ifndef CONFIG_USER_ONLY
 #include "migration/vmstate.h"
+#include "monitor/hmp.h"
 #endif
 
 #include "cpu.h"
@@ -602,11 +603,28 @@ static const VMStateDescription vmstate_m68k_cpu = {
     },
 };
 
+static const MonitorDef m68k_monitor_defs[] = {
+    { "ssp", offsetof(CPUM68KState, sp[0]) },
+    { "usp", offsetof(CPUM68KState, sp[1]) },
+    { "isp", offsetof(CPUM68KState, sp[2]) },
+    { "sfc", offsetof(CPUM68KState, sfc) },
+    { "dfc", offsetof(CPUM68KState, dfc) },
+    { "urp", offsetof(CPUM68KState, mmu.urp) },
+    { "srp", offsetof(CPUM68KState, mmu.srp) },
+    { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) },
+    { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) },
+    { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) },
+    { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) },
+    { "mmusr", offsetof(CPUM68KState, mmu.mmusr) },
+    { NULL },
+};
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps m68k_sysemu_ops = {
     .has_work = m68k_cpu_has_work,
     .get_phys_page_debug = m68k_cpu_get_phys_page_debug,
+    .monitor_defs = m68k_monitor_defs,
 };
 #endif /* !CONFIG_USER_ONLY */
 
target/m68k/monitor.c +0 -21
index be7411edca6..3e0df40a6b8 100644
@@ -21,24 +21,3 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict)
 
     dump_mmu(env1);
 }
-
-static const MonitorDef monitor_defs[] = {
-    { "ssp", offsetof(CPUM68KState, sp[0]) },
-    { "usp", offsetof(CPUM68KState, sp[1]) },
-    { "isp", offsetof(CPUM68KState, sp[2]) },
-    { "sfc", offsetof(CPUM68KState, sfc) },
-    { "dfc", offsetof(CPUM68KState, dfc) },
-    { "urp", offsetof(CPUM68KState, mmu.urp) },
-    { "srp", offsetof(CPUM68KState, mmu.srp) },
-    { "dttr0", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR0]) },
-    { "dttr1", offsetof(CPUM68KState, mmu.ttr[M68K_DTTR1]) },
-    { "ittr0", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR0]) },
-    { "ittr1", offsetof(CPUM68KState, mmu.ttr[M68K_ITTR1]) },
-    { "mmusr", offsetof(CPUM68KState, mmu.mmusr) },
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
#33 lore raw

PATCH v3 25/27 target/sparc: Replace target_monitor_defs -> SysemuCPUOps::monitor_defs

In reply to Philippe Mathieu-Daudé

Restrict sparc64_monitor_defs[] to cpu.c, register it as SysemuCPUOps::monitor_defs hook (taking care to not register it on 32-bit SPARC target), allowing to remove the target_monitor_defs() method.

---
 target/sparc/cpu.c     | 19 +++++++++++++++++++
 target/sparc/monitor.c | 18 ------------------
 2 files changed, 19 insertions(+), 18 deletions(-)
target/sparc/cpu.c +19 -0
index 1493336e7a2..9c5175aca34 100644
@@ -993,12 +993,31 @@ static const Property sparc_cpu_properties[] = {
 };
 
 #ifndef CONFIG_USER_ONLY
+
+#ifdef TARGET_SPARC64
+#include "monitor/hmp.h"
+
+static const MonitorDef sparc64_monitor_defs[] = {
+    { "asi", offsetof(CPUSPARCState, asi) },
+    { "pstate", offsetof(CPUSPARCState, pstate) },
+    { "cansave", offsetof(CPUSPARCState, cansave) },
+    { "canrestore", offsetof(CPUSPARCState, canrestore) },
+    { "otherwin", offsetof(CPUSPARCState, otherwin) },
+    { "wstate", offsetof(CPUSPARCState, wstate) },
+    { "cleanwin", offsetof(CPUSPARCState, cleanwin) },
+    { NULL },
+};
+#endif
+
 #include "hw/core/sysemu-cpu-ops.h"
 
 static const struct SysemuCPUOps sparc_sysemu_ops = {
     .has_work = sparc_cpu_has_work,
     .get_phys_page_debug = sparc_cpu_get_phys_page_debug,
     .legacy_vmsd = &vmstate_sparc_cpu,
+#if defined(TARGET_SPARC64)
+    .monitor_defs = sparc64_monitor_defs,
+#endif
 };
 #endif
 
target/sparc/monitor.c +0 -18
index 99abddbf1e0..36f3d8d58e9 100644
@@ -37,21 +37,3 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict)
     }
     dump_mmu(env1);
 }
-
-const MonitorDef monitor_defs[] = {
-#ifdef TARGET_SPARC64
-    { "asi", offsetof(CPUSPARCState, asi) },
-    { "pstate", offsetof(CPUSPARCState, pstate) },
-    { "cansave", offsetof(CPUSPARCState, cansave) },
-    { "canrestore", offsetof(CPUSPARCState, canrestore) },
-    { "otherwin", offsetof(CPUSPARCState, otherwin) },
-    { "wstate", offsetof(CPUSPARCState, wstate) },
-    { "cleanwin", offsetof(CPUSPARCState, cleanwin) },
-#endif
-    { NULL },
-};
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return monitor_defs;
-}
Signature · 1 line
2.53.0
#34 lore raw

PATCH v3 26/27 monitor: Remove target_monitor_defs()

In reply to Philippe Mathieu-Daudé

target_monitor_defs() is now only a dead stub. Remove as pointless.

---
 include/monitor/hmp.h       | 2 --
 monitor/hmp.c               | 2 +-
 stubs/target-monitor-defs.c | 7 -------
 stubs/meson.build           | 1 -
 4 files changed, 1 insertion(+), 11 deletions(-)
 delete mode 100644 stubs/target-monitor-defs.c
include/monitor/hmp.h +0 -2
index 22784bd4c79..c8ce8579424 100644
@@ -30,8 +30,6 @@ struct MonitorDef {
     int64_t (*get_value)(Monitor *mon, const MonitorDef *md, int offset);
 };
 
-const MonitorDef *target_monitor_defs(void);
-
 CPUArchState *mon_get_cpu_env(Monitor *mon);
 CPUState *mon_get_cpu(Monitor *mon);
 
monitor/hmp.c +1 -1
index 70e5e5c2367..6d0f5b251b9 100644
@@ -1615,7 +1615,7 @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
     if (cs == NULL) {
         return -1;
     }
-    md = cs->cc->sysemu_ops->monitor_defs ?: target_monitor_defs();
+    md = cs->cc->sysemu_ops->monitor_defs;
     if (md == NULL) {
         return -1;
     }
stubs/target-monitor-defs.c deleted +0 -7
deleted file mode 100644
index 0dd4cdb34f6..00000000000
@@ -1,7 +0,0 @@
-#include "qemu/osdep.h"
-#include "monitor/hmp.h"
-
-const MonitorDef *target_monitor_defs(void)
-{
-    return NULL;
-}
stubs/meson.build +0 -1
index 2bf376e15e3..3c6d0032e93 100644
@@ -74,7 +74,6 @@ if have_system
     stub_ss.add(files('igvm.c'))
   endif
   stub_ss.add(files('kvm.c'))
-  stub_ss.add(files('target-monitor-defs.c'))
   stub_ss.add(files('win32-kbd-hook.c'))
   stub_ss.add(files('xen-hw-stub.c'))
   stub_ss.add(files('qmp-arm-gic.c'))
Signature · 1 line
2.53.0
#35 lore raw

PATCH v3 27/27 monitor: Merge hmp-target.c code within hmp-cmds.c

In reply to Philippe Mathieu-Daudé

hmp-target.c doesn't contain any target-specific code anymore. Merge it within hmp-cmds.c (which is already built once).

---
 MAINTAINERS          |  1 -
 monitor/hmp-cmds.c   | 40 ++++++++++++++++++++++++
 monitor/hmp-target.c | 74 --------------------------------------------
 monitor/meson.build  |  3 --
 4 files changed, 40 insertions(+), 78 deletions(-)
 delete mode 100644 monitor/hmp-target.c
MAINTAINERS +0 -1
index 5dcd24a8a89..d184e25ddd4 100644
@@ -3414,7 +3414,6 @@ Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
 S: Maintained
 F: monitor/monitor-internal.h
-F: monitor/hmp-target.c
 F: monitor/monitor.c
 F: monitor/hmp*
 F: hmp.h
monitor/hmp-cmds.c +40 -0
index e81632f5551..409a1a9c701 100644
@@ -14,6 +14,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/base-arch-defs.h"
 #include "system/address-spaces.h"
 #include "system/ioport.h"
 #include "exec/gdbstub.h"
@@ -22,19 +23,58 @@
 #include "monitor/hmp.h"
 #include "qemu/help_option.h"
 #include "monitor/hmp.h"
+#include "monitor/hmp-completion.h"
 #include "monitor/monitor-internal.h"
+#include "monitor/qdev.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-control.h"
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc.h"
+#include "block/block-hmp-cmds.h"
 #include "qobject/qdict.h"
 #include "qemu/cutils.h"
 #include "qemu/log.h"
+#include "net/slirp.h"
+#include "system/device_tree.h"
 #include "system/hw_accel.h"
 #include "system/memory.h"
 #include "system/system.h"
 #include "disas/disas.h"
 
+/* Please update hmp-commands.hx when adding or changing commands */
+static HMPCommand hmp_info_cmds[] = {
+#include "hmp-commands-info.h"
+    { NULL, NULL, },
+};
+
+/* hmp_cmds and hmp_info_cmds would be sorted at runtime */
+static HMPCommand hmp_cmds[] = {
+#include "hmp-commands.h"
+    { NULL, NULL, },
+};
+
+HMPCommand *hmp_cmds_for_target(bool info_command)
+{
+    return info_command ? hmp_info_cmds : hmp_cmds;
+}
+
+static int
+compare_mon_cmd(const void *a, const void *b)
+{
+    return strcmp(((const HMPCommand *)a)->name,
+            ((const HMPCommand *)b)->name);
+}
+
+static void __attribute__((__constructor__)) sortcmdlist(void)
+{
+    qsort(hmp_cmds, ARRAY_SIZE(hmp_cmds) - 1,
+          sizeof(*hmp_cmds),
+          compare_mon_cmd);
+    qsort(hmp_info_cmds, ARRAY_SIZE(hmp_info_cmds) - 1,
+          sizeof(*hmp_info_cmds),
+          compare_mon_cmd);
+}
+
 bool hmp_handle_error(Monitor *mon, Error *err)
 {
     if (err) {
monitor/hmp-target.c deleted +0 -74

74 lines not on this page · raw message

monitor/meson.build +0 -3
index 585251804e4..4c58dd148c0 100644
@@ -7,6 +7,3 @@ system_ss.add(files(
   'qemu-config-qmp.c',
   'qmp-cmds.c',
 ))
-
-specific_ss.add(when: 'CONFIG_SYSTEM_ONLY',
-                if_true: [files('hmp-target.c')])
Signature · 1 line
2.53.0
#37 lore raw
Quoted 2 lines · Markus Armbruster

Doesn't apply to current master for me, and patchew couldn't apply it, either. Got something I could pull?

My single-binary tree is having various dependencies on this series, do you mind if I merged it myself?

#38 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Markus Armbruster

Doesn't apply to current master for me, and patchew couldn't apply it, either. Got something I could pull?

My single-binary tree is having various dependencies on this series, do you mind if I merged it myself?

Do I mind if you take work off me? Hell, no! ;)

I asked because I'd like to give the series a quick eye-over, and I need to compile locally for that.

#39 lore raw
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Markus Armbruster

Doesn't apply to current master for me, and patchew couldn't apply it, either. Got something I could pull?

Quoted 7 lines
Quoted 2 lines

My single-binary tree is having various dependencies on this series, do you mind if I merged it myself?

Do I mind if you take work off me? Hell, no! ;)

I asked because I'd like to give the series a quick eye-over, and I need to compile locally for that.

Rebased as v4: [email protected]

Thanks for the quick eye-over!