From e9a1de69cfdd7ee900366dc658f6c71cdb756cc4 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Mon, 22 Jun 2026 03:51:35 +0000 Subject: [PATCH] stos: bpal: Add memory map callbacks Signed-off-by: Chloe M. --- paw/stos/head/ke/bpal.h | 31 +++++++++++++++++++++++++++++++ paw/stos/ke/bpal/proto/limine.c | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/paw/stos/head/ke/bpal.h b/paw/stos/head/ke/bpal.h index 1ba7cac..2adb469 100644 --- a/paw/stos/head/ke/bpal.h +++ b/paw/stos/head/ke/bpal.h @@ -9,8 +9,37 @@ #ifndef _KE_BPAL_H_ #define _KE_BPAL_H_ 1 +#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 */ @@ -33,10 +62,12 @@ typedef struct { * * @KernelBase: Kernel load base * @Framebuffer: Framebuffer info + * @MemEntryIdx: Callback to get memory map entry by index */ typedef struct { UPTR KernelBase; BPAL_FRAMEBUFFER Framebuffer; + ST_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result); } BPAL_HANDLE; /* diff --git a/paw/stos/ke/bpal/proto/limine.c b/paw/stos/ke/bpal/proto/limine.c index cf37900..8f1275f 100644 --- a/paw/stos/ke/bpal/proto/limine.c +++ b/paw/stos/ke/bpal/proto/limine.c @@ -43,6 +43,13 @@ static struct limine_bootloader_performance_request LoaderPerReq = { .revision = 0 }; +/* Memory map request */ +static struct limine_memmap_response *MapResp = NULL; +static volatile struct limine_memmap_request MapReq = { + .id = LIMINE_MEMMAP_REQUEST_ID, + .revision = 0 +}; + VOID BpalInitFramebuffer(BPAL_HANDLE *Handle) { @@ -65,6 +72,22 @@ BpalInitFramebuffer(BPAL_HANDLE *Handle) Framebuffer->BlueMaskShift = FRAMEBUFFER->blue_mask_shift; } +static ST_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; +} + VOID KeBpalLimineInit(BPAL_HANDLE *Handle) { @@ -72,6 +95,7 @@ KeBpalLimineInit(BPAL_HANDLE *Handle) LoaderPerfResp = LoaderPerReq.response; HHDMResp = HHDMReq.response; FbResp = FbReq.response; + MapResp = MapReq.response; DTRACE( "slut handed control by %s %s\n", @@ -91,4 +115,5 @@ KeBpalLimineInit(BPAL_HANDLE *Handle) BpalInitFramebuffer(Handle); Handle->KernelBase = HHDMResp->offset; + Handle->MemEntryIdx = LimineMemEntryIdx; }