First public contribution.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\epoc\x86\uc_utl.cia
22 #include <e32hashtab.h>
25 // Dummy so we can use same DEF file as WINS
26 EXPORT_C void BootEpoc(TBool)
31 EXPORT_C __NAKED__ void RFastLock::Wait()
34 asm("lock sub dword ptr [ecx+4], 1");
35 asm("jnc fast_lock_wait_sem");
37 asm("fast_lock_wait_sem:");
38 asm("mov eax, %0": : "i"(EExecSemaphoreWait));
39 asm("mov ecx, [ecx]");
45 EXPORT_C __NAKED__ void RFastLock::Signal()
48 asm("lock add dword ptr [ecx+4], 1");
49 asm("jne fast_lock_signal_sem");
51 asm("fast_lock_signal_sem:");
52 asm("mov eax, %0": : "i"(EExecSemaphoreSignal1));
53 asm("mov ecx, [ecx]");
58 #ifdef __MEM_MACHINE_CODED__
59 __NAKED__ EXPORT_C void Mem::Swap( TAny* /*aPtr1*/, TAny* /*aPtr2*/, TInt /*aLength*/ )
61 Swaps a number of bytes of data between two specified locations.
63 The source and target areas can overlap.
65 @param aPtr1 A pointer to the first location taking part in the swap.
66 @param aPtr2 A pointer to second location taking part in the swap.
67 @param aLength The number of bytes to be swapped between the two locations.
68 This value must not be negative.
70 @panic USER 94 In debug builds only, if aLength is negative.
74 // Swap the contents of *aPtr1 with *aPtr2.
75 // NB We assume ES=DS on entry.
80 asm("mov edi,[esp+12]");// aPtr1 address into edi
81 asm("mov esi,[esp+16]");// aPtr2 address into esi
82 asm("mov ecx,[esp+20]");// byte count into ecx
85 asm("test ecx,ecx"); //
86 asm("jz short memswap0");// if length=0, nothing to do
87 asm("cld"); // go forwards through array
88 asm("cmp ecx,7"); // if length<7 don't bother with alignment check
89 asm("jc short memswap1");//
90 asm("mov edx,ecx"); // length into edx
91 // number of bytes to align aPtr1 = 4-(edi mod 4)
93 asm("sub ecx,edi"); //
94 asm("and ecx,3"); // into ecx
95 asm("jz short memswap2");// if aligned, proceed with dword swap
96 asm("sub edx,ecx"); // subtract number of bytes from length
98 asm("mov al,[edi]"); // al = *aPtr1
99 asm("mov ah,[esi]"); // ah = *aPtr2
100 asm("mov [esi],al"); // *aPtr2=al
101 asm("mov [edi],ah"); // *aPtr1=ah
102 asm("inc esi"); // aPtr2++
103 asm("inc edi"); // aPtr1++
105 asm("jnz short memswap3");// loop ecx times - edi is now dword aligned
107 asm("push ebx"); // preserve ebx
108 asm("mov ecx,edx"); // length back into ecx
109 asm("mov ah,cl"); // save lower two bits of dword count in ah bits 3,2
110 asm("add ecx,12"); // divide dword count by 4, rounding to next higher integer
111 asm("shr ecx,4"); // this gives loop count for unfolded loop
112 asm("shl ah,4"); // lower two bits of dword count into ah bits 7,6
113 asm("sahf"); // and into SF,ZF
114 asm("jns short memswap8");// branch if lower two bits of dword count = 0 or 1
115 asm("jz short memswap5");// if lower two bits = 3, miss out first unfolding of loop
116 asm("jnz short memswap6"); // if lower two bits = 2, miss out first two unfoldings
118 asm("jz short memswap7");// if lower two bits = 1, miss out first three unfoldings
120 asm("mov eax,[edi]"); // eax = *aPtr1
121 asm("mov ebx,[esi]"); // ebx = *aPtr2
122 asm("mov [esi],eax"); // *aPtr2=eax
123 asm("mov [edi],ebx"); // *aPtr1=ebx
124 asm("add edi,4"); // aPtr1++
125 asm("add esi,4"); // aPtr2++
127 asm("mov eax,[edi]"); // eax = *aPtr1
128 asm("mov ebx,[esi]"); // ebx = *aPtr2
129 asm("mov [esi],eax"); // *aPtr2=eax
130 asm("mov [edi],ebx"); // *aPtr1=ebx
131 asm("add edi,4"); // aPtr1++
132 asm("add esi,4"); // aPtr2++
134 asm("mov eax,[edi]"); // eax = *aPtr1
135 asm("mov ebx,[esi]"); // ebx = *aPtr2
136 asm("mov [esi],eax"); // *aPtr2=eax
137 asm("mov [edi],ebx"); // *aPtr1=ebx
138 asm("add edi,4"); // aPtr1++
139 asm("add esi,4"); // aPtr2++
141 asm("mov eax,[edi]"); // eax = *aPtr1
142 asm("mov ebx,[esi]"); // ebx = *aPtr2
143 asm("mov [esi],eax"); // *aPtr2=eax
144 asm("mov [edi],ebx"); // *aPtr1=ebx
145 asm("add edi,4"); // aPtr1++
146 asm("add esi,4"); // aPtr2++
148 asm("jnz short memswap4"); // loop ecx times to do main part of swap
149 asm("mov ecx,edx"); // length back into ecx
150 asm("pop ebx"); // restore ebx
151 asm("and ecx,3"); // number of remaining bytes to move
152 asm("jz short memswap0");// if zero, we are finished
153 asm("memswap1:"); // *** come here for small swap
154 asm("mov al,[edi]"); // al = *aPtr1
155 asm("mov ah,[esi]"); // ah = *aPtr2
156 asm("mov [esi],al"); // *aPtr2=al
157 asm("mov [edi],ah"); // *aPtr1=ah
158 asm("inc esi"); // aPtr2++
159 asm("inc edi"); // aPtr1++
161 asm("jnz short memswap1"); // loop ecx times - edi is now dword aligned
171 // Hash an 8 bit string at aPtr, length aLen bytes.
172 __NAKED__ TUint32 DefaultStringHash(const TUint8* /*aPtr*/, TInt /*aLen*/)
175 asm("mov esi, [esp+8]");
176 asm("mov ecx, [esp+12]");
181 asm("xor eax, [esi]");
183 asm("mov edx, 0x9E3779B9");
193 asm("mov dl, [esi+2]");
198 asm("mov dh, [esi+1]");
200 asm("mov dl, [esi]");
202 asm("mov edx, 0x9E3779B9");
209 // Hash a 16 bit string at aPtr, length aLen bytes.
210 __NAKED__ TUint32 DefaultWStringHash(const TUint16* /*aPtr*/, TInt /*aLen*/)
213 asm("mov esi, [esp+8]");
214 asm("mov ecx, [esp+12]");
219 asm("mov edx, [esi+4]");
220 asm("xor eax, [esi]");
224 asm("mov edx, 0x9E3779B9");
230 asm("jz done_defwstrhash");
234 asm("mov dx, [esi+4]");
240 asm("jb onemore_defwstrhash");
241 asm("mov dx, [esi+2]");
243 asm("onemore_defwstrhash:");
244 asm("mov dx, [esi]");
246 asm("mov edx, 0x9E3779B9");
248 asm("done_defwstrhash:");
258 Calculate a 32 bit hash from a 32 bit integer.
260 @param aInt The integer to be hashed.
261 @return The calculated 32 bit hash value.
263 EXPORT_C __NAKED__ TUint32 DefaultHash::Integer(const TInt& /*aInt*/)
265 asm("mov edx, [esp+4]");
266 asm("mov eax, 0x9E3779B9");
267 asm("mul dword ptr [edx]");