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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\nkernsmp\x86\ncutils.cia
21 extern "C" __NAKED__ void NKIdle(TInt)
28 __NAKED__ void InitFpu()
31 asm("and al, 0xf7"); // enable access to FPU
34 asm("lea ecx, %a0": : "i"(DefaultCoprocessorState));
36 asm("fnsave [ecx]"); // save clean coprocessor state
39 asm("mov cr0, eax"); // disable access to coprocessor
44 const TLinAddr addressof_CrashState = (TLinAddr)&::CrashState;
46 /** @internalTechnology
48 Called to indicate that the system has crashed and all CPUs should be
49 halted and should dump their registers.
53 __NAKED__ void NKern::NotifyCrash(const TAny* /*a0*/, TInt /*a1*/)
62 asm("mov ecx, %0": :"i" (addressof_CrashState));
63 asm("mov esi, ds:[%0]" : : "i"(X86_LOCAL_APIC_BASE + X86_LOCAL_APIC_OFFSET_ID));
65 asm("mov esi, [esi*4+%0]" : : "i"(&SubSchedulerLookupTable));
66 asm("mov eax, [ecx] ");
70 asm("jnz short atomic_set_1 ");
71 asm("mov edx, [%a0]" : : "i" (&TheScheduler.iActiveCpus1));
73 asm("atomic_set_1: ");
74 asm("or edx, [esi+%0]" : : "i" _FOFF(TSubScheduler,iCpuMask));
75 asm("lock cmpxchg [ecx], edx ");
76 asm("jne short atomic_set ");
78 asm("cmp eax, 0 "); // were we first to crash?
79 asm("jz first_to_crash ");
81 // not the first to crash - wait for NMI
85 asm("lea eax, crash_halt ");
87 asm("iretd "); // return to next instruction, allowing further NMIs
90 asm("jmp short crash_halt ");
92 asm("first_to_crash: ");
93 asm("mov ebp, [esi+60+%0]" : : "i" _FOFF(TSubScheduler,iExtras)); // points to SCpuData
94 asm("lea ebp, [ebp+%0]" : : "i" _FOFF(SCpuData,iRegs));
95 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEsi));
96 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEbp));
97 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEax));
98 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEdx));
99 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEcx));
100 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEflags));
101 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iEip));
102 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory));
103 asm("pop dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason));
104 asm("mov [ebp+%0], ebx" : : "i" _FOFF(SFullX86RegSet,iEbx));
105 asm("mov [ebp+%0], edi" : : "i" _FOFF(SFullX86RegSet,iEdi));
106 asm("mov [ebp+%0], esp" : : "i" _FOFF(SFullX86RegSet,iEsp));
107 asm("lea eax, [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iCs));
108 asm("mov [eax], cs ");
109 asm("mov [eax+4], ds ");
110 asm("mov [eax+8], es ");
111 asm("mov [eax+12], fs ");
112 asm("mov [eax+16], gs ");
113 asm("mov [eax+20], ss ");
114 asm("lea ebx, [esi+52+%0]" : : "i" _FOFF(TSubScheduler,iExtras)); // points to i_IrqNestCount
115 asm("mov eax, 0x80000000 ");
116 asm("lock xchg eax, [ebx] ");
117 asm("mov [ebp+%0], eax" : : "i" _FOFF(SFullX86RegSet,iIrqNestCount));
119 // send NMI to every other processor
121 asm("xor eax, eax ");
122 asm("mov ds:[%0], eax": :"i"(X86_LOCAL_APIC_BASE + X86_LOCAL_APIC_OFFSET_ICRH));
123 asm("mov eax, %0" : : "i" (0x000C4400));
124 asm("mov ds:[%0], eax": :"i"(X86_LOCAL_APIC_BASE + X86_LOCAL_APIC_OFFSET_ICRL));
126 asm("xor eax, eax ");
130 asm("call %a0" : : "i" (NKCrashHandler));
136 asm("mov eax, [esi+%0] " : : "i" _FOFF(TSubScheduler,iCpuMask));
138 asm("mov edx, %0": :"i" (addressof_CrashState));
139 asm("lock and [edx+2], ax ");
140 asm("mov dword ptr [esi+44+%0], 1" : : "i" _FOFF(TSubScheduler, iExtras)); // flag that this CPU is done
141 asm("xor ecx, ecx ");
142 asm("wait_other_cpus: ");
143 asm("mov ax, [edx+2] ");
145 asm("jz short wait_other_cpus_done ");
147 asm("jnz short wait_other_cpus ");
148 asm("wait_other_cpus_done: ");
150 asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultReason)); // a1 parameter
151 asm("push dword ptr [ebp+%0]" : : "i" _FOFF(SFullX86RegSet,iFaultCategory)); // a0 parameter
153 asm("call %a0" : : "i" (NKCrashHandler));
154 asm("int 0xff "); // shouldn't get here