Exemplo n.º 1
0
void swap_JournalInfoBlock(JournalInfoBlock* record)
{
    // trace("record (%p)", record);

    /*
       struct JournalInfoBlock {
       uint32_t	flags;
       uint32_t       device_signature[8];  // signature used to locate our device.
       uint64_t       offset;               // byte offset to the journal on the device
       uint64_t       size;                 // size in bytes of the journal
       uuid_string_t   ext_jnl_uuid;
       char            machine_serial_num[48];
       char     reserved[JIB_RESERVED_SIZE];
       } __attribute__((aligned(2), packed));
       typedef struct JournalInfoBlock JournalInfoBlock;
     */
    Swap32(record->flags);
    for(unsigned i = 0; i < 8; i++)
        Swap32(record->device_signature[i]);
    Swap64(record->offset);
    Swap64(record->size);
    // noswap: uuid_string_t is a series of char
    // noswap: machine_serial_num is a series of char
    // noswap: reserved is reserved
}
Exemplo n.º 2
0
void swap_HFSPlusExtentKey(HFSPlusExtentKey* record)
{
    // trace("record (%p)", record);
//    noswap: keyLength; swapped in swap_BTNode
    Swap32(record->fileID);
    Swap32(record->startBlock);
}
Exemplo n.º 3
0
static lua_Number LoadNumber(LoadState* S)
{
 lua_Number x;
 LoadVar(S,x);
 if (!S->flip)
  return x;
#ifdef LUA_NUMBER_DOUBLE
 {
	 union { double d; uint32_t i[2]; } u;
	 uint32_t temp;
	 u.d = x;
	 temp = Swap32(u.i[0]);
	 u.i[0] = Swap32(u.i[1]);
	 u.i[1] = temp;
	 return u.d;
 }
#else
 {
	 union { float f; uint32_t i } u;
	 u.f = x;
	 u.i = Swap32(u.i);
	 return u.f;
 }
#endif
}
Exemplo n.º 4
0
void swap_HFSPlusForkData(HFSPlusForkData* record)
{
    // trace("record (%p)", record);
    Swap64(record->logicalSize);
    Swap32(record->totalBlocks);
    Swap32(record->clumpSize);
    swap_HFSPlusExtentRecord(record->extents);
}
Exemplo n.º 5
0
/**
*
* Perform a destructive 32-bit wide register IO test. Each location is tested
* by sequentially writing a 32-bit wide regsiter, reading the register, and
* comparing value. This function tests three kinds of register IO functions,
* normal register IO, little-endian register IO, and big-endian register IO.
* When testing little/big-endian IO, the function perform the following
* sequence, Xil_Out32LE/Xil_Out32BE, Xil_In32, Compare,
* Xil_Out32, Xil_In32LE/Xil_In32BE, Compare. Whether to swap the read-in value
* before comparing is controlled by the 5th argument.
*
* @param	Addr is a pointer to the region of memory to be tested.
* @param	Length is the Length of the block.
* @param	Value is the constant used for writting the memory.
* @param	Kind is the test kind. Acceptable values are:
*		XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
* @param	Swap indicates whether to byte swap the read-in value.
*
* @return
*
* - -1 is returned for a failure
* - 0 is returned for a pass
*
*****************************************************************************/
s32 Xil_TestIO32(u32 *Addr, s32 Length, u32 Value, s32 Kind, s32 Swap)
{
	u32 *TempAddr;
	u32 ValueIn = 0U;
	s32 Index;
	TempAddr = Addr;
	Xil_AssertNonvoid(TempAddr != NULL);

	for (Index = 0; Index < Length; Index++) {
		switch (Kind) {
		case XIL_TESTIO_LE:
			Xil_Out32LE((INTPTR)TempAddr, Value);
			break;
		case XIL_TESTIO_BE:
			Xil_Out32BE((INTPTR)TempAddr, Value);
			break;
		default:
			Xil_Out32((INTPTR)TempAddr, Value);
			break;
		}

		ValueIn = Xil_In32((INTPTR)TempAddr);

		if ((Kind != 0) && (Swap != 0)) {
			ValueIn = Swap32(ValueIn);
		}

		if (Value != ValueIn) {
			return -1;
		}

		/* second round */
		Xil_Out32((INTPTR)TempAddr, Value);


		switch (Kind) {
		case XIL_TESTIO_LE:
			ValueIn = Xil_In32LE((INTPTR)TempAddr);
			break;
		case XIL_TESTIO_BE:
			ValueIn = Xil_In32BE((INTPTR)TempAddr);
			break;
		default:
			ValueIn = Xil_In32((INTPTR)TempAddr);
			break;
		}

		if ((Kind != 0) && (Swap != 0)) {
			ValueIn = Swap32(ValueIn);
		}

		if (Value != ValueIn) {
			return -1;
		}
		TempAddr += sizeof(u32);
	}
	return 0;
}
Exemplo n.º 6
0
void swap_HFSPlusCatalogThread(HFSPlusCatalogThread* record)
{
    // trace("record (%p)", record);

//    Swap16(record->recordType);
    Swap32(record->reserved);
    Swap32(record->parentID);
    swap_HFSUniStr255(&record->nodeName);
}
Exemplo n.º 7
0
void swap_HFSPlusAttrKey(HFSPlusAttrKey* record)
{
    // trace("record (%p)", record);
//    noswap: keyLength; swapped in swap_BTNode
    Swap16(record->pad);
    Swap32(record->fileID);
    Swap32(record->startBlock);
    Swap16(record->attrNameLen);
    for(unsigned i = 0; i < record->attrNameLen; i++) Swap16(record->attrName[i]);
}
Exemplo n.º 8
0
void swap_FndrFileInfo(FndrFileInfo* record)
{
    // trace("record (%p)", record);

    Swap32(record->fdType);
    Swap32(record->fdCreator);
    Swap16(record->fdFlags);
    Swap16(record->fdLocation.v);
    Swap16(record->fdLocation.h);
    Swap16(record->opaque);
}
Exemplo n.º 9
0
void swap_HFSPlusBSDInfo(HFSPlusBSDInfo* record)
{
    // trace("record (%p)", record);

    Swap32(record->ownerID);
    Swap32(record->groupID);
    // noswap: adminFlags is a byte
    // noswap: ownerFlags is a byte
    Swap16(record->fileMode);
    Swap32(record->special.iNodeNum);
}
Exemplo n.º 10
0
/**
*
* Perform a destructive 32-bit wide register IO test. Each location is tested
* by sequentially writing a 32-bit wide regsiter, reading the register, and
* comparing value. This function tests three kinds of register IO functions,
* normal register IO, little-endian register IO, and big-endian register IO.
* When testing little/big-endian IO, the function perform the following
* sequence, Xil_Out32LE/Xil_Out32BE, Xil_In32, Compare,
* Xil_Out32, Xil_In32LE/Xil_In32BE, Compare. Whether to swap the read-in value
* before comparing is controlled by the 5th argument.
*
* @param	Addr is a pointer to the region of memory to be tested.
* @param	Len is the length of the block.
* @param	Value is the constant used for writting the memory.
* @param	Kind is the test kind. Acceptable values are:
*		XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
* @param	Swap indicates whether to byte swap the read-in value.
*
* @return
*
* - -1 is returned for a failure
* - 0 is returned for a pass
*
*****************************************************************************/
int Xil_TestIO32(u32 *Addr, int Len, u32 Value, int Kind, int Swap)
{
	u32 ValueIn;
	int Index;

	for (Index = 0; Index < Len; Index++) {
		switch (Kind) {
		case XIL_TESTIO_LE:
			Xil_Out32LE((u32)Addr, Value);
			break;
		case XIL_TESTIO_BE:
			Xil_Out32BE((u32)Addr, Value);
			break;
		default:
			Xil_Out32((u32)Addr, Value);
			break;
		}

		ValueIn = Xil_In32((u32)Addr);

		if (Kind && Swap)
			ValueIn = Swap32(ValueIn);

		if (Value != ValueIn) {
			return -1;
		}

		/* second round */
		Xil_Out32((u32)Addr, Value);


		switch (Kind) {
		case XIL_TESTIO_LE:
			ValueIn = Xil_In32LE((u32)Addr);
			break;
		case XIL_TESTIO_BE:
			ValueIn = Xil_In32BE((u32)Addr);
			break;
		default:
			ValueIn = Xil_In32((u32)Addr);
			break;
		}

		if (Kind && Swap)
			ValueIn = Swap32(ValueIn);

		if (Value != ValueIn) {
			return -1;
		}
		Addr++;
	}
	return 0;
}
Exemplo n.º 11
0
uint64_t Swap64(uint64_t x)
{
   uint32_t hi, lo;

   /* Separate into high and low 32-bit values and swap them */
   lo = (uint32_t)(x & 0xFFFFFFFF);
   x >>= 32;
   hi = (uint32_t)(x & 0xFFFFFFFF);
   x = Swap32(lo);
   x <<= 32;
   x |= Swap32(hi);
   return(x);
}
Exemplo n.º 12
0
/**
 *	Writes a 32-bit value to the stream.
 */
