5 #ifndef __INTERNAL_HAL_HAL_H
6 #define __INTERNAL_HAL_HAL_H
8 #define HAL_APC_REQUEST 0
9 #define HAL_DPC_REQUEST 1
11 /* CMOS Registers and Ports */
12 #define CMOS_CONTROL_PORT (PUCHAR)0x70
13 #define CMOS_DATA_PORT (PUCHAR)0x71
14 #define RTC_REGISTER_A 0x0A
15 #define RTC_REGISTER_B 0x0B
16 #define RTC_REG_A_UIP 0x80
17 #define RTC_REGISTER_CENTURY 0x32
20 #define IDT_REGISTERED 0x01
21 #define IDT_LATCHED 0x02
22 #define IDT_INTERNAL 0x11
23 #define IDT_DEVICE 0x21
25 /* Conversion functions */
26 #define BCD_INT(bcd) \
27 (((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
28 #define INT_BCD(int) \
29 (UCHAR)(((int / 10) << 4) + (int % 10))
32 // Commonly stated as being 1.19318MHz
34 // See ISA System Architecture 3rd Edition (Tom Shanley, Don Anderson, John Swindle)
37 // However, the true value is closer to 1.19318181[...]81MHz since this is 1/3rd
38 // of the NTSC color subcarrier frequency which runs at 3.57954545[...]45MHz.
40 // Note that Windows uses 1.193167MHz which seems to have no basis. However, if
41 // one takes the NTSC color subcarrier frequency as being 3.579545 (trimming the
42 // infinite series) and divides it by three, one obtains 1.19318167.
44 // It may be that the original NT HAL source code introduced a typo and turned
45 // 119318167 into 1193167 by ommitting the "18". This is very plausible as the
46 // number is quite long.
48 #define PIT_FREQUENCY 1193182
51 // These ports are controlled by the i8254 Programmable Interrupt Timer (PIT)
53 #define TIMER_CHANNEL0_DATA_PORT 0x40
54 #define TIMER_CHANNEL1_DATA_PORT 0x41
55 #define TIMER_CHANNEL2_DATA_PORT 0x42
56 #define TIMER_CONTROL_PORT 0x43
59 // Mode 0 - Interrupt On Terminal Count
60 // Mode 1 - Hardware Re-triggerable One-Shot
61 // Mode 2 - Rate Generator
62 // Mode 3 - Square Wave Generator
63 // Mode 4 - Software Triggered Strobe
64 // Mode 5 - Hardware Triggered Strobe
66 typedef enum _TIMER_OPERATING_MODES
74 PitOperatingMode2Reserved
,
75 PitOperatingMode5Reserved
76 } TIMER_OPERATING_MODES
;
78 typedef enum _TIMER_ACCESS_MODES
80 PitAccessModeCounterLatch
,
86 typedef enum _TIMER_CHANNELS
94 typedef union _TIMER_CONTROL_PORT_REGISTER
99 TIMER_OPERATING_MODES OperatingMode
:3;
100 TIMER_ACCESS_MODES AccessMode
:2;
101 TIMER_CHANNELS Channel
:2;
104 } TIMER_CONTROL_PORT_REGISTER
, *PTIMER_CONTROL_PORT_REGISTER
;
107 // See ISA System Architecture 3rd Edition (Tom Shanley, Don Anderson, John Swindle)
110 // This port is controled by the i8255 Programmable Peripheral Interface (PPI)
112 #define SYSTEM_CONTROL_PORT_A 0x92
113 #define SYSTEM_CONTROL_PORT_B 0x61
114 typedef union _SYSTEM_CONTROL_PORT_B_REGISTER
118 UCHAR Timer2GateToSpeaker
:1;
119 UCHAR SpeakerDataEnable
:1;
120 UCHAR ParityCheckEnable
:1;
121 UCHAR ChannelCheckEnable
:1;
122 UCHAR RefreshRequest
:1;
123 UCHAR Timer2Output
:1;
124 UCHAR ChannelCheck
:1;
128 } SYSTEM_CONTROL_PORT_B_REGISTER
, *PSYSTEM_CONTROL_PORT_B_REGISTER
;
131 // Mm PTE/PDE to Hal PTE/PDE
133 #define HalAddressToPde(x) (PHARDWARE_PTE)MiAddressToPde(x)
134 #define HalAddressToPte(x) (PHARDWARE_PTE)MiAddressToPte(x)
136 typedef struct _IDTUsageFlags
144 UCHAR BusReleativeVector
;
147 typedef struct _HalAddressUsage
149 struct _HalAddressUsage
*Next
;
150 CM_RESOURCE_TYPE Type
;
157 } ADDRESS_USAGE
, *PADDRESS_USAGE
;
160 PADAPTER_OBJECT NTAPI
HalpAllocateAdapterEx(ULONG NumberOfMapRegisters
,BOOLEAN IsMaster
, BOOLEAN Dma32BitAddresses
);
165 HalpRegisterVector(IN UCHAR Flags
,
167 IN ULONG SystemVector
,
172 HalpEnableInterruptHandler(IN UCHAR Flags
,
174 IN ULONG SystemVector
,
177 IN KINTERRUPT_MODE Mode
);
180 VOID NTAPI
HalpInitPICs(VOID
);
183 VOID NTAPI
HalpInitializeClock(VOID
);
187 HalpCalibrateStallExecution(VOID
);
190 VOID
HalpInitPciBus (VOID
);
193 VOID
HalpInitDma (VOID
);
195 /* Non-generic initialization */
196 VOID
HalpInitPhase0 (PLOADER_PARAMETER_BLOCK LoaderBlock
);
197 VOID
HalpInitPhase1(VOID
);
198 VOID NTAPI
HalpClockInterrupt(VOID
);
199 VOID NTAPI
HalpProfileInterrupt(VOID
);
210 HalpCheckPowerButton(
216 HalpRegisterKdSupportFunctions(
222 HalpSetupPciDeviceForDebugging(
223 IN PVOID LoaderBlock
,
224 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
229 HalpReleasePciDeviceForDebugging(
230 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
238 HalpMapPhysicalMemory64(
239 IN PHYSICAL_ADDRESS PhysicalAddress
,
245 HalpUnmapVirtualAddress(
246 IN PVOID VirtualAddress
,
253 HaliQuerySystemInformation(
254 IN HAL_QUERY_INFORMATION_CLASS InformationClass
,
257 OUT PULONG ReturnedLength
262 HaliSetSystemInformation(
263 IN HAL_SET_INFORMATION_CLASS InformationClass
,
273 HalpBiosDisplayReset(
296 // Processor Halt Routine
305 // CMOS initialization
314 // Spinlock for protecting CMOS access
318 HalpAcquireSystemHardwareSpinLock(
324 HalpReleaseCmosSpinLock(
329 #define KfLowerIrql KeLowerIrql
331 /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
332 #define KiAcquireSpinLock(SpinLock)
333 #define KiReleaseSpinLock(SpinLock)
334 #define KfAcquireSpinLock(SpinLock) KfRaiseIrql(DISPATCH_LEVEL);
335 #define KfReleaseSpinLock(SpinLock, OldIrql) KeLowerIrql(OldIrql);
336 #endif // !CONFIG_SMP
339 extern BOOLEAN HalpNMIInProgress
;
341 extern PVOID HalpRealModeStart
;
342 extern PVOID HalpRealModeEnd
;
344 extern ADDRESS_USAGE HalpDefaultIoSpace
;
346 extern KSPIN_LOCK HalpSystemHardwareLock
;
348 extern PADDRESS_USAGE HalpAddressUsageList
;
350 #endif /* __INTERNAL_HAL_HAL_H */