Skip to contentSkip to conversation

target/arm: single-binary

PATCH Superseded Pierrick Bouvier 3 participants 39 messages Apr 7 – Apr 8

Subsystems (2)

v10 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v10 cover target/arm: single-binary

This series tackles (most of) the rest of target/arm, especially tcg folder.

We extract tcg memory operation in a new header, with a new type representing virtual addresses.

Initially, I went down the way to have a dynamic definition of TCGv, which required much more boilerplate and runtime checks. After discussing with Richard, I realized it was not needed, and that could simply split 32 and 64 bit properly in different files instead. This approach will not work with other architectures, requiring something else, but it's enough for target/arm.

Files left are:
- target/arm/tcg/mve_helper.c
- target/arm/tcg/m_helper.c
- target/arm/tcg/cpu32.c

v10
---

- extract patch for endianness handling in arm_disas_set_info
- added some comments

v9
--

- introduce aarch64_translate_code *before* adding parameter to translator_loop
- use TCG_TYPE_VA as address type for translator_loop
- remove inline marker on functions merged from arm_ldst.h to translate.c
- refactor arm_ldl_code/arm_lduw_code

v8
--

- make translate.c compilation unit common.

v7
--

- add parameter to translator_loop to indicate address type for current tb.
- remove TCGv from target/arm/tcg/translate.c

v6
--

- meson.build: extract decode files in separate variables and explicitly include them in user and system code. The duplication is now minimized: one instance for all system binaries, and one per user binary.

v5
--

- reimplemented what v0 did with new approach defining new tcg-op-mem header
- reapply all straightforward patches from v0
- only translate.c is left, but first want to validate that changes here are ok for maintainers before doing more.

v0
--

See original thread:
https://lore.kernel.org/qemu-devel/[email protected]/#t

Note about v1 -> v4
-------------------

- After v0 which was trying to do too many changes, v1 to v4 focused on smaller things, and all patches have been merged already.
https://patchew.org/QEMU/[email protected]/

Pierrick Bouvier (21):
include/tcg/tcg-op: extract memory operations to tcg-op-mem.h target/arm/translate.h: remove tcg-op.h include target/arm/tcg/translate.h: remove tcg-op-gvec.h include target/arm/tcg/translate.h: remove TARGET_AARCH64 target/arm/tcg/translate-vfp.c: make compilation unit common target/arm/tcg/translate-neon.c: make compilation unit common target/arm/tcg/translate-mve.c: make compilation unit common target/arm/tcg/translate-m-nocp.c: make compilation unit common target/arm/tcg/op_helper.c: make compilation unit common target/arm/tcg/gengvec.c: make compilation unit common target/arm/tcg/translate.c: remove MO_TE usage target/arm/tcg/translate.c: replace target_ulong with uint32_t target/arm/tcg/translate.c: extract aarch64_translate_code() tcg/translator: add parameter to translator_loop for current addr type target/arm/tcg/translate.c: replace TCGv with TCGv_va target/arm/tcg/translate-a64.c: use translator_ldl_end instead of
arm_ldl_code
target/arm/tcg/arm_ldst.h: merge in translate.c target/arm/tcg/translate.c: replace translator_ldl_swap with
translator_ldl_end
target/arm/cpu.c: simplify endianness handling in arm_disas_set_info target/arm/tcg/translate.c: remove target_ulong target/arm/tcg/translate.c: make compilation unit common

 include/exec/translator.h        |   4 +-
 include/tcg/tcg-op-mem.h         | 126 +++++++++++++++++++++++++++++++
 include/tcg/tcg-op.h             | 100 +-----------------------
 target/arm/internals.h           |   2 +
 target/arm/tcg/arm_ldst.h        |  47 ------------
 target/arm/tcg/translate.h       |  14 +---
 accel/tcg/translate-all.c        |   1 -
 accel/tcg/translator.c           |   4 +-
 target/alpha/translate.c         |   3 +-
 target/arm/cpu.c                 |   6 +-
 target/arm/tcg/op_helper.c       |   1 -
 target/arm/tcg/stubs32.c         |  24 ++++++
 target/arm/tcg/translate-a64.c   |  17 ++++-
 target/arm/tcg/translate-sme.c   |   1 +
 target/arm/tcg/translate-sve.c   |   1 +
 target/arm/tcg/translate.c       |  73 +++++++++++-------
 target/avr/translate.c           |   3 +-
 target/hexagon/translate.c       |   3 +-
 target/hppa/translate.c          |   3 +-
 target/i386/tcg/translate.c      |   3 +-
 target/loongarch/tcg/translate.c |   3 +-
 target/m68k/translate.c          |   3 +-
 target/microblaze/translate.c    |   3 +-
 target/mips/tcg/translate.c      |   3 +-
 target/or1k/translate.c          |   3 +-
 target/ppc/translate.c           |   3 +-
 target/riscv/translate.c         |   3 +-
 target/rx/translate.c            |   3 +-
 target/s390x/tcg/translate.c     |   3 +-
 target/sh4/translate.c           |   3 +-
 target/sparc/translate.c         |   3 +-
 target/tricore/translate.c       |   3 +-
 target/xtensa/translate.c        |   3 +-
 target/arm/tcg/meson.build       |  57 ++++++++++----
 34 files changed, 304 insertions(+), 228 deletions(-)
 create mode 100644 include/tcg/tcg-op-mem.h
 create mode 100644 target/arm/tcg/stubs32.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH v10 1/21 include/tcg/tcg-op: extract memory operations to tcg-op-mem.h

This new header defines a new type for target virtual address, independent from TCGv and is parameterized by a new define TCG_ADDRESS_BITS (name was suggested by Paolo instead of TARGET_ADDRESS_BITS).

By default, tcg-op.h include set this define to TARGET_LONG_BITS, but it's also possible to include only tcg-op-common.h and tcg-op-mem.h and set TCG_ADDRESS_BITS manually, which is what next commits will do.

We preserve existing MIT license when extracting this new header.

Implemented from:
https://lore.kernel.org/qemu-devel/[email protected]/

---
 include/tcg/tcg-op-mem.h | 126 +++++++++++++++++++++++++++++++++++++++
 include/tcg/tcg-op.h     | 100 +------------------------------
 2 files changed, 129 insertions(+), 97 deletions(-)
 create mode 100644 include/tcg/tcg-op-mem.h
include/tcg/tcg-op-mem.h new file +126 -0
new file mode 100644
index 00000000000..36931d1dd57
@@ -0,0 +1,126 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Target dependent memory related functions.
+ *
+ * Copyright (c) 2008 Fabrice Bellard
+ */
+
+#ifndef TCG_TCG_OP_MEM_H
+#define TCG_TCG_OP_MEM_H
+
+#ifndef TCG_ADDRESS_BITS
+#error TCG_ADDRESS_BITS must be defined
+#endif
+
+#if TCG_ADDRESS_BITS == 32
+typedef TCGv_i32 TCGv_va;
+#define TCG_TYPE_VA TCG_TYPE_I32
+#define tcgv_va_temp tcgv_i32_temp
+#define tcgv_va_temp_new tcg_temp_new_i32
+#elif TCG_ADDRESS_BITS == 64
+typedef TCGv_i64 TCGv_va;
+#define TCG_TYPE_VA TCG_TYPE_I64
+#define tcgv_va_temp tcgv_i64_temp
+#define tcgv_va_temp_new tcg_temp_new_i64
+#else
+#error
+#endif
+
+static inline void
+tcg_gen_qemu_ld_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+static inline void
+tcg_gen_qemu_st_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_st_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+static inline void
+tcg_gen_qemu_ld_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_ld_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+static inline void
+tcg_gen_qemu_st_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_st_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+static inline void
+tcg_gen_qemu_ld_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_ld_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+static inline void
+tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
+{
+    tcg_gen_qemu_st_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+}
+
+#define DEF_ATOMIC2(N, S)                                               \
+    static inline void N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S v,       \
+                               TCGArg i, MemOp m)                       \
+    { N##_##S##_chk(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
+
+#define DEF_ATOMIC3(N, S)                                               \
+    static inline void N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S o,       \
+                               TCGv_##S n, TCGArg i, MemOp m)           \
+    { N##_##S##_chk(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
+
+DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i32)
+DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i64)
+DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i128)
+
+DEF_ATOMIC3(tcg_gen_nonatomic_cmpxchg, i32)
+DEF_ATOMIC3(tcg_gen_nonatomic_cmpxchg, i64)
+DEF_ATOMIC3(tcg_gen_nonatomic_cmpxchg, i128)
+
+DEF_ATOMIC2(tcg_gen_atomic_xchg, i32)
+DEF_ATOMIC2(tcg_gen_atomic_xchg, i64)
+DEF_ATOMIC2(tcg_gen_atomic_xchg, i128)
+
+DEF_ATOMIC2(tcg_gen_atomic_fetch_add, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_add, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_and, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_and, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_and, i128)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_or, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_or, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_or, i128)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_xor, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_xor, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_smin, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_smin, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_umin, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_umin, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_smax, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_smax, i64)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_umax, i32)
+DEF_ATOMIC2(tcg_gen_atomic_fetch_umax, i64)
+
+DEF_ATOMIC2(tcg_gen_atomic_add_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_add_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_and_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_and_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_or_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_or_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_xor_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_xor_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_smin_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_smin_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_umin_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_umin_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_smax_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_smax_fetch, i64)
+DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i32)
+DEF_ATOMIC2(tcg_gen_atomic_umax_fetch, i64)
+
+#undef DEF_ATOMIC2
+#undef DEF_ATOMIC3
+
+#endif /* TCG_TCG_OP_MEM_H */
include/tcg/tcg-op.h +3 -97

112 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw

PATCH v10 2/21 target/arm/translate.h: remove tcg-op.h include

In reply to Pierrick Bouvier

Include tcg-op-common.h instead, and include target specific tcg-op.h in files needing it. This intermediate step allows to clean up every file (TCGv, tcg_gen.*_tl.*) in separate commits.

---
 target/arm/tcg/translate.h     | 2 +-
 target/arm/tcg/translate-a64.c | 1 +
 target/arm/tcg/translate-sme.c | 1 +
 target/arm/tcg/translate-sve.c | 1 +
 target/arm/tcg/translate.c     | 1 +
 5 files changed, 5 insertions(+), 1 deletion(-)
target/arm/tcg/translate.h +1 -1
index 3e3094a463e..6d52606f9b7 100644
@@ -2,7 +2,7 @@
 #define TARGET_ARM_TRANSLATE_H
 
 #include "cpu.h"
-#include "tcg/tcg-op.h"
+#include "tcg/tcg-op-common.h"
 #include "tcg/tcg-op-gvec.h"
 #include "exec/translator.h"
 #include "exec/translation-block.h"
target/arm/tcg/translate-a64.c +1 -0
index 5d261a5e32b..35ad7530c4b 100644
@@ -23,6 +23,7 @@
 #include "helper-sve.h"
 #include "translate.h"
 #include "translate-a64.h"
+#include "tcg/tcg-op.h"
 #include "qemu/log.h"
 #include "arm_ldst.h"
 #include "semihosting/semihost.h"
target/arm/tcg/translate-sme.c +1 -0
index 7d25ac5a51f..08254b088ed 100644
@@ -23,6 +23,7 @@
 #include "helper-sve.h"
 #include "translate.h"
 #include "translate-a64.h"
