From 168b4ea6a568741e88156ed8f96b5df2765d9df7 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Mon, 11 Apr 2022 19:52:27 +0100 Subject: Split mem layout computation in spike.cc (#957) The motivation here is mostly to enable a refactoring where the memory layout (sans allocated memory) gets passed to DTS/DTB code before we ever allocate anything. But it turns out to make merge_overlapping_memory_regions a bit simpler, which is an added bonus. --- riscv/cfg.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'riscv/cfg.h') diff --git a/riscv/cfg.h b/riscv/cfg.h index f0dea9f..e844738 100644 --- a/riscv/cfg.h +++ b/riscv/cfg.h @@ -3,6 +3,8 @@ #define _RISCV_CFG_H #include "decode.h" +#include "mmu.h" +#include template class cfg_arg_t { @@ -25,17 +27,41 @@ private: bool was_set; }; +// Configuration that describes a memory region +class mem_cfg_t +{ +public: + mem_cfg_t(reg_t base, reg_t size) + : base(base), size(size) + { + // The truth of these assertions should be ensured by whatever is creating + // the regions in the first place, but we have them here to make sure that + // we can't end up describing memory regions that don't make sense. They + // ask that the page size is a multiple of the minimum page size, that the + // page is aligned to the minimum page size, that the page is non-empty and + // that the top address is still representable in a reg_t. + assert((size % PGSIZE == 0) && + (base % PGSIZE == 0) && + (base + size > base)); + } + + reg_t base; + reg_t size; +}; + class cfg_t { public: cfg_t(std::pair default_initrd_bounds, const char *default_bootargs, size_t default_nprocs, - const char *default_isa, const char *default_priv) + const char *default_isa, const char *default_priv, + const std::vector &default_mem_layout) : initrd_bounds(default_initrd_bounds), bootargs(default_bootargs), nprocs(default_nprocs), isa(default_isa), - priv(default_priv) + priv(default_priv), + mem_layout(default_mem_layout) {} cfg_arg_t> initrd_bounds; @@ -43,6 +69,7 @@ public: cfg_arg_t nprocs; cfg_arg_t isa; cfg_arg_t priv; + cfg_arg_t> mem_layout; }; #endif -- cgit v1.1