os/kernelhwsrv/kernel/eka/nkernsmp/x86/nccpu.cia
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/nkernsmp/x86/nccpu.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,79 @@
     1.4 +// Copyright (c) 2008-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\nkernsmp\x86\nccpu.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <x86.h>
    1.22 +#include <apic.h>
    1.23 +
    1.24 +__NAKED__ void cmos_write(TUint32 val, TUint32 addr)
    1.25 +	{
    1.26 +	asm("mov eax, [esp+8]");
    1.27 +	asm("out 0x70, al");
    1.28 +	asm("mov eax, [esp+4]");
    1.29 +	asm("out 0x71, al");
    1.30 +	asm("ret");
    1.31 +	}
    1.32 +
    1.33 +__NAKED__ void SetupApInitInfo(volatile SApInitInfo&)
    1.34 +	{
    1.35 +	asm("mov ecx, [esp+4]");
    1.36 +	asm("sgdt [ecx+%0]": :"i"_FOFF(SApInitInfo, iGdtr));
    1.37 +	asm("sidt [ecx+%0]": :"i"_FOFF(SApInitInfo, iIdtr));
    1.38 +	asm("mov eax, cr0");
    1.39 +	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr0));
    1.40 +	asm("mov eax, cr3");
    1.41 +	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr3));
    1.42 +	MOV_EAX_CR4;
    1.43 +	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr4));
    1.44 +	asm("ret");
    1.45 +	}
    1.46 +
    1.47 +__NAKED__ void _ApMain()
    1.48 +	{
    1.49 +	asm("mov eax, %0" : : "i" (RING0_DS));
    1.50 +	asm("mov ss, ax ");
    1.51 +	asm("mov ds, ax ");
    1.52 +	asm("mov es, ax ");
    1.53 +	asm("mov fs, ax ");
    1.54 +	asm("mov gs, ax ");
    1.55 +	asm("lgdt [edi+%0]" : : "i" _FOFF(SApInitInfo, iGdtr));
    1.56 +	asm("lidt [edi+%0]" : : "i" _FOFF(SApInitInfo, iIdtr));
    1.57 +	asm("mov esp, [edi+%0]" : : "i" _FOFF(SApInitInfo, iRgs.iEsp));
    1.58 +	asm("mov eax, [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
    1.59 +	asm("lock dec dword ptr [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
    1.60 +	asm("sub eax, 2 ");
    1.61 +	asm("wait_for_bp: ");
    1.62 +	asm("cmp eax, [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
    1.63 +	X86_PAUSE
    1.64 +	asm("jne wait_for_bp ");
    1.65 +
    1.66 +	asm("mov eax, cr0 ");
    1.67 +	asm("and al, 0xf7 ");	// enable access to FPU
    1.68 +	asm("mov cr0, eax ");
    1.69 +	asm("fninit ");			// initialise coprocessor
    1.70 +	asm("fwait ");
    1.71 +	asm("or al, 8 ");
    1.72 +	asm("mov cr0, eax ");	// disable access to coprocessor
    1.73 +
    1.74 +	asm("mov ecx, [edi+%0]" : : "i" _FOFF(SApInitInfo, iExtra));
    1.75 +	asm("mov eax, [ecx+%0]" : : "i" _FOFF(SAPBootInfo, iMain));
    1.76 +	asm("push ecx ");
    1.77 +	asm("call eax ");
    1.78 +	asm("add esp, 4 ");
    1.79 +	asm("spin: ");
    1.80 +	asm("hlt ");
    1.81 +	asm("jmp spin ");
    1.82 +	}