+#include "tcg/tcg-op.h"
 
 /*
  * Include the generated decoder.
target/arm/tcg/translate-sve.c +1 -0
index 5bace3fda1a..aa7d72a35ef 100644
@@ -23,6 +23,7 @@
 #include "helper-sve.h"
 #include "translate.h"
 #include "translate-a64.h"
+#include "tcg/tcg-op.h"
 #include "fpu/softfloat.h"
 
 
target/arm/tcg/translate.c +1 -0
index f9d1b8897d2..56ef1e0eb59 100644
@@ -22,6 +22,7 @@
 
 #include "translate.h"
 #include "translate-a32.h"
+#include "tcg/tcg-op.h"
 #include "qemu/log.h"
 #include "arm_ldst.h"
 #include "semihosting/semihost.h"
Signature · 1 line
2.47.3
#3 lore raw

PATCH v10 3/21 target/arm/tcg/translate.h: remove tcg-op-gvec.h include

In reply to Pierrick Bouvier

Include tcg-op-gvec-common.h instead.
No target/arm code rely on target specifics for gvec ops.

---
 target/arm/tcg/translate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/translate.h +1 -1
index 6d52606f9b7..e28eac54afb 100644
@@ -3,7 +3,7 @@
 
 #include "cpu.h"
 #include "tcg/tcg-op-common.h"
-#include "tcg/tcg-op-gvec.h"
+#include "tcg/tcg-op-gvec-common.h"
 #include "exec/translator.h"
 #include "exec/translation-block.h"
 #include "helper.h"
Signature · 1 line
2.47.3
#4 lore raw

PATCH v10 4/21 target/arm/tcg/translate.h: remove TARGET_AARCH64

In reply to Pierrick Bouvier

We need to stub a64_translate_init and gen_a64_update_pc. At this point, we don't need to do anything for aarch64_translator_ops since it's just an external symbol.

We can now include target/arm/tcg/translate.h from common code, since all target specific bits have been removed, or can be specialized with specific defines.

---
 target/arm/tcg/translate.h | 10 ----------
 target/arm/tcg/stubs32.c   | 17 +++++++++++++++++
 target/arm/tcg/meson.build |  1 +
 3 files changed, 18 insertions(+), 10 deletions(-)
 create mode 100644 target/arm/tcg/stubs32.c
target/arm/tcg/translate.h +0 -10
index e28eac54afb..77fdc5f3a17 100644
@@ -357,19 +357,9 @@ static inline int curr_insn_len(DisasContext *s)
 /* CPU state was modified dynamically; no need to exit, but do not chain. */
 #define DISAS_UPDATE_NOCHAIN  DISAS_TARGET_10
 
-#ifdef TARGET_AARCH64
 void a64_translate_init(void);
 void gen_a64_update_pc(DisasContext *s, int64_t diff);
 extern const TranslatorOps aarch64_translator_ops;
-#else
-static inline void a64_translate_init(void)
-{
-}
-
-static inline void gen_a64_update_pc(DisasContext *s, int64_t diff)
-{
-}
-#endif
 
 void arm_test_cc(DisasCompare *cmp, int cc);
 void arm_jump_cc(DisasCompare *cmp, TCGLabel *label);
