Skip to content

Commit

Permalink
ia32: backtrace signed idiv
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyg committed Oct 21, 2020
1 parent 8ad91f1 commit bfa8fbd
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions metasm/cpu/ia32/decode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,28 +544,26 @@ def init_backtrace_binding
end
}
when 'div', 'idiv'; lambda { |di, a0|
# TODO idiv => signed
case opsz(di)
when 8
s = opsz(di)
m = mask[di]
if s == 8
src = Expression[eax, :&, 0xffff]
quot = Expression[[src, :/, a0], :&, 0xff]
rem = Expression[[src, :%, a0], :&, 0xff]
else
src = Expression[[eax, :&, m], :|, [[edx, :&, m], :<<, s]]
end
quot = Expression[[src, :/, a0], :&, m]
rem = Expression[[src, :%, a0], :&, m]
if op == 'idiv'
nquot = Expression[[1 << (2*s), :-, [[1 << (2*s), :-, src], :/, a0]], :&, m]
nrem = Expression[[1 << (2*s), :-, [[1 << (2*s), :-, src], :%, a0]], :&, m]
sgn = Expression[[src, :>>, 2*s-1], :&, 1]
quot = Expression[[[1, :-, sgn], :*, quot], :|, [sgn, :*, nquot]]
rem = Expression[[[1, :-, sgn], :*, rem ], :|, [sgn, :*, nrem ]]
end
if s == 8
{ Expression[eax, :&, 0xffff] => Expression[quot, :|, [rem, :<<, 8]] }
when 16
src = Expression[[eax, :&, 0xffff], :|, [[edx, :&, 0xffff], :<<, 16]]
quot = Expression[[src, :/, a0], :&, 0xffff]
rem = Expression[[src, :%, a0], :&, 0xffff]
{ Expression[eax, :&, 0xffff] => quot, Expression[edx, :&, 0xffff] => rem }
when 32
src = Expression[[eax, :&, 0xffffffff], :|, [[edx, :&, 0xffffffff], :<<, 32]]
quot = Expression[[src, :/, a0], :&, 0xffffffff]
rem = Expression[[src, :%, a0], :&, 0xffffffff]
{ Expression[eax, :&, 0xffffffff] => quot, Expression[edx, :&, 0xffffffff] => rem }
when 64
src = Expression[eax, :|, [edx, :<<, 64]]
quot = Expression[src, :/, a0]
rem = Expression[src, :%, a0]
{ eax => quot, edx => rem }
else
{ Expression[eax, :&, m] => quot, Expression[edx, :&, m] => rem }
end
}
when 'rdtsc'; lambda { |di| { eax => Expression::Unknown, edx => Expression::Unknown, :incomplete_binding => Expression[1] } }
Expand Down

0 comments on commit bfa8fbd

Please sign in to comment.