os/kernelhwsrv/kernel/eka/nkern/x86/ncutils.cia
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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\ncutils.cia
    15 // 
    16 //
    17 
    18 #include <x86.h>
    19 
    20 EXPORT_C __NAKED__ TUint64 X86::Timestamp()
    21 	{
    22 	asm("rdtsc");
    23 	asm("ret");
    24 	}
    25 
    26 extern "C" __NAKED__ void NKIdle(TInt)
    27 	{
    28 	asm("hlt");
    29 	asm("ret");
    30 	}
    31 
    32 __NAKED__ void InitFpu()
    33 	{
    34 	asm("mov eax, cr0");
    35 	asm("and al, 0xf7");	// enable access to FPU
    36 	asm("mov cr0, eax");
    37 	asm("fninit");
    38 	asm("lea ecx, %a0": : "i"(DefaultCoprocessorState));
    39 	asm("fwait");
    40 	asm("fnsave [ecx]");	// save clean coprocessor state
    41 	asm("fwait");
    42 	asm("or al, 8");
    43 	asm("mov cr0, eax");	// disable access to coprocessor
    44 	asm("ret");
    45 	}
    46 
    47 
    48 const TLinAddr addressof_CrashState = (TLinAddr)&::CrashState;
    49 const TLinAddr addressof_X86_Regs = (TLinAddr)&::X86_Regs;
    50 const TLinAddr addressof_X86_IrqNestCount = (TLinAddr)&::X86_IrqNestCount;
    51 
    52 /** @internalTechnology
    53 
    54 	Called to indicate that the system has crashed and all CPUs should be
    55 	halted and should dump their registers.
    56 
    57 	Doesn't return
    58 */
    59 __NAKED__ void NKern::NotifyCrash(const TAny* /*a0*/, TInt /*a1*/)
    60 	{
    61 	asm("pushfd ");
    62 	asm("cli ");
    63 	asm("push ebp ");
    64 	asm("mov ebp, %0" : : "i" (addressof_CrashState));
    65 	asm("mov dword ptr [ebp], 1 ");
    66 	asm("mov ebp, %0" : : "i" (addressof_X86_Regs));
    67 	asm("mov [ebp+%0], eax" : : "i" _FOFF(SFullX86RegSet,iEax));
    68 	asm("mov [ebp+%0], ebx" : : "i" _FOFF(SFullX86RegSet,iEbx));
    69 	asm("mov [ebp+%0], ecx" : : "i" _FOFF(SFullX86RegSet,iEcx));
    70 	asm("mov [ebp+%0], edx" : : "i" _FOFF(SFullX86RegSet,iEdx));
    71 	asm("mov [ebp+%0], esi" : : "i" _FOFF(SFullX86RegSet,iEsi));
    72 	asm("mov [ebp+%0], edi" : : "i" _FOFF(SFullX86RegSet,iEdi));
    73 	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEbp));			// pushed EBP
    74 	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEflags));		// pushed EFLAGS
    75 	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEip));			// return address
    76 	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory));	// a0 parameter
    77 	asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason));	// a1 parameter
    78 	asm("mov [ebp+%0], esp" : : "i" _FOFF(SFullX86RegSet,iEsp));
    79 	asm("lea eax, [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iCs));
    80 	asm("mov [eax], cs ");
    81 	asm("mov [eax+4], ds ");
    82 	asm("mov [eax+8], es ");
    83 	asm("mov [eax+12], fs ");
    84 	asm("mov [eax+16], gs ");
    85 	asm("mov [eax+20], ss ");
    86 	asm("mov ebx, %0" : : "i" (addressof_X86_IrqNestCount));
    87 	asm("mov eax, 0x80000000 ");
    88 	asm("lock xchg eax, [ebx] ");
    89 	asm("mov [ebp+%0], eax" : : "i" _FOFF(SFullX86RegSet,iIrqNestCount));
    90 
    91 	asm("xor eax, eax ");
    92 	asm("push eax ");
    93 	asm("push eax ");
    94 	asm("push eax ");
    95 	asm("call %a0" : : "i" (NKCrashHandler));
    96 	asm("pop eax ");
    97 	asm("pop eax ");
    98 	asm("pop eax ");
    99 	asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason));		// a1 parameter
   100 	asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory));	// a0 parameter
   101 	asm("push 1 ");
   102 	asm("call %a0" : : "i" (NKCrashHandler));
   103 
   104 	asm("int 0xff ");	// shouldn't get here
   105 	}
   106