aboutsummaryrefslogtreecommitdiff
path: root/riscv/cfg.cc
blob: ef1d5790a3ac5005ea023fa1b23fac44e9a8045c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// See LICENSE for license details.

#include "cfg.h"
#include "mmu.h"
#include "decode.h"

mem_cfg_t::mem_cfg_t(reg_t base, reg_t size) : base(base), size(size)
{
  assert(mem_cfg_t::check_if_supported(base, size));
}

bool mem_cfg_t::check_if_supported(reg_t base, reg_t size)
{
  // The truth of these conditions 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.
  return (size % PGSIZE == 0) &&
         (base % PGSIZE == 0) &&
         (base + size > base);
}