]> git.corax.cc Git - corax/commitdiff
Add VGA system process elf-loader
authorMatthias Kruk <m@m10k.eu>
Wed, 6 May 2020 04:00:45 +0000 (13:00 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 6 May 2020 04:00:45 +0000 (13:00 +0900)
config.h
sys/Makefile
sys/vga/Makefile [new file with mode: 0644]
sys/vga/main.c [new file with mode: 0644]

index 341b667d245a855d72b79aa0d3c07306ba249470..7cad81f2e50d5ebf36a99df22557fb130bb17114 100644 (file)
--- a/config.h
+++ b/config.h
@@ -63,7 +63,7 @@
 #define CONFIG_ELF 0
 
 #define CONFIG_KBD 1
-#define CONFIG_VGA 0
+#define CONFIG_VGA 1
 
 /* klibc configuration */
 #define CONFIG_SNPRINTF_FLAG_MINUS 0
index 1170973749d0f4b1cf18d0e33abf9bb1073d8cd5..61c8ab7e44aa6ff644610bd736b11089a45a09ff 100644 (file)
@@ -1,4 +1,4 @@
-DEPS = kbd
+DEPS = kbd vga
 PHONY = $(DEPS) clean
 OUTPUT = initfs.a
 INCLUDES = -I.. -I../include
@@ -9,7 +9,9 @@ all: $(OUTPUT)
 
 kbd.ko: kbd
 
-$(OUTPUT): initfs.o kbd.ko
+vga.ko: vga
+
+$(OUTPUT): initfs.o kbd.ko vga.ko
        ar -rc $@ $^
 
 updateinitfs:
diff --git a/sys/vga/Makefile b/sys/vga/Makefile
new file mode 100644 (file)
index 0000000..8e4552b
--- /dev/null
@@ -0,0 +1,26 @@
+OBJECTS = main.o
+OUTPUT = vga
+MODULE = vga.ko
+
+INCLUDES = -I../../include -I../..
+CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding \
+        -nostdinc -fno-builtin -fno-builtin-memcpy
+LIBS = ../../libc/libc.a
+CFLAGS += $(INCLUDES)
+
+ASFLAGS = $(CFLAGS)
+PHONY = clean
+
+all: $(MODULE)
+
+$(MODULE): $(OUTPUT)
+       ld -r --oformat=elf32-i386 -m elf_i386 -b binary -o $@ $<
+       cp $@ ../
+
+$(OUTPUT): $(OBJECTS)
+       gcc -static $(CFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+       rm -f $(OBJECTS) $(OUTPUT)
+
+.PHONY: $(PHONY)
diff --git a/sys/vga/main.c b/sys/vga/main.c
new file mode 100644 (file)
index 0000000..8f52c7c
--- /dev/null
@@ -0,0 +1,120 @@
+#include <sys/mman.h>
+#include <corax/ipc.h>
+#include <crxstd.h>
+#include <string.h>
+#include <stdio.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 main(int argc, char *argv[])
+{
+       struct context ctx;
+       char line[80];
+
+       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);
+
+       snprintf(line, sizeof(line), "VGA video memory mapped at %p\n",
+                ctx.buffer);
+
+       _puts(&ctx, line);
+
+       while(1) {
+               struct cxmsg msg;
+               int err;
+
+               memset(&msg, 0, sizeof(msg));
+
+               err = cxrecv(PID_ANY, &msg);
+
+               /* FIXME: Validate message */
+               /* FIXME: Only accept messages from IO process */
+
+               if(!err) {
+                       err = _puts(&ctx, (const char*)msg.cm_data);
+               }
+
+               msg.cm_retval = err;
+               cxsend(msg.cm_src, &msg);
+       }
+
+       munmap(ctx.buffer, 0x1000);
+
+       return(0);
+}