ptos: bpal: Add memory map interface

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
2026-07-10 20:16:46 +00:00
parent cbd74a54fb
commit 128060dca0
2 changed files with 56 additions and 1 deletions
+30
View File
@@ -12,6 +12,34 @@
#include <ptapi/status.h> #include <ptapi/status.h>
#include <ptdef.h> #include <ptdef.h>
/*
* 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 * Represents a framebuffer
*/ */
@@ -35,10 +63,12 @@ typedef struct {
* *
* @KernelBase: Represents the kernel load base * @KernelBase: Represents the kernel load base
* @Framebuffer: Framebuffer information * @Framebuffer: Framebuffer information
* @MemEntryIdx: Callback to get memory map entry by index
*/ */
typedef struct { typedef struct {
UPTR KernelBase; UPTR KernelBase;
BPAL_FRAMEBUFFER Framebuffer; BPAL_FRAMEBUFFER Framebuffer;
PT_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result);
} BPAL_HANDLE; } BPAL_HANDLE;
/* /*
+26 -1
View File
@@ -25,7 +25,30 @@ static volatile struct limine_hhdm_request HHDMReq = {
.revision = 0 .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) BpalInitFramebuffer(BPAL_HANDLE *Handle)
{ {
BPAL_FRAMEBUFFER *Framebuffer; BPAL_FRAMEBUFFER *Framebuffer;
@@ -56,7 +79,9 @@ KeBpalLimineInit(BPAL_HANDLE *Result)
HHDMResp = HHDMReq.response; HHDMResp = HHDMReq.response;
FbResp = FbReq.response; FbResp = FbReq.response;
MapResp = MapReq.response;
Result->KernelBase = HHDMResp->offset; Result->KernelBase = HHDMResp->offset;
Result->MemEntryIdx = LimineMemEntryIdx;
BpalInitFramebuffer(Result); BpalInitFramebuffer(Result);
} }