1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H
5 #pragma GCC system_header
8 #define X86_EFLAGS_TF 0x00000100 /* Trap flag */
9 #define X86_EFLAGS_IF 0x00000200 /* Interrupt Enable flag */
10 #define X86_EFLAGS_IOPL 0x00003000 /* I/O Privilege Level bits */
11 #define X86_EFLAGS_NT 0x00004000 /* Nested Task flag */
12 #define X86_EFLAGS_RF 0x00010000 /* Resume flag */
13 #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
14 #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
16 #define X86_CR0_PE 0x00000001 /* enable Protected Mode */
17 #define X86_CR0_NE 0x00000020 /* enable native FPU error reporting */
18 #define X86_CR0_TS 0x00000008 /* enable exception on FPU instruction for task switch */
19 #define X86_CR0_EM 0x00000004 /* enable FPU emulation (disable FPU) */
20 #define X86_CR0_MP 0x00000002 /* enable FPU monitoring */
21 #define X86_CR0_WP 0x00010000 /* enable Write Protect (copy on write) */
22 #define X86_CR0_PG 0x80000000 /* enable Paging */
24 #define X86_CR4_PAE 0x00000020 /* enable physical address extensions */
25 #define X86_CR4_PGE 0x00000080 /* enable global pages */
26 #define X86_CR4_OSFXSR 0x00000200 /* enable FXSAVE/FXRSTOR instructions */
27 #define X86_CR4_OSXMMEXCPT 0x00000400 /* enable #XF exception */
29 #define X86_FEATURE_TSC 0x00000010 /* time stamp counters are present */
30 #define X86_FEATURE_PAE 0x00000040 /* physical address extension is present */
31 #define X86_FEATURE_CX8 0x00000100 /* CMPXCHG8B instruction present */
32 #define X86_FEATURE_SYSCALL 0x00000800 /* SYSCALL/SYSRET support present */
33 #define X86_FEATURE_PGE 0x00002000 /* Page Global Enable */
34 #define X86_FEATURE_MMX 0x00800000 /* MMX extension present */
35 #define X86_FEATURE_FXSR 0x01000000 /* FXSAVE/FXRSTOR instructions present */
36 #define X86_FEATURE_SSE 0x02000000 /* SSE extension present */
37 #define X86_FEATURE_SSE2 0x04000000 /* SSE2 extension present */
38 #define X86_FEATURE_HT 0x10000000 /* Hyper-Threading present */
40 #define X86_EXT_FEATURE_SSE3 0x00000001 /* SSE3 extension present */
41 #define X86_EXT_FEATURE_3DNOW 0x40000000 /* 3DNOW! extension present */
43 /* Possible values for KTHREAD's NpxState */
44 #define NPX_STATE_INVALID 0x01
45 #define NPX_STATE_VALID 0x02
46 #define NPX_STATE_DIRTY 0x04
50 typedef struct _KIRQ_TRAPFRAME
68 } KIRQ_TRAPFRAME
, *PKIRQ_TRAPFRAME
;
70 extern ULONG Ke386CacheAlignment
;
74 KiInitializeGdt(struct _KPCR
* Pcr
);
76 Ki386ApplicationProcessorInitializeTSS(VOID
);
78 Ki386BootInitializeTSS(VOID
);
80 KiGdtPrepareForApplicationProcessorInit(ULONG Id
);
82 Ki386InitializeLdt(VOID
);
84 Ki386SetProcessorFeatures(VOID
);
85 ULONG
KeAllocateGdtSelector(ULONG Desc
[2]);
86 VOID
KeFreeGdtSelector(ULONG Entry
);
90 KeApplicationProcessorInitDispatcher(VOID
);
92 KeCreateApplicationProcessorIdleThread(ULONG Id
);
96 (STDCALL
*PKSYSTEM_ROUTINE
)(PKSTART_ROUTINE StartRoutine
,
101 Ke386InitThreadWithContext(PKTHREAD Thread
,
102 PKSYSTEM_ROUTINE SystemRoutine
,
103 PKSTART_ROUTINE StartRoutine
,
107 #ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */
110 KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine
,
111 PKSTART_ROUTINE StartRoutine
,
114 KTRAP_FRAME TrapFrame
);
118 #define LOCK "lock ; "
121 #define KeGetCurrentIrql() (((PKPCR)KPCR_BASE)->Irql)
124 #if defined(__GNUC__)
125 #define Ke386DisableInterrupts() __asm__("cli\n\t");
126 #define Ke386EnableInterrupts() __asm__("sti\n\t");
127 #define Ke386HaltProcessor() __asm__("hlt\n\t");
128 #define Ke386GetPageTableDirectory(X) \
129 __asm__("movl %%cr3,%0\n\t" : "=d" (X));
130 #define Ke386SetPageTableDirectory(X) \
131 __asm__("movl %0,%%cr3\n\t" \
134 #define Ke386SetFileSelector(X) \
135 __asm__("movl %0,%%cr3\n\t" \
138 #define Ke386SetLocalDescriptorTable(X) \
139 __asm__("lldt %0\n\t" \
142 #define Ke386SetGlobalDescriptorTable(X) \
143 __asm__("lgdt %0\n\t" \
146 #define Ke386SaveFlags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
147 #define Ke386RestoreFlags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory")
149 #define _Ke386GetCr(N) ({ \
151 __asm__("movl %%cr" #N ",%0\n\t" :"=r" (__d)); \
154 #define _Ke386SetCr(N,X) __asm__ __volatile__("movl %0,%%cr" #N : :"r" (X));
156 #define Ke386GetCr0() _Ke386GetCr(0)
157 #define Ke386SetCr0(X) _Ke386SetCr(0,X)
158 #define Ke386GetCr2() _Ke386GetCr(2)
159 #define Ke386SetCr2(X) _Ke386SetCr(2,X)
160 #define Ke386GetCr4() _Ke386GetCr(4)
161 #define Ke386SetCr4(X) _Ke386SetCr(4,X)
163 static inline LONG
Ke386TestAndClearBit(ULONG BitPos
, volatile PULONG Addr
)
167 __asm__
__volatile__(LOCK
170 :"=r" (OldBit
),"=m" (*Addr
)
176 static inline LONG
Ke386TestAndSetBit(ULONG BitPos
, volatile PULONG Addr
)
180 __asm__
__volatile__(LOCK
183 :"=r" (OldBit
),"=m" (*Addr
)
190 static inline void Ki386Cpuid(ULONG Op
, PULONG Eax
, PULONG Ebx
, PULONG Ecx
, PULONG Edx
)
193 : "=a" (*Eax
), "=b" (*Ebx
), "=c" (*Ecx
), "=d" (*Edx
)
197 #define Ke386Rdmsr(msr,val1,val2) __asm__ __volatile__("rdmsr" : "=a" (val1), "=d" (val2) : "c" (msr))
199 #define Ke386Wrmsr(msr,val1,val2) __asm__ __volatile__("wrmsr" : /* no outputs */ : "c" (msr), "a" (val1), "d" (val2))
202 #elif defined(_MSC_VER)
204 #define Ke386DisableInterrupts() __asm cli
205 #define Ke386EnableInterrupts() __asm sti
206 #define Ke386HaltProcessor() __asm hlt
207 #define Ke386GetPageTableDirectory(X) \
208 __asm mov eax, cr3; \
210 #define Ke386SetPageTableDirectory(X) \
214 #error Unknown compiler for inline assembler
218 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */