Skip to contentSkip to conversation

cpu: Move target-independent code to common code

PATCH Applied Philippe Mathieu-Daudé 4 participants 13 messages Nov 30, 2022 – Feb 27, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover cpu: Move target-independent code to common code

Trivial housekeeping in cpu*.c.

Philippe Mathieu-Daudé (5):
cpu: Remove capstone meson dependency
cpu: Move cpu_class_init_props() to common code
cpu: Move breakpoint helpers to common code
cpu: Move cpu_abort() to common code
cpu: Remove unused includes

 cpu.c         | 165 --------------------------------------------------
 cpus-common.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++
 meson.build   |   3 +-
 3 files changed, 165 insertions(+), 166 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/5 cpu: Remove capstone meson dependency

Only disas.c requires capstone CFLAGS, not cpu.c.

---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -1
index 5c6b5a1c75..92d449f854 100644
@@ -3097,11 +3097,12 @@ if have_block
 endif
 
 common_ss.add(files('cpus-common.c'))
+specific_ss.add(files('cpu.c'))
 
 subdir('softmmu')
 
 common_ss.add(capstone)
-specific_ss.add(files('cpu.c', 'disas.c'), capstone)
+specific_ss.add(files('disas.c'), capstone)
 
 # Work around a gcc bug/misfeature wherein constant propagation looks
 # through an alias:
Signature · 1 line
2.38.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH-for-8.0 1/5] cpu: Remove capstone meson dependency

Quoted 4 lines · Philippe Mathieu-Daudé

Only disas.c requires capstone CFLAGS, not cpu.c.

Quoted 26 lines
---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meson.build +2 -2
index 5c6b5a1c75..92d449f854 100644
@@ -3097,11 +3097,12 @@ if have_block
 endif
 
 common_ss.add(files('cpus-common.c'))
+specific_ss.add(files('cpu.c'))
 
 subdir('softmmu')
 
 common_ss.add(capstone)
-specific_ss.add(files('cpu.c', 'disas.c'), capstone)
+specific_ss.add(files('disas.c'), capstone)
 
 # Work around a gcc bug/misfeature wherein constant propagation looks
 # through an alias:
--

2.38.1

Signature · 1 line
Marc-André Lureau
#3 lore raw

PATCH 2/5 cpu: Move cpu_class_init_props() to common code

In reply to Philippe Mathieu-Daudé

This code is not target-specific.

---
 cpu.c         | 53 ---------------------------------------------------
 cpus-common.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 53 deletions(-)
cpu.c +0 -53
index 4a7d865427..d4b24ea39a 100644
@@ -21,8 +21,6 @@
 #include "qapi/error.h"
 
 #include "exec/target_page.h"
-#include "hw/qdev-core.h"
-#include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
 #include "migration/vmstate.h"
 #ifdef CONFIG_USER_ONLY
@@ -183,57 +181,6 @@ void cpu_exec_unrealizefn(CPUState *cpu)
     cpu_list_remove(cpu);
 }
 
-/*
- * This can't go in hw/core/cpu.c because that file is compiled only
- * once for both user-mode and system builds.
- */
-static Property cpu_common_props[] = {
-#ifdef CONFIG_USER_ONLY
-    /*
-     * Create a property for the user-only object, so users can
-     * adjust prctl(PR_SET_UNALIGN) from the command-line.
-     * Has no effect if the target does not support the feature.
-     */
-    DEFINE_PROP_BOOL("prctl-unalign-sigbus", CPUState,
-                     prctl_unalign_sigbus, false),
-#else
-    /*
-     * Create a memory property for softmmu CPU object, so users can
-     * wire up its memory.  The default if no link is set up is to use
-     * the system address space.
-     */
-    DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
-                     MemoryRegion *),
-#endif
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static bool cpu_get_start_powered_off(Object *obj, Error **errp)
-{
-    CPUState *cpu = CPU(obj);
-    return cpu->start_powered_off;
-}
-
-static void cpu_set_start_powered_off(Object *obj, bool value, Error **errp)
-{
-    CPUState *cpu = CPU(obj);
-    cpu->start_powered_off = value;
-}
-
-void cpu_class_init_props(DeviceClass *dc)
-{
-    ObjectClass *oc = OBJECT_CLASS(dc);
-
-    device_class_set_props(dc, cpu_common_props);
-    /*
-     * We can't use DEFINE_PROP_BOOL in the Property array for this
-     * property, because we want this to be settable after realize.
-     */
-    object_class_property_add_bool(oc, "start-powered-off",
-                                   cpu_get_start_powered_off,
-                                   cpu_set_start_powered_off);
-}
-
 void cpu_exec_initfn(CPUState *cpu)
 {
     cpu->as = NULL;
cpus-common.c +53 -0

62 lines not on this page · raw message

Signature · 1 line
2.38.1
#4 lore raw

Re: [PATCH-for-8.0 2/5] cpu: Move cpu_class_init_props() to common code

Quoted 22 lines · Philippe Mathieu-Daudé

This code is not target-specific.

---
  cpu.c         | 53 ---------------------------------------------------
  cpus-common.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 53 insertions(+), 53 deletions(-)
cpu.c +0 -2
index 4a7d865427..d4b24ea39a 100644
@@ -21,8 +21,6 @@
  #include "qapi/error.h"
 
  #include "exec/target_page.h"
-#include "hw/qdev-core.h"
-#include "hw/qdev-properties.h"
  #include "qemu/error-report.h"
  #include "migration/vmstate.h"
  #ifdef CONFIG_USER_ONLY

cpu.c void cpu_exec_unrealizefn(CPUState *cpu) · line 191

Quoted 9 lines
cpu.c +0 -6
@@ -183,57 +181,6 @@ void cpu_exec_unrealizefn(CPUState *cpu)
      cpu_list_remove(cpu);
  }
 
