2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/gdt.c
5 * PURPOSE: GDT managment
6 * PROGRAMMER: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
13 #include <ddk/ntddk.h>
16 #include <internal/debug.h>
18 /* GLOBALS *******************************************************************/
22 USHORT KiGdt
[(8 + NR_TASKS
) * 4] = {0x0, 0x0, 0x0, 0x0,
23 0xffff, 0x0, 0x9a00, 0xcf,
24 0xffff, 0x0, 0x9200, 0xcf,
25 0x0, 0x0, 0xfa00, 0xcc,
26 0x0, 0x0, 0xf200, 0xcc,
29 0x1000, 0x0, 0xf200, 0x0};
30 static KSPIN_LOCK GdtLock
;
32 /* FUNCTIONS *****************************************************************/
34 VOID
KeSetBaseGdtSelector(ULONG Entry
,
39 DPRINT("KeSetBaseGdtSelector(Entry %x, Base %x)\n",
42 KeAcquireSpinLock(&GdtLock
, &oldIrql
);
44 Entry
= (Entry
& (~0x3)) / 2;
46 KiGdt
[Entry
+ 1] = ((ULONG
)Base
) & 0xffff;
48 KiGdt
[Entry
+ 2] = KiGdt
[Entry
+ 2] & ~(0xff);
49 KiGdt
[Entry
+ 2] = KiGdt
[Entry
+ 2] |
50 ((((ULONG
)Base
) & 0xff0000) >> 16);
52 KiGdt
[Entry
+ 3] = KiGdt
[Entry
+ 3] & ~(0xff00);
53 KiGdt
[Entry
+ 3] = KiGdt
[Entry
+ 3] |
54 ((((ULONG
)Base
) & 0xff000000) >> 16);
56 DPRINT("%x %x %x %x\n",
62 KeReleaseSpinLock(&GdtLock
, oldIrql
);
65 VOID
KeDumpGdtSelector(ULONG Entry
)
69 VOID
KeFreeGdtSelector(ULONG Entry
)
71 * FUNCTION: Free a gdt selector
73 * Entry = Entry to free
78 DPRINT("KeFreeGdtSelector(Entry %d)\n",Entry
);
80 if (Entry
> (8 + NR_TASKS
))
82 DPRINT1("Entry too large\n");
86 KeAcquireSpinLock(&GdtLock
, &oldIrql
);
88 KiGdt
[Entry
*4 + 1] = 0;
89 KiGdt
[Entry
*4 + 2] = 0;
90 KiGdt
[Entry
*4 + 3] = 0;
91 KeReleaseSpinLock(&GdtLock
, oldIrql
);
94 ULONG
KeAllocateGdtSelector(ULONG Desc
[2])
96 * FUNCTION: Allocate a gdt selector
98 * Desc = Contents for descriptor
99 * RETURNS: The index of the entry allocated
105 DPRINT("KeAllocateGdtSelector(Desc[0] %x, Desc[1] %x)\n",
108 KeAcquireSpinLock(&GdtLock
, &oldIrql
);
109 for (i
=8; i
<(8 + NR_TASKS
); i
++)
111 if (KiGdt
[i
*4] == 0 &&
112 KiGdt
[i
*4 + 1] == 0 &&
113 KiGdt
[i
*4 + 2] == 0 &&
116 ((PULONG
)KiGdt
)[i
*2] = Desc
[0];
117 ((PULONG
)KiGdt
)[i
*2 + 1] = Desc
[1];
118 KeReleaseSpinLock(&GdtLock
, oldIrql
);
119 DPRINT("KeAllocateGdtSelector() = %x\n",i
);
123 KeReleaseSpinLock(&GdtLock
, oldIrql
);