Commit in reactos on MAIN
hal/halx86/irql.c+20-261.15 -> 1.16
ntoskrnl/ex/sysinfo.c+19-161.53 -> 1.54
ntoskrnl/include/internal/ke.h-61.58 -> 1.59
ntoskrnl/ke/i386/irq.c+2-21.46 -> 1.47
                /kernel.c+347-3441.36 -> 1.37
ntoskrnl/ke/dpc.c+47-381.37 -> 1.38
           /timer.c+14-171.80 -> 1.81
ntoskrnl/ps/idle.c+20-91.27 -> 1.28
           /thread.c+4-51.135 -> 1.136
ntoskrnl/ntoskrnl.def+1-21.194 -> 1.195
+474-465
10 modified files
- Used variables from the KPCR for the current irql, for dpc's, for time counters and for the idle thread.

reactos/hal/halx86
irql.c 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- irql.c	20 Jul 2004 21:25:36 -0000	1.15
+++ irql.c	17 Oct 2004 15:39:27 -0000	1.16
@@ -1,4 +1,4 @@
-/* $Id: irql.c,v 1.15 2004/07/20 21:25:36 hbirr Exp $
+/* $Id: irql.c,v 1.16 2004/10/17 15:39:27 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -25,7 +25,6 @@
 /*
  * PURPOSE: Current irq level
  */
-static KIRQL CurrentIrql = HIGH_LEVEL;
 static BOOLEAN ApcRequested = FALSE;
 static BOOLEAN DpcRequested = FALSE;
 
@@ -60,8 +59,6 @@
 static PIC_MASK pic_mask_intr = { 0 };
 #endif
 
-extern IMPORTED ULONG DpcQueueSize;
-
 static ULONG HalpPendingInterruptCount[NR_IRQS];
 
 #define DIRQL_TO_IRQ(x)  (PROFILE_LEVEL - x)
@@ -78,7 +75,7 @@
  * RETURNS: The current irq level
  */
 {
-  return(CurrentIrql);
+  return(KeGetCurrentKPCR()->Irql);
 }
 
 VOID HalpInitPICs(VOID)
@@ -147,7 +144,7 @@
     {
       if (HalpPendingInterruptCount[i] > 0)
 	{
-	   CurrentIrql = (KIRQL)IRQ_TO_DIRQL(i);
+	   KeGetCurrentKPCR()->Irql = (KIRQL)IRQ_TO_DIRQL(i);
 
            while (HalpPendingInterruptCount[i] > 0)
 	     {
@@ -157,8 +154,8 @@
 	       HalpPendingInterruptCount[i]--;
 	       KiInterruptDispatch2(i, NewIrql);
 	     }
-	   CurrentIrql--;
-	   HalpEndSystemInterrupt(CurrentIrql);
+	   KeGetCurrentKPCR()->Irql--;
+	   HalpEndSystemInterrupt(KeGetCurrentKPCR()->Irql);
 	}
     }
 
@@ -169,21 +166,18 @@
 {
   if (NewIrql >= PROFILE_LEVEL)
     {
-      CurrentIrql = NewIrql;
+      KeGetCurrentKPCR()->Irql = NewIrql;
       return;
     }
   HalpExecuteIrqs(NewIrql);
   if (NewIrql >= DISPATCH_LEVEL)
     {
-      CurrentIrql = NewIrql;
+      KeGetCurrentKPCR()->Irql = NewIrql;
       return;
     }
-  CurrentIrql = DISPATCH_LEVEL;
-  if (DpcQueueSize > 0)
-    {
-      KiDispatchInterrupt();
-    }
-  CurrentIrql = APC_LEVEL;
+  KeGetCurrentKPCR()->Irql = DISPATCH_LEVEL;
+  KiDispatchInterrupt();
+  KeGetCurrentKPCR()->Irql = APC_LEVEL;
   if (NewIrql == APC_LEVEL)
     {
       return;
@@ -193,7 +187,7 @@
     {
       KiDeliverApc(0, 0, 0);
     }
-  CurrentIrql = PASSIVE_LEVEL;
+  KeGetCurrentKPCR()->Irql = PASSIVE_LEVEL;
 }
 
 /**********************************************************************
@@ -217,10 +211,10 @@
 {
   DPRINT("KfLowerIrql(NewIrql %d)\n", NewIrql);
   
-  if (NewIrql > CurrentIrql)
+  if (NewIrql > KeGetCurrentKPCR()->Irql)
     {
       DbgPrint ("(%s:%d) NewIrql %x CurrentIrql %x\n",
-		__FILE__, __LINE__, NewIrql, CurrentIrql);
+		__FILE__, __LINE__, NewIrql, KeGetCurrentKPCR()->Irql);
       KEBUGCHECK(0);
       for(;;);
     }
@@ -276,16 +270,16 @@
   
   DPRINT("KfRaiseIrql(NewIrql %d)\n", NewIrql);
   
-  if (NewIrql < CurrentIrql)
+  if (NewIrql < KeGetCurrentKPCR()->Irql)
     {
       DbgPrint ("%s:%d CurrentIrql %x NewIrql %x\n",
-		__FILE__,__LINE__,CurrentIrql,NewIrql);
+		__FILE__,__LINE__,KeGetCurrentKPCR()->Irql,NewIrql);
       KEBUGCHECK (0);
       for(;;);
     }
   
-  OldIrql = CurrentIrql;
-  CurrentIrql = NewIrql;
+  OldIrql = KeGetCurrentKPCR()->Irql;
+  KeGetCurrentKPCR()->Irql = NewIrql;
   return OldIrql;
 }
 
@@ -389,13 +383,13 @@
      WRITE_PORT_UCHAR((PUCHAR)0xa0,0x20);
   }
   
-  if (CurrentIrql >= Irql)
+  if (KeGetCurrentKPCR()->Irql >= Irql)
     {
       HalpPendingInterruptCount[irq]++;
       return(FALSE);
     }
-  *OldIrql = CurrentIrql;
-  CurrentIrql = Irql;
+  *OldIrql = KeGetCurrentKPCR()->Irql;
+  KeGetCurrentKPCR()->Irql = Irql;
 
   return(TRUE);
 }

reactos/ntoskrnl/ex
sysinfo.c 1.53 -> 1.54
diff -u -r1.53 -r1.54
--- sysinfo.c	16 Oct 2004 18:56:54 -0000	1.53
+++ sysinfo.c	17 Oct 2004 15:39:29 -0000	1.54
@@ -1,4 +1,4 @@
-/* $Id: sysinfo.c,v 1.53 2004/10/16 18:56:54 ion Exp $
+/* $Id: sysinfo.c,v 1.54 2004/10/17 15:39:29 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -727,32 +727,35 @@
 	PSYSTEM_PROCESSORTIME_INFO Spi
 		= (PSYSTEM_PROCESSORTIME_INFO) Buffer;
 
-        PEPROCESS TheIdleProcess;
+        ULONG i;
 	TIME CurrentTime;
+	PKPCR Pcr;
 
-	*ReqSize = sizeof (SYSTEM_PROCESSORTIME_INFO);
+	*ReqSize = KeNumberProcessors * sizeof (SYSTEM_PROCESSORTIME_INFO);
 	/*
 	 * Check user buffer's size 
 	 */
-	if (Size < sizeof (SYSTEM_PROCESSORTIME_INFO))
+	if (Size < KeNumberProcessors * sizeof(SYSTEM_PROCESSORTIME_INFO))
 	{
 		return (STATUS_INFO_LENGTH_MISMATCH);
 	}
 
-        PsLookupProcessByProcessId((PVOID) 1, &TheIdleProcess);
-
 	CurrentTime.QuadPart = KeQueryInterruptTime();
+	Pcr = (PKPCR)KPCR_BASE;   
+	for (i = 0; i < KeNumberProcessors; i++)
+	{
 
-        Spi->TotalProcessorRunTime.QuadPart = 
-		TheIdleProcess->Pcb.KernelTime * 100000LL; // IdleTime
-        Spi->TotalProcessorTime.QuadPart =  KiKernelTime * 100000LL; // KernelTime
-        Spi->TotalProcessorUserTime.QuadPart = KiUserTime * 100000LL;
-        Spi->TotalDPCTime.QuadPart = KiDpcTime * 100000LL;
-        Spi->TotalInterruptTime.QuadPart = KiInterruptTime * 100000LL;
-        Spi->TotalInterrupts = KiInterruptCount; // Interrupt Count
-
-	ObDereferenceObject(TheIdleProcess);
-        
+	   Spi->TotalProcessorRunTime.QuadPart = (Pcr->PrcbData.IdleThread->KernelTime + Pcr->PrcbData.IdleThread->UserTime) * 100000LL; // IdleTime
+           Spi->TotalProcessorTime.QuadPart =  Pcr->PrcbData.KernelTime * 100000LL; // KernelTime
+           Spi->TotalProcessorUserTime.QuadPart = Pcr->PrcbData.UserTime * 100000LL;
+           Spi->TotalDPCTime.QuadPart = Pcr->PrcbData.DpcTime * 100000LL;
+           Spi->TotalInterruptTime.QuadPart = Pcr->PrcbData.InterruptTime * 100000LL;
+           Spi->TotalInterrupts = Pcr->PrcbData.InterruptCount; // Interrupt Count
+	   Spi++;
+//	   Pcr++;
+	   Pcr = (PKPCR)((ULONG_PTR)Pcr + PAGE_SIZE);
+	}
+     
 	return (STATUS_SUCCESS);
 }
 

