| author | Mike Kinghan <mikek@symbian.org> |
| Mon, 26 Jul 2010 11:09:46 +0100 | |
| branch | GCC_SURGE |
| changeset 229 | 07a685bbdd3d |
| parent 201 | 43365a9b78a3 |
| child 257 | 3e88ff8f41d5 |
| permissions | -rw-r--r-- |
| 0 | 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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\euser\epoc\x86\uc_utl.cia |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <u32exec.h> |
|
19 |
#include <e32base.h> |
|
20 |
#include <e32rom.h> |
|
21 |
#include <e32svr.h> |
|
22 |
#include <e32hashtab.h> |
|
23 |
||
24 |
||
25 |
// Dummy so we can use same DEF file as WINS |
|
26 |
EXPORT_C void BootEpoc(TBool) |
|
27 |
{
|
|
28 |
} |
|
29 |
||
30 |
||
31 |
EXPORT_C __NAKED__ void RFastLock::Wait() |
|
32 |
{
|
|
33 |
THISCALL_PROLOG0() |
|
34 |
asm("lock sub dword ptr [ecx+4], 1");
|
|
35 |
asm("jnc fast_lock_wait_sem");
|
|
36 |
THISCALL_EPILOG0() |
|
37 |
asm("fast_lock_wait_sem:");
|
|
38 |
asm("mov eax, %0": : "i"(EExecSemaphoreWait));
|
|
39 |
asm("mov ecx, [ecx]");
|
|
40 |
asm("xor edx, edx");
|
|
41 |
asm("int 0x21");
|
|
42 |
THISCALL_EPILOG0() |
|
43 |
} |
|
44 |
||
|
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
EXPORT_C __NAKED__ TInt RFastLock::Poll() |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
{
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
THISCALL_PROLOG0() |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
asm("xor eax, eax ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
asm("xor edx, edx ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
asm("dec edx ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
/* if ([ecx+4]==0) { [ecx+4]=-1; ZF=1;} else {eax=[ecx+4]; ZF=0;} */
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
asm("lock cmpxchg [ecx+4], edx ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
asm("jz short fastlock_poll_done ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
asm("mov eax, %0": : "i"(KErrTimedOut));
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
asm("fastlock_poll_done: ");
|
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
THISCALL_EPILOG0() |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
} |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
|
| 0 | 61 |
EXPORT_C __NAKED__ void RFastLock::Signal() |
62 |
{
|
|
63 |
THISCALL_PROLOG0() |
|
64 |
asm("lock add dword ptr [ecx+4], 1");
|
|
65 |
asm("jne fast_lock_signal_sem");
|
|
66 |
THISCALL_EPILOG0() |
|
67 |
asm("fast_lock_signal_sem:");
|
|
68 |
asm("mov eax, %0": : "i"(EExecSemaphoreSignal1));
|
|
69 |
asm("mov ecx, [ecx]");
|
|
70 |
asm("int 0x21");
|
|
71 |
THISCALL_EPILOG0() |
|
72 |
} |
|
73 |
||
74 |
#ifdef __MEM_MACHINE_CODED__ |
|
75 |
__NAKED__ EXPORT_C void Mem::Swap( TAny* /*aPtr1*/, TAny* /*aPtr2*/, TInt /*aLength*/ ) |
|
76 |
/** |
|
77 |
Swaps a number of bytes of data between two specified locations. |
|
78 |
||
79 |
The source and target areas can overlap. |
|
80 |
||
81 |
@param aPtr1 A pointer to the first location taking part in the swap. |
|
82 |
@param aPtr2 A pointer to second location taking part in the swap. |
|
83 |
@param aLength The number of bytes to be swapped between the two locations. |
|
84 |
This value must not be negative. |
|
85 |
||
86 |
@panic USER 94 In debug builds only, if aLength is negative. |
|
87 |
*/ |
|
88 |
||
89 |
// |
|
90 |
// Swap the contents of *aPtr1 with *aPtr2. |
|
91 |
// NB We assume ES=DS on entry. |
|
92 |
// |
|
93 |
{
|
|
94 |
asm("push esi");
|
|
95 |
asm("push edi");
|
|
96 |
asm("mov edi,[esp+12]");// aPtr1 address into edi
|
|
97 |
asm("mov esi,[esp+16]");// aPtr2 address into esi
|
|
98 |
asm("mov ecx,[esp+20]");// byte count into ecx
|
|
99 |
asm("pushfd");
|
|
100 |
||
101 |
asm("test ecx,ecx"); //
|
|
102 |
asm("jz short memswap0");// if length=0, nothing to do
|
|
103 |
asm("cld"); // go forwards through array
|
|
104 |
asm("cmp ecx,7"); // if length<7 don't bother with alignment check
|
|
105 |
asm("jc short memswap1");//
|
|
106 |
asm("mov edx,ecx"); // length into edx
|
|
107 |
// number of bytes to align aPtr1 = 4-(edi mod 4) |
|
108 |
asm("mov ecx,4");
|
|
109 |
asm("sub ecx,edi"); //
|
|
110 |
asm("and ecx,3"); // into ecx
|
|
111 |
asm("jz short memswap2");// if aligned, proceed with dword swap
|
|
112 |
asm("sub edx,ecx"); // subtract number of bytes from length
|
|
113 |
asm("memswap3:");
|
|
114 |
asm("mov al,[edi]"); // al = *aPtr1
|
|
115 |
asm("mov ah,[esi]"); // ah = *aPtr2
|
|
116 |
asm("mov [esi],al"); // *aPtr2=al
|
|
117 |
asm("mov [edi],ah"); // *aPtr1=ah
|
|
118 |
asm("inc esi"); // aPtr2++
|
|
119 |
asm("inc edi"); // aPtr1++
|
|
120 |
asm("dec ecx"); //
|
|
121 |
asm("jnz short memswap3");// loop ecx times - edi is now dword aligned
|
|
122 |
asm("memswap2:");
|
|
123 |
asm("push ebx"); // preserve ebx
|
|
124 |
asm("mov ecx,edx"); // length back into ecx
|
|
125 |
asm("mov ah,cl"); // save lower two bits of dword count in ah bits 3,2
|
|
126 |
asm("add ecx,12"); // divide dword count by 4, rounding to next higher integer
|
|
127 |
asm("shr ecx,4"); // this gives loop count for unfolded loop
|
|
128 |
asm("shl ah,4"); // lower two bits of dword count into ah bits 7,6
|
|
129 |
asm("sahf"); // and into SF,ZF
|
|
130 |
asm("jns short memswap8");// branch if lower two bits of dword count = 0 or 1
|
|
131 |
asm("jz short memswap5");// if lower two bits = 3, miss out first unfolding of loop
|
|
132 |
asm("jnz short memswap6"); // if lower two bits = 2, miss out first two unfoldings
|
|
133 |
asm("memswap8:");
|
|
134 |
asm("jz short memswap7");// if lower two bits = 1, miss out first three unfoldings
|
|
135 |
asm("memswap4:");
|
|
136 |
asm("mov eax,[edi]"); // eax = *aPtr1
|
|
137 |
asm("mov ebx,[esi]"); // ebx = *aPtr2
|
|
138 |
asm("mov [esi],eax"); // *aPtr2=eax
|
|
139 |
asm("mov [edi],ebx"); // *aPtr1=ebx
|
|
140 |
asm("add edi,4"); // aPtr1++
|
|
141 |
asm("add esi,4"); // aPtr2++
|
|
142 |
asm("memswap5:");
|
|
143 |
asm("mov eax,[edi]"); // eax = *aPtr1
|
|
144 |
asm("mov ebx,[esi]"); // ebx = *aPtr2
|
|
145 |
asm("mov [esi],eax"); // *aPtr2=eax
|
|
146 |
asm("mov [edi],ebx"); // *aPtr1=ebx
|
|
147 |
asm("add edi,4"); // aPtr1++
|
|
148 |
asm("add esi,4"); // aPtr2++
|
|
149 |
asm("memswap6:");
|
|
150 |
asm("mov eax,[edi]"); // eax = *aPtr1
|
|
151 |
asm("mov ebx,[esi]"); // ebx = *aPtr2
|
|
152 |
asm("mov [esi],eax"); // *aPtr2=eax
|
|
153 |
asm("mov [edi],ebx"); // *aPtr1=ebx
|
|
154 |
asm("add edi,4"); // aPtr1++
|
|
155 |
asm("add esi,4"); // aPtr2++
|
|
156 |
asm("memswap7:");
|
|
157 |
asm("mov eax,[edi]"); // eax = *aPtr1
|
|
158 |
asm("mov ebx,[esi]"); // ebx = *aPtr2
|
|
159 |
asm("mov [esi],eax"); // *aPtr2=eax
|
|
160 |
asm("mov [edi],ebx"); // *aPtr1=ebx
|
|
161 |
asm("add edi,4"); // aPtr1++
|
|
162 |
asm("add esi,4"); // aPtr2++
|
|
163 |
asm("dec ecx");
|
|
164 |
asm("jnz short memswap4"); // loop ecx times to do main part of swap
|
|
165 |
asm("mov ecx,edx"); // length back into ecx
|
|
166 |
asm("pop ebx"); // restore ebx
|
|
167 |
asm("and ecx,3"); // number of remaining bytes to move
|
|
168 |
asm("jz short memswap0");// if zero, we are finished
|
|
169 |
asm("memswap1:"); // *** come here for small swap
|
|
170 |
asm("mov al,[edi]"); // al = *aPtr1
|
|
171 |
asm("mov ah,[esi]"); // ah = *aPtr2
|
|
172 |
asm("mov [esi],al"); // *aPtr2=al
|
|
173 |
asm("mov [edi],ah"); // *aPtr1=ah
|
|
174 |
asm("inc esi"); // aPtr2++
|
|
175 |
asm("inc edi"); // aPtr1++
|
|
176 |
asm("dec ecx"); //
|
|
177 |
asm("jnz short memswap1"); // loop ecx times - edi is now dword aligned
|
|
178 |
||
179 |
asm("memswap0:");
|
|
180 |
asm("popfd");
|
|
181 |
asm("pop edi");
|
|
182 |
asm("pop esi");
|
|
183 |
asm("ret");
|
|
184 |
} |
|
185 |
#endif |
|
186 |
||
187 |
// Hash an 8 bit string at aPtr, length aLen bytes. |
|
188 |
__NAKED__ TUint32 DefaultStringHash(const TUint8* /*aPtr*/, TInt /*aLen*/) |
|
189 |
{
|
|
190 |
asm("push esi");
|
|
191 |
asm("mov esi, [esp+8]");
|
|
192 |
asm("mov ecx, [esp+12]");
|
|
193 |
asm("xor eax, eax");
|
|
194 |
asm("sub ecx, 4");
|
|
195 |
asm("jb lt4");
|
|
196 |
asm("ge4:");
|
|
197 |
asm("xor eax, [esi]");
|
|
198 |
asm("add esi, 4");
|
|
199 |
asm("mov edx, 0x9E3779B9");
|
|
200 |
asm("mul edx");
|
|
201 |
asm("sub ecx, 4");
|
|
202 |
asm("jae ge4");
|
|
203 |
asm("lt4:");
|
|
204 |
asm("add ecx, 4");
|
|
205 |
asm("jz done");
|
|
206 |
asm("xor edx, edx");
|
|
207 |
asm("cmp ecx, 2");
|
|
208 |
asm("jbe le2");
|
|
209 |
asm("mov dl, [esi+2]");
|
|
210 |
asm("shl edx, 16");
|
|
211 |
asm("le2:");
|
|
212 |
asm("cmp ecx, 2");
|
|
213 |
asm("jb onemore");
|
|
214 |
asm("mov dh, [esi+1]");
|
|
215 |
asm("onemore:");
|
|
216 |
asm("mov dl, [esi]");
|
|
217 |
asm("xor eax, edx");
|
|
218 |
asm("mov edx, 0x9E3779B9");
|
|
219 |
asm("mul edx");
|
|
220 |
asm("done:");
|
|
221 |
asm("pop esi");
|
|
222 |
asm("ret");
|
|
223 |
} |
|
224 |
||
225 |
// Hash a 16 bit string at aPtr, length aLen bytes. |
|
226 |
__NAKED__ TUint32 DefaultWStringHash(const TUint16* /*aPtr*/, TInt /*aLen*/) |
|
227 |
{
|
|
228 |
asm("push esi");
|
|
229 |
asm("mov esi, [esp+8]");
|
|
230 |
asm("mov ecx, [esp+12]");
|
|
231 |
asm("xor eax, eax");
|
|
232 |
asm("sub ecx, 8");
|
|
233 |
asm("jb lt8");
|
|
234 |
asm("ge8:");
|
|
235 |
asm("mov edx, [esi+4]");
|
|
236 |
asm("xor eax, [esi]");
|
|
237 |
asm("add esi, 8");
|
|
238 |
asm("rol edx, 8");
|
|
239 |
asm("xor eax, edx");
|
|
240 |
asm("mov edx, 0x9E3779B9");
|
|
241 |
asm("mul edx");
|
|
242 |
asm("sub ecx, 8");
|
|
243 |
asm("jae ge8");
|
|
244 |
asm("lt8:");
|
|
245 |
asm("add ecx, 8");
|
|
246 |
asm("jz done_defwstrhash");
|
|
247 |
asm("xor edx, edx");
|
|
248 |
asm("cmp ecx, 4");
|
|
249 |
asm("jbe le4");
|
|
250 |
asm("mov dx, [esi+4]");
|
|
251 |
asm("rol edx, 8");
|
|
252 |
asm("xor eax, edx");
|
|
253 |
asm("xor edx, edx");
|
|
254 |
asm("le4:");
|
|
255 |
asm("cmp ecx, 4");
|
|
256 |
asm("jb onemore_defwstrhash");
|
|
257 |
asm("mov dx, [esi+2]");
|
|
258 |
asm("shl edx, 16");
|
|
259 |
asm("onemore_defwstrhash:");
|
|
260 |
asm("mov dx, [esi]");
|
|
261 |
asm("xor eax, edx");
|
|
262 |
asm("mov edx, 0x9E3779B9");
|
|
263 |
asm("mul edx");
|
|
264 |
asm("done_defwstrhash:");
|
|
265 |
asm("pop esi");
|
|
266 |
asm("ret");
|
|
267 |
} |
|
268 |
||
269 |
||
270 |
/** |
|
271 |
@publishedAll |
|
272 |
@released |
|
273 |
||
274 |
Calculate a 32 bit hash from a 32 bit integer. |
|
275 |
||
276 |
@param aInt The integer to be hashed. |
|
277 |
@return The calculated 32 bit hash value. |
|
278 |
*/ |
|
279 |
EXPORT_C __NAKED__ TUint32 DefaultHash::Integer(const TInt& /*aInt*/) |
|
280 |
{
|
|
281 |
asm("mov edx, [esp+4]");
|
|
282 |
asm("mov eax, 0x9E3779B9");
|
|
283 |
asm("mul dword ptr [edx]");
|
|
284 |
asm("ret");
|
|
285 |
} |
|
286 |