Skip to content

Commit 119e226

Browse files
committed
fix(powerpc): fix immediate size
1 parent 5257f12 commit 119e226

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

plugins/powerpc/powerpc.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,18 @@ module Std : sig
351351
(** The type of lifter functions *)
352352

353353
val signed : 'a ec -> 'a
354-
(** [signed ec] - returnst a signed expression from given [ec] *)
354+
(** [signed ec] - returns a signed expression from given [ec] *)
355355

356356
val unsigned : 'a ec -> 'a
357357
(** [unsigned ec] - returns an unsigned expression from given [ec] *)
358358

359359
val imm : (op -> exp) ec
360360
(** imm constructor - constructs an immediate from operand *)
361361

362+
val imm_32 : (op -> exp) ec
363+
(** imm_32 constructor - constructs an immediate from operand without trimming to 16 bits
364+
*)
365+
362366
val var : (bitwidth -> exp) ec
363367
(** var constructor - constructs a variable of bitwidth *)
364368

plugins/powerpc/powerpc_branch.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ let update_link_register cpu _ops =
77
examples: 4b ff fe f0 b .+67108592 4b ff fe f2 ba 67108592 4b ff fe f1 bl
88
.+67108592 4b ff fe f3 bla 67108592 *)
99
let b cpu ops =
10-
let im = signed imm ops.(0) in
10+
let im = signed imm_32 ops.(0) in
1111
let tm = signed var cpu.word_width in
1212
let sh = unsigned const byte 2 in
1313
RTL.[ tm := last (im << sh) 26; cpu.jmp (cpu.pc + tm) ]
1414

1515
let ba cpu ops =
16-
let im = signed imm ops.(0) in
16+
let im = signed imm_32 ops.(0) in
1717
let tm = signed var cpu.word_width in
1818
let sh = unsigned const byte 2 in
1919
RTL.[ tm := last (im << sh) 26; cpu.jmp tm ]
@@ -25,9 +25,9 @@ let bla = update_link_register ^ ba
2525
3.0 B examples: 42 9f 00 04 bc 20, 31, .+4 42 9f 00 06 bca 20, 31, 4 42 9f
2626
00 05 bcl 20, 31, .+4 42 9f 00 07 bcla 20, 31, 4 *)
2727
let bc cpu ops =
28-
let bo = unsigned imm ops.(0) in
28+
let bo = unsigned imm_32 ops.(0) in
2929
let bi = unsigned cpu.reg ops.(1) in
30-
let bd = signed imm ops.(2) in
30+
let bd = signed imm_32 ops.(2) in
3131
let sh = unsigned const byte 2 in
3232
let ctr_ok = unsigned var bit in
3333
let cond_ok = unsigned var bit in
@@ -44,9 +44,9 @@ let bc cpu ops =
4444
]
4545

4646
let bca cpu ops =
47-
let bo = unsigned imm ops.(0) in
47+
let bo = unsigned imm_32 ops.(0) in
4848
let bi = unsigned cpu.reg ops.(1) in
49-
let bd = signed imm ops.(2) in
49+
let bd = signed imm_32 ops.(2) in
5050
let sh = unsigned const byte 2 in
5151
let ctr_ok = unsigned var bit in
5252
let cond_ok = unsigned var bit in
@@ -66,7 +66,7 @@ let bcla = update_link_register ^ bca
6666

6767
(** bdz target = bc 18,0, target *)
6868
let bdz cpu ops =
69-
let bd = unsigned imm ops.(0) in
69+
let bd = unsigned imm_32 ops.(0) in
7070
let sh = unsigned const byte 2 in
7171
let tm = signed var cpu.word_width in
7272
RTL.
@@ -79,7 +79,7 @@ let bdz cpu ops =
7979

8080
(** bdnz target = bc 16,0, target *)
8181
let bdnz cpu ops =
82-
let bd = unsigned imm ops.(0) in
82+
let bd = unsigned imm_32 ops.(0) in
8383
let sh = unsigned const byte 2 in
8484
let tm = signed var cpu.word_width in
8585
RTL.
@@ -94,7 +94,7 @@ let bdnz cpu ops =
9494
Power ISATM Version 3.0 B examples: 4e 9f 00 20 bclr 20, 31 4e 9f 00 21
9595
bclrl 20, 31 *)
9696
let bclr cpu ops =
97-
let bo = unsigned imm ops.(0) in
97+
let bo = unsigned imm_32 ops.(0) in
9898
let bi = unsigned cpu.reg ops.(1) in
9999
let sh = unsigned const byte 2 in
100100
let ctr_ok = unsigned var bit in
@@ -111,7 +111,7 @@ let bclr cpu ops =
111111
]
112112