void IDataStream::Write32(UInt32 inData)
{
	if(swapBytes)
		inData = Swap32(inData);

	WriteBuf(&inData, sizeof(UInt32));
}
Exemplo n.º 13
0
static void FixLilEndian()
{
#if defined(ENDIAN_LITTLE)
	static bool Initialized = false;
	if( Initialized )
		return; 
	Initialized = true;

	for( int i = 0; i < AVPixelFormats[i].bpp; ++i )
	{
		AVPixelFormat_t &pf = AVPixelFormats[i];

		if( !pf.bByteSwapOnLittleEndian )
			continue;

		for( int mask = 0; mask < 4; ++mask)
		{
			int m = pf.masks[mask];
			switch( pf.bpp )
			{
				case 24: m = Swap24(m); break;
				case 32: m = Swap32(m); break;
				default:
					 FAIL_M(ssprintf("Unsupported BPP value: %i", pf.bpp));
			}
			pf.masks[mask] = m;
		}
	}
#endif
}
Exemplo n.º 14
0
static void LoadDebug(LoadState* S, Proto* f)
{
 int i,n;
 n=LoadInt(S);
 f->lineinfo=luaM_newvector(S->L,n,uint32_t);
 f->sizelineinfo=n;
 LoadVector(S,f->lineinfo,n,sizeof(uint32_t));
 if (S->flip)
  for (i=0; i<n; i++)
   f->lineinfo[i] = Swap32(f->lineinfo[i]);
 n=LoadInt(S);
 f->locvars=luaM_newvector(S->L,n,LocVar);
 f->sizelocvars=n;
 for (i=0; i<n; i++) f->locvars[i].varname=NULL;
 for (i=0; i<n; i++)
 {
  f->locvars[i].varname=LoadString(S);
  f->locvars[i].startpc=LoadInt(S);
  f->locvars[i].endpc=LoadInt(S);
 }
 n=LoadInt(S);
 f->upvalues=luaM_newvector(S->L,n,TString*);
 f->sizeupvalues=n;
 for (i=0; i<n; i++) f->upvalues[i]=NULL;
 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
}
Exemplo n.º 15
0
/*************************** ScriptMgefHandler ********************************/
ScriptMgefHandler::ScriptMgefHandler(EffectSetting& effect) 
: MgefHandler(effect) , scriptFormID(0), useSEFFAlwaysApplies(false), efitAVResType(TESFileFormats::kResType_None), 
    customParamResType(TESFileFormats::kResType_None), customParam(0)
{
    // By default, only the original SEFF effect uses the 'Always Applies' behavior
    if (effect.mgefCode == Swap32('SEFF')) useSEFFAlwaysApplies = true;
}
Exemplo n.º 16
0
void swap_HFSPlusCatalogKey(HFSPlusCatalogKey* record)
{
    // trace("record (%p)", record);

//    noswap: keyLength; swapped in swap_BTNode
    Swap32(record->parentID);
    swap_HFSUniStr255(&record->nodeName);
}
Exemplo n.º 17
0
u32 VSpace::Read32(u32 address)
{
	u32 *buf = (u32 *)buffer;
	u32  idx = (address - vaddr) >> 2;

	/* Return word */
	return Swap32(buf[idx]);
}
Exemplo n.º 18
0
void VSpace::Write32(u32 address, u32 value)
{
	u32 *buf = (u32 *)buffer;
	u32  idx = (address - vaddr) >> 2;

	/* Write word */
	buf[idx] = Swap32(value);
}
Exemplo n.º 19
0
void swap_HFSPlusAttrData(HFSPlusAttrData* record)
{
    // trace("record (%p)", record);
    // noswap: Swap32(record->recordType); (previously swapped)
    // noswap: Swap32(record->reserved[0]);
    // noswap: Swap32(record->reserved[1]);
    Swap32(record->attrSize);
}
Exemplo n.º 20
0
static int LoadInt(LoadState* S)
{
 uint32_t x;
 LoadVar(S,x);
 if (S->flip)
  x = Swap32(x);
 IF ((int32_t)x<0, "bad integer");
 return x;
}
Exemplo n.º 21
0
/**
 *	Reads and returns a 32-bit value from the stream
 */
