Skip to contentSkip to conversation

Fix sreg writes, PC update for system reg TBs

PATCH In review Brian Cain 2 participants 5 messages Jul 16 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

v2 cover Fix sreg writes, PC update for system reg TBs

While preparing l2vic device implementation, I found a couple of bugs that were preventing those tests from working.

v2 adds a new patch: `tests/functional/hexagon: add arch_tests functional
test`, like the one from https://lore.kernel.org/qemu-devel/[email protected]/
but omitting test_int_steering which depends on l2vic.

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

Brian Cain (3):
target/hexagon: initialize deferred sreg-write temps to current value target/hexagon: fix PC not advancing for non-COF TB-ending packets tests/functional/hexagon: add arch_tests functional test

 MAINTAINERS                                 |  1 +
 target/hexagon/translate.h                  |  3 ++
 target/hexagon/genptr.c                     | 14 +++--
 target/hexagon/translate.c                  | 56 +++++++++++++-------
 tests/functional/hexagon/meson.build        |  5 ++
 tests/functional/hexagon/test_arch_tests.py | 57 +++++++++++++++++++++
 tests/functional/meson.build                |  1 +
 7 files changed, 116 insertions(+), 21 deletions(-)
 create mode 100644 tests/functional/hexagon/meson.build
 create mode 100755 tests/functional/hexagon/test_arch_tests.py
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/3 target/hexagon: initialize deferred sreg-write temps to current value

Unconditionally allocate and initialize the temp to the sreg's current value for every logged sreg write, rather than only allocating when need_commit is set or the register is SSR.

Without this, reading a deferred sreg write within the same packet before it is committed can observe an uninitialized temp instead of the register's pre-packet value.

---
 target/hexagon/translate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/hexagon/translate.c +3 -2
