|
From: Tom H. <th...@cy...> - 2003-10-14 09:27:44
|
In message <200...@lu...>
Abhijit Menon-Sen <am...@wi...> wrote:
> At 2003-10-14 05:27:59 +0530, am...@wi... wrote:
> >
> > Would the following suffice to implement LOOPZ/LOOPNZ?
>
> I guess not. :-)
>
> I compiled and ran the following program under valgrind to see what my
> patch would accomplish. I got the following:
>
> -1: JIFZL t10, $0x80483BE [abcdSD]
> opcode: 58
> lit32: 0x80483BE
> size: 4
> val1,val2,val3: 10, 0, 0
> tag1,tag2,tag3: 0, 5, 7
> flags_r: 0x0
> flags_w: 0x0
> extra4b: 0x0
> cond: 0x4
> signed_widen: 0
> jmpkind: 0
> argc,regparms_n: 0, 0
> has_ret_val: 0
> regs_live_after: [abcdSD]
>
> valgrind: vg_to_ucode.c:6528 (disInstr): Assertion `sane' failed.
>
> I'll try to figure out what's happening in VG_(saneUInstr).
> Suggestions and advice are welcome.
You were trying to put a condition on the JIFZ instruction and that
isn't supported, hence the insanity assertion. Here's a patch that uses
a separate condition JMP instruction which does seem to work:
RCS file: /cvsroot/valgrind/valgrind/coregrind/vg_to_ucode.c,v
retrieving revision 1.98
diff -u -r1.98 vg_to_ucode.c
--- vg_to_ucode.c 13 Oct 2003 07:30:40 -0000 1.98
+++ vg_to_ucode.c 14 Oct 2003 09:25:01 -0000
@@ -4876,6 +4876,27 @@
VG_(printf)("loop 0x%x\n", d32);
break;
+ case 0xE1: /* LOOPZ disp8 */
+ case 0xE0: /* LOOPNZ disp8 */
+ d32 = (eip+1) + getSDisp8(eip); eip++;
+ t1 = newTemp(cb);
+ uInstr2(cb, GET, 4, ArchReg, R_ECX, TempReg, t1);
+ uInstr1(cb, DEC, 4, TempReg, t1);
+ uInstr2(cb, PUT, 4, TempReg, t1, ArchReg, R_ECX);
+ uInstr1(cb, JMP, 0, Literal, 0);
+ uLiteral(cb, d32);
+ uCond(cb, (opc == 0xE1 ? CondNZ : CondZ));
+ uFlagsRWU(cb, FlagsOSZACP, FlagsEmpty, FlagsEmpty);
+ uInstr2(cb, JIFZ, 4, TempReg, t1, Literal, 0);
+ uLiteral(cb, eip);
+ uInstr1(cb, JMP, 0, Literal, 0);
+ uLiteral(cb, d32);
+ uCond(cb, CondAlways);
+ *isEnd = True;
+ if (dis)
+ VG_(printf)("loop%s 0x%x\n", (opc == 0xE1 ? "z" : "nz"), d32);
+ break;
+
/* ------------------------ IMUL ----------------------- */
case 0x69: /* IMUL Iv, Ev, Gv */
One thing I don't understand about this is why I had to declare that
the JMP instruction reads all those flags when it only really needs to
read the Z flag, but without that the JMP is asserted as insane.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|