os/kernelhwsrv/kernel/eka/nkern/x86/ncutils.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/ncutils.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,106 @@
     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\ncutils.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <x86.h>
    1.22 +
    1.23 +EXPORT_C __NAKED__ TUint64 X86::Timestamp()
    1.24 +	{
    1.25 +	asm("rdtsc");
    1.26 +	asm("ret");
    1.27 +	}
    1.28 +
    1.29 +extern "C" __NAKED__ void NKIdle(TInt)
    1.30 +	{
    1.31 +	asm("hlt");
    1.32 +	asm("ret");
    1.33 +	}
    1.34 +
    1.35 +__NAKED__ void InitFpu()
    1.36 +	{
    1.37 +	asm("mov eax, cr0");
    1.38 +	asm("and al, 0xf7");	// enable access to FPU
    1.39 +	asm("mov cr0, eax");
    1.40 +	asm("fninit");
    1.41 +	asm("lea ecx, %a0": : "i"(DefaultCoprocessorState));
    1.42 +	asm("fwait");
    1.43 +	asm("fnsave [ecx]");	// save clean coprocessor state
    1.44 +	asm("fwait");
    1.45 +	asm("or al, 8");
    1.46 +	asm("mov cr0, eax");	// disable access to coprocessor
    1.47 +	asm("ret");
    1.48 +	}
    1.49 +
    1.50 +
    1.51 +const TLinAddr addressof_CrashState = (TLinAddr)&::CrashState;
    1.52 +const TLinAddr addressof_X86_Regs = (TLinAddr)&::X86_Regs;
    1.53 +const TLinAddr addressof_X86_IrqNestCount = (TLinAddr)&::X86_IrqNestCount;
    1.54 +
    1.55 +/** @internalTechnology
    1.56 +
    1.57 +	Called to indicate that the system has crashed and all CPUs should be
    1.58 +	halted and should dump their registers.
    1.59 +
    1.60 +	Doesn't return
    1.61 +*/
    1.62 +__NAKED__ void NKern::NotifyCrash(const TAny* /*a0*/, TInt /*a1*/)
    1.63 +	{
    1.64 +	asm("pushfd ");
    1.65 +	asm("cli ");
    1.66 +	asm("push ebp ");
    1.67 +	asm("mov ebp, %0" : : "i" (addressof_CrashState));
    1.68 +	asm("mov dword ptr [ebp], 1 ");
    1.69 +	asm("mov ebp, %0" : : "i" (addressof_X86_Regs));
    1.70 +	asm("mov [ebp+%0], eax" : : "i" _FOFF(SFullX86RegSet,iEax));
    1.71 +	asm("mov [ebp+%0], ebx" : : "i" _FOFF(SFullX86RegSet,iEbx));
    1.72 +	asm("mov [ebp+%0], ecx" : : "i" _FOFF(SFullX86RegSet,iEcx));
    1.73 +	asm("mov [ebp+%0], edx" : : "i" _FOFF(SFullX86RegSet,iEdx));
    1.74 +	asm("mov [ebp+%0], esi" : : "i" _FOFF(SFullX86RegSet,iEsi));
    1.75 +	asm("mov [ebp+%0], edi" : : "i" _FOFF(SFullX86RegSet,iEdi));
    1.76 +	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEbp));			// pushed EBP
    1.77 +	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEflags));		// pushed EFLAGS
    1.78 +	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEip));			// return address
    1.79 +	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory));	// a0 parameter
    1.80 +	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason));	// a1 parameter
    1.81 +	asm("mov [ebp+%0], esp" : : "i" _FOFF(SFullX86RegSet,iEsp));
    1.82 +	asm("lea eax, [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iCs));
    1.83 +	asm("mov [eax], cs ");
    1.84 +	asm("mov [eax+4], ds ");
    1.85 +	asm("mov [eax+8], es ");
    1.86 +	asm("mov [eax+12], fs ");
    1.87 +	asm("mov [eax+16], gs ");
    1.88 +	asm("mov [eax+20], ss ");
    1.89 +	asm("mov ebx, %0" : : "i" (addressof_X86_IrqNestCount));
    1.90 +	asm("mov eax, 0x80000000 ");
    1.91 +	asm("lock xchg eax, [ebx] ");
    1.92 +	asm("mov [ebp+%0], eax" : : "i" _FOFF(SFullX86RegSet,iIrqNestCount));
    1.93 +
    1.94 +	asm("xor eax, eax ");
    1.95 +	asm("push eax ");
    1.96 +	asm("push eax ");
    1.97 +	asm("push eax ");
    1.98 +	asm("call %a0" : : "i" (NKCrashHandler));
    1.99 +	asm("pop eax ");
   1.100 +	asm("pop eax ");
   1.101 +	asm("pop eax ");
   1.102 +	asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason));		// a1 parameter
   1.103 +	asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory));	// a0 parameter
   1.104 +	asm("push 1 ");
   1.105 +	asm("call %a0" : : "i" (NKCrashHandler));
   1.106 +
   1.107 +	asm("int 0xff ");	// shouldn't get here
   1.108 +	}
   1.109 +