summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-12-22 14:41:10 -0500
committerIan Moffett <ian@osmora.org>2025-12-22 14:41:10 -0500
commitc854bc705bb794582fc562d1e29cb3a194fba454 (patch)
treeff8d77ba56ef88a5af101758aad2909196c3d340
parent7958265b8cc534b37fd3fec78a91d638b1e840f6 (diff)
mos: bpt: Add boot memory map interface
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--mos/sys/bpt/bpt_limine.c30
-rw-r--r--mos/sys/inc/kern/bpt.h39
-rw-r--r--mos/sys/kern/kern_bpt.c14
3 files changed, 83 insertions, 0 deletions
diff --git a/mos/sys/bpt/bpt_limine.c b/mos/sys/bpt/bpt_limine.c
index 0decc57..532ce6a 100644
--- a/mos/sys/bpt/bpt_limine.c
+++ b/mos/sys/bpt/bpt_limine.c
@@ -16,6 +16,13 @@ static volatile struct limine_hhdm_request hhdm_req = {
.revision = 0
};
+/* Memory map */
+static struct limine_memmap_response *mem_resp;
+static volatile struct limine_memmap_request mem_req = {
+ .id = LIMINE_MEMMAP_REQUEST,
+ .revision = 0
+};
+
static MOS_STATUS
limine_get_vars(BPT_VARS *res)
{
@@ -27,6 +34,26 @@ limine_get_vars(BPT_VARS *res)
return STATUS_SUCCESS;
}
+static MOS_STATUS
+limine_get_mementry(USIZE index, BPT_MEMENTRY *res)
+{
+ struct limine_memmap_entry *entry;
+
+ if (res == NULL) {
+ return STATUS_INVALID_ARG;
+ }
+
+ if (index >= mem_resp->entry_count) {
+ return STATUS_INVALID_ARG;
+ }
+
+ entry = mem_resp->entries[index];
+ res->base = entry->base;
+ res->length = entry->length;
+ res->type = entry->type; /* 1:1 */
+ return STATUS_SUCCESS;
+}
+
MOS_STATUS
bpt_limine_init(BPT_HOOKS *hooks_res)
{
@@ -35,6 +62,9 @@ bpt_limine_init(BPT_HOOKS *hooks_res)
}
hhdm_resp = hhdm_req.response;
+ mem_resp = mem_req.response;
+
hooks_res->get_vars = limine_get_vars;
+ hooks_res->get_mementry = limine_get_mementry;
return STATUS_SUCCESS;
}
diff --git a/mos/sys/inc/kern/bpt.h b/mos/sys/inc/kern/bpt.h
index 79d55f0..3e3c3f2 100644
--- a/mos/sys/inc/kern/bpt.h
+++ b/mos/sys/inc/kern/bpt.h
@@ -10,6 +10,20 @@
#include <sdk/status.h>
/*
+ * Represents memory map entry types
+ */
+typedef enum {
+ BPT_MEM_USABLE,
+ BPT_MEM_RESERVED,
+ BPT_MEM_ACPI_RECLAIM,
+ BPT_MEM_ACPI_NVS,
+ BPT_MEM_BAD,
+ BPT_MEM_BOOTLOADER,
+ BPT_MEM_KERNEL,
+ BPT_MEM_FRAMEBUFFER
+} BPT_MEM_TYPE;
+
+/*
* Represents boot protocol translation variables that
* contain information provided by the bootloader
*
@@ -20,12 +34,26 @@ typedef struct {
} BPT_VARS;
/*
+ * Represents a memory map entry
+ *
+ * @base: Base address of memory area
+ * @length: Length of memory area in bytes
+ * @type: Memory entry type
+ */
+typedef struct {
+ UPTR base;
+ USIZE length;
+ BPT_MEM_TYPE type;
+} BPT_MEMENTRY;
+
+/*
* 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);
+ MOS_STATUS(*get_mementry)(USIZE index, BPT_MEMENTRY *res);
} BPT_HOOKS;
/*
@@ -37,6 +65,17 @@ typedef struct {
MOS_STATUS bpt_get_vars(BPT_VARS *res);
/*
+ * Obtain a memory map entry
+ *
+ * @index: Entry index
+ * @res: Entry result
+ *
+ * Returns STATUS_SUCCESS if the entry index is within
+ * proper range.
+ */
+MOS_STATUS bpt_get_mementry(USIZE index, BPT_MEMENTRY *res);
+
+/*
* Initialize the boot protocol translation layer
*/
MOS_STATUS bpt_init(void);
diff --git a/mos/sys/kern/kern_bpt.c b/mos/sys/kern/kern_bpt.c
index 21f1c04..7d3511e 100644
--- a/mos/sys/kern/kern_bpt.c
+++ b/mos/sys/kern/kern_bpt.c
@@ -35,6 +35,20 @@ bpt_get_vars(BPT_VARS *res)
}
MOS_STATUS
+bpt_get_mementry(USIZE index, BPT_MEMENTRY *res)
+{
+ if (res == NULL) {
+ return STATUS_INVALID_ARG;
+ }
+
+ if (global_hooks.get_mementry == NULL) {
+ return STATUS_IO_ERROR;
+ }
+
+ return global_hooks.get_mementry(index, res);
+}
+
+MOS_STATUS
bpt_init(void)
{
MOS_STATUS status = STATUS_INVALID_ARG;