UInt32 IDataStream::Read32(void)
{
	UInt32	out;

	ReadBuf(&out, sizeof(UInt32));

	if(swapBytes)
		out = Swap32(out);

	return out;
}
Exemplo n.º 22
0
static void LoadCode(LoadState* S, Proto* f)
{
 int n=LoadInt(S);
 int i=0;
 f->code=luaM_newvector(S->L,n,Instruction);
 f->sizecode=n;
 LoadVector(S,f->code,n,sizeof(Instruction));
 if (!S->flip)
  return;
 for (i=0; i<n; ++i)
  f->code[i] = Swap32(f->code[i]);
}
Exemplo n.º 23
0
Arquivo: twim.c Projeto: Tjalling7/asf
int twi_master_read(volatile avr32_twim_t *twi, const twi_package_t *package) {
    unsigned int addr = Swap32(package->addr);

    // Set Register address if needed
    if (package->addr_length) {
#if AVR32_TWIM_H_VERSION > 101
        while(twim_write(twi, (unsigned char*)&addr, package->addr_length, package->chip,0)!=TWI_SUCCESS);
#else
        twim_write(twi, (unsigned char *)&addr, package->addr_length, package->chip,0);
#endif
    }
    return twim_read(twi, package->buffer, package->length,package->chip, 0);
}
Exemplo n.º 24
0
void swap_HFSPlusCatalogFolder(HFSPlusCatalogFolder* record)
{
    // trace("record (%p)", record);

//    Swap16(record->recordType);
    Swap16(record->flags);
    Swap32(record->valence);
    Swap32(record->folderID);
    Swap32(record->createDate);
    Swap32(record->contentModDate);
    Swap32(record->attributeModDate);
    Swap32(record->accessDate);
    Swap32(record->backupDate);
    swap_HFSPlusBSDInfo(&record->bsdInfo);
    swap_FndrDirInfo(&record->userInfo);
    swap_FndrOpaqueInfo(&record->finderInfo);
    Swap32(record->textEncoding);
    Swap32(record->folderCount);
}
Exemplo n.º 25
0
/**
 *	Writes a 32-bit floating point value to the stream.
 */
