18b453a2bSTaylor Simpson /* 276eaa971STaylor Simpson * Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved. 38b453a2bSTaylor Simpson * 48b453a2bSTaylor Simpson * This program is free software; you can redistribute it and/or modify 58b453a2bSTaylor Simpson * it under the terms of the GNU General Public License as published by 68b453a2bSTaylor Simpson * the Free Software Foundation; either version 2 of the License, or 78b453a2bSTaylor Simpson * (at your option) any later version. 88b453a2bSTaylor Simpson * 98b453a2bSTaylor Simpson * This program is distributed in the hope that it will be useful, 108b453a2bSTaylor Simpson * but WITHOUT ANY WARRANTY; without even the implied warranty of 118b453a2bSTaylor Simpson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128b453a2bSTaylor Simpson * GNU General Public License for more details. 138b453a2bSTaylor Simpson * 148b453a2bSTaylor Simpson * You should have received a copy of the GNU General Public License 158b453a2bSTaylor Simpson * along with this program; if not, see <http://www.gnu.org/licenses/>. 168b453a2bSTaylor Simpson */ 178b453a2bSTaylor Simpson 188b453a2bSTaylor Simpson #ifndef HEXAGON_TRANSLATE_H 198b453a2bSTaylor Simpson #define HEXAGON_TRANSLATE_H 208b453a2bSTaylor Simpson 218b453a2bSTaylor Simpson #include "qemu/bitmap.h" 22cd617484SPhilippe Mathieu-Daudé #include "qemu/log.h" 238b453a2bSTaylor Simpson #include "cpu.h" 248b453a2bSTaylor Simpson #include "exec/translator.h" 258b453a2bSTaylor Simpson #include "tcg/tcg-op.h" 261e536334STaylor Simpson #include "insn.h" 278b453a2bSTaylor Simpson #include "internal.h" 288b453a2bSTaylor Simpson 298b453a2bSTaylor Simpson typedef struct DisasContext { 308b453a2bSTaylor Simpson DisasContextBase base; 311e536334STaylor Simpson Packet *pkt; 321e536334STaylor Simpson Insn *insn; 33613653e5STaylor Simpson uint32_t next_PC; 348b453a2bSTaylor Simpson uint32_t mem_idx; 358b453a2bSTaylor Simpson uint32_t num_packets; 368b453a2bSTaylor Simpson uint32_t num_insns; 37a82dd548STaylor Simpson uint32_t num_hvx_insns; 388b453a2bSTaylor Simpson int reg_log[REG_WRITES_MAX]; 398b453a2bSTaylor Simpson int reg_log_idx; 408b453a2bSTaylor Simpson DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS); 41b9f0326bSTaylor Simpson DECLARE_BITMAP(regs_read, TOTAL_PER_THREAD_REGS); 4210849c26STaylor Simpson DECLARE_BITMAP(predicated_regs, TOTAL_PER_THREAD_REGS); 438b453a2bSTaylor Simpson int preg_log[PRED_WRITES_MAX]; 448b453a2bSTaylor Simpson int preg_log_idx; 456c677c60STaylor Simpson DECLARE_BITMAP(pregs_written, NUM_PREGS); 46b9f0326bSTaylor Simpson DECLARE_BITMAP(pregs_read, NUM_PREGS); 478b453a2bSTaylor Simpson uint8_t store_width[STORES_MAX]; 4892cfa25fSTaylor Simpson bool s1_store_processed; 49a82dd548STaylor Simpson int future_vregs_idx; 50a82dd548STaylor Simpson int future_vregs_num[VECTOR_TEMPS_MAX]; 51a82dd548STaylor Simpson int tmp_vregs_idx; 52a82dd548STaylor Simpson int tmp_vregs_num[VECTOR_TEMPS_MAX]; 53a82dd548STaylor Simpson int vreg_log[NUM_VREGS]; 54a82dd548STaylor Simpson int vreg_log_idx; 55a82dd548STaylor Simpson DECLARE_BITMAP(vregs_updated_tmp, NUM_VREGS); 56a82dd548STaylor Simpson DECLARE_BITMAP(vregs_updated, NUM_VREGS); 57a82dd548STaylor Simpson DECLARE_BITMAP(vregs_select, NUM_VREGS); 584d6f8420STaylor Simpson DECLARE_BITMAP(predicated_future_vregs, NUM_VREGS); 594d6f8420STaylor Simpson DECLARE_BITMAP(predicated_tmp_vregs, NUM_VREGS); 60b9f0326bSTaylor Simpson DECLARE_BITMAP(vregs_read, NUM_VREGS); 61a82dd548STaylor Simpson int qreg_log[NUM_QREGS]; 62a82dd548STaylor Simpson int qreg_log_idx; 63b9f0326bSTaylor Simpson DECLARE_BITMAP(qregs_read, NUM_QREGS); 64a82dd548STaylor Simpson bool pre_commit; 65d54c5615STaylor Simpson bool need_commit; 661b9a7f2aSTaylor Simpson TCGCond branch_cond; 671b9a7f2aSTaylor Simpson target_ulong branch_dest; 68564b2040STaylor Simpson bool is_tight_loop; 69d54c5615STaylor Simpson bool short_circuit; 70d05d5eebSTaylor Simpson bool has_hvx_helper; 714ff56764STaylor Simpson TCGv new_value[TOTAL_PER_THREAD_REGS]; 72e22edc7cSTaylor Simpson TCGv new_pred_value[NUM_PREGS]; 73842b206fSTaylor Simpson TCGv pred_written; 740fc56c43STaylor Simpson TCGv branch_taken; 750fc56c43STaylor Simpson TCGv dczero_addr; 768b453a2bSTaylor Simpson } DisasContext; 778b453a2bSTaylor Simpson 7876eaa971STaylor Simpson bool is_gather_store_insn(DisasContext *ctx); 7976eaa971STaylor Simpson 808b453a2bSTaylor Simpson static inline void ctx_log_pred_write(DisasContext *ctx, int pnum) 818b453a2bSTaylor Simpson { 8210849c26STaylor Simpson if (!test_bit(pnum, ctx->pregs_written)) { 838b453a2bSTaylor Simpson ctx->preg_log[ctx->preg_log_idx] = pnum; 848b453a2bSTaylor Simpson ctx->preg_log_idx++; 856c677c60STaylor Simpson set_bit(pnum, ctx->pregs_written); 868b453a2bSTaylor Simpson } 8710849c26STaylor Simpson } 888b453a2bSTaylor Simpson 89b9f0326bSTaylor Simpson static inline void ctx_log_pred_read(DisasContext *ctx, int pnum) 90b9f0326bSTaylor Simpson { 91b9f0326bSTaylor Simpson set_bit(pnum, ctx->pregs_read); 92b9f0326bSTaylor Simpson } 93b9f0326bSTaylor Simpson 9476eaa971STaylor Simpson static inline void ctx_log_pred_read_new(DisasContext *ctx, int pnum) 9576eaa971STaylor Simpson { 9676eaa971STaylor Simpson g_assert(test_bit(pnum, ctx->pregs_written)); 9776eaa971STaylor Simpson set_bit(pnum, ctx->pregs_read); 9876eaa971STaylor Simpson } 9976eaa971STaylor Simpson 10010849c26STaylor Simpson static inline void ctx_log_reg_write(DisasContext *ctx, int rnum, 10110849c26STaylor Simpson bool is_predicated) 1028b453a2bSTaylor Simpson { 10310849c26STaylor Simpson if (rnum == HEX_REG_P3_0_ALIASED) { 10410849c26STaylor Simpson for (int i = 0; i < NUM_PREGS; i++) { 10510849c26STaylor Simpson ctx_log_pred_write(ctx, i); 10610849c26STaylor Simpson } 10710849c26STaylor Simpson } else { 10810849c26STaylor Simpson if (!test_bit(rnum, ctx->regs_written)) { 10910849c26STaylor Simpson ctx->reg_log[ctx->reg_log_idx] = rnum; 11010849c26STaylor Simpson ctx->reg_log_idx++; 11110849c26STaylor Simpson set_bit(rnum, ctx->regs_written); 11210849c26STaylor Simpson } 11310849c26STaylor Simpson if (is_predicated) { 11410849c26STaylor Simpson set_bit(rnum, ctx->predicated_regs); 11510849c26STaylor Simpson } 11610849c26STaylor Simpson } 11710849c26STaylor Simpson } 11810849c26STaylor Simpson 11910849c26STaylor Simpson static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum, 12010849c26STaylor Simpson bool is_predicated) 12110849c26STaylor Simpson { 12210849c26STaylor Simpson ctx_log_reg_write(ctx, rnum, is_predicated); 12310849c26STaylor Simpson ctx_log_reg_write(ctx, rnum + 1, is_predicated); 1248b453a2bSTaylor Simpson } 1258b453a2bSTaylor Simpson 126b9f0326bSTaylor Simpson static inline void ctx_log_reg_read(DisasContext *ctx, int rnum) 127b9f0326bSTaylor Simpson { 128b9f0326bSTaylor Simpson set_bit(rnum, ctx->regs_read); 129b9f0326bSTaylor Simpson } 130b9f0326bSTaylor Simpson 13176eaa971STaylor Simpson static inline void ctx_log_reg_read_new(DisasContext *ctx, int rnum) 13276eaa971STaylor Simpson { 13376eaa971STaylor Simpson g_assert(test_bit(rnum, ctx->regs_written)); 13476eaa971STaylor Simpson set_bit(rnum, ctx->regs_read); 13576eaa971STaylor Simpson } 13676eaa971STaylor Simpson 137b9f0326bSTaylor Simpson static inline void ctx_log_reg_read_pair(DisasContext *ctx, int rnum) 138b9f0326bSTaylor Simpson { 139b9f0326bSTaylor Simpson ctx_log_reg_read(ctx, rnum); 140b9f0326bSTaylor Simpson ctx_log_reg_read(ctx, rnum + 1); 141b9f0326bSTaylor Simpson } 142b9f0326bSTaylor Simpson 143a82dd548STaylor Simpson intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum, 144a82dd548STaylor Simpson int num, bool alloc_ok); 145a82dd548STaylor Simpson intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum, 146a82dd548STaylor Simpson int num, bool alloc_ok); 147a82dd548STaylor Simpson 148a82dd548STaylor Simpson static inline void ctx_log_vreg_write(DisasContext *ctx, 149a82dd548STaylor Simpson int rnum, VRegWriteType type, 150a82dd548STaylor Simpson bool is_predicated) 151a82dd548STaylor Simpson { 152a82dd548STaylor Simpson if (type != EXT_TMP) { 153c2b33d0bSTaylor Simpson if (!test_bit(rnum, ctx->vregs_updated)) { 154a82dd548STaylor Simpson ctx->vreg_log[ctx->vreg_log_idx] = rnum; 155a82dd548STaylor Simpson ctx->vreg_log_idx++; 156c2b33d0bSTaylor Simpson set_bit(rnum, ctx->vregs_updated); 157c2b33d0bSTaylor Simpson } 158a82dd548STaylor Simpson 159a82dd548STaylor Simpson set_bit(rnum, ctx->vregs_updated); 1604d6f8420STaylor Simpson if (is_predicated) { 1614d6f8420STaylor Simpson set_bit(rnum, ctx->predicated_future_vregs); 1624d6f8420STaylor Simpson } 163a82dd548STaylor Simpson } 164a82dd548STaylor Simpson if (type == EXT_NEW) { 165a82dd548STaylor Simpson set_bit(rnum, ctx->vregs_select); 166a82dd548STaylor Simpson } 167a82dd548STaylor Simpson if (type == EXT_TMP) { 168a82dd548STaylor Simpson set_bit(rnum, ctx->vregs_updated_tmp); 1694d6f8420STaylor Simpson if (is_predicated) { 1704d6f8420STaylor Simpson set_bit(rnum, ctx->predicated_tmp_vregs); 1714d6f8420STaylor Simpson } 172a82dd548STaylor Simpson } 173a82dd548STaylor Simpson } 174a82dd548STaylor Simpson 175a82dd548STaylor Simpson static inline void ctx_log_vreg_write_pair(DisasContext *ctx, 176a82dd548STaylor Simpson int rnum, VRegWriteType type, 177a82dd548STaylor Simpson bool is_predicated) 178a82dd548STaylor Simpson { 179a82dd548STaylor Simpson ctx_log_vreg_write(ctx, rnum ^ 0, type, is_predicated); 180a82dd548STaylor Simpson ctx_log_vreg_write(ctx, rnum ^ 1, type, is_predicated); 181a82dd548STaylor Simpson } 182a82dd548STaylor Simpson 183b9f0326bSTaylor Simpson static inline void ctx_log_vreg_read(DisasContext *ctx, int rnum) 184b9f0326bSTaylor Simpson { 185b9f0326bSTaylor Simpson set_bit(rnum, ctx->vregs_read); 186b9f0326bSTaylor Simpson } 187b9f0326bSTaylor Simpson 18876eaa971STaylor Simpson static inline void ctx_log_vreg_read_new(DisasContext *ctx, int rnum) 18976eaa971STaylor Simpson { 19076eaa971STaylor Simpson g_assert(is_gather_store_insn(ctx) || 19176eaa971STaylor Simpson test_bit(rnum, ctx->vregs_updated) || 19276eaa971STaylor Simpson test_bit(rnum, ctx->vregs_select) || 19376eaa971STaylor Simpson test_bit(rnum, ctx->vregs_updated_tmp)); 19476eaa971STaylor Simpson set_bit(rnum, ctx->vregs_read); 19576eaa971STaylor Simpson } 19676eaa971STaylor Simpson 197b9f0326bSTaylor Simpson static inline void ctx_log_vreg_read_pair(DisasContext *ctx, int rnum) 198b9f0326bSTaylor Simpson { 199b9f0326bSTaylor Simpson ctx_log_vreg_read(ctx, rnum ^ 0); 200b9f0326bSTaylor Simpson ctx_log_vreg_read(ctx, rnum ^ 1); 201b9f0326bSTaylor Simpson } 202b9f0326bSTaylor Simpson 203a82dd548STaylor Simpson static inline void ctx_log_qreg_write(DisasContext *ctx, 204c2b33d0bSTaylor Simpson int rnum) 205a82dd548STaylor Simpson { 206a82dd548STaylor Simpson ctx->qreg_log[ctx->qreg_log_idx] = rnum; 207a82dd548STaylor Simpson ctx->qreg_log_idx++; 208a82dd548STaylor Simpson } 209a82dd548STaylor Simpson 210b9f0326bSTaylor Simpson static inline void ctx_log_qreg_read(DisasContext *ctx, int qnum) 211b9f0326bSTaylor Simpson { 212b9f0326bSTaylor Simpson set_bit(qnum, ctx->qregs_read); 213b9f0326bSTaylor Simpson } 214b9f0326bSTaylor Simpson 2158b453a2bSTaylor Simpson extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS]; 2168b453a2bSTaylor Simpson extern TCGv hex_pred[NUM_PREGS]; 2178b453a2bSTaylor Simpson extern TCGv hex_slot_cancelled; 2186aa4f1d1STaylor Simpson extern TCGv hex_new_value_usr; 2198b453a2bSTaylor Simpson extern TCGv hex_reg_written[TOTAL_PER_THREAD_REGS]; 2208b453a2bSTaylor Simpson extern TCGv hex_store_addr[STORES_MAX]; 2218b453a2bSTaylor Simpson extern TCGv hex_store_width[STORES_MAX]; 2228b453a2bSTaylor Simpson extern TCGv hex_store_val32[STORES_MAX]; 2238b453a2bSTaylor Simpson extern TCGv_i64 hex_store_val64[STORES_MAX]; 2248b453a2bSTaylor Simpson extern TCGv hex_llsc_addr; 2258b453a2bSTaylor Simpson extern TCGv hex_llsc_val; 2268b453a2bSTaylor Simpson extern TCGv_i64 hex_llsc_val_i64; 227a82dd548STaylor Simpson extern TCGv hex_vstore_addr[VSTORES_MAX]; 228a82dd548STaylor Simpson extern TCGv hex_vstore_size[VSTORES_MAX]; 229a82dd548STaylor Simpson extern TCGv hex_vstore_pending[VSTORES_MAX]; 2308b453a2bSTaylor Simpson 2311e536334STaylor Simpson void process_store(DisasContext *ctx, int slot_num); 2327b84fd04STaylor Simpson 2337b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, MMU_IDX, 0, 2) 2347b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 2, 1) 2357b84fd04STaylor Simpson 2367b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST0, 0, 1) 2377b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST1, 1, 1) 2387b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_HVX_STORES, 2, 1) 2397b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S0_IS_PRED, 3, 1) 2407b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S1_IS_PRED, 4, 1) 2412bda44e8STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, MMU_IDX, 5, 2) 2427b84fd04STaylor Simpson 2438b453a2bSTaylor Simpson #endif 244