From af767bfdffb4baffe3240088be912946ea4e92ed Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 12 Nov 2019 18:06:54 +0900 Subject: [PATCH] Start implementation of facilities to support userspace processes - 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 | 5 +++-- include/crxstd.h | 11 ++++++++++ kernel/core/Makefile | 2 +- kernel/core/main.c | 49 +++++++++++++++++++------------------------- kernel/core/net.c | 23 +++++++++++++++++++++ kernel/core/stdio.c | 23 +++++++++++++++++++++ 6 files changed, 82 insertions(+), 31 deletions(-) create mode 100644 include/crxstd.h create mode 100644 kernel/core/net.c create mode 100644 kernel/core/stdio.c diff --git a/include/corax/ipc.h b/include/corax/ipc.h index 90b911f..2c941a5 100644 --- a/include/corax/ipc.h +++ b/include/corax/ipc.h @@ -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 index 0000000..d2b1ef2 --- /dev/null +++ b/include/crxstd.h @@ -0,0 +1,11 @@ +#ifndef __CRXSTD_H +#define __CRXSTD_H + +#include +#include + +extern int cxsend(pid_t, struct cxmsg*); +extern int cxrecv(pid_t, struct cxmsg*); +extern int cxsendrecv(pid_t, struct cxmsg*); + +#endif /* __CRXSTD_H */ diff --git a/kernel/core/Makefile b/kernel/core/Makefile index 298be61..ee28ac1 100644 --- a/kernel/core/Makefile +++ b/kernel/core/Makefile @@ -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) diff --git a/kernel/core/main.c b/kernel/core/main.c index 5de34d1..8ef8527 100644 --- a/kernel/core/main.c +++ b/kernel/core/main.c @@ -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 index 0000000..bbcb3f4 --- /dev/null +++ b/kernel/core/net.c @@ -0,0 +1,23 @@ +#include +#include +#include + +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 index 0000000..fce868d --- /dev/null +++ b/kernel/core/stdio.c @@ -0,0 +1,23 @@ +#include +#include +#include + +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; +} -- 2.47.3