reactos/ntoskrnl/include/internal
ke.h 1.58 -> 1.59
diff -u -r1.58 -r1.59
--- ke.h	13 Oct 2004 01:42:14 -0000	1.58
+++ ke.h	17 Oct 2004 15:39:29 -0000	1.59
@@ -100,12 +100,6 @@
 PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue);
 
 extern LARGE_INTEGER SystemBootTime;
-extern volatile ULONGLONG KiKernelTime;
-extern volatile ULONGLONG KiUserTime;
-extern volatile ULONGLONG KiDpcTime;
-extern volatile ULONGLONG KiInterruptTime;
-extern volatile ULONG KiInterruptCount;
-
 
 /* INITIALIZATION FUNCTIONS *************************************************/
 

reactos/ntoskrnl/ke/i386
irq.c 1.46 -> 1.47
diff -u -r1.46 -r1.47
--- irq.c	1 Oct 2004 20:09:57 -0000	1.46
+++ irq.c	17 Oct 2004 15:39:29 -0000	1.47
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: irq.c,v 1.46 2004/10/01 20:09:57 hbirr Exp $
+/* $Id: irq.c,v 1.47 2004/10/17 15:39:29 hbirr Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/i386/irq.c
@@ -443,7 +443,7 @@
     * the PIC.
     */
     
