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