aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-10-29 21:17:31 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-10-29 21:17:31 +0200
commit5976ad390a15726c3ddfacf8c8b282c8350f9554 (patch)
tree24a55fcd7e6f28d048ac074da59f428b54a81cb0 /arch/riscv64
parent314bca3dc19a864c76153bfcd5a58be8c40000f9 (diff)
downloadkmi-5976ad390a15726c3ddfacf8c8b282c8350f9554.tar.gz
kmi-5976ad390a15726c3ddfacf8c8b282c8350f9554.zip
start moving towards threads always being in rpc
Diffstat (limited to 'arch/riscv64')
-rw-r--r--arch/riscv64/kernel/entry.S4
-rw-r--r--arch/riscv64/kernel/proc.c17
-rw-r--r--arch/riscv64/kernel/vmem.c11
3 files changed, 10 insertions, 22 deletions
diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S
index abf3cba..0bc999e 100644
--- a/arch/riscv64/kernel/entry.S
+++ b/arch/riscv64/kernel/entry.S
@@ -107,10 +107,8 @@ handle_exception:
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
+ call unhandled_panic
j _load_context
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index d3896c1..f012b20 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -42,15 +42,14 @@ void run_init(struct tcb *t, vm_t fdt, vm_t initrd)
{
csr_write(CSR_SSCRATCH, t);
csr_write(CSR_SEPC, t->callback);
- /* gcc gives a warning 'the value of the stack pointer after an asm
- * statement must be the same as it was before the statement', so this
- * is technically speaking undefined behavior, I think.
- *
- * Could be fixed with a separate pure asm run_init, but I guess this
- * works for now.
- */
- vm_t stack_top = t->thread_stack + t->thread_stack_size;
- info("jumping to %lx\n", (long)t->callback);
+
+ /* reference main virtual memory */
+ struct tcb *r = get_rproc(t);
+ clone_uvmem(r->proc.vmem, t->rpc.vmem);
+ flush_tlb_all();
+
+ vm_t stack_top = t->rpc_stack - BASE_PAGE_SIZE;
+ info("jumping to %lx with sp = %lx\n", (long)t->callback, stack_top);
bkl_unlock();
riscv_run_init(0, t->tid, SYS_USER_SPAWNED, fdt, initrd, 1, stack_top);
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 29ec3d5..cf1391e 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -538,7 +538,7 @@ vm_t setup_kernel_io(struct vmem *b, vm_t paddr)
}
#endif
-void clone_uvmem(struct vmem * restrict r, struct vmem * restrict b)
+void clone_uvmem(struct vmem *r, struct vmem *b)
{
size_t i = 0;
for (; i < CSTACK_PAGE; ++i) {
@@ -574,20 +574,11 @@ stat_t setup_rpc_stack(struct tcb *t)
if (!page)
return ERR_OOMEM;
- /* map both into rpc and proc spaces so we can write to the
- * current stack frame directly. Especially important when
- * returning from an rpc. Technically means that we could leak
- * memory if map_vpage() for proc.vmem allocates more and more
- * pages, but good enough for now. */
if (map_vpage(t->rpc.vmem, page,
RPC_STACK_BASE + BASE_PAGE_SIZE * i,
flags, BASE_PAGE))
return ERR_OOMEM;
- if (map_vpage(t->proc.vmem, page,
- RPC_STACK_BASE + BASE_PAGE_SIZE * i,
- flags, BASE_PAGE))
- return ERR_OOMEM;
}
/* we allocated a second order page for rpc stack usage */