os/kernelhwsrv/kernel/eka/euser/epoc/win32/uc_utl.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 
    40 #ifdef __SYMC__
    41 
    42 EXPORT_C TInt TTrap::Trap(TInt&)
    43 	{
    44 		/*
    45 	TTrapHandler* h = Exec::PushTrapFrame(this);
    46 	if (h != NULL)
    47 		h->Trap();
    48 */
    49 	return 0;
    50 	}
    51 
    52 EXPORT_C void TTrap::UnTrap()
    53 	{
    54 	}
    55 
    56 #else
    57 EXPORT_C TInt TTrap::Trap(TInt&)
    58 	{
    59 	return 0;
    60 	}
    61 
    62 EXPORT_C void TTrap::UnTrap()
    63 	{
    64 	}
    65 #endif
    66 
    67 #endif
    68 
    69 EXPORT_C void EmptyFunction()
    70  //Function with an empty body 
    71 	{
    72 	}
    73 
    74 GLDEF_C void Panic(TCdtArchitecturePanic aPanic)
    75 //
    76 // Panic the process with USER as the category.
    77 //
    78 	{
    79 	_LIT(KCategory,"USER-Arch");
    80 	User::Panic(KCategory,aPanic);
    81 	}
    82 
    83 
    84 
    85 
    86 EXPORT_C TInt User::IsRomAddress(TBool& aBool, TAny* aPtr)
    87 //
    88 //  The FileServer loads ROM files as ReadOnly Memory Mapped Files
    89 //  We check the access rights of the given address for :
    90 //      Read access
    91 //      No write access
    92 //
    93 /**
    94 Tests whether the specified address is in the ROM.
    95 
    96 @param aBool True, if the address at aPtr is within the ROM; false, 
    97              otherwise.
    98 @param aPtr  The address to be tested.
    99 
   100 @return Always KErrNone.
   101 */
   102     {
   103 	const TInt KRomMask = 0xFF;
   104 	const TInt KRomAccess = PAGE_READONLY;
   105 
   106     aBool=EFalse;
   107     MEMORY_BASIC_INFORMATION mi;
   108 	
   109 	__LOCK_HOST;
   110     if (VirtualQuery(aPtr, &mi, sizeof(mi)) != 0 && (mi.Protect & KRomMask) == KRomAccess)
   111 		aBool=ETrue;
   112     return KErrNone;
   113     }
   114 
   115 
   116 
   117    
   118 EXPORT_C void BootEpoc(TBool aAutoRun)
   119 	{
   120 	HINSTANCE epoc = LoadLibraryA("ekern.exe");
   121 	if (epoc)
   122 		{
   123 		TBootEpoc ep = (TBootEpoc)GetProcAddress(epoc, "_E32Startup");
   124 		if (ep)
   125 			ep(aAutoRun);
   126 		}
   127 	ExitProcess(102);
   128 	}
   129 
   130 EXPORT_C void RFastLock::Wait()
   131 	{
   132 	if (InterlockedDecrement((LPLONG)&iCount) < -1)
   133 		RSemaphore::Wait();
   134 	}
   135 
   136 EXPORT_C void RFastLock::Signal()
   137 	{
   138 	if (InterlockedIncrement((LPLONG)&iCount) < 0)
   139 		RSemaphore::Signal();
   140 	}
   141 
   142 // Hash an 8 bit string at aPtr, length aLen bytes.
   143 __NAKED__ TUint32 DefaultStringHash(const TUint8* /*aPtr*/, TInt /*aLen*/)
   144 	{
   145 	_asm push esi
   146 	_asm mov esi, [esp+8]
   147 	_asm mov ecx, [esp+12]
   148 	_asm xor eax, eax
   149 	_asm sub ecx, 4
   150 	_asm jb lt4
   151 	ge4:
   152 	_asm xor eax, [esi]
   153 	_asm add esi, 4
   154 	_asm mov edx, 9E3779B9h
   155 	_asm mul edx
   156 	_asm sub ecx, 4
   157 	_asm jae ge4
   158 	lt4:
   159 	_asm add ecx, 4
   160 	_asm jz done
   161 	_asm xor edx, edx
   162 	_asm cmp ecx, 2
   163 	_asm jbe le2
   164 	_asm mov dl, [esi+2]
   165 	_asm shl edx, 16
   166 	le2:
   167 	_asm cmp ecx, 2
   168 	_asm jb onemore
   169 	_asm mov dh, [esi+1]
   170 	onemore:
   171 	_asm mov dl, [esi]
   172 	_asm xor eax, edx
   173 	_asm mov edx, 9E3779B9h
   174 	_asm mul edx
   175 	done:
   176 	_asm pop esi
   177 	_asm ret
   178 	}
   179 
   180 // Hash a 16 bit string at aPtr, length aLen bytes.
   181 __NAKED__ TUint32 DefaultWStringHash(const TUint16* /*aPtr*/, TInt /*aLen*/)
   182 	{
   183 	_asm push esi
   184 	_asm mov esi, [esp+8]
   185 	_asm mov ecx, [esp+12]
   186 	_asm xor eax, eax
   187 	_asm sub ecx, 8
   188 	_asm jb lt8
   189 	ge8:
   190 	_asm mov edx, [esi+4]
   191 	_asm xor eax, [esi]
   192 	_asm add esi, 8
   193 	_asm rol edx, 8
   194 	_asm xor eax, edx
   195 	_asm mov edx, 9E3779B9h
   196 	_asm mul edx
   197 	_asm sub ecx, 8
   198 	_asm jae ge8
   199 	lt8:
   200 	_asm add ecx, 8
   201 	_asm jz done
   202 	_asm xor edx, edx
   203 	_asm cmp ecx, 4
   204 	_asm jbe le4
   205 	_asm mov dx, [esi+4]
   206 	_asm rol edx, 8
   207 	_asm xor eax, edx
   208 	_asm xor edx, edx
   209 	le4:
   210 	_asm cmp ecx, 4
   211 	_asm jb onemore
   212 	_asm mov dx, [esi+2]
   213 	_asm shl edx, 16
   214 	onemore:
   215 	_asm mov dx, [esi]
   216 	_asm xor eax, edx
   217 	_asm mov edx, 9E3779B9h
   218 	_asm mul edx
   219 	done:
   220 	_asm pop esi
   221 	_asm ret
   222 	}
   223 
   224 /**
   225 @publishedAll
   226 @released
   227 
   228 Calculate a 32 bit hash from a 32 bit integer.
   229 
   230 @param	aInt	The integer to be hashed.
   231 @return			The calculated 32 bit hash value.
   232 */
   233 EXPORT_C __NAKED__ TUint32 DefaultHash::Integer(const TInt& /*aInt*/)
   234 	{
   235 	_asm mov edx, [esp+4]
   236 	_asm mov eax, 9E3779B9h
   237 	_asm mul dword ptr [edx]
   238 	_asm ret
   239 	}
   240