cleanup: move some logic out of kernel Main.cpp into separate files/functions
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Init.cpp
|
||||
* Driver initialization orchestration
|
||||
* Copyright (c) 2025 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include "Init.hpp"
|
||||
#include <Drivers/Graphics/IntelGPU.hpp>
|
||||
#include <Drivers/Net/E1000.hpp>
|
||||
#include <Drivers/Net/E1000E.hpp>
|
||||
#include <Graphics/Cursor.hpp>
|
||||
#include <Net/Net.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
|
||||
namespace Drivers {
|
||||
|
||||
void InitializeGraphics() {
|
||||
Graphics::IntelGPU::Initialize();
|
||||
if (Graphics::IntelGPU::IsInitialized()) {
|
||||
::Graphics::Cursor::SetFramebuffer(
|
||||
Graphics::IntelGPU::GetFramebufferBase(),
|
||||
Graphics::IntelGPU::GetWidth(),
|
||||
Graphics::IntelGPU::GetHeight(),
|
||||
Graphics::IntelGPU::GetPitch()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeNetwork() {
|
||||
Net::E1000::Initialize();
|
||||
if (!Net::E1000::IsInitialized()) {
|
||||
Kt::KernelLogStream(Kt::INFO, "Init") << "E1000 not found, trying E1000E...";
|
||||
Net::E1000E::Initialize();
|
||||
}
|
||||
::Net::Initialize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Init.hpp
|
||||
* Driver initialization orchestration
|
||||
* Copyright (c) 2025 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Drivers {
|
||||
|
||||
// Initialize Intel GPU driver and update the cursor framebuffer if found.
|
||||
void InitializeGraphics();
|
||||
|
||||
// Initialize network driver (E1000, falling back to E1000E) and the net stack.
|
||||
void InitializeNetwork();
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "Cursor.hpp"
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Memory/HHDM.hpp>
|
||||
#include <Memory/Paging.hpp>
|
||||
#include <CppLib/Stream.hpp>
|
||||
|
||||
namespace Graphics::Cursor {
|
||||
|
||||
@@ -44,4 +46,20 @@ namespace Graphics::Cursor {
|
||||
return Memory::SubHHDM((uint64_t)g_FbBase);
|
||||
}
|
||||
|
||||
void MapWriteCombining() {
|
||||
uint64_t fbPhys = GetFramebufferPhysBase();
|
||||
uint64_t fbSize = g_FbHeight * g_FbPitch;
|
||||
uint64_t numPages = (fbSize + 0xFFF) / 0x1000;
|
||||
|
||||
for (uint64_t i = 0; i < numPages; i++) {
|
||||
uint64_t phys = fbPhys + i * 0x1000;
|
||||
Memory::VMM::g_paging->MapWC(phys, Memory::HHDM(phys));
|
||||
}
|
||||
|
||||
Memory::VMM::FlushTLB();
|
||||
|
||||
Kt::KernelLogStream(Kt::OK, "Graphics") << "Framebuffer mapped as Write-Combining ("
|
||||
<< kcp::dec << numPages << " pages)";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -20,4 +20,6 @@ namespace Graphics::Cursor {
|
||||
void SetFramebuffer(uint32_t* base, uint64_t width, uint64_t height, uint64_t pitch);
|
||||
uint64_t GetFramebufferPhysBase();
|
||||
|
||||
void MapWriteCombining();
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Cpu.hpp
|
||||
* CPU feature enablement helpers
|
||||
* Copyright (c) 2025 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace Hal {
|
||||
|
||||
// Enable SSE/SSE2 — required for userspace programs compiled with SSE.
|
||||
// CR0: clear EM (bit 2), set MP (bit 1)
|
||||
// CR4: set OSFXSR (bit 9) and OSXMMEXCPT (bit 10)
|
||||
inline void EnableSSE() {
|
||||
uint64_t cr0;
|
||||
asm volatile("mov %%cr0, %0" : "=r"(cr0));
|
||||
cr0 &= ~(1ULL << 2); // Clear EM
|
||||
cr0 |= (1ULL << 1); // Set MP
|
||||
asm volatile("mov %0, %%cr0" :: "r"(cr0));
|
||||
|
||||
uint64_t cr4;
|
||||
asm volatile("mov %%cr4, %0" : "=r"(cr4));
|
||||
cr4 |= (1ULL << 9); // OSFXSR
|
||||
cr4 |= (1ULL << 10); // OSXMMEXCPT
|
||||
asm volatile("mov %0, %%cr4" :: "r"(cr4));
|
||||
}
|
||||
|
||||
}
|
||||
+6
-53
@@ -34,13 +34,11 @@
|
||||
#include <Drivers/PS2/Keyboard.hpp>
|
||||
#include <Drivers/PS2/Mouse.hpp>
|
||||
#include <Drivers/USB/Xhci.hpp>
|
||||
#include <Drivers/Net/E1000.hpp>
|
||||
#include <Drivers/Net/E1000E.hpp>
|
||||
#include <Drivers/Graphics/IntelGPU.hpp>
|
||||
#include <Net/Net.hpp>
|
||||
#include <Drivers/Init.hpp>
|
||||
#include <CppLib/BoxUI.hpp>
|
||||
#include <Graphics/Cursor.hpp>
|
||||
#include <Hal/MSR.hpp>
|
||||
#include <Hal/Cpu.hpp>
|
||||
#include <Fs/Ramdisk.hpp>
|
||||
#include <Fs/Vfs.hpp>
|
||||
#include <Sched/Scheduler.hpp>
|
||||
@@ -98,22 +96,7 @@ extern "C" void kmain() {
|
||||
Hal::PrepareGDT();
|
||||
Hal::BridgeLoadGDT();
|
||||
|
||||
// Enable SSE/SSE2 — required for userspace programs compiled with SSE
|
||||
// CR0: clear EM (bit 2), set MP (bit 1)
|
||||
{
|
||||
uint64_t cr0;
|
||||
asm volatile("mov %%cr0, %0" : "=r"(cr0));
|
||||
cr0 &= ~(1ULL << 2); // Clear EM
|
||||
cr0 |= (1ULL << 1); // Set MP
|
||||
asm volatile("mov %0, %%cr0" :: "r"(cr0));
|
||||
|
||||
// CR4: set OSFXSR (bit 9) and OSXMMEXCPT (bit 10)
|
||||
uint64_t cr4;
|
||||
asm volatile("mov %%cr4, %0" : "=r"(cr4));
|
||||
cr4 |= (1ULL << 9); // OSFXSR
|
||||
cr4 |= (1ULL << 10); // OSXMMEXCPT
|
||||
asm volatile("mov %0, %%cr4" :: "r"(cr4));
|
||||
}
|
||||
Hal::EnableSSE();
|
||||
#endif
|
||||
|
||||
uint64_t hhdm_offset = hhdm_request.response->offset;
|
||||
@@ -155,22 +138,7 @@ extern "C" void kmain() {
|
||||
#if defined (__x86_64__)
|
||||
// Map framebuffer as Write-Combining immediately for faster screen writes.
|
||||
// All subsequent log output benefits from WC burst transfers.
|
||||
{
|
||||
uint64_t fbPhys = Graphics::Cursor::GetFramebufferPhysBase();
|
||||
uint64_t fbSize = Graphics::Cursor::GetFramebufferHeight()
|
||||
* Graphics::Cursor::GetFramebufferPitch();
|
||||
uint64_t numPages = (fbSize + 0xFFF) / 0x1000;
|
||||
|
||||
for (uint64_t i = 0; i < numPages; i++) {
|
||||
uint64_t phys = fbPhys + i * 0x1000;
|
||||
g_paging.MapWC(phys, Memory::HHDM(phys));
|
||||
}
|
||||
|
||||
Memory::VMM::FlushTLB();
|
||||
|
||||
Kt::KernelLogStream(OK, "Graphics") << "Framebuffer mapped as Write-Combining ("
|
||||
<< kcp::dec << numPages << " pages)";
|
||||
}
|
||||
Graphics::Cursor::MapWriteCombining();
|
||||
#endif
|
||||
|
||||
Hal::ACPI g_acpi((Hal::ACPI::XSDP*)Memory::HHDM(rsdp_request.response->address));
|
||||
@@ -181,17 +149,7 @@ extern "C" void kmain() {
|
||||
|
||||
Pci::Initialize(g_acpi.GetXSDT());
|
||||
|
||||
// Intel GPU driver — initialize right after PCI so the native
|
||||
// driver takes over early and all subsequent logs use it.
|
||||
Drivers::Graphics::IntelGPU::Initialize();
|
||||
if (Drivers::Graphics::IntelGPU::IsInitialized()) {
|
||||
Graphics::Cursor::SetFramebuffer(
|
||||
Drivers::Graphics::IntelGPU::GetFramebufferBase(),
|
||||
Drivers::Graphics::IntelGPU::GetWidth(),
|
||||
Drivers::Graphics::IntelGPU::GetHeight(),
|
||||
Drivers::Graphics::IntelGPU::GetPitch()
|
||||
);
|
||||
}
|
||||
Drivers::InitializeGraphics();
|
||||
|
||||
Timekeeping::ApicTimerInitialize();
|
||||
|
||||
@@ -201,12 +159,7 @@ extern "C" void kmain() {
|
||||
|
||||
Drivers::USB::Xhci::Initialize();
|
||||
|
||||
Drivers::Net::E1000::Initialize();
|
||||
if (!Drivers::Net::E1000::IsInitialized()) {
|
||||
KernelLogStream(INFO, "Init") << "E1000 not found, trying E1000E...";
|
||||
Drivers::Net::E1000E::Initialize();
|
||||
}
|
||||
Net::Initialize();
|
||||
Drivers::InitializeNetwork();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user