]> git.corax.cc Git - corax/commitdiff
Start implementation of facilities to support userspace processes
authorMatthias Kruk <m@m10k.eu>
Tue, 12 Nov 2019 09:06:54 +0000 (18:06 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 12 Nov 2019 09:06:54 +0000 (18:06 +0900)
 - Add crxstd.h header with prototypes for Corax-specific syscalls
 - Add dummy NET process
 - Add dummy STDIO process
 - Start NET and STDIO processes from process daemon

include/corax/ipc.h
include/crxstd.h [new file with mode: 0644]
kernel/core/Makefile
kernel/core/main.c
kernel/core/net.c [new file with mode: 0644]
kernel/core/stdio.c [new file with mode: 0644]

index 90b911f53460af98ebb91b061afa5055df2406ff..2c941a5229e0b9cb358217c6ffc0aa97f31bd1e7 100644 (file)
@@ -15,7 +15,8 @@ struct cxmsg {
 
 #define cm_data CM_dat.CM_data
 
-#define PID_INIT 1
-#define PID_UNIX 10
+#define PID_INIT  1
+#define PID_NET   10
+#define PID_STDIO 20
 
 #endif /* __CORAX_IPC_H */
diff --git a/include/crxstd.h b/include/crxstd.h
new file mode 100644 (file)
index 0000000..d2b1ef2
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __CRXSTD_H
+#define __CRXSTD_H
+
+#include <corax/types.h>
+#include <corax/ipc.h>
+
+extern int cxsend(pid_t, struct cxmsg*);
+extern int cxrecv(pid_t, struct cxmsg*);
+extern int cxsendrecv(pid_t, struct cxmsg*);
+
+#endif /* __CRXSTD_H */
index 298be61d60d2479d1a3bc836662764893f27b02f..ee28ac1ec78bde21bcaf542d7c2e9794a039ed74 100644 (file)
@@ -1,4 +1,4 @@
-OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o syscall.o posixcall.o
+OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o syscall.o posixcall.o net.o stdio.o
 OUTPUT = core.o
 INCLUDES = -I../include -I../../include -I../..
 CFLAGS += $(INCLUDES)
index 5de34d1bb0bdcf505ec044aae9b7efd2231d70f1..8ef85278488608bb3932bf9d1173ee255c75b4df 100644 (file)
@@ -28,9 +28,8 @@ void cpu_debug(void);
 int arch_init(void*);
 void sched_tick(void);
 
-pid_t fork(void);
-int cxsend(pid_t, struct cxmsg*);
-int cxrecv(pid_t, struct cxmsg*);
+extern void _stdio(void);
+extern void _net(void);
 
 void _print_mptbl(void *tbl)
 {
@@ -98,37 +97,31 @@ static void _idle(void)
 
 static void _init(void)
 {
-       /* FIXME: Spawn the idle process */
-       while(1);
-}
-
-static void _test(void)
-{
-       pid_t p;
-       pid_t self;
-       process_t *proc;
-
-       /* have to initialize C library */
+       process_t *stdio;
+       process_t *net;
+       int err;
 
-       p = fork();
+       /*
+        * instead of something like /sbin/init, this process will behave more like the process daemon
+        * found in the MINIX3 operating system. It will spawn the daemons necessary for basic system
+        * operation, and restart them in case they should die.
+        */
 
-       proc = process_get_current();
-       self = process_get_id(proc);
+       err = process_create(&stdio, PID_STDIO, 3, (void*)_stdio);
 
-       dbg_printf("[%02x] fork() = %02x\n", self, p);
+       if(err < 0) {
+               dbg_printf("Failed to start stdio process [err=0x%08x]\n", err);
+       }
 
-       for(;;) {
-               if(p == 0) {
-                       dbg_printf("c");
-               } else if(p > 0) {
-                       dbg_printf("p");
-               } else {
-                       dbg_printf("e");
-               }
+       err = process_create(&net, PID_NET, 3, (void*)_net);
 
-               asm volatile("hlt");
+       if(err < 0) {
+               dbg_printf("Failed to start NET process [err=0x%08x]\n", err);
        }
 
+       /* For now, only start them once */
+       _idle();
+
        return;
 }
 
@@ -214,7 +207,7 @@ int corax(void *mb_info, u32_t magic)
                PANIC("Could not spawn idle process\n");
        }
 
-       err = process_create(&proc, PID_INIT, 3, (void*)_init);
+       err = process_create(&proc, PID_ANY, 0, (void*)_init);
 
        if(err < 0) {
                PANIC("Could not spawn init process\n");
diff --git a/kernel/core/net.c b/kernel/core/net.c
new file mode 100644 (file)
index 0000000..bbcb3f4
--- /dev/null
@@ -0,0 +1,23 @@
+#include <config.h>
+#include <crxstd.h>
+#include <corax/errno.h>
+
+void _net(void)
+{
+       struct cxmsg msg;
+       int len;
+
+       while(1) {
+               len = cxrecv(PID_ANY, &msg);
+
+               if(len > 0) {
+                       /* FIXME: handle message */
+
+                       msg.cm_type = (u32_t)-ENOSYS;
+                       msg.cm_dst = msg.cm_src;
+                       cxsend(msg.cm_dst, &msg);
+               }
+       }
+
+       return;
+}
diff --git a/kernel/core/stdio.c b/kernel/core/stdio.c
new file mode 100644 (file)
index 0000000..fce868d
--- /dev/null
@@ -0,0 +1,23 @@
+#include <config.h>
+#include <crxstd.h>
+#include <corax/errno.h>
+
+void _stdio(void)
+{
+       struct cxmsg msg;
+       int err;
+
+       while(1) {
+               err = cxrecv(PID_ANY, &msg);
+
+               if(err > 0) {
+                       /* FIXME: Handle message */
+
+                       msg.cm_dst = msg.cm_src;
+                       msg.cm_type = -ENOSYS;
+                       cxsend(msg.cm_dst, &msg);
+               }
+       }
+
+       return;
+}