Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenke.h
Go to the documentation of this file.
00001 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H 00002 #define __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H 00003 00004 #define X86_EFLAGS_TF 0x00000100 /* Trap flag */ 00005 #define X86_EFLAGS_IF 0x00000200 /* Interrupt Enable flag */ 00006 #define X86_EFLAGS_IOPL 0x00003000 /* I/O Privilege Level bits */ 00007 #define X86_EFLAGS_NT 0x00004000 /* Nested Task flag */ 00008 #define X86_EFLAGS_RF 0x00010000 /* Resume flag */ 00009 #define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */ 00010 #define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */ 00011 00012 #define X86_CR0_PE 0x00000001 /* enable Protected Mode */ 00013 #define X86_CR0_NE 0x00000020 /* enable native FPU error reporting */ 00014 #define X86_CR0_TS 0x00000008 /* enable exception on FPU instruction for task switch */ 00015 #define X86_CR0_EM 0x00000004 /* enable FPU emulation (disable FPU) */ 00016 #define X86_CR0_MP 0x00000002 /* enable FPU monitoring */ 00017 #define X86_CR0_WP 0x00010000 /* enable Write Protect (copy on write) */ 00018 #define X86_CR0_PG 0x80000000 /* enable Paging */ 00019 00020 #define X86_CR4_PAE 0x00000020 /* enable physical address extensions */ 00021 #define X86_CR4_PGE 0x00000080 /* enable global pages */ 00022 #define X86_CR4_OSFXSR 0x00000200 /* enable FXSAVE/FXRSTOR instructions */ 00023 #define X86_CR4_OSXMMEXCPT 0x00000400 /* enable #XF exception */ 00024 00025 #define X86_FEATURE_VME 0x00000002 /* Virtual 8086 Extensions are present */ 00026 #define X86_FEATURE_TSC 0x00000010 /* time stamp counters are present */ 00027 #define X86_FEATURE_PAE 0x00000040 /* physical address extension is present */ 00028 #define X86_FEATURE_CX8 0x00000100 /* CMPXCHG8B instruction present */ 00029 #define X86_FEATURE_SYSCALL 0x00000800 /* SYSCALL/SYSRET support present */ 00030 #define X86_FEATURE_PGE 0x00002000 /* Page Global Enable */ 00031 #define X86_FEATURE_MMX 0x00800000 /* MMX extension present */ 00032 #define X86_FEATURE_FXSR 0x01000000 /* FXSAVE/FXRSTOR instructions present */ 00033 #define X86_FEATURE_SSE 0x02000000 /* SSE extension present */ 00034 #define X86_FEATURE_SSE2 0x04000000 /* SSE2 extension present */ 00035 #define X86_FEATURE_HT 0x10000000 /* Hyper-Threading present */ 00036 00037 #define X86_EXT_FEATURE_SSE3 0x00000001 /* SSE3 extension present */ 00038 #define X86_EXT_FEATURE_3DNOW 0x40000000 /* 3DNOW! extension present */ 00039 00040 #define FRAME_EDITED 0xFFF8 00041 00042 #define X86_MSR_GSBASE 0xC0000101 00043 #define X86_MSR_KERNEL_GSBASE 0xC0000102 00044 #define X86_MSR_EFER 0xC0000080 00045 #define X86_MSR_STAR 0xC0000081 00046 #define X86_MSR_LSTAR 0xC0000082 00047 #define X86_MSR_CSTAR 0xC0000083 00048 #define X86_MSR_SFMASK 0xC0000084 00049 00050 #define EFER_SCE 0x01 00051 #define EFER_LME 0x10 00052 #define EFER_LMA 0x40 00053 #define EFER_NXE 0x80 00054 #define EFER_SVME 0x100 00055 #define EFER_FFXSR 0x400 00056 00057 #define AMD64_TSS 9 00058 00059 #define APIC_EOI_REGISTER 0xFFFFFFFFFFFE00B0ULL 00060 00061 #ifndef __ASM__ 00062 00063 #include "intrin_i.h" 00064 00065 typedef struct _KIDT_INIT 00066 { 00067 UCHAR InterruptId; 00068 UCHAR Dpl; 00069 UCHAR IstIndex; 00070 PVOID ServiceRoutine; 00071 } KIDT_INIT, *PKIDT_INIT; 00072 00073 #include <pshpack1.h> 00074 typedef struct _KI_INTERRUPT_DISPATCH_ENTRY 00075 { 00076 UCHAR _Op_nop; 00077 UCHAR _Op_push; 00078 UCHAR _Vector; 00079 UCHAR _Op_jmp; 00080 ULONG RelativeAddress; 00081 } KI_INTERRUPT_DISPATCH_ENTRY, *PKI_INTERRUPT_DISPATCH_ENTRY; 00082 #include <poppack.h> 00083 00084 extern ULONG Ke386CacheAlignment; 00085 extern ULONG KeI386NpxPresent; 00086 extern ULONG KeI386XMMIPresent; 00087 extern ULONG KeI386FxsrPresent; 00088 extern ULONG KeI386CpuType; 00089 extern ULONG KeI386CpuStep; 00090 00091 // 00092 // INT3 is 1 byte long 00093 // 00094 #define KD_BREAKPOINT_TYPE UCHAR 00095 #define KD_BREAKPOINT_SIZE sizeof(UCHAR) 00096 #define KD_BREAKPOINT_VALUE 0xCC 00097 00098 // 00099 // Macros for getting and setting special purpose registers in portable code 00100 // 00101 #define KeGetContextPc(Context) \ 00102 ((Context)->Rip) 00103 00104 #define KeSetContextPc(Context, ProgramCounter) \ 00105 ((Context)->Rip = (ProgramCounter)) 00106 00107 #define KeGetTrapFramePc(TrapFrame) \ 00108 ((TrapFrame)->Rip) 00109 00110 #define KiGetLinkedTrapFrame(x) \ 00111 (PKTRAP_FRAME)((x)->TrapFrame) 00112 00113 #define KeGetContextReturnRegister(Context) \ 00114 ((Context)->Rax) 00115 00116 #define KeSetContextReturnRegister(Context, ReturnValue) \ 00117 ((Context)->Rax = (ReturnValue)) 00118 00119 // 00120 // Macro to get trap and exception frame from a thread stack 00121 // 00122 #define KeGetTrapFrame(Thread) \ 00123 (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \ 00124 sizeof(KTRAP_FRAME)) 00125 00126 // 00127 // Macro to get context switches from the PRCB 00128 // All architectures but x86 have it in the PRCB's KeContextSwitches 00129 // 00130 #define KeGetContextSwitches(Prcb) \ 00131 (Prcb->KeContextSwitches) 00132 00133 // 00134 // Macro to get the second level cache size field name which differs between 00135 // CISC and RISC architectures, as the former has unified I/D cache 00136 // 00137 #define KiGetSecondLevelDCacheSize() ((PKIPCR)KeGetPcr())->SecondLevelCacheSize 00138 00139 #define KeGetExceptionFrame(Thread) \ 00140 (PKEXCEPTION_FRAME)((ULONG_PTR)KeGetTrapFrame(Thread) - \ 00141 sizeof(KEXCEPTION_FRAME)) 00142 00143 // 00144 // Returns the Interrupt State from a Trap Frame. 00145 // ON = TRUE, OFF = FALSE 00146 // 00147 #define KeGetTrapFrameInterruptState(TrapFrame) \ 00148 BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK) 00149 00150 /* Diable interrupts and return whether they were enabled before */ 00151 FORCEINLINE 00152 BOOLEAN 00153 KeDisableInterrupts(VOID) 00154 { 00155 ULONG_PTR Flags; 00156 00157 /* Get EFLAGS and check if the interrupt bit is set */ 00158 Flags = __readeflags(); 00159 00160 /* Disable interrupts */ 00161 _disable(); 00162 return (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE : FALSE; 00163 } 00164 00165 /* Restore previous interrupt state */ 00166 FORCEINLINE 00167 VOID 00168 KeRestoreInterrupts(BOOLEAN WereEnabled) 00169 { 00170 if (WereEnabled) _enable(); 00171 } 00172 00173 // 00174 // Invalidates the TLB entry for a specified address 00175 // 00176 FORCEINLINE 00177 VOID 00178 KeInvalidateTlbEntry(IN PVOID Address) 00179 { 00180 /* Invalidate the TLB entry for this address */ 00181 __invlpg(Address); 00182 } 00183 00184 FORCEINLINE 00185 VOID 00186 KeFlushProcessTb(VOID) 00187 { 00188 /* Flush the TLB by resetting CR3 */ 00189 __writecr3(__readcr3()); 00190 } 00191 00192 FORCEINLINE 00193 VOID 00194 KiRundownThread(IN PKTHREAD Thread) 00195 { 00196 #ifndef CONFIG_SMP 00197 DbgPrint("KiRundownThread is unimplemented\n"); 00198 #else 00199 /* Nothing to do */ 00200 #endif 00201 } 00202 00203 /* Registers an interrupt handler with an IDT vector */ 00204 FORCEINLINE 00205 VOID 00206 KeRegisterInterruptHandler(IN ULONG Vector, 00207 IN PVOID Handler) 00208 { 00209 UCHAR Entry; 00210 PKIDTENTRY64 Idt; 00211 00212 /* Get the entry from the HAL */ 00213 Entry = HalVectorToIDTEntry(Vector); 00214 00215 /* Now set the data */ 00216 Idt = &KeGetPcr()->IdtBase[Entry]; 00217 Idt->OffsetLow = (ULONG_PTR)Handler & 0xffff; 00218 Idt->OffsetMiddle = ((ULONG_PTR)Handler >> 16) & 0xffff; 00219 Idt->OffsetHigh = (ULONG_PTR)Handler >> 32; 00220 Idt->Selector = KGDT64_R0_CODE; 00221 Idt->IstIndex = 0; 00222 Idt->Type = 0x0e; 00223 Idt->Dpl = 0; 00224 Idt->Present = 1; 00225 Idt->Reserved0 = 0; 00226 Idt->Reserved1 = 0; 00227 } 00228 00229 /* Returns the registered interrupt handler for a given IDT vector */ 00230 FORCEINLINE 00231 PVOID 00232 KeQueryInterruptHandler(IN ULONG Vector) 00233 { 00234 UCHAR Entry; 00235 PKIDTENTRY64 Idt; 00236 00237 /* Get the entry from the HAL */ 00238 Entry = HalVectorToIDTEntry(Vector); 00239 00240 /* Get the IDT entry */ 00241 Idt = &KeGetPcr()->IdtBase[Entry]; 00242 00243 /* Return the address */ 00244 return (PVOID)((ULONG64)Idt->OffsetHigh << 32 | 00245 (ULONG64)Idt->OffsetMiddle << 16 | 00246 (ULONG64)Idt->OffsetLow); 00247 } 00248 00249 VOID 00250 FORCEINLINE 00251 KiSendEOI() 00252 { 00253 /* Write 0 to the apic EOI register */ 00254 *((volatile ULONG*)APIC_EOI_REGISTER) = 0; 00255 } 00256 00257 VOID 00258 FORCEINLINE 00259 KiEndInterrupt(IN KIRQL Irql, 00260 IN PKTRAP_FRAME TrapFrame) 00261 { 00262 /* Make sure this is from the clock handler */ 00263 ASSERT(TrapFrame->ErrorCode == 0xc10c4); 00264 //KeLowerIrql(Irql); 00265 } 00266 00267 BOOLEAN 00268 FORCEINLINE 00269 KiUserTrap(IN PKTRAP_FRAME TrapFrame) 00270 { 00271 /* Anything else but Ring 0 is Ring 3 */ 00272 return !!(TrapFrame->SegCs & MODE_MASK); 00273 } 00274 00275 #define Ki386PerfEnd() 00276 00277 struct _KPCR; 00278 00279 //VOID KiInitializeTss(IN PKTSS Tss, IN UINT64 Stack); 00280 00281 VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack); 00282 VOID KiDivideErrorFault(VOID); 00283 VOID KiDebugTrapOrFault(VOID); 00284 VOID KiNmiInterrupt(VOID); 00285 VOID KiBreakpointTrap(VOID); 00286 VOID KiOverflowTrap(VOID); 00287 VOID KiBoundFault(VOID); 00288 VOID KiInvalidOpcodeFault(VOID); 00289 VOID KiNpxNotAvailableFault(VOID); 00290 VOID KiDoubleFaultAbort(VOID); 00291 VOID KiNpxSegmentOverrunAbort(VOID); 00292 VOID KiInvalidTssFault(VOID); 00293 VOID KiSegmentNotPresentFault(VOID); 00294 VOID KiStackFault(VOID); 00295 VOID KiGeneralProtectionFault(VOID); 00296 VOID KiPageFault(VOID); 00297 VOID KiFloatingErrorFault(VOID); 00298 VOID KiAlignmentFault(VOID); 00299 VOID KiMcheckAbort(VOID); 00300 VOID KiXmmException(VOID); 00301 VOID KiApcInterrupt(VOID); 00302 VOID KiRaiseAssertion(VOID); 00303 VOID KiDebugServiceTrap(VOID); 00304 VOID KiDpcInterrupt(VOID); 00305 VOID KiIpiInterrupt(VOID); 00306 00307 VOID KiGdtPrepareForApplicationProcessorInit(ULONG Id); 00308 VOID Ki386InitializeLdt(VOID); 00309 VOID Ki386SetProcessorFeatures(VOID); 00310 VOID KiGetCacheInformation(VOID); 00311 VOID KiSetProcessorType(VOID); 00312 ULONG KiGetFeatureBits(VOID); 00313 VOID KiInitializeCpuFeatures(VOID); 00314 00315 ULONG KeAllocateGdtSelector(ULONG Desc[2]); 00316 VOID KeFreeGdtSelector(ULONG Entry); 00317 VOID NtEarlyInitVdm(VOID); 00318 VOID KeApplicationProcessorInitDispatcher(VOID); 00319 VOID KeCreateApplicationProcessorIdleThread(ULONG Id); 00320 00321 VOID 00322 Ke386InitThreadWithContext(PKTHREAD Thread, 00323 PKSYSTEM_ROUTINE SystemRoutine, 00324 PKSTART_ROUTINE StartRoutine, 00325 PVOID StartContext, 00326 PCONTEXT Context); 00327 #define KeArchInitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context) \ 00328 Ke386InitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context) 00329 00330 #ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */ 00331 VOID 00332 KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine, 00333 PKSTART_ROUTINE StartRoutine, 00334 PVOID StartContext, 00335 BOOLEAN UserThread, 00336 KTRAP_FRAME TrapFrame); 00337 #endif 00338 00339 #endif /* __ASM__ */ 00340 00341 // HACK 00342 extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount; 00343 00344 // win64 uses DMA macros, this one is not defined 00345 NTHALAPI 00346 NTSTATUS 00347 NTAPI 00348 HalAllocateAdapterChannel( 00349 IN PADAPTER_OBJECT AdapterObject, 00350 IN PWAIT_CONTEXT_BLOCK Wcb, 00351 IN ULONG NumberOfMapRegisters, 00352 IN PDRIVER_CONTROL ExecutionRoutine); 00353 00354 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */ 00355 00356 /* EOF */ Generated on Sun May 27 2012 04:33:22 for ReactOS by
1.7.6.1
|