3 #include "BranchIA64.h"
5 const Byte kBranchTable[32] =
7 0, 0, 0, 0, 0, 0, 0, 0,
8 0, 0, 0, 0, 0, 0, 0, 0,
9 4, 4, 6, 6, 0, 0, 7, 7,
10 4, 4, 0, 0, 4, 4, 0, 0
13 UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
16 for (i = 0; i + 16 <= size; i += 16)
18 UInt32 instrTemplate = data[i] & 0x1F;
19 UInt32 mask = kBranchTable[instrTemplate];
22 for (slot = 0; slot < 3; slot++, bitPos += 41)
24 UInt32 bytePos, bitRes;
25 UInt64 instruction, instNorm;
27 if (((mask >> slot) & 1) == 0)
29 bytePos = (bitPos >> 3);
30 bitRes = bitPos & 0x7;
32 for (j = 0; j < 6; j++)
33 instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);
35 instNorm = instruction >> bitRes;
36 if (((instNorm >> 37) & 0xF) == 0x5
37 && ((instNorm >> 9) & 0x7) == 0
38 /* && (instNorm & 0x3F)== 0 */
41 UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
43 src |= ((UInt32)(instNorm >> 36) & 1) << 20;
48 dest = nowPos + i + src;
50 dest = src - (nowPos + i);
54 instNorm &= ~((UInt64)(0x8FFFFF) << 13);
55 instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
56 instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
58 instruction &= (1 << bitRes) - 1;
59 instruction |= (instNorm << bitRes);
60 for (j = 0; j < 6; j++)
61 data[i + j + bytePos] = (Byte)(instruction >> (8 * j));