Commit e17a44f5 authored by Julian Kranz's avatar Julian Kranz

X86 RREIL Translator

- Added semantics of: IMUL
parent bbf08b39
......@@ -191,6 +191,7 @@ val conv-with conv sz x =
end
val read sz x = conv-with Unsigned sz x
val reads conv sz x = conv-with conv sz x
val read-addr-reg x =
case x of
......@@ -613,6 +614,26 @@ val emit-sub-sbb-flags sz difference minuend subtrahend carry set-carry = do
emit-arithmetic-adjust-flag sz difference minuend subtrahend
end
val emit-mul-flags sz product = do
ov <- fOF;
cf <- fCF;
sf <- fSF;
zf <- fZF;
af <- fAF;
pf <- fPF;
sgn-ext <- mktemp;
movsx sz sgn-ext 1 (var (at-offset product (sz + sz - 1)));
cmpneq sz ov (var (at-offset product sz)) (var sgn-ext);
mov 1 cf (var ov);
undef 1 sf;
undef 1 zf;
undef 1 af;
undef 1 pf
end
## A>>
val sem-adc x = do
......@@ -969,6 +990,24 @@ end
val sem-idiv x = sem-div Signed x
val sem-imul-1 x = sem-mul Signed x
val sem-imul-2-3 op1 op2 op3 = do
sz <- sizeof1 op1;
factor0 <- reads Signed (sz + sz) op2;
factor1 <- reads Signed (sz + sz) op3;
product <- mktemp;
mul (sz + sz) product factor0 factor1;
emit-mul-flags sz product;
result <- write sz op1;
commit sz result (var product)
end
val sem-imul-2 x = sem-imul-2-3 x.opnd1 x.opnd1 x.opnd2
val sem-imul-3 x = sem-imul-2-3 x.opnd1 x.opnd2 x.opnd3
## J>>
val sem-jcc x cond = do
......@@ -1131,18 +1170,19 @@ val sem-movzx x = do
commit sz-dst dst (var temp)
end
val sem-mul x = do
val sem-mul conv x = do
sz <- sizeof1 x.opnd1;
factor0-sem <- return (semantic-register-of (register-by-size low A sz));
factor0 <- expand Unsigned (var factor0-sem) sz (sz + sz);
factor0 <- expand conv (var factor0-sem) sz (sz + sz);
#Remark: Also expands unsigned
factor1 <- read (sz + sz) x.opnd1;
factor1 <- reads conv (sz + sz) x.opnd1;
product <- mktemp;
mul (sz + sz) product factor0 factor1;
emit-mul-flags sz product;
case sz of
8: do
ax <- return (semantic-register-of AX);
......@@ -1155,22 +1195,7 @@ val sem-mul x = do
mov sz high (var (at-offset product sz));
mov sz low (var product)
end
end;
ov <- fOF;
cf <- fCF;
sf <- fSF;
zf <- fZF;
af <- fAF;
pf <- fPF;
cmpneq sz ov (var (at-offset product sz)) (imm 0);
mov 1 cf (var ov);
undef 1 sf;
undef 1 zf;
undef 1 af;
undef 1 pf
end
end
## N>>
......@@ -1952,7 +1977,12 @@ val semantics insn =
| HSUBPD x: sem-undef-arity2 x
| HSUBPS x: sem-undef-arity2 x
| IDIV x: sem-idiv x
| IMUL x: sem-undef-varity x
| IMUL v:
case v of
VA0 x: sem-imul-1 x
| VA1 x: sem-imul-2 x
| VA2 x: sem-imul-3 x
end
| IN x: sem-undef-arity2 x
| INC x: sem-undef-arity1 x
| INSB x: sem-undef-arity0 x
......@@ -2078,7 +2108,7 @@ val semantics insn =
| MOVUPS x: sem-undef-arity2 x
| MOVZX x: sem-movzx x
| MPSADBW x: sem-undef-arity3 x
| MUL x: sem-mul x
| MUL x: sem-mul Unsigned x
| MULPD x: sem-undef-arity2 x
| MULPS x: sem-undef-arity2 x
| MULSD x: sem-undef-arity2 x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment