From 5e03409586efc37931f07b40ee0c71a9a9e109f7 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 15:51:28 +0200 Subject: rsnix: memory management — free-list heap, bitmap pages, paging adoption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - uefi.rs: full EfiMemoryType constants (0-14) + memory_type_name(); fix MEMORY_TYPE_LOADER_DATA from 6 to 2 per the UEFI spec - memory.rs: replace the bump allocator with a first-fit free-list heap (splitting, coalescing, 8-byte back-pointer for alignment-safe free); add a bitmap physical page allocator (heap region reserved, page-0 guard, aligned runs); grow the heap from the page allocator on demand - paging.rs: identity page-table helpers — adopt_tables() rebuilds the firmware map into our own tables (OVMF maps its tables read-only, so the firmware tree can't be modified in place) and switches CR3; map_page/unmap_page/is_mapped with 2 MB/1 GB large-page splitting - main.rs: boot self-tests for heap, pages, and paging --- rsnix/src/uefi.rs | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'rsnix/src/uefi.rs') diff --git a/rsnix/src/uefi.rs b/rsnix/src/uefi.rs index 2e3ed6b..619739e 100644 --- a/rsnix/src/uefi.rs +++ b/rsnix/src/uefi.rs @@ -116,13 +116,43 @@ pub struct MemoryDescriptor { pub attribute: u64, } -pub const MEMORY_TYPE_CONVENTIONAL: u32 = 7; -#[allow(dead_code)] -pub const MEMORY_TYPE_LOADER_DATA: u32 = 6; -#[allow(dead_code)] +pub const MEMORY_TYPE_RESERVED: u32 = 0; +pub const MEMORY_TYPE_LOADER_CODE: u32 = 1; +pub const MEMORY_TYPE_LOADER_DATA: u32 = 2; pub const MEMORY_TYPE_BOOT_SERVICES_CODE: u32 = 3; -#[allow(dead_code)] pub const MEMORY_TYPE_BOOT_SERVICES_DATA: u32 = 4; +pub const MEMORY_TYPE_RUNTIME_CODE: u32 = 5; +pub const MEMORY_TYPE_RUNTIME_DATA: u32 = 6; +pub const MEMORY_TYPE_CONVENTIONAL: u32 = 7; +pub const MEMORY_TYPE_UNUSABLE: u32 = 8; +pub const MEMORY_TYPE_ACPI_RECLAIM: u32 = 9; +pub const MEMORY_TYPE_ACPI_NVS: u32 = 10; +pub const MEMORY_TYPE_MMIO: u32 = 11; +pub const MEMORY_TYPE_MMIO_PORT: u32 = 12; +pub const MEMORY_TYPE_PAL_CODE: u32 = 13; +pub const MEMORY_TYPE_PERSISTENT: u32 = 14; + +/// Human-readable name for a UEFI memory type. +pub fn memory_type_name(kind: u32) -> &'static str { + match kind { + 0 => "Reserved", + 1 => "LoaderCode", + 2 => "LoaderData", + 3 => "BootServicesCode", + 4 => "BootServicesData", + 5 => "RuntimeCode", + 6 => "RuntimeData", + 7 => "Conventional", + 8 => "Unusable", + 9 => "ACPIReclaim", + 10 => "ACPINVS", + 11 => "MMIO", + 12 => "MMIOPort", + 13 => "PalCode", + 14 => "Persistent", + _ => "Unknown", + } +} // --------------------------------------------------------------------------- // Boot services table -- cgit v1.2.3