7 typedef struct _HAL_BIOS_FRAME
14 PKTRAP_FRAME TrapFrame
;
22 } HAL_BIOS_FRAME
, *PHAL_BIOS_FRAME
;
26 (*PHAL_SW_INTERRUPT_HANDLER
)(
34 (*PHAL_SW_INTERRUPT_HANDLER_2ND_ENTRY
)(
35 IN PKTRAP_FRAME TrapFrame
38 #define HAL_APC_REQUEST 0
39 #define HAL_DPC_REQUEST 1
41 /* CMOS Registers and Ports */
42 #define CMOS_CONTROL_PORT (PUCHAR)0x70
43 #define CMOS_DATA_PORT (PUCHAR)0x71
44 #define RTC_REGISTER_A 0x0A
45 #define RTC_REGISTER_B 0x0B
46 #define RTC_REG_A_UIP 0x80
47 #define RTC_REGISTER_CENTURY 0x32
50 #define IDT_REGISTERED 0x01
51 #define IDT_LATCHED 0x02
52 #define IDT_INTERNAL 0x11
53 #define IDT_DEVICE 0x21
55 /* Conversion functions */
56 #define BCD_INT(bcd) \
57 (((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
58 #define INT_BCD(int) \
59 (UCHAR)(((int / 10) << 4) + (int % 10))
64 #define VIDEO_SERVICES 0x10
67 // Operations for INT 10h (in AH)
69 #define SET_VIDEO_MODE 0x00
72 // Video Modes for INT10h AH=00 (in AL)
74 #define GRAPHICS_MODE_12 0x12 /* 80x30 8x16 640x480 16/256K */
77 // Commonly stated as being 1.19318MHz
79 // See ISA System Architecture 3rd Edition (Tom Shanley, Don Anderson, John Swindle)
82 // However, the true value is closer to 1.19318181[...]81MHz since this is 1/3rd
83 // of the NTSC color subcarrier frequency which runs at 3.57954545[...]45MHz.
85 // Note that Windows uses 1.193167MHz which seems to have no basis. However, if
86 // one takes the NTSC color subcarrier frequency as being 3.579545 (trimming the
87 // infinite series) and divides it by three, one obtains 1.19318167.
89 // It may be that the original NT HAL source code introduced a typo and turned
90 // 119318167 into 1193167 by ommitting the "18". This is very plausible as the
91 // number is quite long.
93 #define PIT_FREQUENCY 1193182
96 // These ports are controlled by the i8254 Programmable Interrupt Timer (PIT)
98 #define TIMER_CHANNEL0_DATA_PORT 0x40
99 #define TIMER_CHANNEL1_DATA_PORT 0x41
100 #define TIMER_CHANNEL2_DATA_PORT 0x42
101 #define TIMER_CONTROL_PORT 0x43
104 // Mode 0 - Interrupt On Terminal Count
105 // Mode 1 - Hardware Re-triggerable One-Shot
106 // Mode 2 - Rate Generator
107 // Mode 3 - Square Wave Generator
108 // Mode 4 - Software Triggered Strobe
109 // Mode 5 - Hardware Triggered Strobe
111 typedef enum _TIMER_OPERATING_MODES
119 PitOperatingMode2Reserved
,
120 PitOperatingMode5Reserved
121 } TIMER_OPERATING_MODES
;
123 typedef enum _TIMER_ACCESS_MODES
125 PitAccessModeCounterLatch
,
129 } TIMER_ACCESS_MODES
;
131 typedef enum _TIMER_CHANNELS
139 typedef union _TIMER_CONTROL_PORT_REGISTER
144 TIMER_OPERATING_MODES OperatingMode
:3;
145 TIMER_ACCESS_MODES AccessMode
:2;
146 TIMER_CHANNELS Channel
:2;
149 } TIMER_CONTROL_PORT_REGISTER
, *PTIMER_CONTROL_PORT_REGISTER
;
152 // See ISA System Architecture 3rd Edition (Tom Shanley, Don Anderson, John Swindle)
155 // This port is controled by the i8255 Programmable Peripheral Interface (PPI)
157 #define SYSTEM_CONTROL_PORT_A 0x92
158 #define SYSTEM_CONTROL_PORT_B 0x61
159 typedef union _SYSTEM_CONTROL_PORT_B_REGISTER
163 UCHAR Timer2GateToSpeaker
:1;
164 UCHAR SpeakerDataEnable
:1;
165 UCHAR ParityCheckEnable
:1;
166 UCHAR ChannelCheckEnable
:1;
167 UCHAR RefreshRequest
:1;
168 UCHAR Timer2Output
:1;
169 UCHAR ChannelCheck
:1;
173 } SYSTEM_CONTROL_PORT_B_REGISTER
, *PSYSTEM_CONTROL_PORT_B_REGISTER
;
176 // See ISA System Architecture 3rd Edition (Tom Shanley, Don Anderson, John Swindle)
179 // These ports are controlled by the i8259 Programmable Interrupt Controller (PIC)
181 #define PIC1_CONTROL_PORT 0x20
182 #define PIC1_DATA_PORT 0x21
183 #define PIC2_CONTROL_PORT 0xA0
184 #define PIC2_DATA_PORT 0xA1
187 // Definitions for ICW/OCW Bits
189 typedef enum _I8259_ICW1_OPERATING_MODE
193 } I8259_ICW1_OPERATING_MODE
;
195 typedef enum _I8259_ICW1_INTERRUPT_MODE
199 } I8259_ICW1_INTERRUPT_MODE
;
201 typedef enum _I8259_ICW1_INTERVAL
205 } I8259_ICW1_INTERVAL
;
207 typedef enum _I8259_ICW4_SYSTEM_MODE
211 } I8259_ICW4_SYSTEM_MODE
;
213 typedef enum _I8259_ICW4_EOI_MODE
217 } I8259_ICW4_EOI_MODE
;
219 typedef enum _I8259_ICW4_BUFFERED_MODE
225 } I8259_ICW4_BUFFERED_MODE
;
227 typedef enum _I8259_READ_REQUEST
233 } I8259_READ_REQUEST
;
235 typedef enum _I8259_EOI_MODE
248 // Definitions for ICW Registers
250 typedef union _I8259_ICW1
255 I8259_ICW1_OPERATING_MODE OperatingMode
:1;
256 I8259_ICW1_INTERVAL Interval
:1;
257 I8259_ICW1_INTERRUPT_MODE InterruptMode
:1;
259 UCHAR InterruptVectorAddress
:3;
262 } I8259_ICW1
, *PI8259_ICW1
;
264 typedef union _I8259_ICW2
269 UCHAR InterruptVector
:5;
272 } I8259_ICW2
, *PI8259_ICW2
;
274 typedef union _I8259_ICW3
296 } I8259_ICW3
, *PI8259_ICW3
;
298 typedef union _I8259_ICW4
302 I8259_ICW4_SYSTEM_MODE SystemMode
:1;
303 I8259_ICW4_EOI_MODE EoiMode
:1;
304 I8259_ICW4_BUFFERED_MODE BufferedMode
:2;
305 UCHAR SpecialFullyNestedMode
:1;
309 } I8259_ICW4
, *PI8259_ICW4
;
311 typedef union _I8259_OCW2
317 I8259_EOI_MODE EoiMode
:3;
320 } I8259_OCW2
, *PI8259_OCW2
;
322 typedef union _I8259_OCW3
326 I8259_READ_REQUEST ReadRequest
:2;
330 UCHAR SpecialMaskMode
:2;
334 } I8259_OCW3
, *PI8259_OCW3
;
336 typedef union _I8259_ISR
353 } I8259_ISR
, *PI8259_ISR
;
355 typedef I8259_ISR I8259_IDR
, *PI8259_IDR
;
358 // See EISA System Architecture 2nd Edition (Tom Shanley, Don Anderson, John Swindle)
361 // These ports are controlled by the i8259A Programmable Interrupt Controller (PIC)
363 #define EISA_ELCR_MASTER 0x4D0
364 #define EISA_ELCR_SLAVE 0x4D1
366 typedef union _EISA_ELCR
394 } EISA_ELCR
, *PEISA_ELCR
;
396 typedef struct _PIC_MASK
407 } PIC_MASK
, *PPIC_MASK
;
411 __attribute__((regparm(3)))
412 (*PHAL_DISMISS_INTERRUPT
)(
419 __attribute__((regparm(3)))
420 HalpDismissIrqGeneric(
427 __attribute__((regparm(3)))
435 __attribute__((regparm(3)))
443 __attribute__((regparm(3)))
451 __attribute__((regparm(3)))
459 __attribute__((regparm(3)))
460 HalpDismissIrq15Level(
467 __attribute__((regparm(3)))
468 HalpDismissIrq13Level(
475 __attribute__((regparm(3)))
476 HalpDismissIrq07Level(
483 HalpHardwareInterruptLevel(
488 // Mm PTE/PDE to Hal PTE/PDE
490 #define HalAddressToPde(x) (PHARDWARE_PTE)MiAddressToPde(x)
491 #define HalAddressToPte(x) (PHARDWARE_PTE)MiAddressToPte(x)
493 typedef struct _IDTUsageFlags
501 UCHAR BusReleativeVector
;
504 typedef struct _HalAddressUsage
506 struct _HalAddressUsage
*Next
;
507 CM_RESOURCE_TYPE Type
;
514 } ADDRESS_USAGE
, *PADDRESS_USAGE
;
517 PADAPTER_OBJECT NTAPI
HalpAllocateAdapterEx(ULONG NumberOfMapRegisters
,BOOLEAN IsMaster
, BOOLEAN Dma32BitAddresses
);
522 HalpRegisterVector(IN UCHAR Flags
,
524 IN ULONG SystemVector
,
529 HalpEnableInterruptHandler(IN UCHAR Flags
,
531 IN ULONG SystemVector
,
534 IN KINTERRUPT_MODE Mode
);
537 VOID NTAPI
HalpInitializePICs(IN BOOLEAN EnableInterrupts
);
538 VOID
HalpApcInterrupt(VOID
);
539 VOID
HalpDispatchInterrupt(VOID
);
540 VOID
HalpDispatchInterrupt2(VOID
);
541 VOID FASTCALL DECLSPEC_NORETURN
HalpApcInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame
);
542 VOID FASTCALL DECLSPEC_NORETURN
HalpDispatchInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame
);
545 VOID NTAPI
HalpInitializeClock(VOID
);
546 VOID
HalpClockInterrupt(VOID
);
547 VOID
HalpProfileInterrupt(VOID
);
551 HalpCalibrateStallExecution(VOID
);
554 VOID
HalpInitPciBus (VOID
);
557 VOID
HalpInitDma (VOID
);
559 /* Non-generic initialization */
560 VOID
HalpInitPhase0 (PLOADER_PARAMETER_BLOCK LoaderBlock
);
561 VOID
HalpInitPhase1(VOID
);
572 HalpCheckPowerButton(
578 HalpRegisterKdSupportFunctions(
584 HalpSetupPciDeviceForDebugging(
585 IN PVOID LoaderBlock
,
586 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
591 HalpReleasePciDeviceForDebugging(
592 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
600 HalpMapPhysicalMemory64(
601 IN PHYSICAL_ADDRESS PhysicalAddress
,
607 HalpUnmapVirtualAddress(
608 IN PVOID VirtualAddress
,
615 HaliQuerySystemInformation(
616 IN HAL_QUERY_INFORMATION_CLASS InformationClass
,
619 OUT PULONG ReturnedLength
624 HaliSetSystemInformation(
625 IN HAL_SET_INFORMATION_CLASS InformationClass
,
635 HalpBiosDisplayReset(
642 PKTRAP_FRAME TrapFrame
652 // Processor Halt Routine
661 // CMOS initialization
670 // Spinlock for protecting CMOS access
674 HalpAcquireSystemHardwareSpinLock(
680 HalpReleaseCmosSpinLock(
686 HalpAllocPhysicalMemory(
687 IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
695 HalpMapPhysicalMemory64(
696 IN PHYSICAL_ADDRESS PhysicalAddress
,
703 IN PKTRAP_FRAME TrapFrame
,
709 #define KfLowerIrql KeLowerIrql
711 /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
712 #define KiAcquireSpinLock(SpinLock)
713 #define KiReleaseSpinLock(SpinLock)
714 #define KfAcquireSpinLock(SpinLock) KfRaiseIrql(DISPATCH_LEVEL);
715 #define KfReleaseSpinLock(SpinLock, OldIrql) KeLowerIrql(OldIrql);
716 #endif // !CONFIG_SMP
719 extern BOOLEAN HalpNMIInProgress
;
721 extern ADDRESS_USAGE HalpDefaultIoSpace
;
723 extern KSPIN_LOCK HalpSystemHardwareLock
;
725 extern PADDRESS_USAGE HalpAddressUsageList
;
727 extern LARGE_INTEGER HalpPerfCounter
;