diff --git a/paw/stos/head/ke/bpal.h b/paw/stos/head/ke/bpal.h index 2adb469..1128a93 100644 --- a/paw/stos/head/ke/bpal.h +++ b/paw/stos/head/ke/bpal.h @@ -57,17 +57,30 @@ 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; + /* * Boot protocol abstraction handle * * @KernelBase: Kernel load base * @Framebuffer: Framebuffer info * @MemEntryIdx: Callback to get memory map entry by index + * @ModuleLookup: Lookup a module */ typedef struct { UPTR KernelBase; BPAL_FRAMEBUFFER Framebuffer; ST_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result); + ST_STATUS(*ModuleLookup)(CHAR *Path, BPAL_MODULE *Result); } BPAL_HANDLE; /* diff --git a/paw/stos/ke/bpal/proto/limine.c b/paw/stos/ke/bpal/proto/limine.c index 8f1275f..1d982a1 100644 --- a/paw/stos/ke/bpal/proto/limine.c +++ b/paw/stos/ke/bpal/proto/limine.c @@ -9,6 +9,7 @@ #include #include #include +#include #define FRAMEBUFFER FbResp->framebuffers[0] @@ -50,6 +51,44 @@ static volatile struct limine_memmap_request MapReq = { .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 ST_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 BpalInitFramebuffer(BPAL_HANDLE *Handle) { @@ -94,6 +133,7 @@ KeBpalLimineInit(BPAL_HANDLE *Handle) LoaderInfoResp = LoaderInfoReq.response; LoaderPerfResp = LoaderPerReq.response; HHDMResp = HHDMReq.response; + ModResp = ModReq.response; FbResp = FbReq.response; MapResp = MapReq.response; @@ -116,4 +156,5 @@ KeBpalLimineInit(BPAL_HANDLE *Handle) BpalInitFramebuffer(Handle); Handle->KernelBase = HHDMResp->offset; Handle->MemEntryIdx = LimineMemEntryIdx; + Handle->ModuleLookup = LimineModuleLookup; }