aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-28 16:46:08 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-28 16:46:08 +0100
commitdea4cc9a00cd98f2749e9b658589a03addc6143b (patch)
treea4067d891f6d6f71249fd0c7b9d5a341190e5fd1
parentc374eaacbc0d16983bbd1112fefa74dbe88e1e53 (diff)
downloadrpi-MMU-example-dea4cc9a00cd98f2749e9b658589a03addc6143b.tar.gz
rpi-MMU-example-dea4cc9a00cd98f2749e9b658589a03addc6143b.zip
clean-up memory.h
-rw-r--r--memory.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/memory.h b/memory.h
index d369694..e4493e2 100644
--- a/memory.h
+++ b/memory.h
@@ -1,9 +1,14 @@
#ifndef MEMORY_H
#define MEMORY_H
-#include "paging.h"
+#define POWER_OF_2(EXP) (((uint32_t) 1) << EXP)
-#define SECTION_SIZE (((uint32_t) 1) << 20)
+#define ALIGN_POWER_OF_2(ADDR, EXP) \
+ (((ADDR - 1) & ~(POWER_OF_2(EXP) - 1)) + POWER_OF_2(EXP))
+
+#define SECTION_SIZE POWER_OF_2(20)
+
+#define ALIGN_SECTION(ADDR) ALIGN_POWER_OF_2(ADDR, 20)
#define INTERRUPT_VECTOR_TABLE_START ((uint32_t) 0x0)
@@ -13,26 +18,23 @@
extern const char __end;
extern const char __start;
-#define KERNEL_START ((uint32_t) &__start)
+#define KERNEL_START ((uint32_t) &__start) // this is 0x8000
#define KERNEL_END ((uint32_t) &__end)
// first 2^14 aligned address after the kernel
-#define TRANSLATION_TABLE_BASE \
- (((KERNEL_END - (uint32_t) 1) & ~((uint32_t) 0x3fff)) \
- + (uint32_t) 0x4000)
+#define TRANSLATION_TABLE_BASE ALIGN_POWER_OF_2(KERNEL_END, 14)
#define TRANSLATION_TABLE_END \
(TRANSLATION_TABLE_BASE + (uint32_t) (4096 * 4))
-#define PRIVILEGED_MEMORY_END \
- (((TRANSLATION_TABLE_END - (uint32_t) 1) & ~((uint32_t) 0xfffff)) \
- + SECTION_SIZE)
+#define PRIVILEGED_MEMORY_END ALIGN_SECTION(TRANSLATION_TABLE_END)
#define UNPRIVILEGED_MEMORY_START PRIVILEGED_MEMORY_END
+
#define UNPRIVILEGED_MEMORY_END \
(UNPRIVILEGED_MEMORY_START + SECTION_SIZE)
-#define PL0_SECTION_NUMBER ((uint32_t) 0b101010101010)
+#define PL0_SECTION_NUMBER ((uint32_t) 0b101010101010)
#define VIRTUAL_PL0_MEMORY_START (PL0_SECTION_NUMBER << 20)