From 27ffa747f36aee9c1d5bbc61395a078238366070 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 11 May 2023 22:55:31 +0300 Subject: arbitrary load address and RAM base detection + Both kind of go hand in hand, made sense to do both at the same time. Some parts feel slightly hacky, the loader works by placing everything on the stack and avoiding global values. Still, seems to work? --- include/kmi/mem.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/kmi/mem.h b/include/kmi/mem.h index a6c6bfa..f43ee08 100644 --- a/include/kmi/mem.h +++ b/include/kmi/mem.h @@ -92,7 +92,7 @@ * @param x Physical address. * @return Corresponding virtual address. */ -#define __va(x) (void *)(((uintptr_t)(x)) + VM_DMAP - RAM_BASE) +#define __va(x) (void *)(((uintptr_t)(x)) + VM_DMAP - get_ram_base()) /** * Convert virtual address to physical address in direct mapping. @@ -100,7 +100,7 @@ * @param x Virtual address. * @return Corresponding physical address. */ -#define __pa(x) (void *)(((uintptr_t)(x)) - VM_DMAP + RAM_BASE) +#define __pa(x) (void *)(((uintptr_t)(x)) - VM_DMAP + get_ram_base()) /** * Get page number of physical address. @@ -213,6 +213,22 @@ enum mm_order nearest_order(size_t size); */ void init_mem(size_t max_order, size_t shifts[10], size_t page_shift); +/** + * Set RAM base address for global access. + * For now supports only one RAM bank. + * + * @param base RAM base address. + */ +void set_ram_base(pm_t base); + +/** + * Get RAM base address. + * Very much assumes set_ram_base() has been called beforehand. + * + * @return RAM base address. + */ +pm_t get_ram_base(); + /** Base page size. */ #define BASE_PAGE_SIZE (order_size(BASE_PAGE)) -- cgit v1.3