Commit 95279ff9 authored by Julian Kranz's avatar Julian Kranz

X86 RREIL Translator

- Continued to implement the use of sub scopes
parent 9f1253ec
020dca84d06f508ce7c75112dbc5406a03c2dc49 big_dis.c
272ccff084a7ab367cc51189aa7e829d0cdf11f0 inference_bug
d4e3fd30c779f7a01e1911b77cb46909dd865dc3 remove
d4e3fd30c779f7a01e1911b77cb46909dd865dc3 inference_BUG
......@@ -93,7 +93,7 @@ main:
#cdqe
#add %rax, %rax
add %rax, %rax
#inc %rax
#blah:
......
......@@ -177,33 +177,45 @@ val sem-bswap x = do
write size dst (var temp)
end
val sem-bt-complement base-sz base base-opnd shifted offset-ext = do
output <- mktemp;
#andb base-sz output (var shifted) (imm 1);
#shl base-sz output (var output) (var offset-ext);
shl base-sz output (imm 1) (var offset-ext);
xorb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
end
val sem-bt-reset base-sz base base-opnd shifted offset-ext = do
output <- mktemp;
shl base-sz output (imm 1) (var offset-ext);
xorb base-sz output (var output) (imm (0-1));
#xorb base-sz output (imm (0-1)) (imm 1);
#shl base-sz output (var output) (var offset-ext);
andb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
end
val sem-bt-set base-sz base base-opnd shifted offset-ext = do
output <- mktemp;
shl base-sz output (imm 1) (var offset-ext);
orb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
val sem-bt-complement base-sz base base-opnd shifted offset-ext = let
val sem = do
output <- mktemp;
#andb base-sz output (var shifted) (imm 1);
#shl base-sz output (var output) (var offset-ext);
shl base-sz output (imm 1) (var offset-ext);
xorb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
end
in
with-subscope sem
end
val sem-bt-reset base-sz base base-opnd shifted offset-ext = let
val sem = do
output <- mktemp;
shl base-sz output (imm 1) (var offset-ext);
xorb base-sz output (var output) (imm (0-1));
#xorb base-sz output (imm (0-1)) (imm 1);
#shl base-sz output (var output) (var offset-ext);
andb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
end
in
with-subscope sem
end
val sem-bt-set base-sz base base-opnd shifted offset-ext = let
val sem = do
output <- mktemp;
shl base-sz output (imm 1) (var offset-ext);
orb base-sz output (var output) base;
dst <- lval base-sz base-opnd;
write base-sz dst (var output)
end
in
with-subscope sem
end
val sem-bt-none base-sz base base-opnd shifted offset-ext = return void
......@@ -545,6 +557,7 @@ end
## H>>
val sem-hlt = do
#Todo: ...
return void
end
......
......@@ -392,12 +392,12 @@ val sem-packsswb-packssdw-opnd avx-encoded dst-element-size opnd1 opnd2 opnd3 =
dst-offset <- return (dst-element-size*i);
_if (/gts element-size (var (at-offset temp-src src-offset)) (imm upper)) _then (
mov dst-element-size (at-offset temp-dst dst-offset) (imm upper)
) _else ( _if (/lts element-size (var (at-offset temp-src src-offset)) (imm lower)) _then
mov dst-element-size (at-offset temp-dst dst-offset) (imm lower)
_else
mov dst-element-size (at-offset temp-dst dst-offset) (var (at-offset temp-src (src-offset + dst-element-size)))
)
mov dst-element-size (at-offset temp-dst dst-offset) (imm upper)
) _else ( _if (/lts element-size (var (at-offset temp-src src-offset)) (imm lower)) _then
mov dst-element-size (at-offset temp-dst dst-offset) (imm lower)
_else
mov dst-element-size (at-offset temp-dst dst-offset) (var (at-offset temp-src (src-offset + dst-element-size)))
)
end
in
vector-apply (2*size) element-size m
......@@ -520,6 +520,8 @@ val sem-pand-vpand-opnd avx-encoded opnd1 opnd2 opnd3 = do
write-extend avx-encoded size dst (var temp)
end
### => Subscope <=
val sem-pand x = sem-pand-vpand-opnd '0' x.opnd1 x.opnd1 x.opnd2
val sem-vpand x = sem-pand-vpand-opnd '1' x.opnd1 x.opnd2 x.opnd3
......
......@@ -62,19 +62,14 @@ type signedness =
Signed
| Unsigned
val expand conv lin from-sz to-sz = do
val expand expanded conv lin from-sz to-sz =
if from-sz === to-sz then
return lin
mov to-sz expanded lin
else
do
expanded <- mktemp;
case conv of
Signed: movsx to-sz expanded from-sz lin
| Unsigned: movzx to-sz expanded from-sz lin
end;
return (var expanded)
case conv of
Signed: movsx to-sz expanded from-sz lin
| Unsigned: movzx to-sz expanded from-sz lin
end
end
val segment-add mode64 address segment = let
val seg-sem seg-reg = SEM_LIN_VAR(semantic-register-of seg-reg)
......@@ -104,8 +99,9 @@ val segmented-lin lin sz segment = do
real-addr-sz <- real-addr-sz;
mode64 <- mode64?;
expanded <- expand Unsigned lin sz real-addr-sz;
return (segment-add mode64 expanded segment)
expanded <- mktemp;
expand expanded Unsigned lin sz real-addr-sz;
return (segment-add mode64 (var expanded) segment)
end
val segmented-reg reg segment = segmented-lin (var reg) reg.size segment
......@@ -146,7 +142,9 @@ val conv-with conv sz x =
val conv-reg conv sz r = do
reg <- return (semantic-register-of r);
expand conv (var reg) reg.size sz
expanded <- mktemp;
expand expanded conv (var reg) reg.size sz;
return (var expanded)
end
val conv-sum conv sz x =
......@@ -183,12 +181,19 @@ val conv-with conv sz x =
| SUM x: conv-sum conv sz x
| SCALE x: conv-scale conv sz x
| MEM x:
do
t <- mktemp;
address <- conv-mem x;
segmented-load x.sz t x.psz address x.segment;
expand conv (var t) x.sz sz
end
let
val m expanded = do
t <- mktemp;
address <- conv-mem x;
segmented-load x.sz t x.psz address x.segment;
expand expanded conv (var t) x.sz sz
end
in do
expanded <- mktemp;
with-subscope (m expanded);
return (var expanded)
end end
end
end
......@@ -648,117 +653,133 @@ val emit-arithmetic-adjust-flag sz r op0 op1 = do
cmpneq sz af (var t) (imm 0)
end
val emit-add-adc-flags sz sum s0 s1 carry set-carry = do
eq <- fEQ;
les <- fLES;
leu <- fLEU;
lts <- fLTS;
ltu <- fLTU;
sf <- fSF;
ov <- fOF;
z <- fZF;
cf <- fCF;
t1 <- mktemp;
t2 <- mktemp;
t3 <- mktemp;
zer0 <- zero;
cmpltu sz ltu s0 s1;
xorb sz t1 sum s0;
xorb sz t2 sum s1;
andb sz t3 (var t1) (var t2);
cmplts sz ov (var t3) zer0;
cmplts sz sf sum zer0;
cmpeq sz eq sum zer0;
xorb 1 lts (var sf) (var ov);
orb 1 leu (var ltu) (var eq);
orb 1 les (var lts) (var eq);
cmpeq sz z sum zer0;
# Hacker's Delight - Unsigned Add/Subtract
if set-carry then (
_if (/d carry) _then do
cmpleu sz cf sum s0
end _else do
cmpltu sz cf sum s0
end
) else
return void
;
emit-parity-flag sum;
emit-arithmetic-adjust-flag sz sum s0 s1
end
val emit-sub-sbb-flags sz difference minuend subtrahend carry set-carry = do
eq <- fEQ;
les <- fLES;
leu <- fLEU;
lts <- fLTS;
ltu <- fLTU;
sf <- fSF;
ov <- fOF;
cf <- fCF;
z <- fZF;
t1 <- mktemp;
t2 <- mktemp;
t3 <- mktemp;
zer0 <- zero;
cmpltu sz ltu minuend subtrahend;
cmpleu sz leu minuend subtrahend;
cmplts sz lts minuend subtrahend;
cmples sz les minuend subtrahend;
cmpeq sz eq minuend subtrahend;
cmplts sz sf difference zer0;
xorb 1 ov (var lts) (var sf);
cmpeq sz z difference zer0;
if set-carry then (
val emit-add-adc-flags sz sum s0 s1 carry set-carry = let
val emit = do
eq <- fEQ;
les <- fLES;
leu <- fLEU;
lts <- fLTS;
ltu <- fLTU;
sf <- fSF;
ov <- fOF;
z <- fZF;
cf <- fCF;
t1 <- mktemp;
t2 <- mktemp;
t3 <- mktemp;
zer0 <- zero;
cmpltu sz ltu s0 s1;
xorb sz t1 sum s0;
xorb sz t2 sum s1;
andb sz t3 (var t1) (var t2);
cmplts sz ov (var t3) zer0;
cmplts sz sf sum zer0;
cmpeq sz eq sum zer0;
xorb 1 lts (var sf) (var ov);
orb 1 leu (var ltu) (var eq);
orb 1 les (var lts) (var eq);
cmpeq sz z sum zer0;
# Hacker's Delight - Unsigned Add/Subtract
_if (/d carry) _then do
cmpleu sz cf minuend subtrahend
end _else do
cmpltu sz cf minuend subtrahend
end
) else
return void
;
emit-parity-flag difference;
emit-arithmetic-adjust-flag sz difference minuend subtrahend
if set-carry then (
_if (/d carry) _then do
cmpleu sz cf sum s0
end _else do
cmpltu sz cf sum s0
end
) else
return void
;
emit-parity-flag sum;
emit-arithmetic-adjust-flag sz sum s0 s1
end
in
with-subscope emit
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
val emit-sub-sbb-flags sz difference minuend subtrahend carry set-carry = let
val emit = do
eq <- fEQ;
les <- fLES;
leu <- fLEU;
lts <- fLTS;
ltu <- fLTU;
sf <- fSF;
ov <- fOF;
cf <- fCF;
z <- fZF;
t1 <- mktemp;
t2 <- mktemp;
t3 <- mktemp;
zer0 <- zero;
cmpltu sz ltu minuend subtrahend;
cmpleu sz leu minuend subtrahend;
cmplts sz lts minuend subtrahend;
cmples sz les minuend subtrahend;
cmpeq sz eq minuend subtrahend;
cmplts sz sf difference zer0;
xorb 1 ov (var lts) (var sf);
cmpeq sz z difference zer0;
if set-carry then (
# Hacker's Delight - Unsigned Add/Subtract
_if (/d carry) _then do
cmpleu sz cf minuend subtrahend
end _else do
cmpltu sz cf minuend subtrahend
end
) else
return void
;
emit-parity-flag difference;
emit-arithmetic-adjust-flag sz difference minuend subtrahend
end
in
with-subscope emit
end
val move-to-rflags size lin = do
flags <- rflags;
in-mask <- return 0x0000000000245fd5;
out-mask <- return 0xffffffffffc3a02a;
val emit-mul-flags sz product = let
val emit = 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
in
with-subscope emit
end
temp <- mktemp;
andb size temp lin (imm in-mask);
andb size flags (var flags) (imm out-mask);
orb size flags (var flags) (var temp)
val move-to-rflags size lin = let
val emit = do
flags <- rflags;
in-mask <- return 0x0000000000245fd5;
out-mask <- return 0xffffffffffc3a02a;
temp <- mktemp;
andb size temp lin (imm in-mask);
andb size flags (var flags) (imm out-mask);
orb size flags (var flags) (var temp)
end
in
with-subscope emit
end
val direction-adjust reg-size reg-sem for-size = do
......
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