-/*
- * This can't go in hw/core/cpu.c because that file is compiled only
- * once for both user-mode and system builds.
- */
-static Property cpu_common_props[] = {
-#ifdef CONFIG_USER_ONLY

It is "target" specific in the general sense, in that CONFIG_USER_ONLY is either set or unset.

r~

#5 lore raw

PATCH 3/5 cpu: Move breakpoint helpers to common code

In reply to Philippe Mathieu-Daudé

This code is not target-specific.

---
 cpu.c         | 71 --------------------------------------------------
 cpus-common.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 71 deletions(-)
cpu.c +0 -71
index d4b24ea39a..385e72e140 100644
@@ -257,77 +257,6 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs)
 }
 #endif
 
-/* Add a breakpoint.  */
-int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
-                          CPUBreakpoint **breakpoint)
-{
-    CPUClass *cc = CPU_GET_CLASS(cpu);
-    CPUBreakpoint *bp;
-
-    if (cc->gdb_adjust_breakpoint) {
-        pc = cc->gdb_adjust_breakpoint(cpu, pc);
-    }
-
-    bp = g_malloc(sizeof(*bp));
-
-    bp->pc = pc;
-    bp->flags = flags;
-
-    /* keep all GDB-injected breakpoints in front */
-    if (flags & BP_GDB) {
-        QTAILQ_INSERT_HEAD(&cpu->breakpoints, bp, entry);
-    } else {
-        QTAILQ_INSERT_TAIL(&cpu->breakpoints, bp, entry);
-    }
-
-    if (breakpoint) {
-        *breakpoint = bp;
-    }
-
-    trace_breakpoint_insert(cpu->cpu_index, pc, flags);
-    return 0;
-}
-
-/* Remove a specific breakpoint.  */
-int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags)
-{
-    CPUClass *cc = CPU_GET_CLASS(cpu);
-    CPUBreakpoint *bp;
-
-    if (cc->gdb_adjust_breakpoint) {
-        pc = cc->gdb_adjust_breakpoint(cpu, pc);
-    }
-
-    QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
-        if (bp->pc == pc && bp->flags == flags) {
-            cpu_breakpoint_remove_by_ref(cpu, bp);
-            return 0;
-        }
-    }
-    return -ENOENT;
-}
-
-/* Remove a specific breakpoint by reference.  */
-void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *bp)
-{
-    QTAILQ_REMOVE(&cpu->breakpoints, bp, entry);
-
-    trace_breakpoint_remove(cpu->cpu_index, bp->pc, bp->flags);
-    g_free(bp);
-}
-
-/* Remove all matching breakpoints. */
-void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
-{
-    CPUBreakpoint *bp, *next;
-
-    QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) {
-        if (bp->flags & mask) {
-            cpu_breakpoint_remove_by_ref(cpu, bp);
-        }
-    }
-}
-
 /* enable or disable single step mode. EXCP_DEBUG is returned by the
    CPU loop after each instruction */
 void cpu_single_step(CPUState *cpu, int enabled)
cpus-common.c +72 -0

81 lines not on this page · raw message

Signature · 1 line
2.38.1
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH-for-8.0 3/5] cpu: Move breakpoint helpers to common code

Quoted 7 lines · Philippe Mathieu-Daudé

This code is not target-specific.

