Instruction "translators" are responsible for decoding and loading
instruction operands, calling the passed-in code generator, and
storing the operands back (if applicable). Once a translator returns,
the instruction has been translated to TCG ops, hence the name.
Signed-off-by: Jan Bobek
---
target/i386/translate.c | 288
1 file changed, 288 insertions(+)
diff --git a/target/i386/translate.c b/target/i386/translate.c
index 30180d1c25..0da064d5fd 100644
--- a/target/i386/translate.c
+++ b/target/i386/translate.c
@@ -4715,6 +4715,222 @@ static int ck_cpuid(CPUX86State *env, DisasContext *s,
int ck_cpuid_feat)
#define gen_insn_wrrr(mnem, opW1, opR1, opR2, opR3) \
gen_ ## mnem ## _ ## opW1 ## opR1 ## opR2 ## opR3
+/*
+ * Instruction translators
+ */
+#define translate_insn_r(opR1) \
+translate_insn_r_ ## opR1
+#define translate_insn_rr(opR1, opR2) \
+translate_insn_rr_ ## opR1 ## opR2
+#define translate_insn_w(opW1) \
+translate_insn_w_ ## opW1
+#define translate_insn_wr(opW1, opR1) \
+translate_insn_wr_ ## opW1 ## opR1
+#define translate_insn_wrr(opW1, opR1, opR2)\
+translate_insn_wrr_ ## opW1 ## opR1 ## opR2
+#define translate_insn_wrrr(opW1, opR1, opR2, opR3) \
+translate_insn_wrrr_ ## opW1 ## opR1 ## opR2 ## opR3
+#define translate_group(grpname)\
+translate_group_ ## grpname
+
+static void translate_insn(
+CPUX86State *env, DisasContext *s, int ck_cpuid_feat,
+void (*gen_insn_fp)(CPUX86State *, DisasContext *))
+{
+if (ck_cpuid(env, s, ck_cpuid_feat)) {
+gen_illegal_opcode(s);
+return;
+}
+
+(*gen_insn_fp)(env, s);
+}
+
+#define TRANSLATE_INSN_R(opR1) \
+static void translate_insn_r(opR1)( \
+CPUX86State *env, DisasContext *s, int modrm, int ck_cpuid_feat, \
+void (*gen_insn_fp)(CPUX86State *, DisasContext *, insnop_t(opR1))) \
+{ \
+insnop_t(opR1) arg1;\
+\
+if (ck_cpuid(env, s, ck_cpuid_feat) \
+|| insnop_init(opR1)(env, s, modrm, &arg1)) { \
+gen_illegal_opcode(s); \
+return; \
+} \
+\
+insnop_prepare(opR1)(env, s, modrm, &arg1); \
+(*gen_insn_fp)(env, s, arg1); \
+}
+
+#define TRANSLATE_INSN_RR(opR1, opR2) \
+static void translate_insn_rr(opR1, opR2)( \
+CPUX86State *env, DisasContext *s, int modrm, int ck_cpuid_feat, \
+void (*gen_insn_fp)(CPUX86State *, DisasContext *, insnop_t(opR1), \
+insnop_t(opR2)))\
+{ \
+insnop_t(opR1) arg1;\
+insnop_t(opR2) arg2;\
+\
+if (ck_cpuid(env, s, ck_cpuid_feat) \
+|| insnop_init(opR1)(env, s, modrm, &arg1) \
+|| insnop_init(opR2)(env, s, modrm, &arg2)) { \
+gen_illegal_opcode(s); \
+return; \
+} \
+\
+insnop_prepare(opR1)(env, s, modrm, &arg1); \
+insnop_prepare(opR2)(env, s, modrm, &arg2); \
+(*gen_insn_fp)(env, s, arg1, arg2); \
+}
+
+#define TRANSLATE_INSN_W(opW1) \
+static void translate_insn_w(opW1)( \
+CPUX86State *env, DisasContext *s, int modrm, int ck_cpuid_feat, \
+void (*gen_insn_fp)(CPUX86State *, DisasContext *, insnop_t(opW1))) \
+{ \
+insnop_t(opW1) ret; \
+\
+if (ck_cpuid(env, s, ck_cpuid_feat) \
+|| insnop_init(opW1)(env, s, modrm, &ret)) {