-   KiInterruptCount++;
+   KeGetCurrentKPCR()->PrcbData.InterruptCount++;
 
    /*
     * Notify the rest of the kernel of the raised irq level. For the

reactos/ntoskrnl/ke/i386
kernel.c 1.36 -> 1.37
diff -u -r1.36 -r1.37
--- kernel.c	17 Oct 2004 05:20:29 -0000	1.36
+++ kernel.c	17 Oct 2004 15:39:29 -0000	1.37
@@ -1,344 +1,347 @@
-/*
- *  ReactOS kernel
- *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/*
- * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/ke/i386/kernel.c
- * PURPOSE:         Initializes the kernel
- * PROGRAMMER:      David Welch (welch@mcmail.com)
- * UPDATE HISTORY:
- *                  Created 22/05/98
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntoskrnl.h>
-#define NDEBUG
-#include <internal/debug.h>
-
-/* GLOBALS *******************************************************************/
-
-ULONG KiPcrInitDone = 0;
-static ULONG PcrsAllocated = 0;
-static PFN_TYPE PcrPages[MAXIMUM_PROCESSORS];
-ULONG Ke386CpuidFlags, Ke386CpuidFlags2, Ke386CpuidExFlags;
-ULONG Ke386Cpuid = 0x300;
-ULONG Ke386CacheAlignment;
-CHAR Ke386CpuidVendor[13] = {0,};
-CHAR Ke386CpuidModel[49] = {0,};
-ULONG Ke386L1CacheSize;
-ULONG Ke386L2CacheSize;
-BOOLEAN Ke386NoExecute = FALSE;
-BOOLEAN Ke386Pae = FALSE;
-
-/* FUNCTIONS *****************************************************************/
-
-VOID INIT_FUNCTION STATIC
-Ki386GetCpuId(VOID)
-{
-   ULONG OrigFlags, Flags, FinalFlags;
-   ULONG MaxCpuidLevel;
-   ULONG Dummy, Ebx, Ecx, Edx;
-
-   Ke386CpuidFlags = Ke386CpuidFlags2 =  Ke386CpuidExFlags = 0;
-   Ke386CacheAlignment = 32;
-
-   /* Try to toggle the id bit in eflags. */
-   __asm__ ("pushfl\n\t"
-	    "popl %0\n\t"
-	    : "=r" (OrigFlags));
-   Flags = OrigFlags ^ X86_EFLAGS_ID;
-   __asm__ ("pushl %1\n\t"
-	    "popfl\n\t"
-	    "pushfl\n\t"
-	    "popl %0\n\t"
-	    : "=r" (FinalFlags)
-	    : "r" (Flags));
-   if ((OrigFlags & X86_EFLAGS_ID) == (FinalFlags & X86_EFLAGS_ID))
-   {
-      /* No cpuid supported. */
-      return;
-   }
-
-   /* Get the vendor name and the maximum cpuid level supported. */
-   Ki386Cpuid(0, &MaxCpuidLevel, (PULONG)&Ke386CpuidVendor[0], (PULONG)&Ke386CpuidVendor[8], (PULONG)&Ke386CpuidVendor[4]);
-   if (MaxCpuidLevel > 0)
-   { 
-      /* Get the feature flags. */
-      Ki386Cpuid(1, &Ke386Cpuid, &Ebx, &Ke386CpuidFlags2, &Ke386CpuidFlags);
-      /* Get the cache alignment, if it is available */
-      if (Ke386CpuidFlags & (1<<19))
-      {
-         Ke386CacheAlignment = ((Ebx >> 8) & 0xff) * 8;
-      }
-   }
-
-   /* Get the maximum extended cpuid level supported. */
-   Ki386Cpuid(0x80000000, &MaxCpuidLevel, &Dummy, &Dummy, &Dummy);
-   if (MaxCpuidLevel > 0)
-   {
-      /* Get the extended feature flags. */
-      Ki386Cpuid(0x80000001, &Dummy, &Dummy, &Dummy, &Ke386CpuidExFlags);
-   }
-
-   /* Get the model name. */
-   if (MaxCpuidLevel >= 0x80000004)
-   {
-      PULONG v = (PULONG)&Ke386CpuidModel;
-      Ki386Cpuid(0x80000002, v, v + 1, v + 2, v + 3);
-      Ki386Cpuid(0x80000003, v + 4, v + 5, v + 6, v + 7);
-      Ki386Cpuid(0x80000004, v + 8, v + 9, v + 10, v + 11);
-   }
-
-   /* Get the L1 cache size */
-   if (MaxCpuidLevel >= 0x80000005)
-   {
-      Ki386Cpuid(0x80000005, &Dummy, &Dummy, &Ecx, &Edx);
-      Ke386L1CacheSize = (Ecx >> 24)+(Edx >> 24);
-      if ((Ecx & 0xff) > 0)
-      {
-         Ke386CacheAlignment = Ecx & 0xff;
-      }
-   }
-
-   /* Get the L2 cache size */
-   if (MaxCpuidLevel >= 0x80000006)
-   {
-      Ki386Cpuid(0x80000006, &Dummy, &Dummy, &Ecx, &Dummy);
-      Ke386L2CacheSize = Ecx >> 16;
-   }
-}
-
-VOID INIT_FUNCTION
-KePrepareForApplicationProcessorInit(ULONG Id)
-{
-  MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &PcrPages[Id]);
-  KiGdtPrepareForApplicationProcessorInit(Id);
-}
-
-VOID
-KeApplicationProcessorInit(VOID)
-{
-  PKPCR KPCR;
-  ULONG Offset;
-
-  /*
-   * Create a PCR for this processor
-   */
-  Offset = InterlockedIncrement((LONG *)&PcrsAllocated) - 1;
-  KPCR = (PKPCR)(KPCR_BASE + (Offset * PAGE_SIZE));
-  MmCreateVirtualMappingForKernel((PVOID)KPCR,
-				  PAGE_READWRITE,
-				  &PcrPages[Offset],
-				  1);
-  memset(KPCR, 0, PAGE_SIZE);
-  KPCR->ProcessorNumber = (UCHAR)Offset;
-  KPCR->Tib.Self = &KPCR->Tib;
-  KPCR->Irql = HIGH_LEVEL;
-
-  /* Mark the end of the exception handler list */
-  KPCR->Tib.ExceptionList = (PVOID)-1;
-
-  /*
-   * Initialize the GDT
-   */
-  KiInitializeGdt(KPCR);
-  
-  /*
-   * It is now safe to process interrupts
-   */
-  KeLowerIrql(DISPATCH_LEVEL);
-
-  /*
-   * Initialize the TSS
-   */
-  Ki386ApplicationProcessorInitializeTSS();
-
-  /*
-   * Initialize a default LDT
-   */
-  Ki386InitializeLdt();
-
-  if (Ke386CpuidFlags & X86_FEATURE_PGE)
-  {
-     /* Enable global pages */
-     Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE);
-  }
-  
-  /* Enable PAE mode */
-  if (Ke386CpuidFlags & X86_FEATURE_PAE)
-  {
-     MiEnablePAE(NULL);
-  }
-
-  /* Now we can enable interrupts. */
-  Ke386EnableInterrupts();
-}
-
-VOID INIT_FUNCTION
-KeInit1(PCHAR CommandLine, PULONG LastKernelAddress)
-{
-   PKPCR KPCR;
-   BOOLEAN Pae = FALSE;
-   BOOLEAN NoExecute = FALSE;
-   PCHAR p1, p2;
-   extern USHORT KiBootGdt[];
-   extern KTSS KiBootTss;
-
-   KiCheckFPU();
-   
-   KiInitializeGdt (NULL);
-   Ki386BootInitializeTSS();
-   KeInitExceptions ();
-   KeInitInterrupts ();
-
-   /* 
-    * Initialize the initial PCR region. We can't allocate a page
-    * with MmAllocPage() here because MmInit1() has not yet been
-    * called, so we use a predefined page in low memory 
-    */
-   KPCR = (PKPCR)KPCR_BASE;
-   memset(KPCR, 0, PAGE_SIZE);
-   KPCR->Self = (PKPCR)KPCR_BASE;
-   KPCR->Irql = HIGH_LEVEL;
-   KPCR->Tib.Self  = &KPCR->Tib;
-   KPCR->GDT = KiBootGdt;
-   KPCR->IDT = (PUSHORT)KiIdt;
-   KPCR->TSS = &KiBootTss;
-   KPCR->ProcessorNumber = 0;
-   KiPcrInitDone = 1;
-   PcrsAllocated++;
-
-   /* Mark the end of the exception handler list */
-   KPCR->Tib.ExceptionList = (PVOID)-1;
-
-   Ki386InitializeLdt();
-   
-   /* Get processor information. */
-   Ki386GetCpuId();
-
-   if (Ke386CpuidFlags & X86_FEATURE_PGE)
-   {
-      ULONG Flags;
-      /* Enable global pages */
-      Ke386SaveFlags(Flags);
-      Ke386DisableInterrupts();
-      Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE);
-      Ke386RestoreFlags(Flags);
-   }
-
-   /* Search for pae and noexecute */
-   p1 = (PCHAR)KeLoaderBlock.CommandLine;
-   while(*p1 && (p2 = strchr(p1, '/')))
-   {
-      p2++;
-      if (!_strnicmp(p2, "PAE", 3))
-      {
-	 if (p2[3] == ' ' || p2[3] == 0)
-	 {
-	    p2 += 3;
-	    Pae = TRUE;
-	 }
-      }
-      else if (!_strnicmp(p2, "NOEXECUTE", 9))
-      {
-         if (p2[9] == ' ' || p2[9] == '=' || p2[9] == 0)
-	 {
-	    p2 += 9;
-	    NoExecute = TRUE;
-	 }
-      }
-      p1 = p2;
-   }
-
-   /* 
-    * FIXME:
-    *   Make the detection of the noexecute feature more portable.
-    */
-   if(((Ke386Cpuid >> 8) & 0xf) == 0xf &&
-      0 == strcmp("AuthenticAMD", Ke386CpuidVendor))
-   {
-      if (NoExecute)
-      {
-         ULONG Flags, l, h;
-         Ke386SaveFlags(Flags);
-         Ke386DisableInterrupts();
-
-	 Ke386Rdmsr(0xc0000080, l, h);
-	 l |= (1 << 11);
-	 Ke386Wrmsr(0xc0000080, l, h);
-	 Ke386NoExecute = TRUE;
-         Ke386RestoreFlags(Flags);
-      }
-   }  
-   else
-   {
-      NoExecute=FALSE;
-   }
-
-      
-   /* Enable PAE mode */
-   if ((Pae && (Ke386CpuidFlags & X86_FEATURE_PAE)) || NoExecute)
-   {
-      MiEnablePAE((PVOID*)LastKernelAddress);
-   }
-}
-
-VOID INIT_FUNCTION
-KeInit2(VOID)
-{
-   KeInitDpc();
-   KeInitializeBugCheck();
-   KeInitializeDispatcher();
-   KeInitializeTimerImpl();
-
-   if (Ke386CpuidFlags & X86_FEATURE_PAE)
-   {
-      DPRINT1("CPU supports PAE mode\n");
-      if (Ke386Pae)
-      {
-         DPRINT1("CPU runs in PAE mode\n");
-         if (Ke386NoExecute)
-         {
-            DPRINT1("NoExecute is enabled\n");
-	 }
-      }
-      else
-      {
-         DPRINT1("CPU doesn't run in PAE mode\n");
-      }
-   }
-   if (Ke386CpuidVendor[0])
-   {
-      DPRINT1("CPU Vendor: %s\n", Ke386CpuidVendor);
-   }
-   if (Ke386CpuidModel[0])
-   {
-      DPRINT1("CPU Model:  %s\n", Ke386CpuidModel);
-   }
-
-   DPRINT1("Ke386CacheAlignment: %d\n", Ke386CacheAlignment);
-   if (Ke386L1CacheSize)
-   {
-      DPRINT1("Ke386L1CacheSize: %dkB\n", Ke386L1CacheSize);
-   }
-   if (Ke386L2CacheSize)
-   {
-      DPRINT1("Ke386L2CacheSize: %dkB\n", Ke386L2CacheSize);
-   }
-}
+/*
+ *  ReactOS kernel
+ *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*
+ * PROJECT:         ReactOS kernel
+ * FILE:            ntoskrnl/ke/i386/kernel.c
+ * PURPOSE:         Initializes the kernel
+ * PROGRAMMER:      David Welch (welch@mcmail.com)
+ * UPDATE HISTORY:
+ *                  Created 22/05/98
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <internal/debug.h>
+
+/* GLOBALS *******************************************************************/
+
+ULONG KiPcrInitDone = 0;
+static ULONG PcrsAllocated = 0;
+static PFN_TYPE PcrPages[MAXIMUM_PROCESSORS];
+ULONG Ke386CpuidFlags, Ke386CpuidFlags2, Ke386CpuidExFlags;
+ULONG Ke386Cpuid = 0x300;
+ULONG Ke386CacheAlignment;
+CHAR Ke386CpuidVendor[13] = {0,};
+CHAR Ke386CpuidModel[49] = {0,};
+ULONG Ke386L1CacheSize;
+ULONG Ke386L2CacheSize;
+BOOLEAN Ke386NoExecute = FALSE;
+BOOLEAN Ke386Pae = FALSE;
+
+/* FUNCTIONS *****************************************************************/
+
+VOID INIT_FUNCTION STATIC
+Ki386GetCpuId(VOID)
+{
+   ULONG OrigFlags, Flags, FinalFlags;
+   ULONG MaxCpuidLevel;
+   ULONG Dummy, Ebx, Ecx, Edx;
+
+   Ke386CpuidFlags = Ke386CpuidFlags2 =  Ke386CpuidExFlags = 0;
+   Ke386CacheAlignment = 32;
+
+   /* Try to toggle the id bit in eflags. */
+   __asm__ ("pushfl\n\t"
+	    "popl %0\n\t"
+	    : "=r" (OrigFlags));
+   Flags = OrigFlags ^ X86_EFLAGS_ID;
+   __asm__ ("pushl %1\n\t"
+	    "popfl\n\t"
+	    "pushfl\n\t"
+	    "popl %0\n\t"
+	    : "=r" (FinalFlags)
+	    : "r" (Flags));
+   if ((OrigFlags & X86_EFLAGS_ID) == (FinalFlags & X86_EFLAGS_ID))
+   {
+      /* No cpuid supported. */
+      return;
+   }
+
+   /* Get the vendor name and the maximum cpuid level supported. */
+   Ki386Cpuid(0, &MaxCpuidLevel, (PULONG)&Ke386CpuidVendor[0], (PULONG)&Ke386CpuidVendor[8], (PULONG)&Ke386CpuidVendor[4]);
+   if (MaxCpuidLevel > 0)
+   { 
+      /* Get the feature flags. */
+      Ki386Cpuid(1, &Ke386Cpuid, &Ebx, &Ke386CpuidFlags2, &Ke386CpuidFlags);
+      /* Get the cache alignment, if it is available */
+      if (Ke386CpuidFlags & (1<<19))
+      {
+         Ke386CacheAlignment = ((Ebx >> 8) & 0xff) * 8;
+      }
+   }
+
+   /* Get the maximum extended cpuid level supported. */
+   Ki386Cpuid(0x80000000, &MaxCpuidLevel, &Dummy, &Dummy, &Dummy);
+   if (MaxCpuidLevel > 0)
+   {
+      /* Get the extended feature flags. */
+      Ki386Cpuid(0x80000001, &Dummy, &Dummy, &Dummy, &Ke386CpuidExFlags);
+   }
+
+   /* Get the model name. */
+   if (MaxCpuidLevel >= 0x80000004)
+   {
+      PULONG v = (PULONG)&Ke386CpuidModel;
+      Ki386Cpuid(0x80000002, v, v + 1, v + 2, v + 3);
+      Ki386Cpuid(0x80000003, v + 4, v + 5, v + 6, v + 7);
+      Ki386Cpuid(0x80000004, v + 8, v + 9, v + 10, v + 11);
+   }
+
+   /* Get the L1 cache size */
+   if (MaxCpuidLevel >= 0x80000005)
+   {
+      Ki386Cpuid(0x80000005, &Dummy, &Dummy, &Ecx, &Edx);
+      Ke386L1CacheSize = (Ecx >> 24)+(Edx >> 24);
+      if ((Ecx & 0xff) > 0)
+      {
+         Ke386CacheAlignment = Ecx & 0xff;
+      }
+   }
+
+   /* Get the L2 cache size */
+   if (MaxCpuidLevel >= 0x80000006)
+   {
+      Ki386Cpuid(0x80000006, &Dummy, &Dummy, &Ecx, &Dummy);
+      Ke386L2CacheSize = Ecx >> 16;
+   }
+}
+
+VOID INIT_FUNCTION
+KePrepareForApplicationProcessorInit(ULONG Id)
+{
+  MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &PcrPages[Id]);
+  KiGdtPrepareForApplicationProcessorInit(Id);
+}
+
+VOID
+KeApplicationProcessorInit(VOID)
+{
+  PKPCR KPCR;
+  ULONG Offset;
+
+  if (Ke386CpuidFlags & X86_FEATURE_PGE)
+  {
+     /* Enable global pages */
+     Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE);
+  }
+  
+  /* Enable PAE mode */
+  if (Ke386CpuidFlags & X86_FEATURE_PAE)
+  {
+     MiEnablePAE(NULL);
+  }
+
+  /*
+   * Create a PCR for this processor
+   */
+  Offset = InterlockedIncrement((LONG *)&PcrsAllocated) - 1;
+  KPCR = (PKPCR)(KPCR_BASE + (Offset * PAGE_SIZE));
+  MmCreateVirtualMappingForKernel((PVOID)KPCR,
+				  PAGE_READWRITE,
+				  &PcrPages[Offset],
+				  1);
+  memset(KPCR, 0, PAGE_SIZE);
+  KPCR->ProcessorNumber = (UCHAR)Offset;
+  KPCR->Tib.Self = &KPCR->Tib;
+  KPCR->Self = KPCR;
+  KPCR->Irql = HIGH_LEVEL;
+
+  /* Mark the end of the exception handler list */
+  KPCR->Tib.ExceptionList = (PVOID)-1;
+
+  /*
+   * Initialize the GDT
+   */
+  KiInitializeGdt(KPCR);
+  
+  KeInitDpc();
+
+  /*
+   * It is now safe to process interrupts
+   */
+  KeLowerIrql(DISPATCH_LEVEL);
+
+  /*
+   * Initialize the TSS
+   */
+  Ki386ApplicationProcessorInitializeTSS();
+
+  /*
+   * Initialize a default LDT
+   */
+  Ki386InitializeLdt();
+
+  /* Now we can enable interrupts. */
+  Ke386EnableInterrupts();
+}
+
+VOID INIT_FUNCTION
+KeInit1(PCHAR CommandLine, PULONG LastKernelAddress)
+{
+   PKPCR KPCR;
+   BOOLEAN Pae = FALSE;
+   BOOLEAN NoExecute = FALSE;
+   PCHAR p1, p2;
+   extern USHORT KiBootGdt[];
+   extern KTSS KiBootTss;
+
+   KiCheckFPU();
+   
+   KiInitializeGdt (NULL);
+   Ki386BootInitializeTSS();
+   KeInitExceptions ();
+   KeInitInterrupts ();
+
+   /* 
+    * Initialize the initial PCR region. We can't allocate a page
+    * with MmAllocPage() here because MmInit1() has not yet been
+    * called, so we use a predefined page in low memory 
+    */
+   KPCR = (PKPCR)KPCR_BASE;
+   memset(KPCR, 0, PAGE_SIZE);
+   KPCR->Self = KPCR;
+   KPCR->Irql = HIGH_LEVEL;
+   KPCR->Tib.Self  = &KPCR->Tib;
+   KPCR->GDT = KiBootGdt;
+   KPCR->IDT = (PUSHORT)KiIdt;
+   KPCR->TSS = &KiBootTss;
+   KPCR->ProcessorNumber = 0;
+   KiPcrInitDone = 1;
+   PcrsAllocated++;
+
+   /* Mark the end of the exception handler list */
+   KPCR->Tib.ExceptionList = (PVOID)-1;
+
+   Ki386InitializeLdt();
+   
+   /* Get processor information. */
+   Ki386GetCpuId();
+
+   if (Ke386CpuidFlags & X86_FEATURE_PGE)
+   {
+      ULONG Flags;
+      /* Enable global pages */
+      Ke386SaveFlags(Flags);
+      Ke386DisableInterrupts();
+      Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE);
+      Ke386RestoreFlags(Flags);
+   }
+
+   /* Search for pae and noexecute */
+   p1 = (PCHAR)KeLoaderBlock.CommandLine;
+   while(*p1 && (p2 = strchr(p1, '/')))
+   {
+      p2++;
+      if (!_strnicmp(p2, "PAE", 3))
+      {
+	 if (p2[3] == ' ' || p2[3] == 0)
+	 {
+	    p2 += 3;
+	    Pae = TRUE;
+	 }
+      }
+      else if (!_strnicmp(p2, "NOEXECUTE", 9))
+      {
+         if (p2[9] == ' ' || p2[9] == '=' || p2[9] == 0)
+	 {
+	    p2 += 9;
+	    NoExecute = TRUE;
+	 }
+      }
+      p1 = p2;
+   }
+
+   /* 
+    * FIXME:
+    *   Make the detection of the noexecute feature more portable.
+    */
+   if(((Ke386Cpuid >> 8) & 0xf) == 0xf &&
+      0 == strcmp("AuthenticAMD", Ke386CpuidVendor))
+   {
+      if (NoExecute)
+      {
+         ULONG Flags, l, h;
+         Ke386SaveFlags(Flags);
+         Ke386DisableInterrupts();
+
+	 Ke386Rdmsr(0xc0000080, l, h);
+	 l |= (1 << 11);
+	 Ke386Wrmsr(0xc0000080, l, h);
+	 Ke386NoExecute = TRUE;
+         Ke386RestoreFlags(Flags);
+      }
+   }  
+   else
+   {
+      NoExecute=FALSE;
+   }
+
+      
+   /* Enable PAE mode */
+   if ((Pae && (Ke386CpuidFlags & X86_FEATURE_PAE)) || NoExecute)
+   {
+      MiEnablePAE((PVOID*)LastKernelAddress);
+   }
+}
+
+VOID INIT_FUNCTION
+KeInit2(VOID)
+{
+   KeInitDpc();
+   KeInitializeBugCheck();
+   KeInitializeDispatcher();
+   KeInitializeTimerImpl();
+
+   if (Ke386CpuidFlags & X86_FEATURE_PAE)
+   {
+      DPRINT1("CPU supports PAE mode\n");
+      if (Ke386Pae)
+      {
+         DPRINT1("CPU runs in PAE mode\n");
+         if (Ke386NoExecute)
+         {
+            DPRINT1("NoExecute is enabled\n");
+	 }
+      }
+      else
+      {
+         DPRINT1("CPU doesn't run in PAE mode\n");
+      }
+   }
+   if (Ke386CpuidVendor[0])
+   {
+      DPRINT1("CPU Vendor: %s\n", Ke386CpuidVendor);
+   }
+   if (Ke386CpuidModel[0])
+   {
+      DPRINT1("CPU Model:  %s\n", Ke386CpuidModel);
+   }
+
+   DPRINT1("Ke386CacheAlignment: %d\n", Ke386CacheAlignment);
+   if (Ke386L1CacheSize)
+   {
+      DPRINT1("Ke386L1CacheSize: %dkB\n", Ke386L1CacheSize);
+   }
+   if (Ke386L2CacheSize)
+   {
+      DPRINT1("Ke386L2CacheSize: %dkB\n", Ke386L2CacheSize);
+   }
+}

