|
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 // |
|
15 |
|
16 #include <x86_mem.h> |
|
17 |
|
18 GLDEF_C __NAKED__ void DoProcessSwitch() |
|
19 { |
|
20 // Enter with kernel locked |
|
21 // EBX = pointer to new thread (NThread) |
|
22 // EDI = pointer to TScheduler |
|
23 // ESI = pointer to TSubScheduler (SMP only) |
|
24 // Preserve ESI, EDI |
|
25 // eax = new process (DX86PlatProcess) |
|
26 asm("mov eax, [ebx+%0]": : "i"_FOFF(NThreadBase,iAddressSpace)); |
|
27 #ifdef __SMP__ |
|
28 asm("cmp eax, [esi+%0]": :"i"_FOFF(TSubScheduler,iAddressSpace)); |
|
29 #else |
|
30 asm("cmp eax, [edi+%0]": : "i"_FOFF(TScheduler,iAddressSpace)); |
|
31 #endif |
|
32 asm("jz no_as_switch"); |
|
33 |
|
34 asm("mov ecx, [eax+%0]": : "i"_FOFF(DMemModelProcess,iPageDir)); |
|
35 asm("mov cr3, ecx"); |
|
36 #ifdef __SMP__ |
|
37 asm("mov [esi+%0], eax": :"i"_FOFF(TSubScheduler,iAddressSpace)); |
|
38 #else |
|
39 asm("mov [edi+%0], eax": : "i"_FOFF(TScheduler,iAddressSpace)); |
|
40 #endif |
|
41 |
|
42 asm("no_as_switch:"); |
|
43 |
|
44 // Get DThread* from NThread* (former contains latter so we go backwards in memory to get there) |
|
45 asm("mov ecx, 0"); |
|
46 asm("lea ecx, [ecx+%0]": : "i"_FOFF(DThread,iNThread)); |
|
47 asm("sub ebx, ecx"); |
|
48 |
|
49 // check for memory being aliased... |
|
50 asm("mov ecx, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasLinAddr)); |
|
51 asm("cmp ecx, 0"); |
|
52 asm("jz done"); |
|
53 |
|
54 // restore alias... |
|
55 asm("mov edx, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPdePtr)); |
|
56 asm("mov eax, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPde)); |
|
57 asm("mov [edx], eax"); |
|
58 asm("invlpg [ecx]"); |
|
59 |
|
60 asm("done:"); |
|
61 asm("ret"); |
|
62 }; |
|
63 |
|
64 |
|
65 |
|
66 __NAKED__ void DMemModelThread::RestoreAddressSpace() |
|
67 { |
|
68 #ifndef __SMP__ |
|
69 //SMP FIXME |
|
70 asm("mov eax, [%a0]": : "i"(&TheScheduler.iCurrentThread)); |
|
71 |
|
72 // edx = current thread owning process... |
|
73 asm("mov edx, 0"); |
|
74 asm("lea edx, [edx+%0]": : "i"_FOFF(DThread,iNThread)); |
|
75 asm("neg edx"); |
|
76 asm("mov edx, [eax+edx+%0]": : "i"_FOFF(DThread,iOwningProcess)); |
|
77 |
|
78 // update page directory and address space values... |
|
79 asm("cli"); |
|
80 asm("mov [%a0], edx": :"i"(&TheScheduler.iAddressSpace)); |
|
81 asm("mov [eax+%0], edx": : "i"_FOFF(NThreadBase,iAddressSpace)); |
|
82 asm("mov edx, [edx+%0]": : "i"_FOFF(DMemModelProcess,iPageDir)); |
|
83 asm("mov cr3, edx"); |
|
84 asm("sti"); |
|
85 #endif |
|
86 asm("ret"); |
|
87 } |
|
88 |
|
89 |