]> git.corax.cc Git - corax/commitdiff
Make kernel spawn the idle and init processes in main.c, perform any other testing...
authorMatthias Kruk <m@m10k.eu>
Tue, 12 Nov 2019 07:31:34 +0000 (16:31 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 12 Nov 2019 07:31:34 +0000 (16:31 +0900)
kernel/core/main.c

index 0b4270e920290a7d7738ceeed9c8dd10a9a6a977..5de34d1bb0bdcf505ec044aae9b7efd2231d70f1 100644 (file)
 void cpu_debug(void);
 int arch_init(void*);
 void sched_tick(void);
-/*
-int socket(int, int, int);
-int close(int);
-*/
 
+pid_t fork(void);
 int cxsend(pid_t, struct cxmsg*);
 int cxrecv(pid_t, struct cxmsg*);
 
@@ -85,40 +82,13 @@ void _print_mptbl(void *tbl)
        return;
 }
 
-static void _srv(void)
-{
-       while(1) {
-               struct cxmsg msg;
-
-               cxrecv(PID_ANY, &msg);
-
-               dbg_printf("MSG: [%u -> %u] %u\n", msg.cm_src, msg.cm_dst, msg.cm_type);
-       }
-
-       return;
-}
-
 static void _idle(void)
 {
-#if 0
-       int fd0;
-       int fd1;
-
-       fd0 = socket(PF_INET, SOCK_DGRAM, 0);
-
-       dbg_printf("socket(PF_INET, SOCK_DGRAM, 0) = 0x%08x\n", fd0);
-
-       fd1 = socket(PF_UNIX, SOCK_STREAM, 0);
-
-       dbg_printf("socket(PF_UNIX, SOCK_STREAM, 0) = 0x%08x\n", fd1);
-#endif
-
+       /*
+        * The idle process does nothing but set the CPU to the
+        * lowest pstate and wait for an interrupt.
+        */
        while(1) {
-/*             int fd;
-
-               fd = socket(PF_INET, SOCK_DGRAM, 0);
-               dbg_printf("socket(PF_INET, SOCK_DGRAM, 0) = 0x%08x\n", fd);
-*/
                cpu_set_pstate(1);
                asm volatile("hlt");
        }
@@ -126,50 +96,47 @@ static void _idle(void)
        return;
 }
 
-static void _busy(void)
+static void _init(void)
 {
-/*     int fd, fe;
+       /* FIXME: Spawn the idle process */
+       while(1);
+}
 
-       fd = socket(PF_INET, SOCK_DGRAM, 0);
-       fe = socket(PF_INET, SOCK_STREAM, 0);
-*/
-#if 0
-       if(fd >= 0) {
-               close(fd);
-       }
+static void _test(void)
+{
+       pid_t p;
+       pid_t self;
+       process_t *proc;
 
-       if(fe >= 0) {
-               close(fe);
-       }
-#endif
+       /* have to initialize C library */
 
-#if 0
-       int sock;
+       p = fork();
 
-       sock = socket(PF_INET, SOCK_SEQPACKET, 0);
+       proc = process_get_current();
+       self = process_get_id(proc);
 
-       if(sock < 0) {
-               //      dbg_printf("errno = %u\n", -sock);
-       }
+       dbg_printf("[%02x] fork() = %02x\n", self, p);
 
-       sock = close(sock);
+       for(;;) {
+               if(p == 0) {
+                       dbg_printf("c");
+               } else if(p > 0) {
+                       dbg_printf("p");
+               } else {
+                       dbg_printf("e");
+               }
 
-       if(sock < 0) {
-               // dbg_printf("errno = %u\n", -sock);
+               asm volatile("hlt");
        }
-#endif
-
-       struct cxmsg msg;
-
-       cxsend(101, &msg);
-
-       for(;;);
 
        return;
 }
 
 int corax(void *mb_info, u32_t magic)
 {
+       process_t *proc;
+       int err;
+
     dbg_printf("Corax 0.1 - As the Crow flies\n");
     dbg_printf("(C) 2019 Matthias Kruk <matt@corax.cc>\n");
     dbg_printf("Compiled on %s at %s\n", __DATE__, __TIME__);
@@ -196,7 +163,6 @@ int corax(void *mb_info, u32_t magic)
        }
        */
 
-
     arch_init(mb_info);
 #if 0
        {
@@ -242,28 +208,16 @@ int corax(void *mb_info, u32_t magic)
        }
 */
 
-       process_t *proc;
-       process_t *proc2;
-       process_t *proc3;
-       u32_t err;
-
-       /* enqueue a second process */
-       err = process_create(&proc, 0, (void*)_idle);
-
-       if(err < 0) {
-               dbg_printf("process_create() = 0x%x\n", err);
-       }
-
-       err = process_create(&proc2, 0, (void*)_srv);
+       err = process_create(&proc, PID_ANY, 0, (void*)_idle);
 
        if(err < 0) {
-               dbg_printf("process_create() = 0x%x\n", err);
+               PANIC("Could not spawn idle process\n");
        }
 
-       err = process_create(&proc3, 3, (void*)_busy);
+       err = process_create(&proc, PID_INIT, 3, (void*)_init);
 
        if(err < 0) {
-               dbg_printf("process_create() = 0x%x\n", err);
+               PANIC("Could not spawn init process\n");
        }
 
        sched_tick();