Skip to contentSkip to conversation

target/xtensa: group helpers by functionality

PATCH In review Max Filippov 3 participants 17 messages Jan 14, 2019 – May 17, 2021

lore
Share & tools
lore
#0 lore raw

cover target/xtensa: group helpers by functionality

Hello,

this series moves helper functions for FPU, windowed registers, MMU, native debug, interrupt and exception handling from op_helper.c and helper.c to separate *_helper.c files.
There's no functional changes.

Max Filippov (7):
target/xtensa: extract FPU helpers target/xtensa: extract windowed registers helpers target/xtensa: extract MMU helpers target/xtensa: extract debug helpers target/xtensa: extract interrupt and exception helpers target/xtensa: drop dump_state helper target/xtensa: move non-HELPER functions to helper.c

 target/xtensa/Makefile.objs |   5 +
 target/xtensa/dbg_helper.c  | 129 +++++++
 target/xtensa/exc_helper.c  | 258 +++++++++++++
 target/xtensa/fpu_helper.c  | 166 +++++++++
 target/xtensa/helper.c      | 635 ++------------------------------
 target/xtensa/helper.h      |   1 -
 target/xtensa/mmu_helper.c  | 818 +++++++++++++++++++++++++++++++++++++++++
 target/xtensa/op_helper.c   | 870 --------------------------------------------
 target/xtensa/win_helper.c  | 222 +++++++++++
 9 files changed, 1636 insertions(+), 1468 deletions(-)
 create mode 100644 target/xtensa/dbg_helper.c
 create mode 100644 target/xtensa/exc_helper.c
 create mode 100644 target/xtensa/fpu_helper.c
 create mode 100644 target/xtensa/mmu_helper.c
 create mode 100644 target/xtensa/win_helper.c
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/7 target/xtensa: extract FPU helpers

Move FPU-related HELPER functions from op_helper.c to fpu_helper.c No functional changes.

---
 target/xtensa/Makefile.objs |   1 +
 target/xtensa/fpu_helper.c  | 166 ++++++++++++++++++++++++++++++++++++++++++++
 target/xtensa/op_helper.c   | 135 -----------------------------------
 3 files changed, 167 insertions(+), 135 deletions(-)
 create mode 100644 target/xtensa/fpu_helper.c
target/xtensa/Makefile.objs +1 -0
index f63352cc04db..1508714c4475 100644
@@ -7,4 +7,5 @@ obj-y += core-test_kc705_be.o
 obj-$(CONFIG_SOFTMMU) += monitor.o xtensa-semi.o
 obj-y += xtensa-isa.o
 obj-y += translate.o op_helper.o helper.o cpu.o
+obj-y += fpu_helper.o
 obj-y += gdbstub.o
target/xtensa/fpu_helper.c new file +166 -0

166 lines not on this page · raw message

target/xtensa/op_helper.c +0 -135

147 lines not on this page · raw message

Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/7 target/xtensa: extract windowed registers helpers

In reply to Max Filippov

Move helper functions related to register windows from op_helper.c to win_helper.c. No functional changes.

---
 target/xtensa/Makefile.objs |   1 +
 target/xtensa/op_helper.c   | 190 -------------------------------------
 target/xtensa/win_helper.c  | 222 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 223 insertions(+), 190 deletions(-)
 create mode 100644 target/xtensa/win_helper.c
target/xtensa/Makefile.objs +1 -0
index 1508714c4475..cc550c2ccb51 100644
@@ -9,3 +9,4 @@ obj-y += xtensa-isa.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += fpu_helper.o
 obj-y += gdbstub.o
+obj-y += win_helper.o
target/xtensa/op_helper.c +0 -190

196 lines not on this page · raw message

target/xtensa/win_helper.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.11.0
#3 lore raw

PATCH 3/7 target/xtensa: extract MMU helpers

In reply to Max Filippov

Move MMU-related helper functions from op_helper.c and helper.c to mmu_helper.c. No functional changes.

---
 target/xtensa/Makefile.objs |   1 +
 target/xtensa/helper.c      | 487 --------------------------
 target/xtensa/mmu_helper.c  | 818 ++++++++++++++++++++++++++++++++++++++++++++
 target/xtensa/op_helper.c   | 293 ----------------
 4 files changed, 819 insertions(+), 780 deletions(-)
 create mode 100644 target/xtensa/mmu_helper.c
target/xtensa/Makefile.objs +1 -0
index cc550c2ccb51..b2c720b2df9b 100644
@@ -9,4 +9,5 @@ obj-y += xtensa-isa.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-y += fpu_helper.o
 obj-y += gdbstub.o
