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 CODE_SEG("INIT")
22 VOID
23 NTAPI
HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)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 VOID
45 NTAPI
HalInitializeProcessor(IN ULONG ProcessorNumber,IN PLOADER_PARAMETER_BLOCK LoaderBlock)46 HalInitializeProcessor(
47 IN ULONG ProcessorNumber,
48 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
49 {
50 /* Hal specific initialization for this cpu */
51 HalpInitProcessor(ProcessorNumber, LoaderBlock);
52
53 /* Set default stall count */
54 KeGetPcr()->StallScaleFactor = INITIAL_STALL_COUNT;
55
56 /* Update the interrupt affinity and processor mask */
57 InterlockedBitTestAndSetAffinity(&HalpActiveProcessors, ProcessorNumber);
58 InterlockedBitTestAndSetAffinity(&HalpDefaultInterruptAffinity, ProcessorNumber);
59
60 if (ProcessorNumber == 0)
61 {
62 /* Register routines for KDCOM */
63 HalpRegisterKdSupportFunctions();
64 }
65 }
66
67 /*
68 * @implemented
69 */
70 CODE_SEG("INIT")
71 BOOLEAN
72 NTAPI
HalInitSystem(IN ULONG BootPhase,IN PLOADER_PARAMETER_BLOCK LoaderBlock)73 HalInitSystem(IN ULONG BootPhase,
74 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
75 {
76 PKPRCB Prcb = KeGetCurrentPrcb();
77 NTSTATUS Status;
78
79 /* Check the boot phase */
80 if (BootPhase == 0)
81 {
82 /* Phase 0... save bus type */
83 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
84
85 /* Get command-line parameters */
86 HalpGetParameters(LoaderBlock);
87
88 /* Check for PRCB version mismatch */
89 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
90 {
91 /* No match, bugcheck */
92 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, PRCB_MAJOR_VERSION, 0);
93 }
94
95 /* Checked/free HAL requires checked/free kernel */
96 if (Prcb->BuildType != HalpBuildType)
97 {
98 /* No match, bugcheck */
99 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, HalpBuildType, 0);
100 }
101
102 /* Initialize ACPI */
103 Status = HalpSetupAcpiPhase0(LoaderBlock);
104 if (!NT_SUCCESS(Status))
105 {
106 KeBugCheckEx(ACPI_BIOS_ERROR, Status, 0, 0, 0);
107 }
108
109 /* Initialize the PICs */
110 HalpInitializePICs(TRUE);
111
112 /* Initialize CMOS lock */
113 KeInitializeSpinLock(&HalpSystemHardwareLock);
114
115 /* Initialize CMOS */
116 HalpInitializeCmos();
117
118 /* Fill out the dispatch tables */
119 HalQuerySystemInformation = HaliQuerySystemInformation;
120 HalSetSystemInformation = HaliSetSystemInformation;
121 HalInitPnpDriver = HaliInitPnpDriver;
122 HalGetDmaAdapter = HalpGetDmaAdapter;
123
124 HalGetInterruptTranslator = NULL; // FIXME: TODO
125 HalResetDisplay = HalpBiosDisplayReset;
126 HalHaltSystem = HaliHaltSystem;
127
128 /* Setup I/O space */
129 HalpDefaultIoSpace.Next = HalpAddressUsageList;
130 HalpAddressUsageList = &HalpDefaultIoSpace;
131
132 /* Setup busy waiting */
133 HalpCalibrateStallExecution();
134
135 /* Initialize the clock */
136 HalpInitializeClock();
137
138 /*
139 * We could be rebooting with a pending profile interrupt,
140 * so clear it here before interrupts are enabled
141 */
142 HalStopProfileInterrupt(ProfileTime);
143
144 /* Do some HAL-specific initialization */
145 HalpInitPhase0(LoaderBlock);
146
147 /* Initialize Phase 0 of the x86 emulator */
148 HalInitializeBios(0, LoaderBlock);
149 }
150 else if (BootPhase == 1)
151 {
152 /* Initialize bus handlers */
153 HalpInitBusHandlers();
154
155 /* Do some HAL-specific initialization */
156 HalpInitPhase1();
157
158 /* Initialize Phase 1 of the x86 emulator */
159 HalInitializeBios(1, LoaderBlock);
160 }
161
162 /* All done, return */
163 return TRUE;
164 }
165