aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv/kernel
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2021-12-26 17:50:11 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2021-12-26 17:50:11 +0200
commitd98ec57128628b81fcd32269a92742a037b7f713 (patch)
tree0e3f8d78d8347ef0a6e69d41b9d9be20c822b642 /arch/riscv/kernel
parenta64f3588ff5da7f148659ccb0eff844ccfb57088 (diff)
downloadkmi-d98ec57128628b81fcd32269a92742a037b7f713.tar.gz
kmi-d98ec57128628b81fcd32269a92742a037b7f713.zip
First useful jump to userspace!
Diffstat (limited to 'arch/riscv/kernel')
-rw-r--r--arch/riscv/kernel/main.c11
-rw-r--r--arch/riscv/kernel/proc.c4
-rw-r--r--arch/riscv/kernel/vmem.c5
3 files changed, 10 insertions, 10 deletions
diff --git a/arch/riscv/kernel/main.c b/arch/riscv/kernel/main.c
index 914dcba..1964514 100644
--- a/arch/riscv/kernel/main.c
+++ b/arch/riscv/kernel/main.c
@@ -252,17 +252,13 @@ static void init_proc(void *fdt, struct vm_branch_t *b)
/* binary itself */
size_t sz = get_init_size(fdt);
- /* these need to be fixed and actually map the addresses that the ELF
- * binary wants, instead of willy nilly */
- t->bin = alloc_uvmem(t, sz, VM_V | VM_X | VM_R | VM_W | VM_U);
- /* stack */
+ /* stack (?) */
t->stack = alloc_uvmem(t, SZ_2M, VM_V | VM_R | VM_W | VM_U);
/* should probably wrap this in like tlb_flush_all() or something */
__asm__ ("sfence.vma" : : : "memory");
- move_init(fdt, (void *)t->bin);
- jump_to_userspace(t, 0, 0);
+ jump_to_userspace(t, get_init_base(fdt), 0, 0);
}
#define __va_reg(reg)\
@@ -292,6 +288,9 @@ void __main main(void *fdt)
/* allow supervisor code to touch user data */
csr_set(CSR_SSTATUS, SSTATUS_SUM);
+ /* maybe this is too early but mark that we want to jump to user mode
+ * eventually*/
+ csr_clear(CSR_SSTATUS, SSTATUS_SPP);
struct vm_branch_t *b = init_vmem(fdt);
init_mem_blocks();
init_irq(fdt);
diff --git a/arch/riscv/kernel/proc.c b/arch/riscv/kernel/proc.c
index 3a39dd3..6d351bc 100644
--- a/arch/riscv/kernel/proc.c
+++ b/arch/riscv/kernel/proc.c
@@ -2,9 +2,9 @@
#include <apos/elf.h>
#include <csr.h>
-void jump_to_userspace(struct tcb *t, char **argv, int argc)
+void jump_to_userspace(struct tcb *t, vm_t bin, int argc, char **argv)
{
- csr_write(CSR_SEPC, bin_entry(t->bin));
+ csr_write(CSR_SEPC, prepare_proc(t, bin));
__asm__("mv sp, %0\n" : "=r" (t->stack) :: "memory");
__asm__("sret\n" ::: "memory");
}
diff --git a/arch/riscv/kernel/vmem.c b/arch/riscv/kernel/vmem.c
index bf49716..e3680b3 100644
--- a/arch/riscv/kernel/vmem.c
+++ b/arch/riscv/kernel/vmem.c
@@ -19,7 +19,8 @@
static pm_t *__find_vmem(struct vm_branch_t *b, vm_t v, enum mm_order_t *o)
{
enum mm_order_t top = __mm_max_order;
- *o = MM_O0;
+ if(o)
+ *o = MM_O0;
do {
size_t idx = vm_to_index(v, top);
pm_t pte = (pm_t)b->leaf[idx];
@@ -59,7 +60,7 @@ int stat_vmem(struct vm_branch_t *branch, vm_t vaddr, pm_t *paddr,
pm_t *pte = __find_vmem(branch, vaddr, order);
if(pte){
if(paddr)
- *paddr = pte_paddr(*pte);
+ *paddr = (pm_t)pte_addr(*pte);
if(flags)
*flags = pte_flags(*pte);