aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/riscv64')
-rw-r--r--arch/riscv64/conf/kmi.its4
-rw-r--r--arch/riscv64/include/mem.h15
-rw-r--r--arch/riscv64/include/pmem.h4
-rw-r--r--arch/riscv64/kernel/arch.c7
-rw-r--r--arch/riscv64/kernel/proc.c8
-rw-r--r--arch/riscv64/kernel/vmem.c13
6 files changed, 41 insertions, 10 deletions
diff --git a/arch/riscv64/conf/kmi.its b/arch/riscv64/conf/kmi.its
index 768f98b..be49033 100644
--- a/arch/riscv64/conf/kmi.its
+++ b/arch/riscv64/conf/kmi.its
@@ -12,8 +12,8 @@
arch = "riscv";
os = "kmi";
compression = "none";
- load = <0x80260000>;
- entry = <0x80260000>;
+ load = <0x80200000>;
+ entry = <0x80200000>;
hash-1 {
algo = "sha1";
};
diff --git a/arch/riscv64/include/mem.h b/arch/riscv64/include/mem.h
new file mode 100644
index 0000000..410a428
--- /dev/null
+++ b/arch/riscv64/include/mem.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: copyleft-next-0.3.1 */
+/* Copyright 2021 - 2022, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */
+
+#ifndef KMI_RISCV_MEM_H
+#define KMI_RISCV_MEM_H
+/**
+ * @file pmem.h
+ * riscv64-specific general memory stuff.
+ */
+
+/** Base page size is always 4K, use a constant for better optimizations here
+ * and there */
+#define BASE_PAGE_SIZE 4096
+
+#endif /* KMI_RISCV_MEM_H */
diff --git a/arch/riscv64/include/pmem.h b/arch/riscv64/include/pmem.h
index 7101757..071c3b5 100644
--- a/arch/riscv64/include/pmem.h
+++ b/arch/riscv64/include/pmem.h
@@ -5,7 +5,7 @@
#define KMI_RISCV_PMEM_H
/**
* @file pmem.h
- * riscv64-specific physical memory, currently empty but kept around for
- * forwards compatibility.
+ * riscv64-specific physical memory stuff.
*/
+
#endif /* KMI_RISCV_PMEM_H */
diff --git a/arch/riscv64/kernel/arch.c b/arch/riscv64/kernel/arch.c
index ec4cf43..4561d8b 100644
--- a/arch/riscv64/kernel/arch.c
+++ b/arch/riscv64/kernel/arch.c
@@ -8,6 +8,8 @@
#include <kmi/assert.h>
#include <kmi/debug.h>
+#include <kmi/power.h>
+#include <kmi/bkl.h>
#include "csr.h"
#include "arch.h"
@@ -19,8 +21,11 @@ id_t hartid_to_cpuid(id_t hart)
if (cpuid_to_hartid(i) == hart)
return i;
+ /* put extra cores to sleep so they don't do anything bad */
error("failed to match hart id %ld to cpu id\n", (long)hart);
- /* default to zero, though this should maybe be a panic? */
+ bkl_unlock();
+ sleep();
+ /* should never really be reached but eh */
return 0;
}
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index af4b2f3..4310378 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -33,13 +33,13 @@ void run_init(struct tcb *t, vm_t fdt, vm_t initrd)
"li a0, %1\n"
"li a1, %2\n"
"mv a2, %3\n"
- "mv a3, %4\n"
- "mv a4, %5\n"
+ "mv a3, %4\n"
+ "mv a4, %5\n"
"sret\n"
:
: "r" (stack_top),
- "K"(0), "K"(SYS_USER_BOOTED),
- "r" (t->tid), "r" (fdt), "r" (initrd)
+ "K" (0), "K" (SYS_USER_BOOTED),
+ "r" (t->tid), "r" (fdt), "r" (initrd)
: "memory");
/* we should never reach this */
unreachable();
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 0aa35cc..cb1eba0 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -420,11 +420,15 @@ __aligned(4096) struct vmem bootvmem;
* it. */
__aligned(4096) struct vmem kvmem;
+/* adding a third page entry would let us map the kernel at any 4KiB boundary
+ * but eh, Linux seems fine with 2MiB so I guess I shall be as well. */
+
struct vmem *init_mapping()
{
rpc_pages = order_size(MM_O1) / BASE_PAGE_SIZE;
kvmem.leaf[0] = (struct vmem *)to_pte(get_load_addr(),
- VM_A | VM_G | VM_D | VM_R | VM_W | VM_X | VM_V);
+ VM_A | VM_G | VM_D | VM_R | VM_W |
+ VM_X | VM_V);
__populate_dmap(&bootvmem);
populate_kvmem(&bootvmem);
@@ -462,6 +466,13 @@ void destroy_vmem(struct vmem *b)
__destroy_branch(b);
}
+/**
+ * Helper for mapping in the kernel virtual page.
+ * Remember that the kernel lives on its own in a 2MiB (riscv64) region at
+ * VM_KERNEL, and \ref __va() and \ref __pa() won't directly work on it.
+ *
+ * @param b Branch to map kernel into.
+ */
static void map_kernel(struct vmem *b)
{
/* slightly worried about this not being guaranteed to be pc relative,