aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-06 18:14:04 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-06 18:14:04 +0300
commit76517486919657ecadda9867125dc6730f29a5b7 (patch)
tree02d975db2b911ec7b92c4b1be7c5a2510b418ae1 /arch/riscv64/kernel
parent608f44306a6f0d5692f5c81bcbfe7a621ec254ba (diff)
downloadkmi-76517486919657ecadda9867125dc6730f29a5b7.tar.gz
kmi-76517486919657ecadda9867125dc6730f29a5b7.zip
pretty massive virtual memory rewrite
+ The system is now a bit simpler and hopefully easier to understand, while also extending the shared memory to be 1:N, where there is one owner who may become a zombie while waiting for the N to die.
Diffstat (limited to 'arch/riscv64/kernel')
-rw-r--r--arch/riscv64/kernel/entry.S7
-rw-r--r--arch/riscv64/kernel/proc.c2
-rw-r--r--arch/riscv64/kernel/vmem.c20
3 files changed, 21 insertions, 8 deletions
diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S
index 1680a35..e37d5cc 100644
--- a/arch/riscv64/kernel/entry.S
+++ b/arch/riscv64/kernel/entry.S
@@ -104,6 +104,13 @@ handle_exception:
save_regs
save_args
+ csrr a0, CSR_SEPC
+ csrr a1, CSR_STVAL
+ /* not really a kernel panic but used for now to signify that something
+ * happened in userspace that we can't deal with */
+ csrr a2, CSR_SCAUSE
+ call kernel_panic
+
j _load_context
handle_dispatch:
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index 0c43b3d..f1a62c4 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -83,7 +83,7 @@ vm_t get_stack(struct tcb *t)
return r->sp;
}
-void clone_regs(struct tcb *d, struct tcb *s)
+void copy_regs(struct tcb *d, struct tcb *s)
{
struct riscv_regs *rd = (struct riscv_regs *)(d->regs) - 1;
struct riscv_regs *rs = (struct riscv_regs *)(s->regs) - 1;
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 3f29446..f717771 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -236,6 +236,9 @@ stat_t stat_vpage(struct vmem *branch, vm_t vaddr, pm_t *paddr,
static struct vmem *__create_leaf()
{
pm_t new_leaf = alloc_page(MM_KPAGE);
+ if (!new_leaf)
+ return NULL;
+
memset((void *)new_leaf, 0, sizeof(struct vmem));
return (struct vmem *)to_pte((pm_t)__pa(new_leaf), VM_V);
}
@@ -293,8 +296,13 @@ stat_t map_vpage(struct vmem *branch, pm_t paddr, vm_t vaddr, vmflags_t flags,
while (top != order) {
size_t idx = vm_to_index(vaddr, top);
- if (__unused((pm_t)branch->leaf[idx]))
- branch->leaf[idx] = __create_leaf();
+ if (__unused((pm_t)branch->leaf[idx])) {
+ struct vmem *leaf = __create_leaf();
+ if (!leaf)
+ return ERR_OOMEM;
+
+ branch->leaf[idx] = leaf;
+ }
branch = (struct vmem *)pte_addr(branch->leaf[idx]);
top--;
@@ -438,16 +446,14 @@ struct vmem *create_vmem()
return b;
}
-stat_t use_vmem(struct vmem *b)
+void use_vmem(struct vmem *b)
{
__use_vmem(__pa(b), DEFAULT_Sv_MODE);
- return OK;
}
-stat_t destroy_vmem(struct vmem *b)
+void destroy_vmem(struct vmem *b)
{
__destroy_branch(b);
- return OK;
}
stat_t populate_kvmem(struct vmem *b)
@@ -541,7 +547,7 @@ void destroy_rpc_stack(struct tcb *t)
pm_t page = 0; enum mm_order order = BASE_PAGE;
stat_vpage(t->rpc.vmem, RPC_STACK_BASE + BASE_PAGE_SIZE * i,
&page, &order, NULL);
- free_page(page, order);
+ free_page(order, page);
}
}