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