qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Make the core disassembler functions target-independent
@ 2023-05-09 16:33 Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 1/5] disas: Move disas.c to disas/ Richard Henderson
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

Merges Thomas' RFC patch set with part of my "build-tcg-once" patch set.
The only real change from Thomas' is to use uint64_t instead of hwaddr.


r~


Richard Henderson (3):
  disas: Move disas.c to disas/
  disas: Remove target_ulong from the interface
  disas: Remove target-specific headers

Thomas Huth (2):
  disas: Move softmmu specific code to separate file
  disas: Move disas.c into the target-independent source set

 meson.build              |   3 --
 disas/disas-internal.h   |  21 ++++++++
 include/disas/disas.h    |  23 +++------
 bsd-user/elfload.c       |   5 +-
 disas/disas-mon.c        |  65 +++++++++++++++++++++++++
 disas.c => disas/disas.c | 100 +++++++--------------------------------
 linux-user/elfload.c     |   5 +-
 disas/meson.build        |   6 ++-
 8 files changed, 121 insertions(+), 107 deletions(-)
 create mode 100644 disas/disas-internal.h
 create mode 100644 disas/disas-mon.c
 rename disas.c => disas/disas.c (79%)

-- 
2.34.1



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

* [PATCH v2 1/5] disas: Move disas.c to disas/
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
@ 2023-05-09 16:33 ` Richard Henderson
  2023-05-10 15:12   ` Philippe Mathieu-Daudé
  2023-05-09 16:33 ` [PATCH v2 2/5] disas: Remove target_ulong from the interface Richard Henderson
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230503072331.1747057-80-richard.henderson@linaro.org>
---
 meson.build              | 3 ---
 disas.c => disas/disas.c | 0
 disas/meson.build        | 4 +++-
 3 files changed, 3 insertions(+), 4 deletions(-)
 rename disas.c => disas/disas.c (100%)

diff --git a/meson.build b/meson.build
index 229eb585f7..d56358b65f 100644
--- a/meson.build
+++ b/meson.build
@@ -3152,9 +3152,6 @@ specific_ss.add(files('cpu.c'))
 
 subdir('softmmu')
 
-common_ss.add(capstone)
-specific_ss.add(files('disas.c'), capstone)
-
 # Work around a gcc bug/misfeature wherein constant propagation looks
 # through an alias:
 #   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99696
diff --git a/disas.c b/disas/disas.c
similarity index 100%
rename from disas.c
rename to disas/disas.c
diff --git a/disas/meson.build b/disas/meson.build
index c865bdd882..cbf6315f25 100644
--- a/disas/meson.build
+++ b/disas/meson.build
@@ -10,4 +10,6 @@ common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files('riscv.c'))
 common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
 common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
 common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
-common_ss.add(when: capstone, if_true: files('capstone.c'))
+common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
+
+specific_ss.add(files('disas.c'), capstone)
-- 
2.34.1



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

* [PATCH v2 2/5] disas: Remove target_ulong from the interface
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 1/5] disas: Move disas.c to disas/ Richard Henderson
@ 2023-05-09 16:33 ` Richard Henderson
  2023-05-10  6:48   ` Thomas Huth
  2023-05-09 16:33 ` [PATCH v2 3/5] disas: Remove target-specific headers Richard Henderson
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

Use uint64_t for the pc, and size_t for the size.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230503072331.1747057-81-richard.henderson@linaro.org>
---
 include/disas/disas.h | 17 ++++++-----------
 bsd-user/elfload.c    |  5 +++--
 disas/disas.c         | 19 +++++++++----------
 linux-user/elfload.c  |  5 +++--
 4 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/include/disas/disas.h b/include/disas/disas.h
index d363e95ede..6c394e0b09 100644
--- a/include/disas/disas.h
+++ b/include/disas/disas.h
@@ -7,28 +7,23 @@
 #include "cpu.h"
 
 /* Disassemble this for me please... (debugging). */
-void disas(FILE *out, const void *code, unsigned long size);
-void target_disas(FILE *out, CPUState *cpu, target_ulong code,
-                  target_ulong size);
+void disas(FILE *out, const void *code, size_t size);
+void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size);
 
