f03038b60858e9be698575118886f5205d98ca43
[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 VOID
16 NTAPI
17 HalpGetParameters(
18 IN PLOADER_PARAMETER_BLOCK LoaderBlock
19 );
20
21 #if defined(ALLOC_PRAGMA) && !defined(_MINIHAL_)
22 #pragma alloc_text(INIT, HalInitSystem)
23 #pragma alloc_text(INIT, HalpGetParameters)
24 #endif
25
26 /* GLOBALS *******************************************************************/
27
28 BOOLEAN HalpPciLockSettings;
29
30 /* PRIVATE FUNCTIONS *********************************************************/
31
32 INIT_SECTION
33 VOID
34 NTAPI
35 HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
36 {
37 PCHAR CommandLine;
38
39 /* Make sure we have a loader block and command line */
40 if ((LoaderBlock) && (LoaderBlock->LoadOptions))
41 {
42 /* Read the command line */
43 CommandLine = LoaderBlock->LoadOptions;
44
45 /* Check if PCI is locked */
46 if (strstr(CommandLine, "PCILOCK")) HalpPciLockSettings = TRUE;
47
48 /* Check for initial breakpoint */
49 if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
50 }
51 }
52
53 /* FUNCTIONS *****************************************************************/
54
55 VOID
56 NTAPI
57 HalInitializeProcessor(
58 IN ULONG ProcessorNumber,
59 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
60 {
61 /* Hal specific initialization for this cpu */
62 HalpInitProcessor(ProcessorNumber, LoaderBlock);
63
64 /* Set default stall count */
65 KeGetPcr()->StallScaleFactor = INITIAL_STALL_COUNT;
66
67 /* Update the interrupt affinity and processor mask */
68 InterlockedBitTestAndSet((PLONG)&HalpActiveProcessors, ProcessorNumber);
69 InterlockedBitTestAndSet((PLONG)&HalpDefaultInterruptAffinity,
70 ProcessorNumber);
71
72 /* Register routines for KDCOM */
73 HalpRegisterKdSupportFunctions();
74 }
75
76 /*
77 * @implemented
78 */
79 INIT_SECTION
80 BOOLEAN
81 NTAPI
82 HalInitSystem(IN ULONG BootPhase,
83 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
84 {
85 PKPRCB Prcb = KeGetCurrentPrcb();
86
87 /* Check the boot phase */
88 if (BootPhase == 0)
89 {
90 /* Phase 0... save bus type */
91 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
92
93 /* Get command-line parameters */
94 HalpGetParameters(LoaderBlock);
95
96 /* Check for PRCB version mismatch */
97 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
98 {
99 /* No match, bugcheck */
100 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, PRCB_MAJOR_VERSION, 0);
101 }
102
103 /* Checked/free HAL requires checked/free kernel */
104 if (Prcb->BuildType != HalpBuildType)
105 {
106 /* No match, bugcheck */
107 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, HalpBuildType, 0);
108 }
109
110 /* Initialize ACPI */
111 HalpSetupAcpiPhase0(LoaderBlock);
112
113 /* Initialize the PICs */
114 HalpInitializePICs(TRUE);
115
116 /* Initialize CMOS lock */
117 KeInitializeSpinLock(&HalpSystemHardwareLock);
118
119 /* Initialize CMOS */
120 HalpInitializeCmos();
121
122 /* Fill out the dispatch tables */
123 HalQuerySystemInformation = HaliQuerySystemInformation;
124 HalSetSystemInformation = HaliSetSystemInformation;
125 HalInitPnpDriver = HaliInitPnpDriver;
126 HalGetDmaAdapter = HalpGetDmaAdapter;
127
128 HalGetInterruptTranslator = NULL; // FIXME: TODO
129 HalResetDisplay = HalpBiosDisplayReset;
130 HalHaltSystem = HaliHaltSystem;
131
132 /* Setup I/O space */
133 HalpDefaultIoSpace.Next = HalpAddressUsageList;
134 HalpAddressUsageList = &HalpDefaultIoSpace;
135
136 /* Setup busy waiting */
137 HalpCalibrateStallExecution();
138
139 /* Initialize the clock */
140 HalpInitializeClock();
141
142 /*
143 * We could be rebooting with a pending profile interrupt,
144 * so clear it here before interrupts are enabled
145 */
146 HalStopProfileInterrupt(ProfileTime);
147
148 /* Do some HAL-specific initialization */
149 HalpInitPhase0(LoaderBlock);
150 }
151 else if (BootPhase == 1)
152 {
153 /* Initialize bus handlers */
154 HalpInitBusHandlers();
155
156 /* Do some HAL-specific initialization */
157 HalpInitPhase1();
158 }
159
160 /* All done, return */
161 return TRUE;
162 }