about summary refs log tree commit diff stats
path: root/miasm2/jitter/vm_mngr.c
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2015-11-14 18:45:19 +0100
committerserpilliere <serpilliere@users.noreply.github.com>2015-11-14 18:45:19 +0100
commitd7316f0e60be635f6c3451b83f47f0c0b79a3721 (patch)
treee3c278444b86b0d6250792dee43b618d2f61c865 /miasm2/jitter/vm_mngr.c
parent00f568729a938465f83c8c73fe49462779673222 (diff)
parent8ae102ba0fd8231c9d491a308144b0dd5424e0df (diff)
downloadmiasm-d7316f0e60be635f6c3451b83f47f0c0b79a3721.tar.gz
miasm-d7316f0e60be635f6c3451b83f47f0c0b79a3721.zip
Merge pull request #267 from commial/fix-sem-x86
Fix sem x86
Diffstat (limited to 'miasm2/jitter/vm_mngr.c')
-rw-r--r--miasm2/jitter/vm_mngr.c93
1 files changed, 26 insertions, 67 deletions
diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c
index 3e5c262d..2576dc0f 100644
--- a/miasm2/jitter/vm_mngr.c
+++ b/miasm2/jitter/vm_mngr.c
@@ -847,81 +847,40 @@ uint64_t rot_right(uint64_t size, uint64_t a, uint64_t b)
 }
 
 
-int rcl_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
+unsigned int rcl_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 {
     uint64_t tmp;
-
-
-    size++;
-    b %= size;
-
-    if (b == 0) {
-	    switch(size){
-		    case 8+1:
-			    return a&0xff;
-		    case 16+1:
-			    return a&0xffff;
-		    case 32+1:
-			    return a&0xffffffff;
-		    default:
-			    fprintf(stderr, "inv size in rclleft %d\n", size);
-			    exit(0);
-	    }
-    }
-
-    tmp = (a<<1) | cf;
-    b -=1;
-    switch(size){
-	    case 8+1:
-		    tmp = (tmp << b) | ((tmp&0x1FF) >> (size-b));
-		    return tmp&0xff;
-	    case 16+1:
-		    tmp = (tmp << b) | ((tmp&0x1FFFF) >> (size-b));
-		    return tmp&0xffff;
-	    case 32+1:
-		    tmp = (tmp << b) | ((tmp&0x1FFFFFFFFULL) >> (size-b));
-		    return tmp&0xffffffff;
-	    default:
-		    fprintf(stderr, "inv size in rclleft %d\n", size);
-		    exit(0);
+    uint64_t tmp_count;
+    uint64_t tmp_cf;
+
+    tmp = a;
+    // TODO 64bit mode
+    tmp_count = (b & 0x1f) % (size + 1);
+    while (tmp_count != 0) {
+	    tmp_cf = (tmp >> (size - 1)) & 1;
+	    tmp = (tmp << 1) + cf;
+	    cf = tmp_cf;
+	    tmp_count -= 1;
     }
+    return tmp;
 }
 
-int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
-{
-	return rcl_rez_op(size, a, size+1-b, cf);
-
-}
-
-
-int rcl_cf_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
+unsigned int rcr_rez_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
 {
     uint64_t tmp;
-
-    tmp = (cf<< size) | a;
-
-    size++;
-    b %= size;
-
-    switch(size){
-	    case 8+1:
-		    tmp = (tmp << b) | ((tmp&0x1FF) >> (size-b));
-		    return (tmp>>8)&1;
-	    case 16+1:
-		    tmp = (tmp << b) | ((tmp&0x1FFFF) >> (size-b));
-		    return (tmp>>16)&1;
-	    case 32+1:
-		    tmp = (tmp << b) | ((tmp&0x1FFFFFFFFULL) >> (size-b));
-		    return (tmp>>32)&1;
-	    default:
-		    fprintf(stderr, "inv size in rclleft %d\n", size);
-		    exit(0);
+    uint64_t tmp_count;
+    uint64_t tmp_cf;
+
+    tmp = a;
+    // TODO 64bit mode
+    tmp_count = (b & 0x1f) % (size + 1);
+    while (tmp_count != 0) {
+	    tmp_cf = tmp & 1;
+	    tmp = (tmp >> 1) + (cf << (size - 1));
+	    cf = tmp_cf;
+	    tmp_count -= 1;
     }
-}
-
-int rcr_cf_op(unsigned int size, unsigned int a, unsigned int b, unsigned int cf)
-{
-	return rcl_cf_op(size, a, size+1-b, cf);
+    return tmp;
 }
 
 unsigned int x86_bsr(uint64_t src, unsigned int size)