kernel/eka/memmodel/epoc/flexible/arm/xkernel.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1994-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 //
       
    15 
       
    16 #include "arm_mem.h"
       
    17 #include "../mmu/mm.h"
       
    18 
       
    19 TInt DArmPlatThread::SetupContext(SThreadCreateInfo& aInfo)
       
    20 	{
       
    21 	switch(iThreadType)
       
    22 		{
       
    23 		case EThreadSupervisor:
       
    24 		case EThreadMinimalSupervisor:
       
    25 		case EThreadInitial:
       
    26 		case EThreadAPInitial:
       
    27 			break;
       
    28 		case EThreadUser:
       
    29 #ifndef __SMP__
       
    30 			iNThread.iSpare3 /*iUserContextType*/ = NThread::EContextUndefined;
       
    31 #endif
       
    32 			break;
       
    33 		}
       
    34 	iNThread.SetAddressSpace(iOwningProcess);
       
    35 	iNThread.SetAttributes(KThreadAttAddressSpace);
       
    36 #ifdef __SMP__
       
    37 	iCpuRestoreCookie = -1;
       
    38 #else
       
    39 	// OK to get this thread's owning process os asid as the process can't free
       
    40 	// it's asid while this thread is being created because the current thread
       
    41 	// has the same owning process.
       
    42 	MM::IpcAliasPde(iAliasPdePtr,((DMemModelProcess*)iOwningProcess)->OsAsid());
       
    43 #endif
       
    44 	return KErrNone;
       
    45 	}
       
    46 
       
    47 TIpcExcTrap::TExcLocation TIpcExcTrap::ExcLocation(DThread* aThread, TAny* aContext)
       
    48 	{
       
    49 	TArmExcInfo& info=*(TArmExcInfo*)aContext;
       
    50 	if (info.iExcCode==EArmExceptionDataAbort)
       
    51 		{
       
    52 		TLinAddr va=(TLinAddr)info.iFaultAddress;
       
    53 
       
    54 		TLinAddr aliasAddr = ((DMemModelThread*)aThread)->iAliasLinAddr;
       
    55 		TBool remoteError;
       
    56 		if(aliasAddr)
       
    57 			remoteError = TUint(va^aliasAddr)<TUint(KPageSize);
       
    58 		else
       
    59 			// The second clause in the statement below was "va < iRemoteBase + iSize".
       
    60 			// iRemoteBase + iSize might conceivably wrap round.
       
    61 			// The usual fix for this is to change
       
    62 			//			va >= base && va < base + size
       
    63 			// to		va >= base && (va - base) < size
       
    64 			// but this requires the first clause (va >= base) so that va-base doesn't wrap negative.
       
    65 			// Since the first clause in this expression is va >= (iRemoteBase & ~3)
       
    66 			// we have to re-write the expression as follows:
       
    67 			// Let base' = iRemoteBase & ~3
       
    68 			// so  base  = base' + (base & 3)
       
    69 			// then we have va >= base' && va < base' + (base & 3) + iSize
       
    70 			// (effectively the & ~3 on the first clause extends the range downwards by base & 3)
       
    71 			remoteError = va>=(iRemoteBase&~3) &&
       
    72 							(va - (iRemoteBase & ~3)) < iSize + (iRemoteBase & 3);
       
    73 		if (remoteError)
       
    74 			return EExcRemote;
       
    75 
       
    76 		// Third clause was va < iLocalBase + iSize, fixed as in the "remoteError =" line above
       
    77 		if (iLocalBase && va>=(iLocalBase&~3) &&
       
    78 			(va - (iLocalBase & ~3)) < iSize + (iLocalBase & 3))
       
    79 			return EExcLocal;
       
    80 		}
       
    81 	return EExcUnknown;
       
    82 	}