]> git.corax.cc Git - corax/commitdiff
Add simple processes for vga and keyboard handling
authorMatthias Kruk <m@m10k.eu>
Tue, 24 Dec 2019 14:44:04 +0000 (23:44 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 24 Dec 2019 14:44:04 +0000 (23:44 +0900)
kernel/Makefile
kernel/core/main.c
kernel/kbd/Makefile [new file with mode: 0644]
kernel/kbd/main.c [new file with mode: 0644]
kernel/vga/Makefile [new file with mode: 0644]
kernel/vga/main.c [new file with mode: 0644]

index 318c03d4e550a3d365123c77c72ff76bee901fb0..40b959ce49f838e69dc856fdf9a508161f41f323 100644 (file)
@@ -1,5 +1,5 @@
-OBJECTS = arch/arch.o core/core.o io/io.o klibc/klibc.a
-DEPS = arch core io klibc
+OBJECTS = arch/arch.o core/core.o io/io.o vga/vga.o kbd/kbd.o klibc/klibc.a
+DEPS = arch core io vga kbd klibc
 LDFLAGS = --oformat=elf32-i386 -b elf32-i386 -m elf_i386
 CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding
 PHONY = $(DEPS) clean
index 45dbb3da1afa8dedaf4aa7be9129eef3fb499954..96a016bd2d8ad257a21ea305e7643866ea9fcfa9 100644 (file)
@@ -30,8 +30,11 @@ void cpu_debug(void);
 int arch_init(void*);
 void sched_tick(void);
 
+extern void io_main(void);
 extern void _stdio(void);
 extern void _net(void);
+extern int vga_main(int, char**);
+extern int kbd_main(int, char**);
 
 void _print_mptbl(void *tbl)
 {
@@ -101,6 +104,7 @@ static void _init(void)
 {
        pid_t pid;
        int err;
+       int i;
 
        /*
         * instead of something like /sbin/init, this process will behave more like the process daemon
@@ -108,52 +112,40 @@ static void _init(void)
         * operation, and restart them in case they should die.
         */
 
+       pid_t vgapid;
+
        pid = fork();
 
        if(!pid) {
                /* this is the child */
-               err = execfve(_stdio, NULL, NULL);
+               err = execfve(vga_main, NULL, NULL);
 
                if(err < 0) {
-                       /* FIXME: Print an error message */
-
                        for(;;);
                }
        } else if(pid < 0) {
-               /* FIXME: Print an error message */
-               for(;;);
+               /* FIXME: Handle error */
        }
 
+       vgapid = pid;
+
        pid = fork();
 
        if(!pid) {
-               /* this is the child */
-               err = execfve(_net, NULL, NULL);
+               err = execfve(kbd_main, NULL, NULL);
 
                if(err < 0) {
-                       /* FIXME: Print an error message */
                        for(;;);
                }
        } else if(pid < 0) {
-               /* FIXME: Print an error message */
-               for(;;);
+               /* FIXME: Handle error */
        }
 
-#if 0
-
-       err = process_create(&stdio, PID_STDIO, 3, (void*)_stdio);
-
-       if(err < 0) {
-               dbg_printf("Failed to start stdio process [err=0x%08x]\n", err);
-       }
-
-       err = process_create(&net, PID_NET, 3, (void*)_net);
-
-       if(err < 0) {
-               dbg_printf("Failed to start NET process [err=0x%08x]\n", err);
-       }
+       struct cxmsg msg;
+    char *hw = "Hello, world\n";
 
-#endif /* 0 */
+       memcpy(msg.cm_data, hw, 13);
+       cxsendrecv(vgapid, &msg);
 
        wait(NULL);
 
diff --git a/kernel/kbd/Makefile b/kernel/kbd/Makefile
new file mode 100644 (file)
index 0000000..27233ca
--- /dev/null
@@ -0,0 +1,16 @@
+OBJECTS = main.o
+OUTPUT = kbd.o
+INCLUDES = -I../include -I../../include -I../..
+CFLAGS += $(INCLUDES)
+ASFLAGS = $(CFLAGS)
+PHONY = clean
+
+all: $(OUTPUT)
+
+$(OUTPUT): $(OBJECTS)
+       ld -r $(LDFLAGS) -o $@ $^
+
+clean:
+       rm -f $(OBJECTS) $(OUTPUT)
+
+.PHONY: $(PHONY)
diff --git a/kernel/kbd/main.c b/kernel/kbd/main.c
new file mode 100644 (file)
index 0000000..408dedd
--- /dev/null
@@ -0,0 +1,7 @@
+int kbd_main(int argc, char *argv[])
+{
+       /* FIXME: Handle interrupts, IPC messages */
+       for(;;);
+
+       return(0);
+}
diff --git a/kernel/vga/Makefile b/kernel/vga/Makefile
new file mode 100644 (file)
index 0000000..55fff93
--- /dev/null
@@ -0,0 +1,16 @@
+OBJECTS = main.o
+OUTPUT = vga.o
+INCLUDES = -I../include -I../../include -I../..
+CFLAGS += $(INCLUDES)
+ASFLAGS = $(CFLAGS)
+PHONY = clean
+
+all: $(OUTPUT)
+
+$(OUTPUT): $(OBJECTS)
+       ld -r $(LDFLAGS) -o $@ $^
+
+clean:
+       rm -f $(OBJECTS) $(OUTPUT)
+
+.PHONY: $(PHONY)
diff --git a/kernel/vga/main.c b/kernel/vga/main.c
new file mode 100644 (file)
index 0000000..9b4d162
--- /dev/null
@@ -0,0 +1,106 @@
+#include <sys/mman.h>
+#include <corax/ipc.h>
+#include <crxstd.h>
+#include <string.h>
+
+enum vgacolor {
+       BLACK = 0,
+       BLUE,
+       GREEN,
+       CYAN,
+       RED,
+       MAGENTA,
+       BROWN,
+       LGRAY,
+       GRAY,
+       LBLUE,
+       LGREEN,
+       LCYAN,
+       LRED,
+       LMAGENTA,
+       YELLOW,
+       WHITE
+};
+
+#define FG(c)            ((unsigned short)(((c) & 0xf) << 8))
+#define BG(c)            ((unsigned short)(((c) & 0xf) << 12))
+
+#define VGA_BUFFER_ADDR   ((void*)0xb8000)
+#define VGA_BUFFER_COLS   80
+#define VGA_BUFFER_ROWS   24
+#define VGA_ROW_BYTES     (VGA_BUFFER_COLS << 1)
+#define VGA_SCROLL_SIZE   (VGA_BUFFER_COLS * (VGA_BUFFER_ROWS - 1))
+#define VGA_SCROLL_BYTES  (VGA_BUFFER_SIZE << 1)
+#define VGA_BUFFER_SIZE   (VGA_BUFFER_COLS * VGA_BUFFER_ROWS)
+#define VGA_BUFFER_BYTES  (VGA_BUFFER_SIZE << 1)
+
+struct context {
+       unsigned short *buffer;
+       long offset;
+       unsigned short attrs;
+};
+
+static void _putchar(struct context *ctx, int c)
+{
+       if(c == '\n') {
+               ctx->offset += VGA_BUFFER_COLS - (ctx->offset % VGA_BUFFER_COLS);
+       } else {
+               if(ctx->offset >= VGA_BUFFER_SIZE) {
+                       ctx->offset = VGA_SCROLL_SIZE;
+                       memcpy((void*)ctx->buffer, (void*)ctx->buffer + VGA_ROW_BYTES, VGA_SCROLL_BYTES);
+                       memset((void*)ctx->buffer + VGA_SCROLL_BYTES, 0, VGA_ROW_BYTES);
+               }
+
+               ctx->buffer[ctx->offset++] = ctx->attrs | (c & 0xff);
+       }
+
+       return;
+}
+
+static int _puts(struct context *ctx, const char *s)
+{
+       int i;
+
+       for(i = 0; s[i]; i++) {
+               _putchar(ctx, s[i]);
+       }
+
+       return(i);
+}
+
+int vga_main(int argc, char *argv[])
+{
+       struct context ctx;
+
+       ctx.buffer = mmap(VGA_BUFFER_ADDR, 0x1000, PROT_READ | PROT_WRITE, MAP_PHYS, 0, 0);
+
+       if(!ctx.buffer) {
+               /* nothing to do if we can't get access to the VGA buffer */
+               return(1);
+       }
+
+       ctx.offset = VGA_BUFFER_SIZE;
+       ctx.attrs = FG(LGRAY) | BG(BLACK);
+       memset(ctx.buffer, 0, VGA_BUFFER_SIZE);
+
+       while(1) {
+               struct cxmsg msg;
+               int err;
+
+               err = cxrecv(PID_ANY, &msg);
+
+               /* FIXME: Validate message */
+               /* FIXME: Only accept messages from IO process */
+
+               if(err > 0) {
+                       err = _puts(&ctx, (const char*)msg.cm_data);
+               }
+
+               msg.cm_retval = err;
+               cxsend(msg.cm_src, &msg);
+       }
+
+       munmap(ctx.buffer, 0x1000);
+
+       return(0);
+}