+obj-$(CONFIG_SOFTMMU) += mmu_helper.o
 obj-y += win_helper.o
target/xtensa/helper.c +0 -487

505 lines not on this page · raw message

target/xtensa/mmu_helper.c new file +818 -0

818 lines not on this page · raw message

target/xtensa/op_helper.c +0 -293

305 lines not on this page · raw message

Signature · 1 line
2.11.0
#4 lore raw

PATCH 4/7 target/xtensa: extract debug helpers

In reply to Max Filippov

Move HELPER functions related to native debugging from op_helper.c to dbg_helper.c. No functional changes.

---
 target/xtensa/Makefile.objs |   1 +
 target/xtensa/dbg_helper.c  | 129 ++++++++++++++++++++++++++++++++++++++++++++
 target/xtensa/op_helper.c   |  92 -------------------------------
 3 files changed, 130 insertions(+), 92 deletions(-)
 create mode 100644 target/xtensa/dbg_helper.c
target/xtensa/Makefile.objs +1 -0
index b2c720b2df9b..cfd33ba1d951 100644
@@ -7,6 +7,7 @@ obj-y += core-test_kc705_be.o
 obj-$(CONFIG_SOFTMMU) += monitor.o xtensa-semi.o
 obj-y += xtensa-isa.o
 obj-y += translate.o op_helper.o helper.o cpu.o
+obj-$(CONFIG_SOFTMMU) += dbg_helper.o
 obj-y += fpu_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += mmu_helper.o
target/xtensa/dbg_helper.c new file +129 -0

129 lines not on this page · raw message

target/xtensa/op_helper.c +0 -92

104 lines not on this page · raw message

Signature · 1 line
2.11.0
#5 lore raw

PATCH 5/7 target/xtensa: extract interrupt and exception helpers

In reply to Max Filippov

Move helper functions related to interrupt and exception handling from op_helper.c and helper.c to exc_helper.c. No functional changes.

---
 target/xtensa/Makefile.objs |   1 +
 target/xtensa/exc_helper.c  | 258 ++++++++++++++++++++++++++++++++++++++++++++
 target/xtensa/helper.c      | 127 ----------------------
 target/xtensa/op_helper.c   |  93 ----------------
 4 files changed, 259 insertions(+), 220 deletions(-)
 create mode 100644 target/xtensa/exc_helper.c
target/xtensa/Makefile.objs +1 -0
index cfd33ba1d951..808f7e3fceb8 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_SOFTMMU) += monitor.o xtensa-semi.o
 obj-y += xtensa-isa.o
 obj-y += translate.o op_helper.o helper.o cpu.o
 obj-$(CONFIG_SOFTMMU) += dbg_helper.o
+obj-y += exc_helper.o
 obj-y += fpu_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += mmu_helper.o
target/xtensa/exc_helper.c new file +258 -0

258 lines not on this page · raw message

target/xtensa/helper.c +0 -127

133 lines not on this page · raw message

target/xtensa/op_helper.c +0 -93

111 lines not on this page · raw message

Signature · 1 line
2.11.0
#6 lore raw

PATCH 6/7 target/xtensa: drop dump_state helper

In reply to Max Filippov

Drop unused helper dump_state from op_helper.c

---
 target/xtensa/helper.h    |  1 -
 target/xtensa/op_helper.c | 11 -----------
 2 files changed, 12 deletions(-)
target/xtensa/helper.h +0 -1
index 2ebba0b2c2bf..89eb97e26514 100644
@@ -15,7 +15,6 @@ DEF_HELPER_2(movsp, void, env, i32)
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_1(simcall, void, env)
 #endif
-DEF_HELPER_1(dump_state, void, env)
 
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_3(waiti, void, env, i32, i32)
target/xtensa/op_helper.c +0 -11
index d3e61e22fe82..b0ef828f9ae5 100644
@@ -93,17 +93,6 @@ void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
                                   addr);
 }
 
