From 9edd65c48ee75751327c6ee6d42a7009e726d667 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 10 Nov 2022 15:14:10 +0200 Subject: initial implementation of process copying + Not actually working (at least fully), need to continue debugging when I have time. --- arch/riscv64/conf/init | Bin 2144 -> 2560 bytes arch/riscv64/conf/init.c | 32 ++++++++++++++++++++++++++++++++ arch/riscv64/conf/initrd | Bin 2560 -> 3072 bytes 3 files changed, 32 insertions(+) (limited to 'arch/riscv64') diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init index b75076f..47e733f 100755 Binary files a/arch/riscv64/conf/init and b/arch/riscv64/conf/init differ diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c index feb5177..1886760 100644 --- a/arch/riscv64/conf/init.c +++ b/arch/riscv64/conf/init.c @@ -88,6 +88,26 @@ static void print_value(const char *s, uint64_t v) sys_putch('\n'); } +static uint64_t sys_fork() +{ + long register a0 asm ("a0") = SYS_FORK; + long register a1 asm ("a1") = 0; + ecall(); + if (a0 != 0) + print_value("fork() failed with error ", a0); + return a1; +} + +static uint64_t sys_swap(long tid) +{ + long register a0 asm ("a0") = SYS_SWAP; + long register a1 asm ("a1") = tid; + ecall(); + if (a0 != 0) + print_value("swap() failed with error ", a0); + return a0; +} + void _start() { sys_noop(); @@ -107,4 +127,16 @@ void _start() print_value("End ticks", i); print_value("Syscalls per second", n); + + puts("Starting fork():\n"); + long pid = sys_fork(); + if (pid != 0) { + print_value("Child pid: ", pid); + puts("Swapping to child...\n"); + sys_swap(pid); + puts("We shouldn't be here?\n"); + while(1); + } + + puts("Hello from child!\n"); } diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd index 3af4d2e..24f9fb4 100644 Binary files a/arch/riscv64/conf/initrd and b/arch/riscv64/conf/initrd differ -- cgit v1.3