aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-11-12 16:41:36 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2022-11-12 16:41:36 +0200
commit41ead8de77963bae907375c1bb115dad3315f46b (patch)
tree4b364db137bd3bea69853f15329292af7662897d /arch/riscv64
parent1d37792fb7a47135f0e7b7fc245e83bb1d8fc496 (diff)
downloadkmi-41ead8de77963bae907375c1bb115dad3315f46b.tar.gz
kmi-41ead8de77963bae907375c1bb115dad3315f46b.zip
initial rpc implementations
Diffstat (limited to 'arch/riscv64')
-rwxr-xr-xarch/riscv64/conf/initbin2664 -> 3448 bytes
-rw-r--r--arch/riscv64/conf/init.c94
-rw-r--r--arch/riscv64/conf/initrdbin3072 -> 4096 bytes
-rw-r--r--arch/riscv64/config.h4
-rw-r--r--arch/riscv64/kernel/proc.c6
-rw-r--r--arch/riscv64/kernel/vmem.c2
6 files changed, 96 insertions, 10 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init
index 11d838c..7ab8388 100755
--- a/arch/riscv64/conf/init
+++ b/arch/riscv64/conf/init
Binary files differ
diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c
index 45274d9..01e219e 100644
--- a/arch/riscv64/conf/init.c
+++ b/arch/riscv64/conf/init.c
@@ -9,8 +9,13 @@
#include <stdint.h>
#include "../../../include/apos/syscalls.h"
-#define ecall() do { asm ("ecall" : : : "a0", "a1", "a2", "a3", "a4", "a5"); \
+#define ecall() do { asm volatile ("ecall" \
+ : \
+ : \
+ : "a0", "a1", "a2", "a3", "a4", "a5", \
+ "memory"); \
} while (0)
+
static void sys_noop()
{
long register a0 asm ("a0") = SYS_NOOP;
@@ -108,6 +113,60 @@ static uint64_t sys_swap(long tid)
return a0;
}
+static void sys_ipc_server(void *f)
+{
+ long register a0 asm ("a0") = SYS_IPC_SERVER;
+ long register a1 asm ("a1") = (long)f;
+ ecall();
+ if (a0 != 0)
+ print_value("ipc_server() failed with error ", a0);
+}
+
+static uint64_t sys_ipc_req(long tid, long *d0, long *d1, long *d2, long *d3)
+{
+ long register a0 asm ("a0") = SYS_IPC_REQ;
+ long register a1 asm ("a1") = tid;
+ long register a2 asm ("a2") = *d0;
+ long register a3 asm ("a3") = *d1;
+ long register a4 asm ("a4") = *d2;
+ long register a5 asm ("a5") = *d3;
+ ecall();
+ if (a0)
+ print_value("ipc_req() failed with error ", a0);
+
+ *d0 = a2;
+ *d1 = a3;
+ *d2 = a4;
+ *d3 = a5;
+ return a0;
+}
+
+static void sys_ipc_resp(long d0, long d1, long d2, long d3)
+{
+ long register a0 asm ("a0") = SYS_IPC_RESP;
+ long register a1 asm ("a1") = d0;
+ long register a2 asm ("a2") = d1;
+ long register a3 asm ("a3") = d2;
+ long register a4 asm ("a4") = d3;
+ ecall();
+}
+
+static void sys_poweroff(long type)
+{
+ long register a0 asm ("a0") = SYS_POWEROFF;
+ long register a1 asm ("a1") = type;
+ ecall();
+}
+
+void callback(long status, long tid, long d0, long d1, long d2, long d3)
+{
+ sys_ipc_resp(d0, d1, d2, d3);
+}
+
+#define CSR_TIME "0xc01"
+#define csr_read(csr, \
+ res) __asm__ volatile ("csrr %0, " csr : "=r" (res) :: "memory")
+
void _start()
{
sys_noop();
@@ -128,20 +187,41 @@ void _start()
print_value("End ticks", i);
print_value("Syscalls per second", n);
+ puts("Setting callback...");
+ sys_ipc_server(callback);
+
puts("Starting fork():\n");
long pid = sys_fork();
if (pid != 0) {
- print_value("Child pid: ", pid);
+ print_value("Child pid", pid);
puts("Swapping to child...\n");
while(1) sys_swap(pid);
}
puts("Hello from child!\n");
- puts("Doing 1M swaps...\n");
- start = sys_ticks();
- for (long i = 0; i < 1000000; ++i)
+ puts("Doing swaps...\n");
+ csr_read(CSR_TIME, i);
+ start = i; n = 0;
+ while (i < start + second) {
sys_swap(1);
- uint64_t ticks = sys_ticks() - start;
- print_value("1M swaps took ", ticks / second);
+ csr_read(CSR_TIME, i);
+ n++;
+ }
+
+ print_value("Swaps (both ways) per second", n);
+
+ puts("Doing ipc requests...\n");
+ long d0, d1, d2, d3;
+ csr_read(CSR_TIME, i);
+ start = i; n = 0;
+ while (i < start + second) {
+ sys_ipc_req(1, &d0, &d1, &d2, &d3);
+ csr_read(CSR_TIME, i);
+ n++;
+ }
+
+ print_value("IPC requests per second", n);
+
+ sys_poweroff(0);
}
diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd
index 5c0c9bb..492b80c 100644
--- a/arch/riscv64/conf/initrd
+++ b/arch/riscv64/conf/initrd
Binary files differ
diff --git a/arch/riscv64/config.h b/arch/riscv64/config.h
index 2c3dce6..857f885 100644
--- a/arch/riscv64/config.h
+++ b/arch/riscv64/config.h
@@ -77,10 +77,10 @@
#define UVMEM_END (SZ_256G - SZ_1G)
/** RPC stack top. */
-#define RPC_STACK_TOP (UVMEM_END)
+#define RPC_STACK_TOP (UVMEM_END + SZ_1G)
/** RPC stack base. */
-#define RPC_STACK_BASE (RPC_STACK_TOP - SZ_1G)
+#define RPC_STACK_BASE (UVMEM_END)
/**
* Size of the default top page.
diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c
index 2ccc5bc..3c2ea59 100644
--- a/arch/riscv64/kernel/proc.c
+++ b/arch/riscv64/kernel/proc.c
@@ -56,6 +56,12 @@ void set_thread(struct tcb *t)
r->tp = (long)t->thread_storage;
}
+vm_t get_stack(struct tcb *t)
+{
+ struct riscv_regs *r = (struct riscv_regs *)(t) - 1;
+ return r->sp;
+}
+
void save_regs(struct tcb *t, void *p)
{
struct riscv_regs *r = (struct riscv_regs *)(t) - 1;
diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c
index 8954ee3..d12015c 100644
--- a/arch/riscv64/kernel/vmem.c
+++ b/arch/riscv64/kernel/vmem.c
@@ -316,7 +316,7 @@ vm_t setup_kernel_io(struct vmem *b, vm_t paddr)
stat_t clone_uvmem(struct vmem *r, struct vmem *b)
{
/** \todo error checking? */
- for (size_t i = 0; i <= CSTACK_PAGE; ++i)
+ for (size_t i = 0; i < CSTACK_PAGE; ++i)
b->leaf[i] = r->leaf[i];
return OK;