Update userspace

This commit is contained in:
Alex
2023-06-10 13:10:56 +03:00
parent ed5faa7b55
commit 22e75b9540
63 changed files with 2362 additions and 2151 deletions

View File

@@ -4,15 +4,15 @@
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);
return syscall5(_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4);
}
uintptr_t KrnlRequestPages(size_t Count)
{
return syscall1(_RequestPages, Count);
return syscall1(_RequestPages, Count);
}
void KrnlFreePages(uintptr_t Address, size_t Count)
{
syscall2(_FreePages, Address, Count);
syscall2(_FreePages, Address, Count);
}

View File

@@ -5,41 +5,41 @@
__attribute__((visibility("hidden"))) long __FILE_GetPageSize()
{
static long PageSize = 0;
if (PageSize == 0)
PageSize = DoCtl(KCTL_GET_PAGE_SIZE, 0, 0, 0, 0);
return PageSize;
static long PageSize = 0;
if (PageSize == 0)
PageSize = DoCtl(KCTL_GET_PAGE_SIZE, 0, 0, 0, 0);
return PageSize;
}
File *FileOpen(const char *Path, uint64_t Flags)
{
File *FilePtr = (File *)KrnlRequestPages(sizeof(File) / __FILE_GetPageSize() + 1);
FilePtr->KernelPrivate = (void *)syscall2(_FileOpen, (uint64_t)Path, Flags);
return FilePtr;
File *FilePtr = (File *)KrnlRequestPages(sizeof(File) / __FILE_GetPageSize() + 1);
FilePtr->KernelPrivate = (void *)syscall2(_FileOpen, (uint64_t)Path, Flags);
return FilePtr;
}
void FileClose(File *File)
{
syscall1(_FileClose, (uint64_t)File->KernelPrivate);
KrnlFreePages((uintptr_t)File, sizeof(File) / __FILE_GetPageSize() + 1);
syscall1(_FileClose, (uint64_t)File->KernelPrivate);
KrnlFreePages((uintptr_t)File, sizeof(File) / __FILE_GetPageSize() + 1);
}
uint64_t FileRead(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
{
return syscall4(_FileRead, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
return syscall4(_FileRead, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
}
uint64_t FileWrite(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size)
{
return syscall4(_FileWrite, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
return syscall4(_FileWrite, (uint64_t)File->KernelPrivate, Offset, (uint64_t)Buffer, Size);
}
uint64_t FileSeek(File *File, uint64_t Offset, uint64_t Whence)
{
return syscall3(_FileSeek, (uint64_t)File->KernelPrivate, Offset, Whence);
return syscall3(_FileSeek, (uint64_t)File->KernelPrivate, Offset, Whence);
}
uint64_t FileStatus(File *File)
{
return syscall1(_FileStatus, (uint64_t)File->KernelPrivate);
return syscall1(_FileStatus, (uint64_t)File->KernelPrivate);
}

View File

@@ -3,23 +3,23 @@ include ../../../Makefile.conf
NAME=sys
OBJECT_NAME=lib$(NAME).so
SO_NAME=$(OBJECT_NAME)
ifeq ($(USERSPACE_STATIC_LIBS), 1)
OBJECT_NAME := lib$(NAME).a
else
OBJECT_NAME := lib$(NAME).so
endif
OUTPUT_DIR=../../out/lib/
SYSROOT = --sysroot=../../out/
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
CC = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
AS = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)as
AR = ../../../$(COMPILER_PATH)/$(COMPILER_ARCH)ar
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}
OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${S_SOURCES:.S=.o}
ifeq ($(OSARCH), amd64)
ASM_ARCH := elf64
@@ -27,16 +27,21 @@ else ifeq ($(OSARCH), i386)
ASM_ARCH := elf32
endif
SIMD_FLAGS := -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4 -mno-avx -mno-avx2 -mno-avx512f
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../libc/include
CFLAGS := -fPIC -fPIE -I../include -I../../libc/include $(SIMD_FLAGS)
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
endif
build: $(OBJECT_NAME)
$(OBJECT_NAME): $(OBJ)
$(info Linking $@)
$(CC) -nostdlib -shared -fPIC -fPIE -Wl,-soname,$(SO_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@
$(OBJDUMP) -d $(OUTPUT_DIR)$@ > file_dump.map
ifeq ($(USERSPACE_STATIC_LIBS), 1)
$(AR) rcs $(OUTPUT_DIR)$@ $(OBJ)
else
$(CC) -nostdlib -shared -fPIC -fPIE -Wl,-soname,$(OBJECT_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@
endif
%.o: %.c
$(info Compiling $<)
@@ -50,9 +55,5 @@ $(OBJECT_NAME): $(OBJ)
$(info Compiling $<)
$(AS) -c $< -o $@
%.o: %.asm
$(info Compiling $<)
$(NASM) $< -f $(ASM_ARCH) -o $@
clean:
rm -f file_dump.map $(OBJ)
rm -f $(OBJ)