diff --git a/lib/arm/arm_mov.ml b/lib/arm/arm_mov.ml index 6241a3e16e..008cb1fe70 100644 --- a/lib/arm/arm_mov.ml +++ b/lib/arm/arm_mov.ml @@ -9,8 +9,35 @@ open Arm_flags module Env = Arm_env module Shift = Arm_shift +let width = 32 + + +(** Modified Immediate Constants *) +module MIC : sig + val decode : op -> op +end = struct + let ror value bits = + let p1 = Word.(value lsr bits) in + let rs = Word.(of_int ~width 32 - bits) in + let p2 = Word.(value lsl rs) in + Word.(p1 lor p2) + + let mic x = + let shift = Word.extract_exn ~hi:11 ~lo:8 x + and value = Word.extract_exn ~hi:7 ~lo:0 x in + if Word.is_zero shift then value + else + let shift = Word.extract_exn ~hi:31 shift in + let value = Word.extract_exn ~hi:31 value in + ror value Word.(shift + shift) + + let decode = function + | `Imm x -> `Imm (mic x) + | other -> other +end let lift ?dest src1 ?src2 (itype ) ?sreg ?simm raw ~wflag cond = + let src2 = Option.map src2 ~f:MIC.decode in let dest : var = match dest with | None -> tmp reg32_t | Some (`Reg reg) -> Env.of_reg reg