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