aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/init
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-09-11 21:50:55 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-09-14 21:21:27 +0300
commit025778e89e7d0fe3cd1ad53537c9cc6f3cd819cc (patch)
treea137a9f405578b41e092e13892516feccc4d71e6 /arch/riscv64/init
parent9e2720ca086a74cfb6fa595da8c42e6cd24352ee (diff)
downloadkmi-025778e89e7d0fe3cd1ad53537c9cc6f3cd819cc.tar.gz
kmi-025778e89e7d0fe3cd1ad53537c9cc6f3cd819cc.zip
riscv32 boots and advances as far as riscv64
Diffstat (limited to 'arch/riscv64/init')
-rw-r--r--arch/riscv64/init/init.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c
index 0ea1f37..0680296 100644
--- a/arch/riscv64/init/init.c
+++ b/arch/riscv64/init/init.c
@@ -42,31 +42,27 @@ static void init_bootmem()
* @todo Allocate root_branch statically? */
root_branch = (struct vmem *)align_up(top, SZ_4K);
-#if defined(riscv64)
- const size_t top_size = SZ_1G;
-#else
- const size_t top_size = SZ_4M;
-#endif
-
/* direct mapping (temp) */
for (size_t i = 0; i < CSTACK_PAGE; ++i)
- root_branch->leaf[i] = (struct vmem *)to_pte(top_size * i, flags);
+ root_branch->leaf[i] = (struct vmem *)to_pte(TOP_PAGE_SIZE * i, flags);
/* kernel (also sort of direct mapping) */
flags |= VM_G;
for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i)
root_branch->leaf[i] = (struct vmem *)to_pte(
- RAM_BASE + top_size * (i - KSTART_PAGE), flags);
+ RAM_BASE + TOP_PAGE_SIZE * (i - KSTART_PAGE), flags);
/* kernel IO, map to 0 for now, will be updated in the future */
root_branch->leaf[IO_PAGE] = (struct vmem *)to_pte(0, flags);
-#if defined(riscv64)
- const uintmax_t mode = SATP_MODE_Sv39;
-#else
- const uintmax_t mode = SATP_MODE_Sv32;
-#endif
- csr_write(CSR_SATP, SATP_MODE_Sv39 | ((uintptr_t)root_branch >> 12));
+ uintmax_t mode = Sv39;
+ switch (DEFAULT_Sv_MODE) {
+ case Sv32: mode = SATP_MODE_Sv32; break;
+ case Sv39: mode = SATP_MODE_Sv39; break;
+ case Sv48: mode = SATP_MODE_Sv48; break;
+ default: break;
+ };
+ csr_write(CSR_SATP, mode | ((uintptr_t)root_branch >> 12));
}
/** Relocate kernel proper. */