BOOLEAN NTAPI HalBeginSystemInterrupt (KIRQL Irql, ULONG Vector, PKIRQL OldIrql) { ULONG Flags; DPRINT("Vector (0x%X) Irql (0x%X)\n", Vector, Irql); if (KeGetCurrentIrql () >= Irql) { DPRINT1("current irql %d, new irql %d\n", KeGetCurrentIrql(), Irql); ASSERT(FALSE); } Flags = __readeflags(); if (Flags & EFLAGS_INTERRUPT_MASK) { DPRINT1("HalBeginSystemInterrupt was called with interrupt's enabled\n"); ASSERT(FALSE); } APICWrite (APIC_TPR, IRQL2TPR (Irql) & APIC_TPR_PRI); *OldIrql = KeGetCurrentIrql (); KeSetCurrentIrql (Irql); return(TRUE); }
KIRQL FASTCALL KfRaiseIrql (KIRQL NewIrql) { KIRQL OldIrql; ULONG Flags; Flags = __readeflags(); _disable(); OldIrql = KeGetCurrentIrql (); if (NewIrql < OldIrql) { DPRINT1 ("CurrentIrql %x NewIrql %x\n", KeGetCurrentIrql (), NewIrql); ASSERT(FALSE); } if (NewIrql > DISPATCH_LEVEL) { APICWrite (APIC_TPR, IRQL2TPR(NewIrql) & APIC_TPR_PRI); } KeSetCurrentIrql (NewIrql); if (Flags & EFLAGS_INTERRUPT_MASK) { _enable(); } return OldIrql; }
VOID HalpLowerIrql(KIRQL NewIrql, BOOLEAN FromHalEndSystemInterrupt) { ULONG Flags; UCHAR DpcRequested; if (NewIrql >= DISPATCH_LEVEL) { KeSetCurrentIrql (NewIrql); APICWrite(APIC_TPR, IRQL2TPR (NewIrql) & APIC_TPR_PRI); return; } Flags = __readeflags(); if (KeGetCurrentIrql() > APC_LEVEL) { KeSetCurrentIrql (DISPATCH_LEVEL); APICWrite(APIC_TPR, IRQL2TPR (DISPATCH_LEVEL) & APIC_TPR_PRI); DpcRequested = __readfsbyte(FIELD_OFFSET(KIPCR, HalReserved[HAL_DPC_REQUEST])); if (FromHalEndSystemInterrupt || DpcRequested) { __writefsbyte(FIELD_OFFSET(KIPCR, HalReserved[HAL_DPC_REQUEST]), 0); _enable(); KiDispatchInterrupt(); if (!(Flags & EFLAGS_INTERRUPT_MASK)) { _disable(); } } KeSetCurrentIrql (APC_LEVEL); } if (NewIrql == APC_LEVEL) { return; } if (KeGetCurrentThread () != NULL && KeGetCurrentThread ()->ApcState.KernelApcPending) { _enable(); KiDeliverApc(KernelMode, NULL, NULL); if (!(Flags & EFLAGS_INTERRUPT_MASK)) { _disable(); } } KeSetCurrentIrql (PASSIVE_LEVEL); }
VOID NTAPI KiInitializePcr(IN PKIPCR Pcr, IN ULONG ProcessorNumber, IN PKTHREAD IdleThread, IN PVOID DpcStack) { KDESCRIPTOR GdtDescriptor = {{0},0,0}, IdtDescriptor = {{0},0,0}; PKGDTENTRY64 TssEntry; USHORT Tr = 0; /* Zero out the PCR */ RtlZeroMemory(Pcr, sizeof(KIPCR)); /* Set pointers to ourselves */ Pcr->Self = (PKPCR)Pcr; Pcr->CurrentPrcb = &Pcr->Prcb; /* Set the PCR Version */ Pcr->MajorVersion = PCR_MAJOR_VERSION; Pcr->MinorVersion = PCR_MINOR_VERSION; /* Set the PRCB Version */ Pcr->Prcb.MajorVersion = 1; Pcr->Prcb.MinorVersion = 1; /* Set the Build Type */ Pcr->Prcb.BuildType = 0; #ifndef CONFIG_SMP Pcr->Prcb.BuildType |= PRCB_BUILD_UNIPROCESSOR; #endif #if DBG Pcr->Prcb.BuildType |= PRCB_BUILD_DEBUG; #endif /* Set the Processor Number and current Processor Mask */ Pcr->Prcb.Number = (UCHAR)ProcessorNumber; Pcr->Prcb.SetMember = 1ULL << ProcessorNumber; /* Get GDT and IDT descriptors */ __sgdt(&GdtDescriptor.Limit); __sidt(&IdtDescriptor.Limit); Pcr->GdtBase = (PVOID)GdtDescriptor.Base; Pcr->IdtBase = (PKIDTENTRY)IdtDescriptor.Base; /* Get TSS Selector */ __str(&Tr); ASSERT(Tr == KGDT64_SYS_TSS); /* Get TSS Entry */ TssEntry = KiGetGdtEntry(Pcr->GdtBase, Tr); /* Get the KTSS itself */ Pcr->TssBase = KiGetGdtDescriptorBase(TssEntry); Pcr->Prcb.RspBase = Pcr->TssBase->Rsp0; // FIXME /* Set DPC Stack */ Pcr->Prcb.DpcStack = DpcStack; /* Setup the processor set */ Pcr->Prcb.MultiThreadProcessorSet = Pcr->Prcb.SetMember; /* Clear DR6/7 to cleanup bootloader debugging */ Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0; Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0; /* Set the Current Thread */ Pcr->Prcb.CurrentThread = IdleThread; /* Start us out at PASSIVE_LEVEL */ Pcr->Irql = PASSIVE_LEVEL; KeSetCurrentIrql(PASSIVE_LEVEL); }