kernel/eka/euser/epoc/win32/uc_utl.cpp
changeset 0 a41df078684a
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-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\win32\uc_utl.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "u32std.h"
       
    19 #include <e32base.h>
       
    20 #include <e32base_private.h>
       
    21 #include <e32hashtab.h>
       
    22 #include <emulator.h>
       
    23 #include "uc_std.h"
       
    24 
       
    25 typedef void (*TBootEpoc)(TBool);
       
    26 
       
    27 #ifdef __LEAVE_EQUALS_THROW__
       
    28 
       
    29 // Stub versions of TTrap exports to keep X86 and WINS versions of euser.def
       
    30 // the same.
       
    31 
       
    32 class TTrap
       
    33 	{
       
    34 public:
       
    35 	IMPORT_C TInt Trap(TInt& aResult);
       
    36 	IMPORT_C static void UnTrap();
       
    37 	};
       
    38 
       
    39 EXPORT_C TInt TTrap::Trap(TInt&)
       
    40 	{
       
    41 	return 0;
       
    42 	}
       
    43 
       
    44 EXPORT_C void TTrap::UnTrap()
       
    45 	{
       
    46 	}
       
    47 
       
    48 #endif
       
    49 
       
    50 EXPORT_C void EmptyFunction()
       
    51  //Function with an empty body 
       
    52 	{
       
    53 	}
       
    54 
       
    55 GLDEF_C void Panic(TCdtArchitecturePanic aPanic)
       
    56 //
       
    57 // Panic the process with USER as the category.
       
    58 //
       
    59 	{
       
    60 	_LIT(KCategory,"USER-Arch");
       
    61 	User::Panic(KCategory,aPanic);
       
    62 	}
       
    63 
       
    64 
       
    65 
       
    66 
       
    67 EXPORT_C TInt User::IsRomAddress(TBool& aBool, TAny* aPtr)
       
    68 //
       
    69 //  The FileServer loads ROM files as ReadOnly Memory Mapped Files
       
    70 //  We check the access rights of the given address for :
       
    71 //      Read access
       
    72 //      No write access
       
    73 //
       
    74 /**
       
    75 Tests whether the specified address is in the ROM.
       
    76 
       
    77 @param aBool True, if the address at aPtr is within the ROM; false, 
       
    78              otherwise.
       
    79 @param aPtr  The address to be tested.
       
    80 
       
    81 @return Always KErrNone.
       
    82 */
       
    83     {
       
    84 	const TInt KRomMask = 0xFF;
       
    85 	const TInt KRomAccess = PAGE_READONLY;
       
    86 
       
    87     aBool=EFalse;
       
    88     MEMORY_BASIC_INFORMATION mi;
       
    89 	
       
    90 	__LOCK_HOST;
       
    91     if (VirtualQuery(aPtr, &mi, sizeof(mi)) != 0 && (mi.Protect & KRomMask) == KRomAccess)
       
    92 		aBool=ETrue;
       
    93     return KErrNone;
       
    94     }
       
    95 
       
    96 
       
    97 
       
    98    
       
    99 EXPORT_C void BootEpoc(TBool aAutoRun)
       
   100 	{
       
   101 	HINSTANCE epoc = LoadLibraryA("ekern.exe");
       
   102 	if (epoc)
       
   103 		{
       
   104 		TBootEpoc ep = (TBootEpoc)GetProcAddress(epoc, "_E32Startup");
       
   105 		if (ep)
       
   106 			ep(aAutoRun);
       
   107 		}
       
   108 	ExitProcess(102);
       
   109 	}
       
   110 
       
   111 EXPORT_C void RFastLock::Wait()
       
   112 	{
       
   113 	if (InterlockedDecrement((LPLONG)&iCount) < -1)
       
   114 		RSemaphore::Wait();
       
   115 	}
       
   116 
       
   117 EXPORT_C void RFastLock::Signal()
       
   118 	{
       
   119 	if (InterlockedIncrement((LPLONG)&iCount) < 0)
       
   120 		RSemaphore::Signal();
       
   121 	}
       
   122 
       
   123 // Hash an 8 bit string at aPtr, length aLen bytes.
       
   124 __NAKED__ TUint32 DefaultStringHash(const TUint8* /*aPtr*/, TInt /*aLen*/)
       
   125 	{
       
   126 	_asm push esi
       
   127 	_asm mov esi, [esp+8]
       
   128 	_asm mov ecx, [esp+12]
       
   129 	_asm xor eax, eax
       
   130 	_asm sub ecx, 4
       
   131 	_asm jb lt4
       
   132 	ge4:
       
   133 	_asm xor eax, [esi]
       
   134 	_asm add esi, 4
       
   135 	_asm mov edx, 9E3779B9h
       
   136 	_asm mul edx
       
   137 	_asm sub ecx, 4
       
   138 	_asm jae ge4
       
   139 	lt4:
       
   140 	_asm add ecx, 4
       
   141 	_asm jz done
       
   142 	_asm xor edx, edx
       
   143 	_asm cmp ecx, 2
       
   144 	_asm jbe le2
       
   145 	_asm mov dl, [esi+2]
       
   146 	_asm shl edx, 16
       
   147 	le2:
       
   148 	_asm cmp ecx, 2
       
   149 	_asm jb onemore
       
   150 	_asm mov dh, [esi+1]
       
   151 	onemore:
       
   152 	_asm mov dl, [esi]
       
   153 	_asm xor eax, edx
       
   154 	_asm mov edx, 9E3779B9h
       
   155 	_asm mul edx
       
   156 	done:
       
   157 	_asm pop esi
       
   158 	_asm ret
       
   159 	}
       
   160 
       
   161 // Hash a 16 bit string at aPtr, length aLen bytes.
       
   162 __NAKED__ TUint32 DefaultWStringHash(const TUint16* /*aPtr*/, TInt /*aLen*/)
       
   163 	{
       
   164 	_asm push esi
       
   165 	_asm mov esi, [esp+8]
       
   166 	_asm mov ecx, [esp+12]
       
   167 	_asm xor eax, eax
       
   168 	_asm sub ecx, 8
       
   169 	_asm jb lt8
       
   170 	ge8:
       
   171 	_asm mov edx, [esi+4]
       
   172 	_asm xor eax, [esi]
       
   173 	_asm add esi, 8
       
   174 	_asm rol edx, 8
       
   175 	_asm xor eax, edx
       
   176 	_asm mov edx, 9E3779B9h
       
   177 	_asm mul edx
       
   178 	_asm sub ecx, 8
       
   179 	_asm jae ge8
       
   180 	lt8:
       
   181 	_asm add ecx, 8
       
   182 	_asm jz done
       
   183 	_asm xor edx, edx
       
   184 	_asm cmp ecx, 4
       
   185 	_asm jbe le4
       
   186 	_asm mov dx, [esi+4]
       
   187 	_asm rol edx, 8
       
   188 	_asm xor eax, edx
       
   189 	_asm xor edx, edx
       
   190 	le4:
       
   191 	_asm cmp ecx, 4
       
   192 	_asm jb onemore
       
   193 	_asm mov dx, [esi+2]
       
   194 	_asm shl edx, 16
       
   195 	onemore:
       
   196 	_asm mov dx, [esi]
       
   197 	_asm xor eax, edx
       
   198 	_asm mov edx, 9E3779B9h
       
   199 	_asm mul edx
       
   200 	done:
       
   201 	_asm pop esi
       
   202 	_asm ret
       
   203 	}
       
   204 
       
   205 /**
       
   206 @publishedAll
       
   207 @released
       
   208 
       
   209 Calculate a 32 bit hash from a 32 bit integer.
       
   210 
       
   211 @param	aInt	The integer to be hashed.
       
   212 @return			The calculated 32 bit hash value.
       
   213 */
       
   214 EXPORT_C __NAKED__ TUint32 DefaultHash::Integer(const TInt& /*aInt*/)
       
   215 	{
       
   216 	_asm mov edx, [esp+4]
       
   217 	_asm mov eax, 9E3779B9h
       
   218 	_asm mul dword ptr [edx]
       
   219 	_asm ret
       
   220 	}
       
   221