|
|
@ -401,27 +401,38 @@ BOOL NcFixRelJmps(PNATIVE_CODE_BLOCK Block)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
INT32 BranchDisp = 0;
|
|
|
|
INT32 BranchDisp = 0;
|
|
|
|
if (!NcGetDeltaToLabel(T, &BranchDisp))
|
|
|
|
if (!NcGetDeltaToLabel(T, &BranchDisp))
|
|
|
|
return FALSE;
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n1\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG DispWidth = XedDecodedInstGetBranchDisplacementWidthBits(&T->XedInstruction);
|
|
|
|
ULONG DispWidth = XedDecodedInstGetBranchDisplacementWidthBits(&T->XedInstruction);
|
|
|
|
if (log2(abs(BranchDisp)) + 1 > DispWidth)
|
|
|
|
if (log2(abs(BranchDisp)) + 1 > DispWidth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//duh oh
|
|
|
|
//duh oh
|
|
|
|
if (DispWidth == 32)
|
|
|
|
if (DispWidth == 32)
|
|
|
|
return FALSE;
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n2\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Grow displacement width to required size
|
|
|
|
////Grow displacement width to required size
|
|
|
|
DispWidth *= 2;
|
|
|
|
//DispWidth *= 2;
|
|
|
|
|
|
|
|
|
|
|
|
//Check again
|
|
|
|
////Check again
|
|
|
|
if (log2(abs(BranchDisp)) + 1 > DispWidth)
|
|
|
|
//if (log2(abs(BranchDisp)) + 1 > DispWidth)
|
|
|
|
{
|
|
|
|
//{
|
|
|
|
if (DispWidth == 32)
|
|
|
|
// if (DispWidth == 32)
|
|
|
|
return FALSE;
|
|
|
|
// {
|
|
|
|
|
|
|
|
// printf("\n3\n");
|
|
|
|
|
|
|
|
// return NULL;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//Grow once more if not already at 32
|
|
|
|
// //Grow once more if not already at 32
|
|
|
|
DispWidth *= 2;
|
|
|
|
// DispWidth *= 2;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispWidth = 32;
|
|
|
|
|
|
|
|
|
|
|
|
//Encode new instruction
|
|
|
|
//Encode new instruction
|
|
|
|
XED_STATE MachineState;
|
|
|
|
XED_STATE MachineState;
|
|
|
@ -437,9 +448,17 @@ BOOL NcFixRelJmps(PNATIVE_CODE_BLOCK Block)
|
|
|
|
XedInst1(&EncoderInstruction, MachineState, IClass, DispWidth, XedRelBr(0, DispWidth));
|
|
|
|
XedInst1(&EncoderInstruction, MachineState, IClass, DispWidth, XedRelBr(0, DispWidth));
|
|
|
|
XedEncoderRequestZeroSetMode(&EncoderRequest, &MachineState);
|
|
|
|
XedEncoderRequestZeroSetMode(&EncoderRequest, &MachineState);
|
|
|
|
if (!XedConvertToEncoderRequest(&EncoderRequest, &EncoderInstruction))
|
|
|
|
if (!XedConvertToEncoderRequest(&EncoderRequest, &EncoderInstruction))
|
|
|
|
return FALSE;
|
|
|
|
{
|
|
|
|
if (XED_ERROR_NONE != XedEncode(&EncoderRequest, EncodeBuffer, 15, &ReturnedSize))
|
|
|
|
printf("\n4\n");
|
|
|
|
return FALSE;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XED_ERROR_ENUM Err = XedEncode(&EncoderRequest, EncodeBuffer, 15, &ReturnedSize);
|
|
|
|
|
|
|
|
if (XED_ERROR_NONE != Err)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s %s %u \n", XedErrorEnumToString(Err), XedIClassEnumToString(IClass), DispWidth);
|
|
|
|
|
|
|
|
printf("\n5\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//fixup T->RawData
|
|
|
|
//fixup T->RawData
|
|
|
|
delete[] T->RawData;
|
|
|
|
delete[] T->RawData;
|
|
|
@ -450,7 +469,10 @@ BOOL NcFixRelJmps(PNATIVE_CODE_BLOCK Block)
|
|
|
|
//Decode instruction so its proper and all that
|
|
|
|
//Decode instruction so its proper and all that
|
|
|
|
XedDecodedInstZeroSetMode(&T->XedInstruction, &MachineState);
|
|
|
|
XedDecodedInstZeroSetMode(&T->XedInstruction, &MachineState);
|
|
|
|
if (XED_ERROR_NONE != XedDecode(&T->XedInstruction, T->RawData, T->RawDataSize))
|
|
|
|
if (XED_ERROR_NONE != XedDecode(&T->XedInstruction, T->RawData, T->RawDataSize))
|
|
|
|
return FALSE;
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n6\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Go back to the start and loop through all labels again because now this instruction is larger :))))
|
|
|
|
//Go back to the start and loop through all labels again because now this instruction is larger :))))
|
|
|
|
T = Block->Start;
|
|
|
|
T = Block->Start;
|
|
|
|