From: Nikhil Kumar Singh <[email protected]>
Migrate load-and-reserve instructions (lbarx, lharx, lwarx, ldarx,
lqarx) to decodetree using the X-form layout.
A shared helper (do_load_locked) is introduced for standard-width
variants, while LQARX is handled separately due to its 128-bit
semantics and register pairing constraints.
The implementation preserves legacy behavior, including:
- Reservation granularity and overwrite semantics
- Alignment requirements
- Invalid instruction cases for LQARX
Testing:
- Verified TCG equivalence with legacy implementation
Signed-off-by: Nikhil Kumar Singh <[email protected]>
Reviewed-by: Glenn Miles <[email protected]>
Signed-off-by: Chinmay Rath <[email protected]>
---
target/ppc/insn32.decode | 7 +++
target/ppc/translate.c | 124
+++++++++++++++++++--------------------
2 files changed, 69 insertions(+), 62 deletions(-)
diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
index 342e65dadf..26948e08a7 100644
--- a/target/ppc/insn32.decode
+++ b/target/ppc/insn32.decode
@@ -1309,6 +1309,13 @@ XVF64GERNN 111011 ... -- .... 0 .....
11111010 ..- @XX3_at xa=%xx_xa_pair
##Extend Sign Word and Shift Left Immediate XS-form
EXTSWSLI 011111 ..... ..... ..... 110111101 . . @XS
+## Load and Reserve Instructions
+LBARX 011111 ..... ..... ..... 0000110100 . @X_rc
+LHARX 011111 ..... ..... ..... 0001110100 . @X_rc
+LWARX 011111 ..... ..... ..... 0000010100 . @X_rc
+LDARX 011111 ..... ..... ..... 0001010100 . @X_rc
+LQARX 011111 ..... ..... ..... 0100010100 . @X_rc
+
## Vector Division Instructions
VDIVSW 000100 ..... ..... ..... 00110001011 @VX
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index e627f48f9e..cc9287dcc5 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -2947,30 +2947,6 @@ static void gen_isync(DisasContext *ctx)
ctx->base.is_jmp = DISAS_EXIT_UPDATE;
}
-static void gen_load_locked(DisasContext *ctx, MemOp memop)
-{
- TCGv gpr = cpu_gpr[rD(ctx->opcode)];
- TCGv t0 = tcg_temp_new();
-
- gen_set_access_type(ctx, ACCESS_RES);
- gen_addr_reg_index(ctx, t0);
- tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, DEF_MEMOP(memop) |
MO_ALIGN);
- tcg_gen_mov_tl(cpu_reserve, t0);
- tcg_gen_movi_tl(cpu_reserve_length, memop_size(memop));
- tcg_gen_mov_tl(cpu_reserve_val, gpr);
-}
-
-#define LARX(name, memop) \
-static void gen_##name(DisasContext *ctx) \
-{ \
- gen_load_locked(ctx, memop); \
-}
-
-/* lwarx */
-LARX(lbarx, MO_UB)
-LARX(lharx, MO_UW)
-LARX(lwarx, MO_UL)
-
static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop,
TCGv EA, TCGCond cond, int
addend)
{
@@ -3219,42 +3195,9 @@ STCX(sthcx_, MO_UW)
STCX(stwcx_, MO_UL)
#if defined(TARGET_PPC64)
-/* ldarx */
-LARX(ldarx, MO_UQ)
/* stdcx. */
STCX(stdcx_, MO_UQ)
-/* lqarx */
-static void gen_lqarx(DisasContext *ctx)
-{
- int rd = rD(ctx->opcode);
- TCGv EA, hi, lo;
- TCGv_i128 t16;
-
- if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
- (rd == rB(ctx->opcode)))) {
- gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
- return;
- }
-
- gen_set_access_type(ctx, ACCESS_RES);
- EA = tcg_temp_new();
- gen_addr_reg_index(ctx, EA);
-
- /* Note that the low part is always in RD+1, even in LE mode. */
- lo = cpu_gpr[rd + 1];
- hi = cpu_gpr[rd];
-
- t16 = tcg_temp_new_i128();
- tcg_gen_qemu_ld_i128(t16, EA, ctx->mem_idx, DEF_MEMOP(MO_128 |
MO_ALIGN));
- tcg_gen_extr_i128_i64(lo, hi, t16);
-
- tcg_gen_mov_tl(cpu_reserve, EA);
- tcg_gen_movi_tl(cpu_reserve_length, 16);
- tcg_gen_st_tl(hi, tcg_env, offsetof(CPUPPCState, reserve_val));
- tcg_gen_st_tl(lo, tcg_env, offsetof(CPUPPCState, reserve_val2));
-}
-
/* stqcx. */
static void gen_stqcx_(DisasContext *ctx)
{
@@ -5741,6 +5684,68 @@ static bool trans_EXTSWSLI(DisasContext *ctx,
arg_XS *a)
return true;
}
+/*
+ * Load-and-reserve core
+ */
+static bool do_load_locked(DisasContext *ctx, arg_X_rc *a, MemOp
memop)
+{
+ TCGv EA = do_ea_calc(ctx, a->ra, cpu_gpr[a->rb]);
+ TCGv gpr = cpu_gpr[a->rt];
+
+ gen_set_access_type(ctx, ACCESS_RES);
+
+ tcg_gen_qemu_ld_tl(gpr, EA, ctx->mem_idx, memop | MO_ALIGN);
+
+ tcg_gen_mov_tl(cpu_reserve, EA);
+ tcg_gen_movi_tl(cpu_reserve_length, memop_size(memop));
+
+ tcg_gen_mov_tl(cpu_reserve_val, gpr);
+
+ return true;
+}
+
+TRANS_FLAGS2(ATOMIC_ISA206, LBARX, do_load_locked, DEF_MEMOP(MO_UB))
+TRANS_FLAGS2(ATOMIC_ISA206, LHARX, do_load_locked, DEF_MEMOP(MO_UW))
+TRANS(LWARX, do_load_locked, DEF_MEMOP(MO_UL))
+TRANS64(LDARX, do_load_locked, DEF_MEMOP(MO_UQ))
+
+static bool trans_LQARX(DisasContext *ctx, arg_LQARX *a)
+{
+ REQUIRE_64BIT(ctx);
+ REQUIRE_INSNS_FLAGS2(ctx, ISA207S);