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