reactos/ntoskrnl/ke
dpc.c 1.37 -> 1.38
diff -u -r1.37 -r1.38
--- dpc.c	13 Oct 2004 01:42:14 -0000	1.37
+++ dpc.c	17 Oct 2004 15:39:29 -0000	1.38
@@ -18,7 +18,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: dpc.c,v 1.37 2004/10/13 01:42:14 ion Exp $
+/* $Id: dpc.c,v 1.38 2004/10/17 15:39:29 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -44,21 +44,6 @@
 
 /* GLOBALS ******************************************************************/
 
-static LIST_ENTRY DpcQueueHead; /* Head of the list of pending DPCs */
-static KSPIN_LOCK DpcQueueLock; /* Lock for the above list */
-
-/*
- * Number of pending DPCs. This is inspected by
- * the idle thread to determine if the queue needs to
- * be run down
- */
-ULONG DpcQueueSize = 0;
-
-/*
- * Number of DPC's Processed.
- */
-ULONG DpcCount = 0;
-
 /* FUNCTIONS ****************************************************************/
 
 /*
@@ -95,39 +80,46 @@
    PLIST_ENTRY current_entry;
    PKDPC current;
    KIRQL oldlvl;
+   PKPCR Pcr;
 
    assert_irql(DISPATCH_LEVEL);
 
-   if (DpcQueueSize == 0)
+   Pcr = KeGetCurrentKPCR();
+
+   if (Pcr->PrcbData.DpcData[0].DpcQueueDepth == 0)
      {
 	return;
      }
 
    KeRaiseIrql(HIGH_LEVEL, &oldlvl);
-   KiAcquireSpinLock(&DpcQueueLock);
+   KiAcquireSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
 
-   DpcCount = DpcCount + DpcQueueSize;
-   
-   while (!IsListEmpty(&DpcQueueHead))
+   while (!IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead))
    {
-      current_entry = RemoveHeadList(&DpcQueueHead);
-      DpcQueueSize--;
+      assert(Pcr->PrcbData.DpcData[0].DpcQueueDepth > 0);
+
+      current_entry = RemoveHeadList(&Pcr->PrcbData.DpcData[0].DpcListHead);
+      Pcr->PrcbData.DpcData[0].DpcQueueDepth--;
+      Pcr->PrcbData.DpcData[0].DpcCount++;
 
-      assert(DpcQueueSize || IsListEmpty(&DpcQueueHead));
+      assert((Pcr->PrcbData.DpcData[0].DpcQueueDepth == 0 && IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)) ||
+             (Pcr->PrcbData.DpcData[0].DpcQueueDepth > 0 && !IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)));	     
 
       current = CONTAINING_RECORD(current_entry,KDPC,DpcListEntry);
       current->Lock=FALSE;
-      KiReleaseSpinLock(&DpcQueueLock);
+      Pcr->PrcbData.DpcRoutineActive = 1;
+      KiReleaseSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
       KeLowerIrql(oldlvl);
       current->DeferredRoutine(current,current->DeferredContext,
 			       current->SystemArgument1,
 			       current->SystemArgument2);
 
       KeRaiseIrql(HIGH_LEVEL, &oldlvl);
-      KiAcquireSpinLock(&DpcQueueLock);
+      KiAcquireSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
+      Pcr->PrcbData.DpcRoutineActive = 0;
    }
 
-   KiReleaseSpinLock(&DpcQueueLock);
+   KiReleaseSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
    KeLowerIrql(oldlvl);
 }
 
@@ -170,20 +162,24 @@
 {
    KIRQL oldIrql;
    BOOLEAN WasInQueue;
+   PKPCR Pcr;
+
+   Pcr = KeGetCurrentKPCR();
 
    KeRaiseIrql(HIGH_LEVEL, &oldIrql);
-   KiAcquireSpinLock(&DpcQueueLock);
+   KiAcquireSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
    WasInQueue = Dpc->Lock ? TRUE : FALSE;
    if (WasInQueue)
      {
 	RemoveEntryList(&Dpc->DpcListEntry);
-	DpcQueueSize--;
+	Pcr->PrcbData.DpcData[0].DpcQueueDepth--;
 	Dpc->Lock=0;
      }
 
-   assert(DpcQueueSize || IsListEmpty(&DpcQueueHead));
+   assert((Pcr->PrcbData.DpcData[0].DpcQueueDepth == 0 && IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)) ||
+          (Pcr->PrcbData.DpcData[0].DpcQueueDepth > 0 && !IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)));	     
 
-   KiReleaseSpinLock(&DpcQueueLock);
+   KiReleaseSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
    KeLowerIrql(oldIrql);
 
    return WasInQueue;
@@ -207,6 +203,8 @@
  */
 {
    KIRQL oldlvl;
+   PKPCR Pcr;
+
    DPRINT("KeInsertQueueDpc(dpc %x, SystemArgument1 %x, SystemArgument2 %x)\n",
 	  Dpc, SystemArgument1, SystemArgument2);
 
@@ -220,14 +218,21 @@
      {
 	return(FALSE);
      }
+
+   Pcr = KeGetCurrentKPCR();
    KeRaiseIrql(HIGH_LEVEL, &oldlvl);
-   KiAcquireSpinLock(&DpcQueueLock);
-   assert(DpcQueueSize || IsListEmpty(&DpcQueueHead));
-   InsertHeadList(&DpcQueueHead,&Dpc->DpcListEntry);
+   KiAcquireSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
+   assert((Pcr->PrcbData.DpcData[0].DpcQueueDepth == 0 && IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)) ||
+          (Pcr->PrcbData.DpcData[0].DpcQueueDepth > 0 && !IsListEmpty(&Pcr->PrcbData.DpcData[0].DpcListHead)));	     
+   InsertHeadList(&Pcr->PrcbData.DpcData[0].DpcListHead,&Dpc->DpcListEntry);
    DPRINT("Dpc->DpcListEntry.Flink %x\n", Dpc->DpcListEntry.Flink);