-void monitor_disas(Monitor *mon, CPUState *cpu,
-                   target_ulong pc, int nb_insn, int is_physical);
+void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
+                   int nb_insn, bool is_physical);
 
 char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size);
 
 /* Look up symbol for debugging purpose.  Returns "" if unknown. */
-const char *lookup_symbol(target_ulong orig_addr);
+const char *lookup_symbol(uint64_t orig_addr);
 #endif
 
 struct syminfo;
 struct elf32_sym;
 struct elf64_sym;
 
-#if defined(CONFIG_USER_ONLY)
-typedef const char *(*lookup_symbol_t)(struct syminfo *s, target_ulong orig_addr);
-#else
-typedef const char *(*lookup_symbol_t)(struct syminfo *s, hwaddr orig_addr);
-#endif
+typedef const char *(*lookup_symbol_t)(struct syminfo *s, uint64_t orig_addr);
 
 struct syminfo {
     lookup_symbol_t lookup_symbol;
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index fbcdc94b96..2e76f0d3b5 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -352,9 +352,10 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
 
 static int symfind(const void *s0, const void *s1)
 {
-    target_ulong addr = *(target_ulong *)s0;
+    __typeof(sym->st_value) addr = *(uint64_t *)s0;
     struct elf_sym *sym = (struct elf_sym *)s1;
     int result = 0;
+
     if (addr < sym->st_value) {
         result = -1;
     } else if (addr >= sym->st_value + sym->st_size) {
@@ -363,7 +364,7 @@ static int symfind(const void *s0, const void *s1)
     return result;
 }
 
-static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
+static const char *lookup_symbolxx(struct syminfo *s, uint64_t orig_addr)
 {
 #if ELF_CLASS == ELFCLASS32
     struct elf_sym *syms = s->disas_symtab.elf32;
diff --git a/disas/disas.c b/disas/disas.c
index b087c12c47..f5e95043cf 100644
--- a/disas/disas.c
+++ b/disas/disas.c
@@ -204,10 +204,9 @@ static void initialize_debug_host(CPUDebug *s)
 }
 
 /* Disassemble this for me please... (debugging).  */
-void target_disas(FILE *out, CPUState *cpu, target_ulong code,
-                  target_ulong size)
+void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size)
 {
-    target_ulong pc;
+    uint64_t pc;
     int count;
     CPUDebug s;
 
@@ -226,7 +225,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     }
 
     for (pc = code; size > 0; pc += count, size -= count) {
-	fprintf(out, "0x" TARGET_FMT_lx ":  ", pc);
+	fprintf(out, "0x%08" PRIx64 ":  ", pc);
 	count = s.info.print_insn(pc, &s.info);
 	fprintf(out, "\n");
 	if (count < 0)
@@ -292,7 +291,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
 }
 
 /* Disassemble this for me please... (debugging). */
-void disas(FILE *out, const void *code, unsigned long size)
+void disas(FILE *out, const void *code, size_t size)
 {
     uintptr_t pc;
     int count;
@@ -324,7 +323,7 @@ void disas(FILE *out, const void *code, unsigned long size)
 }
 
 /* Look up symbol for debugging purpose.  Returns "" if unknown. */
-const char *lookup_symbol(target_ulong orig_addr)
+const char *lookup_symbol(uint64_t orig_addr)
 {
     const char *symbol = "";
     struct syminfo *s;
@@ -356,8 +355,8 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
 }
 
 /* Disassembler for the monitor.  */
-void monitor_disas(Monitor *mon, CPUState *cpu,
-                   target_ulong pc, int nb_insn, int is_physical)
+void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
+                   int nb_insn, bool is_physical)
 {
     int count, i;
     CPUDebug s;
@@ -378,13 +377,13 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
     }
 
     if (!s.info.print_insn) {
-        monitor_printf(mon, "0x" TARGET_FMT_lx
+        monitor_printf(mon, "0x%08" PRIx64
                        ": Asm output not supported on this arch\n", pc);
         return;
     }
 
     for (i = 0; i < nb_insn; i++) {
-        g_string_append_printf(ds, "0x" TARGET_FMT_lx ":  ", pc);
+        g_string_append_printf(ds, "0x%08" PRIx64 ":  ", pc);
         count = s.info.print_insn(pc, &s.info);
         g_string_append_c(ds, '\n');
         if (count < 0) {
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 703f7434a0..80085b8a30 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3327,9 +3327,10 @@ static void load_elf_interp(const char *filename, struct image_info *info,
 
 static int symfind(const void *s0, const void *s1)
 {
-    target_ulong addr = *(target_ulong *)s0;
     struct elf_sym *sym = (struct elf_sym *)s1;
+    __typeof(sym->st_value) addr = *(uint64_t *)s0;
     int result = 0;
+
     if (addr < sym->st_value) {
         result = -1;
     } else if (addr >= sym->st_value + sym->st_size) {
@@ -3338,7 +3339,7 @@ static int symfind(const void *s0, const void *s1)
     return result;
 }
 
-static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
+static const char *lookup_symbolxx(struct syminfo *s, uint64_t orig_addr)
 {
 #if ELF_CLASS == ELFCLASS32
     struct elf_sym *syms = s->disas_symtab.elf32;
-- 
2.34.1



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

* [PATCH v2 3/5] disas: Remove target-specific headers
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 1/5] disas: Move disas.c to disas/ Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 2/5] disas: Remove target_ulong from the interface Richard Henderson
@ 2023-05-09 16:33 ` Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 4/5] disas: Move softmmu specific code to separate file Richard Henderson
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230503072331.1747057-83-richard.henderson@linaro.org>
---
 include/disas/disas.h | 6 ------
 disas/disas.c         | 3 ++-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/disas/disas.h b/include/disas/disas.h
index 6c394e0b09..176775eff7 100644
--- a/include/disas/disas.h
+++ b/include/disas/disas.h
@@ -1,11 +1,6 @@
 #ifndef QEMU_DISAS_H
 #define QEMU_DISAS_H
 
-#include "exec/hwaddr.h"
-
-#ifdef NEED_CPU_H
-#include "cpu.h"
-
 /* Disassemble this for me please... (debugging). */
 void disas(FILE *out, const void *code, size_t size);
 void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size);
@@ -17,7 +12,6 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size);
 
 /* Look up symbol for debugging purpose.  Returns "" if unknown. */
 const char *lookup_symbol(uint64_t orig_addr);
-#endif
 
 struct syminfo;
 struct elf32_sym;
diff --git a/disas/disas.c b/disas/disas.c
index f5e95043cf..a709831e8d 100644
--- a/disas/disas.c
+++ b/disas/disas.c
@@ -3,9 +3,10 @@
 #include "disas/dis-asm.h"
 #include "elf.h"
 #include "qemu/qemu-print.h"
-
 #include "disas/disas.h"
 #include "disas/capstone.h"
+#include "hw/core/cpu.h"
+#include "exec/memory.h"
 
 typedef struct CPUDebug {
     struct disassemble_info info;
-- 
2.34.1



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

* [PATCH v2 4/5] disas: Move softmmu specific code to separate file
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
                   ` (2 preceding siblings ...)
  2023-05-09 16:33 ` [PATCH v2 3/5] disas: Remove target-specific headers Richard Henderson
@ 2023-05-09 16:33 ` Richard Henderson
  2023-05-09 16:33 ` [PATCH v2 5/5] disas: Move disas.c into the target-independent source set Richard Henderson
  2023-05-10  6:54 ` [PATCH v2 0/5] Make the core disassembler functions target-independent Thomas Huth
  5 siblings, 0 replies; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

From: Thomas Huth <thuth@redhat.com>

We'd like to move disas.c into the common code source set, where
CONFIG_USER_ONLY is not available anymore. So we have to move
the related code into a separate file instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
[rth: Type change done in a separate patch]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas/disas-internal.h | 21 ++++++++++++
 disas/disas-mon.c      | 65 ++++++++++++++++++++++++++++++++++++
 disas/disas.c          | 76 ++++--------------------------------------
 disas/meson.build      |  1 +
 4 files changed, 93 insertions(+), 70 deletions(-)
 create mode 100644 disas/disas-internal.h
 create mode 100644 disas/disas-mon.c

diff --git a/disas/disas-internal.h b/disas/disas-internal.h
new file mode 100644
index 0000000000..84a01f126f
--- /dev/null
+++ b/disas/disas-internal.h
@@ -0,0 +1,21 @@
+/*
+ * Definitions used internally in the disassembly code
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef DISAS_INTERNAL_H
+#define DISAS_INTERNAL_H
+
+#include "disas/dis-asm.h"
+
+typedef struct CPUDebug {
+    struct disassemble_info info;
+    CPUState *cpu;
+} CPUDebug;
+
+void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu);
+int disas_gstring_printf(FILE *stream, const char *fmt, ...)
+    G_GNUC_PRINTF(2, 3);
+
+#endif
diff --git a/disas/disas-mon.c b/disas/disas-mon.c
new file mode 100644
index 0000000000..48ac492c6c
--- /dev/null
+++ b/disas/disas-mon.c
@@ -0,0 +1,65 @@
+/*
+ * Functions related to disassembly from the monitor
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "disas-internal.h"
+#include "disas/disas.h"
+#include "exec/memory.h"
+#include "hw/core/cpu.h"
+#include "monitor/monitor.h"
+
+static int
+physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
+                     struct disassemble_info *info)
+{
+    CPUDebug *s = container_of(info, CPUDebug, info);
+    MemTxResult res;
+
+    res = address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED,
+                             myaddr, length);
+    return res == MEMTX_OK ? 0 : EIO;
+}
+
+/* Disassembler for the monitor.  */
+void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
+                   int nb_insn, bool is_physical)
+{
+    int count, i;
+    CPUDebug s;
+    g_autoptr(GString) ds = g_string_new("");
+
+    disas_initialize_debug_target(&s, cpu);
+    s.info.fprintf_func = disas_gstring_printf;
+    s.info.stream = (FILE *)ds;  /* abuse this slot */
+
+    if (is_physical) {
+        s.info.read_memory_func = physical_read_memory;
+    }
+    s.info.buffer_vma = pc;
+
+    if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
+        monitor_puts(mon, ds->str);
+        return;
+    }
+
+    if (!s.info.print_insn) {
+        monitor_printf(mon, "0x%08" PRIx64
+                       ": Asm output not supported on this arch\n", pc);
+        return;
+    }
+
+    for (i = 0; i < nb_insn; i++) {
+        g_string_append_printf(ds, "0x%08" PRIx64 ":  ", pc);
+        count = s.info.print_insn(pc, &s.info);
+        g_string_append_c(ds, '\n');
+        if (count < 0) {
+            break;
+        }
+        pc += count;
+    }
+
+    monitor_puts(mon, ds->str);
+}
diff --git a/disas/disas.c b/disas/disas.c
index a709831e8d..5e7401bb6f 100644
--- a/disas/disas.c
+++ b/disas/disas.c
@@ -1,6 +1,6 @@
 /* General "disassemble this chunk" code.  Used for debugging. */
 #include "qemu/osdep.h"
-#include "disas/dis-asm.h"
+#include "disas/disas-internal.h"
 #include "elf.h"
 #include "qemu/qemu-print.h"
 #include "disas/disas.h"
@@ -8,11 +8,6 @@
 #include "hw/core/cpu.h"
 #include "exec/memory.h"
 
-typedef struct CPUDebug {
-    struct disassemble_info info;
-    CPUState *cpu;
-} CPUDebug;
-
 /* Filled in by elfload.c.  Simplistic, but will do for now. */
 struct syminfo *syminfos = NULL;
 
@@ -120,7 +115,7 @@ static void initialize_debug(CPUDebug *s)
     s->info.symbol_at_address_func = symbol_at_address;
 }
 
-static void initialize_debug_target(CPUDebug *s, CPUState *cpu)
+void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
 {
     initialize_debug(s);
 
@@ -211,7 +206,7 @@ void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size)
     int count;
     CPUDebug s;
 
-    initialize_debug_target(&s, cpu);
+    disas_initialize_debug_target(&s, cpu);
     s.info.fprintf_func = fprintf;
     s.info.stream = out;
     s.info.buffer_vma = code;
@@ -241,8 +236,7 @@ void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size)
     }
 }
 
