aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel/proc.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-29 17:38:41 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-29 17:38:41 +0300
commit9273c16434316a8ab60dc78ee65a03e68031203a (patch)
tree41754de4b7c459fc07e20189948c94a0e2cab966 /arch/riscv64/kernel/proc.c
parent105f3d0dab75f669d1fc404c06b73289b343591c (diff)
downloadkmi-9273c16434316a8ab60dc78ee65a03e68031203a.tar.gz
kmi-9273c16434316a8ab60dc78ee65a03e68031203a.zip
continue building base for irq handling
Diffstat (limited to 'arch/riscv64/kernel/proc.c')
-rw-r--r--arch/riscv64/kernel/proc.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index 66325ec..8653254 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -1,10 +1,12 @@
#include <apos/tcb.h>
#include <apos/elf.h>
+#include <regs.h>
#include <csr.h>
stat_t jump_to_userspace(struct tcb *t, int argc, char **argv)
{
csr_write(CSR_SEPC, t->entry);
+ csr_write(CSR_SSCRATCH, t);
__asm__ volatile("mv sp, %0\n" ::"r"(t->proc_stack_top) : "memory");
__asm__ volatile("sret\n" ::: "memory");
/* we should never reach this */
@@ -16,3 +18,18 @@ stat_t return_to_userspace(struct tcb *t)
/* lol */
return ERR_ADDR;
}
+
+stat_t prepare_thread(struct tcb *t)
+{
+ /* get location of registers in memory */
+ /* TODO: check alignment, should be fine but just to be sure */
+ struct riscv_regs *r = (struct riscv_regs *)t;
+ r--;
+
+ r->sp = (long)t->proc_stack_top;
+ r->tp = (long)t;
+
+ /* set entry point */
+ csr_write(CSR_SEPC, t->entry);
+ return OK;
+}