os/kernelhwsrv/kernel/eka/nkern/x86/ncthrd.cia
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/nkern/x86/ncthrd.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,81 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\nkern\x86\ncthrd.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <x86.h>
    1.22 +
    1.23 +const TLinAddr NKern_Exit = (TLinAddr)NKern::Exit;
    1.24 +const TLinAddr NKern_Lock = (TLinAddr)NKern::Lock;
    1.25 +
    1.26 +// Called by a thread when it first runs
    1.27 +__NAKED__ void __StartThread()
    1.28 +	{
    1.29 +	// On entry edi=entry point, esi=parameter block
    1.30 +	asm("sti");
    1.31 +	asm("mov ax, ss");
    1.32 +	asm("mov ds, ax");
    1.33 +	asm("mov es, ax");
    1.34 +	asm("push esi");
    1.35 +	asm("call edi");
    1.36 +	asm("add esp, 4");
    1.37 +	asm("call %a0" : : "i"(NKern_Exit));
    1.38 +	}
    1.39 +
    1.40 +
    1.41 +// Called by a thread which has been forced to exit
    1.42 +// Interrupts off here, kernel unlocked
    1.43 +__NAKED__ void __DoForcedExit()
    1.44 +	{
    1.45 +	asm("sti");
    1.46 +	asm("call %a0" : : "i"(NKern_Lock));
    1.47 +	asm("mov ecx, [%a0]" : : "i"(&TheScheduler.iCurrentThread));
    1.48 +	asm("mov dword ptr [ecx+%0], 0" : : "i"_FOFF(NThreadBase,iCsCount));
    1.49 +#ifdef __GCC32__
    1.50 +	asm("push ecx");
    1.51 +	asm("call __ZN11NThreadBase4ExitEv"); 
    1.52 +	asm("pop ecx");
    1.53 +#else
    1.54 +	TheScheduler.iCurrentThread->Exit();
    1.55 +#endif
    1.56 +	}
    1.57 +
    1.58 +
    1.59 +
    1.60 +__NAKED__ TUint32 X86::GetCR0()
    1.61 +	{
    1.62 +	asm("mov eax, cr0");
    1.63 +	asm("ret");
    1.64 +	}
    1.65 +
    1.66 +__NAKED__ void X86::SetCR0(TUint32)
    1.67 +	{
    1.68 +	asm("mov eax, [esp+4]");
    1.69 +	asm("mov cr0, eax");
    1.70 +	asm("ret");
    1.71 +	}
    1.72 +
    1.73 +__NAKED__ TUint32 X86::ModifyCR0(TUint32 /*clear*/, TUint32 /*set*/)
    1.74 +	{
    1.75 +	asm("mov ecx, [esp+4]");
    1.76 +	asm("mov edx, [esp+8]");
    1.77 +	asm("mov eax, cr0");
    1.78 +	asm("not ecx");
    1.79 +	asm("and ecx, eax");
    1.80 +	asm("or ecx, edx");
    1.81 +	asm("mov cr0, ecx");
    1.82 +	asm("ret");
    1.83 +	}
    1.84 +