From d8d686352d57ce31b2b53af86cbd9b98e4c4df4d Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Fri, 10 Jul 2026 05:09:53 +0000 Subject: [PATCH] ptos: ke: Add BPAL layer groundwork Signed-off-by: Chloe M. --- service/dev/build.env | 1 + service/dev/bvars.env | 1 + service/ptos/head/ke/bpal.h | 40 +++++++++++++++++++++++++ service/ptos/ke/Makefile | 1 + service/ptos/ke/bpal/bpal.c | 46 +++++++++++++++++++++++++++++ service/ptos/ke/bpal/proto/limine.c | 28 ++++++++++++++++++ service/ptos/ke/init.c | 4 +++ 7 files changed, 121 insertions(+) create mode 100644 service/ptos/head/ke/bpal.h create mode 100644 service/ptos/ke/bpal/bpal.c create mode 100644 service/ptos/ke/bpal/proto/limine.c diff --git a/service/dev/build.env b/service/dev/build.env index 1add698..3defa49 100644 --- a/service/dev/build.env +++ b/service/dev/build.env @@ -12,6 +12,7 @@ # Export envs export PT_PROJECT_ROOT=$PT_PROJECT_ROOT export PT_TARGET_ARCH=$PT_TARGET_ARCH +export PT_BOOT_PROTO=$PT_BOOT_PROTO if [ "$PT_BUILD_SOURCED" != "1" ] then diff --git a/service/dev/bvars.env b/service/dev/bvars.env index fd120b4..af2f356 100644 --- a/service/dev/bvars.env +++ b/service/dev/bvars.env @@ -8,3 +8,4 @@ PT_PROJECT_ROOT=$(pwd) PT_TARGET_ARCH=amd64 +PT_BOOT_PROTO=limine diff --git a/service/ptos/head/ke/bpal.h b/service/ptos/head/ke/bpal.h new file mode 100644 index 0000000..3e715f6 --- /dev/null +++ b/service/ptos/head/ke/bpal.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Boot protocol abstraction layer + * Author: Chloe M. + */ + +#ifndef _KE_BPAL_H_ +#define _KE_BPAL_H_ 1 + +#include +#include + +/* + * Represents a handle for the boot protocol abstraction + * layer containing data filled in by the bootloader. + * + * @KernelBase: Represents the kernel load base + */ +typedef struct { + UPTR KernelBase; +} BPAL_HANDLE; + +/* + * Initialize the boot protocol abstraction layer + */ +VOID KeBpalInit(VOID); + +/* + * Obtain the BPAL handle + * + * @Result: Result is written here + */ +PT_STATUS KeBpalGetHandle(BPAL_HANDLE *Result); + +/* Backend protocol init */ +VOID KeBpalLimineInit(BPAL_HANDLE *Result); + +#endif /* !_KE_BPAL_H_ */ diff --git a/service/ptos/ke/Makefile b/service/ptos/ke/Makefile index dd8d496..46bd715 100644 --- a/service/ptos/ke/Makefile +++ b/service/ptos/ke/Makefile @@ -19,6 +19,7 @@ CFLAGS = \ -D_KERNEL \ -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \ -DPRINTF_DISABLE_SUPPORT_FLOAT \ + -D_BOOT_PROTO="\"$(PT_BOOT_PROTO)\"" \ -I../xt/flanterm/src \ -I../head \ -I../target \ diff --git a/service/ptos/ke/bpal/bpal.c b/service/ptos/ke/bpal/bpal.c new file mode 100644 index 0000000..c32e70e --- /dev/null +++ b/service/ptos/ke/bpal/bpal.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: BPAL init logic + * Author: Chloe M. + */ + +#include +#include + +#ifndef _BOOT_PROTO +#error "Boot protocol is undefined" +#else +#define BOOT_PROTO _BOOT_PROTO +#endif /* !_BOOT_PROTO */ + +/* Globals */ +static BPAL_HANDLE BpalHandle; + +PT_STATUS +KeBpalGetHandle(BPAL_HANDLE *Result) +{ + if (Result == NULL) { + return STATUS_INVALID_PARAM; + } + + *Result = BpalHandle; + return STATUS_SUCCESS; +} + +VOID +KeBpalInit(VOID) +{ + const CHAR *BootProto = BOOT_PROTO; + + switch (*BootProto) { + case 'l': + if (RtlStrEq(BootProto, "limine")) { + KeBpalLimineInit(&BpalHandle); + return; + } + } + + /* TODO: Bugcheck here */ +} diff --git a/service/ptos/ke/bpal/proto/limine.c b/service/ptos/ke/bpal/proto/limine.c new file mode 100644 index 0000000..273d1ee --- /dev/null +++ b/service/ptos/ke/bpal/proto/limine.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Limine backend + * Author: Chloe M. + */ + +#include +#include + +/* HHDM request */ +static struct limine_hhdm_response *HHDMResp = NULL; +static volatile struct limine_hhdm_request HHDMReq = { + .id = LIMINE_HHDM_REQUEST_ID, + .revision = 0 +}; + +VOID +KeBpalLimineInit(BPAL_HANDLE *Result) +{ + if (Result == NULL) { + return; + } + + HHDMResp = HHDMReq.response; + Result->KernelBase = HHDMResp->offset; +} diff --git a/service/ptos/ke/init.c b/service/ptos/ke/init.c index 456241f..7567459 100644 --- a/service/ptos/ke/init.c +++ b/service/ptos/ke/init.c @@ -7,6 +7,8 @@ */ #include +#include +#include /* * Starting here is where the world is brought up and system @@ -15,4 +17,6 @@ VOID KiKernelInit(VOID) { + /* Initialize the boot protocol abstraction layer */ + KeBpalInit(); }