void IDataStream::WriteFloat(float inData)
{
	if(swapBytes)
	{
		UInt32	temp = *((UInt32 *)&inData);

		temp = Swap32(temp);

		WriteBuf(&temp, sizeof(UInt32));
	}
	else
	{
		WriteBuf(&inData, sizeof(float));
	}
}
Exemplo n.º 26
0
void swap_HFSPlusCatalogFile(HFSPlusCatalogFile* record)
{
    // trace("record (%p)", record);

//    Swap16(record->recordType);
    Swap16(record->flags);
    Swap32(record->reserved1);
    Swap32(record->fileID);
    Swap32(record->createDate);
    Swap32(record->contentModDate);
    Swap32(record->attributeModDate);
    Swap32(record->accessDate);
    Swap32(record->backupDate);
    swap_HFSPlusBSDInfo(&record->bsdInfo);
    swap_FndrFileInfo(&record->userInfo);
    swap_FndrOpaqueInfo(&record->finderInfo);
    Swap32(record->textEncoding);
    Swap32(record->reserved2);

    swap_HFSPlusForkData(&record->dataFork);
    swap_HFSPlusForkData(&record->resourceFork);
}
Exemplo n.º 27
0
static void CoreOS_Unpack(u8 *buffer)
{
	struct coreHdr   *hdr   = (struct coreHdr   *)buffer;
	struct coreEntry *entry = (struct coreEntry *)hdr->entries;

	u32 i;
	s32 ret;

	/* Unpack entries */
	for (i = 0; i < Swap32(hdr->files); i++, entry++) {
		char *filename = entry->filename;
		u64   filesize = Swap64(entry->filesize);
		u64   offset   = Swap64(entry->offset);

		/* Entry info */
		printf("File: %-32s (offset: 0x%08llX, size: %.2f MB)\n", filename, offset, filesize / MEGABYTE);

		/* Write file */
		ret = File_Write(filename, buffer + offset, filesize);
		if (ret <= 0)
			fprintf(stderr, "ERROR: Could not unpack file \"%s\"! (%d)\n", filename, ret);
	}
}
Exemplo n.º 28
0
        /** Set the extra info (if any) */
        virtual void    finalizeWithExtraInfo(uint8 * outBuffer, const uint8 * extra, const uint32 extraLen)
        {
            uint8 hashArray[OutputSize + 64] = {0};
            uint32 tmpSize = InputSize + 4 + extraLen;
            uint8 hashTmpArray[InputSize + 4 + BaseHasher::DigestSize] = {0};
            uint8 * hashTmp = hashTmpArray;
            if ((extraLen && extra) || hasher.hashSize() > sizeof(hashTmpArray))
            {
                hashTmp = new uint8[max(tmpSize, hasher.hashSize())];
                if (!hashTmp)
                {
                    if (outBuffer) memset(outBuffer, 0, hashSize());
                    return; // Far more error to expect when stack or heap is exhausted
                }
                memset(hashTmp, 0, tmpSize);
            }
            uint32 d = (OutputSize + hasher.hashSize() - 1) / hasher.hashSize();
            for (uint32 i = 0; i < d; i++)
            {
                // Computing the inner hash
                memcpy(hashTmp, hashInput, InputSize);
                uint32 swappedI = Swap32(i);
                memcpy(&hashTmp[InputSize], &swappedI, sizeof(swappedI)); // Big endian
                if (extra && extraLen)
                    memcpy(&hashTmp[InputSize + 4], extra, extraLen);
                // Hash such string now
                hasher.Start();
                hasher.Hash(hashTmp, tmpSize);
                // Overwrite the data with the hash
                hasher.Finalize(hashTmp);

                memcpy(&hashArray[i * hasher.hashSize()], hashTmp, hasher.hashSize());
                memset(hashTmp, 0, tmpSize);
            }
            if ((extraLen && extra) || hasher.hashSize() > sizeof(hashTmpArray)) delete[] hashTmp;
            if (outBuffer) memcpy(outBuffer, hashArray, OutputSize);
        }
