diff --git a/xtoskrnl/includes/ke/proc.hh b/xtoskrnl/includes/ke/proc.hh index e9b63c9..082c3d0 100644 --- a/xtoskrnl/includes/ke/proc.hh +++ b/xtoskrnl/includes/ke/proc.hh @@ -27,8 +27,10 @@ namespace KE STATIC XTAPI ULONG GetCurrentProcessorNumber(VOID); STATIC XTAPI PKTHREAD GetCurrentThread(VOID); STATIC XTAPI PKPROCESSOR_BLOCK GetProcessorBlock(IN ULONG CpuNumber); - STATIC XTAPI XTSTATUS InitializeProcessorStructures(IN ULONG CpuCount); + STATIC XTAPI XTSTATUS InitializeProcessorBlocks(); STATIC XTAPI VOID RegisterHardwareId(IN ULONG HardwareId); + STATIC XTAPI VOID RegisterProcessorBlock(ULONG CpuNumber, + PKPROCESSOR_BLOCK ProcessorBlock); STATIC XTAPI VOID SaveProcessorState(OUT PKPROCESSOR_STATE CpuState); }; } diff --git a/xtoskrnl/ke/amd64/proc.cc b/xtoskrnl/ke/amd64/proc.cc index 7622b80..0449133 100644 --- a/xtoskrnl/ke/amd64/proc.cc +++ b/xtoskrnl/ke/amd64/proc.cc @@ -81,7 +81,7 @@ PKPROCESSOR_BLOCK KE::Processor::GetProcessorBlock(IN ULONG CpuNumber) { /* Check if the requested CPU number is within dynamic bounds */ - if(ProcessorBlocks == NULLPTR || CpuNumber >= InstalledCpus) + if(CpuNumber >= InstalledCpus || ProcessorBlocks == NULLPTR || ProcessorBlocks[CpuNumber] == NULLPTR) { /* Invalid CPU number, return NULLPTR */ return NULLPTR; @@ -94,25 +94,24 @@ KE::Processor::GetProcessorBlock(IN ULONG CpuNumber) /** * Initializes the global processor structures by allocating an array of processor block pointers. * - * @param CpuCount - * Supplies the total number of processors present in the system. - * * @return This routine returns a status code indicating the success or failure of the allocation. * * @since XT 1.0 */ XTAPI XTSTATUS -KE::Processor::InitializeProcessorStructures(IN ULONG CpuCount) +KE::Processor::InitializeProcessorBlocks() { + PACPI_SYSTEM_INFO SystemInfo; XTSTATUS Status; /* Save number of CPUs installed */ - InstalledCpus = CpuCount; + HL::Acpi::GetSystemInformation(&SystemInfo); + InstalledCpus = SystemInfo->CpuCount; /* Allocate an array of pointers */ Status = MM::Allocator::AllocatePool(NonPagedPool, - CpuCount * sizeof(PKPROCESSOR_BLOCK), + InstalledCpus * sizeof(PKPROCESSOR_BLOCK), (PVOID*)&ProcessorBlocks); if(Status != STATUS_SUCCESS) { @@ -121,7 +120,7 @@ KE::Processor::InitializeProcessorStructures(IN ULONG CpuCount) } /* Zero the array initially */ - RTL::Memory::ZeroMemory(ProcessorBlocks, CpuCount * sizeof(PKPROCESSOR_BLOCK)); + RTL::Memory::ZeroMemory(ProcessorBlocks, InstalledCpus * sizeof(PKPROCESSOR_BLOCK)); /* Return success */ return STATUS_SUCCESS; @@ -152,6 +151,32 @@ KE::Processor::RegisterHardwareId(IN ULONG HardwareId) } } +/** + * Registers or deregisters a processor block in the global CPU table. + * + * @param CpuNumber + * Specifies the logical processor number. + * + * @param ProcessorBlock + * Supplies a pointer to the processor block. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::Processor::RegisterProcessorBlock(ULONG CpuNumber, + PKPROCESSOR_BLOCK ProcessorBlock) +{ + /* Check if the requested CPU number is within dynamic bounds */ + if(ProcessorBlocks != NULLPTR && CpuNumber < InstalledCpus) + { + /* Register processor block */ + ProcessorBlocks[CpuNumber] = ProcessorBlock; + } +} + /** * Saves the current processor state. * diff --git a/xtoskrnl/ke/i686/proc.cc b/xtoskrnl/ke/i686/proc.cc index 84f8f89..ced7deb 100644 --- a/xtoskrnl/ke/i686/proc.cc +++ b/xtoskrnl/ke/i686/proc.cc @@ -81,7 +81,7 @@ PKPROCESSOR_BLOCK KE::Processor::GetProcessorBlock(IN ULONG CpuNumber) { /* Check if the requested CPU number is within dynamic bounds */ - if(ProcessorBlocks == NULLPTR || CpuNumber >= InstalledCpus) + if(CpuNumber >= InstalledCpus || ProcessorBlocks == NULLPTR || ProcessorBlocks[CpuNumber] == NULLPTR) { /* Invalid CPU number, return NULLPTR */ return NULLPTR; @@ -94,25 +94,24 @@ KE::Processor::GetProcessorBlock(IN ULONG CpuNumber) /** * Initializes the global processor structures by allocating an array of processor block pointers. * - * @param CpuCount - * Supplies the total number of processors present in the system. - * * @return This routine returns a status code indicating the success or failure of the allocation. * * @since XT 1.0 */ XTAPI XTSTATUS -KE::Processor::InitializeProcessorStructures(IN ULONG CpuCount) +KE::Processor::InitializeProcessorBlocks() { + PACPI_SYSTEM_INFO SystemInfo; XTSTATUS Status; /* Save number of CPUs installed */ - InstalledCpus = CpuCount; + HL::Acpi::GetSystemInformation(&SystemInfo); + InstalledCpus = SystemInfo->CpuCount; /* Allocate an array of pointers */ Status = MM::Allocator::AllocatePool(NonPagedPool, - CpuCount * sizeof(PKPROCESSOR_BLOCK), + InstalledCpus * sizeof(PKPROCESSOR_BLOCK), (PVOID*)&ProcessorBlocks); if(Status != STATUS_SUCCESS) { @@ -121,7 +120,7 @@ KE::Processor::InitializeProcessorStructures(IN ULONG CpuCount) } /* Zero the array initially */ - RTL::Memory::ZeroMemory(ProcessorBlocks, CpuCount * sizeof(PKPROCESSOR_BLOCK)); + RTL::Memory::ZeroMemory(ProcessorBlocks, InstalledCpus * sizeof(PKPROCESSOR_BLOCK)); /* Return success */ return STATUS_SUCCESS; @@ -152,6 +151,32 @@ KE::Processor::RegisterHardwareId(IN ULONG HardwareId) } } +/** + * Registers or deregisters a processor block in the global CPU table. + * + * @param CpuNumber + * Specifies the logical processor number. + * + * @param ProcessorBlock + * Supplies a pointer to the processor block. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::Processor::RegisterProcessorBlock(ULONG CpuNumber, + PKPROCESSOR_BLOCK ProcessorBlock) +{ + /* Check if the requested CPU number is within dynamic bounds */ + if(ProcessorBlocks != NULLPTR && CpuNumber < InstalledCpus) + { + /* Register processor block */ + ProcessorBlocks[CpuNumber] = ProcessorBlock; + } +} + /** * Saves the current processor state. *