aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv64/conf/init.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 07:00:43 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 07:00:43 +0300
commit122374c362ba8bb9082385da3c82e264ab594f15 (patch)
tree0123fad5464aaf64f522d48f5069b35b90207aae /arch/riscv64/conf/init.c
parent03e12129927b0deba537a11bb5575bef93c57d0f (diff)
downloadkmi-122374c362ba8bb9082385da3c82e264ab594f15.tar.gz
kmi-122374c362ba8bb9082385da3c82e264ab594f15.zip
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.
Diffstat (limited to 'arch/riscv64/conf/init.c')
-rw-r--r--arch/riscv64/conf/init.c60
1 files changed, 39 insertions, 21 deletions
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();
+}