summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/main.c83
-rw-r--r--kernel/util.asm20
-rw-r--r--kernel/util.h2
3 files changed, 105 insertions, 0 deletions
diff --git a/kernel/main.c b/kernel/main.c
new file mode 100644
index 0000000..e69af30
--- /dev/null
+++ b/kernel/main.c
@@ -0,0 +1,83 @@
+#include <stdint.h>
+#include "util.h"
+
+#define VGA_WIDTH 80
+#define VGA_HEIGHT 25
+
+struct e820_entry {
+ uint64_t base;
+ uint64_t length;
+ uint32_t type;
+ uint32_t ext_attr;
+};
+
+static uint64_t *
+memsetu64(uint64_t *const dst, const uint64_t c, const uint64_t n)
+{
+ for (uint64_t i = 0; i < n; ++i) dst[i] = c;
+ return dst;
+}
+
+static uint16_t *
+print_hex(uint16_t *dst, uint64_t num)
+{
+ dst[0] = 0x0f00 | '0';
+ dst[1] = 0x0f00 | 'x';
+
+ dst += 2;
+
+ for (int i = 0; i < 16; ++i) {
+ uint16_t x = (num >> 60);
+
+ *(dst++) = 0x0f00 | (x < 0xa ? x+'0' : x+'a'-0xa);
+
+ num <<= 4;
+ }
+
+ return dst;
+}
+
+static uint16_t *
+puts(uint16_t *dst, const char *str)
+{
+ for (; *str; ++str, ++dst) *dst = 0x0f00|(*str);
+ return dst;
+}
+
+static uint16_t *
+print_e820_table(uint16_t *dst, const struct e820_entry *const entries, const uint32_t count)
+{
+ for (uint32_t i = 0; i < count; ++i, dst += VGA_WIDTH) {
+ uint16_t *cursor;
+
+ cursor = print_hex(dst, entries[i].base);
+
+ *(cursor++) = 0x0f00 | '-';
+
+ cursor = print_hex(cursor, entries[i].base + entries[i].length - 1);
+
+ ++cursor;
+ cursor = puts(cursor, entries[i].type == 1 ? "available" : "reserved");
+ }
+
+ return dst;
+}
+
+void
+kmain(void)
+{
+ vga_cursor_hide();
+
+ uint16_t *const vga_memory = (uint16_t *)0xb8000;
+ memsetu64((uint64_t *)vga_memory, 0x0f200f200f200f20, (VGA_WIDTH*VGA_HEIGHT*sizeof(uint16_t))/sizeof(uint64_t));
+
+ puts(vga_memory, "ProvidenceOS v0.1");
+ puts(vga_memory+VGA_WIDTH*2, "e820 memory map:");
+
+ const uint32_t e820_size = *(uint32_t *)0xf000;
+ const struct e820_entry *const e820_mmap = (struct e820_entry *)0xf004;
+
+ print_e820_table(vga_memory+(VGA_WIDTH*3), e820_mmap, e820_size);
+
+ halt();
+}
diff --git a/kernel/util.asm b/kernel/util.asm
new file mode 100644
index 0000000..548223d
--- /dev/null
+++ b/kernel/util.asm
@@ -0,0 +1,20 @@
+format ELF64
+
+section '.text' executable
+
+public vga_cursor_hide
+vga_cursor_hide:
+ mov dx, 0x03d4
+ mov al, 0x0a
+ out dx, al
+
+ inc dx
+ mov al, 0x20
+ out dx, al
+
+ ret
+
+public halt
+halt:
+ hlt
+ jmp halt
diff --git a/kernel/util.h b/kernel/util.h
new file mode 100644
index 0000000..1015c9c
--- /dev/null
+++ b/kernel/util.h
@@ -0,0 +1,2 @@
+void vga_cursor_hide(void);
+void halt(void);