Skip to content

Commit

Permalink
Make inc and dec sized
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed May 26, 2018
1 parent 26d2b04 commit 723ecb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions emu/gadgets-x86/math.S
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@
.endr

# unary operations (well, only one explicit operand)

.irp op, inc,dec
.gadget \op
setf_a src=$1 dst=%_tmp, ss=l
\op\()l %_tmp
.macro do_\op size, s, ss
setf_a src=$1 dst=%tmp\s, ss=\ss
\op\()\ss %tmp\s
seto CPU_of(%_cpu)
setf_zsp %_tmp, l
gret
setf_zsp %tmp\s, \ss
.endm
.endr

.macro do_sign_extend size, s, ss
.if \size != 32
movs\ss\()l %tmp\s, %tmpd
Expand Down Expand Up @@ -177,7 +177,7 @@
not\ss %tmp\s
.endm

.irp op, sign_extend,zero_extend,div,idiv,mul,imul1,neg,not
.irp op, inc,dec,sign_extend,zero_extend,div,idiv,mul,imul1,neg,not
.irp size, SIZE_LIST
.gadget \op\()_\size
ss \size, do_\op
Expand Down
21 changes: 11 additions & 10 deletions emu/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef void (*gadget_t)();
#define ga(g, i) do { extern gadget_t g##_gadgets[]; if (g##_gadgets[i] == NULL) UNDEFINED; GEN(g##_gadgets[i]); } while (0)
#define gag(g, i, a) do { ga(g, i); GEN(a); } while (0)
#define gagg(g, i, a, b) do { ga(g, i); GEN(a); GEN(b); } while (0)
#define gz(g, z) ga(g, sz(z))
#define gg_here(g, a) ggg(g, a, state->ip)
#define UNDEFINED do { gg_here(interrupt, INT_UNDEFINED); return; } while (0)

Expand Down Expand Up @@ -132,8 +133,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); 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 MOVZX(src, dst,zs,zd) load(src, zs); gz(zero_extend, zs); store(dst, zd)
#define MOVSX(src, dst,zs,zd) load(src, zs); gz(sign_extend, 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 All @@ -145,14 +146,14 @@ static inline void gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a
#define XOR(src, dst,z) los(xor, src, dst, z)
#define CMP(src, dst,z) lo(sub, src, dst, z)
#define TEST(src, dst,z) lo(and, src, dst, z)
#define NOT(val,z) load(val,z); ga(not, sz(z)); store(val,z)
#define NEG(val,z) load(val,z); ga(neg, sz(z)); store(val,z)
#define NOT(val,z) load(val,z); gz(not, z); store(val,z)
#define NEG(val,z) load(val,z); gz(neg, z); store(val,z)

#define POP(thing,z) gg(pop, saved_ip); store(thing, z)
#define PUSH(thing,z) load(thing, z); gg(push, saved_ip)

#define INC(val,z) load(val, z); g(inc); store(val, z)
#define DEC(val,z) load(val, z); g(dec); store(val, z)
#define INC(val,z) load(val, z); gz(inc, z); store(val, z)
#define DEC(val,z) load(val, z); gz(dec, z); store(val, z)

#define JMP(loc) load(loc, OP_SIZE); g(jmp_indir)
#define JMP_REL(off) gg(jmp, state->ip + off)
Expand Down Expand Up @@ -187,10 +188,10 @@ static inline void gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a
#define STD UNDEFINED

#define MUL18(val,z) MUL1(val,z)
#define MUL1(val,z) load(val, z); ga(mul, sz(z))
#define IMUL1(val,z) load(val, z); ga(imul1, sz(z))
#define DIV(val, z) load(val, z); ga(div, sz(z))
#define IDIV(val, z) load(val, z); ga(idiv, sz(z))
#define MUL1(val,z) load(val, z); gz(mul, z)
#define IMUL1(val,z) load(val, z); gz(imul1, z)
#define DIV(val, z) load(val, z); gz(div, z)
#define IDIV(val, z) load(val, z); gz(idiv, z)
#define IMUL3(times, src, dst,z) load(src, z); op(imul, times, z); store(dst, z)
#define IMUL2(val, reg,z) IMUL3(val, reg, reg, z)

Expand Down

0 comments on commit 723ecb1

Please sign in to comment.