Merge trunk (r43561)
[reactos.git] / reactos / ntoskrnl / include / internal / amd64 / ke.h
1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H
3
4 #define X86_EFLAGS_TF 0x00000100 /* Trap flag */
5 #define X86_EFLAGS_IF 0x00000200 /* Interrupt Enable flag */
6 #define X86_EFLAGS_IOPL 0x00003000 /* I/O Privilege Level bits */
7 #define X86_EFLAGS_NT 0x00004000 /* Nested Task flag */
8 #define X86_EFLAGS_RF 0x00010000 /* Resume flag */
9 #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
10 #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
11
12 #define X86_CR0_PE 0x00000001 /* enable Protected Mode */
13 #define X86_CR0_NE 0x00000020 /* enable native FPU error reporting */
14 #define X86_CR0_TS 0x00000008 /* enable exception on FPU instruction for task switch */
15 #define X86_CR0_EM 0x00000004 /* enable FPU emulation (disable FPU) */
16 #define X86_CR0_MP 0x00000002 /* enable FPU monitoring */
17 #define X86_CR0_WP 0x00010000 /* enable Write Protect (copy on write) */
18 #define X86_CR0_PG 0x80000000 /* enable Paging */
19
20 #define X86_CR4_PAE 0x00000020 /* enable physical address extensions */
21 #define X86_CR4_PGE 0x00000080 /* enable global pages */
22 #define X86_CR4_OSFXSR 0x00000200 /* enable FXSAVE/FXRSTOR instructions */
23 #define X86_CR4_OSXMMEXCPT 0x00000400 /* enable #XF exception */
24
25 #define X86_FEATURE_VME 0x00000002 /* Virtual 8086 Extensions are present */
26 #define X86_FEATURE_TSC 0x00000010 /* time stamp counters are present */
27 #define X86_FEATURE_PAE 0x00000040 /* physical address extension is present */
28 #define X86_FEATURE_CX8 0x00000100 /* CMPXCHG8B instruction present */
29 #define X86_FEATURE_SYSCALL 0x00000800 /* SYSCALL/SYSRET support present */
30 #define X86_FEATURE_PGE 0x00002000 /* Page Global Enable */
31 #define X86_FEATURE_MMX 0x00800000 /* MMX extension present */
32 #define X86_FEATURE_FXSR 0x01000000 /* FXSAVE/FXRSTOR instructions present */
33 #define X86_FEATURE_SSE 0x02000000 /* SSE extension present */
34 #define X86_FEATURE_SSE2 0x04000000 /* SSE2 extension present */
35 #define X86_FEATURE_HT 0x10000000 /* Hyper-Threading present */
36
37 #define X86_EXT_FEATURE_SSE3 0x00000001 /* SSE3 extension present */
38 #define X86_EXT_FEATURE_3DNOW 0x40000000 /* 3DNOW! extension present */
39
40 #define FRAME_EDITED 0xFFF8
41
42 #define X86_MSR_GSBASE 0xC0000101
43 #define X86_MSR_KERNEL_GSBASE 0xC0000102
44 #define X86_MSR_STAR 0xC0000081
45 #define X86_MSR_LSTAR 0xC0000082
46 #define X86_MSR_CSTAR 0xC0000083
47 #define X86_MSR_SFMASK 0xC0000084
48
49 #ifndef __ASM__
50
51 #include "intrin_i.h"
52
53 typedef struct _KIDT_INIT
54 {
55 UCHAR InterruptId;
56 UCHAR Dpl;
57 UCHAR IstIndex;
58 PVOID ServiceRoutine;
59 } KIDT_INIT, *PKIDT_INIT;
60
61 //#define KeArchFnInit() Ke386FnInit()
62 #define KeArchFnInit() DbgPrint("KeArchFnInit is unimplemented!\n");
63 #define KeArchHaltProcessor() Ke386HaltProcessor()
64 #define KfLowerIrql KeLowerIrql
65 #define KfAcquireSpinLock KeAcquireSpinLock
66 #define KfReleaseSpinLock KeReleaseSpinLock
67
68 extern ULONG Ke386CacheAlignment;
69
70 #define IMAGE_FILE_MACHINE_ARCHITECTURE IMAGE_FILE_MACHINE_I386
71
72 //
73 // INT3 is 1 byte long
74 //
75 #define KD_BREAKPOINT_TYPE UCHAR
76 #define KD_BREAKPOINT_SIZE sizeof(UCHAR)
77 #define KD_BREAKPOINT_VALUE 0xCC
78
79 //
80 // Macros for getting and setting special purpose registers in portable code
81 //
82 #define KeGetContextPc(Context) \
83 ((Context)->Rip)
84
85 #define KeSetContextPc(Context, ProgramCounter) \
86 ((Context)->Rip = (ProgramCounter))
87
88 #define KeGetTrapFramePc(TrapFrame) \
89 ((TrapFrame)->Rip)
90
91 #define KeGetContextReturnRegister(Context) \
92 ((Context)->Rax)
93
94 #define KeSetContextReturnRegister(Context, ReturnValue) \
95 ((Context)->Rax = (ReturnValue))
96
97 //
98 // Returns the Interrupt State from a Trap Frame.
99 // ON = TRUE, OFF = FALSE
100 //
101 #define KeGetTrapFrameInterruptState(TrapFrame) \
102 BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
103
104
105 struct _KPCR;
106 VOID
107 KiInitializeGdt(struct _KPCR* Pcr);
108 VOID
109 Ki386ApplicationProcessorInitializeTSS(VOID);
110
111 // Hack
112 VOID KiRosPrepareForSystemStartup(ULONG, PROS_LOADER_PARAMETER_BLOCK);
113
114 VOID
115 FASTCALL
116 Ki386InitializeTss(
117 IN PKTSS Tss,
118 IN PVOID GdtBase,
119 IN UINT64 Stack
120 );
121
122 VOID KiDivideErrorFault();
123 VOID KiDebugTrapOrFault();
124 VOID KiNmiInterrupt();
125 VOID KiBreakpointTrap();
126 VOID KiOverflowTrap();
127 VOID KiBoundFault();
128 VOID KiInvalidOpcodeFault();
129 VOID KiNpxNotAvailableFault();
130 VOID KiDoubleFaultAbort();
131 VOID KiNpxSegmentOverrunAbort();
132 VOID KiInvalidTssFault();
133 VOID KiSegmentNotPresentFault();
134 VOID KiStackFault();
135 VOID KiGeneralProtectionFault();
136 VOID KiPageFault();
137 VOID KiFloatingErrorFault();
138 VOID KiAlignmentFault();
139 VOID KiMcheckAbort();
140 VOID KiXmmException();
141 VOID KiApcInterrupt();
142 VOID KiRaiseAssertion();
143 VOID KiDebugServiceTrap();
144 VOID KiDpcInterrupt();
145 VOID KiIpiInterrupt();
146
147 VOID
148 KiGdtPrepareForApplicationProcessorInit(ULONG Id);
149 VOID
150 Ki386InitializeLdt(VOID);
151 VOID
152 Ki386SetProcessorFeatures(VOID);
153
154 VOID
155 NTAPI
156 KiGetCacheInformation(VOID);
157
158 BOOLEAN
159 NTAPI
160 KiIsNpxPresent(
161 VOID
162 );
163
164 BOOLEAN
165 NTAPI
166 KiIsNpxErrataPresent(
167 VOID
168 );
169
170 VOID
171 NTAPI
172 KiSetProcessorType(VOID);
173
174 ULONG
175 NTAPI
176 KiGetFeatureBits(VOID);
177
178 VOID
179 NTAPI
180 KiInitializeCpuFeatures();
181
182 ULONG KeAllocateGdtSelector(ULONG Desc[2]);
183 VOID KeFreeGdtSelector(ULONG Entry);
184 VOID
185 NtEarlyInitVdm(VOID);
186 VOID
187 KeApplicationProcessorInitDispatcher(VOID);
188 VOID
189 KeCreateApplicationProcessorIdleThread(ULONG Id);
190
191 VOID
192 NTAPI
193 Ke386InitThreadWithContext(PKTHREAD Thread,
194 PKSYSTEM_ROUTINE SystemRoutine,
195 PKSTART_ROUTINE StartRoutine,
196 PVOID StartContext,
197 PCONTEXT Context);
198 #define KeArchInitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context) \
199 Ke386InitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context)
200
201 #ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */
202 VOID
203 NTAPI
204 KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine,
205 PKSTART_ROUTINE StartRoutine,
206 PVOID StartContext,
207 BOOLEAN UserThread,
208 KTRAP_FRAME TrapFrame);
209 #endif
210
211 #endif
212 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */
213
214 /* EOF */