diff options
| author | Ajax <commial@gmail.com> | 2015-11-13 14:00:14 +0100 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2015-11-13 14:00:14 +0100 |
| commit | c87a0a7e01665081553574f3a1734b96e95b2c6c (patch) | |
| tree | 1ca08262e85210f8e92ca71e23ff929a8f3aae57 | |
| parent | d6a6f4aaa661ee45232b9b985f7b59c516b8b6c4 (diff) | |
| download | miasm-c87a0a7e01665081553574f3a1734b96e95b2c6c.tar.gz miasm-c87a0a7e01665081553574f3a1734b96e95b2c6c.zip | |
x86/TCC: fix rcr/rcl computation
| -rw-r--r-- | miasm2/jitter/vm_mngr.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c index ddcf86ca..2576dc0f 100644 --- a/miasm2/jitter/vm_mngr.c +++ b/miasm2/jitter/vm_mngr.c @@ -850,47 +850,37 @@ uint64_t rot_right(uint64_t size, uint64_t a, uint64_t b) 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) | ((a&0x1FF) >> (size-b-1)); - return tmp&0xff; - case 16+1: - tmp = (tmp << b) | ((a&0x1FFFF) >> (size-b-1)); - return tmp&0xffff; - case 32+1: - tmp = (tmp << b) | ((a&0x1FFFFFFFFULL) >> (size-b-1)); - 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; } unsigned 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); - + uint64_t tmp; + 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; + } + return tmp; } unsigned int x86_bsr(uint64_t src, unsigned int size) |