aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/kernel/proc.c
blob: 86532544beb2d97a0e76ecb54921d02b369e3c3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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 */
	return ERR_ADDR;
}

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;
}