xref: /reactos/ntoskrnl/ke/i386/context.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:         ReactOS Kernel
3*c2c66affSColin Finck  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4*c2c66affSColin Finck  * FILE:            ntoskrnl/ke/i386/context.c
5*c2c66affSColin Finck  * PURPOSE:         Context Switching Related Code
6*c2c66affSColin Finck  * PROGRAMMERS:     ReactOS Portable Systems Group
7*c2c66affSColin Finck  */
8*c2c66affSColin Finck 
9*c2c66affSColin Finck /* INCLUDES *******************************************************************/
10*c2c66affSColin Finck 
11*c2c66affSColin Finck #include <ntoskrnl.h>
12*c2c66affSColin Finck #define NDEBUG
13*c2c66affSColin Finck #include <debug.h>
14*c2c66affSColin Finck 
15*c2c66affSColin Finck /* GLOBALS ********************************************************************/
16*c2c66affSColin Finck 
17*c2c66affSColin Finck /* FUNCTIONS ******************************************************************/
18*c2c66affSColin Finck 
19*c2c66affSColin Finck VOID
20*c2c66affSColin Finck NTAPI
KiSwapProcess(IN PKPROCESS NewProcess,IN PKPROCESS OldProcess)21*c2c66affSColin Finck KiSwapProcess(IN PKPROCESS NewProcess,
22*c2c66affSColin Finck               IN PKPROCESS OldProcess)
23*c2c66affSColin Finck {
24*c2c66affSColin Finck     PKIPCR Pcr = (PKIPCR)KeGetPcr();
25*c2c66affSColin Finck #ifdef CONFIG_SMP
26*c2c66affSColin Finck     LONG SetMember;
27*c2c66affSColin Finck 
28*c2c66affSColin Finck     /* Update active processor mask */
29*c2c66affSColin Finck     SetMember = (LONG)Pcr->SetMember;
30*c2c66affSColin Finck     InterlockedXor((PLONG)&NewProcess->ActiveProcessors, SetMember);
31*c2c66affSColin Finck     InterlockedXor((PLONG)&OldProcess->ActiveProcessors, SetMember);
32*c2c66affSColin Finck #endif
33*c2c66affSColin Finck 
34*c2c66affSColin Finck     /* Check for new LDT */
35*c2c66affSColin Finck     if (NewProcess->LdtDescriptor.LimitLow != OldProcess->LdtDescriptor.LimitLow)
36*c2c66affSColin Finck     {
37*c2c66affSColin Finck         if (NewProcess->LdtDescriptor.LimitLow)
38*c2c66affSColin Finck         {
39*c2c66affSColin Finck             KeSetGdtSelector(KGDT_LDT,
40*c2c66affSColin Finck                              ((PULONG)&NewProcess->LdtDescriptor)[0],
41*c2c66affSColin Finck                              ((PULONG)&NewProcess->LdtDescriptor)[1]);
42*c2c66affSColin Finck             Ke386SetLocalDescriptorTable(KGDT_LDT);
43*c2c66affSColin Finck         }
44*c2c66affSColin Finck         else
45*c2c66affSColin Finck         {
46*c2c66affSColin Finck             Ke386SetLocalDescriptorTable(0);
47*c2c66affSColin Finck         }
48*c2c66affSColin Finck     }
49*c2c66affSColin Finck 
50*c2c66affSColin Finck     /* Update CR3 */
51*c2c66affSColin Finck     __writecr3(NewProcess->DirectoryTableBase[0]);
52*c2c66affSColin Finck 
53*c2c66affSColin Finck     /* Clear GS */
54*c2c66affSColin Finck     Ke386SetGs(0);
55*c2c66affSColin Finck 
56*c2c66affSColin Finck     /* Update IOPM offset */
57*c2c66affSColin Finck     Pcr->TSS->IoMapBase = NewProcess->IopmOffset;
58*c2c66affSColin Finck }
59*c2c66affSColin Finck 
60