From 867d3121775aa574d077971e9274a9929515bb75 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 30 Sep 2022 17:43:14 +0200 Subject: [PATCH] Let's try to start parsing ELFs! --- .gitignore | 4 +++- Makefile | 10 ++++++---- apps/Makefile | 31 +++++++++++++++++++++++++++++++ apps/apps.ld | 21 +++++++++++++++++++++ apps/init.asm | 5 +++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 apps/Makefile create mode 100644 apps/apps.ld create mode 100644 apps/init.asm diff --git a/.gitignore b/.gitignore index 8cc2980e..058e67a8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ toolchain/ **/*.o initrd/boot/moon.elf kernel/bin/moon.elf -initrd/sys/moon.sym \ No newline at end of file +initrd/sys/moon.sym +initrd/bin/** +apps/bin/** \ No newline at end of file diff --git a/Makefile b/Makefile index d2af2bac..20ab9997 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ -build: $(LUNA_ROOT)/kernel/bin/moon.elf +build: $(LUNA_ROOT)/kernel/bin/moon.elf apps-build -clean: moon-clean initrd-clean +clean: moon-clean initrd-clean apps-clean initrd-clean: rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso + rm -rf $(LUNA_ROOT)/initrd/bin -install: $(LUNA_ROOT)/initrd/boot/moon.elf +install: $(LUNA_ROOT)/initrd/boot/moon.elf apps-install -include kernel/Makefile \ No newline at end of file +include kernel/Makefile +include apps/Makefile \ No newline at end of file diff --git a/apps/Makefile b/apps/Makefile new file mode 100644 index 00000000..49272f2b --- /dev/null +++ b/apps/Makefile @@ -0,0 +1,31 @@ +APPS := init + +APPS_DIR := $(LUNA_ROOT)/apps +APPS_OBJ := $(APPS_DIR)/lib +APPS_BIN := $(APPS_DIR)/bin + +REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS)) + +ASMC := nasm +ASMFLAGS := -felf64 + +LD := x86_64-elf-ld +APP_LDFLAGS := -T$(APPS_DIR)/apps.ld -nostdlib + +$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm + @mkdir -p $(@D) + $(ASMC) $(ASMFLAGS) -o $@ $^ + +$(APPS_BIN)/%: $(APPS_OBJ)/%.o + @mkdir -p $(@D) + $(LD) $(APP_LDFLAGS) -o $@ $^ + +apps-build: $(REAL_APPS) + +apps-install: $(REAL_APPS) + @mkdir -p $(LUNA_ROOT)/initrd/bin + cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin + +apps-clean: + rm -f $(APPS_OBJ)/* + rm -f $(APPS_BIN)/* \ No newline at end of file diff --git a/apps/apps.ld b/apps/apps.ld new file mode 100644 index 00000000..d355a2a4 --- /dev/null +++ b/apps/apps.ld @@ -0,0 +1,21 @@ +ENTRY(_start) +OUTPUT_FORMAT(elf64-x86-64) + +SECTIONS +{ + . = 0x10000; + .text : ALIGN(16) { + KEEP(*(.text.boot)) *(.text .text.*) /* code */ + *(.rodata .rodata.*) /* data */ + } + .data : ALIGN(16) { + *(.data .data.*) + } + .bss (NOLOAD) : { /* bss */ + . = ALIGN(16); + *(.bss .bss.*) + *(COMMON) + } + + /DISCARD/ : { *(.eh_frame) *(.comment) } +} diff --git a/apps/init.asm b/apps/init.asm new file mode 100644 index 00000000..4948cf12 --- /dev/null +++ b/apps/init.asm @@ -0,0 +1,5 @@ +section .text +global _start +_start: + mov rax, 0 + int 42h \ No newline at end of file