add a realtime scheduler class and priority-inheritance mutexes with timeouts and abandonment, add an HDA audio driver and a SYS_AUDIO_* syscall family, flesh out kernel32 with Win32 threads, events, mutexes, critical sections, and condition variables, add SYS_RESUME_THREAD for suspended thread creation, add KeInitializeMemoryTypes to reprogram MTRRs and install a canonical PAT for WB/WC/UC control, rework the display pipeline with a pitched present path and console output flush, bring back disk.vhd with mtools since vvfat fucking sucks, harden AHCI with serialized cache flush, USB mass storage with SCSI sense-data decoding, and xHCI with cleaner DMA teardown, fix the last stray for(;;) in HalStopProcessor to while(true), pile on smoke tests for audio, win32 sync primitives, and thread suspend, implement AHCI timeout, kill readahead since it was desperetaly trying to murder me, fix doom sound x2.

This commit is contained in:
maksw committed 2026-08-11 18:38:36 +02:00
1 parent 8b254f84f4
commit 4add6789ba
177 files changed
+22565 -3070

No files matched your search

+47 -17
View File
@@ -26,6 +26,11 @@ int _fltused = 0;
#define KERNEL_VIRT_BASE 0xFFFF800000000000ULL
#define PHYS_MAP_BASE 0xFFFF880000000000ULL
#define PAGE_SIZE 4096ULL
#define BOOT_PAGE_PRESENT 0x01ULL
#define BOOT_PAGE_WRITE 0x02ULL
#define BOOT_PAGE_CACHE_WB 0x00ULL
#define BOOT_PAGE_CACHE_WC 0x08ULL
#define BOOT_PAGE_CACHE_UC 0x10ULL
// Implements the ascii Str To Unicode Str S operation.
static int AsciiStrToUnicodeStrS(const char* Source, uint16_t* Dest, size_t DestMax) {
@@ -168,6 +173,35 @@ static void MapRangeSmart(UINT64 virt, UINT64 phys, UINT64 size, UINT64 flags) {
}
}
// Returns whether a firmware descriptor describes memory that is safe to expose through the direct map.
static bool IsDirectMapRamType(EFI_MEMORY_TYPE type) {
switch (type) {
case EfiLoaderCode:
case EfiLoaderData:
case EfiBootServicesCode:
case EfiBootServicesData:
case EfiRuntimeServicesCode:
case EfiRuntimeServicesData:
case EfiConventionalMemory:
case EfiACPIReclaimMemory:
case EfiACPIMemoryNVS:
return true;
default:
return false;
}
}
// Converts firmware cache attributes into the kernel's canonical PAT policy.
static UINT64 DirectMapCacheFlags(const EFI_MEMORY_DESCRIPTOR* desc) {
if (!desc)
return BOOT_PAGE_CACHE_UC;
if (desc->Attribute & (EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WT))
return BOOT_PAGE_CACHE_UC;
if (desc->Attribute & EFI_MEMORY_WC)
return BOOT_PAGE_CACHE_WC;
return BOOT_PAGE_CACHE_WB;
}
static void MapRangeSkipping(UINT64 virt, UINT64 phys, UINT64 size, UINT64 flags,
const UINT64* holes, UINTN holeCount) {
UINT64 curVirt = virt;
@@ -790,8 +824,8 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable
for (UINT64 i = 0; i < fbBytes; i += PAGE_SIZE) {
UINT64 phys = gop->Mode->FrameBufferBase + i;
Map4K(PHYS_MAP_BASE + phys, phys, 0x13); // P|W|PCD (write-combined MMIO)
Map4K(phys, phys, 0x13);
Map4K(PHYS_MAP_BASE + phys, phys, BOOT_PAGE_PRESENT | BOOT_PAGE_WRITE | BOOT_PAGE_CACHE_WC);
Map4K(phys, phys, BOOT_PAGE_PRESENT | BOOT_PAGE_WRITE | BOOT_PAGE_CACHE_WC);
}
}
@@ -866,21 +900,16 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable
for (UINTN i = 0; i < mapSize / descSz; i++) {
EFI_MEMORY_DESCRIPTOR* desc = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)efiMap + i * descSz);
// Map normal firmware-described regions into the physical window.
// PCI/firmware MMIO is mapped explicitly by the owning driver.
if (desc->Type != EfiUnusableMemory &&
desc->Type != EfiMemoryMappedIO &&
desc->Type != EfiMemoryMappedIOPortSpace) {
// Only firmware-described RAM receives a direct-map alias. Reserved
// and MMIO descriptors stay unmapped until an owning subsystem maps
// them with an explicit PAT policy.
if (IsDirectMapRamType(desc->Type)) {
UINT64 start = desc->PhysicalStart;
UINT64 end = start + (desc->NumberOfPages * PAGE_SIZE);
UINT64 size = desc->NumberOfPages * PAGE_SIZE;
UINT64 flags = BOOT_PAGE_PRESENT | BOOT_PAGE_WRITE | DirectMapCacheFlags(desc);
// Add 2 pages (8KB) of padding to the end of the region.
// This catches ACPI tables that cross page boundaries into unmapped
// memory because of buggy UEFI size reporting.
end += 2 * PAGE_SIZE;
MapRangeSkipping(start, start, end - start, 0x03, idHoles, idHoleCount);
MapRangeSkipping(PHYS_MAP_BASE + start, start, end - start, 0x03, winHoles, winHoleCount);
MapRangeSkipping(start, start, size, flags, idHoles, idHoleCount);
MapRangeSkipping(PHYS_MAP_BASE + start, start, size, flags, winHoles, winHoleCount);
}
}
}
@@ -891,8 +920,9 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable
// We explicitly map the region from 0xFEC00000 up through 0xFEE00FFF
// to guarantee the HAL can access them via the physical window.
for (UINT64 phys = 0xFEC00000; phys < 0xFEE01000; phys += PAGE_SIZE) {
Map4K(phys, phys, 0x13); // Identity Map, P|W|PCD
Map4K(PHYS_MAP_BASE + phys, phys, 0x13); // Physical Window Map, P|W|PCD
UINT64 flags = BOOT_PAGE_PRESENT | BOOT_PAGE_WRITE | BOOT_PAGE_CACHE_UC;
Map4K(phys, phys, flags);
Map4K(PHYS_MAP_BASE + phys, phys, flags);
}
Print(L"8\n");