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 #define DR7_ACTIVE 0x00000055 /* If any of these bits are set, a Dr is active */
45 /* Possible values for KTHREAD's NpxState */
46 #define NPX_STATE_INVALID 0x01
47 #define NPX_STATE_VALID 0x02
48 #define NPX_STATE_DIRTY 0x04
50 #define FRAME_EDITED 0xFFF8
54 typedef struct _KIRQ_TRAPFRAME
72 } KIRQ_TRAPFRAME
, *PKIRQ_TRAPFRAME
;
74 /* Emulate cli/sti instructions */
75 #define KV86M_EMULATE_CLI_STI (0x1)
76 /* Allow the v86 mode code to access i/o ports */
77 #define KV86M_ALLOW_IO_PORT_ACCESS (0x2)
79 typedef struct _KV86M_REGISTERS
82 * General purpose registers
108 ULONG RecoveryAddress
;
109 UCHAR RecoveryInstruction
[4];
113 } KV86M_REGISTERS
, *PKV86M_REGISTERS
;
115 typedef struct _KV86M_TRAP_FRAME
119 ULONG SavedExceptionStack
;
122 * These are put on the top of the stack by the routine that entered
123 * v86 mode so the exception handlers can find the control information
125 struct _KV86M_REGISTERS
* regs
;
127 } KV86M_TRAP_FRAME
, *PKV86M_TRAP_FRAME
;
129 extern ULONG Ke386CacheAlignment
;
133 KiInitializeGdt(struct _KPCR
* Pcr
);
135 Ki386ApplicationProcessorInitializeTSS(VOID
);
137 Ki386BootInitializeTSS(VOID
);
139 KiGdtPrepareForApplicationProcessorInit(ULONG Id
);
141 Ki386InitializeLdt(VOID
);
143 Ki386SetProcessorFeatures(VOID
);
144 ULONG
KeAllocateGdtSelector(ULONG Desc
[2]);
145 VOID
KeFreeGdtSelector(ULONG Entry
);
147 NtEarlyInitVdm(VOID
);
149 KeApplicationProcessorInitDispatcher(VOID
);
151 KeCreateApplicationProcessorIdleThread(ULONG Id
);
155 (STDCALL
*PKSYSTEM_ROUTINE
)(PKSTART_ROUTINE StartRoutine
,
160 Ke386InitThreadWithContext(PKTHREAD Thread
,
161 PKSYSTEM_ROUTINE SystemRoutine
,
162 PKSTART_ROUTINE StartRoutine
,
166 #ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */
169 KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine
,
170 PKSTART_ROUTINE StartRoutine
,
173 KTRAP_FRAME TrapFrame
);
177 #define LOCK "lock ; "
180 #define KeGetCurrentIrql() (((PKPCR)KPCR_BASE)->Irql)
183 #if defined(__GNUC__)
184 #define Ke386DisableInterrupts() __asm__("cli\n\t");
185 #define Ke386EnableInterrupts() __asm__("sti\n\t");
186 #define Ke386HaltProcessor() __asm__("hlt\n\t");
187 #define Ke386GetPageTableDirectory(X) \
188 __asm__("movl %%cr3,%0\n\t" : "=d" (X));
189 #define Ke386SetPageTableDirectory(X) \
190 __asm__("movl %0,%%cr3\n\t" \
193 #define Ke386SetFileSelector(X) \
194 __asm__("movl %0,%%cr3\n\t" \
197 #define Ke386SetLocalDescriptorTable(X) \
198 __asm__("lldt %0\n\t" \
201 #define Ke386SetGlobalDescriptorTable(X) \
202 __asm__("lgdt %0\n\t" \
205 #define Ke386SaveFlags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
206 #define Ke386RestoreFlags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory")
208 #define _Ke386GetCr(N) ({ \
210 __asm__("movl %%cr" #N ",%0\n\t" :"=r" (__d)); \
213 #define _Ke386SetCr(N,X) __asm__ __volatile__("movl %0,%%cr" #N : :"r" (X));
215 #define Ke386GetCr0() _Ke386GetCr(0)
216 #define Ke386SetCr0(X) _Ke386SetCr(0,X)
217 #define Ke386GetCr2() _Ke386GetCr(2)
218 #define Ke386SetCr2(X) _Ke386SetCr(2,X)
219 #define Ke386GetCr4() _Ke386GetCr(4)
220 #define Ke386SetCr4(X) _Ke386SetCr(4,X)
222 static inline LONG
Ke386TestAndClearBit(ULONG BitPos
, volatile PULONG Addr
)
226 __asm__
__volatile__(LOCK
229 :"=r" (OldBit
),"=m" (*Addr
)
235 static inline LONG
Ke386TestAndSetBit(ULONG BitPos
, volatile PULONG Addr
)
239 __asm__
__volatile__(LOCK
242 :"=r" (OldBit
),"=m" (*Addr
)
249 static inline void Ki386Cpuid(ULONG Op
, PULONG Eax
, PULONG Ebx
, PULONG Ecx
, PULONG Edx
)
252 : "=a" (*Eax
), "=b" (*Ebx
), "=c" (*Ecx
), "=d" (*Edx
)
256 #define Ke386Rdmsr(msr,val1,val2) __asm__ __volatile__("rdmsr" : "=a" (val1), "=d" (val2) : "c" (msr))
258 #define Ke386Wrmsr(msr,val1,val2) __asm__ __volatile__("wrmsr" : /* no outputs */ : "c" (msr), "a" (val1), "d" (val2))
261 #elif defined(_MSC_VER)
263 #define Ke386DisableInterrupts() __asm cli
264 #define Ke386EnableInterrupts() __asm sti
265 #define Ke386HaltProcessor() __asm hlt
266 #define Ke386GetPageTableDirectory(X) \
267 __asm mov eax, cr3; \
269 static __forceinline
void Ke386SetPageTableDirectory(ULONG X
)
275 #error Unknown compiler for inline assembler
279 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */