ReactOS  0.4.15-dev-5463-g138eb58
halinit.c File Reference
#include <hal.h>
#include "apicp.h"
#include <smp.h>
#include <debug.h>
Include dependency graph for halinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI ApicInitializeLocalApic (ULONG Cpu)
 
VOID NTAPI HalpInitProcessor (IN ULONG ProcessorNumber, IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID HalpInitPhase0 (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
VOID HalpInitPhase1 (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file halinit.c.

Function Documentation

◆ ApicInitializeLocalApic()

VOID NTAPI ApicInitializeLocalApic ( ULONG  Cpu)

Definition at line 291 of file apic.c.

292 {
293  APIC_BASE_ADRESS_REGISTER BaseRegister;
294  APIC_SPURIOUS_INERRUPT_REGISTER SpIntRegister;
295  LVT_REGISTER LvtEntry;
296 
297  /* Enable the APIC if it wasn't yet */
298  BaseRegister.LongLong = __readmsr(MSR_APIC_BASE);
299  BaseRegister.Enable = 1;
300  BaseRegister.BootStrapCPUCore = (Cpu == 0);
301  __writemsr(MSR_APIC_BASE, BaseRegister.LongLong);
302 
303  /* Set spurious vector and SoftwareEnable to 1 */
304  SpIntRegister.Long = ApicRead(APIC_SIVR);
305  SpIntRegister.Vector = APIC_SPURIOUS_VECTOR;
306  SpIntRegister.SoftwareEnable = 1;
307  SpIntRegister.FocusCPUCoreChecking = 0;
308  ApicWrite(APIC_SIVR, SpIntRegister.Long);
309 
310  /* Read the version and save it globally */
311  if (Cpu == 0) ApicVersion = ApicRead(APIC_VER);
312 
313  /* Set the mode to flat (max 8 CPUs supported!) */
315 
316  /* Set logical apic ID */
317  ApicWrite(APIC_LDR, ApicLogicalId(Cpu) << 24);
318 
319  /* Set the spurious ISR */
321 
322  /* Create a template LVT */
323  LvtEntry.Long = 0;
324  LvtEntry.Vector = APIC_FREE_VECTOR;
325  LvtEntry.MessageType = APIC_MT_Fixed;
326  LvtEntry.DeliveryStatus = 0;
327  LvtEntry.RemoteIRR = 0;
328  LvtEntry.TriggerMode = APIC_TGM_Edge;
329  LvtEntry.Mask = 1;
330  LvtEntry.TimerMode = 0;
331 
332  /* Initialize and mask LVTs */
333  ApicWrite(APIC_TMRLVTR, LvtEntry.Long);
334  ApicWrite(APIC_THRMLVTR, LvtEntry.Long);
335  ApicWrite(APIC_PCLVTR, LvtEntry.Long);
336  ApicWrite(APIC_EXT0LVTR, LvtEntry.Long);
337  ApicWrite(APIC_EXT1LVTR, LvtEntry.Long);
338  ApicWrite(APIC_EXT2LVTR, LvtEntry.Long);
339  ApicWrite(APIC_EXT3LVTR, LvtEntry.Long);
340 
341  /* LINT0 */
342  LvtEntry.Vector = APIC_SPURIOUS_VECTOR;
343  LvtEntry.MessageType = APIC_MT_ExtInt;
344  ApicWrite(APIC_LINT0, LvtEntry.Long);
345 
346  /* Enable LINT1 (NMI) */
347  LvtEntry.Mask = 0;
348  LvtEntry.Vector = APIC_NMI_VECTOR;
349  LvtEntry.MessageType = APIC_MT_NMI;
350  LvtEntry.TriggerMode = APIC_TGM_Level;
351  ApicWrite(APIC_LINT1, LvtEntry.Long);
352 
353  /* Enable error LVTR */
354  LvtEntry.Vector = APIC_ERROR_VECTOR;
355  LvtEntry.MessageType = APIC_MT_Fixed;
356  ApicWrite(APIC_ERRLVTR, LvtEntry.Long);
357 
358  /* Set the IRQL from the PCR */
360 #ifdef APIC_LAZY_IRQL
361  /* Save the new hard IRQL in the IRR field */
362  KeGetPcr()->IRR = KeGetPcr()->Irql;
363 #endif
364 }
Definition: apicp.h:80
Definition: apicp.h:87
FORCEINLINE ULONG ApicRead(APIC_REGISTER Register)
Definition: apicp.h:315
UINT32 Vector
Definition: apicp.h:266
UINT32 DeliveryStatus
Definition: apicp.h:269
#define APIC_NMI_VECTOR
Definition: apicp.h:51
ULONG ApicVersion
Definition: apic.c:27
_Out_ PKIRQL Irql
Definition: csq.h:179
#define APIC_SPURIOUS_VECTOR
Definition: apicp.h:40
#define KeGetPcr()
Definition: ke.h:26
#define ApicLogicalId(Cpu)
Definition: apicp.h:116
UINT32 Long
Definition: apicp.h:263
FORCEINLINE VOID ApicWrite(APIC_REGISTER Register, ULONG Value)
Definition: apicp.h:322
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
UINT32 TimerMode
Definition: apicp.h:274
UINT32 Mask
Definition: apicp.h:273
#define MSR_APIC_BASE
Definition: apicp.h:113
UINT32 RemoteIRR
Definition: apicp.h:271
#define APIC_FREE_VECTOR
Definition: apicp.h:59
UINT32 MessageType
Definition: apicp.h:267
#define APIC_ERROR_VECTOR
Definition: apicp.h:47
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:301
Definition: apicp.h:86
FORCEINLINE VOID ApicSetIrql(KIRQL Irql)
Definition: apic.c:221
VOID __cdecl ApicSpuriousService(VOID)
UINT32 TriggerMode
Definition: apicp.h:272

Referenced by HalpInitProcessor().

◆ HalpInitPhase0()

VOID HalpInitPhase0 ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 50 of file halinit.c.

51 {
52  DPRINT1("Using HAL: APIC %s %s\n",
53  (HalpBuildType & PRCB_BUILD_UNIPROCESSOR) ? "UP" : "SMP",
54  (HalpBuildType & PRCB_BUILD_DEBUG) ? "DBG" : "REL");
55 
57 
58  /* Enable clock interrupt handler */
60  0,
64  Latched);
65 }
const USHORT HalpBuildType
Definition: buildtype.c:14
#define PRCB_BUILD_DEBUG
Definition: ketypes.h:247
#define APIC_CLOCK_VECTOR
Definition: apicp.h:44
VOID NTAPI HalpEnableInterruptHandler(IN UCHAR Flags, IN ULONG BusVector, IN ULONG SystemVector, IN KIRQL Irql, IN PVOID Handler, IN KINTERRUPT_MODE Mode)
Definition: usage.c:49
#define CLOCK2_LEVEL
Definition: env_spec_w32.h:700
VOID HalpPrintApicTables(VOID)
Definition: madt.c:76
#define IDT_INTERNAL
Definition: halp.h:21
VOID HalpClockInterrupt(VOID)
Definition: timer.c:30
#define PRCB_BUILD_UNIPROCESSOR
Definition: ketypes.h:248
#define DPRINT1
Definition: precomp.h:8

Referenced by HalInitSystem().

◆ HalpInitPhase1()

VOID HalpInitPhase1 ( VOID  )

Definition at line 68 of file halinit.c.

69 {
70  /* Initialize DMA. NT does this in Phase 0 */
71  HalpInitDma();
72 }
VOID HalpInitDma(VOID)
Definition: dma.c:185

Referenced by HalInitSystem().

◆ HalpInitProcessor()

VOID NTAPI HalpInitProcessor ( IN ULONG  ProcessorNumber,
IN PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 24 of file halinit.c.

27 {
28 #ifdef CONFIG_SMP
29  if (ProcessorNumber == 0)
30  {
31 #endif
32  HalpParseApicTables(LoaderBlock);
33 #ifdef CONFIG_SMP
34  }
35 
36  HalpSetupProcessorsTable(ProcessorNumber);
37 #endif
38 
39  /* Initialize the local APIC for this cpu */
40  ApicInitializeLocalApic(ProcessorNumber);
41 
42  /* Initialize profiling data (but don't start it) */
44 
45  /* Initialize the timer */
46  //ApicInitializeTimer(ProcessorNumber);
47 }
VOID NTAPI HalInitializeProfiling(VOID)
Definition: apictimer.c:76
VOID HalpSetupProcessorsTable(_In_ UINT32 NTProcessorNumber)
Definition: smp.c:22
VOID HalpParseApicTables(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: madt.c:30
VOID NTAPI ApicInitializeLocalApic(ULONG Cpu)
Definition: apic.c:291

Referenced by HalInitializeProcessor().