diff --git a/libs/Makefile b/libs/Makefile index ed97389..837a8a3 100644 --- a/libs/Makefile +++ b/libs/Makefile @@ -3,8 +3,10 @@ build: make --quiet -C libgcc build make --quiet -C libinit build make --quiet -C libssp build + make --quiet -C libsys build clean: make -C libgcc clean make -C libinit clean make -C libssp clean + make -C libsys clean diff --git a/libs/include/syslib.h b/libs/include/syslib.h new file mode 100644 index 0000000..9d11604 --- /dev/null +++ b/libs/include/syslib.h @@ -0,0 +1,17 @@ +#ifndef __FENNIX_LIBS_SYS_H__ +#define __FENNIX_LIBS_SYS_H__ + +#include + +enum KCtl +{ + KCTL_NULL, + KCTL_GETPID, + KCTL_GETTID, + KCTL_GETUID, + KCTL_GETGID, +}; + +long DoCtl(uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4); + +#endif // !__FENNIX_LIBS_SYS_H__ diff --git a/libs/libsys/Makefile b/libs/libsys/Makefile new file mode 100644 index 0000000..a5669a7 --- /dev/null +++ b/libs/libsys/Makefile @@ -0,0 +1,51 @@ +# Config file +include ../../../Makefile.conf + +NAME=sys + +OBJECT_NAME=lib$(NAME).so +SO_NAME=libsys + +OUTPUT_DIR=../../out/system/lib/ +SYSROOT = --sysroot=../../out/system/ + +CC = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)gcc +AS = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)as +AR = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)ar +OBJDUMP = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)objdump +NASM = /usr/bin/nasm + +C_SOURCES = $(shell find ./ -type f -name '*.c') +CPP_SOURCES = $(shell find ./ -type f -name '*.cpp') +S_SOURCES = $(shell find ./ -type f -name '*.S') +ASM_SOURCES = $(shell find ./ -type f -name '*.asm') +OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.S=.o} + +ifeq ($(OSARCH), amd64) +ASM_ARCH := elf64 +else ifeq ($(OSARCH), i686) +ASM_ARCH := elf32 +endif + +CFLAGS := -fPIC -I../include -I../../libc/include + +build: $(OBJECT_NAME) + +$(OBJECT_NAME): $(OBJ) + $(CC) -nostdlib -shared -fPIC -Wl,-soname,$(SO_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@ + $(OBJDUMP) -d $(OUTPUT_DIR)$@ > file_dump.map + +%.o: %.c + $(CC) $(CFLAGS) -std=c17 -c $< -o $@ + +%.o: %.cpp + $(CC) $(CFLAGS) -std=c++20 -c $< -o $@ + +%.o: %.S + $(AS) -c $< -o $@ + +%.o: %.asm + $(NASM) $< -f $(ASM_ARCH) -o $@ + +clean: + rm -f file_dump.map $(OBJ) diff --git a/libs/libsys/kcall.c b/libs/libsys/kcall.c new file mode 100644 index 0000000..412f017 --- /dev/null +++ b/libs/libsys/kcall.c @@ -0,0 +1,8 @@ +#include + +#include "../../../Kernel/syscalls.h" + +long DoCtl(uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4) +{ + return syscall5(_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4); +}