-   DpcQueueSize++;
+   Pcr->PrcbData.DpcData[0].DpcQueueDepth++;
    Dpc->Lock=(PULONG)1;
-   KiReleaseSpinLock(&DpcQueueLock);
+   if (Pcr->PrcbData.MaximumDpcQueueDepth < Pcr->PrcbData.DpcData[0].DpcQueueDepth)
+     {
+       Pcr->PrcbData.MaximumDpcQueueDepth = Pcr->PrcbData.DpcData[0].DpcQueueDepth;    
+     }
+   KiReleaseSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
    KeLowerIrql(oldlvl);
    DPRINT("DpcQueueHead.Flink %x\n",DpcQueueHead.Flink);
    DPRINT("Leaving KeInsertQueueDpc()\n",0);
@@ -272,8 +277,12 @@
  * FUNCTION: Initialize DPC handling
  */
 {
-   InitializeListHead(&DpcQueueHead);
-   KeInitializeSpinLock(&DpcQueueLock);
+   PKPCR Pcr;
+   Pcr = KeGetCurrentKPCR();
+   InitializeListHead(&Pcr->PrcbData.DpcData[0].DpcListHead);
+   KeInitializeSpinLock(&Pcr->PrcbData.DpcData[0].DpcLock);
+   Pcr->PrcbData.MaximumDpcQueueDepth = 0;
+   Pcr->PrcbData.DpcData[0].DpcQueueDepth = 0;    
 }
 
 /* EOF */

