From 122374c362ba8bb9082385da3c82e264ab594f15 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 7 Jul 2024 07:00:43 +0300 Subject: smp now seems to work + Had some minor issues with a wraparound of size_t that effectively meant that some regions were allocated twice. Also, booting should be a bit more reliable now, turned out that the previous iteration of the booting was just accidentally working due to the kernel being placed 'close enough' in RAM to where it was linked to. Fixed by allocating a vmem of O1 that maps the kernel to a 2MiB boundary at boot, pretty nifty. --- arch/riscv64/conf/init.c | 60 ++++++++++++++++++++++++++--------------- arch/riscv64/conf/kernel-link.S | 2 +- 2 files changed, 40 insertions(+), 22 deletions(-) (limited to 'arch/riscv64/conf') diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c index 6b1ce46..c61848e 100644 --- a/arch/riscv64/conf/init.c +++ b/arch/riscv64/conf/init.c @@ -274,24 +274,9 @@ static void *sys_req_sharedmem(long tid, unsigned long size, void **cbuf) static char *rw_buf = 0; static size_t rw_buf_size = 4096; -void callback(long pid, long tid, long d0, long d1, long d2, long d3) +static void sys_sleep() { - (void)tid; - if (d0 == 1) { - void *cbuf = 0; - rw_buf = sys_req_sharedmem(pid, rw_buf_size, &cbuf); - sys_ipc_resp((long)cbuf, rw_buf_size, 0, 0); - __builtin_unreachable(); - - } else if (d0 == 2) { - puts("Received string: "); - puts(rw_buf); - sys_ipc_resp(0, 0, 0, 0); - __builtin_unreachable(); - } - - sys_ipc_resp(0, 0, 0, 0); - __builtin_unreachable(); + ecall1(SYS_SLEEP); } #define CSR_TIME "0xc01" @@ -300,8 +285,19 @@ void callback(long pid, long tid, long d0, long d1, long d2, long d3) #define CSR_CYCLE "0xc00" -void _start() +static void handle_kernel(long a0, long a1, long d0, long d1, long d2, long d3) { + if (a1 != SYS_USER_BOOTED) + return; + + long tid = d0; + if (tid != 1) { + puts("Woo, more cores!\n"); + while (1) + sys_sleep(); + } + + /* otherwise */ sys_noop(); puts("Hello, world!\n"); @@ -322,9 +318,6 @@ void _start() print_value("Syscalls per second", n); print_value("Executed cycles per second", cend - cstart); - puts("Setting callback..."); - sys_ipc_server(callback); - puts("Starting fork():\n"); long pid = sys_fork(); if (pid != 0) { @@ -387,3 +380,28 @@ void _start() sys_poweroff(0); } + +void _start(long a0, long a1, long d0, long d1, long d2, long d3) +{ + if (a0 == 0) + handle_kernel(a0, a1, d0, d1, d2, d3); + + /* otherwise, implement test functionality */ + long pid = a0; + long tid = a1; + if (d0 == 1) { + void *cbuf = 0; + rw_buf = sys_req_sharedmem(pid, rw_buf_size, &cbuf); + sys_ipc_resp((long)cbuf, rw_buf_size, 0, 0); + __builtin_unreachable(); + + } else if (d0 == 2) { + puts("Received string: "); + puts(rw_buf); + sys_ipc_resp(0, 0, 0, 0); + __builtin_unreachable(); + } + + sys_ipc_resp(0, 0, 0, 0); + __builtin_unreachable(); +} diff --git a/arch/riscv64/conf/kernel-link.S b/arch/riscv64/conf/kernel-link.S index 832a886..88f2e75 100644 --- a/arch/riscv64/conf/kernel-link.S +++ b/arch/riscv64/conf/kernel-link.S @@ -11,7 +11,7 @@ SECTIONS { * hack. * @todo look into this further. */ - . = VM_DMAP; + . = ABSOLUTE(VM_KERNEL); __kernel_start = .; .text ALIGN(4K) : AT(0) { *(.kernel.start); -- cgit v1.3