summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-12-21 23:11:28 -0500
committerIan Moffett <ian@osmora.org>2025-12-21 23:11:28 -0500
commit5b38a8d1455fafc038936a4961f0460b911893b0 (patch)
treebfc90d98d3cccd1744ec3ab78014a6db485a6136
parent58ced49a457fc6083ebdacd13246c9c05e24ffa3 (diff)
mos: Add boot protocol translation layer
The boot protocol translation layer treats all boot protocols as intermediary and thus translates them to a standard MOS protocol. Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--mk/defaults.mk1
-rw-r--r--mos/sys/Makefile2
-rw-r--r--mos/sys/bpt/bpt_limine.c40
-rw-r--r--mos/sys/inc/kern/bpt.h44
-rw-r--r--mos/sys/inc/kern/bptvar.h16
-rw-r--r--mos/sys/kern/Makefile5
-rw-r--r--mos/sys/kern/kern_bpt.c49
-rw-r--r--mos/sys/kern/kern_init.c4
8 files changed, 159 insertions, 2 deletions
diff --git a/mk/defaults.mk b/mk/defaults.mk
index 2c06603..0884e44 100644
--- a/mk/defaults.mk
+++ b/mk/defaults.mk
@@ -3,6 +3,7 @@
# Provided under the BSD-3 clause.
#
+BOOT_PROTO = limine
ARCH = x86_64
QEMU = qemu-system-$(ARCH)
diff --git a/mos/sys/Makefile b/mos/sys/Makefile
index a7bf6a0..e44e855 100644
--- a/mos/sys/Makefile
+++ b/mos/sys/Makefile
@@ -14,7 +14,7 @@ all: target kern arch
.PHONY: kern
kern:
- cd kern/; make CC=$(CC) LD=$(LD) SYS_CFLAGS="$(SYS_CFLAGS)"
+ cd kern/; make CC=$(CC) LD=$(LD) SYS_CFLAGS="$(SYS_CFLAGS)" BOOT_PROTO=$(BOOT_PROTO)
.PHONY: arch
arch:
diff --git a/mos/sys/bpt/bpt_limine.c b/mos/sys/bpt/bpt_limine.c
new file mode 100644
index 0000000..0decc57
--- /dev/null
+++ b/mos/sys/bpt/bpt_limine.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2025, Ian Moffett.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <sdk/types.h>
+#include <sdk/status.h>
+#include <proto/limine.h>
+#include <kern/bpt.h>
+#include <kern/bptvar.h>
+
+/* HHDM request */
+static struct limine_hhdm_response *hhdm_resp;
+static volatile struct limine_hhdm_request hhdm_req = {
+ .id = LIMINE_HHDM_REQUEST,
+ .revision = 0
+};
+
+static MOS_STATUS
+limine_get_vars(BPT_VARS *res)
+{
+ if (res == NULL) {
+ return STATUS_INVALID_ARG;
+ }
+
+ res->kernel_base = hhdm_resp->offset;
+ return STATUS_SUCCESS;
+}
+
+MOS_STATUS
+bpt_limine_init(BPT_HOOKS *hooks_res)
+{
+ if (hooks_res == NULL) {
+ return STATUS_INVALID_ARG;
+ }
+
+ hhdm_resp = hhdm_req.response;
+ hooks_res->get_vars = limine_get_vars;
+ return STATUS_SUCCESS;
+}
diff --git a/mos/sys/inc/kern/bpt.h b/mos/sys/inc/kern/bpt.h
new file mode 100644
index 0000000..79d55f0
--- /dev/null
+++ b/mos/sys/inc/kern/bpt.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2025, Ian Moffett.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef _KERN_BPT_H_
+#define _KERN_BPT_H_ 1
+
+#include <sdk/types.h>
+#include <sdk/status.h>
+
+/*
+ * Represents boot protocol translation variables that
+ * contain information provided by the bootloader
+ *
+ * @kernel_base: Higher half direct map offset (kernel load base)
+ */
+typedef struct {
+ UPTR kernel_base;
+} BPT_VARS;
+
+/*
+ * Represents boot protocol translation hooks that can
+ * be used to obtain state and variables from the underlying
+ * boot protocol in use.
+ */
+typedef struct {
+ MOS_STATUS(*get_vars)(BPT_VARS *res);
+} BPT_HOOKS;
+
+/*
+ * Obtain boot static variables provided by the
+ * bootloader
+ *
+ * @res: Result is written here
+ */
+MOS_STATUS bpt_get_vars(BPT_VARS *res);
+
+/*
+ * Initialize the boot protocol translation layer
+ */
+MOS_STATUS bpt_init(void);
+
+#endif /* !_KERN_BPT_H_ */
diff --git a/mos/sys/inc/kern/bptvar.h b/mos/sys/inc/kern/bptvar.h
new file mode 100644
index 0000000..6e29f70
--- /dev/null
+++ b/mos/sys/inc/kern/bptvar.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025, Ian Moffett.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef _KERN_BPTVAR_H_
+#define _KERN_BPTVAR_H_ 1
+
+#include <sdk/types.h>
+#include <sdk/status.h>
+#include <kern/bpt.h>
+
+/* Initialize the limine boot protocol */
+MOS_STATUS bpt_limine_init(BPT_HOOKS *hooks_res);
+
+#endif /* !_KERN_BPTVAR_H_ */
diff --git a/mos/sys/kern/Makefile b/mos/sys/kern/Makefile
index 6a79c9d..9c08e6e 100644
--- a/mos/sys/kern/Makefile
+++ b/mos/sys/kern/Makefile
@@ -4,6 +4,7 @@
#
CFILES = $(shell find . -name "*.c")
+CFILES += $(shell find ../bpt -name "*.c")
OFILES = $(CFILES:.c=.o)
SYS_CFLAGS =
@@ -11,7 +12,9 @@ CFLAGS = \
$(SYS_CFLAGS) \
-I../../../usr/sdk/inc/ \
-I../inc/ \
- -I../target/inc/
+ -I../target/inc/ \
+ -D_KERNEL \
+ -D_BOOT_PROTO="\"$(BOOT_PROTO)\""
.PHONY: all
all: $(OFILES)
diff --git a/mos/sys/kern/kern_bpt.c b/mos/sys/kern/kern_bpt.c
new file mode 100644
index 0000000..407cc71
--- /dev/null
+++ b/mos/sys/kern/kern_bpt.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2025, Ian Moffett.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <kern/bpt.h>
+#include <kern/bptvar.h>
+#include <kern/trace.h>
+#include <sdk/string.h>
+
+/*
+ * Verify that the boot protocol is actually defined
+ * by the build environment.
+ */
+#ifndef _BOOT_PROTO
+#error "Boot protocol undefined"
+#else
+#define BOOT_PROTO (_BOOT_PROTO)
+#endif /* !_BOOT_PROTO */
+
+static BPT_HOOKS global_hooks;
+
+MOS_STATUS
+bpt_get_vars(BPT_VARS *res)
+{
+ if (res == NULL) {
+ return STATUS_FAILURE;
+ }
+
+ return global_hooks.get_vars(res);
+}
+
+MOS_STATUS
+bpt_init(void)
+{
+ MOS_STATUS status = STATUS_INVALID_ARG;
+
+ switch (BOOT_PROTO[0]) {
+ case 'l':
+ if (strcmp(BOOT_PROTO, "limine") == 0) {
+ status = bpt_limine_init(&global_hooks);
+ }
+
+ break;
+ }
+
+ trace("bpt: hooks engaged\n");
+ return status;
+}
diff --git a/mos/sys/kern/kern_init.c b/mos/sys/kern/kern_init.c
index ec2a5c5..d47f302 100644
--- a/mos/sys/kern/kern_init.c
+++ b/mos/sys/kern/kern_init.c
@@ -4,6 +4,7 @@
*/
#include <kern/trace.h>
+#include <kern/bpt.h>
#include <mu/uart.h>
#define write_boot_header() \
@@ -25,4 +26,7 @@ kern_main(void)
/* Write the boot header */
write_boot_header();
+
+ /* Initialize the boot protocol translation layer */
+ bpt_init();
}