summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile28
-rw-r--r--compile_flags.txt1
-rw-r--r--kernel/main.c7
-rw-r--r--kernel/tty.c32
-rw-r--r--kernel/tty.h6
-rw-r--r--linker.ld24
-rw-r--r--platform/boot.s32
8 files changed, 132 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..98f5968
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.bin
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..593ead0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+AS = i686-elf-as
+CC = i686-elf-gcc
+CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra
+CFLAGS += -I.
+LFLAGS = -ffreestanding -O2 -nostdlib -lgcc
+
+OBJ = platform/boot.o
+OBJ += $(patsubst %.c,%.o,$(wildcard kernel/*.c))
+
+
+.PHONY: boot clean
+boot: kernel.bin
+ qemu-system-i386 -kernel kernel.bin
+
+clean:
+ rm -vf kernel.bin
+ rm -vf **/*.o
+
+
+kernel.bin: $(OBJ)
+ $(CC) $(LFLAGS) -T linker.ld $^ -o $@
+ grub-file --is-x86-multiboot $@
+
+platform/boot.o: platform/boot.s
+ $(AS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
diff --git a/compile_flags.txt b/compile_flags.txt
new file mode 100644
index 0000000..60a4aad
--- /dev/null
+++ b/compile_flags.txt
@@ -0,0 +1 @@
+-I.
diff --git a/kernel/main.c b/kernel/main.c
new file mode 100644
index 0000000..73c66e2
--- /dev/null
+++ b/kernel/main.c
@@ -0,0 +1,7 @@
+#include <kernel/tty.h>
+
+void kmain()
+{
+ for (int i = 0; i < 400; i++)
+ tty_write("words ", 6);
+}
diff --git a/kernel/tty.c b/kernel/tty.c
new file mode 100644
index 0000000..45de728
--- /dev/null
+++ b/kernel/tty.c
@@ -0,0 +1,32 @@
+/* will be moved to userspace later on */
+
+#include <kernel/tty.h>
+
+struct vga_cell {
+ unsigned char c;
+ unsigned char style;
+} __attribute__((__packed__));
+
+static const size_t vga_len = 80 * 25;
+static struct vga_cell *vga = (void*) 0xB8000;
+static size_t vga_pos = 0;
+
+static void tty_scroll() {
+ for (int i = 0; i < vga_len - 80; i++) {
+ vga[i] = vga[i + 80];
+ }
+ vga_pos -= 80;
+}
+
+void tty_putchar(char c)
+{
+ if (vga_pos >= vga_len - 80) tty_scroll();
+ vga[vga_pos++].c = c;
+}
+
+void tty_write(const char *buf, size_t len)
+{
+ for (size_t i = 0; i < len; i++) {
+ tty_putchar(buf[i]);
+ }
+}
diff --git a/kernel/tty.h b/kernel/tty.h
new file mode 100644
index 0000000..87a4744
--- /dev/null
+++ b/kernel/tty.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#include <stddef.h>
+
+void tty_putchar(char c);
+void tty_write(const char *buf, size_t len);
diff --git a/linker.ld b/linker.ld
new file mode 100644
index 0000000..dd7c64c
--- /dev/null
+++ b/linker.ld
@@ -0,0 +1,24 @@
+ENTRY(_start)
+
+SECTIONS
+{
+ . = 1M;
+ .text BLOCK(4K) : ALIGN(4K)
+ {
+ *(.multiboot)
+ *(.text)
+ }
+ .rodata BLOCK(4K) : ALIGN(4K)
+ {
+ *(.rodata)
+ }
+ .data BLOCK(4K) : ALIGN(4K)
+ {
+ *(.data)
+ }
+ .bss BLOCK(4K) : ALIGN(4K)
+ {
+ *(COMMON)
+ *(.bss)
+ }
+}
diff --git a/platform/boot.s b/platform/boot.s
new file mode 100644
index 0000000..77af2bc
--- /dev/null
+++ b/platform/boot.s
@@ -0,0 +1,32 @@
+.set MAGIC, 0x1BADB002
+.set FLAG_ALIGN, 1<<0 /* align modules on page boundaries */
+.set FLAG_MEMINFO, 1<<1 /* memory map */
+.set FLAGS, FLAG_ALIGN | FLAG_MEMINFO
+.set CHECKSUM, -(MAGIC + FLAGS)
+
+.section .multiboot
+.align 4
+.long MAGIC
+.long FLAGS
+.long CHECKSUM
+
+/* a lil stack */
+.section .bss
+.align 16
+stack_bottom:
+.skip 16384
+stack_top:
+
+
+.section .text
+.global _start
+.type _start, @function
+_start:
+ mov $stack_top, %esp
+ call kmain
+
+ cli /* disable interrupts */
+1: hlt
+ jmp 1b
+
+.size _start, . - _start