diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca27376 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.map +*.fex +out/ \ No newline at end of file diff --git a/Makefile b/Makefile index 17ca6be..d28c479 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ build: - + mkdir -p out + mkdir -p out/system + make --quiet -C libc build + make --quiet -C apps build prepare: $(info Nothing to prepare) clean: - + rm -rf out + make --quiet -C libc clean + make --quiet -C apps clean diff --git a/apps/Makefile b/apps/Makefile new file mode 100644 index 0000000..f1cbea0 --- /dev/null +++ b/apps/Makefile @@ -0,0 +1,7 @@ +build: + make --quiet -C system build + make --quiet -C user build + +clean: + make --quiet -C system clean + make --quiet -C user clean diff --git a/apps/system/Makefile b/apps/system/Makefile new file mode 100644 index 0000000..c962034 --- /dev/null +++ b/apps/system/Makefile @@ -0,0 +1,5 @@ +build: + make --quiet -C init build + +clean: + make --quiet -C init clean diff --git a/apps/system/init/Makefile b/apps/system/init/Makefile index f9bf4f2..21c80b5 100644 --- a/apps/system/init/Makefile +++ b/apps/system/init/Makefile @@ -1,13 +1,13 @@ # Config file -include ../../../Makefile.conf +include ../../../../Makefile.conf FILENAME = init.fex -CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc -CPP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ -LD = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld -AS = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as -OBJDUMP = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)objdump +CC = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc +CPP = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)g++ +LD = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ld +AS = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as +OBJDUMP = ../../../../$(COMPILER_PATH)/$(COMPILER_ARCH)objdump GIT_COMMIT = $(shell git rev-parse HEAD) GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD) @@ -47,14 +47,14 @@ ifeq ($(OSARCH), amd64) CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ -mno-red-zone -mno-sse -mno-sse2 \ - -march=x86-64 -pipe \ + -march=x86-64 -pipe -ffunction-sections \ -mcmodel=kernel -msoft-float -fno-builtin LDFLAGS += -Tarch/amd64/linker.ld else ifeq ($(OSARCH), i686) CFLAGS += -fPIC -fno-pie -mno-80387 -mno-mmx -mno-3dnow \ - -mno-red-zone -mno-sse -mno-sse2 \ + -mno-red-zone -mno-sse -mno-sse2 -ffunction-sections \ -march=i686 -pipe -msoft-float -fno-builtin LDFLAGS += -Tarch/i686/linker.ld @@ -73,7 +73,7 @@ else ifeq ($(OSARCH), i686) else ifeq ($(OSARCH), aarch64) endif - mv $(FILENAME) ../../out/$(FILENAME) + mv $(FILENAME) ../../../out/system/$(FILENAME) $(FILENAME): $(OBJ) $(CC) $(LDFLAGS) $(OBJ) -o $@ diff --git a/apps/system/init/arch/amd64/linker.ld b/apps/system/init/arch/amd64/linker.ld index 2a9846f..f818bfc 100644 --- a/apps/system/init/arch/amd64/linker.ld +++ b/apps/system/init/arch/amd64/linker.ld @@ -1,5 +1,3 @@ -/* EXPERIMENTAL */ - OUTPUT_FORMAT(binary) OUTPUT_ARCH(i386:x86-64) diff --git a/apps/system/init/init.cpp b/apps/system/init/init.cpp index 4869dfd..96312a7 100644 --- a/apps/system/init/init.cpp +++ b/apps/system/init/init.cpp @@ -1,39 +1,29 @@ -// EXPERIMENTAL +#include "../../../../Kernel/Fex.hpp" -enum FexFormatType -{ - FexFormatType_Unknown, - FexFormatType_Executable, - FexFormatType_Driver - /* ... */ -}; - -enum FexOSType -{ - FexOSType_Unknown, - FexOSType_Fennix, - FexOSType_Linux - /* ... */ -}; - -struct Fex -{ - char Magic[4]; - int Type; - int OS; - unsigned long Pointer; -}; - -extern "C" int _start(); - -__attribute__((section(".header"))) -Fex header = { - .Magic = {'F', 'E', 'X', '\0'}, - .Type = FexFormatType_Executable, - .OS = FexOSType_Fennix, - .Pointer = (unsigned long)_start}; - -extern "C" int _start() +extern "C" int _start(void *Data); + +HEAD(FexFormatType_Executable, FexOSType_Fennix, _start); + +#define DEFINE_SYSCALL0(function, n) \ + static inline long syscall_##function() \ + { \ + long a = n; \ + __asm__ __volatile__("pushq %%r11\n" \ + "pushq %%rcx\n" \ + "syscall\n" \ + "popq %%rcx\n" \ + "popq %%r11\n" \ + : "=a"(a) \ + : "a"((long)a)); \ + return a; \ + } + +DEFINE_SYSCALL0(exit, 1); +#define UNUSED(x) (void)(x) + +extern "C" int _start(void *Data) { + UNUSED(Data); + syscall_exit(); return 0; } diff --git a/apps/user/Makefile b/apps/user/Makefile new file mode 100644 index 0000000..746a46f --- /dev/null +++ b/apps/user/Makefile @@ -0,0 +1,4 @@ +build: + + +clean: diff --git a/libc/.gitkeep b/libc/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/libc/Makefile b/libc/Makefile new file mode 100644 index 0000000..746a46f --- /dev/null +++ b/libc/Makefile @@ -0,0 +1,4 @@ +build: + + +clean: