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 CODE_SEG("INIT") 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 VOID 45 NTAPI 46 HalInitializeProcessor( 47 IN ULONG ProcessorNumber, 48 IN PLOADER_PARAMETER_BLOCK LoaderBlock) 49 { 50 /* Hal specific initialization for this cpu */ 51 HalpInitProcessor(ProcessorNumber, LoaderBlock); 52 53 /* Set default stall count */ 54 KeGetPcr()->StallScaleFactor = INITIAL_STALL_COUNT; 55 56 /* Update the interrupt affinity and processor mask */ 57 InterlockedBitTestAndSet((PLONG)&HalpActiveProcessors, ProcessorNumber); 58 InterlockedBitTestAndSet((PLONG)&HalpDefaultInterruptAffinity, 59 ProcessorNumber); 60 61 /* Register routines for KDCOM */ 62 HalpRegisterKdSupportFunctions(); 63 } 64 65 /* 66 * @implemented 67 */ 68 CODE_SEG("INIT") 69 BOOLEAN 70 NTAPI 71 HalInitSystem(IN ULONG BootPhase, 72 IN PLOADER_PARAMETER_BLOCK LoaderBlock) 73 { 74 PKPRCB Prcb = KeGetCurrentPrcb(); 75 76 /* Check the boot phase */ 77 if (BootPhase == 0) 78 { 79 /* Phase 0... save bus type */ 80 HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF; 81 82 /* Get command-line parameters */ 83 HalpGetParameters(LoaderBlock); 84 85 /* Check for PRCB version mismatch */ 86 if (Prcb->MajorVersion != PRCB_MAJOR_VERSION) 87 { 88 /* No match, bugcheck */ 89 KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, PRCB_MAJOR_VERSION, 0); 90 } 91 92 /* Checked/free HAL requires checked/free kernel */ 93 if (Prcb->BuildType != HalpBuildType) 94 { 95 /* No match, bugcheck */ 96 KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, HalpBuildType, 0); 97 } 98 99 /* Initialize ACPI */ 100 HalpSetupAcpiPhase0(LoaderBlock); 101 102 /* Initialize the PICs */ 103 HalpInitializePICs(TRUE); 104 105 /* Initialize CMOS lock */ 106 KeInitializeSpinLock(&HalpSystemHardwareLock); 107 108 /* Initialize CMOS */ 109 HalpInitializeCmos(); 110 111 /* Fill out the dispatch tables */ 112 HalQuerySystemInformation = HaliQuerySystemInformation; 113 HalSetSystemInformation = HaliSetSystemInformation; 114 HalInitPnpDriver = HaliInitPnpDriver; 115 HalGetDmaAdapter = HalpGetDmaAdapter; 116 117 HalGetInterruptTranslator = NULL; // FIXME: TODO 118 HalResetDisplay = HalpBiosDisplayReset; 119 HalHaltSystem = HaliHaltSystem; 120 121 /* Setup I/O space */ 122 HalpDefaultIoSpace.Next = HalpAddressUsageList; 123 HalpAddressUsageList = &HalpDefaultIoSpace; 124 125 /* Setup busy waiting */ 126 HalpCalibrateStallExecution(); 127 128 /* Initialize the clock */ 129 HalpInitializeClock(); 130 131 /* 132 * We could be rebooting with a pending profile interrupt, 133 * so clear it here before interrupts are enabled 134 */ 135 HalStopProfileInterrupt(ProfileTime); 136 137 /* Do some HAL-specific initialization */ 138 HalpInitPhase0(LoaderBlock); 139 140 #ifdef _M_AMD64 141 HalInitializeBios(0, LoaderBlock); 142 #endif 143 } 144 else if (BootPhase == 1) 145 { 146 /* Initialize bus handlers */ 147 HalpInitBusHandlers(); 148 149 /* Do some HAL-specific initialization */ 150 HalpInitPhase1(); 151 152 #ifdef _M_AMD64 153 HalInitializeBios(1, LoaderBlock); 154 #endif 155 } 156 157 /* All done, return */ 158 return TRUE; 159 } 160