stos: bpal: Add helper to get bootloader module
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -57,17 +57,30 @@ typedef struct {
|
|||||||
UCHAR BlueMaskShift;
|
UCHAR BlueMaskShift;
|
||||||
} BPAL_FRAMEBUFFER;
|
} 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
|
* Boot protocol abstraction handle
|
||||||
*
|
*
|
||||||
* @KernelBase: Kernel load base
|
* @KernelBase: Kernel load base
|
||||||
* @Framebuffer: Framebuffer info
|
* @Framebuffer: Framebuffer info
|
||||||
* @MemEntryIdx: Callback to get memory map entry by index
|
* @MemEntryIdx: Callback to get memory map entry by index
|
||||||
|
* @ModuleLookup: Lookup a module
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UPTR KernelBase;
|
UPTR KernelBase;
|
||||||
BPAL_FRAMEBUFFER Framebuffer;
|
BPAL_FRAMEBUFFER Framebuffer;
|
||||||
ST_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result);
|
ST_STATUS(*MemEntryIdx)(USIZE Idx, MEMMAP_ENTRY *Result);
|
||||||
|
ST_STATUS(*ModuleLookup)(CHAR *Path, BPAL_MODULE *Result);
|
||||||
} BPAL_HANDLE;
|
} BPAL_HANDLE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <ke/bpal.h>
|
#include <ke/bpal.h>
|
||||||
#include <ex/trace.h>
|
#include <ex/trace.h>
|
||||||
#include <lib/limine.h>
|
#include <lib/limine.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define FRAMEBUFFER FbResp->framebuffers[0]
|
#define FRAMEBUFFER FbResp->framebuffers[0]
|
||||||
|
|
||||||
@@ -50,6 +51,44 @@ static volatile struct limine_memmap_request MapReq = {
|
|||||||
.revision = 0
|
.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
|
VOID
|
||||||
BpalInitFramebuffer(BPAL_HANDLE *Handle)
|
BpalInitFramebuffer(BPAL_HANDLE *Handle)
|
||||||
{
|
{
|
||||||
@@ -94,6 +133,7 @@ KeBpalLimineInit(BPAL_HANDLE *Handle)
|
|||||||
LoaderInfoResp = LoaderInfoReq.response;
|
LoaderInfoResp = LoaderInfoReq.response;
|
||||||
LoaderPerfResp = LoaderPerReq.response;
|
LoaderPerfResp = LoaderPerReq.response;
|
||||||
HHDMResp = HHDMReq.response;
|
HHDMResp = HHDMReq.response;
|
||||||
|
ModResp = ModReq.response;
|
||||||
FbResp = FbReq.response;
|
FbResp = FbReq.response;
|
||||||
MapResp = MapReq.response;
|
MapResp = MapReq.response;
|
||||||
|
|
||||||
@@ -116,4 +156,5 @@ KeBpalLimineInit(BPAL_HANDLE *Handle)
|
|||||||
BpalInitFramebuffer(Handle);
|
BpalInitFramebuffer(Handle);
|
||||||
Handle->KernelBase = HHDMResp->offset;
|
Handle->KernelBase = HHDMResp->offset;
|
||||||
Handle->MemEntryIdx = LimineMemEntryIdx;
|
Handle->MemEntryIdx = LimineMemEntryIdx;
|
||||||
|
Handle->ModuleLookup = LimineModuleLookup;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user