1 /* Bra.c -- Converters for RISC code
\r
2 2010-04-16 : Igor Pavlov : Public domain */
\r
8 SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
\r
15 for (i = 0; i <= size; i += 4)
\r
17 if (data[i + 3] == 0xEB)
\r
20 UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
\r
23 dest = ip + (UInt32)i + src;
\r
25 dest = src - (ip + (UInt32)i);
\r
27 data[i + 2] = (Byte)(dest >> 16);
\r
28 data[i + 1] = (Byte)(dest >> 8);
\r
29 data[i + 0] = (Byte)dest;
\r
35 SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
\r
42 for (i = 0; i <= size; i += 2)
\r
44 if ((data[i + 1] & 0xF8) == 0xF0 &&
\r
45 (data[i + 3] & 0xF8) == 0xF8)
\r
49 (((UInt32)data[i + 1] & 0x7) << 19) |
\r
50 ((UInt32)data[i + 0] << 11) |
\r
51 (((UInt32)data[i + 3] & 0x7) << 8) |
\r
56 dest = ip + (UInt32)i + src;
\r
58 dest = src - (ip + (UInt32)i);
\r
61 data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
\r
62 data[i + 0] = (Byte)(dest >> 11);
\r
63 data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
\r
64 data[i + 2] = (Byte)dest;
\r
71 SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
\r
77 for (i = 0; i <= size; i += 4)
\r
79 if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
\r
81 UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
\r
82 ((UInt32)data[i + 1] << 16) |
\r
83 ((UInt32)data[i + 2] << 8) |
\r
84 ((UInt32)data[i + 3] & (~3));
\r
88 dest = ip + (UInt32)i + src;
\r
90 dest = src - (ip + (UInt32)i);
\r
91 data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
\r
92 data[i + 1] = (Byte)(dest >> 16);
\r
93 data[i + 2] = (Byte)(dest >> 8);
\r
95 data[i + 3] |= dest;
\r
101 SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
\r
107 for (i = 0; i <= size; i += 4)
\r
109 if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
\r
110 (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
\r
113 ((UInt32)data[i + 0] << 24) |
\r
114 ((UInt32)data[i + 1] << 16) |
\r
115 ((UInt32)data[i + 2] << 8) |
\r
116 ((UInt32)data[i + 3]);
\r
121 dest = ip + i + src;
\r
123 dest = src - (ip + i);
\r
126 dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
\r
128 data[i + 0] = (Byte)(dest >> 24);
\r
129 data[i + 1] = (Byte)(dest >> 16);
\r
130 data[i + 2] = (Byte)(dest >> 8);
\r
131 data[i + 3] = (Byte)dest;
\r