Skip to content

Commit

Permalink
Fix several emulation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 26, 2018
1 parent 09a2730 commit cc3dde2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
14 changes: 7 additions & 7 deletions emu/gadgets-x86/bits.S
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include "gadgets.h"

.macro do_shift type, size
.macro do_shift type, size, s, ss
.irp arg, reg_c,imm
.gadget \type\size\()_\arg
.ifc \arg,imm
pushq %rcx
movl %ecx, %r14d
movb (%_ip), %cl
.endif
testb $(\size - 1), %cl
jz 1f
\type\()l %cl, %_tmp
\type\()\ss %cl, %tmp\s
setf_oc
.ifin(\type, shl,shr,sar)
setf_zsp %_tmp, l
setf_zsp %tmp\s, \ss
clearf_a
.endifin
clearf_a
1:
.ifc \arg,imm
popq %rcx
movl %r14d, %ecx
.endif
.ifc \arg,imm
gret 1
Expand All @@ -29,7 +29,7 @@

.irp type, shl,shr,sar,rol,ror
.irp size, 8,16,32
do_shift \type, \size
ss \size, do_shift, \type
.endr
.gadget_array \type
.endr
Expand Down
9 changes: 7 additions & 2 deletions emu/gadgets-x86/math.S
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ do_op_size imul, 32
gret
.endr

.macro do_extend size, s, ss
.macro do_sign_extend size, s, ss
.if \size != 32
movs\ss\()l %tmp\s, %tmpd
.endif
.endm
.macro do_zero_extend size, s, ss
.if \size != 32
movz\ss\()l %tmp\s, %tmpd
.endif
.endm
.macro do_div size, s, ss
div\ss %tmp\s
.endm
Expand All @@ -159,7 +164,7 @@ do_op_size imul, 32
not\ss %tmp\s
.endm

.irp op, extend,div,idiv,mul,imul1,neg,not
.irp op, sign_extend,zero_extend,div,idiv,mul,imul1,neg,not
.irp size, SIZE_LIST
.gadget \op\()_\size
ss \size, do_\op
Expand Down
4 changes: 2 additions & 2 deletions emu/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ static inline void gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a
#define SEG_GS() seg_gs = true

#define MOV(src, dst,z) load(src, z); store(dst, z)
#define MOVZX(src, dst,zs,zd) load(src, zs); store(dst, zd)
#define MOVSX(src, dst,zs,zd) load(src, zs); ga(extend, sz(zs)); store(dst, zd)
#define MOVZX(src, dst,zs,zd) load(src, zs); ga(zero_extend, sz(zs)); store(dst, zd)
#define MOVSX(src, dst,zs,zd) load(src, zs); ga(sign_extend, sz(zs)); store(dst, zd)
#define XCHG(src, dst,z) los(xchg, src, dst, z)

#define ADD(src, dst,z) los(add, src, dst, z)
Expand Down
1 change: 0 additions & 1 deletion emu/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ struct jit *jit_new(struct mem *mem) {
void jit_free(struct jit *jit) {
free(jit);
}

2 changes: 1 addition & 1 deletion tests/looper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define nop() __asm__ volatile("")

int main() {
int loops = 100000000;
int loops = 10000000;
printf("looping %d times\n", loops);
for (int i = 0; i < loops; i++)
nop();
Expand Down

0 comments on commit cc3dde2

Please sign in to comment.