mirror of
https://github.com/Fennix-Project/Userspace.git
synced 2025-05-25 14:04:27 +00:00
Update userspace
This commit is contained in:
parent
0f8cb900cb
commit
2fd23205db
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,4 +2,6 @@
|
||||
*.map
|
||||
*.fex
|
||||
out/
|
||||
cache/*
|
||||
!cache/.gitkeep
|
||||
.dccache
|
||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -4,3 +4,9 @@
|
||||
[submodule "mlibc"]
|
||||
path = mlibc
|
||||
url = https://github.com/Fennix-Project/mlibc.git
|
||||
[submodule "apps/base/bash"]
|
||||
path = apps/base/bash
|
||||
url = https://github.com/Fennix-Project/bash.git
|
||||
[submodule "musl"]
|
||||
path = musl
|
||||
url = https://github.com/Fennix-Project/musl.git
|
||||
|
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
@ -4,7 +4,7 @@
|
||||
"name": "Fennix x64 (Linux, GCC, debug)",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/libc/include/**",
|
||||
"${workspaceFolder}/out/usr/include/**",
|
||||
"${workspaceFolder}/out/include/**",
|
||||
"${workspaceFolder}/libs/include/**",
|
||||
"${workspaceFolder}/libs/include"
|
||||
],
|
||||
@ -56,7 +56,7 @@
|
||||
"name": "Fennix x32 (Linux, GCC, debug)",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/libc/include/**",
|
||||
"${workspaceFolder}/out/usr/include/**",
|
||||
"${workspaceFolder}/out/include/**",
|
||||
"${workspaceFolder}/libs/include/**",
|
||||
"${workspaceFolder}/libs/include"
|
||||
],
|
||||
|
73
Makefile
73
Makefile
@ -1,25 +1,86 @@
|
||||
# Config file
|
||||
include ../Makefile.conf
|
||||
|
||||
build:
|
||||
ifeq ($(NEWLIB),1)
|
||||
make -C mlibc build
|
||||
cwd := $(CURDIR)
|
||||
PREFIX := $(cwd)/out/
|
||||
TARGET := x86_64-fennix
|
||||
|
||||
export CROSS_COMPILE := $(cwd)/../tools/cross/bin/$(TARGET)-
|
||||
export CC := $(cwd)/../tools/cross/bin/$(TARGET)-gcc
|
||||
export LD := $(cwd)/../tools/cross/bin/$(TARGET)-ld
|
||||
export AR := $(cwd)/../tools/cross/bin/$(TARGET)-ar
|
||||
export STRIP := $(cwd)/../tools/cross/bin/$(TARGET)-strip
|
||||
export RANLIB := $(cwd)/../tools/cross/bin/$(TARGET)-ranlib
|
||||
export LD_LIBRARY_PATH := $(cwd)/out/lib/
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
export CFLAGS := --sysroot=$(cwd)/out/ -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
export LDFLAGS := -ggdb3 -O0
|
||||
else
|
||||
export CFLAGS := --sysroot=$(cwd)/out/
|
||||
endif
|
||||
|
||||
ifeq ($(USERSPACE_STATIC_LIBS), 1)
|
||||
MUSL_CONFIGURE_FLAGS := --enable-static --disable-shared
|
||||
MLIBC_CONFIGURE_FLAGS := -Ddefault_library=static
|
||||
else
|
||||
MUSL_CONFIGURE_FLAGS := --enable-shared --enable-static
|
||||
MLIBC_CONFIGURE_FLAGS := -Ddefault_library=both
|
||||
endif
|
||||
|
||||
build_musl:
|
||||
mkdir -p cache/musl
|
||||
cd cache/musl && \
|
||||
../../musl/configure --prefix=$(PREFIX) \
|
||||
--target=$(TARGET) --includedir=$(PREFIX)/include \
|
||||
$(MUSL_CONFIGURE_FLAGS)
|
||||
make -C cache/musl -j$(shell nproc)
|
||||
cd cache/musl && make TARGET=$(TARGET) install
|
||||
cp out/lib/crt1.o out/lib/crt0.o
|
||||
cd out/lib && ln -s /lib/libc.so ./ld-musl-x86_64.so.1 && \
|
||||
ln -s /lib/libc.so ./ld.so
|
||||
mkdir -p out/include/fennix
|
||||
cp ../Kernel/syscalls.h out/include/fennix/syscall.h
|
||||
|
||||
build_mlibc:
|
||||
cp ../Kernel/syscalls.h ./mlibc/sysdeps/fennix/include/fennix/syscall.h
|
||||
ifeq ($(wildcard cache/mlibc),)
|
||||
cd mlibc && meson $(MLIBC_CONFIGURE_FLAGS) --cross-file ci/fennix.cross-file ../cache/mlibc
|
||||
endif
|
||||
cd cache/mlibc && DESTDIR=../../out ninja install
|
||||
mv out/usr/local/include/* out/include/
|
||||
mv out/usr/local/lib/* out/lib/
|
||||
|
||||
create_out:
|
||||
rm -rf out
|
||||
mkdir -p out
|
||||
mkdir -p out/lib
|
||||
mkdir -p out/bin
|
||||
mkdir -p out/lib
|
||||
mkdir -p out/include
|
||||
mkdir -p out/usr/bin
|
||||
mkdir -p out/usr/share
|
||||
mkdir -p out/usr/share/doc
|
||||
mkdir -p out/usr/share/info
|
||||
mkdir -p out/usr/include
|
||||
|
||||
build: create_out
|
||||
ifeq ($(USE_LIBC), internal)
|
||||
make -C libc build
|
||||
else ifeq ($(USE_LIBC), musl)
|
||||
$(MAKE) build_musl
|
||||
else ifeq ($(USE_LIBC), mlibc)
|
||||
$(MAKE) build_mlibc
|
||||
endif
|
||||
make -C libs build
|
||||
make -C apps build
|
||||
endif
|
||||
|
||||
prepare:
|
||||
$(info Nothing to prepare)
|
||||
|
||||
clean:
|
||||
rm -rf out
|
||||
rm -rf out cache
|
||||
mkdir -p cache
|
||||
touch cache/.gitkeep
|
||||
make -C libc clean
|
||||
make -C libs clean
|
||||
make -C apps clean
|
||||
|
@ -1,5 +1,38 @@
|
||||
cwd := $(CURDIR)
|
||||
CACHE_DIR := $(cwd)/../../cache
|
||||
PREFIX := $(cwd)/../../out/
|
||||
TARGET := x86_64-fennix
|
||||
|
||||
export CC := $(cwd)/../../../tools/cross/bin/$(TARGET)-gcc
|
||||
export LD := $(cwd)/../../../tools/cross/bin/$(TARGET)-ld
|
||||
export AR := $(cwd)/../../../tools/cross/bin/$(TARGET)-ar
|
||||
export STRIP := $(cwd)/../../../tools/cross/bin/$(TARGET)-strip
|
||||
export RANLIB := $(cwd)/../../../tools/cross/bin/$(TARGET)-ranlib
|
||||
export LD_LIBRARY_PATH := $(cwd)/../../out/lib/
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
export CFLAGS := --sysroot=$(cwd)/../../out/ -I$(cwd)/../../out/include/ -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
export LDFLAGS := -ggdb3 -O0
|
||||
else
|
||||
export CFLAGS := --sysroot=$(cwd)/../../out/ -I$(cwd)/../../out/include/
|
||||
endif
|
||||
|
||||
build_bash:
|
||||
ifeq ($(wildcard $(CACHE_DIR)/bash),)
|
||||
mkdir -p $(CACHE_DIR)/bash
|
||||
cd $(CACHE_DIR)/bash && \
|
||||
../../apps/base/bash/configure --prefix=$(PREFIX) \
|
||||
--host=$(TARGET) \
|
||||
--enable-minimal-config
|
||||
endif
|
||||
make -C $(CACHE_DIR)/bash -j$(shell nproc)
|
||||
make -C $(CACHE_DIR)/bash install
|
||||
|
||||
build:
|
||||
make -C echo build
|
||||
make -C fsh build
|
||||
# $(MAKE) build_bash
|
||||
|
||||
clean:
|
||||
make -C echo clean
|
||||
make -C fsh clean
|
||||
|
1
apps/base/bash
Submodule
1
apps/base/bash
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 07d7e008172fd30d786917d7924c9aba9a2d14fc
|
@ -30,10 +30,10 @@ OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURC
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = echo
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/usr/include/*)))
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/usr/include \
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
@ -3,9 +3,7 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
printf("%s ", argv[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
66
apps/base/fsh/Makefile
Normal file
66
apps/base/fsh/Makefile
Normal file
@ -0,0 +1,66 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)Makefile.conf
|
||||
|
||||
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
|
||||
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
|
||||
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
||||
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
|
||||
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), i386)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
endif
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = fsh
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
7
apps/base/fsh/fsh.c
Normal file
7
apps/base/fsh/fsh.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
printf("Hello, world!\n");
|
||||
return 0;
|
||||
}
|
@ -30,10 +30,10 @@ OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURC
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = init
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/usr/include/*)))
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/usr/include \
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
69
apps/system/init/aux.h
Normal file
69
apps/system/init/aux.h
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef __FENNIX_LIBC_AUX_H__
|
||||
#define __FENNIX_LIBC_AUX_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define AT_NULL 0
|
||||
#define AT_IGNORE 1
|
||||
#define AT_EXECFD 2
|
||||
#define AT_PHDR 3
|
||||
#define AT_PHENT 4
|
||||
#define AT_PHNUM 5
|
||||
#define AT_PAGESZ 6
|
||||
#define AT_BASE 7
|
||||
#define AT_FLAGS 8
|
||||
#define AT_ENTRY 9
|
||||
#define AT_NOTELF 10
|
||||
#define AT_UID 11
|
||||
#define AT_EUID 12
|
||||
#define AT_GID 13
|
||||
#define AT_EGID 14
|
||||
#define AT_PLATFORM 15
|
||||
#define AT_HWCAP 16
|
||||
#define AT_CLKTCK 17
|
||||
#define AT_SECURE 23
|
||||
#define AT_BASE_PLATFORM 24
|
||||
#define AT_RANDOM 25
|
||||
#define AT_HWCAP2 26
|
||||
#define AT_EXECFN 31
|
||||
#define AT_SYSINFO 32
|
||||
#define AT_SYSINFO_EHDR 33
|
||||
#define AT_L1I_CACHESHAPE 34
|
||||
#define AT_L1D_CACHESHAPE 35
|
||||
#define AT_L2_CACHESHAPE 36
|
||||
#define AT_L3_CACHESHAPE 37
|
||||
#define AT_L1I_CACHESIZE 40
|
||||
#define AT_L1I_CACHEGEOMETRY 41
|
||||
#define AT_L1D_CACHESIZE 42
|
||||
#define AT_L1D_CACHEGEOMETRY 43
|
||||
#define AT_L2_CACHESIZE 44
|
||||
#define AT_L2_CACHEGEOMETRY 45
|
||||
#define AT_L3_CACHESIZE 46
|
||||
#define AT_L3_CACHEGEOMETRY 47
|
||||
#define AT_MINSIGSTKSZ 51
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t a_type;
|
||||
union
|
||||
{
|
||||
uint32_t a_val;
|
||||
} a_un;
|
||||
} Elf32_auxv_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t a_type;
|
||||
union
|
||||
{
|
||||
uint64_t a_val;
|
||||
} a_un;
|
||||
} Elf64_auxv_t;
|
||||
|
||||
#ifdef __LP64__
|
||||
#define Elf_auxv_t Elf64_auxv_t
|
||||
#else
|
||||
#define Elf_auxv_t Elf32_auxv_t
|
||||
#endif
|
||||
|
||||
#endif // !__FENNIX_LIBC_AUX_H__
|
@ -1,8 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
#include <aux.h>
|
||||
#include "aux.h"
|
||||
|
||||
#include <libinit/init.h>
|
||||
#define print(m, ...) init_log(m, ##__VA_ARGS__)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9af0e63ae3ef8948e67ff0d570289a309ff40dcf
|
||||
Subproject commit 1a54c1624fc6b830a8a478b0f6601c447bbc5cc9
|
0
cache/.gitkeep
vendored
Normal file
0
cache/.gitkeep
vendored
Normal file
@ -5,22 +5,22 @@
|
||||
|
||||
uintptr_t RequestPages(size_t Count)
|
||||
{
|
||||
return syscall1(_RequestPages, Count);
|
||||
return syscall1(sys_RequestPages, Count);
|
||||
}
|
||||
|
||||
int FreePages(uintptr_t Address, size_t Count)
|
||||
{
|
||||
return syscall2(_FreePages, Address, Count);
|
||||
return syscall2(sys_FreePages, Address, Count);
|
||||
}
|
||||
|
||||
int IPC(int Command, int Type, int ID, int Flags, void *Buffer, size_t Size)
|
||||
{
|
||||
return syscall6(_IPC, (long)Command, (long)Type, (long)ID, (long)Flags, (long)Buffer, (long)Size);
|
||||
return syscall6(sys_IPC, (long)Command, (long)Type, (long)ID, (long)Flags, (long)Buffer, (long)Size);
|
||||
}
|
||||
|
||||
uintptr_t KernelCTL(int Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4)
|
||||
{
|
||||
return syscall5(_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4);
|
||||
return syscall5(sys_KernelCTL, Command, Arg1, Arg2, Arg3, Arg4);
|
||||
}
|
||||
|
||||
int abs(int i) { return i < 0 ? -i : i; }
|
||||
@ -112,38 +112,38 @@ int strcmp(const char *l, const char *r)
|
||||
|
||||
struct Elf64_Dyn ELFGetDynamicTag(char *Path, enum DynamicTags Tag)
|
||||
{
|
||||
void *KP = syscall2(_FileOpen, Path, (long)"r");
|
||||
if (KP == NULL)
|
||||
syscall1(_Exit, -0xF17E);
|
||||
int fd = syscall2(sys_FileOpen, Path, (long)"r");
|
||||
if (fd < 0)
|
||||
syscall1(sys_Exit, -0xF17E);
|
||||
|
||||
Elf64_Ehdr ELFHeader;
|
||||
syscall3(_FileRead, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Phdr ItrProgramHeader;
|
||||
for (Elf64_Half i = 0; i < ELFHeader.e_phnum; i++)
|
||||
{
|
||||
// memcpy(&ItrProgramHeader, (uint8_t *)ElfFile + ELFHeader.e_phoff + ELFHeader.e_phentsize * i, sizeof(Elf64_Phdr));
|
||||
syscall3(_FileSeek, KP, ELFHeader.e_phoff + ELFHeader.e_phentsize * i, SEEK_SET);
|
||||
syscall3(_FileRead, KP, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sys_FileSeek, fd, ELFHeader.e_phoff + ELFHeader.e_phentsize * i, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
if (ItrProgramHeader.p_type == PT_DYNAMIC)
|
||||
{
|
||||
struct Elf64_Dyn Dynamic; // = (struct Elf64_Dyn *)((uint8_t *)ElfFile + ItrProgramHeader.p_offset);
|
||||
syscall3(_FileSeek, KP, ItrProgramHeader.p_offset, SEEK_SET);
|
||||
syscall3(_FileRead, KP, &Dynamic, ItrProgramHeader.p_filesz);
|
||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Dynamic, ItrProgramHeader.p_filesz);
|
||||
for (size_t i = 0; i < ItrProgramHeader.p_filesz / sizeof(struct Elf64_Dyn); i++)
|
||||
{
|
||||
if (Dynamic.d_tag == Tag || Dynamic.d_tag == DT_NULL)
|
||||
{
|
||||
syscall1(_FileClose, KP);
|
||||
syscall1(sys_FileClose, fd);
|
||||
return Dynamic;
|
||||
}
|
||||
|
||||
syscall3(_FileSeek, KP, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), SEEK_SET);
|
||||
syscall3(_FileRead, KP, &Dynamic, sizeof(struct Elf64_Dyn));
|
||||
syscall3(sys_FileSeek, fd, ItrProgramHeader.p_offset + (i + 1) * sizeof(struct Elf64_Dyn), SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Dynamic, sizeof(struct Elf64_Dyn));
|
||||
}
|
||||
}
|
||||
}
|
||||
syscall1(_FileClose, KP);
|
||||
syscall1(sys_FileClose, fd);
|
||||
return (struct Elf64_Dyn){0};
|
||||
}
|
||||
|
||||
@ -168,12 +168,12 @@ char *GetELFStringTable(Elf64_Ehdr *Header)
|
||||
|
||||
Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
{
|
||||
void *KP = syscall2(_FileOpen, Path, (long)"r");
|
||||
if (KP == NULL)
|
||||
syscall1(_Exit, -0xF17E);
|
||||
int fd = syscall2(sys_FileOpen, Path, (long)"r");
|
||||
if (fd < 0)
|
||||
syscall1(sys_Exit, -0xF17E);
|
||||
|
||||
Elf64_Ehdr ELFHeader;
|
||||
syscall3(_FileRead, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
syscall3(sys_FileRead, fd, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Shdr SymbolTable;
|
||||
Elf64_Shdr StringTable;
|
||||
@ -183,20 +183,20 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
for (Elf64_Half i = 0; i < ELFHeader.e_shnum; i++)
|
||||
{
|
||||
Elf64_Shdr shdr;
|
||||
syscall3(_FileSeek, KP,
|
||||
syscall3(sys_FileSeek, fd,
|
||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * i,
|
||||
SEEK_SET);
|
||||
syscall3(_FileRead, KP, &shdr, sizeof(Elf64_Shdr));
|
||||
SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &shdr, sizeof(Elf64_Shdr));
|
||||
|
||||
switch (shdr.sh_type)
|
||||
{
|
||||
case SHT_SYMTAB:
|
||||
{
|
||||
SymbolTable = shdr;
|
||||
syscall3(_FileSeek, KP,
|
||||
syscall3(sys_FileSeek, fd,
|
||||
ELFHeader.e_shoff + ELFHeader.e_shentsize * shdr.sh_link,
|
||||
SEEK_SET);
|
||||
syscall3(_FileRead, KP, &StringTable, sizeof(Elf64_Shdr));
|
||||
SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &StringTable, sizeof(Elf64_Shdr));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -208,7 +208,7 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
|
||||
if (SymbolTable.sh_size == 0 || StringTable.sh_size == 0)
|
||||
{
|
||||
syscall1(_FileClose, KP);
|
||||
syscall1(sys_FileClose, fd);
|
||||
return (Elf64_Sym){0};
|
||||
}
|
||||
|
||||
@ -216,19 +216,19 @@ Elf64_Sym ELFLookupSymbol(char *Path, const char *Name)
|
||||
{
|
||||
// Symbol = (Elf64_Sym *)((uintptr_t)Header + SymbolTable->sh_offset + (i * sizeof(Elf64_Sym)));
|
||||
// String = (char *)((uintptr_t)Header + StringTable->sh_offset + Symbol->st_name);
|
||||
syscall3(_FileSeek, KP, SymbolTable.sh_offset + (i * sizeof(Elf64_Sym)), SEEK_SET);
|
||||
syscall3(_FileRead, KP, &Symbol, sizeof(Elf64_Sym));
|
||||
syscall3(sys_FileSeek, fd, SymbolTable.sh_offset + (i * sizeof(Elf64_Sym)), SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &Symbol, sizeof(Elf64_Sym));
|
||||
|
||||
syscall3(_FileSeek, KP, StringTable.sh_offset + Symbol.st_name, SEEK_SET);
|
||||
syscall3(_FileRead, KP, &String, sizeof(char *));
|
||||
syscall3(sys_FileSeek, fd, StringTable.sh_offset + Symbol.st_name, SYSCALL_SEEK_SET);
|
||||
syscall3(sys_FileRead, fd, &String, sizeof(char *));
|
||||
|
||||
if (strcmp(String, Name) == 0)
|
||||
{
|
||||
syscall1(_FileClose, KP);
|
||||
syscall1(sys_FileClose, fd);
|
||||
return Symbol;
|
||||
}
|
||||
}
|
||||
|
||||
syscall1(_FileClose, KP);
|
||||
syscall1(sys_FileClose, fd);
|
||||
return (Elf64_Sym){0};
|
||||
}
|
||||
|
@ -90,9 +90,6 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
||||
which determines the end of the list. */
|
||||
while (CurLib->Valid)
|
||||
{
|
||||
KernelCTL(KCTL_GET_ABSOLUTE_PATH, CurLib->LibraryName,
|
||||
LibraryPathBuffer, sizeof(LibraryPathBuffer), 0);
|
||||
|
||||
PrintDbg("-- ");
|
||||
PrintDbg(LibraryPathBuffer);
|
||||
PrintDbg(" ");
|
||||
@ -105,46 +102,46 @@ void (*ELF_LAZY_RESOLVE_MAIN(struct LibsCollection *Info, long RelIndex))()
|
||||
Elf64_Ehdr lib_Header;
|
||||
Elf64_Ehdr app_Header;
|
||||
|
||||
void *KP_lib = syscall2(_FileOpen, LibraryPathBuffer, "r");
|
||||
void *KP_app = syscall2(_FileOpen, ParentPath, "r");
|
||||
int fd_lib = syscall2(sys_FileOpen, LibraryPathBuffer, "r");
|
||||
int fd_app = syscall2(sys_FileOpen, ParentPath, "r");
|
||||
|
||||
if (!KP_lib)
|
||||
if (fd_lib < 0)
|
||||
{
|
||||
PrintNL("Failed to open library");
|
||||
goto RetryNextLib;
|
||||
}
|
||||
|
||||
if (!KP_app)
|
||||
if (fd_app < 0)
|
||||
{
|
||||
PrintNL("Failed to open application");
|
||||
goto RetryNextLib;
|
||||
}
|
||||
|
||||
syscall3(_FileRead, KP_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(_FileRead, KP_app, &app_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(sys_FileRead, fd_lib, &lib_Header, sizeof(Elf64_Ehdr));
|
||||
syscall3(sys_FileRead, fd_app, &app_Header, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Phdr ItrProgramHeader;
|
||||
|
||||
for (Elf64_Half i = 0; i < lib_Header.e_phnum; i++)
|
||||
{
|
||||
syscall3(_FileSeek, KP_lib,
|
||||
syscall3(sys_FileSeek, fd_lib,
|
||||
lib_Header.e_phoff +
|
||||
lib_Header.e_phentsize * i,
|
||||
SEEK_SET);
|
||||
SYSCALL_SEEK_SET);
|
||||
|
||||
syscall3(_FileRead, KP_lib, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sys_FileRead, fd_lib, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
|
||||
lib_BaseAddress = MIN(lib_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||
}
|
||||
|
||||
for (Elf64_Half i = 0; i < app_Header.e_phnum; i++)
|
||||
{
|
||||
syscall3(_FileSeek, KP_app,
|
||||
syscall3(sys_FileSeek, fd_app,
|
||||
app_Header.e_phoff +
|
||||
app_Header.e_phentsize * i,
|
||||
SEEK_SET);
|
||||
SYSCALL_SEEK_SET);
|
||||
|
||||
syscall3(_FileRead, KP_app, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
syscall3(sys_FileRead, fd_app, &ItrProgramHeader, sizeof(Elf64_Phdr));
|
||||
|
||||
app_BaseAddress = MIN(app_BaseAddress, ItrProgramHeader.p_vaddr);
|
||||
}
|
||||
@ -268,7 +265,7 @@ FailEnd:
|
||||
Print(DbgBuff);
|
||||
PrintNL(" not found");
|
||||
int ExitCode = 0x51801;
|
||||
syscall1(_Exit, ExitCode);
|
||||
syscall1(sys_Exit, ExitCode);
|
||||
while (1) // Make sure we don't return
|
||||
;
|
||||
}
|
||||
@ -280,9 +277,9 @@ int ld_main()
|
||||
uintptr_t KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
do
|
||||
{
|
||||
syscall1(_Sleep, 250);
|
||||
syscall1(sys_Sleep, 250);
|
||||
KCTL_ret = KernelCTL(KCTL_IS_CRITICAL, 0, 0, 0, 0);
|
||||
} while (KCTL_ret == SYSCALL_ACCESS_DENIED);
|
||||
} while (KCTL_ret == false);
|
||||
|
||||
if (KCTL_ret == false)
|
||||
return -1;
|
||||
@ -307,111 +304,21 @@ bool ELFAddLazyResolverToGOT(void *MemoryImage, struct LibsCollection *Libs)
|
||||
/* Actual load */
|
||||
int ld_load(int argc, char *argv[], char *envp[])
|
||||
{
|
||||
PrintDbgNL("!");
|
||||
uintptr_t PageSize = KernelCTL(KCTL_GET_PAGE_SIZE, 0, 0, 0, 0);
|
||||
int PagesForIPCDataStruct = sizeof(InterpreterIPCData) / PageSize + 1;
|
||||
int PagesForLibsCollectionStruct = sizeof(struct LibsCollection) / PageSize + 1;
|
||||
|
||||
InterpreterIPCData *IPCBuffer =
|
||||
(InterpreterIPCData *)RequestPages(PagesForIPCDataStruct);
|
||||
|
||||
int IPC_ID = IPC(IPC_CREATE, IPC_TYPE_MessagePassing,
|
||||
0, 0, "LOAD", sizeof(InterpreterIPCData));
|
||||
while (true)
|
||||
{
|
||||
IPC(IPC_LISTEN, IPC_TYPE_MessagePassing, IPC_ID, 1, NULL, 0);
|
||||
IPC(IPC_WAIT, IPC_TYPE_MessagePassing, IPC_ID, 0, NULL, 0);
|
||||
int IPCResult = IPC(IPC_READ, IPC_TYPE_MessagePassing,
|
||||
IPC_ID, 0, IPCBuffer, PageSize);
|
||||
|
||||
if (IPCResult == IPC_E_CODE_Success)
|
||||
break;
|
||||
}
|
||||
|
||||
struct LibsCollection *LibsForLazyResolver =
|
||||
(struct LibsCollection *)RequestPages(PagesForLibsCollectionStruct);
|
||||
|
||||
for (short i = 0; i < 64; i++)
|
||||
{
|
||||
if (IPCBuffer->Libraries[i].Name[0] == '\0')
|
||||
break;
|
||||
|
||||
uintptr_t lib_mm_image =
|
||||
KernelCTL(KCTL_GET_ELF_LIB_MEMORY_IMAGE,
|
||||
(uint64_t)IPCBuffer->Libraries[i].Name, 0, 0, 0);
|
||||
if (lib_mm_image == 0)
|
||||
{
|
||||
enum SyscallsErrorCodes ret =
|
||||
KernelCTL(KCTL_REGISTER_ELF_LIB,
|
||||
(uint64_t)IPCBuffer->Libraries[i].Name,
|
||||
(uint64_t)IPCBuffer->Libraries[i].Name, 0, 0);
|
||||
if (ret != SYSCALL_OK)
|
||||
{
|
||||
PrintNL("Failed to register ELF lib");
|
||||
return -0x11B;
|
||||
}
|
||||
lib_mm_image = KernelCTL(KCTL_GET_ELF_LIB_MEMORY_IMAGE,
|
||||
(uint64_t)IPCBuffer->Libraries[i].Name, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (LibsForLazyResolver->Next == NULL)
|
||||
{
|
||||
LibsForLazyResolver->Valid = true;
|
||||
LibsForLazyResolver->LibraryMemoryImage = (uintptr_t)lib_mm_image;
|
||||
LibsForLazyResolver->ParentMemoryImage = (uintptr_t)IPCBuffer->MemoryImage;
|
||||
for (short j = 0; j < sizeof(LibsForLazyResolver->LibraryName); j++)
|
||||
LibsForLazyResolver->LibraryName[j] = IPCBuffer->Libraries[i].Name[j];
|
||||
|
||||
LibsForLazyResolver->Next =
|
||||
(struct LibsCollection *)RequestPages(PagesForLibsCollectionStruct);
|
||||
memset(LibsForLazyResolver->Next, 0, sizeof(struct LibsCollection));
|
||||
continue;
|
||||
}
|
||||
|
||||
struct LibsCollection *CurrentLib = LibsForLazyResolver;
|
||||
while (CurrentLib->Next != NULL)
|
||||
CurrentLib = CurrentLib->Next;
|
||||
|
||||
CurrentLib->Valid = true;
|
||||
CurrentLib->LibraryMemoryImage = (uintptr_t)lib_mm_image;
|
||||
CurrentLib->ParentMemoryImage = (uintptr_t)IPCBuffer->MemoryImage;
|
||||
for (short j = 0; j < sizeof(LibsForLazyResolver->LibraryName); j++)
|
||||
CurrentLib->LibraryName[j] = IPCBuffer->Libraries[i].Name[j];
|
||||
|
||||
CurrentLib->Next =
|
||||
(struct LibsCollection *)RequestPages(PagesForLibsCollectionStruct);
|
||||
memset(CurrentLib->Next, 0, sizeof(struct LibsCollection));
|
||||
}
|
||||
|
||||
struct LibsCollection *CurrentLib = LibsForLazyResolver;
|
||||
|
||||
for (int i = 0; i < sizeof(ParentPath); i++)
|
||||
ParentPath[i] = IPCBuffer->Path[i];
|
||||
|
||||
if (!ELFAddLazyResolverToGOT(IPCBuffer->MemoryImage,
|
||||
LibsForLazyResolver))
|
||||
{
|
||||
PrintNL("Failed to add lazy resolver to GOT");
|
||||
return -0x607;
|
||||
}
|
||||
|
||||
void *KP = syscall2(_FileOpen, ParentPath, (long)"r");
|
||||
if (KP == NULL)
|
||||
{
|
||||
PrintNL("Failed to open file");
|
||||
syscall1(_Exit, -0xF17E);
|
||||
}
|
||||
|
||||
Elf64_Ehdr ELFHeader;
|
||||
syscall3(_FileRead, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
Elf64_Addr Entry = ELFHeader.e_entry;
|
||||
|
||||
syscall1(_FileClose, KP);
|
||||
|
||||
IPC(IPC_DELETE, IPC_TYPE_MessagePassing, IPC_ID, 0, NULL, 0);
|
||||
FreePages((uintptr_t)IPCBuffer, PagesForIPCDataStruct);
|
||||
|
||||
PrintDbgNL("Calling entry point");
|
||||
return ((int (*)(int, char *[], char *[]))Entry)(argc, argv, envp);
|
||||
|
||||
// void *KP = syscall2(sys_FileOpen, ParentPath, (long)"r");
|
||||
// if (KP == NULL)
|
||||
// {
|
||||
// PrintNL("Failed to open file");
|
||||
// syscall1(sys_Exit, -0xF17E);
|
||||
// }
|
||||
|
||||
// Elf64_Ehdr ELFHeader;
|
||||
// syscall3(sys_FileRead, KP, &ELFHeader, sizeof(Elf64_Ehdr));
|
||||
|
||||
// Elf64_Addr Entry = ELFHeader.e_entry;
|
||||
|
||||
// syscall1(sys_FileClose, KP);
|
||||
|
||||
// return ((int (*)(int, char *[], char *[]))Entry)(argc, argv, envp);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
build:
|
||||
cp -r include/* ../out/usr/include
|
||||
cp ../../Kernel/syscalls.h ../out/usr/include/sys
|
||||
cp -r include/* ../out/include
|
||||
cp ../../Kernel/syscalls.h ../out/include/fennix/syscall.h
|
||||
make -C runtime build
|
||||
make -C src build
|
||||
make -C ElfInterpreter build
|
||||
|
6
libc/include/features.h
Normal file
6
libc/include/features.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _FEATURES_H
|
||||
#define _FEATURES_H
|
||||
|
||||
#define __FENNIX_LIBC__ 1
|
||||
|
||||
#endif
|
0
libc/include/fennix/.gitkeep
Normal file
0
libc/include/fennix/.gitkeep
Normal file
34
libc/include/setjmp.h
Normal file
34
libc/include/setjmp.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef _SETJMP_H
|
||||
#define _SETJMP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t r15;
|
||||
uint64_t r14;
|
||||
uint64_t r13;
|
||||
uint64_t r12;
|
||||
uint64_t r11;
|
||||
uint64_t r10;
|
||||
uint64_t r9;
|
||||
uint64_t r8;
|
||||
uint64_t rbp;
|
||||
uint64_t rsp;
|
||||
uint64_t rdi;
|
||||
uint64_t rsi;
|
||||
uint64_t rdx;
|
||||
uint64_t rcx;
|
||||
uint64_t rbx;
|
||||
uint64_t rax;
|
||||
uint64_t rip;
|
||||
uint64_t rflags;
|
||||
uint64_t cs;
|
||||
uint64_t fs;
|
||||
uint64_t gs;
|
||||
} jmp_buf[1];
|
||||
|
||||
int setjmp(jmp_buf env);
|
||||
__attribute__((noreturn)) void longjmp(jmp_buf env, int value);
|
||||
|
||||
#endif // !_SETJMP_H
|
6
libc/include/stdint.h
Normal file
6
libc/include/stdint.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _STDINT_H
|
||||
#define _STDINT_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !_STDINT_H
|
@ -41,8 +41,6 @@ struct _IO_FILE
|
||||
struct _IO_marker *_markers;
|
||||
struct _IO_FILE *_chain;
|
||||
int _fileno;
|
||||
|
||||
void *KernelPrivate;
|
||||
};
|
||||
|
||||
typedef struct _IO_FILE FILE;
|
||||
|
@ -27,7 +27,7 @@ else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../out/usr/include
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../out/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <sys/syscalls.h>
|
||||
#include <fennix/syscall.h>
|
||||
#include <sys/types.h> // For PUBLIC
|
||||
|
||||
extern void __libc_init_array(void);
|
||||
@ -17,7 +17,7 @@ PUBLIC void _exit(int Code)
|
||||
{
|
||||
__libc_fini_std();
|
||||
__libc_fini_array();
|
||||
syscall1(_Exit, (long)Code);
|
||||
syscall1(sys_Exit, (long)Code);
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ extern "C" int liballoc_unlock()
|
||||
|
||||
extern "C" void *liballoc_alloc(size_t Pages)
|
||||
{
|
||||
return (void *)syscall1(_RequestPages, Pages);
|
||||
return (void *)syscall1(sys_RequestPages, Pages);
|
||||
}
|
||||
|
||||
extern "C" int liballoc_free(void *Address, size_t Pages)
|
||||
{
|
||||
return syscall2(_FreePages, (uint64_t)Address, Pages);
|
||||
return syscall2(sys_FreePages, (uint64_t)Address, Pages);
|
||||
}
|
||||
|
11
libc/src/setjmp.c
Normal file
11
libc/src/setjmp.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <setjmp.h>
|
||||
|
||||
PUBLIC int setjmp(jmp_buf env)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PUBLIC __attribute__((noreturn)) void longjmp(jmp_buf env, int value)
|
||||
{
|
||||
_exit(value);
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/syscalls.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <fennix/syscall.h>
|
||||
#include <sys/types.h> // For PUBLIC
|
||||
|
||||
PUBLIC FILE *stdin = NULL;
|
||||
@ -12,12 +12,12 @@ PUBLIC FILE *stderr = NULL;
|
||||
|
||||
PUBLIC FILE *fopen(const char *filename, const char *mode)
|
||||
{
|
||||
void *KPrivate = (void *)syscall2(_FileOpen, (uint64_t)filename, (uint64_t)mode);
|
||||
if (IsSyscallError(KPrivate))
|
||||
int fd = syscall2(sys_FileOpen, (uint64_t)filename, (uint64_t)mode);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
FILE *FilePtr = malloc(sizeof(FILE));
|
||||
FilePtr->KernelPrivate = KPrivate;
|
||||
FilePtr->_fileno = fd;
|
||||
return FilePtr;
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ PUBLIC size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
syscall3(_FileSeek, stream->KernelPrivate, stream->_offset, SEEK_SET);
|
||||
return syscall3(_FileRead, (uint64_t)stream->KernelPrivate, (uint64_t)ptr, size * nmemb);
|
||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sys_FileRead, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
}
|
||||
|
||||
PUBLIC size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
@ -41,8 +41,8 @@ PUBLIC size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
syscall3(_FileSeek, stream->KernelPrivate, stream->_offset, SEEK_SET);
|
||||
return syscall3(_FileWrite, (uint64_t)stream->KernelPrivate, (uint64_t)ptr, size * nmemb);
|
||||
syscall3(sys_FileSeek, stream->_fileno, stream->_offset, SEEK_SET);
|
||||
return syscall3(sys_FileWrite, (uint64_t)stream->_fileno, (uint64_t)ptr, size * nmemb);
|
||||
}
|
||||
|
||||
PUBLIC int fclose(FILE *fp)
|
||||
@ -53,9 +53,7 @@ PUBLIC int fclose(FILE *fp)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
void *KP = fp->KernelPrivate;
|
||||
free(fp);
|
||||
return syscall1(_FileClose, (uint64_t)KP);
|
||||
return syscall1(sys_FileClose, fp->_fileno);
|
||||
}
|
||||
|
||||
PUBLIC off_t fseek(FILE *stream, off_t offset, int whence)
|
||||
@ -66,8 +64,8 @@ PUBLIC off_t fseek(FILE *stream, off_t offset, int whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
off_t new_offset = syscall3(_FileSeek, stream->KernelPrivate, offset, whence);
|
||||
if (IsSyscallError(new_offset))
|
||||
off_t new_offset = syscall3(sys_FileSeek, stream->_fileno, offset, whence);
|
||||
if (new_offset < 0)
|
||||
return -1;
|
||||
stream->_offset = new_offset;
|
||||
return new_offset;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/syscalls.h>
|
||||
#include <fennix/syscall.h>
|
||||
|
||||
#include <sys/types.h> // For PUBLIC
|
||||
|
||||
@ -12,8 +12,8 @@ PUBLIC int fputc(int c, FILE *stream)
|
||||
// errno = EBADF;
|
||||
// return EOF;
|
||||
// }
|
||||
|
||||
return syscall2(_Print, c, 0);
|
||||
char str[2] = {c, '\0'};
|
||||
return syscall3(sys_KernelCTL, KCTL_PRINT, str, 0);
|
||||
}
|
||||
|
||||
PUBLIC int putc(int c, FILE *stream) { return fputc(c, stream); }
|
||||
|
@ -2,13 +2,13 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/syscalls.h>
|
||||
#include <fennix/syscall.h>
|
||||
|
||||
#include "../mem/liballoc_1_1.h"
|
||||
|
||||
PUBLIC void abort(void)
|
||||
{
|
||||
syscall1(_Exit, -0xAB057);
|
||||
syscall1(sys_Exit, -0xAB057);
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
@ -47,5 +47,5 @@ PUBLIC int execve(const char *pathname, char *const argv[], char *const envp[])
|
||||
|
||||
PUBLIC pid_t fork(void)
|
||||
{
|
||||
return syscall0(_Fork);
|
||||
return syscall0(sys_Fork);
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include <errno.h>
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
PUBLIC unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
return syscall1(_Sleep, seconds * 1000000);
|
||||
return syscall1(sys_Sleep, seconds * 1000000);
|
||||
}
|
||||
|
||||
int usleep(useconds_t usec)
|
||||
PUBLIC int usleep(useconds_t usec)
|
||||
{
|
||||
return syscall1(_Sleep, usec);
|
||||
return syscall1(sys_Sleep, usec);
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
build:
|
||||
cp -r include/* ../out/usr/include
|
||||
cp -r include/* ../out/include
|
||||
make -C libgcc build
|
||||
make -C libinit build
|
||||
make -C libssp build
|
||||
make -C libsys build
|
||||
|
||||
clean:
|
||||
make -C libgcc clean
|
||||
make -C libinit clean
|
||||
make -C libssp clean
|
||||
make -C libsys clean
|
||||
|
@ -1,11 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_BASE_H__
|
||||
#define __FENNIX_LIBS_BASE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
long DoCtl(uint64_t Command, uint64_t Arg1, uint64_t Arg2, uint64_t Arg3, uint64_t Arg4);
|
||||
|
||||
uintptr_t KrnlRequestPages(size_t Count);
|
||||
void KrnlFreePages(uintptr_t Address, size_t Count);
|
||||
|
||||
#endif // !__FENNIX_LIBS_BASE_H__
|
@ -1,32 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SYS_FILE_H__
|
||||
#define __FENNIX_LIBS_SYS_FILE_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *KernelPrivate;
|
||||
} File;
|
||||
|
||||
enum FileFlags
|
||||
{
|
||||
FILE_READ = 1,
|
||||
FILE_WRITE = 2,
|
||||
FILE_APPEND = 4,
|
||||
FILE_CREATE = 8,
|
||||
FILE_TRUNCATE = 16,
|
||||
FILE_EXCLUSIVE = 32,
|
||||
FILE_DIRECTORY = 64,
|
||||
FILE_SYMLINK = 128,
|
||||
FILE_NONBLOCK = 256,
|
||||
FILE_CLOEXEC = 512,
|
||||
};
|
||||
|
||||
File *FileOpen(const char *Path, uint64_t Flags);
|
||||
void FileClose(File *File);
|
||||
uint64_t FileRead(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
||||
uint64_t FileWrite(File *File, uint64_t Offset, uint8_t *Buffer, uint64_t Size);
|
||||
uint64_t FileSeek(File *File, uint64_t Offset, uint64_t Whence);
|
||||
uint64_t FileStatus(File *File);
|
||||
|
||||
#endif // !__FENNIX_LIBS_SYS_FILE_H__
|
@ -1,122 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SYS_PROC_H__
|
||||
#define __FENNIX_LIBS_SYS_PROC_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
enum ProcessState
|
||||
{
|
||||
PROCESS_STATE_READY,
|
||||
PROCESS_STATE_RUNNING,
|
||||
PROCESS_STATE_SLEEPING,
|
||||
PROCESS_STATE_WAITING,
|
||||
PROCESS_STATE_STOPPED,
|
||||
PROCESS_STATE_TERMINATED
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[256];
|
||||
unsigned long ID;
|
||||
enum ProcessState State;
|
||||
void *KernelPrivate;
|
||||
} Process;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char Name[256];
|
||||
unsigned long ID;
|
||||
enum ProcessState State;
|
||||
void *KernelPrivate;
|
||||
} Thread;
|
||||
|
||||
/**
|
||||
* @brief Create a new process from a path
|
||||
*
|
||||
* @param Path Path to the executable
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *Spawn(const char *Path);
|
||||
|
||||
/**
|
||||
* @brief Create a new thread
|
||||
*
|
||||
* @param EntryPoint Entry point of the thread
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *SpawnThread(uintptr_t EntryPoint);
|
||||
|
||||
/**
|
||||
* @brief Get list of threads
|
||||
*
|
||||
* @param Process Process to get the threads from
|
||||
* @return Thread** Pointer to the thread list (NULL terminated)
|
||||
*/
|
||||
Thread **GetThreadList(Process *Process);
|
||||
|
||||
/**
|
||||
* @brief Get process by ID
|
||||
*
|
||||
* @param ID Process ID
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *GetProcessByID(unsigned long ID);
|
||||
|
||||
/**
|
||||
* @brief Get thread by ID
|
||||
*
|
||||
* @param ID Thread ID
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *GetThreadByID(unsigned long ID);
|
||||
|
||||
/**
|
||||
* @brief Get current process
|
||||
*
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* @brief Get current thread
|
||||
*
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *GetCurrentThread();
|
||||
|
||||
/**
|
||||
* @brief [SYSTEM] Create a new empty process
|
||||
*
|
||||
* @param KernelPrivate Process parent
|
||||
* @param Name Process name
|
||||
* @param TrustLevel Process trust level [RESERVED FOR TRUSTED PROCESSES]
|
||||
* @param Image Process file image already loaded in memory
|
||||
* @return Process* Pointer to the process structure
|
||||
*/
|
||||
Process *KrnlCreateProcess(void *KernelPrivate,
|
||||
const char *Name,
|
||||
long TrustLevel,
|
||||
void *Image);
|
||||
|
||||
/**
|
||||
* @brief [SYSTEM] Create a new thread
|
||||
*
|
||||
* @param KernelPrivate Process parent
|
||||
* @param EntryPoint Entry point of the thread
|
||||
* @param argv Arguments
|
||||
* @param envp Environment variables
|
||||
* @param auxv Auxiliary variables
|
||||
* @param Offset Offset of the entry point
|
||||
* @param Architecture Architecture of the thread
|
||||
* @param Compatibility Compatibility of the thread
|
||||
* @return Thread* Pointer to the thread structure
|
||||
*/
|
||||
Thread *KrnlCreateThread(void *KernelPrivate,
|
||||
unsigned long EntryPoint,
|
||||
const char **argv,
|
||||
const char **envp,
|
||||
void *auxv,
|
||||
unsigned long Offset,
|
||||
long Architecture,
|
||||
long Compatibility);
|
||||
|
||||
#endif // !__FENNIX_LIBS_SYS_PROC_H__
|
@ -1,6 +0,0 @@
|
||||
#ifndef __FENNIX_LIBS_SSP_H__
|
||||
#define __FENNIX_LIBS_SSP_H__
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#endif // !__FENNIX_LIBS_SSP_H__
|
@ -27,10 +27,11 @@ else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -fPIE -I../include -I../../libc/include
|
||||
CFLAGS := -fvisibility=hidden -fPIC -fPIE -I../include -I../../out/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(OBJECT_NAME)
|
||||
|
@ -1,7 +1,16 @@
|
||||
#include <libinit/init.h>
|
||||
#include <unistd.h>
|
||||
#include <features.h>
|
||||
#include "printf.h"
|
||||
|
||||
#ifdef __FENNIX_LIBC__
|
||||
#define cprintf printf_libinit
|
||||
#define cvprintf vprintf_libinit
|
||||
#else
|
||||
#define cprintf printf
|
||||
#define cvprintf vprintf
|
||||
#endif
|
||||
|
||||
void init_log(const char *fmt, ...)
|
||||
{
|
||||
static short log_lock = 0;
|
||||
@ -10,12 +19,12 @@ void init_log(const char *fmt, ...)
|
||||
__sync_synchronize();
|
||||
log_lock = 1;
|
||||
|
||||
printf_libinit("\eCCCCCC[\e0088FFinit\eCCCCCC] \eAAAAAA");
|
||||
cprintf("\eCCCCCC[\e0088FFinit\eCCCCCC] \eAAAAAA");
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf_libinit(fmt, args);
|
||||
cvprintf(fmt, args);
|
||||
va_end(args);
|
||||
printf_libinit("\eCCCCCC");
|
||||
cprintf("\eCCCCCC");
|
||||
|
||||
log_lock = 0;
|
||||
__sync_synchronize();
|
||||
|
@ -49,8 +49,9 @@
|
||||
#include <cstdint>
|
||||
#include <climits>
|
||||
#else
|
||||
#include <types.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#endif // __cplusplus
|
||||
|
||||
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
|
||||
|
@ -39,11 +39,14 @@
|
||||
#ifndef PRINTF_H_
|
||||
#define PRINTF_H_
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -27,10 +27,11 @@ else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../libc/include
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../out/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(OBJECT_NAME)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef PUBLIC
|
||||
#define PUBLIC __attribute__((visibility("default")))
|
||||
#endif // !PUBLIC
|
||||
@ -26,19 +25,13 @@ static void __attribute__((constructor, no_stack_protector)) __guard_setup(void)
|
||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __stack_chk_fail(void)
|
||||
{
|
||||
const char *msg = "Stack smashing detected";
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(0), "D"(0x57AC)
|
||||
: "rcx", "r11", "memory");
|
||||
exit(0x57AC);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
PUBLIC __attribute__((weak, noreturn, no_stack_protector)) void __chk_fail(void)
|
||||
{
|
||||
const char *msg = "Buffer overflow detected";
|
||||
__asm__ __volatile__("syscall"
|
||||
:
|
||||
: "a"(0), "D"(0xF700)
|
||||
: "rcx", "r11", "memory");
|
||||
exit(0xF700);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
uintptr_t KrnlRequestPages(size_t Count)
|
||||
{
|
||||
return syscall1(_RequestPages, Count);
|
||||
}
|
||||
|
||||
void KrnlFreePages(uintptr_t Address, size_t Count)
|
||||
{
|
||||
syscall2(_FreePages, Address, Count);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
#include <libsys/file.h>
|
||||
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
__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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void FileClose(File *File)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
uint64_t FileSeek(File *File, uint64_t Offset, uint64_t Whence)
|
||||
{
|
||||
return syscall3(_FileSeek, (uint64_t)File->KernelPrivate, Offset, Whence);
|
||||
}
|
||||
|
||||
uint64_t FileStatus(File *File)
|
||||
{
|
||||
return syscall1(_FileStatus, (uint64_t)File->KernelPrivate);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
# Config file
|
||||
include ../../../Makefile.conf
|
||||
|
||||
NAME=sys
|
||||
|
||||
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 = ../../../$(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')
|
||||
OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${S_SOURCES:.S=.o}
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
ASM_ARCH := elf64
|
||||
else ifeq ($(OSARCH), i386)
|
||||
ASM_ARCH := elf32
|
||||
endif
|
||||
|
||||
CFLAGS := -fvisibility=hidden -fPIC -I../include -I../../libc/include
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
endif
|
||||
|
||||
build: $(OBJECT_NAME)
|
||||
|
||||
$(OBJECT_NAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
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 $<)
|
||||
$(CC) $(CFLAGS) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) -std=c++20 -c $< -o $@
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
@ -1,6 +0,0 @@
|
||||
#include <libsys/base.h>
|
||||
#include <libsys/proc.h>
|
||||
|
||||
#include "../../../Kernel/syscalls.h"
|
||||
|
||||
|
2
mlibc
2
mlibc
@ -1 +1 @@
|
||||
Subproject commit 2b1b3bd7dc09179bb6462afa0bbca7b27339619f
|
||||
Subproject commit e441e78343be6824eb98ae3519f8777d16fe03b4
|
1
musl
Submodule
1
musl
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 718f363bc2067b6487900eddc9180c84e7739f80
|
Loading…
x
Reference in New Issue
Block a user