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