[HAL]
[reactos.git] / reactos / hal / halamd64 / 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 HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
24 {
25 PCHAR CommandLine;
26
27 /* Make sure we have a loader block and command line */
28 if ((LoaderBlock) && (LoaderBlock->LoadOptions))
29 {
30 /* Read the command line */
31 CommandLine = LoaderBlock->LoadOptions;
32
33 /* Check if PCI is locked */
34 if (strstr(CommandLine, "PCILOCK")) HalpPciLockSettings = TRUE;
35
36 /* Check for initial breakpoint */
37 if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
38 }
39 }
40
41 /* FUNCTIONS *****************************************************************/
42
43 NTSTATUS
44 NTAPI
45 DriverEntry(
46 PDRIVER_OBJECT DriverObject,
47 PUNICODE_STRING RegistryPath)
48 {
49 UNIMPLEMENTED;
50
51 return STATUS_SUCCESS;
52 }
53
54 /*
55 * @implemented
56 */
57 BOOLEAN
58 NTAPI
59 HalInitSystem(IN ULONG BootPhase,
60 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
61 {
62 PKPRCB Prcb = KeGetCurrentPrcb();
63
64 /* Check the boot phase */
65 if (BootPhase == 0)
66 {
67 /* Phase 0... save bus type */
68 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
69
70 /* Get command-line parameters */
71 HalpGetParameters(LoaderBlock);
72
73 #if DBG
74 /* Checked HAL requires checked kernel */
75 if (!(Prcb->BuildType & PRCB_BUILD_DEBUG))
76 {
77 /* No match, bugcheck */
78 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 1, 0);
79 }
80 #else
81 /* Release build requires release HAL */
82 if (Prcb->BuildType & PRCB_BUILD_DEBUG)
83 {
84 /* No match, bugcheck */
85 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
86 }
87 #endif
88
89 #ifdef CONFIG_SMP
90 /* SMP HAL requires SMP kernel */
91 if (Prcb->BuildType & PRCB_BUILD_UNIPROCESSOR)
92 {
93 /* No match, bugcheck */
94 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
95 }
96 #endif
97
98 /* Validate the PRCB */
99 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
100 {
101 /* Validation failed, bugcheck */
102 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, 1, 0);
103 }
104
105 DPRINT1("HalInitSystem 1\n");
106
107 /* Initialize the PICs */
108 HalpInitPICs();
109
110 DPRINT1("HalInitSystem 2\n");
111
112 /* Initialize the clock */
113 HalpInitializeClock();
114
115 DPRINT1("HalInitSystem 3\n");
116
117 /* Calibrate counters */
118 // HalpCalibrateCounters();
119
120 /* Fill out the dispatch tables */
121 HalQuerySystemInformation = HaliQuerySystemInformation;
122 HalSetSystemInformation = HaliSetSystemInformation;
123 HalInitPnpDriver = NULL; // FIXME: TODO
124 // HalGetDmaAdapter = HalpGetDmaAdapter;
125 HalGetInterruptTranslator = NULL; // FIXME: TODO
126 // HalResetDisplay = HalpBiosDisplayReset;
127
128 DPRINT1("HalInitSystem 4\n");
129
130 /* Initialize the hardware lock (CMOS) */
131 KeInitializeSpinLock(&HalpSystemHardwareLock);
132
133 /* Do some HAL-specific initialization */
134 HalpInitPhase0(LoaderBlock);
135 }
136 else if (BootPhase == 1)
137 {
138 /* Initialize bus handlers */
139 //HalpInitBusHandler();
140
141 /* Enable the clock interrupt */
142 HalpSetInterruptGate(0x30, HalpClockInterrupt);
143 HalEnableSystemInterrupt(0x30, CLOCK_LEVEL, Latched);
144
145 /* Initialize DMA. NT does this in Phase 0 */
146 HalpInitDma();
147
148 /* Do some HAL-specific initialization */
149 HalpInitPhase1();
150 }
151
152 /* All done, return */
153 return TRUE;
154 }
155
156 /*
157 * @unimplemented
158 */
159 VOID
160 NTAPI
161 HalReportResourceUsage(VOID)
162 {
163 /* Initialize PCI bus. */
164 HalpInitializePciBus();
165
166 /* FIXME: This is done in ReactOS MP HAL only*/
167 //HaliReconfigurePciInterrupts();
168
169 /* FIXME: Report HAL Usage to kernel */
170 }
171
172 /* EOF */