os/kernelhwsrv/kernel/eka/nkernsmp/x86/nccpu.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) 2008-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\nkernsmp\x86\nccpu.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <x86.h>
sl@0
    19
#include <apic.h>
sl@0
    20
sl@0
    21
__NAKED__ void cmos_write(TUint32 val, TUint32 addr)
sl@0
    22
	{
sl@0
    23
	asm("mov eax, [esp+8]");
sl@0
    24
	asm("out 0x70, al");
sl@0
    25
	asm("mov eax, [esp+4]");
sl@0
    26
	asm("out 0x71, al");
sl@0
    27
	asm("ret");
sl@0
    28
	}
sl@0
    29
sl@0
    30
__NAKED__ void SetupApInitInfo(volatile SApInitInfo&)
sl@0
    31
	{
sl@0
    32
	asm("mov ecx, [esp+4]");
sl@0
    33
	asm("sgdt [ecx+%0]": :"i"_FOFF(SApInitInfo, iGdtr));
sl@0
    34
	asm("sidt [ecx+%0]": :"i"_FOFF(SApInitInfo, iIdtr));
sl@0
    35
	asm("mov eax, cr0");
sl@0
    36
	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr0));
sl@0
    37
	asm("mov eax, cr3");
sl@0
    38
	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr3));
sl@0
    39
	MOV_EAX_CR4;
sl@0
    40
	asm("mov [ecx+%0], eax": :"i"_FOFF(SApInitInfo, iCr4));
sl@0
    41
	asm("ret");
sl@0
    42
	}
sl@0
    43
sl@0
    44
__NAKED__ void _ApMain()
sl@0
    45
	{
sl@0
    46
	asm("mov eax, %0" : : "i" (RING0_DS));
sl@0
    47
	asm("mov ss, ax ");
sl@0
    48
	asm("mov ds, ax ");
sl@0
    49
	asm("mov es, ax ");
sl@0
    50
	asm("mov fs, ax ");
sl@0
    51
	asm("mov gs, ax ");
sl@0
    52
	asm("lgdt [edi+%0]" : : "i" _FOFF(SApInitInfo, iGdtr));
sl@0
    53
	asm("lidt [edi+%0]" : : "i" _FOFF(SApInitInfo, iIdtr));
sl@0
    54
	asm("mov esp, [edi+%0]" : : "i" _FOFF(SApInitInfo, iRgs.iEsp));
sl@0
    55
	asm("mov eax, [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
sl@0
    56
	asm("lock dec dword ptr [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
sl@0
    57
	asm("sub eax, 2 ");
sl@0
    58
	asm("wait_for_bp: ");
sl@0
    59
	asm("cmp eax, [edi+%0]" : : "i" _FOFF(SApInitInfo, iBootFlag));
sl@0
    60
	X86_PAUSE
sl@0
    61
	asm("jne wait_for_bp ");
sl@0
    62
sl@0
    63
	asm("mov eax, cr0 ");
sl@0
    64
	asm("and al, 0xf7 ");	// enable access to FPU
sl@0
    65
	asm("mov cr0, eax ");
sl@0
    66
	asm("fninit ");			// initialise coprocessor
sl@0
    67
	asm("fwait ");
sl@0
    68
	asm("or al, 8 ");
sl@0
    69
	asm("mov cr0, eax ");	// disable access to coprocessor
sl@0
    70
sl@0
    71
	asm("mov ecx, [edi+%0]" : : "i" _FOFF(SApInitInfo, iExtra));
sl@0
    72
	asm("mov eax, [ecx+%0]" : : "i" _FOFF(SAPBootInfo, iMain));
sl@0
    73
	asm("push ecx ");
sl@0
    74
	asm("call eax ");
sl@0
    75
	asm("add esp, 4 ");
sl@0
    76
	asm("spin: ");
sl@0
    77
	asm("hlt ");
sl@0
    78
	asm("jmp spin ");
sl@0
    79
	}