Sync to trunk head (r47736)
[reactos.git] / 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 BOOLEAN HalpPciLockSettings;
18
19 /* PRIVATE FUNCTIONS *********************************************************/
20
21 VOID
22 NTAPI
23 HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
24 {
25 PCHAR CommandLine;
26
27 /* Make sure we have a loader block and command line */
28 if ((LoaderBlock) && (LoaderBlock->LoadOptions))
29 {
30 /* Read the command line */
31 CommandLine = LoaderBlock->LoadOptions;
32
33 /* Check if PCI is locked */
34 if (strstr(CommandLine, "PCILOCK")) HalpPciLockSettings = TRUE;
35
36 /* Check for initial breakpoint */
37 if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
38 }
39 }
40
41 /* FUNCTIONS *****************************************************************/
42
43 /*
44 * @implemented
45 */
46 BOOLEAN
47 NTAPI
48 HalInitSystem(IN ULONG BootPhase,
49 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
50 {
51 PKPRCB Prcb = KeGetCurrentPrcb();
52
53 /* Check the boot phase */
54 if (!BootPhase)
55 {
56 /* Phase 0... save bus type */
57 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
58
59 /* Get command-line parameters */
60 HalpGetParameters(LoaderBlock);
61
62 /* Checked HAL requires checked kernel */
63 #if DBG
64 if (!(Prcb->BuildType & PRCB_BUILD_DEBUG))
65 {
66 /* No match, bugcheck */
67 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 1, 0);
68 }
69 #else
70 /* Release build requires release HAL */
71 if (Prcb->BuildType & PRCB_BUILD_DEBUG)
72 {
73 /* No match, bugcheck */
74 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
75 }
76 #endif
77
78 #ifdef CONFIG_SMP
79 /* SMP HAL requires SMP kernel */
80 if (Prcb->BuildType & PRCB_BUILD_UNIPROCESSOR)
81 {
82 /* No match, bugcheck */
83 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
84 }
85 #endif
86
87 /* Validate the PRCB */
88 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
89 {
90 /* Validation failed, bugcheck */
91 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, 1, 0);
92 }
93
94 #ifndef _MINIHAL_
95 /* Initialize ACPI */
96 HalpSetupAcpiPhase0(LoaderBlock);
97
98 /* Initialize the PICs */
99 HalpInitializePICs(TRUE);
100 #endif
101
102 /* Force initial PIC state */
103 KfRaiseIrql(KeGetCurrentIrql());
104
105 /* Initialize CMOS lock */
106 KeInitializeSpinLock(&HalpSystemHardwareLock);
107
108 /* Initialize CMOS */
109 HalpInitializeCmos();
110
111 /* Fill out the dispatch tables */
112 HalQuerySystemInformation = HaliQuerySystemInformation;
113 HalSetSystemInformation = HaliSetSystemInformation;
114 HalInitPnpDriver = NULL; // FIXME: TODO
115 #ifndef _MINIHAL_
116 HalGetDmaAdapter = HalpGetDmaAdapter;
117 #else
118 HalGetDmaAdapter = NULL;
119 #endif
120 HalGetInterruptTranslator = NULL; // FIXME: TODO
121 #ifndef _MINIHAL_
122 HalResetDisplay = HalpBiosDisplayReset;
123 #else
124 HalResetDisplay = NULL;
125 #endif
126 HalHaltSystem = HaliHaltSystem;
127
128 /* Register IRQ 2 */
129 HalpRegisterVector(IDT_INTERNAL,
130 PRIMARY_VECTOR_BASE + 2,
131 PRIMARY_VECTOR_BASE + 2,
132 HIGH_LEVEL);
133
134 /* Setup I/O space */
135 HalpDefaultIoSpace.Next = HalpAddressUsageList;
136 HalpAddressUsageList = &HalpDefaultIoSpace;
137
138 /* Setup busy waiting */
139 HalpCalibrateStallExecution();
140
141 #ifndef _MINIHAL_
142 /* Initialize the clock */
143 HalpInitializeClock();
144 #endif
145
146 /*
147 * We could be rebooting with a pending profile interrupt,
148 * so clear it here before interrupts are enabled
149 */
150 HalStopProfileInterrupt(ProfileTime);
151
152 /* Do some HAL-specific initialization */
153 HalpInitPhase0(LoaderBlock);
154 }
155 else if (BootPhase == 1)
156 {
157 /* Initialize bus handlers */
158 HalpInitBusHandlers();
159
160 #ifndef _MINIHAL_
161 /* Enable IRQ 0 */
162 HalpEnableInterruptHandler(IDT_DEVICE,
163 0,
164 PRIMARY_VECTOR_BASE,
165 CLOCK2_LEVEL,
166 HalpClockInterrupt,
167 Latched);
168
169 /* Enable IRQ 8 */
170 HalpEnableInterruptHandler(IDT_DEVICE,
171 0,
172 PRIMARY_VECTOR_BASE + 8,
173 PROFILE_LEVEL,
174 HalpProfileInterrupt,
175 Latched);
176
177 /* Initialize DMA. NT does this in Phase 0 */
178 HalpInitDma();
179 #endif
180
181 /* Do some HAL-specific initialization */
182 HalpInitPhase1();
183 }
184
185 /* All done, return */
186 return TRUE;
187 }