Skip to content

Commit

Permalink
implements support for ARM Modified Immediate Constants
Browse files Browse the repository at this point in the history
Surprisingly we didn't support them
  • Loading branch information
ivg committed Aug 4, 2020
1 parent 1d739df commit 4a35ce4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/arm/arm_mov.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a35ce4

Please sign in to comment.