]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Start pushing some instructions through the x86 assembler.
authorJulian Seward <jseward@acm.org>
Thu, 22 Jul 2004 17:26:12 +0000 (17:26 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 22 Jul 2004 17:26:12 +0000 (17:26 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@104

VEX/priv/host-x86/x86host_defs.c
VEX/priv/main/vex_main.c
VEX/test_main.c

index e5bac3e9de91c2ddac59df61c9b051a023d855d7..97343f601115b76068aaecfd8e79607ac3c98f79 100644 (file)
@@ -911,7 +911,7 @@ static UChar* doAMode_R ( UChar* p, HReg greg, HReg ereg )
 
 Int emit_X86Instr ( UChar* buf, Int nbuf, X86Instr* i )
 {
-  UInt opc, opc_rr, subopc_imm, opc_imma;
+   UInt opc, opc_rr, subopc_imm, opc_imma;
 
    UChar* p = &buf[0];
    vassert(nbuf >= 32);
@@ -952,6 +952,8 @@ Int emit_X86Instr ( UChar* buf, Int nbuf, X86Instr* i )
                         subopc_imm = 0; opc_imma = 0x05; break;
          case Xalu_SUB: opc = 0x2B; opc_rr = 0x29; 
                         subopc_imm = 5; opc_imma = 0x2D; break;
+         case Xalu_AND: opc = 0x23; opc_rr = 0x21; 
+                        subopc_imm = 4; opc_imma = 0x25; break;
          default: goto bad;
       }
       switch (i->Xin.Alu32R.src->tag) {
@@ -1008,6 +1010,7 @@ Int emit_X86Instr ( UChar* buf, Int nbuf, X86Instr* i )
       opc = subopc_imm = opc_imma = 0;
       switch (i->Xin.Alu32M.op) {
          case Xalu_ADD: opc = 0x01; subopc_imm = 0; break;
+         case Xalu_SUB: opc = 0x29; subopc_imm = 5; break;
          default: goto bad;
       }
       switch (i->Xin.Alu32M.src->tag) {
@@ -1033,6 +1036,26 @@ Int emit_X86Instr ( UChar* buf, Int nbuf, X86Instr* i )
       }
       break;
 
+   case Xin_Goto:
+      if (i->Xin.Goto.cond == Xcc_ALWAYS
+          && i->Xin.Goto.dst->tag == Xri_Imm) {
+         /* movl $immediate, %eax ; ret */
+         *p++ = 0xB8;
+         p = emit32(p, i->Xin.Goto.dst->Xri.Imm.imm32);
+         *p++ = 0xC3;
+         goto done;
+       }
+      if (i->Xin.Goto.cond == Xcc_ALWAYS
+          && i->Xin.Goto.dst->tag == Xri_Reg) {
+         /* movl %reg, %eax ; ret */
+         *p++ = 0x89;
+        p = doAMode_R(p, i->Xin.Goto.dst->Xri.Reg.reg, hregX86_EAX());
+         *p++ = 0xC3;
+         goto done;
+       }
+
+       goto bad;
+
    default: 
       goto bad;
    }
@@ -1063,19 +1086,19 @@ void test_asm86 ( void )
   HReg eax = hregX86_EAX();
   HReg esp = hregX86_ESP();
 
-#define T(_iii)                                        \
-  do { X86Instr* iii = _iii;                        \
-       vex_printf("\n   ");                        \
-       ppX86Instr(iii);                                \
-       vex_printf("\n   ");                        \
+#define T(_iii)                                  \
+  do { X86Instr* iii = _iii;                     \
+       vex_printf("\n   ");                      \
+       ppX86Instr(iii);                          \
+       vex_printf("\n   ");                      \
        n = emit_X86Instr( buf, 32, iii );        \
-       for (i = 0; i < n; i++) {                \
-           if (buf[i] < 0x10)                   \
-              vex_printf("0%x ", (Int)buf[i]);  \
-           else                                 \
-              vex_printf("%x ", (Int)buf[i]);        \
-       }                                        \
-       vex_printf("\n");                        \
+       for (i = 0; i < n; i++) {                 \
+           if (buf[i] < 0x10)                    \
+              vex_printf("0%x ", (Int)buf[i]);   \
+           else                                  \
+              vex_printf("%x ", (Int)buf[i]);    \
+       }                                         \
+       vex_printf("\n");                         \
   } while (0)
 
 #if 0
@@ -1126,6 +1149,14 @@ T( X86Instr_Alu32M(Xalu_ADD, X86RI_Reg(ecx), X86AMode_IR(0x80,ebp)) );
 T( X86Instr_Alu32M(Xalu_ADD, X86RI_Reg(ecx), X86AMode_IR(0x7F,ebp)) );
 #endif
 
+#if 1
+T( X86Instr_Alu32M(Xalu_SUB, X86RI_Imm(0x42), X86AMode_IR(0x99,esi)) );
+T( X86Instr_Alu32M(Xalu_SUB, X86RI_Imm(0x4243), X86AMode_IR(0x99,esi)) );
+T( X86Instr_Alu32M(Xalu_SUB, X86RI_Reg(ecx), X86AMode_IR(0x99,ebp)) );
+T( X86Instr_Alu32M(Xalu_SUB, X86RI_Reg(ecx), X86AMode_IR(0x80,ebp)) );
+T( X86Instr_Alu32M(Xalu_SUB, X86RI_Reg(ecx), X86AMode_IR(0x7F,ebp)) );
+#endif
+
 #undef T
 }
 
index 7b704554ffa8a8f361a513f1666a03bdf856979f..075d2c2dd66f793523d3d764201076b4a0d97ab0 100644 (file)
@@ -192,7 +192,10 @@ TranslateResult LibVEX_Translate (
       j = (*emit)( insn_bytes, 32, rcode->arr[i] );
       if (vex_verbosity > 0) {
          for (k = 0; k < j; k++)
-            vex_printf("0x%-2x ", (UInt)insn_bytes[k]);
+           if (insn_bytes[k] < 16)
+               vex_printf("0%x ",  (UInt)insn_bytes[k]);
+            else
+               vex_printf("%x ", (UInt)insn_bytes[k]);
          vex_printf("\n\n");
       }
       if (out_used + j > host_bytes_size) {
index ad1c7175fab956fed5859dd8608549004be8d31a..75ba22434d799bf924a1d095e00205f777f6e2f9 100644 (file)
@@ -70,10 +70,12 @@ int main ( int argc, char** argv )
                 True, 
                  100 );
 
+#if 0
    {extern void test_asm86(void);
    test_asm86();
    return 0;
    }
+#endif
 
    while (!feof(f)) {
       fgets(linebuf, N_LINEBUF,f);