-static int G_GNUC_PRINTF(2, 3)
-gstring_printf(FILE *stream, const char *fmt, ...)
+int disas_gstring_printf(FILE *stream, const char *fmt, ...)
 {
     /* We abuse the FILE parameter to pass a GString. */
     GString *s = (GString *)stream;
@@ -272,8 +266,8 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
     CPUDebug s;
     GString *ds = g_string_new(NULL);
 
-    initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = gstring_printf;
+    disas_initialize_debug_target(&s, cpu);
+    s.info.fprintf_func = disas_gstring_printf;
     s.info.stream = (FILE *)ds;  /* abuse this slot */
     s.info.buffer_vma = addr;
     s.info.buffer_length = size;
@@ -338,61 +332,3 @@ const char *lookup_symbol(uint64_t orig_addr)
 
     return symbol;
 }
-
-#if !defined(CONFIG_USER_ONLY)
-
-#include "monitor/monitor.h"
-
-static int
-physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
-                     struct disassemble_info *info)
-{
-    CPUDebug *s = container_of(info, CPUDebug, info);
-    MemTxResult res;
-
-    res = address_space_read(s->cpu->as, memaddr, MEMTXATTRS_UNSPECIFIED,
-                             myaddr, length);
-    return res == MEMTX_OK ? 0 : EIO;
-}
-
-/* Disassembler for the monitor.  */
-void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc,
-                   int nb_insn, bool is_physical)
-{
-    int count, i;
-    CPUDebug s;
-    g_autoptr(GString) ds = g_string_new("");
-
-    initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = gstring_printf;
-    s.info.stream = (FILE *)ds;  /* abuse this slot */
-
-    if (is_physical) {
-        s.info.read_memory_func = physical_read_memory;
-    }
-    s.info.buffer_vma = pc;
-
-    if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
-        monitor_puts(mon, ds->str);
-        return;
-    }
-
-    if (!s.info.print_insn) {
-        monitor_printf(mon, "0x%08" PRIx64
-                       ": Asm output not supported on this arch\n", pc);
-        return;
-    }
-
-    for (i = 0; i < nb_insn; i++) {
-        g_string_append_printf(ds, "0x%08" PRIx64 ":  ", pc);
-        count = s.info.print_insn(pc, &s.info);
-        g_string_append_c(ds, '\n');
-        if (count < 0) {
-            break;
-        }
-        pc += count;
-    }
-
-    monitor_puts(mon, ds->str);
-}
-#endif
diff --git a/disas/meson.build b/disas/meson.build
index cbf6315f25..f40230c58f 100644
--- a/disas/meson.build
+++ b/disas/meson.build
@@ -12,4 +12,5 @@ common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
 common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
 common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
 
