|
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32\common\mem.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "common.h" |
|
19 |
|
20 //This is used in heap.cpp and it is defined here, as a requirement for patchdata |
|
21 EXPORT_D extern const TInt KHeapMinCellSize = 0; |
|
22 EXPORT_D extern const TInt KHeapShrinkHysRatio = RHeap::EShrinkRatioDflt; |
|
23 //NOTE - if these values are changed then the WINS test case value must be updated |
|
24 |
|
25 #ifndef __MEM_MACHINE_CODED__ |
|
26 |
|
27 extern "C" { |
|
28 |
|
29 // See header file e32cmn.h for the in-source documentation. |
|
30 EXPORT_C TAny* memcpy(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
31 { |
|
32 return memmove(aTrg, aSrc, aLength); |
|
33 } |
|
34 |
|
35 |
|
36 |
|
37 // See header file e32cmn.h for the in-source documentation. |
|
38 EXPORT_C TAny* memmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
39 { |
|
40 if (aLength==0) |
|
41 return((TUint8*)aTrg); |
|
42 TInt aLen32=0; |
|
43 TUint32* pT32=(TUint32*)aTrg; |
|
44 const TUint32* pS32=(TUint32 *)aSrc; |
|
45 if (((TInt)pT32&3)==0 && ((TInt)pS32&3)==0) |
|
46 aLen32=aLength>>2; |
|
47 TInt aLen8=aLength-(aLen32<<2); |
|
48 TUint32* pE32=pT32+aLen32; |
|
49 TUint8* pT; |
|
50 TUint8* pE; |
|
51 TUint8* pS; |
|
52 if (aTrg<aSrc) |
|
53 { |
|
54 pS32=(TUint32*)aSrc; |
|
55 while (pT32<pE32) |
|
56 *pT32++=(*pS32++); |
|
57 pT=(TUint8*)pT32; |
|
58 pS=(TUint8*)pS32; |
|
59 pE=(TUint8*)aTrg+aLength; |
|
60 while (pT<pE) |
|
61 *pT++=(*pS++); |
|
62 } |
|
63 else if (aTrg>aSrc) |
|
64 { |
|
65 pT=(TUint8*)(pT32+aLen32); |
|
66 pE=pT+aLen8; |
|
67 pS=(TUint8*)aSrc+aLength; |
|
68 while (pE>pT) |
|
69 *--pE=(*--pS); |
|
70 pS32=(TUint32*)pS; |
|
71 while (pE32>pT32) |
|
72 *--pE32=(*--pS32); |
|
73 } |
|
74 return aTrg; |
|
75 } |
|
76 |
|
77 |
|
78 |
|
79 // See header file e32cmn.h for the in-source documentation. |
|
80 EXPORT_C TAny* memclr(TAny* aTrg, unsigned int aLength) |
|
81 { |
|
82 return memset(aTrg, 0, aLength); |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 // See header file e32cmn.h for the in-source documentation. |
|
88 EXPORT_C TAny* memset(TAny* aTrg, TInt aValue, unsigned int aLength) |
|
89 { |
|
90 TInt aLen32=0; |
|
91 TUint32 *pM32=(TUint32 *)aTrg; |
|
92 if (((TInt)aTrg&3)==0) |
|
93 { |
|
94 aLen32=aLength>>2; |
|
95 TUint32 *pE32=pM32+aLen32; |
|
96 TUint c = aValue & 0xff; |
|
97 TUint32 fillChar=c+(c<<8)+(c<<16)+(c<<24); |
|
98 while (pM32<pE32) |
|
99 *pM32++=fillChar; |
|
100 } |
|
101 TInt aLen8=aLength-(aLen32<<2); |
|
102 TUint8 *pM=(TUint8 *)pM32; |
|
103 TUint8 *pE=pM+aLen8; |
|
104 while (pM<pE) |
|
105 *pM++=TUint8(aValue); |
|
106 return aTrg; |
|
107 } |
|
108 |
|
109 } // extern "C" |
|
110 |
|
111 extern "C" { |
|
112 |
|
113 |
|
114 |
|
115 // See header file e32cmn.h for the in-source documentation. |
|
116 EXPORT_C TAny* wordmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
117 { |
|
118 __ASSERT_DEBUG((aLength&3)==0,Panic(EWordMoveLengthNotMultipleOf4)); |
|
119 __ASSERT_DEBUG((((TUint)aSrc)&3)==0,Panic(EWordMoveSourceNotAligned)); |
|
120 __ASSERT_DEBUG((((TUint)aTrg)&3)==0,Panic(EWordMoveTargetNotAligned)); |
|
121 if (aLength==0) |
|
122 return((TUint8*)aTrg); |
|
123 TInt len=aLength>>2; |
|
124 TUint32* pT=(TUint32*)aTrg; |
|
125 const TUint32* pS=(const TUint32*)aSrc; |
|
126 const TUint32* pE=pS+len; |
|
127 if (pT<pS) |
|
128 { |
|
129 while (pS<pE) |
|
130 *pT++=(*pS++); |
|
131 } |
|
132 else if (pT>pS) |
|
133 { |
|
134 pT+=len; |
|
135 while (pE>pS) |
|
136 *--pT=(*--pE); |
|
137 } |
|
138 return aTrg; |
|
139 } |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 // See header file e32cmn.h for the in-source documentation. |
|
145 EXPORT_C TInt memcompare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL) |
|
146 { |
|
147 |
|
148 __ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative)); |
|
149 __ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative)); |
|
150 const TUint8 *pE=aLeft+Min(aLeftL,aRightL); |
|
151 while (aLeft<pE) |
|
152 { |
|
153 TInt d=(*aLeft++)-(*aRight++); |
|
154 if (d!=0) |
|
155 return(d); |
|
156 } |
|
157 return(aLeftL-aRightL); |
|
158 } |
|
159 |
|
160 } // extern "C" |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 #if defined(__GCC32__) && !defined(__KERNEL_MODE__) |
|
166 /** |
|
167 Compares a block of data at one specified location with a block of data at |
|
168 another specified location. |
|
169 |
|
170 The comparison proceeds on a byte for byte basis, the result of the comparison |
|
171 is based on the difference of the first bytes to disagree. |
|
172 |
|
173 The data at the two locations are equal if they have the same length and content. |
|
174 Where the lengths are different and the shorter section of data is the same |
|
175 as the first part of the longer section of data, the shorter is considered |
|
176 to be less than the longer. |
|
177 |
|
178 @param aLeft A pointer to the first (or left) block of 8 bit data |
|
179 to be compared. |
|
180 @param aLeftL The length of the first (or left) block of data to be compared, |
|
181 i.e. the number of bytes. |
|
182 @param aRight A pointer to the second (or right) block of 8 bit data to be |
|
183 compared. |
|
184 @param aRightL The length of the second (or right) block of data to be compared |
|
185 i.e. the number of bytes. |
|
186 |
|
187 @return Positive, if the first (or left) block of data is greater than the |
|
188 second (or right) block of data. |
|
189 Negative, if the first (or left) block of data is less than the |
|
190 second (or right) block of data. |
|
191 Zero, if both the first (or left) and second (or right) blocks of data |
|
192 have the same length and the same content. |
|
193 */ |
|
194 EXPORT_C TInt Mem::Compare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL) |
|
195 { |
|
196 memcompare(aLeft, aLeftL, aRight, aRightL); |
|
197 } |
|
198 #endif |
|
199 |
|
200 #else // __MEM_MACHINE_CODED__ |
|
201 |
|
202 #if defined(_DEBUG) && defined(__CPU_ARM) |
|
203 |
|
204 GLDEF_C void PanicEWordMoveLengthNotMultipleOf4() |
|
205 { |
|
206 Panic(EWordMoveLengthNotMultipleOf4); |
|
207 } |
|
208 |
|
209 GLDEF_C void PanicEWordMoveSourceNotAligned() |
|
210 { |
|
211 Panic(EWordMoveSourceNotAligned); |
|
212 } |
|
213 |
|
214 GLDEF_C void PanicEWordMoveTargetNotAligned() |
|
215 { |
|
216 Panic(EWordMoveTargetNotAligned); |
|
217 } |
|
218 |
|
219 #endif |
|
220 |
|
221 #endif // __MEM_MACHINE_CODED__ |
|
222 |
|
223 #ifndef __KERNEL_MODE__ |
|
224 // |
|
225 // Dummy class for Binary Compatibility purposes |
|
226 // |
|
227 class Mem1 |
|
228 { |
|
229 public: |
|
230 IMPORT_C static TUint8* Copy(TAny* aTrg,const TAny* aSrc,TInt aLength); |
|
231 IMPORT_C static TUint8* Move(TAny* aTrg,const TAny* aSrc,TInt aLength); |
|
232 IMPORT_C static void Fill(TAny* aTrg,TInt aLength,TChar aChar); |
|
233 }; |
|
234 EXPORT_C void Mem1::Fill(TAny* aTrg,TInt aLength,TChar aChar) |
|
235 { Mem::Fill(aTrg,aLength,aChar); } |
|
236 EXPORT_C TUint8* Mem1::Copy(TAny* aTrg, const TAny* aSrc, TInt aLength) |
|
237 { return Mem::Copy(aTrg, aSrc, aLength); } |
|
238 EXPORT_C TUint8* Mem1::Move(TAny* aTrg, const TAny* aSrc, TInt aLength) |
|
239 { return Mem::Move(aTrg, aSrc, aLength); } |
|
240 |
|
241 #endif // __KERNEL_MODE__ |