Let's try to start parsing ELFs!

This commit is contained in:
apio 2022-09-30 17:43:14 +02:00
parent 87f67b255e
commit 867d312177
5 changed files with 66 additions and 5 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ toolchain/
initrd/boot/moon.elf initrd/boot/moon.elf
kernel/bin/moon.elf kernel/bin/moon.elf
initrd/sys/moon.sym initrd/sys/moon.sym
initrd/bin/**
apps/bin/**

View File

@ -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: initrd-clean:
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso 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 include kernel/Makefile
include apps/Makefile

31
apps/Makefile Normal file
View File

@ -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)/*

21
apps/apps.ld Normal file
View File

@ -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) }
}

5
apps/init.asm Normal file
View File

@ -0,0 +1,5 @@
section .text
global _start
_start:
mov rax, 0
int 42h