1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (c) 2021 Loongson Technology Corporation Limited
6 static bool gen_load(DisasContext *ctx, arg_rr_i *a, MemOp mop)
8 TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
9 TCGv addr = gpr_src(ctx, a->rj, EXT_NONE);
11 addr = make_address_i(ctx, addr, a->imm);
13 tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop);
14 gen_set_gpr(a->rd, dest, EXT_NONE);
18 static bool gen_store(DisasContext *ctx, arg_rr_i *a, MemOp mop)
20 TCGv data = gpr_src(ctx, a->rd, EXT_NONE);
21 TCGv addr = gpr_src(ctx, a->rj, EXT_NONE);
23 addr = make_address_i(ctx, addr, a->imm);
25 tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop);
29 static bool gen_loadx(DisasContext *ctx, arg_rrr *a, MemOp mop)
31 TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
32 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
33 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
34 TCGv addr = make_address_x(ctx, src1, src2);
36 tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop);
37 gen_set_gpr(a->rd, dest, EXT_NONE);
42 static bool gen_storex(DisasContext *ctx, arg_rrr *a, MemOp mop)
44 TCGv data = gpr_src(ctx, a->rd, EXT_NONE);
45 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
46 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
47 TCGv addr = make_address_x(ctx, src1, src2);
49 tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop);
54 static bool gen_load_gt(DisasContext *ctx, arg_rrr *a, MemOp mop)
56 TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
57 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
58 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
60 gen_helper_asrtgt_d(tcg_env, src1, src2);
61 src1 = make_address_i(ctx, src1, 0);
62 tcg_gen_qemu_ld_tl(dest, src1, ctx->mem_idx, mop);
63 gen_set_gpr(a->rd, dest, EXT_NONE);
68 static bool gen_load_le(DisasContext *ctx, arg_rrr *a, MemOp mop)
70 TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
71 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
72 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
74 gen_helper_asrtle_d(tcg_env, src1, src2);
75 src1 = make_address_i(ctx, src1, 0);
76 tcg_gen_qemu_ld_tl(dest, src1, ctx->mem_idx, mop);
77 gen_set_gpr(a->rd, dest, EXT_NONE);
82 static bool gen_store_gt(DisasContext *ctx, arg_rrr *a, MemOp mop)
84 TCGv data = gpr_src(ctx, a->rd, EXT_NONE);
85 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
86 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
88 gen_helper_asrtgt_d(tcg_env, src1, src2);
89 src1 = make_address_i(ctx, src1, 0);
90 tcg_gen_qemu_st_tl(data, src1, ctx->mem_idx, mop);
95 static bool gen_store_le(DisasContext *ctx, arg_rrr *a, MemOp mop)
97 TCGv data = gpr_src(ctx, a->rd, EXT_NONE);
98 TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
99 TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
101 gen_helper_asrtle_d(tcg_env, src1, src2);
102 src1 = make_address_i(ctx, src1, 0);
103 tcg_gen_qemu_st_tl(data, src1, ctx->mem_idx, mop);
108 static bool trans_preld(DisasContext *ctx, arg_preld *a)
113 static bool trans_dbar(DisasContext *ctx, arg_dbar * a)
115 tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
119 static bool trans_ibar(DisasContext *ctx, arg_ibar *a)
121 ctx->base.is_jmp = DISAS_STOP;
125 static bool gen_ldptr(DisasContext *ctx, arg_rr_i *a, MemOp mop)
127 TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
128 TCGv addr = gpr_src(ctx, a->rj, EXT_NONE);
130 addr = make_address_i(ctx, addr, a->imm);
132 tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, mop);
133 gen_set_gpr(a->rd, dest, EXT_NONE);
137 static bool gen_stptr(DisasContext *ctx, arg_rr_i *a, MemOp mop)
139 TCGv data = gpr_src(ctx, a->rd, EXT_NONE);
140 TCGv addr = gpr_src(ctx, a->rj, EXT_NONE);
142 addr = make_address_i(ctx, addr, a->imm);
144 tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, mop);
148 TRANS(ld_b, ALL, gen_load, MO_SB)
149 TRANS(ld_h, ALL, gen_load, MO_TESW)
150 TRANS(ld_w, ALL, gen_load, MO_TESL)
151 TRANS(ld_d, 64, gen_load, MO_TEUQ)
152 TRANS(st_b, ALL, gen_store, MO_UB)
153 TRANS(st_h, ALL, gen_store, MO_TEUW)
154 TRANS(st_w, ALL, gen_store, MO_TEUL)
155 TRANS(st_d, 64, gen_store, MO_TEUQ)
156 TRANS(ld_bu, ALL, gen_load, MO_UB)
157 TRANS(ld_hu, ALL, gen_load, MO_TEUW)
158 TRANS(ld_wu, 64, gen_load, MO_TEUL)
159 TRANS(ldx_b, 64, gen_loadx, MO_SB)
160 TRANS(ldx_h, 64, gen_loadx, MO_TESW)
161 TRANS(ldx_w, 64, gen_loadx, MO_TESL)
162 TRANS(ldx_d, 64, gen_loadx, MO_TEUQ)
163 TRANS(stx_b, 64, gen_storex, MO_UB)
164 TRANS(stx_h, 64, gen_storex, MO_TEUW)
165 TRANS(stx_w, 64, gen_storex, MO_TEUL)
166 TRANS(stx_d, 64, gen_storex, MO_TEUQ)
167 TRANS(ldx_bu, 64, gen_loadx, MO_UB)
168 TRANS(ldx_hu, 64, gen_loadx, MO_TEUW)
169 TRANS(ldx_wu, 64, gen_loadx, MO_TEUL)
170 TRANS(ldptr_w, 64, gen_ldptr, MO_TESL)
171 TRANS(stptr_w, 64, gen_stptr, MO_TEUL)
172 TRANS(ldptr_d, 64, gen_ldptr, MO_TEUQ)
173 TRANS(stptr_d, 64, gen_stptr, MO_TEUQ)
174 TRANS(ldgt_b, 64, gen_load_gt, MO_SB)
175 TRANS(ldgt_h, 64, gen_load_gt, MO_TESW)
176 TRANS(ldgt_w, 64, gen_load_gt, MO_TESL)
177 TRANS(ldgt_d, 64, gen_load_gt, MO_TEUQ)
178 TRANS(ldle_b, 64, gen_load_le, MO_SB)
179 TRANS(ldle_h, 64, gen_load_le, MO_TESW)
180 TRANS(ldle_w, 64, gen_load_le, MO_TESL)
181 TRANS(ldle_d, 64, gen_load_le, MO_TEUQ)
182 TRANS(stgt_b, 64, gen_store_gt, MO_UB)
183 TRANS(stgt_h, 64, gen_store_gt, MO_TEUW)
184 TRANS(stgt_w, 64, gen_store_gt, MO_TEUL)
185 TRANS(stgt_d, 64, gen_store_gt, MO_TEUQ)
186 TRANS(stle_b, 64, gen_store_le, MO_UB)
187 TRANS(stle_h, 64, gen_store_le, MO_TEUW)
188 TRANS(stle_w, 64, gen_store_le, MO_TEUL)
189 TRANS(stle_d, 64, gen_store_le, MO_TEUQ)