+softmmu_ss.add(files('disas-mon.c'))
 specific_ss.add(files('disas.c'), capstone)
-- 
2.34.1



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

* [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
                   ` (3 preceding siblings ...)
  2023-05-09 16:33 ` [PATCH v2 4/5] disas: Move softmmu specific code to separate file Richard Henderson
@ 2023-05-09 16:33 ` Richard Henderson
  2023-05-10  6:53   ` Thomas Huth
  2023-05-10  6:54 ` [PATCH v2 0/5] Make the core disassembler functions target-independent Thomas Huth
  5 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2023-05-09 16:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: anjo, philmd, thuth

From: Thomas Huth <thuth@redhat.com>

By using target_words_bigendian() instead of an ifdef,
we can build this code once.

Signed-off-by: Thomas Huth <thuth@redhat.com>
[rth: Type change done in a separate patch]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas/disas.c     | 10 +++++-----
 disas/meson.build |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/disas/disas.c b/disas/disas.c
index 5e7401bb6f..954b385a82 100644
--- a/disas/disas.c
+++ b/disas/disas.c
@@ -122,11 +122,11 @@ void disas_initialize_debug_target(CPUDebug *s, CPUState *cpu)
     s->cpu = cpu;
     s->info.read_memory_func = target_read_memory;
     s->info.print_address_func = print_address;
-#if TARGET_BIG_ENDIAN
-    s->info.endian = BFD_ENDIAN_BIG;
-#else
-    s->info.endian = BFD_ENDIAN_LITTLE;
-#endif
+    if (target_words_bigendian()) {
+        s->info.endian = BFD_ENDIAN_BIG;
+    } else {
+        s->info.endian =  BFD_ENDIAN_LITTLE;
+    }
 
     CPUClass *cc = CPU_GET_CLASS(cpu);
     if (cc->disas_set_info) {
diff --git a/disas/meson.build b/disas/meson.build
index f40230c58f..2ae44691fa 100644
--- a/disas/meson.build
+++ b/disas/meson.build
@@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
 common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
 
 softmmu_ss.add(files('disas-mon.c'))
-specific_ss.add(files('disas.c'), capstone)
+common_ss.add(files('disas.c'), capstone)
+specific_ss.add(capstone)
-- 
2.34.1



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

* Re: [PATCH v2 2/5] disas: Remove target_ulong from the interface
  2023-05-09 16:33 ` [PATCH v2 2/5] disas: Remove target_ulong from the interface Richard Henderson
@ 2023-05-10  6:48   ` Thomas Huth
  0 siblings, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2023-05-10  6:48 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: anjo, philmd

On 09/05/2023 18.33, Richard Henderson wrote:
> Use uint64_t for the pc, and size_t for the size.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> Message-Id: <20230503072331.1747057-81-richard.henderson@linaro.org>
> ---
>   include/disas/disas.h | 17 ++++++-----------
>   bsd-user/elfload.c    |  5 +++--
>   disas/disas.c         | 19 +++++++++----------
>   linux-user/elfload.c  |  5 +++--
>   4 files changed, 21 insertions(+), 25 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-09 16:33 ` [PATCH v2 5/5] disas: Move disas.c into the target-independent source set Richard Henderson
@ 2023-05-10  6:53   ` Thomas Huth
  2023-05-10  7:46     ` Richard Henderson
  0 siblings, 1 reply; 14+ messages in thread
From: Thomas Huth @ 2023-05-10  6:53 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: anjo, philmd

On 09/05/2023 18.33, Richard Henderson wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> By using target_words_bigendian() instead of an ifdef,
> we can build this code once.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> [rth: Type change done in a separate patch]
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
...
> diff --git a/disas/meson.build b/disas/meson.build
> index f40230c58f..2ae44691fa 100644
> --- a/disas/meson.build
> +++ b/disas/meson.build
> @@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
>   common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
>   
>   softmmu_ss.add(files('disas-mon.c'))
> -specific_ss.add(files('disas.c'), capstone)
> +common_ss.add(files('disas.c'), capstone)

I guess you could drop the "capstone" here now since it is already added to 
common_ss now three lines earlier.

  Thomas



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

* Re: [PATCH v2 0/5] Make the core disassembler functions target-independent
  2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
                   ` (4 preceding siblings ...)
  2023-05-09 16:33 ` [PATCH v2 5/5] disas: Move disas.c into the target-independent source set Richard Henderson
@ 2023-05-10  6:54 ` Thomas Huth
  5 siblings, 0 replies; 14+ messages in thread
From: Thomas Huth @ 2023-05-10  6:54 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: anjo, philmd

On 09/05/2023 18.33, Richard Henderson wrote:
> Merges Thomas' RFC patch set with part of my "build-tcg-once" patch set.
> The only real change from Thomas' is to use uint64_t instead of hwaddr.

Thanks for integrating it!

There's a minor nit in patch 5, but apart from that, I think this series is 
fine now for getting merged.

  Thomas




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

* Re: [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-10  6:53   ` Thomas Huth
@ 2023-05-10  7:46     ` Richard Henderson
  2023-05-10  8:10       ` Thomas Huth
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2023-05-10  7:46 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: anjo, philmd

On 5/10/23 07:53, Thomas Huth wrote:
> On 09/05/2023 18.33, Richard Henderson wrote:
>> From: Thomas Huth <thuth@redhat.com>
>>
>> By using target_words_bigendian() instead of an ifdef,
>> we can build this code once.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> [rth: Type change done in a separate patch]
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
> ...
>> diff --git a/disas/meson.build b/disas/meson.build
>> index f40230c58f..2ae44691fa 100644
>> --- a/disas/meson.build
>> +++ b/disas/meson.build
>> @@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
>>   common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
>>   softmmu_ss.add(files('disas-mon.c'))
>> -specific_ss.add(files('disas.c'), capstone)
>> +common_ss.add(files('disas.c'), capstone)
> 
> I guess you could drop the "capstone" here now since it is already added to common_ss now 
> three lines earlier.

I have a memory that it's required to get the include path for <capstone.h> for 
"disas/capstone.h", for use by the target's cpu_set_disas_info.  Otherwise only common_ss 
files have access to the include path.

But I'll double-check.


r~



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

* Re: [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-10  7:46     ` Richard Henderson
@ 2023-05-10  8:10       ` Thomas Huth
  2023-05-10  8:13         ` Richard Henderson
  0 siblings, 1 reply; 14+ messages in thread
From: Thomas Huth @ 2023-05-10  8:10 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: anjo, philmd

On 10/05/2023 09.46, Richard Henderson wrote:
> On 5/10/23 07:53, Thomas Huth wrote:
>> On 09/05/2023 18.33, Richard Henderson wrote:
>>> From: Thomas Huth <thuth@redhat.com>
>>>
>>> By using target_words_bigendian() instead of an ifdef,
>>> we can build this code once.
>>>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> [rth: Type change done in a separate patch]
>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>> ...
>>> diff --git a/disas/meson.build b/disas/meson.build
>>> index f40230c58f..2ae44691fa 100644
>>> --- a/disas/meson.build
>>> +++ b/disas/meson.build
>>> @@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: 
>>> files('xtensa.c'))
>>>   common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
>>>   softmmu_ss.add(files('disas-mon.c'))
>>> -specific_ss.add(files('disas.c'), capstone)
>>> +common_ss.add(files('disas.c'), capstone)
>>
>> I guess you could drop the "capstone" here now since it is already added 
>> to common_ss now three lines earlier.
> 
> I have a memory that it's required to get the include path for <capstone.h> 
> for "disas/capstone.h", for use by the target's cpu_set_disas_info.  
> Otherwise only common_ss files have access to the include path.

I only meant to remove it from the new "common_ss.add(files('disas.c')" line 
since it is already there in the "common_ss.add(when: capstone, if_true: 
[files('capstone.c'), capstone])" line ... I think you have to keep the 
"specific_ss.add(capstone)" line.

  Thomas




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

* Re: [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-10  8:10       ` Thomas Huth
@ 2023-05-10  8:13         ` Richard Henderson
  2023-05-10 15:19           ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Henderson @ 2023-05-10  8:13 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: anjo, philmd

On 5/10/23 09:10, Thomas Huth wrote:
> On 10/05/2023 09.46, Richard Henderson wrote:
>> On 5/10/23 07:53, Thomas Huth wrote:
>>> On 09/05/2023 18.33, Richard Henderson wrote:
>>>> From: Thomas Huth <thuth@redhat.com>
>>>>
>>>> By using target_words_bigendian() instead of an ifdef,
>>>> we can build this code once.
>>>>
>>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>>> [rth: Type change done in a separate patch]
>>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>>> ---
>>> ...
>>>> diff --git a/disas/meson.build b/disas/meson.build
>>>> index f40230c58f..2ae44691fa 100644
>>>> --- a/disas/meson.build
>>>> +++ b/disas/meson.build
>>>> @@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: files('xtensa.c'))
>>>>   common_ss.add(when: capstone, if_true: [files('capstone.c'), capstone])
>>>>   softmmu_ss.add(files('disas-mon.c'))
>>>> -specific_ss.add(files('disas.c'), capstone)
>>>> +common_ss.add(files('disas.c'), capstone)
>>>
>>> I guess you could drop the "capstone" here now since it is already added to common_ss 
>>> now three lines earlier.
>>
>> I have a memory that it's required to get the include path for <capstone.h> for 
>> "disas/capstone.h", for use by the target's cpu_set_disas_info. Otherwise only common_ss 
>> files have access to the include path.
> 
> I only meant to remove it from the new "common_ss.add(files('disas.c')" line since it is 
> already there in the "common_ss.add(when: capstone, if_true: [files('capstone.c'), 
> capstone])" line ... I think you have to keep the "specific_ss.add(capstone)" line.

Oh, yes, duplicate within common_ss.  Removed.


r~



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

* Re: [PATCH v2 1/5] disas: Move disas.c to disas/
  2023-05-09 16:33 ` [PATCH v2 1/5] disas: Move disas.c to disas/ Richard Henderson
@ 2023-05-10 15:12   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-10 15:12 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: anjo, thuth

On 9/5/23 18:33, Richard Henderson wrote:
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> Message-Id: <20230503072331.1747057-80-richard.henderson@linaro.org>
> ---
>   meson.build              | 3 ---
>   disas.c => disas/disas.c | 0
>   disas/meson.build        | 4 +++-
>   3 files changed, 3 insertions(+), 4 deletions(-)
>   rename disas.c => disas/disas.c (100%)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH v2 5/5] disas: Move disas.c into the target-independent source set
  2023-05-10  8:13         ` Richard Henderson
@ 2023-05-10 15:19           ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-10 15:19 UTC (permalink / raw)
  To: Richard Henderson, Thomas Huth, qemu-devel; +Cc: anjo

On 10/5/23 10:13, Richard Henderson wrote:
> On 5/10/23 09:10, Thomas Huth wrote:
>> On 10/05/2023 09.46, Richard Henderson wrote:
>>> On 5/10/23 07:53, Thomas Huth wrote:
>>>> On 09/05/2023 18.33, Richard Henderson wrote:
>>>>> From: Thomas Huth <thuth@redhat.com>
>>>>>
>>>>> By using target_words_bigendian() instead of an ifdef,
>>>>> we can build this code once.
>>>>>
>>>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>>>> [rth: Type change done in a separate patch]
>>>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>>>> ---
>>>> ...
>>>>> diff --git a/disas/meson.build b/disas/meson.build
>>>>> index f40230c58f..2ae44691fa 100644
>>>>> --- a/disas/meson.build
>>>>> +++ b/disas/meson.build
>>>>> @@ -13,4 +13,5 @@ common_ss.add(when: 'CONFIG_XTENSA_DIS', if_true: 
>>>>> files('xtensa.c'))
>>>>>   common_ss.add(when: capstone, if_true: [files('capstone.c'), 
>>>>> capstone])
>>>>>   softmmu_ss.add(files('disas-mon.c'))
>>>>> -specific_ss.add(files('disas.c'), capstone)
>>>>> +common_ss.add(files('disas.c'), capstone)
>>>>
>>>> I guess you could drop the "capstone" here now since it is already 
>>>> added to common_ss now three lines earlier.
>>>
>>> I have a memory that it's required to get the include path for 
>>> <capstone.h> for "disas/capstone.h", for use by the target's 
>>> cpu_set_disas_info. Otherwise only common_ss files have access to the 
>>> include path.
>>
>> I only meant to remove it from the new 
>> "common_ss.add(files('disas.c')" line since it is already there in the 
>> "common_ss.add(when: capstone, if_true: [files('capstone.c'), 
>> capstone])" line ... I think you have to keep the 
>> "specific_ss.add(capstone)" line.
> 
> Oh, yes, duplicate within common_ss.  Removed.

What the final patch looks like?



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

end of thread, other threads:[~2023-05-10 15:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-09 16:33 [PATCH v2 0/5] Make the core disassembler functions target-independent Richard Henderson
2023-05-09 16:33 ` [PATCH v2 1/5] disas: Move disas.c to disas/ Richard Henderson
2023-05-10 15:12   ` Philippe Mathieu-Daudé
2023-05-09 16:33 ` [PATCH v2 2/5] disas: Remove target_ulong from the interface Richard Henderson
2023-05-10  6:48   ` Thomas Huth
2023-05-09 16:33 ` [PATCH v2 3/5] disas: Remove target-specific headers Richard Henderson
2023-05-09 16:33 ` [PATCH v2 4/5] disas: Move softmmu specific code to separate file Richard Henderson
2023-05-09 16:33 ` [PATCH v2 5/5] disas: Move disas.c into the target-independent source set Richard Henderson
2023-05-10  6:53   ` Thomas Huth
2023-05-10  7:46     ` Richard Henderson
2023-05-10  8:10       ` Thomas Huth
2023-05-10  8:13         ` Richard Henderson
2023-05-10 15:19           ` Philippe Mathieu-Daudé
2023-05-10  6:54 ` [PATCH v2 0/5] Make the core disassembler functions target-independent Thomas Huth

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