Skip to contentSkip to conversation

target/openrisc: Remove all uses of target_[u]long types

PATCH Superseded Philippe Mathieu-Daudé 2 participants 22 messages Oct 9, 2025 – Oct 10, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover target/openrisc: Remove all uses of target_[u]long types

v2:
- Remove 'TARGET_LONG_BITS != 32' dead code
- Addressed Anton's review comments (MO_TE -> MO_BE)

Remove all the target_[u]long uses in OpenRISC frontend.

Philippe Mathieu-Daudé (10):
target/openrisc: Replace VMSTATE_UINTTL() -> VMSTATE_UINT32() target/openrisc: Explode MO_TExx -> MO_TE | MO_xx target/openrisc: Replace MO_TE -> MO_BE
target/openrisc: Do not use target_ulong for @mr in MTSPR helper target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers target/openrisc: Remove target_ulong use in raise_mmu_exception() target/openrisc: Use vaddr type for $pc jumps target/openrisc: Remove 'TARGET_LONG_BITS != 32' dead code target/openrisc: Inline tcg_gen_trunc_i64_tl() target/openrisc: Replace target_ulong -> uint32_t

 target/openrisc/cpu.h        |  31 +--
 target/openrisc/helper.h     |   8 +-
 target/openrisc/fpu_helper.c |   8 +-
 target/openrisc/machine.c    |  20 +-
 target/openrisc/mmu.c        |   7 +-
 target/openrisc/sys_helper.c |   7 +-
 target/openrisc/translate.c  | 443 +++++++++++++++++------------------
 7 files changed, 244 insertions(+), 280 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/10 target/openrisc: Replace VMSTATE_UINTTL() -> VMSTATE_UINT32()

Both OpenRISCTLBEntry fields are of uint32_t type. Use the appropriate VMSTATE_UINT32() macro.

There is no functional change (the migration stream is not modified), because the OpenRISC targets are only built as 32-bit:

  $ git grep TARGET_LONG_BITS configs/targets/or1k-*
  configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
  configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32
---
 target/openrisc/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/openrisc/machine.c +2 -2
index 081c706d02c..fa054e528bd 100644
@@ -26,8 +26,8 @@ static const VMStateDescription vmstate_tlb_entry = {
     .version_id = 1,
     .minimum_version_id = 1,
     .fields = (const VMStateField[]) {
-        VMSTATE_UINTTL(mr, OpenRISCTLBEntry),
-        VMSTATE_UINTTL(tr, OpenRISCTLBEntry),
+        VMSTATE_UINT32(mr, OpenRISCTLBEntry),
+        VMSTATE_UINT32(tr, OpenRISCTLBEntry),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
2.51.0
Reviewed-by on v2 1/10
#2 lore raw

Re: [PATCH v2 01/10] target/openrisc: Replace VMSTATE_UINTTL() -> VMSTATE_UINT32()

Quoted 10 lines · Philippe Mathieu-Daudé

Both OpenRISCTLBEntry fields are of uint32_t type. Use the appropriate VMSTATE_UINT32() macro.

There is no functional change (the migration stream is not modified), because the OpenRISC targets are only built as 32-bit:

   $ git grep TARGET_LONG_BITS configs/targets/or1k-*
   configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
   configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32
Quoted 5 lines
---
  target/openrisc/machine.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

r~

#3 lore raw

PATCH v2 2/10 target/openrisc: Explode MO_TExx -> MO_TE | MO_xx

In reply to Philippe Mathieu-Daudé

Extract the implicit MO_TE definition in order to replace it in the next commit.

Mechanical change using:

  $ for n in UW UL UQ UO SW SL SQ; do \
      sed -i -e "s/MO_TE$n/MO_TE | MO_$n/" \
           $(git grep -l MO_TE$n target/openrisc); \
    done
---
 target/openrisc/translate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
target/openrisc/translate.c +8 -8
index 5ab3bc7021d..df0ebcd3138 100644
@@ -647,7 +647,7 @@ static bool trans_l_lwa(DisasContext *dc, arg_load *a)
     check_r0_write(dc, a->d);
     ea = tcg_temp_new();
     tcg_gen_addi_tl(ea, cpu_R(dc, a->a), a->i);
-    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_TEUL);
+    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_TE | MO_UL);
     tcg_gen_mov_tl(cpu_lock_addr, ea);
     tcg_gen_mov_tl(cpu_lock_value, cpu_R(dc, a->d));
     return true;
@@ -665,13 +665,13 @@ static void do_load(DisasContext *dc, arg_load *a, MemOp mop)
 
 static bool trans_l_lwz(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TEUL);
+    do_load(dc, a, MO_TE | MO_UL);
     return true;
 }
 
 static bool trans_l_lws(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TESL);
+    do_load(dc, a, MO_TE | MO_SL);
     return true;
 }
 
@@ -689,13 +689,13 @@ static bool trans_l_lbs(DisasContext *dc, arg_load *a)
 
 static bool trans_l_lhz(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TEUW);