index 77235916f4b..28a171bf623 100644
@@ -615,9 +615,10 @@ static void gen_start_packet(DisasContext *ctx)
     }
     for (i = 0; i < ctx->sreg_log_idx; i++) {
         int reg_num = ctx->sreg_log[i];
-        if (reg_num < HEX_SREG_GLB_START &&
-            (ctx->need_commit || reg_num == HEX_SREG_SSR)) {
+        if (reg_num < HEX_SREG_GLB_START) {
             ctx->t_sreg_new_value[reg_num] = tcg_temp_new();
+            tcg_gen_mov_tl(ctx->t_sreg_new_value[reg_num],
+                          hex_t_sreg[reg_num]);
         }
     }
     for (i = 0; i < NUM_GREGS; i++) {
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/3 target/hexagon: fix PC not advancing for non-COF TB-ending packets

In reply to Brian Cain

Add hex_next_PC, a global mirroring CPUHexagonState::next_PC, and ctx->need_next_pc, so that gen_write_new_pc_addr() can write the branch target through hex_next_PC instead of hex_gpr[HEX_REG_PC] when a later unconditional write of PC is expected. gen_end_tb() then commits hex_next_PC into hex_gpr[HEX_REG_PC] at the end of the packet.

Previously, non-COF instructions that still end a TB did not advance the PC, since next_PC's value was never written back into the PC register.

---
 target/hexagon/translate.h |  3 +++
 target/hexagon/genptr.c    | 14 ++++++++---
 target/hexagon/translate.c | 51 ++++++++++++++++++++++++++------------
 3 files changed, 49 insertions(+), 19 deletions(-)
target/hexagon/translate.h +3 -0
index 0a7f37d5842..2fca157553b 100644
@@ -40,6 +40,7 @@ typedef struct DisasContext {
     int reg_log_idx;
     DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS);
     DECLARE_BITMAP(predicated_regs, TOTAL_PER_THREAD_REGS);
+    bool pkt_ends_tb;
     bool implicit_usr_write;
 #ifndef CONFIG_USER_ONLY
     int greg_log[GREG_WRITES_MAX];
@@ -75,6 +76,7 @@ typedef struct DisasContext {
     DECLARE_BITMAP(insn_qregs_read, NUM_QREGS);
     bool pre_commit;
     bool need_commit;
+    bool need_next_pc;
     TCGCond branch_cond;
     target_ulong branch_dest;
     bool is_tight_loop;
@@ -310,6 +312,7 @@ extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
 extern TCGv hex_pred[NUM_PREGS];
 extern TCGv hex_slot_cancelled;
 extern TCGv hex_new_value_usr;
+extern TCGv hex_next_PC;
 extern TCGv hex_store_addr[STORES_MAX];
 extern TCGv_i32 hex_store_width[STORES_MAX];
 extern TCGv hex_store_val32[STORES_MAX];
target/hexagon/genptr.c +11 -3
index 1ebc7471409..dc9ba8a0060 100644
@@ -613,14 +613,22 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr,
         tcg_gen_brcondi_tl(cond, pred, 1, pred_false);
     }
 
+    /*
+     * If gen_end_tb() will unconditionally overwrite PC with hex_next_PC
+     * (because this packet has a predicated COF that may not execute),
+     * write the branch target there instead of directly into the PC
+     * global, or the overwrite in gen_end_tb() would clobber it.
+     */
+    TCGv pc_wr = ctx->need_next_pc ? hex_next_PC : hex_gpr[HEX_REG_PC];
+
     if (ctx->pkt.pkt_has_multi_cof) {
         /* If there are multiple branches in a packet, ignore the second one */
-        tcg_gen_movcond_tl(TCG_COND_NE, hex_gpr[HEX_REG_PC],
+        tcg_gen_movcond_tl(TCG_COND_NE, pc_wr,
                            ctx->branch_taken, tcg_constant_tl(0),
-                           hex_gpr[HEX_REG_PC], addr);
+                           pc_wr, addr);
         tcg_gen_movi_tl(ctx->branch_taken, 1);
     } else {
-        tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], addr);
+        tcg_gen_mov_tl(pc_wr, addr);
     }
 
     if (cond != TCG_COND_ALWAYS) {
target/hexagon/translate.c +35 -16

93 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 3/3 tests/functional/hexagon: add arch_tests functional test

In reply to Brian Cain

Add new test cases from hexagon-arch-tests to exercise exceptions, guest mode.

---
 MAINTAINERS                                 |  1 +
 tests/functional/hexagon/meson.build        |  5 ++
 tests/functional/hexagon/test_arch_tests.py | 57 +++++++++++++++++++++
 tests/functional/meson.build                |  1 +
 4 files changed, 64 insertions(+)
 create mode 100644 tests/functional/hexagon/meson.build
 create mode 100755 tests/functional/hexagon/test_arch_tests.py
MAINTAINERS +1 -0
index 6171cc74940..a87c5ed23d1 100644
@@ -1357,6 +1357,7 @@ F: hw/hexagon/
 F: include/hw/hexagon/
 F: configs/devices/hexagon-softmmu/default.mak
 F: docs/system/hexagon/
+F: tests/functional/hexagon/
 F: docs/devel/hexagon-sys.rst
 
 LoongArch Machines
tests/functional/hexagon/meson.build new file +5 -0
new file mode 100644
index 00000000000..2b5a1a8f264
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+tests_hexagon_system_thorough = [
+  'arch_tests',
+]
tests/functional/hexagon/test_arch_tests.py new file +57 -0

57 lines not on this page · raw message

tests/functional/meson.build +1 -0
index c158197c4b7..c7362dd00ef 100644
@@ -14,6 +14,7 @@ subdir('aarch64')
 subdir('alpha')
 subdir('arm')
 subdir('avr')
+subdir('hexagon')
 subdir('hppa')
 subdir('i386')
 subdir('loongarch64')
Signature · 1 line
2.34.1
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] tests/functional/hexagon: add arch_tests functional test

Quoted 4 lines · Brian Cain

Add new test cases from hexagon-arch-tests to exercise exceptions, guest mode.

Quoted 9 lines
---
 MAINTAINERS                                 |  1 +
 tests/functional/hexagon/meson.build        |  5 ++
 tests/functional/hexagon/test_arch_tests.py | 57 +++++++++++++++++++++
 tests/functional/meson.build                |  1 +
 4 files changed, 64 insertions(+)
 create mode 100644 tests/functional/hexagon/meson.build
 create mode 100755 tests/functional/hexagon/test_arch_tests.py