ptos: bpal: Add bootloader module lookup support

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-14 16:42:21 -04:00
parent a029f0de5d
commit 94e2dbfed0
2 changed files with 53 additions and 0 deletions
+12
View File
@@ -57,6 +57,17 @@ typedef struct {
UCHAR BlueMaskShift;
} BPAL_FRAMEBUFFER;
/*
* Bootloader module
*
* @Data: Data backed by module
* @Length: Length of data in bytes
*/
typedef struct {
VOID *Data;
USIZE Length;
} BPAL_MODULE;
/*
* Represents a handle for the boot protocol abstraction
* layer containing data filled in by the bootloader.
@@ -71,6 +82,7 @@ typedef struct {
VOID *RsdpBase;
BPAL_FRAMEBUFFER Framebuffer;
PT_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result);
PT_STATUS(*ModuleLookup)(CHAR *Path, BPAL_MODULE *Result);
} BPAL_HANDLE;
/*
+41
View File
@@ -8,6 +8,7 @@
#include <ke/bpal.h>
#include <lib/limine.h>
#include <string.h>
#define FRAMEBUFFER FbResp->framebuffers[0]
@@ -39,6 +40,13 @@ static volatile struct limine_rsdp_request RsdpReq = {
.revision = 0
};
/* Module request */
static struct limine_module_response *ModResp = NULL;
static volatile struct limine_module_request ModReq = {
.id = LIMINE_MODULE_REQUEST_ID,
.revision = 0
};
static PT_STATUS
LimineMemEntryIdx(USIZE Idx, MEMMAP_ENTRY *Result)
{
@@ -77,6 +85,37 @@ BpalInitFramebuffer(BPAL_HANDLE *Handle)
Framebuffer->BlueMaskShift = FRAMEBUFFER->blue_mask_shift;
}
static PT_STATUS
LimineModuleLookup(CHAR *Path, BPAL_MODULE *Result)
{
struct limine_file *Module;
USIZE PathLen;
if (Path == NULL || Result == NULL) {
return STATUS_INVALID_PARAM;
}
if (ModResp == NULL) {
return STATUS_NOT_FOUND;
}
PathLen = RtlStrLen(Path);
for (USIZE Idx = 0; Idx < ModResp->module_count; ++Idx) {
Module = ModResp->modules[Idx];
if (*Module->path != *Path) {
continue;
}
if (RtlMemCmp(Module->path, Path, PathLen) == 0) {
Result->Data = Module->address;
Result->Length = Module->size;
return STATUS_SUCCESS;
}
}
return STATUS_NOT_FOUND;
}
VOID
KeBpalLimineInit(BPAL_HANDLE *Result)
{
@@ -88,9 +127,11 @@ KeBpalLimineInit(BPAL_HANDLE *Result)
FbResp = FbReq.response;
MapResp = MapReq.response;
RsdpResp = RsdpReq.response;
ModResp = ModReq.response;
Result->KernelBase = HHDMResp->offset;
Result->MemEntryIdx = LimineMemEntryIdx;
Result->ModuleLookup = LimineModuleLookup;
Result->RsdpBase = RsdpResp->address;
BpalInitFramebuffer(Result);
}