diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-10 15:14:10 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-11-10 15:14:10 +0200 |
| commit | 9edd65c48ee75751327c6ee6d42a7009e726d667 (patch) | |
| tree | eb46862f518b70c059c6dc36968f7a2ddc373966 /arch | |
| parent | 87a6be8bc3404abea2af788c46cf450dc8bb6204 (diff) | |
| download | kmi-9edd65c48ee75751327c6ee6d42a7009e726d667.tar.gz kmi-9edd65c48ee75751327c6ee6d42a7009e726d667.zip | |
initial implementation of process copying
+ Not actually working (at least fully), need to continue debugging when
I have time.
Diffstat (limited to 'arch')
| -rwxr-xr-x | arch/riscv64/conf/init | bin | 2144 -> 2560 bytes | |||
| -rw-r--r-- | arch/riscv64/conf/init.c | 32 | ||||
| -rw-r--r-- | arch/riscv64/conf/initrd | bin | 2560 -> 3072 bytes |
3 files changed, 32 insertions, 0 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init Binary files differindex b75076f..47e733f 100755 --- a/arch/riscv64/conf/init +++ b/arch/riscv64/conf/init 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 Binary files differindex 3af4d2e..24f9fb4 100644 --- a/arch/riscv64/conf/initrd +++ b/arch/riscv64/conf/initrd |
