sp1: bpt: Add boot protocol translation layer

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-04-18 00:20:26 -04:00
parent a9746d4c55
commit 8b8d48aab4
6 changed files with 163 additions and 3 deletions
+4 -2
View File
@@ -11,6 +11,7 @@
CC_PREFIX = x86_64-pc-mirocom CC_PREFIX = x86_64-pc-mirocom
ARCH_TARGET = amd64 ARCH_TARGET = amd64
BOOT_PROTO = limine
CC = \ CC = \
var/cc/toolchain/gcc/bin/$(CC_PREFIX)-gcc var/cc/toolchain/gcc/bin/$(CC_PREFIX)-gcc
@@ -28,7 +29,7 @@ SYS_CFLAGS = \
-mcmodel=kernel \ -mcmodel=kernel \
-Wno-attributes \ -Wno-attributes \
-fno-stack-protector\ -fno-stack-protector\
-D_SP1_MULTICORE -D_SP1_MULTICORE \
ifeq ($(ARCH_TARGET),x86_64) ifeq ($(ARCH_TARGET),x86_64)
SYS_CFLAGS += \ SYS_CFLAGS += \
@@ -46,4 +47,5 @@ PASSDOWN_ARGS = \
ARCH=$(ARCH_TARGET) \ ARCH=$(ARCH_TARGET) \
SYS_CC=$(CC) \ SYS_CC=$(CC) \
SYS_LD=$(LD) \ SYS_LD=$(LD) \
SYS_CFLAGS="$(SYS_CFLAGS)" SYS_CFLAGS="$(SYS_CFLAGS)" \
BOOT_PROTO="\"$(BOOT_PROTO)\""
+3 -1
View File
@@ -11,6 +11,7 @@
CFILES = $(shell find os/ -name "*.c") CFILES = $(shell find os/ -name "*.c")
CFILES += $(shell find io/ -name "*.c") CFILES += $(shell find io/ -name "*.c")
CFILES += $(shell find bpt/ -name "*.c")
CFILES += $(shell find ../ext -name "*.c") CFILES += $(shell find ../ext -name "*.c")
CFILES += $(shell find ../lib -name "*.c") CFILES += $(shell find ../lib -name "*.c")
@@ -28,7 +29,8 @@ CFLAGS = \
-D_KERNEL \ -D_KERNEL \
-MMD \ -MMD \
-DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \ -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \
-DPRINTF_DISABLE_SUPPORT_FLOAT -DPRINTF_DISABLE_SUPPORT_FLOAT \
-D_BOOT_PROTO="\"$(BOOT_PROTO)\""
.PHONY: all .PHONY: all
all: $(OFILES) all: $(OFILES)
+53
View File
@@ -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 <os/bpt.h>
#include <lib/limine.h>
#include <string.h>
#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;
}
+49
View File
@@ -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 <os/bpt.h>
#include <lib/limine.h>
#include <lib/printf.h>
/* 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;
}
+4
View File
@@ -10,6 +10,7 @@
*/ */
#include <io/cons/cons.h> #include <io/cons/cons.h>
#include <os/bpt.h>
#include <lib/printf.h> #include <lib/printf.h>
#include <mu/cpu.h> #include <mu/cpu.h>
@@ -42,4 +43,7 @@ main(void)
/* Pre-init the processor */ /* Pre-init the processor */
mu_cpu_preinit(&bsp); mu_cpu_preinit(&bsp);
/* Initialize boot protocol translation layer */
bpt_init();
} }
+50
View File
@@ -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 <sys/types.h>
#include <sys/status.h>
/*
* 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_ */