From 8b8d48aab44748dd70e4e263f9561ee7cc54f8c1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 18 Apr 2026 00:20:26 -0400 Subject: [PATCH] sp1: bpt: Add boot protocol translation layer Signed-off-by: Ian Moffett --- usr/src/mk/sys.mk | 6 ++-- usr/src/sp1/common/Makefile | 4 ++- usr/src/sp1/common/bpt/bpt.c | 53 +++++++++++++++++++++++++++++ usr/src/sp1/common/bpt/bpt_limine.c | 49 ++++++++++++++++++++++++++ usr/src/sp1/common/os/main.c | 4 +++ usr/src/sp1/head/os/bpt.h | 50 +++++++++++++++++++++++++++ 6 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 usr/src/sp1/common/bpt/bpt.c create mode 100644 usr/src/sp1/common/bpt/bpt_limine.c create mode 100644 usr/src/sp1/head/os/bpt.h diff --git a/usr/src/mk/sys.mk b/usr/src/mk/sys.mk index f408a8a..fa08d19 100644 --- a/usr/src/mk/sys.mk +++ b/usr/src/mk/sys.mk @@ -11,6 +11,7 @@ CC_PREFIX = x86_64-pc-mirocom ARCH_TARGET = amd64 +BOOT_PROTO = limine CC = \ var/cc/toolchain/gcc/bin/$(CC_PREFIX)-gcc @@ -28,7 +29,7 @@ SYS_CFLAGS = \ -mcmodel=kernel \ -Wno-attributes \ -fno-stack-protector\ - -D_SP1_MULTICORE + -D_SP1_MULTICORE \ ifeq ($(ARCH_TARGET),x86_64) SYS_CFLAGS += \ @@ -46,4 +47,5 @@ PASSDOWN_ARGS = \ ARCH=$(ARCH_TARGET) \ SYS_CC=$(CC) \ SYS_LD=$(LD) \ - SYS_CFLAGS="$(SYS_CFLAGS)" + SYS_CFLAGS="$(SYS_CFLAGS)" \ + BOOT_PROTO="\"$(BOOT_PROTO)\"" diff --git a/usr/src/sp1/common/Makefile b/usr/src/sp1/common/Makefile index ac0d40a..39eadbc 100644 --- a/usr/src/sp1/common/Makefile +++ b/usr/src/sp1/common/Makefile @@ -11,6 +11,7 @@ CFILES = $(shell find os/ -name "*.c") CFILES += $(shell find io/ -name "*.c") +CFILES += $(shell find bpt/ -name "*.c") CFILES += $(shell find ../ext -name "*.c") CFILES += $(shell find ../lib -name "*.c") @@ -28,7 +29,8 @@ CFLAGS = \ -D_KERNEL \ -MMD \ -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \ - -DPRINTF_DISABLE_SUPPORT_FLOAT + -DPRINTF_DISABLE_SUPPORT_FLOAT \ + -D_BOOT_PROTO="\"$(BOOT_PROTO)\"" .PHONY: all all: $(OFILES) diff --git a/usr/src/sp1/common/bpt/bpt.c b/usr/src/sp1/common/bpt/bpt.c new file mode 100644 index 0000000..cc57466 --- /dev/null +++ b/usr/src/sp1/common/bpt/bpt.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include +#include +#include + +#ifndef _BOOT_PROTO +#error "Boot protocol not defined!" +#else +#define BOOT_PROTO _BOOT_PROTO +#endif /* !_BOOT_PROTO */ + +/* Boot protocol translation operations */ +static struct bpt_ops ops; + +status_t +bpt_get_protovar(struct bpt_protovar *res) +{ + if (res == NULL) { + return STATUS_INVALID_PARAM; + } + + if (ops.get_protovar == NULL) { + return STATUS_IO_ERROR; + } + + return ops.get_protovar(res); +} + +status_t +bpt_init(void) +{ + switch (*BOOT_PROTO) { + case 'l': + if (memcmp(BOOT_PROTO, "limine", 6) == 0) { + bpt_init_limine(&ops); + return STATUS_SUCCESS; + } + + break; + } + + return STATUS_INVALID_PARAM; +} diff --git a/usr/src/sp1/common/bpt/bpt_limine.c b/usr/src/sp1/common/bpt/bpt_limine.c new file mode 100644 index 0000000..fb195bb --- /dev/null +++ b/usr/src/sp1/common/bpt/bpt_limine.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include +#include +#include + +/* HHDM request */ +static struct limine_hhdm_response *hhdm_resp = NULL; +static volatile struct limine_hhdm_request hhdm_req = { + .id = LIMINE_HHDM_REQUEST, + .revision = 0 +}; + +/* + * Obtain the boot protocol variables + * + * @res: Result is written here + */ +static status_t +limine_get_protovar(struct bpt_protovar *res) +{ + if (res == NULL) { + return STATUS_INVALID_PARAM; + } + + res->kload_base = hhdm_resp->offset; + return STATUS_SUCCESS; +} + +status_t +bpt_init_limine(struct bpt_ops *ops) +{ + if (ops == NULL) { + return STATUS_INVALID_PARAM; + } + + hhdm_resp = hhdm_req.response; + ops->get_protovar = limine_get_protovar; + return STATUS_SUCCESS; +} diff --git a/usr/src/sp1/common/os/main.c b/usr/src/sp1/common/os/main.c index e400a56..607d56a 100644 --- a/usr/src/sp1/common/os/main.c +++ b/usr/src/sp1/common/os/main.c @@ -10,6 +10,7 @@ */ #include +#include #include #include @@ -42,4 +43,7 @@ main(void) /* Pre-init the processor */ mu_cpu_preinit(&bsp); + + /* Initialize boot protocol translation layer */ + bpt_init(); } diff --git a/usr/src/sp1/head/os/bpt.h b/usr/src/sp1/head/os/bpt.h new file mode 100644 index 0000000..ebc5981 --- /dev/null +++ b/usr/src/sp1/head/os/bpt.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#ifndef _OS_BPT_H_ +#define _OS_BPT_H_ 1 + +#include +#include + +/* + * The protovar stores a list of information passed + * by the bootloader. + * + * @kload_base: Kernel load base + */ +struct bpt_protovar { + uintptr_t kload_base; +}; + +/* + * Operations associated with a specific boot protocol + */ +struct bpt_ops { + status_t(*get_protovar)(struct bpt_protovar *res); +}; + +/* + * Obtain the protocol variable structure reference + * + * @res: Result is written here + */ +status_t bpt_get_protovar(struct bpt_protovar *res); + +/* + * Initialize the boot protocol translation layer + */ +status_t bpt_init(void); + +/* Boot protocol specific init funcs */ +status_t bpt_init_limine(struct bpt_ops *ops); + +#endif /* !_OS_BPT_H_ */