reactos/ntoskrnl/ke
timer.c 1.80 -> 1.81
diff -u -r1.80 -r1.81
--- timer.c	13 Oct 2004 22:27:03 -0000	1.80
+++ timer.c	17 Oct 2004 15:39:29 -0000	1.81
@@ -1,4 +1,4 @@
-/* $Id: timer.c,v 1.80 2004/10/13 22:27:03 ion Exp $
+/* $Id: timer.c,v 1.81 2004/10/17 15:39:29 hbirr Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -34,11 +34,6 @@
 #endif
 
 CHAR KiTimerSystemAuditing = 0;
-volatile ULONGLONG KiKernelTime;
-volatile ULONGLONG KiUserTime;
-volatile ULONGLONG KiDpcTime;
-volatile ULONGLONG KiInterruptTime;
-volatile ULONG KiInterruptCount;
 
 /*
  * Number of timer interrupts since initialisation
@@ -723,27 +718,29 @@
 {
    PKTHREAD CurrentThread;
    PEPROCESS ThreadsProcess;
+   PKPCR Pcr;
 
+   Pcr = KeGetCurrentKPCR();
 
 /*
  *  Make sure no counting can take place until Processes and Threads are
  *  running!
  */
-   if ((PsInitialSystemProcess == NULL) || (PsIdleThreadHandle == NULL) || 
+   if ((PsInitialSystemProcess == NULL) || (Pcr->PrcbData.IdleThread == NULL) || 
         (KiTimerSystemAuditing == 0))
      {
        return;
      }
-   	
-   DPRINT("KiKernelTime  %u, KiUserTime %u \n", KiKernelTime, KiUserTime);
+
+   DPRINT("KernelTime  %u, UserTime %u \n", Kpcr->PrcbData.KernelTime, Kpcr->PrcbData.UserTime);
 
    if (oldIrql > DISPATCH_LEVEL)
    {
-      KiInterruptTime++;
+      Pcr->PrcbData.InterruptTime++;
    }
    else if (oldIrql == DISPATCH_LEVEL)
    {
-      KiDpcTime++;
+      Pcr->PrcbData.DpcTime++;
    }
    else
    {
@@ -762,7 +759,7 @@
          ThreadsProcess->Pcb.UserTime++;
 #endif
          CurrentThread->UserTime++;
-         KiUserTime++;
+         Pcr->PrcbData.UserTime++;
       }
       else
       {
@@ -772,7 +769,7 @@
          ThreadsProcess->Pcb.KernelTime++;  
 #endif
          CurrentThread->KernelTime++;
-         KiKernelTime++;
+         Pcr->PrcbData.KernelTime++;
       }  	
    }
 } 
