sp1: bpt: Add helper to obtain memory map entry

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-04-18 03:06:54 -04:00
parent 18d88ef80c
commit f1f20a3e65
3 changed files with 88 additions and 0 deletions
+14
View File
@@ -36,6 +36,20 @@ bpt_get_protovar(struct bpt_protovar *res)
return ops.get_protovar(res);
}
status_t
bpt_mem_entry_i(size_t index, struct mem_entry *res)
{
if (res == NULL) {
return STATUS_INVALID_PARAM;
}
if (ops.mem_entry_i == NULL) {
return STATUS_IO_ERROR;
}
return ops.mem_entry_i(index, res);
}
status_t
bpt_init(void)
{
+38
View File
@@ -13,6 +13,13 @@
#include <lib/limine.h>
#include <lib/printf.h>
/* Memory map request */
static struct limine_memmap_response *memmap_resp = NULL;
static volatile struct limine_memmap_request memmap_req = {
.id = LIMINE_MEMMAP_REQUEST,
.revision = 0
};
/* HHDM request */
static struct limine_hhdm_response *hhdm_resp = NULL;
static volatile struct limine_hhdm_request hhdm_req = {
@@ -36,6 +43,34 @@ limine_get_protovar(struct bpt_protovar *res)
return STATUS_SUCCESS;
}
/*
* Obtain a memory map entry by index
*
* @index: Index of memory map entry to obtain
* @res: Result is written here
*/
static status_t
limine_mem_entry_i(size_t index, struct mem_entry *res)
{
struct limine_memmap_entry *entry;
if (res == NULL) {
return STATUS_INVALID_PARAM;
}
/* Don't overflow */
if (index >= memmap_resp->entry_count) {
return STATUS_NOT_FOUND;
}
/* 1:1 */
entry = memmap_resp->entries[index];
res->base = entry->base;
res->length = entry->length;
res->type = entry->type;
return STATUS_SUCCESS;
}
status_t
bpt_init_limine(struct bpt_ops *ops)
{
@@ -44,6 +79,9 @@ bpt_init_limine(struct bpt_ops *ops)
}
hhdm_resp = hhdm_req.response;
memmap_resp = memmap_req.response;
ops->get_protovar = limine_get_protovar;
ops->mem_entry_i = limine_mem_entry_i;
return STATUS_SUCCESS;
}
+36
View File
@@ -15,6 +15,34 @@
#include <sys/types.h>
#include <sys/status.h>
/*
* Memory map entry types
*/
typedef enum {
MEMORY_USABLE,
MEMORY_RESERVED,
MEMORY_ACPI_RECLAIM,
MEMORY_ACPI_NVS,
MEMORY_BAD,
MEMORY_BOOTLOADER,
MEMORY_KERNEL,
MEMORY_FRAMEBUFFER,
MEMORY_ACPI_TABLES
} mem_type_t;
/*
* Represents a memory map entry
*
* @base: Entry base address
* @length: Entry length
* @type: Entry type
*/
struct mem_entry {
uintptr_t base;
size_t length;
mem_type_t type;
};
/*
* The protovar stores a list of information passed
* by the bootloader.
@@ -30,6 +58,7 @@ struct bpt_protovar {
*/
struct bpt_ops {
status_t(*get_protovar)(struct bpt_protovar *res);
status_t(*mem_entry_i)(size_t index, struct mem_entry *res);
};
/*
@@ -39,6 +68,13 @@ struct bpt_ops {
*/
status_t bpt_get_protovar(struct bpt_protovar *res);
/*
* Obtain a memory map entry by index
*
* Returns STATUS_NOT_FOUND on failure
*/
status_t bpt_mem_entry_i(size_t index, struct mem_entry *res);
/*
* Initialize the boot protocol translation layer
*/