From 115557a55113fcbebbd00c4c86116d258402da53 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 Mar 2023 00:11:10 +0200 Subject: [PATCH] For Virtual() use KernelPageTable as page table --- Architecture/amd64/MultipleAPICDescriptionTable.cpp | 4 ++-- Architecture/amd64/cpu/SymmetricMultiprocessing.cpp | 8 +++++--- Core/Driver/DriverAPI.cpp | 4 ++-- Core/PeripheralComponentInterconnect.cpp | 9 +++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Architecture/amd64/MultipleAPICDescriptionTable.cpp b/Architecture/amd64/MultipleAPICDescriptionTable.cpp index 51f922f..434c75b 100644 --- a/Architecture/amd64/MultipleAPICDescriptionTable.cpp +++ b/Architecture/amd64/MultipleAPICDescriptionTable.cpp @@ -32,7 +32,7 @@ namespace ACPI { ioapic.push_back((MADTIOApic *)ptr); KPrint("I/O APIC \e8888FF%d\eCCCCCC (Address \e8888FF%#lx\eCCCCCC) found.", ioapic.back()->APICID, ioapic.back()->Address); - Memory::Virtual().Map((void *)(uintptr_t)ioapic.back()->Address, (void *)(uintptr_t)ioapic.back()->Address, Memory::PTFlag::RW | Memory::PTFlag::PCD); // Make sure that the address is mapped. + Memory::Virtual(KernelPageTable).Map((void *)(uintptr_t)ioapic.back()->Address, (void *)(uintptr_t)ioapic.back()->Address, Memory::PTFlag::RW | Memory::PTFlag::PCD); // Make sure that the address is mapped. break; } case 2: @@ -57,7 +57,7 @@ namespace ACPI break; } } - Memory::Virtual().Map((void *)LAPICAddress, (void *)LAPICAddress, Memory::PTFlag::RW | Memory::PTFlag::PCD); // I should map more than one page? + Memory::Virtual(KernelPageTable).Map((void *)LAPICAddress, (void *)LAPICAddress, Memory::PTFlag::RW | Memory::PTFlag::PCD); // I should map more than one page? } CPUCores--; // We start at 0 (BSP) and end at 11 (APs), so we have 12 cores. KPrint("Total CPU cores: %d", CPUCores + 1); diff --git a/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp b/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp index fe2bc66..0bcbdc0 100644 --- a/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp +++ b/Architecture/amd64/cpu/SymmetricMultiprocessing.cpp @@ -85,15 +85,17 @@ namespace SMP ((APIC::APIC *)Interrupts::apic[0])->Write(APIC::APIC_ICRHI, (((ACPI::MADT *)madt)->lapic[i]->APICId << 24)); ((APIC::APIC *)Interrupts::apic[0])->Write(APIC::APIC_ICRLO, 0x500); - Memory::Virtual().Map(0x0, 0x0, Memory::PTFlag::RW | Memory::PTFlag::US); + Memory::Virtual vma = Memory::Virtual(KernelPageTable); + + vma.Map(0x0, 0x0, Memory::PTFlag::RW | Memory::PTFlag::US); uint64_t TrampolineLength = (uintptr_t)&_trampoline_end - (uintptr_t)&_trampoline_start; for (uint64_t i = 0; i < (TrampolineLength / PAGE_SIZE) + 2; i++) - Memory::Virtual().Map((void *)(TRAMPOLINE_START + (i * PAGE_SIZE)), (void *)(TRAMPOLINE_START + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); + vma.Map((void *)(TRAMPOLINE_START + (i * PAGE_SIZE)), (void *)(TRAMPOLINE_START + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US); memcpy((void *)TRAMPOLINE_START, &_trampoline_start, TrampolineLength); - POKE(volatile uint64_t, PAGE_TABLE) = CPU::x64::readcr3().raw; + POKE(volatile uint64_t, PAGE_TABLE) = (uint64_t)KernelPageTable; POKE(volatile uint64_t, STACK) = (uint64_t)KernelAllocator.RequestPages(TO_PAGES(STACK_SIZE)) + STACK_SIZE; POKE(volatile uint64_t, CORE) = i; diff --git a/Core/Driver/DriverAPI.cpp b/Core/Driver/DriverAPI.cpp index 5aa0f64..0ecefff 100644 --- a/Core/Driver/DriverAPI.cpp +++ b/Core/Driver/DriverAPI.cpp @@ -44,14 +44,14 @@ void MapMemory(void *VirtualAddress, void *PhysicalAddress, unsigned long Flags) { SmartLock(DriverDisplayPrintLock); drvdbg("Mapping %#lx to %#lx with flags %#lx...", (unsigned long)VirtualAddress, (unsigned long)PhysicalAddress, Flags); - Memory::Virtual().Map(VirtualAddress, PhysicalAddress, Flags); + Memory::Virtual(KernelPageTable).Map(VirtualAddress, PhysicalAddress, Flags); } void UnmapMemory(void *VirtualAddress) { SmartLock(DriverDisplayPrintLock); drvdbg("Unmapping %#lx...", (unsigned long)VirtualAddress); - Memory::Virtual().Unmap(VirtualAddress); + Memory::Virtual(KernelPageTable).Unmap(VirtualAddress); } void *Drivermemcpy(void *Destination, void *Source, unsigned long Size) diff --git a/Core/PeripheralComponentInterconnect.cpp b/Core/PeripheralComponentInterconnect.cpp index 0b06ff1..33f3289 100644 --- a/Core/PeripheralComponentInterconnect.cpp +++ b/Core/PeripheralComponentInterconnect.cpp @@ -769,7 +769,7 @@ namespace PCI { uintptr_t Offset = Function << 12; uintptr_t FunctionAddress = DeviceAddress + Offset; - Memory::Virtual().Map((void *)FunctionAddress, (void *)FunctionAddress, Memory::PTFlag::RW); + Memory::Virtual(KernelPageTable).Map((void *)FunctionAddress, (void *)FunctionAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)FunctionAddress; if (PCIDeviceHdr->DeviceID == 0) return; @@ -785,7 +785,7 @@ namespace PCI { uintptr_t Offset = Device << 15; uintptr_t DeviceAddress = BusAddress + Offset; - Memory::Virtual().Map((void *)DeviceAddress, (void *)DeviceAddress, Memory::PTFlag::RW); + Memory::Virtual(KernelPageTable).Map((void *)DeviceAddress, (void *)DeviceAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)DeviceAddress; if (PCIDeviceHdr->DeviceID == 0) return; @@ -799,7 +799,7 @@ namespace PCI { uintptr_t Offset = Bus << 20; uintptr_t BusAddress = BaseAddress + Offset; - Memory::Virtual().Map((void *)BusAddress, (void *)BusAddress, Memory::PTFlag::RW); + Memory::Virtual(KernelPageTable).Map((void *)BusAddress, (void *)BusAddress, Memory::PTFlag::RW); PCIDeviceHeader *PCIDeviceHdr = (PCIDeviceHeader *)BusAddress; if (Bus != 0) // TODO: VirtualBox workaround (UNTESTED ON REAL HARDWARE!) { @@ -839,10 +839,11 @@ namespace PCI { #if defined(a64) int Entries = ((((ACPI::ACPI *)PowerManager->GetACPI())->MCFG->Header.Length) - sizeof(ACPI::ACPI::MCFGHeader)) / sizeof(DeviceConfig); + Memory::Virtual vma = Memory::Virtual(KernelPageTable); for (int t = 0; t < Entries; t++) { DeviceConfig *NewDeviceConfig = (DeviceConfig *)((uintptr_t)((ACPI::ACPI *)PowerManager->GetACPI())->MCFG + sizeof(ACPI::ACPI::MCFGHeader) + (sizeof(DeviceConfig) * t)); - Memory::Virtual().Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW); + vma.Map((void *)NewDeviceConfig->BaseAddress, (void *)NewDeviceConfig->BaseAddress, Memory::PTFlag::RW); debug("PCI Entry %d Address:%#llx BUS:%#llx-%#llx", t, NewDeviceConfig->BaseAddress, NewDeviceConfig->StartBus, NewDeviceConfig->EndBus); for (uintptr_t Bus = NewDeviceConfig->StartBus; Bus < NewDeviceConfig->EndBus; Bus++)