Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * LoongArch emulation for QEMU - main translation routines. |
| 4 | * |
| 5 | * Copyright (c) 2021 Loongson Technology Corporation Limited |
| 6 | */ |
| 7 | |
| 8 | #include "qemu/osdep.h" |
| 9 | #include "cpu.h" |
| 10 | #include "tcg/tcg-op.h" |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 11 | #include "tcg/tcg-op-gvec.h" |
Richard Henderson | d654e92 | 2023-04-01 21:11:29 -0700 | [diff] [blame] | 12 | #include "exec/translation-block.h" |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 13 | #include "exec/translator.h" |
| 14 | #include "exec/helper-proto.h" |
| 15 | #include "exec/helper-gen.h" |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 16 | #include "exec/log.h" |
| 17 | #include "qemu/qemu-print.h" |
Song Gao | d578ca6 | 2022-06-06 20:43:00 +0800 | [diff] [blame] | 18 | #include "fpu/softfloat.h" |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 19 | #include "translate.h" |
| 20 | #include "internals.h" |
Song Gao | 008a3b1 | 2023-09-14 10:25:59 +0800 | [diff] [blame] | 21 | #include "vec.h" |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 22 | |
| 23 | /* Global register indices */ |
| 24 | TCGv cpu_gpr[32], cpu_pc; |
| 25 | static TCGv cpu_lladdr, cpu_llval; |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 26 | |
Richard Henderson | d53106c | 2023-03-31 10:37:04 -0700 | [diff] [blame] | 27 | #define HELPER_H "helper.h" |
| 28 | #include "exec/helper-info.c.inc" |
| 29 | #undef HELPER_H |
| 30 | |
Xiaojuan Yang | 5b1dedf | 2022-06-06 20:43:15 +0800 | [diff] [blame] | 31 | #define DISAS_STOP DISAS_TARGET_0 |
| 32 | #define DISAS_EXIT DISAS_TARGET_1 |
| 33 | #define DISAS_EXIT_UPDATE DISAS_TARGET_2 |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 34 | |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 35 | static inline int vec_full_offset(int regno) |
| 36 | { |
| 37 | return offsetof(CPULoongArchState, fpr[regno]); |
| 38 | } |
| 39 | |
Song Gao | f5ce2c8 | 2023-09-14 10:26:39 +0800 | [diff] [blame] | 40 | static inline int vec_reg_offset(int regno, int index, MemOp mop) |
| 41 | { |
| 42 | const uint8_t size = 1 << mop; |
| 43 | int offs = index * size; |
| 44 | |
| 45 | if (HOST_BIG_ENDIAN && size < 8 ) { |
| 46 | offs ^= (8 - size); |
| 47 | } |
| 48 | |
| 49 | return offs + vec_full_offset(regno); |
| 50 | } |
| 51 | |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 52 | static inline void get_vreg64(TCGv_i64 dest, int regno, int index) |
| 53 | { |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 54 | tcg_gen_ld_i64(dest, tcg_env, |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 55 | offsetof(CPULoongArchState, fpr[regno].vreg.D(index))); |
| 56 | } |
| 57 | |
| 58 | static inline void set_vreg64(TCGv_i64 src, int regno, int index) |
| 59 | { |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 60 | tcg_gen_st_i64(src, tcg_env, |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 61 | offsetof(CPULoongArchState, fpr[regno].vreg.D(index))); |
| 62 | } |
| 63 | |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 64 | static inline int plus_1(DisasContext *ctx, int x) |
| 65 | { |
| 66 | return x + 1; |
| 67 | } |
| 68 | |
Song Gao | 843b627 | 2023-05-04 20:28:07 +0800 | [diff] [blame] | 69 | static inline int shl_1(DisasContext *ctx, int x) |
| 70 | { |
| 71 | return x << 1; |
| 72 | } |
| 73 | |
Song Gao | bb79174 | 2022-06-06 20:42:57 +0800 | [diff] [blame] | 74 | static inline int shl_2(DisasContext *ctx, int x) |
| 75 | { |
| 76 | return x << 2; |
| 77 | } |
| 78 | |
Song Gao | 843b627 | 2023-05-04 20:28:07 +0800 | [diff] [blame] | 79 | static inline int shl_3(DisasContext *ctx, int x) |
| 80 | { |
| 81 | return x << 3; |
| 82 | } |
| 83 | |
Song Gao | d578ca6 | 2022-06-06 20:43:00 +0800 | [diff] [blame] | 84 | /* |
| 85 | * LoongArch the upper 32 bits are undefined ("can be any value"). |
| 86 | * QEMU chooses to nanbox, because it is most likely to show guest bugs early. |
| 87 | */ |
| 88 | static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in) |
| 89 | { |
| 90 | tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32)); |
| 91 | } |
| 92 | |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 93 | void generate_exception(DisasContext *ctx, int excp) |
| 94 | { |
| 95 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 96 | gen_helper_raise_exception(tcg_env, tcg_constant_i32(excp)); |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 97 | ctx->base.is_jmp = DISAS_NORETURN; |
| 98 | } |
| 99 | |
| 100 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
| 101 | { |
Jiajie Chen | 7033c0e | 2023-08-22 09:13:55 +0200 | [diff] [blame] | 102 | if (ctx->va32) { |
| 103 | dest = (uint32_t) dest; |
| 104 | } |
| 105 | |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 106 | if (translator_use_goto_tb(&ctx->base, dest)) { |
| 107 | tcg_gen_goto_tb(n); |
| 108 | tcg_gen_movi_tl(cpu_pc, dest); |
| 109 | tcg_gen_exit_tb(ctx->base.tb, n); |
| 110 | } else { |
| 111 | tcg_gen_movi_tl(cpu_pc, dest); |
| 112 | tcg_gen_lookup_and_goto_ptr(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static void loongarch_tr_init_disas_context(DisasContextBase *dcbase, |
| 117 | CPUState *cs) |
| 118 | { |
| 119 | int64_t bound; |
Richard Henderson | b77af26 | 2023-09-13 17:22:49 -0700 | [diff] [blame] | 120 | CPULoongArchState *env = cpu_env(cs); |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 121 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
| 122 | |
| 123 | ctx->page_start = ctx->base.pc_first & TARGET_PAGE_MASK; |
Rui Wang | c8885b8 | 2022-11-07 10:45:25 +0800 | [diff] [blame] | 124 | ctx->plv = ctx->base.tb->flags & HW_FLAGS_PLV_MASK; |
Rui Wang | b4bda20 | 2022-11-04 12:05:16 +0800 | [diff] [blame] | 125 | if (ctx->base.tb->flags & HW_FLAGS_CRMD_PG) { |
Rui Wang | c8885b8 | 2022-11-07 10:45:25 +0800 | [diff] [blame] | 126 | ctx->mem_idx = ctx->plv; |
Rui Wang | b4bda20 | 2022-11-04 12:05:16 +0800 | [diff] [blame] | 127 | } else { |
Rui Wang | c8885b8 | 2022-11-07 10:45:25 +0800 | [diff] [blame] | 128 | ctx->mem_idx = MMU_IDX_DA; |
Rui Wang | b4bda20 | 2022-11-04 12:05:16 +0800 | [diff] [blame] | 129 | } |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 130 | |
| 131 | /* Bound the number of insns to execute to those left on the page. */ |
| 132 | bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; |
| 133 | ctx->base.max_insns = MIN(ctx->base.max_insns, bound); |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 134 | |
Song Gao | 57b4f1a | 2023-05-04 20:27:30 +0800 | [diff] [blame] | 135 | if (FIELD_EX64(env->cpucfg[2], CPUCFG2, LSX)) { |
| 136 | ctx->vl = LSX_LEN; |
| 137 | } |
| 138 | |
Song Gao | 269ca39a | 2023-09-14 10:26:02 +0800 | [diff] [blame] | 139 | if (FIELD_EX64(env->cpucfg[2], CPUCFG2, LASX)) { |
| 140 | ctx->vl = LASX_LEN; |
| 141 | } |
| 142 | |
Jiajie Chen | 3966582 | 2023-08-22 09:13:50 +0200 | [diff] [blame] | 143 | ctx->la64 = is_la64(env); |
| 144 | ctx->va32 = (ctx->base.tb->flags & HW_FLAGS_VA32) != 0; |
| 145 | |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 146 | ctx->zero = tcg_constant_tl(0); |
Song Gao | c0c0461 | 2023-08-22 09:19:52 +0200 | [diff] [blame] | 147 | |
| 148 | ctx->cpucfg1 = env->cpucfg[1]; |
Song Gao | 95e2ca2 | 2023-08-22 09:19:55 +0200 | [diff] [blame] | 149 | ctx->cpucfg2 = env->cpucfg[2]; |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static void loongarch_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | static void loongarch_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) |
| 157 | { |
| 158 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
| 159 | |
| 160 | tcg_gen_insn_start(ctx->base.pc_next); |
| 161 | } |
| 162 | |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 163 | /* |
| 164 | * Wrappers for getting reg values. |
| 165 | * |
| 166 | * The $zero register does not have cpu_gpr[0] allocated -- we supply the |
| 167 | * constant zero as a source, and an uninitialized sink as destination. |
| 168 | * |
| 169 | * Further, we may provide an extension for word operations. |
| 170 | */ |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 171 | static TCGv gpr_src(DisasContext *ctx, int reg_num, DisasExtend src_ext) |
| 172 | { |
| 173 | TCGv t; |
| 174 | |
| 175 | if (reg_num == 0) { |
| 176 | return ctx->zero; |
| 177 | } |
| 178 | |
| 179 | switch (src_ext) { |
| 180 | case EXT_NONE: |
| 181 | return cpu_gpr[reg_num]; |
| 182 | case EXT_SIGN: |
Richard Henderson | 60a7e25 | 2023-02-24 19:05:39 -1000 | [diff] [blame] | 183 | t = tcg_temp_new(); |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 184 | tcg_gen_ext32s_tl(t, cpu_gpr[reg_num]); |
| 185 | return t; |
| 186 | case EXT_ZERO: |
Richard Henderson | 60a7e25 | 2023-02-24 19:05:39 -1000 | [diff] [blame] | 187 | t = tcg_temp_new(); |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 188 | tcg_gen_ext32u_tl(t, cpu_gpr[reg_num]); |
| 189 | return t; |
| 190 | } |
| 191 | g_assert_not_reached(); |
| 192 | } |
| 193 | |
| 194 | static TCGv gpr_dst(DisasContext *ctx, int reg_num, DisasExtend dst_ext) |
| 195 | { |
| 196 | if (reg_num == 0 || dst_ext) { |
Richard Henderson | 60a7e25 | 2023-02-24 19:05:39 -1000 | [diff] [blame] | 197 | return tcg_temp_new(); |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 198 | } |
| 199 | return cpu_gpr[reg_num]; |
| 200 | } |
| 201 | |
| 202 | static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext) |
| 203 | { |
| 204 | if (reg_num != 0) { |
| 205 | switch (dst_ext) { |
| 206 | case EXT_NONE: |
| 207 | tcg_gen_mov_tl(cpu_gpr[reg_num], t); |
| 208 | break; |
| 209 | case EXT_SIGN: |
| 210 | tcg_gen_ext32s_tl(cpu_gpr[reg_num], t); |
| 211 | break; |
| 212 | case EXT_ZERO: |
| 213 | tcg_gen_ext32u_tl(cpu_gpr[reg_num], t); |
| 214 | break; |
| 215 | default: |
| 216 | g_assert_not_reached(); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Song Gao | 4854bbb | 2023-05-04 20:28:09 +0800 | [diff] [blame] | 221 | static TCGv get_fpr(DisasContext *ctx, int reg_num) |
| 222 | { |
| 223 | TCGv t = tcg_temp_new(); |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 224 | tcg_gen_ld_i64(t, tcg_env, |
Song Gao | 4854bbb | 2023-05-04 20:28:09 +0800 | [diff] [blame] | 225 | offsetof(CPULoongArchState, fpr[reg_num].vreg.D(0))); |
| 226 | return t; |
| 227 | } |
| 228 | |
| 229 | static void set_fpr(int reg_num, TCGv val) |
| 230 | { |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 231 | tcg_gen_st_i64(val, tcg_env, |
Song Gao | 4854bbb | 2023-05-04 20:28:09 +0800 | [diff] [blame] | 232 | offsetof(CPULoongArchState, fpr[reg_num].vreg.D(0))); |
| 233 | } |
| 234 | |
Jiajie Chen | 34423c0 | 2023-08-22 09:13:51 +0200 | [diff] [blame] | 235 | static TCGv make_address_x(DisasContext *ctx, TCGv base, TCGv addend) |
| 236 | { |
| 237 | TCGv temp = NULL; |
| 238 | |
Jiajie Chen | 7033c0e | 2023-08-22 09:13:55 +0200 | [diff] [blame] | 239 | if (addend || ctx->va32) { |
Jiajie Chen | 34423c0 | 2023-08-22 09:13:51 +0200 | [diff] [blame] | 240 | temp = tcg_temp_new(); |
Jiajie Chen | 7033c0e | 2023-08-22 09:13:55 +0200 | [diff] [blame] | 241 | } |
| 242 | if (addend) { |
Jiajie Chen | 34423c0 | 2023-08-22 09:13:51 +0200 | [diff] [blame] | 243 | tcg_gen_add_tl(temp, base, addend); |
| 244 | base = temp; |
| 245 | } |
Jiajie Chen | 7033c0e | 2023-08-22 09:13:55 +0200 | [diff] [blame] | 246 | if (ctx->va32) { |
| 247 | tcg_gen_ext32u_tl(temp, base); |
| 248 | base = temp; |
| 249 | } |
Jiajie Chen | 34423c0 | 2023-08-22 09:13:51 +0200 | [diff] [blame] | 250 | return base; |
| 251 | } |
| 252 | |
Jiajie Chen | c5af662 | 2023-08-22 09:13:52 +0200 | [diff] [blame] | 253 | static TCGv make_address_i(DisasContext *ctx, TCGv base, target_long ofs) |
| 254 | { |
| 255 | TCGv addend = ofs ? tcg_constant_tl(ofs) : NULL; |
| 256 | return make_address_x(ctx, base, addend); |
| 257 | } |
| 258 | |
Jiajie Chen | 5a7ce25 | 2023-08-22 09:13:53 +0200 | [diff] [blame] | 259 | static uint64_t make_address_pc(DisasContext *ctx, uint64_t addr) |
| 260 | { |
Jiajie Chen | 6496269 | 2023-08-22 09:19:50 +0200 | [diff] [blame] | 261 | if (ctx->va32) { |
| 262 | addr = (int32_t)addr; |
| 263 | } |
Jiajie Chen | 5a7ce25 | 2023-08-22 09:13:53 +0200 | [diff] [blame] | 264 | return addr; |
| 265 | } |
| 266 | |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 267 | #include "decode-insns.c.inc" |
| 268 | #include "insn_trans/trans_arith.c.inc" |
Song Gao | 63cfcd4 | 2022-06-06 20:42:55 +0800 | [diff] [blame] | 269 | #include "insn_trans/trans_shift.c.inc" |
Song Gao | ad08cb3 | 2022-06-06 20:42:56 +0800 | [diff] [blame] | 270 | #include "insn_trans/trans_bit.c.inc" |
Song Gao | bb79174 | 2022-06-06 20:42:57 +0800 | [diff] [blame] | 271 | #include "insn_trans/trans_memory.c.inc" |
Song Gao | 94b02d5 | 2022-06-06 20:42:58 +0800 | [diff] [blame] | 272 | #include "insn_trans/trans_atomic.c.inc" |
Song Gao | 8708a04 | 2022-06-06 20:42:59 +0800 | [diff] [blame] | 273 | #include "insn_trans/trans_extra.c.inc" |
Song Gao | d578ca6 | 2022-06-06 20:43:00 +0800 | [diff] [blame] | 274 | #include "insn_trans/trans_farith.c.inc" |
Song Gao | 9b74107 | 2022-06-06 20:43:01 +0800 | [diff] [blame] | 275 | #include "insn_trans/trans_fcmp.c.inc" |
Song Gao | 7c1f887 | 2022-06-06 20:43:02 +0800 | [diff] [blame] | 276 | #include "insn_trans/trans_fcnv.c.inc" |
Song Gao | b7dabd5 | 2022-06-06 20:43:03 +0800 | [diff] [blame] | 277 | #include "insn_trans/trans_fmov.c.inc" |
Song Gao | e616bdf | 2022-06-06 20:43:04 +0800 | [diff] [blame] | 278 | #include "insn_trans/trans_fmemory.c.inc" |
Song Gao | ee86bd5 | 2022-06-06 20:43:05 +0800 | [diff] [blame] | 279 | #include "insn_trans/trans_branch.c.inc" |
Xiaojuan Yang | 5b1dedf | 2022-06-06 20:43:15 +0800 | [diff] [blame] | 280 | #include "insn_trans/trans_privileged.c.inc" |
Song Gao | 1dc33f2 | 2023-09-14 10:25:49 +0800 | [diff] [blame] | 281 | #include "insn_trans/trans_vec.c.inc" |
Song Gao | 143d678 | 2022-06-06 20:42:54 +0800 | [diff] [blame] | 282 | |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 283 | static void loongarch_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) |
| 284 | { |
Richard Henderson | b77af26 | 2023-09-13 17:22:49 -0700 | [diff] [blame] | 285 | CPULoongArchState *env = cpu_env(cs); |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 286 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
| 287 | |
tanhongze | ec28dd6 | 2023-03-30 20:46:00 +0800 | [diff] [blame] | 288 | ctx->opcode = translator_ldl(env, &ctx->base, ctx->base.pc_next); |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 289 | |
| 290 | if (!decode(ctx, ctx->opcode)) { |
| 291 | qemu_log_mask(LOG_UNIMP, "Error: unknown opcode. " |
| 292 | TARGET_FMT_lx ": 0x%x\n", |
| 293 | ctx->base.pc_next, ctx->opcode); |
| 294 | generate_exception(ctx, EXCCODE_INE); |
| 295 | } |
| 296 | |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 297 | ctx->base.pc_next += 4; |
Jiajie Chen | 7033c0e | 2023-08-22 09:13:55 +0200 | [diff] [blame] | 298 | |
| 299 | if (ctx->va32) { |
| 300 | ctx->base.pc_next = (uint32_t)ctx->base.pc_next; |
| 301 | } |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static void loongarch_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) |
| 305 | { |
| 306 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
| 307 | |
| 308 | switch (ctx->base.is_jmp) { |
| 309 | case DISAS_STOP: |
| 310 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); |
| 311 | tcg_gen_lookup_and_goto_ptr(); |
| 312 | break; |
| 313 | case DISAS_TOO_MANY: |
| 314 | gen_goto_tb(ctx, 0, ctx->base.pc_next); |
| 315 | break; |
| 316 | case DISAS_NORETURN: |
| 317 | break; |
Xiaojuan Yang | 5b1dedf | 2022-06-06 20:43:15 +0800 | [diff] [blame] | 318 | case DISAS_EXIT_UPDATE: |
| 319 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); |
| 320 | QEMU_FALLTHROUGH; |
| 321 | case DISAS_EXIT: |
| 322 | tcg_gen_exit_tb(NULL, 0); |
| 323 | break; |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 324 | default: |
| 325 | g_assert_not_reached(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | static void loongarch_tr_disas_log(const DisasContextBase *dcbase, |
| 330 | CPUState *cpu, FILE *logfile) |
| 331 | { |
| 332 | qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first)); |
| 333 | target_disas(logfile, cpu, dcbase->pc_first, dcbase->tb->size); |
| 334 | } |
| 335 | |
| 336 | static const TranslatorOps loongarch_tr_ops = { |
| 337 | .init_disas_context = loongarch_tr_init_disas_context, |
| 338 | .tb_start = loongarch_tr_tb_start, |
| 339 | .insn_start = loongarch_tr_insn_start, |
| 340 | .translate_insn = loongarch_tr_translate_insn, |
| 341 | .tb_stop = loongarch_tr_tb_stop, |
| 342 | .disas_log = loongarch_tr_disas_log, |
| 343 | }; |
| 344 | |
Richard Henderson | 597f9b2 | 2023-01-28 15:19:22 -1000 | [diff] [blame] | 345 | void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, |
Richard Henderson | 306c872 | 2022-08-11 13:48:03 -0700 | [diff] [blame] | 346 | target_ulong pc, void *host_pc) |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 347 | { |
| 348 | DisasContext ctx; |
| 349 | |
Richard Henderson | 306c872 | 2022-08-11 13:48:03 -0700 | [diff] [blame] | 350 | translator_loop(cs, tb, max_insns, pc, host_pc, |
| 351 | &loongarch_tr_ops, &ctx.base); |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void loongarch_translate_init(void) |
| 355 | { |
| 356 | int i; |
| 357 | |
| 358 | cpu_gpr[0] = NULL; |
| 359 | for (i = 1; i < 32; i++) { |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 360 | cpu_gpr[i] = tcg_global_mem_new(tcg_env, |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 361 | offsetof(CPULoongArchState, gpr[i]), |
| 362 | regnames[i]); |
| 363 | } |
| 364 | |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 365 | cpu_pc = tcg_global_mem_new(tcg_env, offsetof(CPULoongArchState, pc), "pc"); |
| 366 | cpu_lladdr = tcg_global_mem_new(tcg_env, |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 367 | offsetof(CPULoongArchState, lladdr), "lladdr"); |
Richard Henderson | ad75a51 | 2023-09-13 16:37:36 -0700 | [diff] [blame] | 368 | cpu_llval = tcg_global_mem_new(tcg_env, |
Song Gao | f8da88d | 2022-06-06 20:42:53 +0800 | [diff] [blame] | 369 | offsetof(CPULoongArchState, llval), "llval"); |
| 370 | } |