From ded76cd0afc3663583596fe80a1e05da839c815b Mon Sep 17 00:00:00 2001 From: Curle Date: Sat, 9 Jul 2022 00:20:00 +0100 Subject: [PATCH] Closer to all-cores bootstrap --- inc/kernel/system/core.hpp | 2 +- inc/kernel/system/memory.h | 2 ++ src/drivers/devices/io/apic.cpp | 1 + src/kernel.cpp | 4 ++++ src/system/core.cpp | 7 ++----- src/system/memory/paging.cpp | 13 ++++++++++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/inc/kernel/system/core.hpp b/inc/kernel/system/core.hpp index b079fc7..e990202 100644 --- a/inc/kernel/system/core.hpp +++ b/inc/kernel/system/core.hpp @@ -77,4 +77,4 @@ class Core { void Bootstrap(); void SetupData(size_t ID); -} __attribute__((packed)); +}; diff --git a/inc/kernel/system/memory.h b/inc/kernel/system/memory.h index fb6eba7..d273b29 100644 --- a/inc/kernel/system/memory.h +++ b/inc/kernel/system/memory.h @@ -142,6 +142,8 @@ extern "C" { #define KERNEL_HEAP_REGION 0xFFFFE00080000000ull // Kernel Object Space (kmalloc will allocate into this region) #define KERNEL_HEAP_END 0xFFFFE000C0000000ull // End of Kernel Object Space +#define APIC_REGION 0x00000000FEE00000ull // Physical location of the APIC MMIO region. + #define DIRECT_REGION 0xFFFF800000000000ull #define LOWER_REGION 0x0000000100000000ull // Lower Memory cutoff - 4GB diff --git a/src/drivers/devices/io/apic.cpp b/src/drivers/devices/io/apic.cpp index 7882615..4b66963 100644 --- a/src/drivers/devices/io/apic.cpp +++ b/src/drivers/devices/io/apic.cpp @@ -62,6 +62,7 @@ void APIC::Init() { SerialPrintf("[ ACPI] Enabling APICs...\r\n"); Address = (void*) ACPI::MADT::instance->LocalAPICBase; + SerialPrintf("[ MADT] The APIC of this core is at 0x%p\r\n", (size_t) Address); // TODO: Check whether the identity mapping covers this address diff --git a/src/kernel.cpp b/src/kernel.cpp index f78a90f..9a46742 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -88,10 +88,14 @@ extern "C" [[noreturn]] int Main(void) { SetForegroundColor(0x00FFFFFF); + Device::APIC::driver = new Device::APIC(); + ACPI::RSDP::instance->Init(0); ACPI::MADT::instance->Init(); Device::APIC::driver->Init(); + Core::Init(); + CharPrinterCallbackID = SetupKBCallback(&PrintPressedChar); InternalBufferID = SetupKBCallback(&TrackInternalBuffer); diff --git a/src/system/core.cpp b/src/system/core.cpp index 5b69b63..75e7b26 100644 --- a/src/system/core.cpp +++ b/src/system/core.cpp @@ -7,9 +7,6 @@ *** Chroma *** ***********************/ -extern size_t startCore; -extern size_t endCore; - int Cores = 0; volatile bool Ready = false; @@ -37,7 +34,7 @@ Core::Core(size_t APIC, size_t ID) { GetCore(ID)->LocalAPIC = APIC; Bootstrap(); - SetupData(ID); + //SetupData(ID); Device::APIC::driver->InitializeCore(APIC, reinterpret_cast(initcpu)); @@ -52,7 +49,7 @@ void Core::Init() { using namespace ACPI; Ready = false; - SerialPrintf("[CORE] Enabling Multiprocessing\n"); + SerialPrintf("[ CORE] Enabling Multiprocessing\r\n"); memset(Tasks, 0, Constants::Core::MAX_CORES * sizeof(TSS64)); for (size_t i = 0; i < Constants::Core::MAX_CORES; i++) diff --git a/src/system/memory/paging.cpp b/src/system/memory/paging.cpp index fb87290..54bf2a4 100644 --- a/src/system/memory/paging.cpp +++ b/src/system/memory/paging.cpp @@ -68,6 +68,9 @@ void InitPaging() { } } + SerialPrintf("[ Mem] Identity mapping core system hardware.\r\n"); + MapVirtualPageNoDirect(&KernelAddressSpace, APIC_REGION, APIC_REGION, DEFAULT_PAGE_FLAGS); + SerialPrintf("[ Mem] Mapping 0x%x bytes of bootloader structure, starting at 0x%p\r\n", bootldr.size, BootldrAddress); for (size_t i = BootldrAddress; i < (BootldrAddress + bootldr.size); i += PAGE_SIZE) @@ -352,4 +355,12 @@ size_t* CreateNewPageTable(address_space_t* AddressSpace) { #ifdef __cplusplus } -#endif \ No newline at end of file +#endif + +void *operator new(size_t size) { + return kmalloc(size); +} + +void *operator new[](size_t size) { + return kmalloc(size); +} \ No newline at end of file