diff src/win32/7zip/7z/C/BraIA64.c @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/C/BraIA64.c	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,67 @@
     1.4 +/* BraIA64.c -- Converter for IA-64 code
     1.5 +2008-10-04 : Igor Pavlov : Public domain */
     1.6 +
     1.7 +#include "Bra.h"
     1.8 +
     1.9 +static const Byte kBranchTable[32] =
    1.10 +{
    1.11 +  0, 0, 0, 0, 0, 0, 0, 0,
    1.12 +  0, 0, 0, 0, 0, 0, 0, 0,
    1.13 +  4, 4, 6, 6, 0, 0, 7, 7,
    1.14 +  4, 4, 0, 0, 4, 4, 0, 0
    1.15 +};
    1.16 +
    1.17 +SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
    1.18 +{
    1.19 +  SizeT i;
    1.20 +  if (size < 16)
    1.21 +    return 0;
    1.22 +  size -= 16;
    1.23 +  for (i = 0; i <= size; i += 16)
    1.24 +  {
    1.25 +    UInt32 instrTemplate = data[i] & 0x1F;
    1.26 +    UInt32 mask = kBranchTable[instrTemplate];
    1.27 +    UInt32 bitPos = 5;
    1.28 +    int slot;
    1.29 +    for (slot = 0; slot < 3; slot++, bitPos += 41)
    1.30 +    {
    1.31 +      UInt32 bytePos, bitRes;
    1.32 +      UInt64 instruction, instNorm;
    1.33 +      int j;
    1.34 +      if (((mask >> slot) & 1) == 0)
    1.35 +        continue;
    1.36 +      bytePos = (bitPos >> 3);
    1.37 +      bitRes = bitPos & 0x7;
    1.38 +      instruction = 0;
    1.39 +      for (j = 0; j < 6; j++)
    1.40 +        instruction += (UInt64)data[i + j + bytePos] << (8 * j);
    1.41 +
    1.42 +      instNorm = instruction >> bitRes;
    1.43 +      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
    1.44 +      {
    1.45 +        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
    1.46 +        UInt32 dest;
    1.47 +        src |= ((UInt32)(instNorm >> 36) & 1) << 20;
    1.48 +        
    1.49 +        src <<= 4;
    1.50 +        
    1.51 +        if (encoding)
    1.52 +          dest = ip + (UInt32)i + src;
    1.53 +        else
    1.54 +          dest = src - (ip + (UInt32)i);
    1.55 +        
    1.56 +        dest >>= 4;
    1.57 +        
    1.58 +        instNorm &= ~((UInt64)(0x8FFFFF) << 13);
    1.59 +        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
    1.60 +        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
    1.61 +        
    1.62 +        instruction &= (1 << bitRes) - 1;
    1.63 +        instruction |= (instNorm << bitRes);
    1.64 +        for (j = 0; j < 6; j++)
    1.65 +          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
    1.66 +      }
    1.67 +    }
    1.68 +  }
    1.69 +  return i;
    1.70 +}