From 7f09f23871ea1a12e7dd845fd04cf5ad377096a3 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 9 Dec 2024 20:42:57 +0100 Subject: [PATCH] Mon 9 Dec 20:40:44 CET 2024 --- kernel/main.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/kernel/main.c b/kernel/main.c index 91ca247..5fbec8a 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -3,7 +3,7 @@ Copyright (C) 2015-2019 The University of Notre Dame This software is distributed under the GNU General Public License. See the file LICENSE for details. */ - +#include "kernel/config.h" #include "console.h" #include "page.h" #include "process.h" @@ -38,7 +38,7 @@ int kernel_main() { struct console *console = console_create_root(); console_addref(console); - + printf("Basekernel Version %d.%d %s\n",KERNEL_MAJOR,KERNEL_MINOR,__DATE__); printf("video: %d x %d (addr %x)\n", video_xres, video_yres, video_buffer); printf("kernel: %d bytes\n", kernel_size); @@ -46,7 +46,8 @@ int kernel_main() kmalloc_init((char *) KMALLOC_START, KMALLOC_LENGTH); interrupt_init(); mouse_init(); - keyboard_init(); + keyboard_init(); + serial_init(); rtc_init(); clock_init(); process_init(); @@ -61,12 +62,41 @@ int kernel_main() current->ktable[KNO_STDDIR] = 0; // No current dir until something is mounted. - printf("\n"); + printf("kernel initialization is done.\n"); +#define KSHELL_SERIAL +#ifndef KSHELL_SERIAL kshell_launch(); - + // never reached! +#else + // main IO loop, from kshell_launch + char line[100]; + int lineIndex=0; + while(1) { - console_putchar(console,console_getchar(console)); - } + // console_putchar(console,console_getchar(console)); + char c; + while ((c = serial_read_nonblock(0))<0) clock_wait(10); + console_putchar(console,c); + if (c=='\n') { // End of line + const char *argv[100]; + int argc; + argc = 0; + line[lineIndex]=0; + argv[argc] = strtok(line, " "); + + // split line in tokens separated by spaces + while(argv[argc]) { + argc++; + argv[argc] = strtok(0, " "); + } + if(argc > 0) { + kshell_execute(argc, argv); + } + lineIndex=0; + } else line[lineIndex++]=c; // collect char + } +#endif + // never reached return 0; }