From 9dfb6d9e2b600e6c8c04efb7b4427d52c3050f30 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 18 Apr 2026 21:05:06 -0400 Subject: [PATCH] sp1: mm: Add helpers to convert PMA-to-vma, etc Signed-off-by: Ian Moffett --- usr/src/sp1/head/mm/vm.h | 27 +++++++++++++++++++++++++++ usr/src/sp1/head/os/bpt.h | 16 ++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 usr/src/sp1/head/mm/vm.h diff --git a/usr/src/sp1/head/mm/vm.h b/usr/src/sp1/head/mm/vm.h new file mode 100644 index 0000000..348197d --- /dev/null +++ b/usr/src/sp1/head/mm/vm.h @@ -0,0 +1,27 @@ +/* + * 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 _MM_VM_H_ +#define _MM_VM_H_ 1 + +#include +#include + +/* + * Macros used to convert physical to virtual addresses + * and vice versa. + */ +#define pma_to_vma(pma) \ + PTR_OFFSET((void *)pma, bpt_kload_base()) +#define vma_to_pma(vma) \ + (uintptr_t)PTR_NOFFSET(vma, bpt_kload_base()) + +#endif /* !_MM_VM_H_ */ diff --git a/usr/src/sp1/head/os/bpt.h b/usr/src/sp1/head/os/bpt.h index 43bbc86..ac597a7 100644 --- a/usr/src/sp1/head/os/bpt.h +++ b/usr/src/sp1/head/os/bpt.h @@ -12,6 +12,7 @@ #ifndef _OS_BPT_H_ #define _OS_BPT_H_ 1 +#include #include #include @@ -83,4 +84,19 @@ status_t bpt_init(void); /* Boot protocol specific init funcs */ status_t bpt_init_limine(struct bpt_ops *ops); +/* + * Obtain the kernel load base from the bootloader + */ +__always_inline static inline uintptr_t +bpt_kload_base(void) +{ + struct bpt_protovar pv; + + if (bpt_get_protovar(&pv) != STATUS_SUCCESS) { + return 0; + } + + return pv.kload_base; +} + #endif /* !_OS_BPT_H_ */