@@ -791,7 +788,7 @@
 
 
 /*
- * @implemented
+ * @unimplemented
  */
 VOID
 STDCALL
@@ -799,14 +796,14 @@
 	IN PKTRAP_FRAME	TrapFrame
 )
 {
-	KIRQL OldIrql;
+	KIRQL OldIrql = PASSIVE_LEVEL;
 	
 	/* These are equivalent... we should just remove the Ki and stick it here... */
 	KiUpdateProcessThreadTime(OldIrql, (PKIRQ_TRAPFRAME)TrapFrame);
 }
 
 /*
- * @implemented
+ * @unimplemented
  */
 VOID 
 STDCALL
@@ -815,7 +812,7 @@
 	IN ULONG        Increment
 )
 {
-	KIRQL OldIrql;
+	KIRQL OldIrql = PASSIVE_LEVEL;
 	
 	/* These are equivalent... we should just remove the Ki and stick it here... */
 	KiUpdateSystemTime(OldIrql, (PKIRQ_TRAPFRAME)TrapFrame);

reactos/ntoskrnl/ps
idle.c 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- idle.c	15 Aug 2004 16:39:10 -0000	1.27
+++ idle.c	17 Oct 2004 15:39:29 -0000	1.28
@@ -16,10 +16,6 @@
 
 /* GLOBALS *******************************************************************/
 
-HANDLE PsIdleThreadHandle = NULL;
-extern ULONG DpcQueueSize;
-PETHREAD PiIdleThread;
-
 /* FUNCTIONS *****************************************************************/
 
 /** System idle thread procedure
@@ -29,10 +25,12 @@
 PsIdleThreadMain(PVOID Context)
 {
    KIRQL oldlvl;
+
+   PKPCR Pcr = KeGetCurrentKPCR();
    
    for(;;)
      {
-       if (DpcQueueSize > 0)
+       if (Pcr->PrcbData.DpcData[0].DpcQueueDepth > 0)
 	 {
 	   KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);
 	   KiDispatchInterrupt();
@@ -55,8 +53,10 @@
    KPRIORITY Priority;
    ULONG Affinity;
    NTSTATUS Status;
+   PETHREAD IdleThread;
+   HANDLE IdleThreadHandle;
    
-   Status = PsCreateSystemThread(&PsIdleThreadHandle,
+   Status = PsCreateSystemThread(&IdleThreadHandle,
 			THREAD_ALL_ACCESS,
 			NULL,
 			NULL,
@@ -70,7 +70,7 @@
    }   
 
    Priority = LOW_PRIORITY;
-   Status = NtSetInformationThread(PsIdleThreadHandle,
+   Status = NtSetInformationThread(IdleThreadHandle,
 			  ThreadPriority,
 			  &Priority,
 			  sizeof(Priority));
@@ -80,11 +80,22 @@
    }
    
    Affinity = 1 << 0;
-   Status = NtSetInformationThread(PsIdleThreadHandle,
+   Status = NtSetInformationThread(IdleThreadHandle,
 			  ThreadAffinityMask,
 			  &Affinity,
 			  sizeof(Affinity));
    if(!NT_SUCCESS(Status)) {
 	DPRINT("Couldn't set Affinity Mask to Idle System Thread!");
-   }   
+   }
+   Status = ObReferenceObjectByHandle(IdleThreadHandle,
+				      THREAD_ALL_ACCESS,
+				      PsThreadType,
+				      KernelMode,
+				      (PVOID*)&IdleThread,
+				      NULL);
+   if(!NT_SUCCESS(Status)) {
+	DPRINT("Couldn't get pointer to Idle System Thread!");
+   }
+   KeGetCurrentKPCR()->PrcbData.IdleThread = &IdleThread->Tcb;
+   NtClose(IdleThreadHandle);
 }

reactos/ntoskrnl/ps
thread.c 1.135 -> 1.136
diff -u -r1.135 -r1.136
--- thread.c	3 Oct 2004 03:03:54 -0000	1.135
+++ thread.c	17 Oct 2004 15:39:29 -0000	1.136
@@ -1,4 +1,4 @@
-/* $Id: thread.c,v 1.135 2004/10/03 03:03:54 ion Exp $
+/* $Id: thread.c,v 1.136 2004/10/17 15:39:29 hbirr Exp $
  *
  * COPYRIGHT:              See COPYING in the top level directory
  * PROJECT:                ReactOS kernel
@@ -41,7 +41,6 @@
 static LIST_ENTRY PriorityListHead[MAXIMUM_PRIORITY];
 static ULONG PriorityListMask = 0;
 static BOOLEAN DoneInitYet = FALSE;
-static PETHREAD IdleThreads[MAXIMUM_PROCESSORS];
 static KEVENT PiReaperThreadEvent;
 static BOOLEAN PiReaperThreadShouldTerminate = FALSE;
 
@@ -630,8 +629,7 @@
 VOID
 PsApplicationProcessorInit(VOID)
 {
-  KeGetCurrentKPCR()->PrcbData.CurrentThread =
-    (PVOID)IdleThreads[KeGetCurrentProcessorNumber()];
+  KeGetCurrentKPCR()->PrcbData.CurrentThread = KeGetCurrentKPCR()->PrcbData.IdleThread;
 }
 
 VOID INIT_FUNCTION
@@ -639,6 +637,7 @@
 {
   PETHREAD IdleThread;
   HANDLE IdleThreadHandle;
+  PKPCR Pcr = (PKPCR)((ULONG_PTR)KPCR_BASE + Id * PAGE_SIZE);
 
   PsInitializeThread(NULL,
 		     &IdleThread,
@@ -650,7 +649,7 @@
   IdleThread->Tcb.FreezeCount = 0;
   IdleThread->Tcb.UserAffinity = 1 << Id;
   IdleThread->Tcb.Priority = LOW_PRIORITY;
-  IdleThreads[Id] = IdleThread;
+  Pcr->PrcbData.IdleThread = &IdleThread->Tcb;
 
   NtClose(IdleThreadHandle);
   DPRINT("IdleThread for Processor %d has PID %d\n",

reactos/ntoskrnl
ntoskrnl.def 1.194 -> 1.195
diff -u -r1.194 -r1.195
--- ntoskrnl.def	17 Oct 2004 13:08:26 -0000	1.194
+++ ntoskrnl.def	17 Oct 2004 15:39:30 -0000	1.195
@@ -1,4 +1,4 @@
-; $Id: ntoskrnl.def,v 1.194 2004/10/17 13:08:26 navaraf Exp $
+; $Id: ntoskrnl.def,v 1.195 2004/10/17 15:39:30 hbirr Exp $
 ;
 ; reactos/ntoskrnl/ntoskrnl.def
 ;
@@ -62,7 +62,6 @@
 DbgPrintReturnControlC
 DbgQueryDebugFilterState@8
 DbgSetDebugFilterState@12
-DpcQueueSize DATA
 @ExAcquireFastMutexUnsafe@4
 ExAcquireResourceExclusive@8
 ExAcquireResourceExclusiveLite@8
CVSspam 0.2.8