aboutsummaryrefslogtreecommitdiff
path: root/memory.h
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-28 21:54:42 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-28 21:54:42 +0100
commit700f4c412d42c9b9811269045c0e363a0331bba9 (patch)
tree260feed1ca657843d993c1ae73e93f25a17cede1 /memory.h
parent80c9af17330ac442a4c3d6d55b4041cbe923e9b4 (diff)
downloadrpi-MMU-example-700f4c412d42c9b9811269045c0e363a0331bba9.tar.gz
rpi-MMU-example-700f4c412d42c9b9811269045c0e363a0331bba9.zip
split kernel into 2 stages; second stage gets copied to 0x0 and runs from there
Diffstat (limited to 'memory.h')
-rw-r--r--memory.h43
1 files changed, 29 insertions, 14 deletions
diff --git a/memory.h b/memory.h
index e4493e2..adc3bc0 100644
--- a/memory.h
+++ b/memory.h
@@ -1,7 +1,10 @@
#ifndef MEMORY_H
#define MEMORY_H
-#define POWER_OF_2(EXP) (((uint32_t) 1) << EXP)
+// These macros were heavily used b4 I moved all the address
+// computation to the linker script. Now I'm just keeping them
+// in case they're needed for something else :)
+#define POWER_OF_2(EXP) (((size_t) 1) << EXP)
#define ALIGN_POWER_OF_2(ADDR, EXP) \
(((ADDR - 1) & ~(POWER_OF_2(EXP) - 1)) + POWER_OF_2(EXP))
@@ -10,33 +13,45 @@
#define ALIGN_SECTION(ADDR) ALIGN_POWER_OF_2(ADDR, 20)
-#define INTERRUPT_VECTOR_TABLE_START ((uint32_t) 0x0)
-#define STACK_START ((uint32_t) 0x4000)
-#define STACK_END ((uint32_t) 0x8000)
+// memory layout
+
+#define INTERRUPT_VECTOR_TABLE_START ((uint32_t) 0x0)
+// all those symbols are defined in the linker script
extern const char __end;
extern const char __start;
+extern const char _translation_table_start;
+extern const char _translation_table_end;
+extern const char _stack_start;
+extern const char _stack_top;
+extern const char _unprivileged_memory_start;
+extern const char _unprivileged_memory_end;
-#define KERNEL_START ((uint32_t) &__start) // this is 0x8000
-#define KERNEL_END ((uint32_t) &__end)
+#define KERNEL_START ((size_t) &__start) // this is 0x0
+#define KERNEL_END ((size_t) &__end)
// first 2^14 aligned address after the kernel
-#define TRANSLATION_TABLE_BASE ALIGN_POWER_OF_2(KERNEL_END, 14)
-
-#define TRANSLATION_TABLE_END \
- (TRANSLATION_TABLE_BASE + (uint32_t) (4096 * 4))
+#define TRANSLATION_TABLE_BASE ((size_t) &_translation_table_start)
+#define TRANSLATION_TABLE_END ((size_t) &_translation_table_end)
-#define PRIVILEGED_MEMORY_END ALIGN_SECTION(TRANSLATION_TABLE_END)
+// first section after the translation table is left unused;
+// the next section is used as the stack
+#define STACK_START ((size_t) &_stack_start)
+#define STACK_END ((size_t) &_stack_top)
-#define UNPRIVILEGED_MEMORY_START PRIVILEGED_MEMORY_END
+#define PRIVILEGED_MEMORY_END STACK_END
+#define UNPRIVILEGED_MEMORY_START \
+ ((size_t) &_unprivileged_memory_start) // equal to STACK_END
#define UNPRIVILEGED_MEMORY_END \
- (UNPRIVILEGED_MEMORY_START + SECTION_SIZE)
+ ((size_t) &_unprivileged_memory_end)
-#define PL0_SECTION_NUMBER ((uint32_t) 0b101010101010)
+#define PL0_SECTION_NUMBER ((size_t) 0xaaa)
#define VIRTUAL_PL0_MEMORY_START (PL0_SECTION_NUMBER << 20)
+#define VIRTUAL_PL0_MEMORY_END \
+ (VIRTUAL_PL0_MEMORY_START + SECTION_SIZE)
#endif // MEMORY_H