ReactOS 0.4.17-dev-683-g0dafdc5
ke.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __ASM__
4
5#include "intrin_i.h"
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12//
13// Thread Dispatcher Header DebugActive Mask
14//
15#define DR_MASK(x) (1 << (x))
16#define DR_REG_MASK 0x4F
17
18//
19// INT3 is 1 byte long
20//
21#define KD_BREAKPOINT_TYPE UCHAR
22#define KD_BREAKPOINT_SIZE sizeof(UCHAR)
23#define KD_BREAKPOINT_VALUE 0xCC
24
25/* CPUID 1 - ECX flags */
26#define X86_FEATURE_SSE3 0x00000001
27#define X86_FEATURE_SSSE3 0x00000200
28#define X86_FEATURE_SSE4_1 0x00080000
29#define X86_FEATURE_SSE4_2 0x00100000
30#define X86_FEATURE_XSAVE 0x04000000
31#define X86_FEATURE_RDRAND 0x40000000
32
33/* CPUID 1 - EDX flags */
34#define X86_FEATURE_FPU 0x00000001 /* x87 FPU is present */
35#define X86_FEATURE_VME 0x00000002 /* Virtual 8086 Extensions are present */
36#define X86_FEATURE_DBG 0x00000004 /* Debugging extensions are present */
37#define X86_FEATURE_PSE 0x00000008 /* Page Size Extension is present */
38#define X86_FEATURE_TSC 0x00000010 /* Time Stamp Counters are present */
39#define X86_FEATURE_PAE 0x00000040 /* Physical Address Extension is present */
40#define X86_FEATURE_CX8 0x00000100 /* CMPXCHG8B instruction present */
41#define X86_FEATURE_APIC 0x00000200 /* APIC is present */
42#define X86_FEATURE_SYSCALL 0x00000800 /* SYSCALL/SYSRET support present */
43#define X86_FEATURE_MTRR 0x00001000 /* Memory type range registers are present */
44#define X86_FEATURE_PGE 0x00002000 /* Page Global Enable */
45#define X86_FEATURE_CMOV 0x00008000 /* "Conditional move" instruction supported */
46#define X86_FEATURE_PAT 0x00010000 /* Page Attribute Table is supported */
47#define X86_FEATURE_DS 0x00200000 /* Debug Store is present */
48#define X86_FEATURE_MMX 0x00800000 /* MMX extension present */
49#define X86_FEATURE_FXSR 0x01000000 /* FXSAVE/FXRSTOR instructions present */
50#define X86_FEATURE_SSE 0x02000000 /* SSE extension present */
51#define X86_FEATURE_SSE2 0x04000000 /* SSE2 extension present */
52#define X86_FEATURE_HT 0x10000000 /* Hyper-Threading present */
53
54/* CPUID 0x80000001 - EDX extended flags */
55#define X86_FEATURE_NX 0x00100000 /* NX support present */
56
57//
58// One-liners for getting and setting special purpose registers in portable code
59//
63{
64 return Context->Eip;
65}
66
68VOID
70{
71 Context->Eip = ProgramCounter;
72}
73
77{
78 return Context->Eax;
79}
80
82VOID
84{
85 Context->Eax = ReturnValue;
86}
87
91{
92 return Context->Ebp;
93}
94
96VOID
98{
99 Context->Ebp = Frame;
100}
101
105{
106 return TrapFrame->Eip;
107}
108
112{
113 return (PKTRAP_FRAME)TrapFrame->Edx;
114}
115
116
120{
121 if (TrapFrame->PreviousPreviousMode == KernelMode)
122 return TrapFrame->TempEsp;
123 return TrapFrame->HardwareEsp;
124}
125
129{
130 return TrapFrame->Ebp;
131}
132
136{
137 /* Read the time stamp counter */
138 return __rdtsc();
139}
140
141//
142// Macro to get trap and exception frame from a thread stack
143//
144#define KeGetTrapFrame(Thread) \
145 (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
146 sizeof(KTRAP_FRAME) - \
147 sizeof(FX_SAVE_AREA))
148
149#define KeGetExceptionFrame(Thread) \
150 NULL
151
152//
153// Macro to get context switches from the PRCB
154// All architectures but x86 have it in the PRCB's KeContextSwitches
155//
156#define KeGetContextSwitches(Prcb) \
157 CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches
158
159//
160// Macro to get the second level cache size field name which differs between
161// CISC and RISC architectures, as the former has unified I/D cache
162//
163#define KiGetSecondLevelDCacheSize() ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
164
165//
166// Returns the Interrupt State from a Trap Frame.
167// ON = TRUE, OFF = FALSE
168//
169#define KeGetTrapFrameInterruptState(TrapFrame) \
170 BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
171
172//
173// Flags for exiting a trap
174//
175#define KTE_SKIP_PM_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipPreviousMode = TRUE } }).Bits)
176#define KTE_SKIP_SEG_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipSegments = TRUE } }).Bits)
177#define KTE_SKIP_VOL_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipVolatiles = TRUE } }).Bits)
178
180{
181 struct
182 {
187 };
190
191
192//
193// Flags used by the VDM/V8086 emulation engine for determining instruction prefixes
194//
195#define PFX_FLAG_ES 0x00000100
196#define PFX_FLAG_CS 0x00000200
197#define PFX_FLAG_SS 0x00000400
198#define PFX_FLAG_DS 0x00000800
199#define PFX_FLAG_FS 0x00001000
200#define PFX_FLAG_GS 0x00002000
201#define PFX_FLAG_OPER32 0x00004000
202#define PFX_FLAG_ADDR32 0x00008000
203#define PFX_FLAG_LOCK 0x00010000
204#define PFX_FLAG_REPNE 0x00020000
205#define PFX_FLAG_REP 0x00040000
206
207//
208// VDM State Pointer
209//
210extern const PULONG KiNtVdmState;
211
212//
213// VDM Helper Macros
214//
215// All VDM/V8086 opcode emulators have the same FASTCALL function definition.
216// We need to keep 2 parameters while the original ASM implementation uses 4:
217// TrapFrame, PrefixFlags, Eip, InstructionSize;
218//
219// We pass the trap frame, and prefix flags, in our two parameters.
220//
221// We then realize that since the smallest prefix flag is 0x100, this gives us
222// a count of up to 0xFF. So we OR in the instruction size with the prefix flags
223//
224// We further realize that we always have access to EIP from the trap frame, and
225// that if we want the *current instruction* EIP, we simply have to add the
226// instruction size *MINUS ONE*, and that gives us the EIP we should be looking
227// at now, so we don't need to use the stack to push this parameter.
228//
229// We actually only care about the *current instruction* EIP in one location,
230// so although it may be slightly more expensive to re-calculate the EIP one
231// more time, this way we don't redefine ALL opcode handlers to have 3 parameters,
232// which would be forcing stack usage in all other scenarios.
233//
234#ifdef __GNUC__
235#pragma GCC diagnostic push
236#pragma GCC diagnostic ignored "-Wstringop-overflow"
237#endif
239{
240 return InterlockedOr((PLONG)KiNtVdmState, EFlags);
241}
243{
244 return InterlockedAnd((PLONG)KiNtVdmState, ~EFlags);
245}
246#ifdef __GNUC__
247#pragma GCC diagnostic pop
248#endif
249
250#define KiCallVdmHandler(x) KiVdmOpcode##x(TrapFrame, Flags)
251#define KiCallVdmPrefixHandler(x) KiVdmOpcodePrefix(TrapFrame, Flags | x)
252#define KiVdmUnhandledOpcode(x) \
253 BOOLEAN \
254 FASTCALL \
255 KiVdmOpcode##x(IN PKTRAP_FRAME TrapFrame, \
256 IN ULONG Flags) \
257 { \
258 /* Not yet handled */ \
259 UNIMPLEMENTED_DBGBREAK(); \
260 return FALSE; \
261 }
262
264
265//
266// Local parameters
267//
268typedef struct _KV86_FRAME
269{
274
275//
276// Virtual Stack Frame
277//
279{
284
285//
286// Large Pages Support
287//
289{
296
297//
298// Floating Point Internal Context Structure
299//
301{
307
308/* Diable interrupts and return whether they were enabled before */
312{
313 ULONG Flags;
314 BOOLEAN Return;
315
316 /* Get EFLAGS and check if the interrupt bit is set */
318 Return = (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
319
320 /* Disable interrupts */
321 _disable();
322 return Return;
323}
324
325/* Restore previous interrupt state */
327VOID
329{
330 if (WereEnabled) _enable();
331}
332
333//
334// Registers an interrupt handler with an IDT vector
335//
337VOID
340{
341 UCHAR Entry;
343 PKIPCR Pcr = (PKIPCR)KeGetPcr();
344
345 //
346 // Get the entry from the HAL
347 //
350
351 //
352 // Now set the data
353 //
354 Pcr->IDT[Entry].ExtendedOffset = (USHORT)(Address >> 16);
355 Pcr->IDT[Entry].Offset = (USHORT)Address;
356}
357
358//
359// Returns the registered interrupt handler for a given IDT vector
360//
362PVOID
364{
365 PKIPCR Pcr = (PKIPCR)KeGetPcr();
366 UCHAR Entry;
367
368 //
369 // Get the entry from the HAL
370 //
372
373 //
374 // Read the entry from the IDT
375 //
376 return (PVOID)(((Pcr->IDT[Entry].ExtendedOffset << 16) & 0xFFFF0000) |
377 (Pcr->IDT[Entry].Offset & 0xFFFF));
378}
379
380//
381// Invalidates the TLB entry for a specified address
382//
384VOID
386{
387 /* Invalidate the TLB entry for this address */
389}
390
392VOID
394{
395 /* Flush the TLB by resetting CR3 */
397}
398
400VOID
402 IN SIZE_T FlushSize)
403{
404 //
405 // Always sweep the whole cache
406 //
408 UNREFERENCED_PARAMETER(FlushSize);
409 __wbinvd();
410}
411
415{
416 /* Return the current thread */
417 return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
418}
419
421VOID
423{
424 /* Check if this is the NPX Thread */
425 if (KeGetCurrentPrcb()->NpxThread == Thread)
426 {
427 /* Clear it */
428 KeGetCurrentPrcb()->NpxThread = NULL;
429 Ke386FnInit();
430 }
431}
432
433CODE_SEG("INIT")
434VOID
435NTAPI
436KiInitializePcr(IN ULONG ProcessorNumber,
437 IN PKIPCR Pcr,
438 IN PKIDTENTRY Idt,
439 IN PKGDTENTRY Gdt,
440 IN PKTSS Tss,
441 IN PKTHREAD IdleThread,
442 IN PVOID DpcStack);
443
445VOID
447{
448 GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
449 GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
450 GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
451}
452
454VOID
455KiSetTebBase(PKPCR Pcr, PNT_TIB TebAddress)
456{
457 Pcr->NtTib.Self = TebAddress;
458 Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
459}
460
461CODE_SEG("INIT")
462VOID
465 IN PKTSS Tss,
466 IN PKIDTENTRY Idt,
467 IN PKGDTENTRY Gdt
468);
469
470CODE_SEG("INIT")
471VOID
472NTAPI
474
475CODE_SEG("INIT")
476VOID
477NTAPI
479
480CODE_SEG("INIT")
482NTAPI
484 VOID
485);
486
487CODE_SEG("INIT")
489NTAPI
491 VOID
492);
493
494CODE_SEG("INIT")
495VOID
496NTAPI
498
499CODE_SEG("INIT")
501NTAPI
503
504#if DBG
505CODE_SEG("INIT")
506VOID
507KiReportCpuFeatures(VOID);
508#endif
509
510VOID
511NTAPI
513
515NTAPI
520);
521
522VOID
523NTAPI
525 IN FLOATING_SAVE_AREA *SaveArea
526);
527
528VOID
529NTAPI
531 IN PKTRAP_FRAME TrapFrame
532);
533
534VOID
535NTAPI
537 OUT PTEB VdmTeb
538);
539
540CODE_SEG("INIT")
541VOID
542NTAPI
544 VOID
545);
546
547CODE_SEG("INIT")
549NTAPI
552);
553
554CODE_SEG("INIT")
556NTAPI
559);
560
562NTAPI
564 IN PLARGE_IDENTITY_MAP IdentityMap,
565 IN PVOID StartPtr,
567);
568
569VOID
570NTAPI
572 IN PLARGE_IDENTITY_MAP IdentityMap
573);
574
575VOID
576NTAPI
578 IN ULONG_PTR StartAddress,
579 IN ULONG Cr3
580);
581
582CODE_SEG("INIT")
583VOID
584NTAPI
586 VOID
587);
588
589CODE_SEG("INIT")
590VOID
591NTAPI
593 VOID
594);
595
596CODE_SEG("INIT")
597VOID
598NTAPI
600 IN BOOLEAN FinalCpu
601);
602
603CODE_SEG("INIT")
604VOID
605NTAPI
607 VOID
608);
609
610CODE_SEG("INIT")
611VOID
612NTAPI
614 VOID
615);
616
617CODE_SEG("INIT")
619NTAPI
622);
623
624CODE_SEG("INIT")
626NTAPI
629);
630
631CODE_SEG("INIT")
633NTAPI
636);
637
639NTAPI
641 IN PKTRAP_FRAME TrapFrame
642);
643
645NTAPI
647 _In_ PKTRAP_FRAME TrapFrame
648);
649
653 IN PKTRAP_FRAME TrapFrame,
655);
656
660 IN PKTRAP_FRAME TrapFrame
661);
662
664VOID
667 IN PKTRAP_FRAME TrapFrame
668);
669
670VOID
673 IN PKTRAP_FRAME TrapFrame
674);
675
679 IN PKTRAP_FRAME TrapFrame
680);
681
683VOID
684NTAPI
687 IN ULONG Flags,
689 IN ULONG ParameterCount,
690 IN ULONG_PTR Parameter1,
691 IN ULONG_PTR Parameter2,
692 IN ULONG_PTR Parameter3,
693 IN PKTRAP_FRAME TrapFrame
694);
695
697NTAPI
699 VOID
700);
701
703VOID
706 IN PKTRAP_FRAME TrapFrame,
708);
709
711VOID
714 IN PKTRAP_FRAME TrapFrame
715);
716
719VOID
721 _In_ PKTRAP_FRAME TrapFrame,
722 _In_ PKEXCEPTION_FRAME ExceptionFrame)
723{
724 KiServiceExit2(TrapFrame);
725}
726
727//
728// Global x86 only Kernel data
729//
740extern ULONG KiMXCsrMask;
741extern ULONG KeI386CpuType;
742extern ULONG KeI386CpuStep;
756extern CHAR KiSystemCallExit[];
757extern CHAR KiSystemCallExit2[];
758
759//
760// Trap Macros
761//
762#include "trap_x.h"
763
764//
765// Returns a thread's FPU save area
766//
770{
771 ASSERT((ULONG_PTR)Thread->InitialStack % 16 == 0);
772 return (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof(FX_SAVE_AREA));
773}
774
775//
776// Sanitizes a selector
777//
779ULONG
782{
783 //
784 // Check if we're in kernel-mode, and force CPL 0 if so.
785 // Otherwise, force CPL 3.
786 //
787 return ((Mode == KernelMode) ?
788 (Cs & (0xFFFF & ~RPL_MASK)) :
789 (RPL_MASK | (Cs & 0xFFFF)));
790}
791
792//
793// Sanitizes EFLAGS
794//
796ULONG
799{
800 //
801 // Check if we're in kernel-mode, and sanitize EFLAGS if so.
802 // Otherwise, also force interrupt mask on.
803 //
804 return ((Mode == KernelMode) ?
807}
808
809//
810// Sanitizes a Debug Register
811//
813PVOID
816{
817 //
818 // Check if we're in kernel-mode, and return the address directly if so.
819 // Otherwise, make sure it's not inside the kernel-mode address space.
820 // If it is, then clear the address.
821 //
822 return ((Mode == KernelMode) ? DrAddress :
823 (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0);
824}
825
826//
827// Exception with no arguments
828//
831VOID
834 IN PKTRAP_FRAME TrapFrame)
835{
836 /* Helper for exceptions with no arguments */
837 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 0, 0, 0, 0, TrapFrame);
838}
839
840//
841// Exception with one argument
842//
845VOID
848 IN ULONG P1,
849 IN PKTRAP_FRAME TrapFrame)
850{
851 /* Helper for exceptions with no arguments */
852 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 1, P1, 0, 0, TrapFrame);
853}
854
855//
856// Exception with two arguments
857//
860VOID
863 IN ULONG P1,
864 IN ULONG P2,
865 IN PKTRAP_FRAME TrapFrame)
866{
867 /* Helper for exceptions with no arguments */
868 KiDispatchExceptionFromTrapFrame(Code, 0, Address, 2, P1, P2, 0, TrapFrame);
869}
870
871//
872// Performs a system call
873//
875NTAPI
877 _In_ PVOID Arguments,
878 _In_ ULONG StackBytes);
879
880
881//
882// Checks for pending APCs
883//
885VOID
887{
890
891 /* Check for V8086 or user-mode trap */
892 if ((TrapFrame->EFlags & EFLAGS_V86_MASK) || (KiUserTrap(TrapFrame)))
893 {
894 /* Get the thread */
896 while (TRUE)
897 {
898 /* Turn off the alerted state for kernel mode */
899 Thread->Alerted[KernelMode] = FALSE;
900
901 /* Are there pending user APCs? */
902 if (!Thread->ApcState.UserApcPending) break;
903
904 /* Raise to APC level and enable interrupts */
906 _enable();
907
908 /* Deliver APCs */
909 KiDeliverApc(UserMode, NULL, TrapFrame);
910
911 /* Restore IRQL and disable interrupts once again */
913 _disable();
914 }
915 }
916}
917
918//
919// Switches from boot loader to initial kernel stack
920//
921CODE_SEG("INIT")
924VOID
926{
928
929 /* We have to switch to a new stack before continuing kernel initialization */
930#ifdef __GNUC__
931 __asm__
932 (
933 "movl %0, %%esp\n\t"
934 "subl %1, %%esp\n\t"
935 "pushl %2\n\t"
936 "jmp _KiSystemStartupBootStack@0"
937 :
938 : "c"(InitialStack),
940 "i"(CR0_EM | CR0_TS | CR0_MP),
942 : "%esp"
943 );
944#elif defined(_MSC_VER)
945 __asm
946 {
947 mov esp, InitialStack
951 }
952#else
953#error Unknown Compiler
954#endif
955
957}
958
959//
960// Emits the iret instruction for C code
961//
964VOID
966{
967#if defined(__GNUC__)
968 __asm__ __volatile__
969 (
970 "iret"
971 );
972#elif defined(_MSC_VER)
973 __asm
974 {
975 iretd
976 }
977#else
978#error Unsupported compiler
979#endif
981}
982
983//
984// Normally this is done by the HAL, but on x86 as an optimization, the kernel
985// initiates the end by calling back into the HAL and exiting the trap here.
986//
988VOID
990 IN PKTRAP_FRAME TrapFrame)
991{
992 /* Disable interrupts and end the interrupt */
993 _disable();
994 HalEndSystemInterrupt(Irql, TrapFrame);
995
996 /* Exit the interrupt */
997 KiEoiHelper(TrapFrame);
998}
999
1000//
1001// PERF Code
1002//
1004VOID
1006{
1009 DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
1010 DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
1011 KeGetCurrentPrcb()->InterruptCount,
1012 KeGetCurrentPrcb()->KeSystemCalls,
1014}
1015
1017PULONG
1019{
1020 return &(KeGetCurrentThread()->TrapFrame->HardwareEsp);
1021}
1022
1023#ifdef __cplusplus
1024} // extern "C"
1025#endif
1026
1027#endif
#define CODE_SEG(...)
#define EFLAGS_INTERRUPT_MASK
#define KGDT_R3_TEB
#define RPL_MASK
UINT32 void void ** ReturnValue
Definition: acevents.h:216
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:672
unsigned char BOOLEAN
Definition: actypes.h:127
DECLSPEC_NORETURN VOID NTAPI KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:142
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
LONG NTSTATUS
Definition: precomp.h:26
_Out_ PKIRQL Irql
Definition: csq.h:179
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define __cdecl
Definition: corecrt.h:121
#define DECLSPEC_NORETURN
Definition: corecrt.h:131
#define ULONG_PTR
Definition: config.h:101
#define PtrToUlong(u)
Definition: config.h:107
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define APC_LEVEL
Definition: env_spec_w32.h:695
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Status
Definition: gdiplustypes.h:24
VOID NTAPI HalEndSystemInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
Definition: pic.c:335
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
#define DbgPrint
Definition: hal.h:12
#define KeGetCurrentThread
Definition: hal.h:55
_In_ ULONG Mode
Definition: hubbusif.h:303
#define InterlockedOr
Definition: interlocked.h:239
#define InterlockedAnd
Definition: interlocked.h:77
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1850
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1706
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:2000
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1826
#define C_ASSERT(e)
Definition: intsafe.h:73
#define ASSERT(a)
Definition: mode.c:44
unsigned __int64 ULONG64
Definition: imports.h:198
#define EFLAGS_USER_SANITIZE
Definition: ketypes.h:212
#define EFLAGS_V86_MASK
Definition: ketypes.h:207
#define CR0_MP
Definition: ketypes.h:140
#define CR0_EM
Definition: ketypes.h:141
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1197
struct _KIPCR * PKIPCR
#define MAXIMUM_IDTVECTOR
Definition: ketypes.h:352
#define CR0_TS
Definition: ketypes.h:142
#define HalVectorToIDTEntry
Definition: halfuncs.h:54
#define KernelMode
Definition: asm.h:38
#define NPX_FRAME_LENGTH
Definition: asm.h:247
#define UserMode
Definition: asm.h:39
#define KTRAP_FRAME_LENGTH
Definition: asm.h:316
#define KTRAP_FRAME_ALIGN
Definition: asm.h:317
#define KeGetPcr()
Definition: ketypes.h:81
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
#define _In_
Definition: no_sal2.h:158
#define FASTCALL
Definition: nt_native.h:50
#define UNREACHABLE
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:202
DECLSPEC_NORETURN VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack)
Definition: ke.h:925
ULONG KeI386NpxPresent
Definition: cpu.c:28
#define KeGetContextSwitches(Prcb)
Definition: ke.h:226
FORCEINLINE ULONG_PTR KeGetContextFrameRegister(PCONTEXT Context)
Definition: ke.h:167
ULONG KeI386XMMIPresent
Definition: cpu.c:32
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:274
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:282
FORCEINLINE VOID KeSetContextFrameRegister(PCONTEXT Context, ULONG_PTR Frame)
Definition: ke.h:174
DECLSPEC_NORETURN VOID KiExceptionExit(_In_ PKTRAP_FRAME TrapFrame, _In_ PKEXCEPTION_FRAME ExceptionFrame)
Definition: ke.h:720
FORCEINLINE ULONG64 KxQueryProcessorCycleTime(VOID)
Definition: ke.h:209
FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:195
VOID KiGetCacheInformation(VOID)
Definition: cpu.c:334
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:249
ULONG64 KiGetFeatureBits(VOID)
Evaluates the KeFeatureFlag bits for the current CPU.
Definition: cpu.c:73
FORCEINLINE PVOID KeQueryInterruptHandler(IN ULONG Vector)
Definition: ke.h:337
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:264
ULONG KeI386CpuType
Definition: cpu.c:25
VOID KiSetProcessorType(VOID)
Definition: cpu.c:40
FORCEINLINE VOID KiRundownThread(IN PKTHREAD Thread)
Definition: ke.h:303
ULONG KeI386FxsrPresent
Definition: cpu.c:33
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:377
FORCEINLINE VOID KeSweepICache(IN PVOID BaseAddress, IN SIZE_T FlushSize)
Definition: ke.h:290
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:311
FORCEINLINE PULONG_PTR KiGetUserModeStackAddress(void)
Definition: ke.h:479
ULONG KeI386CpuStep
Definition: cpu.c:26
#define KeSetContextReturnRegister(Context, ReturnValue)
Definition: ke.h:43
#define Ki386PerfEnd()
Definition: ke.h:174
#define KiGetLinkedTrapFrame(x)
Definition: ke.h:177
#define KeSetContextPc(Context, ProgramCounter)
Definition: ke.h:34
#define KiServiceExit2
Definition: ke.h:5
#define KeGetContextPc(Context)
Definition: ke.h:31
#define KeGetContextReturnRegister(Context)
Definition: ke.h:40
#define KeGetTrapFramePc(TrapFrame)
Definition: ke.h:37
#define KiEndInterrupt(x, y)
Definition: ke.h:175
struct _LARGE_IDENTITY_MAP LARGE_IDENTITY_MAP
BOOLEAN NTAPI VdmDispatchPageFault(_In_ PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:367
PVOID Ki386IopmSaveArea
Definition: v86vdm.c:23
BOOLEAN NTAPI VdmDispatchBop(IN PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:313
FORCEINLINE ULONG KiVdmClearVdmEFlags(ULONG EFlags)
Definition: ke.h:242
FORCEINLINE ULONG Ke386SanitizeFlags(IN ULONG Eflags, IN KPROCESSOR_MODE Mode)
Definition: ke.h:797
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException2Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN ULONG P2, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:861
VOID NTAPI KiInitializePAT(VOID)
Definition: patpge.c:61
VOID NTAPI ExpInterlockedPopEntrySListResume(VOID)
BOOLEAN FASTCALL KiVdmOpcodePrefix(IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
Definition: v86vdm.c:456
DECLSPEC_NORETURN VOID NTAPI KiDispatchExceptionFromTrapFrame(IN NTSTATUS Code, IN ULONG Flags, IN ULONG_PTR Address, IN ULONG ParameterCount, IN ULONG_PTR Parameter1, IN ULONG_PTR Parameter2, IN ULONG_PTR Parameter3, IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:1055
VOID FASTCALL Ki386InitializeTss(IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
Definition: cpu.c:729
ULONG KeI386MachineType
Definition: cpu.c:27
BOOLEAN FASTCALL Ki386HandleOpcodeV86(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:470
ULONG_PTR NTAPI Ki386EnableTargetLargePage(IN ULONG_PTR Context)
Definition: patpge.c:70
VOID NTAPI KiFlushNPXState(IN FLOATING_SAVE_AREA *SaveArea)
ULONG KiFastSystemCallDisable
Definition: cpu.c:28
struct _KV86_FRAME KV86_FRAME
VOID __cdecl KiTrap13(VOID)
UCHAR KiDebugRegisterContextOffsets[9]
VOID __cdecl KiTrap02(VOID)
UCHAR KiDebugRegisterTrapOffsets[9]
VOID __cdecl KiTrap08(VOID)
FORCEINLINE ULONG KiVdmSetVdmEFlags(ULONG EFlags)
Definition: ke.h:238
struct _KV8086_STACK_FRAME KV8086_STACK_FRAME
union _KTRAP_EXIT_SKIP_BITS * PKTRAP_EXIT_SKIP_BITS
BOOLEAN KeI386VirtualIntExtensions
Definition: v86vdm.c:24
struct _LARGE_IDENTITY_MAP * PLARGE_IDENTITY_MAP
ULONG KeI386EFlagsAndMaskV86
Definition: v86vdm.c:21
struct _FLOATING_SAVE_CONTEXT * PFLOATING_SAVE_CONTEXT
NTSTATUS NTAPI Ke386GetGdtEntryThread(IN PKTHREAD Thread, IN ULONG Offset, IN PKGDTENTRY Descriptor)
Definition: ldt.c:26
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
union _KTRAP_EXIT_SKIP_BITS KTRAP_EXIT_SKIP_BITS
VOID __cdecl KiFastCallEntry(VOID)
VOID NTAPI KiI386PentiumLockErrataFixup(VOID)
Definition: cpu.c:1018
BOOLEAN NTAPI KiIsNpxErrataPresent(VOID)
Definition: cpu.c:1089
CHAR KiSystemCallExitBranch[]
struct _KV86_FRAME * PKV86_FRAME
ULONG_PTR NTAPI Ki386EnableXMMIExceptions(IN ULONG_PTR Context)
Definition: cpu.c:995
VOID NTAPI KiAmdK6InitializeMTRR(VOID)
Definition: mtrr.c:31
ULONG_PTR NTAPI Ki386EnableFxsr(IN ULONG_PTR Context)
Definition: cpu.c:985
VOID __cdecl ReadBatch(VOID)
BOOLEAN NTAPI Ki386CreateIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap, IN PVOID StartPtr, IN ULONG Length)
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException0Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:832
ULONG KeI386EFlagsOrMaskV86
Definition: v86vdm.c:22
CHAR KiSystemCallExit[]
VOID NTAPI Ki386EnableCurrentLargePage(IN ULONG_PTR StartAddress, IN ULONG Cr3)
VOID NTAPI KiRestoreFastSyscallReturnState(VOID)
Definition: cpu.c:941
FORCEINLINE VOID KiSetTebBase(PKPCR Pcr, PNT_TIB TebAddress)
Definition: ke.h:455
BOOLEAN KiI386PentiumLockErrataPresent
Definition: cpu.c:42
VOID __cdecl CopyParams(VOID)
ULONG_PTR NTAPI Ki386EnableGlobalPage(IN ULONG_PTR Context)
Definition: patpge.c:23
VOID NTAPI Ki386FreeIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap)
ULONG KiMXCsrMask
Definition: cpu.c:30
VOID NTAPI KiInitializeMTRR(IN BOOLEAN FinalCpu)
Definition: mtrr.c:22
NTSTATUS NTAPI KiSystemCallTrampoline(_In_ PVOID Handler, _In_ PVOID Arguments, _In_ ULONG StackBytes)
VOID NTAPI KiSetCR0Bits(VOID)
Definition: cpu.c:658
VOID NTAPI Ki386SetupAndExitToV86Mode(OUT PTEB VdmTeb)
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException1Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:846
KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR+1]
Definition: except.c:50
VOID NTAPI Ki386AdjustEsp0(IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:280
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:769
VOID NTAPI KiInitializePcr(IN ULONG ProcessorNumber, IN PKIPCR Pcr, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt, IN PKTSS Tss, IN PKTHREAD IdleThread, IN PVOID DpcStack)
Definition: kiinit.c:284
FORCEINLINE PVOID Ke386SanitizeDr(IN PVOID DrAddress, IN KPROCESSOR_MODE Mode)
Definition: ke.h:814
ULONG_PTR FASTCALL KiExitV86Mode(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:482
NTSTATUS NTAPI KiConvertToGuiThread(VOID)
struct _FLOATING_SAVE_CONTEXT FLOATING_SAVE_CONTEXT
const PULONG KiNtVdmState
Definition: v86vdm.c:25
FORCEINLINE DECLSPEC_NORETURN VOID KiIret(VOID)
Definition: ke.h:965
struct _KV8086_STACK_FRAME * PKV8086_STACK_FRAME
FORCEINLINE VOID Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
Definition: ke.h:446
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit(IN PKTRAP_FRAME TrapFrame, IN NTSTATUS Status)
Definition: traphdlr.c:150
CHAR KiSystemCallExit2[]
BOOLEAN NTAPI KiIsNpxPresent(VOID)
VOID FASTCALL Ki386BiosCallReturnAddress(IN PKTRAP_FRAME TrapFrame)
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
ULONG_PTR NTAPI Ki386EnableDE(IN ULONG_PTR Context)
Definition: cpu.c:975
FORCEINLINE ULONG Ke386SanitizeSeg(IN ULONG Cs, IN KPROCESSOR_MODE Mode)
Definition: ke.h:780
VOID NTAPI KeI386VdmInitialize(VOID)
Definition: vdmmain.c:42
FORCEINLINE VOID KiCheckForApcDelivery(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:886
VOID NTAPI ExpInterlockedPopEntrySListFault(VOID)
VOID NTAPI KiThreadStartup(VOID)
Definition: thrdini.c:63
ULONGLONG BootCyclesEnd
Definition: ke.h:157
ULONGLONG BootCycles
Definition: kiinit.c:37
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
unsigned short USHORT
Definition: pedump.c:61
char CHAR
Definition: pedump.c:57
static WCHAR Address[46]
Definition: ping.c:68
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tpush %rbx\n" "\t.seh_pushreg %rbx\n" "\tpush %rdi\n" "\t.seh_pushreg %rdi\n" "\tpush %rsi\n" "\t.seh_pushreg %rsi\n" "\tpush %r12\n" "\t.seh_pushreg %r12\n" "\tpush %r13\n" "\t.seh_pushreg %r13\n" "\tpush %r14\n" "\t.seh_pushreg %r14\n" "\tpush %r15\n" "\t.seh_pushreg %r15\n" "\tsub $40, %rsp\n" "\t.seh_stackalloc 40\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $40, %rsp\n" "\tpop %r15\n" "\tpop %r14\n" "\tpop %r13\n" "\tpop %r12\n" "\tpop %rsi\n" "\tpop %rdi\n" "\tpop %rbx\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
Entry
Definition: section.c:5216
_In_ PVOID Context
Definition: storport.h:2269
PKTHREAD CurrentThread
Definition: ke.h:302
PFX_SAVE_AREA PfxSaveArea
Definition: ke.h:305
PFX_SAVE_AREA Buffer
Definition: ke.h:304
KIRQL OldNpxIrql
Definition: ke.h:303
USHORT Offset
Definition: ketypes.h:440
USHORT ExtendedOffset
Definition: ketypes.h:443
PKIDTENTRY IDT
Definition: ketypes.h:822
Definition: ke.h:294
NT_TIB NtTib
Definition: ke.h:297
PUSHORT GDT
Definition: ke.h:54
ULONG TempEsp
Definition: ketypes.h:300
ULONG Ebp
Definition: ketypes.h:319
ULONG PreviousPreviousMode
Definition: ketypes.h:313
ULONG HardwareEsp
Definition: ketypes.h:324
ULONG Eip
Definition: ketypes.h:321
ULONG Edx
Definition: ketypes.h:310
Definition: ketypes.h:854
KTRAP_FRAME TrapFrame
Definition: ke.h:280
KV86_FRAME V86Frame
Definition: ke.h:282
FX_SAVE_AREA NpxArea
Definition: ke.h:281
PVOID ThreadTeb
Definition: ke.h:271
PVOID PcrTeb
Definition: ke.h:272
PVOID ThreadStack
Definition: ke.h:270
ULONG_PTR StartAddress
Definition: ke.h:292
PVOID PagesList[30]
Definition: ke.h:294
PHARDWARE_PTE TopLevelDirectory
Definition: ke.h:290
ULONG PagesCount
Definition: ke.h:293
struct _NT_TIB * Self
Definition: compat.h:720
Definition: compat.h:836
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint64_t ULONGLONG
Definition: typedefs.h:67
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
UCHAR SkipSegments
Definition: ke.h:184
UCHAR SkipPreviousMode
Definition: ke.h:183
UCHAR Reserved
Definition: ke.h:186
UCHAR SkipVolatiles
Definition: ke.h:185
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1707
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define FORCEINLINE
Definition: wdftypes.h:67
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7