xref: /reactos/hal/halarm/generic/halinit.c (revision b819608e)
1 /*
2  * PROJECT:         ReactOS HAL
3  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4  * FILE:            hal/halarm/generic/halinit.c
5  * PURPOSE:         HAL Entrypoint and Initialization
6  * PROGRAMMERS:     ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS ********************************************************************/
16 
17 /* PRIVATE FUNCTIONS **********************************************************/
18 
19 VOID
20 NTAPI
21 HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
22 {
23     PCHAR CommandLine;
24 
25     /* Make sure we have a loader block and command line */
26     if ((LoaderBlock) && (LoaderBlock->LoadOptions))
27     {
28         /* Read the command line */
29         CommandLine = LoaderBlock->LoadOptions;
30 
31         /* Check for initial breakpoint */
32         if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
33     }
34 }
35 
36 /* FUNCTIONS ******************************************************************/
37 
38 /*
39  * @implemented
40  */
41 BOOLEAN
42 NTAPI
43 HalInitSystem(IN ULONG BootPhase,
44               IN PLOADER_PARAMETER_BLOCK LoaderBlock)
45 {
46     PKPRCB Prcb = KeGetCurrentPrcb();
47 
48     /* Check the boot phase */
49     if (!BootPhase)
50     {
51         /* Get command-line parameters */
52         HalpGetParameters(LoaderBlock);
53 
54         /* Checked HAL requires checked kernel */
55 #if DBG
56         if (!(Prcb->BuildType & PRCB_BUILD_DEBUG))
57         {
58             /* No match, bugcheck */
59             KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 1, 0);
60         }
61 #else
62         /* Release build requires release HAL */
63         if (Prcb->BuildType & PRCB_BUILD_DEBUG)
64         {
65             /* No match, bugcheck */
66             KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
67         }
68 #endif
69 
70 #ifdef CONFIG_SMP
71         /* SMP HAL requires SMP kernel */
72         if (Prcb->BuildType & PRCB_BUILD_UNIPROCESSOR)
73         {
74             /* No match, bugcheck */
75             KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, 0, 0);
76         }
77 #endif
78 
79         /* Validate the PRCB */
80         if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
81         {
82             /* Validation failed, bugcheck */
83             KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, 1, 0);
84         }
85 
86         /* Initialize interrupts */
87         HalpInitializeInterrupts();
88 
89         /* Force initial PIC state */
90         KfRaiseIrql(KeGetCurrentIrql());
91 
92         /* Fill out the dispatch tables */
93         //HalQuerySystemInformation = NULL; // FIXME: TODO;
94         //HalSetSystemInformation = NULL; // FIXME: TODO;
95         //HalInitPnpDriver = NULL; // FIXME: TODO
96         //HalGetDmaAdapter = NULL; // FIXME: TODO;
97         //HalGetInterruptTranslator = NULL;  // FIXME: TODO
98         //HalResetDisplay = NULL; // FIXME: TODO;
99         //HalHaltSystem = NULL; // FIXME: TODO;
100 
101         /* Setup I/O space */
102         //HalpDefaultIoSpace.Next = HalpAddressUsageList;
103         //HalpAddressUsageList = &HalpDefaultIoSpace;
104 
105         /* Setup busy waiting */
106         //HalpCalibrateStallExecution();
107 
108         /* Initialize the clock */
109         HalpInitializeClock();
110 
111         /* Setup time increments to 10ms and 1ms */
112         HalpCurrentTimeIncrement = 100000;
113         HalpNextTimeIncrement = 100000;
114         HalpNextIntervalCount = 0;
115         KeSetTimeIncrement(100000, 10000);
116 
117         /*
118          * We could be rebooting with a pending profile interrupt,
119          * so clear it here before interrupts are enabled
120          */
121         HalStopProfileInterrupt(ProfileTime);
122 
123         /* Do some HAL-specific initialization */
124         HalpInitPhase0(LoaderBlock);
125     }
126     else if (BootPhase == 1)
127     {
128         /* Enable timer interrupt */
129         HalpEnableInterruptHandler(IDT_DEVICE,
130                                    0,
131                                    PRIMARY_VECTOR_BASE,
132                                    CLOCK2_LEVEL,
133                                    HalpClockInterrupt,
134                                    Latched);
135 #if 0
136         /* Enable IRQ 8 */
137         HalpEnableInterruptHandler(IDT_DEVICE,
138                                    0,
139                                    PRIMARY_VECTOR_BASE + 8,
140                                    PROFILE_LEVEL,
141                                    HalpProfileInterrupt,
142                                    Latched);
143 #endif
144         /* Initialize DMA. NT does this in Phase 0 */
145         //HalpInitDma();
146 
147         /* Do some HAL-specific initialization */
148         HalpInitPhase1();
149     }
150 
151     /* All done, return */
152     return TRUE;
153 }
154 
155 #include <internal/kd.h>
156 ULONG
157 DbgPrintEarly(const char *fmt, ...)
158 {
159     va_list args;
160     unsigned int i;
161     char Buffer[1024];
162     PCHAR String = Buffer;
163 
164     va_start(args, fmt);
165     i = vsprintf(Buffer, fmt, args);
166     va_end(args);
167 
168     /* Output the message */
169     while (*String != 0)
170     {
171         if (*String == '\n')
172         {
173             KdPortPutByteEx(NULL, '\r');
174         }
175         KdPortPutByteEx(NULL, *String);
176         String++;
177     }
178 
179     return STATUS_SUCCESS;
180 }
181 
182 /* EOF */
183