From 2ba37a7fe433a9e5c549a1b87b658c1c3fb45345 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 6 Nov 2021 20:30:01 +0800 Subject: [PATCH] clarify a bit of rounding code in the create-image routine --- tools/src/bin/create-image.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/src/bin/create-image.rs b/tools/src/bin/create-image.rs index a25024672..0714d81d0 100644 --- a/tools/src/bin/create-image.rs +++ b/tools/src/bin/create-image.rs @@ -188,11 +188,18 @@ fn main() { // region is largely empty and we want to avoid allocating too much space. if region.name == "CSR" { const PAGE_SIZE: usize = 4096; + // round to the nearest page, then add one page as the last entry in the csr_top + // is an alloatable page, and not an end-stop. + let length = if csr_top - region.base & (PAGE_SIZE - 1) == 0 { + csr_top - region.base + } else { + ((csr_top - region.base) & !(PAGE_SIZE - 1)) + PAGE_SIZE + } + PAGE_SIZE; map.insert( region.name.to_lowercase(), tools::utils::CsrMemoryRegion { start: region.base.try_into().unwrap(), - length: (((csr_top - region.base) + PAGE_SIZE) & !(PAGE_SIZE - 1)) + length: length .try_into() .unwrap(), },