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