113113
let bclrl cpu ops =
114-
let bo = unsigned imm ops.(0) in
114+
let bo = unsigned imm_32 ops.(0) in
115115
let bi = unsigned cpu.reg ops.(1) in
116116
let sh = unsigned const byte 2 in
117117
let ctr_ok = unsigned var bit in
@@ -162,7 +162,7 @@ let bdnzlr cpu _ops =
162162
Power ISATM Version 3.0 B examples: 4d 5f 04 20 bcctr 10,31 4d 5f 04 21
163163
bcctrl 10,31 *)
164164
let bcctr cpu ops =
165-
let bo = unsigned imm ops.(0) in
165+
let bo = unsigned imm_32 ops.(0) in
166166
let bi = unsigned cpu.reg ops.(1) in
167167
let cond_ok = unsigned var bit in
168168
let x = unsigned var (bitwidth 5) in
@@ -189,7 +189,7 @@ let bctrl = update_link_register ^ bctr
189189
IBM Power ISATM Version 3.0 B examples: 4e 9f 04 60 bctar 4e 9f 04 61 bctarl
190190
*)
191191
let bctar cpu ops =
192-
let bo = unsigned imm ops.(0) in
192+
let bo = unsigned imm_32 ops.(0) in
193193
let bi = unsigned cpu.reg ops.(1) in
194194
let sh = unsigned const byte 2 in
195195
let cond_ok = unsigned var bit in

plugins/powerpc/powerpc_dsl.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ let int_of_imm = function
2424
| Some x -> x
2525
| None -> ppc_fail "failed to convert imm operand to int")
2626

27-
let imm signed op =
28-
let w = Word.of_int ~width:32 (int_of_imm op) in
27+
let imm' width signed op =
28+
let w = Word.of_int ~width (int_of_imm op) in
2929
if signed then Exp.(signed @@ of_word w) else Exp.(unsigned @@ of_word w)
3030

31+
let imm = imm' 16
32+
let imm_32 = imm' 32
3133
let signed f = f true
3234
let unsigned f = f false
3335
let apply_signess signed e = if signed then Exp.signed e else Exp.unsigned e

plugins/powerpc/powerpc_dsl.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ val quadword : bitwidth
1414
val bitwidth : int -> bitwidth
1515
val int_of_bitwidth : bitwidth -> int
1616
val imm : (op -> exp) ec
17+
val imm_32 : (op -> exp) ec
1718
val var : (bitwidth -> exp) ec
1819
val reg : (reg -> exp) -> (op -> exp) ec
1920
val const : (bitwidth -> int -> exp) ec

plugins/powerpc/powerpc_logical.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ open Powerpc.Std
1010
let andi cpu ops =
1111
let ra = unsigned cpu.reg ops.(0) in
1212
let rs = unsigned cpu.reg ops.(1) in
13-
let im = unsigned imm ops.(2) in
13+
let im = unsigned imm_32 ops.(2) in
1414
RTL.[ ra := rs land im ]
1515

1616
(** Fixed-point AND Immediate Shifted Pages 92-98 of IBM Power ISATM Version 3.0
1717
B examples: 75 2a 08 00 andis. r10,r9,2048 *)
1818
let andis cpu ops =
1919
let ra = unsigned cpu.reg ops.(0) in
2020
let rs = unsigned cpu.reg ops.(1) in
21-
let im = unsigned imm ops.(2) in
21+
let im = unsigned imm_32 ops.(2) in
2222
let sh = unsigned const byte 16 in
2323
RTL.[ ra := rs land (im << sh) ]
2424

@@ -43,7 +43,7 @@ let andc cpu ops =
4343
let ori cpu ops =
4444
let ra = unsigned cpu.reg ops.(0) in
4545
let rs = unsigned cpu.reg ops.(1) in
46-
let im = unsigned imm ops.(2) in
46+
let im = unsigned imm_32 ops.(2) in
4747
RTL.[ ra := rs lor im ]
4848

4949
(** 60 00 00 00 nop (equivalen to ori 0,0,0 *)
@@ -54,7 +54,7 @@ let nop cpu ops = []
5454
let oris cpu ops =
5555
let ra = unsigned cpu.reg ops.(0) in
5656
let rs = unsigned cpu.reg ops.(1) in
57-
let im = unsigned imm ops.(2) in
57+
let im = unsigned imm_32 ops.(2) in
5858
let sh = unsigned const byte 16 in
5959
RTL.[ ra := rs lor (im << sh) ]
6060

@@ -79,15 +79,15 @@ let orc cpu ops =
7979
let xori cpu ops =
8080
let ra = unsigned cpu.reg ops.(0) in
8181
let rs = unsigned cpu.reg ops.(1) in
82-
let im = unsigned imm ops.(2) in
82+
let im = unsigned imm_32 ops.(2) in
8383
RTL.[ ra := rs lxor im ]
8484

8585
(** Fixed-point XOR Immediate Shifted Pages 92-98 of IBM Power ISATM Version 3.0
8686
B examples: 6d 2a 04 00 xoris r10,r9,1024 *)
8787
let xoris cpu ops =
8888
let ra = unsigned cpu.reg ops.(0) in
8989
let rs = unsigned cpu.reg ops.(1) in
90-
let im = unsigned imm ops.(2) in
90+
let im = unsigned imm_32 ops.(2) in
9191
let sh = unsigned const byte 16 in
9292
RTL.[ ra := rs lxor (im << sh) ]
9393

0 commit comments

Comments
 (0)