---
  cpu.c         | 71 --------------------------------------------------
  cpus-common.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 72 insertions(+), 71 deletions(-)

r~

#7 lore raw

PATCH 4/5 cpu: Move cpu_abort() to common code

In reply to Philippe Mathieu-Daudé

This code is not target-specific.

---
 cpu.c         | 38 --------------------------------------
 cpus-common.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 38 deletions(-)
cpu.c +0 -38
index 385e72e140..d6936a536b 100644
@@ -31,11 +31,9 @@
 #endif
 #include "sysemu/tcg.h"
 #include "sysemu/kvm.h"
-#include "sysemu/replay.h"
 #include "exec/cpu-common.h"
 #include "exec/exec-all.h"
 #include "exec/translate-all.h"
-#include "exec/log.h"
 #include "hw/core/accel-cpu.h"
 #include "trace/trace-root.h"
 #include "qemu/accel.h"
@@ -270,42 +268,6 @@ void cpu_single_step(CPUState *cpu, int enabled)
     }
 }
 
-void cpu_abort(CPUState *cpu, const char *fmt, ...)
-{
-    va_list ap;
-    va_list ap2;
-
-    va_start(ap, fmt);
-    va_copy(ap2, ap);
-    fprintf(stderr, "qemu: fatal: ");
-    vfprintf(stderr, fmt, ap);
-    fprintf(stderr, "\n");
-    cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
-    if (qemu_log_separate()) {
-        FILE *logfile = qemu_log_trylock();
-        if (logfile) {
-            fprintf(logfile, "qemu: fatal: ");
-            vfprintf(logfile, fmt, ap2);
-            fprintf(logfile, "\n");
-            cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
-            qemu_log_unlock(logfile);
-        }
-    }
-    va_end(ap2);
-    va_end(ap);
-    replay_finish();
-#if defined(CONFIG_USER_ONLY)
-    {
-        struct sigaction act;
-        sigfillset(&act.sa_mask);
-        act.sa_handler = SIG_DFL;
-        act.sa_flags = 0;
-        sigaction(SIGABRT, &act, NULL);
-    }
-#endif
-    abort();
-}
-
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
 int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
cpus-common.c +38 -0
index 8fdb34740e..38af2ab840 100644
@@ -21,9 +21,11 @@
 #include "qemu/main-loop.h"
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
+#include "exec/log.h"
 #include "hw/qdev-properties.h"
 #include "hw/core/cpu.h"
 #include "sysemu/cpus.h"
+#include "sysemu/replay.h"
 #include "qemu/lockable.h"
 #include "trace/trace-root.h"
 
@@ -485,3 +487,39 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
         }
     }
 }
+
+void cpu_abort(CPUState *cpu, const char *fmt, ...)
+{
+    va_list ap;
+    va_list ap2;
+
+    va_start(ap, fmt);
+    va_copy(ap2, ap);
+    fprintf(stderr, "qemu: fatal: ");
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+    if (qemu_log_separate()) {
+        FILE *logfile = qemu_log_trylock();
+        if (logfile) {
+            fprintf(logfile, "qemu: fatal: ");
+            vfprintf(logfile, fmt, ap2);
+            fprintf(logfile, "\n");
+            cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+            qemu_log_unlock(logfile);
+        }
+    }
+    va_end(ap2);
+    va_end(ap);
+    replay_finish();
+#if defined(CONFIG_USER_ONLY)
+    {
+        struct sigaction act;
+        sigfillset(&act.sa_mask);
+        act.sa_handler = SIG_DFL;
+        act.sa_flags = 0;
+        sigaction(SIGABRT, &act, NULL);
+    }
+#endif
+    abort();
+}
Signature · 1 line
2.38.1
#8 lore raw

Re: [PATCH-for-8.0 4/5] cpu: Move cpu_abort() to common code

Quoted 103 lines · Philippe Mathieu-Daudé

This code is not target-specific.

---
  cpu.c         | 38 --------------------------------------
  cpus-common.c | 38 ++++++++++++++++++++++++++++++++++++++
  2 files changed, 38 insertions(+), 38 deletions(-)
cpu.c +0 -38
index 385e72e140..d6936a536b 100644
@@ -31,11 +31,9 @@
  #endif
  #include "sysemu/tcg.h"
  #include "sysemu/kvm.h"
-#include "sysemu/replay.h"
  #include "exec/cpu-common.h"
  #include "exec/exec-all.h"
  #include "exec/translate-all.h"
-#include "exec/log.h"
  #include "hw/core/accel-cpu.h"
  #include "trace/trace-root.h"
  #include "qemu/accel.h"
