Skip to content

Commit 7a18ffb

Browse files
authored
implements support for ARM Modified Immediate Constants (#1196)
Surprisingly we didn't support them, only when an explicit shift was used.
1 parent 4d34311 commit 7a18ffb

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lib/arm/arm_mov.ml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ open Arm_flags
99
module Env = Arm_env
1010
module Shift = Arm_shift
1111

12+
let width = 32
13+
14+
15+
(** Modified Immediate Constants *)
16+
module MIC : sig
17+
val decode : exp -> exp
18+
end = struct
19+
let ror value bits =
20+
let p1 = Word.(value lsr bits) in
21+
let rs = Word.(of_int ~width 32 - bits) in
22+
let p2 = Word.(value lsl rs) in
23+
Word.(p1 lor p2)
24+
25+
let mic x =
26+
let shift = Word.extract_exn ~hi:11 ~lo:8 x
27+
and value = Word.extract_exn ~hi:7 ~lo:0 x in
28+
if Word.is_zero shift then x
29+
else
30+
let shift = Word.extract_exn ~hi:31 shift in
31+
let value = Word.extract_exn ~hi:31 value in
32+
ror value Word.(shift + shift)
33+
34+
let decode = function
35+
| Bil.Int x -> Bil.Int (mic x)
36+
| other -> other
37+
end
1238

1339
let lift ?dest src1 ?src2 (itype ) ?sreg ?simm raw ~wflag cond =
1440
let dest : var = match dest with
@@ -45,7 +71,7 @@ let lift ?dest src1 ?src2 (itype ) ?sreg ?simm raw ~wflag cond =
4571
let shifted, carry = Shift.lift_i
4672
~src:Bil.(var unshifted) simm reg32_t in
4773
s1, shifted, [Bil.move unshifted s2], carry
48-
| _ -> s1, s2, [], Bil.var Env.cf in
74+
| _ -> s1, (MIC.decode s2), [], Bil.var Env.cf in
4975

5076
let stmts, flags = match itype, src1, src2 with
5177
| `MOV, `Imm i64, _

0 commit comments

Comments
 (0)