+    do_load(dc, a, MO_TE | MO_UW);
     return true;
 }
 
 static bool trans_l_lhs(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TESW);
+    do_load(dc, a, MO_TE | MO_SW);
     return true;
 }
 
@@ -713,7 +713,7 @@ static bool trans_l_swa(DisasContext *dc, arg_store *a)
 
     val = tcg_temp_new();
     tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value,
-                              cpu_R(dc, a->b), dc->mem_idx, MO_TEUL);
+                              cpu_R(dc, a->b), dc->mem_idx, MO_TE | MO_UL);
     tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value);
 
     tcg_gen_br(lab_done);
@@ -735,7 +735,7 @@ static void do_store(DisasContext *dc, arg_store *a, MemOp mop)
 
 static bool trans_l_sw(DisasContext *dc, arg_store *a)
 {
-    do_store(dc, a, MO_TEUL);
+    do_store(dc, a, MO_TE | MO_UL);
     return true;
 }
 
@@ -747,7 +747,7 @@ static bool trans_l_sb(DisasContext *dc, arg_store *a)
 
 static bool trans_l_sh(DisasContext *dc, arg_store *a)
 {
-    do_store(dc, a, MO_TEUW);
+    do_store(dc, a, MO_TE | MO_UW);
     return true;
 }
 
Signature · 1 line
2.51.0
#4 lore raw

Re: [PATCH v2 02/10] target/openrisc: Explode MO_TExx -> MO_TE | MO_xx

Quoted 10 lines · Philippe Mathieu-Daudé

Extract the implicit MO_TE definition in order to replace it in the next commit.

Mechanical change using:

   $ for n in UW UL UQ UO SW SL SQ; do \
       sed -i -e "s/MO_TE$n/MO_TE | MO_$n/" \
            $(git grep -l MO_TE$n target/openrisc); \
     done
Quoted 4 lines
---
  target/openrisc/translate.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)

Why bother splitting, instead of just changing to MO_BEUL, etc?

r~

#5 lore raw

Re: [PATCH v2 02/10] target/openrisc: Explode MO_TExx -> MO_TE | MO_xx

Quoted 11 lines · Richard Henderson
Quoted 10 lines · Philippe Mathieu-Daudé

Extract the implicit MO_TE definition in order to replace it in the next commit.

Mechanical change using:

   $ for n in UW UL UQ UO SW SL SQ; do \
       sed -i -e "s/MO_TE$n/MO_TE | MO_$n/" \
            $(git grep -l MO_TE$n target/openrisc); \
     done
Quoted 6 lines
Quoted 4 lines

---
  target/openrisc/translate.c | 16 ++++++++--------

  1 file changed, 8 insertions(+), 8 deletions(-)

Why bother splitting, instead of just changing to MO_BEUL, etc?

In v3 I'll add a new patch introducing mo_endian(). Even if a target is only build for a particular endianness (sometimes a QEMU limitation) I think having an explicit mo_endian() is useful because 1/ only a single place to look at / change if more endianness support added and 2/ common style between our different targets. Therefore for this patch I prefer a mechanical change before manual following ones.

#6 lore raw

PATCH v2 3/10 target/openrisc: Replace MO_TE -> MO_BE

In reply to Philippe Mathieu-Daudé

We only build the OpenRISC targets using big endianness order:

  $ git grep TARGET_BIG_ENDIAN configs/targets/or1k-*
  configs/targets/or1k-linux-user.mak:2:TARGET_BIG_ENDIAN=y
  configs/targets/or1k-softmmu.mak:2:TARGET_BIG_ENDIAN=y

Therefore the MO_TE definition always expands to MO_BE. Use the latter to simplify.

---
 target/openrisc/translate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
target/openrisc/translate.c +8 -8
index df0ebcd3138..4ece2547614 100644
@@ -647,7 +647,7 @@ static bool trans_l_lwa(DisasContext *dc, arg_load *a)
     check_r0_write(dc, a->d);
     ea = tcg_temp_new();
     tcg_gen_addi_tl(ea, cpu_R(dc, a->a), a->i);
-    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_TE | MO_UL);
+    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_BE | MO_UL);
     tcg_gen_mov_tl(cpu_lock_addr, ea);
     tcg_gen_mov_tl(cpu_lock_value, cpu_R(dc, a->d));
     return true;
@@ -665,13 +665,13 @@ static void do_load(DisasContext *dc, arg_load *a, MemOp mop)
 
 static bool trans_l_lwz(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TE | MO_UL);
+    do_load(dc, a, MO_BE | MO_UL);
     return true;
 }
 
 static bool trans_l_lws(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TE | MO_SL);
+    do_load(dc, a, MO_BE | MO_SL);
     return true;
 }
 
@@ -689,13 +689,13 @@ static bool trans_l_lbs(DisasContext *dc, arg_load *a)
 
 static bool trans_l_lhz(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TE | MO_UW);
