diff --git a/.gitignore b/.gitignore index ca27376..0f66c4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o *.map *.fex +*.elf out/ \ No newline at end of file diff --git a/Fennix Userspace.code-workspace b/Fennix Userspace.code-workspace index 14008ce..22148c5 100644 --- a/Fennix Userspace.code-workspace +++ b/Fennix Userspace.code-workspace @@ -5,6 +5,9 @@ } ], "settings": { - "debug.allowBreakpointsEverywhere": true + "debug.allowBreakpointsEverywhere": true, + "files.associations": { + "fex.hpp": "c" + } } } \ No newline at end of file diff --git a/Makefile b/Makefile index d28c479..5fb33ed 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ build: mkdir -p out mkdir -p out/system + mkdir -p out/system/lib make --quiet -C libc build make --quiet -C apps build diff --git a/libc/Makefile b/libc/Makefile index 746a46f..a595fa3 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -1,4 +1,9 @@ build: - + make --quiet -C runtime build + make --quiet -C libgcc build + make --quiet -C src build clean: + make --quiet -C runtime clean + make --quiet -C libgcc clean + make --quiet -C src clean diff --git a/libc/include/types.h b/libc/include/types.h new file mode 100644 index 0000000..e69de29 diff --git a/libc/libgcc/Makefile b/libc/libgcc/Makefile new file mode 100644 index 0000000..08a0e7e --- /dev/null +++ b/libc/libgcc/Makefile @@ -0,0 +1,44 @@ +# Config file +include ../../../Makefile.conf + +NAME=gcc + +OBJECT_NAME=lib$(NAME).a + +OUTPUT_DIR=../../out/system/lib/ + +CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc +AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar +NASM = /usr/bin/nasm + +C_SOURCES = $(shell find ./ -type f -name '*.c') +S_SOURCES = $(shell find ./ -type f -name '*.s') +ASM_SOURCES = $(shell find ./ -type f -name '*.asm') +OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o} + +INCLUDE_DIR = ../include + +ifeq ($(OSARCH), amd64) +ASM_ARCH := elf64 +else ifeq ($(OSARCH), i686) +ASM_ARCH := elf32 +endif + +CFLAGS := -fPIC -I$(INCLUDE_DIR) + +build: $(OBJECT_NAME) + +$(OBJECT_NAME): $(OBJ) + $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) + +%.o: %.c $(HEADERS) $(HEADERS2) + $(CC) $(CFLAGS) -std=c17 -c $< -o $@ + +%.o: %.cpp $(HEADERS) $(HEADERS2) + $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ + +%.o: %.asm + $(NASM) $< -f $(ASM_ARCH) -o $@ + +clean: + diff --git a/libc/libgcc/cxa.cpp b/libc/libgcc/cxa.cpp new file mode 100644 index 0000000..e69de29 diff --git a/libc/runtime/Makefile b/libc/runtime/Makefile new file mode 100644 index 0000000..2daae15 --- /dev/null +++ b/libc/runtime/Makefile @@ -0,0 +1,31 @@ +# Config file +include ../../../Makefile.conf + +CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc +NASM = /usr/bin/nasm + +C_SOURCES = $(shell find ./ -type f -name '*.c') +S_SOURCES = $(shell find ./ -type f -name '*.s') +ASM_SOURCES = $(shell find ./ -type f -name '*.asm') +OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o} + +ifeq ($(OSARCH), amd64) +ASM_ARCH := elf64 +else ifeq ($(OSARCH), i686) +ASM_ARCH := elf32 +endif + +build: $(OBJ) + mv $^ ../../out/system/lib/ + +%.o: %.c + $(CC) -nostdlib -std=c17 -c $< -o $@ + +%.o: %.asm + $(NASM) $< -f $(ASM_ARCH) -o $@ + +%.bin: %.s + $(NASM) $< -f $(ASM_ARCH) -o $@ + +clean: + diff --git a/libc/runtime/crt0.c b/libc/runtime/crt0.c new file mode 100644 index 0000000..3612f93 --- /dev/null +++ b/libc/runtime/crt0.c @@ -0,0 +1,10 @@ +int main(int argc, char *argv[], char *envp[]); + +int _start(void *Data) +{ + int mainret = main((int)0, (char **)0, (char **)0); + while (1) + ; + return 0; +} +// C stuff \ No newline at end of file diff --git a/libc/runtime/crt1.c b/libc/runtime/crt1.c new file mode 100644 index 0000000..95110bd --- /dev/null +++ b/libc/runtime/crt1.c @@ -0,0 +1,10 @@ +int main(int argc, char *argv[], char *envp[]); + +int _start(void *Data) +{ + int mainret = main((int)0, (char **)0, (char **)0); + while (1) + ; + return 0; +} +// C++ stuff \ No newline at end of file diff --git a/libc/runtime/crtbegin.c b/libc/runtime/crtbegin.c new file mode 100644 index 0000000..507125b --- /dev/null +++ b/libc/runtime/crtbegin.c @@ -0,0 +1 @@ +// C++ constructor/destructor stuff \ No newline at end of file diff --git a/libc/runtime/crtend.c b/libc/runtime/crtend.c new file mode 100644 index 0000000..507125b --- /dev/null +++ b/libc/runtime/crtend.c @@ -0,0 +1 @@ +// C++ constructor/destructor stuff \ No newline at end of file diff --git a/libc/src/Makefile b/libc/src/Makefile new file mode 100644 index 0000000..73de042 --- /dev/null +++ b/libc/src/Makefile @@ -0,0 +1,44 @@ +# Config file +include ../../../Makefile.conf + +NAME=c + +OBJECT_NAME=lib$(NAME).a + +OUTPUT_DIR=../../out/system/lib/ + +CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc +AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar +NASM = /usr/bin/nasm + +C_SOURCES = $(shell find ./ -type f -name '*.c') +S_SOURCES = $(shell find ./ -type f -name '*.s') +ASM_SOURCES = $(shell find ./ -type f -name '*.asm') +OBJ = ${C_SOURCES:.c=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o} + +INCLUDE_DIR = ../include + +ifeq ($(OSARCH), amd64) +ASM_ARCH := elf64 +else ifeq ($(OSARCH), i686) +ASM_ARCH := elf32 +endif + +CFLAGS := -fPIC -I$(INCLUDE_DIR) + +build: $(OBJECT_NAME) + +$(OBJECT_NAME): $(OBJ) + $(AR) rcs $(OUTPUT_DIR)$@ $(OBJ) + +%.o: %.c $(HEADERS) $(HEADERS2) + $(CC) $(CFLAGS) -std=c17 -c $< -o $@ + +%.o: %.cpp $(HEADERS) $(HEADERS2) + $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ + +%.o: %.asm + $(NASM) $< -f $(ASM_ARCH) -o $@ + +clean: + rm -f $(OBJ) diff --git a/libc/src/main.c b/libc/src/main.c new file mode 100644 index 0000000..e69de29