• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiónb9f9c5b41aab06479cb1695990b7cca98ef84fc7 (tree)
Tiempo2016-03-15 02:53:07
AutorRichard Henderson <rth@twid...>
CommiterRichard Henderson

Log Message

target-i386: Dump unknown opcodes with -d unimp

We discriminate here between opcodes that are illegal in the current
cpu mode or with illegal arguments (such as modrm.mod == 3) and
encodings that are unknown (such as an unimplemented isa extension).

Signed-off-by: Richard Henderson <rth@twiddle.net>

Cambiar Resumen

Diferencia incremental

--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -99,6 +99,7 @@ typedef struct DisasContext {
9999 int prefix;
100100 TCGMemOp aflag;
101101 TCGMemOp dflag;
102+ target_ulong pc_start;
102103 target_ulong pc; /* pc = eip + cs_base */
103104 int is_jmp; /* 1 = means jump (stop translation), 2 means CPU
104105 static state change (stop translation) */
@@ -2368,6 +2369,30 @@ static void gen_exception(DisasContext *s, int trapno, target_ulong cur_eip)
23682369 s->is_jmp = DISAS_TB_JUMP;
23692370 }
23702371
2372+/* Generate #UD for the current instruction. The assumption here is that
2373+ the instruction is known, but it isn't allowed in the current cpu mode. */
2374+static void gen_illegal_opcode(DisasContext *s)
2375+{
2376+ gen_exception(s, EXCP06_ILLOP, s->pc_start - s->cs_base);
2377+}
2378+
2379+/* Similarly, except that the assumption here is that we don't decode
2380+ the instruction at all -- either a missing opcode, an unimplemented
2381+ feature, or just a bogus instruction stream. */
2382+static void gen_unknown_opcode(CPUX86State *env, DisasContext *s)
2383+{
2384+ gen_illegal_opcode(s);
2385+
2386+ if (qemu_loglevel_mask(LOG_UNIMP)) {
2387+ target_ulong pc = s->pc_start, end = s->pc;
2388+ qemu_log("ILLOPC: " TARGET_FMT_lx ":", pc);
2389+ for (; pc < end; ++pc) {
2390+ qemu_log(" %02x", cpu_ldub_code(env, pc));
2391+ }
2392+ qemu_log("\n");
2393+ }
2394+}
2395+
23712396 /* an interrupt is different from an exception because of the
23722397 privilege checks */
23732398 static void gen_interrupt(DisasContext *s, int intno,
@@ -2887,7 +2912,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
28872912 b1 = 0;
28882913 sse_fn_epp = sse_op_table1[b][b1];
28892914 if (!sse_fn_epp) {
2890- goto illegal_op;
2915+ goto unknown_op;
28912916 }
28922917 if ((b <= 0x5f && b >= 0x10) || b == 0xc6 || b == 0xc2) {
28932918 is_xmm = 1;
@@ -2906,15 +2931,19 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
29062931 }
29072932 if (s->flags & HF_EM_MASK) {
29082933 illegal_op:
2909- gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base);
2934+ gen_illegal_opcode(s);
29102935 return;
29112936 }
2912- if (is_xmm && !(s->flags & HF_OSFXSR_MASK))
2913- if ((b != 0x38 && b != 0x3a) || (s->prefix & PREFIX_DATA))
2914- goto illegal_op;
2937+ if (is_xmm
2938+ && !(s->flags & HF_OSFXSR_MASK)
2939+ && ((b != 0x38 && b != 0x3a) || (s->prefix & PREFIX_DATA))) {
2940+ goto unknown_op;
2941+ }
29152942 if (b == 0x0e) {
2916- if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
2917- goto illegal_op;
2943+ if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW)) {
2944+ /* If we were fully decoding this we might use illegal_op. */
2945+ goto unknown_op;
2946+ }
29182947 /* femms */
29192948 gen_helper_emms(cpu_env);
29202949 return;
@@ -2939,8 +2968,9 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
29392968 b |= (b1 << 8);
29402969 switch(b) {
29412970 case 0x0e7: /* movntq */
2942- if (mod == 3)
2971+ if (mod == 3) {
29432972 goto illegal_op;
2973+ }
29442974 gen_lea_modrm(env, s, modrm);
29452975 gen_stq_env_A0(s, offsetof(CPUX86State, fpregs[reg].mmx));
29462976 break;
@@ -3266,7 +3296,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
32663296 case 0x172:
32673297 case 0x173:
32683298 if (b1 >= 2) {
3269- goto illegal_op;
3299+ goto unknown_op;
32703300 }
32713301 val = cpu_ldub_code(env, s->pc++);
32723302 if (is_xmm) {
@@ -3285,7 +3315,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
32853315 sse_fn_epp = sse_op_table2[((b - 1) & 3) * 8 +
32863316 (((modrm >> 3)) & 7)][b1];
32873317 if (!sse_fn_epp) {
3288- goto illegal_op;
3318+ goto unknown_op;
32893319 }
32903320 if (is_xmm) {
32913321 rm = (modrm & 7) | REX_B(s);
@@ -3509,12 +3539,12 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
35093539 reg = ((modrm >> 3) & 7) | rex_r;
35103540 mod = (modrm >> 6) & 3;
35113541 if (b1 >= 2) {
3512- goto illegal_op;
3542+ goto unknown_op;
35133543 }
35143544
35153545 sse_fn_epp = sse_op_table6[b].op[b1];
35163546 if (!sse_fn_epp) {
3517- goto illegal_op;
3547+ goto unknown_op;
35183548 }
35193549 if (!(s->cpuid_ext_features & sse_op_table6[b].ext_mask))
35203550 goto illegal_op;
@@ -3564,7 +3594,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
35643594 }
35653595 }
35663596 if (sse_fn_epp == SSE_SPECIAL) {
3567- goto illegal_op;
3597+ goto unknown_op;
35683598 }
35693599
35703600 tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset);
@@ -3932,12 +3962,12 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
39323962 break;
39333963
39343964 default:
3935- goto illegal_op;
3965+ goto unknown_op;
39363966 }
39373967 break;
39383968
39393969 default:
3940- goto illegal_op;
3970+ goto unknown_op;
39413971 }
39423972 break;
39433973
@@ -3949,12 +3979,12 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
39493979 reg = ((modrm >> 3) & 7) | rex_r;
39503980 mod = (modrm >> 6) & 3;
39513981 if (b1 >= 2) {
3952- goto illegal_op;
3982+ goto unknown_op;
39533983 }
39543984
39553985 sse_fn_eppi = sse_op_table7[b].op[b1];
39563986 if (!sse_fn_eppi) {
3957- goto illegal_op;
3987+ goto unknown_op;
39583988 }
39593989 if (!(s->cpuid_ext_features & sse_op_table7[b].ext_mask))
39603990 goto illegal_op;
@@ -4156,12 +4186,14 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
41564186 break;
41574187
41584188 default:
4159- goto illegal_op;
4189+ goto unknown_op;
41604190 }
41614191 break;
41624192
41634193 default:
4164- goto illegal_op;
4194+ unknown_op:
4195+ gen_unknown_opcode(env, s);
4196+ return;
41654197 }
41664198 } else {
41674199 /* generic MMX or SSE operation */
@@ -4237,11 +4269,12 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
42374269 }
42384270 switch(b) {
42394271 case 0x0f: /* 3DNow! data insns */
4240- if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
4241- goto illegal_op;
42424272 val = cpu_ldub_code(env, s->pc++);
42434273 sse_fn_epp = sse_op_table5[val];
42444274 if (!sse_fn_epp) {
4275+ goto unknown_op;
4276+ }
4277+ if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW)) {
42454278 goto illegal_op;
42464279 }
42474280 tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset);
@@ -4261,7 +4294,7 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,
42614294 /* compare insns */
42624295 val = cpu_ldub_code(env, s->pc++);
42634296 if (val >= 8)
4264- goto illegal_op;
4297+ goto unknown_op;
42654298 sse_fn_epp = sse_op_table4[val][b1];
42664299
42674300 tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset);
@@ -4306,7 +4339,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
43064339 target_ulong next_eip, tval;
43074340 int rex_w, rex_r;
43084341
4309- s->pc = pc_start;
4342+ s->pc_start = s->pc = pc_start;
43104343 prefixes = 0;
43114344 s->override = -1;
43124345 rex_w = -1;
@@ -4419,7 +4452,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
44194452 b = 0x13a;
44204453 break;
44214454 default: /* Reserved for future use. */
4422- goto illegal_op;
4455+ goto unknown_op;
44234456 }
44244457 }
44254458 s->vex_v = (~vex3 >> 3) & 0xf;
@@ -4769,7 +4802,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
47694802 }
47704803 break;
47714804 default:
4772- goto illegal_op;
4805+ goto unknown_op;
47734806 }
47744807 break;
47754808
@@ -4782,7 +4815,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
47824815 rm = (modrm & 7) | REX_B(s);
47834816 op = (modrm >> 3) & 7;
47844817 if (op >= 2 && b == 0xfe) {
4785- goto illegal_op;
4818+ goto unknown_op;
47864819 }
47874820 if (CODE64(s)) {
47884821 if (op == 2 || op == 4) {
@@ -4875,7 +4908,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
48754908 gen_push_v(s, cpu_T0);
48764909 break;
48774910 default:
4878- goto illegal_op;
4911+ goto unknown_op;
48794912 }
48804913 break;
48814914
@@ -5744,7 +5777,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
57445777 gen_helper_fpop(cpu_env);
57455778 break;
57465779 default:
5747- goto illegal_op;
5780+ goto unknown_op;
57485781 }
57495782 } else {
57505783 /* register float ops */
@@ -5768,7 +5801,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
57685801 gen_helper_fwait(cpu_env);
57695802 break;
57705803 default:
5771- goto illegal_op;
5804+ goto unknown_op;
57725805 }
57735806 break;
57745807 case 0x0c: /* grp d9/4 */
@@ -5787,7 +5820,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
57875820 gen_helper_fxam_ST0(cpu_env);
57885821 break;
57895822 default:
5790- goto illegal_op;
5823+ goto unknown_op;
57915824 }
57925825 break;
57935826 case 0x0d: /* grp d9/5 */
@@ -5822,7 +5855,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
58225855 gen_helper_fldz_ST0(cpu_env);
58235856 break;
58245857 default:
5825- goto illegal_op;
5858+ goto unknown_op;
58265859 }
58275860 }
58285861 break;
@@ -5922,7 +5955,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
59225955 gen_helper_fpop(cpu_env);
59235956 break;
59245957 default:
5925- goto illegal_op;
5958+ goto unknown_op;
59265959 }
59275960 break;
59285961 case 0x1c:
@@ -5940,7 +5973,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
59405973 case 4: /* fsetpm (287 only, just do nop here) */
59415974 break;
59425975 default:
5943- goto illegal_op;
5976+ goto unknown_op;
59445977 }
59455978 break;
59465979 case 0x1d: /* fucomi */
@@ -5992,7 +6025,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
59926025 gen_helper_fpop(cpu_env);
59936026 break;
59946027 default:
5995- goto illegal_op;
6028+ goto unknown_op;
59966029 }
59976030 break;
59986031 case 0x38: /* ffreep sti, undocumented op */
@@ -6007,7 +6040,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
60076040 gen_op_mov_reg_v(MO_16, R_EAX, cpu_T0);
60086041 break;
60096042 default:
6010- goto illegal_op;
6043+ goto unknown_op;
60116044 }
60126045 break;
60136046 case 0x3d: /* fucomip */
@@ -6053,7 +6086,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
60536086 }
60546087 break;
60556088 default:
6056- goto illegal_op;
6089+ goto unknown_op;
60576090 }
60586091 }
60596092 break;
@@ -6524,7 +6557,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
65246557 val = cpu_ldub_code(env, s->pc++);
65256558 tcg_gen_movi_tl(cpu_T1, val);
65266559 if (op < 4)
6527- goto illegal_op;
6560+ goto unknown_op;
65286561 op -= 4;
65296562 goto bt_op;
65306563 case 0x1a3: /* bt Gv, Ev */
@@ -7035,7 +7068,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
70357068 set_cc_op(s, CC_OP_EFLAGS);
70367069 break;
70377070 default:
7038- goto illegal_op;
7071+ goto unknown_op;
70397072 }
70407073 break;
70417074
@@ -7349,7 +7382,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
73497382 break;
73507383
73517384 default:
7352- goto illegal_op;
7385+ goto unknown_op;
73537386 }
73547387 break;
73557388
@@ -7718,7 +7751,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
77187751 }
77197752 break;
77207753 default:
7721- goto illegal_op;
7754+ goto unknown_op;
77227755 }
77237756 }
77247757 break;
@@ -7940,7 +7973,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
79407973 }
79417974 break;
79427975 }
7943- goto illegal_op;
7976+ goto unknown_op;
79447977
79457978 case 0xf8: /* sfence / pcommit */
79467979 if (prefixes & PREFIX_DATA) {
@@ -7962,7 +7995,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
79627995 break;
79637996
79647997 default:
7965- goto illegal_op;
7998+ goto unknown_op;
79667999 }
79678000 break;
79688001
@@ -8018,7 +8051,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
80188051 gen_sse(env, s, b, pc_start, rex_r);
80198052 break;
80208053 default:
8021- goto illegal_op;
8054+ goto unknown_op;
80228055 }
80238056 /* lock generation */
80248057 if (s->prefix & PREFIX_LOCK)
@@ -8028,7 +8061,13 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
80288061 if (s->prefix & PREFIX_LOCK)
80298062 gen_helper_unlock();
80308063 /* XXX: ensure that no lock was generated */
8031- gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base);
8064+ gen_illegal_opcode(s);
8065+ return s->pc;
8066+ unknown_op:
8067+ if (s->prefix & PREFIX_LOCK)
8068+ gen_helper_unlock();
8069+ /* XXX: ensure that no lock was generated */
8070+ gen_unknown_opcode(env, s);
80328071 return s->pc;
80338072 }
80348073