os/kernelhwsrv/kernel/eka/memmodel/epoc/multiple/x86/xsched.cia
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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\memmodel\epoc\multiple\x86\xsched.cia
    15 // 
    16 //
    17 
    18 #include <x86_mem.h>
    19 
    20 GLDEF_C __NAKED__ void DoProcessSwitch()
    21 	{
    22 	// Enter with kernel locked
    23 	// EBX = pointer to new thread (NThread)
    24 	// EDI = pointer to TScheduler
    25 	// ESI = pointer to TSubScheduler (SMP only)
    26 	// Preserve ESI, EDI
    27 	// eax = new process (DX86PlatProcess)
    28 	asm("mov eax, [ebx+%0]": : "i"_FOFF(NThreadBase,iAddressSpace)); 
    29 #ifdef __SMP__
    30 	asm("cmp eax, [esi+%0]": :"i"_FOFF(TSubScheduler,iAddressSpace));
    31 #else
    32 	asm("cmp eax, [edi+%0]": : "i"_FOFF(TScheduler,iAddressSpace));
    33 #endif
    34 	asm("jz no_as_switch");
    35 
    36 	asm("mov ecx, [eax+%0]": : "i"_FOFF(DMemModelProcess,iGlobalPageDir));
    37 	asm("mov cr3, ecx");
    38 #ifdef __SMP__
    39 	asm("mov [esi+%0], eax": :"i"_FOFF(TSubScheduler,iAddressSpace));
    40 #else
    41 	asm("mov [edi+%0], eax": : "i"_FOFF(TScheduler,iAddressSpace));
    42 #endif
    43 
    44 	asm("no_as_switch:");
    45 
    46 	// Get DThread* from NThread* (former contains latter so we go backwards in memory to get there)
    47 	asm("mov ecx, 0");
    48 	asm("lea ecx, [ecx+%0]": : "i"_FOFF(DThread,iNThread));
    49 	asm("sub ebx, ecx");
    50 
    51 	// check for memory being aliased...
    52 	asm("mov ecx, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasLinAddr));
    53 	asm("cmp ecx, 0");
    54 	asm("jz done");
    55 
    56 	// restore alias...
    57 	asm("mov edx, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPdePtr));
    58 	asm("mov eax, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPde));
    59 	asm("mov [edx], eax");
    60 	asm("invlpg [ecx]");
    61 
    62 	asm("done:");
    63 	asm("ret");
    64 	};
    65