author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:37:04 +0300 | |
changeset 266 | 0008ccd16016 |
parent 36 | 538db54a451d |
permissions | -rw-r--r-- |
0 | 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... |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
// Disable interrupts so setting the alias pde is must complete before |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
// Mmu::RemoveAliasesForPageTable() can execute the alias IPI and vice |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
// versa. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
asm("cli "); // turn off interrupts |
0 | 59 |
asm("mov edx, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPdePtr)); |
60 |
asm("mov eax, [ebx+%0]": : "i"_FOFF(DMemModelThread,iAliasPde)); |
|
61 |
asm("mov [edx], eax"); |
|
62 |
asm("invlpg [ecx]"); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
asm("sti "); // turn on interrupts |
0 | 64 |
|
65 |
asm("done:"); |
|
66 |
asm("ret"); |
|
67 |
}; |
|
68 |
||
69 |
||
70 |
||
71 |
__NAKED__ void DMemModelThread::RestoreAddressSpace() |
|
72 |
{ |
|
73 |
#ifndef __SMP__ |
|
74 |
//SMP FIXME |
|
75 |
asm("mov eax, [%a0]": : "i"(&TheScheduler.iCurrentThread)); |
|
76 |
||
77 |
// edx = current thread owning process... |
|
78 |
asm("mov edx, 0"); |
|
79 |
asm("lea edx, [edx+%0]": : "i"_FOFF(DThread,iNThread)); |
|
80 |
asm("neg edx"); |
|
81 |
asm("mov edx, [eax+edx+%0]": : "i"_FOFF(DThread,iOwningProcess)); |
|
82 |
||
83 |
// update page directory and address space values... |
|
84 |
asm("cli"); |
|
85 |
asm("mov [%a0], edx": :"i"(&TheScheduler.iAddressSpace)); |
|
86 |
asm("mov [eax+%0], edx": : "i"_FOFF(NThreadBase,iAddressSpace)); |
|
87 |
asm("mov edx, [edx+%0]": : "i"_FOFF(DMemModelProcess,iPageDir)); |
|
88 |
asm("mov cr3, edx"); |
|
89 |
asm("sti"); |
|
90 |
#endif |
|
91 |
asm("ret"); |
|
92 |
} |
|
93 |
||
94 |