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