Author: sginsberg
Date: Thu Oct 29 20:58:41 2009
New Revision: 43832
URL:
http://svn.reactos.org/svn/reactos?rev=43832&view=rev
Log:
- INITIAL_STALL_COUNT makes more sense in decimal (100) than hex (0x64) so define it that
way.
- Protect CMOS access with the CMOS spinlock.
- Add CMOS initialization to set up the default value of the CMOS century byte offset (not
used yet).
- Stub out profile interrupt support in HAL. Register and stub out the profile interrupt
handler, but don't handle it yet as vital parts of the rest of the implementation is
missing.
- Fix several bugs in the kernel profile implementation:
- Don't hardcode to PROFILE_LEVEL when raising IRQL : HAL can override this, so use
KiProfileIrql. Also, starting/stopping profile interrupts must be done at the profile
IRQL, so don't lower it back before calling HAL, which is now enabled.
- Fix KeSet/QueryIntervalProfile to properly set/query profile intervals through HAL --
pass the correct structures and handle the ProfileAlignmentFixup case properly, and call
HAL when setting the timer interval as the interval may be overridden by it.
- KeStartProfile returns BOOLEAN to tell if the profile was started or not, just like
KeStopProfile.
- Make the interrupt implementation more portable for non-PIC architectures.
- Fix HalSystemVectorDispatchEntry; it returns a type (UCHAR), not TRUE/FALSE (BOOLEAN).
- Begin implementing the framework for querying HAL resource usage (keeping track of
internal address space and vector registrations/usage).
Modified:
trunk/reactos/hal/halamd64/generic/misc.c
trunk/reactos/hal/halarm/generic/hal.c
trunk/reactos/hal/halppc/generic/misc.c
trunk/reactos/hal/halx86/generic/beep.c
trunk/reactos/hal/halx86/generic/cmos.c
trunk/reactos/hal/halx86/generic/halinit.c
trunk/reactos/hal/halx86/generic/misc.c
trunk/reactos/hal/halx86/generic/reboot.c
trunk/reactos/hal/halx86/generic/sysinfo.c
trunk/reactos/hal/halx86/generic/systimer.S
trunk/reactos/hal/halx86/include/halp.h
trunk/reactos/include/ddk/winddk.h
trunk/reactos/include/ndk/amd64/ketypes.h
trunk/reactos/include/ndk/arm/ketypes.h
trunk/reactos/include/ndk/halfuncs.h
trunk/reactos/include/ndk/i386/asm.h
trunk/reactos/include/ndk/i386/ketypes.h
trunk/reactos/ntoskrnl/fstub/halstub.c
trunk/reactos/ntoskrnl/include/internal/hal.h
trunk/reactos/ntoskrnl/include/internal/ke.h
trunk/reactos/ntoskrnl/ke/i386/irqobj.c
trunk/reactos/ntoskrnl/ke/profobj.c
Modified: trunk/reactos/hal/halamd64/generic/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halamd64/generic/misc.…
==============================================================================
--- trunk/reactos/hal/halamd64/generic/misc.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halamd64/generic/misc.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -83,7 +83,7 @@
/*
* @implemented
*/
-BOOLEAN
+UCHAR
FASTCALL
HalSystemVectorDispatchEntry(IN ULONG Vector,
OUT PKINTERRUPT_ROUTINE **FlatDispatch,
Modified: trunk/reactos/hal/halarm/generic/hal.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halarm/generic/hal.c?r…
==============================================================================
--- trunk/reactos/hal/halarm/generic/hal.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halarm/generic/hal.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -857,12 +857,11 @@
}
-ULONG
-FASTCALL
-HalSystemVectorDispatchEntry(
- ULONG Unknown1,
- ULONG Unknown2,
- ULONG Unknown3)
+UCHAR
+FASTCALL
+HalSystemVectorDispatchEntry(IN ULONG Vector,
+ OUT PKINTERRUPT_ROUTINE **FlatDispatch,
+ OUT PKINTERRUPT_ROUTINE *NoConnection)
{
UNIMPLEMENTED;
Modified: trunk/reactos/hal/halppc/generic/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halppc/generic/misc.c?…
==============================================================================
--- trunk/reactos/hal/halppc/generic/misc.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halppc/generic/misc.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -83,7 +83,7 @@
/*
* @implemented
*/
-BOOLEAN
+UCHAR
FASTCALL
HalSystemVectorDispatchEntry(IN ULONG Vector,
OUT PKINTERRUPT_ROUTINE **FlatDispatch,
Modified: trunk/reactos/hal/halx86/generic/beep.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/beep.c?…
==============================================================================
--- trunk/reactos/hal/halx86/generic/beep.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/beep.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -31,9 +31,9 @@
{
UCHAR Data;
ULONG Divider;
- BOOLEAN Result = TRUE;
- /* FIXME: Acquire CMOS Lock */
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Turn the register off */
Data = READ_PORT_UCHAR(PORT_B);
@@ -49,8 +49,8 @@
if (Divider > 0x10000)
{
/* Fail */
- Result = FALSE;
- goto Cleanup;
+ HalpReleaseCmosSpinLock();
+ return FALSE;
}
/* Set timer divider */
@@ -62,11 +62,9 @@
WRITE_PORT_UCHAR(PORT_B, READ_PORT_UCHAR(PORT_B) | 0x03);
}
-Cleanup:
- /* FIXME: Release hardware lock */
+ /* Release CMOS lock */
+ HalpReleaseCmosSpinLock();
- /* Return result */
- return Result;
+ /* Return success */
+ return TRUE;
}
-
-
Modified: trunk/reactos/hal/halx86/generic/cmos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/cmos.c?…
==============================================================================
--- trunk/reactos/hal/halx86/generic/cmos.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/cmos.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -16,6 +16,7 @@
/* GLOBALS *******************************************************************/
KSPIN_LOCK HalpSystemHardwareLock;
+UCHAR HalpCmosCenturyOffset;
/* PRIVATE FUNCTIONS *********************************************************/
@@ -53,13 +54,14 @@
ULONG Address = SlotNumber;
ULONG Len = Length;
- /* FIXME: Acquire CMOS Lock */
-
/* Do nothing if we don't have a length */
if (!Length) return 0;
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
+
/* Check if this is simple CMOS */
- if (!BusNumber)
+ if (BusNumber == 0)
{
/* Loop the buffer up to 0xFF */
while ((Len > 0) && (Address < 0x100))
@@ -88,7 +90,8 @@
}
}
- /* FIXME: Release the CMOS Lock */
+ /* Release CMOS Lock */
+ HalpReleaseCmosSpinLock();
/* Return length read */
return Length - Len;
@@ -105,13 +108,14 @@
ULONG Address = SlotNumber;
ULONG Len = Length;
- /* FIXME: Acquire CMOS Lock */
-
/* Do nothing if we don't have a length */
if (!Length) return 0;
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
+
/* Check if this is simple CMOS */
- if (!BusNumber)
+ if (BusNumber == 0)
{
/* Loop the buffer up to 0xFF */
while ((Len > 0) && (Address < 0x100))
@@ -140,10 +144,22 @@
}
}
- /* FIXME: Release the CMOS Lock */
+ /* Release CMOS Lock */
+ HalpReleaseCmosSpinLock();
/* Return length read */
return Length - Len;
+}
+
+VOID
+NTAPI
+HalpInitializeCmos(VOID)
+{
+ /* Set default century offset byte */
+ HalpCmosCenturyOffset = 50;
+
+ /* No support for EISA or MCA */
+ ASSERT(HalpBusType == MACHINE_TYPE_ISA);
}
/* PUBLIC FUNCTIONS **********************************************************/
@@ -162,12 +178,14 @@
/* Only variable supported on x86 */
if (_stricmp(Name, "LastKnownGood")) return ENOENT;
- /* FIXME: Acquire CMOS Lock */
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Query the current value */
Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
- /* FIXME: Release CMOS lock */
+ /* Release CMOS lock */
+ HalpReleaseCmosSpinLock();
/* Check the flag */
if (Val)
@@ -201,14 +219,16 @@
/* Check if this is true or false */
if (!_stricmp(Value, "TRUE"))
{
- /* It's true, acquire CMOS lock (FIXME) */
+ /* It's true, acquire CMOS lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Read the current value and add the flag */
Val = HalpReadCmos(RTC_REGISTER_B) | 1;
}
else if (!_stricmp(Value, "FALSE"))
{
- /* It's false, acquire CMOS lock (FIXME) */
+ /* It's false, acquire CMOS lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Read the current value and mask out the flag */
Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
@@ -223,6 +243,7 @@
HalpWriteCmos(RTC_REGISTER_B, Val);
/* Release the lock and return success */
+ HalpReleaseCmosSpinLock();
return ESUCCESS;
}
@@ -233,7 +254,8 @@
NTAPI
HalQueryRealTimeClock(OUT PTIME_FIELDS Time)
{
- /* FIXME: Acquire CMOS Lock */
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Loop while update is in progress */
while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP);
@@ -253,7 +275,8 @@
/* Compensate for the century field */
Time->Year += (Time->Year > 80) ? 1900: 2000;
- /* FIXME: Release CMOS Lock */
+ /* Release CMOS lock */
+ HalpReleaseCmosSpinLock();
/* Always return TRUE */
return TRUE;
@@ -266,7 +289,8 @@
NTAPI
HalSetRealTimeClock(IN PTIME_FIELDS Time)
{
- /* FIXME: Acquire CMOS Lock */
+ /* Acquire CMOS Lock */
+ HalpAcquireSystemHardwareSpinLock();
/* Loop while update is in progress */
while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP);
@@ -282,10 +306,9 @@
/* FIXME: Set the century byte */
- /* FIXME: Release the CMOS Lock */
+ /* Release CMOS lock */
+ HalpReleaseCmosSpinLock();
/* Always return TRUE */
return TRUE;
}
-
-/* EOF */
Modified: trunk/reactos/hal/halx86/generic/halinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/halinit…
==============================================================================
--- trunk/reactos/hal/halx86/generic/halinit.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/halinit.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -97,11 +97,11 @@
/* Force initial PIC state */
KfRaiseIrql(KeGetCurrentIrql());
- /* Setup busy waiting */
- HalpCalibrateStallExecution();
+ /* Initialize CMOS lock */
+ KeInitializeSpinLock(&HalpSystemHardwareLock);
- /* Initialize the clock */
- HalpInitializeClock();
+ /* Initialize CMOS */
+ HalpInitializeCmos();
/* Fill out the dispatch tables */
HalQuerySystemInformation = HaliQuerySystemInformation;
@@ -112,8 +112,27 @@
HalResetDisplay = HalpBiosDisplayReset;
HalHaltSystem = HaliHaltSystem;
- /* Initialize the hardware lock (CMOS) */
- KeInitializeSpinLock(&HalpSystemHardwareLock);
+ /* Register IRQ 2 */
+ HalpRegisterVector(IDT_INTERNAL,
+ PRIMARY_VECTOR_BASE + 2,
+ PRIMARY_VECTOR_BASE + 2,
+ HIGH_LEVEL);
+
+ /* Setup I/O space */
+ HalpDefaultIoSpace.Next = HalpAddressUsageList;
+ HalpAddressUsageList = &HalpDefaultIoSpace;
+
+ /* Setup busy waiting */
+ HalpCalibrateStallExecution();
+
+ /* Initialize the clock */
+ HalpInitializeClock();
+
+ /*
+ * We could be rebooting with a pending profile interrupt,
+ * so clear it here before interrupts are enabled
+ */
+ HalStopProfileInterrupt(ProfileTime);
/* Do some HAL-specific initialization */
HalpInitPhase0(LoaderBlock);
@@ -123,12 +142,21 @@
/* Initialize the default HAL stubs for bus handling functions */
HalpInitNonBusHandler();
- /* Enable the clock interrupt */
- ((PKIPCR)KeGetPcr())->IDT[0x30].ExtendedOffset =
- (USHORT)(((ULONG_PTR)HalpClockInterrupt >> 16) & 0xFFFF);
- ((PKIPCR)KeGetPcr())->IDT[0x30].Offset =
- (USHORT)((ULONG_PTR)HalpClockInterrupt);
- HalEnableSystemInterrupt(0x30, CLOCK2_LEVEL, Latched);
+ /* Enable IRQ 0 */
+ HalpEnableInterruptHandler(IDT_DEVICE,
+ 0,
+ PRIMARY_VECTOR_BASE,
+ CLOCK2_LEVEL,
+ HalpClockInterrupt,
+ Latched);
+
+ /* Enable IRQ 8 */
+ HalpEnableInterruptHandler(IDT_DEVICE,
+ 0,
+ PRIMARY_VECTOR_BASE + 8,
+ PROFILE_LEVEL,
+ HalpProfileInterrupt,
+ Latched);
/* Initialize DMA. NT does this in Phase 0 */
HalpInitDma();
Modified: trunk/reactos/hal/halx86/generic/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/misc.c?…
==============================================================================
--- trunk/reactos/hal/halx86/generic/misc.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/misc.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -83,14 +83,14 @@
/*
* @implemented
*/
-BOOLEAN
+UCHAR
FASTCALL
HalSystemVectorDispatchEntry(IN ULONG Vector,
OUT PKINTERRUPT_ROUTINE **FlatDispatch,
OUT PKINTERRUPT_ROUTINE *NoConnection)
{
/* Not implemented on x86 */
- return FALSE;
+ return 0;
}
/*
Modified: trunk/reactos/hal/halx86/generic/reboot.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/reboot.…
==============================================================================
--- trunk/reactos/hal/halx86/generic/reboot.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/reboot.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -49,10 +49,8 @@
/* Enable warm reboot */
((PUSHORT)ZeroPageMapping)[0x239] = 0x1234;
- /* FIXME: Lock CMOS Access */
-
- /* Disable interrupts */
- _disable();
+ /* Lock CMOS Access */
+ HalpAcquireSystemHardwareSpinLock();
/* Setup control register B */
WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
Modified: trunk/reactos/hal/halx86/generic/sysinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/sysinfo…
==============================================================================
--- trunk/reactos/hal/halx86/generic/sysinfo.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/sysinfo.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -13,15 +13,37 @@
#include <debug.h>
PUCHAR KdComPortInUse;
+PADDRESS_USAGE HalpAddressUsageList;
+IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR];
+IDTUsage HalpIDTUsage[MAXIMUM_IDTVECTOR];
+
+ADDRESS_USAGE HalpDefaultIoSpace =
+{
+ NULL, CmResourceTypePort, IDT_INTERNAL,
+ {
+ {0x2000, 0xC000}, /* PIC?? */
+ {0xC000, 0x1000}, /* DMA 2 */
+ {0x8000, 0x1000}, /* DMA 1 */
+ {0x2000, 0x200}, /* PIC 1 */
+ {0xA000, 0x200}, /* PIC 2 */
+ {0x4000, 0x400}, /* PIT 1 */
+ {0x4800, 0x400}, /* PIT 2 */
+ {0x9200, 0x100}, /* ????? */
+ {0x7000, 0x200}, /* CMOS */
+ {0xF000, 0x1000}, /* ????? */
+ {0xCF800, 0x800}, /* PCI 0 */
+ {0,0},
+ }
+};
/* FUNCTIONS *****************************************************************/
NTSTATUS
NTAPI
-HaliQuerySystemInformation(IN HAL_QUERY_INFORMATION_CLASS InformationClass,
- IN ULONG BufferSize,
- IN OUT PVOID Buffer,
- OUT PULONG ReturnedLength)
+HaliQuerySystemInformation(IN HAL_QUERY_INFORMATION_CLASS InformationClass,
+ IN ULONG BufferSize,
+ IN OUT PVOID Buffer,
+ OUT PULONG ReturnedLength)
{
#define REPORT_THIS_CASE(X) case X: DPRINT1("Unhandled case: %s\n", #X); break
switch (InformationClass)
@@ -68,4 +90,44 @@
return STATUS_NOT_IMPLEMENTED;
}
+VOID
+NTAPI
+HalpRegisterVector(IN UCHAR Flags,
+ IN ULONG BusVector,
+ IN ULONG SystemVector,
+ IN KIRQL Irql)
+{
+ /* Save the vector flags */
+ HalpIDTUsageFlags[SystemVector].Flags = Flags;
+
+ /* Save the vector data */
+ HalpIDTUsage[SystemVector].Irql = Irql;
+ HalpIDTUsage[SystemVector].BusReleativeVector = BusVector;
+}
+
+VOID
+NTAPI
+HalpEnableInterruptHandler(IN UCHAR Flags,
+ IN ULONG BusVector,
+ IN ULONG SystemVector,
+ IN KIRQL Irql,
+ IN PVOID Handler,
+ IN KINTERRUPT_MODE Mode)
+{
+ UCHAR Entry;
+
+ /* Convert the vector into the IDT entry */
+ Entry = HalVectorToIDTEntry(SystemVector);
+
+ /* Register the vector */
+ HalpRegisterVector(Flags, BusVector, SystemVector, Irql);
+
+ /* Connect the interrupt */
+ ((PKIPCR)KeGetPcr())->IDT[Entry].ExtendedOffset = (USHORT)(((ULONG_PTR)Handler
>> 16) & 0xFFFF);
+ ((PKIPCR)KeGetPcr())->IDT[Entry].Offset = (USHORT)((ULONG_PTR)Handler);
+
+ /* Enable the interrupt */
+ HalEnableSystemInterrupt(SystemVector, Irql, Mode);
+}
+
/* EOF */
Modified: trunk/reactos/hal/halx86/generic/systimer.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/systime…
==============================================================================
--- trunk/reactos/hal/halx86/generic/systimer.S [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/systimer.S [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -17,7 +17,6 @@
_HalpLastPerfCounterHigh: .long 0
_HalpPerfCounterLow: .long 0
_HalpPerfCounterHigh: .long 0
-_HalpSystemHardwareLock: .long 0
_HalpSystemHardwareFlags: .long 0
_UnhandledMsg:
@@ -52,6 +51,7 @@
popf
ret
#endif
+
.endfunc
.global _HalpAcquireSystemHardwareSpinLock@0
@@ -84,7 +84,6 @@
/* Spin */
SPIN_ON_LOCK(eax, HardwareLock)
-
#else
/* Save EFLAGS, disable interrupts and return */
pushf
@@ -92,6 +91,7 @@
pop _HalpSystemHardwareFlags
ret
#endif
+
.endfunc
.global _HalpCalibrateStallExecution@0
@@ -632,3 +632,28 @@
jmp _Kei386EoiHelper@0
.endfunc
+.globl _HalpProfileInterrupt@0
+.func HalpProfileInterrupt@0
+TRAP_FIXUPS hpi_a, hpi_t, DoFixupV86, DoFixupAbios
+_HalpProfileInterrupt@0:
+
+ /* Enter trap */
+ INT_PROLOG hpi_a, hpi_t, DoPushFakeErrorCode
+
+ /* Push vector and make stack for IRQL */
+ push 0x38
+ sub esp, 4
+
+ /* Begin the interrupt */
+ push esp
+ push 0x38
+ push PROFILE_LEVEL
+ call _HalBeginSystemInterrupt@12
+
+ /* Check if it's spurious */
+ or al, al
+ jz Spurious
+
+ /* FIXME: We should not be getting profile interrupts yet! */
+ int 3
+.endfunc
Modified: trunk/reactos/hal/halx86/include/halp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/include/halp.h?…
==============================================================================
--- trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -23,18 +23,64 @@
#define TIMER_BOTH 0x30
#define TIMER_MD2 0x4
+/* Usage flags */
+#define IDT_REGISTERED 0x01
+#define IDT_LATCHED 0x02
+#define IDT_INTERNAL 0x11
+#define IDT_DEVICE 0x21
+
/* Conversion functions */
#define BCD_INT(bcd) \
(((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
#define INT_BCD(int) \
(UCHAR)(((int / 10) << 4) + (int % 10))
+typedef struct _IDTUsageFlags
+{
+ UCHAR Flags;
+} IDTUsageFlags;
+
+typedef struct
+{
+ KIRQL Irql;
+ UCHAR BusReleativeVector;
+} IDTUsage;
+
+typedef struct _HalAddressUsage
+{
+ struct _HalAddressUsage *Next;
+ CM_RESOURCE_TYPE Type;
+ UCHAR Flags;
+ struct
+ {
+ ULONG Start;
+ ULONG Length;
+ } Element[];
+} ADDRESS_USAGE, *PADDRESS_USAGE;
+
/* adapter.c */
PADAPTER_OBJECT NTAPI HalpAllocateAdapterEx(ULONG NumberOfMapRegisters,BOOLEAN IsMaster,
BOOLEAN Dma32BitAddresses);
/* bus.c */
VOID NTAPI HalpInitNonBusHandler (VOID);
+/* sysinfo.c */
+VOID
+NTAPI
+HalpRegisterVector(IN UCHAR Flags,
+ IN ULONG BusVector,
+ IN ULONG SystemVector,
+ IN KIRQL Irql);
+
+VOID
+NTAPI
+HalpEnableInterruptHandler(IN UCHAR Flags,
+ IN ULONG BusVector,
+ IN ULONG SystemVector,
+ IN KIRQL Irql,
+ IN PVOID Handler,
+ IN KINTERRUPT_MODE Mode);
+
/* irql.c */
VOID NTAPI HalpInitPICs(VOID);
@@ -44,12 +90,6 @@
VOID
NTAPI
HalpCalibrateStallExecution(VOID);
-
-ULONG
-NTAPI
-HalpQuery8254Counter(
- VOID
-);
/* pci.c */
VOID HalpInitPciBus (VOID);
@@ -61,6 +101,7 @@
VOID HalpInitPhase0 (PLOADER_PARAMETER_BLOCK LoaderBlock);
VOID HalpInitPhase1(VOID);
VOID NTAPI HalpClockInterrupt(VOID);
+VOID NTAPI HalpProfileInterrupt(VOID);
//
// KD Support
@@ -170,6 +211,30 @@
VOID
NTAPI
HaliHaltSystem(
+ VOID
+);
+
+//
+// CMOS initialization
+//
+VOID
+NTAPI
+HalpInitializeCmos(
+ VOID
+);
+
+//
+// Spinlock for protecting CMOS access
+//
+VOID
+NTAPI
+HalpAcquireSystemHardwareSpinLock(
+ VOID
+);
+
+VOID
+NTAPI
+HalpReleaseCmosSpinLock(
VOID
);
@@ -187,6 +252,10 @@
extern PVOID HalpRealModeStart;
extern PVOID HalpRealModeEnd;
+extern ADDRESS_USAGE HalpDefaultIoSpace;
+
extern KSPIN_LOCK HalpSystemHardwareLock;
+extern PADDRESS_USAGE HalpAddressUsageList;
+
#endif /* __INTERNAL_HAL_HAL_H */
Modified: trunk/reactos/include/ddk/winddk.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/winddk.h?rev=4…
==============================================================================
--- trunk/reactos/include/ddk/winddk.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/winddk.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -2433,6 +2433,34 @@
ULONG Flags;
} ARBITER_INTERFACE, *PARBITER_INTERFACE;
+typedef enum _KPROFILE_SOURCE {
+ ProfileTime,
+ ProfileAlignmentFixup,
+ ProfileTotalIssues,
+ ProfilePipelineDry,
+ ProfileLoadInstructions,
+ ProfilePipelineFrozen,
+ ProfileBranchInstructions,
+ ProfileTotalNonissues,
+ ProfileDcacheMisses,
+ ProfileIcacheMisses,
+ ProfileCacheMisses,
+ ProfileBranchMispredictions,
+ ProfileStoreInstructions,
+ ProfileFpInstructions,
+ ProfileIntegerInstructions,
+ Profile2Issue,
+ Profile3Issue,
+ Profile4Issue,
+ ProfileSpecialInstructions,
+ ProfileTotalCycles,
+ ProfileIcacheIssues,
+ ProfileDcacheAccesses,
+ ProfileMemoryBarrierCycles,
+ ProfileLoadLinkedIssues,
+ ProfileMaximum
+} KPROFILE_SOURCE;
+
typedef enum _HAL_QUERY_INFORMATION_CLASS {
HalInstalledBusInformation,
HalProfileSourceInformation,
@@ -2469,6 +2497,19 @@
HalCpeLog,
HalGenerateCmcInterrupt
} HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
+
+typedef struct _HAL_PROFILE_SOURCE_INTERVAL
+{
+ KPROFILE_SOURCE Source;
+ ULONG_PTR Interval;
+} HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
+
+typedef struct _HAL_PROFILE_SOURCE_INFORMATION
+{
+ KPROFILE_SOURCE Source;
+ BOOLEAN Supported;
+ ULONG Interval;
+} HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
typedef struct _MAP_REGISTER_ENTRY
{
@@ -4269,34 +4310,6 @@
(DDKAPI *PKINTERRUPT_ROUTINE)(
VOID);
-typedef enum _KPROFILE_SOURCE {
- ProfileTime,
- ProfileAlignmentFixup,
- ProfileTotalIssues,
- ProfilePipelineDry,
- ProfileLoadInstructions,
- ProfilePipelineFrozen,
- ProfileBranchInstructions,
- ProfileTotalNonissues,
- ProfileDcacheMisses,
- ProfileIcacheMisses,
- ProfileCacheMisses,
- ProfileBranchMispredictions,
- ProfileStoreInstructions,
- ProfileFpInstructions,
- ProfileIntegerInstructions,
- Profile2Issue,
- Profile3Issue,
- Profile4Issue,
- ProfileSpecialInstructions,
- ProfileTotalCycles,
- ProfileIcacheIssues,
- ProfileDcacheAccesses,
- ProfileMemoryBarrierCycles,
- ProfileLoadLinkedIssues,
- ProfileMaximum
-} KPROFILE_SOURCE;
-
typedef enum _CREATE_FILE_TYPE {
CreateFileTypeNone,
CreateFileTypeNamedPipe,
Modified: trunk/reactos/include/ndk/amd64/ketypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/amd64/ketypes.…
==============================================================================
--- trunk/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/amd64/ketypes.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -116,7 +116,7 @@
//
// HAL Variables
//
-#define INITIAL_STALL_COUNT 0x64
+#define INITIAL_STALL_COUNT 100
//
// IOPM Definitions
Modified: trunk/reactos/include/ndk/arm/ketypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/arm/ketypes.h?…
==============================================================================
--- trunk/reactos/include/ndk/arm/ketypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/arm/ketypes.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -47,7 +47,7 @@
//
// HAL Variables
//
-#define INITIAL_STALL_COUNT 0x64
+#define INITIAL_STALL_COUNT 100
//
// Static Kernel-Mode Address start (use MM_KSEG0_BASE for actual)
Modified: trunk/reactos/include/ndk/halfuncs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/halfuncs.h?rev…
==============================================================================
--- trunk/reactos/include/ndk/halfuncs.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/halfuncs.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -203,6 +203,15 @@
PVOID NmiInfo
);
+NTHALAPI
+UCHAR
+FASTCALL
+HalSystemVectorDispatchEntry(
+ IN ULONG Vector,
+ OUT PKINTERRUPT_ROUTINE **FlatDispatch,
+ OUT PKINTERRUPT_ROUTINE *NoConnection
+);
+
//
// Environment Functions
//
@@ -226,6 +235,29 @@
#endif
//
+// Profiling Functions
+//
+VOID
+NTAPI
+HalStartProfileInterrupt(
+ IN KPROFILE_SOURCE ProfileSource
+);
+
+NTHALAPI
+VOID
+NTAPI
+HalStopProfileInterrupt(
+ IN KPROFILE_SOURCE ProfileSource
+);
+
+NTHALAPI
+ULONG_PTR
+NTAPI
+HalSetProfileInterval(
+ IN ULONG_PTR Interval
+);
+
+//
// Time Functions
//
NTHALAPI
Modified: trunk/reactos/include/ndk/i386/asm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/i386/asm.h?rev…
==============================================================================
--- trunk/reactos/include/ndk/i386/asm.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/i386/asm.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -588,6 +588,7 @@
#define PASSIVE_LEVEL 0x0
#define APC_LEVEL 0x1
#define DISPATCH_LEVEL 0x2
+#define PROFILE_LEVEL 0x1B
#define CLOCK2_LEVEL 0x1C
#define IPI_LEVEL 0x1D
#define HIGH_LEVEL 0x1F
Modified: trunk/reactos/include/ndk/i386/ketypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/i386/ketypes.h…
==============================================================================
--- trunk/reactos/include/ndk/i386/ketypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/i386/ketypes.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -124,7 +124,7 @@
//
// HAL Variables
//
-#define INITIAL_STALL_COUNT 0x64
+#define INITIAL_STALL_COUNT 100
//
// IOPM Definitions
Modified: trunk/reactos/ntoskrnl/fstub/halstub.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fstub/halstub.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/fstub/halstub.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/fstub/halstub.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -59,12 +59,20 @@
(pKdReleasePciDeviceForDebugging)NULL,
(pKdGetAcpiTablePhase0)NULL,
(pKdCheckPowerButton)NULL,
- (pHalVectorToIDTEntry)NULL,
+ (pHalVectorToIDTEntry)xHalVectorToIDTEntry,
(pKdMapPhysicalMemory64)NULL,
(pKdUnmapVirtualAddress)NULL
};
/* FUNCTIONS *****************************************************************/
+
+UCHAR
+NTAPI
+xHalVectorToIDTEntry(IN ULONG Vector)
+{
+ /* Return the vector */
+ return Vector;
+}
VOID
NTAPI
Modified: trunk/reactos/ntoskrnl/include/internal/hal.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/hal.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/hal.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -51,6 +51,12 @@
NTAPI
xHalHaltSystem(
VOID
+);
+
+UCHAR
+NTAPI
+xHalVectorToIDTEntry(
+ IN ULONG Vector
);
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ke.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -403,7 +403,7 @@
KAFFINITY Affinity
);
-VOID
+BOOLEAN
NTAPI
KeStartProfile(
struct _KPROFILE* Profile,
Modified: trunk/reactos/ntoskrnl/ke/i386/irqobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/irqobj.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/irqobj.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/i386/irqobj.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -46,10 +46,21 @@
{
PKINTERRUPT_ROUTINE Handler;
ULONG Current;
+ UCHAR Type;
+ UCHAR Entry;
+
+ /* Check if this is a primary or 2nd-level dispatch */
+ Type = HalSystemVectorDispatchEntry(Vector,
+ &Dispatch->FlatDispatch,
+ &Dispatch->NoDispatch);
+ ASSERT(Type == 0);
+
+ /* Get the IDT entry for this vector */
+ Entry = HalVectorToIDTEntry(Vector);
/* Setup the unhandled dispatch */
Dispatch->NoDispatch = (PVOID)(((ULONG_PTR)&KiStartUnexpectedRange) +
- (Vector - PRIMARY_VECTOR_BASE) *
+ (Entry - PRIMARY_VECTOR_BASE) *
KiUnexpectedEntrySize);
/* Setup the handlers */
@@ -59,9 +70,9 @@
Dispatch->FlatDispatch = NULL;
/* Get the current handler */
- Current = ((((PKIPCR)KeGetPcr())->IDT[Vector].ExtendedOffset << 16)
+ Current = ((((PKIPCR)KeGetPcr())->IDT[Entry].ExtendedOffset << 16)
& 0xFFFF0000) |
- (((PKIPCR)KeGetPcr())->IDT[Vector].Offset & 0xFFFF);
+ (((PKIPCR)KeGetPcr())->IDT[Entry].Offset & 0xFFFF);
/* Set the interrupt */
Dispatch->Interrupt = CONTAINING_RECORD(Current,
@@ -105,6 +116,7 @@
DISPATCH_INFO Dispatch;
PKINTERRUPT_ROUTINE Handler;
PULONG Patch = &Interrupt->DispatchCode[0];
+ UCHAR Entry;
/* Get vector data */
KiGetVectorDispatch(Interrupt->Vector, &Dispatch);
@@ -139,10 +151,13 @@
Handler = (PVOID)&Interrupt->DispatchCode;
}
+ /* Get the IDT entry for this vector */
+ Entry = HalVectorToIDTEntry(Interrupt->Vector);
+
/* Set the pointer in the IDT */
- ((PKIPCR)KeGetPcr())->IDT[Interrupt->Vector].ExtendedOffset =
+ ((PKIPCR)KeGetPcr())->IDT[Entry].ExtendedOffset =
(USHORT)(((ULONG_PTR)Handler >> 16) & 0xFFFF);
- ((PKIPCR)KeGetPcr())->IDT[Interrupt->Vector].Offset =
+ ((PKIPCR)KeGetPcr())->IDT[Entry].Offset =
(USHORT)PtrToUlong(Handler);
}
Modified: trunk/reactos/ntoskrnl/ke/profobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/profobj.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/profobj.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/profobj.c [iso-8859-1] Thu Oct 29 20:58:41 2009
@@ -19,6 +19,7 @@
LIST_ENTRY KiProfileSourceListHead;
KSPIN_LOCK KiProfileLock;
ULONG KiProfileTimeInterval = 78125; /* Default resolution 7.8ms (sysinternals) */
+ULONG KiProfileAlignmentFixupInterval;
/* FUNCTIONS *****************************************************************/
@@ -46,27 +47,27 @@
Profile->Affinity = Affinity;
}
-VOID
-NTAPI
-KeStartProfile(PKPROFILE Profile,
- PVOID Buffer)
+BOOLEAN
+NTAPI
+KeStartProfile(IN PKPROFILE Profile,
+ IN PVOID Buffer)
{
KIRQL OldIrql;
PKPROFILE_SOURCE_OBJECT SourceBuffer;
PKPROFILE_SOURCE_OBJECT CurrentSource;
- BOOLEAN FreeBuffer = TRUE, SourceFound = FALSE;
+ BOOLEAN FreeBuffer = TRUE, SourceFound = FALSE, StartedProfile;
PKPROCESS ProfileProcess;
PLIST_ENTRY NextEntry;
/* Allocate a buffer first, before we raise IRQL */
SourceBuffer = ExAllocatePoolWithTag(NonPagedPool,
- sizeof(KPROFILE_SOURCE_OBJECT),
- 'forP');
- if (!SourceBuffer) return;
+ sizeof(KPROFILE_SOURCE_OBJECT),
+ 'forP');
+ if (!SourceBuffer) return FALSE;
RtlZeroMemory(SourceBuffer, sizeof(KPROFILE_SOURCE_OBJECT));
- /* Raise to PROFILE_LEVEL */
- KeRaiseIrql(PROFILE_LEVEL, &OldIrql);
+ /* Raise to profile IRQL and acquire the profile lock */
+ KeRaiseIrql(KiProfileIrql, &OldIrql);
KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
/* Make sure it's not running */
@@ -75,6 +76,7 @@
/* Set it as Started */
Profile->Buffer = Buffer;
Profile->Started = TRUE;
+ StartedProfile = TRUE;
/* Get the process, if any */
ProfileProcess = Profile->Process;
@@ -124,29 +126,39 @@
FreeBuffer = FALSE;
}
}
-
- /* Lower the IRQL */
+ else
+ {
+ /* Already running so nothing to start */
+ StartedProfile = FALSE;
+ }
+
+ /* Release the profile lock */
KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
+
+ /* Tell HAL to start the profile interrupt */
+ HalStartProfileInterrupt(Profile->Source);
+
+ /* Lower back to original IRQL */
KeLowerIrql(OldIrql);
-
- /* FIXME: Tell HAL to Start the Profile Interrupt */
- //HalStartProfileInterrupt(Profile->Source);
/* Free the pool */
if (FreeBuffer) ExFreePool(SourceBuffer);
+
+ /* Return whether we could start the profile */
+ return StartedProfile;
}
BOOLEAN
NTAPI
-KeStopProfile(PKPROFILE Profile)
+KeStopProfile(IN PKPROFILE Profile)
{
KIRQL OldIrql;
PKPROFILE_SOURCE_OBJECT CurrentSource = NULL;
PLIST_ENTRY NextEntry;
- BOOLEAN SourceFound = FALSE;
-
- /* Raise to PROFILE_LEVEL and acquire spinlock */
- KeRaiseIrql(PROFILE_LEVEL, &OldIrql);
+ BOOLEAN SourceFound = FALSE, StoppedProfile;
+
+ /* Raise to profile IRQL and acquire the profile lock */
+ KeRaiseIrql(KiProfileIrql, &OldIrql);
KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
/* Make sure it's running */
@@ -155,6 +167,7 @@
/* Remove it from the list and disable */
RemoveEntryList(&Profile->ProfileListEntry);
Profile->Started = FALSE;
+ StoppedProfile = TRUE;
/* Start looping */
for (NextEntry = KiProfileSourceListHead.Flink;
@@ -179,60 +192,99 @@
}
}
-
- /* Lower IRQL */
+ else
+ {
+ /* It wasn't! */
+ StoppedProfile = FALSE;
+ }
+
+ /* Release the profile lock */
KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
+
+ /* Stop the profile interrupt */
+ HalStopProfileInterrupt(Profile->Source);
+
+ /* Lower back to original IRQL */
KeLowerIrql(OldIrql);
-
- /* Stop Profiling. FIXME: Implement in HAL */
- //HalStopProfileInterrupt(Profile->Source);
/* Free the Source Object */
if (SourceFound) ExFreePool(CurrentSource);
- /* FIXME */
- return FALSE;
+ /* Return whether we could stop the profile */
+ return StoppedProfile;
}
ULONG
NTAPI
-KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource)
-{
- /* Check if this is the timer profile */
+KeQueryIntervalProfile(IN KPROFILE_SOURCE ProfileSource)
+{
+ HAL_PROFILE_SOURCE_INFORMATION ProfileSourceInformation;
+ ULONG ReturnLength, Interval;
+ NTSTATUS Status;
+
+ /* Check what profile this is */
if (ProfileSource == ProfileTime)
{
- /* Return the good old 100ns sampling interval */
- return KiProfileTimeInterval;
+ /* Return the time interval */
+ Interval = KiProfileTimeInterval;
+ }
+ else if (ProfileSource == ProfileAlignmentFixup)
+ {
+ /* Return the alignment interval */
+ Interval = KiProfileAlignmentFixupInterval;
}
else
{
- /* Request it from HAL. FIXME: What structure is used? */
- HalQuerySystemInformation(HalProfileSourceInformation,
- sizeof(NULL),
- NULL,
- NULL);
-
- return 0;
- }
-}
-
-VOID
-NTAPI
-KeSetIntervalProfile(KPROFILE_SOURCE ProfileSource,
- ULONG Interval)
-{
- /* Check if this is the timer profile */
+ /* Request it from HAL */
+ ProfileSourceInformation.Source = ProfileSource;
+ Status = HalQuerySystemInformation(HalProfileSourceInformation,
+ sizeof(HAL_PROFILE_SOURCE_INFORMATION),
+ &ProfileSourceInformation,
+ &ReturnLength);
+
+ /* Check if HAL handled it and supports this profile */
+ if (NT_SUCCESS(Status) && (ProfileSourceInformation.Supported))
+ {
+ /* Get the interval */
+ Interval = ProfileSourceInformation.Interval;
+ }
+ else
+ {
+ /* Unsupported or invalid source, fail */
+ Interval = 0;
+ }
+ }
+
+ /* Return the interval we got */
+ return Interval;
+}
+
+VOID
+NTAPI
+KeSetIntervalProfile(IN KPROFILE_SOURCE ProfileSource,
+ IN ULONG Interval)
+{
+ HAL_PROFILE_SOURCE_INTERVAL ProfileSourceInterval;
+
+ /* Check what profile this is */
if (ProfileSource == ProfileTime)
{
- /* Set the good old 100ns sampling interval */
- KiProfileTimeInterval = Interval;
+ /* Set the interval through HAL */
+ KiProfileTimeInterval = HalSetProfileInterval(Interval);
+ }
+ else if (ProfileSource == ProfileAlignmentFixup)
+ {
+ /* Set the alignment interval */
+ KiProfileAlignmentFixupInterval = Interval;
}
else
{
- /* Set it with HAL. FIXME: What structure is used? */
- HalSetSystemInformation(HalProfileSourceInformation,
- sizeof(NULL),
- NULL);
+ /* HAL handles any other interval */
+ ProfileSourceInterval.Source = ProfileSource;
+ ProfileSourceInterval.Interval = Interval;
+ HalSetSystemInformation(HalProfileSourceInterval,
+ sizeof(HAL_PROFILE_SOURCE_INTERVAL),
+ &ProfileSourceInterval);
}
}
@@ -241,7 +293,7 @@
*/
VOID
NTAPI
-KeProfileInterrupt(PKTRAP_FRAME TrapFrame)
+KeProfileInterrupt(IN PKTRAP_FRAME TrapFrame)
{
/* Called from HAL for Timer Profiling */
KeProfileInterruptWithSource(TrapFrame, ProfileTime);