xref: /qemu/target/hexagon/translate.h (revision 1b9a7f2a)
18b453a2bSTaylor Simpson /*
21e536334STaylor Simpson  *  Copyright(c) 2019-2022 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);
418b453a2bSTaylor Simpson     int preg_log[PRED_WRITES_MAX];
428b453a2bSTaylor Simpson     int preg_log_idx;
436c677c60STaylor Simpson     DECLARE_BITMAP(pregs_written, NUM_PREGS);
448b453a2bSTaylor Simpson     uint8_t store_width[STORES_MAX];
4592cfa25fSTaylor Simpson     bool s1_store_processed;
46a82dd548STaylor Simpson     int future_vregs_idx;
47a82dd548STaylor Simpson     int future_vregs_num[VECTOR_TEMPS_MAX];
48a82dd548STaylor Simpson     int tmp_vregs_idx;
49a82dd548STaylor Simpson     int tmp_vregs_num[VECTOR_TEMPS_MAX];
50a82dd548STaylor Simpson     int vreg_log[NUM_VREGS];
51a82dd548STaylor Simpson     bool vreg_is_predicated[NUM_VREGS];
52a82dd548STaylor Simpson     int vreg_log_idx;
53a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated_tmp, NUM_VREGS);
54a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated, NUM_VREGS);
55a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_select, NUM_VREGS);
56a82dd548STaylor Simpson     int qreg_log[NUM_QREGS];
57a82dd548STaylor Simpson     bool qreg_is_predicated[NUM_QREGS];
58a82dd548STaylor Simpson     int qreg_log_idx;
59a82dd548STaylor Simpson     bool pre_commit;
601b9a7f2aSTaylor Simpson     TCGCond branch_cond;
611b9a7f2aSTaylor Simpson     target_ulong branch_dest;
628b453a2bSTaylor Simpson } DisasContext;
638b453a2bSTaylor Simpson 
648b453a2bSTaylor Simpson static inline void ctx_log_reg_write(DisasContext *ctx, int rnum)
658b453a2bSTaylor Simpson {
668b453a2bSTaylor Simpson     if (test_bit(rnum, ctx->regs_written)) {
678b453a2bSTaylor Simpson         HEX_DEBUG_LOG("WARNING: Multiple writes to r%d\n", rnum);
688b453a2bSTaylor Simpson     }
698b453a2bSTaylor Simpson     ctx->reg_log[ctx->reg_log_idx] = rnum;
708b453a2bSTaylor Simpson     ctx->reg_log_idx++;
718b453a2bSTaylor Simpson     set_bit(rnum, ctx->regs_written);
728b453a2bSTaylor Simpson }
738b453a2bSTaylor Simpson 
748b453a2bSTaylor Simpson static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum)
758b453a2bSTaylor Simpson {
768b453a2bSTaylor Simpson     ctx_log_reg_write(ctx, rnum);
778b453a2bSTaylor Simpson     ctx_log_reg_write(ctx, rnum + 1);
788b453a2bSTaylor Simpson }
798b453a2bSTaylor Simpson 
808b453a2bSTaylor Simpson static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
818b453a2bSTaylor Simpson {
828b453a2bSTaylor Simpson     ctx->preg_log[ctx->preg_log_idx] = pnum;
838b453a2bSTaylor Simpson     ctx->preg_log_idx++;
846c677c60STaylor Simpson     set_bit(pnum, ctx->pregs_written);
858b453a2bSTaylor Simpson }
868b453a2bSTaylor Simpson 
878b453a2bSTaylor Simpson static inline bool is_preloaded(DisasContext *ctx, int num)
888b453a2bSTaylor Simpson {
898b453a2bSTaylor Simpson     return test_bit(num, ctx->regs_written);
908b453a2bSTaylor Simpson }
918b453a2bSTaylor Simpson 
9283853ea0STaylor Simpson static inline bool is_vreg_preloaded(DisasContext *ctx, int num)
9383853ea0STaylor Simpson {
9483853ea0STaylor Simpson     return test_bit(num, ctx->vregs_updated) ||
9583853ea0STaylor Simpson            test_bit(num, ctx->vregs_updated_tmp);
9683853ea0STaylor Simpson }
9783853ea0STaylor Simpson 
98a82dd548STaylor Simpson intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum,
99a82dd548STaylor Simpson                              int num, bool alloc_ok);
100a82dd548STaylor Simpson intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
101a82dd548STaylor Simpson                           int num, bool alloc_ok);
102a82dd548STaylor Simpson 
103a82dd548STaylor Simpson static inline void ctx_log_vreg_write(DisasContext *ctx,
104a82dd548STaylor Simpson                                       int rnum, VRegWriteType type,
105a82dd548STaylor Simpson                                       bool is_predicated)
106a82dd548STaylor Simpson {
107a82dd548STaylor Simpson     if (type != EXT_TMP) {
108a82dd548STaylor Simpson         ctx->vreg_log[ctx->vreg_log_idx] = rnum;
109a82dd548STaylor Simpson         ctx->vreg_is_predicated[ctx->vreg_log_idx] = is_predicated;
110a82dd548STaylor Simpson         ctx->vreg_log_idx++;
111a82dd548STaylor Simpson 
112a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated);
113a82dd548STaylor Simpson     }
114a82dd548STaylor Simpson     if (type == EXT_NEW) {
115a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_select);
116a82dd548STaylor Simpson     }
117a82dd548STaylor Simpson     if (type == EXT_TMP) {
118a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated_tmp);
119a82dd548STaylor Simpson     }
120a82dd548STaylor Simpson }
121a82dd548STaylor Simpson 
122a82dd548STaylor Simpson static inline void ctx_log_vreg_write_pair(DisasContext *ctx,
123a82dd548STaylor Simpson                                            int rnum, VRegWriteType type,
124a82dd548STaylor Simpson                                            bool is_predicated)
125a82dd548STaylor Simpson {
126a82dd548STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 0, type, is_predicated);
127a82dd548STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 1, type, is_predicated);
128a82dd548STaylor Simpson }
129a82dd548STaylor Simpson 
130a82dd548STaylor Simpson static inline void ctx_log_qreg_write(DisasContext *ctx,
131a82dd548STaylor Simpson                                       int rnum, bool is_predicated)
132a82dd548STaylor Simpson {
133a82dd548STaylor Simpson     ctx->qreg_log[ctx->qreg_log_idx] = rnum;
134a82dd548STaylor Simpson     ctx->qreg_is_predicated[ctx->qreg_log_idx] = is_predicated;
135a82dd548STaylor Simpson     ctx->qreg_log_idx++;
136a82dd548STaylor Simpson }
137a82dd548STaylor Simpson 
1388b453a2bSTaylor Simpson extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
1398b453a2bSTaylor Simpson extern TCGv hex_pred[NUM_PREGS];
1408b453a2bSTaylor Simpson extern TCGv hex_this_PC;
1418b453a2bSTaylor Simpson extern TCGv hex_slot_cancelled;
1428b453a2bSTaylor Simpson extern TCGv hex_branch_taken;
1438b453a2bSTaylor Simpson extern TCGv hex_new_value[TOTAL_PER_THREAD_REGS];
1448b453a2bSTaylor Simpson extern TCGv hex_reg_written[TOTAL_PER_THREAD_REGS];
1458b453a2bSTaylor Simpson extern TCGv hex_new_pred_value[NUM_PREGS];
1468b453a2bSTaylor Simpson extern TCGv hex_pred_written;
1478b453a2bSTaylor Simpson extern TCGv hex_store_addr[STORES_MAX];
1488b453a2bSTaylor Simpson extern TCGv hex_store_width[STORES_MAX];
1498b453a2bSTaylor Simpson extern TCGv hex_store_val32[STORES_MAX];
1508b453a2bSTaylor Simpson extern TCGv_i64 hex_store_val64[STORES_MAX];
1518b453a2bSTaylor Simpson extern TCGv hex_dczero_addr;
1528b453a2bSTaylor Simpson extern TCGv hex_llsc_addr;
1538b453a2bSTaylor Simpson extern TCGv hex_llsc_val;
1548b453a2bSTaylor Simpson extern TCGv_i64 hex_llsc_val_i64;
155a82dd548STaylor Simpson extern TCGv hex_VRegs_updated;
156a82dd548STaylor Simpson extern TCGv hex_QRegs_updated;
157a82dd548STaylor Simpson extern TCGv hex_vstore_addr[VSTORES_MAX];
158a82dd548STaylor Simpson extern TCGv hex_vstore_size[VSTORES_MAX];
159a82dd548STaylor Simpson extern TCGv hex_vstore_pending[VSTORES_MAX];
1608b453a2bSTaylor Simpson 
1611e536334STaylor Simpson bool is_gather_store_insn(DisasContext *ctx);
1621e536334STaylor Simpson void process_store(DisasContext *ctx, int slot_num);
1638b453a2bSTaylor Simpson #endif
164