@@ -270,42 +268,6 @@ void cpu_single_step(CPUState *cpu, int enabled)
      }
  }
 
-void cpu_abort(CPUState *cpu, const char *fmt, ...)
-{
-    va_list ap;
-    va_list ap2;
-
-    va_start(ap, fmt);
-    va_copy(ap2, ap);
-    fprintf(stderr, "qemu: fatal: ");
-    vfprintf(stderr, fmt, ap);
-    fprintf(stderr, "\n");
-    cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
-    if (qemu_log_separate()) {
-        FILE *logfile = qemu_log_trylock();
-        if (logfile) {
-            fprintf(logfile, "qemu: fatal: ");
-            vfprintf(logfile, fmt, ap2);
-            fprintf(logfile, "\n");
-            cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
-            qemu_log_unlock(logfile);
-        }
-    }
-    va_end(ap2);
-    va_end(ap);
-    replay_finish();
-#if defined(CONFIG_USER_ONLY)
-    {
-        struct sigaction act;
-        sigfillset(&act.sa_mask);
-        act.sa_handler = SIG_DFL;
-        act.sa_flags = 0;
-        sigaction(SIGABRT, &act, NULL);
-    }
-#endif
-    abort();
-}
-
  /* physical memory access (slow version, mainly for debug) */
  #if defined(CONFIG_USER_ONLY)
  int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
cpus-common.c +18 -0
index 8fdb34740e..38af2ab840 100644
@@ -21,9 +21,11 @@
  #include "qemu/main-loop.h"
  #include "exec/cpu-common.h"
  #include "exec/memory.h"
+#include "exec/log.h"
  #include "hw/qdev-properties.h"
  #include "hw/core/cpu.h"
  #include "sysemu/cpus.h"
+#include "sysemu/replay.h"
  #include "qemu/lockable.h"
  #include "trace/trace-root.h"
 
@@ -485,3 +487,39 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
          }
      }
  }
+
+void cpu_abort(CPUState *cpu, const char *fmt, ...)
+{
+    va_list ap;
+    va_list ap2;
+
+    va_start(ap, fmt);
+    va_copy(ap2, ap);
+    fprintf(stderr, "qemu: fatal: ");
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+    if (qemu_log_separate()) {
+        FILE *logfile = qemu_log_trylock();
+        if (logfile) {
+            fprintf(logfile, "qemu: fatal: ");

cpus-common.c void cpu_breakpoint_remove_all(CPUState *cpu, int mask) · line 515

Quoted 10 lines
cpus-common.c +10 -0
+            vfprintf(logfile, fmt, ap2);
+            fprintf(logfile, "\n");
+            cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+            qemu_log_unlock(logfile);
+        }
+    }
+    va_end(ap2);
+    va_end(ap);
+    replay_finish();
+#if defined(CONFIG_USER_ONLY)

CONFIG_USER_ONLY is build specific.

r~

#9 lore raw

PATCH 5/5 cpu: Remove unused includes

In reply to Philippe Mathieu-Daudé
---
 cpu.c | 3 ---
 1 file changed, 3 deletions(-)
cpu.c +0 -3
index d6936a536b..d512b24c0a 100644
@@ -31,10 +31,7 @@
 #endif
 #include "sysemu/tcg.h"
 #include "sysemu/kvm.h"
-#include "exec/cpu-common.h"
-#include "exec/exec-all.h"
 #include "exec/translate-all.h"
-#include "hw/core/accel-cpu.h"
 #include "trace/trace-root.h"
 #include "qemu/accel.h"
 
Signature · 1 line
2.38.1
Acked-by on v1 5/5
#10 lore raw

Re: [PATCH-for-8.0 5/5] cpu: Remove unused includes

Quoted 10 lines · Philippe Mathieu-Daudé
---
  cpu.c | 3 ---
  1 file changed, 3 deletions(-)
cpu.c +0 -0
index d6936a536b..d512b24c0a 100644

cpu.c line 37

Quoted 10 lines
cpu.c +0 -3
@@ -31,10 +31,7 @@
  #endif
  #include "sysemu/tcg.h"
  #include "sysemu/kvm.h"
-#include "exec/cpu-common.h"
-#include "exec/exec-all.h"
  #include "exec/translate-all.h"
-#include "hw/core/accel-cpu.h"
  #include "trace/trace-root.h"
  #include "qemu/accel.h"
 

r~

#12 lore raw
Quoted 1 line · Paolo Bonzini

Queued, thanks.

I think at least two patches are broken.

r~