os/kernelhwsrv/kernel/eka/common/mem.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/common/mem.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,246 @@
     1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\common\mem.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "common.h"
    1.22 +
    1.23 +//This is used in heap.cpp and it is defined here, as a requirement for patchdata
    1.24 +EXPORT_D extern const TInt KHeapMinCellSize = 0;
    1.25 +EXPORT_D extern const TInt KHeapShrinkHysRatio = RHeap::EShrinkRatioDflt;
    1.26 +//NOTE - if these values are changed then the WINS test case value must be updated
    1.27 +
    1.28 +#ifndef __MEM_MACHINE_CODED__
    1.29 +
    1.30 +extern "C" {
    1.31 +
    1.32 +//SL:
    1.33 +#ifndef __TOOLS__
    1.34 +// See header file e32cmn.h for the in-source documentation.
    1.35 +EXPORT_C TAny* memcpy(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
    1.36 +	{
    1.37 +	return memmove(aTrg, aSrc, aLength);
    1.38 +	}
    1.39 +
    1.40 +// See header file e32cmn.h for the in-source documentation.
    1.41 +EXPORT_C TAny* memmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
    1.42 +	{
    1.43 +	if (aLength==0)
    1.44 +		return((TUint8*)aTrg);
    1.45 +	TInt aLen32=0;
    1.46 +	TUint32* pT32=(TUint32*)aTrg;
    1.47 +	const TUint32* pS32=(TUint32 *)aSrc;
    1.48 +	if (((TInt)pT32&3)==0 && ((TInt)pS32&3)==0)
    1.49 +		aLen32=aLength>>2;
    1.50 +	TInt aLen8=aLength-(aLen32<<2);
    1.51 +	TUint32* pE32=pT32+aLen32;
    1.52 +	TUint8* pT;
    1.53 +    TUint8* pE;
    1.54 +    TUint8* pS;
    1.55 +	if (aTrg<aSrc)
    1.56 +		{
    1.57 +		pS32=(TUint32*)aSrc;
    1.58 +		while (pT32<pE32)
    1.59 +			*pT32++=(*pS32++);
    1.60 +		pT=(TUint8*)pT32;
    1.61 +		pS=(TUint8*)pS32;
    1.62 +		pE=(TUint8*)aTrg+aLength;
    1.63 +		while (pT<pE)
    1.64 +			*pT++=(*pS++);
    1.65 +		}
    1.66 +	else if (aTrg>aSrc)
    1.67 +		{
    1.68 +		pT=(TUint8*)(pT32+aLen32);
    1.69 +		pE=pT+aLen8;
    1.70 +		pS=(TUint8*)aSrc+aLength;
    1.71 +		while (pE>pT)
    1.72 +			*--pE=(*--pS);
    1.73 +		pS32=(TUint32*)pS;
    1.74 +		while (pE32>pT32)
    1.75 +			*--pE32=(*--pS32);
    1.76 +		}
    1.77 +	return aTrg;
    1.78 +	}
    1.79 +#endif
    1.80 +
    1.81 +
    1.82 +// See header file e32cmn.h for the in-source documentation.
    1.83 +EXPORT_C TAny* memclr(TAny* aTrg, unsigned int aLength)
    1.84 +	{
    1.85 +	return memset(aTrg, 0, aLength);
    1.86 +	}
    1.87 +
    1.88 +
    1.89 +//SL:
    1.90 +#ifndef __TOOLS__
    1.91 +
    1.92 +
    1.93 +// See header file e32cmn.h for the in-source documentation.
    1.94 +EXPORT_C TAny* memset(TAny* aTrg, TInt aValue, unsigned int aLength)
    1.95 +	{
    1.96 +	TInt aLen32=0;
    1.97 +	TUint32 *pM32=(TUint32 *)aTrg;
    1.98 +	if (((TInt)aTrg&3)==0)
    1.99 +		{
   1.100 +		aLen32=aLength>>2;
   1.101 +		TUint32 *pE32=pM32+aLen32;
   1.102 +		TUint c = aValue & 0xff;
   1.103 +		TUint32 fillChar=c+(c<<8)+(c<<16)+(c<<24);
   1.104 +		while (pM32<pE32)
   1.105 +			*pM32++=fillChar;
   1.106 +		}
   1.107 +	TInt aLen8=aLength-(aLen32<<2);
   1.108 +	TUint8 *pM=(TUint8 *)pM32;
   1.109 +	TUint8 *pE=pM+aLen8;
   1.110 +	while (pM<pE)
   1.111 +		*pM++=TUint8(aValue);
   1.112 +	return aTrg;
   1.113 +	}
   1.114 +
   1.115 +#endif
   1.116 +
   1.117 +} // extern "C"
   1.118 +
   1.119 +extern "C" {
   1.120 +
   1.121 +
   1.122 +
   1.123 +// See header file e32cmn.h for the in-source documentation.
   1.124 +EXPORT_C TAny* wordmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength)
   1.125 +	{
   1.126 +	__ASSERT_DEBUG((aLength&3)==0,Panic(EWordMoveLengthNotMultipleOf4));
   1.127 +	__ASSERT_DEBUG((((TUint)aSrc)&3)==0,Panic(EWordMoveSourceNotAligned));
   1.128 +	__ASSERT_DEBUG((((TUint)aTrg)&3)==0,Panic(EWordMoveTargetNotAligned));
   1.129 +	if (aLength==0)
   1.130 +		return((TUint8*)aTrg);
   1.131 +	TInt len=aLength>>2;
   1.132 +	TUint32* pT=(TUint32*)aTrg;
   1.133 +	const TUint32* pS=(const TUint32*)aSrc;
   1.134 +	const TUint32* pE=pS+len;
   1.135 +	if (pT<pS)
   1.136 +		{
   1.137 +		while (pS<pE)
   1.138 +			*pT++=(*pS++);
   1.139 +		}
   1.140 +	else if (pT>pS)
   1.141 +		{
   1.142 +        pT+=len;
   1.143 +		while (pE>pS)
   1.144 +			*--pT=(*--pE);
   1.145 +		}
   1.146 +	return aTrg;
   1.147 +	}
   1.148 +
   1.149 +
   1.150 +
   1.151 +
   1.152 +// See header file e32cmn.h for the in-source documentation.
   1.153 +EXPORT_C TInt memcompare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL)
   1.154 +	{
   1.155 +
   1.156 +	__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
   1.157 +	__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
   1.158 +	const TUint8 *pE=aLeft+Min(aLeftL,aRightL);
   1.159 +    while (aLeft<pE)
   1.160 +		{
   1.161 +		TInt d=(*aLeft++)-(*aRight++);
   1.162 +		if (d!=0)
   1.163 +		    return(d);
   1.164 +		}
   1.165 +    return(aLeftL-aRightL);
   1.166 +	}
   1.167 +
   1.168 +} // extern "C"
   1.169 +
   1.170 +
   1.171 +
   1.172 +
   1.173 +#if defined(__GCC32__) && !defined(__KERNEL_MODE__)
   1.174 +/**
   1.175 +Compares a block of data at one specified location with a block of data at 
   1.176 +another specified location.
   1.177 +
   1.178 +The comparison proceeds on a byte for byte basis, the result of the comparison 
   1.179 +is based on the difference of the first bytes to disagree.
   1.180 +
   1.181 +The data at the two locations are equal if they have the same length and content. 
   1.182 +Where the lengths are different and the shorter section of data is the same 
   1.183 +as the first part of the longer section of data, the shorter is considered 
   1.184 +to be less than the longer.
   1.185 +
   1.186 +@param aLeft   A pointer to the first (or left) block of 8 bit data
   1.187 +               to be compared.
   1.188 +@param aLeftL  The length of the first (or left) block of data to be compared,  
   1.189 +               i.e. the number of bytes.
   1.190 +@param aRight  A pointer to the second (or right) block of 8 bit data to be 
   1.191 +               compared.
   1.192 +@param aRightL The length of the second (or right) block of data to be compared 
   1.193 +               i.e. the number of bytes.
   1.194 +               
   1.195 +@return Positive, if the first (or left) block of data is greater than the 
   1.196 +        second (or right) block of data.
   1.197 +        Negative, if the first (or left) block of data is less than the
   1.198 +        second (or right) block of data.
   1.199 +        Zero, if both the first (or left) and second (or right) blocks of data
   1.200 +        have the same length and the same content.
   1.201 +*/
   1.202 +EXPORT_C TInt Mem::Compare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL)
   1.203 +	{
   1.204 +	memcompare(aLeft, aLeftL, aRight, aRightL);
   1.205 +	}
   1.206 +#endif
   1.207 +
   1.208 +#else // __MEM_MACHINE_CODED__
   1.209 +
   1.210 +#if defined(_DEBUG) && defined(__CPU_ARM)
   1.211 +
   1.212 +GLDEF_C void PanicEWordMoveLengthNotMultipleOf4()
   1.213 +	{
   1.214 +	Panic(EWordMoveLengthNotMultipleOf4);
   1.215 +	}
   1.216 +
   1.217 +GLDEF_C void PanicEWordMoveSourceNotAligned()
   1.218 +	{
   1.219 +	Panic(EWordMoveSourceNotAligned);
   1.220 +	}
   1.221 +
   1.222 +GLDEF_C void PanicEWordMoveTargetNotAligned()
   1.223 +	{
   1.224 +	Panic(EWordMoveTargetNotAligned);
   1.225 +	}
   1.226 +
   1.227 +#endif
   1.228 +
   1.229 +#endif // __MEM_MACHINE_CODED__
   1.230 +
   1.231 +#ifndef __KERNEL_MODE__
   1.232 +//
   1.233 +// Dummy class for Binary Compatibility purposes
   1.234 +//
   1.235 +class Mem1
   1.236 +	{
   1.237 +public:
   1.238 +	IMPORT_C static TUint8* Copy(TAny* aTrg,const TAny* aSrc,TInt aLength);
   1.239 +	IMPORT_C static TUint8* Move(TAny* aTrg,const TAny* aSrc,TInt aLength);
   1.240 +	IMPORT_C static void Fill(TAny* aTrg,TInt aLength,TChar aChar);
   1.241 +	};
   1.242 +EXPORT_C void Mem1::Fill(TAny* aTrg,TInt aLength,TChar aChar)
   1.243 +	{ Mem::Fill(aTrg,aLength,aChar); }
   1.244 +EXPORT_C TUint8* Mem1::Copy(TAny* aTrg, const TAny* aSrc, TInt aLength)
   1.245 +	{ return Mem::Copy(aTrg, aSrc, aLength); }
   1.246 +EXPORT_C TUint8* Mem1::Move(TAny* aTrg, const TAny* aSrc, TInt aLength)
   1.247 +	{ return Mem::Move(aTrg, aSrc, aLength); }
   1.248 +		
   1.249 +#endif // __KERNEL_MODE__