-#endif
-
-void HELPER(dump_state)(CPUXtensaState *env)
-{
-    XtensaCPU *cpu = xtensa_env_get_cpu(env);
-
-    cpu_dump_state(CPU(cpu), stderr, fprintf, 0);
-}
-
-#ifndef CONFIG_USER_ONLY
-
 void HELPER(update_ccount)(CPUXtensaState *env)
 {
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
Signature · 1 line
2.11.0
#7 lore raw

PATCH 7/7 target/xtensa: move non-HELPER functions to helper.c

In reply to Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
target/xtensa/helper.c +58 -3
index 2f1dec5c63e9..323c47a7fb54 100644
@@ -29,10 +29,8 @@
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "exec/gdbstub.h"
+#include "exec/helper-proto.h"
 #include "qemu/host-utils.h"
-#if !defined(CONFIG_USER_ONLY)
-#include "hw/loader.h"
-#endif
 
 static struct XtensaConfigList *xtensa_cores;
 
@@ -188,6 +186,63 @@ int xtensa_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw,
 
 #else
 
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
+        cpu_restore_state(CPU(cpu), retaddr, true);
+        HELPER(exception_cause_vaddr)(env,
+                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
+                                      addr);
+    }
+}
+
+void tlb_fill(CPUState *cs, target_ulong vaddr, int size,
+              MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+    uint32_t paddr;
+    uint32_t page_size;
+    unsigned access;
+    int ret = xtensa_get_physical_addr(env, true, vaddr, access_type, mmu_idx,
+                                       &paddr, &page_size, &access);
+
+    qemu_log_mask(CPU_LOG_MMU, "%s(%08x, %d, %d) -> %08x, ret = %d\n",
+                  __func__, vaddr, access_type, mmu_idx, paddr, ret);
+
+    if (ret == 0) {
+        tlb_set_page(cs,
+                     vaddr & TARGET_PAGE_MASK,
+                     paddr & TARGET_PAGE_MASK,
+                     access, mmu_idx, page_size);
+    } else {
+        cpu_restore_state(cs, retaddr, true);
+        HELPER(exception_cause_vaddr)(env, env->pc, ret, vaddr);
+    }
+}
+
+void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
+                                      unsigned size, MMUAccessType access_type,
+                                      int mmu_idx, MemTxAttrs attrs,
+                                      MemTxResult response, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    cpu_restore_state(cs, retaddr, true);
+    HELPER(exception_cause_vaddr)(env, env->pc,
+                                  access_type == MMU_INST_FETCH ?
+                                  INSTR_PIF_ADDR_ERROR_CAUSE :
+                                  LOAD_STORE_PIF_ADDR_ERROR_CAUSE,
+                                  addr);
+}
+
 void xtensa_runstall(CPUXtensaState *env, bool runstall)
 {
     CPUState *cpu = CPU(xtensa_env_get_cpu(env));
target/xtensa/op_helper.c +0 -56

62 lines not on this page · raw message

Signature · 1 line
2.11.0
#8 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Hi Max,

Quoted 10 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)

target/xtensa/helper.c int xtensa_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, · line 197

Quoted 9 lines
target/xtensa/helper.c +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 6 lines
target/xtensa/helper.c +6 -0
+        cpu_restore_state(CPU(cpu), retaddr, true);
+        HELPER(exception_cause_vaddr)(env,
+                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
+                                      addr);
+    }
+}
#9 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

target/xtensa/helper.c int xtensa_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, · line 197

Quoted 9 lines
target/xtensa/helper.c +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Signature · 2 lines
Thanks.
-- Max
#10 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

target/xtensa/helper.c int xtensa_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw, · line 197

Quoted 9 lines
target/xtensa/helper.c +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

Signature · 2 lines
Thanks.
-- Max
#11 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 40 lines · Max Filippov
Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,

- env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
- addr);
- }
+ assert(xtensa_option_enabled(env->config,
+ XTENSA_OPTION_UNALIGNED_EXCEPTION));
+ assert(!xtensa_option_enabled(env->config,
XTENSA_OPTION_HW_ALIGNMENT));
+
+ cpu_restore_state(CPU(cpu), retaddr, true);
+ HELPER(exception_cause_vaddr)(env,
+ env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
+ addr);
}
---

?

Thanks for the quick response btw :)

Phil.

#12 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Max Filippov
Quoted 38 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 6 lines
Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

I meant 'IIUC' (if I understand correctly)...

Quoted 35 lines

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

target/xtensa/helper.c +3 -6
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));
+    assert(!xtensa_option_enabled(env->config,

XTENSA_OPTION_HW_ALIGNMENT));

target/xtensa/helper.c +5 -1
+
+    cpu_restore_state(CPU(cpu), retaddr, true);
+    HELPER(exception_cause_vaddr)(env,
+                                  env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
+                                  addr);
 }
---

?

Thanks for the quick response btw :)

Phil.

#13 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

In reply to Philippe Mathieu-Daudé
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Max Filippov
Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

target/xtensa/helper.c

Quoted 8 lines
target/xtensa/helper.c +2 -6
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));

This part -- yes.

Quoted 2 lines

+ assert(!xtensa_option_enabled(env->config,
XTENSA_OPTION_HW_ALIGNMENT));

This part -- no, because the call to the TCGCPUOps::do_unaligned_access is unconditional and would happen on CPUs that have XTENSA_OPTION_HW_ALIGNMENT enabled. They could have a different CPUClass::tcg_ops, but I'm not sure it's worth it.