target/arm/tcg/stubs32.c new file +17 -0
new file mode 100644
index 00000000000..c5a0bc61f47
@@ -0,0 +1,17 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "target/arm/tcg/translate.h"
+
+
+void gen_a64_update_pc(DisasContext *s, int64_t diff)
+{
+    g_assert_not_reached();
+}
+
+void a64_translate_init(void)
+{
+    /* Don't initialize for 32 bits. Call site will be fixed later. */
+}
target/arm/tcg/meson.build +1 -0
index 5f591560551..3e96c77df73 100644
@@ -21,6 +21,7 @@ gen_a32 = [
 
 arm_ss.add(gen_a32)
 arm_ss.add(when: 'TARGET_AARCH64', if_true: gen_a64)
+arm_ss.add(when: 'TARGET_AARCH64', if_false: files('stubs32.c'))
 
 arm_ss.add(files(
   'cpu32.c',
Signature · 1 line
2.47.3
#5 lore raw

PATCH v10 5/21 target/arm/tcg/translate-vfp.c: make compilation unit common

In reply to Pierrick Bouvier

Generated decode files must be duplicated between user and system, as they are generated in private folders per libs, and can't be included otherwise, as meson does not give control on output folder. Indeed, meson generator is a different approach than custom_target, and this is a limitation by design.

They were already duplicated between arch variants anyway, so nothing new here. They will now be compiled once for system binaries, and still per target for user binaries.

---
 target/arm/tcg/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
target/arm/tcg/meson.build +13 -5
index 3e96c77df73..5f33ecd76e0 100644
@@ -5,12 +5,15 @@ gen_a64 = [
   decodetree.process('sme-fa64.decode', extra_args: '--static-decode=disas_sme_fa64'),
 ]
 
+vfp_d = [
+  decodetree.process('vfp.decode', extra_args: '--decode=disas_vfp'),
+  decodetree.process('vfp-uncond.decode', extra_args: '--decode=disas_vfp_uncond'),
+]
+
 gen_a32 = [
   decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'),
   decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'),
   decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'),
-  decodetree.process('vfp.decode', extra_args: '--decode=disas_vfp'),
-  decodetree.process('vfp-uncond.decode', extra_args: '--decode=disas_vfp_uncond'),
   decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'),
   decodetree.process('mve.decode', extra_args: '--decode=disas_mve'),
   decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'),
@@ -30,7 +33,6 @@ arm_ss.add(files(
   'translate-m-nocp.c',
   'translate-mve.c',
   'translate-neon.c',
-  'translate-vfp.c',
   'm_helper.c',
   'mve_helper.c',
   'op_helper.c',
@@ -60,7 +62,9 @@ arm_common_ss.add(files(
   'crypto_helper.c',
 ))
 
-arm_common_system_ss.add(files(
+arm_common_system_ss.add(
+  vfp_d,
+  files(
   'cpregs-at.c',
   'debug.c',
   'hflags.c',
@@ -68,14 +72,18 @@ arm_common_system_ss.add(files(
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
+  'translate-vfp.c',
   'vec_helper.c',
   'vfp_helper.c',
 ))
-arm_user_ss.add(files(
+arm_user_ss.add(
+  vfp_d,
+  files(
   'debug.c',
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
+  'translate-vfp.c',
   'vec_helper.c',
   'vfp_helper.c',
 ))
Signature · 1 line
2.47.3
#6 lore raw

PATCH v10 6/21 target/arm/tcg/translate-neon.c: make compilation unit common

In reply to Pierrick Bouvier
---
 target/arm/tcg/meson.build | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/arm/tcg/meson.build +8 -2
index 5f33ecd76e0..8d9112f6da2 100644
@@ -10,10 +10,13 @@ vfp_d = [
   decodetree.process('vfp-uncond.decode', extra_args: '--decode=disas_vfp_uncond'),
 ]
 
-gen_a32 = [
+neon_d = [
   decodetree.process('neon-shared.decode', extra_args: '--decode=disas_neon_shared'),
   decodetree.process('neon-dp.decode', extra_args: '--decode=disas_neon_dp'),
   decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'),
+]
+
+gen_a32 = [
   decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'),
   decodetree.process('mve.decode', extra_args: '--decode=disas_mve'),
   decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'),
@@ -32,7 +35,6 @@ arm_ss.add(files(
   'translate.c',
   'translate-m-nocp.c',
   'translate-mve.c',
-  'translate-neon.c',
   'm_helper.c',
   'mve_helper.c',
   'op_helper.c',
@@ -63,6 +65,7 @@ arm_common_ss.add(files(
 ))
 
 arm_common_system_ss.add(
+  neon_d,
   vfp_d,
   files(
   'cpregs-at.c',
@@ -72,17 +75,20 @@ arm_common_system_ss.add(
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
+  'translate-neon.c',
   'translate-vfp.c',
   'vec_helper.c',
   'vfp_helper.c',
 ))
 arm_user_ss.add(
+  neon_d,
   vfp_d,
   files(
   'debug.c',
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
+  'translate-neon.c',
   'translate-vfp.c',
   'vec_helper.c',
   'vfp_helper.c',
Signature · 1 line
2.47.3
#7 lore raw

PATCH v10 7/21 target/arm/tcg/translate-mve.c: make compilation unit common

In reply to Pierrick Bouvier
---
 target/arm/tcg/meson.build | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
target/arm/tcg/meson.build +6 -2
index 8d9112f6da2..89c3b476822 100644
@@ -16,9 +16,10 @@ neon_d = [
   decodetree.process('neon-ls.decode', extra_args: '--decode=disas_neon_ls'),
 ]
 
+mve_d = decodetree.process('mve.decode', extra_args: '--decode=disas_mve')
+
 gen_a32 = [
   decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'),
-  decodetree.process('mve.decode', extra_args: '--decode=disas_mve'),
   decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'),
   decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'),
   decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'),
@@ -34,7 +35,6 @@ arm_ss.add(files(
   'gengvec.c',
   'translate.c',
   'translate-m-nocp.c',
-  'translate-mve.c',
   'm_helper.c',
   'mve_helper.c',
   'op_helper.c',
@@ -65,6 +65,7 @@ arm_common_ss.add(files(
 ))
 
 arm_common_system_ss.add(
+  mve_d,
   neon_d,
   vfp_d,
   files(
@@ -75,12 +76,14 @@ arm_common_system_ss.add(
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
+  'translate-mve.c',
   'translate-neon.c',
   'translate-vfp.c',
   'vec_helper.c',
   'vfp_helper.c',
 ))
 arm_user_ss.add(
+  mve_d,
   neon_d,
   vfp_d,
   files(
@@ -88,6 +91,7 @@ arm_user_ss.add(
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
+  'translate-mve.c',
   'translate-neon.c',
   'translate-vfp.c',
   'vec_helper.c',
Signature · 1 line
2.47.3
#8 lore raw

PATCH v10 8/21 target/arm/tcg/translate-m-nocp.c: make compilation unit common

In reply to Pierrick Bouvier
---
 target/arm/tcg/meson.build | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
target/arm/tcg/meson.build +6 -2
index 89c3b476822..70beec7a6c9 100644
@@ -18,8 +18,9 @@ neon_d = [
 
 mve_d = decodetree.process('mve.decode', extra_args: '--decode=disas_mve')
 
+m_nocp_d = decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp')
+
 gen_a32 = [
-  decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp'),
   decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'),
   decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'),
   decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'),
@@ -34,7 +35,6 @@ arm_ss.add(files(
   'cpu32.c',
   'gengvec.c',
   'translate.c',
-  'translate-m-nocp.c',
   'm_helper.c',
   'mve_helper.c',
   'op_helper.c',
@@ -65,6 +65,7 @@ arm_common_ss.add(files(
 ))
 
 arm_common_system_ss.add(
+  m_nocp_d,
   mve_d,
   neon_d,
   vfp_d,
@@ -76,6 +77,7 @@ arm_common_system_ss.add(
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
+  'translate-m-nocp.c',
   'translate-mve.c',
   'translate-neon.c',
   'translate-vfp.c',
@@ -83,6 +85,7 @@ arm_common_system_ss.add(
   'vfp_helper.c',
 ))
 arm_user_ss.add(
+  m_nocp_d,
   mve_d,
   neon_d,
   vfp_d,
@@ -91,6 +94,7 @@ arm_user_ss.add(
   'hflags.c',
   'neon_helper.c',
   'tlb_helper.c',
+  'translate-m-nocp.c',
   'translate-mve.c',
   'translate-neon.c',
   'translate-vfp.c',
Signature · 1 line
2.47.3
#9 lore raw

PATCH v10 9/21 target/arm/tcg/op_helper.c: make compilation unit common

In reply to Pierrick Bouvier

Remove unused header accel/tcg/cpu-ldst.h that has target specifics.

---
 target/arm/tcg/op_helper.c | 1 -
 target/arm/tcg/meson.build | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)
target/arm/tcg/op_helper.c +0 -1
index aa14f15eb62..75ad53ec6c6 100644
@@ -23,7 +23,6 @@
 #include "helper.h"
 #include "internals.h"
 #include "cpu-features.h"
-#include "accel/tcg/cpu-ldst.h"
 #include "accel/tcg/probe.h"
 #include "cpregs.h"
 
target/arm/tcg/meson.build +2 -1
index 70beec7a6c9..1fa26670587 100644
@@ -37,7 +37,6 @@ arm_ss.add(files(
   'translate.c',
   'm_helper.c',
   'mve_helper.c',
-  'op_helper.c',
 ))
 
 arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
@@ -74,6 +73,7 @@ arm_common_system_ss.add(
   'debug.c',
   'hflags.c',
   'neon_helper.c',
+  'op_helper.c',
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
@@ -93,6 +93,7 @@ arm_user_ss.add(
   'debug.c',
   'hflags.c',
   'neon_helper.c',
+  'op_helper.c',
   'tlb_helper.c',
   'translate-m-nocp.c',
   'translate-mve.c',
Signature · 1 line
2.47.3
#10 lore raw

PATCH v10 10/21 target/arm/tcg/gengvec.c: make compilation unit common

In reply to Pierrick Bouvier
---
 target/arm/tcg/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/tcg/meson.build +2 -1
index 1fa26670587..0740de92c1a 100644
@@ -33,7 +33,6 @@ arm_ss.add(when: 'TARGET_AARCH64', if_false: files('stubs32.c'))
 
 arm_ss.add(files(
   'cpu32.c',
-  'gengvec.c',
   'translate.c',
   'm_helper.c',
   'mve_helper.c',
@@ -72,6 +71,7 @@ arm_common_system_ss.add(
   'cpregs-at.c',
   'debug.c',
   'hflags.c',
+  'gengvec.c',
   'neon_helper.c',
   'op_helper.c',
   'psci.c',
@@ -91,6 +91,7 @@ arm_user_ss.add(
   vfp_d,
   files(
   'debug.c',
+  'gengvec.c',
   'hflags.c',
   'neon_helper.c',
   'op_helper.c',
Signature · 1 line
2.47.3
#11 lore raw

PATCH v10 11/21 target/arm/tcg/translate.c: remove MO_TE usage

In reply to Pierrick Bouvier

dc->be_data is already set just above in the same function:

```
    dc->be_data = EX_TBFLAG_ANY(tb_flags, BE_DATA) ? MO_BE : MO_LE;
```
Fixes a729a46b05a ("target/arm: Add wrapper macros for accessing tbflags")
---
 target/arm/tcg/translate.c | 1 -
 1 file changed, 1 deletion(-)
target/arm/tcg/translate.c +0 -1
index 56ef1e0eb59..4546bbeeeff 100644
@@ -6344,7 +6344,6 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
 
     if (arm_feature(env, ARM_FEATURE_M)) {
         dc->vfp_enabled = 1;
-        dc->be_data = MO_TE;
         dc->v7m_handler_mode = EX_TBFLAG_M32(tb_flags, HANDLER);
         dc->v8m_secure = EX_TBFLAG_M32(tb_flags, SECURE);
         dc->v8m_stackcheck = EX_TBFLAG_M32(tb_flags, STACKCHECK);
Signature · 1 line
2.47.3
#12 lore raw

Re: [PATCH v10 11/21] target/arm/tcg/translate.c: remove MO_TE usage

Quoted 6 lines · Pierrick Bouvier

dc->be_data is already set just above in the same function:

```
     dc->be_data = EX_TBFLAG_ANY(tb_flags, BE_DATA) ? MO_BE : MO_LE;
```

Why Cc stable? This is just removing pointless code, right?

Quoted 1 line
Fixes a729a46b05a ("target/arm: Add wrapper macros for accessing tbflags")

This commit doesn't seem to be related.

Do you mean commit 79cabf1f473 ("target/arm: Recover 4 bits from TBFLAGs")?

We had completely run out of TBFLAG bits.
Split A- and M-profile bits into two overlapping buckets. This results in 4 free bits.

We used to initialize all of the a32 and m32 fields in DisasContext by assignment, in arm_tr_init_disas_context. Now we only initialize either the a32 or m32 by assignment, because the bits overlap in tbflags. So zero the entire structure in gen_intermediate_code.

Since BE_DATA is in the TBFLAG_ANY set, I don't get why it is set to MO_TE for M-profile.

At any rate this patch description deserves a better explanation IMHO.

Quoted 18 lines
---
  target/arm/tcg/translate.c | 1 -
  1 file changed, 1 deletion(-)
target/arm/tcg/translate.c +0 -1
index 56ef1e0eb59..4546bbeeeff 100644
@@ -6344,7 +6344,6 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
 
      if (arm_feature(env, ARM_FEATURE_M)) {
          dc->vfp_enabled = 1;
-        dc->be_data = MO_TE;
          dc->v7m_handler_mode = EX_TBFLAG_M32(tb_flags, HANDLER);
          dc->v8m_secure = EX_TBFLAG_M32(tb_flags, SECURE);
          dc->v8m_stackcheck = EX_TBFLAG_M32(tb_flags, STACKCHECK);
#13 lore raw

Re: [PATCH v10 11/21] target/arm/tcg/translate.c: remove MO_TE usage

Quoted 43 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Pierrick Bouvier

dc->be_data is already set just above in the same function:

```
      dc->be_data = EX_TBFLAG_ANY(tb_flags, BE_DATA) ? MO_BE : MO_LE;
```

Why Cc stable? This is just removing pointless code, right?

Quoted 1 line
Fixes a729a46b05a ("target/arm: Add wrapper macros for accessing tbflags")

This commit doesn't seem to be related.

Do you mean commit 79cabf1f473 ("target/arm: Recover 4 bits from TBFLAGs")?

We had completely run out of TBFLAG bits.
Split A- and M-profile bits into two overlapping buckets. This results in 4 free bits.

We used to initialize all of the a32 and m32 fields in DisasContext by assignment, in arm_tr_init_disas_context. Now we only initialize either the a32 or m32 by assignment, because the bits overlap in tbflags. So zero the entire structure in gen_intermediate_code.

Since BE_DATA is in the TBFLAG_ANY set, I don't get why it is set to MO_TE for M-profile.

At any rate this patch description deserves a better explanation IMHO.

Quoted 12 lines
---
   target/arm/tcg/translate.c | 1 -
   1 file changed, 1 deletion(-)
target/arm/tcg/translate.c +0 -0
index 56ef1e0eb59..4546bbeeeff 100644
@@ -6344,7 +6344,6 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
 
Quoted 7 lines

target/arm/tcg/translate.c static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) · line 6349

Quoted 6 lines
target/arm/tcg/translate.c +0 -1
       if (arm_feature(env, ARM_FEATURE_M)) {
           dc->vfp_enabled = 1;
-        dc->be_data = MO_TE;
           dc->v7m_handler_mode = EX_TBFLAG_M32(tb_flags, HANDLER);
           dc->v8m_secure = EX_TBFLAG_M32(tb_flags, SECURE);
           dc->v8m_stackcheck = EX_TBFLAG_M32(tb_flags, STACKCHECK);

See:
https://lore.kernel.org/qemu-devel/[email protected]/

#14 lore raw

PATCH v10 12/21 target/arm/tcg/translate.c: replace target_ulong with uint32_t

In reply to Pierrick Bouvier
---
 target/arm/tcg/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/tcg/translate.c +2 -2
index 4546bbeeeff..204f9657993 100644
@@ -6450,7 +6450,7 @@ static void arm_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
      * fields here.
      */
     uint32_t condexec_bits;
-    target_ulong pc_arg = dc->base.pc_next;
+    uint32_t pc_arg = dc->base.pc_next;
 
     if (tb_cflags(dcbase->tb) & CF_PCREL) {
         pc_arg &= ~TARGET_PAGE_MASK;
@@ -6612,7 +6612,7 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
     bool is_16bit;
     /* TCG op to rewind to if this turns out to be an invalid ECI state */
     TCGOp *insn_eci_rewind = NULL;
-    target_ulong insn_eci_pc_save = -1;
+    uint32_t insn_eci_pc_save = -1;
 
     /* Misaligned thumb PC is architecturally impossible. */
     assert((dc->base.pc_next & 1) == 0);
Signature · 1 line
2.47.3
#15 lore raw

PATCH v10 13/21 target/arm/tcg/translate.c: extract aarch64_translate_code()

In reply to Pierrick Bouvier

This allows to get rid of TARGET_AARCH64, and helps with next patch which will define at runtime tcg address type, by adding a second entry point in a different source file.

---
 target/arm/internals.h         |  2 ++
 target/arm/tcg/stubs32.c       |  7 +++++++
 target/arm/tcg/translate-a64.c |  9 +++++++++
 target/arm/tcg/translate.c     | 19 +++++++++----------
 4 files changed, 27 insertions(+), 10 deletions(-)
target/arm/internals.h +2 -0
index 8ec27508473..2850edcb198 100644
@@ -381,6 +381,8 @@ void arm_init_cpreg_list(ARMCPU *cpu);
 
 void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
 void arm_translate_init(void);
+void aarch64_translate_code(CPUState *cs, TranslationBlock *tb,
+                            int *max_insns, vaddr pc, void *host_pc);
 void arm_translate_code(CPUState *cs, TranslationBlock *tb,
                         int *max_insns, vaddr pc, void *host_pc);
 
target/arm/tcg/stubs32.c +7 -0
index c5a0bc61f47..3945dc49e5e 100644
@@ -3,6 +3,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "target/arm/internals.h"
 #include "target/arm/tcg/translate.h"
 
 
@@ -15,3 +16,9 @@ void a64_translate_init(void)
 {
     /* Don't initialize for 32 bits. Call site will be fixed later. */
 }
+
+void aarch64_translate_code(CPUState *cs, TranslationBlock *tb,
+                            int *max_insns, vaddr pc, void *host_pc)
+{
+    g_assert_not_reached();
+}
target/arm/tcg/translate-a64.c +9 -0
index 35ad7530c4b..7533a4d01b6 100644
@@ -18,6 +18,7 @@
  */
 #include "qemu/osdep.h"
 #include "exec/target_page.h"
+#include "exec/translator.h"
 #include "helper-a64.h"
 #include "helper-sme.h"
 #include "helper-sve.h"
@@ -10949,3 +10950,11 @@ const TranslatorOps aarch64_translator_ops = {
     .translate_insn     = aarch64_tr_translate_insn,
     .tb_stop            = aarch64_tr_tb_stop,
 };
+
+void aarch64_translate_code(CPUState *cpu, TranslationBlock *tb,
+                            int *max_insns, vaddr pc, void *host_pc)
+{
+     DisasContext dc = {};
+     translator_loop(cpu, tb, max_insns, pc, host_pc,
+                     &aarch64_translator_ops, &dc.base);
+}
target/arm/tcg/translate.c +9 -10
index 204f9657993..9ab926b118e 100644
@@ -28,6 +28,7 @@
 #include "semihosting/semihost.h"
 #include "cpregs.h"
 #include "exec/target_page.h"
+#include "exec/translator.h"
 #include "helper.h"
 #include "helper-mve.h"
 
@@ -6878,18 +6879,16 @@ static const TranslatorOps thumb_translator_ops = {
 void arm_translate_code(CPUState *cpu, TranslationBlock *tb,
                         int *max_insns, vaddr pc, void *host_pc)
 {
-    DisasContext dc = { };
-    const TranslatorOps *ops = &arm_translator_ops;
     CPUARMTBFlags tb_flags = arm_tbflags_from_tb(tb);
 
-    if (EX_TBFLAG_AM32(tb_flags, THUMB)) {
-        ops = &thumb_translator_ops;
-    }
-#ifdef TARGET_AARCH64
     if (EX_TBFLAG_ANY(tb_flags, AARCH64_STATE)) {
-        ops = &aarch64_translator_ops;
+        aarch64_translate_code(cpu, tb, max_insns, pc, host_pc);
+    } else {
+        DisasContext dc = { };
+        translator_loop(cpu, tb, max_insns, pc, host_pc,
+                        (EX_TBFLAG_AM32(tb_flags, THUMB)
+                        ? &thumb_translator_ops
+                        : &arm_translator_ops),
+                        &dc.base);
     }
-#endif
-
-    translator_loop(cpu, tb, max_insns, pc, host_pc, ops, &dc.base);
 }
Signature · 1 line
2.47.3
Reviewed-by on v10 13/21
#16 lore raw

Re: [PATCH v10 13/21] target/arm/tcg/translate.c: extract aarch64_translate_code()

Quoted 7 lines · Pierrick Bouvier

This allows to get rid of TARGET_AARCH64, and helps with next patch which will define at runtime tcg address type, by adding a second entry point in a different source file.

Quoted 6 lines
---
  target/arm/internals.h         |  2 ++
  target/arm/tcg/stubs32.c       |  7 +++++++
  target/arm/tcg/translate-a64.c |  9 +++++++++
  target/arm/tcg/translate.c     | 19 +++++++++----------
  4 files changed, 27 insertions(+), 10 deletions(-)
#17 lore raw

PATCH v10 14/21 tcg/translator: add parameter to translator_loop for current addr type

In reply to Pierrick Bouvier

With TCG_ADDRESS_BITS mechanism, it's now possible to specify which variant every source file is written for. Compared to before, it means that addr_type will now vary per tb translation, where it was constant for a given target previously.

Thus, we add new a parameter to translator_loop(). This will allow us to convert targets one by one.

---
 include/exec/translator.h        | 4 +++-
 accel/tcg/translate-all.c        | 1 -
 accel/tcg/translator.c           | 4 +++-
 target/alpha/translate.c         | 3 ++-
 target/arm/tcg/translate-a64.c   | 3 ++-
 target/arm/tcg/translate.c       | 2 +-
 target/avr/translate.c           | 3 ++-
 target/hexagon/translate.c       | 3 ++-
 target/hppa/translate.c          | 3 ++-
 target/i386/tcg/translate.c      | 3 ++-
 target/loongarch/tcg/translate.c | 3 ++-
 target/m68k/translate.c          | 3 ++-
 target/microblaze/translate.c    | 3 ++-
 target/mips/tcg/translate.c      | 3 ++-
 target/or1k/translate.c          | 3 ++-
 target/ppc/translate.c           | 3 ++-
 target/riscv/translate.c         | 3 ++-
 target/rx/translate.c            | 3 ++-
 target/s390x/tcg/translate.c     | 3 ++-
 target/sh4/translate.c           | 3 ++-
 target/sparc/translate.c         | 3 ++-
 target/tricore/translate.c       | 3 ++-
 target/xtensa/translate.c        | 3 ++-
 23 files changed, 45 insertions(+), 23 deletions(-)
include/exec/translator.h +3 -1
index 8d343627bd9..c1d31e06b53 100644
@@ -20,6 +20,7 @@
 
 #include "exec/memop.h"
 #include "exec/vaddr.h"
+#include "tcg/tcg.h"
 
 /**
  * DisasJumpType:
@@ -132,6 +133,7 @@ typedef struct TranslatorOps {
  * @host_pc: host physical program counter address
  * @ops: Target-specific operations.
  * @db: Disassembly context.
+ * @addr_type: TCG Type for addresses (TCGv_va).
  *
  * Generic translator loop.
  *
@@ -147,7 +149,7 @@ typedef struct TranslatorOps {
  */
 void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
                      vaddr pc, void *host_pc, const TranslatorOps *ops,
-                     DisasContextBase *db);
+                     DisasContextBase *db, TCGType addr_type);
 
 /**
  * translator_use_goto_tb
accel/tcg/translate-all.c +0 -1
index fba4e9dc21c..05d9ce512a4 100644
@@ -316,7 +316,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
     }
 
     tcg_ctx->gen_tb = tb;
-    tcg_ctx->addr_type = target_long_bits() == 32 ? TCG_TYPE_I32 : TCG_TYPE_I64;
     tcg_ctx->guest_mo = cpu->cc->tcg_ops->guest_default_memory_order;
 
  restart_translate:
accel/tcg/translator.c +3 -1
index f3eddcbb2e8..cd7d079fe05 100644
@@ -121,13 +121,15 @@ bool translator_use_goto_tb(DisasContextBase *db, vaddr dest)
 
 void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
                      vaddr pc, void *host_pc, const TranslatorOps *ops,
-                     DisasContextBase *db)
+                     DisasContextBase *db, TCGType addr_type)
 {
     uint32_t cflags = tb_cflags(tb);
     TCGOp *icount_start_insn;
     TCGOp *first_insn_start = NULL;
     bool plugin_enabled;
 
+    tcg_ctx->addr_type = addr_type;
+
     /* Initialize DisasContext */
     db->tb = tb;
     db->pc_first = pc;
target/alpha/translate.c +2 -1
index 4d22d7d5a45..d2d1467a812 100644
@@ -2953,5 +2953,6 @@ void alpha_translate_code(CPUState *cpu, TranslationBlock *tb,
                           int *max_insns, vaddr pc, void *host_pc)
 {
     DisasContext dc;
-    translator_loop(cpu, tb, max_insns, pc, host_pc, &alpha_tr_ops, &dc.base);
+    translator_loop(cpu, tb, max_insns, pc, host_pc, &alpha_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
target/arm/tcg/translate-a64.c +2 -1
index 7533a4d01b6..df2cbd66b38 100644
@@ -10956,5 +10956,6 @@ void aarch64_translate_code(CPUState *cpu, TranslationBlock *tb,
 {
      DisasContext dc = {};
      translator_loop(cpu, tb, max_insns, pc, host_pc,
-                     &aarch64_translator_ops, &dc.base);
+                     &aarch64_translator_ops, &dc.base,
+                     TCG_TYPE_VA);
 }
target/arm/tcg/translate.c +1 -1
index 9ab926b118e..fa4c7907dcd 100644
@@ -6889,6 +6889,6 @@ void arm_translate_code(CPUState *cpu, TranslationBlock *tb,
                         (EX_TBFLAG_AM32(tb_flags, THUMB)
                         ? &thumb_translator_ops
                         : &arm_translator_ops),
-                        &dc.base);
+                        &dc.base, TCG_TYPE_VA);
     }
 }
target/avr/translate.c +2 -1
index 649dd4b0112..3c576060970 100644
@@ -2802,5 +2802,6 @@ void avr_cpu_translate_code(CPUState *cs, TranslationBlock *tb,
                             int *max_insns, vaddr pc, void *host_pc)
 {
     DisasContext dc = { };
-    translator_loop(cs, tb, max_insns, pc, host_pc, &avr_tr_ops, &dc.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &avr_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
target/hexagon/translate.c +2 -1
index 633401451d8..6ae2adabc0f 100644
@@ -1077,7 +1077,8 @@ void hexagon_translate_code(CPUState *cs, TranslationBlock *tb,
     DisasContext ctx;
 
     translator_loop(cs, tb, max_insns, pc, host_pc,
-                    &hexagon_tr_ops, &ctx.base);
+                    &hexagon_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 #define NAME_LEN               64
target/hppa/translate.c +2 -1
index 70c20c00377..cf57ec518d4 100644
@@ -4899,5 +4899,6 @@ void hppa_translate_code(CPUState *cs, TranslationBlock *tb,
                          int *max_insns, vaddr pc, void *host_pc)
 {
     DisasContext ctx = { };
-    translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
target/i386/tcg/translate.c +2 -1
index 14210d569f7..2115c5cd24b 100644
@@ -3615,5 +3615,6 @@ void x86_translate_code(CPUState *cpu, TranslationBlock *tb,
 {
     DisasContext dc;
 
-    translator_loop(cpu, tb, max_insns, pc, host_pc, &i386_tr_ops, &dc.base);
+    translator_loop(cpu, tb, max_insns, pc, host_pc, &i386_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
target/loongarch/tcg/translate.c +2 -1
index b9ed13d19c6..202b80e0475 100644
@@ -342,7 +342,8 @@ void loongarch_translate_code(CPUState *cs, TranslationBlock *tb,
     DisasContext ctx;
 
     translator_loop(cs, tb, max_insns, pc, host_pc,
-                    &loongarch_tr_ops, &ctx.base);
+                    &loongarch_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 void loongarch_translate_init(void)
target/m68k/translate.c +2 -1
index abc1c79f3cd..138c89d3e53 100644
@@ -6126,7 +6126,8 @@ void m68k_translate_code(CPUState *cpu, TranslationBlock *tb,
                          int *max_insns, vaddr pc, void *host_pc)
 {
     DisasContext dc;
-    translator_loop(cpu, tb, max_insns, pc, host_pc, &m68k_tr_ops, &dc.base);
+    translator_loop(cpu, tb, max_insns, pc, host_pc, &m68k_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low)
target/microblaze/translate.c +2 -1
index 2af67beecec..5e8bb4ed77b 100644
@@ -1788,7 +1788,8 @@ void mb_translate_code(CPUState *cpu, TranslationBlock *tb,
                        int *max_insns, vaddr pc, void *host_pc)
 {
     DisasContext dc;
-    translator_loop(cpu, tb, max_insns, pc, host_pc, &mb_tr_ops, &dc.base);
+    translator_loop(cpu, tb, max_insns, pc, host_pc, &mb_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags)
target/mips/tcg/translate.c +2 -1
index 54849e9ff1a..3426acd37b4 100644
@@ -15242,7 +15242,8 @@ void mips_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext ctx;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &mips_tr_ops, &ctx.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &mips_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 void mips_tcg_init(void)
target/or1k/translate.c +2 -1
index de81dc6ef8d..eb4485312f2 100644
@@ -1647,7 +1647,8 @@ void openrisc_translate_code(CPUState *cs, TranslationBlock *tb,
     DisasContext ctx;
 
     translator_loop(cs, tb, max_insns, pc, host_pc,
-                    &openrisc_tr_ops, &ctx.base);
+                    &openrisc_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 void openrisc_cpu_dump_state(CPUState *cs, FILE *f, int flags)
target/ppc/translate.c +2 -1
index a09a6df93fd..3f6d326cef3 100644
@@ -6719,5 +6719,6 @@ void ppc_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext ctx;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &ppc_tr_ops, &ctx.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &ppc_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
target/riscv/translate.c +2 -1
index cb4f4436018..f42e53df888 100644
@@ -1440,7 +1440,8 @@ void riscv_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext ctx;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &riscv_tr_ops, &ctx.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &riscv_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 void riscv_translate_init(void)
target/rx/translate.c +2 -1
index a245b9db8fe..132d495710c 100644
@@ -2270,7 +2270,8 @@ void rx_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext dc;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &rx_tr_ops, &dc.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &rx_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 #define ALLOC_REGISTER(sym, name) \
target/s390x/tcg/translate.c +2 -1
index 92344441878..0f274621e5a 100644
@@ -6509,7 +6509,8 @@ void s390x_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext dc;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &s390x_tr_ops, &dc.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &s390x_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 void s390x_restore_state_to_opc(CPUState *cs,
target/sh4/translate.c +2 -1
index b1057727c55..5adf650744c 100644
@@ -2316,5 +2316,6 @@ void sh4_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext ctx;
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &sh4_tr_ops, &ctx.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &sh4_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
target/sparc/translate.c +2 -1
index 7e8558dbbd8..3156be6a94c 100644
@@ -5853,7 +5853,8 @@ void sparc_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext dc = {};
 
-    translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base);
+    translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 void sparc_tcg_init(void)
target/tricore/translate.c +2 -1
index 0eaf7a82f87..8cd6b58f66b 100644
@@ -8500,7 +8500,8 @@ void tricore_translate_code(CPUState *cs, TranslationBlock *tb,
 {
     DisasContext ctx;
     translator_loop(cs, tb, max_insns, pc, host_pc,
-                    &tricore_tr_ops, &ctx.base);
+                    &tricore_tr_ops, &ctx.base,
+                    TCG_TYPE_VA);
 }
 
 /*
target/xtensa/translate.c +2 -1
index 5e3707d3fdf..6f9dd9fb5cf 100644
@@ -1233,7 +1233,8 @@ void xtensa_translate_code(CPUState *cpu, TranslationBlock *tb,
 {
     DisasContext dc = {};
     translator_loop(cpu, tb, max_insns, pc, host_pc,
-                    &xtensa_translator_ops, &dc.base);
+                    &xtensa_translator_ops, &dc.base,
+                    TCG_TYPE_VA);
 }
 
 void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
Signature · 1 line
2.47.3
Reviewed-by on v10 14/21
#18 lore raw

Re: [PATCH v10 14/21] tcg/translator: add parameter to translator_loop for current addr type

Quoted 49 lines · Pierrick Bouvier

With TCG_ADDRESS_BITS mechanism, it's now possible to specify which variant every source file is written for. Compared to before, it means that addr_type will now vary per tb translation, where it was constant for a given target previously.

Thus, we add new a parameter to translator_loop(). This will allow us to convert targets one by one.

---
  include/exec/translator.h        | 4 +++-
  accel/tcg/translate-all.c        | 1 -
  accel/tcg/translator.c           | 4 +++-
  target/alpha/translate.c         | 3 ++-
  target/arm/tcg/translate-a64.c   | 3 ++-
  target/arm/tcg/translate.c       | 2 +-
  target/avr/translate.c           | 3 ++-
  target/hexagon/translate.c       | 3 ++-
  target/hppa/translate.c          | 3 ++-
  target/i386/tcg/translate.c      | 3 ++-
  target/loongarch/tcg/translate.c | 3 ++-
  target/m68k/translate.c          | 3 ++-
  target/microblaze/translate.c    | 3 ++-
  target/mips/tcg/translate.c      | 3 ++-
  target/or1k/translate.c          | 3 ++-
  target/ppc/translate.c           | 3 ++-
  target/riscv/translate.c         | 3 ++-
  target/rx/translate.c            | 3 ++-
  target/s390x/tcg/translate.c     | 3 ++-
  target/sh4/translate.c           | 3 ++-
  target/sparc/translate.c         | 3 ++-
  target/tricore/translate.c       | 3 ++-
  target/xtensa/translate.c        | 3 ++-
  23 files changed, 45 insertions(+), 23 deletions(-)
include/exec/translator.h +1 -0
index 8d343627bd9..c1d31e06b53 100644
@@ -20,6 +20,7 @@
 
  #include "exec/memop.h"
  #include "exec/vaddr.h"
+#include "tcg/tcg.h"
 
  /**
   * DisasJumpType:

include/exec/translator.h typedef struct TranslatorOps { · line 136

Quoted 4 lines
include/exec/translator.h +1 -0
@@ -132,6 +133,7 @@ typedef struct TranslatorOps {
   * @host_pc: host physical program counter address
   * @ops: Target-specific operations.
   * @db: Disassembly context.
+ * @addr_type: TCG Type for addresses (TCGv_va).

"TCGv_va" confuses me here, do you mean TCG_TYPE_VA?

What about:

"@addr_type: #TCG_TYPE_VA for TCGv_va address expansion."

Otherwise,

#19 lore raw

Re: [PATCH v10 14/21] tcg/translator: add parameter to translator_loop for current addr type

Quoted 57 lines · Philippe Mathieu-Daudé
Quoted 49 lines · Pierrick Bouvier

With TCG_ADDRESS_BITS mechanism, it's now possible to specify which variant every source file is written for. Compared to before, it means that addr_type will now vary per tb translation, where it was constant for a given target previously.

Thus, we add new a parameter to translator_loop(). This will allow us to convert targets one by one.

---
   include/exec/translator.h        | 4 +++-
   accel/tcg/translate-all.c        | 1 -
   accel/tcg/translator.c           | 4 +++-
   target/alpha/translate.c         | 3 ++-
   target/arm/tcg/translate-a64.c   | 3 ++-
   target/arm/tcg/translate.c       | 2 +-
   target/avr/translate.c           | 3 ++-
   target/hexagon/translate.c       | 3 ++-
   target/hppa/translate.c          | 3 ++-
   target/i386/tcg/translate.c      | 3 ++-
   target/loongarch/tcg/translate.c | 3 ++-
   target/m68k/translate.c          | 3 ++-
   target/microblaze/translate.c    | 3 ++-
   target/mips/tcg/translate.c      | 3 ++-
   target/or1k/translate.c          | 3 ++-
   target/ppc/translate.c           | 3 ++-
   target/riscv/translate.c         | 3 ++-
   target/rx/translate.c            | 3 ++-
   target/s390x/tcg/translate.c     | 3 ++-
   target/sh4/translate.c           | 3 ++-
   target/sparc/translate.c         | 3 ++-
   target/tricore/translate.c       | 3 ++-
   target/xtensa/translate.c        | 3 ++-
   23 files changed, 45 insertions(+), 23 deletions(-)
include/exec/translator.h +1 -0
index 8d343627bd9..c1d31e06b53 100644
@@ -20,6 +20,7 @@
 
   #include "exec/memop.h"
   #include "exec/vaddr.h"
+#include "tcg/tcg.h"
 
   /**
    * DisasJumpType:

include/exec/translator.h typedef struct TranslatorOps { · line 136

Quoted 4 lines
include/exec/translator.h +1 -0
@@ -132,6 +133,7 @@ typedef struct TranslatorOps {
    * @host_pc: host physical program counter address
    * @ops: Target-specific operations.
    * @db: Disassembly context.
+ * @addr_type: TCG Type for addresses (TCGv_va).

"TCGv_va" confuses me here, do you mean TCG_TYPE_VA?

Quoted 4 lines

What about:

"@addr_type: #TCG_TYPE_VA for TCGv_va address expansion."

Right, I'll update comment.

Quoted 4 lines

Otherwise,

#20 lore raw

PATCH v10 15/21 target/arm/tcg/translate.c: replace TCGv with TCGv_va

In reply to Pierrick Bouvier

We know this file is for 32-bit runtime target, so we can set TCG_ADDRESS_BITS. TCG_TYPE_VA is derived accordingly and is already passed to translator_loop.

---
 target/arm/tcg/translate.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/tcg/translate.c +15 -14
index fa4c7907dcd..0b3b4ab86be 100644
@@ -22,7 +22,8 @@
 
 #include "translate.h"
 #include "translate-a32.h"
-#include "tcg/tcg-op.h"
+#define TCG_ADDRESS_BITS 32
+#include "tcg/tcg-op-mem.h"
 #include "qemu/log.h"
 #include "arm_ldst.h"
 #include "semihosting/semihost.h"
@@ -910,14 +911,14 @@ MemOp pow2_align(unsigned i)
  * that the address argument is TCGv_i32 rather than TCGv.
  */
 
-static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
+static TCGv_va gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
 {
-    TCGv addr = tcg_temp_new();
-    tcg_gen_extu_i32_tl(addr, a32);
+    TCGv_va addr = tcgv_va_temp_new();
+    tcg_gen_mov_i32(addr, a32);
 
     /* Not needed for user-mode BE32, where we use MO_BE instead.  */
     if (!IS_USER_ONLY && s->sctlr_b && (op & MO_SIZE) < MO_32) {
-        tcg_gen_xori_tl(addr, addr, 4 - (1 << (op & MO_SIZE)));
+        tcg_gen_xori_i32(addr, addr, 4 - (1 << (op & MO_SIZE)));
     }
     return addr;
 }
@@ -929,21 +930,21 @@ static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
 void gen_aa32_ld_internal_i32(DisasContext *s, TCGv_i32 val,
                               TCGv_i32 a32, int index, MemOp opc)
 {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
     tcg_gen_qemu_ld_i32(val, addr, index, opc);
 }
 
 void gen_aa32_st_internal_i32(DisasContext *s, TCGv_i32 val,
                               TCGv_i32 a32, int index, MemOp opc)
 {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
     tcg_gen_qemu_st_i32(val, addr, index, opc);
 }
 
 void gen_aa32_ld_internal_i64(DisasContext *s, TCGv_i64 val,
                               TCGv_i32 a32, int index, MemOp opc)
 {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
 
     tcg_gen_qemu_ld_i64(val, addr, index, opc);
 
@@ -956,7 +957,7 @@ void gen_aa32_ld_internal_i64(DisasContext *s, TCGv_i64 val,
 void gen_aa32_st_internal_i64(DisasContext *s, TCGv_i64 val,
                               TCGv_i32 a32, int index, MemOp opc)
 {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
 
     /* Not needed for user-mode BE32, where we use MO_BE instead.  */
     if (!IS_USER_ONLY && s->sctlr_b && (opc & MO_SIZE) == MO_64) {
@@ -2036,7 +2037,7 @@ static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
          * architecturally 64-bit access, but instead do a 64-bit access
          * using MO_BE if appropriate and then split the two halves.
          */
-        TCGv taddr = gen_aa32_addr(s, addr, opc);
+        TCGv_va taddr = gen_aa32_addr(s, addr, opc);
 
         tcg_gen_qemu_ld_i64(t64, taddr, get_mem_index(s), opc);
         tcg_gen_mov_i64(cpu_exclusive_val, t64);
@@ -2065,7 +2066,7 @@ static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
 {
     TCGv_i32 t0, t1, t2;
     TCGv_i64 extaddr;
-    TCGv taddr;
+    TCGv_va taddr;
     TCGLabel *done_label;
     TCGLabel *fail_label;
     MemOp opc = size | MO_ALIGN | s->be_data;
@@ -3792,7 +3793,7 @@ static void do_ldrd_load(DisasContext *s, TCGv_i32 addr, int rt, int rt2)
      */
     int mem_idx = get_mem_index(s);
     MemOp opc = MO_64 | MO_ALIGN_4 | MO_ATOM_SUBALIGN | s->be_data;
-    TCGv taddr = gen_aa32_addr(s, addr, opc);
+    TCGv_va taddr = gen_aa32_addr(s, addr, opc);
     TCGv_i64 t64 = tcg_temp_new_i64();
     TCGv_i32 tmp = tcg_temp_new_i32();
     TCGv_i32 tmp2 = tcg_temp_new_i32();
@@ -3847,7 +3848,7 @@ static void do_strd_store(DisasContext *s, TCGv_i32 addr, int rt, int rt2)
      */
     int mem_idx = get_mem_index(s);
     MemOp opc = MO_64 | MO_ALIGN_4 | MO_ATOM_SUBALIGN | s->be_data;
-    TCGv taddr = gen_aa32_addr(s, addr, opc);
+    TCGv_va taddr = gen_aa32_addr(s, addr, opc);
     TCGv_i32 t1 = load_reg(s, rt);
     TCGv_i32 t2 = load_reg(s, rt2);
     TCGv_i64 t64 = tcg_temp_new_i64();
@@ -4068,7 +4069,7 @@ DO_LDST(STRH, store, MO_UW)
 static bool op_swp(DisasContext *s, arg_SWP *a, MemOp opc)
 {
     TCGv_i32 addr, tmp;
-    TCGv taddr;
+    TCGv_va taddr;
 
     opc |= s->be_data;
     addr = load_reg(s, a->rn);
Signature · 1 line
2.47.3
Reviewed-by on v10 15/21
#21 lore raw

Re: [PATCH v10 15/21] target/arm/tcg/translate.c: replace TCGv with TCGv_va

Quoted 25 lines · Pierrick Bouvier

We know this file is for 32-bit runtime target, so we can set TCG_ADDRESS_BITS. TCG_TYPE_VA is derived accordingly and is already passed to translator_loop.

---
  target/arm/tcg/translate.c | 29 +++++++++++++++--------------
  1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/tcg/translate.c +2 -1
index fa4c7907dcd..0b3b4ab86be 100644
@@ -22,7 +22,8 @@
 
  #include "translate.h"
  #include "translate-a32.h"
-#include "tcg/tcg-op.h"
+#define TCG_ADDRESS_BITS 32
+#include "tcg/tcg-op-mem.h"
  #include "qemu/log.h"
  #include "arm_ldst.h"
  #include "semihosting/semihost.h"

target/arm/tcg/translate.c MemOp pow2_align(unsigned i) · line 917

Quoted 10 lines
target/arm/tcg/translate.c +3 -3
@@ -910,14 +911,14 @@ MemOp pow2_align(unsigned i)
   * that the address argument is TCGv_i32 rather than TCGv.
   */
 
-static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
+static TCGv_va gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
  {
-    TCGv addr = tcg_temp_new();
-    tcg_gen_extu_i32_tl(addr, a32);
+    TCGv_va addr = tcgv_va_temp_new();
+    tcg_gen_mov_i32(addr, a32);

The implicit TCGv_va -> TCGv_i32 bugs me here, but the overall change will make my sleep better :) So:

Quoted 16 lines
target/arm/tcg/translate.c +2 -2
      /* Not needed for user-mode BE32, where we use MO_BE instead.  */
      if (!IS_USER_ONLY && s->sctlr_b && (op & MO_SIZE) < MO_32) {
-        tcg_gen_xori_tl(addr, addr, 4 - (1 << (op & MO_SIZE)));
+        tcg_gen_xori_i32(addr, addr, 4 - (1 << (op & MO_SIZE)));
      }
      return addr;
  }
@@ -929,21 +930,21 @@ static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
  void gen_aa32_ld_internal_i32(DisasContext *s, TCGv_i32 val,
                                TCGv_i32 a32, int index, MemOp opc)
  {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
      tcg_gen_qemu_ld_i32(val, addr, index, opc);
  }
#22 lore raw

Re: [PATCH v10 15/21] target/arm/tcg/translate.c: replace TCGv with TCGv_va

Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Pierrick Bouvier

We know this file is for 32-bit runtime target, so we can set TCG_ADDRESS_BITS. TCG_TYPE_VA is derived accordingly and is already passed to translator_loop.

---
   target/arm/tcg/translate.c | 29 +++++++++++++++--------------
   1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/tcg/translate.c +2 -1
index fa4c7907dcd..0b3b4ab86be 100644
@@ -22,7 +22,8 @@
 
   #include "translate.h"
   #include "translate-a32.h"
-#include "tcg/tcg-op.h"
+#define TCG_ADDRESS_BITS 32
+#include "tcg/tcg-op-mem.h"
   #include "qemu/log.h"
   #include "arm_ldst.h"
   #include "semihosting/semihost.h"
@@ -910,14 +911,14 @@ MemOp pow2_align(unsigned i)
    * that the address argument is TCGv_i32 rather than TCGv.
    */
 
Quoted 11 lines

target/arm/tcg/translate.c MemOp pow2_align(unsigned i) · line 917

Quoted 7 lines
target/arm/tcg/translate.c +3 -3
-static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
+static TCGv_va gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
   {
-    TCGv addr = tcg_temp_new();
-    tcg_gen_extu_i32_tl(addr, a32);
+    TCGv_va addr = tcgv_va_temp_new();
+    tcg_gen_mov_i32(addr, a32);

The implicit TCGv_va -> TCGv_i32 bugs me here, but the overall change will make my sleep better :) So:

We could use TCGv_i32 directly, TCGv_va is just useful here to document the intention. I can update this if Richard and you prefer this.

Quoted 19 lines
Quoted 16 lines
target/arm/tcg/translate.c +2 -2
       /* Not needed for user-mode BE32, where we use MO_BE instead.  */
       if (!IS_USER_ONLY && s->sctlr_b && (op & MO_SIZE) < MO_32) {
-        tcg_gen_xori_tl(addr, addr, 4 - (1 << (op & MO_SIZE)));
+        tcg_gen_xori_i32(addr, addr, 4 - (1 << (op & MO_SIZE)));
       }
       return addr;
   }
@@ -929,21 +930,21 @@ static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
   void gen_aa32_ld_internal_i32(DisasContext *s, TCGv_i32 val,
                                 TCGv_i32 a32, int index, MemOp opc)
   {
-    TCGv addr = gen_aa32_addr(s, a32, opc);
+    TCGv_va addr = gen_aa32_addr(s, a32, opc);
       tcg_gen_qemu_ld_i32(val, addr, index, opc);
   }
#23 lore raw

Re: [PATCH v10 15/21] target/arm/tcg/translate.c: replace TCGv with TCGv_va

Quoted 40 lines · Pierrick Bouvier
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Pierrick Bouvier

We know this file is for 32-bit runtime target, so we can set TCG_ADDRESS_BITS. TCG_TYPE_VA is derived accordingly and is already passed to translator_loop.

---
   target/arm/tcg/translate.c | 29 +++++++++++++++--------------

   1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/tcg/translate.c +3 -2
index fa4c7907dcd..0b3b4ab86be 100644
@@ -22,7 +22,8 @@
    #include "translate.h"
    #include "translate-a32.h"
-#include "tcg/tcg-op.h"
+#define TCG_ADDRESS_BITS 32
+#include "tcg/tcg-op-mem.h"
    #include "qemu/log.h"
    #include "arm_ldst.h"
    #include "semihosting/semihost.h"
@@ -910,14 +911,14 @@ MemOp pow2_align(unsigned i)
     * that the address argument is TCGv_i32 rather than TCGv.
     */
-static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
+static TCGv_va gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
Quoted 9 lines

target/arm/tcg/translate.c MemOp pow2_align(unsigned i) · line 917

Quoted 5 lines
target/arm/tcg/translate.c +2 -2
    {
-    TCGv addr = tcg_temp_new();
-    tcg_gen_extu_i32_tl(addr, a32);
+    TCGv_va addr = tcgv_va_temp_new();
+    tcg_gen_mov_i32(addr, a32);

The implicit TCGv_va -> TCGv_i32 bugs me here, but the overall change will make my sleep better :) So:

Quoted 1 line

We could use TCGv_i32 directly, TCGv_va is just useful here to document the intention. I can update this if Richard and you prefer this.

I think this is fine, as I'm not keen on introducing a complete set of tcg_gen_foo_va macros. As is, any mismatch will be caught at compile-time.

r~

#24 lore raw

Re: [PATCH v10 15/21] target/arm/tcg/translate.c: replace TCGv with TCGv_va

Quoted 41 lines · Richard Henderson
Quoted 40 lines · Pierrick Bouvier
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Pierrick Bouvier

We know this file is for 32-bit runtime target, so we can set TCG_ADDRESS_BITS. TCG_TYPE_VA is derived accordingly and is already passed to translator_loop.

---
    target/arm/tcg/translate.c | 29 +++++++++++++++--------------
    1 file changed, 15 insertions(+), 14 deletions(-)
target/arm/tcg/translate.c +2 -1
index fa4c7907dcd..0b3b4ab86be 100644
@@ -22,7 +22,8 @@
    #include "translate.h"
    #include "translate-a32.h"
-#include "tcg/tcg-op.h"
+#define TCG_ADDRESS_BITS 32
+#include "tcg/tcg-op-mem.h"
    #include "qemu/log.h"
    #include "arm_ldst.h"
    #include "semihosting/semihost.h"

target/arm/tcg/translate.c MemOp pow2_align(unsigned i) · line 916

Quoted 9 lines
target/arm/tcg/translate.c +3 -3
@@ -910,14 +911,14 @@ MemOp pow2_align(unsigned i)
     * that the address argument is TCGv_i32 rather than TCGv.
     */
-static TCGv gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
+static TCGv_va gen_aa32_addr(DisasContext *s, TCGv_i32 a32, MemOp op)
    {
-    TCGv addr = tcg_temp_new();
-    tcg_gen_extu_i32_tl(addr, a32);
+    TCGv_va addr = tcgv_va_temp_new();
+    tcg_gen_mov_i32(addr, a32);

The implicit TCGv_va -> TCGv_i32 bugs me here, but the overall change will make my sleep better :) So:

Quoted 6 lines
Quoted 2 lines

We could use TCGv_i32 directly, TCGv_va is just useful here to document the intention. I can update this if Richard and you prefer this.

I think this is fine, as I'm not keen on introducing a complete set of tcg_gen_foo_va macros. As is, any mismatch will be caught at compile-time.

Agreed. Usage should be reduced to address related functions.

Quoted 2 lines

r~

#25 lore raw

PATCH v10 16/21 target/arm/tcg/translate-a64.c: use translator_ldl_end instead of arm_ldl_code

In reply to Pierrick Bouvier

Allows to reduce scope of target/arm/tcg/arm_ldst.h to aarch32 only.

---
 target/arm/tcg/translate-a64.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/arm/tcg/translate-a64.c +3 -3
index df2cbd66b38..48b5c572555 100644
@@ -26,7 +26,6 @@
 #include "translate-a64.h"
 #include "tcg/tcg-op.h"
 #include "qemu/log.h"
-#include "arm_ldst.h"
 #include "semihosting/semihost.h"
 #include "cpregs.h"
 
@@ -10801,7 +10800,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
     if (pc & 3) {
         /*
          * PC alignment fault.  This has priority over the instruction abort
-         * that we would receive from a translation fault via arm_ldl_code.
+         * that we would receive from a translation fault via translator_ldl_end.
          * This should only be possible after an indirect branch, at the
          * start of the TB.
          */
@@ -10813,7 +10812,8 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
     }
 
     s->pc_curr = pc;
-    insn = arm_ldl_code(env, &s->base, pc, s->sctlr_b);
+    /* Code is always little-endian on Aarch64 */
+    insn = translator_ldl_end(env, &s->base, pc, MO_LE);
     s->insn = insn;
     s->base.pc_next = pc + 4;
 
Signature · 1 line
2.47.3
#26 lore raw

PATCH v10 17/21 target/arm/tcg/arm_ldst.h: merge in translate.c

In reply to Pierrick Bouvier

Only translate.c uses those functions, thus move them back to this file.

---
 target/arm/tcg/arm_ldst.h  | 47 --------------------------------------
 target/arm/tcg/translate.c | 22 +++++++++++++++++-
 2 files changed, 21 insertions(+), 48 deletions(-)
target/arm/tcg/arm_ldst.h +0 -47
index cee0548a1c7..e69de29bb2d 100644
@@ -1,47 +0,0 @@
-/*
- * ARM load/store instructions for code (armeb-user support)
- *
- *  Copyright (c) 2012 CodeSourcery, LLC
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef ARM_LDST_H
-#define ARM_LDST_H
-
-#include "exec/translator.h"
-#include "qemu/bswap.h"
-
-/* Load an instruction and return it in the standard little-endian order */
-static inline uint32_t arm_ldl_code(CPUARMState *env, DisasContextBase *s,
-                                    target_ulong addr, bool sctlr_b)
-{
-    return translator_ldl_swap(env, s, addr, bswap_code(sctlr_b));
-}
-
-/* Ditto, for a halfword (Thumb) instruction */
-static inline uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
-                                     target_ulong addr, bool sctlr_b)
-{
-#ifndef CONFIG_USER_ONLY
-    /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
-       within each word.  Undo that now.  */
-    if (sctlr_b) {
-        addr ^= 2;
-    }
-#endif
-    return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
-}
-
-#endif
target/arm/tcg/translate.c +21 -1
index 0b3b4ab86be..20f5bdcbe2c 100644
@@ -25,7 +25,6 @@
 #define TCG_ADDRESS_BITS 32
 #include "tcg/tcg-op-mem.h"
 #include "qemu/log.h"
-#include "arm_ldst.h"
 #include "semihosting/semihost.h"
 #include "cpregs.h"
 #include "exec/target_page.h"
@@ -6281,6 +6280,20 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn)
     }
 }
 
+/* Ditto, for a halfword (Thumb) instruction */
+static uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
+                              target_ulong addr, bool sctlr_b)
+{
+#ifndef CONFIG_USER_ONLY
+    /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
+       within each word.  Undo that now.  */
+    if (sctlr_b) {
+        addr ^= 2;
+    }
+#endif
+    return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
+}
+
 static bool insn_crosses_page(CPUARMState *env, DisasContext *s)
 {
     /* Return true if the insn at dc->base.pc_next might cross a page boundary.
@@ -6515,6 +6528,13 @@ static void arm_post_translate_insn(DisasContext *dc)
     }
 }
 
+/* Load an instruction and return it in the standard little-endian order */
+static uint32_t arm_ldl_code(CPUARMState *env, DisasContextBase *s,
+                             target_ulong addr, bool sctlr_b)
+{
+    return translator_ldl_swap(env, s, addr, bswap_code(sctlr_b));
+}
+
 static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
 {
     DisasContext *dc = container_of(dcbase, DisasContext, base);
Signature · 1 line
2.47.3
#27 lore raw

Re: [PATCH v10 17/21] target/arm/tcg/arm_ldst.h: merge in translate.c

Quoted 10 lines · Pierrick Bouvier

Only translate.c uses those functions, thus move them back to this file.

---
  target/arm/tcg/arm_ldst.h  | 47 --------------------------------------
  target/arm/tcg/translate.c | 22 +++++++++++++++++-
  2 files changed, 21 insertions(+), 48 deletions(-)

target/arm/tcg/translate.c static void disas_thumb_insn(DisasContext *s, uint32_t insn) · line 6289

Quoted 7 lines
target/arm/tcg/translate.c +7 -0
+/* Ditto, for a halfword (Thumb) instruction */
+static uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
+                              target_ulong addr, bool sctlr_b)
+{
+#ifndef CONFIG_USER_ONLY
+    /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
+       within each word.  Undo that now.  */

Pre-existing and removed in the next patch, but in case you have to respin:

WARNING: Block comments use * on subsequent lines
#91: FILE: target/arm/tcg/translate.c:6289:
+ /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
+ within each word. Undo that now. */

Quoted 6 lines
target/arm/tcg/translate.c +6 -0
+    if (sctlr_b) {
+        addr ^= 2;
+    }
+#endif
+    return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
+}
Reviewed-by on v10 17/21
#28 lore raw

Re: [PATCH v10 17/21] target/arm/tcg/arm_ldst.h: merge in translate.c

In reply to Pierrick Bouvier
Quoted 8 lines · Pierrick Bouvier

Only translate.c uses those functions, thus move them back to this file.

---
  target/arm/tcg/arm_ldst.h  | 47 --------------------------------------
  target/arm/tcg/translate.c | 22 +++++++++++++++++-
  2 files changed, 21 insertions(+), 48 deletions(-)
#29 lore raw

PATCH v10 18/21 target/arm/tcg/translate.c: replace translator_ldl_swap with translator_ldl_end

In reply to Pierrick Bouvier
---
 target/arm/tcg/translate.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
target/arm/tcg/translate.c +5 -6
index 20f5bdcbe2c..c432de2a268 100644
@@ -6284,14 +6284,13 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn)
 static uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
                               target_ulong addr, bool sctlr_b)
 {
-#ifndef CONFIG_USER_ONLY
-    /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
-       within each word.  Undo that now.  */
+    MemOp end = MO_LE;
     if (sctlr_b) {
+        /* In BE32 mode, adjacent Thumb instructions are swapped. */
         addr ^= 2;
+        end = MO_BE;
     }
-#endif
-    return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
+    return translator_lduw_end(env, s, addr, end);
 }
 
 static bool insn_crosses_page(CPUARMState *env, DisasContext *s)
@@ -6532,7 +6531,7 @@ static void arm_post_translate_insn(DisasContext *dc)
 static uint32_t arm_ldl_code(CPUARMState *env, DisasContextBase *s,
                              target_ulong addr, bool sctlr_b)
 {
-    return translator_ldl_swap(env, s, addr, bswap_code(sctlr_b));
+    return translator_ldl_end(env, s, addr, sctlr_b ? MO_BE : MO_LE);
 }
 
 static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
Signature · 1 line
2.47.3
Reviewed-by on v10 18/21
#30 lore raw

Re: [PATCH v10 18/21] target/arm/tcg/translate.c: replace translator_ldl_swap with translator_ldl_end

Quoted 16 lines · Pierrick Bouvier
---
  target/arm/tcg/translate.c | 11 +++++------
  1 file changed, 5 insertions(+), 6 deletions(-)
target/arm/tcg/translate.c +0 -2
index 20f5bdcbe2c..c432de2a268 100644
@@ -6284,14 +6284,13 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn)
  static uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
                                target_ulong addr, bool sctlr_b)
  {
-#ifndef CONFIG_USER_ONLY
-    /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped

target/arm/tcg/translate.c static void disas_thumb_insn(DisasContext *s, uint32_t insn) · line 6293

Quoted 10 lines
target/arm/tcg/translate.c +4 -3
-       within each word.  Undo that now.  */
+    MemOp end = MO_LE;
      if (sctlr_b) {
+        /* In BE32 mode, adjacent Thumb instructions are swapped. */
          addr ^= 2;
+        end = MO_BE;
      }
-#endif
-    return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
+    return translator_lduw_end(env, s, addr, end);

Great, this removes the last translator_lduw_swap() use \o/

And a lot of complexity is removed :~)

#31 lore raw

PATCH v10 19/21 target/arm/cpu.c: simplify endianness handling in arm_disas_set_info

In reply to Pierrick Bouvier
---
 target/arm/cpu.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
target/arm/cpu.c +1 -5
index ccc47c8a9ad..b62de8addff 100644
@@ -828,15 +828,11 @@ static void arm_disas_set_info(const CPUState *cpu, disassemble_info *info)
     }
 
     info->endian = BFD_ENDIAN_LITTLE;
-    if (bswap_code(sctlr_b)) {
-        info->endian = target_big_endian() ? BFD_ENDIAN_LITTLE : BFD_ENDIAN_BIG;
-    }
     info->flags &= ~INSN_ARM_BE32;
-#ifndef CONFIG_USER_ONLY
     if (sctlr_b) {
+        info->endian |= BFD_ENDIAN_BIG;
         info->flags |= INSN_ARM_BE32;
     }
-#endif
 }
 
 static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
Signature · 1 line
2.47.3
#33 lore raw

PATCH v10 20/21 target/arm/tcg/translate.c: remove target_ulong

In reply to Pierrick Bouvier

We can replace it with uint32_t, because we know it's limited to 32-bit target.

---
 target/arm/tcg/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/tcg/translate.c +2 -2
index c432de2a268..ce427c5a3ca 100644
@@ -6282,7 +6282,7 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn)
 
 /* Ditto, for a halfword (Thumb) instruction */
 static uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
-                              target_ulong addr, bool sctlr_b)
+                              uint32_t addr, bool sctlr_b)
 {
     MemOp end = MO_LE;
     if (sctlr_b) {
@@ -6529,7 +6529,7 @@ static void arm_post_translate_insn(DisasContext *dc)
 
 /* Load an instruction and return it in the standard little-endian order */
 static uint32_t arm_ldl_code(CPUARMState *env, DisasContextBase *s,
-                             target_ulong addr, bool sctlr_b)
+                             uint32_t addr, bool sctlr_b)
 {
     return translator_ldl_end(env, s, addr, sctlr_b ? MO_BE : MO_LE);
 }
Signature · 1 line
2.47.3
#34 lore raw

PATCH v10 21/21 target/arm/tcg/translate.c: make compilation unit common

In reply to Pierrick Bouvier

We removed all target specifics, and can finally compile this file only once.

---
 target/arm/tcg/meson.build | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
target/arm/tcg/meson.build +5 -3
index 0740de92c1a..506f031f1aa 100644
@@ -20,20 +20,18 @@ mve_d = decodetree.process('mve.decode', extra_args: '--decode=disas_mve')
 
 m_nocp_d = decodetree.process('m-nocp.decode', extra_args: '--decode=disas_m_nocp')
 
-gen_a32 = [
+translate32_d = [
   decodetree.process('a32.decode', extra_args: '--static-decode=disas_a32'),
   decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'),
   decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'),
   decodetree.process('t16.decode', extra_args: ['-w', '16', '--static-decode=disas_t16']),
 ]
 
-arm_ss.add(gen_a32)
 arm_ss.add(when: 'TARGET_AARCH64', if_true: gen_a64)
 arm_ss.add(when: 'TARGET_AARCH64', if_false: files('stubs32.c'))
 
 arm_ss.add(files(
   'cpu32.c',
-  'translate.c',
   'm_helper.c',
   'mve_helper.c',
 ))
@@ -66,6 +64,7 @@ arm_common_system_ss.add(
   m_nocp_d,
   mve_d,
   neon_d,
+  translate32_d,
   vfp_d,
   files(
   'cpregs-at.c',
@@ -77,6 +76,7 @@ arm_common_system_ss.add(
   'psci.c',
   'tlb_helper.c',
   'tlb-insns.c',
+  'translate.c',
   'translate-m-nocp.c',
   'translate-mve.c',
   'translate-neon.c',
@@ -88,6 +88,7 @@ arm_user_ss.add(
   m_nocp_d,
   mve_d,
   neon_d,
+  translate32_d,
   vfp_d,
   files(
   'debug.c',
@@ -96,6 +97,7 @@ arm_user_ss.add(
   'neon_helper.c',
   'op_helper.c',
   'tlb_helper.c',
+  'translate.c',
   'translate-m-nocp.c',
   'translate-mve.c',
   'translate-neon.c',
Signature · 1 line
2.47.3
#35 lore raw
In reply to Pierrick Bouvier
Quoted 11 lines · Pierrick Bouvier

This series tackles (most of) the rest of target/arm, especially tcg folder.

We extract tcg memory operation in a new header, with a new type representing virtual addresses.

Initially, I went down the way to have a dynamic definition of TCGv, which required much more boilerplate and runtime checks. After discussing with Richard, I realized it was not needed, and that could simply split 32 and 64 bit properly in different files instead. This approach will not work with other architectures, requiring something else, but it's enough for target/arm.

Quoted 4 lines

Files left are:
- target/arm/tcg/mve_helper.c
- target/arm/tcg/m_helper.c
- target/arm/tcg/cpu32.c

I remember having an issue with cpu32.c when it registers TYPE_CPU QOM objects, "max" overlaps with cpu64.c one.

As a kludge we could rename arm_max_initfn -> aarch64_max_tcg_initfn and move it to target/arm/tcg/stubs32.c =)

#36 lore raw
In reply to Pierrick Bouvier
Quoted 129 lines · Pierrick Bouvier

This series tackles (most of) the rest of target/arm, especially tcg folder.

We extract tcg memory operation in a new header, with a new type representing virtual addresses.

Initially, I went down the way to have a dynamic definition of TCGv, which required much more boilerplate and runtime checks. After discussing with Richard, I realized it was not needed, and that could simply split 32 and 64 bit properly in different files instead. This approach will not work with other architectures, requiring something else, but it's enough for target/arm.

Files left are:
- target/arm/tcg/mve_helper.c
- target/arm/tcg/m_helper.c
- target/arm/tcg/cpu32.c

v10
---

- extract patch for endianness handling in arm_disas_set_info
- added some comments

v9
--

- introduce aarch64_translate_code *before* adding parameter to translator_loop
- use TCG_TYPE_VA as address type for translator_loop
- remove inline marker on functions merged from arm_ldst.h to translate.c
- refactor arm_ldl_code/arm_lduw_code

v8
--

- make translate.c compilation unit common.

v7
--

- add parameter to translator_loop to indicate address type for current tb.
- remove TCGv from target/arm/tcg/translate.c

v6
--

- meson.build: extract decode files in separate variables and explicitly include them in user and system code. The duplication is now minimized: one instance for all system binaries, and one per user binary.

v5
--

- reimplemented what v0 did with new approach defining new tcg-op-mem header
- reapply all straightforward patches from v0
- only translate.c is left, but first want to validate that changes here are ok for maintainers before doing more.

v0
--

See original thread:
https://lore.kernel.org/qemu-devel/[email protected]/#t

Note about v1 -> v4
-------------------

- After v0 which was trying to do too many changes, v1 to v4 focused on smaller things, and all patches have been merged already.
https://patchew.org/QEMU/[email protected]/

Pierrick Bouvier (21):
include/tcg/tcg-op: extract memory operations to tcg-op-mem.h target/arm/translate.h: remove tcg-op.h include target/arm/tcg/translate.h: remove tcg-op-gvec.h include target/arm/tcg/translate.h: remove TARGET_AARCH64 target/arm/tcg/translate-vfp.c: make compilation unit common target/arm/tcg/translate-neon.c: make compilation unit common target/arm/tcg/translate-mve.c: make compilation unit common target/arm/tcg/translate-m-nocp.c: make compilation unit common target/arm/tcg/op_helper.c: make compilation unit common target/arm/tcg/gengvec.c: make compilation unit common target/arm/tcg/translate.c: remove MO_TE usage target/arm/tcg/translate.c: replace target_ulong with uint32_t target/arm/tcg/translate.c: extract aarch64_translate_code() tcg/translator: add parameter to translator_loop for current addr type target/arm/tcg/translate.c: replace TCGv with TCGv_va target/arm/tcg/translate-a64.c: use translator_ldl_end instead of
arm_ldl_code
target/arm/tcg/arm_ldst.h: merge in translate.c target/arm/tcg/translate.c: replace translator_ldl_swap with
translator_ldl_end
target/arm/cpu.c: simplify endianness handling in arm_disas_set_info target/arm/tcg/translate.c: remove target_ulong target/arm/tcg/translate.c: make compilation unit common

  include/exec/translator.h        |   4 +-
  include/tcg/tcg-op-mem.h         | 126 +++++++++++++++++++++++++++++++
  include/tcg/tcg-op.h             | 100 +-----------------------
  target/arm/internals.h           |   2 +
  target/arm/tcg/arm_ldst.h        |  47 ------------
  target/arm/tcg/translate.h       |  14 +---
  accel/tcg/translate-all.c        |   1 -
  accel/tcg/translator.c           |   4 +-
  target/alpha/translate.c         |   3 +-
  target/arm/cpu.c                 |   6 +-
  target/arm/tcg/op_helper.c       |   1 -
  target/arm/tcg/stubs32.c         |  24 ++++++
  target/arm/tcg/translate-a64.c   |  17 ++++-
  target/arm/tcg/translate-sme.c   |   1 +
  target/arm/tcg/translate-sve.c   |   1 +
  target/arm/tcg/translate.c       |  73 +++++++++++-------
  target/avr/translate.c           |   3 +-
  target/hexagon/translate.c       |   3 +-
  target/hppa/translate.c          |   3 +-
  target/i386/tcg/translate.c      |   3 +-
  target/loongarch/tcg/translate.c |   3 +-
  target/m68k/translate.c          |   3 +-
  target/microblaze/translate.c    |   3 +-
  target/mips/tcg/translate.c      |   3 +-
  target/or1k/translate.c          |   3 +-
  target/ppc/translate.c           |   3 +-
  target/riscv/translate.c         |   3 +-
  target/rx/translate.c            |   3 +-
  target/s390x/tcg/translate.c     |   3 +-
  target/sh4/translate.c           |   3 +-
  target/sparc/translate.c         |   3 +-
  target/tricore/translate.c       |   3 +-
  target/xtensa/translate.c        |   3 +-
  target/arm/tcg/meson.build       |  57 ++++++++++----
  34 files changed, 304 insertions(+), 228 deletions(-)
Quoted 3 lines

create mode 100644 include/tcg/tcg-op-mem.h
create mode 100644 target/arm/tcg/stubs32.c

v11 sent:
https://lore.kernel.org/qemu-devel/[email protected]/

Regards,
Pierrick

#37 lore raw

PATCH v10 1/1 linux-user/arm: Inline bswap_code()

In reply to Pierrick Bouvier

bswap_code() is now used once in get_user_code_u32(), inline it and simplify removing dead system code.

---
 target/arm/cpu.h          | 16 ----------------
 linux-user/arm/cpu_loop.c | 10 ++++++++++
 2 files changed, 10 insertions(+), 16 deletions(-)
target/arm/cpu.h +0 -16
index 657ff4ab20b..917e9919e8c 100644
@@ -2568,22 +2568,6 @@ static inline int sme_vq(CPUARMState *env)
     return EX_TBFLAG_A64(env->hflags, SVL) + 1;
 }
 
-static inline bool bswap_code(bool sctlr_b)
-{
-#ifdef CONFIG_USER_ONLY
-    /* BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian.
-     * The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0
-     * would also end up as a mixed-endian mode with BE code, LE data.
-     */
-    return TARGET_BIG_ENDIAN ^ sctlr_b;
-#else
-    /* All code access in ARM is little endian, and there are no loaders
-     * doing swaps that need to be reversed
-     */
-    return 0;
-#endif
-}
-
 enum {
     QEMU_PSCI_CONDUIT_DISABLED = 0,
     QEMU_PSCI_CONDUIT_SMC = 1,
linux-user/arm/cpu_loop.c +10 -0
index 19874f4c727..24a66b52cee 100644
@@ -29,6 +29,16 @@
 #include "user/page-protection.h"
 #include "target/arm/syndrome.h"
 
+static inline bool bswap_code(bool sctlr_b)
+{
+    /*
+     * BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian.
+     * The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0
+     * would also end up as a mixed-endian mode with BE code, LE data.
+     */
+    return TARGET_BIG_ENDIAN ^ sctlr_b;
+}
+
 #define get_user_code_u32(x, gaddr, env)                \
     ({ abi_long __r = get_user_u32((x), (gaddr));       \
         if (!__r && bswap_code(arm_sctlr_b(env))) {     \
Signature · 1 line
2.53.0
#38 lore raw

Re: [PATCH v10 19.5/21] linux-user/arm: Inline bswap_code()

Quoted 47 lines · Philippe Mathieu-Daudé

bswap_code() is now used once in get_user_code_u32(), inline it and simplify removing dead system code.

---
  target/arm/cpu.h          | 16 ----------------
  linux-user/arm/cpu_loop.c | 10 ++++++++++
  2 files changed, 10 insertions(+), 16 deletions(-)
target/arm/cpu.h +0 -16
index 657ff4ab20b..917e9919e8c 100644
@@ -2568,22 +2568,6 @@ static inline int sme_vq(CPUARMState *env)
      return EX_TBFLAG_A64(env->hflags, SVL) + 1;
  }
 
-static inline bool bswap_code(bool sctlr_b)
-{
-#ifdef CONFIG_USER_ONLY
-    /* BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian.
-     * The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0
-     * would also end up as a mixed-endian mode with BE code, LE data.
-     */
-    return TARGET_BIG_ENDIAN ^ sctlr_b;
-#else
-    /* All code access in ARM is little endian, and there are no loaders
-     * doing swaps that need to be reversed
-     */
-    return 0;
-#endif
-}
-
  enum {
      QEMU_PSCI_CONDUIT_DISABLED = 0,
      QEMU_PSCI_CONDUIT_SMC = 1,
linux-user/arm/cpu_loop.c +3 -0
index 19874f4c727..24a66b52cee 100644
@@ -29,6 +29,16 @@
  #include "user/page-protection.h"
  #include "target/arm/syndrome.h"
 
+static inline bool bswap_code(bool sctlr_b)
+{
+    /*

linux-user/arm/cpu_loop.c line 44

Quoted 10 lines
linux-user/arm/cpu_loop.c +7 -0
+     * BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian.
+     * The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0
+     * would also end up as a mixed-endian mode with BE code, LE data.
+     */
+    return TARGET_BIG_ENDIAN ^ sctlr_b;
+}
+
  #define get_user_code_u32(x, gaddr, env)                \
      ({ abi_long __r = get_user_u32((x), (gaddr));       \
          if (!__r && bswap_code(arm_sctlr_b(env))) {     \

I don't think so, Richard wants to remove bswap_code completely and get_user_code_u32 is last usage of it. I'm waiting for his patch to integrate it in series.