+    do_load(dc, a, MO_BE | MO_UW);
     return true;
 }
 
 static bool trans_l_lhs(DisasContext *dc, arg_load *a)
 {
-    do_load(dc, a, MO_TE | MO_SW);
+    do_load(dc, a, MO_BE | MO_SW);
     return true;
 }
 
@@ -713,7 +713,7 @@ static bool trans_l_swa(DisasContext *dc, arg_store *a)
 
     val = tcg_temp_new();
     tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value,
-                              cpu_R(dc, a->b), dc->mem_idx, MO_TE | MO_UL);
+                              cpu_R(dc, a->b), dc->mem_idx, MO_BE | MO_UL);
     tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value);
 
     tcg_gen_br(lab_done);
@@ -735,7 +735,7 @@ static void do_store(DisasContext *dc, arg_store *a, MemOp mop)
 
 static bool trans_l_sw(DisasContext *dc, arg_store *a)
 {
-    do_store(dc, a, MO_TE | MO_UL);
+    do_store(dc, a, MO_BE | MO_UL);
     return true;
 }
 
@@ -747,7 +747,7 @@ static bool trans_l_sb(DisasContext *dc, arg_store *a)
 
 static bool trans_l_sh(DisasContext *dc, arg_store *a)
 {
-    do_store(dc, a, MO_TE | MO_UW);
+    do_store(dc, a, MO_BE | MO_UW);
     return true;
 }
 
Signature · 1 line
2.51.0
#7 lore raw

Re: [PATCH v2 03/10] target/openrisc: Replace MO_TE -> MO_BE

Quoted 32 lines · Philippe Mathieu-Daudé

We only build the OpenRISC targets using big endianness order:

   $ git grep TARGET_BIG_ENDIAN configs/targets/or1k-*
   configs/targets/or1k-linux-user.mak:2:TARGET_BIG_ENDIAN=y
   configs/targets/or1k-softmmu.mak:2:TARGET_BIG_ENDIAN=y

Therefore the MO_TE definition always expands to MO_BE. Use the latter to simplify.

---
  target/openrisc/translate.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
target/openrisc/translate.c +1 -2
index df0ebcd3138..4ece2547614 100644
@@ -647,7 +647,7 @@ static bool trans_l_lwa(DisasContext *dc, arg_load *a)
      check_r0_write(dc, a->d);
      ea = tcg_temp_new();
      tcg_gen_addi_tl(ea, cpu_R(dc, a->a), a->i);
-    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_TE | MO_UL);
+    tcg_gen_qemu_ld_tl(cpu_R(dc, a->d), ea, dc->mem_idx, MO_BE | MO_UL);
      tcg_gen_mov_tl(cpu_lock_addr, ea);
      tcg_gen_mov_tl(cpu_lock_value, cpu_R(dc, a->d));
      return true;
@@ -665,13 +665,13 @@ static void do_load(DisasContext *dc, arg_load *a, MemOp mop)
 
  static bool trans_l_lwz(DisasContext *dc, arg_load *a)
  {
-    do_load(dc, a, MO_TE | MO_UL);

target/openrisc/translate.c static void do_load(DisasContext *dc, arg_load *a, MemOp mop) · line 676

Quoted 10 lines
target/openrisc/translate.c +2 -1
+    do_load(dc, a, MO_BE | MO_UL);
      return true;
  }
 
  static bool trans_l_lws(DisasContext *dc, arg_load *a)
  {
-    do_load(dc, a, MO_TE | MO_SL);
+    do_load(dc, a, MO_BE | MO_SL);
      return true;
  }

Hmm should we move MO_BE within do_load()?

#8 lore raw

PATCH v2 4/10 target/openrisc: Do not use target_ulong for @mr in MTSPR helper

In reply to Philippe Mathieu-Daudé

OpenRISCTLBEntry::@mr field is a uint32_t type since its introduction in commit 726fe045720 ("target-or32: Add MMU support").

---
 target/openrisc/sys_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/sys_helper.c +1 -1
index b091a9c6685..ad59939db3b 100644
@@ -45,7 +45,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)
     OpenRISCCPU *cpu = env_archcpu(env);
 #ifndef CONFIG_USER_ONLY
     CPUState *cs = env_cpu(env);
-    target_ulong mr;
+    uint32_t mr;
     int idx;
 #endif
 
Signature · 1 line
2.51.0
Reviewed-by on v2 4/10
#9 lore raw

Re: [PATCH v2 04/10] target/openrisc: Do not use target_ulong for @mr in MTSPR helper

Quoted 14 lines · Philippe Mathieu-Daudé

OpenRISCTLBEntry::@mr field is a uint32_t type since its introduction in commit 726fe045720 ("target-or32: Add MMU support").

---
  target/openrisc/sys_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/sys_helper.c +0 -0
index b091a9c6685..ad59939db3b 100644

target/openrisc/sys_helper.c void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) · line 51

Quoted 8 lines
target/openrisc/sys_helper.c +1 -1
@@ -45,7 +45,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)
      OpenRISCCPU *cpu = env_archcpu(env);
  #ifndef CONFIG_USER_ONLY
      CPUState *cs = env_cpu(env);
