1 /* Bra.c -- Converters for RISC code
2 2010-04-16 : Igor Pavlov : Public domain */
6 SizeT
ARM_Convert(Byte
*data
, SizeT size
, UInt32 ip
, int encoding
)
13 for (i
= 0; i
<= size
; i
+= 4)
15 if (data
[i
+ 3] == 0xEB)
18 UInt32 src
= ((UInt32
)data
[i
+ 2] << 16) | ((UInt32
)data
[i
+ 1] << 8) | (data
[i
+ 0]);
21 dest
= ip
+ (UInt32
)i
+ src
;
23 dest
= src
- (ip
+ (UInt32
)i
);
25 data
[i
+ 2] = (Byte
)(dest
>> 16);
26 data
[i
+ 1] = (Byte
)(dest
>> 8);
27 data
[i
+ 0] = (Byte
)dest
;
33 SizeT
ARMT_Convert(Byte
*data
, SizeT size
, UInt32 ip
, int encoding
)
40 for (i
= 0; i
<= size
; i
+= 2)
42 if ((data
[i
+ 1] & 0xF8) == 0xF0 &&
43 (data
[i
+ 3] & 0xF8) == 0xF8)
47 (((UInt32
)data
[i
+ 1] & 0x7) << 19) |
48 ((UInt32
)data
[i
+ 0] << 11) |
49 (((UInt32
)data
[i
+ 3] & 0x7) << 8) |
54 dest
= ip
+ (UInt32
)i
+ src
;
56 dest
= src
- (ip
+ (UInt32
)i
);
59 data
[i
+ 1] = (Byte
)(0xF0 | ((dest
>> 19) & 0x7));
60 data
[i
+ 0] = (Byte
)(dest
>> 11);
61 data
[i
+ 3] = (Byte
)(0xF8 | ((dest
>> 8) & 0x7));
62 data
[i
+ 2] = (Byte
)dest
;
69 SizeT
PPC_Convert(Byte
*data
, SizeT size
, UInt32 ip
, int encoding
)
75 for (i
= 0; i
<= size
; i
+= 4)
77 if ((data
[i
] >> 2) == 0x12 && (data
[i
+ 3] & 3) == 1)
79 UInt32 src
= ((UInt32
)(data
[i
+ 0] & 3) << 24) |
80 ((UInt32
)data
[i
+ 1] << 16) |
81 ((UInt32
)data
[i
+ 2] << 8) |
82 ((UInt32
)data
[i
+ 3] & (~3));
86 dest
= ip
+ (UInt32
)i
+ src
;
88 dest
= src
- (ip
+ (UInt32
)i
);
89 data
[i
+ 0] = (Byte
)(0x48 | ((dest
>> 24) & 0x3));
90 data
[i
+ 1] = (Byte
)(dest
>> 16);
91 data
[i
+ 2] = (Byte
)(dest
>> 8);
99 SizeT
SPARC_Convert(Byte
*data
, SizeT size
, UInt32 ip
, int encoding
)
105 for (i
= 0; i
<= size
; i
+= 4)
107 if ((data
[i
] == 0x40 && (data
[i
+ 1] & 0xC0) == 0x00) ||
108 (data
[i
] == 0x7F && (data
[i
+ 1] & 0xC0) == 0xC0))
111 ((UInt32
)data
[i
+ 0] << 24) |
112 ((UInt32
)data
[i
+ 1] << 16) |
113 ((UInt32
)data
[i
+ 2] << 8) |
114 ((UInt32
)data
[i
+ 3]);
121 dest
= src
- (ip
+ i
);
124 dest
= (((0 - ((dest
>> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest
& 0x3FFFFF) | 0x40000000;
126 data
[i
+ 0] = (Byte
)(dest
>> 24);
127 data
[i
+ 1] = (Byte
)(dest
>> 16);
128 data
[i
+ 2] = (Byte
)(dest
>> 8);
129 data
[i
+ 3] = (Byte
)dest
;