ReactOS  0.4.15-dev-2972-gda2a567
halinit.c
Go to the documentation of this file.
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 
18 
19 /* PRIVATE FUNCTIONS *********************************************************/
20 
21 CODE_SEG("INIT")
22 VOID
23 NTAPI
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
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 */
59  ProcessorNumber);
60 
61  /* Register routines for KDCOM */
63 }
64 
65 /*
66  * @implemented
67  */
68 CODE_SEG("INIT")
69 BOOLEAN
70 NTAPI
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 */
104 
105  /* Initialize CMOS lock */
107 
108  /* Initialize CMOS */
110 
111  /* Fill out the dispatch tables */
116 
117  HalGetInterruptTranslator = NULL; // FIXME: TODO
120 
121  /* Setup I/O space */
124 
125  /* Setup busy waiting */
127 
128  /* Initialize the clock */
130 
131  /*
132  * We could be rebooting with a pending profile interrupt,
133  * so clear it here before interrupts are enabled
134  */
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 */
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 }
signed char * PCHAR
Definition: retypes.h:7
#define INITIAL_STALL_COUNT
Definition: processor.c:22
#define HalResetDisplay
Definition: halfuncs.h:45
LONG HalpActiveProcessors
Definition: processor.c:17
#define HalGetDmaAdapter
Definition: haltypes.h:291
#define IN
Definition: typedefs.h:39
VOID NTAPI HalInitializeBios(_In_ ULONG Phase, _In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: x86bios.c:48
KAFFINITY HalpDefaultInterruptAffinity
Definition: processor.c:18
PADDRESS_USAGE HalpAddressUsageList
Definition: usage.c:20
#define TRUE
Definition: types.h:120
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
#define HalGetInterruptTranslator
Definition: haltypes.h:292
NTSTATUS NTAPI HaliQuerySystemInformation(IN HAL_QUERY_INFORMATION_CLASS InformationClass, IN ULONG BufferSize, IN OUT PVOID Buffer, OUT PULONG ReturnedLength)
Definition: sysinfo.c:19
BOOLEAN NTAPI HalpBiosDisplayReset(VOID)
Definition: halinit.c:60
VOID NTAPI HalpInitializePICs(IN BOOLEAN EnableInterrupts)
Definition: halinit.c:44
#define HalQuerySystemInformation
Definition: haltypes.h:283
const USHORT HalpBuildType
Definition: buildtype.c:14
VOID NTAPI HalpInitBusHandlers(VOID)
Definition: halacpi.c:935
BOOLEAN HalpPciLockSettings
Definition: halinit.c:18
void DbgBreakPoint()
Definition: mach.c:553
#define HalSetSystemInformation
Definition: haltypes.h:284
#define KeGetPcr()
Definition: ke.h:26
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID NTAPI HalpGetParameters(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:21
NTSTATUS NTAPI HaliSetSystemInformation(IN HAL_SET_INFORMATION_CLASS InformationClass, IN ULONG BufferSize, IN OUT PVOID Buffer)
Definition: sysinfo.c:31
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
unsigned char BOOLEAN
VOID NTAPI HaliHaltSystem(VOID)
Definition: processor.c:21
PDMA_ADAPTER NTAPI HalpGetDmaAdapter(IN PVOID Context, IN PDEVICE_DESCRIPTION DeviceDescription, OUT PULONG NumberOfMapRegisters)
Definition: halinit.c:50
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
ULONG HalpBusType
Definition: bus.c:17
VOID HalpInitPhase1(VOID)
Definition: halinit.c:54
VOID HalpInitPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:38
#define HalHaltSystem
Definition: halfuncs.h:43
VOID HalpInitializeClock(VOID)
Definition: timer.c:54
NTSTATUS NTAPI HalpSetupAcpiPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:37
UCHAR BuildType
Definition: ketypes.h:603
VOID NTAPI HalpRegisterKdSupportFunctions(VOID)
Definition: bus.c:23
ADDRESS_USAGE HalpDefaultIoSpace
Definition: usage.c:42
VOID HalpCalibrateStallExecution(VOID)
Definition: pchw.c:105
USHORT MajorVersion
Definition: ketypes.h:602
#define NULL
Definition: types.h:112
NTSTATUS NTAPI HaliInitPnpDriver(VOID)
Definition: halpnpdd.c:886
KSPIN_LOCK HalpSystemHardwareLock
Definition: cmos.c:18
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
Definition: profil.c:22
struct _HalAddressUsage * Next
Definition: halp.h:178
VOID NTAPI HalpInitializeCmos(VOID)
Definition: cmos.c:159
BOOLEAN NTAPI HalInitSystem(IN ULONG BootPhase, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:43
signed int * PLONG
Definition: retypes.h:5
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define HalInitPnpDriver
Definition: haltypes.h:289
#define PRCB_MAJOR_VERSION
Definition: ketypes.h:245
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
VOID NTAPI HalInitializeProcessor(IN ULONG ProcessorNumber, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:46
VOID NTAPI HalpInitProcessor(IN ULONG ProcessorNumber, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: halinit.c:23