[ntoskrnl]
[reactos.git] / reactos / 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 /* 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 /*
44 * @implemented
45 */
46 BOOLEAN
47 NTAPI
48 HalInitSystem(IN ULONG BootPhase,
49 IN PLOADER_PARAMETER_BLOCK LoaderBlock)
50 {
51 PKPRCB Prcb = KeGetCurrentPrcb();
52
53 /* Check the boot phase */
54 if (!BootPhase)
55 {
56 /* Phase 0... save bus type */
57 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
58
59 /* Get command-line parameters */
60 HalpGetParameters(LoaderBlock);
61
62 /* Checked HAL requires checked kernel */
63 #if DBG
64 if (!(Prcb->BuildType & PRCB_BUILD_DEBUG))
65 {
66 /* No match, bugcheck */
67 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 1, 0);
68 }
69 #else
70 /* Release build requires release HAL */
71 if (Prcb->BuildType & PRCB_BUILD_DEBUG)
72 {
73 /* No match, bugcheck */
74 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
75 }
76 #endif
77
78 #ifdef CONFIG_SMP
79 /* SMP HAL requires SMP kernel */
80 if (Prcb->BuildType & PRCB_BUILD_UNIPROCESSOR)
81 {
82 /* No match, bugcheck */
83 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
84 }
85 #endif
86
87 /* Validate the PRCB */
88 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
89 {
90 /* Validation failed, bugcheck */
91 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, 1, 0);
92 }
93
94 /* Initialize the PICs */
95 HalpInitPICs();
96
97 /* Force initial PIC state */
98 KfRaiseIrql(KeGetCurrentIrql());
99
100 /* Initialize the clock */
101 HalpInitializeClock();
102
103 /* Setup busy waiting */
104 HalpCalibrateStallExecution();
105
106 /* Fill out the dispatch tables */
107 HalQuerySystemInformation = HaliQuerySystemInformation;
108 HalSetSystemInformation = HaliSetSystemInformation;
109 HalInitPnpDriver = NULL; // FIXME: TODO
110 HalGetDmaAdapter = HalpGetDmaAdapter;
111 HalGetInterruptTranslator = NULL; // FIXME: TODO
112 HalResetDisplay = HalpBiosDisplayReset;
113
114 /* Initialize the hardware lock (CMOS) */
115 KeInitializeSpinLock(&HalpSystemHardwareLock);
116
117 /* Do some HAL-specific initialization */
118 HalpInitPhase0(LoaderBlock);
119 }
120 else if (BootPhase == 1)
121 {
122 /* Initialize the default HAL stubs for bus handling functions */
123 HalpInitNonBusHandler();
124
125 /* Enable the clock interrupt */
126 ((PKIPCR)KeGetPcr())->IDT[0x30].ExtendedOffset =
127 (USHORT)(((ULONG_PTR)HalpClockInterrupt >> 16) & 0xFFFF);
128 ((PKIPCR)KeGetPcr())->IDT[0x30].Offset =
129 (USHORT)((ULONG_PTR)HalpClockInterrupt);
130 HalEnableSystemInterrupt(0x30, CLOCK2_LEVEL, Latched);
131
132 /* Initialize DMA. NT does this in Phase 0 */
133 HalpInitDma();
134
135 /* Do some HAL-specific initialization */
136 HalpInitPhase1();
137 }
138
139 /* All done, return */
140 return TRUE;
141 }
142
143 /*
144 * @unimplemented
145 */
146 VOID
147 NTAPI
148 HalReportResourceUsage(VOID)
149 {
150 /* Initialize PCI bus. */
151 HalpInitializePciBus();
152
153 /* FIXME: This is done in ReactOS MP HAL only*/
154 //HaliReconfigurePciInterrupts();
155
156 /* FIXME: Report HAL Usage to kernel */
157 }
158
159 /* EOF */