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