ReactOS  0.4.15-dev-2721-g5912c11
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
8 extern "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 //
26 // One-liners for getting and setting special purpose registers in portable code
27 //
31 {
32  return Context->Eip;
33 }
34 
36 VOID
38 {
39  Context->Eip = ProgramCounter;
40 }
41 
45 {
46  return Context->Eax;
47 }
48 
50 VOID
52 {
53  Context->Eax = ReturnValue;
54 }
55 
59 {
60  return Context->Ebp;
61 }
62 
64 VOID
66 {
67  Context->Ebp = Frame;
68 }
69 
73 {
74  return TrapFrame->Eip;
75 }
76 
80 {
81  return (PKTRAP_FRAME)TrapFrame->Edx;
82 }
83 
84 
88 {
89  if (TrapFrame->PreviousPreviousMode == KernelMode)
90  return TrapFrame->TempEsp;
91  return TrapFrame->HardwareEsp;
92 }
93 
97 {
98  return TrapFrame->Ebp;
99 }
100 
101 //
102 // Macro to get trap and exception frame from a thread stack
103 //
104 #define KeGetTrapFrame(Thread) \
105  (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
106  sizeof(KTRAP_FRAME) - \
107  sizeof(FX_SAVE_AREA))
108 
109 #define KeGetExceptionFrame(Thread) \
110  NULL
111 
112 //
113 // Macro to get context switches from the PRCB
114 // All architectures but x86 have it in the PRCB's KeContextSwitches
115 //
116 #define KeGetContextSwitches(Prcb) \
117  CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches
118 
119 //
120 // Macro to get the second level cache size field name which differs between
121 // CISC and RISC architectures, as the former has unified I/D cache
122 //
123 #define KiGetSecondLevelDCacheSize() ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
124 
125 //
126 // Returns the Interrupt State from a Trap Frame.
127 // ON = TRUE, OFF = FALSE
128 //
129 #define KeGetTrapFrameInterruptState(TrapFrame) \
130  BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
131 
132 //
133 // Flags for exiting a trap
134 //
135 #define KTE_SKIP_PM_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipPreviousMode = TRUE } }).Bits)
136 #define KTE_SKIP_SEG_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipSegments = TRUE } }).Bits)
137 #define KTE_SKIP_VOL_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipVolatiles = TRUE } }).Bits)
138 
140 {
141  struct
142  {
147  };
150 
151 
152 //
153 // Flags used by the VDM/V8086 emulation engine for determining instruction prefixes
154 //
155 #define PFX_FLAG_ES 0x00000100
156 #define PFX_FLAG_CS 0x00000200
157 #define PFX_FLAG_SS 0x00000400
158 #define PFX_FLAG_DS 0x00000800
159 #define PFX_FLAG_FS 0x00001000
160 #define PFX_FLAG_GS 0x00002000
161 #define PFX_FLAG_OPER32 0x00004000
162 #define PFX_FLAG_ADDR32 0x00008000
163 #define PFX_FLAG_LOCK 0x00010000
164 #define PFX_FLAG_REPNE 0x00020000
165 #define PFX_FLAG_REP 0x00040000
166 
167 //
168 // VDM Helper Macros
169 //
170 // All VDM/V8086 opcode emulators have the same FASTCALL function definition.
171 // We need to keep 2 parameters while the original ASM implementation uses 4:
172 // TrapFrame, PrefixFlags, Eip, InstructionSize;
173 //
174 // We pass the trap frame, and prefix flags, in our two parameters.
175 //
176 // We then realize that since the smallest prefix flag is 0x100, this gives us
177 // a count of up to 0xFF. So we OR in the instruction size with the prefix flags
178 //
179 // We further realize that we always have access to EIP from the trap frame, and
180 // that if we want the *current instruction* EIP, we simply have to add the
181 // instruction size *MINUS ONE*, and that gives us the EIP we should be looking
182 // at now, so we don't need to use the stack to push this parameter.
183 //
184 // We actually only care about the *current instruction* EIP in one location,
185 // so although it may be slightly more expensive to re-calculate the EIP one
186 // more time, this way we don't redefine ALL opcode handlers to have 3 parameters,
187 // which would be forcing stack usage in all other scenarios.
188 //
189 #define KiVdmSetVdmEFlags(x) InterlockedOr((PLONG)KiNtVdmState, (x));
190 #define KiVdmClearVdmEFlags(x) InterlockedAnd((PLONG)KiNtVdmState, ~(x))
191 #define KiCallVdmHandler(x) KiVdmOpcode##x(TrapFrame, Flags)
192 #define KiCallVdmPrefixHandler(x) KiVdmOpcodePrefix(TrapFrame, Flags | x)
193 #define KiVdmUnhandledOpcode(x) \
194  BOOLEAN \
195  FASTCALL \
196  KiVdmOpcode##x(IN PKTRAP_FRAME TrapFrame, \
197  IN ULONG Flags) \
198  { \
199  /* Not yet handled */ \
200  UNIMPLEMENTED_DBGBREAK(); \
201  return FALSE; \
202  }
203 
205 
206 //
207 // Local parameters
208 //
209 typedef struct _KV86_FRAME
210 {
215 
216 //
217 // Virtual Stack Frame
218 //
219 typedef struct _KV8086_STACK_FRAME
220 {
225 
226 //
227 // Large Pages Support
228 //
229 typedef struct _LARGE_IDENTITY_MAP
230 {
237 
238 /* Diable interrupts and return whether they were enabled before */
240 BOOLEAN
242 {
243  ULONG Flags;
244  BOOLEAN Return;
245 
246  /* Get EFLAGS and check if the interrupt bit is set */
247  Flags = __readeflags();
248  Return = (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
249 
250  /* Disable interrupts */
251  _disable();
252  return Return;
253 }
254 
255 /* Restore previous interrupt state */
257 VOID
259 {
260  if (WereEnabled) _enable();
261 }
262 
263 //
264 // Registers an interrupt handler with an IDT vector
265 //
267 VOID
269  IN PVOID Handler)
270 {
271  UCHAR Entry;
273  PKIPCR Pcr = (PKIPCR)KeGetPcr();
274 
275  //
276  // Get the entry from the HAL
277  //
280 
281  //
282  // Now set the data
283  //
284  Pcr->IDT[Entry].ExtendedOffset = (USHORT)(Address >> 16);
285  Pcr->IDT[Entry].Offset = (USHORT)Address;
286 }
287 
288 //
289 // Returns the registered interrupt handler for a given IDT vector
290 //
292 PVOID
294 {
295  PKIPCR Pcr = (PKIPCR)KeGetPcr();
296  UCHAR Entry;
297 
298  //
299  // Get the entry from the HAL
300  //
302 
303  //
304  // Read the entry from the IDT
305  //
306  return (PVOID)(((Pcr->IDT[Entry].ExtendedOffset << 16) & 0xFFFF0000) |
307  (Pcr->IDT[Entry].Offset & 0xFFFF));
308 }
309 
310 //
311 // Invalidates the TLB entry for a specified address
312 //
314 VOID
316 {
317  /* Invalidate the TLB entry for this address */
318  __invlpg(Address);
319 }
320 
322 VOID
324 {
325  /* Flush the TLB by resetting CR3 */
327 }
328 
330 VOID
332  IN SIZE_T FlushSize)
333 {
334  //
335  // Always sweep the whole cache
336  //
338  UNREFERENCED_PARAMETER(FlushSize);
339  __wbinvd();
340 }
341 
343 PRKTHREAD
345 {
346  /* Return the current thread */
347  return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
348 }
349 
351 VOID
353 {
354 #ifndef CONFIG_SMP
355  /* Check if this is the NPX Thread */
356  if (KeGetCurrentPrcb()->NpxThread == Thread)
357  {
358  /* Clear it */
359  KeGetCurrentPrcb()->NpxThread = NULL;
360  Ke386FnInit();
361  }
362 #else
363  /* Nothing to do */
364 #endif
365 }
366 
368 VOID
370 {
371  GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
372  GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
373  GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
374 }
375 
377 VOID
378 KiSetTebBase(PKPCR Pcr, PNT_TIB TebAddress)
379 {
380  Pcr->NtTib.Self = TebAddress;
381  Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
382 }
383 
384 CODE_SEG("INIT")
385 VOID
386 FASTCALL
388  IN PKTSS Tss,
389  IN PKIDTENTRY Idt,
390  IN PKGDTENTRY Gdt
391 );
392 
393 CODE_SEG("INIT")
394 VOID
395 NTAPI
397 
398 CODE_SEG("INIT")
399 VOID
400 NTAPI
402 
403 CODE_SEG("INIT")
404 BOOLEAN
405 NTAPI
407  VOID
408 );
409 
410 CODE_SEG("INIT")
411 BOOLEAN
412 NTAPI
414  VOID
415 );
416 
417 CODE_SEG("INIT")
418 VOID
419 NTAPI
421 
422 CODE_SEG("INIT")
423 ULONG
424 NTAPI
426 
427 VOID
428 NTAPI
430 
431 NTSTATUS
432 NTAPI
435  IN ULONG Offset,
437 );
438 
439 VOID
440 NTAPI
442  IN FLOATING_SAVE_AREA *SaveArea
443 );
444 
445 VOID
446 NTAPI
448  IN PKTRAP_FRAME TrapFrame
449 );
450 
451 VOID
452 NTAPI
454  OUT PTEB VdmTeb
455 );
456 
457 CODE_SEG("INIT")
458 VOID
459 NTAPI
461  VOID
462 );
463 
464 CODE_SEG("INIT")
465 ULONG_PTR
466 NTAPI
469 );
470 
471 CODE_SEG("INIT")
472 ULONG_PTR
473 NTAPI
476 );
477 
478 BOOLEAN
479 NTAPI
481  IN PLARGE_IDENTITY_MAP IdentityMap,
482  IN PVOID StartPtr,
483  IN ULONG Length
484 );
485 
486 VOID
487 NTAPI
489  IN PLARGE_IDENTITY_MAP IdentityMap
490 );
491 
492 VOID
493 NTAPI
495  IN ULONG_PTR StartAddress,
496  IN ULONG Cr3
497 );
498 
499 CODE_SEG("INIT")
500 VOID
501 NTAPI
503  VOID
504 );
505 
506 CODE_SEG("INIT")
507 VOID
508 NTAPI
510  VOID
511 );
512 
513 CODE_SEG("INIT")
514 VOID
515 NTAPI
517  IN BOOLEAN FinalCpu
518 );
519 
520 CODE_SEG("INIT")
521 VOID
522 NTAPI
524  VOID
525 );
526 
527 CODE_SEG("INIT")
528 VOID
529 NTAPI
531  VOID
532 );
533 
534 CODE_SEG("INIT")
535 ULONG_PTR
536 NTAPI
539 );
540 
541 CODE_SEG("INIT")
542 ULONG_PTR
543 NTAPI
546 );
547 
548 CODE_SEG("INIT")
549 ULONG_PTR
550 NTAPI
553 );
554 
555 BOOLEAN
556 NTAPI
558  IN PKTRAP_FRAME TrapFrame
559 );
560 
561 BOOLEAN
562 NTAPI
564  _In_ PKTRAP_FRAME TrapFrame
565 );
566 
567 BOOLEAN
568 FASTCALL
570  IN PKTRAP_FRAME TrapFrame,
571  IN ULONG Flags
572 );
573 
574 BOOLEAN
575 FASTCALL
577  IN PKTRAP_FRAME TrapFrame
578 );
579 
581 VOID
582 FASTCALL
584  IN PKTRAP_FRAME TrapFrame
585 );
586 
587 VOID
588 FASTCALL
590  IN PKTRAP_FRAME TrapFrame
591 );
592 
593 ULONG_PTR
594 FASTCALL
596  IN PKTRAP_FRAME TrapFrame
597 );
598 
600 VOID
601 NTAPI
603  IN NTSTATUS Code,
604  IN ULONG Flags,
606  IN ULONG ParameterCount,
607  IN ULONG_PTR Parameter1,
608  IN ULONG_PTR Parameter2,
609  IN ULONG_PTR Parameter3,
610  IN PKTRAP_FRAME TrapFrame
611 );
612 
613 NTSTATUS
614 NTAPI
616  VOID
617 );
618 
619 //
620 // Global x86 only Kernel data
621 //
622 extern PVOID Ki386IopmSaveArea;
629 extern ULONG KeI386NpxPresent;
630 extern ULONG KeI386XMMIPresent;
631 extern ULONG KeI386FxsrPresent;
632 extern ULONG KiMXCsrMask;
633 extern ULONG KeI386CpuType;
634 extern ULONG KeI386CpuStep;
638 extern VOID __cdecl KiTrap02(VOID);
639 extern VOID __cdecl KiTrap08(VOID);
640 extern VOID __cdecl KiTrap13(VOID);
644 extern VOID __cdecl CopyParams(VOID);
645 extern VOID __cdecl ReadBatch(VOID);
647 extern CHAR KiSystemCallExit[];
648 extern CHAR KiSystemCallExit2[];
649 
650 //
651 // Trap Macros
652 //
653 #include "trap_x.h"
654 
655 //
656 // Returns a thread's FPU save area
657 //
661 {
662  ASSERT((ULONG_PTR)Thread->InitialStack % 16 == 0);
663  return (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof(FX_SAVE_AREA));
664 }
665 
666 //
667 // Sanitizes a selector
668 //
670 ULONG
673 {
674  //
675  // Check if we're in kernel-mode, and force CPL 0 if so.
676  // Otherwise, force CPL 3.
677  //
678  return ((Mode == KernelMode) ?
679  (Cs & (0xFFFF & ~RPL_MASK)) :
680  (RPL_MASK | (Cs & 0xFFFF)));
681 }
682 
683 //
684 // Sanitizes EFLAGS
685 //
687 ULONG
690 {
691  //
692  // Check if we're in kernel-mode, and sanitize EFLAGS if so.
693  // Otherwise, also force interrupt mask on.
694  //
695  return ((Mode == KernelMode) ?
698 }
699 
700 //
701 // Sanitizes a Debug Register
702 //
704 PVOID
707 {
708  //
709  // Check if we're in kernel-mode, and return the address directly if so.
710  // Otherwise, make sure it's not inside the kernel-mode address space.
711  // If it is, then clear the address.
712  //
713  return ((Mode == KernelMode) ? DrAddress :
714  (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0);
715 }
716 
717 //
718 // Exception with no arguments
719 //
722 VOID
725  IN PKTRAP_FRAME TrapFrame)
726 {
727  /* Helper for exceptions with no arguments */
728  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 0, 0, 0, 0, TrapFrame);
729 }
730 
731 //
732 // Exception with one argument
733 //
736 VOID
739  IN ULONG P1,
740  IN PKTRAP_FRAME TrapFrame)
741 {
742  /* Helper for exceptions with no arguments */
743  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 1, P1, 0, 0, TrapFrame);
744 }
745 
746 //
747 // Exception with two arguments
748 //
751 VOID
754  IN ULONG P1,
755  IN ULONG P2,
756  IN PKTRAP_FRAME TrapFrame)
757 {
758  /* Helper for exceptions with no arguments */
759  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 2, P1, P2, 0, TrapFrame);
760 }
761 
762 //
763 // Performs a system call
764 //
765 NTSTATUS
766 NTAPI
768  _In_ PVOID Arguments,
769  _In_ ULONG StackBytes);
770 
771 
772 //
773 // Checks for pending APCs
774 //
776 VOID
778 {
780  KIRQL OldIrql;
781 
782  /* Check for V8086 or user-mode trap */
783  if ((TrapFrame->EFlags & EFLAGS_V86_MASK) || (KiUserTrap(TrapFrame)))
784  {
785  /* Get the thread */
787  while (TRUE)
788  {
789  /* Turn off the alerted state for kernel mode */
790  Thread->Alerted[KernelMode] = FALSE;
791 
792  /* Are there pending user APCs? */
793  if (!Thread->ApcState.UserApcPending) break;
794 
795  /* Raise to APC level and enable interrupts */
797  _enable();
798 
799  /* Deliver APCs */
800  KiDeliverApc(UserMode, NULL, TrapFrame);
801 
802  /* Restore IRQL and disable interrupts once again */
804  _disable();
805  }
806  }
807 }
808 
809 //
810 // Switches from boot loader to initial kernel stack
811 //
812 CODE_SEG("INIT")
815 VOID
817 {
819 
820  /* We have to switch to a new stack before continuing kernel initialization */
821 #ifdef __GNUC__
822  __asm__
823  (
824  "movl %0, %%esp\n\t"
825  "subl %1, %%esp\n\t"
826  "pushl %2\n\t"
827  "jmp _KiSystemStartupBootStack@0"
828  :
829  : "c"(InitialStack),
831  "i"(CR0_EM | CR0_TS | CR0_MP),
833  : "%esp"
834  );
835 #elif defined(_MSC_VER)
836  __asm
837  {
838  mov esp, InitialStack
840  push (CR0_EM | CR0_TS | CR0_MP)
842  }
843 #else
844 #error Unknown Compiler
845 #endif
846 
847  UNREACHABLE;
848 }
849 
850 //
851 // Emits the iret instruction for C code
852 //
855 VOID
857 {
858 #if defined(__GNUC__)
859  __asm__ __volatile__
860  (
861  "iret"
862  );
863 #elif defined(_MSC_VER)
864  __asm
865  {
866  iretd
867  }
868 #else
869 #error Unsupported compiler
870 #endif
871  UNREACHABLE;
872 }
873 
874 //
875 // Normally this is done by the HAL, but on x86 as an optimization, the kernel
876 // initiates the end by calling back into the HAL and exiting the trap here.
877 //
879 VOID
881  IN PKTRAP_FRAME TrapFrame)
882 {
883  /* Disable interrupts and end the interrupt */
884  _disable();
885  HalEndSystemInterrupt(Irql, TrapFrame);
886 
887  /* Exit the interrupt */
888  KiEoiHelper(TrapFrame);
889 }
890 
891 //
892 // PERF Code
893 //
895 VOID
897 {
900  DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
901  DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
902  KeGetCurrentPrcb()->InterruptCount,
903  KeGetCurrentPrcb()->KeSystemCalls,
905 }
906 
908 PULONG
910 {
912 }
913 
914 #ifdef __cplusplus
915 } // extern "C"
916 #endif
917 
918 #endif
VOID NTAPI ExpInterlockedPopEntrySListResume(VOID)
#define CR0_EM
Definition: asm.h:247
KV86_FRAME V86Frame
Definition: ke.h:223
struct _NT_TIB * Self
Definition: compat.h:579
ULONG TempEsp
Definition: ketypes.h:246
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
#define IN
Definition: typedefs.h:39
VOID NTAPI HalEndSystemInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
Definition: pic.c:335
FORCEINLINE VOID KeSetContextFrameRegister(PCONTEXT Context, ULONG_PTR Frame)
Definition: ke.h:168
BOOLEAN KiI386PentiumLockErrataPresent
Definition: cpu.c:40
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
#define NPX_FRAME_LENGTH
Definition: asm.h:246
UCHAR SkipSegments
Definition: ke.h:144
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:752
FORCEINLINE PKTRAP_FRAME KiGetLinkedTrapFrame(PKTRAP_FRAME TrapFrame)
Definition: ke.h:182
struct _Entry Entry
Definition: kefuncs.h:627
CHAR KiSystemCallExit2[]
#define __cdecl
Definition: accygwin.h:79
_In_ ULONG Mode
Definition: hubbusif.h:303
#define DbgPrint
Definition: loader.c:25
ULONG_PTR StartAddress
Definition: ke.h:233
DECLSPEC_NORETURN VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack)
Definition: ke.h:816
FX_SAVE_AREA NpxArea
Definition: ke.h:222
VOID NTAPI KiSetCR0Bits(VOID)
Definition: cpu.c:728
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
USHORT BaseLow
Definition: ketypes.h:336
struct _KV8086_STACK_FRAME * PKV8086_STACK_FRAME
ULONGLONG BootCycles
Definition: kiinit.c:30
ULONG KiFastSystemCallDisable
Definition: cpu.c:26
BOOLEAN NTAPI Ki386CreateIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap, IN PVOID StartPtr, IN ULONG Length)
char CHAR
Definition: xmlstorage.h:175
FORCEINLINE ULONG Ke386SanitizeFlags(IN ULONG Eflags, IN KPROCESSOR_MODE Mode)
Definition: ke.h:688
void __cdecl _enable(void)
Definition: intrin_arm.h:373
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN FASTCALL Ki386HandleOpcodeV86(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:456
ULONG KiGetFeatureBits(VOID)
Definition: cpu.c:119
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
ULONG KeI386EFlagsOrMaskV86
Definition: v86vdm.c:22
DECLSPEC_NORETURN VOID NTAPI KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:58
struct _KIPCR * PKIPCR
VOID NTAPI Ki386AdjustEsp0(IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:280
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:1100
PVOID PcrTeb
Definition: ke.h:213
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
VOID NTAPI KiInitializeMTRR(IN BOOLEAN FinalCpu)
Definition: mtrr.c:22
FORCEINLINE PVOID Ke386SanitizeDr(IN PVOID DrAddress, IN KPROCESSOR_MODE Mode)
Definition: ke.h:705
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1706
ULONG KeI386NpxPresent
Definition: cpu.c:25
BOOLEAN NTAPI KiIsNpxErrataPresent(VOID)
Definition: cpu.c:1209
Definition: ke.h:289
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1819
union _KTRAP_EXIT_SKIP_BITS KTRAP_EXIT_SKIP_BITS
ULONG_PTR NTAPI Ki386EnableGlobalPage(IN ULONG_PTR Context)
Definition: patpge.c:23
FORCEINLINE PULONG_PTR KiGetUserModeStackAddress(void)
Definition: ke.h:447
ULONG_PTR NTAPI Ki386EnableDE(IN ULONG_PTR Context)
Definition: cpu.c:1045
#define FASTCALL
Definition: nt_native.h:50
union _KTRAP_EXIT_SKIP_BITS * PKTRAP_EXIT_SKIP_BITS
_Out_ PKIRQL Irql
Definition: csq.h:179
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
FORCEINLINE PVOID KeQueryInterruptHandler(IN ULONG Vector)
Definition: ke.h:323
ULONG KeI386FxsrPresent
Definition: cpu.c:31
#define EFLAGS_V86_MASK
Definition: ketypes.h:132
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN NTAPI KiIsNpxPresent(VOID)
Definition: cpu.c:1168
UCHAR KIRQL
Definition: env_spec_w32.h:591
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1795
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1675
UINT32 void void ** ReturnValue
Definition: acevents.h:214
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID ThreadStack
Definition: ke.h:211
#define FALSE
Definition: types.h:117
FORCEINLINE VOID KeSetContextPc(PCONTEXT Context, ULONG_PTR ProgramCounter)
Definition: ke.h:133
UCHAR Reserved
Definition: ke.h:146
ULONG PagesCount
Definition: ke.h:234
NTKERNELAPI KIRQL NTAPI KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:344
#define EFLAGS_USER_SANITIZE
Definition: ketypes.h:137
#define RPL_MASK
Definition: ketypes.h:69
unsigned char BOOLEAN
NTSTATUS NTAPI KiConvertToGuiThread(VOID)
VOID NTAPI KiInitializePAT(VOID)
Definition: patpge.c:61
struct _KV86_FRAME KV86_FRAME
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI Ki386FreeIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap)
Definition: ketypes.h:789
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:235
FORCEINLINE VOID Ki386PerfEnd(VOID)
Definition: ke.h:896
ULONG KeI386XMMIPresent
Definition: cpu.c:30
FORCEINLINE VOID Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
Definition: ke.h:369
CODE_SEG("INIT")
Definition: Interface.c:1810
FORCEINLINE ULONG_PTR KeGetTrapFrameStackRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:189
ULONGLONG BootCyclesEnd
Definition: kiinit.c:30
VOID __cdecl CopyParams(VOID)
UCHAR SkipPreviousMode
Definition: ke.h:143
ULONG KiMXCsrMask
Definition: cpu.c:28
VOID NTAPI ExpInterlockedPopEntrySListFault(VOID)
#define PtrToUlong(u)
Definition: config.h:107
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:660
UCHAR KiDebugRegisterTrapOffsets[9]
FORCEINLINE VOID KiCheckForApcDelivery(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:777
VOID FASTCALL Ki386InitializeTss(IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
Definition: cpu.c:799
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:260
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:44
C_ASSERT(NPX_FRAME_LENGTH==sizeof(FX_SAVE_AREA))
uint64_t ULONGLONG
Definition: typedefs.h:67
#define APC_LEVEL
VOID NTAPI KiRestoreFastSyscallReturnState(VOID)
Definition: cpu.c:1011
ULONG HardwareEsp
Definition: ketypes.h:270
ULONG KeI386CpuType
Definition: cpu.c:22
#define KGDT_R3_TEB
Definition: ketypes.h:81
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KiGetCacheInformation(VOID)
Definition: cpu.c:208
USHORT Offset
Definition: ketypes.h:386
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
BOOLEAN FASTCALL KiVdmOpcodePrefix(IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
Definition: v86vdm.c:442
USHORT ExtendedOffset
Definition: ketypes.h:389
PVOID ThreadTeb
Definition: ke.h:212
FORCEINLINE DECLSPEC_NORETURN VOID KiIret(VOID)
Definition: ke.h:856
FORCEINLINE ULONG_PTR KeGetContextPc(PCONTEXT Context)
Definition: ke.h:126
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _KGDTENTRY::@2407::@2408 Bytes
ULONG KeI386CpuStep
Definition: cpu.c:23
NTSTATUS NTAPI KiSystemCallTrampoline(_In_ PVOID Handler, _In_ PVOID Arguments, _In_ ULONG StackBytes)
NTSTATUS NTAPI Ke386GetGdtEntryThread(IN PKTHREAD Thread, IN ULONG Offset, IN PKGDTENTRY Descriptor)
Definition: ldt.c:26
VOID NTAPI Ki386SetupAndExitToV86Mode(OUT PTEB VdmTeb)
VOID __cdecl KiTrap13(VOID)
struct _KV8086_STACK_FRAME KV8086_STACK_FRAME
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID FASTCALL Ki386BiosCallReturnAddress(IN PKTRAP_FRAME TrapFrame)
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1697
FORCEINLINE VOID KeSetContextReturnRegister(PCONTEXT Context, ULONG_PTR ReturnValue)
Definition: ke.h:147
ULONG_PTR FASTCALL KiExitV86Mode(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:468
PVOID Ki386IopmSaveArea
Definition: v86vdm.c:23
ULONG_PTR NTAPI Ki386EnableXMMIExceptions(IN ULONG_PTR Context)
Definition: cpu.c:1065
NT_TIB NtTib
Definition: ke.h:293
ULONG Eip
Definition: ketypes.h:267
struct _LARGE_IDENTITY_MAP LARGE_IDENTITY_MAP
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:360
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical 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:668
UCHAR KiDebugRegisterContextOffsets[9]
FORCEINLINE ULONG Ke386SanitizeSeg(IN ULONG Cs, IN KPROCESSOR_MODE Mode)
Definition: ke.h:671
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:327
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:297
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR+1]
Definition: except.c:50
#define _In_
Definition: no_sal2.h:158
ULONG PreviousPreviousMode
Definition: ketypes.h:259
FORCEINLINE ULONG_PTR KeGetTrapFramePc(PKTRAP_FRAME TrapFrame)
Definition: ke.h:175
PUSHORT GDT
Definition: ke.h:54
ULONG_PTR SIZE_T
Definition: typedefs.h:80
VOID __cdecl ReadBatch(VOID)
Definition: compat.h:694
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException0Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:723
struct _KV86_FRAME * PKV86_FRAME
FORCEINLINE VOID KiSetTebBase(PKPCR Pcr, PNT_TIB TebAddress)
Definition: ke.h:378
FORCEINLINE ULONG_PTR KeGetContextReturnRegister(PCONTEXT Context)
Definition: ke.h:140
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException1Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:737
VOID __cdecl KiTrap08(VOID)
unsigned short USHORT
Definition: pedump.c:61
PHARDWARE_PTE TopLevelDirectory
Definition: ke.h:231
BOOLEAN NTAPI VdmDispatchPageFault(_In_ PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:367
PVOID PagesList[30]
Definition: ke.h:235
ULONG KeI386EFlagsAndMaskV86
Definition: v86vdm.c:21
NTKERNELAPI VOID NTAPI KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
#define CR0_TS
Definition: asm.h:248
FORCEINLINE ULONG_PTR KeGetContextFrameRegister(PCONTEXT Context)
Definition: ke.h:161
#define FORCEINLINE
Definition: wdftypes.h:67
VOID NTAPI KiFlushNPXState(IN FLOATING_SAVE_AREA *SaveArea)
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:250
UCHAR SkipVolatiles
Definition: ke.h:145
FORCEINLINE VOID KiRundownThread(IN PKTHREAD Thread)
Definition: ke.h:289
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
union _KGDTENTRY::@2407 HighWord
VOID NTAPI KiAmdK6InitializeMTRR(VOID)
Definition: mtrr.c:31
BOOLEAN NTAPI VdmDispatchBop(IN PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:313
FORCEINLINE VOID KiEndInterrupt(IN KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:350
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:268
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1969
VOID NTAPI KeI386VdmInitialize(VOID)
Definition: stubs.c:156
#define OUT
Definition: typedefs.h:40
VOID __cdecl KiTrap02(VOID)
VOID NTAPI Ki386EnableCurrentLargePage(IN ULONG_PTR StartAddress, IN ULONG Cr3)
VOID NTAPI KiThreadStartup(VOID)
Definition: thrdini.c:63
void __cdecl _disable(void)
Definition: intrin_arm.h:365
FORCEINLINE ULONG_PTR KeGetTrapFrameFrameRegister(PKTRAP_FRAME TrapFrame)
Definition: ke.h:196
unsigned int ULONG
Definition: retypes.h:1
CHAR KiSystemCallExitBranch[]
struct _LARGE_IDENTITY_MAP * PLARGE_IDENTITY_MAP
#define UNREACHABLE
VOID __cdecl KiFastCallEntry(VOID)
#define ULONG_PTR
Definition: config.h:101
#define KTRAP_FRAME_LENGTH
Definition: asm.h:126
ULONG_PTR NTAPI Ki386EnableTargetLargePage(IN ULONG_PTR Context)
Definition: patpge.c:70
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
VOID KiSetProcessorType(VOID)
Definition: cpu.c:49
#define CR0_MP
Definition: asm.h:246
BOOLEAN KeI386VirtualIntExtensions
Definition: v86vdm.c:24
PKIDTENTRY IDT
Definition: ketypes.h:758
ULONG_PTR NTAPI Ki386EnableFxsr(IN ULONG_PTR Context)
Definition: cpu.c:1055
CHAR KiSystemCallExit[]
#define KTRAP_FRAME_ALIGN
Definition: asm.h:125
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define KeGetContextSwitches(Prcb)
Definition: ke.h:116
#define MAXIMUM_IDTVECTOR
Definition: asm.h:280
base of all file and directory entries
Definition: entries.h:82
ULONG Edx
Definition: ketypes.h:256
ULONG Ebp
Definition: ketypes.h:265
FORCEINLINE VOID KeSweepICache(IN PVOID BaseAddress, IN SIZE_T FlushSize)
Definition: ke.h:276
VOID NTAPI KiI386PentiumLockErrataFixup(VOID)
Definition: cpu.c:1088
KTRAP_FRAME TrapFrame
Definition: ke.h:221
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
jmp_buf jmp
Definition: mach.c:35
#define HalVectorToIDTEntry
Definition: halfuncs.h:51