From 1820286d8b8dc2c4fd28416dcf75bfd3bffbc0e9 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 7 Sep 2022 10:33:22 +0200 Subject: [PATCH] stuff --- kernel/include/log/Address.h | 10 ++++++++++ kernel/include/memory/KernelMemoryManager.h | 3 +++ kernel/src/acpi/RSDT.cpp | 4 ++++ kernel/src/main.cpp | 16 +++++++++++++--- kernel/src/memory/KernelMemoryManager.cpp | 14 ++++++++++++++ tools/debug.sh | 2 +- tools/rebuild-and-run.sh | 2 +- tools/run.sh | 2 +- 8 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 kernel/include/log/Address.h diff --git a/kernel/include/log/Address.h b/kernel/include/log/Address.h new file mode 100644 index 00000000..429e41f1 --- /dev/null +++ b/kernel/include/log/Address.h @@ -0,0 +1,10 @@ +#pragma once +#include "log/Log.h" +#include "std/stdio.h" +#include + +// clang-format off + +#define kinfoptr(pointer) char result##pointer[40 + sizeof(#pointer)]; snprintf(result##pointer, sizeof result##pointer, "%s points to 0x%zx\n", #pointer, (uint64_t)pointer); kinfo(result##pointer) + +// clang-format on \ No newline at end of file diff --git a/kernel/include/memory/KernelMemoryManager.h b/kernel/include/memory/KernelMemoryManager.h index b9645333..d6ef0450 100644 --- a/kernel/include/memory/KernelMemoryManager.h +++ b/kernel/include/memory/KernelMemoryManager.h @@ -6,6 +6,9 @@ namespace KernelMemoryManager void* get_mapping(void* physicalAddress); void release_mapping(void* mapping); + void* get_unaligned_mapping(void* physicalAddress); + void release_unaligned_mapping(void* mapping); + void* get_page(); void* get_pages(uint64_t count); diff --git a/kernel/src/acpi/RSDT.cpp b/kernel/src/acpi/RSDT.cpp index ebd5fd71..07e25435 100644 --- a/kernel/src/acpi/RSDT.cpp +++ b/kernel/src/acpi/RSDT.cpp @@ -1,5 +1,7 @@ #include "acpi/RSDT.h" #include "bootboot.h" +#include "log/Address.h" +#include "memory/KernelMemoryManager.h" #include "std/stdio.h" #include "std/string.h" @@ -24,7 +26,9 @@ void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature) uint32_t entry = ((RSDT*)rootSDT)->PointerToOtherSDT[i]; h = (SDTHeader*)(uint64_t)entry; } + SDTHeader* realHeader = (SDTHeader*)KernelMemoryManager::get_unaligned_mapping(h); if (strncmp(h->Signature, signature, 4) == 0) return (void*)h; + KernelMemoryManager::release_unaligned_mapping(realHeader); } return NULL; diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 5be2e0a0..2cddb6c3 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -11,6 +11,7 @@ #include "interrupts/Interrupts.h" #include "io/PIC.h" #include "io/Serial.h" +#include "log/Address.h" #include "log/Log.h" #include "memory/KernelHeap.h" #include "memory/KernelMemoryManager.h" @@ -76,7 +77,7 @@ extern "C" void _start() kinfoln("Interrupts enabled"); Debug::DebugStatus::the()->StartBootStage(Color{0x33, 0x33, 0x00, 0xFF}); - ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT(); + ACPI::SDTHeader* rootSDT = (ACPI::SDTHeader*)KernelMemoryManager::get_unaligned_mapping(ACPI::GetRSDTOrXSDT()); bool isXSDT = false; if (strncmp(rootSDT->Signature, "XSDT", 4) != 0) { @@ -130,8 +131,17 @@ extern "C" void _start() } } - sleep(2500); - shutdown(); + ACPI::SDTHeader* madt = (ACPI::SDTHeader*)ACPI::FindTable(rootSDT, "APIC"); + if (!madt) + { + kerrorln("MADT not found"); + while (1) halt(); + } + + KernelMemoryManager::release_unaligned_mapping(rootSDT); + + /*sleep(2500); + shutdown();*/ while (1) halt(); loop: diff --git a/kernel/src/memory/KernelMemoryManager.cpp b/kernel/src/memory/KernelMemoryManager.cpp index 7a72577b..a1cf8ae1 100644 --- a/kernel/src/memory/KernelMemoryManager.cpp +++ b/kernel/src/memory/KernelMemoryManager.cpp @@ -11,6 +11,20 @@ void* KernelMemoryManager::get_mapping(void* physicalAddress) return (void*)virtualAddress; } +void* KernelMemoryManager::get_unaligned_mapping(void* physicalAddress) +{ + uint64_t offset = (uint64_t)physicalAddress % 4096; + uint64_t virtualAddress = KernelHeap::request_virtual_page(); + kernelVMM.map(virtualAddress, (uint64_t)physicalAddress - offset); + return (void*)(virtualAddress + offset); +} + +void KernelMemoryManager::release_unaligned_mapping(void* mapping) +{ + uint64_t offset = (uint64_t)mapping % 4096; + kernelVMM.unmap((uint64_t)mapping - offset); +} + void KernelMemoryManager::release_mapping(void* mapping) { kernelVMM.unmap((uint64_t)mapping); diff --git a/tools/debug.sh b/tools/debug.sh index b4f2c047..81648bd6 100755 --- a/tools/debug.sh +++ b/tools/debug.sh @@ -5,4 +5,4 @@ source $(dirname $0)/env.sh tools/build-iso.sh -qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -d int,cpu_reset -s -no-reboot \ No newline at end of file +qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -d int,cpu_reset -s -no-reboot $@ \ No newline at end of file diff --git a/tools/rebuild-and-run.sh b/tools/rebuild-and-run.sh index fa3cc7df..84c862af 100755 --- a/tools/rebuild-and-run.sh +++ b/tools/rebuild-and-run.sh @@ -5,4 +5,4 @@ source $(dirname $0)/env.sh tools/rebuild-iso.sh -qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm \ No newline at end of file +qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm $@ \ No newline at end of file diff --git a/tools/run.sh b/tools/run.sh index 1c87ea26..2025e470 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -5,4 +5,4 @@ source $(dirname $0)/env.sh tools/build-iso.sh -qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm \ No newline at end of file +qemu-system-x86_64 -cdrom Luna.iso -smp 1 -m 256M -serial stdio -enable-kvm $@ \ No newline at end of file