Exemplo n.º 29
0
void LoadKTX( const char *name, byte **data, int *width, int *height,
	      int *numLayers, int *numMips, int *bits, byte )
{
	KTX_header_t *hdr;
	byte         *ptr;
	size_t        bufLen, size;
	uint32_t      imageSize;

	*numLayers = 0;

	bufLen = ri.FS_ReadFile( name, ( void ** ) &hdr );

	if( !hdr )
	{
		return;
	}

	if( bufLen < sizeof( KTX_header_t ) ||
	    memcmp( hdr->identifier, KTX_identifier, sizeof( KTX_identifier) ) ) {
		ri.FS_FreeFile( hdr );
		return;
	}

	switch( hdr->endianness ) {
	case KTX_endianness:
		break;

	case KTX_endianness_reverse:
		hdr->glType                = Swap32( hdr->glType );
		hdr->glTypeSize            = Swap32( hdr->glTypeSize );
		hdr->glFormat              = Swap32( hdr->glFormat );
		hdr->glInternalFormat      = Swap32( hdr->glInternalFormat );
		hdr->glBaseInternalFormat  = Swap32( hdr->glBaseInternalFormat );
		hdr->pixelWidth            = Swap32( hdr->pixelWidth );
		hdr->pixelHeight           = Swap32( hdr->pixelHeight );
		hdr->pixelDepth            = Swap32( hdr->pixelDepth );
		hdr->numberOfArrayElements = Swap32( hdr->numberOfArrayElements );
		hdr->numberOfFaces         = Swap32( hdr->numberOfFaces );
		hdr->numberOfMipmapLevels  = Swap32( hdr->numberOfMipmapLevels );
		hdr->bytesOfKeyValueData   = Swap32( hdr->bytesOfKeyValueData );
		break;

	default:
		ri.FS_FreeFile( hdr );
		return;
	}

	// Support only for RGBA8 and BCn
	switch( hdr->glInternalFormat ) {
	case GL_RGBA8:
		break;
	case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
		*bits |= IF_BC1;
		break;
	case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
		*bits |= IF_BC3;
		break;
	case GL_COMPRESSED_RED_RGTC1:
		*bits |= IF_BC4;
		break;
	case GL_COMPRESSED_RG_RGTC2:
		*bits |= IF_BC5;
		break;
	default:
		ri.FS_FreeFile( hdr );
		return;
	}

	if( hdr->numberOfArrayElements != 0 ||
	    (hdr->numberOfFaces != 1 && hdr->numberOfFaces != 6) ||
	    hdr->pixelWidth == 0 ||
	    hdr->pixelHeight == 0 ||
	    hdr->pixelDepth != 0 ) {
		ri.FS_FreeFile( hdr );
		return;
	}

	*width = hdr->pixelWidth;
	*height = hdr->pixelHeight;
	*numMips = hdr->numberOfMipmapLevels;
	*numLayers = hdr->numberOfFaces == 6 ? 6 : 0;

	ptr = (byte *)(hdr + 1);
	ptr += hdr->bytesOfKeyValueData;
	size = 0;
	for(unsigned i = 0; i < hdr->numberOfMipmapLevels; i++ ) {
		imageSize = *((uint32_t *)ptr);
		if( hdr->endianness == KTX_endianness_reverse )
			imageSize = Swap32( imageSize );
		imageSize = PAD( imageSize, 4 );

		size += imageSize * hdr->numberOfFaces;
		ptr += 4 + imageSize;
	}

	ptr = (byte *)(hdr + 1);
	ptr += hdr->bytesOfKeyValueData;
	data[ 0 ] = (byte *)ri.Z_Malloc( size );

	imageSize = *((uint32_t *)ptr);
	if( hdr->endianness == KTX_endianness_reverse )
		imageSize = Swap32( imageSize );
	imageSize = PAD( imageSize, 4 );
	ptr += 4;
	Com_Memcpy( data[ 0 ], ptr, imageSize );
	ptr += imageSize;
	for(unsigned j = 1; j < hdr->numberOfFaces; j++ ) {
		data[ j ] = data[ j - 1 ] + imageSize;
		Com_Memcpy( data[ j ], ptr, imageSize );
		ptr += imageSize;
	}
	for(unsigned i = 1; i <= hdr->numberOfMipmapLevels; i++ ) {
		imageSize = *((uint32_t *)ptr);
		if( hdr->endianness == KTX_endianness_reverse )
			imageSize = Swap32( imageSize );
		imageSize = PAD( imageSize, 4 );
		ptr += 4;

		for(unsigned j = 0; j < hdr->numberOfFaces; j++ ) {
			int idx = i * hdr->numberOfFaces + j;
			data[ idx ] = data[ idx - 1 ] + imageSize;
			Com_Memcpy( data[ idx ], ptr, imageSize );
			ptr += imageSize;
		}
	}

	ri.FS_FreeFile( hdr );
}
Exemplo n.º 30
0
void DispelMgefHandler::SaveHandlerChunk()
{
    TESForm::PutFormRecordChunkData(Swap32('EHND'),&ehCode,kEHNDChunkSize);
}