-    target_ulong mr;
+    uint32_t mr;
      int idx;
  #endif
 

r~

#10 lore raw

PATCH v2 5/10 target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers

In reply to Philippe Mathieu-Daudé

Commit 23d45ebdb19 ("target/openrisc: Remove indirect function calls for mmu") removed the last uses of both cpu_openrisc_map_address_code() and cpu_openrisc_map_address_data() helpers.

---
 target/openrisc/cpu.h | 9 ---------
 1 file changed, 9 deletions(-)
target/openrisc/cpu.h +0 -9
index f4bcf00b073..87201365a91 100644
@@ -220,15 +220,6 @@ typedef struct OpenRISCTLBEntry {
 typedef struct CPUOpenRISCTLBContext {
     OpenRISCTLBEntry itlb[TLB_SIZE];
     OpenRISCTLBEntry dtlb[TLB_SIZE];
-
-    int (*cpu_openrisc_map_address_code)(OpenRISCCPU *cpu,
-                                         hwaddr *physical,
-                                         int *prot,
-                                         target_ulong address, int rw);
-    int (*cpu_openrisc_map_address_data)(OpenRISCCPU *cpu,
-                                         hwaddr *physical,
-                                         int *prot,
-                                         target_ulong address, int rw);
 } CPUOpenRISCTLBContext;
 #endif
 
Signature · 1 line
2.51.0
Reviewed-by on v2 5/10
#11 lore raw

Re: [PATCH v2 05/10] target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers

Quoted 21 lines · Philippe Mathieu-Daudé

Commit 23d45ebdb19 ("target/openrisc: Remove indirect function calls for mmu") removed the last uses of both cpu_openrisc_map_address_code() and cpu_openrisc_map_address_data() helpers.

---
  target/openrisc/cpu.h | 9 ---------
  1 file changed, 9 deletions(-)
target/openrisc/cpu.h +0 -2
index f4bcf00b073..87201365a91 100644
@@ -220,15 +220,6 @@ typedef struct OpenRISCTLBEntry {
  typedef struct CPUOpenRISCTLBContext {
      OpenRISCTLBEntry itlb[TLB_SIZE];
      OpenRISCTLBEntry dtlb[TLB_SIZE];
-
-    int (*cpu_openrisc_map_address_code)(OpenRISCCPU *cpu,

target/openrisc/cpu.h typedef struct OpenRISCTLBEntry { · line 225

Quoted 10 lines
target/openrisc/cpu.h +0 -7
-                                         hwaddr *physical,
-                                         int *prot,
-                                         target_ulong address, int rw);
-    int (*cpu_openrisc_map_address_data)(OpenRISCCPU *cpu,
-                                         hwaddr *physical,
-                                         int *prot,
-                                         target_ulong address, int rw);
  } CPUOpenRISCTLBContext;
  #endif
 

Oops, my bad.

r~

#12 lore raw

PATCH v2 6/10 target/openrisc: Remove target_ulong use in raise_mmu_exception()

In reply to Philippe Mathieu-Daudé

TCGCPUOps::tlb_fill() handler provides a vaddr type (since commit 7510454e3e7 "cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook").

---
 target/openrisc/mmu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
target/openrisc/mmu.c +3 -4
index acea50c41eb..6fb3f6318a1 100644
@@ -28,15 +28,14 @@
 #include "qemu/host-utils.h"
 #include "hw/loader.h"
 
-static inline void get_phys_nommu(hwaddr *phys_addr, int *prot,
-                                  target_ulong address)
+static inline void get_phys_nommu(hwaddr *phys_addr, int *prot, vaddr address)
 {
     *phys_addr = address;
     *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
 }
 
 static int get_phys_mmu(OpenRISCCPU *cpu, hwaddr *phys_addr, int *prot,
-                        target_ulong addr, int need, bool super)
+                        vaddr addr, int need, bool super)
 {
     int idx = (addr >> TARGET_PAGE_BITS) & TLB_MASK;
     uint32_t imr = cpu->env.tlb.itlb[idx].mr;
@@ -95,7 +94,7 @@ static int get_phys_mmu(OpenRISCCPU *cpu, hwaddr *phys_addr, int *prot,
     }
 }
 
-static void raise_mmu_exception(OpenRISCCPU *cpu, target_ulong address,
+static void raise_mmu_exception(OpenRISCCPU *cpu, vaddr address,
                                 int exception)
 {
     CPUState *cs = CPU(cpu);
Signature · 1 line
2.51.0
Reviewed-by on v2 6/10
#13 lore raw

Re: [PATCH v2 06/10] target/openrisc: Remove target_ulong use in raise_mmu_exception()

Quoted 8 lines · Philippe Mathieu-Daudé

TCGCPUOps::tlb_fill() handler provides a vaddr type (since commit 7510454e3e7 "cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook").

---
  target/openrisc/mmu.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)

r~

#14 lore raw

PATCH v2 7/10 target/openrisc: Use vaddr type for $pc jumps

In reply to Philippe Mathieu-Daudé

translator_use_goto_tb() expects a vaddr type since commit b1c09220b4c ("accel/tcg: Replace target_ulong with vaddr in translator_*()").

---
 target/openrisc/translate.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
target/openrisc/translate.c +6 -6
index 4ece2547614..06625367ae4 100644
@@ -51,7 +51,7 @@ typedef struct DisasContext {
     uint32_t avr;
 
     /* If not -1, jmp_pc contains this value and so is a direct jump.  */
-    target_ulong jmp_pc_imm;
+    vaddr jmp_pc_imm;
 
     /* The temporary corresponding to register 0 for this compilation.  */
     TCGv R0;
@@ -580,7 +580,7 @@ static bool trans_l_muldu(DisasContext *dc, arg_ab *a)
 
 static bool trans_l_j(DisasContext *dc, arg_l_j *a)
 {
-    target_ulong tmp_pc = dc->base.pc_next + a->n * 4;
+    vaddr tmp_pc = dc->base.pc_next + a->n * 4;
 
     tcg_gen_movi_tl(jmp_pc, tmp_pc);
     dc->jmp_pc_imm = tmp_pc;
@@ -590,8 +590,8 @@ static bool trans_l_j(DisasContext *dc, arg_l_j *a)
 
 static bool trans_l_jal(DisasContext *dc, arg_l_jal *a)
 {
-    target_ulong tmp_pc = dc->base.pc_next + a->n * 4;
-    target_ulong ret_pc = dc->base.pc_next + 8;
+    vaddr tmp_pc = dc->base.pc_next + a->n * 4;
+    vaddr ret_pc = dc->base.pc_next + 8;
 
     tcg_gen_movi_tl(cpu_regs[9], ret_pc);
     /* Optimize jal being used to load the PC for PIC.  */
@@ -605,7 +605,7 @@ static bool trans_l_jal(DisasContext *dc, arg_l_jal *a)
 
 static void do_bf(DisasContext *dc, arg_l_bf *a, TCGCond cond)
 {
-    target_ulong tmp_pc = dc->base.pc_next + a->n * 4;
+    vaddr tmp_pc = dc->base.pc_next + a->n * 4;
     TCGv t_next = tcg_constant_tl(dc->base.pc_next + 8);
     TCGv t_true = tcg_constant_tl(tmp_pc);
 
@@ -1586,7 +1586,7 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
 static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
 {
     DisasContext *dc = container_of(dcbase, DisasContext, base);
-    target_ulong jmp_dest;
+    vaddr jmp_dest;
 
     /* If we have already exited the TB, nothing following has effect.  */
     if (dc->base.is_jmp == DISAS_NORETURN) {
Signature · 1 line
2.51.0
Reviewed-by on v2 7/10
#15 lore raw

Re: [PATCH v2 07/10] target/openrisc: Use vaddr type for $pc jumps

Quoted 9 lines · Philippe Mathieu-Daudé

translator_use_goto_tb() expects a vaddr type since commit b1c09220b4c ("accel/tcg: Replace target_ulong with vaddr in translator_*()").

---
  target/openrisc/translate.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

r~

#16 lore raw

PATCH v2 8/10 target/openrisc: Remove 'TARGET_LONG_BITS != 32' dead code

In reply to Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit:

  $ git grep TARGET_LONG_BITS configs/targets/or1k-*
  configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
  configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32

Remove the dead code guarded within TARGET_LONG_BITS != 32.

---
 target/openrisc/translate.c | 33 ++++-----------------------------
 1 file changed, 4 insertions(+), 29 deletions(-)
target/openrisc/translate.c +4 -29
index 06625367ae4..dd93cfd6074 100644
@@ -298,19 +298,8 @@ static void gen_muld(DisasContext *dc, TCGv srca, TCGv srcb)
 
     tcg_gen_ext_tl_i64(t1, srca);
     tcg_gen_ext_tl_i64(t2, srcb);
-    if (TARGET_LONG_BITS == 32) {
-        tcg_gen_mul_i64(cpu_mac, t1, t2);
-        tcg_gen_movi_tl(cpu_sr_ov, 0);
-    } else {
-        TCGv_i64 high = tcg_temp_new_i64();
-
-        tcg_gen_muls2_i64(cpu_mac, high, t1, t2);
-        tcg_gen_sari_i64(t1, cpu_mac, 63);
-        tcg_gen_negsetcond_i64(TCG_COND_NE, t1, t1, high);
-        tcg_gen_trunc_i64_tl(cpu_sr_ov, t1);
-
-        gen_ove_ov(dc);
-    }
+    tcg_gen_mul_i64(cpu_mac, t1, t2);
+    tcg_gen_movi_tl(cpu_sr_ov, 0);
 }
 
 static void gen_muldu(DisasContext *dc, TCGv srca, TCGv srcb)
@@ -320,18 +309,8 @@ static void gen_muldu(DisasContext *dc, TCGv srca, TCGv srcb)
 
     tcg_gen_extu_tl_i64(t1, srca);
     tcg_gen_extu_tl_i64(t2, srcb);
-    if (TARGET_LONG_BITS == 32) {
-        tcg_gen_mul_i64(cpu_mac, t1, t2);
-        tcg_gen_movi_tl(cpu_sr_cy, 0);
-    } else {
-        TCGv_i64 high = tcg_temp_new_i64();
-
-        tcg_gen_mulu2_i64(cpu_mac, high, t1, t2);
-        tcg_gen_setcondi_i64(TCG_COND_NE, high, high, 0);
-        tcg_gen_trunc_i64_tl(cpu_sr_cy, high);
-
-        gen_ove_cy(dc);
-    }
+    tcg_gen_mul_i64(cpu_mac, t1, t2);
+    tcg_gen_movi_tl(cpu_sr_cy, 0);
 }
 
 static void gen_mac(DisasContext *dc, TCGv srca, TCGv srcb)
@@ -349,11 +328,7 @@ static void gen_mac(DisasContext *dc, TCGv srca, TCGv srcb)
     tcg_gen_xor_i64(t1, t1, cpu_mac);
     tcg_gen_andc_i64(t1, t1, t2);
 
-#if TARGET_LONG_BITS == 32
     tcg_gen_extrh_i64_i32(cpu_sr_ov, t1);
-#else
-    tcg_gen_mov_i64(cpu_sr_ov, t1);
-#endif
 
     gen_ove_ov(dc);
 }
Signature · 1 line
2.51.0
Reviewed-by on v2 8/10
#17 lore raw

Re: [PATCH v2 08/10] target/openrisc: Remove 'TARGET_LONG_BITS != 32' dead code

Quoted 6 lines · Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit:

   $ git grep TARGET_LONG_BITS configs/targets/or1k-*
   configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
   configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32
Quoted 6 lines

Remove the dead code guarded within TARGET_LONG_BITS != 32.

---
  target/openrisc/translate.c | 33 ++++-----------------------------
  1 file changed, 4 insertions(+), 29 deletions(-)

r~

#18 lore raw

PATCH v2 9/10 target/openrisc: Inline tcg_gen_trunc_i64_tl()

In reply to Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit, so tcg_gen_trunc_i64_tl expands to tcg_gen_extrl_i64_i32(). Use the latter to simplify the next commit mechanical change.

---
 target/openrisc/translate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/openrisc/translate.c +3 -3
index dd93cfd6074..7cb4152e357 100644
@@ -345,7 +345,7 @@ static void gen_macu(DisasContext *dc, TCGv srca, TCGv srcb)
     /* Note that overflow is only computed during addition stage.  */
     tcg_gen_add_i64(cpu_mac, cpu_mac, t1);
     tcg_gen_setcond_i64(TCG_COND_LTU, t1, cpu_mac, t1);
-    tcg_gen_trunc_i64_tl(cpu_sr_cy, t1);
+    tcg_gen_extrl_i64_i32(cpu_sr_cy, t1);
 
     gen_ove_cy(dc);
 }
@@ -386,7 +386,7 @@ static void gen_msbu(DisasContext *dc, TCGv srca, TCGv srcb)
     /* Note that overflow is only computed during subtraction stage.  */
     tcg_gen_setcond_i64(TCG_COND_LTU, t2, cpu_mac, t1);
     tcg_gen_sub_i64(cpu_mac, cpu_mac, t1);
-    tcg_gen_trunc_i64_tl(cpu_sr_cy, t2);
+    tcg_gen_extrl_i64_i32(cpu_sr_cy, t2);
 
     gen_ove_cy(dc);
 }
@@ -904,7 +904,7 @@ static bool trans_l_movhi(DisasContext *dc, arg_l_movhi *a)
 static bool trans_l_macrc(DisasContext *dc, arg_l_macrc *a)
 {
     check_r0_write(dc, a->d);
-    tcg_gen_trunc_i64_tl(cpu_R(dc, a->d), cpu_mac);
+    tcg_gen_extrl_i64_i32(cpu_R(dc, a->d), cpu_mac);
     tcg_gen_movi_i64(cpu_mac, 0);
     return true;
 }
Signature · 1 line
2.51.0
Reviewed-by on v2 9/10
#19 lore raw

Re: [PATCH v2 09/10] target/openrisc: Inline tcg_gen_trunc_i64_tl()

Quoted 9 lines · Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit, so tcg_gen_trunc_i64_tl expands to tcg_gen_extrl_i64_i32(). Use the latter to simplify the next commit mechanical change.

---
  target/openrisc/translate.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

r~

#20 lore raw

PATCH v2 10/10 target/openrisc: Replace target_ulong -> uint32_t

In reply to Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit:

  $ git grep TARGET_LONG_BITS configs/targets/or1k-*
  configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
  configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32

Therefore target_ulong always expands to uint32_t. Replace and adapt the API uses mechanically:

target_ulong -> uint32_t
target_long -> int32_t
tl -> i32
TCGv -> TCGv_i32
tcg_temp_new -> tcg_temp_new_i32
tcg_global_mem_new -> tcg_global_mem_new_i32
VMSTATE_UINTTL -> VMSTATE_UINT32

There is no functional change (the migration stream is not modified).

---
 target/openrisc/cpu.h        |  22 +-
 target/openrisc/helper.h     |   8 +-
 target/openrisc/fpu_helper.c |   8 +-
 target/openrisc/machine.c    |  16 +-
 target/openrisc/sys_helper.c |   5 +-
 target/openrisc/translate.c  | 382 +++++++++++++++++------------------
 6 files changed, 220 insertions(+), 221 deletions(-)
target/openrisc/cpu.h +11 -11
index 87201365a91..c8e2827930b 100644
@@ -224,20 +224,20 @@ typedef struct CPUOpenRISCTLBContext {
 #endif
 
 typedef struct CPUArchState {
-    target_ulong shadow_gpr[16][32]; /* Shadow registers */
+    uint32_t shadow_gpr[16][32]; /* Shadow registers */
 
-    target_ulong pc;          /* Program counter */
-    target_ulong ppc;         /* Prev PC */
-    target_ulong jmp_pc;      /* Jump PC */
+    uint32_t pc;              /* Program counter */
+    uint32_t ppc;             /* Prev PC */
+    uint32_t jmp_pc;          /* Jump PC */
 
     uint64_t mac;             /* Multiply registers MACHI:MACLO */
 
-    target_ulong epcr;        /* Exception PC register */
-    target_ulong eear;        /* Exception EA register */
+    uint32_t epcr;            /* Exception PC register */
+    uint32_t eear;            /* Exception EA register */
 
-    target_ulong sr_f;        /* the SR_F bit, values 0, 1.  */
-    target_ulong sr_cy;       /* the SR_CY bit, values 0, 1.  */
-    target_long  sr_ov;       /* the SR_OV bit (in the sign bit only) */
+    uint32_t sr_f;            /* the SR_F bit, values 0, 1.  */
+    uint32_t sr_cy;           /* the SR_CY bit, values 0, 1.  */
+    int32_t  sr_ov;           /* the SR_OV bit (in the sign bit only) */
     uint32_t sr;              /* Supervisor register, without SR_{F,CY,OV} */
     uint32_t esr;             /* Exception supervisor register */
     uint32_t evbar;           /* Exception vector base address register */
@@ -245,8 +245,8 @@ typedef struct CPUArchState {
     uint32_t fpcsr;           /* Float register */
     float_status fp_status;
 
-    target_ulong lock_addr;
-    target_ulong lock_value;
+    uint32_t lock_addr;
+    uint32_t lock_value;
 
     uint32_t dflag;           /* In delay slot (boolean) */
 
target/openrisc/helper.h +4 -4
index d847814a28d..e0a8d402271 100644
@@ -47,8 +47,8 @@ FOP_CALC(rem)
 #undef FOP_CALC
 
 #define FOP_CMP(op)                                              \
-DEF_HELPER_FLAGS_3(float_ ## op ## _s, TCG_CALL_NO_RWG, tl, env, i32, i32) \
-DEF_HELPER_FLAGS_3(float_ ## op ## _d, TCG_CALL_NO_RWG, tl, env, i64, i64)
+DEF_HELPER_FLAGS_3(float_ ## op ## _s, TCG_CALL_NO_RWG, i32, env, i32, i32) \
+DEF_HELPER_FLAGS_3(float_ ## op ## _d, TCG_CALL_NO_RWG, i32, env, i64, i64)
 FOP_CMP(eq)
 FOP_CMP(lt)
 FOP_CMP(le)
@@ -62,5 +62,5 @@ FOP_CMP(ult)
 DEF_HELPER_FLAGS_1(rfe, 0, void, env)
 
 /* sys */
-DEF_HELPER_FLAGS_3(mtspr, 0, void, env, tl, tl)
-DEF_HELPER_FLAGS_3(mfspr, TCG_CALL_NO_WG, tl, env, tl, tl)
+DEF_HELPER_FLAGS_3(mtspr, 0, void, env, i32, i32)
+DEF_HELPER_FLAGS_3(mfspr, TCG_CALL_NO_WG, i32, env, i32, i32)
target/openrisc/fpu_helper.c +4 -4
index dba997255c6..39b6195dd7d 100644
@@ -146,10 +146,10 @@ uint32_t helper_float_madd_s(CPUOpenRISCState *env, uint32_t a,
 
 
 #define FLOAT_CMP(name, impl)                                             \
-target_ulong helper_float_ ## name ## _d(CPUOpenRISCState *env,           \
+uint32_t helper_float_ ## name ## _d(CPUOpenRISCState *env,               \
                                          uint64_t fdt0, uint64_t fdt1)    \
 { return float64_ ## impl(fdt0, fdt1, &env->fp_status); }                 \
-target_ulong helper_float_ ## name ## _s(CPUOpenRISCState *env,           \
+uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env,               \
                                          uint32_t fdt0, uint32_t fdt1)    \
 { return float32_ ## impl(fdt0, fdt1, &env->fp_status); }
 
@@ -160,13 +160,13 @@ FLOAT_CMP(un, unordered_quiet)
 #undef FLOAT_CMP
 
 #define FLOAT_UCMP(name, expr) \
-target_ulong helper_float_ ## name ## _d(CPUOpenRISCState *env,           \
+uint32_t helper_float_ ## name ## _d(CPUOpenRISCState *env,               \
                                          uint64_t fdt0, uint64_t fdt1)    \
 {                                                                         \
     FloatRelation r = float64_compare_quiet(fdt0, fdt1, &env->fp_status); \
     return expr;                                                          \
 }                                                                         \
-target_ulong helper_float_ ## name ## _s(CPUOpenRISCState *env,           \
+uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env,               \
                                          uint32_t fdt0, uint32_t fdt1)    \
 {                                                                         \
     FloatRelation r = float32_compare_quiet(fdt0, fdt1, &env->fp_status); \
target/openrisc/machine.c +8 -8
index fa054e528bd..f2853674f0f 100644
@@ -72,14 +72,14 @@ static const VMStateDescription vmstate_env = {
     .version_id = 6,
     .minimum_version_id = 6,
     .fields = (const VMStateField[]) {
-        VMSTATE_UINTTL_2DARRAY(shadow_gpr, CPUOpenRISCState, 16, 32),
-        VMSTATE_UINTTL(pc, CPUOpenRISCState),
-        VMSTATE_UINTTL(ppc, CPUOpenRISCState),
-        VMSTATE_UINTTL(jmp_pc, CPUOpenRISCState),
-        VMSTATE_UINTTL(lock_addr, CPUOpenRISCState),
-        VMSTATE_UINTTL(lock_value, CPUOpenRISCState),
-        VMSTATE_UINTTL(epcr, CPUOpenRISCState),
-        VMSTATE_UINTTL(eear, CPUOpenRISCState),
+        VMSTATE_UINT32_2DARRAY(shadow_gpr, CPUOpenRISCState, 16, 32),
+        VMSTATE_UINT32(pc, CPUOpenRISCState),
+        VMSTATE_UINT32(ppc, CPUOpenRISCState),
+        VMSTATE_UINT32(jmp_pc, CPUOpenRISCState),
+        VMSTATE_UINT32(lock_addr, CPUOpenRISCState),
+        VMSTATE_UINT32(lock_value, CPUOpenRISCState),
+        VMSTATE_UINT32(epcr, CPUOpenRISCState),
+        VMSTATE_UINT32(eear, CPUOpenRISCState),
 
         /* Save the architecture value of the SR, not the internally
            expanded version.  Since this architecture value does not
target/openrisc/sys_helper.c +2 -3
index ad59939db3b..7ad908b6322 100644
@@ -40,7 +40,7 @@ static inline bool is_user(CPUOpenRISCState *env)
 #endif
 }
 
-void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)
+void HELPER(mtspr)(CPUOpenRISCState *env, uint32_t spr, uint32_t rb)
 {
     OpenRISCCPU *cpu = env_archcpu(env);
 #ifndef CONFIG_USER_ONLY
@@ -213,8 +213,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb)
 #endif
 }
 
-target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd,
-                           target_ulong spr)
+uint32_t HELPER(mfspr)(CPUOpenRISCState *env, uint32_t rd, uint32_t spr)
 {
     OpenRISCCPU *cpu = env_archcpu(env);
 #ifndef CONFIG_USER_ONLY
target/openrisc/translate.c +191 -191

981 lines not on this page · raw message

Signature · 1 line
2.51.0
Reviewed-by on v2 10/10
#21 lore raw

Re: [PATCH v2 10/10] target/openrisc: Replace target_ulong -> uint32_t

Quoted 21 lines · Philippe Mathieu-Daudé

The OpenRISC targets are only built as 32-bit:

   $ git grep TARGET_LONG_BITS configs/targets/or1k-*
   configs/targets/or1k-linux-user.mak:5:TARGET_LONG_BITS=32
   configs/targets/or1k-softmmu.mak:5:TARGET_LONG_BITS=32

Therefore target_ulong always expands to uint32_t. Replace and adapt the API uses mechanically:

   target_ulong -> uint32_t
   target_long -> int32_t
   tl -> i32
   TCGv -> TCGv_i32
   tcg_temp_new -> tcg_temp_new_i32
   tcg_global_mem_new -> tcg_global_mem_new_i32
   VMSTATE_UINTTL -> VMSTATE_UINT32

There is no functional change (the migration stream is not modified).

Quoted 8 lines
---
  target/openrisc/cpu.h        |  22 +-
  target/openrisc/helper.h     |   8 +-
  target/openrisc/fpu_helper.c |   8 +-
  target/openrisc/machine.c    |  16 +-
  target/openrisc/sys_helper.c |   5 +-
  target/openrisc/translate.c  | 382 +++++++++++++++++------------------
  6 files changed, 220 insertions(+), 221 deletions(-)

r~