Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pc value in pc-relative thumb ldr #1414

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plugins/thumb/thumb_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,20 @@ module Thumb(CT : Theory.Core) = struct
!!Insn.empty


let lift_mem pc opcode insn =
let lift_mem addr opcode insn =
let module Mem = Thumb_mem.Make(CT) in
let open Mem in
let pc = W32.(addr + int 4) in
match opcode, (MC.Insn.ops insn : Op.t array) with
| `tLDRi, [|Reg rd; Reg rm; Imm i; Imm c; _|]
| `tLDRspi, [|Reg rd; Reg rm; Imm i; Imm c; _|] ->
ldri (reg rd) (reg rm) (imm i * 4) (cnd c)
| `tLDRr, [|Reg rd; Reg rm; Reg rn; Imm c; _|] ->
ldrr (reg rd) (reg rm) (reg rn) (cnd c)
| `tLDRpci, [|Reg rd; Imm i; Imm c; _|] ->
ldrpci (reg rd) W32.(pc + int 2) (imm i) (cnd c)
ldrpci (reg rd) pc (imm i) (cnd c)
| `t2LDRpci, [|Reg rd; Imm i; Imm c; _|] ->
ldrpci (reg rd) W32.(pc + int 4) (imm i) (cnd c)
ldrpci (reg rd) pc (imm i) (cnd c)
| `tLDRBi, [|Reg rd; Reg rm; Imm i; Imm c; _|] ->
ldrbi (reg rd) (reg rm) (imm i) (cnd c)
| `tLDRBr, [|Reg rd; Reg rm; Reg rn; Imm c; _|] ->
Expand Down
2 changes: 1 addition & 1 deletion plugins/thumb/thumb_mem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Make(CT : Theory.Core) = struct
rd <-? signed @@ load s16 (var rn + var rm)

let ldrpci rd pc off =
rd <-? load s32 @@ bitv pc + const off
rd <-? load s32 @@ bitv W32.(pc land ~~(int 3)) + const off

let ldm b regs cnd =
branch cnd [
Expand Down