Signature · 2 lines
Thanks.
-- Max
#14 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 73 lines · Max Filippov
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Max Filippov
Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

target/xtensa/helper.c

Quoted 8 lines
target/xtensa/helper.c +2 -6
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));

This part -- yes.

Quoted 5 lines
Quoted 2 lines

+ assert(!xtensa_option_enabled(env->config,
XTENSA_OPTION_HW_ALIGNMENT));

This part -- no, because the call to the TCGCPUOps::do_unaligned_access is unconditional

Oh, I've checked get_alignment_bits and now I see that it's conditional. This change can be done then, but the translation part also needs to be changed to put MO_UNALN on cores with XTENSA_OPTION_HW_ALIGNMENT.

Signature · 2 lines
Thanks.
-- Max
#15 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 77 lines · Max Filippov
Quoted 76 lines · Max Filippov
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Max Filippov
Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

target/xtensa/helper.c

Quoted 8 lines
target/xtensa/helper.c +2 -6
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));

This part -- yes.

Quoted 2 lines

+ assert(!xtensa_option_enabled(env->config,
XTENSA_OPTION_HW_ALIGNMENT));

Quoted 6 lines
Quoted 2 lines

This part -- no, because the call to the TCGCPUOps::do_unaligned_access is unconditional

Oh, I've checked get_alignment_bits and now I see that it's conditional. This change can be done then, but the translation part also needs to be changed to put MO_UNALN on cores with XTENSA_OPTION_HW_ALIGNMENT.

If you don't mind writing the patch, I'd prefer you do it because you have a better understanding and will likely get it right, otherwise I'll add it to my TODO and come back to it when other of my in-flight series get merged :)

Regards,

Phil.

#16 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/xtensa: move non-HELPER functions to helper.c

Quoted 82 lines · Philippe Mathieu-Daudé
Quoted 80 lines · Max Filippov
Quoted 78 lines · Max Filippov
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 40 lines · Max Filippov
Quoted 34 lines · Max Filippov

Hi Philippe,

Quoted 14 lines · Philippe Mathieu-Daudé

Hi Max,

Quoted 9 lines · Max Filippov

Move remaining non-HELPER functions from op_helper.c to helper.c. No functional changes.

---
 target/xtensa/helper.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++---
 target/xtensa/op_helper.c | 56 -------------------------------------------
 2 files changed, 58 insertions(+), 59 deletions(-)
Quoted 14 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+void xtensa_cpu_do_unaligned_access(CPUState *cs,
+                                    vaddr addr, MMUAccessType access_type,
+                                    int mmu_idx, uintptr_t retaddr)
+{
+    XtensaCPU *cpu = XTENSA_CPU(cs);
+    CPUXtensaState *env = &cpu->env;
+
+    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
+        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {

I know this is a simple code movement, but I wonder, what should happen when there is
an unaligned fault and the options are disabled? Is this an impossible case (unreachable)?

Quoted 4 lines

It should be unreachable when XTENSA_OPTION_UNALIGNED_EXCEPTION is disabled. In that case the translation code generates access on aligned addresses according to the xtensa ISA, see the function gen_load_store_alignment in target/xtensa/translate.c

Quoted 4 lines

There's also a case when both options are enabled, i.e. the xtensa core has support for transparent unaligned access. In that case the helper does nothing and the generic TCG code is supposed to deal with the unaligned access correctly,

IIRC we can simplify as:

-- >8 --

target/xtensa/helper.c +0 -1
index eeffee297d1..6e8a6cdc99e 100644
@@ -270,13 +270,14 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config,

XTENSA_OPTION_UNALIGNED_EXCEPTION) &&

target/xtensa/helper.c

Quoted 8 lines
target/xtensa/helper.c +2 -6
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));

This part -- yes.

Quoted 2 lines

+ assert(!xtensa_option_enabled(env->config,
XTENSA_OPTION_HW_ALIGNMENT));

This part -- no, because the call to the TCGCPUOps::do_unaligned_access is unconditional

Quoted 8 lines
Quoted 3 lines

Oh, I've checked get_alignment_bits and now I see that it's conditional. This change can be done then, but the translation part also needs to be changed to put MO_UNALN on cores with XTENSA_OPTION_HW_ALIGNMENT.

If you don't mind writing the patch, I'd prefer you do it because you have a better understanding and will likely get it right, otherwise I'll add it to my TODO and come back to it when other of my in-flight series get merged :)

Almost done, will send it after some testing.
Thanks for drawing my attention to it (:

Signature · 2 lines
Thanks.
-- Max