Skip to contentSkip to conversation

target/hexagon: fix PC not advancing for non-COF TB-ending packets

PATCH In review Brian Cain 2 participants 5 messages Jul 17 – Jul 20

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

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

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
#1 lore raw

PATCH 2/3 target/hexagon: fix ciad assertion

The ciad helper was a stub, so executing a ciad instruction aborted QEMU.

The full ciad behavior also clears the pending interrupt in the l2vic, but the l2vic device is not modelled yet, so log it for now.

---
 target/hexagon/op_helper.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
target/hexagon/op_helper.c +18 -1
index 125952aee59..7f6e561eced 100644
@@ -1557,7 +1557,24 @@ void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
 
 void HELPER(ciad)(CPUHexagonState *env, uint32_t mask)
 {
-    g_assert_not_reached();
+    uint32_t ipendad;
+    uint32_t iad;
+    HexagonCPU *cpu;
+
+    BQL_LOCK_GUARD();
+    cpu = env_archcpu(env);
+    ipendad = hexagon_globalreg_read(cpu->globalregs, HEX_SREG_IPENDAD,
+                                     env->threadId);
+    iad = fGET_FIELD(ipendad, IPENDAD_IAD);
+    fSET_FIELD(ipendad, IPENDAD_IAD, iad & ~mask);
+    hexagon_globalreg_write(cpu->globalregs, HEX_SREG_IPENDAD,
+                            ipendad, env->threadId);
+
+    qemu_log_mask(LOG_UNIMP,
+                  "%s: l2vic clear-interrupt effect not implemented "
+                  "(mask=0x%" PRIx32 ")\n", __func__, mask);
+
+    hex_interrupt_update(env);
 }
 
 void HELPER(siad)(CPUHexagonState *env, uint32_t mask)
Signature · 1 line
2.34.1
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] target/hexagon: fix ciad assertion

Quoted 10 lines · Brian Cain

The ciad helper was a stub, so executing a ciad instruction aborted QEMU.

The full ciad behavior also clears the pending interrupt in the l2vic, but the l2vic device is not modelled yet, so log it for now.

---
 target/hexagon/op_helper.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
author
#3 lore raw

PATCH 3/3 tests/tcg/hexagon: add swi/ciad system-mode test

In reply to Brian Cain

Add a minimal Hexagon system-mode check-tcg test that exercises software-interrupt delivery and the ciad instruction.

Pass/fail is reported via the thread-0 r2 value passed to stop.

---
 tests/tcg/hexagon/Makefile.softmmu-target |  23 ++++
 tests/tcg/hexagon/system/swi_ciad.S       | 148 ++++++++++++++++++++++
 tests/tcg/hexagon/system/system.ld        |  46 +++++++
 3 files changed, 217 insertions(+)
 create mode 100644 tests/tcg/hexagon/Makefile.softmmu-target
 create mode 100644 tests/tcg/hexagon/system/swi_ciad.S
 create mode 100644 tests/tcg/hexagon/system/system.ld
tests/tcg/hexagon/Makefile.softmmu-target new file +23 -0
new file mode 100644
index 00000000000..3c5189edbdb
@@ -0,0 +1,23 @@
+# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Hexagon system tests
+#
+
+HEX_SYS_SRC = $(SRC_PATH)/tests/tcg/hexagon/system
+VPATH += $(HEX_SYS_SRC)
+
+LINK_SCRIPT = $(HEX_SYS_SRC)/system.ld
+
+HEX_SYS_FLAGS = --no-default-config -target hexagon-unknown-none-elf \
+                -mv73 -O0 -g -static -nostdlib \
+                -Wl,--build-id=none -Wl,-T,$(LINK_SCRIPT)
+
+QEMU_OPTS = -M V66G_1024 -kernel
+
+swi_ciad: swi_ciad.S $(LINK_SCRIPT)
+	$(CC) $(HEX_SYS_FLAGS) $< -o $@
+
+HEX_SYS_TESTS = swi_ciad
+
+TESTS += $(HEX_SYS_TESTS)
tests/tcg/hexagon/system/swi_ciad.S new file +148 -0

148 lines not on this page · raw message

tests/tcg/hexagon/system/system.ld new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] tests/tcg/hexagon: add swi/ciad system-mode test

Quoted 6 lines · Brian Cain

Add a minimal Hexagon system-mode check-tcg test that exercises software-interrupt delivery and the ciad instruction.

Pass/fail is reported via the thread-0 r2 value passed to stop.

Quoted 9 lines
---
 tests/tcg/hexagon/Makefile.softmmu-target |  23 ++++
 tests/tcg/hexagon/system/swi_ciad.S       | 148 ++++++++++++++++++++++
 tests/tcg/hexagon/system/system.ld        |  46 +++++++
 3 files changed, 217 insertions(+)
 create mode 100644 tests/tcg/hexagon/Makefile.softmmu-target
 create mode 100644 tests/tcg/hexagon/system/swi_ciad.S
 create mode 100644 tests/tcg/hexagon/system/system.ld