xref: /openbmc/qemu/target/hexagon/translate.c (revision 7d9ab202)
18b453a2bSTaylor Simpson /*
28b453a2bSTaylor Simpson  *  Copyright(c) 2019-2021 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 #define QEMU_GENERATE
198b453a2bSTaylor Simpson #include "qemu/osdep.h"
208b453a2bSTaylor Simpson #include "cpu.h"
218b453a2bSTaylor Simpson #include "tcg/tcg-op.h"
228b453a2bSTaylor Simpson #include "exec/cpu_ldst.h"
238b453a2bSTaylor Simpson #include "exec/log.h"
248b453a2bSTaylor Simpson #include "internal.h"
258b453a2bSTaylor Simpson #include "attribs.h"
268b453a2bSTaylor Simpson #include "insn.h"
278b453a2bSTaylor Simpson #include "decode.h"
288b453a2bSTaylor Simpson #include "translate.h"
298b453a2bSTaylor Simpson #include "printinsn.h"
308b453a2bSTaylor Simpson 
318b453a2bSTaylor Simpson TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
328b453a2bSTaylor Simpson TCGv hex_pred[NUM_PREGS];
338b453a2bSTaylor Simpson TCGv hex_next_PC;
348b453a2bSTaylor Simpson TCGv hex_this_PC;
358b453a2bSTaylor Simpson TCGv hex_slot_cancelled;
368b453a2bSTaylor Simpson TCGv hex_branch_taken;
378b453a2bSTaylor Simpson TCGv hex_new_value[TOTAL_PER_THREAD_REGS];
388b453a2bSTaylor Simpson #if HEX_DEBUG
398b453a2bSTaylor Simpson TCGv hex_reg_written[TOTAL_PER_THREAD_REGS];
408b453a2bSTaylor Simpson #endif
418b453a2bSTaylor Simpson TCGv hex_new_pred_value[NUM_PREGS];
428b453a2bSTaylor Simpson TCGv hex_pred_written;
438b453a2bSTaylor Simpson TCGv hex_store_addr[STORES_MAX];
448b453a2bSTaylor Simpson TCGv hex_store_width[STORES_MAX];
458b453a2bSTaylor Simpson TCGv hex_store_val32[STORES_MAX];
468b453a2bSTaylor Simpson TCGv_i64 hex_store_val64[STORES_MAX];
478b453a2bSTaylor Simpson TCGv hex_pkt_has_store_s1;
488b453a2bSTaylor Simpson TCGv hex_dczero_addr;
498b453a2bSTaylor Simpson TCGv hex_llsc_addr;
508b453a2bSTaylor Simpson TCGv hex_llsc_val;
518b453a2bSTaylor Simpson TCGv_i64 hex_llsc_val_i64;
528b453a2bSTaylor Simpson 
538b453a2bSTaylor Simpson static const char * const hexagon_prednames[] = {
548b453a2bSTaylor Simpson   "p0", "p1", "p2", "p3"
558b453a2bSTaylor Simpson };
568b453a2bSTaylor Simpson 
578b453a2bSTaylor Simpson void gen_exception(int excp)
588b453a2bSTaylor Simpson {
598b453a2bSTaylor Simpson     TCGv_i32 helper_tmp = tcg_const_i32(excp);
608b453a2bSTaylor Simpson     gen_helper_raise_exception(cpu_env, helper_tmp);
618b453a2bSTaylor Simpson     tcg_temp_free_i32(helper_tmp);
628b453a2bSTaylor Simpson }
638b453a2bSTaylor Simpson 
648b453a2bSTaylor Simpson void gen_exception_debug(void)
658b453a2bSTaylor Simpson {
668b453a2bSTaylor Simpson     gen_exception(EXCP_DEBUG);
678b453a2bSTaylor Simpson }
688b453a2bSTaylor Simpson 
698b453a2bSTaylor Simpson #if HEX_DEBUG
708b453a2bSTaylor Simpson #define PACKET_BUFFER_LEN              1028
718b453a2bSTaylor Simpson static void print_pkt(Packet *pkt)
728b453a2bSTaylor Simpson {
738b453a2bSTaylor Simpson     GString *buf = g_string_sized_new(PACKET_BUFFER_LEN);
748b453a2bSTaylor Simpson     snprint_a_pkt_debug(buf, pkt);
758b453a2bSTaylor Simpson     HEX_DEBUG_LOG("%s", buf->str);
768b453a2bSTaylor Simpson     g_string_free(buf, true);
778b453a2bSTaylor Simpson }
788b453a2bSTaylor Simpson #define HEX_DEBUG_PRINT_PKT(pkt)  print_pkt(pkt)
798b453a2bSTaylor Simpson #else
808b453a2bSTaylor Simpson #define HEX_DEBUG_PRINT_PKT(pkt)  /* nothing */
818b453a2bSTaylor Simpson #endif
828b453a2bSTaylor Simpson 
838b453a2bSTaylor Simpson static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
848b453a2bSTaylor Simpson                              uint32_t words[])
858b453a2bSTaylor Simpson {
868b453a2bSTaylor Simpson     bool found_end = false;
878b453a2bSTaylor Simpson     int nwords, max_words;
888b453a2bSTaylor Simpson 
898b453a2bSTaylor Simpson     memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
908b453a2bSTaylor Simpson     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
91a27c100cSTaylor Simpson         words[nwords] =
92a27c100cSTaylor Simpson             translator_ldl(env, ctx->base.pc_next + nwords * sizeof(uint32_t));
938b453a2bSTaylor Simpson         found_end = is_packet_end(words[nwords]);
948b453a2bSTaylor Simpson     }
958b453a2bSTaylor Simpson     if (!found_end) {
968b453a2bSTaylor Simpson         /* Read too many words without finding the end */
978b453a2bSTaylor Simpson         return 0;
988b453a2bSTaylor Simpson     }
998b453a2bSTaylor Simpson 
1008b453a2bSTaylor Simpson     /* Check for page boundary crossing */
1018b453a2bSTaylor Simpson     max_words = -(ctx->base.pc_next | TARGET_PAGE_MASK) / sizeof(uint32_t);
1028b453a2bSTaylor Simpson     if (nwords > max_words) {
1038b453a2bSTaylor Simpson         /* We can only cross a page boundary at the beginning of a TB */
1048b453a2bSTaylor Simpson         g_assert(ctx->base.num_insns == 1);
1058b453a2bSTaylor Simpson     }
1068b453a2bSTaylor Simpson 
1078b453a2bSTaylor Simpson     HEX_DEBUG_LOG("decode_packet: pc = 0x%x\n", ctx->base.pc_next);
1088b453a2bSTaylor Simpson     HEX_DEBUG_LOG("    words = { ");
1098b453a2bSTaylor Simpson     for (int i = 0; i < nwords; i++) {
1108b453a2bSTaylor Simpson         HEX_DEBUG_LOG("0x%x, ", words[i]);
1118b453a2bSTaylor Simpson     }
1128b453a2bSTaylor Simpson     HEX_DEBUG_LOG("}\n");
1138b453a2bSTaylor Simpson 
1148b453a2bSTaylor Simpson     return nwords;
1158b453a2bSTaylor Simpson }
1168b453a2bSTaylor Simpson 
1178b453a2bSTaylor Simpson static bool check_for_attrib(Packet *pkt, int attrib)
1188b453a2bSTaylor Simpson {
1198b453a2bSTaylor Simpson     for (int i = 0; i < pkt->num_insns; i++) {
1208b453a2bSTaylor Simpson         if (GET_ATTRIB(pkt->insn[i].opcode, attrib)) {
1218b453a2bSTaylor Simpson             return true;
1228b453a2bSTaylor Simpson         }
1238b453a2bSTaylor Simpson     }
1248b453a2bSTaylor Simpson     return false;
1258b453a2bSTaylor Simpson }
1268b453a2bSTaylor Simpson 
1278b453a2bSTaylor Simpson static bool need_pc(Packet *pkt)
1288b453a2bSTaylor Simpson {
1298b453a2bSTaylor Simpson     return check_for_attrib(pkt, A_IMPLICIT_READS_PC);
1308b453a2bSTaylor Simpson }
1318b453a2bSTaylor Simpson 
1328b453a2bSTaylor Simpson static bool need_slot_cancelled(Packet *pkt)
1338b453a2bSTaylor Simpson {
1348b453a2bSTaylor Simpson     return check_for_attrib(pkt, A_CONDEXEC);
1358b453a2bSTaylor Simpson }
1368b453a2bSTaylor Simpson 
1378b453a2bSTaylor Simpson static bool need_pred_written(Packet *pkt)
1388b453a2bSTaylor Simpson {
1398b453a2bSTaylor Simpson     return check_for_attrib(pkt, A_WRITES_PRED_REG);
1408b453a2bSTaylor Simpson }
1418b453a2bSTaylor Simpson 
1428b453a2bSTaylor Simpson static void gen_start_packet(DisasContext *ctx, Packet *pkt)
1438b453a2bSTaylor Simpson {
1448b453a2bSTaylor Simpson     target_ulong next_PC = ctx->base.pc_next + pkt->encod_pkt_size_in_bytes;
1458b453a2bSTaylor Simpson     int i;
1468b453a2bSTaylor Simpson 
1478b453a2bSTaylor Simpson     /* Clear out the disassembly context */
1488b453a2bSTaylor Simpson     ctx->reg_log_idx = 0;
1498b453a2bSTaylor Simpson     bitmap_zero(ctx->regs_written, TOTAL_PER_THREAD_REGS);
1508b453a2bSTaylor Simpson     ctx->preg_log_idx = 0;
1518b453a2bSTaylor Simpson     for (i = 0; i < STORES_MAX; i++) {
1528b453a2bSTaylor Simpson         ctx->store_width[i] = 0;
1538b453a2bSTaylor Simpson     }
1548b453a2bSTaylor Simpson     tcg_gen_movi_tl(hex_pkt_has_store_s1, pkt->pkt_has_store_s1);
1558b453a2bSTaylor Simpson     ctx->s1_store_processed = 0;
1568b453a2bSTaylor Simpson 
1578b453a2bSTaylor Simpson #if HEX_DEBUG
1588b453a2bSTaylor Simpson     /* Handy place to set a breakpoint before the packet executes */
1598b453a2bSTaylor Simpson     gen_helper_debug_start_packet(cpu_env);
1608b453a2bSTaylor Simpson     tcg_gen_movi_tl(hex_this_PC, ctx->base.pc_next);
1618b453a2bSTaylor Simpson #endif
1628b453a2bSTaylor Simpson 
1638b453a2bSTaylor Simpson     /* Initialize the runtime state for packet semantics */
1648b453a2bSTaylor Simpson     if (need_pc(pkt)) {
1658b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);
1668b453a2bSTaylor Simpson     }
1678b453a2bSTaylor Simpson     if (need_slot_cancelled(pkt)) {
1688b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_slot_cancelled, 0);
1698b453a2bSTaylor Simpson     }
1708b453a2bSTaylor Simpson     if (pkt->pkt_has_cof) {
1718b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_branch_taken, 0);
1728b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_next_PC, next_PC);
1738b453a2bSTaylor Simpson     }
1748b453a2bSTaylor Simpson     if (need_pred_written(pkt)) {
1758b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_pred_written, 0);
1768b453a2bSTaylor Simpson     }
1778b453a2bSTaylor Simpson }
1788b453a2bSTaylor Simpson 
1798b453a2bSTaylor Simpson /*
1808b453a2bSTaylor Simpson  * The LOG_*_WRITE macros mark most of the writes in a packet
1818b453a2bSTaylor Simpson  * However, there are some implicit writes marked as attributes
1828b453a2bSTaylor Simpson  * of the applicable instructions.
1838b453a2bSTaylor Simpson  */
1848b453a2bSTaylor Simpson static void mark_implicit_reg_write(DisasContext *ctx, Insn *insn,
1858b453a2bSTaylor Simpson                                     int attrib, int rnum)
1868b453a2bSTaylor Simpson {
1878b453a2bSTaylor Simpson     if (GET_ATTRIB(insn->opcode, attrib)) {
1888b453a2bSTaylor Simpson         int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC);
1898b453a2bSTaylor Simpson         if (is_predicated && !is_preloaded(ctx, rnum)) {
1908b453a2bSTaylor Simpson             tcg_gen_mov_tl(hex_new_value[rnum], hex_gpr[rnum]);
1918b453a2bSTaylor Simpson         }
1928b453a2bSTaylor Simpson 
1938b453a2bSTaylor Simpson         ctx_log_reg_write(ctx, rnum);
1948b453a2bSTaylor Simpson     }
1958b453a2bSTaylor Simpson }
1968b453a2bSTaylor Simpson 
1978b453a2bSTaylor Simpson static void mark_implicit_pred_write(DisasContext *ctx, Insn *insn,
1988b453a2bSTaylor Simpson                                      int attrib, int pnum)
1998b453a2bSTaylor Simpson {
2008b453a2bSTaylor Simpson     if (GET_ATTRIB(insn->opcode, attrib)) {
2018b453a2bSTaylor Simpson         ctx_log_pred_write(ctx, pnum);
2028b453a2bSTaylor Simpson     }
2038b453a2bSTaylor Simpson }
2048b453a2bSTaylor Simpson 
2058b453a2bSTaylor Simpson static void mark_implicit_writes(DisasContext *ctx, Insn *insn)
2068b453a2bSTaylor Simpson {
2078b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_FP,  HEX_REG_FP);
2088b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_SP,  HEX_REG_SP);
2098b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_LR,  HEX_REG_LR);
2108b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_LC0, HEX_REG_LC0);
2118b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_SA0, HEX_REG_SA0);
2128b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_LC1, HEX_REG_LC1);
2138b453a2bSTaylor Simpson     mark_implicit_reg_write(ctx, insn, A_IMPLICIT_WRITES_SA1, HEX_REG_SA1);
2148b453a2bSTaylor Simpson 
2158b453a2bSTaylor Simpson     mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P0, 0);
2168b453a2bSTaylor Simpson     mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P1, 1);
2178b453a2bSTaylor Simpson     mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P2, 2);
2188b453a2bSTaylor Simpson     mark_implicit_pred_write(ctx, insn, A_IMPLICIT_WRITES_P3, 3);
2198b453a2bSTaylor Simpson }
2208b453a2bSTaylor Simpson 
2218b453a2bSTaylor Simpson static void gen_insn(CPUHexagonState *env, DisasContext *ctx,
2228b453a2bSTaylor Simpson                      Insn *insn, Packet *pkt)
2238b453a2bSTaylor Simpson {
2248b453a2bSTaylor Simpson     if (insn->generate) {
2258b453a2bSTaylor Simpson         mark_implicit_writes(ctx, insn);
2268b453a2bSTaylor Simpson         insn->generate(env, ctx, insn, pkt);
2278b453a2bSTaylor Simpson     } else {
2288b453a2bSTaylor Simpson         gen_exception(HEX_EXCP_INVALID_OPCODE);
2298b453a2bSTaylor Simpson         ctx->base.is_jmp = DISAS_NORETURN;
2308b453a2bSTaylor Simpson     }
2318b453a2bSTaylor Simpson }
2328b453a2bSTaylor Simpson 
2338b453a2bSTaylor Simpson /*
2348b453a2bSTaylor Simpson  * Helpers for generating the packet commit
2358b453a2bSTaylor Simpson  */
2368b453a2bSTaylor Simpson static void gen_reg_writes(DisasContext *ctx)
2378b453a2bSTaylor Simpson {
2388b453a2bSTaylor Simpson     int i;
2398b453a2bSTaylor Simpson 
2408b453a2bSTaylor Simpson     for (i = 0; i < ctx->reg_log_idx; i++) {
2418b453a2bSTaylor Simpson         int reg_num = ctx->reg_log[i];
2428b453a2bSTaylor Simpson 
2438b453a2bSTaylor Simpson         tcg_gen_mov_tl(hex_gpr[reg_num], hex_new_value[reg_num]);
2448b453a2bSTaylor Simpson     }
2458b453a2bSTaylor Simpson }
2468b453a2bSTaylor Simpson 
2478b453a2bSTaylor Simpson static void gen_pred_writes(DisasContext *ctx, Packet *pkt)
2488b453a2bSTaylor Simpson {
2498b453a2bSTaylor Simpson     TCGv zero, control_reg, pval;
2508b453a2bSTaylor Simpson     int i;
2518b453a2bSTaylor Simpson 
2528b453a2bSTaylor Simpson     /* Early exit if the log is empty */
2538b453a2bSTaylor Simpson     if (!ctx->preg_log_idx) {
2548b453a2bSTaylor Simpson         return;
2558b453a2bSTaylor Simpson     }
2568b453a2bSTaylor Simpson 
2578b453a2bSTaylor Simpson     zero = tcg_const_tl(0);
2588b453a2bSTaylor Simpson     control_reg = tcg_temp_new();
2598b453a2bSTaylor Simpson     pval = tcg_temp_new();
2608b453a2bSTaylor Simpson 
2618b453a2bSTaylor Simpson     /*
2628b453a2bSTaylor Simpson      * Only endloop instructions will conditionally
2638b453a2bSTaylor Simpson      * write a predicate.  If there are no endloop
2648b453a2bSTaylor Simpson      * instructions, we can use the non-conditional
2658b453a2bSTaylor Simpson      * write of the predicates.
2668b453a2bSTaylor Simpson      */
2678b453a2bSTaylor Simpson     if (pkt->pkt_has_endloop) {
2688b453a2bSTaylor Simpson         TCGv pred_written = tcg_temp_new();
2698b453a2bSTaylor Simpson         for (i = 0; i < ctx->preg_log_idx; i++) {
2708b453a2bSTaylor Simpson             int pred_num = ctx->preg_log[i];
2718b453a2bSTaylor Simpson 
2728b453a2bSTaylor Simpson             tcg_gen_andi_tl(pred_written, hex_pred_written, 1 << pred_num);
2738b453a2bSTaylor Simpson             tcg_gen_movcond_tl(TCG_COND_NE, hex_pred[pred_num],
2748b453a2bSTaylor Simpson                                pred_written, zero,
2758b453a2bSTaylor Simpson                                hex_new_pred_value[pred_num],
2768b453a2bSTaylor Simpson                                hex_pred[pred_num]);
2778b453a2bSTaylor Simpson         }
2788b453a2bSTaylor Simpson         tcg_temp_free(pred_written);
2798b453a2bSTaylor Simpson     } else {
2808b453a2bSTaylor Simpson         for (i = 0; i < ctx->preg_log_idx; i++) {
2818b453a2bSTaylor Simpson             int pred_num = ctx->preg_log[i];
2828b453a2bSTaylor Simpson             tcg_gen_mov_tl(hex_pred[pred_num], hex_new_pred_value[pred_num]);
2838b453a2bSTaylor Simpson #if HEX_DEBUG
2848b453a2bSTaylor Simpson             /* Do this so HELPER(debug_commit_end) will know */
2858b453a2bSTaylor Simpson             tcg_gen_ori_tl(hex_pred_written, hex_pred_written, 1 << pred_num);
2868b453a2bSTaylor Simpson #endif
2878b453a2bSTaylor Simpson         }
2888b453a2bSTaylor Simpson     }
2898b453a2bSTaylor Simpson 
2908b453a2bSTaylor Simpson     tcg_temp_free(zero);
2918b453a2bSTaylor Simpson     tcg_temp_free(control_reg);
2928b453a2bSTaylor Simpson     tcg_temp_free(pval);
2938b453a2bSTaylor Simpson }
2948b453a2bSTaylor Simpson 
295a27c100cSTaylor Simpson static void gen_check_store_width(DisasContext *ctx, int slot_num)
2968b453a2bSTaylor Simpson {
297a27c100cSTaylor Simpson #if HEX_DEBUG
2988b453a2bSTaylor Simpson     TCGv slot = tcg_const_tl(slot_num);
2998b453a2bSTaylor Simpson     TCGv check = tcg_const_tl(ctx->store_width[slot_num]);
3008b453a2bSTaylor Simpson     gen_helper_debug_check_store_width(cpu_env, slot, check);
3018b453a2bSTaylor Simpson     tcg_temp_free(slot);
3028b453a2bSTaylor Simpson     tcg_temp_free(check);
3038b453a2bSTaylor Simpson #endif
304a27c100cSTaylor Simpson }
3058b453a2bSTaylor Simpson 
3068b453a2bSTaylor Simpson static bool slot_is_predicated(Packet *pkt, int slot_num)
3078b453a2bSTaylor Simpson {
3088b453a2bSTaylor Simpson     for (int i = 0; i < pkt->num_insns; i++) {
3098b453a2bSTaylor Simpson         if (pkt->insn[i].slot == slot_num) {
3108b453a2bSTaylor Simpson             return GET_ATTRIB(pkt->insn[i].opcode, A_CONDEXEC);
3118b453a2bSTaylor Simpson         }
3128b453a2bSTaylor Simpson     }
3138b453a2bSTaylor Simpson     /* If we get to here, we didn't find an instruction in the requested slot */
3148b453a2bSTaylor Simpson     g_assert_not_reached();
3158b453a2bSTaylor Simpson }
3168b453a2bSTaylor Simpson 
3178b453a2bSTaylor Simpson void process_store(DisasContext *ctx, Packet *pkt, int slot_num)
3188b453a2bSTaylor Simpson {
3198b453a2bSTaylor Simpson     bool is_predicated = slot_is_predicated(pkt, slot_num);
3208b453a2bSTaylor Simpson     TCGLabel *label_end = NULL;
3218b453a2bSTaylor Simpson 
3228b453a2bSTaylor Simpson     /*
3238b453a2bSTaylor Simpson      * We may have already processed this store
3248b453a2bSTaylor Simpson      * See CHECK_NOSHUF in macros.h
3258b453a2bSTaylor Simpson      */
3268b453a2bSTaylor Simpson     if (slot_num == 1 && ctx->s1_store_processed) {
3278b453a2bSTaylor Simpson         return;
3288b453a2bSTaylor Simpson     }
3298b453a2bSTaylor Simpson     ctx->s1_store_processed = 1;
3308b453a2bSTaylor Simpson 
3318b453a2bSTaylor Simpson     if (is_predicated) {
3328b453a2bSTaylor Simpson         TCGv cancelled = tcg_temp_new();
3338b453a2bSTaylor Simpson         label_end = gen_new_label();
3348b453a2bSTaylor Simpson 
3358b453a2bSTaylor Simpson         /* Don't do anything if the slot was cancelled */
3368b453a2bSTaylor Simpson         tcg_gen_extract_tl(cancelled, hex_slot_cancelled, slot_num, 1);
3378b453a2bSTaylor Simpson         tcg_gen_brcondi_tl(TCG_COND_NE, cancelled, 0, label_end);
3388b453a2bSTaylor Simpson         tcg_temp_free(cancelled);
3398b453a2bSTaylor Simpson     }
3408b453a2bSTaylor Simpson     {
3418b453a2bSTaylor Simpson         TCGv address = tcg_temp_local_new();
3428b453a2bSTaylor Simpson         tcg_gen_mov_tl(address, hex_store_addr[slot_num]);
3438b453a2bSTaylor Simpson 
3448b453a2bSTaylor Simpson         /*
3458b453a2bSTaylor Simpson          * If we know the width from the DisasContext, we can
3468b453a2bSTaylor Simpson          * generate much cleaner code.
3478b453a2bSTaylor Simpson          * Unfortunately, not all instructions execute the fSTORE
3488b453a2bSTaylor Simpson          * macro during code generation.  Anything that uses the
3498b453a2bSTaylor Simpson          * generic helper will have this problem.  Instructions
3508b453a2bSTaylor Simpson          * that use fWRAP to generate proper TCG code will be OK.
3518b453a2bSTaylor Simpson          */
3528b453a2bSTaylor Simpson         switch (ctx->store_width[slot_num]) {
3538b453a2bSTaylor Simpson         case 1:
354a27c100cSTaylor Simpson             gen_check_store_width(ctx, slot_num);
3558b453a2bSTaylor Simpson             tcg_gen_qemu_st8(hex_store_val32[slot_num],
3568b453a2bSTaylor Simpson                              hex_store_addr[slot_num],
3578b453a2bSTaylor Simpson                              ctx->mem_idx);
3588b453a2bSTaylor Simpson             break;
3598b453a2bSTaylor Simpson         case 2:
360a27c100cSTaylor Simpson             gen_check_store_width(ctx, slot_num);
3618b453a2bSTaylor Simpson             tcg_gen_qemu_st16(hex_store_val32[slot_num],
3628b453a2bSTaylor Simpson                               hex_store_addr[slot_num],
3638b453a2bSTaylor Simpson                               ctx->mem_idx);
3648b453a2bSTaylor Simpson             break;
3658b453a2bSTaylor Simpson         case 4:
366a27c100cSTaylor Simpson             gen_check_store_width(ctx, slot_num);
3678b453a2bSTaylor Simpson             tcg_gen_qemu_st32(hex_store_val32[slot_num],
3688b453a2bSTaylor Simpson                               hex_store_addr[slot_num],
3698b453a2bSTaylor Simpson                               ctx->mem_idx);
3708b453a2bSTaylor Simpson             break;
3718b453a2bSTaylor Simpson         case 8:
372a27c100cSTaylor Simpson             gen_check_store_width(ctx, slot_num);
3738b453a2bSTaylor Simpson             tcg_gen_qemu_st64(hex_store_val64[slot_num],
3748b453a2bSTaylor Simpson                               hex_store_addr[slot_num],
3758b453a2bSTaylor Simpson                               ctx->mem_idx);
3768b453a2bSTaylor Simpson             break;
3778b453a2bSTaylor Simpson         default:
3788b453a2bSTaylor Simpson             {
3798b453a2bSTaylor Simpson                 /*
3808b453a2bSTaylor Simpson                  * If we get to here, we don't know the width at
3818b453a2bSTaylor Simpson                  * TCG generation time, we'll use a helper to
3828b453a2bSTaylor Simpson                  * avoid branching based on the width at runtime.
3838b453a2bSTaylor Simpson                  */
3848b453a2bSTaylor Simpson                 TCGv slot = tcg_const_tl(slot_num);
3858b453a2bSTaylor Simpson                 gen_helper_commit_store(cpu_env, slot);
3868b453a2bSTaylor Simpson                 tcg_temp_free(slot);
3878b453a2bSTaylor Simpson             }
3888b453a2bSTaylor Simpson         }
3898b453a2bSTaylor Simpson         tcg_temp_free(address);
3908b453a2bSTaylor Simpson     }
3918b453a2bSTaylor Simpson     if (is_predicated) {
3928b453a2bSTaylor Simpson         gen_set_label(label_end);
3938b453a2bSTaylor Simpson     }
3948b453a2bSTaylor Simpson }
3958b453a2bSTaylor Simpson 
3968b453a2bSTaylor Simpson static void process_store_log(DisasContext *ctx, Packet *pkt)
3978b453a2bSTaylor Simpson {
3988b453a2bSTaylor Simpson     /*
3998b453a2bSTaylor Simpson      *  When a packet has two stores, the hardware processes
4008b453a2bSTaylor Simpson      *  slot 1 and then slot 2.  This will be important when
4018b453a2bSTaylor Simpson      *  the memory accesses overlap.
4028b453a2bSTaylor Simpson      */
4038b453a2bSTaylor Simpson     if (pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa) {
4048b453a2bSTaylor Simpson         process_store(ctx, pkt, 1);
4058b453a2bSTaylor Simpson     }
4068b453a2bSTaylor Simpson     if (pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa) {
4078b453a2bSTaylor Simpson         process_store(ctx, pkt, 0);
4088b453a2bSTaylor Simpson     }
4098b453a2bSTaylor Simpson }
4108b453a2bSTaylor Simpson 
4118b453a2bSTaylor Simpson /* Zero out a 32-bit cache line */
4128b453a2bSTaylor Simpson static void process_dczeroa(DisasContext *ctx, Packet *pkt)
4138b453a2bSTaylor Simpson {
4148b453a2bSTaylor Simpson     if (pkt->pkt_has_dczeroa) {
4158b453a2bSTaylor Simpson         /* Store 32 bytes of zero starting at (addr & ~0x1f) */
4168b453a2bSTaylor Simpson         TCGv addr = tcg_temp_new();
4178b453a2bSTaylor Simpson         TCGv_i64 zero = tcg_const_i64(0);
4188b453a2bSTaylor Simpson 
4198b453a2bSTaylor Simpson         tcg_gen_andi_tl(addr, hex_dczero_addr, ~0x1f);
4208b453a2bSTaylor Simpson         tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
4218b453a2bSTaylor Simpson         tcg_gen_addi_tl(addr, addr, 8);
4228b453a2bSTaylor Simpson         tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
4238b453a2bSTaylor Simpson         tcg_gen_addi_tl(addr, addr, 8);
4248b453a2bSTaylor Simpson         tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
4258b453a2bSTaylor Simpson         tcg_gen_addi_tl(addr, addr, 8);
4268b453a2bSTaylor Simpson         tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
4278b453a2bSTaylor Simpson 
4288b453a2bSTaylor Simpson         tcg_temp_free(addr);
4298b453a2bSTaylor Simpson         tcg_temp_free_i64(zero);
4308b453a2bSTaylor Simpson     }
4318b453a2bSTaylor Simpson }
4328b453a2bSTaylor Simpson 
4338b453a2bSTaylor Simpson static void update_exec_counters(DisasContext *ctx, Packet *pkt)
4348b453a2bSTaylor Simpson {
4358b453a2bSTaylor Simpson     int num_insns = pkt->num_insns;
4368b453a2bSTaylor Simpson     int num_real_insns = 0;
4378b453a2bSTaylor Simpson 
4388b453a2bSTaylor Simpson     for (int i = 0; i < num_insns; i++) {
4398b453a2bSTaylor Simpson         if (!pkt->insn[i].is_endloop &&
4408b453a2bSTaylor Simpson             !pkt->insn[i].part1 &&
4418b453a2bSTaylor Simpson             !GET_ATTRIB(pkt->insn[i].opcode, A_IT_NOP)) {
4428b453a2bSTaylor Simpson             num_real_insns++;
4438b453a2bSTaylor Simpson         }
4448b453a2bSTaylor Simpson     }
4458b453a2bSTaylor Simpson 
4468b453a2bSTaylor Simpson     ctx->num_packets++;
4478b453a2bSTaylor Simpson     ctx->num_insns += num_real_insns;
4488b453a2bSTaylor Simpson }
4498b453a2bSTaylor Simpson 
4508b453a2bSTaylor Simpson static void gen_exec_counters(DisasContext *ctx)
4518b453a2bSTaylor Simpson {
4528b453a2bSTaylor Simpson     tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_PKT_CNT],
4538b453a2bSTaylor Simpson                     hex_gpr[HEX_REG_QEMU_PKT_CNT], ctx->num_packets);
4548b453a2bSTaylor Simpson     tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_INSN_CNT],
4558b453a2bSTaylor Simpson                     hex_gpr[HEX_REG_QEMU_INSN_CNT], ctx->num_insns);
4568b453a2bSTaylor Simpson }
4578b453a2bSTaylor Simpson 
4588b453a2bSTaylor Simpson static void gen_commit_packet(DisasContext *ctx, Packet *pkt)
4598b453a2bSTaylor Simpson {
4608b453a2bSTaylor Simpson     gen_reg_writes(ctx);
4618b453a2bSTaylor Simpson     gen_pred_writes(ctx, pkt);
4628b453a2bSTaylor Simpson     process_store_log(ctx, pkt);
4638b453a2bSTaylor Simpson     process_dczeroa(ctx, pkt);
4648b453a2bSTaylor Simpson     update_exec_counters(ctx, pkt);
4658b453a2bSTaylor Simpson #if HEX_DEBUG
4668b453a2bSTaylor Simpson     {
4678b453a2bSTaylor Simpson         TCGv has_st0 =
4688b453a2bSTaylor Simpson             tcg_const_tl(pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa);
4698b453a2bSTaylor Simpson         TCGv has_st1 =
4708b453a2bSTaylor Simpson             tcg_const_tl(pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa);
4718b453a2bSTaylor Simpson 
4728b453a2bSTaylor Simpson         /* Handy place to set a breakpoint at the end of execution */
4738b453a2bSTaylor Simpson         gen_helper_debug_commit_end(cpu_env, has_st0, has_st1);
4748b453a2bSTaylor Simpson 
4758b453a2bSTaylor Simpson         tcg_temp_free(has_st0);
4768b453a2bSTaylor Simpson         tcg_temp_free(has_st1);
4778b453a2bSTaylor Simpson     }
4788b453a2bSTaylor Simpson #endif
4798b453a2bSTaylor Simpson 
4808b453a2bSTaylor Simpson     if (pkt->pkt_has_cof) {
4818b453a2bSTaylor Simpson         ctx->base.is_jmp = DISAS_NORETURN;
4828b453a2bSTaylor Simpson     }
4838b453a2bSTaylor Simpson }
4848b453a2bSTaylor Simpson 
4858b453a2bSTaylor Simpson static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)
4868b453a2bSTaylor Simpson {
4878b453a2bSTaylor Simpson     uint32_t words[PACKET_WORDS_MAX];
4888b453a2bSTaylor Simpson     int nwords;
4898b453a2bSTaylor Simpson     Packet pkt;
4908b453a2bSTaylor Simpson     int i;
4918b453a2bSTaylor Simpson 
4928b453a2bSTaylor Simpson     nwords = read_packet_words(env, ctx, words);
4938b453a2bSTaylor Simpson     if (!nwords) {
4948b453a2bSTaylor Simpson         gen_exception(HEX_EXCP_INVALID_PACKET);
4958b453a2bSTaylor Simpson         ctx->base.is_jmp = DISAS_NORETURN;
4968b453a2bSTaylor Simpson         return;
4978b453a2bSTaylor Simpson     }
4988b453a2bSTaylor Simpson 
4998b453a2bSTaylor Simpson     if (decode_packet(nwords, words, &pkt, false) > 0) {
5008b453a2bSTaylor Simpson         HEX_DEBUG_PRINT_PKT(&pkt);
5018b453a2bSTaylor Simpson         gen_start_packet(ctx, &pkt);
5028b453a2bSTaylor Simpson         for (i = 0; i < pkt.num_insns; i++) {
5038b453a2bSTaylor Simpson             gen_insn(env, ctx, &pkt.insn[i], &pkt);
5048b453a2bSTaylor Simpson         }
5058b453a2bSTaylor Simpson         gen_commit_packet(ctx, &pkt);
5068b453a2bSTaylor Simpson         ctx->base.pc_next += pkt.encod_pkt_size_in_bytes;
5078b453a2bSTaylor Simpson     } else {
5088b453a2bSTaylor Simpson         gen_exception(HEX_EXCP_INVALID_PACKET);
5098b453a2bSTaylor Simpson         ctx->base.is_jmp = DISAS_NORETURN;
5108b453a2bSTaylor Simpson     }
5118b453a2bSTaylor Simpson }
5128b453a2bSTaylor Simpson 
5138b453a2bSTaylor Simpson static void hexagon_tr_init_disas_context(DisasContextBase *dcbase,
5148b453a2bSTaylor Simpson                                           CPUState *cs)
5158b453a2bSTaylor Simpson {
5168b453a2bSTaylor Simpson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
5178b453a2bSTaylor Simpson 
5188b453a2bSTaylor Simpson     ctx->mem_idx = MMU_USER_IDX;
5198b453a2bSTaylor Simpson     ctx->num_packets = 0;
5208b453a2bSTaylor Simpson     ctx->num_insns = 0;
5218b453a2bSTaylor Simpson }
5228b453a2bSTaylor Simpson 
5238b453a2bSTaylor Simpson static void hexagon_tr_tb_start(DisasContextBase *db, CPUState *cpu)
5248b453a2bSTaylor Simpson {
5258b453a2bSTaylor Simpson }
5268b453a2bSTaylor Simpson 
5278b453a2bSTaylor Simpson static void hexagon_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
5288b453a2bSTaylor Simpson {
5298b453a2bSTaylor Simpson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
5308b453a2bSTaylor Simpson 
5318b453a2bSTaylor Simpson     tcg_gen_insn_start(ctx->base.pc_next);
5328b453a2bSTaylor Simpson }
5338b453a2bSTaylor Simpson 
5348b453a2bSTaylor Simpson static bool hexagon_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
5358b453a2bSTaylor Simpson                                         const CPUBreakpoint *bp)
5368b453a2bSTaylor Simpson {
5378b453a2bSTaylor Simpson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
5388b453a2bSTaylor Simpson 
5398b453a2bSTaylor Simpson     tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);
5408b453a2bSTaylor Simpson     ctx->base.is_jmp = DISAS_NORETURN;
5418b453a2bSTaylor Simpson     gen_exception_debug();
5428b453a2bSTaylor Simpson     /*
5438b453a2bSTaylor Simpson      * The address covered by the breakpoint must be included in
5448b453a2bSTaylor Simpson      * [tb->pc, tb->pc + tb->size) in order to for it to be
5458b453a2bSTaylor Simpson      * properly cleared -- thus we increment the PC here so that
5468b453a2bSTaylor Simpson      * the logic setting tb->size below does the right thing.
5478b453a2bSTaylor Simpson      */
5488b453a2bSTaylor Simpson     ctx->base.pc_next += 4;
5498b453a2bSTaylor Simpson     return true;
5508b453a2bSTaylor Simpson }
5518b453a2bSTaylor Simpson 
5528b453a2bSTaylor Simpson static bool pkt_crosses_page(CPUHexagonState *env, DisasContext *ctx)
5538b453a2bSTaylor Simpson {
5548b453a2bSTaylor Simpson     target_ulong page_start = ctx->base.pc_first & TARGET_PAGE_MASK;
5558b453a2bSTaylor Simpson     bool found_end = false;
5568b453a2bSTaylor Simpson     int nwords;
5578b453a2bSTaylor Simpson 
5588b453a2bSTaylor Simpson     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
5598b453a2bSTaylor Simpson         uint32_t word = cpu_ldl_code(env,
5608b453a2bSTaylor Simpson                             ctx->base.pc_next + nwords * sizeof(uint32_t));
5618b453a2bSTaylor Simpson         found_end = is_packet_end(word);
5628b453a2bSTaylor Simpson     }
5638b453a2bSTaylor Simpson     uint32_t next_ptr =  ctx->base.pc_next + nwords * sizeof(uint32_t);
5648b453a2bSTaylor Simpson     return found_end && next_ptr - page_start >= TARGET_PAGE_SIZE;
5658b453a2bSTaylor Simpson }
5668b453a2bSTaylor Simpson 
5678b453a2bSTaylor Simpson static void hexagon_tr_translate_packet(DisasContextBase *dcbase, CPUState *cpu)
5688b453a2bSTaylor Simpson {
5698b453a2bSTaylor Simpson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
5708b453a2bSTaylor Simpson     CPUHexagonState *env = cpu->env_ptr;
5718b453a2bSTaylor Simpson 
5728b453a2bSTaylor Simpson     decode_and_translate_packet(env, ctx);
5738b453a2bSTaylor Simpson 
5748b453a2bSTaylor Simpson     if (ctx->base.is_jmp == DISAS_NEXT) {
5758b453a2bSTaylor Simpson         target_ulong page_start = ctx->base.pc_first & TARGET_PAGE_MASK;
5768b453a2bSTaylor Simpson         target_ulong bytes_max = PACKET_WORDS_MAX * sizeof(target_ulong);
5778b453a2bSTaylor Simpson 
5788b453a2bSTaylor Simpson         if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE ||
5798b453a2bSTaylor Simpson             (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE - bytes_max &&
5808b453a2bSTaylor Simpson              pkt_crosses_page(env, ctx))) {
5818b453a2bSTaylor Simpson             ctx->base.is_jmp = DISAS_TOO_MANY;
5828b453a2bSTaylor Simpson         }
5838b453a2bSTaylor Simpson 
5848b453a2bSTaylor Simpson         /*
5858b453a2bSTaylor Simpson          * The CPU log is used to compare against LLDB single stepping,
5868b453a2bSTaylor Simpson          * so end the TLB after every packet.
5878b453a2bSTaylor Simpson          */
588*7d9ab202STaylor Simpson         HexagonCPU *hex_cpu = env_archcpu(env);
5898b453a2bSTaylor Simpson         if (hex_cpu->lldb_compat && qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
5908b453a2bSTaylor Simpson             ctx->base.is_jmp = DISAS_TOO_MANY;
5918b453a2bSTaylor Simpson         }
5928b453a2bSTaylor Simpson     }
5938b453a2bSTaylor Simpson }
5948b453a2bSTaylor Simpson 
5958b453a2bSTaylor Simpson static void hexagon_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
5968b453a2bSTaylor Simpson {
5978b453a2bSTaylor Simpson     DisasContext *ctx = container_of(dcbase, DisasContext, base);
5988b453a2bSTaylor Simpson 
5998b453a2bSTaylor Simpson     switch (ctx->base.is_jmp) {
6008b453a2bSTaylor Simpson     case DISAS_TOO_MANY:
6018b453a2bSTaylor Simpson         gen_exec_counters(ctx);
6028b453a2bSTaylor Simpson         tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);
6038b453a2bSTaylor Simpson         if (ctx->base.singlestep_enabled) {
6048b453a2bSTaylor Simpson             gen_exception_debug();
6058b453a2bSTaylor Simpson         } else {
6068b453a2bSTaylor Simpson             tcg_gen_exit_tb(NULL, 0);
6078b453a2bSTaylor Simpson         }
6088b453a2bSTaylor Simpson         break;
6098b453a2bSTaylor Simpson     case DISAS_NORETURN:
6108b453a2bSTaylor Simpson         gen_exec_counters(ctx);
6118b453a2bSTaylor Simpson         tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
6128b453a2bSTaylor Simpson         if (ctx->base.singlestep_enabled) {
6138b453a2bSTaylor Simpson             gen_exception_debug();
6148b453a2bSTaylor Simpson         } else {
6158b453a2bSTaylor Simpson             tcg_gen_exit_tb(NULL, 0);
6168b453a2bSTaylor Simpson         }
6178b453a2bSTaylor Simpson         break;
6188b453a2bSTaylor Simpson     default:
6198b453a2bSTaylor Simpson         g_assert_not_reached();
6208b453a2bSTaylor Simpson     }
6218b453a2bSTaylor Simpson }
6228b453a2bSTaylor Simpson 
6238b453a2bSTaylor Simpson static void hexagon_tr_disas_log(const DisasContextBase *dcbase, CPUState *cpu)
6248b453a2bSTaylor Simpson {
6258b453a2bSTaylor Simpson     qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first));
6268b453a2bSTaylor Simpson     log_target_disas(cpu, dcbase->pc_first, dcbase->tb->size);
6278b453a2bSTaylor Simpson }
6288b453a2bSTaylor Simpson 
6298b453a2bSTaylor Simpson 
6308b453a2bSTaylor Simpson static const TranslatorOps hexagon_tr_ops = {
6318b453a2bSTaylor Simpson     .init_disas_context = hexagon_tr_init_disas_context,
6328b453a2bSTaylor Simpson     .tb_start           = hexagon_tr_tb_start,
6338b453a2bSTaylor Simpson     .insn_start         = hexagon_tr_insn_start,
6348b453a2bSTaylor Simpson     .breakpoint_check   = hexagon_tr_breakpoint_check,
6358b453a2bSTaylor Simpson     .translate_insn     = hexagon_tr_translate_packet,
6368b453a2bSTaylor Simpson     .tb_stop            = hexagon_tr_tb_stop,
6378b453a2bSTaylor Simpson     .disas_log          = hexagon_tr_disas_log,
6388b453a2bSTaylor Simpson };
6398b453a2bSTaylor Simpson 
6408b453a2bSTaylor Simpson void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns)
6418b453a2bSTaylor Simpson {
6428b453a2bSTaylor Simpson     DisasContext ctx;
6438b453a2bSTaylor Simpson 
6448b453a2bSTaylor Simpson     translator_loop(&hexagon_tr_ops, &ctx.base, cs, tb, max_insns);
6458b453a2bSTaylor Simpson }
6468b453a2bSTaylor Simpson 
6478b453a2bSTaylor Simpson #define NAME_LEN               64
6488b453a2bSTaylor Simpson static char new_value_names[TOTAL_PER_THREAD_REGS][NAME_LEN];
6498b453a2bSTaylor Simpson #if HEX_DEBUG
6508b453a2bSTaylor Simpson static char reg_written_names[TOTAL_PER_THREAD_REGS][NAME_LEN];
6518b453a2bSTaylor Simpson #endif
6528b453a2bSTaylor Simpson static char new_pred_value_names[NUM_PREGS][NAME_LEN];
6538b453a2bSTaylor Simpson static char store_addr_names[STORES_MAX][NAME_LEN];
6548b453a2bSTaylor Simpson static char store_width_names[STORES_MAX][NAME_LEN];
6558b453a2bSTaylor Simpson static char store_val32_names[STORES_MAX][NAME_LEN];
6568b453a2bSTaylor Simpson static char store_val64_names[STORES_MAX][NAME_LEN];
6578b453a2bSTaylor Simpson 
6588b453a2bSTaylor Simpson void hexagon_translate_init(void)
6598b453a2bSTaylor Simpson {
6608b453a2bSTaylor Simpson     int i;
6618b453a2bSTaylor Simpson 
6628b453a2bSTaylor Simpson     opcode_init();
6638b453a2bSTaylor Simpson 
6648b453a2bSTaylor Simpson #if HEX_DEBUG
6658b453a2bSTaylor Simpson     if (!qemu_logfile) {
6668b453a2bSTaylor Simpson         qemu_set_log(qemu_loglevel);
6678b453a2bSTaylor Simpson     }
6688b453a2bSTaylor Simpson #endif
6698b453a2bSTaylor Simpson 
6708b453a2bSTaylor Simpson     for (i = 0; i < TOTAL_PER_THREAD_REGS; i++) {
6718b453a2bSTaylor Simpson         hex_gpr[i] = tcg_global_mem_new(cpu_env,
6728b453a2bSTaylor Simpson             offsetof(CPUHexagonState, gpr[i]),
6738b453a2bSTaylor Simpson             hexagon_regnames[i]);
6748b453a2bSTaylor Simpson 
6758b453a2bSTaylor Simpson         snprintf(new_value_names[i], NAME_LEN, "new_%s", hexagon_regnames[i]);
6768b453a2bSTaylor Simpson         hex_new_value[i] = tcg_global_mem_new(cpu_env,
6778b453a2bSTaylor Simpson             offsetof(CPUHexagonState, new_value[i]),
6788b453a2bSTaylor Simpson             new_value_names[i]);
6798b453a2bSTaylor Simpson 
6808b453a2bSTaylor Simpson #if HEX_DEBUG
6818b453a2bSTaylor Simpson         snprintf(reg_written_names[i], NAME_LEN, "reg_written_%s",
6828b453a2bSTaylor Simpson                  hexagon_regnames[i]);
6838b453a2bSTaylor Simpson         hex_reg_written[i] = tcg_global_mem_new(cpu_env,
6848b453a2bSTaylor Simpson             offsetof(CPUHexagonState, reg_written[i]),
6858b453a2bSTaylor Simpson             reg_written_names[i]);
6868b453a2bSTaylor Simpson #endif
6878b453a2bSTaylor Simpson     }
6888b453a2bSTaylor Simpson     for (i = 0; i < NUM_PREGS; i++) {
6898b453a2bSTaylor Simpson         hex_pred[i] = tcg_global_mem_new(cpu_env,
6908b453a2bSTaylor Simpson             offsetof(CPUHexagonState, pred[i]),
6918b453a2bSTaylor Simpson             hexagon_prednames[i]);
6928b453a2bSTaylor Simpson 
6938b453a2bSTaylor Simpson         snprintf(new_pred_value_names[i], NAME_LEN, "new_pred_%s",
6948b453a2bSTaylor Simpson                  hexagon_prednames[i]);
6958b453a2bSTaylor Simpson         hex_new_pred_value[i] = tcg_global_mem_new(cpu_env,
6968b453a2bSTaylor Simpson             offsetof(CPUHexagonState, new_pred_value[i]),
6978b453a2bSTaylor Simpson             new_pred_value_names[i]);
6988b453a2bSTaylor Simpson     }
6998b453a2bSTaylor Simpson     hex_pred_written = tcg_global_mem_new(cpu_env,
7008b453a2bSTaylor Simpson         offsetof(CPUHexagonState, pred_written), "pred_written");
7018b453a2bSTaylor Simpson     hex_next_PC = tcg_global_mem_new(cpu_env,
7028b453a2bSTaylor Simpson         offsetof(CPUHexagonState, next_PC), "next_PC");
7038b453a2bSTaylor Simpson     hex_this_PC = tcg_global_mem_new(cpu_env,
7048b453a2bSTaylor Simpson         offsetof(CPUHexagonState, this_PC), "this_PC");
7058b453a2bSTaylor Simpson     hex_slot_cancelled = tcg_global_mem_new(cpu_env,
7068b453a2bSTaylor Simpson         offsetof(CPUHexagonState, slot_cancelled), "slot_cancelled");
7078b453a2bSTaylor Simpson     hex_branch_taken = tcg_global_mem_new(cpu_env,
7088b453a2bSTaylor Simpson         offsetof(CPUHexagonState, branch_taken), "branch_taken");
7098b453a2bSTaylor Simpson     hex_pkt_has_store_s1 = tcg_global_mem_new(cpu_env,
7108b453a2bSTaylor Simpson         offsetof(CPUHexagonState, pkt_has_store_s1), "pkt_has_store_s1");
7118b453a2bSTaylor Simpson     hex_dczero_addr = tcg_global_mem_new(cpu_env,
7128b453a2bSTaylor Simpson         offsetof(CPUHexagonState, dczero_addr), "dczero_addr");
7138b453a2bSTaylor Simpson     hex_llsc_addr = tcg_global_mem_new(cpu_env,
7148b453a2bSTaylor Simpson         offsetof(CPUHexagonState, llsc_addr), "llsc_addr");
7158b453a2bSTaylor Simpson     hex_llsc_val = tcg_global_mem_new(cpu_env,
7168b453a2bSTaylor Simpson         offsetof(CPUHexagonState, llsc_val), "llsc_val");
7178b453a2bSTaylor Simpson     hex_llsc_val_i64 = tcg_global_mem_new_i64(cpu_env,
7188b453a2bSTaylor Simpson         offsetof(CPUHexagonState, llsc_val_i64), "llsc_val_i64");
7198b453a2bSTaylor Simpson     for (i = 0; i < STORES_MAX; i++) {
7208b453a2bSTaylor Simpson         snprintf(store_addr_names[i], NAME_LEN, "store_addr_%d", i);
7218b453a2bSTaylor Simpson         hex_store_addr[i] = tcg_global_mem_new(cpu_env,
7228b453a2bSTaylor Simpson             offsetof(CPUHexagonState, mem_log_stores[i].va),
7238b453a2bSTaylor Simpson             store_addr_names[i]);
7248b453a2bSTaylor Simpson 
7258b453a2bSTaylor Simpson         snprintf(store_width_names[i], NAME_LEN, "store_width_%d", i);
7268b453a2bSTaylor Simpson         hex_store_width[i] = tcg_global_mem_new(cpu_env,
7278b453a2bSTaylor Simpson             offsetof(CPUHexagonState, mem_log_stores[i].width),
7288b453a2bSTaylor Simpson             store_width_names[i]);
7298b453a2bSTaylor Simpson 
7308b453a2bSTaylor Simpson         snprintf(store_val32_names[i], NAME_LEN, "store_val32_%d", i);
7318b453a2bSTaylor Simpson         hex_store_val32[i] = tcg_global_mem_new(cpu_env,
7328b453a2bSTaylor Simpson             offsetof(CPUHexagonState, mem_log_stores[i].data32),
7338b453a2bSTaylor Simpson             store_val32_names[i]);
7348b453a2bSTaylor Simpson 
7358b453a2bSTaylor Simpson         snprintf(store_val64_names[i], NAME_LEN, "store_val64_%d", i);
7368b453a2bSTaylor Simpson         hex_store_val64[i] = tcg_global_mem_new_i64(cpu_env,
7378b453a2bSTaylor Simpson             offsetof(CPUHexagonState, mem_log_stores[i].data64),
7388b453a2bSTaylor Simpson             store_val64_names[i]);
7398b453a2bSTaylor Simpson     }
7408b453a2bSTaylor Simpson }
741