Merge 25584, 25588.
[reactos.git] / reactos / hal / halx86 / generic / halinit.c
1 /*
2 * PROJECT: ReactOS HAL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halx86/generic/halinit.c
5 * PURPOSE: HAL Entrypoint and Initialization
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS *******************************************************************/
16
17 HALP_HOOKS HalpHooks;
18 BOOLEAN HalpPciLockSettings;
19
20 /* PRIVATE FUNCTIONS *********************************************************/
21
22 VOID
23 NTAPI
24 HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
25 {
26 PCHAR CommandLine;
27
28 /* Make sure we have a loader block and command line */
29 if ((LoaderBlock) && (LoaderBlock->LoadOptions))
30 {
31 /* Read the command line */
32 CommandLine = LoaderBlock->LoadOptions;
33
34 /* Check if PCI is locked */
35 if (strstr(CommandLine, "PCILOCK")) HalpPciLockSettings = TRUE;
36
37 /* Check for initial breakpoint */
38 if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
39 }
40 }
41
42 /* FUNCTIONS *****************************************************************/
43
44 /*
45 * @implemented
46 */
47 BOOLEAN
48 NTAPI
49 HalInitSystem(IN ULONG BootPhase,
50 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
51 {
52 PKPRCB Prcb = KeGetCurrentPrcb();
53
54 /* Check the boot phase */
55 if (!BootPhase)
56 {
57 /* Phase 0... save bus type */
58 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
59
60 /* Get command-line parameters */
61 HalpGetParameters(LoaderBlock);
62
63 /* Checked HAL requires checked kernel */
64 #if DBG
65 if (!(Prcb->BuildType & PRCB_BUILD_DEBUG))
66 {
67 /* No match, bugcheck */
68 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 1, 0);
69 }
70 #else
71 /* Release build requires release HAL */
72 if (Prcb->BuildType & PRCB_BUILD_DEBUG)
73 {
74 /* No match, bugcheck */
75 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
76 }
77 #endif
78
79 #ifdef CONFIG_SMP
80 /* SMP HAL requires SMP kernel */
81 if (Prcb->BuildType & PRCB_BUILD_UNIPROCESSOR)
82 {
83 /* No match, bugcheck */
84 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
85 }
86 #endif
87
88 /* Validate the PRCB */
89 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
90 {
91 /* Validation failed, bugcheck */
92 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, 1, 0);
93 }
94
95 /* Initialize the PICs */
96 HalpInitPICs();
97
98 /* Force initial PIC state */
99 KfRaiseIrql(KeGetCurrentIrql());
100
101 /* Initialize the clock */
102 HalpInitializeClock();
103
104 /* Setup busy waiting */
105 //HalpCalibrateStallExecution();
106
107 /* Fill out the dispatch tables */
108 HalQuerySystemInformation = HaliQuerySystemInformation;
109 HalSetSystemInformation = HaliSetSystemInformation;
110 HalInitPnpDriver = NULL; // FIXME: TODO
111 HalGetDmaAdapter = HalpGetDmaAdapter;
112 HalGetInterruptTranslator = NULL; // FIXME: TODO
113
114 /* Initialize the hardware lock (CMOS) */
115 KeInitializeSpinLock(&HalpSystemHardwareLock);
116 }
117 else if (BootPhase == 1)
118 {
119 /* Initialize the default HAL stubs for bus handling functions */
120 HalpInitNonBusHandler();
121
122 /* Enable the clock interrupt */
123 ((PKIPCR)KeGetPcr())->IDT[0x30].ExtendedOffset =
124 (USHORT)(((ULONG_PTR)HalpClockInterrupt >> 16) & 0xFFFF);
125 ((PKIPCR)KeGetPcr())->IDT[0x30].Offset =
126 (USHORT)HalpClockInterrupt;
127 HalEnableSystemInterrupt(0x30, CLOCK2_LEVEL, Latched);
128
129 /* Initialize DMA. NT does this in Phase 0 */
130 HalpInitDma();
131 }
132
133 /* All done, return */
134 return TRUE;
135 }
136
137 /*
138 * @unimplemented
139 */
140 VOID
141 NTAPI
142 HalReportResourceUsage(VOID)
143 {
144 /* Initialize PCI bus. */
145 HalpInitializePciBus();
146
147 /* FIXME: This is done in ReactOS MP HAL only*/
148 //HaliReconfigurePciInterrupts();
149
150 /* FIXME: Report HAL Usage to kernel */
151 }
152
153 /* EOF */