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