From 128060dca0a7817e0c2c9445f9593e5669a2b71c Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Fri, 10 Jul 2026 20:16:46 +0000 Subject: [PATCH] ptos: bpal: Add memory map interface Signed-off-by: Chloe M. --- service/ptos/head/ke/bpal.h | 30 +++++++++++++++++++++++++++++ service/ptos/ke/bpal/proto/limine.c | 27 +++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/service/ptos/head/ke/bpal.h b/service/ptos/head/ke/bpal.h index 37e0eec..2caaff6 100644 --- a/service/ptos/head/ke/bpal.h +++ b/service/ptos/head/ke/bpal.h @@ -12,6 +12,34 @@ #include #include +/* + * Valid memory types + */ +typedef enum { + MEMORY_USABLE, + MEMORY_RESERVED, + MEMORY_ACPI_RECLAIM, + MEMORY_ACPI_NVS, + MEMORY_BAD, + MEMORY_BOOTLOADER, + MEMORY_KERNEL, + MEMORY_FRAMEBUFFER, + MEMORY_ACPI_TABLES +} MEM_TYPE; + +/* + * Memory map entry + * + * @Base: Entry base + * @Length: Entry length + * @Type: Entry type + */ +typedef struct { + UQUAD Base; + UQUAD Length; + UQUAD Type; +} MEMMAP_ENTRY; + /* * Represents a framebuffer */ @@ -35,10 +63,12 @@ typedef struct { * * @KernelBase: Represents the kernel load base * @Framebuffer: Framebuffer information + * @MemEntryIdx: Callback to get memory map entry by index */ typedef struct { UPTR KernelBase; BPAL_FRAMEBUFFER Framebuffer; + PT_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result); } BPAL_HANDLE; /* diff --git a/service/ptos/ke/bpal/proto/limine.c b/service/ptos/ke/bpal/proto/limine.c index cab1a21..59d421e 100644 --- a/service/ptos/ke/bpal/proto/limine.c +++ b/service/ptos/ke/bpal/proto/limine.c @@ -25,7 +25,30 @@ static volatile struct limine_hhdm_request HHDMReq = { .revision = 0 }; -VOID +/* Memory map request */ +static struct limine_memmap_response *MapResp = NULL; +static volatile struct limine_memmap_request MapReq = { + .id = LIMINE_MEMMAP_REQUEST_ID, + .revision = 0 +}; + +static PT_STATUS +LimineMemEntryIdx(USIZE Idx, MEMMAP_ENTRY *Result) +{ + struct limine_memmap_entry *Entry; + + if (Idx >= MapResp->entry_count) { + return STATUS_NOT_FOUND; + } + + Entry = MapResp->entries[Idx]; + Result->Base = Entry->base; + Result->Length = Entry->length; + Result->Type = Entry->type; + return STATUS_SUCCESS; +} + +static VOID BpalInitFramebuffer(BPAL_HANDLE *Handle) { BPAL_FRAMEBUFFER *Framebuffer; @@ -56,7 +79,9 @@ KeBpalLimineInit(BPAL_HANDLE *Result) HHDMResp = HHDMReq.response; FbResp = FbReq.response; + MapResp = MapReq.response; Result->KernelBase = HHDMResp->offset; + Result->MemEntryIdx = LimineMemEntryIdx; BpalInitFramebuffer(Result); }