2006-11-15 00:08:51 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS HAL
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2006-11-29 08:28:20 +00:00
|
|
|
* FILE: hal/halx86/generic/halinit.c
|
|
|
|
* PURPOSE: HAL Entrypoint and Initialization
|
2006-11-15 00:08:51 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2001-08-21 20:18:27 +00:00
|
|
|
*/
|
|
|
|
|
2006-11-15 00:08:51 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2005-06-18 14:29:31 +00:00
|
|
|
#include <hal.h>
|
2005-06-19 22:53:49 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2015-09-05 18:33:38 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
HalpGetParameters(
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(ALLOC_PRAGMA) && !defined(_MINIHAL_)
|
|
|
|
#pragma alloc_text(INIT, HalInitSystem)
|
|
|
|
#pragma alloc_text(INIT, HalpGetParameters)
|
|
|
|
#endif
|
|
|
|
|
2006-11-15 00:08:51 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2004-03-18 19:58:35 +00:00
|
|
|
|
2006-11-27 19:26:31 +00:00
|
|
|
BOOLEAN HalpPciLockSettings;
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2006-11-27 19:26:31 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
|
|
|
{
|
|
|
|
PCHAR CommandLine;
|
|
|
|
|
|
|
|
/* Make sure we have a loader block and command line */
|
|
|
|
if ((LoaderBlock) && (LoaderBlock->LoadOptions))
|
|
|
|
{
|
|
|
|
/* Read the command line */
|
|
|
|
CommandLine = LoaderBlock->LoadOptions;
|
|
|
|
|
|
|
|
/* Check if PCI is locked */
|
|
|
|
if (strstr(CommandLine, "PCILOCK")) HalpPciLockSettings = TRUE;
|
|
|
|
|
|
|
|
/* Check for initial breakpoint */
|
|
|
|
if (strstr(CommandLine, "BREAK")) DbgBreakPoint();
|
|
|
|
}
|
|
|
|
}
|
2004-03-18 19:58:35 +00:00
|
|
|
|
2006-11-15 00:08:51 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2011-09-07 18:25:43 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
HalInitializeProcessor(
|
|
|
|
IN ULONG ProcessorNumber,
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
|
|
|
{
|
|
|
|
/* Hal specific initialization for this cpu */
|
|
|
|
HalpInitProcessor(ProcessorNumber, LoaderBlock);
|
|
|
|
|
|
|
|
/* Set default stall count */
|
|
|
|
KeGetPcr()->StallScaleFactor = INITIAL_STALL_COUNT;
|
|
|
|
|
|
|
|
/* Update the interrupt affinity and processor mask */
|
|
|
|
InterlockedBitTestAndSet((PLONG)&HalpActiveProcessors, ProcessorNumber);
|
|
|
|
InterlockedBitTestAndSet((PLONG)&HalpDefaultInterruptAffinity,
|
|
|
|
ProcessorNumber);
|
|
|
|
|
|
|
|
/* Register routines for KDCOM */
|
|
|
|
HalpRegisterKdSupportFunctions();
|
|
|
|
}
|
|
|
|
|
2006-11-15 00:08:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2006-11-15 00:08:51 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
HalInitSystem(IN ULONG BootPhase,
|
|
|
|
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2006-11-27 19:26:31 +00:00
|
|
|
PKPRCB Prcb = KeGetCurrentPrcb();
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-27 19:26:31 +00:00
|
|
|
/* Check the boot phase */
|
2011-09-02 14:45:19 +00:00
|
|
|
if (BootPhase == 0)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2006-11-27 19:26:31 +00:00
|
|
|
/* Phase 0... save bus type */
|
|
|
|
HalpBusType = LoaderBlock->u.I386.MachineType & 0xFF;
|
|
|
|
|
|
|
|
/* Get command-line parameters */
|
|
|
|
HalpGetParameters(LoaderBlock);
|
|
|
|
|
2011-09-07 18:25:43 +00:00
|
|
|
/* Check for PRCB version mismatch */
|
|
|
|
if (Prcb->MajorVersion != PRCB_MAJOR_VERSION)
|
2006-11-27 19:26:31 +00:00
|
|
|
{
|
|
|
|
/* No match, bugcheck */
|
2011-09-07 18:25:43 +00:00
|
|
|
KeBugCheckEx(MISMATCHED_HAL, 1, Prcb->MajorVersion, PRCB_MAJOR_VERSION, 0);
|
2006-11-27 19:26:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 18:25:43 +00:00
|
|
|
/* Checked/free HAL requires checked/free kernel */
|
2011-09-10 18:58:01 +00:00
|
|
|
if (Prcb->BuildType != HalpBuildType)
|
2006-11-27 19:26:31 +00:00
|
|
|
{
|
|
|
|
/* No match, bugcheck */
|
2011-09-10 18:58:01 +00:00
|
|
|
KeBugCheckEx(MISMATCHED_HAL, 2, Prcb->BuildType, HalpBuildType, 0);
|
2006-11-27 19:26:31 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 04:43:39 +00:00
|
|
|
/* Initialize ACPI */
|
|
|
|
HalpSetupAcpiPhase0(LoaderBlock);
|
|
|
|
|
2006-11-29 08:28:20 +00:00
|
|
|
/* Initialize the PICs */
|
2010-01-21 12:51:13 +00:00
|
|
|
HalpInitializePICs(TRUE);
|
2006-11-29 08:28:20 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Initialize CMOS lock */
|
|
|
|
KeInitializeSpinLock(&HalpSystemHardwareLock);
|
2006-11-27 19:26:31 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Initialize CMOS */
|
|
|
|
HalpInitializeCmos();
|
2009-10-27 01:03:41 +00:00
|
|
|
|
2006-11-27 19:26:31 +00:00
|
|
|
/* Fill out the dispatch tables */
|
|
|
|
HalQuerySystemInformation = HaliQuerySystemInformation;
|
|
|
|
HalSetSystemInformation = HaliSetSystemInformation;
|
2010-09-10 21:46:13 +00:00
|
|
|
HalInitPnpDriver = HaliInitPnpDriver;
|
2006-11-27 19:26:31 +00:00
|
|
|
HalGetDmaAdapter = HalpGetDmaAdapter;
|
2011-09-07 18:25:43 +00:00
|
|
|
|
2006-11-27 19:26:31 +00:00
|
|
|
HalGetInterruptTranslator = NULL; // FIXME: TODO
|
2007-12-15 17:15:48 +00:00
|
|
|
HalResetDisplay = HalpBiosDisplayReset;
|
- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysicalMemoryApi, DbgKdWriteBreakPointExApi, DbgKdRestoreBreakPointExApi, DbgKdSearchMemoryApi and DbgKdFillMemoryApi cases more properly.
- Fail on physical memory write like we do for read too.
- Don't handle OldVlm1/2 as they appear to be deprecated and unhandled in Windows.
- Implement HalHaltSystem to halt execution in a portable way. Default to xHalHaltSystem, a simple infinite loop, if we get called before HAL has initialized. Use this in KiBugCheckDebugBreak and the system shutdown handler instead of x86/AMD64/ARM intrinsics.
- Don't try to halt the CPU if KeBugCheck has been called 3 times or more -- if this happens, something has gone very wrong, and we shouldn't try to do anything special. Just loop infinitely.
- Fix KiBugCheckDebugBreak -- it shouldn't halt execution when called for the first chance as bugcheck callbacks have not been invoked at this point (nor has the BSOD been displayed). Use SEH to protect against a crash instead of checking KdDebuggerNotPresent as the debugger, if it is present, *could* disconnect while the trap is being handled. Also, don't halt execution if the debugger handled the breakpoint, just break again.
- Don't call MmMapIoSpace from HalpReboot! The reboot might take place at elevated IRQL (as high as HIGH_LEVEL if called from KeBugCheck), and thus can't use any Mm support routines. Use a PTE from the reserved HAL region and map it ourselves instead as done in the BIOS call code.
- Acquire the display ownership in HalReturnToFirmware in case the caller hasn't done so (as done in the KD reboot routine, for example).
- Just include ntndk.h in hal.h instead of including 6 NDK headers (which turns into more than half of the NDK anyway since those headers include other NDK headers).
- Crashing and rebooting from KD now works properly.
svn path=/trunk/; revision=43380
2009-10-11 20:16:45 +00:00
|
|
|
HalHaltSystem = HaliHaltSystem;
|
2006-11-27 19:26:31 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Setup I/O space */
|
|
|
|
HalpDefaultIoSpace.Next = HalpAddressUsageList;
|
|
|
|
HalpAddressUsageList = &HalpDefaultIoSpace;
|
|
|
|
|
|
|
|
/* Setup busy waiting */
|
|
|
|
HalpCalibrateStallExecution();
|
|
|
|
|
|
|
|
/* Initialize the clock */
|
|
|
|
HalpInitializeClock();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We could be rebooting with a pending profile interrupt,
|
|
|
|
* so clear it here before interrupts are enabled
|
|
|
|
*/
|
|
|
|
HalStopProfileInterrupt(ProfileTime);
|
2007-12-13 15:44:17 +00:00
|
|
|
|
|
|
|
/* Do some HAL-specific initialization */
|
|
|
|
HalpInitPhase0(LoaderBlock);
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|
2006-11-15 00:08:51 +00:00
|
|
|
else if (BootPhase == 1)
|
2001-08-21 20:18:27 +00:00
|
|
|
{
|
2009-11-09 22:59:49 +00:00
|
|
|
/* Initialize bus handlers */
|
[HAL]: Bus support in the HAL actually creates a further wedge between the different x86 HALs: There are actually two dinstinct implementations. On the ACPI HAL, the system is assumed not to have things like special ISA, MCA, EISA buses, and a PCI driver is used in combination with the ACPI Interface for PCI Bus support. On non-ACPI systems, the legacy "Bus Handler" library is used, and the HAL provides a core set of CMOS, EISA, ISA, MCA and PCI bus handlers, each with their own routines and specific code. Additionally, PCI IRQ Routing and other PCI bus internals are handled directly by the HAL -- on the ACPI HAL, the PCI Bus support is implemented through a "Fake"/static bus handler, just to keep the functions shared. On ReactOS, both the ACPI and non-ACPI HAL were currently using a mix of both HAL bus handling types, mostly implemented the "ACPI way" (with a fake PCI bus handler and such).
As a result, none of the Hal*Bus HALDISPATCH routines were implemented, which bus drivers expect to find when they're not on ACPI systems (ReactOS today). eVb's new PCI driver was crashing, for example.
Furthermore, legacy systems suffer, because the ACPI HAL Bus routines (that we currently have) expect perfect ACPI-style-compliant systems, not the legacy crap from the early 90ies. This works fine in VMs and new hardware, but old hardware is left behind.
This patch basically corrects the first part of the problem, by making the bus handling support separate between ACPI and non-ACPI HALs. For now, the code remains 100% the same in functionality between both.
However, I have started adding the first few elements:
[HAL]: Implement HalRegisterBusHandler HALDISPATCH routine.
[HAL]: On legacy HALs, register the CMOS, ISA, SYSTEM handlers.
[HAL]: Add cmosbus.c. Stub all bus-specific bus handler routines in the xxxbus.c files.
No real functionality change occurs with this patch, yet.
svn path=/trunk/; revision=47649
2010-06-07 01:09:41 +00:00
|
|
|
HalpInitBusHandlers();
|
2006-11-27 19:26:31 +00:00
|
|
|
|
2007-12-13 15:44:17 +00:00
|
|
|
/* Do some HAL-specific initialization */
|
|
|
|
HalpInitPhase1();
|
2018-02-11 18:21:01 +00:00
|
|
|
|
|
|
|
#ifdef _M_AMD64
|
|
|
|
HalInitializeBios(0, LoaderBlock);
|
|
|
|
#endif
|
2006-11-15 00:08:51 +00:00
|
|
|
}
|
2001-08-21 20:18:27 +00:00
|
|
|
|
2006-11-15 00:08:51 +00:00
|
|
|
/* All done, return */
|
|
|
|
return TRUE;
|
2001-08-21 20:18:27 +00:00
|
|
|
}
|