Instruction prefixes can appear in any order. coregrind/vg_to_ucode.c | 49 ++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff -puN coregrind/vg_to_ucode.c~fix-prefixes coregrind/vg_to_ucode.c --- valgrind/coregrind/vg_to_ucode.c~fix-prefixes 2005-01-10 16:40:48.000000000 -0800 +++ valgrind-jeremy/coregrind/vg_to_ucode.c 2005-01-10 16:40:48.000000000 -0800 @@ -3859,6 +3859,7 @@ static Addr disInstr ( UCodeBlock* cb, A UChar dis_buf[50]; Int am_sz, d_sz; static Char loc_buf[M_VG_ERRTXT]; + Bool done; /* Holds eip at the start of the insn, so that we can print consistent error messages for unimplemented insns. */ @@ -3906,25 +3907,28 @@ static Addr disInstr ( UCodeBlock* cb, A } } - /* Skip a LOCK prefix. */ - if (getUChar(eip) == 0xF0) { - /* VG_(printf)("LOCK LOCK LOCK LOCK LOCK \n"); */ - uInstr0(cb, LOCK, 0); - eip++; - } + /* There can be any number of prefixes in any order */ + for(done = False; !done;) { + switch (getUChar(eip)) { + case 0xf0: /* LOCK */ + /* Skip a LOCK prefix. */ + /* VG_(printf)("LOCK LOCK LOCK LOCK LOCK \n"); */ + eip++; + break; + + case 0x66: /* operand size */ + sz = 2; + eip++; + break; - /* Detect operand-size overrides. */ - if (getUChar(eip) == 0x66) { sz = 2; eip++; }; - - /* segment override prefixes come after the operand-size override, - it seems */ - switch (getUChar(eip)) { + /* Segment overrides */ case 0x3E: /* %DS: */ case 0x26: /* %ES: */ case 0x64: /* %FS: */ case 0x65: /* %GS: */ sorb = getUChar(eip); eip++; break; + case 0x2E: /* %CS: */ /* 2E prefix on a conditional branch instruction is a branch-prediction hint, which can safely be ignored. */ @@ -3945,8 +3949,12 @@ static Addr disInstr ( UCodeBlock* cb, A VG_(unimplemented)("x86 segment override (SEG=SS) prefix"); /*NOTREACHED*/ break; + default: - break; + done = True; + break; + + } } /* ---------------------------------------------------- */ @@ -7319,16 +7327,17 @@ static Addr disInstr ( UCodeBlock* cb, A default: decode_failure: /* All decode failures end up here. */ - VG_(printf)("disInstr: unhandled instruction bytes: " - "0x%x 0x%x 0x%x 0x%x\n", - (Int)eip_start[0], - (Int)eip_start[1], - (Int)eip_start[2], - (Int)eip_start[3] ); + VG_(message)(Vg_DebugMsg, + "disInstr: unhandled instruction bytes: " + "0x%x 0x%x 0x%x 0x%x", + (Int)eip_start[0], + (Int)eip_start[1], + (Int)eip_start[2], + (Int)eip_start[3] ); /* Print address of failing instruction. */ VG_(describe_eip)((Addr)eip_start, loc_buf, M_VG_ERRTXT); - VG_(printf)(" at %s\n", loc_buf); + VG_(message)(Vg_DebugMsg, " at %s", loc_buf); uInstr0(cb, CALLM_S, 0); uInstr1(cb, CALLM, 0, Lit16, _