os/kernelhwsrv/kernel/eka/nkern/x86/ncthrd.cia
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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\nkern\x86\ncthrd.cia
    15 // 
    16 //
    17 
    18 #include <x86.h>
    19 
    20 const TLinAddr NKern_Exit = (TLinAddr)NKern::Exit;
    21 const TLinAddr NKern_Lock = (TLinAddr)NKern::Lock;
    22 
    23 // Called by a thread when it first runs
    24 __NAKED__ void __StartThread()
    25 	{
    26 	// On entry edi=entry point, esi=parameter block
    27 	asm("sti");
    28 	asm("mov ax, ss");
    29 	asm("mov ds, ax");
    30 	asm("mov es, ax");
    31 	asm("push esi");
    32 	asm("call edi");
    33 	asm("add esp, 4");
    34 	asm("call %a0" : : "i"(NKern_Exit));
    35 	}
    36 
    37 
    38 // Called by a thread which has been forced to exit
    39 // Interrupts off here, kernel unlocked
    40 __NAKED__ void __DoForcedExit()
    41 	{
    42 	asm("sti");
    43 	asm("call %a0" : : "i"(NKern_Lock));
    44 	asm("mov ecx, [%a0]" : : "i"(&TheScheduler.iCurrentThread));
    45 	asm("mov dword ptr [ecx+%0], 0" : : "i"_FOFF(NThreadBase,iCsCount));
    46 #ifdef __GCC32__
    47 	asm("push ecx");
    48 	asm("call __ZN11NThreadBase4ExitEv"); 
    49 	asm("pop ecx");
    50 #else
    51 	TheScheduler.iCurrentThread->Exit();
    52 #endif
    53 	}
    54 
    55 
    56 
    57 __NAKED__ TUint32 X86::GetCR0()
    58 	{
    59 	asm("mov eax, cr0");
    60 	asm("ret");
    61 	}
    62 
    63 __NAKED__ void X86::SetCR0(TUint32)
    64 	{
    65 	asm("mov eax, [esp+4]");
    66 	asm("mov cr0, eax");
    67 	asm("ret");
    68 	}
    69 
    70 __NAKED__ TUint32 X86::ModifyCR0(TUint32 /*clear*/, TUint32 /*set*/)
    71 	{
    72 	asm("mov ecx, [esp+4]");
    73 	asm("mov edx, [esp+8]");
    74 	asm("mov eax, cr0");
    75 	asm("not ecx");
    76 	asm("and ecx, eax");
    77 	asm("or ecx, edx");
    78 	asm("mov cr0, ecx");
    79 	asm("ret");
    80 	}
    81