summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile38
-rw-r--r--kfs.ld15
-rw-r--r--src/crt0.S17
3 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3ccecb1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+NAME = kfs
+SRC = $(wildcard src/*.c src/crt0.S)
+
+LDSCRIPT = kfs.ld
+
+CPPFLAGS +=
+LDFLAGS += -T $(LDSCRIPT) -nostdlib -Wl,--build-id=none -m32
+CFLAGS += -W -Wall -Wextra -std=gnu99 -g \
+ -nostdinc -fno-builtin -fno-stack-protector -m32
+
+CC = gcc
+
+OBJ = $(SRC:.c=.o)
+
+all: $(NAME)
+
+$(NAME): $(OBJ) $(LDSCRIPT)
+ # TODO
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+clean:
+ $(RM) $(OBJ)
+ $(RM) $(NAME)
+
+mrproper: clean
+
+distclean: mrproper
+ $(RM) $(addsuffix ~,$(SRC))
+ $(RM) $(wildcard $(addsuffix .sw*,$(addprefix .,$(SRC))))
+
+boot: all
+ $(shell qemu-system-x86_64 -kernel $(NAME) -nographic)
+
+debug: all
+ $(shell qemu-system-x86_64 -kernel $(NAME) -s -S)
+
+.PHONY: all clean mrproper distclean boot
+
diff --git a/kfs.ld b/kfs.ld
new file mode 100644
index 0000000..6527fbf
--- /dev/null
+++ b/kfs.ld
@@ -0,0 +1,15 @@
+OUTPUT_FORMAT("elf32-i386")
+OUTPUT_ARCH("i386")
+
+ENTRY(_start)
+
+SECTIONS
+{
+ . = 0x100000 + SIZEOF_HEADERS;
+
+ PROVIDE(begin_text = .);
+ .text :
+ {
+ *(.multiboot) *(.text)
+ }
+}
diff --git a/src/crt0.S b/src/crt0.S
new file mode 100644
index 0000000..5116a7a
--- /dev/null
+++ b/src/crt0.S
@@ -0,0 +1,17 @@
+#define MAGIC 0x1BADB002
+#define FLAGS 0x7
+
+.section .multiboot
+ .align 4
+ .long MAGIC
+ .long FLAGS
+ .long -(MAGIC + FLAGS)
+
+.section .text
+.global _start
+
+_start:
+ push %ebx
+ push %eax
+ call main
+ hlt