aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv
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
parenta64f3588ff5da7f148659ccb0eff844ccfb57088 (diff)
downloadkmi-d98ec57128628b81fcd32269a92742a037b7f713.tar.gz
kmi-d98ec57128628b81fcd32269a92742a037b7f713.zip
First useful jump to userspace!
Diffstat (limited to 'arch/riscv')
-rwxr-xr-xarch/riscv/conf/initbin1032 -> 1040 bytes
-rw-r--r--arch/riscv/conf/initrdbin1536 -> 1536 bytes
-rw-r--r--arch/riscv/conf/s.S5
-rw-r--r--arch/riscv/include/csr.h1
-rw-r--r--arch/riscv/kernel/main.c11
-rw-r--r--arch/riscv/kernel/proc.c4
-rw-r--r--arch/riscv/kernel/vmem.c5
7 files changed, 15 insertions, 11 deletions
diff --git a/arch/riscv/conf/init b/arch/riscv/conf/init
index 06e61e0..43a179c 100755
--- a/arch/riscv/conf/init
+++ b/arch/riscv/conf/init
Binary files differ
diff --git a/arch/riscv/conf/initrd b/arch/riscv/conf/initrd
index 8dc931b..e3704f2 100644
--- a/arch/riscv/conf/initrd
+++ b/arch/riscv/conf/initrd
Binary files differ
diff --git a/arch/riscv/conf/s.S b/arch/riscv/conf/s.S
index 7b796ce..e6997ac 100644
--- a/arch/riscv/conf/s.S
+++ b/arch/riscv/conf/s.S
@@ -1,4 +1,7 @@
.text
.global _start
_start:
-loop: j loop
+li a1, 1
+loop:
+add a0, a0, a1
+jal loop
diff --git a/arch/riscv/include/csr.h b/arch/riscv/include/csr.h
index bd02b04..b309f0b 100644
--- a/arch/riscv/include/csr.h
+++ b/arch/riscv/include/csr.h
@@ -39,6 +39,7 @@
/* status CSR bits */
#define SSTATUS_SUM (1 << 18)
+#define SSTATUS_SPP (1 << 8)
/* directly lifted from Linux:/arch/riscv/include/asm/asm.h:9-13 */
#ifdef __ASSEMBLY__
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);