diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-01-10 17:45:09 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-01-10 17:45:09 +0200 |
| commit | a5cfead3bd0761ba22a07a4e168670dfb7c9fb84 (patch) | |
| tree | 8081f1ba46f93b6788b94c167e16cba700b9fbb1 | |
| parent | 23207f0393be1776fdcc224248b7e7d88c1bf622 (diff) | |
| download | kmi-a5cfead3bd0761ba22a07a4e168670dfb7c9fb84.tar.gz kmi-a5cfead3bd0761ba22a07a4e168670dfb7c9fb84.zip | |
some kmx alleviations
| -rw-r--r-- | arch/riscv64/kernel/proc.c | 17 | ||||
| -rw-r--r-- | arch/riscv64/kernel/vmem.c | 11 | ||||
| -rw-r--r-- | common/main.c | 3 | ||||
| -rw-r--r-- | common/string.c | 1 | ||||
| -rw-r--r-- | common/uapi/ipc.c | 2 | ||||
| -rw-r--r-- | include/arch/proc.h | 3 | ||||
| -rw-r--r-- | include/kmi/syscalls.h | 41 | ||||
| -rw-r--r-- | include/kmi/types.h | 6 | ||||
| -rw-r--r-- | include/kmi/uapi.h | 34 |
9 files changed, 70 insertions, 48 deletions
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c index a7721e2..4e4d7ec 100644 --- a/arch/riscv64/kernel/proc.c +++ b/arch/riscv64/kernel/proc.c @@ -15,9 +15,9 @@ #include "regs.h" #include "csr.h" -void run_init(struct tcb *t, void *fdt) +void run_init(struct tcb *t, void *fdt, void *initrd) { - /** \todo actually map fdt into the target address space */ + /** \todo actually map fdt and initrd into the target address space */ csr_write(CSR_SSCRATCH, t); csr_write(CSR_SEPC, t->exec); /* gcc gives a warning 'the value of the stack pointer after an asm @@ -27,10 +27,15 @@ void run_init(struct tcb *t, void *fdt) * Could be fixed with a separate pure asm run_init, but I guess this * works for now. */ - __asm__ volatile ("mv sp, %0\n" : : "r" (t->thread_stack_top) : "memory"); - __asm__ volatile ("mv a0, %0\n" : : "r" (t->tid) : "a0"); - __asm__ volatile ("mv a1, %0\n" : : "r" (fdt) : "a1"); - __asm__ volatile ("sret\n" ::: "memory"); + __asm__ volatile ("mv sp, %0\n" + "mv a0, %1\n" + "mv a1, %2\n" + "mv a2, %3\n" + "sret\n" + : + : "r" (t->thread_stack_top), "r" (t->tid), "r" (fdt), + "r" (initrd) + : "memory"); /* we should never reach this */ unreachable(); } diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c index 37b9040..bc984e4 100644 --- a/arch/riscv64/kernel/vmem.c +++ b/arch/riscv64/kernel/vmem.c @@ -493,12 +493,12 @@ void setup_rpc_stack(struct tcb *t) for (size_t i = 0; i < pages; ++i) { pm_t page = alloc_page(BASE_PAGE); map_vpage(t->rpc.vmem, page, - RPC_STACK_BASE + BASE_PAGE_SIZE * i, - flags, BASE_PAGE); + RPC_STACK_BASE + BASE_PAGE_SIZE * i, + flags, BASE_PAGE); map_vpage(t->proc.vmem, page, - RPC_STACK_BASE + BASE_PAGE_SIZE * i, - flags, BASE_PAGE); + RPC_STACK_BASE + BASE_PAGE_SIZE * i, + flags, BASE_PAGE); } /* we allocated a second order page for rpc stack usage */ @@ -506,7 +506,8 @@ void setup_rpc_stack(struct tcb *t) /* slightly hacky maybe but we know the first pte is at RPC_STACK_BASE, * which means that it must also be the leaf */ t->arch.rpc_leaf = (struct vmem *)__find_vmem(t->rpc.vmem, - RPC_STACK_BASE, BASE_PAGE); + RPC_STACK_BASE, + BASE_PAGE); /* 'reserve' top page of stack for kernel use */ t->arch.rpc_idx = 511; } diff --git a/common/main.c b/common/main.c index 7291387..478b2f5 100644 --- a/common/main.c +++ b/common/main.c @@ -57,5 +57,6 @@ void __main main(void *fdt, uintptr_t ram_base) smp_bringup(b, fdt); /* start running init program */ - run_init(cur_tcb(), fdt); + void *initrd = (void *)get_initrdbase(fdt); + run_init(cur_tcb(), fdt, initrd); } diff --git a/common/string.c b/common/string.c index 359a938..8c88e65 100644 --- a/common/string.c +++ b/common/string.c @@ -307,6 +307,7 @@ __weak void *memmove(void *dst, const void *src, size_t num) m1 += num; m2 += num; + /* doesn't really take into account aliasing yet */ while (num--) *(--m2) = *(--m1); diff --git a/common/uapi/ipc.c b/common/uapi/ipc.c index dc292ef..18c3b1a 100644 --- a/common/uapi/ipc.c +++ b/common/uapi/ipc.c @@ -79,7 +79,7 @@ static void finalize_rpc(struct tcb *t, struct tcb *r, vm_t s) * @return RPC stack difference that should be passed to finalize_rpc(). */ static vm_t enter_rpc(struct tcb *t, struct sys_ret a, - enum ipc_kind kind) + enum ipc_kind kind) { vm_t rpc_stack = rpc_position(t); diff --git a/include/arch/proc.h b/include/arch/proc.h index 341a2f4..345f812 100644 --- a/include/arch/proc.h +++ b/include/arch/proc.h @@ -112,8 +112,9 @@ void adjust_syscall(struct tcb *t); * * @param t Thread that \c init is attached to. * @param fdt Pointer to FDT that is passed to \c init. + * @param initrd Pointer to initrd that is passed to \c init. */ -__noreturn void run_init(struct tcb *t, void *fdt); +__noreturn void run_init(struct tcb *t, void *fdt, void *initrd); /** * Return to userspace fast. diff --git a/include/kmi/syscalls.h b/include/kmi/syscalls.h index 79cd692..1de4fb2 100644 --- a/include/kmi/syscalls.h +++ b/include/kmi/syscalls.h @@ -9,6 +9,13 @@ * Table of system calls. */ +/* pass VM_X etc. to userspace */ +#if defined(riscv64) +#include "../../arch/riscv64/include/vmem.h" +#elif defined(riscv32) +#include "../../arch/riscv32/include/vmem.h" +#endif + /** enum for now, possibly macros in the future once I get an approximate idea of * which syscalls are necessary etc. */ enum { @@ -146,4 +153,38 @@ enum { /* function declarations should be somewhere else, this file could be used in * userspace applications as well */ +/** + * Syscall argument type. + * + * \todo: Should this be arch specific? should be the size of an integer + * register. + */ +typedef long sys_arg_t; + +/** + * Return structure of syscall. + * \note Field names are generic, and can be used for whatever, + * check documentation of whatever you're doing. + * @todo should this be placed into syscalls.h? + */ +struct sys_ret { + /** Status. */ + sys_arg_t s; + + /** First argument. */ + sys_arg_t ar0; + + /** Second argument. */ + sys_arg_t ar1; + + /** Third argument. */ + sys_arg_t ar2; + + /** Fourth argument. */ + sys_arg_t ar3; + + /** Fifth argument. */ + sys_arg_t ar4; +}; + #endif /* KMI_SYSCALLS_H */ diff --git a/include/kmi/types.h b/include/kmi/types.h index 5d7225e..2443f89 100644 --- a/include/kmi/types.h +++ b/include/kmi/types.h @@ -127,6 +127,12 @@ typedef uint32_t size_t; typedef int32_t ssize_t; #endif +/** Maximum alignment. Works for most platforms, I think. */ +typedef union { + intmax_t ll; + long double ld; +} max_align_t; + /** Expands to integer constant of type \ref int8_t. */ #define INT8_C __INT8_C diff --git a/include/kmi/uapi.h b/include/kmi/uapi.h index 891b5f9..39ba79f 100644 --- a/include/kmi/uapi.h +++ b/include/kmi/uapi.h @@ -18,40 +18,6 @@ */ typedef void (*sys_t)(struct tcb *t, long, long, long, long, long); -/** - * Syscall argument type. - * - * \todo: Should this be arch specific? should be the size of an integer - * register. - */ -typedef long sys_arg_t; - -/** - * Return structure of syscall. - * \note Field names are generic, and can be used for whatever, - * check documentation of whatever you're doing. - * @todo should this be placed into syscalls.h? - */ -struct sys_ret { - /** Status. */ - sys_arg_t s; - - /** First argument. */ - sys_arg_t ar0; - - /** Second argument. */ - sys_arg_t ar1; - - /** Third argument. */ - sys_arg_t ar2; - - /** Fourth argument. */ - sys_arg_t ar3; - - /** Fifth argument. */ - sys_arg_t ar4; -}; - /** Helper for returning sys_ret with 0 arguments. */ #define SYS_RET0() (struct sys_ret){0, 0, 0, 0, 0, 0} |
