e9a1de69cf
Signed-off-by: Chloe M. <chloe@mensia.org>
120 lines
3.1 KiB
C
120 lines
3.1 KiB
C
/*
|
|
* Copyright (c) 2026, Chloe M.
|
|
* Provided under the BSD-3 clause.
|
|
*
|
|
* Description: Boot protocol abstraction layer
|
|
* Author: Chloe M.
|
|
*/
|
|
|
|
#include <ke/bpal.h>
|
|
#include <ex/trace.h>
|
|
#include <lib/limine.h>
|
|
|
|
#define FRAMEBUFFER FbResp->framebuffers[0]
|
|
|
|
#define DTRACE(Fmt, ...) \
|
|
TRACE("[ BPAL ]: " Fmt, ##__VA_ARGS__)
|
|
|
|
/* Framebuffer request */
|
|
static struct limine_framebuffer_response *FbResp = NULL;
|
|
static struct limine_framebuffer_request FbReq = {
|
|
.id = LIMINE_FRAMEBUFFER_REQUEST_ID,
|
|
.revision = 0
|
|
};
|
|
|
|
/* HHDM request */
|
|
static struct limine_hhdm_response *HHDMResp = NULL;
|
|
static volatile struct limine_hhdm_request HHDMReq = {
|
|
.id = LIMINE_HHDM_REQUEST_ID,
|
|
.revision = 0
|
|
};
|
|
|
|
/* Bootloader information */
|
|
static struct limine_bootloader_info_response *LoaderInfoResp = NULL;
|
|
static volatile struct limine_bootloader_info_request LoaderInfoReq = {
|
|
.id = LIMINE_BOOTLOADER_INFO_REQUEST_ID,
|
|
.revision = 0
|
|
};
|
|
|
|
/* Bootloader perf information */
|
|
static struct limine_bootloader_performance_response *LoaderPerfResp = NULL;
|
|
static struct limine_bootloader_performance_request LoaderPerReq = {
|
|
.id = LIMINE_BOOTLOADER_PERFORMANCE_REQUEST_ID,
|
|
.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)
|
|
{
|
|
BPAL_FRAMEBUFFER *Framebuffer;
|
|
|
|
if (Handle == NULL) {
|
|
return;
|
|
}
|
|
|
|
Framebuffer = &Handle->Framebuffer;
|
|
Framebuffer->Address = FRAMEBUFFER->address;
|
|
Framebuffer->Width = FRAMEBUFFER->width;
|
|
Framebuffer->Height = FRAMEBUFFER->height;
|
|
Framebuffer->Pitch = FRAMEBUFFER->pitch;
|
|
Framebuffer->RedMaskSize = FRAMEBUFFER->red_mask_size;
|
|
Framebuffer->RedMaskShift = FRAMEBUFFER->red_mask_shift;
|
|
Framebuffer->GreenMaskSize = FRAMEBUFFER->green_mask_size;
|
|
Framebuffer->GreenMaskShift = FRAMEBUFFER->green_mask_shift;
|
|
Framebuffer->BlueMaskSize = FRAMEBUFFER->blue_mask_size;
|
|
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)
|
|
{
|
|
LoaderInfoResp = LoaderInfoReq.response;
|
|
LoaderPerfResp = LoaderPerReq.response;
|
|
HHDMResp = HHDMReq.response;
|
|
FbResp = FbReq.response;
|
|
MapResp = MapReq.response;
|
|
|
|
DTRACE(
|
|
"slut handed control by %s %s\n",
|
|
LoaderInfoResp->name,
|
|
LoaderInfoResp->version
|
|
);
|
|
|
|
DTRACE(
|
|
"loader took %d usec\n",
|
|
LoaderPerfResp->init_usec
|
|
);
|
|
|
|
DTRACE(
|
|
"handoff took %d usec\n",
|
|
LoaderPerfResp->exec_usec
|
|
);
|
|
|
|
BpalInitFramebuffer(Handle);
|
|
Handle->KernelBase = HHDMResp->offset;
|
|
Handle->MemEntryIdx = LimineMemEntryIdx;
|
|
}
|