From: Matthias Kruk Date: Sun, 27 Oct 2019 16:18:53 +0000 (+0900) Subject: Add some IPC testing code to main.c X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=215006330cb19d9e22b5dd0791f9dd7890c91fd8;p=corax Add some IPC testing code to main.c --- diff --git a/kernel/core/main.c b/kernel/core/main.c index 2528676..0b4270e 100644 --- a/kernel/core/main.c +++ b/kernel/core/main.c @@ -22,10 +22,18 @@ #include #include #include +#include void cpu_debug(void); int arch_init(void*); void sched_tick(void); +/* +int socket(int, int, int); +int close(int); +*/ + +int cxsend(pid_t, struct cxmsg*); +int cxrecv(pid_t, struct cxmsg*); void _print_mptbl(void *tbl) { @@ -77,22 +85,95 @@ 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 + 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"); } return; } +static void _busy(void) +{ +/* int fd, fe; + + fd = socket(PF_INET, SOCK_DGRAM, 0); + fe = socket(PF_INET, SOCK_STREAM, 0); +*/ +#if 0 + if(fd >= 0) { + close(fd); + } + + if(fe >= 0) { + close(fe); + } +#endif + +#if 0 + int sock; + + sock = socket(PF_INET, SOCK_SEQPACKET, 0); + + if(sock < 0) { + // dbg_printf("errno = %u\n", -sock); + } + + sock = close(sock); + + if(sock < 0) { + // dbg_printf("errno = %u\n", -sock); + } +#endif + + struct cxmsg msg; + + cxsend(101, &msg); + + for(;;); + + return; +} + int corax(void *mb_info, u32_t magic) { dbg_printf("Corax 0.1 - As the Crow flies\n"); dbg_printf("(C) 2019 Matthias Kruk \n"); dbg_printf("Compiled on %s at %s\n", __DATE__, __TIME__); - u32_t p; /* void *ptr; @@ -160,34 +241,26 @@ int corax(void *mb_info, u32_t magic) } } */ -#if 0 - void *ptr; - - ptr = kmalloc(1024 * 1024); - - dbg_printf("Allocated 1024KB @ %p\n", ptr); - - kfree(ptr); -#endif - - dbg_printf("Switching pstate\n"); - - p = cpu_set_pstate(1); - dbg_printf("Entered P-state %u. (0x%x)\n", p & 0xffff, p); - dbg_printf("Initialisation complete. Nothing to do.\n"); 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); } - /* enqueue a second process */ - err = process_create(&proc2, 0, (void*)_idle); + err = process_create(&proc2, 0, (void*)_srv); + + if(err < 0) { + dbg_printf("process_create() = 0x%x\n", err); + } + + err = process_create(&proc3, 3, (void*)_busy); if(err < 0) { dbg_printf("process_create() = 0x%x\n", err);